Skip to content

Commit

Permalink
Merge pull request #1 from Keightiie/json-themes
Browse files Browse the repository at this point in the history
JSON Support for Themes
  • Loading branch information
Keightiie authored Sep 25, 2023
2 parents 1fa8384 + a61fdbe commit 2d3c046
Show file tree
Hide file tree
Showing 19 changed files with 1,137 additions and 127 deletions.
2 changes: 2 additions & 0 deletions dronline-client.pro
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ HEADERS += \
src/drsplashmovie.h \
src/drstickerviewer.h \
src/drtextedit.h \
src/drtheme.h \
src/drthememovie.h \
src/file_functions.h \
src/hardware_functions.h \
Expand Down Expand Up @@ -142,6 +143,7 @@ SOURCES += \
src/drstickerviewer.cpp \
src/drtextedit.cpp \
src/drdiscord.cpp \
src/drtheme.cpp \
src/drthememovie.cpp \
src/emotes.cpp \
src/file_functions.cpp \
Expand Down
4 changes: 4 additions & 0 deletions src/aoapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "file_functions.h"
#include "lobby.h"
#include "theme.h"
#include "drtheme.h"
#include "version.h"

#include <QDir>
Expand Down Expand Up @@ -536,6 +537,9 @@ void AOApplication::resolve_current_theme()
}
ao_config->set_theme(l_target_theme.value());
}

current_theme = new DRTheme(this);
current_theme->InitTheme();
}

bool AOApplication::notify(QObject *receiver, QEvent *event)
Expand Down
4 changes: 4 additions & 0 deletions src/aoapplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class AOConfig;
class AOConfigPanel;
class Courtroom;
class DRDiscord;
class DRTheme;
class DRMasterClient;
class Lobby;

Expand Down Expand Up @@ -54,6 +55,8 @@ class AOApplication : public QApplication

DRDiscord *get_discord() const;

DRTheme *current_theme = nullptr;

VersionNumber get_server_client_version() const;
VersionStatus get_server_client_version_status() const;
bool is_server_client_version_compatible() const;
Expand Down Expand Up @@ -92,6 +95,7 @@ class AOApplication : public QApplication
QString find_asset_path(QString p_file);
QString find_theme_asset_path(QString file, QStringList extension_list);
QString find_theme_asset_path(QString file);
QString find_current_theme_path();

QString get_case_sensitive_path(QString p_file);

Expand Down
8 changes: 5 additions & 3 deletions src/aoconfigpanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "aoguiloader.h"
#include "datatypes.h"
#include "drpather.h"
#include "drtheme.h"
#include "mk2/spritedynamicreader.h"
#include "version.h"

Expand Down Expand Up @@ -448,7 +449,8 @@ void AOConfigPanel::refresh_gamemode_list()
// add empty entry indicating no gamemode chosen
ui_manual_gamemode->addItem("<default>");
// gamemodes
QString path = DRPather::get_application_path() + "/base/themes/" + m_config->theme() + "/gamemodes/";
QString path = ao_app->find_current_theme_path() + "/gamemodes/";

for (const QString &i_folder : QDir(ao_app->get_case_sensitive_path(path)).entryList(QDir::Dirs))
{
if (i_folder == "." || i_folder == "..")
Expand Down Expand Up @@ -477,10 +479,10 @@ void AOConfigPanel::refresh_timeofday_list()
QString l_timeofday_path;

if (l_gamemode.isEmpty())
l_timeofday_path = DRPather::get_application_path() + "/base/themes/" + l_theme + "/times/";
l_timeofday_path = ao_app->find_current_theme_path() + "/times/";
else
l_timeofday_path =
DRPather::get_application_path() + "/base/themes/" + l_theme + "/gamemodes/" + l_gamemode + "/times/";
ao_app->find_current_theme_path() + "/gamemodes/" + l_gamemode + "/times/";

// times of day
for (const QString &i_folder : QDir(ao_app->get_case_sensitive_path(l_timeofday_path)).entryList(QDir::Dirs))
Expand Down
3 changes: 2 additions & 1 deletion src/charselect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "file_functions.h"
#include "hardware_functions.h"
#include "theme.h"
#include "drtheme.h"

#include <QDebug>
#include <QSignalMapper>
Expand Down Expand Up @@ -51,7 +52,7 @@ void Courtroom::reconstruct_char_select()
{
qDeleteAll(ui_char_button_list.begin(), ui_char_button_list.end());

QPoint f_spacing = ao_app->get_button_spacing("char_button_spacing", COURTROOM_DESIGN_INI);
QPoint f_spacing = ao_app->current_theme->get_widget_settings_spacing("char_buttons", "courtroom", "char_button_spacing");

const int button_width = 60;
int x_spacing = f_spacing.x();
Expand Down
3 changes: 3 additions & 0 deletions src/commondefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ const QString COURTROOM_STYLESHEETS_CSS = "courtroom_stylesheets.css";

const QString LOBBY_DESIGN_INI = "lobby_design.ini";
const QString LOBBY_FONTS_INI = "lobby_fonts.ini";


const QString THEME_JSON = "theme.json";
2 changes: 2 additions & 0 deletions src/commondefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ extern const QString COURTROOM_STYLESHEETS_CSS;

extern const QString LOBBY_DESIGN_INI;
extern const QString LOBBY_FONTS_INI;

extern const QString THEME_JSON;
103 changes: 80 additions & 23 deletions src/courtroom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "drcharactermovie.h"
#include "drchatlog.h"
#include "drdiscord.h"
#include "drtheme.h"
#include "dreffectmovie.h"
#include "drpacket.h"
#include "drscenemovie.h"
Expand Down Expand Up @@ -78,7 +79,7 @@ Courtroom::Courtroom(AOApplication *p_ao_app, QWidget *parent)
setup_courtroom();
map_viewport_viewers();
map_viewport_readers();
if (ao_app->read_theme_ini_bool("use_toggles", COURTROOM_CONFIG_INI))
if (ao_app->current_theme->read_config_bool("use_toggles"))
switch_toggle(ToggleState::Chat);

set_char_select();
Expand Down Expand Up @@ -568,12 +569,13 @@ void Courtroom::update_music_text_anim()
{
pos_size_type res_a = ao_app->get_element_dimensions("music_name", COURTROOM_DESIGN_INI);
pos_size_type res_b = ao_app->get_element_dimensions("music_area", COURTROOM_DESIGN_INI);
float speed = static_cast<float>(ao_app->get_font_property("music_name_speed", COURTROOM_FONTS_INI));

float speed = static_cast<float>(ao_app->current_theme->get_music_name_speed());

QFont f_font = ui_vp_music_name->font();
QFontMetrics fm(f_font);
int dist;
if (ao_app->read_theme_ini_bool("enable_const_music_speed", COURTROOM_CONFIG_INI))
if (ao_app->current_theme->read_config_bool("enable_const_music_speed"))
dist = res_b.width;
else
dist = fm.horizontalAdvance(ui_vp_music_name->toPlainText());
Expand Down Expand Up @@ -625,13 +627,15 @@ void Courtroom::filter_list_widget(QListWidget *p_list_widget, QString p_filter)

bool Courtroom::is_area_music_list_separated()
{
return ao_app->read_theme_ini_bool("enable_music_and_area_list_separation", COURTROOM_CONFIG_INI);
return ao_app->current_theme->read_config_bool("enable_music_and_area_list_separation");
}

void Courtroom::list_music()
{
const QBrush l_song_brush(ao_app->get_color("found_song_color", COURTROOM_DESIGN_INI));
const QBrush l_missing_song_brush(ao_app->get_color("missing_song_color", COURTROOM_DESIGN_INI));

const QBrush l_song_brush = ao_app->current_theme->get_widget_settings_color("music_list", "courtroom", "found_song", "found_song_color");
const QBrush l_missing_song_brush = ao_app->current_theme->get_widget_settings_color("music_list", "courtroom", "missing_song", "missing_song_color");

ui_music_list->clear();
for (const QString &i_song : qAsConst(m_music_list))
{
Expand All @@ -648,7 +652,8 @@ void Courtroom::list_music()

void Courtroom::list_areas()
{
const QBrush l_area_brush(ao_app->get_color("area_free_color", COURTROOM_DESIGN_INI));

const QBrush l_area_brush = ao_app->current_theme->get_widget_settings_color("area_list", "courtroom", "area_free", "area_free_color");
ui_area_list->clear();
for (const QString &i_item_name : qAsConst(m_area_list))
{
Expand Down Expand Up @@ -1298,7 +1303,7 @@ void Courtroom::handle_chatmessage_3()
if (!chatmessage_is_empty)
{
QString l_showname_image;
if (ao_app->read_theme_ini_bool("enable_showname_image", COURTROOM_CONFIG_INI))
if (ao_app->current_theme->read_config_bool("enable_showname_image"))
{
l_showname_image = ao_app->find_theme_asset_path("characters/" + f_char + "/showname", static_extensions());
if (l_showname_image.isEmpty())
Expand Down Expand Up @@ -1418,11 +1423,26 @@ void Courtroom::load_ic_text_format()
m_ic_log_format.base.setForeground(ui_ic_chatlog->palette().color(ui_ic_chatlog->foregroundRole()));

auto set_format_color = [this](const QString &f_identifier, QTextCharFormat &f_format) {
if (const std::optional<QColor> l_color = ao_app->maybe_color(QString("ic_chatlog_%1_color").arg(f_identifier), COURTROOM_FONTS_INI); l_color.has_value())
f_format.setForeground(l_color.value());

if (ao_app->get_font_property(QString("ic_chatlog_%1_bold").arg(f_identifier), COURTROOM_FONTS_INI))
f_format.setFontWeight(QFont::Bold);
if(ao_app->current_theme->m_jsonLoaded)
{
if (const std::optional<QColor> l_color = ao_app->current_theme->get_widget_font_color("ic_chatlog", "courtroom", f_identifier); l_color.has_value())
f_format.setForeground(l_color.value());

if (ao_app->current_theme->get_widget_font_bool("ic_chatlog", "courtroom", "bold", f_identifier))
f_format.setFontWeight(QFont::Bold);
;
}
else
{
if (const std::optional<QColor> l_color = ao_app->maybe_color(QString("ic_chatlog_%1_color").arg(f_identifier), COURTROOM_FONTS_INI); l_color.has_value())
f_format.setForeground(l_color.value());
if (ao_app->get_font_property(QString("ic_chatlog_%1_bold").arg(f_identifier), COURTROOM_FONTS_INI))
f_format.setFontWeight(QFont::Bold);
}



};

m_ic_log_format.name = m_ic_log_format.base;
Expand Down Expand Up @@ -1671,7 +1691,7 @@ void Courtroom::setup_chat()

// Cache these so chat_tick performs better
m_chatbox_message_outline = (ao_app->get_font_property("message_outline", COURTROOM_FONTS_INI) == 1);
m_chatbox_message_enable_highlighting = (ao_app->read_theme_ini_bool("enable_highlighting", COURTROOM_CONFIG_INI));
m_chatbox_message_enable_highlighting = (ao_app->current_theme->read_config_bool("enable_highlighting"));
m_chatbox_message_highlight_colors = ao_app->get_highlight_colors();

QString f_gender = ao_app->get_gender(m_chatmessage[CMChrName]);
Expand Down Expand Up @@ -2358,7 +2378,7 @@ void Courtroom::on_cycle_clicked()
break;
}

if (ao_app->read_theme_ini_bool("enable_cycle_ding", COURTROOM_CONFIG_INI))
if (ao_app->current_theme->read_config_bool("enable_cycle_ding"))
m_system_player->play(ao_app->get_sfx("cycle"));

set_shouts();
Expand Down Expand Up @@ -2552,12 +2572,13 @@ void Courtroom::on_change_character_clicked()

void Courtroom::load_theme()
{
ao_app->current_theme->InitTheme();
switch_toggle(ToggleState::All);
setup_courtroom();
setup_screenshake_anim();
update_background_scene();

if (ao_app->read_theme_ini_bool("use_toggles", COURTROOM_CONFIG_INI)) switch_toggle(ToggleState::Chat);
if (ao_app->current_theme->read_config_bool("use_toggles")) switch_toggle(ToggleState::Chat);
}

void Courtroom::reload_theme()
Expand Down Expand Up @@ -2732,23 +2753,45 @@ void Courtroom::switch_toggle(ToggleState state)
}


for (const QString &widget_toggle: widget_toggles.keys())
if(ao_app->current_theme->m_jsonLoaded)
{
QStringList toggle_widgets = ao_app->current_theme->get_tab_widgets(state_name);
QStringList disable_widgets = ao_app->current_theme->get_tab_widgets_disable(state_name);

for (const QString widget_off: disable_widgets)
{
if(widget_names.contains(widget_off))
widget_names[widget_off]->hide();
}

for (const QString widget_on: toggle_widgets)
{
if(widget_names.contains(widget_on))
widget_names[widget_on]->show();
}

}
else
{
for (const QString &widget_toggle: widget_toggles.keys())
{
if(widget_toggles[widget_toggle].toLower() == state_name)
{

if(widget_names.contains(widget_toggle))
widget_names[widget_toggle]->show();
if(widget_names.contains(widget_toggle))
widget_names[widget_toggle]->show();

}
else
{
if(widget_names.contains(widget_toggle))
widget_names[widget_toggle]->hide();
widget_names[widget_toggle]->hide();

}
}
}


set_judge_enabled(is_judge);
}

Expand Down Expand Up @@ -2901,7 +2944,7 @@ void Courtroom::construct_playerlist_layout()
delete m_player_list.takeLast();

//Setup Player list
QPoint f_spacing = ao_app->get_button_spacing("player_list_spacing", COURTROOM_DESIGN_INI);
QPoint f_spacing = ao_app->current_theme->get_widget_settings_spacing("player_list", "courtroom", "player_list_spacing");

set_size_and_pos(ui_player_list, "player_list", COURTROOM_DESIGN_INI, ao_app);

Expand Down Expand Up @@ -3010,19 +3053,33 @@ void Courtroom::on_area_look_clicked()

void Courtroom::write_area_desc()
{
std::optional<QColor> l_color;
bool is_bold = false;

if(ao_app->current_theme->m_jsonLoaded)
{
l_color = ao_app->current_theme->get_widget_font_color("area_desc", "courtroom");
is_bold = ao_app->current_theme->get_widget_font_bool("area_desc", "courtroom", "bold");
}
else
{
l_color = ao_app->maybe_color(QString("area_desc_color"), COURTROOM_FONTS_INI);
is_bold = ao_app->get_font_property(QString("area_desc_bold"), COURTROOM_FONTS_INI);
}


ui_area_desc->ensurePolished();
QTextCharFormat formatting = QTextCharFormat();

//Set the color
const std::optional<QColor> l_color = ao_app->maybe_color(QString("area_desc_color"), COURTROOM_FONTS_INI);

if(l_color.has_value())
{
formatting.setForeground(l_color.value());
}

//Set the bold
if (ao_app->get_font_property(QString("area_desc_bold"), COURTROOM_FONTS_INI))
formatting.setFontWeight(QFont::Bold);
if (is_bold) formatting.setFontWeight(QFont::Bold);

//Clear the text
ui_area_desc->clear();
Expand Down
1 change: 1 addition & 0 deletions src/courtroom.h
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,7 @@ class Courtroom : public QWidget
template <typename T>
void insert_widget_names(QVector<QString> &p_widget_names, QVector<T *> &p_widgets);
void set_widget_layers();
void set_widget_layers_legacy();

void reset_widget_toggles();

Expand Down
6 changes: 4 additions & 2 deletions src/courtroom_sfx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "aosfxplayer.h"
#include "commondefs.h"
#include "file_functions.h"
#include "drtheme.h"

#include <QCheckBox>
#include <QColor>
Expand Down Expand Up @@ -35,8 +36,9 @@ QString Courtroom::current_sfx_file()

void Courtroom::load_sfx_list_theme()
{
m_sfx_color_found = ao_app->get_color("found_song_color", COURTROOM_DESIGN_INI);
m_sfx_color_missing = ao_app->get_color("missing_song_color", COURTROOM_DESIGN_INI);

m_sfx_color_found = ao_app->current_theme->get_widget_settings_color("sfx_list", "courtroom", "found_sfx", "found_song_color");
m_sfx_color_missing = ao_app->current_theme->get_widget_settings_color("sfx_list", "courtroom", "missing_sfx", "found_song_color");
update_all_sfx_item_color();
}

Expand Down
Loading

0 comments on commit 2d3c046

Please sign in to comment.