Skip to content

Commit

Permalink
Merge pull request #218 from Chrezm/nonum/gamemode-tod-fix
Browse files Browse the repository at this point in the history
The config panel now reset back to the previous TOD (if available)
  • Loading branch information
Chrezm authored Sep 18, 2021
2 parents be8fc77 + 839dc5a commit b87cfd3
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 162 deletions.
4 changes: 2 additions & 2 deletions include/aoapplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class AOApplication : public QApplication
QString get_current_background_path();
QString get_evidence_path(QString p_file);

QString sanitize_path(QString p_file);
bool is_safe_path(QString p_file);

QString find_asset_path(QStringList file_list, QStringList extension_list);
QString find_asset_path(QStringList file_list);
Expand Down Expand Up @@ -207,7 +207,7 @@ public slots:
void loading_cancelled();

signals:
void reload_theme();
void theme_reloaded();

private:
AOConfig *ao_config = nullptr;
Expand Down
4 changes: 2 additions & 2 deletions include/aoconfigpanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ private slots:
void on_reload_theme_clicked();
void on_theme_changed(QString);
void on_gamemode_changed(QString);
void on_manual_gamemode_selection_changed(bool);
void on_manual_gamemode_changed(QString);
void on_manual_gamemode_index_changed(QString p_text);
void on_manual_gamemode_selection_changed(bool);
void on_timeofday_changed(QString);
void on_manual_timeofday_selection_changed(bool);
void on_manual_timeofday_changed(QString);
void on_manual_timeofday_index_changed(QString p_text);
void on_manual_timeofday_selection_changed(bool);
void on_showname_placeholder_changed(QString p_text);
void on_log_is_topdown_changed(bool p_enabled);
void on_device_current_index_changed(int p_index);
Expand Down
12 changes: 2 additions & 10 deletions include/courtroom.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,6 @@ class Courtroom : public QMainWindow
// it's a legacy bg
DRAreaBackground get_background();
void set_background(DRAreaBackground p_area_bg);
QString get_gamemode();
void set_gamemode(QString p_gamemode);
QString get_timeofday();
void set_timeofday(QString p_time_of_day);

void set_tick_rate(const int tick_rate);

Expand Down Expand Up @@ -227,8 +223,6 @@ class Courtroom : public QMainWindow
AOApplication *ao_app = nullptr;
AOConfig *ao_config = nullptr;

QTimer *m_reload_timer = nullptr;

QVector<char_type> m_chr_list;
QVector<evi_type> m_evidence_list;
QStringList m_area_list;
Expand Down Expand Up @@ -300,7 +294,7 @@ class Courtroom : public QMainWindow
// if true, a reload theme order was delayed to be executed *after* a shout
// this allows reload theme orders that were received while a shout was
// playing to be executed only after the shout is done playing
bool shout_delayed_reload_theme = false;
bool m_shout_reload_theme = false;

int m_shout_state = 0;
int m_effect_state = 0;
Expand Down Expand Up @@ -342,8 +336,6 @@ class Courtroom : public QMainWindow
int m_current_clock = -1;

DRAreaBackground m_background;
QString m_gamemode;
QString m_timeofday;

AOImageDisplay *ui_background = nullptr;

Expand Down Expand Up @@ -650,7 +642,7 @@ private slots:
void on_wtce_clicked();

void on_change_character_clicked();
void on_app_reload_theme_requested();
void reload_theme();
void on_call_mod_clicked();

void on_switch_area_music_clicked();
Expand Down
22 changes: 12 additions & 10 deletions src/aoapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ AOApplication::AOApplication(int &argc, char **argv) : QApplication(argc, argv)
m_server_socket = new DRServerSocket(this);

connect(ao_config, SIGNAL(theme_changed(QString)), this, SLOT(handle_theme_modification()));
connect(ao_config, SIGNAL(gamemode_changed(QString)), this, SLOT(handle_theme_modification()));
connect(ao_config, SIGNAL(timeofday_changed(QString)), this, SLOT(handle_theme_modification()));
connect(ao_config, SIGNAL(manual_gamemode_changed(QString)), this, SLOT(handle_theme_modification()));
connect(ao_config, SIGNAL(manual_gamemode_selection_changed(bool)), this, SLOT(handle_theme_modification()));
connect(ao_config, SIGNAL(manual_timeofday_changed(QString)), this, SLOT(handle_theme_modification()));
Expand Down Expand Up @@ -159,6 +161,8 @@ void AOApplication::destruct_courtroom()
{
delete m_courtroom;
is_courtroom_constructed = false;
ao_config->set_gamemode(nullptr);
ao_config->set_timeofday(nullptr);
}
else
{
Expand Down Expand Up @@ -203,7 +207,7 @@ void AOApplication::handle_theme_modification()
{
load_fonts();

Q_EMIT reload_theme();
Q_EMIT theme_reloaded();
}

void AOApplication::set_favorite_list()
Expand Down Expand Up @@ -232,17 +236,15 @@ QString AOApplication::get_current_char()
* @return A sanitized path. If any check fails, the path returned is an empty string. The sanitized path does not
* necessarily exist.
*/
QString AOApplication::sanitize_path(QString p_file)
bool AOApplication::is_safe_path(QString p_file)
{
if (!p_file.contains(".."))
return p_file;

QStringList list = p_file.split(QRegularExpression("[\\/]"));
while (!list.isEmpty())
if (list.takeFirst().contains(QRegularExpression("\\.{2,}")))
return nullptr;

return p_file;
return true;
const QStringList l_item_list = p_file.split(QRegularExpression("[\\/]"));
for (auto it = l_item_list.crbegin(); it != l_item_list.crend(); ++it)
if (*it == "..")
return false;
return true;
}

void AOApplication::toggle_config_panel()
Expand Down
4 changes: 3 additions & 1 deletion src/aoconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,8 @@ void AOConfig::set_theme(QString p_string)
if (d->theme == p_string)
return;
d->theme = p_string;
d->manual_gamemode.clear();
d->manual_timeofday.clear();
d->invoke_signal("theme_changed", Q_ARG(QString, p_string));
}

Expand All @@ -658,8 +660,8 @@ void AOConfig::set_manual_gamemode(QString p_string)
if (d->manual_gamemode == p_string)
return;
d->manual_gamemode = p_string;
d->manual_timeofday.clear();
d->invoke_signal("manual_gamemode_changed", Q_ARG(QString, p_string));
set_manual_timeofday(nullptr);
}

void AOConfig::set_manual_gamemode_selection_enabled(bool p_enabled)
Expand Down
105 changes: 33 additions & 72 deletions src/aoconfigpanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,18 +282,12 @@ void AOConfigPanel::showEvent(QShowEvent *event)

if (isVisible())
{
// refresh theme, gamemode and time of day comboboxes
refresh_theme_list();
refresh_gamemode_list();
refresh_timeofday_list();
}
}

void AOConfigPanel::refresh_theme_list()
{
const QString p_prev_text = ui_theme->currentText();

// block signals
ui_theme->blockSignals(true);
ui_theme->clear();

Expand All @@ -307,17 +301,12 @@ void AOConfigPanel::refresh_theme_list()
}

// restore previous selection
ui_theme->setCurrentText(p_prev_text);

// unblock
ui_theme->setCurrentText(m_config->theme());
ui_theme->blockSignals(false);
}

void AOConfigPanel::refresh_gamemode_list()
{
const QString p_prev_text = ui_manual_gamemode->currentText();

// block signals
ui_manual_gamemode->blockSignals(true);
ui_manual_gamemode->clear();

Expand All @@ -332,45 +321,41 @@ void AOConfigPanel::refresh_gamemode_list()
ui_manual_gamemode->addItem(i_folder, i_folder);
}

// restore previous selection
ui_manual_gamemode->setCurrentText(p_prev_text);

// unblock
ui_manual_gamemode->setCurrentText(m_config->manual_gamemode());
ui_manual_gamemode->blockSignals(false);
}

void AOConfigPanel::refresh_timeofday_list()
{
const QString p_prev_text = ui_manual_timeofday->currentText();

// block signals
ui_manual_timeofday->blockSignals(true);
ui_manual_timeofday->clear();

// add empty entry indicating no time of day chosen
ui_manual_timeofday->addItem("<default>");

const QString l_theme = m_config->theme();
const QString l_gamemode =
m_config->is_manual_gamemode_selection_enabled() ? m_config->manual_gamemode() : m_config->gamemode();

// decide path to look for times of day. This differs whether there is a
// gamemode chosen or not
QString path;
if (m_config->manual_gamemode().isEmpty())
path = DRPather::get_application_path() + "/base/themes/" + m_config->theme() + "/times/";
QString l_timeofday_path;

if (l_gamemode.isEmpty())
l_timeofday_path = DRPather::get_application_path() + "/base/themes/" + l_theme + "/times/";
else
path = DRPather::get_application_path() + "/base/themes/" + m_config->theme() + "/gamemodes/" +
m_config->manual_gamemode() + "/times/";
l_timeofday_path =
DRPather::get_application_path() + "/base/themes/" + l_theme + "/gamemodes/" + l_gamemode + "/times/";

// times of day
for (const QString &i_folder : QDir(ao_app->get_case_sensitive_path(path)).entryList(QDir::Dirs))
for (const QString &i_folder : QDir(ao_app->get_case_sensitive_path(l_timeofday_path)).entryList(QDir::Dirs))
{
if (i_folder == "." || i_folder == "..")
continue;
ui_manual_timeofday->addItem(i_folder, i_folder);
}

// restore previous selection
ui_manual_timeofday->setCurrentText(p_prev_text);

// unblock
ui_manual_timeofday->setCurrentText(m_config->manual_timeofday());
ui_manual_timeofday->blockSignals(false);
}

Expand Down Expand Up @@ -415,31 +400,31 @@ void AOConfigPanel::on_reload_theme_clicked()

void AOConfigPanel::on_theme_changed(QString p_name)
{
Q_UNUSED(p_name);
refresh_theme_list();
refresh_gamemode_list();
refresh_timeofday_list();
ui_theme->setCurrentText(p_name);
}

void AOConfigPanel::on_gamemode_changed(QString p_text)
{
ui_gamemode->setText(p_text.isEmpty() ? "<default>" : p_text);
}

void AOConfigPanel::on_manual_gamemode_changed(QString p_name)
void AOConfigPanel::on_manual_gamemode_selection_changed(bool p_enabled)
{
refresh_theme_list();
ui_gamemode->setHidden(p_enabled);
ui_manual_gamemode->setVisible(p_enabled);
ui_manual_gamemode_selection->setChecked(p_enabled);
refresh_gamemode_list();
refresh_timeofday_list();
ui_manual_gamemode->setCurrentText(p_name);
}

void AOConfigPanel::on_manual_timeofday_changed(QString p_name)
void AOConfigPanel::on_manual_gamemode_changed(QString p_name)
{
refresh_theme_list();
Q_UNUSED(p_name);
refresh_gamemode_list();
refresh_timeofday_list();
ui_manual_timeofday->setCurrentText(p_name);
}

void AOConfigPanel::on_manual_gamemode_index_changed(QString p_text)
Expand All @@ -448,31 +433,23 @@ void AOConfigPanel::on_manual_gamemode_index_changed(QString p_text)
m_config->set_manual_gamemode(ui_manual_gamemode->currentData().toString());
}

void AOConfigPanel::on_manual_gamemode_selection_changed(bool p_enabled)
void AOConfigPanel::on_timeofday_changed(QString p_text)
{
/***
* As of time of writing, it is better to do this kind of ordered
* visibility calls to prevent layout reorganization 'lag'.
*
* The lag occurs due to themes immediately attempting to reload.
*/
if (p_enabled)
{
ui_gamemode->hide();
ui_manual_gamemode->show();
}
else
{
ui_manual_gamemode->hide();
ui_gamemode->show();
}
ui_timeofday->setText(p_text.isEmpty() ? "<default>" : p_text);
}

ui_manual_gamemode_selection->setChecked(p_enabled);
void AOConfigPanel::on_manual_timeofday_selection_changed(bool p_enabled)
{
ui_timeofday->setHidden(p_enabled);
ui_manual_timeofday->setVisible(p_enabled);
ui_manual_timeofday_selection->setChecked(p_enabled);
refresh_timeofday_list();
}

void AOConfigPanel::on_timeofday_changed(QString p_text)
void AOConfigPanel::on_manual_timeofday_changed(QString p_name)
{
ui_timeofday->setText(p_text.isEmpty() ? "<default>" : p_text);
Q_UNUSED(p_name);
refresh_timeofday_list();
}

void AOConfigPanel::on_manual_timeofday_index_changed(QString p_text)
Expand All @@ -481,22 +458,6 @@ void AOConfigPanel::on_manual_timeofday_index_changed(QString p_text)
m_config->set_manual_timeofday(ui_manual_timeofday->currentData().toString());
}

void AOConfigPanel::on_manual_timeofday_selection_changed(bool p_enabled)
{
if (p_enabled)
{
ui_timeofday->hide();
ui_manual_timeofday->show();
}
else
{
ui_manual_timeofday->hide();
ui_timeofday->show();
}

ui_manual_timeofday_selection->setChecked(p_enabled);
}

void AOConfigPanel::on_showname_placeholder_changed(QString p_text)
{
const QString l_showname(p_text.trimmed().isEmpty() ? "Showname" : p_text);
Expand Down
Loading

0 comments on commit b87cfd3

Please sign in to comment.