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 | |
7 | class CEditorActionLayerBase : public IEditorAction |
8 | { |
9 | public: |
10 | CEditorActionLayerBase(CEditor *pEditor, int GroupIndex, int LayerIndex); |
11 | |
12 | virtual void Undo() override {} |
13 | virtual void Redo() override {} |
14 | |
15 | protected: |
16 | int m_GroupIndex; |
17 | int m_LayerIndex; |
18 | std::shared_ptr<CLayer> m_pLayer; |
19 | }; |
20 | |
21 | class CEditorBrushDrawAction : public IEditorAction |
22 | { |
23 | public: |
24 | CEditorBrushDrawAction(CEditor *pEditor, int Group); |
25 | |
26 | void Undo() override; |
27 | void Redo() override; |
28 | bool IsEmpty() override; |
29 | |
30 | private: |
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 | |
50 | class CEditorActionQuadPlace : public CEditorActionLayerBase |
51 | { |
52 | public: |
53 | CEditorActionQuadPlace(CEditor *pEditor, int GroupIndex, int LayerIndex, std::vector<CQuad> &vBrush); |
54 | |
55 | void Undo() override; |
56 | void Redo() override; |
57 | |
58 | private: |
59 | std::vector<CQuad> m_vBrush; |
60 | }; |
61 | |
62 | class CEditorActionSoundPlace : public CEditorActionLayerBase |
63 | { |
64 | public: |
65 | CEditorActionSoundPlace(CEditor *pEditor, int GroupIndex, int LayerIndex, std::vector<CSoundSource> &vBrush); |
66 | |
67 | void Undo() override; |
68 | void Redo() override; |
69 | |
70 | private: |
71 | std::vector<CSoundSource> m_vBrush; |
72 | }; |
73 | |
74 | // ------------------------------------------------------------- |
75 | |
76 | class CEditorActionDeleteQuad : public CEditorActionLayerBase |
77 | { |
78 | public: |
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 | |
84 | private: |
85 | std::vector<int> m_vQuadsIndices; |
86 | std::vector<CQuad> m_vDeletedQuads; |
87 | }; |
88 | |
89 | // ------------------------------------------------------------- |
90 | |
91 | class CEditorActionEditQuadPoint : public CEditorActionLayerBase |
92 | { |
93 | public: |
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 | |
99 | private: |
100 | int m_QuadIndex; |
101 | std::vector<CPoint> m_vPreviousPoints; |
102 | std::vector<CPoint> m_vCurrentPoints; |
103 | }; |
104 | |
105 | class CEditorActionEditQuadProp : public CEditorActionLayerBase |
106 | { |
107 | public: |
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 | |
113 | private: |
114 | int m_QuadIndex; |
115 | EQuadProp m_Prop; |
116 | int m_Previous; |
117 | int m_Current; |
118 | |
119 | void Apply(int Value); |
120 | }; |
121 | |
122 | class CEditorActionEditQuadPointProp : public CEditorActionLayerBase |
123 | { |
124 | public: |
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 | |
130 | private: |
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 | |
142 | class CEditorActionBulk : public IEditorAction |
143 | { |
144 | public: |
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 | |
150 | private: |
151 | std::vector<std::shared_ptr<IEditorAction>> m_vpActions; |
152 | std::string m_Display; |
153 | bool m_Reverse; |
154 | }; |
155 | |
156 | // |
157 | |
158 | class CEditorActionTileChanges : public CEditorActionLayerBase |
159 | { |
160 | public: |
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 | |
166 | private: |
167 | EditorTileStateChangeHistory<STileStateChange> m_Changes; |
168 | int m_TotalChanges; |
169 | |
170 | void ComputeInfos(); |
171 | void Apply(bool Undo); |
172 | }; |
173 | |
174 | // ------------------------------------------------------------- |
175 | |
176 | class CEditorActionAddLayer : public CEditorActionLayerBase |
177 | { |
178 | public: |
179 | CEditorActionAddLayer(CEditor *pEditor, int GroupIndex, int LayerIndex, bool Duplicate = false); |
180 | |
181 | void Undo() override; |
182 | void Redo() override; |
183 | |
184 | private: |
185 | bool m_Duplicate; |
186 | }; |
187 | |
188 | class CEditorActionDeleteLayer : public CEditorActionLayerBase |
189 | { |
190 | public: |
191 | CEditorActionDeleteLayer(CEditor *pEditor, int GroupIndex, int LayerIndex); |
192 | |
193 | void Undo() override; |
194 | void Redo() override; |
195 | }; |
196 | |
197 | class CEditorActionGroup : public IEditorAction |
198 | { |
199 | public: |
200 | CEditorActionGroup(CEditor *pEditor, int GroupIndex, bool Delete); |
201 | |
202 | void Undo() override; |
203 | void Redo() override; |
204 | |
205 | private: |
206 | int m_GroupIndex; |
207 | bool m_Delete; |
208 | std::shared_ptr<CLayerGroup> m_pGroup; |
209 | }; |
210 | |
211 | class CEditorActionEditGroupProp : public IEditorAction |
212 | { |
213 | public: |
214 | CEditorActionEditGroupProp(CEditor *pEditor, int GroupIndex, EGroupProp Prop, int Previous, int Current); |
215 | |
216 | void Undo() override; |
217 | void Redo() override; |
218 | |
219 | private: |
220 | int m_GroupIndex; |
221 | EGroupProp m_Prop; |
222 | int m_Previous; |
223 | int m_Current; |
224 | |
225 | void Apply(int Value); |
226 | }; |
227 | |
228 | template<typename E> |
229 | class CEditorActionEditLayerPropBase : public CEditorActionLayerBase |
230 | { |
231 | public: |
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 | |
237 | protected: |
238 | E m_Prop; |
239 | int m_Previous; |
240 | int m_Current; |
241 | }; |
242 | |
243 | class CEditorActionEditLayerProp : public CEditorActionEditLayerPropBase<ELayerProp> |
244 | { |
245 | public: |
246 | CEditorActionEditLayerProp(CEditor *pEditor, int GroupIndex, int LayerIndex, ELayerProp Prop, int Previous, int Current); |
247 | |
248 | void Undo() override; |
249 | void Redo() override; |
250 | |
251 | private: |
252 | void Apply(int Value); |
253 | }; |
254 | |
255 | class CEditorActionEditLayerTilesProp : public CEditorActionEditLayerPropBase<ETilesProp> |
256 | { |
257 | public: |
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 | |
265 | private: |
266 | std::map<int, std::shared_ptr<CLayer>> m_SavedLayers; |
267 | |
268 | void RestoreLayer(int Layer, const std::shared_ptr<CLayerTiles> &pLayerTiles); |
269 | }; |
270 | |
271 | class CEditorActionEditLayerQuadsProp : public CEditorActionEditLayerPropBase<ELayerQuadsProp> |
272 | { |
273 | public: |
274 | CEditorActionEditLayerQuadsProp(CEditor *pEditor, int GroupIndex, int LayerIndex, ELayerQuadsProp Prop, int Previous, int Current); |
275 | |
276 | void Undo() override; |
277 | void Redo() override; |
278 | |
279 | private: |
280 | void Apply(int Value); |
281 | }; |
282 | |
283 | class CEditorActionEditLayersGroupAndOrder : public IEditorAction |
284 | { |
285 | public: |
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 | |
291 | private: |
292 | int m_GroupIndex; |
293 | std::vector<int> m_LayerIndices; |
294 | int m_NewGroupIndex; |
295 | std::vector<int> m_NewLayerIndices; |
296 | }; |
297 | |
298 | // -------------- |
299 | |
300 | class CEditorActionAppendMap : public IEditorAction |
301 | { |
302 | public: |
303 | struct SPrevInfo |
304 | { |
305 | int m_Groups; |
306 | int m_Images; |
307 | int m_Sounds; |
308 | int m_Envelopes; |
309 | }; |
310 | |
311 | public: |
312 | CEditorActionAppendMap(CEditor *pEditor, const char *pMapName, const SPrevInfo &PrevInfo, std::vector<int> &vImageIndexMap); |
313 | |
314 | void Undo() override; |
315 | void Redo() override; |
316 | |
317 | private: |
318 | char m_aMapName[IO_MAX_PATH_LENGTH]; |
319 | SPrevInfo m_PrevInfo; |
320 | std::vector<int> m_vImageIndexMap; |
321 | }; |
322 | |
323 | // -------------- |
324 | |
325 | class CEditorActionTileArt : public IEditorAction |
326 | { |
327 | public: |
328 | CEditorActionTileArt(CEditor *pEditor, int PreviousImageCount, const char *pTileArtFile, std::vector<int> &vImageIndexMap); |
329 | |
330 | void Undo() override; |
331 | void Redo() override; |
332 | |
333 | private: |
334 | int m_PreviousImageCount; |
335 | char m_aTileArtFile[IO_MAX_PATH_LENGTH]; |
336 | std::vector<int> m_vImageIndexMap; |
337 | }; |
338 | |
339 | // ---------------------- |
340 | |
341 | class CEditorCommandAction : public IEditorAction |
342 | { |
343 | public: |
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 | |
358 | private: |
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 | |
368 | class CEditorActionEnvelopeAdd : public IEditorAction |
369 | { |
370 | public: |
371 | CEditorActionEnvelopeAdd(CEditor *pEditor, const std::shared_ptr<CEnvelope> &pEnv); |
372 | |
373 | void Undo() override; |
374 | void Redo() override; |
375 | |
376 | private: |
377 | std::shared_ptr<CEnvelope> m_pEnv; |
378 | }; |
379 | |
380 | class CEditorActionEveloppeDelete : public IEditorAction |
381 | { |
382 | public: |
383 | CEditorActionEveloppeDelete(CEditor *pEditor, int EnvelopeIndex); |
384 | |
385 | void Undo() override; |
386 | void Redo() override; |
387 | |
388 | private: |
389 | int m_EnvelopeIndex; |
390 | std::shared_ptr<CEnvelope> m_pEnv; |
391 | }; |
392 | |
393 | class CEditorActionEnvelopeEdit : public IEditorAction |
394 | { |
395 | public: |
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 | |
407 | private: |
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 | |
415 | class CEditorActionEnvelopeEditPoint : public IEditorAction |
416 | { |
417 | public: |
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 | |
431 | private: |
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 | |
443 | class CEditorActionAddEnvelopePoint : public IEditorAction |
444 | { |
445 | public: |
446 | CEditorActionAddEnvelopePoint(CEditor *pEditor, int EnvIndex, int Time, ColorRGBA Channels); |
447 | |
448 | void Undo() override; |
449 | void Redo() override; |
450 | |
451 | private: |
452 | int m_EnvIndex; |
453 | int m_Time; |
454 | ColorRGBA m_Channels; |
455 | }; |
456 | |
457 | class CEditorActionDeleteEnvelopePoint : public IEditorAction |
458 | { |
459 | public: |
460 | CEditorActionDeleteEnvelopePoint(CEditor *pEditor, int EnvIndex, int PointIndex); |
461 | |
462 | void Undo() override; |
463 | void Redo() override; |
464 | |
465 | private: |
466 | int m_EnvIndex; |
467 | int m_PointIndex; |
468 | CEnvPoint_runtime m_Point; |
469 | }; |
470 | |
471 | class CEditorActionEditEnvelopePointValue : public IEditorAction |
472 | { |
473 | public: |
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 | |
486 | private: |
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 | |
499 | class CEditorActionResetEnvelopePointTangent : public IEditorAction |
500 | { |
501 | public: |
502 | CEditorActionResetEnvelopePointTangent(CEditor *pEditor, int EnvIndex, int PointIndex, int Channel, bool In); |
503 | |
504 | void Undo() override; |
505 | void Redo() override; |
506 | |
507 | private: |
508 | int m_EnvIndex; |
509 | int m_PointIndex; |
510 | int m_Channel; |
511 | bool m_In; |
512 | int m_Previous[2]; |
513 | }; |
514 | |
515 | class CEditorActionEditLayerSoundsProp : public CEditorActionEditLayerPropBase<ELayerSoundsProp> |
516 | { |
517 | public: |
518 | CEditorActionEditLayerSoundsProp(CEditor *pEditor, int GroupIndex, int LayerIndex, ELayerSoundsProp Prop, int Previous, int Current); |
519 | |
520 | void Undo() override; |
521 | void Redo() override; |
522 | |
523 | private: |
524 | void Apply(int Value); |
525 | }; |
526 | |
527 | class CEditorActionDeleteSoundSource : public CEditorActionLayerBase |
528 | { |
529 | public: |
530 | CEditorActionDeleteSoundSource(CEditor *pEditor, int GroupIndex, int LayerIndex, int SourceIndex); |
531 | |
532 | void Undo() override; |
533 | void Redo() override; |
534 | |
535 | private: |
536 | int m_SourceIndex; |
537 | CSoundSource m_Source; |
538 | }; |
539 | |
540 | class CEditorActionEditSoundSource : public CEditorActionLayerBase |
541 | { |
542 | public: |
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 | |
554 | private: |
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 | |
565 | class CEditorActionEditSoundSourceProp : public CEditorActionEditLayerPropBase<ESoundProp> |
566 | { |
567 | public: |
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 | |
573 | private: |
574 | int m_SourceIndex; |
575 | |
576 | private: |
577 | void Apply(int Value); |
578 | }; |
579 | |
580 | class CEditorActionEditRectSoundSourceShapeProp : public CEditorActionEditLayerPropBase<ERectangleShapeProp> |
581 | { |
582 | public: |
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 | |
588 | private: |
589 | int m_SourceIndex; |
590 | |
591 | private: |
592 | void Apply(int Value); |
593 | }; |
594 | |
595 | class CEditorActionEditCircleSoundSourceShapeProp : public CEditorActionEditLayerPropBase<ECircleShapeProp> |
596 | { |
597 | public: |
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 | |
603 | private: |
604 | int m_SourceIndex; |
605 | |
606 | private: |
607 | void Apply(int Value); |
608 | }; |
609 | |
610 | class CEditorActionNewEmptySound : public CEditorActionLayerBase |
611 | { |
612 | public: |
613 | CEditorActionNewEmptySound(CEditor *pEditor, int GroupIndex, int LayerIndex, int x, int y); |
614 | |
615 | void Undo() override; |
616 | void Redo() override; |
617 | |
618 | private: |
619 | int m_X; |
620 | int m_Y; |
621 | }; |
622 | |
623 | class CEditorActionNewEmptyQuad : public CEditorActionLayerBase |
624 | { |
625 | public: |
626 | CEditorActionNewEmptyQuad(CEditor *pEditor, int GroupIndex, int LayerIndex, int x, int y); |
627 | |
628 | void Undo() override; |
629 | void Redo() override; |
630 | |
631 | private: |
632 | int m_X; |
633 | int m_Y; |
634 | }; |
635 | |
636 | class CEditorActionNewQuad : public CEditorActionLayerBase |
637 | { |
638 | public: |
639 | CEditorActionNewQuad(CEditor *pEditor, int GroupIndex, int LayerIndex); |
640 | |
641 | void Undo() override; |
642 | void Redo() override; |
643 | |
644 | private: |
645 | CQuad m_Quad; |
646 | }; |
647 | |
648 | class CEditorActionMoveSoundSource : public CEditorActionLayerBase |
649 | { |
650 | public: |
651 | CEditorActionMoveSoundSource(CEditor *pEditor, int GroupIndex, int LayerIndex, int SourceIndex, CPoint OriginalPosition, CPoint CurrentPosition); |
652 | |
653 | void Undo() override; |
654 | void Redo() override; |
655 | |
656 | private: |
657 | int m_SourceIndex; |
658 | CPoint m_OriginalPosition; |
659 | CPoint m_CurrentPosition; |
660 | }; |
661 | |
662 | #endif |
663 | |