Skip to content

Commit

Permalink
gui/themes: Add support of BGM.
Browse files Browse the repository at this point in the history
- Some small improvement and comment added.
config & gui/settings dialog: Add control of bgm volume.
- Change start screen delay min to 30 sec and max to 5 min.
codec: Set default value to 0 for send of atrac 9.
  • Loading branch information
Zangetsu38 committed Oct 26, 2024
1 parent 52b82dd commit 05f6038
Show file tree
Hide file tree
Showing 10 changed files with 344 additions and 8 deletions.
2 changes: 1 addition & 1 deletion vita3k/codec/include/codec/state.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ struct Atrac9DecoderState : public DecoderState {
uint32_t get(DecoderQuery query) override;
uint32_t get_es_size() override;

bool send(const uint8_t *data, uint32_t size) override;
bool send(const uint8_t *data, uint32_t size = 0) override;
bool receive(uint8_t *data, DecoderSize *size) override;
void flush() override;

Expand Down
1 change: 1 addition & 0 deletions vita3k/config/include/config/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(SCE_SYSTEM_PARAM_ENTER_BUTTON_CROSS), sys_button) \
code(int, "sys-lang", static_cast<int>(SCE_SYSTEM_PARAM_LANG_ENGLISH_US), sys_lang) \
code(int, "sys-date-format", (int)SCE_SYSTEM_PARAM_DATE_FORMAT_MMDDYYYY, sys_date_format) \
Expand Down
4 changes: 2 additions & 2 deletions vita3k/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 4 additions & 0 deletions vita3k/gui/include/gui/functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<gui::App> &app_list);
void init_bgm(EmuEnvState &emuenv, const std::pair<std::string, std::string> path_bgm);
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);
Expand Down Expand Up @@ -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_volume_bgm(const float vol);
void stop_bgm();
void switch_state_bgm(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);
Expand Down
3 changes: 3 additions & 0 deletions vita3k/gui/src/home_screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_state_bgm(true);
const auto is_sys = app_path.starts_with("NPXS") && (app_path != "NPXS10007");
if (!is_sys) {
if (emuenv.io.app_path != app_path) {
Expand Down Expand Up @@ -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_state_bgm(false);
}

void close_and_run_new_app(GuiState &gui, EmuEnvState &emuenv, const std::string &app_path) {
Expand Down Expand Up @@ -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_state_bgm(true);
}
}
}
Expand Down
18 changes: 14 additions & 4 deletions vita3k/gui/src/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,26 @@ struct Theme {

static std::map<std::string, Theme> themes_info;
static std::vector<std::pair<std::string, time_t>> themes_list;
static time_t last_updated_themes_list = 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))) {
LOG_WARN("Theme path is empty");
return;
}

// Check if the themes list has been updated recently to avoid unnecessary updates
if ((fs::last_write_time(theme_path) <= last_updated_themes_list) && (fs::last_write_time(fw_theme_path) < last_updated_themes_list))
return;
else if (last_updated_themes_list != 0)
LOG_INFO("Found new update of themes list, updating...");

gui.themes_preview.clear();
themes_info.clear();
themes_list.clear();

std::string user_lang;
const auto sys_lang = static_cast<SceSystemParamLang>(emuenv.cfg.sys_lang);
switch (sys_lang) {
Expand Down Expand Up @@ -180,6 +187,8 @@ static void get_themes_list(GuiState &gui, EmuEnvState &emuenv) {
}
}
}

last_updated_themes_list = time(0);
}

static std::string popup, menu, sub_menu, selected, title, delete_user_background, delete_theme;
Expand Down Expand Up @@ -467,6 +476,7 @@ void draw_settings(GuiState &gui, EmuEnvState &emuenv) {
init_theme_start_background(gui, emuenv, "default");
}
fs::remove_all(emuenv.pref_path / "ux0/theme" / fs_utils::utf8_to_path(selected));
last_updated_themes_list = time(0);
if (emuenv.app_path == "NPXS10026")
init_content_manager(gui, emuenv);
delete_theme = selected;
Expand Down
5 changes: 4 additions & 1 deletion vita3k/gui/src/settings_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ static void save_config(GuiState &gui, EmuEnvState &emuenv) {
app::update_viewport(emuenv);
}

set_volume_bgm(emuenv.cfg.bgm_volume);
config::serialize_config(emuenv.cfg, emuenv.cfg.config_path);
}

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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, 30, 300);
SetTooltipEx(lang.gui["select_delay_start"].c_str());
ImGui::EndTabItem();
} else
Expand Down
Loading

0 comments on commit 05f6038

Please sign in to comment.