1#ifndef GAME_EDITOR_EDITOR_ACTIONS_H
2#define GAME_EDITOR_EDITOR_ACTIONS_H
3
4#include "editor.h"
5#include "editor_action.h"
6
7class CEditorActionLayerBase : public IEditorAction
8{
9public:
10 CEditorActionLayerBase(CEditor *pEditor, int GroupIndex, int LayerIndex);
11
12 virtual void Undo() override {}
13 virtual void Redo() override {}
14
15protected:
16 int m_GroupIndex;
17 int m_LayerIndex;
18 std::shared_ptr<CLayer> m_pLayer;
19};
20
21class CEditorBrushDrawAction : public IEditorAction
22{
23public:
24 CEditorBrushDrawAction(CEditor *pEditor, int Group);
25
26 void Undo() override;
27 void Redo() override;
28 bool IsEmpty() override;
29
30private:
31 int m_Group;
32 // m_vTileChanges is a list of changes for each layer that was modified.
33 // The std::pair is used to pair one layer (index) with its history (2D map).
34 // EditorTileStateChangeHistory<T> is a 2D map, storing a change item at a specific y,x position.
35 std::vector<std::pair<int, EditorTileStateChangeHistory<STileStateChange>>> m_vTileChanges;
36 EditorTileStateChangeHistory<STeleTileStateChange> m_TeleTileChanges;
37 EditorTileStateChangeHistory<SSpeedupTileStateChange> m_SpeedupTileChanges;
38 EditorTileStateChangeHistory<SSwitchTileStateChange> m_SwitchTileChanges;
39 EditorTileStateChangeHistory<STuneTileStateChange> m_TuneTileChanges;
40
41 int m_TotalTilesDrawn;
42 int m_TotalLayers;
43
44 void Apply(bool Undo);
45 void SetInfos();
46};
47
48// ---------------------------------------------------------
49
50class CEditorActionQuadPlace : public CEditorActionLayerBase
51{
52public:
53 CEditorActionQuadPlace(CEditor *pEditor, int GroupIndex, int LayerIndex, std::vector<CQuad> &vBrush);
54
55 void Undo() override;
56 void Redo() override;
57
58private:
59 std::vector<CQuad> m_vBrush;
60};
61
62class CEditorActionSoundPlace : public CEditorActionLayerBase
63{
64public:
65 CEditorActionSoundPlace(CEditor *pEditor, int GroupIndex, int LayerIndex, std::vector<CSoundSource> &vBrush);
66
67 void Undo() override;
68 void Redo() override;
69
70private:
71 std::vector<CSoundSource> m_vBrush;
72};
73
74// -------------------------------------------------------------
75
76class CEditorActionDeleteQuad : public CEditorActionLayerBase
77{
78public:
79 CEditorActionDeleteQuad(CEditor *pEditor, int GroupIndex, int LayerIndex, std::vector<int> const &vQuadsIndices, std::vector<CQuad> const &vDeletedQuads);
80
81 void Undo() override;
82 void Redo() override;
83
84private:
85 std::vector<int> m_vQuadsIndices;
86 std::vector<CQuad> m_vDeletedQuads;
87};
88
89// -------------------------------------------------------------
90
91class CEditorActionEditQuadPoint : public CEditorActionLayerBase
92{
93public:
94 CEditorActionEditQuadPoint(CEditor *pEditor, int GroupIndex, int LayerIndex, int QuadIndex, std::vector<CPoint> const &vPreviousPoints, std::vector<CPoint> const &vCurrentPoints);
95
96 void Undo() override;
97 void Redo() override;
98
99private:
100 int m_QuadIndex;
101 std::vector<CPoint> m_vPreviousPoints;
102 std::vector<CPoint> m_vCurrentPoints;
103};
104
105class CEditorActionEditQuadProp : public CEditorActionLayerBase
106{
107public:
108 CEditorActionEditQuadProp(CEditor *pEditor, int GroupIndex, int LayerIndex, int QuadIndex, EQuadProp Prop, int Previous, int Current);
109
110 void Undo() override;
111 void Redo() override;
112
113private:
114 int m_QuadIndex;
115 EQuadProp m_Prop;
116 int m_Previous;
117 int m_Current;
118
119 void Apply(int Value);
120};
121
122class CEditorActionEditQuadPointProp : public CEditorActionLayerBase
123{
124public:
125 CEditorActionEditQuadPointProp(CEditor *pEditor, int GroupIndex, int LayerIndex, int QuadIndex, int PointIndex, EQuadPointProp Prop, int Previous, int Current);
126
127 void Undo() override;
128 void Redo() override;
129
130private:
131 int m_QuadIndex;
132 int m_PointIndex;
133 EQuadPointProp m_Prop;
134 int m_Previous;
135 int m_Current;
136
137 void Apply(int Value);
138};
139
140// -------------------------------------------------------------
141
142class CEditorActionBulk : public IEditorAction
143{
144public:
145 CEditorActionBulk(CEditor *pEditor, const std::vector<std::shared_ptr<IEditorAction>> &vpActions, const char *pDisplay = nullptr, bool Reverse = false);
146
147 void Undo() override;
148 void Redo() override;
149
150private:
151 std::vector<std::shared_ptr<IEditorAction>> m_vpActions;
152 std::string m_Display;
153 bool m_Reverse;
154};
155
156//
157
158class CEditorActionTileChanges : public CEditorActionLayerBase
159{
160public:
161 CEditorActionTileChanges(CEditor *pEditor, int GroupIndex, int LayerIndex, const char *pAction, const EditorTileStateChangeHistory<STileStateChange> &Changes);
162
163 void Undo() override;
164 void Redo() override;
165
166private:
167 EditorTileStateChangeHistory<STileStateChange> m_Changes;
168 int m_TotalChanges;
169
170 void ComputeInfos();
171 void Apply(bool Undo);
172};
173
174// -------------------------------------------------------------
175
176class CEditorActionAddLayer : public CEditorActionLayerBase
177{
178public:
179 CEditorActionAddLayer(CEditor *pEditor, int GroupIndex, int LayerIndex, bool Duplicate = false);
180
181 void Undo() override;
182 void Redo() override;
183
184private:
185 bool m_Duplicate;
186};
187
188class CEditorActionDeleteLayer : public CEditorActionLayerBase
189{
190public:
191 CEditorActionDeleteLayer(CEditor *pEditor, int GroupIndex, int LayerIndex);
192
193 void Undo() override;
194 void Redo() override;
195};
196
197class CEditorActionGroup : public IEditorAction
198{
199public:
200 CEditorActionGroup(CEditor *pEditor, int GroupIndex, bool Delete);
201
202 void Undo() override;
203 void Redo() override;
204
205private:
206 int m_GroupIndex;
207 bool m_Delete;
208 std::shared_ptr<CLayerGroup> m_pGroup;
209};
210
211class CEditorActionEditGroupProp : public IEditorAction
212{
213public:
214 CEditorActionEditGroupProp(CEditor *pEditor, int GroupIndex, EGroupProp Prop, int Previous, int Current);
215
216 void Undo() override;
217 void Redo() override;
218
219private:
220 int m_GroupIndex;
221 EGroupProp m_Prop;
222 int m_Previous;
223 int m_Current;
224
225 void Apply(int Value);
226};
227
228template<typename E>
229class CEditorActionEditLayerPropBase : public CEditorActionLayerBase
230{
231public:
232 CEditorActionEditLayerPropBase(CEditor *pEditor, int GroupIndex, int LayerIndex, E Prop, int Previous, int Current);
233
234 virtual void Undo() override {}
235 virtual void Redo() override {}
236
237protected:
238 E m_Prop;
239 int m_Previous;
240 int m_Current;
241};
242
243class CEditorActionEditLayerProp : public CEditorActionEditLayerPropBase<ELayerProp>
244{
245public:
246 CEditorActionEditLayerProp(CEditor *pEditor, int GroupIndex, int LayerIndex, ELayerProp Prop, int Previous, int Current);
247
248 void Undo() override;
249 void Redo() override;
250
251private:
252 void Apply(int Value);
253};
254
255class CEditorActionEditLayerTilesProp : public CEditorActionEditLayerPropBase<ETilesProp>
256{
257public:
258 CEditorActionEditLayerTilesProp(CEditor *pEditor, int GroupIndex, int LayerIndex, ETilesProp Prop, int Previous, int Current);
259
260 void Undo() override;
261 void Redo() override;
262
263 void SetSavedLayers(const std::map<int, std::shared_ptr<CLayer>> &SavedLayers);
264
265private:
266 std::map<int, std::shared_ptr<CLayer>> m_SavedLayers;
267
268 void RestoreLayer(int Layer, const std::shared_ptr<CLayerTiles> &pLayerTiles);
269};
270
271class CEditorActionEditLayerQuadsProp : public CEditorActionEditLayerPropBase<ELayerQuadsProp>
272{
273public:
274 CEditorActionEditLayerQuadsProp(CEditor *pEditor, int GroupIndex, int LayerIndex, ELayerQuadsProp Prop, int Previous, int Current);
275
276 void Undo() override;
277 void Redo() override;
278
279private:
280 void Apply(int Value);
281};
282
283class CEditorActionEditLayersGroupAndOrder : public IEditorAction
284{
285public:
286 CEditorActionEditLayersGroupAndOrder(CEditor *pEditor, int GroupIndex, const std::vector<int> &LayerIndices, int NewGroupIndex, const std::vector<int> &NewLayerIndices);
287
288 void Undo() override;
289 void Redo() override;
290
291private:
292 int m_GroupIndex;
293 std::vector<int> m_LayerIndices;
294 int m_NewGroupIndex;
295 std::vector<int> m_NewLayerIndices;
296};
297
298// --------------
299
300class CEditorActionAppendMap : public IEditorAction
301{
302public:
303 struct SPrevInfo
304 {
305 int m_Groups;
306 int m_Images;
307 int m_Sounds;
308 int m_Envelopes;
309 };
310
311public:
312 CEditorActionAppendMap(CEditor *pEditor, const char *pMapName, const SPrevInfo &PrevInfo, std::vector<int> &vImageIndexMap);
313
314 void Undo() override;
315 void Redo() override;
316
317private:
318 char m_aMapName[IO_MAX_PATH_LENGTH];
319 SPrevInfo m_PrevInfo;
320 std::vector<int> m_vImageIndexMap;
321};
322
323// --------------
324
325class CEditorActionTileArt : public IEditorAction
326{
327public:
328 CEditorActionTileArt(CEditor *pEditor, int PreviousImageCount, const char *pTileArtFile, std::vector<int> &vImageIndexMap);
329
330 void Undo() override;
331 void Redo() override;
332
333private:
334 int m_PreviousImageCount;
335 char m_aTileArtFile[IO_MAX_PATH_LENGTH];
336 std::vector<int> m_vImageIndexMap;
337};
338
339// ----------------------
340
341class CEditorCommandAction : public IEditorAction
342{
343public:
344 enum class EType
345 {
346 DELETE,
347 ADD,
348 EDIT,
349 MOVE_UP,
350 MOVE_DOWN
351 };
352
353 CEditorCommandAction(CEditor *pEditor, EType Type, int *pSelectedCommandIndex, int CommandIndex, const char *pPreviousCommand = nullptr, const char *pCurrentCommand = nullptr);
354
355 void Undo() override;
356 void Redo() override;
357
358private:
359 EType m_Type;
360 int *m_pSelectedCommandIndex;
361 int m_CommandIndex;
362 std::string m_PreviousCommand;
363 std::string m_CurrentCommand;
364};
365
366// ------------------------------
367
368class CEditorActionEnvelopeAdd : public IEditorAction
369{
370public:
371 CEditorActionEnvelopeAdd(CEditor *pEditor, const std::shared_ptr<CEnvelope> &pEnv);
372
373 void Undo() override;
374 void Redo() override;
375
376private:
377 std::shared_ptr<CEnvelope> m_pEnv;
378};
379
380class CEditorActionEveloppeDelete : public IEditorAction
381{
382public:
383 CEditorActionEveloppeDelete(CEditor *pEditor, int EnvelopeIndex);
384
385 void Undo() override;
386 void Redo() override;
387
388private:
389 int m_EnvelopeIndex;
390 std::shared_ptr<CEnvelope> m_pEnv;
391};
392
393class CEditorActionEnvelopeEdit : public IEditorAction
394{
395public:
396 enum class EEditType
397 {
398 SYNC,
399 ORDER
400 };
401
402 CEditorActionEnvelopeEdit(CEditor *pEditor, int EnvelopeIndex, EEditType EditType, int Previous, int Current);
403
404 void Undo() override;
405 void Redo() override;
406
407private:
408 int m_EnvelopeIndex;
409 EEditType m_EditType;
410 int m_Previous;
411 int m_Current;
412 std::shared_ptr<CEnvelope> m_pEnv;
413};
414
415class CEditorActionEnvelopeEditPoint : public IEditorAction
416{
417public:
418 enum class EEditType
419 {
420 TIME,
421 VALUE,
422 CURVE_TYPE,
423 HANDLE
424 };
425
426 CEditorActionEnvelopeEditPoint(CEditor *pEditor, int EnvelopeIndex, int PointIndex, int Channel, EEditType EditType, int Previous, int Current);
427
428 void Undo() override;
429 void Redo() override;
430
431private:
432 int m_EnvelopeIndex;
433 int m_PointIndex;
434 int m_Channel;
435 EEditType m_EditType;
436 int m_Previous;
437 int m_Current;
438 std::shared_ptr<CEnvelope> m_pEnv;
439
440 void Apply(int Value);
441};
442
443class CEditorActionAddEnvelopePoint : public IEditorAction
444{
445public:
446 CEditorActionAddEnvelopePoint(CEditor *pEditor, int EnvIndex, int Time, ColorRGBA Channels);
447
448 void Undo() override;
449 void Redo() override;
450
451private:
452 int m_EnvIndex;
453 int m_Time;
454 ColorRGBA m_Channels;
455};
456
457class CEditorActionDeleteEnvelopePoint : public IEditorAction
458{
459public:
460 CEditorActionDeleteEnvelopePoint(CEditor *pEditor, int EnvIndex, int PointIndex);
461
462 void Undo() override;
463 void Redo() override;
464
465private:
466 int m_EnvIndex;
467 int m_PointIndex;
468 CEnvPoint_runtime m_Point;
469};
470
471class CEditorActionEditEnvelopePointValue : public IEditorAction
472{
473public:
474 enum class EType
475 {
476 TANGENT_IN,
477 TANGENT_OUT,
478 POINT
479 };
480
481 CEditorActionEditEnvelopePointValue(CEditor *pEditor, int EnvIndex, int PointIndex, int Channel, EType Type, int OldTime, int OldValue, int NewTime, int NewValue);
482
483 void Undo() override;
484 void Redo() override;
485
486private:
487 int m_EnvIndex;
488 int m_PtIndex;
489 int m_Channel;
490 EType m_Type;
491 int m_OldTime;
492 int m_OldValue;
493 int m_NewTime;
494 int m_NewValue;
495
496 void Apply(bool Undo);
497};
498
499class CEditorActionResetEnvelopePointTangent : public IEditorAction
500{
501public:
502 CEditorActionResetEnvelopePointTangent(CEditor *pEditor, int EnvIndex, int PointIndex, int Channel, bool In);
503
504 void Undo() override;
505 void Redo() override;
506
507private:
508 int m_EnvIndex;
509 int m_PointIndex;
510 int m_Channel;
511 bool m_In;
512 int m_Previous[2];
513};
514
515class CEditorActionEditLayerSoundsProp : public CEditorActionEditLayerPropBase<ELayerSoundsProp>
516{
517public:
518 CEditorActionEditLayerSoundsProp(CEditor *pEditor, int GroupIndex, int LayerIndex, ELayerSoundsProp Prop, int Previous, int Current);
519
520 void Undo() override;
521 void Redo() override;
522
523private:
524 void Apply(int Value);
525};
526
527class CEditorActionDeleteSoundSource : public CEditorActionLayerBase
528{
529public:
530 CEditorActionDeleteSoundSource(CEditor *pEditor, int GroupIndex, int LayerIndex, int SourceIndex);
531
532 void Undo() override;
533 void Redo() override;
534
535private:
536 int m_SourceIndex;
537 CSoundSource m_Source;
538};
539
540class CEditorActionEditSoundSource : public CEditorActionLayerBase
541{
542public:
543 enum class EEditType
544 {
545 SHAPE
546 };
547
548 CEditorActionEditSoundSource(CEditor *pEditor, int GroupIndex, int LayerIndex, int SourceIndex, EEditType Type, int Value);
549 ~CEditorActionEditSoundSource() override;
550
551 void Undo() override;
552 void Redo() override;
553
554private:
555 int m_SourceIndex;
556 EEditType m_EditType;
557 int m_CurrentValue;
558
559 std::vector<int> m_vOriginalValues;
560 void *m_pSavedObject;
561
562 void Save();
563};
564
565class CEditorActionEditSoundSourceProp : public CEditorActionEditLayerPropBase<ESoundProp>
566{
567public:
568 CEditorActionEditSoundSourceProp(CEditor *pEditor, int GroupIndex, int LayerIndex, int SourceIndex, ESoundProp Prop, int Previous, int Current);
569
570 void Undo() override;
571 void Redo() override;
572
573private:
574 int m_SourceIndex;
575
576private:
577 void Apply(int Value);
578};
579
580class CEditorActionEditRectSoundSourceShapeProp : public CEditorActionEditLayerPropBase<ERectangleShapeProp>
581{
582public:
583 CEditorActionEditRectSoundSourceShapeProp(CEditor *pEditor, int GroupIndex, int LayerIndex, int SourceIndex, ERectangleShapeProp Prop, int Previous, int Current);
584
585 void Undo() override;
586 void Redo() override;
587
588private:
589 int m_SourceIndex;
590
591private:
592 void Apply(int Value);
593};
594
595class CEditorActionEditCircleSoundSourceShapeProp : public CEditorActionEditLayerPropBase<ECircleShapeProp>
596{
597public:
598 CEditorActionEditCircleSoundSourceShapeProp(CEditor *pEditor, int GroupIndex, int LayerIndex, int SourceIndex, ECircleShapeProp Prop, int Previous, int Current);
599
600 void Undo() override;
601 void Redo() override;
602
603private:
604 int m_SourceIndex;
605
606private:
607 void Apply(int Value);
608};
609
610class CEditorActionNewEmptySound : public CEditorActionLayerBase
611{
612public:
613 CEditorActionNewEmptySound(CEditor *pEditor, int GroupIndex, int LayerIndex, int x, int y);
614
615 void Undo() override;
616 void Redo() override;
617
618private:
619 int m_X;
620 int m_Y;
621};
622
623class CEditorActionNewEmptyQuad : public CEditorActionLayerBase
624{
625public:
626 CEditorActionNewEmptyQuad(CEditor *pEditor, int GroupIndex, int LayerIndex, int x, int y);
627
628 void Undo() override;
629 void Redo() override;
630
631private:
632 int m_X;
633 int m_Y;
634};
635
636class CEditorActionNewQuad : public CEditorActionLayerBase
637{
638public:
639 CEditorActionNewQuad(CEditor *pEditor, int GroupIndex, int LayerIndex);
640
641 void Undo() override;
642 void Redo() override;
643
644private:
645 CQuad m_Quad;
646};
647
648class CEditorActionMoveSoundSource : public CEditorActionLayerBase
649{
650public:
651 CEditorActionMoveSoundSource(CEditor *pEditor, int GroupIndex, int LayerIndex, int SourceIndex, CPoint OriginalPosition, CPoint CurrentPosition);
652
653 void Undo() override;
654 void Redo() override;
655
656private:
657 int m_SourceIndex;
658 CPoint m_OriginalPosition;
659 CPoint m_CurrentPosition;
660};
661
662#endif
663