void MapSettingsControl::ReadFromEngine() { AtlasMessage::qGetMapSettings qry; qry.Post(); if (!(*qry.settings).empty()) { // Prevent error if there's no map settings to parse m_MapSettings = AtlasObject::LoadFromJSON(*qry.settings); } // map name wxDynamicCast(FindWindow(ID_MapName), wxTextCtrl)->ChangeValue(wxString(m_MapSettings["Name"])); // map description wxDynamicCast(FindWindow(ID_MapDescription), wxTextCtrl)->ChangeValue(wxString(m_MapSettings["Description"])); // map preview wxDynamicCast(FindWindow(ID_MapPreview), wxTextCtrl)->ChangeValue(wxString(m_MapSettings["Preview"])); // reveal map wxDynamicCast(FindWindow(ID_MapReveal), wxCheckBox)->SetValue(wxString(m_MapSettings["RevealMap"]) == L"true"); // game type / victory conditions if (m_MapSettings["GameType"].defined()) wxDynamicCast(FindWindow(ID_MapType), wxChoice)->SetStringSelection(wxString(m_MapSettings["GameType"])); else wxDynamicCast(FindWindow(ID_MapType), wxChoice)->SetSelection(0); // lock teams wxDynamicCast(FindWindow(ID_MapTeams), wxCheckBox)->SetValue(wxString(m_MapSettings["LockTeams"]) == L"true"); // keywords { m_MapSettingsKeywords.clear(); for (AtIter keyword = m_MapSettings["Keywords"]["item"]; keyword.defined(); ++keyword) m_MapSettingsKeywords.insert(std::wstring(keyword)); wxDynamicCast(FindWindow(ID_MapKW_Demo), wxCheckBox)->SetValue(m_MapSettingsKeywords.count(L"demo") != 0); wxDynamicCast(FindWindow(ID_MapKW_Naval), wxCheckBox)->SetValue(m_MapSettingsKeywords.count(L"naval") != 0); } }
void PlayerSettingsControl::ReadFromEngine() { AtlasMessage::qGetMapSettings qry; qry.Post(); if (!(*qry.settings).empty()) { // Prevent error if there's no map settings to parse m_MapSettings = AtlasObject::LoadFromJSON(*qry.settings); } else { // Use blank object, it will be created next m_MapSettings = AtObj(); } AtIter player = m_MapSettings["PlayerData"]["item"]; if (!m_MapSettings.defined() || !player.defined() || player.count() == 0) { // Player data missing - set number of players to max m_NumPlayers = MAX_NUM_PLAYERS; } else m_NumPlayers = player.count(); wxASSERT(m_NumPlayers <= MAX_NUM_PLAYERS && m_NumPlayers != 0); // To prevent recursion, don't handle GUI events right now m_InGUIUpdate = true; wxDynamicCast(FindWindow(ID_NumPlayers), wxSpinCtrl)->SetValue(m_NumPlayers); // Remove / add extra player pages as needed m_Players->ResizePlayers(m_NumPlayers); // Update player controls with player data AtIter playerDefs = m_PlayerDefaults["item"]; if (playerDefs.defined()) ++playerDefs; // skip gaia for (size_t i = 0; i < MAX_NUM_PLAYERS; ++i) { const PlayerPageControls& controls = m_PlayerControls[i]; // name wxString name(_("Unknown")); bool defined = player["Name"].defined(); if (defined) name = wxString(player["Name"]); else if (playerDefs["Name"].defined()) name = wxString(playerDefs["Name"]); controls.name->SetValue(name); wxDynamicCast(FindWindowById(ID_DefaultName, controls.page), DefaultCheckbox)->SetValue(defined); // civ wxChoice* choice = controls.civ; wxString civCode; defined = player["Civ"].defined(); if (defined) civCode = wxString(player["Civ"]); else civCode = wxString(playerDefs["Civ"]); for (size_t j = 0; j < choice->GetCount(); ++j) { wxStringClientData* str = dynamic_cast<wxStringClientData*>(choice->GetClientObject(j)); if (str->GetData() == civCode) { choice->SetSelection(j); break; } } wxDynamicCast(FindWindowById(ID_DefaultCiv, controls.page), DefaultCheckbox)->SetValue(defined); // colour wxColour colour; AtObj clrObj = *player["Colour"]; defined = clrObj.defined(); if (!defined) clrObj = *playerDefs["Colour"]; colour = wxColor((*clrObj["r"]).getInt(), (*clrObj["g"]).getInt(), (*clrObj["b"]).getInt()); controls.colour->SetBackgroundColour(colour); wxDynamicCast(FindWindowById(ID_DefaultColour, controls.page), DefaultCheckbox)->SetValue(defined); // player type wxString aiID; defined = player["AI"].defined(); if (defined) aiID = wxString(player["AI"]); else aiID = wxString(playerDefs["AI"]); choice = controls.ai; if (!aiID.empty()) { // AI for (size_t j = 0; j < choice->GetCount(); ++j) { wxStringClientData* str = dynamic_cast<wxStringClientData*>(choice->GetClientObject(j)); if (str->GetData() == aiID) { choice->SetSelection(j); break; } } } else // Human choice->SetSelection(0); wxDynamicCast(FindWindowById(ID_DefaultAI, controls.page), DefaultCheckbox)->SetValue(defined); // resources AtObj resObj = *player["Resources"]; defined = resObj.defined() && resObj["food"].defined(); if (defined) controls.food->SetValue(wxString(resObj["food"])); else controls.food->SetValue(0); wxDynamicCast(FindWindowById(ID_DefaultFood, controls.page), DefaultCheckbox)->SetValue(defined); defined = resObj.defined() && resObj["wood"].defined(); if (defined) controls.wood->SetValue(wxString(resObj["wood"])); else controls.wood->SetValue(0); wxDynamicCast(FindWindowById(ID_DefaultWood, controls.page), DefaultCheckbox)->SetValue(defined); defined = resObj.defined() && resObj["metal"].defined(); if (defined) controls.metal->SetValue(wxString(resObj["metal"])); else controls.metal->SetValue(0); wxDynamicCast(FindWindowById(ID_DefaultMetal, controls.page), DefaultCheckbox)->SetValue(defined); defined = resObj.defined() && resObj["stone"].defined(); if (defined) controls.stone->SetValue(wxString(resObj["stone"])); else controls.stone->SetValue(0); wxDynamicCast(FindWindowById(ID_DefaultStone, controls.page), DefaultCheckbox)->SetValue(defined); // population limit defined = player["PopulationLimit"].defined(); if (defined) controls.pop->SetValue(wxString(player["PopulationLimit"])); else controls.pop->SetValue(0); wxDynamicCast(FindWindowById(ID_DefaultPop, controls.page), DefaultCheckbox)->SetValue(defined); // team defined = player["Team"].defined(); if (defined) controls.team->SetSelection((*player["Team"]).getInt() + 1); else controls.team->SetSelection(0); wxDynamicCast(FindWindowById(ID_DefaultTeam, controls.page), DefaultCheckbox)->SetValue(defined); // camera if (player["StartingCamera"].defined()) { sCameraInfo info; // Don't use wxAtof because it depends on locales which // may cause problems with decimal points // see: http://www.wxwidgets.org/docs/faqgtk.htm#locale AtObj camPos = *player["StartingCamera"]["Position"]; info.pX = (float)(*camPos["x"]).getDouble(); info.pY = (float)(*camPos["y"]).getDouble(); info.pZ = (float)(*camPos["z"]).getDouble(); AtObj camRot = *player["StartingCamera"]["Rotation"]; info.rX = (float)(*camRot["x"]).getDouble(); info.rY = (float)(*camRot["y"]).getDouble(); info.rZ = (float)(*camRot["z"]).getDouble(); controls.page->SetCamera(info, true); } else controls.page->SetCamera(sCameraInfo(), false); // Only increment AtIters if they are defined if (player.defined()) ++player; if (playerDefs.defined()) ++playerDefs; } // Send default properties to engine, since they might not be set SendToEngine(); m_InGUIUpdate = false; }