Port achievements and player rankings to the Modern UI (by Codex)
This commit is contained in:
1 parent
d419943e86
commit
96e88c9579
29 files changed
+1362
-17
No files matched your search
@@ -0,0 +1,69 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
bool App::rankings_action(const std::string &action, Rml::Element *target) {
|
||||
if (!action.starts_with("rankings-")) return false;
|
||||
if (menu_ != "scorers" || !world_ || !target) return true;
|
||||
rankings_remember_scroll();
|
||||
const auto value = target->GetAttribute<Rml::String>("data-value", "");
|
||||
if (action == "rankings-tab") {
|
||||
const int kind = target->GetAttribute<int>("data-kind", -1);
|
||||
if (kind < 0 || kind > 3) return true;
|
||||
rankings_view_["tab"] = kind;
|
||||
focus_after_render_ = "player-stat-tab-" + std::to_string(kind);
|
||||
} else if (action == "rankings-country") {
|
||||
const auto leagues = world_->leagues(value);
|
||||
if (leagues.empty()) return true;
|
||||
rankings_view_["league"] = leagues.front()->at("id");
|
||||
} else if (action == "rankings-league") {
|
||||
const auto *league = world_->find("competitions", value);
|
||||
if (!league || league->value("type", "") != "league") return true;
|
||||
rankings_view_["league"] = value;
|
||||
} else if (action == "rankings-scope") {
|
||||
if (value != "0" && value != "1") return true;
|
||||
rankings_view_["scope"] = value == "1" ? 1 : 0;
|
||||
} else return true;
|
||||
refresh();
|
||||
return true;
|
||||
}
|
||||
bool App::rankings_event(Rml::Event &event) {
|
||||
if (menu_ != "scorers" || !report_detail_kind_.empty() ||
|
||||
!report_picker_.empty() || event.GetType() != "keydown") return false;
|
||||
auto *target = event.GetTargetElement();
|
||||
const auto key = Rml::Input::KeyIdentifier(event.GetParameter<int>("key_identifier", 0));
|
||||
if (key == Rml::Input::KI_TAB) {
|
||||
Rml::ElementList controls;
|
||||
if (auto *canvas = element("canvas"))
|
||||
canvas->QuerySelectorAll(controls, ".window button,.window input,.window select");
|
||||
std::erase_if(controls, [](auto *node) {
|
||||
return !node->IsVisible(true) || node->HasAttribute("disabled") ||
|
||||
(node->GetId().starts_with("player-stat-tab-") &&
|
||||
node->template GetAttribute<Rml::String>("aria-selected", "false") != "true");
|
||||
});
|
||||
if (!controls.empty()) {
|
||||
const auto found = std::find(controls.begin(), controls.end(), context_->GetFocusElement());
|
||||
const bool backwards = event.GetParameter<int>("shift_key", 0) != 0;
|
||||
const int count = int(controls.size()), old = found == controls.end() ? -1 : int(found - controls.begin());
|
||||
const int next = old < 0 ? (backwards ? count - 1 : 0)
|
||||
: (old + (backwards ? -1 : 1) + count) % count;
|
||||
controls[size_t(next)]->Focus(true);
|
||||
if (controls[size_t(next)]->GetId().starts_with("rankings-player-") ||
|
||||
controls[size_t(next)]->GetId().starts_with("rankings-club-"))
|
||||
controls[size_t(next)]->ScrollIntoView(Rml::ScrollIntoViewOptions(Rml::ScrollAlignment::Nearest));
|
||||
dirty_ = true;
|
||||
}
|
||||
event.StopImmediatePropagation();
|
||||
return true;
|
||||
}
|
||||
if (!target || !target->GetId().starts_with("player-stat-tab-")) return false;
|
||||
const int current = rankings_view_.value("tab", 0);
|
||||
int next = current;
|
||||
if (key == Rml::Input::KI_LEFT) next = (current + 3) % 4;
|
||||
else if (key == Rml::Input::KI_RIGHT) next = (current + 1) % 4;
|
||||
else if (key == Rml::Input::KI_HOME) next = 0;
|
||||
else if (key == Rml::Input::KI_END) next = 3;
|
||||
else return false;
|
||||
rankings_remember_scroll();
|
||||
rankings_view_["tab"] = next;
|
||||
focus_after_render_ = "player-stat-tab-" + std::to_string(next);
|
||||
refresh(); event.StopImmediatePropagation();
|
||||
return true;
|
||||
}
|
||||
Reference in new issue
Block a user