0
|
1 //
|
|
2 // GameToolbar.swift
|
|
3 // GeoQuiz
|
|
4 //
|
|
5 // Created by Dennis Concepción Martín on 18/9/22.
|
|
6 //
|
|
7
|
|
8 import SwiftUI
|
|
9
|
3
|
10 struct GameToolbar<T: Game>: View {
|
|
11 @ObservedObject var game: T
|
|
12
|
6
|
13 var color: Color
|
0
|
14
|
|
15 var body: some View {
|
|
16 HStack(spacing: 0) {
|
|
17 Group {
|
|
18 Button {
|
4
|
19 game.showingExitGameAlert = true
|
0
|
20 } label: {
|
|
21 Image(systemName: "multiply")
|
6
|
22 .font(.headline)
|
|
23 .foregroundColor(color)
|
0
|
24 .padding(10)
|
|
25 .background(
|
|
26 Circle()
|
6
|
27 .foregroundColor(.white)
|
0
|
28 )
|
|
29 }
|
|
30 }
|
|
31 .font(.headline)
|
|
32 .frame(maxWidth: .infinity, alignment: .leading)
|
|
33
|
|
34 Group {
|
4
|
35 Button {
|
|
36 game.showingGameStatsView = true
|
|
37 } label: {
|
|
38 Text("\(game.userScore)")
|
6
|
39 .font(.title.bold())
|
|
40 .foregroundColor(color)
|
4
|
41 .padding()
|
|
42 .background(
|
|
43 Circle()
|
6
|
44 .foregroundColor(.white)
|
4
|
45 )
|
|
46 }
|
0
|
47 }
|
|
48 .font(.title2)
|
3
|
49 .scaleEffect(game.scoreScaleAmount)
|
0
|
50 .frame(maxWidth: .infinity, alignment: .center)
|
|
51
|
|
52 Group {
|
|
53 Button {
|
3
|
54 game.showingBuyLivesView = true
|
0
|
55 } label: {
|
|
56 HStack {
|
|
57 Image(systemName: "heart.fill")
|
3
|
58 Text("\(game.userLives)")
|
0
|
59 }
|
6
|
60 .font(.headline)
|
|
61 .foregroundColor(color)
|
0
|
62 .padding(10)
|
|
63 .background(
|
|
64 Capsule()
|
6
|
65 .foregroundColor(.white)
|
0
|
66 )
|
3
|
67 .scaleEffect(game.livesScaleAmount)
|
0
|
68 }
|
|
69 }
|
|
70 .font(.headline)
|
|
71 .frame(maxWidth: .infinity, alignment: .trailing)
|
|
72 }
|
|
73 }
|
|
74 }
|
|
75
|
|
76 struct GameToolbar_Previews: PreviewProvider {
|
|
77 static var previews: some View {
|
|
78 ZStack {
|
|
79 LinearGradient(gradient: .main, startPoint: .top, endPoint: .bottom)
|
|
80 .ignoresSafeArea()
|
|
81
|
|
82 GeometryReader { geo in
|
|
83 VStack {
|
6
|
84 GameToolbar(game: CountryGame(), color: .mayaBlue)
|
0
|
85
|
|
86 Spacer()
|
|
87 }
|
|
88 .padding()
|
|
89 }
|
|
90 }
|
|
91 }
|
|
92 }
|