From a4e448576b43b9cf4f984253abb3daf7296aa154 Mon Sep 17 00:00:00 2001 From: Crystalwarrior Date: Mon, 24 Feb 2020 22:20:43 +0300 Subject: [PATCH] Make pos dropdown more abstract and actually useful by letting servers send only pos you can actually access. Pos dropdown system also reads the actual bg folder of the current BG to see all the created pos. --- include/courtroom.h | 6 +++ src/courtroom.cpp | 79 +++++++++++++++++-------------------- src/packet_distribution.cpp | 9 +++++ 3 files changed, 51 insertions(+), 43 deletions(-) diff --git a/include/courtroom.h b/include/courtroom.h index d204417..417d455 100644 --- a/include/courtroom.h +++ b/include/courtroom.h @@ -159,6 +159,9 @@ public: //sets the local character pos/side to use. void set_side(QString p_side); + //sets the pos dropdown + void set_pos_dropdown(QStringList pos_dropdowns); + //sets the evidence list member variable to argument void set_evidence_list(QVector &p_evi_list); @@ -394,6 +397,9 @@ private: QVector color_markdown_talking_list; //Text Color-related optimization END + //List of all currently available pos + QStringList pos_dropdown_list; + bool is_presenting_evidence = false; QString effect = ""; diff --git a/src/courtroom.cpp b/src/courtroom.cpp index 81e043e..ea6f165 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -180,14 +180,6 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() initialize_emotes(); ui_pos_dropdown = new QComboBox(this); - ui_pos_dropdown->addItem("wit"); - ui_pos_dropdown->addItem("def"); - ui_pos_dropdown->addItem("pro"); - ui_pos_dropdown->addItem("jud"); - ui_pos_dropdown->addItem("hld"); - ui_pos_dropdown->addItem("hlp"); - ui_pos_dropdown->addItem("jur"); - ui_pos_dropdown->addItem("sea"); ui_iniswap_dropdown = new QComboBox(this); ui_iniswap_dropdown->setContextMenuPolicy(Qt::CustomContextMenu); @@ -1005,10 +997,32 @@ void Courtroom::set_background(QString p_background, bool display) ui_vp_testimony->stop(); current_background = p_background; + //welcome to hardcode central may I take your order of regularly scheduled CBT + QMap default_pos; + default_pos["defenseempty"] = "def"; + default_pos["helperstand"] = "hld"; + default_pos["prosecutorempty"] = "pro"; + default_pos["prohelperstand"] = "hlp"; + default_pos["witnessempty"] = "wit"; + default_pos["judgestand"] = "jud"; + default_pos["jurystand"] = "jur"; + default_pos["seancestand"] = "sea"; + + //Populate the dropdown list with all pos that exist on this bg + QStringList pos_list = {}; + for (QString key : default_pos.keys()) + { + if (file_exists(ao_app->get_static_image_suffix(ao_app->get_background_path(key)))) + { + pos_list.append(default_pos[key]); + } + } + + //TODO: search through extra/custom pos and add them to the pos dropdown as well + + set_pos_dropdown(pos_list); + is_ao2_bg = true; -// file_exists(ao_app->get_static_image_suffix(ao_app->get_background_path("defensedesk"))) && -// file_exists(ao_app->get_static_image_suffix(ao_app->get_background_path("prosecutiondesk"))) && -// file_exists(ao_app->get_static_image_suffix(ao_app->get_background_path("stand"))); if (is_ao2_bg) { @@ -1070,6 +1084,13 @@ void Courtroom::set_side(QString p_side) } } +void Courtroom::set_pos_dropdown(QStringList pos_dropdowns) +{ + pos_dropdown_list = pos_dropdowns; + ui_pos_dropdown->clear(); + ui_pos_dropdown->addItems(pos_dropdown_list); + qDebug() << pos_dropdown_list; +} void Courtroom::update_character(int p_cid) { @@ -3336,42 +3357,14 @@ void Courtroom::on_pos_dropdown_changed(int p_index) toggle_judge_buttons(false); - QString f_pos; - - switch (p_index) - { - case 0: - f_pos = "wit"; - break; - case 1: - f_pos = "def"; - break; - case 2: - f_pos = "pro"; - break; - case 3: - f_pos = "jud"; - toggle_judge_buttons(true); - break; - case 4: - f_pos = "hld"; - break; - case 5: - f_pos = "hlp"; - break; - case 6: - f_pos = "jur"; - break; - case 7: - f_pos = "sea"; - break; - default: - f_pos = ""; - } + QString f_pos = ui_pos_dropdown->itemText(p_index); if (f_pos == "") return; + if (f_pos == "jud") + toggle_judge_buttons(true); + //YEAH SENDING LIKE 20 PACKETS IF THE USER SCROLLS THROUGH, GREAT IDEA //how about this instead set_side(f_pos); diff --git a/src/packet_distribution.cpp b/src/packet_distribution.cpp index 8c74b76..2305083 100644 --- a/src/packet_distribution.cpp +++ b/src/packet_distribution.cpp @@ -595,7 +595,16 @@ void AOApplication::server_packet_received(AOPacket *p_packet) goto end; if (courtroom_constructed) //We were sent a "set position" packet + { w_courtroom->set_side(f_contents.at(0)); + } + } + else if (header == "SD") //Send pos dropdown + { + if (f_contents.size() < 1) + goto end; + + w_courtroom->set_pos_dropdown(f_contents.at(0).split("*")); } //server accepting char request(CC) packet else if (header == "PV")