Pioneer
Loading...
Searching...
No Matches
SystemBodyUndo.h
Go to the documentation of this file.
1// Copyright © 2008-2024 Pioneer Developers. See AUTHORS.txt for details
2// Licensed under the terms of the GPL v3. See licenses/GPL-3.txt
3
4#pragma once
5
6#include "GalaxyEditAPI.h"
7
8#include "editor/UndoSystem.h"
9#include "galaxy/StarSystem.h"
10#include "galaxy/SystemBody.h"
11
13
15 public:
16 ManageStarSystemBody(StarSystem *system, SystemBody *add, SystemBody *rem = nullptr, bool apply = false) :
17 m_system(system),
18 m_addBody(add),
19 m_remBody(rem)
20 {
21 if (apply)
22 Swap();
23 }
24
25 void Swap() override {
26 if (m_addBody)
27 StarSystem::EditorAPI::AddBody(m_system, m_addBody.Get());
28 if (m_remBody)
29 StarSystem::EditorAPI::RemoveBody(m_system, m_remBody.Get());
30 std::swap(m_addBody, m_remBody);
31 }
32
33 private:
34 StarSystem *m_system;
37 };
38
39 // Helper to reorder body indexes at the end of an undo / redo operation by adding two undo steps
41 public:
42 ReorderStarSystemBodies(StarSystem *system, bool onRedo = false) :
43 m_system(system),
44 m_onRedo(onRedo)
45 {
46 Redo();
47 }
48
49 void Undo() override {
50 if (!m_onRedo)
52 }
53
54 void Redo() override {
55 if (m_onRedo)
57 }
58
59 private:
60 StarSystem *m_system;
61 bool m_onRedo;
62 };
63
64 // Helper to sort body hierarchy from index at the end of an undo / redo operation by adding two undo steps
66 public:
67 SortStarSystemBodies(StarSystem *system, bool isRedo) :
68 m_system(system),
69 m_isRedo(isRedo)
70 {
71 }
72
73 void Undo() override {
74 if (!m_isRedo)
76 }
77
78 void Redo() override {
79 if (m_isRedo)
81 }
82
83 private:
84 StarSystem *m_system;
85 bool m_isRedo;
86 };
87
88 // UndoStep helper to handle adding or deleting a child SystemBody from a parent
90 public:
91 AddRemoveChildBody(SystemBody *parent, SystemBody *add, size_t idx) :
92 m_parent(parent),
93 m_add(add),
94 m_idx(idx)
95 {
96 Swap();
97 }
98
100 m_parent(parent),
101 m_add(add),
102 m_idx(-1)
103 {
104 Swap();
105 }
106
107 AddRemoveChildBody(SystemBody *parent, size_t idx) :
108 m_parent(parent),
109 m_add(nullptr),
110 m_idx(idx)
111 {
112 Swap();
113 }
114
115 void Swap() override {
116 if (m_add) {
117 SystemBody::EditorAPI::AddChild(m_parent, m_add.Get(), m_idx);
118 m_add.Reset();
119 } else {
120 m_add.Reset(SystemBody::EditorAPI::RemoveChild(m_parent, m_idx));
121 }
122 }
123
124 private:
125 SystemBody *m_parent;
127 size_t m_idx;
128 };
129
130} // namespace Editor
Definition: SystemBodyUndo.h:89
void Swap() override
Definition: SystemBodyUndo.h:115
AddRemoveChildBody(SystemBody *parent, size_t idx)
Definition: SystemBodyUndo.h:107
AddRemoveChildBody(SystemBody *parent, SystemBody *add, size_t idx)
Definition: SystemBodyUndo.h:91
AddRemoveChildBody(SystemBody *parent, SystemBody *add)
Definition: SystemBodyUndo.h:99
Definition: SystemBodyUndo.h:14
ManageStarSystemBody(StarSystem *system, SystemBody *add, SystemBody *rem=nullptr, bool apply=false)
Definition: SystemBodyUndo.h:16
void Swap() override
Definition: SystemBodyUndo.h:25
ReorderStarSystemBodies(StarSystem *system, bool onRedo=false)
Definition: SystemBodyUndo.h:42
void Redo() override
Definition: SystemBodyUndo.h:54
void Undo() override
Definition: SystemBodyUndo.h:49
Definition: SystemBodyUndo.h:65
SortStarSystemBodies(StarSystem *system, bool isRedo)
Definition: SystemBodyUndo.h:67
void Undo() override
Definition: SystemBodyUndo.h:73
void Redo() override
Definition: SystemBodyUndo.h:78
Definition: UndoSystem.h:31
Definition: RefCounted.h:36
T * Get() const
Definition: SmartPtr.h:37
void Reset(T *p=0)
Definition: SmartPtr.h:25
static void AddBody(StarSystem *system, SystemBody *body, size_t idx=-1)
Definition: GalaxyEditAPI.cpp:114
static void ReorderBodyIndex(StarSystem *system)
Definition: GalaxyEditAPI.cpp:130
static void ReorderBodyHierarchy(StarSystem *system)
Definition: GalaxyEditAPI.cpp:156
static void RemoveBody(StarSystem *system, SystemBody *body)
Definition: GalaxyEditAPI.cpp:123
Definition: StarSystem.h:28
static void AddChild(SystemBody *parent, SystemBody *child, size_t idx=-1)
Definition: GalaxyEditAPI.cpp:428
static SystemBody * RemoveChild(SystemBody *parent, size_t idx=-1)
Definition: GalaxyEditAPI.cpp:439
Definition: SystemBody.h:137
Definition: SystemBodyUndo.h:12