234 lines
12 KiB
C++
234 lines
12 KiB
C++
// SPDX-License-Identifier: GPL-3.0-only
|
|
// Included in the native UI implementation's anonymous namespace.
|
|
void App::init_desktop() {
|
|
if(!desktop_.contains("objects"))desktop_=default_desktop();
|
|
if(!working_desktop_initialized_){
|
|
working_desktop_initialized_=true;
|
|
const auto file=user_dir()/"working-desktop.json";
|
|
if(config_.state.empty()&&fs::is_regular_file(file)){
|
|
try{auto next=Json::parse(editor::read_file(file));if(!migrate_desktop(next))throw editor::Error("Ungültige Desktopanordnung.");desktop_=std::move(next);}
|
|
catch(const std::exception &){message("Die gespeicherte Desktopanordnung konnte nicht geladen werden. Die Standardansicht wird verwendet.");}
|
|
}
|
|
working_desktop_base_=desktop_;saved_desktop_=desktop_;
|
|
}
|
|
}
|
|
|
|
std::string App::render_desktop() {
|
|
init_desktop();
|
|
const auto s = snap();
|
|
widget_data_=demo_desktop_widgets(*world_,s.state);
|
|
const bool national=s.state.at("career").value("role", "club")=="national";
|
|
const auto *c = club(s);
|
|
std::string out =
|
|
"<div class=\"desktop-layer\"><div class=\"info-bar\">" +
|
|
btn("desktop-context",
|
|
(national?img("career.national-de",82,82,false,false,256):crest(c,82)) + "<span><strong>" + esc(national?"Deutschland":c ? world_->name(*c) : "") +
|
|
"</strong><small>" + esc(manager(s).value("name", "")) +
|
|
"</small></span>",
|
|
"identity", "id=\"desktop-identity\"") +
|
|
"<div class=\"info-date\">" + std::string(widget_data_.at("matchday")==0?"Saisonvorbereitung":std::to_string(widget_data_.at("matchday").get<int>())+". Spieltag") + "<small>" +
|
|
esc(widget_data_.at("season").get<std::string>()) +
|
|
"</small></div><div class=\"info-cash\"><small>"+std::string(national?"Aufgabenbereich":"Guthaben")+"</small><strong>" +
|
|
(national?std::string("Nationalmannschaft"):cash(s.state.value("cash", int64_t(0)))) + "</strong></div></div>";
|
|
if(desktop_.value("grid",true))for(int row=0;row<7;++row)for(int col=0;col<15;++col)out+="<span class=\"desktop-grid-dot\" style=\"left:"+std::to_string(64+col*248)+"dp;top:"+std::to_string(224+row*248)+"dp;\"></span>";
|
|
for (const auto &[id, o] : desktop_["objects"].items()) {
|
|
if (!o.value("visible", false) || (o.value("widget",false)?!demo_career_widget_available(s.state,id):!demo_career_menu_available(s.state,id.substr(4))))
|
|
continue;
|
|
const auto style = rect(o.value("x", 0), o.value("y", 0), o.value("w", 224),
|
|
o.value("h", 224)) + "z-index:" + std::to_string(o.value("z", 1)) + ";";
|
|
if (o.value("widget", false)) {
|
|
std::string size="s",route;
|
|
for(const auto &d:widget_catalogue())if(d.at("id")==id){route=d.value("route","");for(const auto &[key,span]:d.at("spans").items())if(o.at("w")==span[0].get<int>()*248-24&&o.at("h")==span[1].get<int>()*248-24)size=key;}
|
|
out += "<div tabindex=\"0\" data-widget=\""+esc(id)+"\" data-size=\""+size+"\" data-pinned=\""+(o.value("pinned",true)?"true":"false")+"\" "+(route.empty()?"":"data-action=\"open:"+route+"\" ")+"id=\"object-" + esc(id) + "\" data-object=\"" + esc(id) +
|
|
"\" class=\"desktop-card desk-card "+std::string(id=="trash"?"desk-utility":"")+"\" style=\"" + style + "\">" +
|
|
widget(id, o) +
|
|
(o.value("pinned", true) ? "<div class=\"pin-dot\"></div>" : "") +
|
|
"</div>";
|
|
} else {
|
|
const auto route = id.substr(4);
|
|
const std::array<std::string, 32> colors = {
|
|
"#3d789b", "#375a83", "#477c73", "#42846b", "#a58a49", "#586ba0",
|
|
"#517d71", "#668a98", "#af6860", "#6b809c", "#657cb3", "#507b9c",
|
|
"#559b76", "#a7474e", "#967d50", "#648f91", "#54856b", "#558f93",
|
|
"#6379a3", "#788598", "#8d7856", "#a66d64", "#748474", "#6887a2",
|
|
"#6b9270", "#7c8b9c", "#ac8b52", "#7783a4", "#648f83", "#927d9d",
|
|
"#ac5e63", "#806c98"};
|
|
const auto i = std::find(routes.begin(), routes.end(), route);
|
|
const auto color = colors[size_t(i - routes.begin())];
|
|
const auto top = theme_ == "matchday" ? mixed_color(color, "#27282e", .55)
|
|
: mixed_color(color, "#c5ddf1", .1);
|
|
const auto bottom =
|
|
theme_ == "matchday" ? "#272a30" : mixed_color(color, "#07111e", .38);
|
|
out += "<button id=\"object-" + esc(id) + "\" data-object=\"" + esc(id) +
|
|
"\" data-action=\"open:" + route +
|
|
"\" class=\"desktop-app\" style=\"" + style +
|
|
"\"><div class=\"app-tile\" "
|
|
"style=\"decorator:linear-gradient(140deg," +
|
|
top + "," + bottom + ");\">" +
|
|
img("button." + route, 146, 146, false, false, 256) +
|
|
"</div><span class=\"app-name\">" + esc(route=="newplayer"?"Manager":route=="transfer"?"Transfer":title(route)) + "</span>" +
|
|
(o.value("pinned", true) ? "<div class=\"pin-dot\"></div>" : "") +
|
|
"</button>";
|
|
}
|
|
}
|
|
return out + "</div>";
|
|
}
|
|
std::string App::render_camp() {
|
|
const auto index_file =
|
|
Json::parse(editor::read_file(gui_.root() / "gui-assets.json"));
|
|
const auto demo = index_file.at("demo"), camps = demo.at("training_camps");
|
|
const auto s = snap();
|
|
const auto id = s.state.at("camp").value("selected", std::string("resort:4"));
|
|
const Json *chosen = nullptr;
|
|
for (const auto &c : camps)
|
|
if (c.value("id", "") == id)
|
|
chosen = &c;
|
|
if (!chosen)
|
|
chosen = &camps.at(0);
|
|
auto region = selections_["camp-region"];
|
|
if (region.empty())
|
|
region = chosen->value("map", "map:eu");
|
|
std::string body = "<div "
|
|
"style=\"position:absolute;left:0;top:0;width:1440dp;"
|
|
"bottom:0;\"><div class=\"toolbar\">";
|
|
for (const auto &m : demo.at("maps"))
|
|
body += btn("camp-region", esc(m.value("name", "")),
|
|
m.value("id", "") == region ? "primary" : "",
|
|
"data-id=\"" + esc(m.value("id", "")) + "\"");
|
|
body += "</div><div "
|
|
"style=\"position:absolute;left:0;top:120dp;width:1440dp;height:1603."
|
|
"2dp;overflow:hidden;border-radius:22dp;\">" +
|
|
img("map." + region.substr(4), 1440, 1603.2, false, false, 1600);
|
|
for (const auto &c : camps)
|
|
if (c.value("map", "") == region) {
|
|
const double x = c.value("x", 0) * 1.2, y = c.value("y", 0) * 1.2;
|
|
body += btn("camp-select",
|
|
"<span "
|
|
"style=\"display:block;width:18dp;height:18dp;background-"
|
|
"color:#dfb668;border-radius:9dp;\"></span>",
|
|
c.value("id", "") == id ? "primary" : "",
|
|
"data-id=\"" + esc(c.value("id", "")) +
|
|
"\" style=\"position:absolute;" +
|
|
rect(x - 34, y - 34, 68, 68) +
|
|
"padding:23dp;border-radius:34dp;\"");
|
|
}
|
|
body += "</div></div><div "
|
|
"style=\"position:absolute;left:1500dp;right:0;top:0;bottom:0;\"><"
|
|
"div style=\"height:570dp;overflow:hidden;border-radius:24dp;\">" +
|
|
img(chosen->value("gui_image", ""), 1100, 570, false, true, 1400) +
|
|
"</div><h2 style=\"margin-top:22dp;\">" +
|
|
esc(chosen->value("name", "")) +
|
|
"</h2><p class=\"small\" style=\"margin-top:14dp;\">" +
|
|
esc(chosen->value("place", "")) + "</p>";
|
|
const std::array<const char *, 4> qualities = {
|
|
"Platzqualität", "Fitnessgeräte", "Verpflegung", "Unterkunft"};
|
|
for (size_t i = 0; i < 4; ++i) {
|
|
const int q = chosen->at("quality")[i].get<int>();
|
|
std::string stars;
|
|
for (int j = 0; j < q; ++j)
|
|
stars += glyph("star", 32);
|
|
body += "<div class=\"field-row\" style=\"min-height:78dp;padding:12dp "
|
|
"0;\"><span>" +
|
|
std::string(qualities[i]) +
|
|
"</span><span class=\"row\" style=\"gap:5dp;color:#d9b96f;\">" +
|
|
stars + "</span></div>";
|
|
}
|
|
body += "<div class=\"field-row\"><strong>Preis</strong><strong "
|
|
"class=\"accent\">" +
|
|
cash(chosen->value("price", int64_t(0))) + "</strong></div>";
|
|
const std::array<const char *, 4> focus = {"Kondition", "Technik", "Spiel",
|
|
"Erholung"};
|
|
const auto values = s.state.at("camp").at("focus");
|
|
int sum = 0;
|
|
for (const auto &v : values)
|
|
sum += v.get<int>();
|
|
for (int i = 0; i < 4; ++i) {
|
|
const int value = i == 3 ? 15 - sum / 3 : values[size_t(i)].get<int>();
|
|
body += "<div class=\"field-row\" style=\"min-height:100dp;padding:8dp "
|
|
"0;\"><label>" +
|
|
std::string(focus[size_t(i)]) +
|
|
"</label><input type=\"range\" id=\"camp-focus-" +
|
|
std::to_string(i) + "\" data-input=\"camp-focus\" data-id=\"" +
|
|
std::to_string(i) + "\" min=\"0\" max=\"15\" step=\"1\" value=\"" +
|
|
std::to_string(value) + "\" style=\"width:400dp;\" " +
|
|
(i == 3 ? "disabled" : "") + "/><span id=\"camp-value-" +
|
|
std::to_string(i) +
|
|
"\" style=\"width:145dp;flex-shrink:0;text-align:right;\">" +
|
|
std::to_string(value) + " / 15</span></div>";
|
|
}
|
|
body += "<div class=\"row\" "
|
|
"style=\"margin-top:26dp;justify-content:flex-end;\">" +
|
|
btn("camp-remember", "Vormerken", "primary") + "</div></div>";
|
|
return body;
|
|
}
|
|
std::string App::render_menu(const std::string &key) {
|
|
if(key=="view-save"||key=="view-load")return render_files(true,key=="view-save");
|
|
if (key == "widgets" || key == "background" || key == "warning" || key == "quit") return render_widget_dialog(key);
|
|
if (key == "news")
|
|
return "<div class=\"fill\" style=\"z-index:100;\">" + render_news() + "</div>";
|
|
std::string body;
|
|
if(source_ && snap().state.at("career").value("role","club")=="national" && std::set<std::string>{"achievements","friendlies","scorers"}.contains(key))
|
|
body=render_national(key);
|
|
else if (key == "tables" || key == "strengths" || key == "league" || key == "other")
|
|
body = render_reports(key);
|
|
else if (key == "almanac")
|
|
body = render_almanac();
|
|
else if (key == "postpone")
|
|
body = render_postpone();
|
|
else if (key == "friendlies")
|
|
body = render_friendlies();
|
|
else if (key == "indoor")
|
|
body = render_indoor();
|
|
else if (key == "lineup")
|
|
body = render_lineup();
|
|
else if (key == "transfer")
|
|
body = render_transfer();
|
|
else if (key == "achievements")
|
|
body = render_achievements();
|
|
else if (key == "scorers")
|
|
body = render_scorers();
|
|
else if (key == "fairplay")
|
|
body = render_fairplay();
|
|
else if (key == "highscore")
|
|
body = render_highscore();
|
|
else if (key == "stadium")
|
|
body = render_stadium();
|
|
else if (key == "statistics")
|
|
body = render_statistics();
|
|
else if (key == "environment")
|
|
body = render_environment();
|
|
else if (key == "advertising")
|
|
body = render_advertising();
|
|
else if (key == "toto")
|
|
body = render_toto();
|
|
else if (key == "bank")
|
|
body = render_bank();
|
|
else if (key == "balance")
|
|
body = render_balance();
|
|
else if (key == "contracts")
|
|
body = render_contracts();
|
|
else if (key == "training")
|
|
body = render_training();
|
|
else if (key == "tactics")
|
|
body = render_tactics();
|
|
else if (key == "calendar")
|
|
body = render_calendar();
|
|
else if (key == "camp")
|
|
body = render_camp();
|
|
else if (key == "settings")
|
|
body = render_settings();
|
|
else if (key == "save" || key == "load")
|
|
body = render_files(false,key == "save");
|
|
else
|
|
throw editor::Error("Diese native Ansicht ist noch nicht verfügbar.");
|
|
std::string heading = key == "postpone" ? "Spiel verlegen" : title(key);
|
|
if (key == "bank" && bank_view_ != "entrance") {
|
|
const std::map<std::string, std::string> labels = {{"savings", "Sparbuch"}, {"properties", "Immobilien"},
|
|
{"stocks", "Aktien"}, {"credit", "Kredit"}, {"overview", "Finanzübersicht"}};
|
|
if (labels.contains(bank_view_)) heading += " · " + labels.at(bank_view_);
|
|
}
|
|
return "<div class=\"fill\" style=\"z-index:100;\">" +
|
|
window(heading, body) +
|
|
(key == "statistics" ? render_statistics_trophy() : "") + "</div>";
|
|
}
|