126 lines
3.4 KiB
C++
126 lines
3.4 KiB
C++
#include "courtroom.h"
|
|
|
|
#include <QDebug>
|
|
|
|
void Courtroom::construct_char_select()
|
|
{
|
|
ui_char_select_background = new AOImage(this, ao_app);
|
|
|
|
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_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);
|
|
|
|
//constructing character button grid
|
|
|
|
const int x_modifier{67};
|
|
int x_mod_count{0};
|
|
|
|
const int y_modifier{67};
|
|
int y_mod_count{0};
|
|
|
|
for (int n = 0 ; n < 90 ; ++n)
|
|
{
|
|
int x_pos = (x_modifier * x_mod_count);
|
|
int y_pos = (y_modifier * y_mod_count);
|
|
|
|
ui_char_button_list.append(new AOCharButton(ui_char_buttons, ao_app, x_pos, y_pos));
|
|
|
|
connect(ui_char_button_list.at(n), SIGNAL(clicked()), char_button_mapper, SLOT(map())) ;
|
|
char_button_mapper->setMapping (ui_char_button_list.at(n), n) ;
|
|
|
|
++x_mod_count;
|
|
|
|
//if char number is divisible by ten with rest 9 then the next charicon should start on a new line
|
|
if (n % 10 == 9 && n != 0)
|
|
{
|
|
++y_mod_count;
|
|
x_mod_count = 0;
|
|
}
|
|
}
|
|
|
|
connect (char_button_mapper, SIGNAL(mapped(int)), this, SLOT(char_clicked(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()));
|
|
}
|
|
|
|
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 courtroom width or height in courtroom_design.ini!";
|
|
this->resize(714, 668);
|
|
}
|
|
else
|
|
this->resize(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.png");
|
|
}
|
|
|
|
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->hide();
|
|
|
|
int total_pages = char_list.size() / 90;
|
|
int chars_on_page = 0;
|
|
|
|
if (char_list.size() % 90 != 0)
|
|
{
|
|
++total_pages;
|
|
//i. e. not on the last page
|
|
if (total_pages > current_char_page + 1)
|
|
chars_on_page = 90;
|
|
else
|
|
chars_on_page = char_list.size() % 90;
|
|
|
|
}
|
|
else
|
|
chars_on_page = 90;
|
|
|
|
if (total_pages > current_char_page + 1)
|
|
ui_char_select_right->show();
|
|
|
|
if (current_char_page > 0)
|
|
ui_char_select_left->show();
|
|
|
|
for (int n_button = 0 ; n_button < chars_on_page ; ++n_button)
|
|
{
|
|
int n_real_char = n_button + current_char_page * 90;
|
|
AOCharButton *f_button = ui_char_button_list.at(n_button);
|
|
|
|
f_button->reset();
|
|
f_button->set_image(char_list.at(n_real_char).name);
|
|
f_button->show();
|
|
|
|
if (char_list.at(n_real_char).taken)
|
|
f_button->set_taken();
|
|
}
|
|
|
|
}
|
|
|