Mercurial > public > geoquiz
annotate GeoQuiz/Components/GameToolbarHelper.swift @ 11:039b26a99a48
implementing RevenueCat
author | Dennis C. M. <dennis@denniscm.com> |
---|---|
date | Sun, 09 Oct 2022 17:02:34 +0200 |
parents | a793f33f05fb |
children | f140bb277c96 |
rev | line source |
---|---|
0 | 1 // |
10
a793f33f05fb
refactor code and fix layout
Dennis C. M. <dennis@denniscm.com>
parents:
8
diff
changeset
|
2 // GameToolbarHelper.swift |
0 | 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() | |
10
a793f33f05fb
refactor code and fix layout
Dennis C. M. <dennis@denniscm.com>
parents:
8
diff
changeset
|
27 .foregroundColor(.white) |
0 | 28 ) |
29 } | |
30 } | |
31 .font(.headline) | |
32 .frame(maxWidth: .infinity, alignment: .leading) | |
33 | |
34 Group { | |
7 | 35 Text("\(game.userScore)") |
36 .font(.title.bold()) | |
37 .foregroundColor(color) | |
38 .padding() | |
39 .background( | |
8 | 40 Group { |
41 if game.userScore < 1000 { | |
42 Circle() | |
43 } else { | |
44 Capsule() | |
45 } | |
46 } | |
10
a793f33f05fb
refactor code and fix layout
Dennis C. M. <dennis@denniscm.com>
parents:
8
diff
changeset
|
47 .foregroundColor(.white) |
7 | 48 ) |
0 | 49 } |
50 .font(.title2) | |
3 | 51 .scaleEffect(game.scoreScaleAmount) |
0 | 52 .frame(maxWidth: .infinity, alignment: .center) |
53 | |
54 Group { | |
7 | 55 HStack { |
56 Image(systemName: "heart.fill") | |
57 Text("\(game.userLives)") | |
0 | 58 } |
7 | 59 .font(.headline) |
60 .foregroundColor(color) | |
61 .padding(10) | |
62 .background( | |
63 Capsule() | |
10
a793f33f05fb
refactor code and fix layout
Dennis C. M. <dennis@denniscm.com>
parents:
8
diff
changeset
|
64 .foregroundColor(.white) |
7 | 65 ) |
66 .scaleEffect(game.livesScaleAmount) | |
0 | 67 } |
68 .font(.headline) | |
69 .frame(maxWidth: .infinity, alignment: .trailing) | |
70 } | |
71 } | |
72 } | |
73 | |
74 struct GameToolbar_Previews: PreviewProvider { | |
75 static var previews: some View { | |
76 ZStack { | |
77 LinearGradient(gradient: .main, startPoint: .top, endPoint: .bottom) | |
78 .ignoresSafeArea() | |
79 | |
80 GeometryReader { geo in | |
81 VStack { | |
6 | 82 GameToolbar(game: CountryGame(), color: .mayaBlue) |
0 | 83 |
84 Spacer() | |
85 } | |
86 .padding() | |
87 } | |
88 } | |
89 } | |
90 } |