aboutsummaryrefslogtreecommitdiff
path: root/src/charselect.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/charselect.cpp')
-rw-r--r--src/charselect.cpp74
1 files changed, 70 insertions, 4 deletions
diff --git a/src/charselect.cpp b/src/charselect.cpp
index 33cc5176..abed0950 100644
--- a/src/charselect.cpp
+++ b/src/charselect.cpp
@@ -11,6 +11,16 @@ void Courtroom::construct_char_select()
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);
@@ -46,6 +56,9 @@ void Courtroom::construct_char_select()
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()));
@@ -126,6 +139,21 @@ void Courtroom::set_char_select_page()
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)
@@ -218,7 +246,32 @@ void Courtroom::character_loading_finished()
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); });
@@ -241,7 +294,7 @@ void Courtroom::character_loading_finished()
.arg(QString::number(ao_app->char_list_size)));
}
}
-
+ ui_char_list->expandAll();
filter_character_list();
}
@@ -250,24 +303,37 @@ 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)
+ 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))
+ 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);
}