- Timestamp:
- 06/14/11 01:32:41 (14 years ago)
- Location:
- ps/trunk
- Files:
-
- 18 edited
-
binaries/data/mods/public/simulation/components/Player.js (modified) (2 diffs)
-
binaries/data/mods/public/simulation/helpers/Player.js (modified) (1 diff)
-
source/graphics/MapReader.cpp (modified) (10 diffs)
-
source/graphics/MapReader.h (modified) (1 diff)
-
source/simulation2/Simulation2.cpp (modified) (1 diff)
-
source/simulation2/Simulation2.h (modified) (1 diff)
-
source/simulation2/components/ICmpPlayer.cpp (modified) (3 diffs)
-
source/simulation2/components/ICmpPlayer.h (modified) (3 diffs)
-
source/tools/atlas/AtlasObject/AtlasObject.h (modified) (2 diffs)
-
source/tools/atlas/AtlasObject/AtlasObjectImpl.cpp (modified) (2 diffs)
-
source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Map/Map.cpp (modified) (1 diff)
-
source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Object/Object.cpp (modified) (6 diffs)
-
source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Object/Object.h (modified) (2 diffs)
-
source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Player/Player.cpp (modified) (17 diffs)
-
source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Player/Player.h (modified) (2 diffs)
-
source/tools/atlas/GameInterface/Handlers/CameraCtrlHandlers.cpp (modified) (1 diff)
-
source/tools/atlas/GameInterface/Handlers/PlayerHandlers.cpp (modified) (1 diff)
-
source/tools/atlas/GameInterface/Messages.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
ps/trunk/binaries/data/mods/public/simulation/components/Player.js
r8652 r9617 26 26 this.conquestCriticalEntitiesCount = 0; // number of owned units with ConquestCritical class 27 27 this.phase = "village"; 28 this.startCam = undefined; 28 29 }; 29 30 … … 226 227 }; 227 228 229 Player.prototype.GetStartingCamera = function() 230 { 231 return this.startCam; 232 } 233 234 Player.prototype.SetStartingCamera = function(pos) 235 { 236 this.startCam = pos; 237 } 238 239 Player.prototype.HasStartingCamera = function() 240 { 241 return (this.startCam !== undefined); 242 } 243 228 244 /** 229 245 * Keep track of population effects of all entities that -
ps/trunk/binaries/data/mods/public/simulation/helpers/Player.js
r9602 r9617 129 129 player.SetDiplomacy(diplomacy); 130 130 } 131 132 if (getSetting(pData, pDefs, "StartingCamera") !== undefined) 133 { 134 player.SetStartingCamera(getSetting(pData, pDefs, "StartingCamera")); 135 } 131 136 } 132 137 else -
ps/trunk/source/graphics/MapReader.cpp
r9609 r9617 75 75 pSimulation2 = pSimulation2_; 76 76 m_PlayerID = playerID_; 77 78 m_CameraStartupTarget = INVALID_ENTITY; 77 m_StartingCameraTarget = INVALID_ENTITY; 79 78 80 79 filename_xml = pathname.ChangeExtension(L".xml"); … … 147 146 pSimulation2 = pSimulation2_; 148 147 m_PlayerID = playerID_; 149 150 m_CameraStartupTarget = INVALID_ENTITY; 148 m_StartingCameraTarget = INVALID_ENTITY; 151 149 152 150 // delete all existing entities … … 285 283 *pLightEnv = m_LightEnv; 286 284 287 if (pGameView) 288 { 285 CmpPtr<ICmpPlayerManager> cmpPlayerManager(*pSimulation2, SYSTEM_ENTITY); 286 287 if (pGameView && !cmpPlayerManager.null()) 288 { 289 // Default to global camera (with constraints) 289 290 pGameView->ResetCameraTarget(pGameView->GetCamera()->GetFocus()); 290 291 if (m_CameraStartupTarget != INVALID_ENTITY) 292 { 293 CmpPtr<ICmpPosition> cmpPosition(*pSimulation2, m_CameraStartupTarget); 291 292 CmpPtr<ICmpPlayer> cmpPlayer(*pSimulation2, cmpPlayerManager->GetPlayerByID(m_PlayerID)); 293 if (!cmpPlayer.null() && cmpPlayer->HasStartingCamera()) 294 { 295 // Use player starting camera 296 CFixedVector3D pos = cmpPlayer->GetStartingCamera(); 297 pGameView->ResetCameraTarget(CVector3D(pos.X.ToFloat(), pos.Y.ToFloat(), pos.Z.ToFloat())); 298 } 299 else if (m_StartingCameraTarget != INVALID_ENTITY) 300 { 301 // Point camera at entity 302 CmpPtr<ICmpPosition> cmpPosition(*pSimulation2, m_StartingCameraTarget); 294 303 if (!cmpPosition.null()) 295 304 { … … 679 688 void CXMLReader::ReadCamera(XMBElement parent) 680 689 { 690 // defaults if we don't find player starting camera 681 691 #define EL(x) int el_##x = xmb_file.GetElementID(#x) 682 692 #define AT(x) int at_##x = xmb_file.GetAttributeID(#x) … … 850 860 851 861 CSimulation2& sim = *m_MapReader.pSimulation2; 852 CmpPtr<ICmpPlayerManager> cmpPlayerManager(sim .GetSimContext(), SYSTEM_ENTITY);862 CmpPtr<ICmpPlayerManager> cmpPlayerManager(sim, SYSTEM_ENTITY); 853 863 854 864 while (entity_idx < entities.Count) … … 908 918 909 919 entity_id_t ent = sim.AddEntity(TemplateName, EntityUid); 910 if (ent == INVALID_ENTITY) 911 { 920 entity_id_t player = cmpPlayerManager->GetPlayerByID(PlayerID); 921 if (ent == INVALID_ENTITY || player == INVALID_ENTITY) 922 { // Don't add entities with invalid player IDs 912 923 LOGERROR(L"Failed to load entity template '%ls'", TemplateName.c_str()); 913 924 } 914 else if (cmpPlayerManager->GetPlayerByID(PlayerID) != INVALID_ENTITY) 915 { // Don't add entities with invalid player IDs 916 // TODO: Is a warning OK or should it just silently fail? 917 925 else 926 { 918 927 CmpPtr<ICmpPosition> cmpPosition(sim, ent); 919 928 if (!cmpPosition.null()) … … 928 937 cmpOwner->SetOwner(PlayerID); 929 938 930 if ( boost::algorithm::ends_with(TemplateName, L"civil_centre"))939 if (PlayerID == m_MapReader.m_PlayerID && (boost::algorithm::ends_with(TemplateName, L"civil_centre") || m_MapReader.m_StartingCameraTarget == INVALID_ENTITY)) 931 940 { 932 // HACK: we special-case civil centre files to initialise the camera. 933 // This ought to be based on a more generic mechanism for indicating 934 // per-player camera start locations. 935 if (m_MapReader.m_CameraStartupTarget == INVALID_ENTITY && PlayerID == m_MapReader.m_PlayerID && !cmpPosition.null()) 936 m_MapReader.m_CameraStartupTarget = ent; 941 // Focus on civil centre or first entity owned by player 942 m_MapReader.m_StartingCameraTarget = ent; 937 943 } 938 944 } … … 1202 1208 LOGWARNING(L"CMapReader::ParseEntities() failed to get 'entities' property"); 1203 1209 1210 CSimulation2& sim = *pSimulation2; 1211 CmpPtr<ICmpPlayerManager> cmpPlayerManager(sim, SYSTEM_ENTITY); 1212 1204 1213 size_t entity_idx = 0; 1205 1214 size_t num_entities = entities.size(); … … 1213 1222 1214 1223 entity_id_t ent = pSimulation2->AddEntity(currEnt.templateName, currEnt.entityID); 1215 // Check that entity was added1216 if (ent == INVALID_ENTITY )1217 { 1224 entity_id_t player = cmpPlayerManager->GetPlayerByID(currEnt.playerID); 1225 if (ent == INVALID_ENTITY || player == INVALID_ENTITY) 1226 { // Don't add entities with invalid player IDs 1218 1227 LOGERROR(L"Failed to load entity template '%ls'", currEnt.templateName.c_str()); 1219 1228 } 1220 1229 else 1221 1230 { 1222 CmpPtr<ICmpPosition> cmpPosition(*pSimulation2, ent); 1231 CFixedVector3D Position; 1232 Position.X = fixed::FromFloat(currEnt.positionX); 1233 Position.Z = fixed::FromFloat(currEnt.positionZ); 1234 1235 CmpPtr<ICmpPosition> cmpPosition(sim, ent); 1223 1236 if (!cmpPosition.null()) 1224 1237 { 1225 cmpPosition->JumpTo( entity_pos_t::FromFloat(currEnt.positionX), entity_pos_t::FromFloat(currEnt.positionZ));1238 cmpPosition->JumpTo(Position.X, Position.Z); 1226 1239 cmpPosition->SetYRotation(entity_angle_t::FromFloat(currEnt.orientationY)); 1227 1240 // TODO: other parts of the position 1228 1241 } 1229 1242 1230 CmpPtr<ICmpOwnership> cmpOwner( *pSimulation2, ent);1243 CmpPtr<ICmpOwnership> cmpOwner(sim, ent); 1231 1244 if (!cmpOwner.null()) 1232 1245 cmpOwner->SetOwner(currEnt.playerID); 1233 1246 1234 if ( boost::algorithm::ends_with(currEnt.templateName, L"civil_centre"))1247 if (currEnt.playerID == m_PlayerID && (boost::algorithm::ends_with(currEnt.templateName, L"civil_centre") || m_StartingCameraTarget == INVALID_ENTITY)) 1235 1248 { 1236 // HACK: we special-case civil centre files to initialise the camera. 1237 // This ought to be based on a more generic mechanism for indicating 1238 // per-player camera start locations. 1239 if (m_CameraStartupTarget == INVALID_ENTITY && currEnt.playerID == m_PlayerID && !cmpPosition.null()) 1240 m_CameraStartupTarget = ent; 1241 1249 // Focus on civil centre or first entity owned by player 1250 m_StartingCameraTarget = currEnt.entityID; 1242 1251 } 1243 1252 } … … 1328 1337 { 1329 1338 // parse camera settings from map data 1330 // defaults if we don't find camera1339 // defaults if we don't find player starting camera 1331 1340 float declination = DEGTORAD(30.f), rotation = DEGTORAD(-45.f); 1332 1341 CVector3D translation = CVector3D(100, 150, -100); -
ps/trunk/source/graphics/MapReader.h
r9220 r9617 138 138 bool only_xml; 139 139 u32 file_format_version; 140 entity_id_t m_CameraStartupTarget; 140 entity_id_t m_StartingCameraTarget; 141 CVector3D m_StartingCamera; 141 142 142 143 // UnpackTerrain generator state -
ps/trunk/source/simulation2/Simulation2.cpp
r9609 r9617 626 626 return data; 627 627 } 628 629 std::string CSimulation2::GetAIData() 630 { 631 ScriptInterface& scriptInterface = GetScriptInterface(); 632 std::vector<CScriptValRooted> aiData = ICmpAIManager::GetAIs(scriptInterface); 633 634 // Build single JSON string with array of AI data 635 CScriptValRooted ais; 636 if (!scriptInterface.Eval("({})", ais) || !scriptInterface.SetProperty(ais.get(), "AIData", aiData)) 637 return std::string(); 638 639 return scriptInterface.StringifyJSON(ais.get()); 640 } -
ps/trunk/source/simulation2/Simulation2.h
r9609 r9617 234 234 std::string GetMapSizes(); 235 235 236 /** 237 * Get AI data 238 * 239 * @return string containing JSON format data 240 */ 241 std::string GetAIData(); 242 236 243 private: 237 244 CSimulation2Impl* m; -
ps/trunk/source/simulation2/components/ICmpPlayer.cpp
r7655 r9617 1 /* Copyright (C) 201 0Wildfire Games.1 /* Copyright (C) 2011 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * … … 20 20 #include "ICmpPlayer.h" 21 21 22 #include "maths/FixedVector3D.h" 22 23 #include "simulation2/system/InterfaceScripted.h" 23 24 #include "simulation2/scripting/ScriptComponent.h" … … 52 53 return m_Script.Call<CColor>("GetColour"); 53 54 } 55 56 virtual CFixedVector3D GetStartingCamera() 57 { 58 return m_Script.Call<CFixedVector3D>("GetStartingCamera"); 59 } 60 61 virtual bool HasStartingCamera() 62 { 63 return m_Script.Call<bool>("HasStartingCamera"); 64 } 54 65 }; 55 66 -
ps/trunk/source/simulation2/components/ICmpPlayer.h
r7655 r9617 1 /* Copyright (C) 201 0Wildfire Games.1 /* Copyright (C) 2011 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * … … 22 22 23 23 struct CColor; 24 class CFixedVector3D; 24 25 25 26 /** … … 36 37 37 38 virtual CColor GetColour() = 0; 39 virtual CFixedVector3D GetStartingCamera() = 0; 40 41 virtual bool HasStartingCamera() = 0; 38 42 39 43 DECLARE_INTERFACE_TYPE(Player) -
ps/trunk/source/tools/atlas/AtlasObject/AtlasObject.h
r9566 r9617 1 /* Copyright (C) 20 09Wildfire Games.1 /* Copyright (C) 2011 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * … … 154 154 void set(const char* key, AtObj& data); 155 155 void setBool(const char* key, bool value); 156 void setDouble(const char* key, double value); 156 157 void setInt(const char* key, int value); 157 158 void setString(const wchar_t* value); -
ps/trunk/source/tools/atlas/AtlasObject/AtlasObjectImpl.cpp
r9566 r9617 1 /* Copyright (C) 20 09Wildfire Games.1 /* Copyright (C) 2011 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * … … 176 176 } 177 177 178 void AtObj::setDouble(const char* key, double value) 179 { 180 std::wstringstream str; 181 str << value; 182 AtNode* o = new AtNode(str.str().c_str()); 183 o->children.insert(AtNode::child_pairtype("@number", AtNode::Ptr(new AtNode()))); 184 185 if (!p) 186 p = new AtNode(); 187 188 p = p->setChild(key, AtNode::Ptr(o)); 189 } 190 178 191 void AtObj::setInt(const char* key, int value) 179 192 { -
ps/trunk/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Map/Map.cpp
r9608 r9617 449 449 wxString size; 450 450 size << (intptr_t)sizeChoice->GetClientData(sizeChoice->GetSelection()); 451 AtObj sizeObj; 452 sizeObj.setString(size); 453 sizeObj.set("@number", L""); 454 settings.set("Size", sizeObj); 455 456 AtObj seedObj; 457 seedObj.setString(wxDynamicCast(FindWindow(ID_RandomSeed), wxTextCtrl)->GetValue()); 458 seedObj.set("@number", L""); 459 settings.set("Seed", seedObj); 451 settings.setInt("Size", wxAtoi(size)); 452 453 settings.setInt("Seed", wxAtoi(wxDynamicCast(FindWindow(ID_RandomSeed), wxTextCtrl)->GetValue())); 460 454 461 455 std::string json = AtlasObject::SaveToJSON(m_ScenarioEditor.GetScriptInterface().GetContext(), settings); -
ps/trunk/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Object/Object.cpp
r9608 r9617 35 35 { 36 36 ID_ObjectType = 1, 37 ID_ObjectFilter, 37 38 ID_PlayerSelect, 38 39 ID_SelectObject, … … 111 112 : Sidebar(scenarioEditor, sidebarContainer, bottomBarContainer), p(new ObjectSidebarImpl()) 112 113 { 114 wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL); 115 sizer->Add(new wxStaticText(this, wxID_ANY, _("Filter")), wxSizerFlags().Align(wxALIGN_CENTER)); 116 wxTextCtrl* objectFilter = new wxTextCtrl(this, ID_ObjectFilter); 117 sizer->Add(objectFilter, wxSizerFlags().Expand().Proportion(1)); 118 m_MainSizer->Add(sizer, wxSizerFlags().Expand()); 119 113 120 wxArrayString strings; 114 121 strings.Add(_("Entities")); … … 159 166 p->m_Objects = *qry.objects; 160 167 // Display first group of objects 161 SetObjectFilter(0); 162 } 163 164 void ObjectSidebar::SetObjectFilter(int type) 165 { 168 FilterObjects(); 169 } 170 171 void ObjectSidebar::FilterObjects() 172 { 173 int filterType = wxDynamicCast(FindWindow(ID_ObjectType), wxChoice)->GetSelection(); 174 wxString filterName = wxDynamicCast(FindWindow(ID_ObjectFilter), wxTextCtrl)->GetValue(); 175 166 176 p->m_ObjectListBox->Freeze(); 167 177 p->m_ObjectListBox->Clear(); 168 178 for (std::vector<AtlasMessage::sObjectsListItem>::iterator it = p->m_Objects.begin(); it != p->m_Objects.end(); ++it) 169 179 { 170 if (it->type == type)180 if (it->type == filterType) 171 181 { 172 182 wxString id = it->id.c_str(); 173 183 wxString name = it->name.c_str(); 174 p->m_ObjectListBox->Append(name, new wxStringClientData(id)); 184 185 if (name.Lower().Find(filterName.Lower()) != wxNOT_FOUND) 186 { 187 p->m_ObjectListBox->Append(name, new wxStringClientData(id)); 188 } 175 189 } 176 190 } … … 186 200 } 187 201 188 void ObjectSidebar::OnSelectType(wxCommandEvent& evt) 189 { 190 // Switch between displayed lists of objects (e.g. entities vs actors) 191 SetObjectFilter(evt.GetSelection()); 202 void ObjectSidebar::OnSelectType(wxCommandEvent& WXUNUSED(evt)) 203 { 204 FilterObjects(); 192 205 } 193 206 … … 214 227 } 215 228 229 void ObjectSidebar::OnSelectFilter(wxCommandEvent& WXUNUSED(evt)) 230 { 231 FilterObjects(); 232 } 233 216 234 BEGIN_EVENT_TABLE(ObjectSidebar, Sidebar) 217 235 EVT_CHOICE(ID_ObjectType, ObjectSidebar::OnSelectType) 236 EVT_TEXT(ID_ObjectFilter, ObjectSidebar::OnSelectFilter) 218 237 EVT_LISTBOX(ID_SelectObject, ObjectSidebar::OnSelectObject) 219 238 EVT_BUTTON(ID_ToggleViewer, ObjectSidebar::ToggleViewer) … … 257 276 Clear(); 258 277 size_t numPlayers = settings["PlayerData"]["item"].count(); 259 for (size_t i = 0; i <= numPlayers ; ++i)278 for (size_t i = 0; i <= numPlayers && i < m_Players.Count(); ++i) 260 279 { 261 280 Append(m_Players[i]); -
ps/trunk/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Object/Object.h
r9559 r9617 26 26 ObjectSidebar(ScenarioEditor& scenarioEditor, wxWindow* sidebarContainer, wxWindow* bottomBarContainer); 27 27 ~ObjectSidebar(); 28 void SetObjectFilter(int type);28 void FilterObjects(); 29 29 30 30 protected: … … 36 36 void ToggleViewer(wxCommandEvent& evt); 37 37 void OnSelectType(wxCommandEvent& evt); 38 void OnSelectFilter(wxCommandEvent& evt); 38 39 void OnSelectObject(wxCommandEvent& evt); 39 40 -
ps/trunk/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Player/Player.cpp
r9608 r9617 22 22 #include "AtlasObject/AtlasObject.h" 23 23 #include "AtlasScript/ScriptInterface.h" 24 #include "GameInterface/Messages.h"25 24 #include "ScenarioEditor/ScenarioEditor.h" 26 25 … … 35 34 ID_PlayerStone, 36 35 ID_PlayerPop, 37 ID_PlayerColour 38 }; 39 40 // Controls present on each player page 41 struct PlayerPageControls 42 { 43 wxTextCtrl* name; 44 wxChoice* civ; 45 wxButton* colour; 46 wxSpinCtrl* food; 47 wxSpinCtrl* wood; 48 wxSpinCtrl* stone; 49 wxSpinCtrl* metal; 50 wxSpinCtrl* pop; 51 wxChoice* team; 36 ID_PlayerColour, 37 ID_PlayerHuman, 38 ID_PlayerAI, 39 ID_CameraSet, 40 ID_CameraView, 41 ID_CameraClear 52 42 }; 53 43 … … 71 61 : wxPanel(parent, wxID_ANY), m_ScenarioEditor(scenarioEditor), m_Name(name), m_PlayerID(playerID) 72 62 { 63 64 m_Controls.page = this; 73 65 74 66 Freeze(); … … 94 86 gridSizer->Add(Tooltipped(colourButton, _("Set player colour")), wxSizerFlags(1).Expand().Align(wxALIGN_RIGHT)); 95 87 m_Controls.colour = colourButton; 88 gridSizer->Add(new wxStaticText(this, wxID_ANY, _("Default AI")), wxSizerFlags().Align(wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT)); 89 wxChoice* aiChoice = new wxChoice(this, wxID_ANY); 90 gridSizer->Add(Tooltipped(aiChoice, _("Select default AI")), wxSizerFlags(1).Expand().Align(wxALIGN_RIGHT)); 91 m_Controls.ai = aiChoice; 96 92 97 93 playerInfoSizer->Add(gridSizer, wxSizerFlags(1).Expand()); … … 143 139 144 140 // TODO: possibly have advanced panel where each player's diplomacy can be set? 145 146 141 // Advanced panel 147 142 /*wxCollapsiblePane* advPane = new wxCollapsiblePane(this, wxID_ANY, _("Advanced")); … … 151 146 sizer->Add(diplomacySizer, wxSizerFlags().Expand()); 152 147 148 ///////////////////////////////////////////////////////////////////////// 149 // Camera 150 wxStaticBoxSizer* cameraSizer = new wxStaticBoxSizer(wxHORIZONTAL, this, _("Starting Camera")); 151 wxButton* cameraSet = new wxButton(this, ID_CameraSet, _("Set")); 152 cameraSizer->Add(Tooltipped(cameraSet, _("Set player camera to this view")), wxSizerFlags(1)); 153 wxButton* cameraView = new wxButton(this, ID_CameraView, _("View")); 154 cameraView->Enable(false); 155 cameraSizer->Add(Tooltipped(cameraView, _("View the player camera")), wxSizerFlags(1)); 156 wxButton* cameraClear = new wxButton(this, ID_CameraClear, _("Clear")); 157 cameraClear->Enable(false); 158 cameraSizer->Add(Tooltipped(cameraClear, _("Clear player camera")), wxSizerFlags(1)); 159 160 sizer->Add(cameraSizer, wxSizerFlags().Expand()); 161 153 162 Layout(); 154 163 Thaw(); … … 173 182 { 174 183 return m_PlayerID; 184 } 185 186 bool IsCameraDefined() 187 { 188 return m_CameraDefined; 189 } 190 191 sCameraInfo GetCamera() 192 { 193 return m_Camera; 194 } 195 196 void SetCamera(sCameraInfo info, bool isDefined = true) 197 { 198 m_Camera = info; 199 m_CameraDefined = isDefined; 200 201 // Enable/disable controls 202 wxDynamicCast(FindWindow(ID_CameraView), wxButton)->Enable(isDefined); 203 wxDynamicCast(FindWindow(ID_CameraClear), wxButton)->Enable(isDefined); 175 204 } 176 205 … … 194 223 } 195 224 196 ScenarioEditor& m_ScenarioEditor; 225 void OnCameraSet(wxCommandEvent& evt) 226 { 227 AtlasMessage::qGetView qryView; 228 qryView.Post(); 229 SetCamera(qryView.info, true); 230 231 // Pass event on to next handler 232 evt.Skip(); 233 } 234 235 void OnCameraView(wxCommandEvent& WXUNUSED(evt)) 236 { 237 POST_MESSAGE(SetView, (m_Camera)); 238 } 239 240 void OnCameraClear(wxCommandEvent& evt) 241 { 242 SetCamera(sCameraInfo(), false); 243 244 // Pass event on to next handler 245 evt.Skip(); 246 } 247 248 sCameraInfo m_Camera; 249 bool m_CameraDefined; 197 250 wxString m_Name; 198 251 size_t m_PlayerID; 199 252 ScenarioEditor& m_ScenarioEditor; 253 200 254 PlayerPageControls m_Controls; 201 255 … … 205 259 BEGIN_EVENT_TABLE(PlayerNotebookPage, wxPanel) 206 260 EVT_BUTTON(ID_PlayerColour, PlayerNotebookPage::OnColour) 261 EVT_BUTTON(ID_CameraSet, PlayerNotebookPage::OnCameraSet) 262 EVT_BUTTON(ID_CameraView, PlayerNotebookPage::OnCameraView) 263 EVT_BUTTON(ID_CameraClear, PlayerNotebookPage::OnCameraClear) 207 264 END_EVENT_TABLE(); 208 265 … … 332 389 BEGIN_EVENT_TABLE(PlayerSettingsControl, wxPanel) 333 390 EVT_BUTTON(ID_PlayerColour, PlayerSettingsControl::OnEdit) 391 EVT_BUTTON(ID_CameraSet, PlayerSettingsControl::OnEdit) 392 EVT_BUTTON(ID_CameraClear, PlayerSettingsControl::OnEdit) 334 393 EVT_CHOICE(wxID_ANY, PlayerSettingsControl::OnEdit) 335 394 EVT_TEXT(wxID_ANY, PlayerSettingsControl::OnEdit) … … 383 442 } 384 443 444 // Load AI data 445 ArrayOfAIData ais(AIData::CompareAIData); 446 AtlasMessage::qGetAIData qryAI; 447 qryAI.Post(); 448 AtObj aiData = AtlasObject::LoadFromJSON(m_ScenarioEditor.GetScriptInterface().GetContext(), *qryAI.data); 449 for (AtIter a = aiData["AIData"]["item"]; a.defined(); ++a) 450 { 451 ais.Add(new AIData(wxString(a["id"]), wxString(a["data"]["name"]))); 452 } 453 385 454 // Create player pages 386 455 AtIter player = m_PlayerDefaults["item"]; … … 396 465 for (size_t j = 0; j < civNames.Count(); ++j) 397 466 civChoice->Append(civNames[j], new wxStringClientData(civCodes[j])); 467 civChoice->SetSelection(0); 468 469 // Populate ai choice box 470 wxChoice* aiChoice = controls.ai; 471 aiChoice->Append(_("<None>"), new wxStringClientData()); 472 for (size_t j = 0; j < ais.Count(); ++j) 473 aiChoice->Append(ais[j]->GetName(), new wxStringClientData(ais[j]->GetID())); 474 aiChoice->SetSelection(0); 398 475 } 399 476 … … 418 495 // Prevent error if there's no map settings to parse 419 496 m_MapSettings = AtlasObject::LoadFromJSON(m_ScenarioEditor.GetScriptInterface().GetContext(), *qry.settings); 497 } 498 else 499 { // Use blank object, it will be created next 500 m_MapSettings = AtObj(); 420 501 } 421 502 … … 481 562 controls.colour->SetBackgroundColour(colour); 482 563 564 // player type 565 wxString aiID; 566 if (player["AI"].defined()) 567 aiID = wxString(player["AI"]); 568 else 569 aiID = wxString(playerDefs["AI"]); 570 571 choice = controls.ai; 572 if (!aiID.empty()) 573 { // AI 574 for (size_t j = 0; j < choice->GetCount(); ++j) 575 { 576 wxStringClientData* str = dynamic_cast<wxStringClientData*>(choice->GetClientObject(j)); 577 if (str->GetData() == aiID) 578 { 579 choice->SetSelection(j); 580 break; 581 } 582 } 583 } 584 else 585 { // Human 586 choice->SetSelection(0); 587 } 588 483 589 // resources 484 590 AtObj resObj = *player["Resources"]; … … 514 620 else 515 621 controls.team->SetSelection(0); 622 623 // camera 624 if (player["StartingCamera"].defined()) 625 { 626 AtObj cam = *player["StartingCamera"]; 627 sCameraInfo info; 628 info.pX = wxAtof(*cam["x"]); 629 info.pY = wxAtof(*cam["y"]); 630 info.pZ = wxAtof(*cam["z"]); 631 632 controls.page->SetCamera(info, true); 633 } 634 else 635 controls.page->SetCamera(sCameraInfo(), false); 516 636 517 637 } … … 556 676 clrObj.setInt("b", (int)colour.Blue()); 557 677 player.set("Colour", clrObj); 678 679 // player type 680 choice = controls.ai; 681 if (choice->GetSelection() > 0) 682 { // ai - get id 683 wxStringClientData* str = dynamic_cast<wxStringClientData*>(choice->GetClientObject(choice->GetSelection())); 684 player.set("AI", str->GetData()); 685 } 686 else 687 { // human 688 player.set("AI", _T("")); 689 } 558 690 559 691 // resources … … 582 714 } 583 715 716 // camera 717 if (controls.page->IsCameraDefined()) 718 { 719 sCameraInfo cam = controls.page->GetCamera(); 720 AtObj camObj; 721 camObj.setDouble("x", cam.pX); 722 camObj.setDouble("y", cam.pY); 723 camObj.setDouble("z", cam.pZ); 724 player.set("StartingCamera", camObj); 725 } 726 584 727 players.add("item", player); 585 728 if (oldPlayer.defined()) -
ps/trunk/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Player/Player.h
r9608 r9617 18 18 #include "../Common/Sidebar.h" 19 19 20 #include "GameInterface/Messages.h" 21 20 22 #include "wx/collpane.h" 21 23 24 using namespace AtlasMessage; 25 26 class PlayerNotebookPage; 22 27 class PlayerSettingsControl; 23 28 … … 41 46 DECLARE_EVENT_TABLE(); 42 47 }; 48 49 // Controls present on each player page 50 struct PlayerPageControls 51 { 52 PlayerNotebookPage* page; 53 54 wxTextCtrl* name; 55 wxChoice* civ; 56 wxButton* colour; 57 wxSpinCtrl* food; 58 wxSpinCtrl* wood; 59 wxSpinCtrl* stone; 60 wxSpinCtrl* metal; 61 wxSpinCtrl* pop; 62 wxChoice* team; 63 wxChoice* ai; 64 }; 65 66 // Definitions for keeping AI data sorted 67 class AIData 68 { 69 public: 70 AIData(const wxString& id, const wxString& name) 71 : m_ID(id), m_Name(name) 72 { 73 } 74 75 wxString& GetID() 76 { 77 return m_ID; 78 } 79 80 wxString& GetName() 81 { 82 return m_Name; 83 } 84 85 static int CompareAIData(AIData* ai1, AIData* ai2) 86 { 87 return ai1->m_Name.Cmp(ai2->m_Name); 88 } 89 90 private: 91 wxString m_ID; 92 wxString m_Name; 93 }; 94 WX_DEFINE_SORTED_ARRAY(AIData*, ArrayOfAIData); -
ps/trunk/source/tools/atlas/GameInterface/Handlers/CameraCtrlHandlers.cpp
r8911 r9617 220 220 } 221 221 222 223 } 222 QUERYHANDLER(GetView) 223 { 224 CVector3D focus = g_Game->GetView()->GetCamera()->GetFocus(); 225 226 sCameraInfo info; 227 228 info.pX = focus.X; 229 info.pY = focus.Y; 230 info.pZ = focus.Z; 231 232 // TODO: Rotation 233 234 msg->info = info; 235 } 236 237 MESSAGEHANDLER(SetView) 238 { 239 if (g_Game->GetView()->GetCinema()->IsPlaying()) 240 return; 241 242 CGameView* view = g_Game->GetView(); 243 view->ResetCameraTarget(view->GetCamera()->GetFocus()); 244 245 sCameraInfo cam = msg->info; 246 247 view->ResetCameraTarget(CVector3D(cam.pX, cam.pY, cam.pZ)); 248 } 249 250 } -
ps/trunk/source/tools/atlas/GameInterface/Handlers/PlayerHandlers.cpp
r9247 r9617 36 36 } 37 37 38 QUERYHANDLER(GetAIData) 39 { 40 msg->data = g_Game->GetSimulation2()->GetAIData(); 38 41 } 42 43 } -
ps/trunk/source/tools/atlas/GameInterface/Messages.h
r9609 r9617 184 184 ); 185 185 186 QUERY(GetAIData, 187 , 188 ((std::string, data)) 189 ); 190 186 191 ////////////////////////////////////////////////////////////////////////// 187 192 … … 362 367 363 368 MESSAGE(CameraReset, ); 369 370 QUERY(GetView, 371 , 372 ((sCameraInfo, info)) 373 ); 374 375 MESSAGE(SetView, 376 ((sCameraInfo, info)) 377 ); 364 378 365 379 //////////////////////////////////////////////////////////////////////////
Note:
See TracChangeset
for help on using the changeset viewer.
