Skip to content

Play your Steam library's Windows games on a jailbroken PS5.

C++

Make a game's Collections sheet add and remove the game

Leonardo Lobato558e645a7247
diff --git a/src/homebrew/simulation.cpp b/src/homebrew/simulation.cpp
index 931a46f..9095bf0 100644
--- a/src/homebrew/simulation.cpp
+++ b/src/homebrew/simulation.cpp
@@ -452,7 +452,7 @@ std::string action_label(const std::string& key) {
{"inject-logs-ready", "Inject ready logs"}, {"account-auth", "Authentication"},
{"account-last-sync", "Last library sync"}, {"account-sync", "Sync now"},
{"account-recover", "Reconnect account"}, {"account-switch", "Switch account"},
- {"account-reauth", "Sign in again"}, {"job-resume-all", "Resume all"}, {"job-clear-completed", "Clear completed"},
+ {"account-reauth", "Sign in again"}, {"job-resume-all", "Resume all"}, {"job-clear-completed", "Clear completed"}, {"collection-new", "New collection"}, {"collection-manage", "Manage collections"},
{"about-build", "Build"}, {"about-framework", "Framework"}, {"about-platform", "Platform"},
{"about-kit", "Compatibility kit"}, {"about-kit-source", "Built from"},
{"about-back", "Back"}, {"inject-library-refresh", "Refresh library fixture"},
@@ -710,6 +710,40 @@ void Simulation::UpdateKeptBottles(std::vector<LiveKeptBottle> kept) {
rebuild_view();
}
+std::vector<std::string> Simulation::collection_sheet_actions(const std::string& sheet) const {
+ std::vector<std::string> actions;
+ if (sheet == "collections") {
+ for (const auto& collection : state_.library.collections) actions.push_back("collection-toggle-" + collection.id);
+ actions.push_back("collection-new");
+ if (!state_.library.collections.empty()) actions.push_back("collection-manage");
+ } else {
+ for (const auto& collection : state_.library.collections) {
+ actions.push_back("collection-rename-" + collection.id);
+ actions.push_back("collection-pin-" + collection.id);
+ actions.push_back("collection-delete-" + collection.id);
+ }
+ }
+ actions.push_back("cancel");
+ return actions;
+}
+
+// Open collection sheets list the collections as they are now; `focus` moves the focus to a row.
+void Simulation::refresh_collection_sheets(const std::string& focus) {
+ auto& modals = state_.navigation.modals;
+ for (std::size_t index = 0; index < modals.size(); ++index) {
+ auto& modal = modals[index];
+ if (modal.id != "collections" && modal.id != "collections-manage") continue;
+ const auto focused = focus.empty() && modal.focused_action < static_cast<int>(modal.action_keys.size())
+ ? modal.action_keys[static_cast<std::size_t>(modal.focused_action)] : focus;
+ modal.action_keys = collection_sheet_actions(modal.id);
+ const auto found = std::find(modal.action_keys.begin(), modal.action_keys.end(), focused);
+ modal.focused_action = found == modal.action_keys.end()
+ ? std::min(modal.focused_action, static_cast<int>(modal.action_keys.size()) - 1)
+ : static_cast<int>(found - modal.action_keys.begin());
+ if (index + 1 == modals.size()) state_.navigation.focus_key = modal.action_keys[static_cast<std::size_t>(modal.focused_action)];
+ }
+}
+
std::vector<std::string> Simulation::kept_manager_actions() const {
std::vector<std::string> actions{"kept-select-all"};
for (const auto& kept : state_.kept_bottles) actions.push_back("kept-toggle-" + std::to_string(kept.game_id));
@@ -2796,17 +2830,30 @@ void Simulation::rebuild_view() {
const auto current = rating == state_.library.ratings.end() ? Compatibility::Untested : rating->second;
item.selected = (value == "works" && current == Compatibility::Works) || (value == "playable" && current == Compatibility::Playable)
|| (value == "broken" && current == Compatibility::Broken) || (value == "untested" && current == Compatibility::Untested);
- } else if (action_key.rfind("collection-", 0) == 0 && action_key != "collection-new") {
+ } else if (action_key.rfind("collection-", 0) == 0 && action_key != "collection-new" && action_key != "collection-manage") {
+ // A game's sheet: one checkbox per collection. Manage: rename, pin and delete each one.
const char* prefixes[] = {"collection-toggle-", "collection-rename-", "collection-pin-", "collection-delete-"};
- const char* verbs[] = {"Membership", "Rename", "Pin on Home", "Delete"};
for (std::size_t index = 0; index < 4; ++index) if (action_key.rfind(prefixes[index], 0) == 0) {
const auto id = action_key.substr(std::char_traits<char>::length(prefixes[index]));
const auto found = std::find_if(state_.library.collections.begin(), state_.library.collections.end(), [&id](const Collection& value) { return value.id == id; });
- if (found != state_.library.collections.end()) {
- item.title = std::string(verbs[index]) + ": " + found->name;
- if (index == 0) item.selected = found->members.contains(state_.navigation.selected_game_id);
- if (index == 2) item.selected = found->pinned;
- if (index == 3) item.dangerous = true;
+ if (found == state_.library.collections.end()) continue;
+ const auto count = found->members.size();
+ const std::string games = std::to_string(count) + (count == 1 ? " game" : " games");
+ if (index == 0) {
+ item.kind = RowKind::Toggle;
+ item.title = found->name;
+ item.value = games;
+ item.selected = found->members.contains(state_.navigation.selected_game_id);
+ } else if (index == 1) {
+ item.title = "Rename \u201c" + found->name + "\u201d";
+ item.value = games;
+ } else if (index == 2) {
+ item.title = "Pin \u201c" + found->name + "\u201d on Home";
+ item.selected = found->pinned;
+ item.value = found->pinned ? "On" : "Off";
+ } else {
+ item.title = "Delete \u201c" + found->name + "\u201d";
+ item.dangerous = true;
}
}
}
@@ -3533,7 +3580,18 @@ void Simulation::commit_editor() {
std::string id;
do { id = "collection-" + std::to_string(next_collection_serial_++); }
while (std::any_of(state_.library.collections.begin(), state_.library.collections.end(), [&id](const Collection& value) { return value.id == id; }));
- state_.library.collections.push_back({std::move(id), name, false, {}});
+ // Made from a game's Collections sheet, the new collection holds that game.
+ const bool from_game = std::any_of(state_.navigation.modals.begin(), state_.navigation.modals.end(),
+ [](const ModalEntry& modal) { return modal.id == "collections"; });
+ std::set<GameId> members;
+ if (from_game && state_.navigation.selected_game_id != 0) members.insert(state_.navigation.selected_game_id);
+ const auto new_id = id;
+ state_.library.collections.push_back({std::move(id), name, false, std::move(members)});
+ state_.editor.active = false;
+ state_.navigation.focus_key = state_.editor.opener_focus_key;
+ refresh_collection_sheets("collection-toggle-" + new_id);
+ save_profile();
+ return;
} else if (state_.editor.purpose == "Rename collection") {
const auto name = trimmed(state_.editor.value);
const auto duplicate = std::find_if(state_.library.collections.begin(), state_.library.collections.end(), [this, &name](const Collection& value) { return value.name == name && value.id != editing_target_id_; });
@@ -3543,6 +3601,11 @@ void Simulation::commit_editor() {
return;
}
target->name = name;
+ state_.editor.active = false;
+ state_.navigation.focus_key = state_.editor.opener_focus_key;
+ refresh_collection_sheets();
+ save_profile();
+ return;
}
state_.editor.active = false;
state_.navigation.focus_key = state_.editor.opener_focus_key;
@@ -4564,6 +4627,13 @@ void Simulation::activate() {
state_.navigation.library_rail_focused = false;
reconcile_library_selection(state_);
}
+ // Back to the collection sheets the delete came from, which list what is left.
+ close_modal();
+ pending_destructive_action_.clear();
+ refresh_collection_sheets();
+ save_profile();
+ rebuild_view();
+ return;
}
state_.navigation.modals.clear();
pending_destructive_action_.clear();
@@ -4775,17 +4845,9 @@ void Simulation::activate() {
save_profile(); close_modal();
}
else if (action_name == "edit-note") start_editor("Note", state_.library.notes[state_.navigation.selected_game_id]);
- else if (action_name == "collection") {
- std::vector<std::string> actions;
- for (const auto& collection : state_.library.collections) {
- actions.push_back("collection-toggle-" + collection.id);
- actions.push_back("collection-rename-" + collection.id);
- actions.push_back("collection-pin-" + collection.id);
- actions.push_back("collection-delete-" + collection.id);
- }
- actions.push_back("collection-new"); actions.push_back("cancel");
- open_modal({"collections", "Collections", "collection", std::move(actions), 0, false});
- }
+ else if (action_name == "collection") open_modal({"collections", "Collections", "collection", collection_sheet_actions("collections"), 0, false});
+ else if (action_name == "collection-manage")
+ open_modal({"collections-manage", "Manage collections", "collection-manage", collection_sheet_actions("collections-manage"), 0, false});
else if (action_name == "collection-new") { editing_target_id_.clear(); start_editor("Collection name", ""); }
else if (action_name.rfind("collection-toggle-", 0) == 0) {
const auto id = action_name.substr(18);
@@ -4804,6 +4866,7 @@ void Simulation::activate() {
const auto id = action_name.substr(15);
const auto found = std::find_if(state_.library.collections.begin(), state_.library.collections.end(), [&id](const Collection& value) { return value.id == id; });
if (found != state_.library.collections.end()) { found->pinned = !found->pinned; save_profile(); }
+ refresh_collection_sheets();
}
else if (action_name.rfind("collection-delete-", 0) == 0) {
pending_destructive_action_ = action_name;
diff --git a/src/homebrew/simulation.hpp b/src/homebrew/simulation.hpp
index e69587c..6b0dc96 100644
--- a/src/homebrew/simulation.hpp
+++ b/src/homebrew/simulation.hpp
@@ -747,6 +747,8 @@ private:
void advance_jobs();
[[nodiscard]] std::vector<std::string> game_settings_actions() const;
[[nodiscard]] std::vector<std::string> kept_manager_actions() const;
+ [[nodiscard]] std::vector<std::string> collection_sheet_actions(const std::string& sheet) const;
+ void refresh_collection_sheets(const std::string& focus = {});
void refresh_game_settings();
bool can_change_game_settings();
void set_game_setting(const std::string& id, const std::string& value);
diff --git a/src/homebrew/view.cpp b/src/homebrew/view.cpp
index f1f5034..639eaff 100644
--- a/src/homebrew/view.cpp
+++ b/src/homebrew/view.cpp
@@ -2902,7 +2902,7 @@ class Render::Impl
static const std::map<std::string, std::string> names = {
{"choice-picker", "Game settings"}, {"preset-picker", "Game settings"}, {"button-mapping", "Game settings"},
{"game-settings", "Playden"}, {"game-maintenance", "Playden"}, {"kept-data", "Settings"},
- {"job-actions", "Downloads"}, {"context", "Game"}, {"compatibility", "Game"}, {"collections", "Game"},
+ {"job-actions", "Downloads"}, {"context", "Game"}, {"compatibility", "Game"}, {"collections", "Game"}, {"collections-manage", "Library"},
{"filters", "Library"}, {"logs-controls", "Logs"}, {"setting-value", "Settings"}, {"diagnostics", "Settings"},
{"notices", "Notifications"}, {"qr-controls", "Sign in"}, {"session-controls", "Simulation"},
{"simulation-controls", "Simulation"}, {"scenarios", "Simulation"}};
@@ -3294,7 +3294,8 @@ class Render::Impl
return 54.0F + 12.0F;
if (row.kind == RowKind::Heading || row.kind == RowKind::Separator)
return 54.0F;
- const bool checkbox = view.surface == "kept-data" && row.kind == RowKind::Toggle;
+ const bool checkbox = (view.surface == "kept-data" || (view.surface == "collections" && row.action.rfind("collection-toggle-", 0) == 0)) &&
+ row.kind == RowKind::Toggle;
const bool described = (settings_sheet || checkbox) && !row.subtitle.empty();
return (described ? 96.0F : 72.0F) + 12.0F;
};
@@ -3362,7 +3363,8 @@ class Render::Impl
// Game settings rows carry an effect line under the name (or the reason a row is
// disabled), an accent dot when the player changed the value, and a tag.
// Kept game data: each game is a checkbox row with its kept date under the name.
- const bool checkbox = view.surface == "kept-data" && row.kind == RowKind::Toggle;
+ const bool checkbox = (view.surface == "kept-data" || (view.surface == "collections" && row.action.rfind("collection-toggle-", 0) == 0)) &&
+ row.kind == RowKind::Toggle;
const bool described = (settings_sheet || checkbox) && !row.subtitle.empty() && row.kind != RowKind::Heading;
const gfx::Rect rect{bounds.x, y, bounds.w, described ? 96.0F : 72.0F};
const float amount = control_focus("sheet-" + row.key, index == view.focused_row);
diff --git a/tests/homebrew_controller_tour_test.cpp b/tests/homebrew_controller_tour_test.cpp
index 743dc7b..91807e3 100644
--- a/tests/homebrew_controller_tour_test.cpp
+++ b/tests/homebrew_controller_tour_test.cpp
@@ -71,12 +71,15 @@ int main(int argc, char** argv) {
require(simulation.state().navigation.focus_key == "note", "rating picker restores its context opener");
choose(simulation, "collection");
choose(simulation, "collection-toggle-collection-1");
+ choose(simulation, "collection-manage");
choose(simulation, "collection-pin-collection-1");
choose(simulation, "collection-delete-collection-1");
require(simulation.state().navigation.focus_key == "cancel", "collection deletion defaults to Cancel");
choose(simulation, "confirm-destructive");
require(simulation.state().games.size() == 24 && simulation.state().library.collections.empty(),
"controller deletes only collection organization");
+ require(!simulation.state().navigation.modals.empty() && simulation.state().navigation.modals.back().id == "collections-manage",
+ "deleting returns to the collection sheets, which list what is left");
// Leave stacked menus and reach account destruction through normal sections.
while (!simulation.state().navigation.modals.empty()) press(simulation, "circle");
press(simulation, "circle");
diff --git a/tests/homebrew_library_model_test.cpp b/tests/homebrew_library_model_test.cpp
index cc5f4cc..88ccbbb 100644
--- a/tests/homebrew_library_model_test.cpp
+++ b/tests/homebrew_library_model_test.cpp
@@ -1400,6 +1400,47 @@ void live_completed_downloads_follow_the_queue() {
"Clear completed empties the list");
}
+void game_collections_sheet_adds_and_removes_the_game() {
+ using namespace playden::homebrew;
+ auto model = make_live();
+ model.UpdateAccount({AuthState::SignedIn, "123", "Synthetic", {}, {}, true});
+ check(model.UpdateLibrary({{game(42, "Metro"), game(43, "Other")}, false, {}, false, false, {}}), "library loaded");
+ check(model.action("details:42") && model.action("focus:details-more") && model.action("cross"), "game actions open");
+ activate(model, "collection");
+ check(model.state().navigation.modals.back().id == "collections" && has_row(model, "collection-new") &&
+ !has_row(model, "collection-manage") && find_row(model, "collection-new")->title == "New collection",
+ "with no collections the sheet offers New collection");
+
+ activate(model, "collection-new");
+ model.text("To test");
+ check(model.action("done"), "the name is entered");
+ const auto& collections = model.state().library.collections;
+ check(collections.size() == 1 && collections[0].name == "To test" && collections[0].members.contains(42),
+ "a collection made from a game's sheet holds that game");
+ const auto toggle = "collection-toggle-" + collections[0].id;
+ const auto* row = find_row(model, toggle);
+ check(row && row->title == "To test" && row->selected && row->value == "1 game" &&
+ model.state().navigation.focus_key == toggle && has_row(model, "collection-manage"),
+ "the new collection shows in the open sheet, checked and focused");
+
+ check(model.action("cross"), "the checkbox toggles");
+ check(!model.state().library.collections[0].members.contains(42) && !find_row(model, toggle)->selected &&
+ model.state().navigation.modals.back().id == "collections",
+ "unchecking removes the game and keeps the sheet open");
+
+ activate(model, "collection-manage");
+ const auto id = model.state().library.collections[0].id;
+ check(find_row(model, "collection-rename-" + id)->title == "Rename \u201cTo test\u201d" &&
+ find_row(model, "collection-pin-" + id) && find_row(model, "collection-delete-" + id)->dangerous,
+ "Manage collections renames, pins and deletes each collection");
+ activate(model, "collection-rename-" + id);
+ model.text(" later");
+ check(model.action("done"), "the new name is entered");
+ check(model.state().library.collections[0].name == "To test later" &&
+ find_row(model, "collection-rename-" + id)->title == "Rename \u201cTo test later\u201d",
+ "a rename shows in the open sheet");
+}
+
void live_download_reorder_reaches_service() {
using namespace playden::homebrew;
auto model = make_live();
@@ -1435,6 +1476,7 @@ int main() {
live_install_confirmation_checks_space_and_unknowns();
live_install_notifications();
live_completed_downloads_follow_the_queue();
+ game_collections_sheet_adds_and_removes_the_game();
live_log_viewer();
live_cloud_saves();
live_saves_tab();
diff --git a/tests/homebrew_persistence_model_test.cpp b/tests/homebrew_persistence_model_test.cpp
index fe5ed5f..ee22dba 100644
--- a/tests/homebrew_persistence_model_test.cpp
+++ b/tests/homebrew_persistence_model_test.cpp
@@ -313,6 +313,7 @@ void RealModalActionsAdvancePersistence() {
model.UpdateLibrary({{Game(20, "Twenty")}, false, {}, false, true, 1});
model.action("options");
Activate(model, "collection");
+ Activate(model, "collection-manage");
Activate(model, "collection-delete-collection-1");
Activate(model, "confirm-destructive");
const auto removed = model.ExportOrganization();