Differential D1240 Diff 6097 ps/trunk/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Map/Map.cpp
Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Map/Map.cpp
Show All 35 Lines | enum | ||||
ID_MapName, | ID_MapName, | ||||
ID_MapDescription, | ID_MapDescription, | ||||
ID_MapReveal, | ID_MapReveal, | ||||
ID_MapType, | ID_MapType, | ||||
ID_MapPreview, | ID_MapPreview, | ||||
ID_MapTeams, | ID_MapTeams, | ||||
ID_MapKW_Demo, | ID_MapKW_Demo, | ||||
ID_MapKW_Naval, | ID_MapKW_Naval, | ||||
ID_VC_Conquest, | |||||
ID_VC_ConquestUnits, | |||||
ID_VC_ConquestStructures, | |||||
ID_VC_CaptureTheRelic, | |||||
ID_VC_Wonder, | |||||
ID_VC_Regicide, | |||||
ID_RandomScript, | ID_RandomScript, | ||||
ID_RandomSize, | ID_RandomSize, | ||||
ID_RandomNomad, | ID_RandomNomad, | ||||
ID_RandomSeed, | ID_RandomSeed, | ||||
ID_RandomReseed, | ID_RandomReseed, | ||||
ID_RandomGenerate, | ID_RandomGenerate, | ||||
ID_SimPlay, | ID_SimPlay, | ||||
ID_SimFast, | ID_SimFast, | ||||
Show All 40 Lines | |||||
public: | public: | ||||
MapSettingsControl(wxWindow* parent, ScenarioEditor& scenarioEditor); | MapSettingsControl(wxWindow* parent, ScenarioEditor& scenarioEditor); | ||||
void CreateWidgets(); | void CreateWidgets(); | ||||
void ReadFromEngine(); | void ReadFromEngine(); | ||||
void SetMapSettings(const AtObj& obj); | void SetMapSettings(const AtObj& obj); | ||||
AtObj UpdateSettingsObject(); | AtObj UpdateSettingsObject(); | ||||
private: | private: | ||||
void SendToEngine(); | void SendToEngine(); | ||||
void OnConquestChanged(); | |||||
void OnEdit(wxCommandEvent& WXUNUSED(evt)) | void OnEdit(wxCommandEvent& evt) | ||||
{ | { | ||||
SendToEngine(); | SendToEngine(); | ||||
if (evt.GetId() == ID_VC_Conquest) | |||||
OnConquestChanged(); | |||||
} | } | ||||
std::set<std::wstring> m_MapSettingsKeywords; | std::set<std::wstring> m_MapSettingsKeywords; | ||||
std::set<std::wstring> m_MapSettingsVictoryConditions; | |||||
std::vector<wxChoice*> m_PlayerCivChoices; | std::vector<wxChoice*> m_PlayerCivChoices; | ||||
Observable<AtObj>& m_MapSettings; | Observable<AtObj>& m_MapSettings; | ||||
DECLARE_EVENT_TABLE(); | DECLARE_EVENT_TABLE(); | ||||
}; | }; | ||||
BEGIN_EVENT_TABLE(MapSettingsControl, wxPanel) | BEGIN_EVENT_TABLE(MapSettingsControl, wxPanel) | ||||
EVT_TEXT(ID_MapName, MapSettingsControl::OnEdit) | EVT_TEXT(ID_MapName, MapSettingsControl::OnEdit) | ||||
Show All 26 Lines | void MapSettingsControl::CreateWidgets() | ||||
sizer->Add(0, 2); | sizer->Add(0, 2); | ||||
sizer->Add(new wxStaticText(this, wxID_ANY, _("Description"))); | sizer->Add(new wxStaticText(this, wxID_ANY, _("Description"))); | ||||
sizer->Add(Tooltipped(new wxTextCtrl(this, ID_MapDescription, wxEmptyString, wxDefaultPosition, wxSize(-1, 100), wxTE_MULTILINE), | sizer->Add(Tooltipped(new wxTextCtrl(this, ID_MapDescription, wxEmptyString, wxDefaultPosition, wxSize(-1, 100), wxTE_MULTILINE), | ||||
_("Short description used on the map selection screen")), wxSizerFlags().Expand()); | _("Short description used on the map selection screen")), wxSizerFlags().Expand()); | ||||
sizer->AddSpacer(5); | sizer->AddSpacer(5); | ||||
// TODO: replace by filenames in binaries/data/mods/public/simulation/data/settings/victory_conditions/ | |||||
wxArrayString gameTypes; | |||||
gameTypes.Add(_T("conquest")); | |||||
gameTypes.Add(_T("conquest_structures")); | |||||
gameTypes.Add(_T("conquest_units")); | |||||
gameTypes.Add(_T("wonder")); | |||||
gameTypes.Add(_T("endless")); | |||||
gameTypes.Add(_T("regicide")); | |||||
gameTypes.Add(_T("capture_the_relic")); | |||||
wxFlexGridSizer* gridSizer = new wxFlexGridSizer(2, 5, 5); | wxFlexGridSizer* gridSizer = new wxFlexGridSizer(2, 5, 5); | ||||
gridSizer->AddGrowableCol(1); | gridSizer->AddGrowableCol(1); | ||||
// TODO: have preview selector tool? | // TODO: have preview selector tool? | ||||
gridSizer->Add(new wxStaticText(this, wxID_ANY, _("Preview")), wxSizerFlags().Align(wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT)); | gridSizer->Add(new wxStaticText(this, wxID_ANY, _("Preview")), wxSizerFlags().Align(wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT)); | ||||
gridSizer->Add(Tooltipped(new wxTextCtrl(this, ID_MapPreview, wxEmptyString), | gridSizer->Add(Tooltipped(new wxTextCtrl(this, ID_MapPreview, wxEmptyString), | ||||
_("Texture used for map preview")), wxSizerFlags().Expand()); | _("Texture used for map preview")), wxSizerFlags().Expand()); | ||||
CREATE_CHECKBOX(this, gridSizer, "Reveal map", "If checked, players won't need to explore", ID_MapReveal); | CREATE_CHECKBOX(this, gridSizer, "Reveal map", "If checked, players won't need to explore", ID_MapReveal); | ||||
gridSizer->Add(new wxStaticText(this, wxID_ANY, _("Game type")), wxSizerFlags().Align(wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT)); | |||||
gridSizer->Add(Tooltipped(new wxChoice(this, ID_MapType, wxDefaultPosition, wxDefaultSize, gameTypes), | |||||
_("Select the game type (or victory condition)")), wxSizerFlags().Expand()); | |||||
CREATE_CHECKBOX(this, gridSizer, "Lock teams", "If checked, teams will be locked", ID_MapTeams); | CREATE_CHECKBOX(this, gridSizer, "Lock teams", "If checked, teams will be locked", ID_MapTeams); | ||||
sizer->Add(gridSizer, wxSizerFlags().Expand()); | sizer->Add(gridSizer, wxSizerFlags().Expand()); | ||||
sizer->AddSpacer(5); | sizer->AddSpacer(5); | ||||
// TODO: replace by names in binaries/data/mods/public/simulation/data/settings/victory_conditions/ | |||||
wxStaticBoxSizer* victoryConditionSizer = new wxStaticBoxSizer(wxVERTICAL, this, _("Victory Conditions")); | |||||
wxFlexGridSizer* vcGridSizer = new wxFlexGridSizer(2, 0, 5); | |||||
vcGridSizer->AddGrowableCol(1); | |||||
CREATE_CHECKBOX(this, vcGridSizer, "Conquest", "Select Conquest victory condition", ID_VC_Conquest); | |||||
CREATE_CHECKBOX(this, vcGridSizer, "Conquest Units", "Select Conquest Units victory condition", ID_VC_ConquestUnits); | |||||
CREATE_CHECKBOX(this, vcGridSizer, "Conquest Structures", "Select Conquest Structures victory condition", ID_VC_ConquestStructures); | |||||
CREATE_CHECKBOX(this, vcGridSizer, "Capture the Relic", "Select Capture the Relic victory condition", ID_VC_CaptureTheRelic); | |||||
CREATE_CHECKBOX(this, vcGridSizer, "Wonder", "Select Wonder victory condition", ID_VC_Wonder); | |||||
CREATE_CHECKBOX(this, vcGridSizer, "Regicide", "Select Regicide victory condition", ID_VC_Regicide); | |||||
victoryConditionSizer->Add(vcGridSizer); | |||||
sizer->Add(victoryConditionSizer, wxSizerFlags().Expand()); | |||||
sizer->AddSpacer(5); | |||||
wxStaticBoxSizer* keywordsSizer = new wxStaticBoxSizer(wxVERTICAL, this, _("Keywords")); | wxStaticBoxSizer* keywordsSizer = new wxStaticBoxSizer(wxVERTICAL, this, _("Keywords")); | ||||
wxFlexGridSizer* kwGridSizer = new wxFlexGridSizer(4, 5, 5); | wxFlexGridSizer* kwGridSizer = new wxFlexGridSizer(4, 5, 5); | ||||
CREATE_CHECKBOX(this, kwGridSizer, "Demo", "If checked, map will only be visible using filters in game setup", ID_MapKW_Demo); | CREATE_CHECKBOX(this, kwGridSizer, "Demo", "If checked, map will only be visible using filters in game setup", ID_MapKW_Demo); | ||||
CREATE_CHECKBOX(this, kwGridSizer, "Naval", "If checked, map will only be visible using filters in game setup", ID_MapKW_Naval); | CREATE_CHECKBOX(this, kwGridSizer, "Naval", "If checked, map will only be visible using filters in game setup", ID_MapKW_Naval); | ||||
keywordsSizer->Add(kwGridSizer); | keywordsSizer->Add(kwGridSizer); | ||||
sizer->Add(keywordsSizer, wxSizerFlags().Expand()); | sizer->Add(keywordsSizer, wxSizerFlags().Expand()); | ||||
} | } | ||||
Show All 14 Lines | void MapSettingsControl::ReadFromEngine() | ||||
wxDynamicCast(FindWindow(ID_MapDescription), wxTextCtrl)->ChangeValue(wxString(m_MapSettings["Description"])); | wxDynamicCast(FindWindow(ID_MapDescription), wxTextCtrl)->ChangeValue(wxString(m_MapSettings["Description"])); | ||||
// map preview | // map preview | ||||
wxDynamicCast(FindWindow(ID_MapPreview), wxTextCtrl)->ChangeValue(wxString(m_MapSettings["Preview"])); | wxDynamicCast(FindWindow(ID_MapPreview), wxTextCtrl)->ChangeValue(wxString(m_MapSettings["Preview"])); | ||||
// reveal map | // reveal map | ||||
wxDynamicCast(FindWindow(ID_MapReveal), wxCheckBox)->SetValue(wxString(m_MapSettings["RevealMap"]) == L"true"); | wxDynamicCast(FindWindow(ID_MapReveal), wxCheckBox)->SetValue(wxString(m_MapSettings["RevealMap"]) == L"true"); | ||||
// game type / victory conditions | // victory conditions | ||||
if (m_MapSettings["GameType"].defined()) | m_MapSettingsVictoryConditions.clear(); | ||||
wxDynamicCast(FindWindow(ID_MapType), wxChoice)->SetStringSelection(wxString(m_MapSettings["GameType"])); | for (AtIter victoryCondition = m_MapSettings["VictoryConditions"]["item"]; victoryCondition.defined(); ++victoryCondition) | ||||
else | m_MapSettingsVictoryConditions.insert(std::wstring(victoryCondition)); | ||||
wxDynamicCast(FindWindow(ID_MapType), wxChoice)->SetSelection(0); | |||||
wxWindow* window; | |||||
#define INIT_CHECKBOX(ID, mapSettings, value) \ | |||||
window = FindWindow(ID); \ | |||||
if (window != nullptr) \ | |||||
wxDynamicCast(window, wxCheckBox)->SetValue(mapSettings.count(value) != 0); | |||||
INIT_CHECKBOX(ID_VC_Conquest, m_MapSettingsVictoryConditions, L"conquest"); | |||||
INIT_CHECKBOX(ID_VC_ConquestUnits, m_MapSettingsVictoryConditions, L"conquest_units"); | |||||
INIT_CHECKBOX(ID_VC_ConquestStructures, m_MapSettingsVictoryConditions, L"conquest_structures"); | |||||
INIT_CHECKBOX(ID_VC_CaptureTheRelic, m_MapSettingsVictoryConditions, L"capture_the_relic"); | |||||
INIT_CHECKBOX(ID_VC_Wonder, m_MapSettingsVictoryConditions, L"wonder"); | |||||
INIT_CHECKBOX(ID_VC_Regicide, m_MapSettingsVictoryConditions, L"regicide"); | |||||
OnConquestChanged(); | |||||
// lock teams | // lock teams | ||||
wxDynamicCast(FindWindow(ID_MapTeams), wxCheckBox)->SetValue(wxString(m_MapSettings["LockTeams"]) == L"true"); | wxDynamicCast(FindWindow(ID_MapTeams), wxCheckBox)->SetValue(wxString(m_MapSettings["LockTeams"]) == L"true"); | ||||
// keywords | // keywords | ||||
{ | { | ||||
m_MapSettingsKeywords.clear(); | m_MapSettingsKeywords.clear(); | ||||
for (AtIter keyword = m_MapSettings["Keywords"]["item"]; keyword.defined(); ++keyword) | for (AtIter keyword = m_MapSettings["Keywords"]["item"]; keyword.defined(); ++keyword) | ||||
m_MapSettingsKeywords.insert(std::wstring(keyword)); | m_MapSettingsKeywords.insert(std::wstring(keyword)); | ||||
wxDynamicCast(FindWindow(ID_MapKW_Demo), wxCheckBox)->SetValue(m_MapSettingsKeywords.count(L"demo") != 0); | INIT_CHECKBOX(ID_MapKW_Demo, m_MapSettingsKeywords, L"demo"); | ||||
wxDynamicCast(FindWindow(ID_MapKW_Naval), wxCheckBox)->SetValue(m_MapSettingsKeywords.count(L"naval") != 0); | INIT_CHECKBOX(ID_MapKW_Naval, m_MapSettingsKeywords, L"naval"); | ||||
} | } | ||||
#undef INIT_CHECKBOX | |||||
} | } | ||||
void MapSettingsControl::SetMapSettings(const AtObj& obj) | void MapSettingsControl::SetMapSettings(const AtObj& obj) | ||||
{ | { | ||||
m_MapSettings = obj; | m_MapSettings = obj; | ||||
m_MapSettings.NotifyObservers(); | m_MapSettings.NotifyObservers(); | ||||
SendToEngine(); | SendToEngine(); | ||||
} | } | ||||
// TODO Use the json data for this | |||||
void MapSettingsControl::OnConquestChanged() | |||||
{ | |||||
bool conqestEnabled = wxDynamicCast(FindWindow(ID_VC_Conquest), wxCheckBox)->GetValue(); | |||||
wxCheckBox* conquestUnitsCheckbox = wxDynamicCast(FindWindow(ID_VC_ConquestUnits), wxCheckBox); | |||||
conquestUnitsCheckbox->Enable(!conqestEnabled); | |||||
wxCheckBox* conquestStructuresCheckbox = wxDynamicCast(FindWindow(ID_VC_ConquestStructures), wxCheckBox); | |||||
conquestStructuresCheckbox->Enable(!conqestEnabled); | |||||
if (conqestEnabled) | |||||
{ | |||||
conquestUnitsCheckbox->SetValue(false); | |||||
conquestStructuresCheckbox->SetValue(false); | |||||
} | |||||
} | |||||
AtObj MapSettingsControl::UpdateSettingsObject() | AtObj MapSettingsControl::UpdateSettingsObject() | ||||
{ | { | ||||
// map name | // map name | ||||
m_MapSettings.set("Name", wxDynamicCast(FindWindow(ID_MapName), wxTextCtrl)->GetValue()); | m_MapSettings.set("Name", wxDynamicCast(FindWindow(ID_MapName), wxTextCtrl)->GetValue()); | ||||
// map description | // map description | ||||
m_MapSettings.set("Description", wxDynamicCast(FindWindow(ID_MapDescription), wxTextCtrl)->GetValue()); | m_MapSettings.set("Description", wxDynamicCast(FindWindow(ID_MapDescription), wxTextCtrl)->GetValue()); | ||||
// map preview | // map preview | ||||
m_MapSettings.set("Preview", wxDynamicCast(FindWindow(ID_MapPreview), wxTextCtrl)->GetValue()); | m_MapSettings.set("Preview", wxDynamicCast(FindWindow(ID_MapPreview), wxTextCtrl)->GetValue()); | ||||
// reveal map | // reveal map | ||||
m_MapSettings.setBool("RevealMap", wxDynamicCast(FindWindow(ID_MapReveal), wxCheckBox)->GetValue()); | m_MapSettings.setBool("RevealMap", wxDynamicCast(FindWindow(ID_MapReveal), wxCheckBox)->GetValue()); | ||||
// game type / victory conditions | // victory conditions | ||||
m_MapSettings.set("GameType", wxDynamicCast(FindWindow(ID_MapType), wxChoice)->GetStringSelection()); | #define INSERT_VICTORY_CONDITION_CHECKBOX(name, ID) \ | ||||
if (wxDynamicCast(FindWindow(ID), wxCheckBox)->GetValue()) \ | |||||
m_MapSettingsVictoryConditions.insert(name); \ | |||||
else \ | |||||
m_MapSettingsVictoryConditions.erase(name); | |||||
INSERT_VICTORY_CONDITION_CHECKBOX(L"conquest", ID_VC_Conquest); | |||||
INSERT_VICTORY_CONDITION_CHECKBOX(L"conquest_units", ID_VC_ConquestUnits); | |||||
INSERT_VICTORY_CONDITION_CHECKBOX(L"conquest_structures", ID_VC_ConquestStructures); | |||||
INSERT_VICTORY_CONDITION_CHECKBOX(L"capture_the_relic", ID_VC_CaptureTheRelic); | |||||
INSERT_VICTORY_CONDITION_CHECKBOX(L"wonder", ID_VC_Wonder); | |||||
INSERT_VICTORY_CONDITION_CHECKBOX(L"regicide", ID_VC_Regicide); | |||||
#undef INSERT_VICTORY_CONDITION_CHECKBOX | |||||
AtObj victoryConditions; | |||||
victoryConditions.set("@array", L""); | |||||
for (std::set<std::wstring>::iterator it = m_MapSettingsVictoryConditions.begin(); it != m_MapSettingsVictoryConditions.end(); ++it) | |||||
victoryConditions.add("item", it->c_str()); | |||||
m_MapSettings.set("VictoryConditions", victoryConditions); | |||||
// keywords | // keywords | ||||
{ | { | ||||
if (wxDynamicCast(FindWindow(ID_MapKW_Demo), wxCheckBox)->GetValue()) | if (wxDynamicCast(FindWindow(ID_MapKW_Demo), wxCheckBox)->GetValue()) | ||||
m_MapSettingsKeywords.insert(L"demo"); | m_MapSettingsKeywords.insert(L"demo"); | ||||
else | else | ||||
m_MapSettingsKeywords.erase(L"demo"); | m_MapSettingsKeywords.erase(L"demo"); | ||||
▲ Show 20 Lines • Show All 334 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator