Skip to content

Commit

Permalink
gui/trophy_collection: Allow to display hidden trophy (Vita3K#3431)
Browse files Browse the repository at this point in the history
  • Loading branch information
nishinji authored Dec 3, 2024
1 parent 19be7c3 commit 7c04fd2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
2 changes: 2 additions & 0 deletions lang/system/en.xml
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,8 @@ You can earn trophies by using an application that supports the trophy feature.<
<grade>Grade</grade>
<progress>Progress</progress>
<updated>Updated</updated>
<advance>Advance</advance>
<show_hidden>Show Hidden Trophies</show_hidden>
</trophy_collection>

<user_management>
Expand Down
44 changes: 27 additions & 17 deletions vita3k/gui/src/trophy_collection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,56 +67,56 @@ static bool load_trophy_progress(IOState &io, const SceUID &progress_input_file,
// Check magic
uint32_t magic;
if (read_trophy_progress_file(&magic, 4) != 4 || magic != TROPHY_USR_MAGIC) {
LOG_ERROR("Fail read stuff magic");
LOG_ERROR("Failed to read stuff magic");
return false;
}

// Read trophy progress
std::fill_n(np_com_id_info[np_com_id].context.trophy_progress, (MAX_TROPHIES >> 5), 0);
if (read_trophy_progress_file(np_com_id_info[np_com_id].context.trophy_progress, sizeof(np_com_id_info[np_com_id].context.trophy_progress)) != sizeof(np_com_id_info[np_com_id].context.trophy_progress)) {
LOG_ERROR("Fail read trophy progress");
LOG_ERROR("Failed to read trophy progress");
return false;
}

// Read trophy availability
if (read_trophy_progress_file(np_com_id_info[np_com_id].context.trophy_availability, sizeof(np_com_id_info[np_com_id].context.trophy_availability)) != sizeof(np_com_id_info[np_com_id].context.trophy_availability)) {
LOG_ERROR("Fail read trophy availability");
LOG_ERROR("Failed to read trophy availability");
return false;
}

// Read group count
if (read_trophy_progress_file(&np_com_id_info[np_com_id].context.group_count, 4) != 4) {
LOG_ERROR("Fail read count group id");
LOG_ERROR("Failed to read count group id");
return false;
}

// Read trophy count
if (read_trophy_progress_file(&np_com_id_info[np_com_id].context.trophy_count, 4) != 4) {
LOG_ERROR("Fail read trophy count");
LOG_ERROR("Failed to read trophy count");
return false;
}

// Read platinum trophy ID
if (read_trophy_progress_file(&np_com_id_info[np_com_id].context.platinum_trophy_id, 4) != 4) {
LOG_ERROR("Fail read platinum trophy ID");
LOG_ERROR("Failed to read platinum trophy ID");
return false;
}

// Read trophy count by group
if (read_trophy_progress_file(np_com_id_info[np_com_id].context.trophy_count_by_group.data(), (uint32_t)np_com_id_info[np_com_id].context.trophy_count_by_group.size() * 4) != (int)np_com_id_info[np_com_id].context.trophy_count_by_group.size() * 4) {
LOG_ERROR("Fail read trophy count by group");
LOG_ERROR("Failed to read trophy count by group");
return false;
}

// Read trophy timestamps
if (read_trophy_progress_file(np_com_id_info[np_com_id].context.unlock_timestamps.data(), (uint32_t)np_com_id_info[np_com_id].context.unlock_timestamps.size() * 8) != (int)np_com_id_info[np_com_id].context.unlock_timestamps.size() * 8) {
LOG_ERROR("Fail read unlock_timestamp");
LOG_ERROR("Failed to read unlock_timestamp");
return false;
}

// Read trophy type
if (read_trophy_progress_file(np_com_id_info[np_com_id].context.trophy_kinds.data(), (uint32_t)np_com_id_info[np_com_id].context.trophy_kinds.size() * 4) != (int)np_com_id_info[np_com_id].context.trophy_kinds.size() * 4) {
LOG_ERROR("Fail read trophy type");
LOG_ERROR("Failed to read trophy type");
return false;
}

Expand All @@ -129,6 +129,7 @@ enum class NpComIdSortType {
PROGRESS
};
static NpComIdSortType np_com_id_sort;
bool show_hidden_trophy = false;

void init_trophy_collection(GuiState &gui, EmuEnvState &emuenv) {
const auto TROPHY_PATH{ emuenv.pref_path / "ux0/user" / emuenv.io.user_id / "trophy" };
Expand Down Expand Up @@ -162,7 +163,7 @@ void init_trophy_collection(GuiState &gui, EmuEnvState &emuenv) {
const auto progress_input_file = open_file(emuenv.io, trophy_progress_save_file.c_str(), SCE_O_RDONLY, emuenv.pref_path, "load_trophy_progress_file");

if (!load_trophy_progress(emuenv.io, progress_input_file, np_com_id)) {
LOG_ERROR("Fail load trophy progress for Np Com ID: {}, clean trophy file.", np_com_id);
LOG_ERROR("Failed to load trophy progress for Np Com ID: {}, cleaning the trophy file.", np_com_id);
close_file(emuenv.io, progress_input_file, "load_trophy_progress_file");
fs::remove_all(trophy_data_np_com_id_path);
fs::remove_all(trophy_conf_np_com_id_path);
Expand Down Expand Up @@ -705,14 +706,14 @@ void draw_trophy_collection(GuiState &gui, EmuEnvState &emuenv) {
ImGui::NextColumn();
const auto hidden_trophy = (!trophy_info[trophy.id].earned && (trophy_info[trophy.id].hidden == "yes"));
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + (14.f * SCALE.y));
ImGui::TextColored(GUI_COLOR_TEXT, "%s", hidden_trophy ? "?" : trophy_info[trophy.id].type["general"].c_str());
ImGui::TextColored(GUI_COLOR_TEXT, "%s", hidden_trophy && !show_hidden_trophy ? "?" : trophy_info[trophy.id].type["general"].c_str());
ImGui::NextColumn();
ImGui::PushStyleVar(ImGuiStyleVar_SelectableTextAlign, ImVec2(0.f, 0.2f));
const auto name_pos = ImGui::GetCursorPosY();
if (ImGui::Selectable(hidden_trophy ? hidden_trophy_str : trophy.name.c_str(), false, ImGuiSelectableFlags_SpanAllColumns, ImVec2(0.f, SIZE_TROPHY_LIST.y)))
if (ImGui::Selectable(hidden_trophy && !show_hidden_trophy ? hidden_trophy_str : trophy.name.c_str(), false, ImGuiSelectableFlags_SpanAllColumns, ImVec2(0.f, SIZE_TROPHY_LIST.y)))
trophy_id_selected = trophy.id;
ImGui::PopStyleVar();
if (!hidden_trophy) {
if (!hidden_trophy || show_hidden_trophy) {
ImGui::SetCursorPosY(name_pos + (40.f * SCALE.y));
ImGui::SetWindowFontScale(1.0f * RES_SCALE.x);
ImGui::Text("%s", trophy_info[trophy.id].detail.c_str());
Expand All @@ -730,7 +731,7 @@ void draw_trophy_collection(GuiState &gui, EmuEnvState &emuenv) {
ImGui::TextColored(GUI_COLOR_TEXT, "%s", lang["locked"].c_str());
}
const auto hidden_trophy = (!trophy_info[trophy_id_selected].earned && (trophy_info[trophy_id_selected].hidden == "yes"));
const auto selected_trophy_str = hidden_trophy ? hidden_trophy_str : trophy_info[trophy_id_selected].name.c_str();
const auto selected_trophy_str = hidden_trophy && !show_hidden_trophy ? hidden_trophy_str : trophy_info[trophy_id_selected].name.c_str();
const auto CALC_NAME = ImGui::CalcTextSize(selected_trophy_str, nullptr, false, SIZE_INFO.x - SIZE_TROPHY_LIST.x - 48.f).y / 2.f;
ImGui::SetCursorPos(ImVec2(SIZE_TROPHY_LIST.x + 20.f, (SIZE_TROPHY_LIST.y / 2.f) - CALC_NAME));
ImGui::PushTextWrapPos(ImGui::GetCursorPosX() + SIZE_INFO.x - SIZE_TROPHY_LIST.x - (48.f * SCALE.x));
Expand All @@ -739,7 +740,7 @@ void draw_trophy_collection(GuiState &gui, EmuEnvState &emuenv) {
ImGui::SetCursorPosY(SIZE_TROPHY_LIST.y + (25.f * SCALE.y));
ImGui::TextColored(GUI_COLOR_TEXT, "%s", lang["grade"].c_str());
ImGui::SameLine(250.f * SCALE.x);
ImGui::TextColored(GUI_COLOR_TEXT, "%s", hidden_trophy ? "?" : trophy_info[trophy_id_selected].type["detail"].c_str());
ImGui::TextColored(GUI_COLOR_TEXT, "%s", hidden_trophy && !show_hidden_trophy ? "?" : trophy_info[trophy_id_selected].type["detail"].c_str());
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + (25.f * SCALE.y));
ImGui::TextColored(GUI_COLOR_TEXT, "%s", lang["earned"].c_str());
ImGui::SameLine(250.f * SCALE.x);
Expand All @@ -756,7 +757,7 @@ void draw_trophy_collection(GuiState &gui, EmuEnvState &emuenv) {
ImGui::TextColored(GUI_COLOR_TEXT, "%s", lang["details"].c_str());
ImGui::SameLine(250.f * SCALE.x);
ImGui::PushTextWrapPos(SIZE_INFO.x);
ImGui::TextColored(GUI_COLOR_TEXT, "%s", hidden_trophy ? "-" : trophy_info[trophy_id_selected].detail.c_str());
ImGui::TextColored(GUI_COLOR_TEXT, "%s", hidden_trophy && !show_hidden_trophy ? "-" : trophy_info[trophy_id_selected].detail.c_str());
ImGui::PopTextWrapPos();
}
}
Expand Down Expand Up @@ -829,7 +830,7 @@ void draw_trophy_collection(GuiState &gui, EmuEnvState &emuenv) {
ImGui::Spacing();
if (ImGui::MenuItem(gui.lang.indicator["delete_all"].c_str())) {
if (fs::remove_all(TROPHY_PATH))
LOG_INFO("Delete all trophies successfully.");
LOG_INFO("All trophies successfully deleted.");
}
} else {
if (ImGui::MenuItem(lang["original"].c_str(), nullptr, trophy_sort == TrophySortType::ORIGINAL)) {
Expand All @@ -856,6 +857,15 @@ void draw_trophy_collection(GuiState &gui, EmuEnvState &emuenv) {
});
trophy_sort = TrophySortType::NAME;
}
ImGui::Spacing();
ImGui::Separator();
ImGui::Spacing();
ImGui::TextColored(GUI_COLOR_TEXT_TITLE, "%s", lang["advance"].c_str());
ImGui::Spacing();
ImGui::Separator();
ImGui::Spacing();
if (ImGui::MenuItem(lang["show_hidden"].c_str(), nullptr, show_hidden_trophy))
show_hidden_trophy = !show_hidden_trophy;
}
ImGui::EndPopup();
}
Expand Down
4 changes: 3 additions & 1 deletion vita3k/lang/include/lang/state.h
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,9 @@ struct LangState {
{ "trophies", "Trophies" },
{ "grade", "Grade" },
{ "progress", "Progress" },
{ "updated", "Updated" }
{ "updated", "Updated" },
{ "advance", "Advance" },
{ "show_hidden", "Show Hidden Trophies" }
};
std::map<std::string, std::string> user_management = {
{ "select_user", "Select User" },
Expand Down

0 comments on commit 7c04fd2

Please sign in to comment.