-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGibEditor.cpp
More file actions
739 lines (635 loc) · 29.1 KB
/
Copy pathGibEditor.cpp
File metadata and controls
739 lines (635 loc) · 29.1 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
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
#include "GibEditor.h"
#include "WindowMan.h"
#include "PresetMan.h"
#include "MovableMan.h"
#include "FrameMan.h"
#include "UInputMan.h"
// #include "AHuman.h"
// #include "MOPixel.h"
#include "SLTerrain.h"
#include "Controller.h"
// #include "AtomGroup.h"
#include "Actor.h"
#include "AHuman.h"
#include "ACRocket.h"
#include "HeldDevice.h"
#include "Scene.h"
#include "DataModule.h"
#include "GUI.h"
#include "AllegroBitmap.h"
#include "GUICollectionBox.h"
#include "GUITextBox.h"
#include "GUIButton.h"
#include "GUILabel.h"
#include "GUIComboBox.h"
#include "System.h"
#include "GibEditorGUI.h"
using namespace RTE;
ConcreteClassInfo(GibEditor, EditorActivity, 0);
GibEditor::GibEditor() {
Clear();
}
GibEditor::~GibEditor() {
Destroy(true);
}
void GibEditor::Clear() {
m_pEditedObject = 0;
m_pTestingObject = 0;
m_TestCounter = 0;
m_pObjectToLoad = 0;
m_pEditorGUI = 0;
}
int GibEditor::Create() {
if (EditorActivity::Create() < 0)
return -1;
return 0;
}
int GibEditor::Create(const GibEditor& reference) {
if (EditorActivity::Create(reference) < 0)
return -1;
if (m_Description.empty())
m_Description = "Edit how Movable Objects break apart into smaller pieces.";
return 0;
}
int GibEditor::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 GibEditor::Save(Writer& writer) const {
EditorActivity::Save(writer);
return 0;
}
void GibEditor::Destroy(bool notInherited) {
delete m_pEditedObject;
delete m_pTestingObject;
delete m_pEditorGUI;
if (!notInherited)
EditorActivity::Destroy();
Clear();
}
int GibEditor::Start() {
int error = EditorActivity::Start();
//////////////////////////////////////////////
// Allocate and (re)create the Editor GUI
if (m_pEditorGUI)
m_pEditorGUI->Destroy();
else
m_pEditorGUI = new GibEditorGUI;
m_pEditorGUI->Create(&(m_PlayerController[0]));
//////////////////////////////////////////////////////////////
// Hooking up directly to the controls defined in the GUI ini
m_pGUIController->Load("Base.rte/GUIs/GibEditorGUI.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_pNewModuleCombo = dynamic_cast<GUIComboBox *>(m_pGUIController->GetControl("NewModuleCB"));
m_pNewButton = dynamic_cast<GUIButton*>(m_pGUIController->GetControl("NewSceneButton"));
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_pLoadButton = dynamic_cast<GUIButton*>(m_pGUIController->GetControl("LoadButton"));
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("SaveNameTB"));
m_pSaveModuleLabel = dynamic_cast<GUILabel*>(m_pGUIController->GetControl("SaveModuleLabel"));
m_pSaveButton = dynamic_cast<GUIButton*>(m_pGUIController->GetControl("SaveButton"));
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"));
m_EditorMode = EditorActivity::EDITINGOBJECT;
// Show the picker dialog to select an object to load
m_pEditorGUI->SetEditorGUIMode(GibEditorGUI::PICKOBJECTTOLOAD);
m_ModeChange = true;
return error;
}
void GibEditor::SetPaused(bool pause) {
// Override the pause
m_Paused = false;
}
void GibEditor::End() {
EditorActivity::End();
m_ActivityState = ActivityState::Over;
}
void GibEditor::Update() {
// And object hasn't been loaded yet, so get the loading picker going
if (!m_pEditedObject && !m_pObjectToLoad) {
m_NeedSave = false;
m_HasEverBeenSaved = false;
m_PreviousMode = EditorActivity::LOADDIALOG;
m_EditorMode = EditorActivity::EDITINGOBJECT;
// Show the picker dialog to select an object to load
m_pEditorGUI->SetEditorGUIMode(GibEditorGUI::PICKOBJECTTOLOAD);
m_ModeChange = true;
}
// Mode switching etc
EditorActivity::Update();
if (!g_SceneMan.GetScene())
return;
//////////////////////////////////////
// Special testing mode
if (m_EditorMode == EditorActivity::TESTINGOBJECT) {
if (m_ModeChange) {
m_pGUIController->EnableMouse(false);
m_ModeChange = false;
}
// We haven't detonated yet
if (m_pTestingObject) {
g_FrameMan.SetScreenText("Click to test gib the object!", 0, 333);
// Detonate on command!
if (m_PlayerController[0].IsState(PRESS_PRIMARY) || m_PlayerController[0].IsState(PRESS_SECONDARY) || m_PlayerController[0].IsState(PRESS_FACEBUTTON)) {
// This adds all the gibs to the movableman
m_pTestingObject->GibThis();
// Now safe to get rid of the test subject
m_pTestingObject->DestroyScriptState();
delete m_pTestingObject;
m_pTestingObject = nullptr;
}
}
// Test has blown up, now waiting for user to finish watching the pieces fly
else {
g_FrameMan.SetScreenText("Click again to go back to editing...");
if (m_PlayerController[0].IsState(PRESS_PRIMARY) || m_PlayerController[0].IsState(PRESS_SECONDARY) || m_PlayerController[0].IsState(PRESS_FACEBUTTON)) {
// Clear out the terrain after a few tests
if (m_TestCounter >= 3) {
ClearTestArea();
m_TestCounter = 0;
}
// Clear all crap still flying around
g_MovableMan.PurgeAllMOs();
g_MovableMan.Update();
// Go back to editing the edited object
m_pEditorGUI->SetEditorGUIMode(GibEditorGUI::INACTIVE);
m_EditorMode = EditorActivity::EDITINGOBJECT;
m_ModeChange = true;
// Pause the sim again
m_Paused = true;
}
}
}
// All dialog boxes are gone and we're editing the object
else if (m_pEditedObject && 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->GetCurrentGib() ? GibEditorGUI::ADDINGGIB : GibEditorGUI::PICKINGGIB);
// Hide the cursor for this layer of interface
m_pGUIController->EnableMouse(false);
m_ModeChange = false;
}
g_UInputMan.DisableKeys(false);
}
// We are doing something in the dialog boxes, so don't do anything in the editor interface
else if (m_pEditedObject)
m_pEditorGUI->SetEditorGUIMode(GibEditorGUI::INACTIVE);
/////////////////////////////////////////////////////
// Update the editor interface
m_pEditorGUI->Update();
// Any edits made, dirtying the object?
m_NeedSave = m_NeedSave || m_pEditorGUI->EditMade();
// Get any mode change commands that the user gave the Editor GUI
if (m_pEditorGUI->GetActivatedPieSlice() == PieSliceType::EditorNew && m_EditorMode != NEWDIALOG) {
m_pEditorGUI->SetEditorGUIMode(GibEditorGUI::INACTIVE);
m_EditorMode = EditorActivity::NEWDIALOG;
m_ModeChange = true;
}
// Loading is done differently, only when user has already picked an object ot load from the picker should the dialog box appear
else if (m_pEditorGUI->GetObjectToLoad() && m_EditorMode != LOADDIALOG) {
m_pObjectToLoad = m_pEditorGUI->GetObjectToLoad();
m_pEditorGUI->SetEditorGUIMode(GibEditorGUI::INACTIVE);
m_EditorMode = EditorActivity::LOADDIALOG;
m_ModeChange = true;
} else if (m_pEditorGUI->GetActivatedPieSlice() == PieSliceType::EditorSave && m_EditorMode != SAVEDIALOG) {
m_pEditorGUI->SetEditorGUIMode(GibEditorGUI::INACTIVE);
m_EditorMode = EditorActivity::SAVEDIALOG;
m_ModeChange = true;
}
// Test the object by allowing the player to gib temporary test copy instances of the edited object
else if (m_pEditorGUI->GetActivatedPieSlice() == PieSliceType::EditorDone) {
// Make the copy of the current edited object
m_pTestingObject->DestroyScriptState();
delete m_pTestingObject;
m_pTestingObject = dynamic_cast<MOSRotating*>(m_pEditedObject->Clone());
// Put the proxy gibs into the test object
StuffEditedGibs(m_pTestingObject);
// Increment the number of tests, after certain amount the terrain is cleared of debris
m_TestCounter++;
m_pEditorGUI->SetEditorGUIMode(GibEditorGUI::INACTIVE);
m_PreviousMode = EditorActivity::EDITINGOBJECT;
m_EditorMode = EditorActivity::TESTINGOBJECT;
m_ModeChange = true;
// Start running the sim
m_Paused = false;
}
////////////////////////////////////////////////////////
// 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 new object
if (anEvent.GetControl() == m_pNewButton)
{
// Get the selected Module
GUIListPanel::Item *pItem = m_pNewModuleCombo->GetItem(m_pNewModuleCombo->GetSelectedIndex());
if (pItem && !pItem->m_Name.empty())
{
m_ModuleSpaceID = g_PresetMan.GetModuleID(pItem->m_Name);
// Allocate Scene
Scene *pNewScene = new Scene();
// Get the selected Terrain and create the Scene using it
pItem = m_pNewTerrainCombo->GetItem(m_pNewTerrainCombo->GetSelectedIndex());
if (pItem && !pItem->m_Name.empty())
{
SLTerrain *pNewTerrain = dynamic_cast<SLTerrain *>(g_PresetMan.GetEntityPreset("SLTerrain", pItem->m_Name, m_ModuleSpaceID)->Clone());
RTEAssert(pNewTerrain, "No SLTerrain of that name defined!");
pNewScene->Create(pNewTerrain);
}
// Add specified object layers
pItem = m_pNewBG1Combo->GetItem(m_pNewBG1Combo->GetSelectedIndex());
if (pItem && !pItem->m_Name.empty())
{
SceneLayer *pNewLayer = dynamic_cast<SceneLayer *>(g_PresetMan.GetEntityPreset("SceneLayer", pItem->m_Name, m_ModuleSpaceID)->Clone());
RTEAssert(pNewLayer, "No SceneLayer of the name set as BG1 is defined!");
pNewScene->GetBackLayers().push_back(pNewLayer);
}
pItem = m_pNewBG2Combo->GetItem(m_pNewBG2Combo->GetSelectedIndex());
if (pItem && !pItem->m_Name.empty())
{
SceneLayer *pNewLayer = dynamic_cast<SceneLayer *>(g_PresetMan.GetEntityPreset("SceneLayer", pItem->m_Name, m_ModuleSpaceID)->Clone());
RTEAssert(pNewLayer, "No SceneLayer of the name set as BG2 is defined!");
pNewScene->GetBackLayers().push_back(pNewLayer);
}
pItem = m_pNewBG3Combo->GetItem(m_pNewBG3Combo->GetSelectedIndex());
if (pItem && !pItem->m_Name.empty())
{
SceneLayer *pNewLayer = dynamic_cast<SceneLayer *>(g_PresetMan.GetEntityPreset("SceneLayer", pItem->m_Name, m_ModuleSpaceID)->Clone());
RTEAssert(pNewLayer, "No SceneLayer of the name set as BG3 is defined!");
pNewScene->GetBackLayers().push_back(pNewLayer);
}
// Actually load the object's data and set it up as the current object
g_SceneMan.LoadScene(pNewScene);
// Reset the rest of the editor GUI
m_pEditorGUI->Destroy();
m_pEditorGUI->Create(&(m_PlayerController[0]), m_ModuleSpaceID);
}
m_NeedSave = false;
m_HasEverBeenSaved = false;
m_EditorMode = m_PreviousMode = EditorActivity::EDITINGOBJECT;
m_ModeChange = true;
}
*/
//////////////////////////////////////////////////////////
// LOAD button pressed; load the selected Object
if (anEvent.GetControl() == m_pLoadButton && m_pObjectToLoad) {
m_pEditedObject = dynamic_cast<MOSRotating*>(m_pObjectToLoad->Clone());
if (m_pEditedObject) {
// Get the module space ID
m_ModuleSpaceID = m_pEditedObject->GetModuleID();
RTEAssert(m_ModuleSpaceID >= 0, "Loaded Object's DataModule ID is negative? Should always be a specific one..");
// Restart the editor GUI
m_pEditorGUI->Destroy();
m_pEditorGUI->Create(&(m_PlayerController[0]), m_ModuleSpaceID);
// Set the position of the loaded edited object to the middle of the scene
m_pEditedObject->SetPos(Vector(g_SceneMan.GetSceneWidth() / 2, g_SceneMan.GetSceneHeight() / 2));
m_pEditedObject->Update();
// Make proxy copies of the loaded objects' gib reference instances and place them in the list to be edited
std::list<Gib>* pLoadedGibList = m_pEditedObject->GetGibList();
std::list<MovableObject*>* pEditedGibList = m_pEditorGUI->GetPlacedGibs();
MovableObject* pGibCopy = 0;
for (auto gItr = pLoadedGibList->begin(); gItr != pLoadedGibList->end(); ++gItr) {
pGibCopy = dynamic_cast<MovableObject*>((*gItr).GetParticlePreset()->Clone());
if (pGibCopy) {
pGibCopy->SetPos(m_pEditedObject->GetPos() + (*gItr).GetOffset());
pEditedGibList->push_back(pGibCopy);
}
pGibCopy = 0;
}
// Clear out the testing area
ClearTestArea();
m_TestCounter = 0;
m_pObjectToLoad = 0;
}
m_NeedSave = false;
m_HasEverBeenSaved = true;
m_EditorMode = m_PreviousMode = EditorActivity::EDITINGOBJECT;
m_ModeChange = true;
}
//////////////////////////////////////////////////////////
// SAVE button pressed; save the selected Object
if (anEvent.GetControl() == m_pSaveButton) {
if (!m_pSaveNameBox->GetText().empty()) {
// Save the object to the name specified in the text box
if (SaveObject(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 object
m_EditorMode = m_PreviousMode;
m_ModeChange = true;
}
// Should really leave dialog box open? error handling, bitte
else {
;
}
}
}
///////////////////////////////////////////////////////////////
// Save Changes YES pressed
if (anEvent.GetControl() == m_pChangesYesButton && m_pEditedObject) {
if (m_HasEverBeenSaved) {
if (SaveObject(m_pEditedObject->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 object
m_EditorMode = m_PreviousMode;
m_ModeChange = true;
}
}
// Open the save object 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 Object YES pressed
if (anEvent.GetControl() == m_pOverwriteYesButton && m_pEditedObject) {
// Force overwrite
if (SaveObject(m_pEditedObject->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 object
m_EditorMode = m_PreviousMode != EditorActivity::SAVEDIALOG ? m_PreviousMode : EditorActivity::EDITINGOBJECT;
m_ModeChange = true;
}
// TODO: Show overwrite error?
}
///////////////////////////////////////////////////////////////
// Overwrite Object 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 load is cancel when just opening the scene
if (anEvent.GetControl() == m_pLoadCancel && !m_pEditedObject) {
m_PreviousMode = EditorActivity::LOADDIALOG;
m_EditorMode = EditorActivity::EDITINGOBJECT;
// Show the picker dialog to select an object to load
m_pEditorGUI->SetEditorGUIMode(GibEditorGUI::PICKOBJECTTOLOAD);
m_ModeChange = true;
}
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 Object Module combo
if (anEvent.GetControl() == m_pNewModuleCombo) {
// Closed it, IE selected somehting
if (anEvent.GetMsg() == GUIComboBox::Closed)
UpdateNewDialog();
}
}
}
}
void GibEditor::DrawGUI(BITMAP* pTargetBitmap, const Vector& targetPos, int which) {
// Testing mode
if (m_EditorMode == EditorActivity::TESTINGOBJECT) {
if (m_pTestingObject)
m_pTestingObject->Draw(pTargetBitmap, targetPos, g_DrawColor, true);
}
// Regular drawing mode
else {
// Draw ghost outline of edited object to place gibs upon
if (m_pEditedObject) {
g_FrameMan.SetTransTableFromPreset(TransparencyPreset::MoreTrans);
// Draw only the MOSRotating since that's all we are adding gibs for; any attachables have to be edited separately
m_pEditedObject->MOSRotating::Draw(pTargetBitmap, targetPos, g_DrawTrans, true);
}
m_pEditorGUI->Draw(pTargetBitmap, targetPos);
EditorActivity::DrawGUI(pTargetBitmap, targetPos, which);
}
}
void GibEditor::Draw(BITMAP* pTargetBitmap, const Vector& targetPos) {
EditorActivity::Draw(pTargetBitmap, targetPos);
}
bool GibEditor::SaveObject(const std::string& saveAsName, bool forceOverwrite) {
if (!m_pEditedObject) {
return false;
}
m_pEditedObject->SetPresetName(saveAsName);
// Replace the gibs of the object with the proxies that have been edited in the GUI.
StuffEditedGibs(m_pEditedObject);
std::string dataModuleName = g_PresetMan.GetDataModule(m_ModuleSpaceID)->GetFileName();
std::string dataModuleFullPath = g_PresetMan.GetFullModulePath(dataModuleName);
std::string newDataDir = dataModuleFullPath + "/NewData";
std::string objectSavePath = newDataDir + "/" + saveAsName + ".ini";
if (!System::PathExistsCaseSensitive(newDataDir) && !System::MakeDirectory(newDataDir)) {
RTEError::ShowMessageBox("Failed to create NewData directory in:\n\n" + dataModuleFullPath + "\n\nTHE EDITED OBJECT PRESET WAS NOT SAVED!!!");
return false;
}
// Force overwrite the stored preset so we aren't prompted to every time for every preset. This doesn't screw with the original ini because there's no system for that in place
// and doesn't actually get loaded on the next game start either, so any changes will be discarded at the end of the current runtime.
if (g_PresetMan.AddEntityPreset(m_pEditedObject, m_ModuleSpaceID, true, objectSavePath)) {
// Show the overwrite dialog only when actually overwriting a saved ini in NewData or forcing an overwrite.
if (!System::PathExistsCaseSensitive(objectSavePath) || forceOverwrite) {
if (Writer objectWriter(objectSavePath, false); !objectWriter.WriterOK()) {
RTEError::ShowMessageBox("Failed to create Writer to path:\n\n" + objectSavePath + "\n\nTHE EDITED OBJECT PRESET WAS NOT SAVED!!!");
} else {
std::string addObjectType;
switch (m_pEditedObject->GetMOType()) {
case MovableObject::MOType::TypeActor:
addObjectType = "AddActor";
break;
case MovableObject::MOType::TypeHeldDevice:
case MovableObject::MOType::TypeThrownDevice:
addObjectType = "AddDevice";
break;
default:
addObjectType = "AddEffect";
}
objectWriter.NewProperty(addObjectType);
m_pEditedObject->Entity::Save(objectWriter);
for (const Gib& gib: *m_pEditedObject->GetGibList()) {
objectWriter.NewPropertyWithValue("AddGib", gib);
}
objectWriter.ObjectEnd();
objectWriter.EndWrite();
m_HasEverBeenSaved = true;
// TODO: Maybe make system for saving into/over the existing definition read originally from the ini's, wherever it was.
return true;
}
} else {
// Got to ask if we can overwrite the existing object.
m_PreviousMode = EditorMode::SAVEDIALOG;
m_EditorMode = EditorMode::OVERWRITEDIALOG;
m_ModeChange = true;
}
}
return false;
}
void GibEditor::StuffEditedGibs(MOSRotating* pEditedObject) {
if (!pEditedObject)
return;
// Replace the gibs of the object with the proxies that have been edited in the gui
std::list<Gib>* pObjectGibList = pEditedObject->GetGibList();
pObjectGibList->clear();
// Take each proxy object and stuff it into a Gib instance which then gets stuffed into the object to be saved
std::list<MovableObject*>* pProxyGibList = m_pEditorGUI->GetPlacedGibs();
for (std::list<MovableObject*>::iterator gItr = pProxyGibList->begin(); gItr != pProxyGibList->end(); ++gItr) {
Gib newGib;
// Only set the refernce instance directly from the isntanceman. OWNERSHIP IS NOT TRANSFERRED!
newGib.m_GibParticle = dynamic_cast<const MovableObject*>(g_PresetMan.GetEntityPreset((*gItr)->GetClassName(), (*gItr)->GetPresetName(), m_ModuleSpaceID));
if (newGib.m_GibParticle) {
newGib.m_Count = 1;
newGib.m_Offset = (*gItr)->GetPos() - pEditedObject->GetPos();
// TODO: do proper velocity calculations here!
// ... actually leave these as 0 and let them be calculated in GibThis
// newGib.m_MinVelocity = (100.0f + 50.0f * NormalRand()) / (*gItr)->GetMass();
// newGib.m_MaxVelocity = newGib.m_MinVelocity + ((100.0f * RandomNum()) / (*gItr)->GetMass());
pObjectGibList->push_back(newGib);
}
}
}
void GibEditor::UpdateNewDialog() {
/*
// Only refill modules if empty
if (m_pNewModuleCombo->GetCount() <= 0)
{
for (int module = 0; module < g_PresetMan.GetTotalModuleCount(); ++module)
m_pNewModuleCombo->AddItem(g_PresetMan.GetDataModule(module)->GetFileName());
// Select the first one
m_pNewModuleCombo->SetSelectedIndex(0);
}
// Get the ID of the module currently selected so we can limit the following boxes to only show stuff in that module
int selectedModuleID = -1;
GUIListPanel::Item *pItem = m_pNewModuleCombo->GetItem(m_pNewModuleCombo->GetSelectedIndex());
if (pItem && !pItem->m_Name.empty())
selectedModuleID = g_PresetMan.GetModuleID(pItem->m_Name);
// Refill Terrains
m_pNewTerrainCombo->ClearList();
// Get the list of all read in terrains
list<Entity *> terrainList;
g_PresetMan.GetAllOfTypeInModuleSpace(terrainList, "SLTerrain", selectedModuleID);
// Go through the list and add their names to the combo box
for (list<Entity *>::iterator itr = terrainList.begin(); itr != terrainList.end(); ++itr)
m_pNewTerrainCombo->AddItem((*itr)->GetPresetName());
// Select the first one
m_pNewTerrainCombo->SetSelectedIndex(0);
// Refill backdrops
m_pNewBG1Combo->SetText("");
m_pNewBG2Combo->SetText("");
m_pNewBG3Combo->SetText("");
m_pNewBG1Combo->ClearList();
m_pNewBG2Combo->ClearList();
m_pNewBG3Combo->ClearList();
// Get the list of all read in terrains
list<Entity *> bgList;
g_PresetMan.GetAllOfTypeInModuleSpace(bgList, "SceneLayer", selectedModuleID);
// Go through the list and add their names to the combo box
for (list<Entity *>::iterator itr = bgList.begin(); itr != bgList.end(); ++itr)
{
m_pNewBG1Combo->AddItem((*itr)->GetPresetName());
m_pNewBG2Combo->AddItem((*itr)->GetPresetName());
m_pNewBG3Combo->AddItem((*itr)->GetPresetName());
}
// Select the first one
m_pNewBG1Combo->SetSelectedIndex(0);
m_pNewBG2Combo->SetSelectedIndex(0);
m_pNewBG3Combo->SetSelectedIndex(0);
*/
}
void GibEditor::UpdateLoadDialog() {
if (m_pObjectToLoad)
dynamic_cast<GUILabel*>(m_pGUIController->GetControl("LoadNameLabel"))->SetText("Load object named " + m_pObjectToLoad->GetPresetName() + "?");
}
void GibEditor::UpdateSaveDialog() {
if (!m_pEditedObject)
return;
m_pSaveNameBox->SetText((m_pEditedObject->GetPresetName() == "None" || !m_HasEverBeenSaved) ? "New Object" : m_pEditedObject->GetPresetName());
// TODO: Really?
m_pSaveModuleLabel->SetText("Will save in " + g_PresetMan.GetDataModule(m_ModuleSpaceID)->GetFileName() + "/NewData/");
}
void GibEditor::UpdateChangesDialog() {
if (!m_pEditedObject)
return;
if (m_HasEverBeenSaved) {
dynamic_cast<GUILabel*>(m_pGUIController->GetControl("ChangesExpLabel"))->SetText("Do you want to save your changes to:");
m_pChangesNameLabel->SetText(g_PresetMan.GetDataModule(m_ModuleSpaceID)->GetFileName() + "/NewData/" + m_pEditedObject->GetPresetName() + ".ini");
} else {
dynamic_cast<GUILabel*>(m_pGUIController->GetControl("ChangesExpLabel"))->SetText("Save your new Object first?");
m_pChangesNameLabel->SetText("");
}
}
void GibEditor::UpdateOverwriteDialog() {
if (m_pEditedObject)
m_pOverwriteNameLabel->SetText(g_PresetMan.GetDataModule(m_ModuleSpaceID)->GetFileName() + "/NewData/" + m_pEditedObject->GetPresetName() + ".ini");
}
void GibEditor::ClearTestArea() const {
clear_bitmap(g_SceneMan.GetTerrain()->GetFGColorBitmap());
clear_bitmap(g_SceneMan.GetTerrain()->GetBGColorBitmap());
clear_bitmap(g_SceneMan.GetTerrain()->GetMaterialBitmap());
}