From e4462f3fbf0c772fdd72d4ea32ff9d3ac941296c Mon Sep 17 00:00:00 2001 From: Zangetsu38 Date: Thu, 24 Oct 2024 00:55:32 +0200 Subject: [PATCH] gui/themes: Add support of BGM. - Some small improvement and comment added. gui/setting: Check for recent theme updates to avoid unnecessary processing. config & gui/settings dialog: Add control of bgm volume. - Change start screen delay max to 5 min. --- vita3k/config/include/config/config.h | 1 + vita3k/gui/CMakeLists.txt | 4 +- vita3k/gui/include/gui/functions.h | 4 + vita3k/gui/src/gui.cpp | 1 + vita3k/gui/src/home_screen.cpp | 3 + vita3k/gui/src/settings.cpp | 18 +- vita3k/gui/src/settings_dialog.cpp | 5 +- vita3k/gui/src/themes.cpp | 251 ++++++++++++++++++++++++++ vita3k/interface.cpp | 2 + vita3k/main.cpp | 1 + 10 files changed, 282 insertions(+), 8 deletions(-) diff --git a/vita3k/config/include/config/config.h b/vita3k/config/include/config/config.h index 4b74d07c78..f99a59a794 100644 --- a/vita3k/config/include/config/config.h +++ b/vita3k/config/include/config/config.h @@ -89,6 +89,7 @@ enum ScreenshotFormat { code(std::string, "audio-backend", "SDL", audio_backend) \ code(int, "audio-volume", 100, audio_volume) \ code(bool, "ngs-enable", true, ngs_enable) \ + code(int, "bgm-volume", 100, bgm_volume) \ code(int, "sys-button", static_cast(SCE_SYSTEM_PARAM_ENTER_BUTTON_CROSS), sys_button) \ code(int, "sys-lang", static_cast(SCE_SYSTEM_PARAM_LANG_ENGLISH_US), sys_lang) \ code(int, "sys-date-format", (int)SCE_SYSTEM_PARAM_DATE_FORMAT_MMDDYYYY, sys_date_format) \ diff --git a/vita3k/gui/CMakeLists.txt b/vita3k/gui/CMakeLists.txt index f9553f1b1c..5d30793a39 100644 --- a/vita3k/gui/CMakeLists.txt +++ b/vita3k/gui/CMakeLists.txt @@ -50,6 +50,6 @@ add_library( ) target_include_directories(gui PUBLIC include ${CMAKE_SOURCE_DIR}/vita3k) -target_link_libraries(gui PUBLIC app compat config dialog emuenv ime imgui lang regmgr np) -target_link_libraries(gui PRIVATE audio cppcommon ctrl kernel miniz psvpfsparser pugixml::pugixml stb renderer packages sdl2 touch vkutil host::dialog concurrentqueue) +target_link_libraries(gui PUBLIC app codec compat config dialog emuenv ime imgui lang regmgr np) +target_link_libraries(gui PRIVATE audio cubeb cppcommon ctrl kernel miniz psvpfsparser pugixml::pugixml stb renderer packages sdl2 touch vkutil host::dialog concurrentqueue) target_link_libraries(gui PUBLIC tracy) diff --git a/vita3k/gui/include/gui/functions.h b/vita3k/gui/include/gui/functions.h index 0cb5576e80..e7e7f47d4d 100644 --- a/vita3k/gui/include/gui/functions.h +++ b/vita3k/gui/include/gui/functions.h @@ -69,6 +69,7 @@ void init(GuiState &gui, EmuEnvState &emuenv); void init_app_background(GuiState &gui, EmuEnvState &emuenv, const std::string &app_path); void init_app_icon(GuiState &gui, EmuEnvState &emuenv, const std::string &app_path); void init_apps_icon(GuiState &gui, EmuEnvState &emuenv, const std::vector &app_list); +void init_bgm_player(const float vol); void init_config(GuiState &gui, EmuEnvState &emuenv, const std::string &app_path); void init_content_manager(GuiState &gui, EmuEnvState &emuenv); vfs::FileBuffer init_default_icon(GuiState &gui, EmuEnvState &emuenv); @@ -103,6 +104,9 @@ void save_apps_cache(GuiState &gui, EmuEnvState &emuenv); void save_user(GuiState &gui, EmuEnvState &emuenv, const std::string &user_id); void set_config(GuiState &gui, EmuEnvState &emuenv, const std::string &app_path); void set_shaders_compiled_display(GuiState &gui, EmuEnvState &emuenv); +void set_bgm_volume(const float volume); +void stop_bgm_theme(); +void switch_bgm_state(const bool pause); void update_app(GuiState &gui, EmuEnvState &emuenv, const std::string &app_path); void update_last_time_app_used(GuiState &gui, EmuEnvState &emuenv, const std::string &app); void update_live_area_current_open_apps_list(GuiState &gui, EmuEnvState &emuenv, const std::string &app_path); diff --git a/vita3k/gui/src/gui.cpp b/vita3k/gui/src/gui.cpp index 0045137355..0171cdc987 100644 --- a/vita3k/gui/src/gui.cpp +++ b/vita3k/gui/src/gui.cpp @@ -524,6 +524,7 @@ void init_home(GuiState &gui, EmuEnvState &emuenv) { } init_app_background(gui, emuenv, "NPXS10015"); + init_bgm_player(emuenv.cfg.bgm_volume / 100.f); regmgr::init_regmgr(emuenv.regmgr, emuenv.pref_path); diff --git a/vita3k/gui/src/home_screen.cpp b/vita3k/gui/src/home_screen.cpp index e169588ec7..0bbef43561 100644 --- a/vita3k/gui/src/home_screen.cpp +++ b/vita3k/gui/src/home_screen.cpp @@ -144,6 +144,7 @@ void pre_load_app(GuiState &gui, EmuEnvState &emuenv, bool live_area, const std: } void pre_run_app(GuiState &gui, EmuEnvState &emuenv, const std::string &app_path) { + switch_bgm_state(true); const auto is_sys = app_path.starts_with("NPXS") && (app_path != "NPXS10007"); if (!is_sys) { if (emuenv.io.app_path != app_path) { @@ -213,6 +214,7 @@ void close_system_app(GuiState &gui, EmuEnvState &emuenv) { gui.vita_area.information_bar = true; gui.vita_area.home_screen = true; } + switch_bgm_state(false); } void close_and_run_new_app(GuiState &gui, EmuEnvState &emuenv, const std::string &app_path) { @@ -544,6 +546,7 @@ void draw_home_screen(GuiState &gui, EmuEnvState &emuenv) { gui.vita_area.home_screen = false; gui.vita_area.information_bar = true; gui.vita_area.start_screen = true; + switch_bgm_state(true); } } } diff --git a/vita3k/gui/src/settings.cpp b/vita3k/gui/src/settings.cpp index 2b43be8acb..6fd506d35d 100644 --- a/vita3k/gui/src/settings.cpp +++ b/vita3k/gui/src/settings.cpp @@ -47,12 +47,8 @@ struct Theme { static std::map themes_info; static std::vector> themes_list; - +static time_t last_update_themes = 0; static void get_themes_list(GuiState &gui, EmuEnvState &emuenv) { - gui.themes_preview.clear(); - themes_info.clear(); - themes_list.clear(); - const auto theme_path{ emuenv.pref_path / "ux0/theme" }; const auto fw_theme_path{ emuenv.pref_path / "vs0/data/internal/theme" }; if ((!fs::exists(fw_theme_path) || fs::is_empty(fw_theme_path)) && (!fs::exists(theme_path) || fs::is_empty(theme_path))) { @@ -60,6 +56,16 @@ static void get_themes_list(GuiState &gui, EmuEnvState &emuenv) { return; } + // Check if the theme has been updated recently to avoid unnecessary updates + if ((fs::last_write_time(theme_path) < last_update_themes) && (fs::last_write_time(fw_theme_path) < last_update_themes)) { + LOG_INFO("No updates found for themes list. Last updated:\n{}", std::ctime(&last_update_themes)); + return; + } + + gui.themes_preview.clear(); + themes_info.clear(); + themes_list.clear(); + std::string user_lang; const auto sys_lang = static_cast(emuenv.cfg.sys_lang); switch (sys_lang) { @@ -180,6 +186,8 @@ static void get_themes_list(GuiState &gui, EmuEnvState &emuenv) { } } } + + last_update_themes = time(0); } static std::string popup, menu, sub_menu, selected, title, delete_user_background, delete_theme; diff --git a/vita3k/gui/src/settings_dialog.cpp b/vita3k/gui/src/settings_dialog.cpp index 9c6550e3b5..22b33dab7a 100644 --- a/vita3k/gui/src/settings_dialog.cpp +++ b/vita3k/gui/src/settings_dialog.cpp @@ -380,6 +380,7 @@ static void save_config(GuiState &gui, EmuEnvState &emuenv) { app::update_viewport(emuenv); } + set_bgm_volume(emuenv.cfg.bgm_volume / 100.f); config::serialize_config(emuenv.cfg, emuenv.cfg.config_path); } @@ -813,6 +814,8 @@ void draw_settings_dialog(GuiState &gui, EmuEnvState &emuenv) { ImGui::Checkbox(lang.audio["enable_ngs_support"].c_str(), &config.ngs_enable); SetTooltipEx(lang.audio["ngs_description"].c_str()); ImGui::Spacing(); + ImGui::SliderInt("Bgm Volume", &emuenv.cfg.bgm_volume, 0, 100, "%d %%", ImGuiSliderFlags_AlwaysClamp); + SetTooltipEx("Adjusts the background music volume percentage of the theme"); ImGui::Separator(); ImGui::Spacing(); ImGui::EndTabItem(); @@ -1065,7 +1068,7 @@ void draw_settings_dialog(GuiState &gui, EmuEnvState &emuenv) { SetTooltipEx(lang.gui["select_delay_background"].c_str()); } ImGui::Spacing(); - ImGui::SliderInt(lang.gui["delay_start"].c_str(), &emuenv.cfg.delay_start, 10, 60); + ImGui::SliderInt(lang.gui["delay_start"].c_str(), &emuenv.cfg.delay_start, 10, 300); SetTooltipEx(lang.gui["select_delay_start"].c_str()); ImGui::EndTabItem(); } else diff --git a/vita3k/gui/src/themes.cpp b/vita3k/gui/src/themes.cpp index 34f0d05a11..a60346d36b 100644 --- a/vita3k/gui/src/themes.cpp +++ b/vita3k/gui/src/themes.cpp @@ -17,7 +17,10 @@ #include "private.h" +#include