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
|
#include "courtroom.h"
#include "lobby.h"
#include "debug_functions.h"
#include "file_functions.h"
#include "hardware_functions.h"
void Courtroom::construct_char_select()
{
this->setWindowFlags( (this->windowFlags() | Qt::CustomizeWindowHint) & ~Qt::WindowMaximizeButtonHint);
ui_char_select_background = new AOImage(this, ao_app);
ui_char_list = new QTreeWidget(ui_char_select_background);
ui_char_list->setColumnCount(2);
ui_char_list->setHeaderLabels({"Name", "ID"});
ui_char_list->setHeaderHidden(true);
ui_char_list->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
ui_char_list->hideColumn(1);
ui_char_list->setDropIndicatorShown(true);
set_size_and_pos(ui_char_list, "char_list");
ui_char_buttons = new QWidget(ui_char_select_background);
ui_selector = new AOImage(ui_char_select_background, ao_app);
ui_selector->setAttribute(Qt::WA_TransparentForMouseEvents);
ui_selector->resize(62, 62);
ui_back_to_lobby = new AOButton(ui_char_select_background, ao_app);
ui_char_password = new QLineEdit(ui_char_select_background);
ui_char_password->setPlaceholderText(tr("Password"));
ui_char_select_left = new AOButton(ui_char_select_background, ao_app);
ui_char_select_right = new AOButton(ui_char_select_background, ao_app);
ui_spectator = new AOButton(ui_char_select_background, ao_app);
ui_spectator->setText(tr("Spectator"));
ui_char_search = new QLineEdit(ui_char_select_background);
ui_char_search->setPlaceholderText(tr("Search"));
ui_char_search->setFocus();
set_size_and_pos(ui_char_search, "char_search");
ui_char_passworded = new QCheckBox(ui_char_select_background);
ui_char_passworded->setText(tr("Passworded"));
set_size_and_pos(ui_char_passworded, "char_passworded");
ui_char_taken = new QCheckBox(ui_char_select_background);
ui_char_taken->setText(tr("Taken"));
set_size_and_pos(ui_char_taken, "char_taken");
ui_char_taken->setChecked(true);
ui_char_passworded->setChecked(true);
set_size_and_pos(ui_char_buttons, "char_buttons");
connect(ui_char_list, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)),
this, SLOT(on_char_list_double_clicked(QTreeWidgetItem *, int)));
connect(ui_back_to_lobby, SIGNAL(clicked()), this,
SLOT(on_back_to_lobby_clicked()));
connect(ui_char_select_left, SIGNAL(clicked()), this,
SLOT(on_char_select_left_clicked()));
connect(ui_char_select_right, SIGNAL(clicked()), this,
SLOT(on_char_select_right_clicked()));
connect(ui_spectator, SIGNAL(clicked()), this, SLOT(on_spectator_clicked()));
connect(ui_char_search, SIGNAL(textEdited(const QString &)), this,
SLOT(on_char_search_changed()));
connect(ui_char_passworded, SIGNAL(stateChanged(int)), this,
SLOT(on_char_passworded_clicked()));
connect(ui_char_taken, SIGNAL(stateChanged(int)), this,
SLOT(on_char_taken_clicked()));
truncate_label_text(ui_char_taken, "char_taken");
truncate_label_text(ui_char_passworded, "char_passworded");
}
void Courtroom::set_char_select()
{
QString filename = "courtroom_design.ini";
pos_size_type f_charselect =
ao_app->get_element_dimensions("char_select", filename);
if (f_charselect.width < 0 || f_charselect.height < 0) {
qDebug() << "W: did not find char_select width or height in "
"courtroom_design.ini!";
this->setFixedSize(714, 668);
}
else
this->setFixedSize(f_charselect.width, f_charselect.height);
ui_char_select_background->resize(f_charselect.width, f_charselect.height);
ui_char_select_background->set_image("charselect_background");
filter_character_list();
ui_char_search->setFocus();
}
void Courtroom::set_char_select_page()
{
ui_char_select_background->show();
ui_char_select_left->hide();
ui_char_select_right->hide();
for (AOCharButton *i_button : ui_char_button_list) {
i_button->reset();
i_button->hide();
i_button->move(0, 0);
}
int total_pages = ui_char_button_list_filtered.size() / max_chars_on_page;
int chars_on_page = 0;
if (ui_char_button_list_filtered.size() % max_chars_on_page != 0) {
++total_pages;
// i. e. not on the last page
if (total_pages > current_char_page + 1)
chars_on_page = max_chars_on_page;
else
chars_on_page = ui_char_button_list_filtered.size() % max_chars_on_page;
}
else
chars_on_page = max_chars_on_page;
if (total_pages > current_char_page + 1)
ui_char_select_right->show();
if (current_char_page > 0)
ui_char_select_left->show();
put_button_in_place(current_char_page * max_chars_on_page, chars_on_page);
}
void Courtroom::on_char_list_double_clicked(QTreeWidgetItem *p_item, int column)
{
UNUSED(column);
int cid = p_item->text(1).toInt();
if (cid == -1 && !p_item->isExpanded()) {
p_item->setExpanded(true);
return;
}
else if (cid == -1) {
p_item->setExpanded(false);
return;
}
char_clicked(cid);
}
void Courtroom::char_clicked(int n_char)
{
if (n_char != -1)
{
QString char_ini_path =
ao_app->get_character_path(char_list.at(n_char).name, "char.ini");
qDebug() << "char_ini_path" << char_ini_path;
if (!file_exists(char_ini_path)) {
call_error("Could not find " + char_ini_path);
return;
}
}
if (n_char != m_cid) {
ao_app->send_server_packet(
new AOPacket("PW#" + ui_char_password->text() + "#%"));
ao_app->send_server_packet(
new AOPacket("CC#" + QString::number(ao_app->s_pv) + "#" +
QString::number(n_char) + "#" + get_hdid() + "#%"));
}
else
update_character(n_char);
if (n_char != -1)
ui_ic_chat_name->setPlaceholderText(char_list.at(n_char).name);
}
void Courtroom::put_button_in_place(int starting, int chars_on_this_page)
{
if (ui_char_button_list_filtered.size() == 0)
return;
QPoint f_spacing =
ao_app->get_button_spacing("char_button_spacing", "courtroom_design.ini");
int x_spacing = f_spacing.x();
int x_mod_count = 0;
int y_spacing = f_spacing.y();
int y_mod_count = 0;
char_columns =
((ui_char_buttons->width() - button_width) / (x_spacing + button_width)) +
1;
char_rows = ((ui_char_buttons->height() - button_height) /
(y_spacing + button_height)) +
1;
max_chars_on_page = char_columns * char_rows;
int startout = starting;
for (int n = starting; n < startout + chars_on_this_page; ++n) {
int x_pos = (button_width + x_spacing) * x_mod_count;
int y_pos = (button_height + y_spacing) * y_mod_count;
ui_char_button_list_filtered.at(n)->move(x_pos, y_pos);
ui_char_button_list_filtered.at(n)->show();
ui_char_button_list_filtered.at(n)->apply_taken_image();
++x_mod_count;
if (x_mod_count == char_columns) {
++y_mod_count;
x_mod_count = 0;
}
}
}
void Courtroom::character_loading_finished()
{
// Zeroeth, we'll clear any leftover characters from previous server visits.
ao_app->generated_chars = 0;
if (ui_char_button_list.size() > 0) {
foreach (AOCharButton *item, ui_char_button_list) {
delete item;
}
ui_char_button_list.clear();
}
// First, we'll make all the character buttons in the very beginning.
// We also hide them all, so they can't be accidentally clicked.
// Later on, we'll be revealing buttons as we need them.
for (int n = 0; n < char_list.size(); n++) {
AOCharButton *char_button =
new AOCharButton(ui_char_buttons, ao_app, 0, 0, char_list.at(n).taken);
char_button->reset();
char_button->hide();
char_button->set_image(char_list.at(n).name);
char_button->setToolTip(char_list.at(n).name);
ui_char_button_list.append(char_button);
QString char_category = ao_app->get_category(char_list.at(n).name);
QList<QTreeWidgetItem*> matching_list = ui_char_list->findItems(char_category, Qt::MatchFixedString, 0);
// create the character tree item
QTreeWidgetItem *treeItem = new QTreeWidgetItem();
treeItem->setText(0, char_list.at(n).name);
treeItem->setIcon(0, QIcon(ao_app->get_static_image_suffix(
ao_app->get_character_path(char_list.at(n).name, "char_icon"))));
treeItem->setText(1, QString::number(n));
// category logic
QTreeWidgetItem *category;
if (char_category == "") // no category
ui_char_list->addTopLevelItem(treeItem);
else if (!matching_list.isEmpty()) { // our category already exists
category = matching_list[0];
category->addChild(treeItem);
}
else { // we need to make a new category
category = new QTreeWidgetItem();
category->setText(0, char_category);
category->setText(1, "-1");
category->setChildIndicatorPolicy(QTreeWidgetItem::DontShowIndicatorWhenChildless);
ui_char_list->insertTopLevelItem(0, category);
category->addChild(treeItem);
}
connect(char_button, &AOCharButton::clicked,
[this, n]() { this->char_clicked(n); });
// This part here serves as a way of showing to the player that the game is
// still running, it is just loading the pictures of the characters.
if (ao_app->lobby_constructed) {
ao_app->generated_chars++;
int total_loading_size = ao_app->char_list_size * 2 +
ao_app->evidence_list_size +
ao_app->music_list_size;
int loading_value =
int(((ao_app->loaded_chars + ao_app->generated_chars +
ao_app->loaded_music + ao_app->loaded_evidence) /
static_cast<double>(total_loading_size)) *
100);
ao_app->w_lobby->set_loading_value(loading_value);
ao_app->w_lobby->set_loading_text(
tr("Generating chars:\n%1/%2")
.arg(QString::number(ao_app->generated_chars))
.arg(QString::number(ao_app->char_list_size)));
}
}
ui_char_list->expandAll();
filter_character_list();
}
void Courtroom::filter_character_list()
{
ui_char_button_list_filtered.clear();
for (int i = 0; i < char_list.size(); i++) {
AOCharButton *current_char = ui_char_button_list.at(i);
QTreeWidgetItem* current_char_list_item = ui_char_list->findItems(QString::number(i), Qt::MatchExactly | Qt::MatchRecursive, 1)[0];
// It seems passwording characters is unimplemented yet?
// Until then, this will stay here, I suppose.
// if (ui_char_passworded->isChecked() && character_is_passworded??)
// continue;
if (!ui_char_taken->isChecked() && char_list.at(i).taken) {
current_char_list_item->setHidden(true);
continue;
}
if (!char_list.at(i).name.contains(ui_char_search->text(),
Qt::CaseInsensitive)) {
current_char_list_item->setHidden(true);
continue;
}
// We only really need to update the fact that a character is taken
// for the buttons that actually appear.
// You'd also update the passwordedness and etc. here later.
current_char->reset();
current_char_list_item->setHidden(false);
current_char->set_taken(char_list.at(i).taken);
current_char_list_item->setText(0, char_list.at(i).name);
// reset disabled
current_char_list_item->setDisabled(false);
if (char_list.at(i).taken) // woops, we are taken
current_char_list_item->setDisabled(true);
ui_char_button_list_filtered.append(current_char);
}
current_char_page = 0;
set_char_select_page();
}
void Courtroom::on_char_search_changed() { filter_character_list(); }
void Courtroom::on_char_passworded_clicked() { filter_character_list(); }
void Courtroom::on_char_taken_clicked() { filter_character_list(); }
|