-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssemblyEditor.cpp
More file actions
610 lines (503 loc) · 23.8 KB
/
AssemblyEditor.cpp
File metadata and controls
610 lines (503 loc) · 23.8 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
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
#include "AssemblyEditor.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 "GUI.h"
#include "GUICollectionBox.h"
#include "GUITextBox.h"
#include "GUIButton.h"
#include "GUILabel.h"
#include "GUIComboBox.h"
#include "AssemblyEditorGUI.h"
#include "BunkerAssembly.h"
#include "BunkerAssemblyScheme.h"
using namespace RTE;
ConcreteClassInfo(AssemblyEditor, EditorActivity, 0);
AssemblyEditor::AssemblyEditor() {
Clear();
}
AssemblyEditor::~AssemblyEditor() {
Destroy(true);
}
void AssemblyEditor::Clear() {
m_pEditorGUI = 0;
m_pModuleCombo = 0;
}
int AssemblyEditor::Create() {
if (EditorActivity::Create() < 0)
return -1;
return 0;
}
int AssemblyEditor::Create(const AssemblyEditor& reference) {
if (EditorActivity::Create(reference) < 0)
return -1;
if (m_Description.empty())
m_Description = "Edit this Scene, including placement of all terrain objects and movable objects, AI blueprints, etc.";
return 0;
}
int AssemblyEditor::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 AssemblyEditor::Save(Writer& writer) const {
EditorActivity::Save(writer);
return 0;
}
void AssemblyEditor::Destroy(bool notInherited) {
delete m_pEditorGUI;
if (!notInherited)
EditorActivity::Destroy();
Clear();
}
int AssemblyEditor::Start() {
int error = EditorActivity::Start();
//////////////////////////////////////////////
// Allocate and (re)create the Editor GUI
if (m_pEditorGUI)
m_pEditorGUI->Destroy();
else
m_pEditorGUI = new AssemblyEditorGUI;
m_pEditorGUI->Create(&(m_PlayerController[0]), AssemblyEditorGUI::ONLOADEDIT);
//////////////////////////////////////////////////////////////
// Hooking up directly to the controls defined in the GUI ini
m_pGUIController->Load("Base.rte/GUIs/AssemblyEditorGUI.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_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_pModuleCombo = dynamic_cast<GUIComboBox*>(m_pGUIController->GetControl("ModuleCB"));
m_pModuleCombo->SetDropHeight(std::min(m_pModuleCombo->GetDropHeight(), g_WindowMan.GetResY() / 2));
m_pLoadDialogBox->SetSize(m_pLoadDialogBox->GetWidth(), m_pLoadDialogBox->GetHeight() + (std::max(m_pLoadNameCombo->GetDropHeight(), m_pModuleCombo->GetDropHeight()))); // Make sure the dropdowns can fit, no matter how tall they are.
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
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 AssemblyEditor::SetPaused(bool pause) {
// Override the pause
m_Paused = false;
}
void AssemblyEditor::End() {
EditorActivity::End();
m_ActivityState = ActivityState::Over;
}
void AssemblyEditor::Update() {
EditorActivity::Update();
if (!g_SceneMan.GetScene())
return;
// Update the loaded objects of the loaded scene so they look right
g_SceneMan.GetScene()->UpdatePlacedObjects(Scene::PLACEONLOAD);
// All dialog boxes are gone and we're editing the scene
if (m_EditorMode == EditorActivity::EDITINGOBJECT) {
if (m_ModeChange) {
// Open the picker depending on whetehr there's somehting in the cursor hand or not
m_pEditorGUI->SetEditorGUIMode(m_pEditorGUI->GetCurrentObject() ? AssemblyEditorGUI::ADDINGOBJECT : AssemblyEditorGUI::PICKINGOBJECT);
// 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
else
m_pEditorGUI->SetEditorGUIMode(AssemblyEditorGUI::INACTIVE);
/////////////////////////////////////////////////////
// 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(AssemblyEditorGUI::INACTIVE);
m_EditorMode = EditorActivity::NEWDIALOG;
m_ModeChange = true;
} else if (m_pEditorGUI->GetActivatedPieSlice() == PieSliceType::EditorLoad && m_EditorMode != LOADDIALOG) {
m_pEditorGUI->SetEditorGUIMode(AssemblyEditorGUI::INACTIVE);
m_EditorMode = EditorActivity::LOADDIALOG;
m_ModeChange = true;
} else if (m_pEditorGUI->GetActivatedPieSlice() == PieSliceType::EditorSave && m_EditorMode != SAVEDIALOG) {
m_pEditorGUI->SetEditorGUIMode(AssemblyEditorGUI::INACTIVE);
m_EditorMode = EditorActivity::SAVEDIALOG;
m_ModeChange = true;
}
////////////////////////////////////////////////////////
// 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) {
//////////////////////////////////////////////////////////
// LOAD TO NEW button pressed; go from the load to the new dialog
if (anEvent.GetControl() == m_pLoadToNewButton) {
m_pEditorGUI->SetEditorGUIMode(AssemblyEditorGUI::INACTIVE);
m_EditorMode = EditorActivity::NEWDIALOG;
m_ModeChange = true;
}
//////////////////////////////////////////////////////////
// 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
if (g_SceneMan.GetScene()) {
// m_ModuleSpaceID = g_SceneMan.GetScene()->GetModuleID();
m_ModuleSpaceID = g_PresetMan.GetModuleID(m_pModuleCombo->GetSelectedItem()->m_Name);
RTEAssert(m_ModuleSpaceID >= 0, "Loaded Scene's DataModule ID is negative? Should always be a specific one..");
m_pEditorGUI->Destroy();
if (m_ModuleSpaceID == g_PresetMan.GetModuleID(c_UserScenesModuleName))
m_pEditorGUI->Create(&(m_PlayerController[0]), AssemblyEditorGUI::ONLOADEDIT, -1);
else
m_pEditorGUI->Create(&(m_PlayerController[0]), AssemblyEditorGUI::ONLOADEDIT, m_ModuleSpaceID);
// 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 (SaveAssembly(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 = EditorActivity::EDITINGOBJECT;
m_ModeChange = true;
}
// Should really leave dialog box open?
else {
;
}
}
}
///////////////////////////////////////////////////////////////
// Save Changes YES pressed
if (anEvent.GetControl() == m_pChangesYesButton) {
if (m_HasEverBeenSaved) {
if (SaveAssembly(m_pEditorGUI->GetCurrentAssemblyName(), 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 = EditorActivity::EDITINGOBJECT;
m_ModeChange = true;
}
}
// Open the save scene dialog to ask user where to save it then
else {
m_PreviousMode = m_PreviousMode;
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 (SaveAssembly(m_pEditorGUI->GetCurrentAssemblyName(), 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 = EditorActivity::EDITINGOBJECT;
m_ModeChange = true;
}
}
///////////////////////////////////////////////////////////////
// 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) {
// Don't allow canceling out of diags if we're still in the special "Editor Scene", don't allow users to edit it!
// Just exit the whole editor into the main menu
if (g_SceneMan.GetScene()->GetPresetName() == "Editor Scene") {
g_ActivityMan.PauseActivity();
}
// Just do normal cancel of the dialog and go back to editing
else
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 AssemblyEditor::DrawGUI(BITMAP* pTargetBitmap, const Vector& targetPos, int which) {
m_pEditorGUI->Draw(pTargetBitmap, targetPos);
EditorActivity::DrawGUI(pTargetBitmap, targetPos, which);
}
void AssemblyEditor::Draw(BITMAP* pTargetBitmap, const Vector& targetPos) {
EditorActivity::Draw(pTargetBitmap, targetPos);
}
BunkerAssembly* AssemblyEditor::BuildAssembly(std::string saveAsName) {
// Create new bunker assembly to save
BunkerAssembly* pBA = new BunkerAssembly();
pBA->Create(m_pEditorGUI->GetCurrentAssemblyScheme());
// Retreive some properties if we're overwriting existing bunker assembly
const BunkerAssembly* pExistingBA = dynamic_cast<const BunkerAssembly*>(g_PresetMan.GetEntityPreset("BunkerAssembly", saveAsName, m_ModuleSpaceID));
if (pExistingBA) {
pBA->SetSymmetricAssemblyName(pExistingBA->GetSymmetricAssemblyName());
}
pBA->SetPresetName(saveAsName);
m_pEditorGUI->SetCurrentAssemblyName(saveAsName);
const std::list<SceneObject*>* pSceneObjectList = 0;
pSceneObjectList = g_SceneMan.GetScene()->GetPlacedObjects(Scene::PLACEONLOAD);
for (std::list<SceneObject*>::const_iterator itr = pSceneObjectList->begin(); itr != pSceneObjectList->end(); ++itr) {
// Check if object fits the assembly box
bool skip = true;
Vector pos = (*itr)->GetPos() - pBA->GetPos() - pBA->GetBitmapOffset();
Vector finalPos = pos;
if ((pos.m_X >= 0) && (pos.m_X < pBA->GetBitmapWidth()) &&
(pos.m_Y >= 0) && (pos.m_Y < pBA->GetBitmapHeight()))
skip = false;
// Try to move scene object across seams and see if it fits into assembly box
if (g_SceneMan.GetScene()->WrapsX()) {
pos = (*itr)->GetPos() - pBA->GetPos() - pBA->GetBitmapOffset() + Vector(g_SceneMan.GetScene()->GetWidth(), 0);
if ((pos.m_X >= 0) && (pos.m_X < pBA->GetBitmapWidth()) &&
(pos.m_Y >= 0) && (pos.m_Y < pBA->GetBitmapHeight())) {
skip = false;
finalPos = pos;
}
pos = (*itr)->GetPos() - pBA->GetPos() - pBA->GetBitmapOffset() - Vector(g_SceneMan.GetScene()->GetWidth(), 0);
if ((pos.m_X >= 0) && (pos.m_X < pBA->GetBitmapWidth()) &&
(pos.m_Y >= 0) && (pos.m_Y < pBA->GetBitmapHeight())) {
skip = false;
finalPos = pos;
}
}
if (g_SceneMan.GetScene()->WrapsY()) {
pos = (*itr)->GetPos() - pBA->GetPos() - pBA->GetBitmapOffset() + Vector(0, g_SceneMan.GetScene()->GetHeight());
if ((pos.m_X >= 0) && (pos.m_X < pBA->GetBitmapWidth()) &&
(pos.m_Y >= 0) && (pos.m_Y < pBA->GetBitmapHeight())) {
skip = false;
finalPos = pos;
}
pos = (*itr)->GetPos() - pBA->GetPos() - pBA->GetBitmapOffset() - Vector(0, g_SceneMan.GetScene()->GetHeight());
if ((pos.m_X >= 0) && (pos.m_X < pBA->GetBitmapWidth()) &&
(pos.m_Y >= 0) && (pos.m_Y < pBA->GetBitmapHeight())) {
skip = false;
finalPos = pos;
}
}
if (!skip) {
SceneObject* pNewSO = dynamic_cast<SceneObject*>((*itr)->Clone());
// Set position relative to this Bunker Assembly
// pNewSO->SetPos(pNewSO->GetPos() - pBA->GetPos() - pBA->GetBitmapOffset());
pNewSO->SetPos(finalPos);
pBA->AddPlacedObject(pNewSO);
}
}
return pBA;
}
bool AssemblyEditor::SaveAssembly(const std::string& saveAsName, bool forceOverwrite) {
std::unique_ptr<BunkerAssembly> editedAssembly(BuildAssembly(saveAsName));
std::string dataModuleName = g_PresetMan.GetDataModule(m_ModuleSpaceID)->GetFileName();
bool savingToUserScenesModule = (dataModuleName == c_UserScenesModuleName);
std::string dataModuleFullPath = g_PresetMan.GetFullModulePath(dataModuleName);
std::string assemblySavePath;
if (savingToUserScenesModule) {
assemblySavePath = dataModuleFullPath + "/" + saveAsName + ".ini";
} else {
if (dataModuleName == "Base.rte") {
assemblySavePath = dataModuleFullPath + "/Scenes/Objects/Bunkers/BunkerAssemblies/" + saveAsName + ".ini";
} else {
System::MakeDirectory((dataModuleFullPath + "/BunkerAssemblies").c_str());
assemblySavePath = dataModuleFullPath + "/BunkerAssemblies/" + saveAsName + ".ini";
}
}
if (g_PresetMan.AddEntityPreset(editedAssembly.get(), m_ModuleSpaceID, forceOverwrite, assemblySavePath)) {
if (Writer assemblyWriter(assemblySavePath, false); !assemblyWriter.WriterOK()) {
RTEError::ShowMessageBox("Failed to create Writer to path:\n\n" + assemblySavePath + "\n\nTHE EDITED BUNKER ASSEMBLY PRESET WAS NOT SAVED!!!");
} else {
// TODO: Check if the ini file already exists, and then ask if overwrite.
assemblyWriter.NewPropertyWithValue("AddBunkerAssembly", editedAssembly.get());
assemblyWriter.EndWrite();
m_HasEverBeenSaved = true;
if (!savingToUserScenesModule) {
// First find/create a BunkerAssemblies.ini file to include the new .ini into.
std::string assembliesFilePath = dataModuleFullPath + ((dataModuleName == "Base.rte") ? "/Scenes/Objects/Bunkers/BunkerAssemblies/BunkerAssemblies.ini" : "/BunkerAssemblies/BunkerAssemblies.ini");
bool assembliesFileExists = System::PathExistsCaseSensitive(assembliesFilePath);
if (Writer assembliesFileWriter(assembliesFilePath, true); !assembliesFileWriter.WriterOK()) {
RTEError::ShowMessageBox("Failed to create Writer to path:\n\n" + assembliesFilePath + "\n\nThe edited Scene preset was saved but will not be loaded on next game start!\nPlease include the Scene preset manually!");
} else {
assembliesFileWriter.NewPropertyWithValue("IncludeFile", assemblySavePath);
assembliesFileWriter.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 (!assembliesFileExists) {
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 << assembliesFilePath;
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 AssemblyEditor::UpdateNewDialog() {
}
void AssemblyEditor::UpdateLoadDialog() {
int scenesIndex = 0;
if (m_pModuleCombo->GetCount() <= 0) {
for (int module = 0; module < g_PresetMan.GetTotalModuleCount(); ++module) {
// Cut-off vanilla modules except Base.rte
bool isValid = false;
// If metascenes are visible then allow to save assemblies to Base.rte
if (g_SettingsMan.ShowMetascenes()) {
if ((module == 0 || module > 8) && g_PresetMan.GetDataModule(module)->GetFileName() != c_UserConquestSavesModuleName && g_PresetMan.GetDataModule(module)->GetFileName() != "Missions.rte")
isValid = true;
} else {
if (module > 8 && g_PresetMan.GetDataModule(module)->GetFileName() != c_UserConquestSavesModuleName && g_PresetMan.GetDataModule(module)->GetFileName() != "Missions.rte" && g_PresetMan.GetDataModule(module)->GetFileName() != c_UserScriptedSavesModuleName)
isValid = true;
}
// If Saving to Base.rte is enabled, every module is valid for saving
if (g_SettingsMan.AllowSavingToBase())
isValid = true;
if (isValid) {
m_pModuleCombo->AddItem(g_PresetMan.GetDataModule(module)->GetFileName());
if (g_SettingsMan.AllowSavingToBase()) {
// If editors are in dev-mode then select Base.rte as default module to save stuff
if (g_PresetMan.GetDataModule(module)->GetFileName() == "Base.rte")
scenesIndex = m_pModuleCombo->GetCount() - 1;
} else {
if (g_PresetMan.GetDataModule(module)->GetFileName() == c_UserScenesModuleName)
scenesIndex = m_pModuleCombo->GetCount() - 1;
}
}
}
m_pModuleCombo->SetDropHeight(std::min({m_pModuleCombo->GetListPanel()->GetStackHeight() + 4, m_pModuleCombo->GetDropHeight(), g_WindowMan.GetResY() / 2}));
// Select the user scenes module
m_pModuleCombo->SetSelectedIndex(scenesIndex);
}
// 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 AssemblyEditor::UpdateSaveDialog() {
std::string defaultName = "";
BunkerAssemblyScheme* pScheme = m_pEditorGUI->GetCurrentAssemblyScheme();
if (pScheme)
defaultName = pScheme->GetPresetName() + " - ";
m_pSaveNameBox->SetText(m_pEditorGUI->GetCurrentAssemblyName() == "" ? defaultName : m_pEditorGUI->GetCurrentAssemblyName());
m_pSaveModuleLabel->SetText("Will save in " + g_PresetMan.GetDataModule(m_ModuleSpaceID)->GetFileName());
}
void AssemblyEditor::UpdateChangesDialog() {
if (m_HasEverBeenSaved) {
dynamic_cast<GUILabel*>(m_pGUIController->GetControl("ChangesExpLabel"))->SetText("Do you want to save your changes to:");
m_pChangesNameLabel->SetText(m_pEditorGUI->GetCurrentAssemblyName());
} else {
dynamic_cast<GUILabel*>(m_pGUIController->GetControl("ChangesExpLabel"))->SetText("Save your new Assembly first?");
m_pChangesNameLabel->SetText(m_pEditorGUI->GetCurrentAssemblyName());
}
}
void AssemblyEditor::UpdateOverwriteDialog() {
m_pOverwriteNameLabel->SetText(m_pEditorGUI->GetCurrentAssemblyName());
}