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
    ResetPassword,
168
    ReviewGame,
169
    ReviewGameBackward,
170
    ReviewGameBackwardAll,
171
    ReviewGameChildNext,
172
    ReviewGameForward,
173
    ReviewGameForwardAll,
174
    RoleSelected(Role),
175
    ServerShutdown,
176
    StreamConnected(mpsc::Sender<String>),
177
    TabSelected(TabId),
178
    TcpConnectFailed,
179
    TcpDisconnect,
180
    TextChanged(String),
181
    TextEdit(text_editor::Action),
182
    TextReceived(String),
183
    TextSend,
184
    TextSendEmail,
185
    TextSendEmailCode,
186
    TextSendCreateAccount,
187
    TextSendLogin,
188
    Tick,
189
    Time(TimeEnum),
190
    Tournaments,
191
    TournamentJoin,
192
    TournamentLeave,
193
    TournamentStart,
194
    TournamentDelete,
195
    TournamentTreeDelete,
196
    UsersSortedBy(SortBy),
197
    VolumeChanged(u32),
198
    WindowResized((f32, f32)),
199
}
200

            
201
#[derive(Clone, Debug)]
202
pub(crate) enum Move {
203
    From,
204
    To,
205
    Revert,
206
    None,
207
}
208

            
209
#[derive(Clone, Debug, Default, Eq, PartialEq)]
210
pub(crate) enum Screen {
211
    EmailEveryone,
212
    #[default]
213
    Login,
214
    Game,
215
    GameReview,
216
    Games,
217
}
218

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

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

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

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