diff --git a/aoapplication.h b/aoapplication.h index 0fed8c9..202a1b0 100644 --- a/aoapplication.h +++ b/aoapplication.h @@ -102,12 +102,11 @@ public: QString get_default_theme_path(QString p_file); QString get_character_path(QString p_character, QString p_file); QString get_character_emotions_path(QString p_character, QString p_file); - QString get_demothings_path(); QString get_sounds_path(); QString get_music_path(QString p_song); - QString get_background_path(); - QString get_default_background_path(); - QString get_evidence_path(); + QString get_background_path(QString p_file); + QString get_default_background_path(QString p_file); + QString get_evidence_path(QString p_file); QString get_case_sensitive_path(QString p_file); ////// Functions for reading and writing files ////// diff --git a/aobutton.cpp b/aobutton.cpp index ded35af..5be2e67 100644 --- a/aobutton.cpp +++ b/aobutton.cpp @@ -15,8 +15,8 @@ AOButton::~AOButton() void AOButton::set_image(QString p_image) { - QString image_path = ao_app->get_theme_path() + p_image; - QString default_image_path = ao_app->get_default_theme_path() + p_image; + QString image_path = ao_app->get_theme_path(p_image); + QString default_image_path = ao_app->get_default_theme_path(p_image); if (file_exists(image_path)) this->setStyleSheet("border-image:url(\"" + image_path + "\")"); diff --git a/aocharmovie.cpp b/aocharmovie.cpp index b591c22..180052a 100644 --- a/aocharmovie.cpp +++ b/aocharmovie.cpp @@ -19,10 +19,10 @@ AOCharMovie::AOCharMovie(QWidget *p_parent, AOApplication *p_ao_app) : QLabel(p_ void AOCharMovie::play(QString p_char, QString p_emote, QString emote_prefix) { - QString original_path = ao_app->get_character_path(p_char) + emote_prefix + p_emote.toLower() + ".gif"; - QString alt_path = ao_app->get_character_path(p_char) + p_emote.toLower() + ".png"; - QString placeholder_path = ao_app->get_theme_path() + "placeholder.gif"; - QString placeholder_default_path = ao_app->get_default_theme_path() + "placeholder.gif"; + QString original_path = ao_app->get_character_path(p_char, emote_prefix + p_emote + ".gif"); + QString alt_path = ao_app->get_character_path(p_char, p_emote + ".png"); + QString placeholder_path = ao_app->get_theme_path("placeholder.gif"); + QString placeholder_default_path = ao_app->get_default_theme_path("placeholder.gif"); QString gif_path; if (file_exists(original_path)) @@ -58,7 +58,7 @@ void AOCharMovie::play(QString p_char, QString p_emote, QString emote_prefix) void AOCharMovie::play_pre(QString p_char, QString p_emote, int duration) { - QString gif_path = ao_app->get_character_path(p_char) + p_emote.toLower(); + QString gif_path = ao_app->get_character_path(p_char, p_emote); m_movie->stop(); this->clear(); @@ -107,7 +107,7 @@ void AOCharMovie::play_pre(QString p_char, QString p_emote, int duration) void AOCharMovie::play_talking(QString p_char, QString p_emote) { - QString gif_path = ao_app->get_character_path(p_char) + "(b)" + p_emote.toLower(); + QString gif_path = ao_app->get_character_path(p_char, "(b)" + p_emote); m_movie->stop(); this->clear(); @@ -120,7 +120,7 @@ void AOCharMovie::play_talking(QString p_char, QString p_emote) void AOCharMovie::play_idle(QString p_char, QString p_emote) { - QString gif_path = ao_app->get_character_path(p_char) + "(a)" + p_emote.toLower(); + QString gif_path = ao_app->get_character_path(p_char, "(a)" + p_emote); m_movie->stop(); this->clear(); diff --git a/aoemotebutton.cpp b/aoemotebutton.cpp index 9e3c446..76029cf 100644 --- a/aoemotebutton.cpp +++ b/aoemotebutton.cpp @@ -16,19 +16,13 @@ AOEmoteButton::AOEmoteButton(QWidget *p_parent, AOApplication *p_ao_app, int p_x void AOEmoteButton::set_image(QString p_char, int p_emote, QString suffix) { QString emotion_number = QString::number(p_emote + 1); - QString image_path = ao_app->get_character_path(p_char) + "emotions/ao2/button" + emotion_number + suffix; - QString alt_path = ao_app->get_character_path(p_char) + "emotions/button" + emotion_number + suffix; + QString image_path = ao_app->get_character_emotions_path(p_char, "button" + emotion_number + suffix); if (file_exists(image_path)) { this->setText(""); this->setStyleSheet("border-image:url(\"" + image_path + "\")"); } - else if (file_exists(alt_path)) - { - this->setText(""); - this->setStyleSheet("border-image:url(\"" + alt_path + "\")"); - } else { this->setText(ao_app->get_emote_comment(p_char, p_emote)); diff --git a/aoevidencebutton.cpp b/aoevidencebutton.cpp index 573b8ef..924aeb8 100644 --- a/aoevidencebutton.cpp +++ b/aoevidencebutton.cpp @@ -37,7 +37,7 @@ void AOEvidenceButton::reset() void AOEvidenceButton::set_image(QString p_image) { - QString image_path = ao_app->get_evidence_path() + p_image; + QString image_path = ao_app->get_evidence_path(p_image); if (file_exists(image_path)) { @@ -53,8 +53,8 @@ void AOEvidenceButton::set_image(QString p_image) void AOEvidenceButton::set_theme_image(QString p_image) { - QString theme_image_path = ao_app->get_theme_path() + p_image; - QString default_image_path = ao_app->get_default_theme_path() + p_image; + QString theme_image_path = ao_app->get_theme_path(p_image); + QString default_image_path = ao_app->get_default_theme_path(p_image); QString final_image_path; diff --git a/aoevidencedisplay.cpp b/aoevidencedisplay.cpp index 5364ffb..9ec105d 100644 --- a/aoevidencedisplay.cpp +++ b/aoevidencedisplay.cpp @@ -21,7 +21,7 @@ void AOEvidenceDisplay::show_evidence(QString p_evidence_image, bool is_left_sid sfx_player->set_volume(p_volume); - QString f_evidence_path = ao_app->get_evidence_path() + p_evidence_image; + QString f_evidence_path = ao_app->get_evidence_path(p_evidence_image); QPixmap f_pixmap(f_evidence_path); @@ -47,8 +47,8 @@ void AOEvidenceDisplay::show_evidence(QString p_evidence_image, bool is_left_sid evidence_icon->setPixmap(f_pixmap.scaled(evidence_icon->width(), evidence_icon->height(), Qt::IgnoreAspectRatio)); - QString f_default_gif_path = ao_app->get_default_theme_path() + gif_name; - QString f_gif_path = ao_app->get_theme_path() + gif_name; + QString f_default_gif_path = ao_app->get_default_theme_path(gif_name); + QString f_gif_path = ao_app->get_theme_path(gif_name); if (file_exists(f_gif_path)) final_gif_path = f_gif_path; diff --git a/aoimage.cpp b/aoimage.cpp index 935ba74..7bb56bb 100644 --- a/aoimage.cpp +++ b/aoimage.cpp @@ -15,8 +15,8 @@ AOImage::~AOImage() void AOImage::set_image(QString p_image) { - QString theme_image_path = ao_app->get_theme_path() + p_image; - QString default_image_path = ao_app->get_default_theme_path() + p_image; + QString theme_image_path = ao_app->get_theme_path(p_image); + QString default_image_path = ao_app->get_default_theme_path(p_image); QString final_image_path; @@ -32,7 +32,7 @@ void AOImage::set_image(QString p_image) void AOImage::set_image_from_path(QString p_path) { - QString default_path = ao_app->get_default_theme_path() + "chatmed.png"; + QString default_path = ao_app->get_default_theme_path("chatmed.png"); QString final_path; diff --git a/aomovie.cpp b/aomovie.cpp index 90c3701..53181de 100644 --- a/aomovie.cpp +++ b/aomovie.cpp @@ -28,15 +28,15 @@ void AOMovie::play(QString p_gif, QString p_char, QString p_custom_theme) QString custom_path; if (p_gif == "custom") - custom_path = ao_app->get_character_path(p_char) + p_gif + ".gif"; + custom_path = ao_app->get_character_path(p_char, p_gif + ".gif"); else - custom_path = ao_app->get_character_path(p_char) + p_gif + "_bubble.gif"; + custom_path = ao_app->get_character_path(p_char, p_gif + "_bubble.gif"); QString custom_theme_path = ao_app->get_base_path() + "themes/" + p_custom_theme + "/" + p_gif + ".gif"; - QString theme_path = ao_app->get_theme_path() + p_gif + ".gif"; - QString default_theme_path = ao_app->get_default_theme_path() + p_gif + ".gif"; - QString placeholder_path = ao_app->get_theme_path() + "placeholder.gif"; - QString default_placeholder_path = ao_app->get_default_theme_path() + "placeholder.gif"; + QString theme_path = ao_app->get_theme_path(p_gif + ".gif"); + QString default_theme_path = ao_app->get_default_theme_path(p_gif + ".gif"); + QString placeholder_path = ao_app->get_theme_path("placeholder.gif"); + QString default_placeholder_path = ao_app->get_default_theme_path("placeholder.gif"); if (file_exists(custom_path)) gif_path = custom_path; diff --git a/aoscene.cpp b/aoscene.cpp index 5fe8304..7056bfc 100644 --- a/aoscene.cpp +++ b/aoscene.cpp @@ -10,9 +10,9 @@ AOScene::AOScene(QWidget *parent, AOApplication *p_ao_app) : QLabel(parent) void AOScene::set_image(QString p_image) { - QString background_path = ao_app->get_background_path() + p_image + ".png"; - QString animated_background_path = ao_app->get_background_path() + p_image + ".gif"; - QString default_path = ao_app->get_default_background_path() + p_image; + QString background_path = ao_app->get_background_path(p_image + ".png"); + QString animated_background_path = ao_app->get_background_path(p_image + ".gif"); + QString default_path = ao_app->get_default_background_path(p_image + ".png"); QPixmap background(background_path); QPixmap animated_background(animated_background_path); @@ -34,8 +34,8 @@ void AOScene::set_legacy_desk(QString p_image) //vanilla desks vary in both width and height. in order to make that work with viewport rescaling, //some INTENSE math is needed. - QString desk_path = ao_app->get_background_path() + p_image; - QString default_path = ao_app->get_default_background_path() + p_image; + QString desk_path = ao_app->get_background_path(p_image); + QString default_path = ao_app->get_default_background_path(p_image); QPixmap f_desk; @@ -53,7 +53,7 @@ void AOScene::set_legacy_desk(QString p_image) //int final_y = y_modifier * vp_height; //int final_w = w_modifier * f_desk.width(); - int final_h = h_modifier * f_desk.height(); + int final_h = static_cast(h_modifier * f_desk.height()); //this->resize(final_w, final_h); //this->setPixmap(f_desk.scaled(final_w, final_h)); diff --git a/aosfxplayer.cpp b/aosfxplayer.cpp index cc2f383..03a3ac5 100644 --- a/aosfxplayer.cpp +++ b/aosfxplayer.cpp @@ -19,7 +19,7 @@ void AOSfxPlayer::play(QString p_sfx, QString p_char) p_sfx = p_sfx.toLower(); QString f_path; if (p_char != "") - f_path = ao_app->get_character_path(p_char) + p_sfx; + f_path = ao_app->get_character_path(p_char, p_sfx); else f_path = ao_app->get_sounds_path() + p_sfx; diff --git a/charselect.cpp b/charselect.cpp index 4e4bccb..5686dd8 100644 --- a/charselect.cpp +++ b/charselect.cpp @@ -140,12 +140,11 @@ void Courtroom::char_clicked(int n_char) { int n_real_char = n_char + current_char_page * max_chars_on_page; - QString char_ini_path = ao_app->get_character_path(char_list.at(n_real_char).name) + "char.ini"; + QString char_ini_path = ao_app->get_character_path(char_list.at(n_real_char).name, "char.ini"); qDebug() << "char_ini_path" << char_ini_path; if (!file_exists(char_ini_path)) { - qDebug() << "did not find " << char_ini_path; call_notice("Could not find " + char_ini_path); return; } diff --git a/courtroom.cpp b/courtroom.cpp index 5c3f966..372d4b9 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -319,7 +319,7 @@ void Courtroom::set_widgets() //the size of the ui_vp_legacy_desk element relies on various factors and is set in set_scene() double y_modifier = 147.0 / 192.0; - int final_y = y_modifier * ui_viewport->height(); + int final_y = static_cast(y_modifier * ui_viewport->height()); ui_vp_legacy_desk->move(0, final_y); ui_vp_legacy_desk->hide(); @@ -620,11 +620,10 @@ void Courtroom::set_background(QString p_background) testimony_in_progress = false; current_background = p_background; - QString bg_path = get_background_path(); - is_ao2_bg = file_exists(bg_path + "defensedesk.png") && - file_exists(bg_path + "prosecutiondesk.png") && - file_exists(bg_path + "stand.png"); + is_ao2_bg = file_exists(ao_app->get_background_path("defensedesk.png")) && + file_exists(ao_app->get_background_path("prosecutiondesk.png")) && + file_exists(ao_app->get_background_path("stand.png")); if (is_ao2_bg) { @@ -696,11 +695,9 @@ void Courtroom::enter_courtroom(int p_cid) ui_prosecution_plus->hide(); } - QString char_path = ao_app->get_character_path(current_char); - if (ao_app->custom_objection_enabled && - file_exists(char_path + "custom.gif") && - file_exists(char_path + "custom.wav")) + file_exists(ao_app->get_character_path(current_char, "custom.gif")) && + file_exists(ao_app->get_character_path(current_char, "custom.wav"))) ui_custom_objection->show(); else ui_custom_objection->hide(); @@ -1197,12 +1194,12 @@ void Courtroom::play_preanim() sfx_delay_timer->start(sfx_delay); - if (!file_exists(ao_app->get_character_path(f_char) + f_preanim.toLower() + ".gif") || + if (!file_exists(ao_app->get_character_path(f_char, f_preanim.toLower() + ".gif")) || preanim_duration < 0) { anim_state = 1; preanim_done(); - qDebug() << "could not find " + ao_app->get_character_path(f_char) + f_preanim.toLower() + ".gif"; + qDebug() << "could not find " + ao_app->get_character_path(f_char, f_preanim.toLower() + ".gif"); return; } diff --git a/courtroom.h b/courtroom.h index 3c937b9..286ae7e 100644 --- a/courtroom.h +++ b/courtroom.h @@ -100,13 +100,10 @@ public: //send a message that the player is banned and quits the server void set_ban(int p_cid); - //implementations in path_functions.cpp - QString get_background_path(); - QString get_default_background_path(QString p_file); - //cid = character id, returns the cid of the currently selected character int get_cid() {return m_cid;} QString get_current_char() {return current_char;} + QString get_current_background() {return current_background;} //properly sets up some varibles: resets user state void enter_courtroom(int p_cid); diff --git a/evidence.cpp b/evidence.cpp index 19ffecf..4562136 100644 --- a/evidence.cpp +++ b/evidence.cpp @@ -195,7 +195,7 @@ void Courtroom::on_evidence_image_button_clicked() dialog.setFileMode(QFileDialog::ExistingFile); dialog.setNameFilter(tr("Images (*.png)")); dialog.setViewMode(QFileDialog::List); - dialog.setDirectory(ao_app->get_evidence_path()); + dialog.setDirectory(ao_app->get_base_path() + "evidence"); QStringList filenames; diff --git a/path_functions.cpp b/path_functions.cpp index 5c4972f..83e4752 100644 --- a/path_functions.cpp +++ b/path_functions.cpp @@ -46,91 +46,128 @@ QString AOApplication::get_data_path() return get_base_path() + "data/"; } -QString AOApplication::get_theme_path() -{ - return get_base_path() + "themes/" + current_theme.toLower() + "/"; -} - -QString AOApplication::get_default_theme_path() -{ - return get_base_path() + "themes/default/"; -} - -QString AOApplication::get_character_path(QString p_character) -{ - return get_base_path() + "characters/" + p_character.toLower() + "/"; -} - -QString AOApplication::get_demothings_path() -{ - QString default_path = "misc/demothings/"; - QString alt_path = "misc/RosterImages"; - if (dir_exists(default_path)) - return get_base_path() + default_path; - else if (dir_exists(alt_path)) - return get_base_path() + alt_path; - else - return get_base_path() + default_path; -} -QString AOApplication::get_sounds_path() -{ - return get_base_path() + "sounds/general/"; -} -QString AOApplication::get_music_path(QString p_song) +QString AOApplication::get_default_theme_path(QString p_file) { + QString path = get_base_path() + "themes/default/" + p_file; #ifndef CASE_SENSITIVE_FILESYSTEM - return get_base_path() + "sounds/music/" + p_song; + return path; #else - return get_case_sensitive_path(get_base_path() + "sounds/music/", p_song); + return get_case_sensitive_path(path); #endif } -QString AOApplication::get_background_path() +//assume that the capitalization of the theme in config is correct +QString AOApplication::get_theme_path(QString p_file) { - if (courtroom_constructed) - return w_courtroom->get_background_path(); + QString path = get_base_path() + "themes/" + current_theme + "/" + p_file; +#ifndef CASE_SENSITIVE_FILESYSTEM + return path; +#else + return get_case_sensitive_path(path); +#endif +} + +QString AOApplication::get_character_path(QString p_character, QString p_file) +{ + QString char_path = get_base_path() + "characters/" + p_character; +#ifndef CASE_SENSITIVE_FILESYSTEM + return char_path + "/" + p_file; +#else + //need two calls to get_case_sensitive_path because character folder name may be wrong as well as the filename + return get_case_sensitive_path( + get_case_sensitive_path(char_path) + "/" + p_file); +#endif +} + +QString AOApplication::get_character_emotions_path(QString p_character, QString p_file) +{ + QString char_path = get_base_path() + "characters/" + p_character; +#ifndef CASE_SENSITIVE_FILESYSTEM + return char_path + "/emotions/" + p_file; +#else + return get_case_sensitive_path( + get_case_sensitive_path(char_path) + "/emotions/" + p_file); +#endif +} + +QString AOApplication::get_sounds_path() +{ + QString path = get_base_path() + "sounds/general/"; +#ifndef CASE_SENSITIVE_FILESYSTEM + return path; +#else + return get_case_sensitive_path(path); +#endif +} + +QString AOApplication::get_music_path(QString p_song) +{ + QString path = get_base_path() + "sounds/music/" + p_song; +#ifndef CASE_SENSITIVE_FILESYSTEM + return path; +#else + return get_case_sensitive_path(path); +#endif +} + +QString AOApplication::get_background_path(QString p_file) +{ + QString bg_path = get_base_path() + "background/" + w_courtroom->get_current_background(); + if (courtroom_constructed) { +#ifndef CASE_SENSITIVE_FILESYSTEM + return bg_path + "/" + p_file; +#else + return get_case_sensitive_path( + get_case_sensitive_path(bg_path) + "/" + p_file); +#endif + } //this function being called when the courtroom isn't constructed makes no sense return ""; } -QString AOApplication::get_default_background_path() +QString AOApplication::get_default_background_path(QString p_file) { - return get_base_path() + "background/default/"; + QString path = get_base_path() + "background/default/" + p_file; +#ifndef CASE_SENSITIVE_FILESYSTEM + return path; +#else + return get_case_sensitive_path(path); +#endif } -QString AOApplication::get_evidence_path() +QString AOApplication::get_evidence_path(QString p_file) { - QString default_path = "evidence/"; - QString alt_path = "items/"; - if (dir_exists(default_path)) - return get_base_path() + default_path; - else if (dir_exists(alt_path)) - return get_base_path() + alt_path; - else - return get_base_path() + default_path; + QString path = get_base_path() + "evidence/" + p_file; +#ifndef CASE_SENSITIVE_FILESYSTEM + return path; +#else + return get_case_sensitive_path(path); +#endif } -QString AOApplication::get_case_sensitive_path(QString p_dir, QString p_file) { - qDebug() << "calling get_case_sensitive_path"; - QRegExp file_rx = QRegExp(p_file, Qt::CaseInsensitive); - QStringList files = QDir(p_dir).entryList(); +QString AOApplication::get_case_sensitive_path(QString p_file) { + qDebug() << "calling get_case_sensitive_path: " << p_file; + + QFileInfo file(p_file); + + //quick check to see if it's actually there first + if (file.exists()) return p_file; + + QString file_name = file.fileName(); + + qDebug() << "file_name: " << file_name; + + QString file_path = file.absolutePath(); + + qDebug() << "file_path: " << file_path; + + QRegExp file_rx = QRegExp(file_name, Qt::CaseInsensitive); + QStringList files = QDir(file_path).entryList(); int result = files.indexOf(file_rx); - if (result != -1) { - QString path = p_dir + files.at(result); - qDebug() << "returning " << path; - return path; - } + if (result != -1) + return file_path + "/" + files.at(result); + //if nothing is found, let the caller handle the missing file - return p_dir + p_file; -} - -QString Courtroom::get_background_path() -{ - return ao_app->get_base_path() + "background/" + current_background.toLower() + "/"; -} - -QString Courtroom::get_default_background_path() -{ - return ao_app->get_base_path() + "background/default/"; + return p_file; } diff --git a/text_file_functions.cpp b/text_file_functions.cpp index 1aebc35..e31ff86 100644 --- a/text_file_functions.cpp +++ b/text_file_functions.cpp @@ -212,8 +212,8 @@ QString AOApplication::read_design_ini(QString p_identifier, QString p_design_pa QPoint AOApplication::get_button_spacing(QString p_identifier, QString p_file) { - QString design_ini_path = get_theme_path() + p_file; - QString default_path = get_default_theme_path() + p_file; + QString design_ini_path = get_theme_path(p_file); + QString default_path = get_default_theme_path(p_file); QString f_result = read_design_ini(p_identifier, design_ini_path); QPoint return_value; @@ -242,8 +242,8 @@ QPoint AOApplication::get_button_spacing(QString p_identifier, QString p_file) pos_size_type AOApplication::get_element_dimensions(QString p_identifier, QString p_file) { - QString design_ini_path = get_theme_path() + p_file; - QString default_path = get_default_theme_path() + p_file; + QString design_ini_path = get_theme_path(p_file); + QString default_path = get_default_theme_path(p_file); QString f_result = read_design_ini(p_identifier, design_ini_path); pos_size_type return_value; @@ -276,8 +276,8 @@ pos_size_type AOApplication::get_element_dimensions(QString p_identifier, QStrin int AOApplication::get_font_size(QString p_identifier, QString p_file) { - QString design_ini_path = get_theme_path() + p_file; - QString default_path = get_default_theme_path() + p_file; + QString design_ini_path = get_theme_path(p_file); + QString default_path = get_default_theme_path(p_file); QString f_result = read_design_ini(p_identifier, design_ini_path); if (f_result == "") @@ -293,8 +293,8 @@ int AOApplication::get_font_size(QString p_identifier, QString p_file) QColor AOApplication::get_color(QString p_identifier, QString p_file) { - QString design_ini_path = get_theme_path() + p_file; - QString default_path = get_default_theme_path() + p_file; + QString design_ini_path = get_theme_path(p_file); + QString default_path = get_default_theme_path(p_file); QString f_result = read_design_ini(p_identifier, design_ini_path); QColor return_color(255, 255, 255); @@ -321,8 +321,8 @@ QColor AOApplication::get_color(QString p_identifier, QString p_file) QString AOApplication::get_sfx(QString p_identifier) { - QString design_ini_path = get_theme_path() + "courtroom_sounds.ini"; - QString default_path = get_default_theme_path() + "courtroom_sounds.ini"; + QString design_ini_path = get_theme_path("courtroom_sounds.ini"); + QString default_path = get_default_theme_path("courtroom_sounds.ini"); QString f_result = read_design_ini(p_identifier, design_ini_path); QString return_sfx = ""; @@ -344,7 +344,7 @@ QString AOApplication::get_sfx(QString p_identifier) //returns the empty string if the search line couldnt be found QString AOApplication::read_char_ini(QString p_char, QString p_search_line, QString target_tag, QString terminator_tag) { - QString char_ini_path = get_character_path(p_char) + "char.ini"; + QString char_ini_path = get_character_path(p_char, "char.ini"); QFile char_ini; @@ -586,4 +586,4 @@ bool AOApplication::ic_scroll_down_enabled() { QString f_result = read_config("ic_scroll_down"); return f_result.startsWith("true"); -} \ No newline at end of file +}