Xbox Cloud Gaming app for PS5 Homebrew
C
Search filters: play mode, genre and language lists; On sale removed
Rafael Abud Ferreira52f386cff4df
diff --git a/src/app/autoplay.cpp b/src/app/autoplay.cppindex 35ee711..a426d2d 100644--- a/src/app/autoplay.cpp+++ b/src/app/autoplay.cpp@@ -447,12 +447,15 @@ void autoplayScreens(const ui::Canvas& canvas, uint64_t now) {for (const auto& [name, p] : g_ui->searchResults(12))XC_LOGI("search %s %2d: %.2f (was %.2f) %s", what, ++i, p.list, p.msrp, name.c_str());};- if (step == 0 && now - since > 20000) g_ui->showFilteredSearch(1), ++step;+ if (step == 0 && now - since > 20000) g_ui->showFilteredSearch(ui::Tab::Library, true, 0, "", 0), ++step;else if (step == 1 && now - since > 24000) saveCanvas("cheapest.ppm"), logResults("lowest"), ++step;- else if (step == 2) g_ui->showFilteredSearch(2), ++step;- else if (step == 3 && now - since > 28000) {- saveCanvas("sale.ppm");- logResults("sale");+ // Game Pass, online co-op and spoken in the app's language, once the+ // details have had time to arrive.+ else if (step == 2 && now - since > 60000) g_ui->showFilteredSearch(ui::Tab::GamePass, false, 3, "", 2), ++step;+ else if (step == 3 && now - since > 63000) saveCanvas("filters.ppm"), logResults("co-op, dubbed"), ++step;+ else if (step == 4) g_ui->showFilteredSearch(ui::Tab::GamePass, false, 0, "", 0, 1), ++step; // the genres' list+ else if (step == 5 && now - since > 66000) {+ saveCanvas("genres.ppm");g_autoplay.searchTest = false;XC_LOGI("AUTOPLAY END: search test");}diff --git a/src/app/autoplay.h b/src/app/autoplay.hindex 6042049..a68268e 100644--- a/src/app/autoplay.h+++ b/src/app/autoplay.h@@ -60,7 +60,8 @@ struct Autoplay {bool updateTest = false; // updatetest: accept the update pop-up, save update.ppm / updating.ppmbool updateSkip = false; // updateskip: "Not now" on the update pop-upbool settingsUpdate = false; // settingsupdate: Settings > Updates, Cross- bool searchTest = false; // searchtest: "Your games" by lowest price, then on sale (cheapest.ppm, sale.ppm)+ bool searchTest = false; // searchtest: lowest price, Game Pass co-op + dubbed, the genres' list+ // (cheapest.ppm, filters.ppm, genres.ppm)bool tuneTest = false; // tunetest: the dead zone's stick tester and the trigger tester (sticks.ppm, triggers.ppm)bool confirmTest = false; // confirmtest: physical Cross / Circle presses through Settings > Confirm buttonbool menuShot = false; // menushot: the game menu open over the 10 s snapshot (screen.ppm)diff --git a/src/app/library.cpp b/src/app/library.cppindex ace6cc0..a076d14 100644--- a/src/app/library.cpp+++ b/src/app/library.cpp@@ -36,6 +36,13 @@ json::Value productToJson(const xcloud::Product& p) {json::Value cats = json::Value::array();for (const auto& c : p.categories) cats.push(c);v.set("categories", cats);+ if (p.detailed) {+ v.set("d", true);+ v.set("modes", static_cast<int64_t>(p.modes));+ json::Value langs = json::Value::object();+ for (const auto& [lang, bits] : p.languages) langs.set(lang, static_cast<int64_t>(bits));+ v.set("langs", langs);+ }return v;}@@ -51,6 +58,9 @@ xcloud::Product productFromJson(const std::string& id, const json::Value& v) {p.posterUrl = v["poster"].str();p.heroUrl = v["hero"].str();for (const auto& c : v["categories"].items()) p.categories.push_back(c.str());+ p.detailed = v["d"].asBool(false);+ p.modes = static_cast<uint32_t>(v["modes"].asInt(0));+ for (const auto& [lang, bits] : v["langs"].members()) p.languages[lang] = static_cast<uint8_t>(bits.asInt(0));return p;}@@ -102,6 +112,10 @@ ui::GameTile Library::tile(const std::string& productId, const std::string& titlt.tileUrl = p.tileUrl.empty() ? p.posterUrl : p.tileUrl;t.heroUrl = p.heroUrl;t.categories = p.categories;+ t.detailed = p.detailed;+ t.modes = p.modes;+ if (auto lang = p.languages.find(language_.substr(0, language_.find('-'))); lang != p.languages.end())+ t.languages = lang->second; // in the app's languageif (ownershipKnown_) t.playable = ownedTitles_.count(t.titleId) || ownedProducts_.count(t.productId);t.freeInStore = freeInStore_.count(productId) > 0;// A free-to-play game not on the account yet is got like one bought@@ -230,8 +244,10 @@ void Library::saveCache() const {root.set("ownedProducts", prods);root.set("owned", itemsToJson(owned_));root.set("purchasable", itemsToJson(purchasable_));- // Details of everything on the home screen and in "Your games": the next- // launch shows them, hero art and all, before the network answers.+ // Details of everything on the home screen, in "Your games" and in the+ // Game Pass search: the next launch shows them, hero art and all, before+ // the network answers, and the search's filters (play modes, languages)+ // work without asking again.json::Value details = json::Value::object();auto keep = [&](const std::string& pid) {auto it = products_.find(pid);@@ -241,6 +257,7 @@ void Library::saveCache() const {for (const auto& item : r.items) keep(item.first);for (const auto* list : {&owned_, &purchasable_})for (const auto& [pid, tid] : *list) keep(pid);+ for (const auto& pid : allGames_) keep(pid);root.set("products", details);json::Value platforms = json::Value::object(), xboxTitles = json::Value::object();for (const auto& [id, code] : platform_) platforms.set(id, code);@@ -464,6 +481,11 @@ void Library::loadCatalogNames(const Changed& changed, const std::atomic<bool>*if (old != products_.end()) {if (p.heroUrl.empty()) p.heroUrl = old->second.heroUrl;if (p.description.empty() && !otherLanguage_.count(id)) p.description = old->second.description;+ if (!p.detailed && old->second.detailed) { // modes and languages don't change with the language+ p.detailed = true;+ p.modes = old->second.modes;+ p.languages = old->second.languages;+ }}products_[id] = std::move(p);otherLanguage_.erase(id);@@ -480,28 +502,47 @@ void Library::loadCatalogNames(const Changed& changed, const std::atomic<bool>*bool Library::fetchFull(const std::vector<std::string>& ids, const Changed& changed, const std::atomic<bool>* stop,size_t firstBatch) {+ bool ok = true;+ int batches = 0;std::vector<std::string> order;std::set<std::string> queued;for (const auto& id : ids) {auto it = products_.find(id);- if ((it == products_.end() || it->second.heroUrl.empty() || it->second.description.empty()) &&+ if ((it == products_.end() || it->second.heroUrl.empty() || it->second.description.empty() ||+ !it->second.detailed) &&queued.insert(id).second)order.push_back(id);}+ // Batches of 20 (~10 KB per product: bigger ones made the catalog time+ // out, 504, and weren't faster).for (size_t i = 0, n = firstBatch; i < order.size(); i += n, n = 20) {if (stop && *stop) return true;std::vector<std::string> batch(order.begin() + static_cast<long>(i),order.begin() + static_cast<long>(std::min(order.size(), i + n)));std::map<std::string, xcloud::Product> full;std::string e;- if (!xcloud::fetchProducts(batch, market_, language_, full, e, true)) {- XC_LOGW("%s", e.c_str());- return false;+ // A batch that fails (a timeout now and then) is asked again; one+ // that keeps failing is left for next time, and the rest carries on.+ bool got = false;+ for (int attempt = 0; attempt < 3 && !got; ++attempt) {+ if (attempt) platform::sleepMs(1000);+ got = xcloud::fetchProducts(batch, market_, language_, full, e, true);+ if (!got) XC_LOGW("%s%s", e.c_str(), attempt < 2 ? " (asking again)" : " (skipped)");+ }+ if (!got) {+ ok = false;+ continue;+ }+ for (const auto& id : batch) {+ // Not in the catalog's details: nothing more to know, not asked again.+ auto known = products_.find(id);+ if (!full.count(id) && known != products_.end()) known->second.detailed = true;}for (auto& [id, p] : full) products_[id] = std::move(p);changed();+ if (++batches % 4 == 0) saveCache(); // a long fetch keeps what it got if the app closes}- return true;+ return ok;}void Library::fetchPlatformsFor(const std::vector<std::string>& ids, const std::string& xblAuth) {@@ -567,8 +608,17 @@ void Library::hydrate(const Changed& changed, const std::atomic<bool>* stop) {for (const auto& r : layout_)for (const auto& item : r.items) ids.push_back(item.first);for (const auto& item : owned_) ids.push_back(item.first);- if (fetchFull(ids, changed, stop)) saveCache(); // descriptions and hero art for next time- XC_LOGI("library: %zu rows, %zu products with details", layout_.size(), products_.size());+ // Then every game the search goes through: its filters (play mode,+ // language) need the full details.+ for (const auto& item : purchasable_) ids.push_back(item.first);+ ids.insert(ids.end(), allGames_.begin(), allGames_.end());+ uint64_t t0 = platform::nowMs();+ fetchFull(ids, changed, stop);+ saveCache(); // descriptions, hero art, modes and languages for next time+ size_t detailed = 0;+ for (const auto& [id, p] : products_) detailed += p.detailed;+ XC_LOGI("library: %zu rows, %zu of %zu products with details (%llu s)", layout_.size(), detailed, products_.size(),+ static_cast<unsigned long long>((platform::nowMs() - t0) / 1000));}} // namespace xc::appdiff --git a/src/app/library.h b/src/app/library.hindex 817305f..503cd21 100644--- a/src/app/library.h+++ b/src/app/library.h@@ -55,7 +55,9 @@ public:void loadCatalogNames(const Changed& changed, const std::atomic<bool>* stop = nullptr);// Console generation of every known game; `xblAuth` from the profile.void loadPlatforms(const std::string& xblAuth, const Changed& changed, const std::atomic<bool>* stop = nullptr);- // Hero art and descriptions, in batches; stops early when `stop` is set.+ // Hero art, descriptions, play modes and languages (the full details), in+ // batches: the rows, the account's games, then the rest of the search's+ // games; stops early when `stop` is set.void hydrate(const Changed& changed, const std::atomic<bool>* stop = nullptr);std::vector<ui::GameRow> rows() const;diff --git a/src/ui/app_ui.cpp b/src/ui/app_ui.cppindex bb855cc..ea90144 100644--- a/src/ui/app_ui.cpp+++ b/src/ui/app_ui.cpp@@ -3,6 +3,7 @@#include "ui/app_ui.h"#include "input/tuning.h"+#include "xcloud/catalog.h"#include "ui/accent_color.h"#include "ui/brand.h"@@ -421,7 +422,7 @@ void AppUi::setPrices(const std::map<std::string, PriceInfo>& prices) {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_))+ if (searching_ && searchOnKeys_ && tab_ == Tab::Library && (filterCheapest_ || filterFree_))runSearch();dirty_ = true;}@@ -513,15 +514,23 @@ const GameTile* AppUi::libraryTile(int index) const {return i < hiddenTiles_.size() ? &hiddenTiles_[i] : nullptr;}-void AppUi::showFilteredSearch(int filterIndex) {+void AppUi::showFilteredSearch(Tab tab, bool cheapest, int mode, const std::string& genre, int language, int openList) {std::lock_guard<std::mutex> lock(mutex_);screen_ = Screen::Home;- tab_ = Tab::Library;+ tab_ = tab;searching_ = true;+ searchOnKeys_ = true;query_.clear();- filterFree_ = filterCheapest_ = filterSale_ = false;+ filterFree_ = false;+ filterCheapest_ = cheapest;filterConsole_ = 0;- pressFilter(filterIndex);+ filterMode_ = mode;+ filterGenre_ = genre;+ filterLanguage_ = language;+ runSearch();+ keyRow_ = kKeyRows + 2; // the row of lists+ keyCol_ = std::max(0, openList);+ if (openList >= 0) pressFilter(filterRow(1)[static_cast<size_t>(openList)]);dirty_ = true;}@@ -589,20 +598,29 @@ void AppUi::runSearch() {if (j > i) words.push_back(q.substr(i, j - i));i = j + 1;}- bool filtering = anyFilter() && (tab_ == Tab::Library || filterConsole_);+ bool filtering = anyFilter();if (words.empty() && !filtering) return;std::string compact = withoutSpaces(q);static const char* kConsoleCodes[] = {"", "XS", "ONE", "360"};struct Hit {int score;double order; // the price now (with any discount), by the active order filter- double discount; // On sale: the bigger first among equal prices+ double discount; // the bigger first among equal pricesconst 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;+ // Play mode and language need the full details: a game without them+ // yet comes in when they arrive.+ static constexpr uint32_t kModeBits[] = {0, xcloud::kModeSingle, xcloud::kModeOnlineMulti, xcloud::kModeOnlineCoop,+ xcloud::kModeLocal};+ if (filterMode_ && !(t.modes & kModeBits[filterMode_])) continue;+ if (filterLanguage_ == 1 && !(t.languages & (xcloud::kLangInterface | xcloud::kLangSubtitles))) continue;+ if (filterLanguage_ == 2 && !(t.languages & xcloud::kLangAudio)) continue;+ if (!filterGenre_.empty() && std::find(t.categories.begin(), t.categories.end(), filterGenre_) == t.categories.end())+ continue;auto price = prices_.find(t.productId);bool priced = price != prices_.end();if (tab_ == Tab::Library) {@@ -614,10 +632,9 @@ void AppUi::runSearch() {if (filterFree_ && !freeToPlay && !zeroNow) continue; // Free: both// Free-to-play games have their own filter: the price orders// leave them out, unless Free is on too. Giveaways stay (first).- if ((filterCheapest_ || filterSale_) && freeToPlay && !filterFree_) continue;+ if (filterCheapest_ && freeToPlay && !filterFree_) 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;+ if (filterCheapest_ && !t.purchasable) continue;}std::string name = fold(t.name);int score = 0;@@ -630,14 +647,15 @@ void AppUi::runSearch() {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- // Both price orders go by the price now, lowest first (on sale: the- // discounted price, not the regular one); unknown prices last.+ // Lowest price: by the price now (with any discount, not the regular+ // one), lowest first; unknown prices last; the bigger discount first+ // among equal prices.double order = 0, discount = 0;- if (filterCheapest_ || filterSale_) order = priced ? price->second.list : 1e12;- if (filterSale_ && priced) discount = 1.0 - price->second.list / price->second.msrp;+ if (filterCheapest_) order = priced ? price->second.list : 1e12;+ if (filterCheapest_ && priced && price->second.msrp > 0) discount = 1.0 - price->second.list / price->second.msrp;hits.push_back({score, order, discount, &t});}- bool byOrder = tab_ == Tab::Library && (filterCheapest_ || filterSale_);+ bool byOrder = tab_ == Tab::Library && filterCheapest_;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 (byOrder && a.discount != b.discount) return a.discount > b.discount;@@ -1124,6 +1142,7 @@ void AppUi::handleHome(const NavInput& in, UiEvent& ev) {screen_ = Screen::Settings;settingsRow_ = 0;dropdownOpen_ = false;+ filterList_ = -1;dirty_ = true;return;}@@ -1137,7 +1156,7 @@ void AppUi::handleHome(const NavInput& in, UiEvent& ev) {}if (searching_) {if (searchOnKeys_) {- if (in.back || in.triangle) { // close the search+ if ((in.back || in.triangle) && filterList_ < 0) { // close the search (Circle closes an open list first)searching_ = false;dirty_ = true;return;@@ -1273,45 +1292,134 @@ void AppUi::handleHome(const NavInput& in, UiEvent& ev) {}}-std::vector<std::string> AppUi::filterLabels() const {+bool AppUi::anyFilter() const {+ // Caller holds mutex_. Free and Lowest price only count in "Your games".+ bool library = tab_ == Tab::Library && (filterFree_ || filterCheapest_);+ return library || filterConsole_ || filterMode_ || !filterGenre_.empty() || filterLanguage_;+}++std::vector<AppUi::Filter> AppUi::filterRow(int row) 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};+ // games aren't bought).+ if (row == 1) return {Filter::Mode, Filter::Genre, Filter::Language};+ if (tab_ == Tab::GamePass) return {Filter::Console};+ return {Filter::Free, Filter::Cheapest, Filter::Console};+}++std::vector<std::string> AppUi::poolGenres() const {+ // Caller holds mutex_.+ std::map<std::string, int> count;+ for (const auto& t : tab_ == Tab::GamePass ? gamePassPool_ : libraryPool_)+ for (const auto& c : t.categories) ++count[c];+ std::vector<std::pair<int, std::string>> order;+ for (const auto& [g, n] : count) order.push_back({-n, g});+ std::sort(order.begin(), order.end());+ std::vector<std::string> out;+ for (const auto& [n, g] : order) out.push_back(g);+ return out;+}++std::vector<std::string> AppUi::filterOptions(Filter f) const {+ // Caller holds mutex_. The first choice is always "all".+ switch (f) {+ case Filter::Console: return {tr(Str::FilterAllConsoles), "SERIES X|S", "XBOX ONE", "XBOX 360"};+ case Filter::Mode:+ return {tr(Str::ModeAll), tr(Str::ModeSingle), tr(Str::ModeOnlineMulti), tr(Str::ModeOnlineCoop), tr(Str::ModeLocal)};+ case Filter::Genre: {+ std::vector<std::string> out = {tr(Str::GenreAll)};+ for (auto& g : poolGenres()) out.push_back(std::move(g));+ return out;+ }+ case Filter::Language:+ return {tr(Str::LanguageAll), trf(Str::LangSubtitles, tr(Str::LanguageNoun)), trf(Str::LangAudio, tr(Str::LanguageNoun))};+ default: return {};+ }}-void AppUi::pressFilter(int index) {+int AppUi::filterSelected(Filter f) const {// 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;+ if (f == Filter::Console) return filterConsole_;+ if (f == Filter::Mode) return filterMode_;+ if (f == Filter::Language) return filterLanguage_;+ if (f == Filter::Genre) {+ auto genres = poolGenres();+ for (size_t i = 0; i < genres.size(); ++i)+ if (genres[i] == filterGenre_) return static_cast<int>(i) + 1;+ }+ return 0;+}++void AppUi::chooseFilter(Filter f, int index) {+ // Caller holds mutex_.+ if (f == Filter::Console) filterConsole_ = index;+ if (f == Filter::Mode) filterMode_ = index;+ if (f == Filter::Language) filterLanguage_ = index;+ if (f == Filter::Genre) {+ auto genres = poolGenres();+ filterGenre_ = index > 0 && index <= static_cast<int>(genres.size()) ? genres[static_cast<size_t>(index - 1)] : "";}runSearch();+ dirty_ = true;+}++std::string AppUi::filterText(Filter f) const {+ // Caller holds mutex_. A list shows its name until a choice is made.+ if (f == Filter::Free) return tr(Str::FilterFree);+ if (f == Filter::Cheapest) return tr(Str::FilterCheapest);+ int sel = filterSelected(f);+ if (sel > 0 || f == Filter::Console) {+ auto options = filterOptions(f);+ if (sel < static_cast<int>(options.size())) return options[static_cast<size_t>(sel)];+ }+ return tr(f == Filter::Mode ? Str::FilterMode : f == Filter::Genre ? Str::FilterGenre : Str::FilterLanguage);+}++bool AppUi::filterOn(Filter f) const {+ // Caller holds mutex_.+ if (f == Filter::Free) return filterFree_;+ if (f == Filter::Cheapest) return filterCheapest_;+ return filterSelected(f) > 0;+}++void AppUi::pressFilter(Filter f) {+ // Caller holds mutex_. A list opens its drop-down at the current choice.+ if (isList(f)) {+ filterList_ = static_cast<int>(f);+ filterListIndex_ = filterSelected(f);+ filterListTop_ = 0;+ } else {+ (f == Filter::Free ? filterFree_ : filterCheapest_) ^= true;+ runSearch();+ }+ dirty_ = true;}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); kKeyRows + 1 the filters.- bool wide = keyRow_ == kKeyRows, filters = keyRow_ == kKeyRows + 1;- int filterCount = static_cast<int>(filterLabels().size());+ // keyCol_ is 0..2 (Space, Delete, Clear); kKeyRows + 1 and + 2 the two+ // rows of filters.+ if (filterList_ >= 0) {+ // A filter's drop-down: up / down, Cross picks, Circle closes it unchanged.+ Filter f = static_cast<Filter>(filterList_);+ int n = static_cast<int>(filterOptions(f).size());+ if (in.down && filterListIndex_ + 1 < n) ++filterListIndex_;+ if (in.up && filterListIndex_ > 0) --filterListIndex_;+ if (in.accept) chooseFilter(f, filterListIndex_);+ if (in.accept || in.back) filterList_ = -1;+ dirty_ = true;+ return;+ }+ bool wide = keyRow_ == kKeyRows, filters = keyRow_ > kKeyRows;+ int filterCount = filters ? static_cast<int>(filterRow(keyRow_ - kKeyRows - 1).size()) : 0;if (in.up && keyRow_ > 0) {if (wide) keyCol_ = kWideCols[keyCol_];- if (filters) keyCol_ = std::min(keyCol_, 2);+ if (keyRow_ == kKeyRows + 1) keyCol_ = std::min(keyCol_, 2);--keyRow_;- } else if (in.down && keyRow_ < kKeyRows + 1) {+ if (keyRow_ == kKeyRows + 1) keyCol_ = std::min(keyCol_, static_cast<int>(filterRow(0).size()) - 1);+ } else if (in.down && keyRow_ < kKeyRows + 2) {++keyRow_;if (keyRow_ == kKeyRows) keyCol_ = keyCol_ < 3 ? 0 : keyCol_ < 5 ? 1 : 2;- else if (keyRow_ == kKeyRows + 1) keyCol_ = std::min(keyCol_, filterCount - 1);+ else keyCol_ = std::min(keyCol_, static_cast<int>(filterRow(keyRow_ - kKeyRows - 1).size()) - 1);} else if (in.left && keyCol_ > 0) {--keyCol_;} else if (in.right) {@@ -1326,7 +1434,7 @@ void AppUi::handleSearchKeys(const NavInput& in) {bool edited = false;if (in.accept) {if (filters) {- pressFilter(keyCol_);+ pressFilter(filterRow(keyRow_ - kKeyRows - 1)[static_cast<size_t>(keyCol_)]);} else if (!wide) {query_ += kKeys[keyRow_ * kKeyCols + keyCol_];} else if (keyCol_ == 0) {@@ -1892,7 +2000,7 @@ void AppUi::drawSearch(Canvas& c, uint64_t nowMs) {drawTopBar(c);drawTabs(c);const char* scope = tab_ == Tab::GamePass ? tr(Str::TabGamePass) : tr(Str::YourGames);- bool filtering = anyFilter() && (tab_ == Tab::Library || filterConsole_);+ bool filtering = anyFilter();if (query_.empty() && !filtering) {fonts_.semibold.draw(c, tr(Str::SearchHint), kResultsX, 150, 26, kDim);} else if (results_.empty()) {@@ -1935,35 +2043,82 @@ 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.gradientV({0, kH - 190, kW, 110}, withAlpha(kBg, 0), withAlpha(kBg, 245));+ c.fillRect({0, kH - 80, kW, 80}, withAlpha(kBg, 245));+ // The filters, two rows under the keys (over the fade): green when on;+ // the lists with a chevron.+ const int kbW2 = kKeyCols * (kKeyW + kKeyGap) - kKeyGap, gap = 10, px = 18, fh = 50;+ const int fy0 = kKeysY + (kKeyRows + 1) * (kKeyH + kKeyGap) + 6;+ Rect openChip{};+ for (int row = 0; row < 2; ++row) {+ auto chips = filterRow(row);+ int fy = fy0 + row * (fh + 10);+ int chipW = (kbW2 - gap * (static_cast<int>(chips.size()) - 1)) / static_cast<int>(chips.size());+ for (size_t k = 0; k < chips.size(); ++k) {+ Filter f = chips[k];+ bool on = filterOn(f);+ bool focused = searchOnKeys_ && keyRow_ == kKeyRows + 1 + row && keyCol_ == static_cast<int>(k);+ Rect chip{kMargin + static_cast<int>(k) * (chipW + gap), fy, chipW, fh};+ if (filterList_ == static_cast<int>(f)) openChip = chip;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;+ Color text = focused ? kBg : kWhite;+ int room = chip.w - (isList(f) ? 44 : 16);+ std::string label = fonts_.semibold.fit(filterText(f), px, room);+ int tw = fonts_.semibold.measure(label, px);+ int tx = chip.x + (isList(f) ? (chip.w - 22 - tw) / 2 : (chip.w - tw) / 2);+ fonts_.semibold.draw(c, label, tx, fonts_.semibold.centeredY(chip.y, chip.h, px), px, text);+ if (isList(f)) { // a list: a chevron at the right+ float cx = static_cast<float>(chip.x + chip.w - 24), cy = static_cast<float>(chip.y + chip.h / 2);+ c.line(cx - 6, cy - 3, cx, cy + 3, 2.5f, text);+ c.line(cx, cy + 3, cx + 6, cy - 3, 2.5f, text);+ }}}- 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_)+ if (filterList_ >= 0) {+ // The open list, above its chip (they are near the bottom); scrolls+ // past kVisible choices.+ Filter f = static_cast<Filter>(filterList_);+ auto options = filterOptions(f);+ int sel = filterSelected(f);+ constexpr int kItemH = 54, kVisible = 9;+ int n = static_cast<int>(options.size()), visible = std::min(n, kVisible);+ if (filterListIndex_ < filterListTop_) filterListTop_ = filterListIndex_;+ if (filterListIndex_ >= filterListTop_ + visible) filterListTop_ = filterListIndex_ - visible + 1;+ int listW = std::max(openChip.w, 460);+ Rect panel{openChip.x, openChip.y - 10 - (visible * kItemH + 16), listW, visible * kItemH + 16};+ panel.y = std::max(120, panel.y);+ c.fillRect({panel.x + 6, panel.y + 10, panel.w, panel.h}, rgba(0, 0, 0, 120), 18); // shadow+ c.fillRect(panel, rgba(38, 38, 38, 250), 18);+ c.strokeRect(panel, rgba(255, 255, 255, 50), 2, 18);+ for (int k = 0; k < visible; ++k) {+ int i = filterListTop_ + k;+ Rect item{panel.x + 8, panel.y + 8 + k * kItemH, panel.w - 16, kItemH};+ bool on = i == filterListIndex_;+ if (on) c.fillRect(item, kWhite, 12);+ Color text = on ? kBg : (i == sel ? kWhite : kGray);+ std::string label = fonts_.semibold.fit(options[static_cast<size_t>(i)], 24, item.w - 70);+ fonts_.semibold.draw(c, label, item.x + 20, fonts_.semibold.centeredY(item.y, item.h, 24), 24, text);+ if (i == sel) { // a check mark on the current choice+ float cx = static_cast<float>(item.x + item.w - 30), cy = static_cast<float>(item.y + item.h / 2);+ c.line(cx - 9, cy, cx - 3, cy + 6, 3, on ? kBg : kGreen);+ c.line(cx - 3, cy + 6, cx + 9, cy - 6, 3, on ? kBg : kGreen);+ }+ }+ if (filterListTop_ > 0) { // more above / below+ float cx = static_cast<float>(panel.x + panel.w / 2), cy = static_cast<float>(panel.y - 12);+ c.line(cx - 9, cy + 4, cx, cy - 4, 3, kGray);+ c.line(cx, cy - 4, cx + 9, cy + 4, 3, kGray);+ }+ if (filterListTop_ + visible < n) {+ float cx = static_cast<float>(panel.x + panel.w / 2), cy = static_cast<float>(panel.y + panel.h + 12);+ c.line(cx - 9, cy - 4, cx, cy + 4, 3, kGray);+ c.line(cx, cy + 4, cx + 9, cy - 4, 3, kGray);+ }+ }+ if (filterList_ >= 0)+ drawHints(c, {{kIconCross, tr(Str::Select)}, {kIconCircle, tr(Str::Back)}});+ else if (searchOnKeys_)drawHints(c, {{kIconCross, tr(Str::KeyType)}, {kIconSquare, tr(Str::KeyDelete)}, {kIconCircle, tr(Str::Back)}});elsedrawHints(c, {{kIconCross, tr(Str::Select)}, {kIconSquare, tr(Str::KeyDelete)}, {kIconCircle, tr(Str::Back)}});diff --git a/src/ui/app_ui.h b/src/ui/app_ui.hindex 58547de..d79a88b 100644--- a/src/ui/app_ui.h+++ b/src/ui/app_ui.h@@ -43,6 +43,12 @@ struct GameTile {std::string platform;// Not a game: the user's own Xbox (Remote Play); titleId is its serverId.bool homeConsole = false;+ // Once the store's full details are in (`detailed`): how it can be+ // played (xcloud::kMode* bits) and what is translated into the app's+ // language (xcloud::kLang* bits).+ bool detailed = false;+ uint32_t modes = 0;+ uint8_t languages = 0;};// One of the user's own consoles, as "My consoles" shows it.@@ -214,9 +220,10 @@ public:Tab tab() const;// Switches the home screen's tab (autoplay tests).void showTab(Tab t);- // Autoplay tests: "Your games" searched with one filter button pressed- // (0 free, 1 lowest price, 2 on sale), and the first results with prices.- void showFilteredSearch(int filterIndex);+ // Autoplay tests: a tab's search with these filters (`mode` and+ // `language` as their lists' index, `genre` "" for all), optionally with+ // `openList` (0 mode, 1 genre, 2 language) open; and the first results.+ void showFilteredSearch(Tab tab, bool cheapest, int mode, const std::string& genre, int language, int openList = -1);std::vector<std::pair<std::string, PriceInfo>> searchResults(size_t max) const;void invalidate();@@ -274,9 +281,20 @@ private: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_; }+ // The search's filters, in two rows: Free, Lowest price (in "Your games"+ // only) and Console; then Mode, Genre and Language. The lists open a+ // drop-down; Free and Lowest price turn on and off.+ enum class Filter { Free, Cheapest, Console, Mode, Genre, Language };+ std::vector<Filter> filterRow(int row) const;+ bool isList(Filter f) const { return f != Filter::Free && f != Filter::Cheapest; }+ std::string filterText(Filter f) const; // the chip's label: its choice when one is made+ bool filterOn(Filter f) const;+ std::vector<std::string> filterOptions(Filter f) const;+ int filterSelected(Filter f) const;+ void chooseFilter(Filter f, int index);+ void pressFilter(Filter f);+ std::vector<std::string> poolGenres() const; // the genres of the tab's games, most common first+ bool anyFilter() const;void handleHome(const NavInput& in, UiEvent& ev);void handleSearchKeys(const NavInput& in);void runSearch();@@ -337,8 +355,13 @@ private:void drawLoadingBar(Canvas& c, int x, int y, int w, uint64_t nowMs);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 filterFree_ = false, filterCheapest_ = false;+ int filterConsole_ = 0; // 0 all, 1 Series X|S, 2 Xbox One, 3 Xbox 360+ int filterMode_ = 0; // 0 all, single, online multiplayer, online co-op, local+ std::string filterGenre_; // empty: all+ int filterLanguage_ = 0; // 0 any, 1 subtitles (or menus) in the app's language, 2 audio+ // The filter whose drop-down is open (-1: none), its focus and first row.+ int filterList_ = -1, filterListIndex_ = 0, filterListTop_ = 0;bool ownedKnown_ = false;int gridFocus_ = 0;Anim gridScroll_;diff --git a/src/ui/strings.cpp b/src/ui/strings.cppindex eb746c0..bb3c828 100644--- a/src/ui/strings.cpp+++ b/src/ui/strings.cpp@@ -109,7 +109,6 @@ constexpr Column kEnglish = {"Sort", // SortHint"Free", // FilterFree"Lowest price", // FilterCheapest- "On sale", // FilterSale"All consoles", // FilterAllConsoles"1 game", // OneGame"Sections", // Sections@@ -214,6 +213,19 @@ constexpr Column kEnglish = {"Style", // TriggerStyle"Vibration", // StyleVibration"Force pulses", // StylePulses+ "Mode", // FilterMode+ "Genre", // FilterGenre+ "Language", // FilterLanguage+ "All modes", // ModeAll+ "Single player", // ModeSingle+ "Online multiplayer", // ModeOnlineMulti+ "Online co-op", // ModeOnlineCoop+ "Local / split screen", // ModeLocal+ "All genres", // GenreAll+ "Any language", // LanguageAll+ "English", // LanguageNoun+ "Subtitles in %s", // LangSubtitles+ "Audio in %s", // LangAudio};constexpr Column kPortugueseBR = {@@ -293,7 +305,6 @@ constexpr Column kPortugueseBR = {"Ordenar","Grátis","Menor preço",- "Em promoção","Todos os consoles","1 jogo","Seções",@@ -398,6 +409,19 @@ constexpr Column kPortugueseBR = {"Estilo","Vibração","Pulsos de força",+ "Modo",+ "Gênero",+ "Idioma",+ "Todos os modos",+ "Um jogador",+ "Multijogador online",+ "Cooperação online",+ "Local / tela dividida",+ "Todos os gêneros",+ "Qualquer idioma",+ "português",+ "Legendas em %s",+ "Dublado em %s",};constexpr Column kSpanish = {@@ -477,7 +501,6 @@ constexpr Column kSpanish = {"Ordenar","Gratis","Menor precio",- "En oferta","Todas las consolas","1 juego","Secciones",@@ -582,6 +605,19 @@ constexpr Column kSpanish = {"Estilo","Vibración","Pulsos de fuerza",+ "Modo",+ "Género",+ "Idioma",+ "Todos los modos",+ "Un jugador",+ "Multijugador en línea",+ "Cooperativo en línea",+ "Local / pantalla dividida",+ "Todos los géneros",+ "Cualquier idioma",+ "español",+ "Subtítulos en %s",+ "Doblado al %s",};constexpr Column kFrench = {@@ -661,7 +697,6 @@ constexpr Column kFrench = {"Trier","Gratuit","Prix croissant",- "En promotion","Toutes les consoles","1 jeu","Sections",@@ -766,6 +801,19 @@ constexpr Column kFrench = {"Style","Vibration","Impulsions de force",+ "Mode",+ "Genre",+ "Langue",+ "Tous les modes",+ "Solo",+ "Multijoueur en ligne",+ "Coopération en ligne",+ "Local / écran partagé",+ "Tous les genres",+ "Toutes les langues",+ "français",+ "Sous-titres en %s",+ "Doublé en %s",};constexpr Column kGerman = {@@ -845,7 +893,6 @@ constexpr Column kGerman = {"Sortieren","Kostenlos","Niedrigster Preis",- "Im Angebot","Alle Konsolen","1 Spiel","Abschnitte",@@ -950,6 +997,19 @@ constexpr Column kGerman = {"Stil","Vibration","Kraftimpulse",+ "Modus",+ "Genre",+ "Sprache",+ "Alle Modi",+ "Einzelspieler",+ "Online-Mehrspieler",+ "Online-Koop",+ "Lokal / geteilter Bildschirm",+ "Alle Genres",+ "Alle Sprachen",+ "Deutsch",+ "Untertitel: %s",+ "Sprachausgabe: %s",};constexpr Column kItalian = {@@ -1029,7 +1089,6 @@ constexpr Column kItalian = {"Ordina","Gratis","Prezzo più basso",- "In offerta","Tutte le console","1 gioco","Sezioni",@@ -1134,6 +1193,19 @@ constexpr Column kItalian = {"Stile","Vibrazione","Impulsi di forza",+ "Modalità",+ "Genere",+ "Lingua",+ "Tutte le modalità",+ "Giocatore singolo",+ "Multigiocatore online",+ "Cooperativa online",+ "Locale / schermo condiviso",+ "Tutti i generi",+ "Qualsiasi lingua",+ "italiano",+ "Sottotitoli in %s",+ "Doppiato in %s",};constexpr std::array<const Column*, kLangs> kTable = {&kEnglish, &kPortugueseBR, &kSpanish,diff --git a/src/ui/strings.h b/src/ui/strings.hindex c5d1168..7c6eae9 100644--- a/src/ui/strings.h+++ b/src/ui/strings.h@@ -86,7 +86,6 @@ enum class Str {SortHint, // hint for R3FilterFree,FilterCheapest,- FilterSale,FilterAllConsoles,OneGame, // GamesCount for exactly oneSections, // hint for L2 / R2: jump between sections@@ -191,6 +190,19 @@ enum class Str {TriggerStyle, // the trigger tester: how the game's vibration is feltStyleVibration,StylePulses, // the resistance pushing and letting go+ FilterMode, // search filter (a list): how a game can be played+ FilterGenre, // search filter (a list)+ FilterLanguage, // search filter (a list): translated into the app's language+ ModeAll,+ ModeSingle,+ ModeOnlineMulti,+ ModeOnlineCoop,+ ModeLocal, // local multiplayer or co-op, split screen+ GenreAll,+ LanguageAll,+ LanguageNoun, // this language's name, as the filters say it+ LangSubtitles, // "%s" = LanguageNoun: subtitles or menus in it+ LangAudio, // "%s" = LanguageNoun: spoken in itCount};diff --git a/src/xcloud/catalog.cpp b/src/xcloud/catalog.cppindex dd6791e..be035ae 100644--- a/src/xcloud/catalog.cpp+++ b/src/xcloud/catalog.cpp@@ -83,6 +83,30 @@ bool fetchProducts(const std::vector<std::string>& ids, const std::string& markeprod.heroUrl = imageUrl(p["Image_Hero"]);if (prod.heroUrl.empty()) prod.heroUrl = imageUrl(p["Image_TitledHero"]);for (const auto& c : p["LocalizedCategories"].items()) prod.categories.push_back(c.str());+ if (full) {+ // How it can be played, from the store's attributes.+ prod.detailed = true;+ for (const auto& a : p["Attributes"].items()) {+ std::string n = a["Name"].str();+ if (n == "SinglePlayer") prod.modes |= kModeSingle;+ if (n == "XblOnlineMultiPlayer" || n == "XblCrossPlatformMultiPlayer" || n == "XboxLiveCrossGenMP")+ prod.modes |= kModeOnlineMulti;+ if (n == "XblOnlineCoop" || n == "XblCrossPlatformCoop") prod.modes |= kModeOnlineCoop;+ if (n == "XblLocalMultiPlayer" || n == "XblLocalCoop" || n == "SharedSplitScreen") prod.modes |= kModeLocal;+ }+ // What is translated, per language: "pt-BR" and "pt-PT" both count as "pt".+ for (const auto& [locale, support] : p["LanguageSupport"].members()) {+ std::string lang = locale.substr(0, locale.find('-'));+ for (const char* kept : kKeptLanguages) {+ if (lang != kept) continue;+ uint8_t bits = 0;+ if (support["InterfaceLanguageSupport"].asInt(0)) bits |= kLangInterface;+ if (support["SubtitlesLanguageSupport"].asInt(0)) bits |= kLangSubtitles;+ if (support["GamePlayAudioLanguageSupport"].asInt(0)) bits |= kLangAudio;+ prod.languages[lang] |= bits;+ }+ }+ }out[id] = std::move(prod);}}diff --git a/src/xcloud/catalog.h b/src/xcloud/catalog.hindex c7063ff..50dfbf5 100644--- a/src/xcloud/catalog.h+++ b/src/xcloud/catalog.h@@ -6,6 +6,7 @@// Public endpoints: no authentication.#pragma once+#include <cstdint>#include <map>#include <string>#include <vector>@@ -23,8 +24,19 @@ struct Product {std::string posterUrl; // 2:3std::string heroUrl; // 16:9 backgroundstd::vector<std::string> categories;+ // From the full details only (`detailed`): how it can be played+ // (kMode* bits) and, per language ("en", "pt"...: any of its locales),+ // what is translated (kLang* bits).+ bool detailed = false;+ uint32_t modes = 0;+ std::map<std::string, uint8_t> languages;};+constexpr uint32_t kModeSingle = 1, kModeOnlineMulti = 2, kModeOnlineCoop = 4, kModeLocal = 8;+constexpr uint8_t kLangInterface = 1, kLangSubtitles = 2, kLangAudio = 4;+// The languages kept from a product's list: the app's own.+constexpr const char* kKeptLanguages[] = {"en", "pt", "es", "fr", "de", "it"};+// Lists shown on xbox.com/play.namespace sigl {constexpr const char* kRecentlyAdded = "06323672-b8c8-43cc-b0de-32d5a9834749";