Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overlays folder #31

Merged
merged 18 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/aoapplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ class AOApplication : public QApplication {
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);
// pre-2.8 old style pos handling
QString get_old_pos_path(const QString& pos, bool desk = false);
QString get_case_sensitive_path(QString p_file);
QString get_real_path(const VPath &vpath, const QStringList &suffixes={""});
void invalidate_lookup_cache();
Expand Down
6 changes: 2 additions & 4 deletions src/aolayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,12 @@ void BackgroundLayer::load_image(QString p_filename)
#ifdef DEBUG_MOVIE
qDebug() << "[BackgroundLayer] BG loaded: " << p_filename;
#endif
QString final_path = ao_app->get_image_suffix(ao_app->get_background_path(p_filename));

if (final_path == last_path) {
if (p_filename == last_path) {
// Don't restart background if background is unchanged
return;
}

start_playback(final_path);
start_playback(p_filename);
play();
}

Expand Down
32 changes: 27 additions & 5 deletions src/courtroom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1679,19 +1679,33 @@ void Courtroom::set_background(QString p_background, bool display)
// Populate the dropdown list with all pos that exist on this bg
QStringList pos_list = {};
for (const QString &key : default_pos.keys()) {
if (file_exists(ao_app->get_image_suffix(
ao_app->get_background_path(default_pos[key]))) || // if we have 2.8-style positions, e.g. def.png, wit.webp, hld.apng
file_exists(
if (file_exists(
ao_app->get_image_suffix(ao_app->get_background_path(key)))) { // if we have pre-2.8-style positions, e.g. defenseempty.png
pos_list.append(default_pos[key]);
}
}
// design.ini positions=def,pro,wit,...
for (const QString &pos : ao_app->read_design_ini("positions", ao_app->get_background_path("design.ini")).split(",")) {
if (file_exists(ao_app->get_image_suffix(ao_app->get_background_path(pos)))) {
pos_list.append(pos);
}
}

// DRO-Style positions.ini overrides all
QString positions_ini = ao_app->get_real_path(ao_app->get_background_path("positions.ini"));
if (file_exists(positions_ini)) {
pos_list.clear();
QSettings settings(positions_ini, QSettings::IniFormat);
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
settings.setIniCodec("UTF-8");
#endif
QStringList keys = settings.childGroups();
// UNFORTUNATLEY, the order of pos inserted will be unpredictable because ini's are unordered!
for (const QString &pos : keys) {
pos_list.append(pos);
}
}

set_pos_dropdown(pos_list);

if (display) {
Expand Down Expand Up @@ -4505,9 +4519,12 @@ void Courtroom::play_sfx()
ao_app->get_sfx_looping(current_char, current_emote) == "1");
}

void Courtroom::set_scene(bool show_desk, const QString f_side)
void Courtroom::set_scene(bool show_desk, QString f_side)
{
current_side = f_side;
if (current_side.isEmpty()) {
f_side = ao_app->get_char_side(current_char);
}
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));

Expand Down Expand Up @@ -5156,7 +5173,12 @@ void Courtroom::display_pos_remove()
ui_pos_remove->hide();
else {
QString default_pos = ao_app->get_char_side(current_char);
if ((selected_side != default_pos && pos_dropdown_list.contains(default_pos)) || !pos_dropdown_list.contains(selected_side)){
if ((selected_side != default_pos && pos_dropdown_list.contains(default_pos)) ||
(!pos_dropdown_list.contains(selected_side) ||
(ui_pos_dropdown->count() > 0 && selected_side != ui_pos_dropdown->itemText(0))
)
)
{
ui_pos_remove->show();
return;
}
Expand Down
4 changes: 1 addition & 3 deletions src/packet_distribution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,9 +373,7 @@ void AOApplication::server_packet_received(AOPacket *p_packet)
if (f_contents_size > 3) {
// Set overlay if not empty
// overlay
if (!f_contents[2].isEmpty()) {
w_courtroom->server_overlay = f_contents[2];
}
w_courtroom->server_overlay = f_contents[2];
}

const bool shouldShowImmediately =
Expand Down
91 changes: 71 additions & 20 deletions src/path_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ VPath AOApplication::get_music_path(QString p_song)
VPath AOApplication::get_background_path(QString p_file)
{
if (courtroom_constructed) {
return VPath("background/" + w_courtroom->get_current_background() + "/" + p_file);
if (p_file.startsWith("overlays/")){
return VPath(p_file);
}else{
return VPath("background/" + w_courtroom->get_current_background() + "/" + p_file);
}
}
return get_default_background_path(p_file);
}
Expand All @@ -78,18 +82,74 @@ VPath AOApplication::get_default_background_path(QString 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;
// Witness is default BG
QString f_background = "wit";
QString f_desk_image = "wit_overlay";

if (desk) {
f_desk_image = get_old_pos_path(pos, desk);
}
else {
f_background = get_old_pos_path(pos, desk);
}

// Special desk handling
QString desk_override = read_design_ini("overlays/" + f_background, get_background_path("design.ini"));
if (desk_override != "") {
f_desk_image = get_image_suffix(get_background_path(desk_override));
}

// DRO-style override handling
QString suffix = "back";
if (desk) {
suffix = "front";
}

// Read the positions.ini file
QString override = read_design_ini(pos + "/" + suffix, get_background_path("positions.ini"));
if (override != "") {
// Set both to the override (we only send back 1 of the 2 anyway)
f_desk_image = get_image_suffix(get_background_path(override));
f_background = get_image_suffix(get_background_path(override));
}

// Server dictates to override our overlay
if (w_courtroom->server_overlay != "") {
// Overlay is located inside of our BG folder
QString path_test = get_image_suffix(get_background_path(w_courtroom->server_overlay));
if (file_exists(path_test)) {
f_desk_image = path_test;
}

// Specific overlay *folder* to access inside of the overlay folder
path_test = get_image_suffix(VPath("overlays/" + w_courtroom->server_overlay + "/" + pos));
if (file_exists(path_test)) {
f_desk_image = path_test;
}

// Specific file path to access inside of the overlay folder
path_test = get_image_suffix(VPath("overlays/" + w_courtroom->server_overlay));
if (file_exists(path_test)) {
f_desk_image = path_test;
}
}
if (desk) {
return f_desk_image;
}
return f_background;
}

QString AOApplication::get_old_pos_path(const QString& pos, const bool desk)
{
QString f_background = "wit";
QString f_desk_image = "wit_overlay";
// if we have pre-2.8-style positions, e.g. witnessempty.png, use that as the default.
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";
}

// Pre-2.8-style positions are detected
if (pos == "def" && file_exists(get_image_suffix(
get_background_path("defenseempty")))) {
f_background = "defenseempty";
Expand Down Expand Up @@ -137,22 +197,13 @@ QString AOApplication::get_pos_path(const QString& pos, const bool desk)
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;
} else if (w_courtroom->server_overlay != "") { // BN+ Packet
if (file_exists(get_image_suffix(
get_background_path(w_courtroom->server_overlay))))
{
f_desk_image = w_courtroom->server_overlay;
}
}
if (desk) {
return f_desk_image;
return get_image_suffix(get_background_path(f_desk_image));
}
return f_background;
return get_image_suffix(get_background_path(f_background));
}


VPath AOApplication::get_evidence_path(QString p_file)
{
return VPath("evidence/" + p_file);
Expand Down