Skip to content

Commit

Permalink
Settings: Add pref path on settings dialog.
Browse files Browse the repository at this point in the history
Settings: Add Log Level on Setting Dialog and fix it.
Settings: Add path background image and fix alpha.
Gui: Set game Background with Hovered cursor on game icon.
Gui: restore user background with hovered app ver/title.
  • Loading branch information
Zangetsu38 committed May 10, 2019
1 parent 149b18a commit ce8697a
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 42 deletions.
20 changes: 11 additions & 9 deletions src/emulator/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,18 @@ bool serialize(Config &cfg) {
config_file_emit_single(emitter, "log-uniforms", cfg.log_uniforms);
config_file_emit_single(emitter, "pstv-mode", cfg.pstv_mode);
config_file_emit_single(emitter, "show-gui", cfg.show_gui);
config_file_emit_single(emitter, "show-game-background", cfg.show_game_background);
config_file_emit_single(emitter, "icon-size", cfg.icon_size);
config_file_emit_single(emitter, "archive-log", cfg.archive_log);
config_file_emit_single(emitter, "texture-cache", cfg.texture_cache);
config_file_emit_single(emitter, "sys-button", cfg.sys_button);
config_file_emit_single(emitter, "sys-lang", cfg.sys_lang);
config_file_emit_single(emitter, "background-image", cfg.background_image);
config_file_emit_single(emitter, "background-alpha", cfg.background_alpha);
config_file_emit_single(emitter, "log-level", cfg.log_level);
config_file_emit_single(emitter, "pref-path", cfg.pref_path);
config_file_emit_vector(emitter, "lle-modules", cfg.lle_modules);
config_file_emit_optional_single(emitter, "log-level", cfg.log_level);
config_file_emit_optional_single(emitter, "pref-path", cfg.pref_path);
config_file_emit_optional_single(emitter, "wait-for-debugger", cfg.wait_for_debugger);
config_file_emit_optional_single(emitter, "background-image", cfg.background_image);

emitter << YAML::EndMap;

Expand Down Expand Up @@ -135,16 +136,17 @@ static bool deserialize(Config &cfg) {
get_yaml_value(config_node, "log-uniforms", &cfg.log_uniforms, false);
get_yaml_value(config_node, "pstv-mode", &cfg.pstv_mode, false);
get_yaml_value(config_node, "show-gui", &cfg.show_gui, false);
get_yaml_value(config_node, "show-game-background", &cfg.show_game_background, true);
get_yaml_value(config_node, "icon-size", &cfg.icon_size, static_cast<int>(64));
get_yaml_value(config_node, "archive-log", &cfg.archive_log, false);
get_yaml_value(config_node, "texture-cache", &cfg.texture_cache, true);
get_yaml_value(config_node, "sys-button", &cfg.sys_button, static_cast<int>(SCE_SYSTEM_PARAM_ENTER_BUTTON_CROSS));
get_yaml_value(config_node, "sys-lang", &cfg.sys_lang, static_cast<int>(SCE_SYSTEM_PARAM_LANG_ENGLISH_US));
get_yaml_value(config_node, "background-image", &cfg.background_image, std::string{});
get_yaml_value(config_node, "background-alpha", &cfg.background_alpha, 0.000f);
get_yaml_value_optional(config_node, "log-level", &cfg.log_level, static_cast<int>(spdlog::level::trace));
get_yaml_value_optional(config_node, "pref-path", &cfg.pref_path);
get_yaml_value(config_node, "log-level", &cfg.log_level, static_cast<int>(spdlog::level::trace));
get_yaml_value(config_node, "pref-path", &cfg.pref_path, std::string{});
get_yaml_value_optional(config_node, "wait-for-debugger", &cfg.wait_for_debugger);
get_yaml_value_optional(config_node, "background-image", &cfg.background_image);

// lle-modules
try {
Expand Down Expand Up @@ -181,7 +183,7 @@ InitResult init(Config &cfg, int argc, char **argv) {
config_desc.add_options()
("archive-log,A", po::bool_switch(&cfg.archive_log), "Makes a duplicate of the log file with TITLE_ID and Game ID as title")
("lle-modules,m", po::value<std::string>(), "Load given (decrypted) OS modules from disk. Separate by commas to specify multiple modules (no spaces). Full path and extension should not be included, the following are assumed: vs0:sys/external/<name>.suprx\nExample: --lle-modules libscemp4,libngs")
("log-level,l", po::value(&cfg.log_level)->default_value(spdlog::level::trace), "logging level:\nTRACE = 0\nDEBUG = 1\nINFO = 2\nWARN = 3\nERROR = 4\nCRITICAL = 5\nOFF = 6")
("log-level,l", po::value(&cfg.log_level), "logging level:\nTRACE = 0\nDEBUG = 1\nINFO = 2\nWARN = 3\nERROR = 4\nCRITICAL = 5\nOFF = 6")
("log-imports,I", po::bool_switch(&cfg.log_imports), "Log Imports")
("log-exports,E", po::bool_switch(&cfg.log_exports), "Log Exports")
("log-active-shaders,S", po::bool_switch(&cfg.log_active_shaders), "Log Active Shaders")
Expand Down Expand Up @@ -228,7 +230,7 @@ InitResult init(Config &cfg, int argc, char **argv) {
return InitResult::QUIT;
}

logging::set_level(static_cast<spdlog::level::level_enum>(*cfg.log_level));
logging::set_level(static_cast<spdlog::level::level_enum>(cfg.log_level));

LOG_INFO_IF(cfg.vpk_path, "input-vpk-path: {}", *cfg.vpk_path);
LOG_INFO_IF(cfg.run_title_id, "input-installed-id: {}", *cfg.run_title_id);
Expand All @@ -240,7 +242,7 @@ InitResult init(Config &cfg, int argc, char **argv) {
modules.pop_back();
LOG_INFO("lle-modules: {}", modules);
}
LOG_INFO_IF(cfg.log_level, "log-level: {}", *cfg.log_level);
LOG_INFO("log-level: {}", cfg.log_level);
LOG_INFO("log-imports: {}", cfg.log_imports);
LOG_INFO("log-exports: {}", cfg.log_exports);
LOG_INFO("log-active-shaders: {}", cfg.log_active_shaders);
Expand Down
3 changes: 3 additions & 0 deletions src/emulator/gui/include/gui/functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

#pragma once

#include <string>

struct HostState;
struct SDL_Window;

Expand All @@ -29,6 +31,7 @@ enum GenericDialogState {
};

void init(HostState &host);
void init_background(HostState &host, const std::string &image_path);
void load_game_background(HostState &host, const std::string &title_id);
void draw_begin(HostState &host);
void draw_end(SDL_Window *window);
Expand Down
2 changes: 1 addition & 1 deletion src/emulator/gui/include/gui/state.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ struct State {
std::vector<std::string> disassembly;

GLuint current_background = 0;
GLObject background_texture;
std::map<std::string, GLObject> game_backgrounds;
std::map<std::string, GLObject> user_backgrounds;

SceUID thread_watch_index = -1;

Expand Down
27 changes: 19 additions & 8 deletions src/emulator/gui/src/game_selector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ void draw_game_selector(HostState &host) {

ImGui::SetNextWindowPos(ImVec2(0, MENUBAR_HEIGHT), ImGuiSetCond_Always);
ImGui::SetNextWindowSize(ImVec2(display_size.x, display_size.y - MENUBAR_HEIGHT), ImGuiSetCond_Always);
ImGui::SetNextWindowBgAlpha(host.cfg.background_alpha);
if (host.gui.current_background)
ImGui::SetNextWindowBgAlpha(host.cfg.background_alpha);
ImGui::Begin("Game Selector", nullptr, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoSavedSettings);

static ImGuiTextFilter search_bar;
Expand Down Expand Up @@ -169,21 +170,31 @@ void draw_game_selector(HostState &host) {
continue;
if (host.gui.game_selector.icons[game.title_id]) {
GLuint texture = host.gui.game_selector.icons[game.title_id].get();
if (ImGui::ImageButton(reinterpret_cast<void *>(texture), ImVec2(icon_size, icon_size))) {
if (!host.gui.game_backgrounds[game.title_id]) {
load_game_background(host, game.title_id);
ImGui::ImageButton(reinterpret_cast<void *>(texture), ImVec2(icon_size, icon_size));
if (ImGui::IsItemHovered()) {
if (host.cfg.show_game_background) {
if (!host.gui.game_backgrounds[game.title_id])
load_game_background(host, game.title_id);
else if (host.gui.game_backgrounds[game.title_id])
host.gui.current_background = host.gui.game_backgrounds[game.title_id];
}
if (host.gui.game_backgrounds[game.title_id]) {
host.gui.current_background = host.gui.game_backgrounds[game.title_id];
}
//selected[0] = true;
if (ImGui::IsMouseClicked(0))
selected[0] = true;
}
}
ImGui::NextColumn();
ImGui::Selectable(game.title_id.c_str(), &selected[1], ImGuiSelectableFlags_SpanAllColumns, ImVec2(0, icon_size));
ImGui::NextColumn();
ImGui::Selectable(game.app_ver.c_str(), &selected[2], ImGuiSelectableFlags_SpanAllColumns, ImVec2(0, icon_size));
ImGui::NextColumn();
if (ImGui::IsItemHovered()) {
if (host.cfg.show_game_background) {
if (host.gui.user_backgrounds[host.cfg.background_image])
host.gui.current_background = host.gui.user_backgrounds[host.cfg.background_image];
else if (!host.gui.user_backgrounds[host.cfg.background_image])
host.gui.current_background = 0;
}
}
ImGui::Selectable(game.title.c_str(), &selected[3], ImGuiSelectableFlags_SpanAllColumns, ImVec2(0, icon_size));
ImGui::NextColumn();
if (std::find(std::begin(selected), std::end(selected), true) != std::end(selected)) {
Expand Down
31 changes: 18 additions & 13 deletions src/emulator/gui/src/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ static void init_font(State &gui) {
gui.normal_font = io.Fonts->AddFontFromMemoryTTF(gui.font_data.data(), static_cast<int>(font_file_size), 16, &font_config, io.Fonts->GetGlyphRangesJapanese());
}

static void init_background(State &gui, const std::string &image_path) {
void init_background(HostState &host, const std::string &image_path) {
if (!fs::exists(image_path)) {
LOG_INFO("Invalid background file path {}.", image_path);
LOG_WARN("Image doesn't exist: {}.", image_path);
return;
}

Expand All @@ -153,12 +153,12 @@ static void init_background(State &gui, const std::string &image_path) {
stbi_uc *data = stbi_load(image_path.c_str(), &width, &height, nullptr, STBI_rgb_alpha);

if (!data) {
LOG_INFO("Could not load image from {}.", image_path);
LOG_ERROR("Invalid or corrupted image: {}.", image_path);
return;
}

gui.background_texture.init(load_texture(width, height, data), glDeleteTextures);
gui.current_background = host.gui.background_texture.get();
host.gui.user_backgrounds[image_path].init(load_texture(width, height, data), glDeleteTextures);
host.gui.current_background = host.gui.user_backgrounds[image_path];
stbi_image_free(data);
}

Expand All @@ -170,12 +170,12 @@ static void init_icons(HostState &host) {

vfs::read_app_file(buffer, host.pref_path, game.title_id, "sce_sys/icon0.png");
if (buffer.empty()) {
LOG_INFO("Could not load icon or image for title {}.", game.title_id);
LOG_WARN("Icon not found for title {}, {}.", game.title_id, game.title);
continue;
}
stbi_uc *data = stbi_load_from_memory(&buffer[0], buffer.size(), &width, &height, nullptr, STBI_rgb);
if (width != 128 || height != 128) {
LOG_INFO("Invalid icon or image for title {}.", game.title_id);
LOG_ERROR("Invalid icon for title {}, {}.", game.title_id, game.title);
continue;
}
host.gui.game_selector.icons[game.title_id].init(load_texture(width, height, data, GL_RGB), glDeleteTextures);
Expand All @@ -190,12 +190,18 @@ void load_game_background(HostState &host, const std::string &title_id) {

vfs::read_app_file(buffer, host.pref_path, title_id, "sce_sys/pic0.png");
if (buffer.empty()) {
LOG_INFO("Could not load icon or image for title {}.", title_id);
return;
if (vfs::read_app_file(buffer, host.pref_path, title_id, "sce_sys/livearea/contents/template.xml")) {
LOG_INFO("Game background found in template for title {}.", title_id);
vfs::read_app_file(buffer, host.pref_path, title_id, "sce_sys/livearea/contents/bg.png");
vfs::read_app_file(buffer, host.pref_path, title_id, "sce_sys/livearea/contents/bg0.png");
} else {
LOG_WARN("Game background not found for title {}.", title_id);
return;
}
}
stbi_uc *data = stbi_load_from_memory(&buffer[0], buffer.size(), &width, &height, nullptr, STBI_rgb_alpha);
if (!data) {
LOG_INFO("Invalid icon or image for title {}.", title_id);
LOG_ERROR("Invalid game background for title {}.", title_id);
return;
}
host.gui.game_backgrounds[title_id].init(load_texture(width, height, data), glDeleteTextures);
Expand All @@ -209,9 +215,8 @@ void init(HostState &host) {
init_style();
init_font(host.gui);
init_icons(host);
if (host.cfg.background_image) {
init_background(host.gui, host.cfg.background_image.value());
}
if (!host.cfg.background_image.empty())
init_background(host, host.cfg.background_image);
}

void draw_begin(HostState &host) {
Expand Down
39 changes: 36 additions & 3 deletions src/emulator/gui/src/settings_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@

#include "private.h"
#include <config.h>
#include <gui/functions.h>

#include <host/state.h>
#include <misc/cpp/imgui_stdlib.h>

namespace gui {

Expand Down Expand Up @@ -56,13 +59,21 @@ void draw_settings_dialog(HostState &host) {
ImGui::PushStyleColor(ImGuiCol_Text, GUI_COLOR_TEXT_MENUBAR_OPTIONS);
if (ImGui::BeginTabItem("Emulator")) {
ImGui::PopStyleColor();
ImGui::Spacing();
ImGui::Combo("Log Level \nSelect your preferred log level.", &host.cfg.log_level, "Trace\0Debug\0Info\0Warning\0Error\0Critical\0Off\0");
ImGui::Checkbox("Archive Log", &host.cfg.archive_log);
ImGui::SameLine();
if (ImGui::IsItemHovered())
ImGui::SetTooltip("Check the box to enable Archiving Log.");
ImGui::Checkbox("Texture Cache", &host.cfg.texture_cache);
if (ImGui::IsItemHovered())
ImGui::SetTooltip("Uncheck the box to disable texture cache.");
ImGui::Spacing();
ImGui::PushItemWidth(400);
ImGui::InputTextWithHint("Set emulated system storage folder \n(Reboot after change for apply)", "Write your path folder here", &host.cfg.pref_path);
ImGui::PopItemWidth();
if (ImGui::IsItemHovered())
ImGui::SetTooltip("Store game data in your personal folder. \nAdd the path to the folder here.");
ImGui::EndTabItem();
} else {
ImGui::PopStyleColor();
Expand All @@ -75,12 +86,34 @@ void draw_settings_dialog(HostState &host) {
ImGui::Checkbox("GUI Visible", &host.cfg.show_gui);
if (ImGui::IsItemHovered())
ImGui::SetTooltip("Check the box to show GUI after booting a game.");
ImGui::SameLine();
ImGui::Checkbox("Game Background", &host.cfg.show_game_background);
if (ImGui::IsItemHovered())
ImGui::SetTooltip("Uncheck the box to disable viewing Game background.");
ImGui::Spacing();
ImGui::SliderInt("Game Icon Size \nSelect your preferred icon size.", &host.cfg.icon_size, 16, 128);
ImGui::Spacing();
ImGui::SliderFloat("Background Alpha \nSelect your preferred transparent background effect.", &host.cfg.background_alpha, 0.999f, 0.000f);
if (ImGui::IsItemHovered())
ImGui::SetTooltip("Minimum slider is opaque and maximum is transparent.");
ImGui::PushItemWidth(400);
ImGui::InputTextWithHint("Set background image", "Add your path to the image here", &host.cfg.background_image);
ImGui::PopItemWidth();
if (ImGui::Button("Apply Change Image")) {
if (!host.gui.user_backgrounds[host.cfg.background_image])
init_background(host, host.cfg.background_image);
else if (host.gui.user_backgrounds[host.cfg.background_image])
host.gui.current_background = host.gui.user_backgrounds[host.cfg.background_image];
}
ImGui::SameLine();
if (ImGui::Button("Reset Background")) {
host.cfg.background_image.clear();
host.gui.user_backgrounds.clear();
host.gui.current_background = 0;
}
ImGui::Spacing();
if (host.gui.current_background) {
ImGui::SliderFloat("Background Alpha \nSelect your preferred transparent background effect.", &host.cfg.background_alpha, 0.999f, 0.000f);
if (ImGui::IsItemHovered())
ImGui::SetTooltip("The minimum slider is opaque and the maximum is transparent.");
}
ImGui::EndTabItem();
} else {
ImGui::PopStyleColor();
Expand Down
7 changes: 4 additions & 3 deletions src/emulator/host/include/host/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct Config {
optional<std::string> vpk_path;
optional<std::string> run_title_id;
optional<std::string> recompile_shader_path;
optional<int> log_level;
int log_level;
int sys_button;
int sys_lang;
bool log_imports = false;
Expand All @@ -39,11 +39,12 @@ struct Config {
std::vector<std::string> lle_modules;
bool pstv_mode = false;
bool show_gui = false;
optional<std::string> pref_path;
bool show_game_background = true;
std::string pref_path;
bool archive_log = false;
bool texture_cache = true;
optional<bool> wait_for_debugger;
optional<std::string> background_image;
std::string background_image;
float background_alpha;
int icon_size;
};
9 changes: 5 additions & 4 deletions src/emulator/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "sfo.h"

#include <audio/functions.h>
#include <config.h>
#include <glutil/gl.h>
#include <host/state.h>
#include <host/version.h>
Expand Down Expand Up @@ -120,12 +121,11 @@ bool init(HostState &state, Config cfg) {
state.base_path = base_path.get();

// If configuration already provides preference path
if (!state.cfg.pref_path) {
if (state.cfg.pref_path.empty()) {
state.pref_path = pref_path.get();
state.cfg.pref_path = state.pref_path;
} else {
state.pref_path = state.cfg.pref_path.value();
}
} else
state.pref_path = state.cfg.pref_path;

state.window = WindowPtr(SDL_CreateWindow(window_title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, DEFAULT_RES_WIDTH, DEFAULT_RES_HEIGHT, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE), SDL_DestroyWindow);
if (!state.window || !init(state.mem) || !init(state.audio, resume_thread) || !init(state.io, state.pref_path.c_str(), state.base_path.c_str())) {
Expand Down Expand Up @@ -200,5 +200,6 @@ bool init(HostState &state, Config cfg) {
closedir(d);
#endif

config::serialize(state.cfg);
return true;
}
2 changes: 1 addition & 1 deletion src/external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ set_property(TARGET microprofile PROPERTY CXX_STANDARD 11)
target_compile_definitions(microprofile PUBLIC MICROPROFILE_ENABLED=0 MICROPROFILE_GPU_TIMERS=0)

# The imgui target is including both imgui and imgui_club.
add_library(imgui STATIC imgui/imgui.cpp imgui/imgui_draw.cpp imgui/imgui_widgets.cpp)
add_library(imgui STATIC imgui/imgui.cpp imgui/imgui_draw.cpp imgui/imgui_widgets.cpp imgui/misc/cpp/imgui_stdlib.cpp)
target_include_directories(imgui PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/imgui"
"${CMAKE_CURRENT_SOURCE_DIR}/imgui_club/imgui_memory_editor/")

Expand Down

0 comments on commit ce8697a

Please sign in to comment.