Mercurial > public > geoquiz
comparison GeoQuiz/Components/GameAlertsModifier.swift @ 10:a793f33f05fb
refactor code and fix layout
author | Dennis C. M. <dennis@denniscm.com> |
---|---|
date | Sat, 08 Oct 2022 21:36:40 +0200 |
parents | GeoQuiz/Helpers/GameAlertsModifier.swift@e09959b4e4a8 |
children | f1967f8cc67b |
comparison
equal
deleted
inserted
replaced
9:3540c7efc216 | 10:a793f33f05fb |
---|---|
1 // | |
2 // GameAlertsModifier.swift | |
3 // GeoQuiz | |
4 // | |
5 // Created by Dennis Concepción Martín on 22/9/22. | |
6 // | |
7 | |
8 import SwiftUI | |
9 | |
10 struct GameAlertsModifier<T: Game>: ViewModifier { | |
11 @ObservedObject var game: T | |
12 @Environment(\.dismiss) var dismiss | |
13 | |
14 func body(content: Content) -> some View { | |
15 content | |
16 .alert(game.alertTitle, isPresented: $game.showingWrongAnswerAlert) { | |
17 Button("Continue", role: .cancel) { | |
18 game.askQuestion { | |
19 game.selector() | |
20 } | |
21 } | |
22 } message: { | |
23 Text(game.alertMessage) | |
24 } | |
25 | |
26 .alert(game.alertTitle, isPresented: $game.showingGameOverAlert) { | |
27 Button("Try again") { | |
28 game.reset { | |
29 game.selector() | |
30 } | |
31 } | |
32 Button("Exit", role: .cancel) { dismiss()} | |
33 } message: { | |
34 Text(game.alertMessage) | |
35 } | |
36 | |
37 .alert(game.alertTitle, isPresented: $game.showingEndGameAlert) { | |
38 Button("Play again") { | |
39 game.reset() { | |
40 game.selector() | |
41 } | |
42 } | |
43 Button("Exit", role: .cancel) { dismiss() } | |
44 } message: { | |
45 Text(game.alertMessage) | |
46 } | |
47 | |
48 .alert("Are you sure?", isPresented: $game.showingExitGameAlert) { | |
49 Button("Exit", role: .destructive) { dismiss() } | |
50 Button("Cancel", role: .cancel) { } | |
51 } message: { | |
52 Text("Progress won't be saved.") | |
53 } | |
54 } | |
55 } |