Mercurial > public > geoquiz
comparison GeoQuiz/Components/GameButtonHelper.swift @ 19:f140bb277c96
refactor code
author | Dennis C. M. <dennis@denniscm.com> |
---|---|
date | Sun, 23 Oct 2022 00:11:38 +0100 |
parents | 039b26a99a48 |
children |
comparison
equal
deleted
inserted
replaced
18:d20cf93c9812 | 19:f140bb277c96 |
---|---|
6 // | 6 // |
7 | 7 |
8 import SwiftUI | 8 import SwiftUI |
9 | 9 |
10 struct GameButton: View { | 10 struct GameButton: View { |
11 let gradient: Gradient | 11 let gameInfo: GameInfo |
12 let level: String | 12 let isActive: Bool |
13 let symbol: String | 13 |
14 let name: String | 14 init(gameType: GameType, isActive: Bool) { |
15 self.gameInfo = GameInfoController.getInfo(for: gameType) | |
16 self.isActive = isActive | |
17 } | |
15 | 18 |
16 var body: some View { | 19 var body: some View { |
17 RoundedRectangle(cornerRadius: 20) | 20 RoundedRectangle(cornerRadius: 20) |
18 .fill( | 21 .fill( |
19 LinearGradient( | 22 LinearGradient( |
20 gradient: gradient, | 23 gradient: gameInfo.gradient, |
21 startPoint: .trailing, endPoint: .leading | 24 startPoint: .trailing, endPoint: .leading |
22 ) | 25 ) |
23 ) | 26 ) |
24 .frame(height: 180) | 27 .frame(height: 180) |
25 .frame(maxWidth: 700) | 28 .frame(maxWidth: 700) |
26 .overlay { | 29 .overlay { |
27 ZStack(alignment: .trailing) { | 30 ZStack(alignment: .trailing) { |
28 VStack(alignment: .leading) { | 31 VStack(alignment: .leading) { |
29 HStack { | 32 HStack { |
30 Image(systemName: symbol) | 33 Image(systemName: isActive ? gameInfo.symbol : "lock.fill") |
31 .font(.headline) | 34 .font(.headline) |
32 .padding(5) | 35 .padding(5) |
33 .background( | 36 .background( |
34 RoundedRectangle(cornerRadius: 5) | 37 RoundedRectangle(cornerRadius: 5) |
35 .stroke(lineWidth: 1.5) | 38 .stroke(lineWidth: 1.5) |
38 Spacer() | 41 Spacer() |
39 } | 42 } |
40 .padding(.bottom) | 43 .padding(.bottom) |
41 | 44 |
42 VStack(alignment: .leading, spacing: 5) { | 45 VStack(alignment: .leading, spacing: 5) { |
43 Text(level) | 46 Text(gameInfo.level) |
44 .font(.callout) | 47 .font(.callout) |
45 | 48 |
46 Text(name) | 49 Text(gameInfo.name) |
47 .font(.title.bold()) | 50 .font(.title.bold()) |
48 } | 51 } |
49 } | 52 } |
50 .foregroundColor(.white) | 53 .foregroundColor(.white) |
51 .padding() | 54 .padding() |
54 } | 57 } |
55 } | 58 } |
56 | 59 |
57 struct GameButton_Previews: PreviewProvider { | 60 struct GameButton_Previews: PreviewProvider { |
58 static var previews: some View { | 61 static var previews: some View { |
59 GameButton( | 62 GameButton(gameType: .guessTheFlag, isActive: false) |
60 gradient: .main, | |
61 level: "Level 1", | |
62 symbol: "flag.fill", | |
63 name: "Guess the flag" | |
64 ) | |
65 } | 63 } |
66 } | 64 } |