From 27726c9ce1fd6ff1e581bade5911e3bf05bc59f2 Mon Sep 17 00:00:00 2001 From: in1tiate <32779090+in1tiate@users.noreply.github.com> Date: Sat, 10 Feb 2024 05:23:34 -0600 Subject: [PATCH] Add integer-based theme scaling (#935) Configurable over the options menu, --- include/aoapplication.h | 2 + include/options.h | 3 + include/widgets/aooptionsdialog.h | 1 + resource/ui/options_dialog.ui | 128 +++++++++++++++++------------- src/aocharbutton.cpp | 17 ++-- src/charselect.cpp | 13 +-- src/courtroom.cpp | 9 ++- src/main.cpp | 8 ++ src/options.cpp | 13 ++- src/text_file_functions.cpp | 15 ++-- src/widgets/aooptionsdialog.cpp | 9 ++- 11 files changed, 142 insertions(+), 76 deletions(-) diff --git a/include/aoapplication.h b/include/aoapplication.h index 8ef2a12..72c3457 100644 --- a/include/aoapplication.h +++ b/include/aoapplication.h @@ -66,6 +66,8 @@ public: Courtroom *w_courtroom; AttorneyOnline::Discord *discord; + QFont default_font; + bool lobby_constructed = false; bool courtroom_constructed = false; diff --git a/include/options.h b/include/options.h index aba346c..2beae23 100644 --- a/include/options.h +++ b/include/options.h @@ -48,6 +48,9 @@ public: QString theme() const; void setTheme(QString value); + int themeScalingFactor() const; + void setThemeScalingFactor(int value); + // Returns the value of oocname in config.ini QString oocName() const; void setOocName(QString value); diff --git a/include/widgets/aooptionsdialog.h b/include/widgets/aooptionsdialog.h index dcc66c1..ab36652 100644 --- a/include/widgets/aooptionsdialog.h +++ b/include/widgets/aooptionsdialog.h @@ -47,6 +47,7 @@ private: QWidget *ui_settings_widget; QComboBox *ui_theme_combobox; QComboBox *ui_subtheme_combobox; + QSpinBox *ui_theme_scaling_factor_sb; QPushButton *ui_theme_reload_button; QPushButton *ui_theme_folder_button; QCheckBox *ui_evidence_double_click_cb; diff --git a/resource/ui/options_dialog.ui b/resource/ui/options_dialog.ui index 26cfa93..19cbb94 100644 --- a/resource/ui/options_dialog.ui +++ b/resource/ui/options_dialog.ui @@ -41,18 +41,18 @@ 0 0 394 - 826 + 828 - + - + Stop music when double-clicking a category. If this is disabled, use the right-click context menu to stop music. @@ -62,7 +62,7 @@ - + @@ -72,7 +72,7 @@ - + Sets the default scaling method, if there is not one already defined specifically for the character. @@ -82,7 +82,7 @@ - + Turn this on to allow characters to define their own custom chat box designs. @@ -92,7 +92,7 @@ - + Allows screen effects. Disable this if you have concerns or issues with photosensitivity and/or seizures. @@ -102,7 +102,7 @@ - + @@ -119,7 +119,7 @@ - + Overrides the base URL to retrieve server information from. @@ -129,14 +129,14 @@ - + Instant Objection: - + ms @@ -156,7 +156,7 @@ - + @@ -195,10 +195,10 @@ - + - + Send screen-shaking, flashes and sounds as defined in the char.ini over the network. Only works for servers that support this functionality. @@ -208,7 +208,7 @@ - + Chat Rate Limit: @@ -218,7 +218,7 @@ - + ms @@ -228,7 +228,7 @@ - + If ticked, themes will be allowed to have animated elements. @@ -238,7 +238,7 @@ - + Amount of time (in miliseconds) spent on each letter when the in-character text is being displayed. @@ -258,17 +258,17 @@ - + - + - + Your showname will be automatically set to this value when you join a server. @@ -278,7 +278,7 @@ - + @@ -288,7 +288,7 @@ - + Turn this on to allow characters to define their own stickers (unique images that show up over the chatbox - like avatars or shownames). @@ -298,7 +298,7 @@ - + Turn this on to prevent preanimation checkbox from clearing after playing the emote. @@ -308,7 +308,7 @@ - + ms @@ -318,7 +318,7 @@ - + Gives the default value for the in-game 'Custom shownames' tickbox, which in turn determines whether the client should display custom in-character names. @@ -328,7 +328,7 @@ - + Turn this on to prevent the effects dropdown from clearing the effect after playing it. @@ -338,14 +338,14 @@ - + - + Minimum amount of time (in miliseconds) an IC message must stay on screen before the next IC message is shown, acting as a 'queue'. Set to 0 to disable this behavior. @@ -355,7 +355,7 @@ - + Sets the language if you don't want to use your system language. @@ -365,35 +365,35 @@ - + - + - + - + - + If the SFX dropdown has an SFX selected, send the custom SFX alongside the message even if Preanim is OFF. @@ -403,7 +403,7 @@ - + Turn this on to prevent the sound dropdown from clearing the sound after playing it. @@ -413,14 +413,14 @@ - + - + Your OOC name will be automatically set to this value when you join a server. @@ -430,7 +430,7 @@ - + Allows screenshaking. Disable this if you have concerns or issues with photosensitivity and/or seizures. @@ -440,14 +440,14 @@ - + - + Allows others on Discord to see what server you are in, what character are you playing, and how long you have been playing for. @@ -457,7 +457,7 @@ - + Use the markup colors in the server IC chatlog. @@ -477,31 +477,31 @@ - + - + - + - + - + QFrame::HLine @@ -511,7 +511,7 @@ - + QFrame::HLine @@ -521,14 +521,14 @@ - + - + If ticked, Evidence needs a double-click to view rather than a single click. @@ -538,7 +538,7 @@ - + QFrame::HLine @@ -548,14 +548,14 @@ - + - + Whether or not to resume playing animations from where they left off. Turning off might reduce lag. @@ -565,13 +565,33 @@ - + 30 + + + + 1 + + + 8 + + + + + + + <html><head/><body><p>The factor by which to scale the size of the UI</p></body></html> + + + UI Scaling Factor + + + diff --git a/src/aocharbutton.cpp b/src/aocharbutton.cpp index 0c4ff12..1c9193c 100644 --- a/src/aocharbutton.cpp +++ b/src/aocharbutton.cpp @@ -12,24 +12,28 @@ AOCharButton::AOCharButton(QWidget *parent, AOApplication *p_ao_app, int x_pos, taken = is_taken; - this->resize(60, 60); + int size = 60 * Options::getInstance().themeScalingFactor(); + int selector_size = 62 * Options::getInstance().themeScalingFactor(); + + this->resize(size, size); this->move(x_pos, y_pos); ui_taken = new AOImage(this, ao_app, true); - ui_taken->resize(60, 60); + ui_taken->resize(size, size); ui_taken->set_image("char_taken"); ui_taken->setAttribute(Qt::WA_TransparentForMouseEvents); ui_taken->hide(); ui_passworded = new AOImage(this, ao_app, true); - ui_passworded->resize(60, 60); + ui_passworded->resize(size, size); ui_passworded->set_image("char_passworded"); ui_passworded->setAttribute(Qt::WA_TransparentForMouseEvents); ui_passworded->hide(); ui_selector = new AOImage(parent, ao_app, true); - ui_selector->resize(62, 62); - ui_selector->move(x_pos - 1, y_pos - 1); + ui_selector->resize(selector_size, selector_size); + int offset = Options::getInstance().themeScalingFactor(); + ui_selector->move(x_pos - offset, y_pos - offset); ui_selector->set_image("char_selector"); ui_selector->setAttribute(Qt::WA_TransparentForMouseEvents); ui_selector->hide(); @@ -84,7 +88,8 @@ void AOCharButton::enterEvent(QEvent *e) void AOCharButton::enterEvent(QEnterEvent *e) #endif { - ui_selector->move(this->x() - 1, this->y() - 1); + int offset = Options::getInstance().themeScalingFactor(); + ui_selector->move(this->x() - offset, this->y() - offset); ui_selector->raise(); ui_selector->show(); diff --git a/src/charselect.cpp b/src/charselect.cpp index 31cf471..3fc9654 100644 --- a/src/charselect.cpp +++ b/src/charselect.cpp @@ -151,11 +151,13 @@ void Courtroom::set_char_select_page() QPoint f_spacing = ao_app->get_button_spacing("char_button_spacing", "courtroom_design.ini"); + int s_button_size = button_width * Options::getInstance().themeScalingFactor(); + char_columns = - ((ui_char_buttons->width() - button_width) / (f_spacing.x() + button_width)) + + ((ui_char_buttons->width() - s_button_size) / (f_spacing.x() + s_button_size)) + 1; - char_rows = ((ui_char_buttons->height() - button_height) / - (f_spacing.y() + button_height)) + + char_rows = ((ui_char_buttons->height() - s_button_size) / + (f_spacing.y() + s_button_size)) + 1; max_chars_on_page = char_columns * char_rows; @@ -255,9 +257,10 @@ void Courtroom::put_button_in_place(int starting, int chars_on_this_page) int y_mod_count = 0; int startout = starting; + int size = button_width * Options::getInstance().themeScalingFactor(); for (int n = starting; n < startout + chars_on_this_page; ++n) { - int x_pos = (button_width + f_spacing.x()) * x_mod_count; - int y_pos = (button_height + f_spacing.y()) * y_mod_count; + int x_pos = (size + f_spacing.x()) * x_mod_count; + int y_pos = (size + f_spacing.y()) * y_mod_count; ui_char_button_list_filtered.at(n)->move(x_pos, y_pos); ui_char_button_list_filtered.at(n)->show(); diff --git a/src/courtroom.cpp b/src/courtroom.cpp index 6786aac..0e4ac25 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -612,7 +612,7 @@ void Courtroom::set_courtroom_size() m_courtroom_width = f_courtroom.width; m_courtroom_height = f_courtroom.height; - this->setFixedSize(f_courtroom.width, f_courtroom.height); + this->setFixedSize(m_courtroom_width, m_courtroom_height); } ui_background->move(0, 0); ui_background->resize(m_courtroom_width, m_courtroom_height); @@ -1137,6 +1137,11 @@ void Courtroom::set_widgets() void Courtroom::set_fonts(QString p_char) { + QFont new_font = ao_app->default_font; + int new_font_size = new_font.pointSize() * Options::getInstance().themeScalingFactor(); + new_font.setPointSize(new_font_size); + ao_app->setFont(new_font); + set_font(ui_vp_showname, "", "showname", p_char); set_font(ui_vp_message, "", "message", p_char); set_font(ui_ic_chatlog, "", "ic_chatlog", p_char); @@ -1159,7 +1164,7 @@ void Courtroom::set_font(QWidget *widget, QString class_name, QString design_file = "courtroom_fonts.ini"; if (f_pointsize <= 0) f_pointsize = - ao_app->get_design_element(p_identifier, design_file, ao_app->get_chat(p_char)).toInt(); + ao_app->get_design_element(p_identifier, design_file, ao_app->get_chat(p_char)).toInt() * Options::getInstance().themeScalingFactor(); if (font_name == "") font_name = ao_app->get_design_element(p_identifier + "_font", design_file, ao_app->get_chat(p_char)); diff --git a/src/main.cpp b/src/main.cpp index 4528bc4..2c36c53 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -26,6 +26,14 @@ int main(int argc, char *argv[]) AOApplication::addLibraryPath(AOApplication::applicationDirPath() + "/lib"); QResource::registerResource(main_app.get_asset("themes/" + Options::getInstance().theme() + ".rcc")); + QFont main_font = main_app.font(); + main_app.default_font = main_font; + + QFont new_font = main_font; + int new_font_size = main_app.default_font.pointSize() * Options::getInstance().themeScalingFactor(); + new_font.setPointSize(new_font_size); + main_app.setFont(new_font); + QFontDatabase fontDatabase; QDirIterator it(get_base_path() + "fonts", QDirIterator::Subdirectories); diff --git a/src/options.cpp b/src/options.cpp index 4c32e96..d1822ee 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -87,6 +87,17 @@ QString Options::theme() const void Options::setTheme(QString value) { config.setValue("theme", value); } +int Options::themeScalingFactor() const +{ + int value = config.value("theme_scaling_factor", "1").toInt(); + if (value <= 0) { + value = 1; + } + return value; +} + +void Options::setThemeScalingFactor(int value) { config.setValue("theme_scaling_factor", value); } + int Options::blipRate() const { return config.value("blip_rate", 2).toInt(); } void Options::setBlipRate(int value) { config.setValue("blip_rate", value); } @@ -480,7 +491,7 @@ void Options::setServerSubTheme(QString value) { m_server_subtheme = value; } bool Options::animatedThemeEnabled() const { - return config.value("animated_theme", true).toBool(); + return config.value("animated_theme", false).toBool(); } void Options::setAnimatedThemeEnabled(bool value) diff --git a/src/text_file_functions.cpp b/src/text_file_functions.cpp index 8aba93f..51dc95a 100644 --- a/src/text_file_functions.cpp +++ b/src/text_file_functions.cpp @@ -173,9 +173,8 @@ QPoint AOApplication::get_button_spacing(QString p_identifier, QString p_file) if (sub_line_elements.size() < 2) return return_value; - - return_value.setX(sub_line_elements.at(0).toInt()); - return_value.setY(sub_line_elements.at(1).toInt()); + return_value.setX(sub_line_elements.at(0).toInt() * Options::getInstance().themeScalingFactor()); + return_value.setY(sub_line_elements.at(1).toInt() * Options::getInstance().themeScalingFactor()); return return_value; } @@ -196,10 +195,12 @@ pos_size_type AOApplication::get_element_dimensions(QString p_identifier, if (sub_line_elements.size() < 4) return return_value; - return_value.x = sub_line_elements.at(0).toInt(); - return_value.y = sub_line_elements.at(1).toInt(); - return_value.width = sub_line_elements.at(2).toInt(); - return_value.height = sub_line_elements.at(3).toInt(); + int scale = Options::getInstance().themeScalingFactor(); + + return_value.x = sub_line_elements.at(0).toInt() * scale; + return_value.y = sub_line_elements.at(1).toInt() * scale; + return_value.width = sub_line_elements.at(2).toInt() * scale; + return_value.height = sub_line_elements.at(3).toInt() * scale; return return_value; } diff --git a/src/widgets/aooptionsdialog.cpp b/src/widgets/aooptionsdialog.cpp index 6f121b3..e25b380 100644 --- a/src/widgets/aooptionsdialog.cpp +++ b/src/widgets/aooptionsdialog.cpp @@ -216,7 +216,10 @@ void AOOptionsDialog::updateValues() void AOOptionsDialog::savePressed() { - bool l_reload_theme_required = (ui_theme_combobox->currentText() != Options::getInstance().theme()); + bool l_reload_theme_required = + (ui_theme_combobox->currentText() != Options::getInstance().theme()) || + (ui_theme_scaling_factor_sb->value() != + Options::getInstance().themeScalingFactor()); for (const OptionEntry &entry : qAsConst(optionEntries)) { entry.save(); } @@ -337,6 +340,7 @@ void AOOptionsDialog::setupUI() QDesktopServices::openUrl(QUrl::fromLocalFile(p_path)); }); + FROM_UI(QSpinBox, theme_scaling_factor_sb) FROM_UI(QCheckBox, animated_theme_cb) FROM_UI(QSpinBox, stay_time_spinbox) FROM_UI(QCheckBox, instant_objection_cb) @@ -363,6 +367,9 @@ void AOOptionsDialog::setupUI() FROM_UI(QCheckBox, sfx_on_idle_cb) FROM_UI(QCheckBox, evidence_double_click_cb) + registerOption("theme_scaling_factor_sb", + &Options::themeScalingFactor, + &Options::setThemeScalingFactor); registerOption("animated_theme_cb", &Options::animatedThemeEnabled, &Options::setAnimatedThemeEnabled);