This repository has been archived by the owner on Jun 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lobby.cpp
374 lines (287 loc) · 9.86 KB
/
lobby.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
//////////////////////////////////////////////////
//
// This work is licensed under the MIT license.
//
// You are free to copy, modify and distribute
// this work freely given that proper attribution
// is supplied and the author is not held liable.
// See LICENSE for details.
//
// Copyright (c) 2016-2018 David "OmniTroid" Skoland
//
//////////////////////////////////////////////////
#include "lobby.h"
#include "aoapplication.h"
#include "networkmanager.h"
#include "aosfxplayer.h"
#include "misc_functions.h"
#include <QDebug>
#include <QScrollBar>
Lobby::Lobby(AOApplication *p_ao_app) : QMainWindow()
{
ao_app = p_ao_app;
this->setWindowTitle("Attorney Online 2");
ui_background = new AOImage(this, ao_app);
ui_public_servers = new AOButton(this, ao_app);
ui_favorites = new AOButton(this, ao_app);
ui_refresh = new AOButton(this, ao_app);
ui_add_to_fav = new AOButton(this, ao_app);
ui_connect = new AOButton(this, ao_app);
ui_version = new QLabel(this);
ui_about = new AOButton(this, ao_app);
ui_server_list = new QListWidget(this);
ui_player_count = new QLabel(this);
ui_description = new AOTextArea(this);
ui_chatbox = new AOTextArea(this);
ui_chatbox->setOpenExternalLinks(true);
ui_chatname = new QLineEdit(this);
ui_chatname->setPlaceholderText("Name");
ui_chatmessage = new QLineEdit(this);
ui_loading_background = new AOImage(this, ao_app);
ui_loading_text = new QTextEdit(ui_loading_background);
ui_progress_bar = new QProgressBar(ui_loading_background);
ui_progress_bar->setMinimum(0);
ui_progress_bar->setMaximum(100);
ui_progress_bar->setStyleSheet("QProgressBar{ color: white; }");
ui_cancel = new AOButton(ui_loading_background, ao_app);
connect(ui_public_servers, SIGNAL(clicked()), this, SLOT(on_public_servers_clicked()));
connect(ui_favorites, SIGNAL(clicked()), this, SLOT(on_favorites_clicked()));
connect(ui_refresh, SIGNAL(pressed()), this, SLOT(on_refresh_pressed()));
connect(ui_refresh, SIGNAL(released()), this, SLOT(on_refresh_released()));
connect(ui_add_to_fav, SIGNAL(pressed()), this, SLOT(on_add_to_fav_pressed()));
connect(ui_add_to_fav, SIGNAL(released()), this, SLOT(on_add_to_fav_released()));
connect(ui_connect, SIGNAL(pressed()), this, SLOT(on_connect_pressed()));
connect(ui_connect, SIGNAL(released()), this, SLOT(on_connect_released()));
connect(ui_about, SIGNAL(clicked()), this, SLOT(on_about_clicked()));
connect(ui_server_list, SIGNAL(clicked(QModelIndex)), this, SLOT(on_server_list_clicked(QModelIndex)));
connect(ui_chatmessage, SIGNAL(returnPressed()), this, SLOT(on_chatfield_return_pressed()));
connect(ui_cancel, SIGNAL(clicked()), ao_app, SLOT(loading_cancelled()));
set_widgets();
}
//sets images, position and size
void Lobby::set_widgets()
{
ao_app->reload_theme();
QString filename = "lobby_design.ini";
pos_size_type f_lobby = ao_app->get_element_dimensions("lobby", filename);
if (f_lobby.width < 0 || f_lobby.height < 0)
{
qDebug() << "W: did not find lobby width or height in " << filename;
this->resize(517, 666);
}
else
{
this->resize(f_lobby.width, f_lobby.height);
}
set_size_and_pos(ui_background, "lobby");
ui_background->set_image("lobbybackground.png");
set_size_and_pos(ui_public_servers, "public_servers");
ui_public_servers->set_image("publicservers_selected.png");
set_size_and_pos(ui_favorites, "favorites");
ui_favorites->set_image("favorites.png");
set_size_and_pos(ui_refresh, "refresh");
ui_refresh->set_image("refresh.png");
set_size_and_pos(ui_add_to_fav, "add_to_fav");
ui_add_to_fav->set_image("addtofav.png");
set_size_and_pos(ui_connect, "connect");
ui_connect->set_image("connect.png");
set_size_and_pos(ui_version, "version");
ui_version->setText("Version: " + ao_app->get_version_string());
set_size_and_pos(ui_about, "about");
ui_about->set_image("about.png");
set_size_and_pos(ui_server_list, "server_list");
ui_server_list->setStyleSheet("background-color: rgba(0, 0, 0, 0);"
"font: bold;");
set_size_and_pos(ui_player_count, "player_count");
ui_player_count->setText("Offline");
ui_player_count->setStyleSheet("font: bold;"
"color: white;"
"qproperty-alignment: AlignCenter;");
set_size_and_pos(ui_description, "description");
ui_description->setReadOnly(true);
ui_description->setStyleSheet("background-color: rgba(0, 0, 0, 0);"
"color: white;");
set_size_and_pos(ui_chatbox, "chatbox");
ui_chatbox->setReadOnly(true);
ui_chatbox->setStyleSheet("QTextBrowser{background-color: rgba(0, 0, 0, 0);}");
set_size_and_pos(ui_chatname, "chatname");
ui_chatname->setStyleSheet("background-color: rgba(0, 0, 0, 0);"
"selection-background-color: rgba(0, 0, 0, 0);");
set_size_and_pos(ui_chatmessage, "chatmessage");
ui_chatmessage->setStyleSheet("background-color: rgba(0, 0, 0, 0);"
"selection-background-color: rgba(0, 0, 0, 0);");
ui_loading_background->resize(this->width(), this->height());
ui_loading_background->set_image("loadingbackground.png");
set_size_and_pos(ui_loading_text, "loading_label");
ui_loading_text->setFont(QFont("Arial", 20, QFont::Bold));
ui_loading_text->setReadOnly(true);
ui_loading_text->setAlignment(Qt::AlignCenter);
ui_loading_text->setFrameStyle(QFrame::NoFrame);
ui_loading_text->setStyleSheet("background-color: rgba(0, 0, 0, 0);"
"color: rgba(255, 128, 0, 255);");
ui_loading_text->append("Loading");
set_size_and_pos(ui_progress_bar, "progress_bar");
set_size_and_pos(ui_cancel, "cancel");
ui_cancel->setText("Cancel");
ui_loading_background->hide();
}
void Lobby::set_size_and_pos(QWidget *p_widget, QString p_identifier)
{
QString filename = "lobby_design.ini";
pos_size_type design_ini_result = ao_app->get_element_dimensions(p_identifier, filename);
if (design_ini_result.width < 0 || design_ini_result.height < 0)
{
qDebug() << "W: could not find " << p_identifier << " in " << filename;
p_widget->hide();
}
else
{
p_widget->move(design_ini_result.x, design_ini_result.y);
p_widget->resize(design_ini_result.width, design_ini_result.height);
}
}
void Lobby::set_loading_text(QString p_text)
{
ui_loading_text->clear();
ui_loading_text->setAlignment(Qt::AlignCenter);
ui_loading_text->append(p_text);
}
QString Lobby::get_chatlog()
{
QString return_value = ui_chatbox->toPlainText();
return return_value;
}
int Lobby::get_selected_server()
{
return ui_server_list->currentRow();
}
void Lobby::set_loading_value(int p_value)
{
ui_progress_bar->setValue(p_value);
}
void Lobby::on_public_servers_clicked()
{
ui_public_servers->set_image("publicservers_selected.png");
ui_favorites->set_image("favorites.png");
list_servers();
public_servers_selected = true;
}
void Lobby::on_favorites_clicked()
{
ui_favorites->set_image("favorites_selected.png");
ui_public_servers->set_image("publicservers.png");
ao_app->set_favorite_list();
//ao_app->favorite_list = read_serverlist_txt();
list_favorites();
public_servers_selected = false;
}
void Lobby::on_refresh_pressed()
{
ui_refresh->set_image("refresh_pressed.png");
}
void Lobby::on_refresh_released()
{
ui_refresh->set_image("refresh.png");
AOPacket *f_packet = new AOPacket("ALL#%");
ao_app->send_ms_packet(f_packet);
}
void Lobby::on_add_to_fav_pressed()
{
ui_add_to_fav->set_image("addtofav_pressed.png");
}
void Lobby::on_add_to_fav_released()
{
ui_add_to_fav->set_image("addtofav.png");
//you cant add favorites from favorites m8
if (!public_servers_selected)
return;
ao_app->add_favorite_server(ui_server_list->currentRow());
}
void Lobby::on_connect_pressed()
{
ui_connect->set_image("connect_pressed.png");
}
void Lobby::on_connect_released()
{
ui_connect->set_image("connect.png");
AOPacket *f_packet;
f_packet = new AOPacket("askchaa#%");
ao_app->send_server_packet(f_packet);
}
void Lobby::on_about_clicked()
{
call_notice("Development:\n"
"OmniTroid\n\n"
"UI and logo design:\n"
"Ruekasu\n\n"
"Copyright (c) David \"OmniTroid\" Skoland 2016-2018\n\n"
"https://github.com/OmniTroid/attorney_online");
}
void Lobby::on_server_list_clicked(QModelIndex p_model)
{
server_type f_server;
int n_server = p_model.row();
if (n_server < 0)
return;
if (public_servers_selected)
{
QVector<server_type> f_server_list = ao_app->get_server_list();
if (n_server >= f_server_list.size())
return;
f_server = f_server_list.at(p_model.row());
}
else
{
if (n_server >= ao_app->get_favorite_list().size())
return;
f_server = ao_app->get_favorite_list().at(p_model.row());
}
ui_description->clear();
ui_description->append(f_server.desc);
ui_description->moveCursor(QTextCursor::Start);
ui_description->ensureCursorVisible();
ui_player_count->setText("Offline");
ao_app->net_manager->connect_to_server(f_server);
}
void Lobby::on_chatfield_return_pressed()
{
//no you can't send empty messages
if (ui_chatname->text() == "" || ui_chatmessage->text() == "")
return;
QString f_header = "CT";
QStringList f_contents{ui_chatname->text(), ui_chatmessage->text()};
AOPacket *f_packet = new AOPacket(f_header, f_contents);
ao_app->send_ms_packet(f_packet);
ui_chatmessage->clear();
}
void Lobby::list_servers()
{
public_servers_selected = true;
ui_favorites->set_image("favorites.png");
ui_public_servers->set_image("publicservers_selected.png");
ui_server_list->clear();
for (server_type i_server : ao_app->get_server_list())
{
ui_server_list->addItem(i_server.name);
}
}
void Lobby::list_favorites()
{
ui_server_list->clear();
for (server_type i_server : ao_app->get_favorite_list())
{
ui_server_list->addItem(i_server.name);
}
}
void Lobby::append_chatmessage(QString f_name, QString f_message)
{
ui_chatbox->append_chatmessage(f_name, f_message);
}
void Lobby::set_player_count(int players_online, int max_players)
{
QString f_string = "Online: " + QString::number(players_online) + "/" + QString::number(max_players);
ui_player_count->setText(f_string);
}
Lobby::~Lobby()
{
}