1
// This file is part of hnefatafl-copenhagen.
2
//
3
// hnefatafl-copenhagen is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU Affero General Public License as published by
5
// the Free Software Foundation, either version 3 of the License, or
6
// (at your option) any later version.
7
//
8
// hnefatafl-copenhagen is distributed in the hope that it will be useful,
9
// but WITHOUT ANY WARRANTY; without even the implied warranty of
10
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
// GNU Affero General Public License for more details.
12
//
13
// You should have received a copy of the GNU Affero General Public License
14
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
15

            
16
use std::{ops::Not, sync::mpsc};
17

            
18
use hnefatafl_copenhagen::{
19
    Id,
20
    ai::GenerateMove,
21
    board::BoardSize,
22
    draw::Draw,
23
    locale::Locale,
24
    play::Vertex,
25
    role::Role,
26
    server_game::ArchivedGame,
27
    time::TimeEnum,
28
    tree::{Node, Tree},
29
};
30
use iced::widget::text_editor;
31
use serde::{Deserialize, Serialize};
32

            
33
#[derive(Clone, Copy, Debug, Default, Deserialize, Serialize)]
34
pub(crate) enum Coordinates {
35
    Hide,
36
    #[default]
37
    Show,
38
}
39

            
40
impl Not for Coordinates {
41
    type Output = Coordinates;
42

            
43
    fn not(self) -> Self::Output {
44
        match self {
45
            Self::Hide => Self::Show,
46
            Self::Show => Self::Hide,
47
        }
48
    }
49
}
50

            
51
impl From<bool> for Coordinates {
52
    fn from(value: bool) -> Self {
53
        if value { Self::Show } else { Self::Hide }
54
    }
55
}
56

            
57
impl From<Coordinates> for bool {
58
    fn from(coordinates: Coordinates) -> Self {
59
        match coordinates {
60
            Coordinates::Show => true,
61
            Coordinates::Hide => false,
62
        }
63
    }
64
}
65

            
66
#[derive(Clone, Debug)]
67
pub(crate) enum JoinGame {
68
    Cancel,
69
    Join,
70
    None,
71
    Resume,
72
    Watch,
73
}
74

            
75
#[derive(Clone, Debug, Eq, PartialEq)]
76
pub(crate) enum LoggedIn {
77
    No,
78
    None,
79
    Yes,
80
}
81

            
82
#[derive(Clone, Debug)]
83
pub(crate) enum Message {
84
    AccountSettings,
85
    ArchivedGames(Vec<ArchivedGame>),
86
    ArchivedGamesGet,
87
    ArchivedGameSelected(ArchivedGame),
88
    BoardSizeSelected(BoardSize),
89
    CancelGame(Id),
90
    ChangeTheme(Theme),
91
    ConnectedTo(String),
92
    Coordinates(bool),
93
    DeleteAccount,
94
    EmailEveryone,
95
    EmailReset,
96
    EstimateScore,
97
    EstimateScoreConnected(mpsc::Sender<Tree>),
98
    EstimateScoreDisplay((Node, GenerateMove)),
99
    Exit,
100
    FocusPrevious,
101
    FocusNext,
102
    GameAccept(Id),
103
    GameCancel(Id),
104
    GameDecline(Id),
105
    GameJoin(Id),
106
    GameNew,
107
    GameResume(Id),
108
    GameSubmit,
109
    GameWatch(Id),
110
    HeatMap(bool),
111
    Leave,
112
    LeaveSoft,
113
    LocaleSelected(Locale),
114
    MyGamesOnly(bool),
115
    OpenUrl(String),
116
    PasswordChanged(String),
117
    PasswordSave(bool),
118
    PasswordShow(bool),
119
    PlayDraw,
120
    PlayDrawDecision(Draw),
121
    PlayMoveFrom(Vertex),
122
    PlayMoveTo(Vertex),
123
    PlayMoveRevert,
124
    PlayResign,
125
    PressEnter,
126
    PressA(bool),
127
    PressB(bool),
128
    PressC(bool),
129
    PressD(bool),
130
    PressE(bool),
131
    PressF(bool),
132
    PressG(bool),
133
    PressH(bool),
134
    PressI(bool),
135
    PressJ(bool),
136
    PressK(bool),
137
    PressL(bool),
138
    PressM(bool),
139
    PressN(bool),
140
    PressO(bool),
141
    PressP(bool),
142
    PressQ(bool),
143
    PressR(bool),
144
    PressS(bool),
145
    PressT(bool),
146
    PressU(bool),
147
    PressV(bool),
148
    PressW(bool),
149
    PressX(bool),
150
    PressY(bool),
151
    PressZ(bool),
152
    Press1,
153
    Press2,
154
    Press3,
155
    Press4,
156
    Press5,
157
    Press6,
158
    Press7,
159
    Press8,
160
    Press9,
161
    Press0,
162
    SoundMuted(bool),
163
    RatedSelected(bool),
164
    ResetPassword,
165
    ReviewGame,
166
    ReviewGameBackward,
167
    ReviewGameBackwardAll,
168
    ReviewGameChildNext,
169
    ReviewGameForward,
170
    ReviewGameForwardAll,
171
    RoleSelected(Role),
172
    ServerShutdown,
173
    StreamConnected(mpsc::Sender<String>),
174
    TcpDisconnect,
175
    TextChanged(String),
176
    TextEdit(text_editor::Action),
177
    TextReceived(String),
178
    TextSend,
179
    TextSendEmail,
180
    TextSendEmailCode,
181
    TextSendCreateAccount,
182
    TextSendLogin,
183
    Tick,
184
    Time(TimeEnum),
185
    Tournament,
186
    TournamentJoin,
187
    TournamentLeave,
188
    TournamentStart,
189
    TournamentDelete,
190
    TournamentTreeDelete,
191
    Users,
192
    UsersSortedBy(SortBy),
193
    WindowResized((f32, f32)),
194
}
195

            
196
#[derive(Clone, Debug)]
197
pub(crate) enum Move {
198
    From,
199
    To,
200
    Revert,
201
    None,
202
}
203

            
204
#[derive(Clone, Debug, Default, Eq, PartialEq)]
205
pub(crate) enum Screen {
206
    AccountSettings,
207
    EmailEveryone,
208
    #[default]
209
    Login,
210
    Game,
211
    GameNew,
212
    GameReview,
213
    Games,
214
    Tournament,
215
    Users,
216
}
217

            
218
#[derive(Clone, Debug, Default, Eq, PartialEq)]
219
pub(crate) enum Size {
220
    Tiny,
221
    TinyWide,
222
    #[default]
223
    Small,
224
    Medium,
225
    Large,
226
    Giant,
227
}
228

            
229
#[derive(Clone, Debug, Default, Eq, PartialEq)]
230
pub(crate) enum SortBy {
231
    Name,
232
    #[default]
233
    Rating,
234
}
235

            
236
#[derive(Clone, Debug, Eq, PartialEq)]
237
pub(crate) enum State {
238
    Challenger,
239
    Creator,
240
    CreatorOnly,
241
    Spectator,
242
}
243

            
244
#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
245
pub(crate) enum Theme {
246
    #[default]
247
    Dark,
248
    Light,
249
    Tol,
250
}