|
4 | 4 | #include "PresetMan.h" |
5 | 5 | #include "LuaMan.h" |
6 | 6 |
|
7 | | -namespace RTE { |
| 7 | +using namespace RTE; |
8 | 8 |
|
9 | | - ConcreteClassInfo(PieSlice, Entity, 80); |
| 9 | +ConcreteClassInfo(PieSlice, Entity, 80); |
10 | 10 |
|
11 | | - PieSlice::PieSlice() { |
12 | | - Clear(); |
13 | | - } |
| 11 | +PieSlice::PieSlice() { |
| 12 | + Clear(); |
| 13 | +} |
14 | 14 |
|
15 | | - PieSlice::~PieSlice() { |
16 | | - Destroy(true); |
17 | | - } |
| 15 | +PieSlice::~PieSlice() { |
| 16 | + Destroy(true); |
| 17 | +} |
| 18 | + |
| 19 | +void PieSlice::Clear() { |
| 20 | + m_Type = PieSliceType::NoType; |
| 21 | + m_Direction = Directions::Any; |
| 22 | + m_CanBeMiddleSlice = true; |
| 23 | + m_OriginalSource = nullptr; |
18 | 24 |
|
19 | | - void PieSlice::Clear() { |
20 | | - m_Type = PieSliceType::NoType; |
21 | | - m_Direction = Directions::Any; |
22 | | - m_CanBeMiddleSlice = true; |
23 | | - m_OriginalSource = nullptr; |
| 25 | + m_Enabled = true; |
| 26 | + m_Icon = nullptr; |
24 | 27 |
|
25 | | - m_Enabled = true; |
26 | | - m_Icon = nullptr; |
| 28 | + m_LuabindFunctionObject.reset(); |
| 29 | + m_FunctionName.clear(); |
27 | 30 |
|
28 | | - m_LuabindFunctionObject.reset(); |
29 | | - m_FunctionName.clear(); |
| 31 | + m_SubPieMenu.reset(); |
30 | 32 |
|
31 | | - m_SubPieMenu.reset(); |
| 33 | + m_StartAngle = 0; |
| 34 | + m_SlotCount = 0; |
| 35 | + m_MidAngle = 0; |
32 | 36 |
|
33 | | - m_StartAngle = 0; |
34 | | - m_SlotCount = 0; |
35 | | - m_MidAngle = 0; |
| 37 | + m_DrawFlippedToMatchAbsoluteAngle = false; |
| 38 | +} |
36 | 39 |
|
37 | | - m_DrawFlippedToMatchAbsoluteAngle = false; |
| 40 | +int PieSlice::Create() { |
| 41 | + if (Entity::Create() < 0) { |
| 42 | + return -1; |
| 43 | + } |
| 44 | + if (!HasIcon()) { |
| 45 | + m_Icon = std::unique_ptr<Icon>(dynamic_cast<Icon*>(g_PresetMan.GetEntityPreset("Icon", "Blank")->Clone())); |
38 | 46 | } |
39 | 47 |
|
40 | | - int PieSlice::Create() { |
41 | | - if (Entity::Create() < 0) { |
42 | | - return -1; |
43 | | - } |
44 | | - if (!HasIcon()) { |
45 | | - m_Icon = std::unique_ptr<Icon>(dynamic_cast<Icon*>(g_PresetMan.GetEntityPreset("Icon", "Blank")->Clone())); |
46 | | - } |
| 48 | + return 0; |
| 49 | +} |
47 | 50 |
|
48 | | - return 0; |
49 | | - } |
| 51 | +int PieSlice::Create(const PieSlice& reference) { |
| 52 | + Entity::Create(reference); |
50 | 53 |
|
51 | | - int PieSlice::Create(const PieSlice& reference) { |
52 | | - Entity::Create(reference); |
| 54 | + m_Type = reference.m_Type; |
| 55 | + m_Direction = reference.m_Direction; |
| 56 | + m_CanBeMiddleSlice = reference.m_CanBeMiddleSlice; |
53 | 57 |
|
54 | | - m_Type = reference.m_Type; |
55 | | - m_Direction = reference.m_Direction; |
56 | | - m_CanBeMiddleSlice = reference.m_CanBeMiddleSlice; |
| 58 | + m_Enabled = reference.m_Enabled; |
| 59 | + m_Icon = std::unique_ptr<Icon>(dynamic_cast<Icon*>(reference.m_Icon->Clone())); |
57 | 60 |
|
58 | | - m_Enabled = reference.m_Enabled; |
59 | | - m_Icon = std::unique_ptr<Icon>(dynamic_cast<Icon*>(reference.m_Icon->Clone())); |
| 61 | + m_FunctionName = reference.m_FunctionName; |
| 62 | + if (reference.m_LuabindFunctionObject) { |
| 63 | + m_LuabindFunctionObject = std::make_unique<LuabindObjectWrapper>(nullptr, reference.m_LuabindFunctionObject->GetFilePath()); |
| 64 | + ReloadScripts(); |
| 65 | + } |
60 | 66 |
|
61 | | - m_FunctionName = reference.m_FunctionName; |
62 | | - if (reference.m_LuabindFunctionObject) { |
63 | | - m_LuabindFunctionObject = std::make_unique<LuabindObjectWrapper>(nullptr, reference.m_LuabindFunctionObject->GetFilePath()); |
64 | | - ReloadScripts(); |
65 | | - } |
| 67 | + if (reference.m_SubPieMenu) { |
| 68 | + SetSubPieMenu(dynamic_cast<PieMenu*>(reference.m_SubPieMenu->Clone())); |
| 69 | + } |
66 | 70 |
|
67 | | - if (reference.m_SubPieMenu) { |
68 | | - SetSubPieMenu(dynamic_cast<PieMenu*>(reference.m_SubPieMenu->Clone())); |
69 | | - } |
| 71 | + m_StartAngle = reference.m_StartAngle; |
| 72 | + m_SlotCount = reference.m_SlotCount; |
| 73 | + m_MidAngle = reference.m_MidAngle; |
70 | 74 |
|
71 | | - m_StartAngle = reference.m_StartAngle; |
72 | | - m_SlotCount = reference.m_SlotCount; |
73 | | - m_MidAngle = reference.m_MidAngle; |
| 75 | + m_DrawFlippedToMatchAbsoluteAngle = reference.m_DrawFlippedToMatchAbsoluteAngle; |
74 | 76 |
|
75 | | - m_DrawFlippedToMatchAbsoluteAngle = reference.m_DrawFlippedToMatchAbsoluteAngle; |
| 77 | + return 0; |
| 78 | +} |
76 | 79 |
|
77 | | - return 0; |
78 | | - } |
| 80 | +int PieSlice::ReadProperty(const std::string_view& propName, Reader& reader) { |
| 81 | + StartPropertyList(return Entity::ReadProperty(propName, reader)); |
79 | 82 |
|
80 | | - int PieSlice::ReadProperty(const std::string_view& propName, Reader& reader) { |
81 | | - StartPropertyList(return Entity::ReadProperty(propName, reader)); |
82 | | - |
83 | | - MatchProperty("Type", { m_Type = static_cast<PieSliceType>(std::stoi(reader.ReadPropValue())); }); |
84 | | - MatchProperty("Direction", { |
85 | | - if (std::string directionString = reader.ReadPropValue(); c_DirectionNameToDirectionsMap.find(directionString) != c_DirectionNameToDirectionsMap.end()) { |
86 | | - m_Direction = c_DirectionNameToDirectionsMap.find(directionString)->second; |
87 | | - } else { |
88 | | - try { |
89 | | - int direction = std::stoi(directionString); |
90 | | - if (direction < Directions::None || direction > Directions::Any) { |
91 | | - reader.ReportError("Direction " + directionString + " is invalid (Out of Bounds)."); |
92 | | - } |
93 | | - m_Direction = static_cast<Directions>(direction); |
94 | | - } catch (const std::invalid_argument&) { |
95 | | - reader.ReportError("Direction " + directionString + " is invalid."); |
| 83 | + MatchProperty("Type", { m_Type = static_cast<PieSliceType>(std::stoi(reader.ReadPropValue())); }); |
| 84 | + MatchProperty("Direction", { |
| 85 | + if (std::string directionString = reader.ReadPropValue(); c_DirectionNameToDirectionsMap.find(directionString) != c_DirectionNameToDirectionsMap.end()) { |
| 86 | + m_Direction = c_DirectionNameToDirectionsMap.find(directionString)->second; |
| 87 | + } else { |
| 88 | + try { |
| 89 | + int direction = std::stoi(directionString); |
| 90 | + if (direction < Directions::None || direction > Directions::Any) { |
| 91 | + reader.ReportError("Direction " + directionString + " is invalid (Out of Bounds)."); |
96 | 92 | } |
| 93 | + m_Direction = static_cast<Directions>(direction); |
| 94 | + } catch (const std::invalid_argument&) { |
| 95 | + reader.ReportError("Direction " + directionString + " is invalid."); |
97 | 96 | } |
98 | | - if (m_Direction == Directions::None) { |
99 | | - reader.ReportError("Pie Slices cannot have direction None."); |
100 | | - } |
101 | | - }); |
102 | | - MatchProperty("CanBeMiddleSlice", { reader >> m_CanBeMiddleSlice; }); |
103 | | - MatchProperty("Enabled", { reader >> m_Enabled; }); |
104 | | - MatchProperty("Icon", { SetIcon(dynamic_cast<Icon*>(g_PresetMan.ReadReflectedPreset(reader))); }); |
105 | | - MatchProperty("ScriptPath", { |
106 | | - std::string scriptPath; |
107 | | - reader >> scriptPath; |
108 | | - m_LuabindFunctionObject = std::make_unique<LuabindObjectWrapper>(nullptr, scriptPath); |
109 | | - if (!m_FunctionName.empty()) { |
110 | | - ReloadScripts(); |
111 | | - } |
112 | | - }); |
113 | | - MatchProperty("FunctionName", { |
114 | | - reader >> m_FunctionName; |
115 | | - if (m_LuabindFunctionObject) { |
116 | | - ReloadScripts(); |
117 | | - } |
118 | | - }); |
119 | | - MatchProperty("SubPieMenu", { SetSubPieMenu(dynamic_cast<PieMenu*>(g_PresetMan.ReadReflectedPreset(reader))); }); |
120 | | - MatchProperty("DrawFlippedToMatchAbsoluteAngle", { reader >> m_DrawFlippedToMatchAbsoluteAngle; }); |
121 | | - |
122 | | - EndPropertyList; |
123 | | - } |
124 | | - |
125 | | - int PieSlice::Save(Writer& writer) const { |
126 | | - Entity::Save(writer); |
127 | | - |
128 | | - if (m_Type != PieSliceType::NoType) { |
129 | | - writer.NewPropertyWithValue("Type", static_cast<int>(m_Type)); |
130 | 97 | } |
131 | | - if (m_Direction != Directions::Any) { |
132 | | - writer.NewPropertyWithValue("Direction", static_cast<int>(m_Direction)); |
| 98 | + if (m_Direction == Directions::None) { |
| 99 | + reader.ReportError("Pie Slices cannot have direction None."); |
133 | 100 | } |
134 | | - if (!m_Enabled) { |
135 | | - writer.NewPropertyWithValue("Enabled", m_Enabled); |
136 | | - } |
137 | | - writer.NewPropertyWithValue("Icon", m_Icon.get()); |
138 | | - if (m_LuabindFunctionObject && !m_FunctionName.empty()) { |
139 | | - writer.NewPropertyWithValue("ScriptPath", m_LuabindFunctionObject->GetFilePath()); |
140 | | - writer.NewPropertyWithValue("FunctionName", m_FunctionName); |
| 101 | + }); |
| 102 | + MatchProperty("CanBeMiddleSlice", { reader >> m_CanBeMiddleSlice; }); |
| 103 | + MatchProperty("Enabled", { reader >> m_Enabled; }); |
| 104 | + MatchProperty("Icon", { SetIcon(dynamic_cast<Icon*>(g_PresetMan.ReadReflectedPreset(reader))); }); |
| 105 | + MatchProperty("ScriptPath", { |
| 106 | + std::string scriptPath; |
| 107 | + reader >> scriptPath; |
| 108 | + m_LuabindFunctionObject = std::make_unique<LuabindObjectWrapper>(nullptr, scriptPath); |
| 109 | + if (!m_FunctionName.empty()) { |
| 110 | + ReloadScripts(); |
141 | 111 | } |
142 | | - if (m_SubPieMenu) { |
143 | | - writer.NewPropertyWithValue("SubPieMenu", m_SubPieMenu.get()); |
| 112 | + }); |
| 113 | + MatchProperty("FunctionName", { |
| 114 | + reader >> m_FunctionName; |
| 115 | + if (m_LuabindFunctionObject) { |
| 116 | + ReloadScripts(); |
144 | 117 | } |
| 118 | + }); |
| 119 | + MatchProperty("SubPieMenu", { SetSubPieMenu(dynamic_cast<PieMenu*>(g_PresetMan.ReadReflectedPreset(reader))); }); |
| 120 | + MatchProperty("DrawFlippedToMatchAbsoluteAngle", { reader >> m_DrawFlippedToMatchAbsoluteAngle; }); |
| 121 | + |
| 122 | + EndPropertyList; |
| 123 | +} |
145 | 124 |
|
146 | | - return 0; |
| 125 | +int PieSlice::Save(Writer& writer) const { |
| 126 | + Entity::Save(writer); |
| 127 | + |
| 128 | + if (m_Type != PieSliceType::NoType) { |
| 129 | + writer.NewPropertyWithValue("Type", static_cast<int>(m_Type)); |
| 130 | + } |
| 131 | + if (m_Direction != Directions::Any) { |
| 132 | + writer.NewPropertyWithValue("Direction", static_cast<int>(m_Direction)); |
| 133 | + } |
| 134 | + if (!m_Enabled) { |
| 135 | + writer.NewPropertyWithValue("Enabled", m_Enabled); |
| 136 | + } |
| 137 | + writer.NewPropertyWithValue("Icon", m_Icon.get()); |
| 138 | + if (m_LuabindFunctionObject && !m_FunctionName.empty()) { |
| 139 | + writer.NewPropertyWithValue("ScriptPath", m_LuabindFunctionObject->GetFilePath()); |
| 140 | + writer.NewPropertyWithValue("FunctionName", m_FunctionName); |
| 141 | + } |
| 142 | + if (m_SubPieMenu) { |
| 143 | + writer.NewPropertyWithValue("SubPieMenu", m_SubPieMenu.get()); |
147 | 144 | } |
148 | 145 |
|
149 | | - BITMAP* RTE::PieSlice::GetAppropriateIcon(bool sliceIsSelected) const { |
150 | | - if (int iconFrameCount = m_Icon->GetFrameCount(); iconFrameCount > 0) { |
151 | | - if (!IsEnabled() && iconFrameCount > 2) { |
152 | | - return m_Icon->GetBitmaps8()[2]; |
153 | | - } else if (sliceIsSelected && iconFrameCount > 1) { |
154 | | - return m_Icon->GetBitmaps8()[1]; |
155 | | - } else { |
156 | | - return m_Icon->GetBitmaps8()[0]; |
157 | | - } |
| 146 | + return 0; |
| 147 | +} |
| 148 | + |
| 149 | +BITMAP* RTE::PieSlice::GetAppropriateIcon(bool sliceIsSelected) const { |
| 150 | + if (int iconFrameCount = m_Icon->GetFrameCount(); iconFrameCount > 0) { |
| 151 | + if (!IsEnabled() && iconFrameCount > 2) { |
| 152 | + return m_Icon->GetBitmaps8()[2]; |
| 153 | + } else if (sliceIsSelected && iconFrameCount > 1) { |
| 154 | + return m_Icon->GetBitmaps8()[1]; |
| 155 | + } else { |
| 156 | + return m_Icon->GetBitmaps8()[0]; |
158 | 157 | } |
159 | | - return nullptr; |
160 | 158 | } |
| 159 | + return nullptr; |
| 160 | +} |
161 | 161 |
|
162 | | - PieMenu* PieSlice::GetSubPieMenu() const { |
163 | | - return m_SubPieMenu.get(); |
164 | | - } |
| 162 | +PieMenu* PieSlice::GetSubPieMenu() const { |
| 163 | + return m_SubPieMenu.get(); |
| 164 | +} |
165 | 165 |
|
166 | | - void PieSlice::SetSubPieMenu(PieMenu* newSubPieMenu) { |
167 | | - m_SubPieMenu = std::unique_ptr<PieMenu, PieMenuCustomDeleter>(newSubPieMenu); |
168 | | - } |
| 166 | +void PieSlice::SetSubPieMenu(PieMenu* newSubPieMenu) { |
| 167 | + m_SubPieMenu = std::unique_ptr<PieMenu, PieMenuCustomDeleter>(newSubPieMenu); |
| 168 | +} |
169 | 169 |
|
170 | | - int PieSlice::ReloadScripts() { |
171 | | - int status = 0; |
| 170 | +int PieSlice::ReloadScripts() { |
| 171 | + int status = 0; |
172 | 172 |
|
173 | | - if (m_LuabindFunctionObject) { |
174 | | - std::string filePath = m_LuabindFunctionObject->GetFilePath(); |
175 | | - std::unordered_map<std::string, LuabindObjectWrapper*> scriptFileFunctions; |
| 173 | + if (m_LuabindFunctionObject) { |
| 174 | + std::string filePath = m_LuabindFunctionObject->GetFilePath(); |
| 175 | + std::unordered_map<std::string, LuabindObjectWrapper*> scriptFileFunctions; |
176 | 176 |
|
177 | | - status = g_LuaMan.GetMasterScriptState().RunScriptFileAndRetrieveFunctions(filePath, {m_FunctionName}, scriptFileFunctions, true); |
178 | | - if (scriptFileFunctions.find(m_FunctionName) != scriptFileFunctions.end()) { |
179 | | - m_LuabindFunctionObject = std::unique_ptr<LuabindObjectWrapper>(scriptFileFunctions.at(m_FunctionName)); |
180 | | - } |
| 177 | + status = g_LuaMan.GetMasterScriptState().RunScriptFileAndRetrieveFunctions(filePath, {m_FunctionName}, scriptFileFunctions, true); |
| 178 | + if (scriptFileFunctions.find(m_FunctionName) != scriptFileFunctions.end()) { |
| 179 | + m_LuabindFunctionObject = std::unique_ptr<LuabindObjectWrapper>(scriptFileFunctions.at(m_FunctionName)); |
181 | 180 | } |
182 | | - |
183 | | - return status; |
184 | 181 | } |
185 | 182 |
|
186 | | - void PieSlice::RecalculateMidAngle() { |
187 | | - m_MidAngle = m_StartAngle + (static_cast<float>(m_SlotCount) * PieQuadrant::c_PieSliceSlotSize / 2.0F); |
188 | | - } |
| 183 | + return status; |
| 184 | +} |
189 | 185 |
|
190 | | - void PieSlice::PieMenuCustomDeleter::operator()(PieMenu* pieMenu) const { |
191 | | - pieMenu->Destroy(true); |
192 | | - } |
193 | | -} // namespace RTE |
| 186 | +void PieSlice::RecalculateMidAngle() { |
| 187 | + m_MidAngle = m_StartAngle + (static_cast<float>(m_SlotCount) * PieQuadrant::c_PieSliceSlotSize / 2.0F); |
| 188 | +} |
| 189 | + |
| 190 | +void PieSlice::PieMenuCustomDeleter::operator()(PieMenu* pieMenu) const { |
| 191 | + pieMenu->Destroy(true); |
| 192 | +} |
0 commit comments