// SPDX-License-Identifier: GPL-3.0-only bool App::statistics_picker_select(const std::string &kind,const std::string &value) { if(menu_!="statistics"||(!source_&&!engine_mode_)||statistics_trophy_.contains("asset"))return false; const auto items=statistics_picker_items(kind); if(std::none_of(items.begin(),items.end(),[&](const auto &item){return item.first==value;}))return false; statistics_remember_scroll(); if(kind=="winner-country")statistics_view_["winner_country"]=value; else { const auto field=kind=="stat-section"?"section":kind=="stat-category"?"category":"country"; statistics_view_[field]=std::stoi(value); } if(engine_mode_)engine_statistics_load(); return true; } bool App::statistics_action(const std::string &action,Rml::Element *target) { if(!action.starts_with("statistics-"))return false; if(menu_!="statistics"||(!source_&&!engine_mode_))return true; if(action=="statistics-trophy-close") { if(statistics_trophy_.contains("asset")) { focus_after_render_=statistics_trophy_.value("return_focus","");statistics_trophy_=Json::object();refresh(); } return true; } if(!target||statistics_trophy_.contains("asset")||!report_detail_kind_.empty()||!report_picker_.empty())return true; const auto data=statistics_data(); if(!data.value("ok",false))return true; statistics_remember_scroll(); if(action=="statistics-absolute"&&data.at("section")==2)statistics_view_["absolute"]=!data.at("absolute").get(); else if(action=="statistics-curve"&&data.at("section")==2) { const int index=target->GetAttribute("data-index",-1);if(index<0||index>=6)return true; auto curves=data.at("curves");curves[size_t(index)]=!curves[size_t(index)].get();statistics_view_["curves"]=curves; } else if(action=="statistics-trophy") { const int r=target->GetAttribute("data-row",-2),c=target->GetAttribute("data-column",-1); if(c<0||c>=int(data.at("columns").size()))return true; Json entry; if(r==-1&&data.at("section")==7)entry=data.at("columns")[size_t(c)]; else if(r>=0&&r(); if(!world_||(!world_->find("clubs",winner)&&!world_->find("nations",winner)))return true; const std::map captions{{"championship","Deutscher Meister"},{"dfb-cup","DFB-Pokalsieger"},{"supercup","Supercup-Sieger"},{"champions-league","Champions-League-Sieger"},{"cup-winners","Europapokalsieger"},{"uefa-cup","UEFA-Cup-Sieger"},{"world-cup","Weltmeister"},{"european-championship","Europameister"},{"indoor-masters","Hallenmasters-Sieger"},{"en-premier-league","Englischer Meister"},{"en-fa-cup","FA-Cup-Sieger"},{"fr-ligue-1","Französischer Meister"},{"fr-coupe-de-france","Coupe-de-France-Sieger"},{"it-serie-a","Italienischer Meister"},{"it-coppa-italia","Coppa-Italia-Sieger"},{"es-la-liga","Spanischer Meister"},{"es-copa-del-rey","Copa-del-Rey-Sieger"}}; const auto title=captions.contains(trophy)?captions.at(trophy):entry.value("text","Sieger"); statistics_trophy_={{"asset",asset},{"title",title},{"winner",winner},{"season",entry.value("season",data.value("previous_season",""))},{"return_focus",target->GetId()}}; focus_after_render_="statistics-trophy-close"; } else return true; if(engine_mode_&&action!="statistics-trophy")engine_statistics_load(); if(action!="statistics-trophy")focus_after_render_=target->GetId(); refresh();return true; } bool App::statistics_event(Rml::Event &event) { if(menu_!="statistics")return false; const auto type=event.GetType();const bool keyboard=type=="keydown"; const auto key=keyboard?Rml::Input::KeyIdentifier(event.GetParameter("key_identifier",0)):Rml::Input::KI_UNKNOWN; if(statistics_trophy_.contains("asset")) { if((keyboard&&key==Rml::Input::KI_ESCAPE)||(type=="mouseup"&&event.GetParameter("button",0)==1)) { statistics_action("statistics-trophy-close",nullptr);event.StopImmediatePropagation();return true; } if(keyboard&&key==Rml::Input::KI_TAB) { if(auto *close=element("statistics-trophy-close"))close->Focus(true); event.StopImmediatePropagation();return true; } bool inside=false; for(auto *node=event.GetTargetElement();node&&node!=doc_;node=node->GetParentNode())if(node->GetId()=="statistics-trophy-layer")inside=true; if(!inside&&(type=="click"||type=="dblclick"||type=="mousedown"||type=="mouseup"||keyboard)) {event.StopImmediatePropagation();return true;} return false; } if(!keyboard||key!=Rml::Input::KI_TAB||!report_detail_kind_.empty()||!report_picker_.empty())return false; 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");}); if(!controls.empty()) { const auto found=std::find(controls.begin(),controls.end(),context_->GetFocusElement()); const int old=found==controls.end()?-1:int(found-controls.begin()),count=int(controls.size()); const bool back=event.GetParameter("shift_key",0)!=0; const int next=old<0?(back?count-1:0):(old+(back?-1:1)+count)%count; controls[size_t(next)]->Focus(true);controls[size_t(next)]->ScrollIntoView({Rml::ScrollAlignment::Nearest});dirty_=true; } event.StopImmediatePropagation();return true; }