aboutsummaryrefslogtreecommitdiff
path: root/courtroom.cpp
diff options
context:
space:
mode:
authorDavid Skoland <davidskoland@gmail.com>2017-01-26 16:03:48 +0100
committerDavid Skoland <davidskoland@gmail.com>2017-01-26 16:03:48 +0100
commit5e2ea2b24c2c0151ff8b0354632aa00148e0e6d6 (patch)
tree4373f833ae982e12d072466df971c91e48a628de /courtroom.cpp
parent47ffce5db5220f476e01e88a17dffcb0f5970f7e (diff)
finished charselect and cleaned up some files
Diffstat (limited to 'courtroom.cpp')
-rw-r--r--courtroom.cpp109
1 files changed, 102 insertions, 7 deletions
diff --git a/courtroom.cpp b/courtroom.cpp
index 282c70cd..381d1595 100644
--- a/courtroom.cpp
+++ b/courtroom.cpp
@@ -11,6 +11,8 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow()
{
ao_app = p_ao_app;
+ char_button_mapper = new QSignalMapper(this);
+
ui_background = new AOImage(this, ao_app);
//viewport elements like background, desk, etc.
@@ -91,7 +93,7 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow()
ui_char_select_background = new AOImage(this, ao_app);
- //setting up the grid and positions
+ //constructing character button grid
const int base_x_pos{25};
const int base_y_pos{36};
@@ -103,15 +105,37 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow()
for (int n = 0 ; n < 90 ; ++n)
{
- ui_char_button_list.append(new AOCharButton(ui_char_select_background, ao_app));
+ int x_pos = base_x_pos + (x_modifier * x_mod_count);
+ int y_pos = base_y_pos + (y_modifier * y_mod_count);
+
+ ui_char_button_list.append(new AOCharButton(ui_char_select_background, 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))) ;
+
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);
connect(ui_change_character, SIGNAL(clicked()), this, SLOT(on_change_character_clicked()));
@@ -120,6 +144,9 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow()
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()));
set_widgets();
@@ -256,10 +283,9 @@ void Courtroom::set_widgets()
ui_char_select_background->move(0, 0);
ui_char_select_background->resize(m_courtroom_width, m_courtroom_height);
- //T0D0: uncomment and set position properly
- //QVector<AOCharButton*> ui_char_button_list;
+ //buttons are in the constructor
- ui_selector->set_image("selector.png");
+ ui_selector->set_image("char_selector.png");
ui_selector->hide();
ui_back_to_lobby->setText("Back to Lobby");
@@ -267,6 +293,14 @@ void Courtroom::set_widgets()
set_size_and_pos(ui_char_password, "char_password");
+ ui_char_select_left->set_image("arrow_left.png");
+ ui_char_select_left->move(2, 325);
+ ui_char_select_left->resize(20, 20);
+
+ ui_char_select_right->set_image("arrow_right.png");
+ ui_char_select_right->move(691, 325);
+ ui_char_select_right->resize(20, 20);
+
ui_spectator->setText("Spectator");
set_size_and_pos(ui_spectator, "spectator");
@@ -305,13 +339,57 @@ void Courtroom::set_taken(int n_char, bool p_taken)
}
char_type f_char;
- f_char.name = char_list.at(0).name;
- f_char.description = char_list.at(1).description;
+ f_char.name = char_list.at(n_char).name;
+ f_char.description = char_list.at(n_char).description;
f_char.taken = p_taken;
char_list.replace(n_char, f_char);
}
+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;
+
+ qDebug() << "chars_on_page: " << 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();
+
+ for (int n_button = 0 ; n_button < chars_on_page ; ++n_button)
+ {
+ int n_real_char = n_button + current_char_page * 90;
+
+ ui_char_button_list.at(n_button)->set_image(char_list.at(n_real_char).name);
+ ui_char_button_list.at(n_button)->show();
+ }
+
+}
+
void Courtroom::on_change_character_clicked()
{
ui_char_select_background->show();
@@ -331,11 +409,28 @@ void Courtroom::on_back_to_lobby_clicked()
ao_app->destruct_courtroom();
}
+void Courtroom::on_char_select_left_clicked()
+{
+ --current_char_page;
+ set_char_select_page();
+}
+
+void Courtroom::on_char_select_right_clicked()
+{
+ ++current_char_page;
+ set_char_select_page();
+}
+
void Courtroom::on_spectator_clicked()
{
ui_char_select_background->hide();
}
+void Courtroom::char_clicked(int n_char)
+{
+
+}
+
Courtroom::~Courtroom()
{