-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathSceneEditorGUI.cpp
More file actions
1456 lines (1271 loc) · 56 KB
/
SceneEditorGUI.cpp
File metadata and controls
1456 lines (1271 loc) · 56 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
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "SceneEditorGUI.h"
#include "CameraMan.h"
#include "FrameMan.h"
#include "PresetMan.h"
#include "ActivityMan.h"
#include "GameActivity.h"
#include "SceneEditor.h"
#include "UInputMan.h"
#include "Controller.h"
#include "SceneObject.h"
#include "MOSprite.h"
#include "HeldDevice.h"
#include "HDFirearm.h"
#include "TDExplosive.h"
#include "TerrainObject.h"
#include "AHuman.h"
#include "ACrab.h"
#include "SLTerrain.h"
#include "ObjectPickerGUI.h"
#include "Scene.h"
#include "SettingsMan.h"
#include "Deployment.h"
#include "BunkerAssemblyScheme.h"
#include "GLResourceMan.h"
#include <array>
#include <string>
using namespace RTE;
#define MAXBRAINPATHCOST 10000
#define BLUEPRINTREVEALRATE 150
#define BLUEPRINTREVEALPAUSE 1500
BITMAP* SceneEditorGUI::s_pValidPathDot = 0;
BITMAP* SceneEditorGUI::s_pInvalidPathDot = 0;
SceneEditorGUI::SceneEditorGUI() {
Clear();
}
SceneEditorGUI::~SceneEditorGUI() {
Destroy();
}
void SceneEditorGUI::Clear() {
m_pController = 0;
m_FeatureSet = INGAMEEDIT;
m_EditMade = false;
m_EditorGUIMode = PICKINGOBJECT;
m_PreviousMode = ADDINGOBJECT;
m_ModeChanged = true;
m_BlinkTimer.Reset();
m_BlinkMode = NOBLINK;
m_RepeatStartTimer.Reset();
m_RepeatTimer.Reset();
m_RevealTimer.Reset();
m_RevealIndex = 0;
m_PieMenu = nullptr;
m_pPicker = 0;
m_NativeTechModule = 0;
m_ForeignCostMult = 4.0;
m_GridSnapping = true;
m_CursorPos.Reset();
m_CursorOffset.Reset();
m_CursorInAir = true;
m_FacingLeft = false;
m_PlaceTeam = Activity::TeamOne;
m_pCurrentObject = 0;
m_ObjectListOrder = -1;
m_DrawCurrentObject = true;
m_pObjectToBlink = 0;
m_BrainSkyPath.clear();
m_BrainSkyPathCost = 0;
m_RequireClearPathToOrbit = false;
m_PathRequest.reset();
}
int SceneEditorGUI::Create(Controller* pController, FeatureSets featureSet, int whichModuleSpace, int nativeTechModule, float foreignCostMult) {
RTEAssert(pController, "No controller sent to SceneEditorGUI on creation!");
m_pController = pController;
SetFeatureSet(featureSet);
// Update the brain path
UpdateBrainPath();
// Allocate and (re)create the Editor GUIs
if (!m_pPicker)
m_pPicker = new ObjectPickerGUI();
else
m_pPicker->Reset();
m_pPicker->Create(pController, whichModuleSpace);
m_NativeTechModule = nativeTechModule;
m_ForeignCostMult = foreignCostMult;
// Also apply these to the picker
m_pPicker->SetNativeTechModule(m_NativeTechModule);
m_pPicker->SetForeignCostMultiplier(m_ForeignCostMult);
// Cursor init
m_CursorPos = g_SceneMan.GetSceneDim() / 2;
// Set initial focus, category std::list, and label settings
m_EditorGUIMode = PICKINGOBJECT;
m_ModeChanged = true;
m_pCurrentObject = 0;
// Reset repeat timers
m_RepeatStartTimer.Reset();
m_RepeatTimer.Reset();
m_RevealTimer.Reset();
m_RevealTimer.SetRealTimeLimitMS(100);
// Check if we need to check for a clear path to orbit
m_RequireClearPathToOrbit = false;
GameActivity* gameActivity = dynamic_cast<GameActivity*>(g_ActivityMan.GetActivity());
if (gameActivity) {
m_RequireClearPathToOrbit = gameActivity->GetRequireClearPathToOrbit();
}
// Always disable clear path requirement in scene editor
SceneEditor* editorActivity = dynamic_cast<SceneEditor*>(g_ActivityMan.GetActivity());
if (editorActivity) {
m_RequireClearPathToOrbit = false;
}
// Only load the static dot bitmaps once
if (!s_pValidPathDot) {
ContentFile dotFile("Base.rte/GUIs/Indicators/PathDotValid.png");
s_pValidPathDot = dotFile.GetAsBitmap();
dotFile.SetDataPath("Base.rte/GUIs/Indicators/PathDotInvalid.png");
s_pInvalidPathDot = dotFile.GetAsBitmap();
}
return 0;
}
void SceneEditorGUI::Destroy() {
delete m_pPicker;
delete m_pCurrentObject;
Clear();
}
void SceneEditorGUI::SetController(Controller* pController) {
m_pController = pController;
m_PieMenu->SetMenuController(pController);
m_pPicker->SetController(pController);
}
void SceneEditorGUI::SetFeatureSet(SceneEditorGUI::FeatureSets newFeatureSet) {
m_FeatureSet = newFeatureSet;
if (m_PieMenu) {
m_PieMenu = nullptr;
}
std::string pieMenuName;
switch (m_FeatureSet) {
case FeatureSets::ONLOADEDIT:
pieMenuName = "Scene Editor Full Pie Menu";
break;
case FeatureSets::BLUEPRINTEDIT:
pieMenuName = "Scene Editor Blueprint Pie Menu";
break;
case FeatureSets::AIPLANEDIT:
pieMenuName = "Scene Editor AI Build Plan Pie Menu";
break;
case FeatureSets::INGAMEEDIT:
pieMenuName = "Scene Editor In-Game Pie Menu";
break;
default:
RTEAbort("Unhandled SceneEditorGUI FeatureSet when setting up PieMenu.");
}
m_PieMenu = std::unique_ptr<PieMenu>(dynamic_cast<PieMenu*>(g_PresetMan.GetEntityPreset("PieMenu", pieMenuName)->Clone()));
// m_PieMenu->Create();
m_PieMenu->SetMenuController(m_pController);
}
void SceneEditorGUI::SetPosOnScreen(int newPosX, int newPosY) {
m_pPicker->SetPosOnScreen(newPosX, newPosY);
}
bool SceneEditorGUI::SetCurrentObject(SceneObject* pNewObject) {
if (m_pCurrentObject == pNewObject)
return true;
// Replace the current object with the new one
delete m_pCurrentObject;
m_pCurrentObject = pNewObject;
if (!m_pCurrentObject)
return false;
m_pCurrentObject->SetTeam(m_FeatureSet == ONLOADEDIT ? m_PlaceTeam : m_pController->GetTeam());
m_pCurrentObject->SetPlacedByPlayer(m_pController->GetPlayer());
// Disable any controller, if an actor
if (Actor* pActor = dynamic_cast<Actor*>(m_pCurrentObject)) {
pActor->GetController()->SetDisabled(true);
pActor->SetStatus(Actor::INACTIVE);
}
return true;
}
PieSliceType SceneEditorGUI::GetActivatedPieSlice() const {
return m_PieMenu->GetPieCommand();
}
void SceneEditorGUI::SetModuleSpace(int moduleSpaceID) {
m_pPicker->SetModuleSpace(moduleSpaceID);
}
void SceneEditorGUI::SetNativeTechModule(int whichModule) {
if (whichModule >= 0 && whichModule < g_PresetMan.GetTotalModuleCount()) {
m_NativeTechModule = whichModule;
m_pPicker->SetNativeTechModule(m_NativeTechModule);
}
}
void SceneEditorGUI::SetForeignCostMultiplier(float newMultiplier) {
m_ForeignCostMult = newMultiplier;
m_pPicker->SetForeignCostMultiplier(m_ForeignCostMult);
}
bool SceneEditorGUI::TestBrainResidence(bool noBrainIsOK) {
// Do we have a resident at all?
SceneObject* pBrain = g_SceneMan.GetScene()->GetResidentBrain(m_pController->GetPlayer());
// If not, can we find an unassigned brain and make it the resident?
if (!pBrain) {
pBrain = g_MovableMan.GetUnassignedBrain(g_ActivityMan.GetActivity()->GetTeamOfPlayer(m_pController->GetPlayer()));
// Found one, so make it the resident brain (passing ownership) and remove it from the sim
if (pBrain) {
g_SceneMan.GetScene()->SetResidentBrain(m_pController->GetPlayer(), pBrain);
g_MovableMan.RemoveMO(dynamic_cast<MovableObject*>(pBrain));
}
}
// We do we have a resident brain now, so let's check that it's in a legit spot
if (pBrain) {
// Got to update the pathfinding graphs so the latest terrain is used for the below tests
g_SceneMan.GetScene()->UpdatePathFinding();
UpdateBrainSkyPathAndCost(pBrain->GetPos());
} else {
// No brain found, so we better place one
if (!noBrainIsOK) {
m_EditorGUIMode = INSTALLINGBRAIN;
m_ModeChanged = true;
UpdateBrainPath();
g_GUISound.UserErrorSound()->Play(m_pController->GetPlayer());
}
return false;
}
// Block on our path request completing
while (m_PathRequest && !m_PathRequest->complete) {};
// Nope! Not valid spot for this brain we found, need to force user to re-place it
if (m_BrainSkyPathCost > MAXBRAINPATHCOST && m_RequireClearPathToOrbit) {
// Jump to where the bad brain is
m_CursorPos = pBrain->GetPos();
// Put the resident clone as the current object we need to place
SetCurrentObject(dynamic_cast<SceneObject*>(pBrain->Clone()));
// Get rid of the resident - it can't be helped there
g_SceneMan.GetScene()->SetResidentBrain(m_pController->GetPlayer(), 0);
// Switch to brain placement mode
m_EditorGUIMode = INSTALLINGBRAIN;
m_ModeChanged = true;
UpdateBrainPath();
g_GUISound.UserErrorSound()->Play(m_pController->GetPlayer());
return false;
}
// Brain is fine, leave it be
return true;
}
void SceneEditorGUI::Update() {
// Update the user controller
// m_pController->Update();
m_EditMade = false;
m_pObjectToBlink = 0;
// Which set of placed objects in the scene we're editing
int editedSet = m_FeatureSet == ONLOADEDIT ? Scene::PLACEONLOAD : (m_FeatureSet == AIPLANEDIT ? Scene::AIPLAN : Scene::BLUEPRINT);
////////////////////////////////////////////
// Blinking logic
/*
if (m_BlinkMode == OBJECTBLINK)
{
m_pCostLabel->SetVisible(m_BlinkTimer.AlternateSim(250));
}
else if (m_BlinkMode == NOCRAFT)
{
bool blink = m_BlinkTimer.AlternateSim(250);
m_pCraftLabel->SetVisible(blink);
m_pCraftBox->SetVisible(blink);
}
// Time out the blinker
if (m_BlinkMode != NOBLINK && m_BlinkTimer.IsPastSimMS(1500))
{
m_pCostLabel->SetVisible(true);
m_pCraftLabel->SetVisible(true);
m_pCraftBox->SetVisible(true);
m_BlinkMode = NOBLINK;
}
*/
if (m_pCurrentObject && m_EditorGUIMode != PICKINGOBJECT && g_PresetMan.GetReloadEntityPresetCalledThisUpdate()) {
m_pCurrentObject = dynamic_cast<SceneObject*>(g_PresetMan.GetEntityPreset(m_pCurrentObject->GetClassName(), m_pCurrentObject->GetPresetName(), m_pCurrentObject->GetModuleName())->Clone());
}
/////////////////////////////////////////////
// Repeating input logic
bool pressLeft = m_pController->IsState(PRESS_LEFT);
bool pressRight = m_pController->IsState(PRESS_RIGHT);
bool pressUp = m_pController->IsState(PRESS_UP);
bool pressDown = m_pController->IsState(PRESS_DOWN);
// If no direciton is held down, then cancel the repeating
if (!(m_pController->IsState(MOVE_RIGHT) || m_pController->IsState(MOVE_LEFT) || m_pController->IsState(MOVE_UP) || m_pController->IsState(MOVE_DOWN))) {
m_RepeatStartTimer.Reset();
m_RepeatTimer.Reset();
}
// Check if any direction has been held for the starting amount of time to get into repeat mode
if (m_RepeatStartTimer.IsPastRealMS(200)) {
// Check for the repeat interval
if (m_RepeatTimer.IsPastRealMS(30)) {
if (m_pController->IsState(MOVE_RIGHT))
pressRight = true;
else if (m_pController->IsState(MOVE_LEFT))
pressLeft = true;
if (m_pController->IsState(MOVE_UP))
pressUp = true;
else if (m_pController->IsState(MOVE_DOWN))
pressDown = true;
m_RepeatTimer.Reset();
}
}
///////////////////////////////////////////////
// Analog cursor input
Vector analogInput;
if (m_pController->GetAnalogMove().MagnitudeIsGreaterThan(0.1F))
analogInput = m_pController->GetAnalogMove();
// else if (m_pController->GetAnalogAim().MagnitudeIsGreaterThan(0.1F))
// analogInput = m_pController->GetAnalogAim();
/////////////////////////////////////////////
// PIE MENU
m_PieMenu->Update();
// Show the pie menu only when the secondary button is held down
if (m_pController->IsState(PIE_MENU_ACTIVE) && m_EditorGUIMode != INACTIVE && m_EditorGUIMode != PICKINGOBJECT) {
m_PieMenu->SetEnabled(true);
m_PieMenu->SetPos(m_GridSnapping ? g_SceneMan.SnapPosition(m_CursorPos) : m_CursorPos);
std::array<PieSlice*, 2> infrontAndBehindPieSlices = {m_PieMenu->GetFirstPieSliceByType(PieSliceType::EditorInFront), m_PieMenu->GetFirstPieSliceByType(PieSliceType::EditorBehind)};
for (PieSlice* pieSlice: infrontAndBehindPieSlices) {
if (pieSlice) {
pieSlice->SetEnabled(m_EditorGUIMode == ADDINGOBJECT);
}
}
} else {
m_PieMenu->SetEnabled(false);
}
///////////////////////////////////////
// Handle pie menu selections
if (m_PieMenu->GetPieCommand() != PieSliceType::NoType) {
if (m_PieMenu->GetPieCommand() == PieSliceType::EditorPick) {
m_EditorGUIMode = PICKINGOBJECT;
} else if (m_PieMenu->GetPieCommand() == PieSliceType::EditorMove) {
m_EditorGUIMode = MOVINGOBJECT;
} else if (m_PieMenu->GetPieCommand() == PieSliceType::EditorRemove) {
m_EditorGUIMode = DELETINGOBJECT;
} else if (m_PieMenu->GetPieCommand() == PieSliceType::BrainHunt) {
m_EditorGUIMode = INSTALLINGBRAIN;
} else if (m_PieMenu->GetPieCommand() == PieSliceType::EditorDone) {
m_EditorGUIMode = DONEEDITING;
} else if (m_PieMenu->GetPieCommand() == PieSliceType::EditorInFront) {
m_PreviousMode = m_EditorGUIMode;
m_EditorGUIMode = PLACEINFRONT;
} else if (m_PieMenu->GetPieCommand() == PieSliceType::EditorBehind) {
m_PreviousMode = m_EditorGUIMode;
m_EditorGUIMode = PLACEBEHIND;
} else if (m_PieMenu->GetPieCommand() == PieSliceType::EditorTeam1) {
m_PlaceTeam = Activity::TeamOne;
} else if (m_PieMenu->GetPieCommand() == PieSliceType::EditorTeam2) {
m_PlaceTeam = Activity::TeamTwo;
} else if (m_PieMenu->GetPieCommand() == PieSliceType::EditorTeam3) {
m_PlaceTeam = Activity::TeamThree;
} else if (m_PieMenu->GetPieCommand() == PieSliceType::EditorTeam4) {
m_PlaceTeam = Activity::TeamFour;
// Toggle between normal scene object editing, and AI plan editing
} else if (m_PieMenu->GetPieCommand() == PieSliceType::Map) {
SetFeatureSet(m_FeatureSet == FeatureSets::ONLOADEDIT ? FeatureSets::AIPLANEDIT : FeatureSets::ONLOADEDIT);
}
UpdateBrainPath();
m_ModeChanged = true;
}
//////////////////////////////////////////
// Picker logic
// Enable or disable the picker
m_pPicker->SetEnabled(m_EditorGUIMode == PICKINGOBJECT);
// Update the picker GUI
m_pPicker->Update();
if (m_EditorGUIMode == PICKINGOBJECT && m_pPicker->ObjectPicked()) {
// Assign a copy of the picked object to be the currently held one.
if (SetCurrentObject(dynamic_cast<SceneObject*>(m_pPicker->ObjectPicked()->Clone()))) {
// Set the team
if (m_FeatureSet != ONLOADEDIT)
m_pCurrentObject->SetTeam(m_pController->GetTeam());
// Set the std::list order to be at the end so new objects are added there
m_ObjectListOrder = -1;
// Update the object
m_pCurrentObject->FullUpdate();
// Update the path to the brain, or clear it if there's none
UpdateBrainPath();
// If done picking, revert to moving object mode
if (m_pPicker->DonePicking()) {
// If picked a Brain Actor, then enter install brain mode. Allow to use deployments in brain mode only while editing in-game
if (m_pCurrentObject->IsInGroup("Brains") && (m_FeatureSet == INGAMEEDIT || !dynamic_cast<Deployment*>(m_pCurrentObject)))
m_EditorGUIMode = INSTALLINGBRAIN;
else
m_EditorGUIMode = ADDINGOBJECT;
UpdateBrainPath();
m_ModeChanged = true;
}
}
}
if (!m_pPicker->IsVisible())
g_CameraMan.SetScreenOcclusion(Vector(), g_ActivityMan.GetActivity()->ScreenOfPlayer(m_pController->GetPlayer()));
else
g_FrameMan.SetScreenText("Pick what you want to place next", g_ActivityMan.GetActivity()->ScreenOfPlayer(m_pController->GetPlayer()));
/////////////////////////////////////
// ADDING OBJECT MODE
if (m_EditorGUIMode == ADDINGOBJECT && !m_PieMenu->IsEnabled()) {
if (m_ModeChanged) {
m_ModeChanged = false;
}
g_FrameMan.SetScreenText("Click to ADD a new object - Drag for precision", g_ActivityMan.GetActivity()->ScreenOfPlayer(m_pController->GetPlayer()));
m_DrawCurrentObject = true;
// Trap the mouse cursor
g_UInputMan.TrapMousePos(true, m_pController->GetPlayer());
// Move the cursor according to analog or mouse input
if (!analogInput.IsZero()) {
m_CursorPos += analogInput * 8;
// Re-enable snapping only when the cursor is moved again
m_GridSnapping = true;
} else if (!m_pController->GetMouseMovement().IsZero()) {
m_CursorPos += m_pController->GetMouseMovement();
// Re-enable snapping only when the cursor is moved again
m_GridSnapping = true;
}
// Digital input?
else {
if (pressUp)
m_CursorPos.m_Y -= SCENESNAPSIZE;
if (pressRight)
m_CursorPos.m_X += SCENESNAPSIZE;
if (pressDown)
m_CursorPos.m_Y += SCENESNAPSIZE;
if (pressLeft)
m_CursorPos.m_X -= SCENESNAPSIZE;
// Re-enable snapping only when the cursor is moved again
if (pressUp || pressRight || pressDown || pressLeft)
m_GridSnapping = true;
}
// Detect whether the cursor is in the air, or if it's overlapping some terrain
Vector snappedPos = g_SceneMan.SnapPosition(m_CursorPos, m_GridSnapping);
m_CursorInAir = g_SceneMan.GetTerrMatter(snappedPos.GetFloorIntX(), snappedPos.GetFloorIntY()) == g_MaterialAir;
// Mousewheel is used as shortcut for getting next and prev items in teh picker's object std::list
if (m_pController->IsState(SCROLL_UP) || m_pController->IsState(ControlState::ACTOR_NEXT)) {
// Assign a copy of the next picked object to be the currently held one.
const SceneObject* pNewObject = m_pPicker->GetPrevObject();
if (pNewObject) {
// Set and update the cursor object
if (SetCurrentObject(dynamic_cast<SceneObject*>(pNewObject->Clone())))
m_pCurrentObject->FullUpdate();
}
} else if (m_pController->IsState(SCROLL_DOWN) || m_pController->IsState(ControlState::ACTOR_PREV)) {
// Assign a copy of the next picked object to be the currently held one.
const SceneObject* pNewObject = m_pPicker->GetNextObject();
if (pNewObject) {
// Set and update the object
if (SetCurrentObject(dynamic_cast<SceneObject*>(pNewObject->Clone())))
m_pCurrentObject->FullUpdate();
}
}
// Start the timer when the button is first pressed, and when the picker has deactivated
if (m_pController->IsState(PRESS_PRIMARY) && !m_pPicker->IsVisible()) {
m_BlinkTimer.Reset();
m_EditorGUIMode = PLACINGOBJECT;
m_PreviousMode = ADDINGOBJECT;
m_ModeChanged = true;
g_GUISound.PlacementBlip()->Play(m_pController->GetPlayer());
}
// Apply the team to the current actor, if applicable
if (m_DrawCurrentObject) {
// Set the team of SceneObject based on what's been selected
// Only if full featured mode, otherwise it's based on the controller when placed
if (m_FeatureSet == ONLOADEDIT)
m_pCurrentObject->SetTeam(m_PlaceTeam);
}
}
/////////////////////////////////////
// INSTALLING BRAIN MODE
if (m_EditorGUIMode == INSTALLINGBRAIN && !m_PieMenu->IsEnabled()) {
if (m_ModeChanged) {
// Check if we already have a resident brain to replace/re-place
SceneObject* pBrain = g_SceneMan.GetScene()->GetResidentBrain(m_pController->GetPlayer());
if (pBrain) {
// Fly over to where the brain was previously found
SetCursorPos(pBrain->GetPos());
// If the brain in hand is not appropriate replacement, then just use the resident brain as a copy to re-place it
if (!m_pCurrentObject->IsInGroup("Brains")) {
// Make sure the player's resident brain is the one being held in cursor
SetCurrentObject(dynamic_cast<SceneObject*>(pBrain->Clone()));
// Clear the brain of the scene; it will be reinstated when we place it again
// NOPE, keep it here in case placing the brain goes awry - it won't be drawn anyway
// g_SceneMan.GetScene()->SetResidentBrain(m_pController->GetPlayer(), 0);
}
}
// Ok, so no resident brain - do we have one in hand already??
else if (m_pCurrentObject && m_pCurrentObject->IsInGroup("Brains")) {
// Continue with placing it as per usual
;
}
// Pick a brain to install if no one existed already in scene or in hand
else {
m_pPicker->SelectGroupByName("Brains");
m_EditorGUIMode = PICKINGOBJECT;
m_ModeChanged = true;
UpdateBrainPath();
}
m_ModeChanged = false;
}
g_FrameMan.SetScreenText("Click to INSTALL your governor brain with a clear path to orbit - Drag for precision", g_ActivityMan.GetActivity()->ScreenOfPlayer(m_pController->GetPlayer()));
m_DrawCurrentObject = true;
// Trap the mouse cursor
g_UInputMan.TrapMousePos(true, m_pController->GetPlayer());
// Move the cursor according to analog or mouse input
if (!analogInput.IsZero()) {
m_CursorPos += analogInput * 8;
// Re-enable snapping only when the cursor is moved again
m_GridSnapping = true;
} else if (!m_pController->GetMouseMovement().IsZero()) {
m_CursorPos += m_pController->GetMouseMovement();
// Re-enable snapping only when the cursor is moved again
m_GridSnapping = true;
}
// Digital input?
else {
if (pressUp)
m_CursorPos.m_Y -= SCENESNAPSIZE;
if (pressRight)
m_CursorPos.m_X += SCENESNAPSIZE;
if (pressDown)
m_CursorPos.m_Y += SCENESNAPSIZE;
if (pressLeft)
m_CursorPos.m_X -= SCENESNAPSIZE;
// Re-enable snapping only when the cursor is moved again
if (pressUp || pressRight || pressDown || pressLeft)
m_GridSnapping = true;
}
// Detect whether the cursor is in the air, or if it's overlapping some terrain
Vector snappedPos = g_SceneMan.SnapPosition(m_CursorPos, m_GridSnapping);
m_CursorInAir = g_SceneMan.GetTerrMatter(snappedPos.GetFloorIntX(), snappedPos.GetFloorIntY()) == g_MaterialAir;
// Check brain position validity with pathfinding and show a path to the sky
UpdateBrainSkyPathAndCost(m_CursorPos);
/*
// Process the new path we now have, if any
if (!m_BrainSkyPath.empty())
{
// Smash all airborne waypoints down to just above the ground, except for when it makes the path intersect terrain or it is the final destination
std::list<Vector>::iterator finalItr = m_BrainSkyPath.end();
finalItr--;
Vector smashedPoint;
Vector previousPoint = *(m_BrainSkyPath.begin());
std::list<Vector>::iterator nextItr = m_BrainSkyPath.begin();
for (std::list<Vector>::iterator lItr = m_BrainSkyPath.begin(); lItr != finalItr; ++lItr)
{
nextItr++;
smashedPoint = g_SceneMan.MovePointToGround((*lItr), 20, 10);
Vector notUsed;
// Only smash if the new location doesn't cause the path to intersect hard terrain ahead or behind of it
// Try three times to halve the height to see if that won't intersect
for (int i = 0; i < 3; i++)
{
if (!g_SceneMan.CastStrengthRay(previousPoint, smashedPoint - previousPoint, 5, notUsed, 3, g_MaterialDoor) &&
nextItr != m_BrainSkyPath.end() && !g_SceneMan.CastStrengthRay(smashedPoint, (*nextItr) - smashedPoint, 5, notUsed, 3, g_MaterialDoor))
{
(*lItr) = smashedPoint;
break;
}
else
smashedPoint.m_Y -= ((smashedPoint.m_Y - (*lItr).m_Y) / 2);
}
previousPoint = (*lItr);
}
}
*/
// Start the timer when the button is first pressed, and when the picker has deactivated
if (m_pController->IsState(PRESS_PRIMARY) && !m_pPicker->IsVisible()) {
m_BlinkTimer.Reset();
m_EditorGUIMode = PLACINGOBJECT;
m_PreviousMode = INSTALLINGBRAIN;
m_ModeChanged = true;
g_GUISound.PlacementBlip()->Play(m_pController->GetPlayer());
}
// Apply the team to the current actor, if applicable
if (m_pCurrentObject && m_DrawCurrentObject) {
// Set the team of SceneObject based on what's been selected
// Only if full featured mode, otherwise it's based on the controller when placed
if (m_FeatureSet == ONLOADEDIT)
m_pCurrentObject->SetTeam(m_PlaceTeam);
}
}
/////////////////////////////////////////////////////////////
// PLACING MODE
else if (m_EditorGUIMode == PLACINGOBJECT) {
if (m_ModeChanged) {
m_ModeChanged = false;
}
if (m_PreviousMode == MOVINGOBJECT)
g_FrameMan.SetScreenText("Click and drag on a placed object to MOVE it - Click quickly to DETACH", g_ActivityMan.GetActivity()->ScreenOfPlayer(m_pController->GetPlayer()));
else if (m_PreviousMode == INSTALLINGBRAIN)
g_FrameMan.SetScreenText("Release to INSTALL the governor brain - Tap other button to cancel", g_ActivityMan.GetActivity()->ScreenOfPlayer(m_pController->GetPlayer()));
else
g_FrameMan.SetScreenText("Release to ADD the new object - Tap other button to cancel", g_ActivityMan.GetActivity()->ScreenOfPlayer(m_pController->GetPlayer()));
// Check brain position validity with pathfinding and show a path to the sky
if (m_PreviousMode == INSTALLINGBRAIN) {
UpdateBrainSkyPathAndCost(m_CursorPos);
}
m_DrawCurrentObject = true;
// Freeze when first pressing down and grid snapping is still engaged
if (!(m_pController->IsState(PRIMARY_ACTION) && m_GridSnapping)) {
if (!analogInput.IsZero()) {
m_CursorPos += analogInput;
m_FacingLeft = analogInput.m_X < 0 || (m_FacingLeft && analogInput.m_X == 0);
}
// Try the mouse
else if (!m_pController->GetMouseMovement().IsZero()) {
m_CursorPos += m_pController->GetMouseMovement();
m_FacingLeft = m_pController->GetMouseMovement().m_X < 0 || (m_FacingLeft && m_pController->GetMouseMovement().m_X == 0);
}
// Digital input?
else {
if (pressUp)
m_CursorPos.m_Y -= 1;
if (pressRight) {
m_CursorPos.m_X += 1;
m_FacingLeft = false;
}
if (pressDown)
m_CursorPos.m_Y += 1;
if (pressLeft) {
m_CursorPos.m_X -= 1;
m_FacingLeft = true;
}
}
// Detect whether the cursor is in the air, or if it's overlapping some terrain
Vector snappedPos = g_SceneMan.SnapPosition(m_CursorPos, m_GridSnapping);
m_CursorInAir = g_SceneMan.GetTerrMatter(snappedPos.GetFloorIntX(), snappedPos.GetFloorIntY()) == g_MaterialAir;
// Also check that it isn't over unseen areas, can't place there
m_CursorInAir = m_CursorInAir && !g_SceneMan.IsUnseen(snappedPos.GetFloorIntX(), snappedPos.GetFloorIntY(), m_pController->GetTeam());
}
// Constrain the cursor to only be within specific scene areas
// TODO: THIS!!!
// Disable snapping after a small interval of holding down the button, to avoid unintentional nudges when just placing on the grid
if (m_pController->IsState(PRIMARY_ACTION) && m_BlinkTimer.IsPastRealMS(333) && m_GridSnapping) {
m_GridSnapping = false;
m_CursorPos = g_SceneMan.SnapPosition(m_CursorPos);
}
// Cancel placing if secondary button is pressed
if (m_pController->IsState(PRESS_SECONDARY) || m_pController->IsState(PIE_MENU_ACTIVE)) {
m_EditorGUIMode = m_PreviousMode;
m_ModeChanged = true;
}
// If previous mode was moving, tear the gib loose if the button is released to soo
else if (m_PreviousMode == MOVINGOBJECT && m_pController->IsState(RELEASE_PRIMARY) && !m_BlinkTimer.IsPastRealMS(150)) {
m_EditorGUIMode = ADDINGOBJECT;
m_ModeChanged = true;
}
// Only place if the picker and pie menus are completely out of view, to avoid immediate placing after picking
else if (m_pCurrentObject && m_pController->IsState(RELEASE_PRIMARY) && !m_pPicker->IsVisible()) {
m_pCurrentObject->FullUpdate();
// Placing governor brain, which actually just puts it back into the resident brain roster
if (m_PreviousMode == INSTALLINGBRAIN) {
// Force our path request to complete so we know whether we can place or not
while (m_PathRequest && !m_PathRequest->complete) {};
// Only place if the brain has a clear path to the sky!
if (m_BrainSkyPathCost <= MAXBRAINPATHCOST || !m_RequireClearPathToOrbit) {
bool placeBrain = true;
// Brain deployment's are translated into the appropriate loadout and put in place in the scene
// but only while editing ingame
Deployment* pDep = dynamic_cast<Deployment*>(m_pCurrentObject);
if (pDep) {
if (m_FeatureSet == INGAMEEDIT) {
float cost;
Actor* pActor = pDep->CreateDeployedActor(pDep->GetPlacedByPlayer(), cost);
if (pActor && pActor->IsInGroup("Brains")) {
delete m_pCurrentObject;
m_pCurrentObject = pActor;
} else {
placeBrain = false;
}
} else {
placeBrain = false;
}
}
if (placeBrain) {
// Place and let go (passing ownership) of the new governor brain
g_SceneMan.GetScene()->SetResidentBrain(m_pController->GetPlayer(), m_pCurrentObject);
// NO! This deletes the brain we just passed ownership of! just let go, man
// SetCurrentObject(0);
m_pCurrentObject = 0;
// Nothing in cursor now, so force to pick somehting else to place right away
m_EditorGUIMode = PICKINGOBJECT;
m_ModeChanged = true;
// Try to switch away from brains so it's clear we placed it
if (!m_pPicker->SelectGroupByName("Weapons - Primary"))
m_pPicker->SelectGroupByName("Weapons");
// Also jolt the cursor off the newly placed brain to make it even clearer
m_CursorPos.m_X += 40;
m_CursorPos.m_Y += 10;
UpdateBrainPath();
g_GUISound.PlacementThud()->Play(m_pController->GetPlayer());
}
}
// If no clear path to the sky, just reject the placment and keep the brain in hand
else {
g_FrameMan.ClearScreenText(g_ActivityMan.GetActivity()->ScreenOfPlayer(m_pController->GetPlayer()));
g_FrameMan.SetScreenText("Your brain can only be placed with a clear access path to orbit!", g_ActivityMan.GetActivity()->ScreenOfPlayer(m_pController->GetPlayer()), 333, 3500);
g_GUISound.UserErrorSound()->Play(m_pController->GetPlayer());
}
}
// Non-brain thing is being placed
else {
// If we're not editing in-game, then just add to the placed objects std::list
if (m_FeatureSet != INGAMEEDIT) {
// If true we need to place object in the end, if false, then it was already given to an actor
bool toPlace = true;
// If we're placing an item then give that item to actor instead of dropping it nearby
HeldDevice* pHeldDevice = dynamic_cast<HeldDevice*>(m_pCurrentObject);
if (pHeldDevice)
if (dynamic_cast<HDFirearm*>(pHeldDevice) || dynamic_cast<TDExplosive*>(pHeldDevice)) {
int objectListPosition = -1;
// Find out if we have AHuman under the cursor
const SceneObject* pPickedSceneObject = g_SceneMan.GetScene()->PickPlacedObject(editedSet, m_CursorPos, &objectListPosition);
const Actor* pAHuman = 0;
// Looks like we got nothing, search for actors in range then
if (!pPickedSceneObject)
pPickedSceneObject = g_SceneMan.GetScene()->PickPlacedActorInRange(editedSet, m_CursorPos, 20, &objectListPosition);
if (pPickedSceneObject) {
pAHuman = dynamic_cast<const AHuman*>(pPickedSceneObject);
if (!pAHuman) {
// Maybe we clicked the underlying bunker module, search for actor in range
pPickedSceneObject = g_SceneMan.GetScene()->PickPlacedActorInRange(editedSet, m_CursorPos, 20, &objectListPosition);
if (pPickedSceneObject)
pAHuman = dynamic_cast<const AHuman*>(pPickedSceneObject);
}
if (pAHuman) {
// Create a new AHuman instead of old one, give him an item, and delete old AHuman
SceneObject* pNewObject = dynamic_cast<SceneObject*>(pPickedSceneObject->Clone());
g_SceneMan.GetScene()->RemovePlacedObject(editedSet, objectListPosition);
AHuman* pAHuman = dynamic_cast<AHuman*>(pNewObject);
if (pAHuman) {
pAHuman->AddInventoryItem(dynamic_cast<MovableObject*>(m_pCurrentObject->Clone()));
pAHuman->FlashWhite(150);
}
g_SceneMan.GetScene()->AddPlacedObject(editedSet, pNewObject, objectListPosition);
m_EditMade = true;
g_GUISound.PlacementThud()->Play(m_pController->GetPlayer());
toPlace = false;
}
} else {
// No human? Look for brains robots then
SceneObject* pBrain = g_SceneMan.GetScene()->GetResidentBrain(m_pController->GetPlayer());
if (pBrain) {
if (g_SceneMan.ShortestDistance(pBrain->GetPos(), m_CursorPos, true).MagnitudeIsLessThan(20.0F)) {
AHuman* pBrainAHuman = dynamic_cast<AHuman*>(pBrain);
if (pBrainAHuman) {
pBrainAHuman->AddInventoryItem(dynamic_cast<MovableObject*>(m_pCurrentObject->Clone()));
pBrainAHuman->FlashWhite(150);
m_EditMade = true;
g_GUISound.PlacementThud()->Play(m_pController->GetPlayer());
toPlace = false;
}
}
}
}
}
if (toPlace) {
g_SceneMan.GetScene()->AddPlacedObject(editedSet, dynamic_cast<SceneObject*>(m_pCurrentObject->Clone()), m_ObjectListOrder);
// Increment the std::list order so we place over last placed item
if (m_ObjectListOrder >= 0)
m_ObjectListOrder++;
g_GUISound.PlacementThud()->Play(m_pController->GetPlayer());
m_EditMade = true;
}
}
// If in-game editing, then place into the sim
else {
// Check if team can afford the placed object and if so, deduct the cost
if (g_ActivityMan.GetActivity()->GetTeamFunds(m_pController->GetTeam()) < m_pCurrentObject->GetTotalValue(m_NativeTechModule, m_ForeignCostMult)) {
g_FrameMan.ClearScreenText(g_ActivityMan.GetActivity()->ScreenOfPlayer(m_pController->GetPlayer()));
g_FrameMan.SetScreenText("You can't afford to place that!", g_ActivityMan.GetActivity()->ScreenOfPlayer(m_pController->GetPlayer()), 333, 1500);
g_GUISound.UserErrorSound()->Play(m_pController->GetPlayer());
} else {
// TODO: Experimental! clean up this messiness
SceneObject* pPlacedClone = dynamic_cast<SceneObject*>(m_pCurrentObject->Clone());
pPlacedClone->SetTeam(m_pController->GetTeam());
TerrainObject* pTO = dynamic_cast<TerrainObject*>(pPlacedClone);
if (pTO) {
// Deduct the cost from team funds
g_ActivityMan.GetActivity()->ChangeTeamFunds(-m_pCurrentObject->GetTotalValue(m_NativeTechModule, m_ForeignCostMult), m_pController->GetTeam());
pTO->PlaceOnTerrain(g_SceneMan.GetTerrain());
g_SceneMan.GetTerrain()->CleanAir();
Vector terrainObjectPos = pTO->GetPos() + pTO->GetBitmapOffset();
if (pTO->HasBGColorBitmap()) {
g_SceneMan.RegisterTerrainChange(terrainObjectPos.GetFloorIntX(), terrainObjectPos.GetFloorIntY(), pTO->GetBitmapWidth(), pTO->GetBitmapHeight(), ColorKeys::g_MaskColor, true);
}
if (pTO->HasFGColorBitmap()) {
g_SceneMan.RegisterTerrainChange(terrainObjectPos.GetFloorIntX(), terrainObjectPos.GetFloorIntY(), pTO->GetBitmapWidth(), pTO->GetBitmapHeight(), ColorKeys::g_MaskColor, false);
}
// TODO: Make IsBrain function to see if one was placed
if (pTO->GetPresetName() == "Brain Vault") {
// Register the brain as this player's
// g_ActivityMan.GetActivity()->SetPlayerBrain(pBrain, m_pController->GetPlayer());
m_EditorGUIMode = PICKINGOBJECT;
m_ModeChanged = true;
}
delete pPlacedClone;
pPlacedClone = 0;
g_GUISound.PlacementThud()->Play(m_pController->GetPlayer());
g_GUISound.PlacementGravel()->Play(m_pController->GetPlayer());
m_EditMade = true;
}
// Only place if the cursor is clear of terrain obstructions
else if (m_CursorInAir) {
float value = m_pCurrentObject->GetTotalValue(m_NativeTechModule, m_ForeignCostMult);
// Deployment:s are translated into the appropriate loadout and put in place in the scene
Deployment* pDep = dynamic_cast<Deployment*>(pPlacedClone);
if (pDep) {
// Ownership IS transferred here; pass it along into the MovableMan
float cost = 0;
Actor* pActor = pDep->CreateDeployedActor(pDep->GetPlacedByPlayer(), cost);
if (pActor) {
value = cost;
g_MovableMan.AddActor(pActor);
}
// Just a simple Device in the Deployment?
else {
value = cost;
// Get the Item/Device and add to scene, passing ownership
SceneObject* pObject = pDep->CreateDeployedObject(pDep->GetPlacedByPlayer(), cost);
MovableObject* pMO = dynamic_cast<MovableObject*>(pObject);
if (pMO)
g_MovableMan.AddMO(pMO);
else {
delete pObject;
pObject = 0;
}
}
delete pPlacedClone;
pPlacedClone = 0;
g_GUISound.PlacementThud()->Play(m_pController->GetPlayer());
g_GUISound.PlacementGravel()->Play(m_pController->GetPlayer());
m_EditMade = true;
}
// Deduct the cost from team funds
g_ActivityMan.GetActivity()->ChangeTeamFunds(-value, m_pController->GetTeam());
Actor* pActor = dynamic_cast<Actor*>(pPlacedClone);
HeldDevice* pDevice = 0;
if (pActor) {
g_MovableMan.AddActor(pActor);
m_EditMade = true;
} else if (pDevice = dynamic_cast<HeldDevice*>(pPlacedClone)) {
// If we have a friendly actor or brain nearby then give him an item instead of placing it
bool toPlace = true;
Vector distanceToActor;
Actor* pNearestActor = g_MovableMan.GetClosestTeamActor(m_pController->GetTeam(), m_pController->GetPlayer(), pPlacedClone->GetPos(), 20, distanceToActor);
// If we could not find an ordinary actor, then look for brain actor
if (!pNearestActor) {
// Find a brain and check if it's close enough
SceneObject* pBrain = g_SceneMan.GetScene()->GetResidentBrain(m_pController->GetPlayer());
if (pBrain) {
if (g_SceneMan.ShortestDistance(pBrain->GetPos(), pPlacedClone->GetPos(), true).MagnitudeIsLessThan(20.0F)) {
AHuman* pBrainAHuman = dynamic_cast<AHuman*>(pBrain);
if (pBrainAHuman) {
pNearestActor = pBrainAHuman;
}
}
}
}
// If we have any AHuman actor then give it an item
if (pNearestActor) {
AHuman* pNearestAHuman = dynamic_cast<AHuman*>(pNearestActor);
if (pNearestAHuman) {
pNearestAHuman->AddInventoryItem(pDevice);
// TODO: Resident brain remains white when flashed, don't know how to avoid that. Better than nothing though
pNearestAHuman->FlashWhite(150);
toPlace = false;
m_EditMade = true;
}
}
if (toPlace) {
g_MovableMan.AddItem(pDevice);
m_EditMade = true;
}
}
// Something else
else {
MovableObject* pObj = dynamic_cast<MovableObject*>(pPlacedClone);
if (pObj)
g_MovableMan.AddParticle(pObj);
m_EditMade = true;