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
// SPDX-License-Identifier: AGPL-3.0-or-later
17
// SPDX-FileCopyrightText: 2025 David Campbell <david@hnefatafl.org>
18

            
19
use std::{ops::Not, sync::mpsc};
20

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

            
37
use crate::tabs::TabId;
38

            
39
#[derive(Clone, Copy, Debug, Default, Deserialize, Serialize)]
40
pub(crate) enum Coordinates {
41
    Hide,
42
    #[default]
43
    Show,
44
}
45

            
46
impl Not for Coordinates {
47
    type Output = Coordinates;
48

            
49
    fn not(self) -> Self::Output {
50
        match self {
51
            Self::Hide => Self::Show,
52
            Self::Show => Self::Hide,
53
        }
54
    }
55
}
56

            
57
impl From<bool> for Coordinates {
58
    fn from(value: bool) -> Self {
59
        if value { Self::Show } else { Self::Hide }
60
    }
61
}
62

            
63
impl From<Coordinates> for bool {
64
    fn from(coordinates: Coordinates) -> Self {
65
        match coordinates {
66
            Coordinates::Show => true,
67
            Coordinates::Hide => false,
68
        }
69
    }
70
}
71

            
72
#[derive(Clone, Debug)]
73
pub(crate) enum JoinGame {
74
    Cancel,
75
    Join,
76
    None,
77
    Resume,
78
    Watch,
79
}
80

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

            
205
#[derive(Clone, Debug)]
206
pub(crate) enum Move {
207
    From,
208
    To,
209
    Revert,
210
    None,
211
}
212

            
213
#[derive(Clone, Debug, Default, Eq, PartialEq)]
214
pub(crate) enum Screen {
215
    EmailEveryone,
216
    #[default]
217
    Login,
218
    Game,
219
    GameReview,
220
    Games,
221
}
222

            
223
#[derive(Clone, Debug, Default, Eq, PartialEq)]
224
pub(crate) enum Size {
225
    Tiny,
226
    TinyWide,
227
    #[default]
228
    Small,
229
    Medium,
230
    Large,
231
    Giant,
232
}
233

            
234
#[derive(Clone, Debug, Default, Eq, PartialEq)]
235
pub(crate) enum SortBy {
236
    Name,
237
    #[default]
238
    Rating,
239
}
240

            
241
#[derive(Clone, Debug, Eq, PartialEq)]
242
pub(crate) enum State {
243
    Challenger,
244
    Creator,
245
    CreatorOnly,
246
    Spectator,
247
}
248

            
249
#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
250
pub(crate) enum Theme {
251
    #[default]
252
    Dark,
253
    Light,
254
    Tol,
255
}