-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathAreaEditor.cpp
More file actions
572 lines (485 loc) · 22.7 KB
/
AreaEditor.cpp
File metadata and controls
572 lines (485 loc) · 22.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
#include "AreaEditor.h"
#include "WindowMan.h"
#include "PresetMan.h"
#include "MovableMan.h"
#include "FrameMan.h"
#include "UInputMan.h"
#include "SettingsMan.h"
#include "SLTerrain.h"
#include "Controller.h"
#include "Actor.h"
#include "AHuman.h"
#include "ACRocket.h"
#include "HeldDevice.h"
#include "Scene.h"
#include "DataModule.h"
#include "System.h"
#include "GUI.h"
#include "AllegroBitmap.h"
#include "GUICollectionBox.h"
#include "GUITextBox.h"
#include "GUIButton.h"
#include "GUILabel.h"
#include "GUIComboBox.h"
#include "AreaEditorGUI.h"
#include "GameActivity.h"
using namespace RTE;
ConcreteClassInfo(AreaEditor, EditorActivity, 0);
AreaEditor::AreaEditor() {
Clear();
}
AreaEditor::~AreaEditor() {
Destroy(true);
}
void AreaEditor::Clear() {
m_pEditorGUI = 0;
m_pNewAreaName = 0;
}
int AreaEditor::Create() {
if (EditorActivity::Create() < 0)
return -1;
return 0;
}
int AreaEditor::Create(const AreaEditor& reference) {
if (EditorActivity::Create(reference) < 0)
return -1;
if (m_Description.empty())
m_Description = "Define and edit Areas on this Scene.";
return 0;
}
int AreaEditor::ReadProperty(const std::string_view& propName, Reader& reader) {
StartPropertyList(return EditorActivity::ReadProperty(propName, reader));
/*
MatchProperty("CPUTeam", { reader >> m_CPUTeam; });
MatchProperty("Difficulty", { reader >> m_Difficulty; });
MatchProperty("DeliveryDelay", { reader >> m_DeliveryDelay; });
*/
EndPropertyList;
}
int AreaEditor::Save(Writer& writer) const {
EditorActivity::Save(writer);
return 0;
}
void AreaEditor::Destroy(bool notInherited) {
delete m_pEditorGUI;
if (!notInherited)
EditorActivity::Destroy();
Clear();
}
int AreaEditor::Start() {
int error = EditorActivity::Start();
//////////////////////////////////////////////
// Allocate and (re)create the Editor GUI
if (m_pEditorGUI)
m_pEditorGUI->Destroy();
else
m_pEditorGUI = new AreaEditorGUI;
m_pEditorGUI->Create(&(m_PlayerController[0]), true);
//////////////////////////////////////////////////////////////
// Hooking up directly to the controls defined in the GUI ini
m_pGUIController->Load("Base.rte/GUIs/AreaEditorGUI.ini");
// Resize the invisible root container so it matches the screen rez
GUICollectionBox* pRootBox = dynamic_cast<GUICollectionBox*>(m_pGUIController->GetControl("base"));
if (pRootBox)
pRootBox->SetSize(g_WindowMan.GetResX(), g_WindowMan.GetResY());
// Make sure we have convenient points to the containing GUI dialog boxes that we will manipulate the positions of
if (!m_pNewDialogBox) {
m_pNewDialogBox = dynamic_cast<GUICollectionBox*>(m_pGUIController->GetControl("NewDialogBox"));
// m_pNewDialogBox->SetDrawType(GUICollectionBox::Color);
m_pNewDialogBox->SetPositionAbs((g_FrameMan.GetPlayerScreenWidth() / 2) - (m_pNewDialogBox->GetWidth() / 2), (g_FrameMan.GetPlayerScreenHeight() / 2) - (m_pNewDialogBox->GetHeight() / 2));
m_pNewDialogBox->SetVisible(false);
}
m_pNewAreaName = dynamic_cast<GUITextBox*>(m_pGUIController->GetControl("NewAreaNameTB"));
m_pNewButton = dynamic_cast<GUIButton*>(m_pGUIController->GetControl("NewAreaButton"));
m_pNewCancel = dynamic_cast<GUIButton*>(m_pGUIController->GetControl("NewCancelButton"));
// Make sure we have convenient points to the containing GUI dialog boxes that we will manipulate the positions of
if (!m_pLoadDialogBox) {
m_pLoadDialogBox = dynamic_cast<GUICollectionBox*>(m_pGUIController->GetControl("LoadDialogBox"));
// m_pLoadDialogBox->SetDrawType(GUICollectionBox::Color);
m_pLoadDialogBox->SetPositionAbs((g_FrameMan.GetPlayerScreenWidth() / 2) - (m_pLoadDialogBox->GetWidth() / 2), (g_FrameMan.GetPlayerScreenHeight() / 2) - (m_pLoadDialogBox->GetHeight() / 2));
m_pLoadDialogBox->SetVisible(false);
}
m_pLoadNameCombo = dynamic_cast<GUIComboBox*>(m_pGUIController->GetControl("LoadSceneCB"));
m_pLoadNameCombo->SetDropHeight(std::min(m_pLoadNameCombo->GetDropHeight(), g_WindowMan.GetResY() / 2));
m_pLoadDialogBox->SetSize(m_pLoadDialogBox->GetWidth(), m_pLoadDialogBox->GetHeight() + m_pLoadNameCombo->GetDropHeight()); // Make sure the dropdown can fit, no matter how tall it is.
m_pLoadButton = dynamic_cast<GUIButton*>(m_pGUIController->GetControl("LoadSceneButton"));
m_pLoadCancel = dynamic_cast<GUIButton*>(m_pGUIController->GetControl("LoadCancelButton"));
if (!m_pSaveDialogBox) {
m_pSaveDialogBox = dynamic_cast<GUICollectionBox*>(m_pGUIController->GetControl("SaveDialogBox"));
// Set the background image of the parent collection box
// ContentFile backgroundFile("Base.rte/GUIs/BuyMenuBackground.png");
// m_pSaveDialogBox->SetDrawImage(new AllegroBitmap(backgroundFile.GetAsBitmap()));
// m_pSaveDialogBox->SetDrawBackground(true);
// m_pSaveDialogBox->SetDrawType(GUICollectionBox::Image);
// m_pSaveDialogBox->SetDrawType(GUICollectionBox::Color);
m_pSaveDialogBox->SetPositionAbs((g_FrameMan.GetPlayerScreenWidth() / 2) - (m_pSaveDialogBox->GetWidth() / 2), (g_FrameMan.GetPlayerScreenHeight() / 2) - (m_pSaveDialogBox->GetHeight() / 2));
m_pSaveDialogBox->SetVisible(false);
}
m_pSaveNameBox = dynamic_cast<GUITextBox*>(m_pGUIController->GetControl("SaveSceneNameTB"));
m_pSaveModuleLabel = dynamic_cast<GUILabel*>(m_pGUIController->GetControl("SaveModuleLabel"));
m_pSaveButton = dynamic_cast<GUIButton*>(m_pGUIController->GetControl("SaveSceneButton"));
m_pSaveCancel = dynamic_cast<GUIButton*>(m_pGUIController->GetControl("SaveCancelButton"));
if (!m_pChangesDialogBox) {
m_pChangesDialogBox = dynamic_cast<GUICollectionBox*>(m_pGUIController->GetControl("ChangesDialogBox"));
m_pChangesDialogBox->SetPositionAbs((g_FrameMan.GetPlayerScreenWidth() / 2) - (m_pChangesDialogBox->GetWidth() / 2), (g_FrameMan.GetPlayerScreenHeight() / 2) - (m_pChangesDialogBox->GetHeight() / 2));
m_pChangesDialogBox->SetVisible(false);
}
m_pChangesNameLabel = dynamic_cast<GUILabel*>(m_pGUIController->GetControl("ChangesNameLabel"));
m_pChangesYesButton = dynamic_cast<GUIButton*>(m_pGUIController->GetControl("ChangesYesButton"));
m_pChangesNoButton = dynamic_cast<GUIButton*>(m_pGUIController->GetControl("ChangesNoButton"));
if (!m_pOverwriteDialogBox) {
m_pOverwriteDialogBox = dynamic_cast<GUICollectionBox*>(m_pGUIController->GetControl("OverwriteDialogBox"));
m_pOverwriteDialogBox->SetPositionAbs((g_FrameMan.GetPlayerScreenWidth() / 2) - (m_pOverwriteDialogBox->GetWidth() / 2), (g_FrameMan.GetPlayerScreenHeight() / 2) - (m_pOverwriteDialogBox->GetHeight() / 2));
m_pOverwriteDialogBox->SetVisible(false);
}
m_pOverwriteNameLabel = dynamic_cast<GUILabel*>(m_pGUIController->GetControl("OverwriteNameLabel"));
m_pOverwriteYesButton = dynamic_cast<GUIButton*>(m_pGUIController->GetControl("OverwriteYesButton"));
m_pOverwriteNoButton = dynamic_cast<GUIButton*>(m_pGUIController->GetControl("OverwriteNoButton"));
return error;
}
void AreaEditor::SetPaused(bool pause) {
// Override the pause
m_Paused = false;
}
void AreaEditor::End() {
EditorActivity::End();
m_ActivityState = ActivityState::Over;
}
void AreaEditor::Update() {
EditorActivity::Update();
if (!g_SceneMan.GetScene())
return;
Scene* pCurrentScene = g_SceneMan.GetScene();
// Update the loaded objects of the loaded scene so they look right
pCurrentScene->UpdatePlacedObjects(Scene::PLACEONLOAD);
// If the scene has no Area:s yet, force the user to make a new one
if (pCurrentScene->m_AreaList.empty())
m_EditorMode = EditorActivity::NEWDIALOG;
// All dialog boxes are gone and we're editing the scene's Area:s
if (m_EditorMode == EditorActivity::EDITINGOBJECT) {
if (m_ModeChange) {
// Start in the add/move mode
m_pEditorGUI->SetEditorGUIMode(AreaEditorGUI::PREADDMOVEBOX);
// Hide the cursor for this layer of interface
m_pGUIController->EnableMouse(false);
m_ModeChange = false;
}
g_UInputMan.DisableKeys(false);
}
// We are doing something int he dialog boxes, so don't do anything in the editor interface or show any text messages
else {
m_pEditorGUI->SetEditorGUIMode(AreaEditorGUI::INACTIVE);
g_FrameMan.ClearScreenText();
}
/////////////////////////////////////////////////////
// Update the editor interface
m_pEditorGUI->Update();
// Any edits made, dirtying the scene?
m_NeedSave = m_pEditorGUI->EditMade() || m_NeedSave;
// Get any mode change commands that the user gave the Editor GUI
if (m_pEditorGUI->GetActivatedPieSlice() == PieSliceType::EditorNew && m_EditorMode != NEWDIALOG) {
m_pEditorGUI->SetEditorGUIMode(AreaEditorGUI::INACTIVE);
m_EditorMode = EditorActivity::NEWDIALOG;
m_ModeChange = true;
// This is ahack so we don't get a 'save changes dialog' when we jsut want to create a new area.
// Will turn on dirtyness immediately as New button is pressed below
m_NeedSave = false;
} else if (m_pEditorGUI->GetActivatedPieSlice() == PieSliceType::EditorLoad && m_EditorMode != LOADDIALOG) {
m_pEditorGUI->SetEditorGUIMode(AreaEditorGUI::INACTIVE);
m_EditorMode = EditorActivity::LOADDIALOG;
m_ModeChange = true;
} else if (m_pEditorGUI->GetActivatedPieSlice() == PieSliceType::EditorSave && m_EditorMode != SAVEDIALOG) {
m_pEditorGUI->SetEditorGUIMode(AreaEditorGUI::INACTIVE);
m_EditorMode = EditorActivity::SAVEDIALOG;
m_ModeChange = true;
}
// Test the scene by starting a Skirmish Defense with it, after saving
else if (m_pEditorGUI->GetActivatedPieSlice() == PieSliceType::EditorDone || m_EditorMode == TESTINGOBJECT) {
m_pEditorGUI->SetEditorGUIMode(AreaEditorGUI::INACTIVE);
if (m_NeedSave) {
m_PreviousMode = EditorActivity::TESTINGOBJECT;
m_EditorMode = EditorActivity::CHANGESDIALOG;
m_ModeChange = true;
/*
if (m_HasEverBeenSaved)
SaveScene(pCurrentScene->GetPresetName());
else
{
m_PreviousMode = TESTINGOBJECT;
m_EditorMode = SAVEDIALOG;
m_ModeChange = true;
}
*/
} else {
g_SceneMan.SetSceneToLoad(pCurrentScene->GetPresetName());
const Activity* pActivityPreset = dynamic_cast<const Activity*>(g_PresetMan.GetEntityPreset("GAScripted", "Skirmish Defense"));
Activity* pActivity = dynamic_cast<Activity*>(pActivityPreset->Clone());
GameActivity* pTestGame = dynamic_cast<GameActivity*>(pActivity);
RTEAssert(pTestGame, "Couldn't find the \"Skirmish Defense\" GAScripted Activity! Has it been defined?");
pTestGame->SetTeamOfPlayer(0, 0);
pTestGame->SetCPUTeam(1);
pTestGame->SetStartingGold(10000);
pTestGame->SetFogOfWarEnabled(false);
pTestGame->SetDifficulty(DifficultySetting::MediumDifficulty);
g_ActivityMan.SetStartActivity(pTestGame);
g_ActivityMan.SetRestartActivity();
}
}
////////////////////////////////////////////////////////
// Handle events for mouse input on the controls
GUIEvent anEvent;
while (m_pGUIController->GetEvent(&anEvent)) {
// If we're not supposed to have mouse control, then ignore these messages
// Uh this is not right, editor always has mouse control so far
// if (!m_PlayerController[0].IsMouseControlled())
// break;
if (anEvent.GetType() == GUIEvent::Command) {
//////////////////////////////////////////////////////////
// NEW button pressed; create a Area in the current scene
if (anEvent.GetControl() == m_pNewButton) {
// Make sure we're not trying to create a noname area
if (!m_pNewAreaName->GetText().empty()) {
// Check if name is already taken, and if so, select the taken one instead of creating a new
if (Scene::Area* pArea = pCurrentScene->GetArea(m_pNewAreaName->GetText())) {
m_pEditorGUI->SetCurrentArea(pArea);
m_pEditorGUI->SetEditorGUIMode(AreaEditorGUI::PREADDMOVEBOX);
} else {
// Make and name new Area
Scene::Area* newArea = new Scene::Area(m_pNewAreaName->GetText());
pCurrentScene->m_AreaList.push_back(newArea);
// Set the new area as the active one in the GUI, note we're getting the correct one from the scene, it's a copy of the one passed in
m_pEditorGUI->SetCurrentArea(pCurrentScene->GetArea(newArea->GetName()));
// Update teh picker list of the GUI so we can mousewheel between all the Areas, incl the new one
m_pEditorGUI->UpdatePickerList(newArea->GetName());
}
// Change mode to start editing the new/newly selected Area
m_EditorMode = m_PreviousMode = EditorActivity::EDITINGOBJECT;
m_ModeChange = true;
m_NeedSave = true;
} else {
// TODO: Play some error sound?
}
}
//////////////////////////////////////////////////////////
// LOAD button pressed; load the selected Scene
if (anEvent.GetControl() == m_pLoadButton) {
GUIListPanel::Item* pItem = m_pLoadNameCombo->GetItem(m_pLoadNameCombo->GetSelectedIndex());
if (pItem && !pItem->m_Name.empty()) {
// Attempt to load the scene, without applying its placed objects
g_SceneMan.SetSceneToLoad(pItem->m_Name, false);
g_SceneMan.LoadScene();
// Get the Module ID that the scene exists in, so we can limit the picker to only show objects from that DataModule space
m_ModuleSpaceID = g_SceneMan.GetScene()->GetModuleID();
if (pCurrentScene) {
m_pEditorGUI->Destroy();
m_pEditorGUI->Create(&(m_PlayerController[0]), true);
// TODO: Should read in all the already placed objects in the loaded scene and have them appear int he editor instead
}
}
m_NeedSave = false;
m_HasEverBeenSaved = true;
m_EditorMode = m_PreviousMode = EditorActivity::EDITINGOBJECT;
m_ModeChange = true;
}
//////////////////////////////////////////////////////////
// SAVE button pressed; save the selected Scene
if (anEvent.GetControl() == m_pSaveButton) {
if (!m_pSaveNameBox->GetText().empty()) {
// Save the scene to the name specified in the text box
if (SaveScene(m_pSaveNameBox->GetText())) {
// Close the dialog box on success
m_NeedSave = false;
m_HasEverBeenSaved = true;
// Go back to previous mode after save dialog is done, may have been on the way to test the scene
m_EditorMode = m_PreviousMode;
m_ModeChange = true;
}
// Should really leave dialog box open?
else {
;
}
}
}
///////////////////////////////////////////////////////////////
// Save Changes YES pressed
if (anEvent.GetControl() == m_pChangesYesButton) {
if (m_HasEverBeenSaved) {
if (SaveScene(pCurrentScene->GetPresetName(), true)) {
// Close the dialog box on success
m_NeedSave = false;
m_HasEverBeenSaved = true;
// Go back to previous mode after save dialog is done, may have been on the way to test the scene
m_EditorMode = m_PreviousMode;
m_ModeChange = true;
}
}
// Open the save scene dialog to ask user where to save it then
else {
m_PreviousMode = m_EditorMode;
m_EditorMode = EditorActivity::SAVEDIALOG;
m_ModeChange = true;
}
}
///////////////////////////////////////////////////////////////
// Save Changes NO pressed
if (anEvent.GetControl() == m_pChangesNoButton) {
// Just go back to previous mode
m_EditorMode = m_PreviousMode;
m_ModeChange = true;
m_NeedSave = false;
}
///////////////////////////////////////////////////////////////
// Overwrite Scene YES pressed
if (anEvent.GetControl() == m_pOverwriteYesButton) {
// Force overwrite
if (SaveScene(pCurrentScene->GetPresetName(), true)) {
// Close the dialog box on success
m_NeedSave = false;
m_HasEverBeenSaved = true;
// Go back to previous mode after overwrite dialog is done, may have been on the way to test the scene
m_EditorMode = m_PreviousMode != EditorActivity::SAVEDIALOG ? m_PreviousMode : EditorActivity::EDITINGOBJECT;
m_ModeChange = true;
}
// TODO: Show overwrite error?
}
///////////////////////////////////////////////////////////////
// Overwrite Scene NO pressed
if (anEvent.GetControl() == m_pOverwriteNoButton) {
// Just go back to previous mode
m_EditorMode = m_PreviousMode;
m_ModeChange = true;
}
///////////////////////////////////////////////////////////////
// CANCEL button pressed; exit any active dialog box
if (anEvent.GetControl() == m_pNewCancel || anEvent.GetControl() == m_pLoadCancel || anEvent.GetControl() == m_pSaveCancel) {
m_EditorMode = m_PreviousMode = EditorActivity::EDITINGOBJECT;
m_ModeChange = true;
}
}
// Notifications
else if (anEvent.GetType() == GUIEvent::Notification) {
/*
///////////////////////////////////////
// Clicks on the New Scene Module combo
if (anEvent.GetControl() == m_pNewModuleCombo)
{
// Closed it, IE selected somehting
if(anEvent.GetMsg() == GUIComboBox::Closed)
UpdateNewDialog();
}
*/
}
}
}
void AreaEditor::DrawGUI(BITMAP* pTargetBitmap, const Vector& targetPos, int which) {
m_pEditorGUI->Draw(pTargetBitmap, targetPos);
EditorActivity::DrawGUI(pTargetBitmap, targetPos, which);
}
void AreaEditor::Draw(BITMAP* pTargetBitmap, const Vector& targetPos) {
EditorActivity::Draw(pTargetBitmap, targetPos);
}
bool AreaEditor::SaveScene(const std::string& saveAsName, bool forceOverwrite) {
Scene* editedScene = g_SceneMan.GetScene();
editedScene->SetPresetName(saveAsName);
std::string dataModuleName = g_PresetMan.GetDataModule(m_ModuleSpaceID)->GetFileName();
bool savingToUserScenesModule = (dataModuleName == c_UserScenesModuleName);
std::string dataModuleFullPath = g_PresetMan.GetFullModulePath(dataModuleName);
std::string sceneSavePath;
std::string previewSavePath;
if (savingToUserScenesModule) {
sceneSavePath = dataModuleFullPath + "/" + saveAsName + ".ini";
previewSavePath = dataModuleFullPath + "/" + saveAsName + ".preview.png";
} else {
sceneSavePath = dataModuleFullPath + "/Scenes/" + saveAsName + ".ini";
previewSavePath = dataModuleFullPath + "/Scenes/" + saveAsName + ".preview.png";
}
if (g_PresetMan.AddEntityPreset(editedScene, m_ModuleSpaceID, forceOverwrite, sceneSavePath)) {
if (Writer sceneWriter(sceneSavePath, false); !sceneWriter.WriterOK()) {
RTEError::ShowMessageBox("Failed to create Writer to path:\n\n" + sceneSavePath + "\n\nTHE EDITED SCENE PRESET WAS NOT SAVED!!!");
} else {
// TODO: Check if the ini file already exists, and then ask if overwrite.
sceneWriter.NewPropertyWithValue("AddScene", editedScene);
sceneWriter.EndWrite();
editedScene->SavePreview(previewSavePath);
m_HasEverBeenSaved = true;
if (!savingToUserScenesModule) {
// First find/create a Scenes.ini file to include the new .ini into.
std::string scenesFilePath(dataModuleFullPath + "/Scenes.ini");
bool scenesFileExists = System::PathExistsCaseSensitive(scenesFilePath);
if (Writer scenesFileWriter(scenesFilePath, true); !scenesFileWriter.WriterOK()) {
RTEError::ShowMessageBox("Failed to create Writer to path:\n\n" + scenesFilePath + "\n\nThe edited Scene preset was saved but will not be loaded on next game start!\nPlease include the Scene preset manually!");
} else {
scenesFileWriter.NewPropertyWithValue("IncludeFile", sceneSavePath);
scenesFileWriter.EndWrite();
// Append to the end of the modules' Index.ini to include the newly created Scenes.ini next startup.
// If it's somehow already included without actually existing, it doesn't matter, the definitions will just bounce the second time.
if (!scenesFileExists) {
std::string indexFilePath = dataModuleFullPath + "/Index.ini";
if (Writer indexWriter(indexFilePath, true); !indexWriter.WriterOK()) {
RTEError::ShowMessageBox("Failed to create Writer to path:\n\n" + indexFilePath + "\n\nThe edited Scene preset was saved but will not be loaded on next game start!\nPlease include the Scene preset manually!");
} else {
// Add extra tab since the DataModule has everything indented.
indexWriter.NewProperty("\tIncludeFile");
indexWriter << scenesFilePath;
indexWriter.EndWrite();
}
}
}
}
return true;
}
} else {
// Got to ask if we can overwrite the existing preset.
m_PreviousMode = EditorMode::SAVEDIALOG;
m_EditorMode = EditorMode::OVERWRITEDIALOG;
m_ModeChange = true;
}
return false;
}
void AreaEditor::UpdateNewDialog() {
// Reset the new Area name text field
if (m_pNewAreaName->GetText().empty())
m_pNewAreaName->SetText("Test Area 1");
}
void AreaEditor::UpdateLoadDialog() {
// Clear out the control
m_pLoadNameCombo->ClearList();
// Get the list of all read in scenes
std::list<Entity*> sceneList;
g_PresetMan.GetAllOfType(sceneList, "Scene");
// Go through the list and add their names to the combo box
for (std::list<Entity*>::iterator itr = sceneList.begin(); itr != sceneList.end(); ++itr) {
Scene* pScene = dynamic_cast<Scene*>(*itr);
if (pScene)
// Don't add the special "Editor Scene" or metascenes, users shouldn't be messing with them
if (pScene->GetPresetName() != "Editor Scene" && !pScene->IsMetagameInternal() && !pScene->IsSavedGameInternal() && (pScene->GetMetasceneParent() == "" || g_SettingsMan.ShowMetascenes()))
m_pLoadNameCombo->AddItem(pScene->GetPresetName());
}
// Select the first one
m_pLoadNameCombo->SetSelectedIndex(0);
}
void AreaEditor::UpdateSaveDialog() {
m_pSaveNameBox->SetText((g_SceneMan.GetScene()->GetPresetName() == "None" || !m_HasEverBeenSaved) ? "New Scene" : g_SceneMan.GetScene()->GetPresetName());
if (g_PresetMan.GetDataModule(m_ModuleSpaceID)->GetFileName() == c_UserScenesModuleName)
m_pSaveModuleLabel->SetText("Will save in " + g_PresetMan.GetDataModule(m_ModuleSpaceID)->GetFileName() + "/");
else
m_pSaveModuleLabel->SetText("Will save in " + g_PresetMan.GetDataModule(m_ModuleSpaceID)->GetFileName() + "/Scenes");
}
void AreaEditor::UpdateChangesDialog() {
if (m_HasEverBeenSaved) {
dynamic_cast<GUILabel*>(m_pGUIController->GetControl("ChangesExpLabel"))->SetText("Do you want to save your changes to:");
if (g_PresetMan.GetDataModule(m_ModuleSpaceID)->GetFileName() == c_UserScenesModuleName)
m_pChangesNameLabel->SetText(g_PresetMan.GetDataModule(m_ModuleSpaceID)->GetFileName() + "/" + g_SceneMan.GetScene()->GetPresetName());
else
m_pChangesNameLabel->SetText(g_PresetMan.GetDataModule(m_ModuleSpaceID)->GetFileName() + "/Scenes/" + g_SceneMan.GetScene()->GetPresetName());
} else {
dynamic_cast<GUILabel*>(m_pGUIController->GetControl("ChangesExpLabel"))->SetText("Save your new Scene first?");
m_pChangesNameLabel->SetText("");
}
}
void AreaEditor::UpdateOverwriteDialog() {
if (g_PresetMan.GetDataModule(m_ModuleSpaceID)->GetFileName() == c_UserScenesModuleName)
m_pOverwriteNameLabel->SetText(g_PresetMan.GetDataModule(m_ModuleSpaceID)->GetFileName() + "/" + g_SceneMan.GetScene()->GetPresetName());
else
m_pOverwriteNameLabel->SetText(g_PresetMan.GetDataModule(m_ModuleSpaceID)->GetFileName() + "/Scenes/" + g_SceneMan.GetScene()->GetPresetName());
}