aboutsummaryrefslogtreecommitdiff
path: root/charselect.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'charselect.cpp')
-rw-r--r--charselect.cpp64
1 files changed, 49 insertions, 15 deletions
diff --git a/charselect.cpp b/charselect.cpp
index 6465565..1f18217 100644
--- a/charselect.cpp
+++ b/charselect.cpp
@@ -1,5 +1,9 @@
#include "courtroom.h"
+#include "file_functions.h"
+#include "debug_functions.h"
+#include "hardware_functions.h"
+
#include <QDebug>
void Courtroom::construct_char_select()
@@ -21,18 +25,27 @@ void Courtroom::construct_char_select()
ui_spectator = new AOButton(ui_char_select_background, ao_app);
- //constructing character button grid
+ QPoint f_spacing = ao_app->get_button_spacing("char_button_spacing", "courtroom_design.ini");
+
+ const int button_width = 60;
+ int x_spacing = f_spacing.x();
+ int x_mod_count = 0;
+
+ const int button_height = 60;
+ int y_spacing = f_spacing.y();
+ int y_mod_count = 0;
+
+ set_size_and_pos(ui_char_buttons, "char_buttons");
- const int x_modifier{67};
- int x_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;
- const int y_modifier{67};
- int y_mod_count{0};
+ max_chars_on_page = char_columns * char_rows;
- for (int n = 0 ; n < 90 ; ++n)
+ for (int n = 0 ; n < max_chars_on_page ; ++n)
{
- int x_pos = (x_modifier * x_mod_count);
- int y_pos = (y_modifier * y_mod_count);
+ int x_pos = (button_width + x_spacing) * x_mod_count;
+ int y_pos = (button_height + y_spacing) * y_mod_count;
ui_char_button_list.append(new AOCharButton(ui_char_buttons, ao_app, x_pos, y_pos));
@@ -42,7 +55,8 @@ void Courtroom::construct_char_select()
++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)
+ //if (n % 10 == 9 && n != 0)
+ if (x_mod_count == char_columns)
{
++y_mod_count;
x_mod_count = 0;
@@ -86,21 +100,21 @@ void Courtroom::set_char_select_page()
for (AOCharButton *i_button : ui_char_button_list)
i_button->hide();
- int total_pages = char_list.size() / 90;
+ int total_pages = char_list.size() / max_chars_on_page;
int chars_on_page = 0;
- if (char_list.size() % 90 != 0)
+ if (char_list.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 = 90;
+ chars_on_page = max_chars_on_page;
else
- chars_on_page = char_list.size() % 90;
+ chars_on_page = char_list.size() % max_chars_on_page;
}
else
- chars_on_page = 90;
+ chars_on_page = max_chars_on_page;
if (total_pages > current_char_page + 1)
ui_char_select_right->show();
@@ -110,7 +124,7 @@ void Courtroom::set_char_select_page()
for (int n_button = 0 ; n_button < chars_on_page ; ++n_button)
{
- int n_real_char = n_button + current_char_page * 90;
+ int n_real_char = n_button + current_char_page * max_chars_on_page;
AOCharButton *f_button = ui_char_button_list.at(n_button);
f_button->reset();
@@ -123,3 +137,23 @@ void Courtroom::set_char_select_page()
}
+void Courtroom::char_clicked(int n_char)
+{
+ int n_real_char = n_char + current_char_page * max_chars_on_page;
+
+ QString char_ini_path = ao_app->get_character_path(char_list.at(n_real_char).name) + "char.ini";
+ qDebug() << "char_ini_path" << char_ini_path;
+
+ if (!file_exists(char_ini_path))
+ {
+ qDebug() << "did not find " << char_ini_path;
+ call_notice("Could not find " + char_ini_path);
+ return;
+ }
+
+ if (n_real_char == m_cid)
+ enter_courtroom(m_cid);
+ else
+ ao_app->send_server_packet(new AOPacket("CC#" + QString::number(ao_app->s_pv) + "#" + QString::number(n_real_char) + "#" + get_hdid() + "#%"));
+}
+