Skip to content

Xbox Cloud Gaming app for PS5 Homebrew

C

Hide games, sort "Your games" with R3, search filters by price and console

Rafael Abud Ferreira09448eade7ee
diff --git a/src/app/cli_main.cpp b/src/app/cli_main.cpp
index 1dad56a..4b4288d 100644
--- a/src/app/cli_main.cpp
+++ b/src/app/cli_main.cpp
@@ -352,10 +352,11 @@ int cmdUiPreview(auth::AuthManager& am, const std::string& dir) {
std::string e;
xcloud::fetchPrices(app.pricesWanted(40), gssv.session().market.empty() ? "US" : gssv.session().market,
ui::catalogLanguage(), got, e);
- std::map<std::string, std::pair<std::string, std::string>> texts;
+ std::map<std::string, ui::PriceInfo> texts;
for (const auto& [id, p] : got)
texts[id] = {p.list < 0.005 ? ui::tr(ui::Str::Free) : xcloud::formatPrice(p.list, p.currency),
- p.msrp > p.list + 0.005 ? xcloud::formatPrice(p.msrp, p.currency) : std::string()};
+ p.msrp > p.list + 0.005 ? xcloud::formatPrice(p.msrp, p.currency) : std::string(), p.list,
+ p.msrp};
app.setPrices(texts);
}
save("library_buy", 3000);
@@ -587,7 +588,8 @@ int main(int argc, char** argv) {
save("settings_resolution");
return 0;
} else if (cmd == "ui-badges" && argi < argc) {
- // Offline: cards with every badge, to check their layout.
+ // Offline: "Your games" with every badge, hiding, sorting and the
+ // search filters, with made-up games. PNGs into the given directory.
ui::Fonts fonts;
if (!fonts.load("assets/fonts")) return 1;
ui::ImageCache images([] {});
@@ -595,32 +597,59 @@ int main(int argc, char** argv) {
ui::Canvas canvas(1920, 1080);
std::vector<ui::GameTile> owned, buy;
const char* platforms[] = {"XS", "ONE", "360"};
+ const char* names[] = {"Zeta", "Alpha", "Mango", "Bravo", "Kilo", "Delta"};
for (int i = 0; i < 6; ++i) {
ui::GameTile t;
t.productId = "OWNED" + std::to_string(i);
t.titleId = t.productId;
- t.name = "Owned game " + std::to_string(i);
+ t.name = std::string(names[i]) + " owned";
t.platform = platforms[i % 3];
owned.push_back(t);
t.productId = "BUY" + std::to_string(i);
t.titleId = t.productId;
- t.name = "Game to buy " + std::to_string(i);
+ t.name = std::string(names[i]) + " to buy";
t.playable = false;
t.purchasable = true;
+ t.freeInStore = i == 2;
buy.push_back(t);
}
+ std::vector<ui::GameTile> pool = owned;
+ pool.insert(pool.end(), buy.begin(), buy.end());
app.setOwned(owned, buy, true);
- app.setPrices({{"BUY0", {"R$ 56,98", "R$ 284,90"}}, {"BUY1", {"R$ 199,99", ""}}, {"BUY2", {"GR\xC3\x81TIS", ""}},
- {"BUY3", {"R$ 1.299,90", ""}}});
+ app.setSearchPools({}, pool);
+ app.setPrices({{"BUY0", {"R$ 56,98", "R$ 284,90", 56.98, 284.9}},
+ {"BUY1", {"R$ 199,99", "", 199.99, 199.99}},
+ {"BUY2", {"GR\xC3\x81TIS", "", 0, 0}},
+ {"BUY3", {"R$ 1.299,90", "", 1299.9, 1299.9}},
+ {"BUY4", {"R$ 20,00", "R$ 40,00", 20, 40}}});
app.showHome();
- ui::NavInput r1;
- r1.r1 = true;
- app.handle(r1);
- app.render(canvas, 1000);
- app.render(canvas, 2000);
- std::string path = argv[argi];
- stbi_write_png(path.c_str(), canvas.width(), canvas.height(), 4, canvas.data(), canvas.width() * 4);
- std::printf("wrote %s\n", path.c_str());
+ auto press = [&](auto set, int times = 1) {
+ for (int i = 0; i < times; ++i) {
+ ui::NavInput n;
+ set(n);
+ app.handle(n);
+ }
+ };
+ uint64_t clock = 1000;
+ auto save = [&](const std::string& name) {
+ app.render(canvas, clock += 1000);
+ app.render(canvas, clock += 1000);
+ std::string path = std::string(argv[argi]) + "/" + name + ".png";
+ stbi_write_png(path.c_str(), canvas.width(), canvas.height(), 4, canvas.data(), canvas.width() * 4);
+ std::printf("wrote %s\n", path.c_str());
+ };
+ press([](ui::NavInput& n) { n.r1 = true; });
+ save("badges");
+ press([](ui::NavInput& n) { n.square = true; }); // hide the first game
+ press([](ui::NavInput& n) { n.r3 = true; }, 2); // Recent -> A-Z -> By console
+ save("library_console");
+ press([](ui::NavInput& n) { n.down = true; }, 3); // down to "Hidden"
+ save("library_hidden");
+ press([](ui::NavInput& n) { n.triangle = true; }); // search "Your games"
+ press([](ui::NavInput& n) { n.down = true; }, 7); // the filter row
+ press([](ui::NavInput& n) { n.right = true; }); // "Lowest price"
+ press([](ui::NavInput& n) { n.accept = true; });
+ save("search_cheapest");
return 0;
} else if (cmd == "ui-preview" && argi < argc) {
rc = cmdUiPreview(am, argv[argi]);
diff --git a/src/app/library.cpp b/src/app/library.cpp
index 03e54c0..df97564 100644
--- a/src/app/library.cpp
+++ b/src/app/library.cpp
@@ -104,6 +104,7 @@ ui::GameTile Library::tile(const std::string& productId, const std::string& titl
t.categories = p.categories;
if (ownershipKnown_) t.playable = ownedTitles_.count(t.titleId) || ownedProducts_.count(t.productId);
t.purchasable = !t.playable && purchasableSet_.count(productId);
+ t.freeInStore = freeInStore_.count(productId) > 0;
if (siblingsFor_ != products_.size()) {
seriesSiblings_.clear();
for (const auto& [id, prod] : products_) {
@@ -193,6 +194,7 @@ bool Library::loadCache() {
if (!products_.count(id)) products_[id] = productFromJson(id, v);
for (const auto& [id, code] : (*j)["platforms"].members()) platform_[id] = code.str();
for (const auto& [pid, xbox] : (*j)["xboxTitles"].members()) xboxTitleOf_[pid] = xbox.str();
+ for (const auto& id : (*j)["freeInStore"].items()) freeInStore_.insert(id.str());
for (const auto& t : (*j)["ownedTitles"].items()) ownedTitles_.insert(t.str());
for (const auto& p : (*j)["ownedProducts"].items()) ownedProducts_.insert(p.str());
owned_.clear();
@@ -239,6 +241,9 @@ void Library::saveCache() const {
for (const auto& [pid, xbox] : xboxTitleOf_) xboxTitles.set(pid, xbox);
root.set("platforms", platforms);
root.set("xboxTitles", xboxTitles);
+ json::Value free = json::Value::array();
+ for (const auto& id : freeInStore_) free.push(id);
+ root.set("freeInStore", free);
if (!platform::writeFileAtomic(cachePath_, root.dump())) XC_LOGW("library: could not write %s", cachePath_.c_str());
}
@@ -257,6 +262,7 @@ bool Library::load(xcloud::GssvClient& gssv, const std::string& language, const
owned_.clear();
purchasable_.clear();
purchasableSet_.clear();
+ freeInStore_.clear();
xboxTitleOf_.clear();
platform_.clear();
std::string lastErr;
@@ -366,6 +372,7 @@ void Library::loadOwned(xcloud::GssvClient gssv, const Changed& changed, const s
std::map<std::string, std::string> toBuy; // productId -> titleId
for (const auto& t : titles) {
if (!t.productId.empty() && !t.xboxTitleId.empty()) xboxTitleOf_[t.productId] = t.xboxTitleId;
+ if (t.isFreeInStore && !t.productId.empty()) freeInStore_.insert(t.productId);
if (t.hasEntitlement) {
ownedTitles.insert(t.titleId);
if (t.productId.empty()) continue;
diff --git a/src/app/library.h b/src/app/library.h
index 866c1a3..1bc3736 100644
--- a/src/app/library.h
+++ b/src/app/library.h
@@ -101,6 +101,7 @@ private:
std::vector<Item> owned_; // outside Game Pass
std::vector<Item> purchasable_; // streamable once bought
std::set<std::string> purchasableSet_;
+ std::set<std::string> freeInStore_; // product ids free in the store
std::map<std::string, std::string> xboxTitleOf_; // productId -> Xbox title id
std::map<std::string, std::string> platform_; // Xbox title id -> platform code
// Xbox title ids that have a "... - Xbox Series X|S" product, rebuilt
diff --git a/src/app/ps5_main.cpp b/src/app/ps5_main.cpp
index 90bab04..d13ed72 100644
--- a/src/app/ps5_main.cpp
+++ b/src/app/ps5_main.cpp
@@ -344,10 +344,13 @@ constexpr int64_t kPriceTtlSeconds = 24 * 3600;
std::string pricesPath() { return platform::dataDir() + "/prices.json"; }
-std::pair<std::string, std::string> priceTexts(const xcloud::Price& p) {
- std::string now = p.list < 0.005 ? ui::tr(ui::Str::Free) : xcloud::formatPrice(p.list, p.currency);
- std::string was = p.msrp > p.list + 0.005 ? xcloud::formatPrice(p.msrp, p.currency) : std::string();
- return {now, was};
+ui::PriceInfo priceTexts(const xcloud::Price& p) {
+ ui::PriceInfo info;
+ info.now = p.list < 0.005 ? ui::tr(ui::Str::Free) : xcloud::formatPrice(p.list, p.currency);
+ info.was = p.msrp > p.list + 0.005 ? xcloud::formatPrice(p.msrp, p.currency) : std::string();
+ info.list = p.list;
+ info.msrp = p.msrp;
+ return info;
}
void priceLoop() {
@@ -359,7 +362,7 @@ void priceLoop() {
}
// Fresh cached prices to the UI right away.
int64_t now = static_cast<int64_t>(std::time(nullptr));
- std::map<std::string, std::pair<std::string, std::string>> shown;
+ std::map<std::string, ui::PriceInfo> shown;
json::Value kept = json::Value::object();
for (const auto& [id, v] : cache.members()) {
if (now - v["t"].asInt() > kPriceTtlSeconds) continue;
@@ -388,7 +391,7 @@ void priceLoop() {
}
XC_LOGI("details of %s: %s", id.c_str(), ok ? "ok" : err.empty() ? "not in the catalog" : err.c_str());
}
- std::vector<std::string> ids = market.empty() ? std::vector<std::string>() : g_ui->pricesWanted(20);
+ std::vector<std::string> ids = market.empty() ? std::vector<std::string>() : g_ui->pricesWanted(20, true);
if (ids.empty()) {
platform::sleepMs(300);
continue;
@@ -396,7 +399,7 @@ void priceLoop() {
std::map<std::string, xcloud::Price> got;
std::string err;
if (!xcloud::fetchPrices(ids, market, language, got, err)) XC_LOGW("%s", err.c_str());
- std::map<std::string, std::pair<std::string, std::string>> texts;
+ std::map<std::string, ui::PriceInfo> texts;
now = static_cast<int64_t>(std::time(nullptr));
for (const auto& [id, p] : got) {
texts[id] = priceTexts(p);
@@ -633,6 +636,9 @@ int main(int argc, char** argv) {
choice.region = g_settings.region;
g_ui->setSettings(choice);
g_ui->setRegionLatency(g_settings.regionRtt);
+ g_ui->setPrefs(g_settings.hidden, g_settings.librarySort == "az" ? ui::LibrarySort::AZ
+ : g_settings.librarySort == "console" ? ui::LibrarySort::Console
+ : ui::LibrarySort::Recent);
}
ui::Canvas canvas(display::kWidth, display::kHeight);
@@ -688,6 +694,7 @@ int main(int argc, char** argv) {
nav.r1 = pad.btnR1 && !prev.btnR1;
nav.square = pad.btnX && !prev.btnX; // Square (Xbox X)
nav.triangle = pad.btnY && !prev.btnY; // Triangle (Xbox Y)
+ nav.r3 = pad.btnR3 && !prev.btnR3;
nav.touchpad = pad.btnTouchpad;
nav.nowMs = now;
prev = pad;
@@ -706,6 +713,16 @@ int main(int argc, char** argv) {
break;
case ui::Action::Retry: g_command = kSignIn; break;
case ui::Action::CancelLaunch: g_cancel = true; break;
+ case ui::Action::PrefsChanged: {
+ std::lock_guard<std::mutex> lock(g_settingsMutex);
+ g_settings.hidden = ev.hidden;
+ g_settings.librarySort = ev.librarySort == ui::LibrarySort::AZ ? "az"
+ : ev.librarySort == ui::LibrarySort::Console ? "console"
+ : "recent";
+ if (!g_settings.save(settingsPath())) XC_LOGW("could not save settings");
+ XC_LOGI("prefs saved: %zu hidden, sort %s", g_settings.hidden.size(), g_settings.librarySort.c_str());
+ break;
+ }
case ui::Action::SettingsChanged: {
bool languageChanged;
{
diff --git a/src/app/settings.cpp b/src/app/settings.cpp
index 761eeb2..88c7e35 100644
--- a/src/app/settings.cpp
+++ b/src/app/settings.cpp
@@ -16,6 +16,10 @@ bool Settings::load(const std::string& path) {
resolution = (*j)["resolution"].str(resolution);
region = (*j)["region"].str(region);
if (resolution != "720p" && resolution != "1440p") resolution = "1080p";
+ hidden.clear();
+ for (const auto& id : (*j)["hidden"].items())
+ if (!id.str().empty()) hidden.push_back(id.str());
+ librarySort = (*j)["librarySort"].str(librarySort);
regionRtt.clear();
for (const auto& [name, ms] : (*j)["regionRtt"].members())
if (ms.asInt() > 0) regionRtt[name] = static_cast<int>(ms.asInt());
@@ -30,6 +34,10 @@ bool Settings::save(const std::string& path) const {
json::Value rtt = json::Value::object();
for (const auto& [name, ms] : regionRtt) rtt.set(name, ms);
v.set("regionRtt", rtt);
+ json::Value hiddenIds = json::Value::array();
+ for (const auto& id : hidden) hiddenIds.push(id);
+ v.set("hidden", hiddenIds);
+ v.set("librarySort", librarySort);
return platform::writeFileAtomic(path, v.dump());
}
diff --git a/src/app/settings.h b/src/app/settings.h
index 8586be3..d9ea3be 100644
--- a/src/app/settings.h
+++ b/src/app/settings.h
@@ -5,6 +5,7 @@
#include <map>
#include <string>
+#include <vector>
namespace xc::app {
@@ -14,6 +15,10 @@ struct Settings {
std::string region; // gssv region name; empty = automatic
// Round trip to the stream server measured in past sessions, per region (ms).
std::map<std::string, int> regionRtt;
+ // Games hidden with Square (product ids), and the "Your games" order
+ // ("recent", "az", "console").
+ std::vector<std::string> hidden;
+ std::string librarySort = "recent";
bool load(const std::string& path);
bool save(const std::string& path) const;
diff --git a/src/ui/app_ui.cpp b/src/ui/app_ui.cpp
index a6dd02c..d15e211 100644
--- a/src/ui/app_ui.cpp
+++ b/src/ui/app_ui.cpp
@@ -42,7 +42,7 @@ constexpr Color kGreen = rgba(16, 124, 16);
constexpr Color kPanel = rgba(36, 36, 36);
constexpr Color kPlaceholder = rgba(44, 44, 44);
-enum Icon { kIconCross, kIconCircle, kIconOptions, kIconTriangle, kIconTouchpad, kIconSquare };
+enum Icon { kIconCross, kIconCircle, kIconOptions, kIconTriangle, kIconTouchpad, kIconSquare, kIconR3 };
// The resolution list, lowest first: SettingsChoice::resolution value per
// position (0 = 1080p, 1 = 720p, 2 = 1440p, as saved).
@@ -56,6 +56,7 @@ constexpr int kGridTop = 236; // y of the first card row
constexpr int kResultsX = 760;
constexpr int kSectionHeaderH = 96; // "Available to buy" heading in the grid
constexpr size_t kMaxResults = 60;
+constexpr size_t kMaxFilterResults = 300; // filters with no words: lists, not lookups
// The search keyboard: 6 x 6 letters and digits, then Space / Delete / Clear.
constexpr const char* kKeys = "abcdefghijklmnopqrstuvwxyz0123456789";
@@ -94,6 +95,9 @@ std::string fold(const std::string& s) {
return out;
}
+// "164 games", "1 game".
+std::string gamesCount(size_t n) { return n == 1 ? std::string(tr(Str::OneGame)) : trf(Str::GamesCount, std::to_string(n)); }
+
std::string withoutSpaces(std::string s) {
s.erase(std::remove(s.begin(), s.end(), ' '), s.end());
return s;
@@ -175,7 +179,13 @@ void AppUi::setProfile(const std::string& gamertag, const std::string& gamerpicU
void AppUi::setRows(std::vector<GameRow> rows) {
std::lock_guard<std::mutex> lock(mutex_);
- // Remember, per row title, which game had the focus and the scroll.
+ allRows_ = std::move(rows);
+ rebuild();
+}
+
+void AppUi::setRowsLocked(std::vector<GameRow> rows) {
+ // Caller holds mutex_. Remember, per row title, which game had the focus
+ // and the scroll.
struct Kept {
std::string productId;
Anim scroll;
@@ -216,29 +226,107 @@ void AppUi::setRows(std::vector<GameRow> rows) {
void AppUi::setOwned(std::vector<GameTile> owned, std::vector<GameTile> purchasable, bool known) {
std::lock_guard<std::mutex> lock(mutex_);
+ allOwned_ = std::move(owned);
+ allPurchasable_ = std::move(purchasable);
+ ownedKnown_ = known;
+ rebuild();
+}
+
+namespace {
+
+int consoleRank(const std::string& platform) {
+ return platform == "XS" ? 0 : platform == "ONE" ? 1 : platform == "360" ? 2 : 3;
+}
+
+} // namespace
+
+void AppUi::rebuild() {
+ // Caller holds mutex_.
const GameTile* was = libraryTile(gridFocus_);
std::string focused = was ? was->productId : "";
- owned_ = std::move(owned);
- purchasable_ = std::move(purchasable);
- ownedKnown_ = known;
+ auto visible = [&](const std::vector<GameTile>& in) {
+ std::vector<GameTile> out;
+ for (const auto& t : in)
+ if (!hidden_.count(t.productId)) out.push_back(t);
+ return out;
+ };
+ // "Recent" keeps the order received: recently played first for the
+ // account's games, most popular first for the games to buy.
+ auto byName = [](const GameTile& a, const GameTile& b) { return fold(a.name) < fold(b.name); };
+ auto sorted = [&](std::vector<GameTile> v) {
+ if (librarySort_ == LibrarySort::AZ) {
+ std::stable_sort(v.begin(), v.end(), byName);
+ } else if (librarySort_ == LibrarySort::Console) {
+ std::stable_sort(v.begin(), v.end(), [&](const GameTile& a, const GameTile& b) {
+ int ra = consoleRank(a.platform), rb = consoleRank(b.platform);
+ return ra != rb ? ra < rb : byName(a, b);
+ });
+ }
+ return v;
+ };
+ owned_ = sorted(visible(allOwned_));
+ purchasable_ = sorted(visible(allPurchasable_));
+ // Hidden games, from wherever they appear, once each, A-Z.
+ hiddenTiles_.clear();
+ std::set<std::string> seen;
+ auto collect = [&](const GameTile& t) {
+ if (hidden_.count(t.productId) && seen.insert(t.productId).second) hiddenTiles_.push_back(t);
+ };
+ for (const auto* list : {&allOwned_, &allPurchasable_, &gamePassPool_})
+ for (const auto& t : *list) collect(t);
+ for (const auto& row : allRows_)
+ for (const auto& t : row.tiles) collect(t);
+ std::stable_sort(hiddenTiles_.begin(), hiddenTiles_.end(), byName);
+
+ std::vector<GameRow> rows;
+ for (const auto& row : allRows_) {
+ GameRow r = row;
+ r.tiles = visible(row.tiles);
+ rows.push_back(std::move(r));
+ }
+ setRowsLocked(std::move(rows));
+
gridFocus_ = 0;
for (int i = 0; libraryTile(i); ++i)
if (libraryTile(i)->productId == focused) gridFocus_ = i;
+ if (searching_) runSearch();
refreshDetail();
dirty_ = true;
}
+void AppUi::setPrefs(const std::vector<std::string>& hidden, LibrarySort sort) {
+ std::lock_guard<std::mutex> lock(mutex_);
+ hidden_ = std::set<std::string>(hidden.begin(), hidden.end());
+ librarySort_ = sort;
+ rebuild();
+}
+
+void AppUi::prefsEvent(UiEvent& ev) const {
+ // Caller holds mutex_.
+ ev.action = Action::PrefsChanged;
+ ev.hidden.assign(hidden_.begin(), hidden_.end());
+ ev.librarySort = librarySort_;
+}
+
+void AppUi::toggleHidden(const GameTile& tile, UiEvent& ev) {
+ // Caller holds mutex_.
+ if (tile.productId.empty()) return;
+ bool hide = !hidden_.count(tile.productId);
+ if (hide) hidden_.insert(tile.productId);
+ else hidden_.erase(tile.productId);
+ toast_ = tr(hide ? Str::HiddenToast : Str::UnhiddenToast);
+ toastUntil_ = 0;
+ rebuild();
+ prefsEvent(ev);
+}
+
void AppUi::setSearchPools(std::vector<GameTile> gamePass, std::vector<GameTile> library) {
std::lock_guard<std::mutex> lock(mutex_);
gamePassPool_ = std::move(gamePass);
libraryPool_ = std::move(library);
- if (searching_) {
- int keep = resultFocus_;
- runSearch();
- resultFocus_ = std::min(keep, std::max(0, static_cast<int>(results_.size()) - 1));
- }
- refreshDetail();
- dirty_ = true;
+ int keep = resultFocus_;
+ rebuild(); // hidden games may be in the pools only
+ if (searching_) resultFocus_ = std::min(keep, std::max(0, static_cast<int>(results_.size()) - 1));
}
void AppUi::setRegionLatency(std::map<std::string, int> ms) {
@@ -247,13 +335,17 @@ void AppUi::setRegionLatency(std::map<std::string, int> ms) {
dirty_ = true;
}
-void AppUi::setPrices(const std::map<std::string, std::pair<std::string, std::string>>& prices) {
+void AppUi::setPrices(const std::map<std::string, PriceInfo>& prices) {
std::lock_guard<std::mutex> lock(mutex_);
for (const auto& [id, p] : prices) prices_[id] = p;
+ // A list ordered or filtered by price fills in as prices arrive (not
+ // while the user moves through it).
+ if (searching_ && searchOnKeys_ && tab_ == Tab::Library && (filterCheapest_ || filterSale_ || filterFree_))
+ runSearch();
dirty_ = true;
}
-std::vector<std::string> AppUi::pricesWanted(size_t max) {
+std::vector<std::string> AppUi::pricesWanted(size_t max, bool background) {
std::lock_guard<std::mutex> lock(mutex_);
std::vector<std::string> out;
auto want = [&](const GameTile& t) {
@@ -261,6 +353,7 @@ std::vector<std::string> AppUi::pricesWanted(size_t max) {
out.push_back(t.productId);
};
if (screen_ == Screen::Details) want(detail_);
+ if (screen_ == Screen::Streaming || screen_ == Screen::Launching) return out;
if (screen_ != Screen::Home && screen_ != Screen::Details) return out;
if (searching_) {
for (const auto& t : results_) want(t);
@@ -270,9 +363,13 @@ std::vector<std::string> AppUi::pricesWanted(size_t max) {
float top = gridScroll_.target - kGridPitchY, bottom = gridScroll_.target + kH + 2 * kGridPitchY;
for (size_t i = owned_.size(); i < L.rowOf.size(); ++i) {
int y = L.rowY[static_cast<size_t>(L.rowOf[i])];
- if (y >= top && y <= bottom) want(purchasable_[i - owned_.size()]);
+ if (y >= top && y <= bottom && i - owned_.size() < purchasable_.size())
+ want(purchasable_[i - owned_.size()]);
}
}
+ // The rest, for the price filters and orders.
+ if (background && out.empty())
+ for (const auto& t : allPurchasable_) want(t);
return out;
}
@@ -315,7 +412,9 @@ const GameTile* AppUi::libraryTile(int index) const {
size_t i = static_cast<size_t>(index);
if (i < owned_.size()) return &owned_[i];
i -= owned_.size();
- return i < purchasable_.size() ? &purchasable_[i] : nullptr;
+ if (i < purchasable_.size()) return &purchasable_[i];
+ i -= purchasable_.size();
+ return i < hiddenTiles_.size() ? &hiddenTiles_[i] : nullptr;
}
Tab AppUi::tab() const {
@@ -352,7 +451,8 @@ void AppUi::refreshDetail() {
}
void AppUi::runSearch() {
- // Caller holds mutex_.
+ // Caller holds mutex_. The typed words narrow by name; the filters by
+ // price and console. With filters and no words: every game that passes.
results_.clear();
resultFocus_ = 0;
resultScroll_ = Anim{};
@@ -364,29 +464,52 @@ void AppUi::runSearch() {
if (j > i) words.push_back(q.substr(i, j - i));
i = j + 1;
}
- if (words.empty()) return;
+ bool filtering = anyFilter() && (tab_ == Tab::Library || filterConsole_);
+ if (words.empty() && !filtering) return;
std::string compact = withoutSpaces(q);
+ static const char* kConsoleCodes[] = {"", "XS", "ONE", "360"};
struct Hit {
int score;
+ double order; // price or discount, by the active order filter
const GameTile* tile;
};
std::vector<Hit> hits;
for (const auto& t : tab_ == Tab::GamePass ? gamePassPool_ : libraryPool_) {
+ if (hidden_.count(t.productId)) continue;
+ if (filterConsole_ && t.platform != kConsoleCodes[filterConsole_]) continue;
+ auto price = prices_.find(t.productId);
+ bool priced = price != prices_.end();
+ if (tab_ == Tab::Library) {
+ bool free = t.freeInStore || (t.purchasable && priced && price->second.list < 0.005);
+ if (filterFree_ && !free) continue;
+ // Price filters look at games to buy only.
+ if ((filterCheapest_ || filterSale_) && !t.purchasable) continue;
+ if (filterSale_ && !(priced && price->second.msrp > price->second.list + 0.005)) continue;
+ }
std::string name = fold(t.name);
- bool all = true;
- for (const auto& w : words)
- if (name.find(w) == std::string::npos) all = false;
- if (!all && withoutSpaces(name).find(compact) == std::string::npos) continue;
- // Starts with the query, then a word starting with it, then the rest.
- int score = name.rfind(words[0], 0) == 0 ? 0 : name.find(" " + words[0]) != std::string::npos ? 1 : 2;
+ int score = 0;
+ if (!words.empty()) {
+ bool all = true;
+ for (const auto& w : words)
+ if (name.find(w) == std::string::npos) all = false;
+ if (!all && withoutSpaces(name).find(compact) == std::string::npos) continue;
+ // Starts with the query, then a word starting with it, then the rest.
+ score = name.rfind(words[0], 0) == 0 ? 0 : name.find(" " + words[0]) != std::string::npos ? 1 : 2;
+ }
if (!t.playable) score += 3; // in "Your games": owned before games to buy
- hits.push_back({score, &t});
+ double order = 0;
+ if (filterCheapest_) order = priced ? price->second.list : 1e12; // unknown prices last
+ if (filterSale_ && priced) order = -(1.0 - price->second.list / price->second.msrp); // biggest discount first
+ hits.push_back({score, order, &t});
}
- std::stable_sort(hits.begin(), hits.end(), [](const Hit& a, const Hit& b) {
+ bool byOrder = tab_ == Tab::Library && (filterCheapest_ || filterSale_);
+ std::stable_sort(hits.begin(), hits.end(), [&](const Hit& a, const Hit& b) {
+ if (byOrder && a.order != b.order) return a.order < b.order;
if (a.score != b.score) return a.score < b.score;
- return a.tile->name < b.tile->name;
+ return fold(a.tile->name) < fold(b.tile->name);
});
- for (size_t i = 0; i < hits.size() && i < kMaxResults; ++i) results_.push_back(*hits[i].tile);
+ size_t max = words.empty() ? kMaxFilterResults : kMaxResults;
+ for (size_t i = 0; i < hits.size() && i < max; ++i) results_.push_back(*hits[i].tile);
}
void AppUi::showHome(const std::string& toast) {
@@ -539,17 +662,17 @@ float gridTarget(int focus, int cols) { return static_cast<float>(std::max(0, fo
} // namespace
AppUi::LibraryLayout AppUi::libraryLayout() const {
- // Caller holds mutex_. The account's games, then (after a header) the
- // games to buy, both kLibraryCols wide.
+ // Caller holds mutex_. The account's games, then (after headers) the
+ // games to buy and the hidden games, all kLibraryCols wide.
LibraryLayout L;
L.cols = kLibraryCols;
int y = 0, row = 0, index = 0;
- for (int section = 0; section < 2; ++section) {
- const auto& list = section == 0 ? owned_ : purchasable_;
+ for (int section = 0; section < 3; ++section) {
+ const auto& list = section == 0 ? owned_ : section == 1 ? purchasable_ : hiddenTiles_;
if (list.empty()) continue;
- if (section == 1) {
+ if (section > 0) {
if (row > 0) y += 30;
- L.headerY[1] = y;
+ L.headerY[section] = y;
y += kSectionHeaderH;
}
for (size_t i = 0; i < list.size(); ++i, ++index) {
@@ -635,6 +758,7 @@ void AppUi::handleHome(const NavInput& in, UiEvent& ev) {
dirty_ = true;
}
if (in.accept && focusedTile()) openDetails(*focusedTile());
+ if (in.square && focusedTile()) toggleHidden(*focusedTile(), ev);
break;
}
case Tab::Library: {
@@ -659,26 +783,67 @@ void AppUi::handleHome(const NavInput& in, UiEvent& ev) {
dirty_ = true;
}
if (in.accept && libraryTile(f)) openDetails(*libraryTile(f));
+ if (in.square && libraryTile(f)) {
+ GameTile t = *libraryTile(f);
+ toggleHidden(t, ev);
+ }
+ if (in.r3) { // next sort order
+ librarySort_ = static_cast<LibrarySort>((static_cast<int>(librarySort_) + 1) %
+ static_cast<int>(LibrarySort::Count));
+ gridFocus_ = 0;
+ gridScroll_.target = 0;
+ rebuild();
+ gridFocus_ = 0;
+ prefsEvent(ev);
+ }
break;
}
}
- (void)ev;
+}
+
+std::vector<std::string> AppUi::filterLabels() const {
+ // Caller holds mutex_. Prices only matter in "Your games" (Game Pass
+ // games aren't bought): there, Free / Lowest price / On sale first.
+ static const char* kConsoles[] = {nullptr, "SERIES X|S", "XBOX ONE", "XBOX 360"};
+ std::string console = filterConsole_ ? kConsoles[filterConsole_] : tr(Str::FilterAllConsoles);
+ if (tab_ == Tab::GamePass) return {console};
+ return {tr(Str::FilterFree), tr(Str::FilterCheapest), tr(Str::FilterSale), console};
+}
+
+void AppUi::pressFilter(int index) {
+ // Caller holds mutex_.
+ int console = static_cast<int>(filterLabels().size()) - 1; // always last
+ if (index == console) {
+ filterConsole_ = (filterConsole_ + 1) % 4;
+ } else if (index == 0) {
+ filterFree_ = !filterFree_;
+ } else if (index == 1) {
+ filterCheapest_ = !filterCheapest_;
+ if (filterCheapest_) filterSale_ = false; // one order at a time
+ } else if (index == 2) {
+ filterSale_ = !filterSale_;
+ if (filterSale_) filterCheapest_ = false;
+ }
+ runSearch();
}
void AppUi::handleSearchKeys(const NavInput& in) {
// Caller holds mutex_. keyRow_ == kKeyRows is the row of wide keys, where
- // keyCol_ is 0..2 (Space, Delete, Clear).
- bool wide = keyRow_ == kKeyRows;
+ // keyCol_ is 0..2 (Space, Delete, Clear); kKeyRows + 1 the filters.
+ bool wide = keyRow_ == kKeyRows, filters = keyRow_ == kKeyRows + 1;
+ int filterCount = static_cast<int>(filterLabels().size());
if (in.up && keyRow_ > 0) {
if (wide) keyCol_ = kWideCols[keyCol_];
+ if (filters) keyCol_ = std::min(keyCol_, 2);
--keyRow_;
- } else if (in.down && keyRow_ < kKeyRows) {
+ } else if (in.down && keyRow_ < kKeyRows + 1) {
++keyRow_;
if (keyRow_ == kKeyRows) keyCol_ = keyCol_ < 3 ? 0 : keyCol_ < 5 ? 1 : 2;
+ else if (keyRow_ == kKeyRows + 1) keyCol_ = std::min(keyCol_, filterCount - 1);
} else if (in.left && keyCol_ > 0) {
--keyCol_;
} else if (in.right) {
- int last = wide ? 2 : kKeyCols - 1;
+ int last = filters ? filterCount - 1 : wide ? 2 : kKeyCols - 1;
if (keyCol_ < last) {
++keyCol_;
} else if (!results_.empty()) { // on to the results
@@ -688,7 +853,9 @@ void AppUi::handleSearchKeys(const NavInput& in) {
}
bool edited = false;
if (in.accept) {
- if (!wide) {
+ if (filters) {
+ pressFilter(keyCol_);
+ } else if (!wide) {
query_ += kKeys[keyRow_ * kKeyCols + keyCol_];
} else if (keyCol_ == 0) {
if (!query_.empty() && query_.back() != ' ') query_ += ' ';
@@ -697,7 +864,8 @@ void AppUi::handleSearchKeys(const NavInput& in) {
} else {
query_.clear();
}
- edited = true;
+ edited = !filters;
+ dirty_ = true;
}
if (in.square && !query_.empty()) {
query_.pop_back();
@@ -745,6 +913,7 @@ UiEvent AppUi::handle(const NavInput& in) {
ev.action = Action::Play;
ev.game = detail_;
}
+ if (in.square) toggleHidden(detail_, ev); // the page stays open
if (in.back) {
screen_ = Screen::Home;
dirty_ = true;
@@ -826,7 +995,12 @@ void AppUi::drawHints(Canvas& c, const std::vector<std::pair<int, const char*>>&
fonts_.semibold.draw(c, it->second, x, y, kPx, kGray);
x -= 10 + 2 * kR;
float cx = x + kR, cy = y + 13;
- if (it->first == kIconTouchpad) {
+ if (it->first == kIconR3) {
+ Rect pill{x - 6, static_cast<int>(cy) - 12, 2 * kR + 12, 24};
+ c.fillRect(pill, rgba(255, 255, 255, 40), 8);
+ fonts_.bold.draw(c, "R3", pill.x + (pill.w - fonts_.bold.measure("R3", 14)) / 2,
+ fonts_.bold.centeredY(pill.y, pill.h, 14), 14, kGray);
+ } else if (it->first == kIconTouchpad) {
Rect pad{x - 18, static_cast<int>(cy) - 10, 2 * kR + 12, 20};
c.fillRect(pad, rgba(255, 255, 255, 40), 6);
c.strokeRect(pad, kGray, 2, 6);
@@ -1028,7 +1202,7 @@ void AppUi::drawCard(Canvas& c, const GameTile& t, int x, int y, bool focused, b
if (t.purchasable) {
c.fillRect({x, y, kCard, kCard}, rgba(0, 0, 0, 70), 10);
auto price = prices_.find(t.productId);
- std::string label = price != prices_.end() ? price->second.first : tr(Str::BuyBadge);
+ std::string label = price != prices_.end() ? price->second.now : tr(Str::BuyBadge);
int w = fonts_.bold.measure(label, 13) + 42;
Rect badge{x + 10, y + kCard - 34, w, 24};
c.fillRect(badge, rgba(16, 124, 16, 235), 4);
@@ -1088,11 +1262,22 @@ void AppUi::drawLibrary(Canvas& c, uint64_t nowMs) {
drawBag(c, left + 14, hy + 30, kGreen);
fonts_.bold.draw(c, tr(Str::AvailableToBuy), left + 40, hy + 8, 34, kWhite);
int w = fonts_.bold.measure(tr(Str::AvailableToBuy), 34);
- fonts_.semibold.draw(c, trf(Str::GamesCount, std::to_string(purchasable_.size())), left + 60 + w, hy + 20,
+ fonts_.semibold.draw(c, gamesCount(purchasable_.size()), left + 60 + w, hy + 20,
22, kDim);
fonts_.regular.draw(c, tr(Str::BuyToPlay), left + 40, hy + 52, 22, kGray);
}
}
+ // "Hidden": the games hidden with Square, at the very end.
+ if (!hiddenTiles_.empty()) {
+ int hy = kGridTop + L.headerY[2] - offset;
+ if (hy > clipTop - 80 && hy < kH) {
+ fonts_.bold.draw(c, tr(Str::HiddenSection), left, hy + 8, 34, kWhite);
+ int w = fonts_.bold.measure(tr(Str::HiddenSection), 34);
+ fonts_.semibold.draw(c, gamesCount(hiddenTiles_.size()), left + 20 + w, hy + 20,
+ 22, kDim);
+ fonts_.regular.draw(c, tr(Str::HiddenHint), left, hy + 52, 22, kGray);
+ }
+ }
for (size_t i = 0; i < L.rowOf.size(); ++i) {
int y = kGridTop + L.rowY[static_cast<size_t>(L.rowOf[i])] - offset;
if (y + kCard + 40 < clipTop) continue;
@@ -1101,6 +1286,7 @@ void AppUi::drawLibrary(Canvas& c, uint64_t nowMs) {
const GameTile* t = libraryTile(static_cast<int>(i));
bool focused = static_cast<int>(i) == gridFocus_;
drawCard(c, *t, x, y, focused, false);
+ if (hidden_.count(t->productId)) c.fillRect({x, y, kCard, kCard}, rgba(0, 0, 0, 120), 10);
auto name = fonts_.semibold.wrap(t->name, 20, kCard, 1);
if (!name.empty()) fonts_.semibold.draw(c, name[0], x, y + kCard + 12, 20, focused ? kWhite : kGray);
}
@@ -1110,7 +1296,7 @@ void AppUi::drawLibrary(Canvas& c, uint64_t nowMs) {
drawTabs(c);
fonts_.bold.draw(c, tr(Str::YourGames), left, 130, 40, kWhite);
if (!owned_.empty()) {
- std::string count = trf(Str::GamesCount, std::to_string(owned_.size()));
+ std::string count = gamesCount(owned_.size());
fonts_.semibold.draw(c, count, left + fonts_.bold.measure(tr(Str::YourGames), 40) + 24, 144, 24, kDim);
} else if (!ownedKnown_) {
drawSpinner(c, kW / 2.0f, 470, 26, nowMs);
@@ -1119,10 +1305,28 @@ void AppUi::drawLibrary(Canvas& c, uint64_t nowMs) {
} else if (purchasable_.empty()) {
drawCentered(c, fonts_.semibold, tr(Str::NoGames), 500, 30, kGray);
}
+ {
+ // The order, right-aligned in the header, with its button.
+ Str sortName = librarySort_ == LibrarySort::AZ ? Str::SortAZ
+ : librarySort_ == LibrarySort::Console ? Str::SortConsole
+ : Str::SortRecent;
+ std::string label = trf(Str::SortLabel, tr(sortName));
+ int w = fonts_.semibold.measure(label, 24);
+ int right = left + kGridW;
+ Rect pill{right - 44, 138, 44, 30};
+ c.fillRect(pill, rgba(255, 255, 255, 40), 8);
+ fonts_.bold.draw(c, "R3", pill.x + (pill.w - fonts_.bold.measure("R3", 16)) / 2,
+ fonts_.bold.centeredY(pill.y, pill.h, 16), 16, kGray);
+ fonts_.semibold.draw(c, label, pill.x - 14 - w, fonts_.semibold.centeredY(pill.y, pill.h, 24), 24, kGray);
+ }
c.gradientV({0, kH - 190, kW, 110}, withAlpha(kBg, 0), withAlpha(kBg, 245));
c.fillRect({0, kH - 80, kW, 80}, withAlpha(kBg, 245));
+ const GameTile* focus = libraryTile(gridFocus_);
+ bool focusHidden = focus && hidden_.count(focus->productId);
drawHints(c, {{kIconCross, tr(Str::Select)},
+ {kIconSquare, tr(focusHidden ? Str::Unhide : Str::Hide)},
{kIconTriangle, tr(Str::TabSearch)},
+ {kIconR3, tr(Str::SortHint)},
{kIconOptions, tr(Str::Settings)},
{kIconTouchpad, tr(Str::HoldSignOut)}});
drawToast(c, nowMs);
@@ -1136,7 +1340,8 @@ void AppUi::drawSearch(Canvas& c, uint64_t nowMs) {
drawTopBar(c);
drawTabs(c);
const char* scope = tab_ == Tab::GamePass ? tr(Str::TabGamePass) : tr(Str::YourGames);
- if (query_.empty()) {
+ bool filtering = anyFilter() && (tab_ == Tab::Library || filterConsole_);
+ if (query_.empty() && !filtering) {
fonts_.semibold.draw(c, tr(Str::SearchHint), kResultsX, 150, 26, kDim);
} else if (results_.empty()) {
fonts_.semibold.draw(c, tr(Str::NoResults), kResultsX, 150, 26, kGray);
@@ -1177,6 +1382,32 @@ void AppUi::drawSearch(Canvas& c, uint64_t nowMs) {
focused ? kBg : kWhite);
}
}
+ // The filters, one row under the keys: green when on.
+ {
+ auto labels = filterLabels();
+ const int kbW = kKeyCols * (kKeyW + kKeyGap) - kKeyGap, gap = 10, px = 18;
+ const int fy = kKeysY + (kKeyRows + 1) * (kKeyH + kKeyGap) + 6, fh = 54;
+ int textTotal = 0;
+ for (const auto& l : labels) textTotal += fonts_.semibold.measure(l, px);
+ int spare = kbW - textTotal - gap * (static_cast<int>(labels.size()) - 1);
+ int pad = std::max(8, spare / static_cast<int>(labels.size()));
+ int x = kMargin;
+ for (size_t k = 0; k < labels.size(); ++k) {
+ bool console = k + 1 == labels.size();
+ bool on = console ? filterConsole_ != 0
+ : (k == 0 ? filterFree_ : k == 1 ? filterCheapest_ : filterSale_);
+ bool focused = searchOnKeys_ && keyRow_ == kKeyRows + 1 && keyCol_ == static_cast<int>(k);
+ int w = fonts_.semibold.measure(labels[k], px) + pad;
+ if (k + 1 == labels.size()) w = kMargin + kbW - x; // the last one fills the row
+ Rect chip{x, fy, w, fh};
+ c.fillRect(chip, focused ? kWhite : on ? rgba(16, 124, 16, 255) : kPanel, fh / 2);
+ if (on && focused) c.strokeRect({chip.x + 3, chip.y + 3, chip.w - 6, chip.h - 6}, kGreen, 3, fh / 2 - 3);
+ std::string text = fonts_.semibold.fit(labels[k], px, w - 16);
+ fonts_.semibold.draw(c, text, chip.x + (chip.w - fonts_.semibold.measure(text, px)) / 2,
+ fonts_.semibold.centeredY(chip.y, chip.h, px), px, focused ? kBg : kWhite);
+ x += w + gap;
+ }
+ }
c.gradientV({0, kH - 190, kW, 110}, withAlpha(kBg, 0), withAlpha(kBg, 245));
c.fillRect({0, kH - 80, kW, 80}, withAlpha(kBg, 245));
if (searchOnKeys_)
@@ -1235,6 +1466,7 @@ void AppUi::drawHome(Canvas& c, uint64_t nowMs) {
c.gradientV({0, kH - 190, kW, 110}, withAlpha(kBg, 0), withAlpha(kBg, 245));
c.fillRect({0, kH - 80, kW, 80}, withAlpha(kBg, 245));
drawHints(c, {{kIconCross, tr(Str::Select)},
+ {kIconSquare, tr(Str::Hide)},
{kIconTriangle, tr(Str::TabSearch)},
{kIconOptions, tr(Str::Settings)},
{kIconTouchpad, tr(Str::HoldSignOut)}});
@@ -1289,11 +1521,11 @@ void AppUi::drawDetails(Canvas& c, uint64_t nowMs) {
if (price != prices_.end()) {
// The price, and the regular one crossed out while on sale.
int px = kMargin;
- fonts_.bold.draw(c, price->second.first, px, ty, 52, kWhite);
- px += fonts_.bold.measure(price->second.first, 52) + 24;
- if (!price->second.second.empty()) {
- int w = fonts_.semibold.measure(price->second.second, 30);
- fonts_.semibold.draw(c, price->second.second, px, ty + 14, 30, kDim);
+ fonts_.bold.draw(c, price->second.now, px, ty, 52, kWhite);
+ px += fonts_.bold.measure(price->second.now, 52) + 24;
+ if (!price->second.was.empty()) {
+ int w = fonts_.semibold.measure(price->second.was, 30);
+ fonts_.semibold.draw(c, price->second.was, px, ty + 14, 30, kDim);
c.line(static_cast<float>(px), static_cast<float>(ty + 32), static_cast<float>(px + w),
static_cast<float>(ty + 32), 2, kDim);
}
@@ -1321,7 +1553,8 @@ void AppUi::drawDetails(Canvas& c, uint64_t nowMs) {
int w = fonts_.semibold.measure(tr(Str::ScanToBuy), 26);
fonts_.semibold.draw(c, tr(Str::ScanToBuy), box.x + (box.w - w) / 2, box.y + box.h + 22, 26, kWhite);
}
- drawHints(c, {{kIconCircle, tr(Str::Back)}});
+ drawHints(c, {{kIconSquare, tr(hidden_.count(g->productId) ? Str::Unhide : Str::Hide)}, {kIconCircle, tr(Str::Back)}});
+ drawToast(c, nowMs);
return;
}
if (!g->playable) {
@@ -1330,7 +1563,8 @@ void AppUi::drawDetails(Canvas& c, uint64_t nowMs) {
c.fillRect(note, rgba(255, 255, 255, 40), 38);
drawLock(c, note.x + 52, note.y + note.h / 2);
fonts_.semibold.draw(c, tr(Str::NotPlayable), note.x + 90, note.y + 22, 28, kGray);
- drawHints(c, {{kIconCircle, tr(Str::Back)}});
+ drawHints(c, {{kIconSquare, tr(hidden_.count(g->productId) ? Str::Unhide : Str::Hide)}, {kIconCircle, tr(Str::Back)}});
+ drawToast(c, nowMs);
return;
}
// Play button (focused).
@@ -1342,7 +1576,10 @@ void AppUi::drawDetails(Canvas& c, uint64_t nowMs) {
c.line(tx - 8, ty - 13, tx + 13, ty, 4, kWhite);
c.line(tx - 8, ty + 13, tx + 13, ty, 4, kWhite);
fonts_.semibold.draw(c, tr(Str::Play), play.x + 108, play.y + 20, 32, kWhite);
- drawHints(c, {{kIconCross, tr(Str::Play)}, {kIconCircle, tr(Str::Back)}});
+ drawHints(c, {{kIconCross, tr(Str::Play)},
+ {kIconSquare, tr(hidden_.count(g->productId) ? Str::Unhide : Str::Hide)},
+ {kIconCircle, tr(Str::Back)}});
+ drawToast(c, nowMs);
}
void AppUi::drawLaunching(Canvas& c, uint64_t nowMs) {
diff --git a/src/ui/app_ui.h b/src/ui/app_ui.h
index daac52f..91f93b6 100644
--- a/src/ui/app_ui.h
+++ b/src/ui/app_ui.h
@@ -35,6 +35,8 @@ struct GameTile {
bool playable = true;
// Not playable, but streams in the cloud once bought.
bool purchasable = false;
+ // Free in the store (free-to-play): the "Free" search filter.
+ bool freeInStore = false;
// Console it was made for: "360", "ONE", "XS" (xcloud/titlehub.h); empty
// while unknown.
std::string platform;
@@ -54,7 +56,7 @@ enum class Tab { GamePass, Library };
struct NavInput {
bool up = false, down = false, left = false, right = false;
bool accept = false, back = false, options = false;
- bool l1 = false, r1 = false, square = false, triangle = false;
+ bool l1 = false, r1 = false, square = false, triangle = false, r3 = false;
bool touchpad = false; // held right now (sign out needs a 5 s hold)
uint64_t nowMs = 0;
};
@@ -66,12 +68,24 @@ struct SettingsChoice {
std::string region; // gssv region name; empty = automatic
};
-enum class Action { None, Play, SignOut, Retry, CancelLaunch, SettingsChanged };
+enum class Action { None, Play, SignOut, Retry, CancelLaunch, SettingsChanged, PrefsChanged };
+
+// How "Your games" is sorted (R3).
+enum class LibrarySort { Recent, AZ, Console, Count };
+
+// A store price, as shown and as a number (for sorting and the filters).
+struct PriceInfo {
+ std::string now, was; // formatted; `was` empty unless on sale
+ double list = 0, msrp = 0;
+};
struct UiEvent {
Action action = Action::None;
GameTile game;
SettingsChoice settings; // SettingsChanged
+ // PrefsChanged: hidden games (product ids) and the "Your games" order.
+ std::vector<std::string> hidden;
+ LibrarySort librarySort = LibrarySort::Recent;
};
// "SOUTHCENTRALUS" -> "South Central US".
@@ -95,10 +109,13 @@ public:
// Measured round trip to each region, ms (shown in Settings).
void setRegionLatency(std::map<std::string, int> ms);
// Store prices, formatted: productId -> {now, regular (empty unless on sale)}.
- void setPrices(const std::map<std::string, std::pair<std::string, std::string>>& prices);
+ void setPrices(const std::map<std::string, PriceInfo>& prices);
+ // Saved preferences: hidden games and the "Your games" order.
+ void setPrefs(const std::vector<std::string>& hidden, LibrarySort sort);
// Games to buy on screen (or about to be) whose price hasn't been asked
- // for yet; marks them asked.
- std::vector<std::string> pricesWanted(size_t max);
+ // for yet; with `background`, any other game to buy once those are done
+ // (never while streaming). Marks them asked.
+ std::vector<std::string> pricesWanted(size_t max, bool background = false);
// The game whose page is open, if its description or hero art hasn't
// arrived; asked again every 5 s while missing (empty otherwise).
std::string detailWanted(uint64_t nowMs);
@@ -162,10 +179,20 @@ private:
std::vector<int> rowOf, colOf; // per tile index (owned, then purchasable)
std::vector<int> rowY; // per row, y relative to the grid top
std::vector<int> rowFirst; // first tile index of each row
- int headerY[2] = {0, 0}; // section headers, relative
+ int headerY[3] = {0, 0, 0}; // section headers, relative (1: to buy, 2: hidden)
};
LibraryLayout libraryLayout() const;
const GameTile* libraryTile(int index) const;
+ // Applies hiding and sorting to the received lists (caller holds mutex_).
+ void rebuild();
+ void setRowsLocked(std::vector<GameRow> rows);
+ // Hides / shows a game; fills `ev` so the app saves it.
+ void toggleHidden(const GameTile& tile, UiEvent& ev);
+ void prefsEvent(UiEvent& ev) const;
+ // The filter buttons of the current tab's search.
+ std::vector<std::string> filterLabels() const;
+ void pressFilter(int index);
+ bool anyFilter() const { return filterFree_ || filterCheapest_ || filterSale_ || filterConsole_; }
void handleHome(const NavInput& in, UiEvent& ev);
void handleSearchKeys(const NavInput& in);
void runSearch();
@@ -197,7 +224,15 @@ private:
std::vector<Anim> rowScroll_;
Anim rowY_;
Tab tab_ = Tab::GamePass;
- std::vector<GameTile> owned_, purchasable_;
+ std::vector<GameTile> owned_, purchasable_, hiddenTiles_; // as shown
+ // As received, before hiding and sorting (rebuild() derives the above).
+ std::vector<GameRow> allRows_;
+ std::vector<GameTile> allOwned_, allPurchasable_;
+ std::set<std::string> hidden_;
+ LibrarySort librarySort_ = LibrarySort::Recent;
+ // Search filters (the row of buttons under the keys).
+ bool filterFree_ = false, filterCheapest_ = false, filterSale_ = false;
+ int filterConsole_ = 0; // 0 all, 1 Series X|S, 2 Xbox One, 3 Xbox 360
bool ownedKnown_ = false;
int gridFocus_ = 0;
Anim gridScroll_;
@@ -215,7 +250,7 @@ private:
std::vector<std::string> regions_;
std::string defaultRegion_;
std::map<std::string, int> regionMs_;
- std::map<std::string, std::pair<std::string, std::string>> prices_;
+ std::map<std::string, PriceInfo> prices_;
std::set<std::string> pricesAsked_;
std::string detailAskedFor_;
uint64_t detailAskedAt_ = 0;
diff --git a/src/ui/strings.cpp b/src/ui/strings.cpp
index 8f4380d..767f9cb 100644
--- a/src/ui/strings.cpp
+++ b/src/ui/strings.cpp
@@ -96,6 +96,22 @@ constexpr Column kEnglish = {
"Scan to open the store page", // ScanToBuy
"Search in %s", // SearchIn
"FREE", // Free
+ "Hide", // Hide
+ "Show", // Unhide
+ "Hidden", // HiddenSection
+ "Square shows a game again", // HiddenHint
+ "Hidden: find it in Your games > Hidden", // HiddenToast
+ "Shown again", // UnhiddenToast
+ "Sort: %s", // SortLabel
+ "Recent first", // SortRecent
+ "A-Z", // SortAZ
+ "By console", // SortConsole
+ "Sort", // SortHint
+ "Free", // FilterFree
+ "Lowest price", // FilterCheapest
+ "On sale", // FilterSale
+ "All consoles", // FilterAllConsoles
+ "1 game", // OneGame
};
constexpr Column kPortugueseBR = {
@@ -162,6 +178,22 @@ constexpr Column kPortugueseBR = {
"Escaneie para abrir a página da loja",
"Pesquisar em %s",
"GRÁTIS",
+ "Ocultar",
+ "Mostrar",
+ "Ocultos",
+ "\xE2\x96\xA1 mostra o jogo de novo",
+ "Oculto: veja em Seus jogos > Ocultos",
+ "Visível de novo",
+ "Ordenar: %s",
+ "Recentes primeiro",
+ "A-Z",
+ "Por console",
+ "Ordenar",
+ "Grátis",
+ "Menor preço",
+ "Em promoção",
+ "Todos os consoles",
+ "1 jogo",
};
constexpr Column kSpanish = {
@@ -228,6 +260,22 @@ constexpr Column kSpanish = {
"Escanea para abrir la página de la tienda",
"Buscar en %s",
"GRATIS",
+ "Ocultar",
+ "Mostrar",
+ "Ocultos",
+ "\xE2\x96\xA1 vuelve a mostrar un juego",
+ "Oculto: búscalo en Tus juegos > Ocultos",
+ "Visible de nuevo",
+ "Ordenar: %s",
+ "Recientes primero",
+ "A-Z",
+ "Por consola",
+ "Ordenar",
+ "Gratis",
+ "Menor precio",
+ "En oferta",
+ "Todas las consolas",
+ "1 juego",
};
constexpr Column kFrench = {
@@ -294,6 +342,22 @@ constexpr Column kFrench = {
"Scannez pour ouvrir la page du magasin",
"Rechercher dans %s",
"GRATUIT",
+ "Masquer",
+ "Afficher",
+ "Masqués",
+ "\xE2\x96\xA1 réaffiche un jeu",
+ "Masqué : voir Vos jeux > Masqués",
+ "De nouveau visible",
+ "Trier : %s",
+ "Récents d'abord",
+ "A-Z",
+ "Par console",
+ "Trier",
+ "Gratuit",
+ "Prix croissant",
+ "En promotion",
+ "Toutes les consoles",
+ "1 jeu",
};
constexpr Column kGerman = {
@@ -360,6 +424,22 @@ constexpr Column kGerman = {
"Scannen, um die Store-Seite zu öffnen",
"Suchen in %s",
"KOSTENLOS",
+ "Ausblenden",
+ "Einblenden",
+ "Ausgeblendet",
+ "\xE2\x96\xA1 blendet ein Spiel wieder ein",
+ "Ausgeblendet: unter Deine Spiele > Ausgeblendet",
+ "Wieder sichtbar",
+ "Sortieren: %s",
+ "Zuletzt gespielt",
+ "A-Z",
+ "Nach Konsole",
+ "Sortieren",
+ "Kostenlos",
+ "Niedrigster Preis",
+ "Im Angebot",
+ "Alle Konsolen",
+ "1 Spiel",
};
constexpr Column kItalian = {
@@ -426,6 +506,22 @@ constexpr Column kItalian = {
"Scansiona per aprire la pagina dello store",
"Cerca in %s",
"GRATIS",
+ "Nascondi",
+ "Mostra",
+ "Nascosti",
+ "\xE2\x96\xA1 mostra di nuovo un gioco",
+ "Nascosto: lo trovi in I tuoi giochi > Nascosti",
+ "Di nuovo visibile",
+ "Ordina: %s",
+ "Recenti prima",
+ "A-Z",
+ "Per console",
+ "Ordina",
+ "Gratis",
+ "Prezzo più basso",
+ "In offerta",
+ "Tutte le console",
+ "1 gioco",
};
constexpr std::array<const Column*, kLangs> kTable = {&kEnglish, &kPortugueseBR, &kSpanish,
diff --git a/src/ui/strings.h b/src/ui/strings.h
index 1123020..ab8d6ec 100644
--- a/src/ui/strings.h
+++ b/src/ui/strings.h
@@ -73,6 +73,22 @@ enum class Str {
ScanToBuy,
SearchIn, // "%s" = tab name
Free, // price 0 (free-to-play games still "bought" in the store)
+ Hide,
+ Unhide,
+ HiddenSection, // section of hidden games in "Your games"
+ HiddenHint,
+ HiddenToast,
+ UnhiddenToast,
+ SortLabel, // "%s" = sort name
+ SortRecent,
+ SortAZ,
+ SortConsole,
+ SortHint, // hint for R3
+ FilterFree,
+ FilterCheapest,
+ FilterSale,
+ FilterAllConsoles,
+ OneGame, // GamesCount for exactly one
Count
};
diff --git a/src/xcloud/gssv.cpp b/src/xcloud/gssv.cpp
index bf87806..12f9310 100644
--- a/src/xcloud/gssv.cpp
+++ b/src/xcloud/gssv.cpp
@@ -236,6 +236,7 @@ bool GssvClient::listTitles(std::vector<Title>& out, std::string& err, bool rece
title.productId = t["details"]["productId"].str();
title.hasEntitlement = t["details"]["hasEntitlement"].asBool();
title.xboxTitleId = t["details"]["xboxTitleId"].str();
+ title.isFreeInStore = t["details"]["isFreeInStore"].asBool();
if (!title.titleId.empty()) out.push_back(std::move(title));
}
continuation = recentOnly ? std::string() : (*j)["continuationToken"].str();
diff --git a/src/xcloud/gssv.h b/src/xcloud/gssv.h
index 2b3c781..fd92c67 100644
--- a/src/xcloud/gssv.h
+++ b/src/xcloud/gssv.h
@@ -37,6 +37,7 @@ struct Title {
std::string imageUrl; // box art / tile
bool hasEntitlement = false;
std::string xboxTitleId; // Xbox Live title id (titlehub)
+ bool isFreeInStore = false;
};
enum class SessionState { Unknown, Provisioning, WaitingForResources, ReadyToConnect, Provisioned, Failed };