1 | #include <game/editor/editor.h> |
2 | |
3 | #include "image.h" |
4 | |
5 | void CEditorMap::OnModify() |
6 | { |
7 | m_Modified = true; |
8 | m_ModifiedAuto = true; |
9 | m_LastModifiedTime = m_pEditor->Client()->GlobalTime(); |
10 | } |
11 | |
12 | void CEditorMap::DeleteEnvelope(int Index) |
13 | { |
14 | if(Index < 0 || Index >= (int)m_vpEnvelopes.size()) |
15 | return; |
16 | |
17 | OnModify(); |
18 | |
19 | VisitEnvelopeReferences(Visitor: [Index](int &ElementIndex) { |
20 | if(ElementIndex == Index) |
21 | ElementIndex = -1; |
22 | else if(ElementIndex > Index) |
23 | ElementIndex--; |
24 | }); |
25 | |
26 | m_vpEnvelopes.erase(position: m_vpEnvelopes.begin() + Index); |
27 | } |
28 | |
29 | void CEditorMap::SwapEnvelopes(int Index0, int Index1) |
30 | { |
31 | if(Index0 < 0 || Index0 >= (int)m_vpEnvelopes.size()) |
32 | return; |
33 | if(Index1 < 0 || Index1 >= (int)m_vpEnvelopes.size()) |
34 | return; |
35 | if(Index0 == Index1) |
36 | return; |
37 | |
38 | OnModify(); |
39 | |
40 | VisitEnvelopeReferences(Visitor: [Index0, Index1](int &ElementIndex) { |
41 | if(ElementIndex == Index0) |
42 | ElementIndex = Index1; |
43 | else if(ElementIndex == Index1) |
44 | ElementIndex = Index0; |
45 | }); |
46 | |
47 | std::swap(a&: m_vpEnvelopes[Index0], b&: m_vpEnvelopes[Index1]); |
48 | } |
49 | |
50 | template<typename F> |
51 | void CEditorMap::VisitEnvelopeReferences(F &&Visitor) |
52 | { |
53 | for(auto &pGroup : m_vpGroups) |
54 | { |
55 | for(auto &pLayer : pGroup->m_vpLayers) |
56 | { |
57 | if(pLayer->m_Type == LAYERTYPE_QUADS) |
58 | { |
59 | std::shared_ptr<CLayerQuads> pLayerQuads = std::static_pointer_cast<CLayerQuads>(r: pLayer); |
60 | for(auto &Quad : pLayerQuads->m_vQuads) |
61 | { |
62 | Visitor(Quad.m_PosEnv); |
63 | Visitor(Quad.m_ColorEnv); |
64 | } |
65 | } |
66 | else if(pLayer->m_Type == LAYERTYPE_TILES) |
67 | { |
68 | std::shared_ptr<CLayerTiles> pLayerTiles = std::static_pointer_cast<CLayerTiles>(r: pLayer); |
69 | Visitor(pLayerTiles->m_ColorEnv); |
70 | } |
71 | else if(pLayer->m_Type == LAYERTYPE_SOUNDS) |
72 | { |
73 | std::shared_ptr<CLayerSounds> pLayerSounds = std::static_pointer_cast<CLayerSounds>(r: pLayer); |
74 | for(auto &Source : pLayerSounds->m_vSources) |
75 | { |
76 | Visitor(Source.m_PosEnv); |
77 | Visitor(Source.m_SoundEnv); |
78 | } |
79 | } |
80 | } |
81 | } |
82 | } |
83 | |
84 | void CEditorMap::MakeGameLayer(const std::shared_ptr<CLayer> &pLayer) |
85 | { |
86 | m_pGameLayer = std::static_pointer_cast<CLayerGame>(r: pLayer); |
87 | m_pGameLayer->m_pEditor = m_pEditor; |
88 | } |
89 | |
90 | void CEditorMap::MakeGameGroup(std::shared_ptr<CLayerGroup> pGroup) |
91 | { |
92 | m_pGameGroup = std::move(pGroup); |
93 | m_pGameGroup->m_GameGroup = true; |
94 | str_copy(dst&: m_pGameGroup->m_aName, src: "Game" ); |
95 | } |
96 | |
97 | void CEditorMap::Clean() |
98 | { |
99 | m_vpGroups.clear(); |
100 | m_vpEnvelopes.clear(); |
101 | m_vpImages.clear(); |
102 | m_vpSounds.clear(); |
103 | |
104 | m_MapInfo.Reset(); |
105 | m_MapInfoTmp.Reset(); |
106 | |
107 | m_vSettings.clear(); |
108 | |
109 | m_pGameLayer = nullptr; |
110 | m_pGameGroup = nullptr; |
111 | |
112 | m_Modified = false; |
113 | m_ModifiedAuto = false; |
114 | |
115 | m_pTeleLayer = nullptr; |
116 | m_pSpeedupLayer = nullptr; |
117 | m_pFrontLayer = nullptr; |
118 | m_pSwitchLayer = nullptr; |
119 | m_pTuneLayer = nullptr; |
120 | } |
121 | |
122 | void CEditorMap::CreateDefault(IGraphics::CTextureHandle EntitiesTexture) |
123 | { |
124 | // add background |
125 | std::shared_ptr<CLayerGroup> pGroup = NewGroup(); |
126 | pGroup->m_ParallaxX = 0; |
127 | pGroup->m_ParallaxY = 0; |
128 | std::shared_ptr<CLayerQuads> pLayer = std::make_shared<CLayerQuads>(args&: m_pEditor); |
129 | CQuad *pQuad = pLayer->NewQuad(x: 0, y: 0, Width: 1600, Height: 1200); |
130 | pQuad->m_aColors[0].r = pQuad->m_aColors[1].r = 94; |
131 | pQuad->m_aColors[0].g = pQuad->m_aColors[1].g = 132; |
132 | pQuad->m_aColors[0].b = pQuad->m_aColors[1].b = 174; |
133 | pQuad->m_aColors[2].r = pQuad->m_aColors[3].r = 204; |
134 | pQuad->m_aColors[2].g = pQuad->m_aColors[3].g = 232; |
135 | pQuad->m_aColors[2].b = pQuad->m_aColors[3].b = 255; |
136 | pGroup->AddLayer(pLayer); |
137 | |
138 | // add game layer and reset front, tele, speedup, tune and switch layer pointers |
139 | MakeGameGroup(pGroup: NewGroup()); |
140 | MakeGameLayer(pLayer: std::make_shared<CLayerGame>(args&: m_pEditor, args: 50, args: 50)); |
141 | m_pGameGroup->AddLayer(pLayer: m_pGameLayer); |
142 | |
143 | m_pFrontLayer = nullptr; |
144 | m_pTeleLayer = nullptr; |
145 | m_pSpeedupLayer = nullptr; |
146 | m_pSwitchLayer = nullptr; |
147 | m_pTuneLayer = nullptr; |
148 | } |
149 | |
150 | void CEditorMap::MakeTeleLayer(const std::shared_ptr<CLayer> &pLayer) |
151 | { |
152 | m_pTeleLayer = std::static_pointer_cast<CLayerTele>(r: pLayer); |
153 | m_pTeleLayer->m_pEditor = m_pEditor; |
154 | } |
155 | |
156 | void CEditorMap::MakeSpeedupLayer(const std::shared_ptr<CLayer> &pLayer) |
157 | { |
158 | m_pSpeedupLayer = std::static_pointer_cast<CLayerSpeedup>(r: pLayer); |
159 | m_pSpeedupLayer->m_pEditor = m_pEditor; |
160 | } |
161 | |
162 | void CEditorMap::MakeFrontLayer(const std::shared_ptr<CLayer> &pLayer) |
163 | { |
164 | m_pFrontLayer = std::static_pointer_cast<CLayerFront>(r: pLayer); |
165 | m_pFrontLayer->m_pEditor = m_pEditor; |
166 | } |
167 | |
168 | void CEditorMap::MakeSwitchLayer(const std::shared_ptr<CLayer> &pLayer) |
169 | { |
170 | m_pSwitchLayer = std::static_pointer_cast<CLayerSwitch>(r: pLayer); |
171 | m_pSwitchLayer->m_pEditor = m_pEditor; |
172 | } |
173 | |
174 | void CEditorMap::MakeTuneLayer(const std::shared_ptr<CLayer> &pLayer) |
175 | { |
176 | m_pTuneLayer = std::static_pointer_cast<CLayerTune>(r: pLayer); |
177 | m_pTuneLayer->m_pEditor = m_pEditor; |
178 | } |
179 | |