From c3a5bfb98a50396a75b29bb39c4b3eb25b1353c5 Mon Sep 17 00:00:00 2001 From: Crystalwarrior Date: Fri, 3 Jun 2022 13:41:31 +0300 Subject: [PATCH] Add icons for pos dropdown (#715) * Add icons for pos dropdown * Make sure to upscale the icons to actually fit (so tiny 1pix bg images for ex. still show up properly) * move get_pos_path * add const to desk mod Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Revert "add const to desk mod" This reverts commit 7d6007fb1be0781e29985d0b83f2f6da16295e90. * make set_scene const * make pos const * add and to const Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * add braces Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Revert "add and to const" This reverts commit aa5e5066dcf42ae18c2aeb349d470271226601da. * make desk const * fix get pos path for real Co-authored-by: stonedDiscord Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- include/aoapplication.h | 1 + src/courtroom.cpp | 81 +++++++---------------------------------- src/path_functions.cpp | 71 ++++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+), 68 deletions(-) diff --git a/include/aoapplication.h b/include/aoapplication.h index 5f808f5..4809c3f 100644 --- a/include/aoapplication.h +++ b/include/aoapplication.h @@ -162,6 +162,7 @@ public: QString get_asset(QString p_element, QString p_theme="", QString p_subtheme="", QString p_default_theme="", QString p_misc="", QString p_character="", QString p_placeholder=""); QString get_image(QString p_element, QString p_theme="", QString p_subtheme="", QString p_default_theme="", QString p_misc="", QString p_character="", QString p_placeholder="", bool static_image=false); QString get_sfx(QString p_sfx, QString p_misc="", QString p_character=""); + QString get_pos_path(const QString& pos, bool desk = false); QString get_case_sensitive_path(QString p_file); QString get_real_path(const VPath &vpath); QString get_real_suffixed_path(const VPath &vpath, const QStringList &suffixes); diff --git a/src/courtroom.cpp b/src/courtroom.cpp index 249f09e..c525ef1 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -1443,7 +1443,15 @@ void Courtroom::set_pos_dropdown(QStringList pos_dropdowns) ui_pos_dropdown->blockSignals(true); pos_dropdown_list = pos_dropdowns; ui_pos_dropdown->clear(); - ui_pos_dropdown->addItems(pos_dropdown_list); + for (int n = 0; n < pos_dropdown_list.size(); ++n) { + QString pos = pos_dropdown_list.at(n); + ui_pos_dropdown->addItem(pos); + QPixmap image = QPixmap(ao_app->get_image_suffix(ao_app->get_background_path(ao_app->get_pos_path(pos)))); + if (!image.isNull()) { + image = image.scaledToHeight(ui_pos_dropdown->iconSize().height()); + } + ui_pos_dropdown->setItemIcon(n, image); + } if (current_side != "" && !pos_dropdown_list.contains(current_side)) ui_pos_dropdown->setEditText(current_side); @@ -3754,73 +3762,10 @@ void Courtroom::play_sfx() ao_app->get_sfx_looping(current_char, current_emote) == "1"); } -void Courtroom::set_scene(QString f_desk_mod, QString f_side) +void Courtroom::set_scene(const QString f_desk_mod, const QString f_side) { - // witness is default if pos is invalid - QString f_background; - QString f_desk_image; - if (file_exists(ao_app->get_image_suffix(ao_app->get_background_path("witnessempty")))) { - f_background = "witnessempty"; - f_desk_image = "stand"; - } - else { - f_background = "wit"; - f_desk_image = "wit_overlay"; - } - - if (f_side == "def" && file_exists(ao_app->get_image_suffix( - ao_app->get_background_path("defenseempty")))) { - f_background = "defenseempty"; - f_desk_image = "defensedesk"; - } - else if (f_side == "pro" && - file_exists(ao_app->get_image_suffix( - ao_app->get_background_path("prosecutorempty")))) { - f_background = "prosecutorempty"; - f_desk_image = "prosecutiondesk"; - } - else if (f_side == "jud" && file_exists(ao_app->get_image_suffix( - ao_app->get_background_path("judgestand")))) { - f_background = "judgestand"; - f_desk_image = "judgedesk"; - } - else if (f_side == "hld" && - file_exists(ao_app->get_image_suffix( - ao_app->get_background_path("helperstand")))) { - f_background = "helperstand"; - f_desk_image = "helperdesk"; - } - else if (f_side == "hlp" && - file_exists(ao_app->get_image_suffix( - ao_app->get_background_path("prohelperstand")))) { - f_background = "prohelperstand"; - f_desk_image = "prohelperdesk"; - } - else if (f_side == "jur" && file_exists(ao_app->get_image_suffix( - ao_app->get_background_path("jurystand")))) { - f_background = "jurystand"; - f_desk_image = "jurydesk"; - } - else if (f_side == "sea" && - file_exists(ao_app->get_image_suffix( - ao_app->get_background_path("seancestand")))) { - f_background = "seancestand"; - f_desk_image = "seancedesk"; - } - - if (file_exists(ao_app->get_image_suffix( - ao_app->get_background_path(f_side)))) // Unique pos path - { - f_background = f_side; - f_desk_image = f_side + "_overlay"; - } - - QString desk_override = ao_app->read_design_ini("overlays/" + f_background, ao_app->get_background_path("design.ini")); - if (desk_override != "") - f_desk_image = desk_override; - - ui_vp_background->load_image(f_background); - ui_vp_desk->load_image(f_desk_image); + ui_vp_background->load_image(ao_app->get_pos_path(f_side)); + ui_vp_desk->load_image(ao_app->get_pos_path(f_side, true)); if (f_desk_mod == "0" || (f_desk_mod != "1" && @@ -5194,7 +5139,7 @@ void Courtroom::set_text_color_dropdown() ui_text_color->addItem(color_name); QPixmap pixmap(16, 16); pixmap.fill(color); - ui_text_color->setItemIcon(ui_text_color->count() - 1, QIcon(pixmap)); + ui_text_color->setItemIcon(ui_text_color->count() - 1, pixmap); color_row_to_number.append(c); } for (int c = 0; c < max_colors; ++c) { diff --git a/src/path_functions.cpp b/src/path_functions.cpp index ded1b67..575461f 100644 --- a/src/path_functions.cpp +++ b/src/path_functions.cpp @@ -92,6 +92,77 @@ VPath AOApplication::get_default_background_path(QString p_file) return VPath("background/default/" + p_file); } +QString AOApplication::get_pos_path(const QString& pos, const bool desk) +{ + // witness is default if pos is invalid + QString f_background; + QString f_desk_image; + if (file_exists(get_image_suffix(get_background_path("witnessempty")))) { + f_background = "witnessempty"; + f_desk_image = "stand"; + } + else { + f_background = "wit"; + f_desk_image = "wit_overlay"; + } + + if (pos == "def" && file_exists(get_image_suffix( + get_background_path("defenseempty")))) { + f_background = "defenseempty"; + f_desk_image = "defensedesk"; + } + else if (pos == "pro" && + file_exists(get_image_suffix( + get_background_path("prosecutorempty")))) { + f_background = "prosecutorempty"; + f_desk_image = "prosecutiondesk"; + } + else if (pos == "jud" && file_exists(get_image_suffix( + get_background_path("judgestand")))) { + f_background = "judgestand"; + f_desk_image = "judgedesk"; + } + else if (pos == "hld" && + file_exists(get_image_suffix( + get_background_path("helperstand")))) { + f_background = "helperstand"; + f_desk_image = "helperdesk"; + } + else if (pos == "hlp" && + file_exists(get_image_suffix( + get_background_path("prohelperstand")))) { + f_background = "prohelperstand"; + f_desk_image = "prohelperdesk"; + } + else if (pos == "jur" && file_exists(get_image_suffix( + get_background_path("jurystand")))) { + f_background = "jurystand"; + f_desk_image = "jurydesk"; + } + else if (pos == "sea" && + file_exists(get_image_suffix( + get_background_path("seancestand")))) { + f_background = "seancestand"; + f_desk_image = "seancedesk"; + } + + if (file_exists(get_image_suffix( + get_background_path(pos)))) // Unique pos path + { + f_background = pos; + f_desk_image = pos + "_overlay"; + } + + QString desk_override = read_design_ini("overlays/" + f_background, get_background_path("design.ini")); + if (desk_override != "") { + f_desk_image = desk_override; +} + if (desk) { + return f_desk_image; + } + return f_background; +} + VPath AOApplication::get_evidence_path(QString p_file) { return VPath("evidence/" + p_file);