1/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
2/* If you are missing that file, acquire a complete release at teeworlds.com. */
3
4#include "editor.h"
5#include "editor_actions.h"
6
7#include <base/color.h>
8
9#include <engine/font_icons.h>
10#include <engine/graphics.h>
11#include <engine/input.h>
12#include <engine/keys.h>
13#include <engine/shared/config.h>
14#include <engine/storage.h>
15
16#include <game/client/gameclient.h>
17#include <game/client/ui_scrollregion.h>
18#include <game/editor/mapitems/image.h>
19#include <game/editor/mapitems/sound.h>
20
21#include <limits>
22
23CUi::EPopupMenuFunctionResult CEditor::PopupMenuFile(void *pContext, CUIRect View, bool Active)
24{
25 CEditor *pEditor = static_cast<CEditor *>(pContext);
26
27 CUIRect Slot;
28 View.HSplitTop(Cut: 12.0f, pTop: &Slot, pBottom: &View);
29 if(pEditor->DoButton_MenuItem(pId: &pEditor->m_QuickActionNewMap, pText: "New", Checked: 0, pRect: &Slot, Flags: BUTTONFLAG_LEFT, pToolTip: pEditor->m_QuickActionNewMap.Description()))
30 {
31 pEditor->m_QuickActionNewMap.Call();
32 return CUi::POPUP_CLOSE_CURRENT;
33 }
34
35 View.HSplitTop(Cut: 10.0f, pTop: nullptr, pBottom: &View);
36 View.HSplitTop(Cut: 12.0f, pTop: &Slot, pBottom: &View);
37 if(pEditor->DoButton_MenuItem(pId: &pEditor->m_QuickActionLoadMap, pText: "Load", Checked: 0, pRect: &Slot, Flags: BUTTONFLAG_LEFT, pToolTip: pEditor->m_QuickActionLoadMap.Description()))
38 {
39 pEditor->m_QuickActionLoadMap.Call();
40 return CUi::POPUP_CLOSE_CURRENT;
41 }
42
43 View.HSplitTop(Cut: 2.0f, pTop: nullptr, pBottom: &View);
44 View.HSplitTop(Cut: 12.0f, pTop: &Slot, pBottom: &View);
45 if(pEditor->DoButton_MenuItem(pId: &pEditor->m_QuickActionLoadIngameMap, pText: pEditor->m_QuickActionLoadIngameMap.Label(), Checked: pEditor->m_QuickActionLoadIngameMap.Disabled() ? -1 : 0, pRect: &Slot, Flags: BUTTONFLAG_LEFT, pToolTip: pEditor->m_QuickActionLoadIngameMap.Description()))
46 {
47 pEditor->m_QuickActionLoadIngameMap.Call();
48 return CUi::POPUP_CLOSE_CURRENT;
49 }
50
51 View.HSplitTop(Cut: 10.0f, pTop: nullptr, pBottom: &View);
52 View.HSplitTop(Cut: 12.0f, pTop: &Slot, pBottom: &View);
53 if(pEditor->DoButton_MenuItem(pId: &pEditor->m_QuickActionAppendMap, pText: "Append", Checked: 0, pRect: &Slot, Flags: BUTTONFLAG_LEFT, pToolTip: pEditor->m_QuickActionAppendMap.Description()))
54 {
55 pEditor->m_QuickActionAppendMap.Call();
56 return CUi::POPUP_CLOSE_CURRENT;
57 }
58
59 View.HSplitTop(Cut: 10.0f, pTop: nullptr, pBottom: &View);
60 View.HSplitTop(Cut: 12.0f, pTop: &Slot, pBottom: &View);
61 if(pEditor->DoButton_MenuItem(pId: &pEditor->m_QuickActionSave, pText: pEditor->m_QuickActionSave.Label(), Checked: 0, pRect: &Slot, Flags: BUTTONFLAG_LEFT, pToolTip: pEditor->m_QuickActionSave.Description()))
62 {
63 pEditor->m_QuickActionSave.Call();
64 return CUi::POPUP_CLOSE_CURRENT;
65 }
66
67 View.HSplitTop(Cut: 2.0f, pTop: nullptr, pBottom: &View);
68 View.HSplitTop(Cut: 12.0f, pTop: &Slot, pBottom: &View);
69 if(pEditor->DoButton_MenuItem(pId: &pEditor->m_QuickActionSaveAs, pText: pEditor->m_QuickActionSaveAs.Label(), Checked: 0, pRect: &Slot, Flags: BUTTONFLAG_LEFT, pToolTip: pEditor->m_QuickActionSaveAs.Description()))
70 {
71 pEditor->m_QuickActionSaveAs.Call();
72 return CUi::POPUP_CLOSE_CURRENT;
73 }
74
75 View.HSplitTop(Cut: 2.0f, pTop: nullptr, pBottom: &View);
76 View.HSplitTop(Cut: 12.0f, pTop: &Slot, pBottom: &View);
77 if(pEditor->DoButton_MenuItem(pId: &pEditor->m_QuickActionSaveCopy, pText: pEditor->m_QuickActionSaveCopy.Label(), Checked: 0, pRect: &Slot, Flags: BUTTONFLAG_LEFT, pToolTip: pEditor->m_QuickActionSaveCopy.Description()))
78 {
79 pEditor->m_QuickActionSaveCopy.Call();
80 return CUi::POPUP_CLOSE_CURRENT;
81 }
82
83 View.HSplitTop(Cut: 10.0f, pTop: nullptr, pBottom: &View);
84 View.HSplitTop(Cut: 12.0f, pTop: &Slot, pBottom: &View);
85 if(pEditor->DoButton_MenuItem(pId: &pEditor->m_QuickActionMapDetails, pText: pEditor->m_QuickActionMapDetails.Label(), Checked: 0, pRect: &Slot, Flags: BUTTONFLAG_LEFT, pToolTip: pEditor->m_QuickActionMapDetails.Description()))
86 {
87 pEditor->m_QuickActionMapDetails.Call();
88 return CUi::POPUP_CLOSE_CURRENT;
89 }
90
91 View.HSplitTop(Cut: 2.0f, pTop: nullptr, pBottom: &View);
92 View.HSplitTop(Cut: 12.0f, pTop: &Slot, pBottom: &View);
93 if(pEditor->DoButton_MenuItem(pId: &pEditor->m_QuickActionTestMapLocally, pText: pEditor->m_QuickActionTestMapLocally.Label(), Checked: 0, pRect: &Slot, Flags: BUTTONFLAG_LEFT, pToolTip: pEditor->m_QuickActionTestMapLocally.Description()))
94 {
95 pEditor->m_QuickActionTestMapLocally.Call();
96 return CUi::POPUP_CLOSE_CURRENT;
97 }
98
99 View.HSplitTop(Cut: 10.0f, pTop: nullptr, pBottom: &View);
100 View.HSplitTop(Cut: 12.0f, pTop: &Slot, pBottom: &View);
101 if(pEditor->DoButton_MenuItem(pId: &pEditor->m_QuickActionCloseMap, pText: pEditor->m_QuickActionCloseMap.Label(), Checked: 0, pRect: &Slot, Flags: BUTTONFLAG_LEFT, pToolTip: pEditor->m_QuickActionCloseMap.Description()))
102 {
103 pEditor->m_QuickActionCloseMap.Call();
104 return CUi::POPUP_CLOSE_CURRENT;
105 }
106
107 View.HSplitTop(Cut: 10.0f, pTop: nullptr, pBottom: &View);
108 View.HSplitTop(Cut: 12.0f, pTop: &Slot, pBottom: &View);
109 if(pEditor->DoButton_MenuItem(pId: &pEditor->m_QuickActionExit, pText: pEditor->m_QuickActionExit.Label(), Checked: 0, pRect: &Slot, Flags: BUTTONFLAG_LEFT, pToolTip: pEditor->m_QuickActionExit.Description()))
110 {
111 pEditor->m_QuickActionExit.Call();
112 return CUi::POPUP_CLOSE_CURRENT;
113 }
114
115 return CUi::POPUP_KEEP_OPEN;
116}
117
118CUi::EPopupMenuFunctionResult CEditor::PopupMenuTools(void *pContext, CUIRect View, bool Active)
119{
120 CEditor *pEditor = static_cast<CEditor *>(pContext);
121
122 CUIRect Slot;
123 View.HSplitTop(Cut: 12.0f, pTop: &Slot, pBottom: &View);
124 static int s_RemoveUnusedEnvelopesButton = 0;
125 static CUi::SConfirmPopupContext s_ConfirmPopupContext;
126 if(pEditor->DoButton_MenuItem(pId: &s_RemoveUnusedEnvelopesButton, pText: "Remove unused envelopes", Checked: 0, pRect: &Slot, Flags: BUTTONFLAG_LEFT, pToolTip: "Remove all unused envelopes from the map."))
127 {
128 s_ConfirmPopupContext.Reset();
129 s_ConfirmPopupContext.YesNoButtons();
130 str_copy(dst&: s_ConfirmPopupContext.m_aMessage, src: "Are you sure that you want to remove all unused envelopes from this map?");
131 pEditor->Ui()->ShowPopupConfirm(X: Slot.x + Slot.w, Y: Slot.y, pContext: &s_ConfirmPopupContext);
132 }
133 if(s_ConfirmPopupContext.m_Result == CUi::SConfirmPopupContext::CONFIRMED)
134 pEditor->Map()->RemoveUnusedEnvelopes();
135 if(s_ConfirmPopupContext.m_Result != CUi::SConfirmPopupContext::UNSET)
136 {
137 s_ConfirmPopupContext.Reset();
138 return CUi::POPUP_CLOSE_CURRENT;
139 }
140
141 static int s_BorderButton = 0;
142 View.HSplitTop(Cut: 2.0f, pTop: nullptr, pBottom: &View);
143 View.HSplitTop(Cut: 12.0f, pTop: &Slot, pBottom: &View);
144 if(pEditor->DoButton_MenuItem(pId: &s_BorderButton, pText: "Place border", Checked: 0, pRect: &Slot, Flags: BUTTONFLAG_LEFT, pToolTip: "Place tiles in a 2-tile wide border at the edges of the selected tile layer."))
145 {
146 std::shared_ptr<CLayerTiles> pT = std::static_pointer_cast<CLayerTiles>(r: pEditor->Map()->SelectedLayerType(Index: 0, Type: LAYERTYPE_TILES));
147 if(pT && !pT->m_HasTele && !pT->m_HasSpeedup && !pT->m_HasSwitch && !pT->m_HasFront && !pT->m_HasTune)
148 {
149 pEditor->m_PopupEventType = POPEVENT_PLACE_BORDER_TILES;
150 pEditor->m_PopupEventActivated = true;
151 }
152 else
153 {
154 pEditor->ShowFileDialogError(pFormat: "No tile layer selected");
155 }
156 }
157
158 View.HSplitTop(Cut: 2.0f, pTop: nullptr, pBottom: &View);
159 View.HSplitTop(Cut: 12.0f, pTop: &Slot, pBottom: &View);
160 if(pEditor->DoButton_MenuItem(pId: &pEditor->m_QuickActionGotoPosition, pText: pEditor->m_QuickActionGotoPosition.Label(), Checked: 0, pRect: &Slot, Flags: BUTTONFLAG_LEFT, pToolTip: pEditor->m_QuickActionGotoPosition.Description()))
161 {
162 pEditor->m_QuickActionGotoPosition.Call();
163 }
164
165 static int s_TileArtButton = 0;
166 View.HSplitTop(Cut: 2.0f, pTop: nullptr, pBottom: &View);
167 View.HSplitTop(Cut: 12.0f, pTop: &Slot, pBottom: &View);
168 if(pEditor->DoButton_MenuItem(pId: &s_TileArtButton, pText: "Add tile art", Checked: 0, pRect: &Slot, Flags: BUTTONFLAG_LEFT, pToolTip: "Generate tile art from image."))
169 {
170 pEditor->m_FileBrowser.ShowFileDialog(StorageType: IStorage::TYPE_ALL, FileType: CFileBrowser::EFileType::IMAGE, pTitle: "Add tile art", pButtonText: "Open", pInitialPath: "mapres", pInitialFilename: "", pfnOpenCallback: CallbackAddTileArt, pOpenCallbackUser: pEditor);
171 return CUi::POPUP_CLOSE_CURRENT;
172 }
173
174 static int s_QuadArtButton = 0;
175 View.HSplitTop(Cut: 2.0f, pTop: nullptr, pBottom: &View);
176 View.HSplitTop(Cut: 12.0f, pTop: &Slot, pBottom: &View);
177 if(pEditor->DoButton_MenuItem(pId: &s_QuadArtButton, pText: "Add quad art", Checked: 0, pRect: &Slot, Flags: BUTTONFLAG_LEFT, pToolTip: "Generate quad art from image."))
178 {
179 pEditor->m_FileBrowser.ShowFileDialog(StorageType: IStorage::TYPE_ALL, FileType: CFileBrowser::EFileType::IMAGE, pTitle: "Add quad art", pButtonText: "Open", pInitialPath: "mapres", pInitialFilename: "", pfnOpenCallback: CallbackAddQuadArt, pOpenCallbackUser: pEditor);
180 return CUi::POPUP_CLOSE_CURRENT;
181 }
182
183 return CUi::POPUP_KEEP_OPEN;
184}
185
186static int EntitiesListdirCallback(const char *pName, int IsDir, int StorageType, void *pUser)
187{
188 CEditor *pEditor = (CEditor *)pUser;
189 if(!IsDir && str_endswith(str: pName, suffix: ".png"))
190 {
191 std::string Name = pName;
192 pEditor->m_vSelectEntitiesFiles.push_back(x: Name.substr(pos: 0, n: Name.length() - 4));
193 }
194
195 return 0;
196}
197
198CUi::EPopupMenuFunctionResult CEditor::PopupMenuSettings(void *pContext, CUIRect View, bool Active)
199{
200 CEditor *pEditor = static_cast<CEditor *>(pContext);
201
202 CUIRect Slot;
203 View.HSplitTop(Cut: 12.0f, pTop: &Slot, pBottom: &View);
204 static int s_EntitiesButtonId = 0;
205 char aButtonText[64];
206 str_format(buffer: aButtonText, buffer_size: sizeof(aButtonText), format: "Entities: %s", pEditor->m_SelectEntitiesImage.c_str());
207 if(pEditor->DoButton_MenuItem(pId: &s_EntitiesButtonId, pText: aButtonText, Checked: 0, pRect: &Slot, Flags: BUTTONFLAG_LEFT, pToolTip: "Choose game layer entities image for different gametypes."))
208 {
209 pEditor->m_vSelectEntitiesFiles.clear();
210 pEditor->Storage()->ListDirectory(Type: IStorage::TYPE_ALL, pPath: "editor/entities", pfnCallback: EntitiesListdirCallback, pUser: pEditor);
211 std::sort(first: pEditor->m_vSelectEntitiesFiles.begin(), last: pEditor->m_vSelectEntitiesFiles.end());
212 pEditor->m_vSelectEntitiesFiles.emplace_back(args: "Custom…");
213
214 static SPopupMenuId s_PopupEntitiesId;
215 pEditor->Ui()->DoPopupMenu(pId: &s_PopupEntitiesId, X: Slot.x, Y: Slot.y + Slot.h, Width: 250, Height: pEditor->m_vSelectEntitiesFiles.size() * 14.0f + 10.0f, pContext: pEditor, pfnFunc: PopupEntities);
216 }
217
218 View.HSplitTop(Cut: 2.0f, pTop: nullptr, pBottom: &View);
219 View.HSplitTop(Cut: 12.0f, pTop: &Slot, pBottom: &View);
220 {
221 Slot.VMargin(Cut: 5.0f, pOtherRect: &Slot);
222
223 CUIRect Label, Selector;
224 Slot.VSplitMid(pLeft: &Label, pRight: &Selector);
225 CUIRect No, Yes;
226 Selector.VSplitMid(pLeft: &No, pRight: &Yes);
227
228 pEditor->Ui()->DoLabel(pRect: &Label, pText: "Brush coloring", Size: 10.0f, Align: TEXTALIGN_ML);
229 static int s_ButtonNo = 0;
230 static int s_ButtonYes = 0;
231 if(pEditor->DoButton_Ex(pId: &s_ButtonNo, pText: "No", Checked: !pEditor->m_BrushColorEnabled, pRect: &No, Flags: BUTTONFLAG_LEFT, pToolTip: "Disable brush coloring.", Corners: IGraphics::CORNER_L))
232 {
233 pEditor->m_BrushColorEnabled = false;
234 }
235 if(pEditor->DoButton_Ex(pId: &s_ButtonYes, pText: "Yes", Checked: pEditor->m_BrushColorEnabled, pRect: &Yes, Flags: BUTTONFLAG_LEFT, pToolTip: "Enable brush coloring.", Corners: IGraphics::CORNER_R))
236 {
237 pEditor->m_BrushColorEnabled = true;
238 }
239 }
240
241 View.HSplitTop(Cut: 2.0f, pTop: nullptr, pBottom: &View);
242 View.HSplitTop(Cut: 12.0f, pTop: &Slot, pBottom: &View);
243 {
244 Slot.VMargin(Cut: 5.0f, pOtherRect: &Slot);
245
246 CUIRect Label, Selector;
247 Slot.VSplitMid(pLeft: &Label, pRight: &Selector);
248 CUIRect No, Yes;
249 Selector.VSplitMid(pLeft: &No, pRight: &Yes);
250
251 pEditor->Ui()->DoLabel(pRect: &Label, pText: "Allow unused", Size: 10.0f, Align: TEXTALIGN_ML);
252 if(pEditor->m_AllowPlaceUnusedTiles != EUnusedEntities::ALLOWED_IMPLICIT)
253 {
254 static int s_ButtonNo = 0;
255 static int s_ButtonYes = 0;
256 if(pEditor->DoButton_Ex(pId: &s_ButtonNo, pText: "No", Checked: pEditor->m_AllowPlaceUnusedTiles == EUnusedEntities::NOT_ALLOWED, pRect: &No, Flags: BUTTONFLAG_LEFT, pToolTip: "[Ctrl+U] Disallow placing unused tiles.", Corners: IGraphics::CORNER_L))
257 {
258 pEditor->m_AllowPlaceUnusedTiles = EUnusedEntities::NOT_ALLOWED;
259 }
260 if(pEditor->DoButton_Ex(pId: &s_ButtonYes, pText: "Yes", Checked: pEditor->m_AllowPlaceUnusedTiles == EUnusedEntities::ALLOWED_EXPLICIT, pRect: &Yes, Flags: BUTTONFLAG_LEFT, pToolTip: "[Ctrl+U] Allow placing unused tiles.", Corners: IGraphics::CORNER_R))
261 {
262 pEditor->m_AllowPlaceUnusedTiles = EUnusedEntities::ALLOWED_EXPLICIT;
263 }
264 }
265 }
266
267 View.HSplitTop(Cut: 2.0f, pTop: nullptr, pBottom: &View);
268 View.HSplitTop(Cut: 12.0f, pTop: &Slot, pBottom: &View);
269 {
270 Slot.VMargin(Cut: 5.0f, pOtherRect: &Slot);
271
272 CUIRect Label, Selector;
273 Slot.VSplitMid(pLeft: &Label, pRight: &Selector);
274 CUIRect Off, Dec, Hex;
275 Selector.VSplitLeft(Cut: Selector.w / 3.0f, pLeft: &Off, pRight: &Selector);
276 Selector.VSplitMid(pLeft: &Dec, pRight: &Hex);
277
278 pEditor->Ui()->DoLabel(pRect: &Label, pText: "Show info", Size: 10.0f, Align: TEXTALIGN_ML);
279 static int s_ButtonOff = 0;
280 static int s_ButtonDec = 0;
281 static int s_ButtonHex = 0;
282 CQuickAction *pAction = &pEditor->m_QuickActionShowInfoOff;
283 if(pEditor->DoButton_Ex(pId: &s_ButtonOff, pText: pAction->LabelShort(), Checked: pAction->Active(), pRect: &Off, Flags: BUTTONFLAG_LEFT, pToolTip: pAction->Description(), Corners: IGraphics::CORNER_L))
284 {
285 pAction->Call();
286 }
287 pAction = &pEditor->m_QuickActionShowInfoDec;
288 if(pEditor->DoButton_Ex(pId: &s_ButtonDec, pText: pAction->LabelShort(), Checked: pAction->Active(), pRect: &Dec, Flags: BUTTONFLAG_LEFT, pToolTip: pAction->Description(), Corners: IGraphics::CORNER_NONE))
289 {
290 pAction->Call();
291 }
292 pAction = &pEditor->m_QuickActionShowInfoHex;
293 if(pEditor->DoButton_Ex(pId: &s_ButtonHex, pText: pAction->LabelShort(), Checked: pAction->Active(), pRect: &Hex, Flags: BUTTONFLAG_LEFT, pToolTip: pAction->Description(), Corners: IGraphics::CORNER_R))
294 {
295 pAction->Call();
296 }
297 }
298
299 View.HSplitTop(Cut: 2.0f, pTop: nullptr, pBottom: &View);
300 View.HSplitTop(Cut: 12.0f, pTop: &Slot, pBottom: &View);
301 {
302 Slot.VMargin(Cut: 5.0f, pOtherRect: &Slot);
303
304 CUIRect Label, Selector;
305 Slot.VSplitMid(pLeft: &Label, pRight: &Selector);
306 CUIRect No, Yes;
307 Selector.VSplitMid(pLeft: &No, pRight: &Yes);
308
309 pEditor->Ui()->DoLabel(pRect: &Label, pText: "Preview quad envelopes", Size: 10.0f, Align: TEXTALIGN_ML);
310
311 static int s_ButtonNo = 0;
312 static int s_ButtonYes = 0;
313 if(pEditor->DoButton_Ex(pId: &s_ButtonNo, pText: "No", Checked: !pEditor->m_ShowEnvelopePreview, pRect: &No, Flags: BUTTONFLAG_LEFT, pToolTip: "Do not preview the paths of quads with a position envelope when a quad layer is selected.", Corners: IGraphics::CORNER_L))
314 {
315 pEditor->m_ShowEnvelopePreview = false;
316 pEditor->m_ActiveEnvelopePreview = EEnvelopePreview::NONE;
317 }
318 if(pEditor->DoButton_Ex(pId: &s_ButtonYes, pText: "Yes", Checked: pEditor->m_ShowEnvelopePreview, pRect: &Yes, Flags: BUTTONFLAG_LEFT, pToolTip: "Preview the paths of quads with a position envelope when a quad layer is selected.", Corners: IGraphics::CORNER_R))
319 {
320 pEditor->m_ShowEnvelopePreview = true;
321 pEditor->m_ActiveEnvelopePreview = EEnvelopePreview::NONE;
322 }
323 }
324
325 View.HSplitTop(Cut: 2.0f, pTop: nullptr, pBottom: &View);
326 View.HSplitTop(Cut: 12.0f, pTop: &Slot, pBottom: &View);
327 {
328 Slot.VMargin(Cut: 5.0f, pOtherRect: &Slot);
329
330 CUIRect Label, Selector;
331 Slot.VSplitMid(pLeft: &Label, pRight: &Selector);
332 CUIRect No, Yes;
333 Selector.VSplitMid(pLeft: &No, pRight: &Yes);
334
335 pEditor->Ui()->DoLabel(pRect: &Label, pText: "Align quads", Size: 10.0f, Align: TEXTALIGN_ML);
336
337 static int s_ButtonNo = 0;
338 static int s_ButtonYes = 0;
339 if(pEditor->DoButton_Ex(pId: &s_ButtonNo, pText: "No", Checked: !g_Config.m_EdAlignQuads, pRect: &No, Flags: BUTTONFLAG_LEFT, pToolTip: "Do not perform quad alignment to other quads/points when moving quads.", Corners: IGraphics::CORNER_L))
340 {
341 g_Config.m_EdAlignQuads = false;
342 }
343 if(pEditor->DoButton_Ex(pId: &s_ButtonYes, pText: "Yes", Checked: g_Config.m_EdAlignQuads, pRect: &Yes, Flags: BUTTONFLAG_LEFT, pToolTip: "Allow quad alignment to other quads/points when moving quads.", Corners: IGraphics::CORNER_R))
344 {
345 g_Config.m_EdAlignQuads = true;
346 }
347 }
348
349 View.HSplitTop(Cut: 2.0f, pTop: nullptr, pBottom: &View);
350 View.HSplitTop(Cut: 12.0f, pTop: &Slot, pBottom: &View);
351 {
352 Slot.VMargin(Cut: 5.0f, pOtherRect: &Slot);
353
354 CUIRect Label, Selector;
355 Slot.VSplitMid(pLeft: &Label, pRight: &Selector);
356 CUIRect No, Yes;
357 Selector.VSplitMid(pLeft: &No, pRight: &Yes);
358
359 pEditor->Ui()->DoLabel(pRect: &Label, pText: "Show quads bounds", Size: 10.0f, Align: TEXTALIGN_ML);
360
361 static int s_ButtonNo = 0;
362 static int s_ButtonYes = 0;
363 if(pEditor->DoButton_Ex(pId: &s_ButtonNo, pText: "No", Checked: !g_Config.m_EdShowQuadsRect, pRect: &No, Flags: BUTTONFLAG_LEFT, pToolTip: "Do not show quad bounds when moving quads.", Corners: IGraphics::CORNER_L))
364 {
365 g_Config.m_EdShowQuadsRect = false;
366 }
367 if(pEditor->DoButton_Ex(pId: &s_ButtonYes, pText: "Yes", Checked: g_Config.m_EdShowQuadsRect, pRect: &Yes, Flags: BUTTONFLAG_LEFT, pToolTip: "Show quad bounds when moving quads.", Corners: IGraphics::CORNER_R))
368 {
369 g_Config.m_EdShowQuadsRect = true;
370 }
371 }
372
373 View.HSplitTop(Cut: 2.0f, pTop: nullptr, pBottom: &View);
374 View.HSplitTop(Cut: 12.0f, pTop: &Slot, pBottom: &View);
375 {
376 Slot.VMargin(Cut: 5.0f, pOtherRect: &Slot);
377
378 CUIRect Label, Selector;
379 Slot.VSplitMid(pLeft: &Label, pRight: &Selector);
380 CUIRect No, Yes;
381 Selector.VSplitMid(pLeft: &No, pRight: &Yes);
382
383 pEditor->Ui()->DoLabel(pRect: &Label, pText: "Auto map reload", Size: 10.0f, Align: TEXTALIGN_ML);
384
385 static int s_ButtonNo = 0;
386 static int s_ButtonYes = 0;
387 if(pEditor->DoButton_Ex(pId: &s_ButtonNo, pText: "No", Checked: !g_Config.m_EdAutoMapReload, pRect: &No, Flags: BUTTONFLAG_LEFT, pToolTip: "Do not run 'hot_reload' on the local server while rcon authed on map save.", Corners: IGraphics::CORNER_L))
388 {
389 g_Config.m_EdAutoMapReload = false;
390 }
391 if(pEditor->DoButton_Ex(pId: &s_ButtonYes, pText: "Yes", Checked: g_Config.m_EdAutoMapReload, pRect: &Yes, Flags: BUTTONFLAG_LEFT, pToolTip: "Run 'hot_reload' on the local server while rcon authed on map save.", Corners: IGraphics::CORNER_R))
392 {
393 g_Config.m_EdAutoMapReload = true;
394 }
395 }
396
397 View.HSplitTop(Cut: 2.0f, pTop: nullptr, pBottom: &View);
398 View.HSplitTop(Cut: 12.0f, pTop: &Slot, pBottom: &View);
399 {
400 Slot.VMargin(Cut: 5.0f, pOtherRect: &Slot);
401
402 CUIRect Label, Selector;
403 Slot.VSplitMid(pLeft: &Label, pRight: &Selector);
404 CUIRect No, Yes;
405 Selector.VSplitMid(pLeft: &No, pRight: &Yes);
406
407 pEditor->Ui()->DoLabel(pRect: &Label, pText: "Select layers by tile", Size: 10.0f, Align: TEXTALIGN_ML);
408
409 static int s_ButtonNo = 0;
410 static int s_ButtonYes = 0;
411 if(pEditor->DoButton_Ex(pId: &s_ButtonNo, pText: "No", Checked: !g_Config.m_EdLayerSelector, pRect: &No, Flags: BUTTONFLAG_LEFT, pToolTip: "Do not select layers when ctrl+right clicking on a tile.", Corners: IGraphics::CORNER_L))
412 {
413 g_Config.m_EdLayerSelector = false;
414 }
415 if(pEditor->DoButton_Ex(pId: &s_ButtonYes, pText: "Yes", Checked: g_Config.m_EdLayerSelector, pRect: &Yes, Flags: BUTTONFLAG_LEFT, pToolTip: "Select layers when ctrl+right clicking on a tile.", Corners: IGraphics::CORNER_R))
416 {
417 g_Config.m_EdLayerSelector = true;
418 }
419 }
420
421 View.HSplitTop(Cut: 2.0f, pTop: nullptr, pBottom: &View);
422 View.HSplitTop(Cut: 12.0f, pTop: &Slot, pBottom: &View);
423 {
424 Slot.VMargin(Cut: 5.0f, pOtherRect: &Slot);
425
426 CUIRect Label, Selector;
427 Slot.VSplitMid(pLeft: &Label, pRight: &Selector);
428 CUIRect No, Yes;
429 Selector.VSplitMid(pLeft: &No, pRight: &Yes);
430
431 pEditor->Ui()->DoLabel(pRect: &Label, pText: "Show ingame entities", Size: 10.0f, Align: TEXTALIGN_ML);
432
433 static int s_ButtonNo = 0;
434 static int s_ButtonYes = 0;
435 if(pEditor->DoButton_Ex(pId: &s_ButtonNo, pText: "No", Checked: !g_Config.m_EdShowIngameEntities, pRect: &No, Flags: BUTTONFLAG_LEFT, pToolTip: "Do not show how weapons, shields, hearts and flags appear ingame.", Corners: IGraphics::CORNER_L))
436 {
437 g_Config.m_EdShowIngameEntities = false;
438 }
439 if(pEditor->DoButton_Ex(pId: &s_ButtonYes, pText: "Yes", Checked: g_Config.m_EdShowIngameEntities, pRect: &Yes, Flags: BUTTONFLAG_LEFT, pToolTip: "Show how weapons, shields, hearts and flags appear ingame.", Corners: IGraphics::CORNER_R))
440 {
441 g_Config.m_EdShowIngameEntities = true;
442 }
443 }
444
445 return CUi::POPUP_KEEP_OPEN;
446}
447
448CUi::EPopupMenuFunctionResult CEditor::CPopupMapTab::Render(void *pContext, CUIRect View, bool Active)
449{
450 CPopupMapTab *pPopupMapTab = static_cast<CPopupMapTab *>(pContext);
451 CEditor *pEditor = pPopupMapTab->m_pEditor;
452
453 const size_t SelectedMapIndex = pPopupMapTab->m_SelectedMap;
454 const auto &pSelectedMap = pEditor->m_vpMaps[SelectedMapIndex];
455 const bool Saving = pEditor->IsSaving(pFilename: pSelectedMap->m_aFilename);
456 const bool Saved = pSelectedMap->m_aFilename[0] != '\0';
457
458 CUIRect Slot;
459 View.HSplitTop(Cut: 12.0f, pTop: &Slot, pBottom: &View);
460 if(pEditor->DoButton_MenuItem(pId: &pPopupMapTab->m_CloseButtonId, pText: "Close", Checked: Saving ? -1 : 0, pRect: &Slot, Flags: BUTTONFLAG_LEFT, pToolTip: "Close this map."))
461 {
462 pEditor->CloseMap(Index: SelectedMapIndex, Confirm: true);
463 return CUi::POPUP_CLOSE_CURRENT;
464 }
465
466 View.HSplitTop(Cut: 10.0f, pTop: nullptr, pBottom: &View);
467 View.HSplitTop(Cut: 12.0f, pTop: &Slot, pBottom: &View);
468 if(pEditor->DoButton_MenuItem(pId: &pPopupMapTab->m_CopyNameButtonId, pText: "Copy name", Checked: Saved ? 0 : -1, pRect: &Slot, Flags: BUTTONFLAG_LEFT, pToolTip: "Copy the name of this map to the clipboard."))
469 {
470 char aFilename[IO_MAX_PATH_LENGTH];
471 fs_split_file_extension(filename: fs_filename(path: pSelectedMap->m_aFilename), name: aFilename, name_size: sizeof(aFilename));
472 pEditor->Input()->SetClipboardText(aFilename);
473 return CUi::POPUP_CLOSE_CURRENT;
474 }
475
476 View.HSplitTop(Cut: 2.0f, pTop: nullptr, pBottom: &View);
477 View.HSplitTop(Cut: 12.0f, pTop: &Slot, pBottom: &View);
478 if(pEditor->DoButton_MenuItem(pId: &pPopupMapTab->m_CopyPathButtonId, pText: "Copy path", Checked: Saved ? 0 : -1, pRect: &Slot, Flags: BUTTONFLAG_LEFT, pToolTip: "Copy the path of this map to the clipboard."))
479 {
480 pEditor->Input()->SetClipboardText(pSelectedMap->m_aFilename);
481 return CUi::POPUP_CLOSE_CURRENT;
482 }
483
484 View.HSplitTop(Cut: 10.0f, pTop: nullptr, pBottom: &View);
485 View.HSplitTop(Cut: 12.0f, pTop: &Slot, pBottom: &View);
486 if(pEditor->DoButton_MenuItem(pId: &pPopupMapTab->m_ShowFileButtonId, pText: "Show file", Checked: Saved ? 0 : -1, pRect: &Slot, Flags: BUTTONFLAG_LEFT, pToolTip: "Show this map in the file browser."))
487 {
488 bool FoundMap = false;
489 for(int CheckStorageType = IStorage::TYPE_SAVE; CheckStorageType < pEditor->Storage()->NumPaths(); ++CheckStorageType)
490 {
491 if(pEditor->Storage()->FileExists(pFilename: pSelectedMap->m_aFilename, Type: CheckStorageType))
492 {
493 // TODO: Select the map file directly instead of opening the parent folder. See https://github.com/ddnet/ddnet/issues/11334
494 char aParentDirectory[IO_MAX_PATH_LENGTH];
495 str_copy(dst&: aParentDirectory, src: pSelectedMap->m_aFilename);
496 if(fs_parent_dir(path: aParentDirectory) != 0)
497 {
498 pEditor->ShowFileDialogError(pFormat: "Failed to determine parent folder for map file '%s'.", pSelectedMap->m_aFilename);
499 FoundMap = true;
500 break;
501 }
502 char aCompletePath[IO_MAX_PATH_LENGTH];
503 pEditor->Storage()->GetCompletePath(Type: CheckStorageType, pDir: aParentDirectory, pBuffer: aCompletePath, BufferSize: sizeof(aCompletePath));
504 if(!pEditor->Client()->ViewFile(pFilename: aCompletePath))
505 {
506 pEditor->ShowFileDialogError(pFormat: "Failed to open the folder '%s'.", aCompletePath);
507 }
508 FoundMap = true;
509 break;
510 }
511 }
512 if(!FoundMap)
513 {
514 pEditor->ShowFileDialogError(pFormat: "The map file '%s' could not be found.", pSelectedMap->m_aFilename);
515 }
516 return CUi::POPUP_CLOSE_CURRENT;
517 }
518
519 return CUi::POPUP_KEEP_OPEN;
520}
521
522CUi::EPopupMenuFunctionResult CEditor::PopupGroup(void *pContext, CUIRect View, bool Active)
523{
524 CEditor *pEditor = static_cast<CEditor *>(pContext);
525
526 // remove group button
527 CUIRect Button;
528 View.HSplitBottom(Cut: 12.0f, pTop: &View, pBottom: &Button);
529 static int s_DeleteButton = 0;
530
531 // don't allow deletion of game group
532 if(pEditor->Map()->m_pGameGroup != pEditor->Map()->SelectedGroup())
533 {
534 if(pEditor->DoButton_Editor(pId: &s_DeleteButton, pText: "Delete group", Checked: 0, pRect: &Button, Flags: BUTTONFLAG_LEFT, pToolTip: "Delete the group."))
535 {
536 pEditor->Map()->m_EditorHistory.RecordAction(pAction: std::make_shared<CEditorActionGroup>(args: pEditor->Map(), args&: pEditor->Map()->m_SelectedGroup, args: true));
537 pEditor->Map()->DeleteGroup(Index: pEditor->Map()->m_SelectedGroup);
538 pEditor->Map()->m_SelectedGroup = std::max(a: 0, b: pEditor->Map()->m_SelectedGroup - 1);
539 return CUi::POPUP_CLOSE_CURRENT;
540 }
541 }
542 else
543 {
544 if(pEditor->DoButton_Editor(pId: &s_DeleteButton, pText: "Clean up game tiles", Checked: 0, pRect: &Button, Flags: BUTTONFLAG_LEFT, pToolTip: "Remove game tiles that aren't based on a layer."))
545 {
546 // gather all tile layers
547 std::vector<std::shared_ptr<CLayerTiles>> vpLayers;
548 int GameLayerIndex = -1;
549 for(int LayerIndex = 0; LayerIndex < (int)pEditor->Map()->m_pGameGroup->m_vpLayers.size(); LayerIndex++)
550 {
551 auto &pLayer = pEditor->Map()->m_pGameGroup->m_vpLayers.at(n: LayerIndex);
552 if(pLayer != pEditor->Map()->m_pGameLayer && pLayer->m_Type == LAYERTYPE_TILES)
553 vpLayers.push_back(x: std::static_pointer_cast<CLayerTiles>(r: pLayer));
554 else if(pLayer == pEditor->Map()->m_pGameLayer)
555 GameLayerIndex = LayerIndex;
556 }
557
558 // search for unneeded game tiles
559 std::shared_ptr<CLayerTiles> pGameLayer = pEditor->Map()->m_pGameLayer;
560 for(int y = 0; y < pGameLayer->m_Height; ++y)
561 {
562 for(int x = 0; x < pGameLayer->m_Width; ++x)
563 {
564 if(pGameLayer->m_pTiles[y * pGameLayer->m_Width + x].m_Index > static_cast<unsigned char>(TILE_NOHOOK))
565 continue;
566
567 bool Found = false;
568 for(const auto &pLayer : vpLayers)
569 {
570 if(x < pLayer->m_Width && y < pLayer->m_Height && pLayer->m_pTiles[y * pLayer->m_Width + x].m_Index)
571 {
572 Found = true;
573 break;
574 }
575 }
576
577 CTile Tile = pGameLayer->GetTile(x, y);
578 if(!Found && Tile.m_Index != TILE_AIR)
579 {
580 Tile.m_Index = TILE_AIR;
581 pGameLayer->SetTile(x, y, Tile);
582 pEditor->Map()->OnModify();
583 }
584 }
585 }
586
587 if(!pGameLayer->m_TilesHistory.empty())
588 {
589 if(GameLayerIndex == -1)
590 {
591 dbg_msg(sys: "editor", fmt: "failed to record action (GameLayerIndex not found)");
592 }
593 else
594 {
595 // record undo
596 pEditor->Map()->m_EditorHistory.RecordAction(pAction: std::make_shared<CEditorActionTileChanges>(args: pEditor->Map(), args&: pEditor->Map()->m_SelectedGroup, args&: GameLayerIndex, args: "Clean up game tiles", args&: pGameLayer->m_TilesHistory));
597 }
598 pGameLayer->ClearHistory();
599 }
600
601 return CUi::POPUP_CLOSE_CURRENT;
602 }
603 }
604
605 if(pEditor->Map()->SelectedGroup()->m_GameGroup && !pEditor->Map()->m_pTeleLayer)
606 {
607 // new tele layer
608 View.HSplitBottom(Cut: 5.0f, pTop: &View, pBottom: nullptr);
609 View.HSplitBottom(Cut: 12.0f, pTop: &View, pBottom: &Button);
610 if(pEditor->DoButton_Editor(pId: &pEditor->m_QuickActionAddTeleLayer, pText: pEditor->m_QuickActionAddTeleLayer.Label(), Checked: 0, pRect: &Button, Flags: BUTTONFLAG_LEFT, pToolTip: pEditor->m_QuickActionAddTeleLayer.Description()))
611 {
612 pEditor->m_QuickActionAddTeleLayer.Call();
613 return CUi::POPUP_CLOSE_CURRENT;
614 }
615 }
616
617 if(pEditor->Map()->SelectedGroup()->m_GameGroup && !pEditor->Map()->m_pSpeedupLayer)
618 {
619 // new speedup layer
620 View.HSplitBottom(Cut: 5.0f, pTop: &View, pBottom: nullptr);
621 View.HSplitBottom(Cut: 12.0f, pTop: &View, pBottom: &Button);
622 if(pEditor->DoButton_Editor(pId: &pEditor->m_QuickActionAddSpeedupLayer, pText: pEditor->m_QuickActionAddSpeedupLayer.Label(), Checked: 0, pRect: &Button, Flags: BUTTONFLAG_LEFT, pToolTip: pEditor->m_QuickActionAddSpeedupLayer.Description()))
623 {
624 pEditor->m_QuickActionAddSpeedupLayer.Call();
625 return CUi::POPUP_CLOSE_CURRENT;
626 }
627 }
628
629 if(pEditor->Map()->SelectedGroup()->m_GameGroup && !pEditor->Map()->m_pTuneLayer)
630 {
631 // new tune layer
632 View.HSplitBottom(Cut: 5.0f, pTop: &View, pBottom: nullptr);
633 View.HSplitBottom(Cut: 12.0f, pTop: &View, pBottom: &Button);
634 if(pEditor->DoButton_Editor(pId: &pEditor->m_QuickActionAddTuneLayer, pText: pEditor->m_QuickActionAddTuneLayer.Label(), Checked: 0, pRect: &Button, Flags: BUTTONFLAG_LEFT, pToolTip: pEditor->m_QuickActionAddTuneLayer.Description()))
635 {
636 pEditor->m_QuickActionAddTuneLayer.Call();
637 return CUi::POPUP_CLOSE_CURRENT;
638 }
639 }
640
641 if(pEditor->Map()->SelectedGroup()->m_GameGroup && !pEditor->Map()->m_pFrontLayer)
642 {
643 // new front layer
644 View.HSplitBottom(Cut: 5.0f, pTop: &View, pBottom: nullptr);
645 View.HSplitBottom(Cut: 12.0f, pTop: &View, pBottom: &Button);
646 if(pEditor->DoButton_Editor(pId: &pEditor->m_QuickActionAddFrontLayer, pText: pEditor->m_QuickActionAddFrontLayer.Label(), Checked: 0, pRect: &Button, Flags: BUTTONFLAG_LEFT, pToolTip: pEditor->m_QuickActionAddFrontLayer.Description()))
647 {
648 pEditor->m_QuickActionAddFrontLayer.Call();
649 return CUi::POPUP_CLOSE_CURRENT;
650 }
651 }
652
653 if(pEditor->Map()->SelectedGroup()->m_GameGroup && !pEditor->Map()->m_pSwitchLayer)
654 {
655 // new Switch layer
656 View.HSplitBottom(Cut: 5.0f, pTop: &View, pBottom: nullptr);
657 View.HSplitBottom(Cut: 12.0f, pTop: &View, pBottom: &Button);
658 if(pEditor->DoButton_Editor(pId: &pEditor->m_QuickActionAddSwitchLayer, pText: pEditor->m_QuickActionAddSwitchLayer.Label(), Checked: 0, pRect: &Button, Flags: BUTTONFLAG_LEFT, pToolTip: pEditor->m_QuickActionAddSwitchLayer.Description()))
659 {
660 pEditor->m_QuickActionAddSwitchLayer.Call();
661 return CUi::POPUP_CLOSE_CURRENT;
662 }
663 }
664
665 // new quad layer
666 View.HSplitBottom(Cut: 5.0f, pTop: &View, pBottom: nullptr);
667 View.HSplitBottom(Cut: 12.0f, pTop: &View, pBottom: &Button);
668 if(pEditor->DoButton_Editor(pId: &pEditor->m_QuickActionAddQuadsLayer, pText: pEditor->m_QuickActionAddQuadsLayer.Label(), Checked: 0, pRect: &Button, Flags: BUTTONFLAG_LEFT, pToolTip: pEditor->m_QuickActionAddQuadsLayer.Description()))
669 {
670 pEditor->m_QuickActionAddQuadsLayer.Call();
671 return CUi::POPUP_CLOSE_CURRENT;
672 }
673
674 // new tile layer
675 View.HSplitBottom(Cut: 5.0f, pTop: &View, pBottom: nullptr);
676 View.HSplitBottom(Cut: 12.0f, pTop: &View, pBottom: &Button);
677 if(pEditor->DoButton_Editor(pId: &pEditor->m_QuickActionAddTileLayer, pText: pEditor->m_QuickActionAddTileLayer.Label(), Checked: 0, pRect: &Button, Flags: BUTTONFLAG_LEFT, pToolTip: pEditor->m_QuickActionAddTileLayer.Description()))
678 {
679 pEditor->m_QuickActionAddTileLayer.Call();
680 return CUi::POPUP_CLOSE_CURRENT;
681 }
682
683 // new sound layer
684 View.HSplitBottom(Cut: 5.0f, pTop: &View, pBottom: nullptr);
685 View.HSplitBottom(Cut: 12.0f, pTop: &View, pBottom: &Button);
686 if(pEditor->DoButton_Editor(pId: &pEditor->m_QuickActionAddSoundLayer, pText: pEditor->m_QuickActionAddSoundLayer.Label(), Checked: 0, pRect: &Button, Flags: BUTTONFLAG_LEFT, pToolTip: pEditor->m_QuickActionAddSoundLayer.Description()))
687 {
688 pEditor->m_QuickActionAddSoundLayer.Call();
689 return CUi::POPUP_CLOSE_CURRENT;
690 }
691
692 // group name
693 if(!pEditor->Map()->SelectedGroup()->m_GameGroup)
694 {
695 View.HSplitBottom(Cut: 5.0f, pTop: &View, pBottom: nullptr);
696 View.HSplitBottom(Cut: 12.0f, pTop: &View, pBottom: &Button);
697 pEditor->Ui()->DoLabel(pRect: &Button, pText: "Name:", Size: 10.0f, Align: TEXTALIGN_ML);
698 Button.VSplitLeft(Cut: 40.0f, pLeft: nullptr, pRight: &Button);
699 static CLineInput s_NameInput;
700 s_NameInput.SetBuffer(pStr: pEditor->Map()->m_vpGroups[pEditor->Map()->m_SelectedGroup]->m_aName, MaxSize: sizeof(pEditor->Map()->m_vpGroups[pEditor->Map()->m_SelectedGroup]->m_aName));
701 if(pEditor->DoEditBox(pLineInput: &s_NameInput, pRect: &Button, FontSize: 10.0f))
702 pEditor->Map()->OnModify();
703 }
704
705 CProperty aProps[] = {
706 {"Order", pEditor->Map()->m_SelectedGroup, PROPTYPE_INT, 0, (int)pEditor->Map()->m_vpGroups.size() - 1},
707 {"Pos X", -pEditor->Map()->m_vpGroups[pEditor->Map()->m_SelectedGroup]->m_OffsetX, PROPTYPE_INT, -1000000, 1000000},
708 {"Pos Y", -pEditor->Map()->m_vpGroups[pEditor->Map()->m_SelectedGroup]->m_OffsetY, PROPTYPE_INT, -1000000, 1000000},
709 {"Para X", pEditor->Map()->m_vpGroups[pEditor->Map()->m_SelectedGroup]->m_ParallaxX, PROPTYPE_INT, -1000000, 1000000},
710 {"Para Y", pEditor->Map()->m_vpGroups[pEditor->Map()->m_SelectedGroup]->m_ParallaxY, PROPTYPE_INT, -1000000, 1000000},
711 {"Use Clipping", pEditor->Map()->m_vpGroups[pEditor->Map()->m_SelectedGroup]->m_UseClipping, PROPTYPE_BOOL, 0, 1},
712 {"Clip X", pEditor->Map()->m_vpGroups[pEditor->Map()->m_SelectedGroup]->m_ClipX, PROPTYPE_INT, -1000000, 1000000},
713 {"Clip Y", pEditor->Map()->m_vpGroups[pEditor->Map()->m_SelectedGroup]->m_ClipY, PROPTYPE_INT, -1000000, 1000000},
714 {"Clip W", pEditor->Map()->m_vpGroups[pEditor->Map()->m_SelectedGroup]->m_ClipW, PROPTYPE_INT, 0, 1000000},
715 {"Clip H", pEditor->Map()->m_vpGroups[pEditor->Map()->m_SelectedGroup]->m_ClipH, PROPTYPE_INT, 0, 1000000},
716 {nullptr},
717 };
718
719 // cut the properties that aren't needed
720 if(pEditor->Map()->SelectedGroup()->m_GameGroup)
721 aProps[(int)EGroupProp::POS_X].m_pName = nullptr;
722
723 static int s_aIds[(int)EGroupProp::NUM_PROPS] = {0};
724 int NewVal = 0;
725 auto [State, Prop] = pEditor->DoPropertiesWithState<EGroupProp>(pToolbox: &View, pProps: aProps, pIds: s_aIds, pNewVal: &NewVal);
726 if(Prop != EGroupProp::NONE && (State == EEditState::END || State == EEditState::ONE_GO))
727 {
728 pEditor->Map()->OnModify();
729 }
730
731 pEditor->Map()->m_LayerGroupPropTracker.Begin(pObject: pEditor->Map()->SelectedGroup().get(), Prop, State);
732
733 if(Prop == EGroupProp::ORDER)
734 {
735 pEditor->Map()->m_SelectedGroup = pEditor->Map()->MoveGroup(IndexFrom: pEditor->Map()->m_SelectedGroup, IndexTo: NewVal);
736 }
737
738 // these can not be changed on the game group
739 if(!pEditor->Map()->SelectedGroup()->m_GameGroup)
740 {
741 if(Prop == EGroupProp::PARA_X)
742 {
743 pEditor->Map()->m_vpGroups[pEditor->Map()->m_SelectedGroup]->m_ParallaxX = NewVal;
744 }
745 else if(Prop == EGroupProp::PARA_Y)
746 {
747 pEditor->Map()->m_vpGroups[pEditor->Map()->m_SelectedGroup]->m_ParallaxY = NewVal;
748 }
749 else if(Prop == EGroupProp::POS_X)
750 {
751 pEditor->Map()->m_vpGroups[pEditor->Map()->m_SelectedGroup]->m_OffsetX = -NewVal;
752 }
753 else if(Prop == EGroupProp::POS_Y)
754 {
755 pEditor->Map()->m_vpGroups[pEditor->Map()->m_SelectedGroup]->m_OffsetY = -NewVal;
756 }
757 else if(Prop == EGroupProp::USE_CLIPPING)
758 {
759 pEditor->Map()->m_vpGroups[pEditor->Map()->m_SelectedGroup]->m_UseClipping = NewVal;
760 }
761 else if(Prop == EGroupProp::CLIP_X)
762 {
763 pEditor->Map()->m_vpGroups[pEditor->Map()->m_SelectedGroup]->m_ClipX = NewVal;
764 }
765 else if(Prop == EGroupProp::CLIP_Y)
766 {
767 pEditor->Map()->m_vpGroups[pEditor->Map()->m_SelectedGroup]->m_ClipY = NewVal;
768 }
769 else if(Prop == EGroupProp::CLIP_W)
770 {
771 pEditor->Map()->m_vpGroups[pEditor->Map()->m_SelectedGroup]->m_ClipW = NewVal;
772 }
773 else if(Prop == EGroupProp::CLIP_H)
774 {
775 pEditor->Map()->m_vpGroups[pEditor->Map()->m_SelectedGroup]->m_ClipH = NewVal;
776 }
777 }
778
779 pEditor->Map()->m_LayerGroupPropTracker.End(Prop, State);
780
781 return CUi::POPUP_KEEP_OPEN;
782}
783
784CUi::EPopupMenuFunctionResult CEditor::PopupLayer(void *pContext, CUIRect View, bool Active)
785{
786 SLayerPopupContext *pPopup = (SLayerPopupContext *)pContext;
787 CEditor *pEditor = pPopup->m_pEditor;
788
789 std::shared_ptr<CLayerGroup> pCurrentGroup = pEditor->Map()->m_vpGroups[pEditor->Map()->m_SelectedGroup];
790 std::shared_ptr<CLayer> pCurrentLayer = pEditor->Map()->SelectedLayer(Index: 0);
791
792 if(!pCurrentLayer || !pCurrentGroup)
793 return CUi::POPUP_CLOSE_CURRENT;
794
795 if(pPopup->m_vpLayers.size() > 1)
796 {
797 return CLayerTiles::RenderCommonProperties(State&: pPopup->m_CommonPropState, pEditorMap: pEditor->Map(), pToolbox: &View, vpLayers&: pPopup->m_vpLayers, vLayerIndices&: pPopup->m_vLayerIndices);
798 }
799
800 const bool EntitiesLayer = pCurrentLayer->IsEntitiesLayer();
801
802 // delete button
803 if(pEditor->Map()->m_pGameLayer != pCurrentLayer) // entities layers except the game layer can be deleted
804 {
805 CUIRect DeleteButton;
806 View.HSplitBottom(Cut: 12.0f, pTop: &View, pBottom: &DeleteButton);
807 if(pEditor->DoButton_Editor(pId: &pEditor->m_QuickActionDeleteLayer, pText: pEditor->m_QuickActionDeleteLayer.Label(), Checked: 0, pRect: &DeleteButton, Flags: BUTTONFLAG_LEFT, pToolTip: pEditor->m_QuickActionDeleteLayer.Description()))
808 {
809 pEditor->m_QuickActionDeleteLayer.Call();
810 return CUi::POPUP_CLOSE_CURRENT;
811 }
812 }
813
814 // duplicate button
815 if(!EntitiesLayer) // entities layers cannot be duplicated
816 {
817 CUIRect DuplicateButton;
818 View.HSplitBottom(Cut: 4.0f, pTop: &View, pBottom: nullptr);
819 View.HSplitBottom(Cut: 12.0f, pTop: &View, pBottom: &DuplicateButton);
820 static int s_DuplicationButton = 0;
821 if(pEditor->DoButton_Editor(pId: &s_DuplicationButton, pText: "Duplicate layer", Checked: 0, pRect: &DuplicateButton, Flags: BUTTONFLAG_LEFT, pToolTip: "Create an identical copy of the selected layer."))
822 {
823 pEditor->Map()->m_vpGroups[pEditor->Map()->m_SelectedGroup]->DuplicateLayer(Index: pEditor->Map()->m_vSelectedLayers[0]);
824 pEditor->Map()->m_EditorHistory.RecordAction(pAction: std::make_shared<CEditorActionAddLayer>(args: pEditor->Map(), args&: pEditor->Map()->m_SelectedGroup, args: pEditor->Map()->m_vSelectedLayers[0] + 1, args: true));
825 return CUi::POPUP_CLOSE_CURRENT;
826 }
827 }
828
829 // layer name
830 if(!EntitiesLayer) // name cannot be changed for entities layers
831 {
832 CUIRect Label, EditBox;
833 View.HSplitBottom(Cut: 5.0f, pTop: &View, pBottom: nullptr);
834 View.HSplitBottom(Cut: 12.0f, pTop: &View, pBottom: &Label);
835 Label.VSplitLeft(Cut: 40.0f, pLeft: &Label, pRight: &EditBox);
836 pEditor->Ui()->DoLabel(pRect: &Label, pText: "Name:", Size: 10.0f, Align: TEXTALIGN_ML);
837 static CLineInput s_NameInput;
838 s_NameInput.SetBuffer(pStr: pCurrentLayer->m_aName, MaxSize: sizeof(pCurrentLayer->m_aName));
839 if(pEditor->DoEditBox(pLineInput: &s_NameInput, pRect: &EditBox, FontSize: 10.0f))
840 pEditor->Map()->OnModify();
841 }
842
843 // spacing if any button was rendered
844 if(!EntitiesLayer || pEditor->Map()->m_pGameLayer != pCurrentLayer)
845 View.HSplitBottom(Cut: 10.0f, pTop: &View, pBottom: nullptr);
846
847 CProperty aProps[] = {
848 {"Group", pEditor->Map()->m_SelectedGroup, PROPTYPE_INT, 0, (int)pEditor->Map()->m_vpGroups.size() - 1},
849 {"Order", pEditor->Map()->m_vSelectedLayers[0], PROPTYPE_INT, 0, (int)pCurrentGroup->m_vpLayers.size() - 1},
850 {"Detail", pCurrentLayer->m_Flags & LAYERFLAG_DETAIL, PROPTYPE_BOOL, 0, 1},
851 {nullptr},
852 };
853
854 // don't use Group and Detail from the selection if this is an entities layer
855 if(EntitiesLayer)
856 {
857 aProps[0].m_Type = PROPTYPE_NULL;
858 aProps[2].m_Type = PROPTYPE_NULL;
859 }
860
861 static int s_aIds[(int)ELayerProp::NUM_PROPS] = {0};
862 int NewVal = 0;
863 auto [State, Prop] = pEditor->DoPropertiesWithState<ELayerProp>(pToolbox: &View, pProps: aProps, pIds: s_aIds, pNewVal: &NewVal);
864 if(Prop != ELayerProp::NONE && (State == EEditState::END || State == EEditState::ONE_GO))
865 {
866 pEditor->Map()->OnModify();
867 }
868
869 pEditor->Map()->m_LayerPropTracker.Begin(pObject: pCurrentLayer.get(), Prop, State);
870
871 if(Prop == ELayerProp::ORDER)
872 {
873 pEditor->Map()->SelectLayer(LayerIndex: pCurrentGroup->MoveLayer(IndexFrom: pEditor->Map()->m_vSelectedLayers[0], IndexTo: NewVal));
874 }
875 else if(Prop == ELayerProp::GROUP)
876 {
877 if(NewVal >= 0 && (size_t)NewVal < pEditor->Map()->m_vpGroups.size() && NewVal != pEditor->Map()->m_SelectedGroup)
878 {
879 auto Position = std::find(first: pCurrentGroup->m_vpLayers.begin(), last: pCurrentGroup->m_vpLayers.end(), val: pCurrentLayer);
880 if(Position != pCurrentGroup->m_vpLayers.end())
881 pCurrentGroup->m_vpLayers.erase(position: Position);
882 pEditor->Map()->m_vpGroups[NewVal]->m_vpLayers.push_back(x: pCurrentLayer);
883 pEditor->Map()->m_SelectedGroup = NewVal;
884 pEditor->Map()->SelectLayer(LayerIndex: pEditor->Map()->m_vpGroups[NewVal]->m_vpLayers.size() - 1);
885 }
886 }
887 else if(Prop == ELayerProp::HQ)
888 {
889 pCurrentLayer->m_Flags &= ~LAYERFLAG_DETAIL;
890 if(NewVal)
891 pCurrentLayer->m_Flags |= LAYERFLAG_DETAIL;
892 }
893
894 pEditor->Map()->m_LayerPropTracker.End(Prop, State);
895
896 return pCurrentLayer->RenderProperties(pToolbox: &View);
897}
898
899CUi::EPopupMenuFunctionResult CEditor::PopupQuad(void *pContext, CUIRect View, bool Active)
900{
901 CQuadPopupContext *pQuadPopupContext = static_cast<CQuadPopupContext *>(pContext);
902 CEditor *pEditor = pQuadPopupContext->m_pEditor;
903 std::vector<CQuad *> vpQuads = pEditor->Map()->SelectedQuads();
904 if(!in_range<int>(a: pQuadPopupContext->m_SelectedQuadIndex, lower: 0, upper: vpQuads.size() - 1))
905 {
906 return CUi::POPUP_CLOSE_CURRENT;
907 }
908 CQuad *pCurrentQuad = vpQuads[pQuadPopupContext->m_SelectedQuadIndex];
909 std::shared_ptr<CLayerQuads> pLayer = std::static_pointer_cast<CLayerQuads>(r: pEditor->Map()->SelectedLayerType(Index: 0, Type: LAYERTYPE_QUADS));
910
911 CUIRect Button;
912
913 // delete button
914 View.HSplitBottom(Cut: 12.0f, pTop: &View, pBottom: &Button);
915 static int s_DeleteButton = 0;
916 if(pEditor->DoButton_Editor(pId: &s_DeleteButton, pText: "Delete", Checked: 0, pRect: &Button, Flags: BUTTONFLAG_LEFT, pToolTip: "Delete the current quad."))
917 {
918 if(pLayer)
919 {
920 pEditor->Map()->OnModify();
921 pEditor->Map()->DeleteSelectedQuads();
922 }
923 return CUi::POPUP_CLOSE_CURRENT;
924 }
925
926 // aspect ratio button
927 View.HSplitBottom(Cut: 10.0f, pTop: &View, pBottom: nullptr);
928 View.HSplitBottom(Cut: 12.0f, pTop: &View, pBottom: &Button);
929 if(pLayer && pLayer->m_Image >= 0 && (size_t)pLayer->m_Image < pEditor->Map()->m_vpImages.size())
930 {
931 static int s_AspectRatioButton = 0;
932 if(pEditor->DoButton_Editor(pId: &s_AspectRatioButton, pText: "Aspect ratio", Checked: 0, pRect: &Button, Flags: BUTTONFLAG_LEFT, pToolTip: "Resize the current quad based on the aspect ratio of its image."))
933 {
934 pEditor->Map()->m_QuadTracker.BeginQuadTrack(pLayer, vSelectedQuads: pEditor->Map()->m_vSelectedQuads);
935 for(auto &pQuad : vpQuads)
936 {
937 int Top = pQuad->m_aPoints[0].y;
938 int Left = pQuad->m_aPoints[0].x;
939 int Right = pQuad->m_aPoints[0].x;
940
941 for(int k = 1; k < 4; k++)
942 {
943 if(pQuad->m_aPoints[k].y < Top)
944 Top = pQuad->m_aPoints[k].y;
945 if(pQuad->m_aPoints[k].x < Left)
946 Left = pQuad->m_aPoints[k].x;
947 if(pQuad->m_aPoints[k].x > Right)
948 Right = pQuad->m_aPoints[k].x;
949 }
950
951 const int Height = (Right - Left) * pEditor->Map()->m_vpImages[pLayer->m_Image]->m_Height / pEditor->Map()->m_vpImages[pLayer->m_Image]->m_Width;
952
953 pQuad->m_aPoints[0].x = Left;
954 pQuad->m_aPoints[0].y = Top;
955 pQuad->m_aPoints[1].x = Right;
956 pQuad->m_aPoints[1].y = Top;
957 pQuad->m_aPoints[2].x = Left;
958 pQuad->m_aPoints[2].y = Top + Height;
959 pQuad->m_aPoints[3].x = Right;
960 pQuad->m_aPoints[3].y = Top + Height;
961 pEditor->Map()->OnModify();
962 }
963 pEditor->Map()->m_QuadTracker.EndQuadTrack();
964
965 return CUi::POPUP_CLOSE_CURRENT;
966 }
967 }
968
969 // center pivot button
970 View.HSplitBottom(Cut: 6.0f, pTop: &View, pBottom: nullptr);
971 View.HSplitBottom(Cut: 12.0f, pTop: &View, pBottom: &Button);
972 static int s_CenterButton = 0;
973 if(pEditor->DoButton_Editor(pId: &s_CenterButton, pText: "Center pivot", Checked: 0, pRect: &Button, Flags: BUTTONFLAG_LEFT, pToolTip: "Center the pivot of the current quad."))
974 {
975 pEditor->Map()->m_QuadTracker.BeginQuadTrack(pLayer, vSelectedQuads: pEditor->Map()->m_vSelectedQuads);
976 int Top = pCurrentQuad->m_aPoints[0].y;
977 int Left = pCurrentQuad->m_aPoints[0].x;
978 int Bottom = pCurrentQuad->m_aPoints[0].y;
979 int Right = pCurrentQuad->m_aPoints[0].x;
980
981 for(int k = 1; k < 4; k++)
982 {
983 if(pCurrentQuad->m_aPoints[k].y < Top)
984 Top = pCurrentQuad->m_aPoints[k].y;
985 if(pCurrentQuad->m_aPoints[k].x < Left)
986 Left = pCurrentQuad->m_aPoints[k].x;
987 if(pCurrentQuad->m_aPoints[k].y > Bottom)
988 Bottom = pCurrentQuad->m_aPoints[k].y;
989 if(pCurrentQuad->m_aPoints[k].x > Right)
990 Right = pCurrentQuad->m_aPoints[k].x;
991 }
992
993 pCurrentQuad->m_aPoints[4].x = Left + (Right - Left) / 2;
994 pCurrentQuad->m_aPoints[4].y = Top + (Bottom - Top) / 2;
995 pEditor->Map()->m_QuadTracker.EndQuadTrack();
996 pEditor->Map()->OnModify();
997 return CUi::POPUP_CLOSE_CURRENT;
998 }
999
1000 // align button
1001 View.HSplitBottom(Cut: 6.0f, pTop: &View, pBottom: nullptr);
1002 View.HSplitBottom(Cut: 12.0f, pTop: &View, pBottom: &Button);
1003 static int s_AlignButton = 0;
1004 if(pEditor->DoButton_Editor(pId: &s_AlignButton, pText: "Align", Checked: 0, pRect: &Button, Flags: BUTTONFLAG_LEFT, pToolTip: "Align coordinates of the quad points."))
1005 {
1006 pEditor->Map()->m_QuadTracker.BeginQuadTrack(pLayer, vSelectedQuads: pEditor->Map()->m_vSelectedQuads);
1007 for(auto &pQuad : vpQuads)
1008 {
1009 for(int k = 1; k < 4; k++)
1010 {
1011 pQuad->m_aPoints[k].x = 1000.0f * (pQuad->m_aPoints[k].x / 1000);
1012 pQuad->m_aPoints[k].y = 1000.0f * (pQuad->m_aPoints[k].y / 1000);
1013 }
1014 pEditor->Map()->OnModify();
1015 }
1016 pEditor->Map()->m_QuadTracker.EndQuadTrack();
1017 return CUi::POPUP_CLOSE_CURRENT;
1018 }
1019
1020 // square button
1021 View.HSplitBottom(Cut: 6.0f, pTop: &View, pBottom: nullptr);
1022 View.HSplitBottom(Cut: 12.0f, pTop: &View, pBottom: &Button);
1023 static int s_Button = 0;
1024 if(pEditor->DoButton_Editor(pId: &s_Button, pText: "Square", Checked: 0, pRect: &Button, Flags: BUTTONFLAG_LEFT, pToolTip: "Square the current quad."))
1025 {
1026 pEditor->Map()->m_QuadTracker.BeginQuadTrack(pLayer, vSelectedQuads: pEditor->Map()->m_vSelectedQuads);
1027 for(auto &pQuad : vpQuads)
1028 {
1029 int Top = pQuad->m_aPoints[0].y;
1030 int Left = pQuad->m_aPoints[0].x;
1031 int Bottom = pQuad->m_aPoints[0].y;
1032 int Right = pQuad->m_aPoints[0].x;
1033
1034 for(int k = 1; k < 4; k++)
1035 {
1036 if(pQuad->m_aPoints[k].y < Top)
1037 Top = pQuad->m_aPoints[k].y;
1038 if(pQuad->m_aPoints[k].x < Left)
1039 Left = pQuad->m_aPoints[k].x;
1040 if(pQuad->m_aPoints[k].y > Bottom)
1041 Bottom = pQuad->m_aPoints[k].y;
1042 if(pQuad->m_aPoints[k].x > Right)
1043 Right = pQuad->m_aPoints[k].x;
1044 }
1045
1046 pQuad->m_aPoints[0].x = Left;
1047 pQuad->m_aPoints[0].y = Top;
1048 pQuad->m_aPoints[1].x = Right;
1049 pQuad->m_aPoints[1].y = Top;
1050 pQuad->m_aPoints[2].x = Left;
1051 pQuad->m_aPoints[2].y = Bottom;
1052 pQuad->m_aPoints[3].x = Right;
1053 pQuad->m_aPoints[3].y = Bottom;
1054 pEditor->Map()->OnModify();
1055 }
1056 pEditor->Map()->m_QuadTracker.EndQuadTrack();
1057 return CUi::POPUP_CLOSE_CURRENT;
1058 }
1059
1060 // slice button
1061 View.HSplitBottom(Cut: 6.0f, pTop: &View, pBottom: nullptr);
1062 View.HSplitBottom(Cut: 12.0f, pTop: &View, pBottom: &Button);
1063 static int s_SliceButton = 0;
1064 if(pEditor->DoButton_Editor(pId: &s_SliceButton, pText: "Slice", Checked: 0, pRect: &Button, Flags: BUTTONFLAG_LEFT, pToolTip: "Enable quad knife mode."))
1065 {
1066 pEditor->m_QuadKnife.Activate(SelectedQuad: pQuadPopupContext->m_SelectedQuadIndex);
1067 return CUi::POPUP_CLOSE_CURRENT;
1068 }
1069
1070 const int NumQuads = pLayer ? (int)pLayer->m_vQuads.size() : 0;
1071 CProperty aProps[] = {
1072 {"Order", pEditor->Map()->m_vSelectedQuads[pQuadPopupContext->m_SelectedQuadIndex], PROPTYPE_INT, 0, NumQuads},
1073 {"Pos X", fx2i(v: pCurrentQuad->m_aPoints[4].x), PROPTYPE_INT, -1000000, 1000000},
1074 {"Pos Y", fx2i(v: pCurrentQuad->m_aPoints[4].y), PROPTYPE_INT, -1000000, 1000000},
1075 {"Pos. Env", pCurrentQuad->m_PosEnv + 1, PROPTYPE_ENVELOPE, 0, 0},
1076 {"Pos. TO", pCurrentQuad->m_PosEnvOffset, PROPTYPE_INT, -1000000, 1000000},
1077 {"Color", pQuadPopupContext->m_Color, PROPTYPE_COLOR, 0, 0},
1078 {"Color Env", pCurrentQuad->m_ColorEnv + 1, PROPTYPE_ENVELOPE, 0, 0},
1079 {"Color TO", pCurrentQuad->m_ColorEnvOffset, PROPTYPE_INT, -1000000, 1000000},
1080 {nullptr},
1081 };
1082
1083 static int s_aIds[(int)EQuadProp::NUM_PROPS] = {0};
1084 int NewVal = 0;
1085 auto [State, Prop] = pEditor->DoPropertiesWithState<EQuadProp>(pToolbox: &View, pProps: aProps, pIds: s_aIds, pNewVal: &NewVal);
1086 if(Prop != EQuadProp::NONE && (State == EEditState::START || State == EEditState::ONE_GO))
1087 {
1088 pEditor->Map()->m_QuadTracker.BeginQuadPropTrack(pLayer, vSelectedQuads: pEditor->Map()->m_vSelectedQuads, Prop);
1089 }
1090
1091 const float OffsetX = i2fx(v: NewVal) - pCurrentQuad->m_aPoints[4].x;
1092 const float OffsetY = i2fx(v: NewVal) - pCurrentQuad->m_aPoints[4].y;
1093
1094 if(Prop == EQuadProp::ORDER && pLayer)
1095 {
1096 const int QuadIndex = pLayer->SwapQuads(Index0: pEditor->Map()->m_vSelectedQuads[pQuadPopupContext->m_SelectedQuadIndex], Index1: NewVal);
1097 pEditor->Map()->m_vSelectedQuads[pQuadPopupContext->m_SelectedQuadIndex] = QuadIndex;
1098 }
1099
1100 for(auto &pQuad : vpQuads)
1101 {
1102 if(Prop == EQuadProp::POS_X)
1103 {
1104 for(auto &Point : pQuad->m_aPoints)
1105 Point.x += OffsetX;
1106 }
1107 else if(Prop == EQuadProp::POS_Y)
1108 {
1109 for(auto &Point : pQuad->m_aPoints)
1110 Point.y += OffsetY;
1111 }
1112 else if(Prop == EQuadProp::POS_ENV)
1113 {
1114 int Index = std::clamp(val: NewVal - 1, lo: -1, hi: (int)pEditor->Map()->m_vpEnvelopes.size() - 1);
1115 int StepDirection = Index < pQuad->m_PosEnv ? -1 : 1;
1116 if(StepDirection != 0)
1117 {
1118 for(; Index >= -1 && Index < (int)pEditor->Map()->m_vpEnvelopes.size(); Index += StepDirection)
1119 {
1120 if(Index == -1 || pEditor->Map()->m_vpEnvelopes[Index]->GetChannels() == 3)
1121 {
1122 pQuad->m_PosEnv = Index;
1123 break;
1124 }
1125 }
1126 }
1127 }
1128 else if(Prop == EQuadProp::POS_ENV_OFFSET)
1129 {
1130 pQuad->m_PosEnvOffset = NewVal;
1131 }
1132 else if(Prop == EQuadProp::COLOR)
1133 {
1134 pQuadPopupContext->m_Color = NewVal;
1135 std::fill(first: std::begin(arr&: pQuad->m_aColors), last: std::end(arr&: pQuad->m_aColors), value: UnpackColor(PackedColor: NewVal));
1136 }
1137 else if(Prop == EQuadProp::COLOR_ENV)
1138 {
1139 int Index = std::clamp(val: NewVal - 1, lo: -1, hi: (int)pEditor->Map()->m_vpEnvelopes.size() - 1);
1140 int StepDirection = Index < pQuad->m_ColorEnv ? -1 : 1;
1141 if(StepDirection != 0)
1142 {
1143 for(; Index >= -1 && Index < (int)pEditor->Map()->m_vpEnvelopes.size(); Index += StepDirection)
1144 {
1145 if(Index == -1 || pEditor->Map()->m_vpEnvelopes[Index]->GetChannels() == 4)
1146 {
1147 pQuad->m_ColorEnv = Index;
1148 break;
1149 }
1150 }
1151 }
1152 }
1153 else if(Prop == EQuadProp::COLOR_ENV_OFFSET)
1154 {
1155 pQuad->m_ColorEnvOffset = NewVal;
1156 }
1157 }
1158
1159 if(Prop != EQuadProp::NONE && (State == EEditState::END || State == EEditState::ONE_GO))
1160 {
1161 pEditor->Map()->m_QuadTracker.EndQuadPropTrack(Prop);
1162 pEditor->Map()->OnModify();
1163 }
1164
1165 return CUi::POPUP_KEEP_OPEN;
1166}
1167
1168CUi::EPopupMenuFunctionResult CEditor::PopupSource(void *pContext, CUIRect View, bool Active)
1169{
1170 CEditor *pEditor = static_cast<CEditor *>(pContext);
1171 CSoundSource *pSource = pEditor->Map()->SelectedSoundSource();
1172 if(!pSource)
1173 return CUi::POPUP_CLOSE_CURRENT;
1174
1175 CUIRect Button;
1176
1177 // delete button
1178 View.HSplitBottom(Cut: 12.0f, pTop: &View, pBottom: &Button);
1179 static int s_DeleteButton = 0;
1180 if(pEditor->DoButton_Editor(pId: &s_DeleteButton, pText: "Delete", Checked: 0, pRect: &Button, Flags: BUTTONFLAG_LEFT, pToolTip: "Delete the current sound source."))
1181 {
1182 std::shared_ptr<CLayerSounds> pLayer = std::static_pointer_cast<CLayerSounds>(r: pEditor->Map()->SelectedLayerType(Index: 0, Type: LAYERTYPE_SOUNDS));
1183 if(pLayer)
1184 {
1185 pEditor->Map()->m_EditorHistory.Execute(pAction: std::make_shared<CEditorActionDeleteSoundSource>(args: pEditor->Map(), args&: pEditor->Map()->m_SelectedGroup, args&: pEditor->Map()->m_vSelectedLayers[0], args&: pEditor->Map()->m_SelectedSoundSource));
1186 }
1187 return CUi::POPUP_CLOSE_CURRENT;
1188 }
1189
1190 // Sound shape button
1191 CUIRect ShapeButton;
1192 View.HSplitBottom(Cut: 3.0f, pTop: &View, pBottom: nullptr);
1193 View.HSplitBottom(Cut: 12.0f, pTop: &View, pBottom: &ShapeButton);
1194
1195 static const char *s_apShapeNames[CSoundShape::NUM_SHAPES] = {
1196 "Rectangle",
1197 "Circle"};
1198
1199 pSource->m_Shape.m_Type = pSource->m_Shape.m_Type % CSoundShape::NUM_SHAPES; // prevent out of array errors
1200
1201 static int s_ShapeTypeButton = 0;
1202 if(pEditor->DoButton_Editor(pId: &s_ShapeTypeButton, pText: s_apShapeNames[pSource->m_Shape.m_Type], Checked: 0, pRect: &ShapeButton, Flags: BUTTONFLAG_LEFT, pToolTip: "Change sound source shape."))
1203 {
1204 pEditor->Map()->m_EditorHistory.Execute(pAction: std::make_shared<CEditorActionEditSoundSourceShape>(args: pEditor->Map(), args&: pEditor->Map()->m_SelectedGroup, args&: pEditor->Map()->m_vSelectedLayers[0], args&: pEditor->Map()->m_SelectedSoundSource, args: (pSource->m_Shape.m_Type + 1) % CSoundShape::NUM_SHAPES));
1205 }
1206
1207 CProperty aProps[] = {
1208 {"Pos X", pSource->m_Position.x / 1000, PROPTYPE_INT, -1000000, 1000000},
1209 {"Pos Y", pSource->m_Position.y / 1000, PROPTYPE_INT, -1000000, 1000000},
1210 {"Loop", pSource->m_Loop, PROPTYPE_BOOL, 0, 1},
1211 {"Pan", pSource->m_Pan, PROPTYPE_BOOL, 0, 1},
1212 {"Delay", pSource->m_TimeDelay, PROPTYPE_INT, 0, 1000000},
1213 {"Falloff", pSource->m_Falloff, PROPTYPE_INT, 0, 255},
1214 {"Pos. Env", pSource->m_PosEnv + 1, PROPTYPE_ENVELOPE, 0, 0},
1215 {"Pos. TO", pSource->m_PosEnvOffset, PROPTYPE_INT, -1000000, 1000000},
1216 {"Sound Env", pSource->m_SoundEnv + 1, PROPTYPE_ENVELOPE, 0, 0},
1217 {"Sound. TO", pSource->m_SoundEnvOffset, PROPTYPE_INT, -1000000, 1000000},
1218 {nullptr},
1219 };
1220
1221 static int s_aIds[(int)ESoundProp::NUM_PROPS] = {0};
1222 int NewVal = 0;
1223 auto [State, Prop] = pEditor->DoPropertiesWithState<ESoundProp>(pToolbox: &View, pProps: aProps, pIds: s_aIds, pNewVal: &NewVal);
1224 if(Prop != ESoundProp::NONE && (State == EEditState::END || State == EEditState::ONE_GO))
1225 {
1226 pEditor->Map()->OnModify();
1227 }
1228
1229 pEditor->Map()->m_SoundSourcePropTracker.Begin(pObject: pSource, Prop, State);
1230
1231 if(Prop == ESoundProp::POS_X)
1232 {
1233 pSource->m_Position.x = NewVal * 1000;
1234 }
1235 else if(Prop == ESoundProp::POS_Y)
1236 {
1237 pSource->m_Position.y = NewVal * 1000;
1238 }
1239 else if(Prop == ESoundProp::LOOP)
1240 {
1241 pSource->m_Loop = NewVal;
1242 }
1243 else if(Prop == ESoundProp::PAN)
1244 {
1245 pSource->m_Pan = NewVal;
1246 }
1247 else if(Prop == ESoundProp::TIME_DELAY)
1248 {
1249 pSource->m_TimeDelay = NewVal;
1250 }
1251 else if(Prop == ESoundProp::FALLOFF)
1252 {
1253 pSource->m_Falloff = NewVal;
1254 }
1255 else if(Prop == ESoundProp::POS_ENV)
1256 {
1257 int Index = std::clamp(val: NewVal - 1, lo: -1, hi: (int)pEditor->Map()->m_vpEnvelopes.size() - 1);
1258 const int StepDirection = Index < pSource->m_PosEnv ? -1 : 1;
1259 for(; Index >= -1 && Index < (int)pEditor->Map()->m_vpEnvelopes.size(); Index += StepDirection)
1260 {
1261 if(Index == -1 || pEditor->Map()->m_vpEnvelopes[Index]->GetChannels() == 3)
1262 {
1263 pSource->m_PosEnv = Index;
1264 break;
1265 }
1266 }
1267 }
1268 else if(Prop == ESoundProp::POS_ENV_OFFSET)
1269 {
1270 pSource->m_PosEnvOffset = NewVal;
1271 }
1272 else if(Prop == ESoundProp::SOUND_ENV)
1273 {
1274 int Index = std::clamp(val: NewVal - 1, lo: -1, hi: (int)pEditor->Map()->m_vpEnvelopes.size() - 1);
1275 const int StepDirection = Index < pSource->m_SoundEnv ? -1 : 1;
1276 for(; Index >= -1 && Index < (int)pEditor->Map()->m_vpEnvelopes.size(); Index += StepDirection)
1277 {
1278 if(Index == -1 || pEditor->Map()->m_vpEnvelopes[Index]->GetChannels() == 1)
1279 {
1280 pSource->m_SoundEnv = Index;
1281 break;
1282 }
1283 }
1284 }
1285 else if(Prop == ESoundProp::SOUND_ENV_OFFSET)
1286 {
1287 pSource->m_SoundEnvOffset = NewVal;
1288 }
1289
1290 pEditor->Map()->m_SoundSourcePropTracker.End(Prop, State);
1291
1292 // source shape properties
1293 switch(pSource->m_Shape.m_Type)
1294 {
1295 case CSoundShape::SHAPE_CIRCLE:
1296 {
1297 CProperty aCircleProps[] = {
1298 {"Radius", pSource->m_Shape.m_Circle.m_Radius, PROPTYPE_INT, 0, 1000000},
1299 {nullptr},
1300 };
1301
1302 static int s_aCircleIds[(int)ECircleShapeProp::NUM_PROPS] = {0};
1303 NewVal = 0;
1304 auto [LocalState, LocalProp] = pEditor->DoPropertiesWithState<ECircleShapeProp>(pToolbox: &View, pProps: aCircleProps, pIds: s_aCircleIds, pNewVal: &NewVal);
1305 if(LocalProp != ECircleShapeProp::NONE && (LocalState == EEditState::END || LocalState == EEditState::ONE_GO))
1306 {
1307 pEditor->Map()->OnModify();
1308 }
1309
1310 pEditor->Map()->m_SoundSourceCircleShapePropTracker.Begin(pObject: pSource, Prop: LocalProp, State: LocalState);
1311
1312 if(LocalProp == ECircleShapeProp::CIRCLE_RADIUS)
1313 {
1314 pSource->m_Shape.m_Circle.m_Radius = NewVal;
1315 }
1316
1317 pEditor->Map()->m_SoundSourceCircleShapePropTracker.End(Prop: LocalProp, State: LocalState);
1318 break;
1319 }
1320
1321 case CSoundShape::SHAPE_RECTANGLE:
1322 {
1323 CProperty aRectangleProps[] = {
1324 {"Width", pSource->m_Shape.m_Rectangle.m_Width / 1024, PROPTYPE_INT, 0, 1000000},
1325 {"Height", pSource->m_Shape.m_Rectangle.m_Height / 1024, PROPTYPE_INT, 0, 1000000},
1326 {nullptr},
1327 };
1328
1329 static int s_aRectangleIds[(int)ERectangleShapeProp::NUM_PROPS] = {0};
1330 NewVal = 0;
1331 auto [LocalState, LocalProp] = pEditor->DoPropertiesWithState<ERectangleShapeProp>(pToolbox: &View, pProps: aRectangleProps, pIds: s_aRectangleIds, pNewVal: &NewVal);
1332 if(LocalProp != ERectangleShapeProp::NONE && (LocalState == EEditState::END || LocalState == EEditState::ONE_GO))
1333 {
1334 pEditor->Map()->OnModify();
1335 }
1336
1337 pEditor->Map()->m_SoundSourceRectShapePropTracker.Begin(pObject: pSource, Prop: LocalProp, State: LocalState);
1338
1339 if(LocalProp == ERectangleShapeProp::RECTANGLE_WIDTH)
1340 {
1341 pSource->m_Shape.m_Rectangle.m_Width = NewVal * 1024;
1342 }
1343 else if(LocalProp == ERectangleShapeProp::RECTANGLE_HEIGHT)
1344 {
1345 pSource->m_Shape.m_Rectangle.m_Height = NewVal * 1024;
1346 }
1347
1348 pEditor->Map()->m_SoundSourceRectShapePropTracker.End(Prop: LocalProp, State: LocalState);
1349 break;
1350 }
1351 }
1352
1353 return CUi::POPUP_KEEP_OPEN;
1354}
1355
1356CUi::EPopupMenuFunctionResult CEditor::PopupPoint(void *pContext, CUIRect View, bool Active)
1357{
1358 CPointPopupContext *pPointPopupContext = static_cast<CPointPopupContext *>(pContext);
1359 CEditor *pEditor = pPointPopupContext->m_pEditor;
1360 std::vector<CQuad *> vpQuads = pEditor->Map()->SelectedQuads();
1361 if(!in_range<int>(a: pPointPopupContext->m_SelectedQuadIndex, lower: 0, upper: vpQuads.size() - 1))
1362 {
1363 return CUi::POPUP_CLOSE_CURRENT;
1364 }
1365 CQuad *pCurrentQuad = vpQuads[pPointPopupContext->m_SelectedQuadIndex];
1366 std::shared_ptr<CLayerQuads> pLayer = std::static_pointer_cast<CLayerQuads>(r: pEditor->Map()->SelectedLayerType(Index: 0, Type: LAYERTYPE_QUADS));
1367
1368 const int X = fx2i(v: pCurrentQuad->m_aPoints[pPointPopupContext->m_SelectedQuadPoint].x);
1369 const int Y = fx2i(v: pCurrentQuad->m_aPoints[pPointPopupContext->m_SelectedQuadPoint].y);
1370 const int TextureU = fx2f(v: pCurrentQuad->m_aTexcoords[pPointPopupContext->m_SelectedQuadPoint].x) * 1024;
1371 const int TextureV = fx2f(v: pCurrentQuad->m_aTexcoords[pPointPopupContext->m_SelectedQuadPoint].y) * 1024;
1372
1373 CProperty aProps[] = {
1374 {"Pos X", X, PROPTYPE_INT, -1000000, 1000000},
1375 {"Pos Y", Y, PROPTYPE_INT, -1000000, 1000000},
1376 {"Color", PackColor(Color: pCurrentQuad->m_aColors[pPointPopupContext->m_SelectedQuadPoint]), PROPTYPE_COLOR, 0, 0},
1377 {"Tex U", TextureU, PROPTYPE_INT, -1000000, 1000000},
1378 {"Tex V", TextureV, PROPTYPE_INT, -1000000, 1000000},
1379 {nullptr},
1380 };
1381
1382 static int s_aIds[(int)EQuadPointProp::NUM_PROPS] = {0};
1383 int NewVal = 0;
1384 auto [State, Prop] = pEditor->DoPropertiesWithState<EQuadPointProp>(pToolbox: &View, pProps: aProps, pIds: s_aIds, pNewVal: &NewVal);
1385 if(Prop != EQuadPointProp::NONE && (State == EEditState::START || State == EEditState::ONE_GO))
1386 {
1387 pEditor->Map()->m_QuadTracker.BeginQuadPointPropTrack(pLayer, vSelectedQuads: pEditor->Map()->m_vSelectedQuads, SelectedQuadPoints: pEditor->Map()->m_SelectedQuadPoints);
1388 pEditor->Map()->m_QuadTracker.AddQuadPointPropTrack(Prop);
1389 }
1390
1391 for(CQuad *pQuad : vpQuads)
1392 {
1393 if(Prop == EQuadPointProp::POS_X)
1394 {
1395 for(int v = 0; v < 4; v++)
1396 if(pEditor->Map()->IsQuadCornerSelected(Index: v))
1397 pQuad->m_aPoints[v].x = i2fx(v: fx2i(v: pQuad->m_aPoints[v].x) + NewVal - X);
1398 }
1399 else if(Prop == EQuadPointProp::POS_Y)
1400 {
1401 for(int v = 0; v < 4; v++)
1402 if(pEditor->Map()->IsQuadCornerSelected(Index: v))
1403 pQuad->m_aPoints[v].y = i2fx(v: fx2i(v: pQuad->m_aPoints[v].y) + NewVal - Y);
1404 }
1405 else if(Prop == EQuadPointProp::COLOR)
1406 {
1407 for(int v = 0; v < 4; v++)
1408 {
1409 if(pEditor->Map()->IsQuadCornerSelected(Index: v))
1410 {
1411 pQuad->m_aColors[v] = UnpackColor(PackedColor: NewVal);
1412 }
1413 }
1414 }
1415 else if(Prop == EQuadPointProp::TEX_U)
1416 {
1417 for(int v = 0; v < 4; v++)
1418 if(pEditor->Map()->IsQuadCornerSelected(Index: v))
1419 pQuad->m_aTexcoords[v].x = f2fx(v: fx2f(v: pQuad->m_aTexcoords[v].x) + (NewVal - TextureU) / 1024.0f);
1420 }
1421 else if(Prop == EQuadPointProp::TEX_V)
1422 {
1423 for(int v = 0; v < 4; v++)
1424 if(pEditor->Map()->IsQuadCornerSelected(Index: v))
1425 pQuad->m_aTexcoords[v].y = f2fx(v: fx2f(v: pQuad->m_aTexcoords[v].y) + (NewVal - TextureV) / 1024.0f);
1426 }
1427 }
1428
1429 if(Prop != EQuadPointProp::NONE && (State == EEditState::END || State == EEditState::ONE_GO))
1430 {
1431 pEditor->Map()->m_QuadTracker.EndQuadPointPropTrack(Prop);
1432 pEditor->Map()->OnModify();
1433 }
1434
1435 return CUi::POPUP_KEEP_OPEN;
1436}
1437
1438static const auto &&gs_ModifyIndexDeleted = [](int DeletedIndex) {
1439 return [DeletedIndex](int *pIndex) {
1440 if(*pIndex == DeletedIndex)
1441 *pIndex = -1;
1442 else if(*pIndex > DeletedIndex)
1443 *pIndex = *pIndex - 1;
1444 };
1445};
1446
1447CUi::EPopupMenuFunctionResult CEditor::PopupImage(void *pContext, CUIRect View, bool Active)
1448{
1449 CEditor *pEditor = static_cast<CEditor *>(pContext);
1450
1451 static int s_ExternalButton = 0;
1452 static int s_ReimportButton = 0;
1453 static int s_ReplaceButton = 0;
1454 static int s_RemoveButton = 0;
1455 static int s_ExportButton = 0;
1456
1457 const float RowHeight = 12.0f;
1458
1459 CUIRect Slot;
1460 View.HSplitTop(Cut: RowHeight, pTop: &Slot, pBottom: &View);
1461 std::shared_ptr<CEditorImage> pImg = pEditor->Map()->SelectedImage();
1462
1463 if(!pImg->m_External)
1464 {
1465 CUIRect Label, EditBox;
1466
1467 static CLineInput s_RenameInput;
1468
1469 Slot.VMargin(Cut: 5.0f, pOtherRect: &Slot);
1470 Slot.VSplitLeft(Cut: 35.0f, pLeft: &Label, pRight: &Slot);
1471 Slot.VSplitLeft(Cut: RowHeight - 2.0f, pLeft: nullptr, pRight: &EditBox);
1472 pEditor->Ui()->DoLabel(pRect: &Label, pText: "Name:", Size: RowHeight - 2.0f, Align: TEXTALIGN_ML);
1473
1474 s_RenameInput.SetBuffer(pStr: pImg->m_aName, MaxSize: sizeof(pImg->m_aName));
1475 if(pEditor->DoEditBox(pLineInput: &s_RenameInput, pRect: &EditBox, FontSize: RowHeight - 2.0f))
1476 pEditor->Map()->OnModify();
1477
1478 View.HSplitTop(Cut: 5.0f, pTop: nullptr, pBottom: &View);
1479 View.HSplitTop(Cut: RowHeight, pTop: &Slot, pBottom: &View);
1480 }
1481
1482 if(pImg->m_External)
1483 {
1484 if(pEditor->DoButton_MenuItem(pId: &s_ExternalButton, pText: "Embed", Checked: 0, pRect: &Slot, Flags: BUTTONFLAG_LEFT, pToolTip: "Embed the image into the map file."))
1485 {
1486 if(pImg->m_pData == nullptr)
1487 {
1488 pEditor->ShowFileDialogError(pFormat: "Embedding is not possible because the image could not be loaded.");
1489 return CUi::POPUP_KEEP_OPEN;
1490 }
1491 pImg->m_External = 0;
1492 return CUi::POPUP_CLOSE_CURRENT;
1493 }
1494 View.HSplitTop(Cut: 5.0f, pTop: nullptr, pBottom: &View);
1495 View.HSplitTop(Cut: RowHeight, pTop: &Slot, pBottom: &View);
1496 }
1497 else if(CEditor::IsVanillaImage(pImage: pImg->m_aName))
1498 {
1499 if(pEditor->DoButton_MenuItem(pId: &s_ExternalButton, pText: "Make external", Checked: 0, pRect: &Slot, Flags: BUTTONFLAG_LEFT, pToolTip: "Remove the image from the map file."))
1500 {
1501 pImg->m_External = 1;
1502 return CUi::POPUP_CLOSE_CURRENT;
1503 }
1504 View.HSplitTop(Cut: 5.0f, pTop: nullptr, pBottom: &View);
1505 View.HSplitTop(Cut: RowHeight, pTop: &Slot, pBottom: &View);
1506 }
1507
1508 static CUi::SSelectionPopupContext s_SelectionPopupContext;
1509 static CScrollRegion s_SelectionPopupScrollRegion;
1510 s_SelectionPopupContext.m_pScrollRegion = &s_SelectionPopupScrollRegion;
1511 if(pEditor->DoButton_MenuItem(pId: &s_ReimportButton, pText: "Re-import", Checked: 0, pRect: &Slot, Flags: BUTTONFLAG_LEFT, pToolTip: "Re-import the image from the mapres folder."))
1512 {
1513 char aFilename[IO_MAX_PATH_LENGTH];
1514 str_format(buffer: aFilename, buffer_size: sizeof(aFilename), format: "%s.png", pImg->m_aName);
1515 s_SelectionPopupContext.Reset();
1516 std::set<std::string> EntriesSet;
1517 pEditor->Storage()->FindFiles(pFilename: aFilename, pPath: "mapres", Type: IStorage::TYPE_ALL, pEntries: &EntriesSet);
1518 for(const auto &Entry : EntriesSet)
1519 s_SelectionPopupContext.m_vEntries.push_back(x: Entry);
1520 if(s_SelectionPopupContext.m_vEntries.empty())
1521 {
1522 pEditor->ShowFileDialogError(pFormat: "Error: could not find image '%s' in the mapres folder.", aFilename);
1523 }
1524 else if(s_SelectionPopupContext.m_vEntries.size() == 1)
1525 {
1526 s_SelectionPopupContext.m_pSelection = &s_SelectionPopupContext.m_vEntries.front();
1527 }
1528 else
1529 {
1530 str_copy(dst&: s_SelectionPopupContext.m_aMessage, src: "Select the wanted image:");
1531 pEditor->Ui()->ShowPopupSelection(X: pEditor->Ui()->MouseX(), Y: pEditor->Ui()->MouseY(), pContext: &s_SelectionPopupContext);
1532 }
1533 }
1534 if(s_SelectionPopupContext.m_pSelection != nullptr)
1535 {
1536 const bool WasExternal = pImg->m_External;
1537 const bool Result = pEditor->ReplaceImage(pFilename: s_SelectionPopupContext.m_pSelection->c_str(), StorageType: IStorage::TYPE_ALL, CheckDuplicate: false);
1538 pImg->m_External = WasExternal;
1539 s_SelectionPopupContext.Reset();
1540 return Result ? CUi::POPUP_CLOSE_CURRENT : CUi::POPUP_KEEP_OPEN;
1541 }
1542
1543 View.HSplitTop(Cut: 5.0f, pTop: nullptr, pBottom: &View);
1544 View.HSplitTop(Cut: RowHeight, pTop: &Slot, pBottom: &View);
1545 if(pEditor->DoButton_MenuItem(pId: &s_ReplaceButton, pText: "Replace", Checked: 0, pRect: &Slot, Flags: BUTTONFLAG_LEFT, pToolTip: "Replace the image with a new one."))
1546 {
1547 pEditor->m_FileBrowser.ShowFileDialog(StorageType: IStorage::TYPE_ALL, FileType: CFileBrowser::EFileType::IMAGE, pTitle: "Replace image", pButtonText: "Replace", pInitialPath: "mapres", pInitialFilename: "", pfnOpenCallback: ReplaceImageCallback, pOpenCallbackUser: pEditor);
1548 return CUi::POPUP_CLOSE_CURRENT;
1549 }
1550
1551 View.HSplitTop(Cut: 5.0f, pTop: nullptr, pBottom: &View);
1552 View.HSplitTop(Cut: RowHeight, pTop: &Slot, pBottom: &View);
1553 if(pEditor->DoButton_MenuItem(pId: &s_RemoveButton, pText: "Remove", Checked: 0, pRect: &Slot, Flags: BUTTONFLAG_LEFT, pToolTip: "Remove the image from the map."))
1554 {
1555 if(pEditor->Map()->IsImageUsed(ImageIndex: pEditor->Map()->m_SelectedImage))
1556 {
1557 pEditor->m_PopupEventType = POPEVENT_REMOVE_USED_IMAGE;
1558 pEditor->m_PopupEventActivated = true;
1559 }
1560 else
1561 {
1562 pEditor->Map()->m_vpImages.erase(position: pEditor->Map()->m_vpImages.begin() + pEditor->Map()->m_SelectedImage);
1563 pEditor->Map()->ModifyImageIndex(IndexModifyFunction: gs_ModifyIndexDeleted(pEditor->Map()->m_SelectedImage));
1564 }
1565 return CUi::POPUP_CLOSE_CURRENT;
1566 }
1567
1568 if(!pImg->m_External)
1569 {
1570 View.HSplitTop(Cut: 5.0f, pTop: nullptr, pBottom: &View);
1571 View.HSplitTop(Cut: RowHeight, pTop: &Slot, pBottom: &View);
1572 if(pEditor->DoButton_MenuItem(pId: &s_ExportButton, pText: "Export", Checked: 0, pRect: &Slot, Flags: BUTTONFLAG_LEFT, pToolTip: "Export the image to a separate file."))
1573 {
1574 if(pImg->m_pData == nullptr)
1575 {
1576 pEditor->ShowFileDialogError(pFormat: "Exporting is not possible because the image could not be loaded.");
1577 return CUi::POPUP_KEEP_OPEN;
1578 }
1579 pEditor->m_FileBrowser.ShowFileDialog(StorageType: IStorage::TYPE_SAVE, FileType: CFileBrowser::EFileType::IMAGE, pTitle: "Save image", pButtonText: "Save", pInitialPath: "mapres", pInitialFilename: pImg->m_aName, pfnOpenCallback: CallbackSaveImage, pOpenCallbackUser: pEditor);
1580 return CUi::POPUP_CLOSE_CURRENT;
1581 }
1582 }
1583
1584 return CUi::POPUP_KEEP_OPEN;
1585}
1586
1587CUi::EPopupMenuFunctionResult CEditor::PopupSound(void *pContext, CUIRect View, bool Active)
1588{
1589 CEditor *pEditor = static_cast<CEditor *>(pContext);
1590
1591 static int s_ReimportButton = 0;
1592 static int s_ReplaceButton = 0;
1593 static int s_RemoveButton = 0;
1594 static int s_ExportButton = 0;
1595
1596 const float RowHeight = 12.0f;
1597
1598 CUIRect Slot;
1599 View.HSplitTop(Cut: RowHeight, pTop: &Slot, pBottom: &View);
1600 std::shared_ptr<CEditorSound> pSound = pEditor->Map()->SelectedSound();
1601
1602 static CUi::SSelectionPopupContext s_SelectionPopupContext;
1603 static CScrollRegion s_SelectionPopupScrollRegion;
1604 s_SelectionPopupContext.m_pScrollRegion = &s_SelectionPopupScrollRegion;
1605
1606 CUIRect Label, EditBox;
1607
1608 static CLineInput s_RenameInput;
1609
1610 Slot.VMargin(Cut: 5.0f, pOtherRect: &Slot);
1611 Slot.VSplitLeft(Cut: 35.0f, pLeft: &Label, pRight: &Slot);
1612 Slot.VSplitLeft(Cut: RowHeight - 2.0f, pLeft: nullptr, pRight: &EditBox);
1613 pEditor->Ui()->DoLabel(pRect: &Label, pText: "Name:", Size: RowHeight - 2.0f, Align: TEXTALIGN_ML);
1614
1615 s_RenameInput.SetBuffer(pStr: pSound->m_aName, MaxSize: sizeof(pSound->m_aName));
1616 if(pEditor->DoEditBox(pLineInput: &s_RenameInput, pRect: &EditBox, FontSize: RowHeight - 2.0f))
1617 pEditor->Map()->OnModify();
1618
1619 View.HSplitTop(Cut: 5.0f, pTop: nullptr, pBottom: &View);
1620 View.HSplitTop(Cut: RowHeight, pTop: &Slot, pBottom: &View);
1621
1622 if(pEditor->DoButton_MenuItem(pId: &s_ReimportButton, pText: "Re-import", Checked: 0, pRect: &Slot, Flags: BUTTONFLAG_LEFT, pToolTip: "Re-import the sound from the mapres folder."))
1623 {
1624 char aFilename[IO_MAX_PATH_LENGTH];
1625 str_format(buffer: aFilename, buffer_size: sizeof(aFilename), format: "%s.opus", pSound->m_aName);
1626 s_SelectionPopupContext.Reset();
1627 std::set<std::string> EntriesSet;
1628 pEditor->Storage()->FindFiles(pFilename: aFilename, pPath: "mapres", Type: IStorage::TYPE_ALL, pEntries: &EntriesSet);
1629 for(const auto &Entry : EntriesSet)
1630 s_SelectionPopupContext.m_vEntries.push_back(x: Entry);
1631 if(s_SelectionPopupContext.m_vEntries.empty())
1632 {
1633 pEditor->ShowFileDialogError(pFormat: "Error: could not find sound '%s' in the mapres folder.", aFilename);
1634 }
1635 else if(s_SelectionPopupContext.m_vEntries.size() == 1)
1636 {
1637 s_SelectionPopupContext.m_pSelection = &s_SelectionPopupContext.m_vEntries.front();
1638 }
1639 else
1640 {
1641 str_copy(dst&: s_SelectionPopupContext.m_aMessage, src: "Select the wanted sound:");
1642 pEditor->Ui()->ShowPopupSelection(X: pEditor->Ui()->MouseX(), Y: pEditor->Ui()->MouseY(), pContext: &s_SelectionPopupContext);
1643 }
1644 }
1645 if(s_SelectionPopupContext.m_pSelection != nullptr)
1646 {
1647 const bool Result = pEditor->ReplaceSound(pFilename: s_SelectionPopupContext.m_pSelection->c_str(), StorageType: IStorage::TYPE_ALL, CheckDuplicate: false);
1648 s_SelectionPopupContext.Reset();
1649 return Result ? CUi::POPUP_CLOSE_CURRENT : CUi::POPUP_KEEP_OPEN;
1650 }
1651
1652 View.HSplitTop(Cut: 5.0f, pTop: nullptr, pBottom: &View);
1653 View.HSplitTop(Cut: RowHeight, pTop: &Slot, pBottom: &View);
1654 if(pEditor->DoButton_MenuItem(pId: &s_ReplaceButton, pText: "Replace", Checked: 0, pRect: &Slot, Flags: BUTTONFLAG_LEFT, pToolTip: "Replace the sound with a new one."))
1655 {
1656 pEditor->m_FileBrowser.ShowFileDialog(StorageType: IStorage::TYPE_ALL, FileType: CFileBrowser::EFileType::SOUND, pTitle: "Replace sound", pButtonText: "Replace", pInitialPath: "mapres", pInitialFilename: "", pfnOpenCallback: ReplaceSoundCallback, pOpenCallbackUser: pEditor);
1657 return CUi::POPUP_CLOSE_CURRENT;
1658 }
1659
1660 View.HSplitTop(Cut: 5.0f, pTop: nullptr, pBottom: &View);
1661 View.HSplitTop(Cut: RowHeight, pTop: &Slot, pBottom: &View);
1662 if(pEditor->DoButton_MenuItem(pId: &s_RemoveButton, pText: "Remove", Checked: 0, pRect: &Slot, Flags: BUTTONFLAG_LEFT, pToolTip: "Remove the sound from the map."))
1663 {
1664 if(pEditor->Map()->IsSoundUsed(SoundIndex: pEditor->Map()->m_SelectedSound))
1665 {
1666 pEditor->m_PopupEventType = POPEVENT_REMOVE_USED_SOUND;
1667 pEditor->m_PopupEventActivated = true;
1668 }
1669 else
1670 {
1671 pEditor->Map()->m_vpSounds.erase(position: pEditor->Map()->m_vpSounds.begin() + pEditor->Map()->m_SelectedSound);
1672 pEditor->Map()->ModifySoundIndex(IndexModifyFunction: gs_ModifyIndexDeleted(pEditor->Map()->m_SelectedSound));
1673 pEditor->m_ToolbarPreviewSound = -1;
1674 }
1675 return CUi::POPUP_CLOSE_CURRENT;
1676 }
1677
1678 View.HSplitTop(Cut: 5.0f, pTop: nullptr, pBottom: &View);
1679 View.HSplitTop(Cut: RowHeight, pTop: &Slot, pBottom: &View);
1680 if(pEditor->DoButton_MenuItem(pId: &s_ExportButton, pText: "Export", Checked: 0, pRect: &Slot, Flags: BUTTONFLAG_LEFT, pToolTip: "Export the sound to a separate file."))
1681 {
1682 if(pSound->m_pData == nullptr)
1683 {
1684 pEditor->ShowFileDialogError(pFormat: "Exporting is not possible because the sound could not be loaded.");
1685 return CUi::POPUP_KEEP_OPEN;
1686 }
1687 pEditor->m_FileBrowser.ShowFileDialog(StorageType: IStorage::TYPE_SAVE, FileType: CFileBrowser::EFileType::SOUND, pTitle: "Save sound", pButtonText: "Save", pInitialPath: "mapres", pInitialFilename: pSound->m_aName, pfnOpenCallback: CallbackSaveSound, pOpenCallbackUser: pEditor);
1688 return CUi::POPUP_CLOSE_CURRENT;
1689 }
1690
1691 return CUi::POPUP_KEEP_OPEN;
1692}
1693
1694CUi::EPopupMenuFunctionResult CEditor::PopupMapInfo(void *pContext, CUIRect View, bool Active)
1695{
1696 CEditor *pEditor = static_cast<CEditor *>(pContext);
1697
1698 CUIRect Label, ButtonBar, Button;
1699
1700 View.Margin(Cut: 10.0f, pOtherRect: &View);
1701 View.HSplitBottom(Cut: 20.0f, pTop: &View, pBottom: &ButtonBar);
1702
1703 // title
1704 View.HSplitTop(Cut: 20.0f, pTop: &Label, pBottom: &View);
1705 pEditor->Ui()->DoLabel(pRect: &Label, pText: "Map details", Size: 20.0f, Align: TEXTALIGN_MC);
1706 View.HSplitTop(Cut: 10.0f, pTop: nullptr, pBottom: &View);
1707
1708 // author box
1709 View.HSplitTop(Cut: 20.0f, pTop: &Label, pBottom: &View);
1710 pEditor->Ui()->DoLabel(pRect: &Label, pText: "Author:", Size: 10.0f, Align: TEXTALIGN_ML);
1711 Label.VSplitLeft(Cut: 60.0f, pLeft: nullptr, pRight: &Button);
1712 Button.HMargin(Cut: 3.0f, pOtherRect: &Button);
1713 static CLineInput s_AuthorInput;
1714 s_AuthorInput.SetBuffer(pStr: pEditor->Map()->m_MapInfoTmp.m_aAuthor, MaxSize: sizeof(pEditor->Map()->m_MapInfoTmp.m_aAuthor));
1715 pEditor->DoEditBox(pLineInput: &s_AuthorInput, pRect: &Button, FontSize: 10.0f);
1716
1717 // version box
1718 View.HSplitTop(Cut: 20.0f, pTop: &Label, pBottom: &View);
1719 pEditor->Ui()->DoLabel(pRect: &Label, pText: "Version:", Size: 10.0f, Align: TEXTALIGN_ML);
1720 Label.VSplitLeft(Cut: 60.0f, pLeft: nullptr, pRight: &Button);
1721 Button.HMargin(Cut: 3.0f, pOtherRect: &Button);
1722 static CLineInput s_VersionInput;
1723 s_VersionInput.SetBuffer(pStr: pEditor->Map()->m_MapInfoTmp.m_aVersion, MaxSize: sizeof(pEditor->Map()->m_MapInfoTmp.m_aVersion));
1724 pEditor->DoEditBox(pLineInput: &s_VersionInput, pRect: &Button, FontSize: 10.0f);
1725
1726 // credits box
1727 View.HSplitTop(Cut: 20.0f, pTop: &Label, pBottom: &View);
1728 pEditor->Ui()->DoLabel(pRect: &Label, pText: "Credits:", Size: 10.0f, Align: TEXTALIGN_ML);
1729 Label.VSplitLeft(Cut: 60.0f, pLeft: nullptr, pRight: &Button);
1730 Button.HMargin(Cut: 3.0f, pOtherRect: &Button);
1731 static CLineInput s_CreditsInput;
1732 s_CreditsInput.SetBuffer(pStr: pEditor->Map()->m_MapInfoTmp.m_aCredits, MaxSize: sizeof(pEditor->Map()->m_MapInfoTmp.m_aCredits));
1733 pEditor->DoEditBox(pLineInput: &s_CreditsInput, pRect: &Button, FontSize: 10.0f);
1734
1735 // license box
1736 View.HSplitTop(Cut: 20.0f, pTop: &Label, pBottom: &View);
1737 pEditor->Ui()->DoLabel(pRect: &Label, pText: "License:", Size: 10.0f, Align: TEXTALIGN_ML);
1738 Label.VSplitLeft(Cut: 60.0f, pLeft: nullptr, pRight: &Button);
1739 Button.HMargin(Cut: 3.0f, pOtherRect: &Button);
1740 static CLineInput s_LicenseInput;
1741 s_LicenseInput.SetBuffer(pStr: pEditor->Map()->m_MapInfoTmp.m_aLicense, MaxSize: sizeof(pEditor->Map()->m_MapInfoTmp.m_aLicense));
1742 pEditor->DoEditBox(pLineInput: &s_LicenseInput, pRect: &Button, FontSize: 10.0f);
1743
1744 // button bar
1745 ButtonBar.VSplitLeft(Cut: 110.0f, pLeft: &Label, pRight: &ButtonBar);
1746 static int s_CancelButton = 0;
1747 if(pEditor->DoButton_Editor(pId: &s_CancelButton, pText: "Cancel", Checked: 0, pRect: &Label, Flags: BUTTONFLAG_LEFT, pToolTip: nullptr))
1748 return CUi::POPUP_CLOSE_CURRENT;
1749
1750 ButtonBar.VSplitRight(Cut: 110.0f, pLeft: &ButtonBar, pRight: &Label);
1751 static int s_ConfirmButton = 0;
1752 if(pEditor->DoButton_Editor(pId: &s_ConfirmButton, pText: "Confirm", Checked: 0, pRect: &Label, Flags: BUTTONFLAG_LEFT, pToolTip: nullptr) || (Active && pEditor->Ui()->ConsumeHotkey(Hotkey: CUi::HOTKEY_ENTER)))
1753 {
1754 bool AuthorDifferent = str_comp(a: pEditor->Map()->m_MapInfoTmp.m_aAuthor, b: pEditor->Map()->m_MapInfo.m_aAuthor) != 0;
1755 bool VersionDifferent = str_comp(a: pEditor->Map()->m_MapInfoTmp.m_aVersion, b: pEditor->Map()->m_MapInfo.m_aVersion) != 0;
1756 bool CreditsDifferent = str_comp(a: pEditor->Map()->m_MapInfoTmp.m_aCredits, b: pEditor->Map()->m_MapInfo.m_aCredits) != 0;
1757 bool LicenseDifferent = str_comp(a: pEditor->Map()->m_MapInfoTmp.m_aLicense, b: pEditor->Map()->m_MapInfo.m_aLicense) != 0;
1758
1759 if(AuthorDifferent || VersionDifferent || CreditsDifferent || LicenseDifferent)
1760 pEditor->Map()->OnModify();
1761
1762 pEditor->Map()->m_MapInfo.Copy(Source: pEditor->Map()->m_MapInfoTmp);
1763 return CUi::POPUP_CLOSE_CURRENT;
1764 }
1765
1766 return CUi::POPUP_KEEP_OPEN;
1767}
1768
1769CUi::EPopupMenuFunctionResult CEditor::PopupEvent(void *pContext, CUIRect View, bool Active)
1770{
1771 CEditor *pEditor = static_cast<CEditor *>(pContext);
1772
1773 const char *pTitle;
1774 const char *pMessage;
1775 char aMessageBuf[128 + IO_MAX_PATH_LENGTH];
1776 if(pEditor->m_PopupEventType == POPEVENT_EXIT)
1777 {
1778 pTitle = "Exit the editor";
1779 pMessage = "The map contains unsaved data, you might want to save it before you exit the editor.\n\nContinue anyway?";
1780 }
1781 else if(pEditor->m_PopupEventType == POPEVENT_CLOSE_MAP)
1782 {
1783 pTitle = "Save changes?";
1784 str_format(buffer: aMessageBuf, buffer_size: sizeof(aMessageBuf), format: "Do you want to save your changes to '%s'?\n\nYour changes will be lost if you do not save them.", pEditor->Map()->m_aDisplayName);
1785 pMessage = aMessageBuf;
1786 }
1787 else if(pEditor->m_PopupEventType == POPEVENT_LARGELAYER)
1788 {
1789 pTitle = "Large layer";
1790 pMessage = "You are trying to set the height or width of a layer to more than 1000 tiles. This is actually possible, but only rarely necessary. It may cause the editor to work slower and will result in a larger file size as well as higher memory usage for client and server.";
1791 }
1792 else if(pEditor->m_PopupEventType == POPEVENT_PREVENTUNUSEDTILES)
1793 {
1794 pTitle = "Unused tiles disabled";
1795 pMessage = "Unused tiles can't be placed by default because they could get a use later and then destroy your map.\n\nActivate the 'Allow unused' setting to be able to place every tile.";
1796 }
1797 else if(pEditor->m_PopupEventType == POPEVENT_IMAGEDIV16)
1798 {
1799 pTitle = "Image width/height";
1800 pMessage = "The width or height of this image is not divisible by 16. This is required for images used in tile layers.";
1801 }
1802 else if(pEditor->m_PopupEventType == POPEVENT_IMAGE_MAX)
1803 {
1804 pTitle = "Max images";
1805 str_format(buffer: aMessageBuf, buffer_size: sizeof(aMessageBuf), format: "The client only allows a maximum of %" PRIzu " images.", MAX_MAPIMAGES);
1806 pMessage = aMessageBuf;
1807 }
1808 else if(pEditor->m_PopupEventType == POPEVENT_SOUND_MAX)
1809 {
1810 pTitle = "Max sounds";
1811 str_format(buffer: aMessageBuf, buffer_size: sizeof(aMessageBuf), format: "The client only allows a maximum of %" PRIzu " sounds.", MAX_MAPSOUNDS);
1812 pMessage = aMessageBuf;
1813 }
1814 else if(pEditor->m_PopupEventType == POPEVENT_PLACE_BORDER_TILES)
1815 {
1816 pTitle = "Place border tiles";
1817 pMessage = "This is going to overwrite any existing tiles around the edges of the layer.\n\nContinue?";
1818 }
1819 else if(pEditor->m_PopupEventType == POPEVENT_TILE_ART_BIG_IMAGE)
1820 {
1821 pTitle = "Big image";
1822 pMessage = "The selected image is big. Converting it to tile art may take some time.\n\nContinue anyway?";
1823 }
1824 else if(pEditor->m_PopupEventType == POPEVENT_TILE_ART_MANY_COLORS)
1825 {
1826 pTitle = "Many colors";
1827 pMessage = "The selected image contains many colors, which will lead to a big mapfile. You may want to consider reducing the number of colors.\n\nContinue anyway?";
1828 }
1829 else if(pEditor->m_PopupEventType == POPEVENT_TILE_ART_TOO_MANY_COLORS)
1830 {
1831 pTitle = "Too many colors";
1832 pMessage = "The client only supports 64 images but more would be needed to add the selected image as tile art.";
1833 }
1834 else if(pEditor->m_PopupEventType == POPEVENT_QUAD_ART_BIG_IMAGE)
1835 {
1836 pTitle = "Big image";
1837 pMessage = "The selected image is really big. Expect performance issues!\n\nContinue anyway?";
1838 }
1839 else if(pEditor->m_PopupEventType == POPEVENT_REMOVE_USED_IMAGE)
1840 {
1841 pTitle = "Remove image";
1842 pMessage = "This image is used in the map. Removing it will reset all layers that use this image to their default.\n\nRemove anyway?";
1843 }
1844 else if(pEditor->m_PopupEventType == POPEVENT_REMOVE_USED_SOUND)
1845 {
1846 pTitle = "Remove sound";
1847 pMessage = "This sound is used in the map. Removing it will reset all layers that use this sound to their default.\n\nRemove anyway?";
1848 }
1849 else if(pEditor->m_PopupEventType == POPEVENT_RESTART_SERVER)
1850 {
1851 pTitle = "Restart server";
1852 pMessage = "You have a local server running, but you are not authorized or connected.\n\nDo you want to restart the server and reconnect?";
1853 }
1854 else if(pEditor->m_PopupEventType == POPEVENT_RESTARTING_SERVER)
1855 {
1856 pTitle = "Restarting server";
1857 pMessage = "Local server is restarting. Please wait…";
1858
1859 CGameClient *pGameClient = (CGameClient *)pEditor->Kernel()->RequestInterface<IGameClient>();
1860 if(!pGameClient->m_LocalServer.IsServerRunning())
1861 {
1862 pEditor->TestMapLocally();
1863 return CUi::POPUP_CLOSE_CURRENT;
1864 }
1865 }
1866 else
1867 {
1868 dbg_assert_failed("m_PopupEventType invalid");
1869 }
1870
1871 CUIRect Label, ButtonBar, Button;
1872
1873 View.Margin(Cut: 10.0f, pOtherRect: &View);
1874 View.HSplitBottom(Cut: 20.0f, pTop: &View, pBottom: &ButtonBar);
1875
1876 // title
1877 View.HSplitTop(Cut: 20.0f, pTop: &Label, pBottom: &View);
1878 pEditor->Ui()->DoLabel(pRect: &Label, pText: pTitle, Size: 20.0f, Align: TEXTALIGN_MC);
1879
1880 // message
1881 SLabelProperties Props;
1882 Props.m_MaxWidth = View.w;
1883 pEditor->Ui()->DoLabel(pRect: &View, pText: pMessage, Size: 10.0f, Align: TEXTALIGN_ML, LabelProps: Props);
1884
1885 // button bar
1886 ButtonBar.VSplitLeft(Cut: 110.0f, pLeft: &Button, pRight: &ButtonBar);
1887 if(pEditor->m_PopupEventType != POPEVENT_LARGELAYER &&
1888 pEditor->m_PopupEventType != POPEVENT_PREVENTUNUSEDTILES &&
1889 pEditor->m_PopupEventType != POPEVENT_IMAGEDIV16 &&
1890 pEditor->m_PopupEventType != POPEVENT_IMAGE_MAX &&
1891 pEditor->m_PopupEventType != POPEVENT_SOUND_MAX &&
1892 pEditor->m_PopupEventType != POPEVENT_TILE_ART_TOO_MANY_COLORS)
1893 {
1894 static int s_CancelButton = 0;
1895 if(pEditor->DoButton_Editor(pId: &s_CancelButton, pText: "Cancel", Checked: 0, pRect: &Button, Flags: BUTTONFLAG_LEFT, pToolTip: nullptr))
1896 {
1897 if(pEditor->m_PopupEventType == POPEVENT_TILE_ART_BIG_IMAGE || pEditor->m_PopupEventType == POPEVENT_TILE_ART_MANY_COLORS)
1898 {
1899 pEditor->m_TileArtImageInfo.Free();
1900 }
1901 else if(pEditor->m_PopupEventType == POPEVENT_QUAD_ART_BIG_IMAGE)
1902 {
1903 pEditor->m_QuadArtImageInfo.Free();
1904 }
1905
1906 pEditor->m_PopupEventWasActivated = false;
1907 return CUi::POPUP_CLOSE_CURRENT;
1908 }
1909 }
1910
1911 if(pEditor->m_PopupEventType == POPEVENT_RESTARTING_SERVER)
1912 return CUi::POPUP_KEEP_OPEN;
1913
1914 ButtonBar.VSplitRight(Cut: 110.0f, pLeft: &ButtonBar, pRight: &Button);
1915 static int s_ConfirmButton = 0;
1916 const char *pConfirmLabel = pEditor->m_PopupEventType == POPEVENT_CLOSE_MAP ? "Save changes" : "Confirm";
1917 const int ConfirmChecked = pEditor->m_PopupEventType == POPEVENT_CLOSE_MAP ? EditorButtonChecked::POSITIVE_ACTION : 0;
1918 if(pEditor->DoButton_Editor(pId: &s_ConfirmButton, pText: pConfirmLabel, Checked: ConfirmChecked, pRect: &Button, Flags: BUTTONFLAG_LEFT, pToolTip: nullptr) ||
1919 (Active && pEditor->Ui()->ConsumeHotkey(Hotkey: CUi::HOTKEY_ENTER)))
1920 {
1921 if(pEditor->m_PopupEventType == POPEVENT_EXIT)
1922 {
1923 pEditor->OnClose();
1924 g_Config.m_ClEditor = 0;
1925 }
1926 else if(pEditor->m_PopupEventType == POPEVENT_CLOSE_MAP)
1927 {
1928 pEditor->Map()->m_CloseOnSave = true;
1929 pEditor->m_QuickActionSave.Call();
1930 }
1931 else if(pEditor->m_PopupEventType == POPEVENT_PLACE_BORDER_TILES)
1932 {
1933 pEditor->Map()->PlaceBorderTiles();
1934 }
1935 else if(pEditor->m_PopupEventType == POPEVENT_TILE_ART_BIG_IMAGE)
1936 {
1937 pEditor->TileArtCheckColors();
1938 }
1939 else if(pEditor->m_PopupEventType == POPEVENT_TILE_ART_MANY_COLORS)
1940 {
1941 pEditor->Map()->AddTileArt(Image: std::move(pEditor->m_TileArtImageInfo), pFilename: pEditor->m_aTileArtFilename, IgnoreHistory: false);
1942 pEditor->OnDialogClose();
1943 }
1944 else if(pEditor->m_PopupEventType == POPEVENT_QUAD_ART_BIG_IMAGE)
1945 {
1946 pEditor->Map()->AddQuadArt(Image: std::move(pEditor->m_QuadArtImageInfo), Parameters: pEditor->m_QuadArtParameters, IgnoreHistory: false);
1947 pEditor->OnDialogClose();
1948 }
1949 else if(pEditor->m_PopupEventType == POPEVENT_REMOVE_USED_IMAGE)
1950 {
1951 pEditor->Map()->m_vpImages.erase(position: pEditor->Map()->m_vpImages.begin() + pEditor->Map()->m_SelectedImage);
1952 pEditor->Map()->ModifyImageIndex(IndexModifyFunction: gs_ModifyIndexDeleted(pEditor->Map()->m_SelectedImage));
1953 }
1954 else if(pEditor->m_PopupEventType == POPEVENT_REMOVE_USED_SOUND)
1955 {
1956 pEditor->Map()->m_vpSounds.erase(position: pEditor->Map()->m_vpSounds.begin() + pEditor->Map()->m_SelectedSound);
1957 pEditor->Map()->ModifySoundIndex(IndexModifyFunction: gs_ModifyIndexDeleted(pEditor->Map()->m_SelectedSound));
1958 pEditor->m_ToolbarPreviewSound = -1;
1959 }
1960 else if(pEditor->m_PopupEventType == POPEVENT_RESTART_SERVER)
1961 {
1962 CGameClient *pGameClient = (CGameClient *)pEditor->Kernel()->RequestInterface<IGameClient>();
1963 pGameClient->m_LocalServer.KillServer();
1964 pEditor->m_PopupEventType = CEditor::POPEVENT_RESTARTING_SERVER;
1965 pEditor->m_PopupEventActivated = true;
1966 }
1967 pEditor->m_PopupEventWasActivated = false;
1968 return CUi::POPUP_CLOSE_CURRENT;
1969 }
1970
1971 if(pEditor->m_PopupEventType == POPEVENT_CLOSE_MAP)
1972 {
1973 static int s_DiscardButton = 0;
1974 ButtonBar.VMargin(Cut: (ButtonBar.w - 110.0f) / 2.0f, pOtherRect: &Button);
1975 if(pEditor->DoButton_Editor(pId: &s_DiscardButton, pText: "Discard changes", Checked: EditorButtonChecked::DANGEROUS_ACTION, pRect: &Button, Flags: BUTTONFLAG_LEFT, pToolTip: nullptr))
1976 {
1977 pEditor->CloseMap(Index: pEditor->m_SelectedMap, Confirm: false);
1978 }
1979 }
1980
1981 return CUi::POPUP_KEEP_OPEN;
1982}
1983
1984static int g_SelectImageSelected = -100;
1985static int g_SelectImageCurrent = -100;
1986
1987CUi::EPopupMenuFunctionResult CEditor::PopupSelectImage(void *pContext, CUIRect View, bool Active)
1988{
1989 CEditor *pEditor = static_cast<CEditor *>(pContext);
1990
1991 CUIRect ButtonBar, ImageView;
1992 View.VSplitLeft(Cut: 150.0f, pLeft: &ButtonBar, pRight: &View);
1993 View.Margin(Cut: 10.0f, pOtherRect: &ImageView);
1994
1995 int ShowImage = g_SelectImageCurrent;
1996
1997 const float ButtonHeight = 12.0f;
1998 const float ButtonMargin = 2.0f;
1999
2000 static CListBox s_ListBox;
2001 s_ListBox.DoStart(RowHeight: ButtonHeight, NumItems: pEditor->Map()->m_vpImages.size() + 1, ItemsPerRow: 1, RowsPerScroll: 4, SelectedIndex: g_SelectImageCurrent + 1, pRect: &ButtonBar, Background: false);
2002 s_ListBox.DoAutoSpacing(Spacing: ButtonMargin);
2003
2004 for(int i = 0; i <= (int)pEditor->Map()->m_vpImages.size(); i++)
2005 {
2006 static int s_NoneButton = 0;
2007 CListboxItem Item = s_ListBox.DoNextItem(pId: i == 0 ? (void *)&s_NoneButton : &pEditor->Map()->m_vpImages[i - 1], Selected: (i - 1) == g_SelectImageCurrent, CornerRadius: 3.0f);
2008 if(!Item.m_Visible)
2009 continue;
2010
2011 if(pEditor->Ui()->MouseInside(pRect: &Item.m_Rect))
2012 ShowImage = i - 1;
2013
2014 CUIRect Label;
2015 Item.m_Rect.VMargin(Cut: 5.0f, pOtherRect: &Label);
2016
2017 SLabelProperties Props;
2018 Props.m_MaxWidth = Label.w;
2019 Props.m_EllipsisAtEnd = true;
2020 pEditor->Ui()->DoLabel(pRect: &Label, pText: i == 0 ? "None" : pEditor->Map()->m_vpImages[i - 1]->m_aName, Size: EditorFontSizes::MENU, Align: TEXTALIGN_ML, LabelProps: Props);
2021 }
2022
2023 int NewSelected = s_ListBox.DoEnd() - 1;
2024 if(NewSelected != g_SelectImageCurrent)
2025 g_SelectImageSelected = NewSelected;
2026
2027 if(ShowImage >= 0 && (size_t)ShowImage < pEditor->Map()->m_vpImages.size())
2028 {
2029 if(ImageView.h < ImageView.w)
2030 ImageView.w = ImageView.h;
2031 else
2032 ImageView.h = ImageView.w;
2033 float Max = std::max(a: pEditor->Map()->m_vpImages[ShowImage]->m_Width, b: pEditor->Map()->m_vpImages[ShowImage]->m_Height);
2034 ImageView.w *= pEditor->Map()->m_vpImages[ShowImage]->m_Width / Max;
2035 ImageView.h *= pEditor->Map()->m_vpImages[ShowImage]->m_Height / Max;
2036 pEditor->Graphics()->TextureSet(Texture: pEditor->Map()->m_vpImages[ShowImage]->m_Texture);
2037 pEditor->Graphics()->WrapClamp();
2038 pEditor->Graphics()->QuadsBegin();
2039 IGraphics::CQuadItem QuadItem(ImageView.x, ImageView.y, ImageView.w, ImageView.h);
2040 pEditor->Graphics()->QuadsDrawTL(pArray: &QuadItem, Num: 1);
2041 pEditor->Graphics()->QuadsEnd();
2042 pEditor->Graphics()->WrapNormal();
2043 }
2044
2045 return CUi::POPUP_KEEP_OPEN;
2046}
2047
2048void CEditor::PopupSelectImageInvoke(int Current, float x, float y)
2049{
2050 static SPopupMenuId s_PopupSelectImageId;
2051 g_SelectImageSelected = -100;
2052 g_SelectImageCurrent = Current;
2053 Ui()->DoPopupMenu(pId: &s_PopupSelectImageId, X: x, Y: y, Width: 450, Height: 300, pContext: this, pfnFunc: PopupSelectImage);
2054}
2055
2056int CEditor::PopupSelectImageResult()
2057{
2058 if(g_SelectImageSelected == -100)
2059 return -100;
2060
2061 g_SelectImageCurrent = g_SelectImageSelected;
2062 g_SelectImageSelected = -100;
2063 return g_SelectImageCurrent;
2064}
2065
2066static int g_SelectSoundSelected = -100;
2067static int g_SelectSoundCurrent = -100;
2068
2069CUi::EPopupMenuFunctionResult CEditor::PopupSelectSound(void *pContext, CUIRect View, bool Active)
2070{
2071 CEditor *pEditor = static_cast<CEditor *>(pContext);
2072
2073 const float ButtonHeight = 12.0f;
2074 const float ButtonMargin = 2.0f;
2075
2076 static CListBox s_ListBox;
2077 s_ListBox.DoStart(RowHeight: ButtonHeight, NumItems: pEditor->Map()->m_vpSounds.size() + 1, ItemsPerRow: 1, RowsPerScroll: 4, SelectedIndex: g_SelectSoundCurrent + 1, pRect: &View, Background: false);
2078 s_ListBox.DoAutoSpacing(Spacing: ButtonMargin);
2079
2080 for(int i = 0; i <= (int)pEditor->Map()->m_vpSounds.size(); i++)
2081 {
2082 static int s_NoneButton = 0;
2083 CListboxItem Item = s_ListBox.DoNextItem(pId: i == 0 ? (void *)&s_NoneButton : &pEditor->Map()->m_vpSounds[i - 1], Selected: (i - 1) == g_SelectSoundCurrent, CornerRadius: 3.0f);
2084 if(!Item.m_Visible)
2085 continue;
2086
2087 CUIRect Label;
2088 Item.m_Rect.VMargin(Cut: 5.0f, pOtherRect: &Label);
2089
2090 SLabelProperties Props;
2091 Props.m_MaxWidth = Label.w;
2092 Props.m_EllipsisAtEnd = true;
2093 pEditor->Ui()->DoLabel(pRect: &Label, pText: i == 0 ? "None" : pEditor->Map()->m_vpSounds[i - 1]->m_aName, Size: EditorFontSizes::MENU, Align: TEXTALIGN_ML, LabelProps: Props);
2094 }
2095
2096 int NewSelected = s_ListBox.DoEnd() - 1;
2097 if(NewSelected != g_SelectSoundCurrent)
2098 g_SelectSoundSelected = NewSelected;
2099
2100 return CUi::POPUP_KEEP_OPEN;
2101}
2102
2103void CEditor::PopupSelectSoundInvoke(int Current, float x, float y)
2104{
2105 static SPopupMenuId s_PopupSelectSoundId;
2106 g_SelectSoundSelected = -100;
2107 g_SelectSoundCurrent = Current;
2108 Ui()->DoPopupMenu(pId: &s_PopupSelectSoundId, X: x, Y: y, Width: 150, Height: 300, pContext: this, pfnFunc: PopupSelectSound);
2109}
2110
2111int CEditor::PopupSelectSoundResult()
2112{
2113 if(g_SelectSoundSelected == -100)
2114 return -100;
2115
2116 g_SelectSoundCurrent = g_SelectSoundSelected;
2117 g_SelectSoundSelected = -100;
2118 return g_SelectSoundCurrent;
2119}
2120
2121static int s_GametileOpSelected = -1;
2122
2123static const char *s_apGametileOpButtonNames[] = {
2124 "Air",
2125 "Hookable",
2126 "Death",
2127 "Unhookable",
2128 "Hookthrough",
2129 "Freeze",
2130 "Unfreeze",
2131 "Deep Freeze",
2132 "Deep Unfreeze",
2133 "Blue Check-Tele",
2134 "Red Check-Tele",
2135 "Live Freeze",
2136 "Live Unfreeze",
2137};
2138
2139CUi::EPopupMenuFunctionResult CEditor::PopupSelectGametileOp(void *pContext, CUIRect View, bool Active)
2140{
2141 CEditor *pEditor = static_cast<CEditor *>(pContext);
2142
2143 const int PreviousSelected = s_GametileOpSelected;
2144
2145 CUIRect Button;
2146 for(size_t i = 0; i < std::size(s_apGametileOpButtonNames); ++i)
2147 {
2148 View.HSplitTop(Cut: 2.0f, pTop: nullptr, pBottom: &View);
2149 View.HSplitTop(Cut: 12.0f, pTop: &Button, pBottom: &View);
2150 if(pEditor->DoButton_Editor(pId: &s_apGametileOpButtonNames[i], pText: s_apGametileOpButtonNames[i], Checked: 0, pRect: &Button, Flags: BUTTONFLAG_LEFT, pToolTip: nullptr))
2151 s_GametileOpSelected = i;
2152 }
2153
2154 return s_GametileOpSelected == PreviousSelected ? CUi::POPUP_KEEP_OPEN : CUi::POPUP_CLOSE_CURRENT;
2155}
2156
2157void CEditor::PopupSelectGametileOpInvoke(float x, float y)
2158{
2159 static SPopupMenuId s_PopupSelectGametileOpId;
2160 s_GametileOpSelected = -1;
2161 Ui()->DoPopupMenu(pId: &s_PopupSelectGametileOpId, X: x, Y: y, Width: 120.0f, Height: std::size(s_apGametileOpButtonNames) * 14.0f + 10.0f, pContext: this, pfnFunc: PopupSelectGametileOp);
2162}
2163
2164int CEditor::PopupSelectGameTileOpResult()
2165{
2166 if(s_GametileOpSelected < 0)
2167 return -1;
2168
2169 int Result = s_GametileOpSelected;
2170 s_GametileOpSelected = -1;
2171 return Result;
2172}
2173
2174static int s_AutomapperConfigSelected = -100;
2175static int s_AutomapperConfigCurrent = -100;
2176
2177CUi::EPopupMenuFunctionResult CEditor::PopupSelectAutomapperConfig(void *pContext, CUIRect View, bool Active)
2178{
2179 CEditor *pEditor = static_cast<CEditor *>(pContext);
2180 std::shared_ptr<CLayerTiles> pLayer = std::static_pointer_cast<CLayerTiles>(r: pEditor->Map()->SelectedLayer(Index: 0));
2181 CAutomapper *pAutomapper = &pEditor->Map()->m_vpImages[pLayer->m_Image]->m_Automapper;
2182
2183 const float ButtonHeight = 12.0f;
2184 const float ButtonMargin = 2.0f;
2185
2186 CUIRect Button;
2187 View.HSplitBottom(Cut: ButtonHeight, pTop: &View, pBottom: &Button);
2188 static char s_ShowDirectoryButton;
2189 if(pEditor->DoButton_MenuItem(pId: &s_ShowDirectoryButton, pText: "Show directory", Checked: 0, pRect: &Button, Flags: BUTTONFLAG_LEFT, pToolTip: "Open the directory for automapper rules in the file browser."))
2190 {
2191 char aPath[IO_MAX_PATH_LENGTH];
2192 pEditor->Storage()->GetCompletePath(Type: IStorage::TYPE_SAVE, pDir: "editor/automap", pBuffer: aPath, BufferSize: sizeof(aPath));
2193 pEditor->Storage()->CreateFolder(pFoldername: "editor", Type: IStorage::TYPE_SAVE);
2194 pEditor->Storage()->CreateFolder(pFoldername: "editor/automap", Type: IStorage::TYPE_SAVE);
2195 pEditor->Client()->ViewFile(pFilename: aPath);
2196 }
2197
2198 View.HSplitBottom(Cut: 5.0f, pTop: &View, pBottom: &Button);
2199 IGraphics::CLineItem LineItem(Button.x, Button.y + Button.h / 2, Button.x + Button.w, Button.y + Button.h / 2);
2200 pEditor->Graphics()->TextureClear();
2201 pEditor->Graphics()->LinesBegin();
2202 pEditor->Graphics()->LinesDraw(pArray: &LineItem, Num: 1);
2203 pEditor->Graphics()->LinesEnd();
2204
2205 static CListBox s_ListBox;
2206 s_ListBox.DoStart(RowHeight: ButtonHeight, NumItems: pAutomapper->ConfigNamesNum() + 1, ItemsPerRow: 1, RowsPerScroll: 4, SelectedIndex: s_AutomapperConfigCurrent + 1, pRect: &View, Background: false);
2207 s_ListBox.SetScrollbarWidth(15.0f);
2208 s_ListBox.DoAutoSpacing(Spacing: ButtonMargin);
2209
2210 for(int i = 0; i < pAutomapper->ConfigNamesNum() + 1; i++)
2211 {
2212 static int s_NoneButton = 0;
2213 CListboxItem Item = s_ListBox.DoNextItem(pId: i == 0 ? (void *)&s_NoneButton : pAutomapper->GetConfigName(Index: i - 1), Selected: (i - 1) == s_AutomapperConfigCurrent, CornerRadius: 3.0f);
2214 if(!Item.m_Visible)
2215 continue;
2216
2217 CUIRect Label;
2218 Item.m_Rect.VMargin(Cut: 5.0f, pOtherRect: &Label);
2219
2220 SLabelProperties Props;
2221 Props.m_MaxWidth = Label.w;
2222 Props.m_EllipsisAtEnd = true;
2223 pEditor->Ui()->DoLabel(pRect: &Label, pText: i == 0 ? "None" : pAutomapper->GetConfigName(Index: i - 1), Size: EditorFontSizes::MENU, Align: TEXTALIGN_ML, LabelProps: Props);
2224 }
2225
2226 int NewSelected = s_ListBox.DoEnd() - 1;
2227 if(NewSelected != s_AutomapperConfigCurrent)
2228 s_AutomapperConfigSelected = NewSelected;
2229
2230 return CUi::POPUP_KEEP_OPEN;
2231}
2232
2233void CEditor::PopupSelectAutomapperConfigInvoke(int Current, float x, float y)
2234{
2235 static SPopupMenuId s_PopupSelectAutomapperConfigId;
2236 s_AutomapperConfigSelected = -100;
2237 s_AutomapperConfigCurrent = Current;
2238 std::shared_ptr<CLayerTiles> pLayer = std::static_pointer_cast<CLayerTiles>(r: Map()->SelectedLayer(Index: 0));
2239 const int ItemCount = std::min(a: Map()->m_vpImages[pLayer->m_Image]->m_Automapper.ConfigNamesNum() + 1, b: 10); // +1 for None-entry
2240 // Width for buttons is 120, 15 is the scrollbar width, 2 is the margin between both.
2241 Ui()->DoPopupMenu(pId: &s_PopupSelectAutomapperConfigId, X: x, Y: y, Width: 120.0f + 15.0f + 2.0f, Height: 10.0f + 12.0f * ItemCount + 2.0f * (ItemCount - 1) + 5.0f + 12.0f, pContext: this, pfnFunc: PopupSelectAutomapperConfig);
2242}
2243
2244int CEditor::PopupSelectAutomapperConfigResult()
2245{
2246 if(s_AutomapperConfigSelected == -100)
2247 return -100;
2248
2249 s_AutomapperConfigCurrent = s_AutomapperConfigSelected;
2250 s_AutomapperConfigSelected = -100;
2251 return s_AutomapperConfigCurrent;
2252}
2253
2254static int s_AutomapperReferenceSelected = -100;
2255static int s_AutomapperReferenceCurrent = -100;
2256
2257CUi::EPopupMenuFunctionResult CEditor::PopupSelectAutomapperReference(void *pContext, CUIRect View, bool Active)
2258{
2259 CEditor *pEditor = static_cast<CEditor *>(pContext);
2260
2261 const float ButtonHeight = 12.0f;
2262 const float ButtonMargin = 2.0f;
2263
2264 static CListBox s_ListBox;
2265 s_ListBox.DoStart(RowHeight: ButtonHeight, NumItems: std::size(AUTOMAP_REFERENCE_NAMES) + 1, ItemsPerRow: 1, RowsPerScroll: 4, SelectedIndex: s_AutomapperReferenceCurrent + 1, pRect: &View, Background: false);
2266 s_ListBox.DoAutoSpacing(Spacing: ButtonMargin);
2267
2268 for(int i = 0; i < static_cast<int>(std::size(AUTOMAP_REFERENCE_NAMES)) + 1; i++)
2269 {
2270 static int s_NoneButton = 0;
2271 CListboxItem Item = s_ListBox.DoNextItem(pId: i == 0 ? (void *)&s_NoneButton : AUTOMAP_REFERENCE_NAMES[i - 1], Selected: (i - 1) == s_AutomapperReferenceCurrent, CornerRadius: 3.0f);
2272 if(!Item.m_Visible)
2273 continue;
2274
2275 CUIRect Label;
2276 Item.m_Rect.VMargin(Cut: 5.0f, pOtherRect: &Label);
2277
2278 SLabelProperties Props;
2279 Props.m_MaxWidth = Label.w;
2280 Props.m_EllipsisAtEnd = true;
2281 pEditor->Ui()->DoLabel(pRect: &Label, pText: i == 0 ? "None" : AUTOMAP_REFERENCE_NAMES[i - 1], Size: EditorFontSizes::MENU, Align: TEXTALIGN_ML, LabelProps: Props);
2282 }
2283
2284 int NewSelected = s_ListBox.DoEnd() - 1;
2285 if(NewSelected != s_AutomapperReferenceCurrent)
2286 s_AutomapperReferenceSelected = NewSelected;
2287
2288 return CUi::POPUP_KEEP_OPEN;
2289}
2290
2291void CEditor::PopupSelectAutomapperReferenceInvoke(int Current, float x, float y)
2292{
2293 static SPopupMenuId s_PopupSelectAutomapperReferenceId;
2294 s_AutomapperReferenceSelected = -100;
2295 s_AutomapperReferenceCurrent = Current;
2296 // Width for buttons is 120, 15 is the scrollbar width, 2 is the margin between both.
2297 Ui()->DoPopupMenu(pId: &s_PopupSelectAutomapperReferenceId, X: x, Y: y, Width: 120.0f + 15.0f + 2.0f, Height: 26.0f + 14.0f * std::size(AUTOMAP_REFERENCE_NAMES) + 1, pContext: this, pfnFunc: PopupSelectAutomapperReference);
2298}
2299
2300int CEditor::PopupSelectAutomapperReferenceResult()
2301{
2302 if(s_AutomapperReferenceSelected == -100)
2303 return -100;
2304
2305 s_AutomapperReferenceCurrent = s_AutomapperReferenceSelected;
2306 s_AutomapperReferenceSelected = -100;
2307 return s_AutomapperReferenceCurrent;
2308}
2309
2310// DDRace
2311
2312CUi::EPopupMenuFunctionResult CEditor::PopupTele(void *pContext, CUIRect View, bool Active)
2313{
2314 CEditor *pEditor = static_cast<CEditor *>(pContext);
2315
2316 if(!pEditor->Map()->m_pTeleLayer)
2317 return CUi::POPUP_CLOSE_CURRENT;
2318
2319 static int s_PreviousTeleNumber;
2320 static int s_PreviousCheckpointNumber;
2321 static int s_PreviousViewTeleNumber;
2322
2323 CUIRect NumberPicker;
2324 CUIRect FindEmptySlot;
2325 CUIRect FindFreeTeleSlot, FindFreeCheckpointSlot, FindFreeViewSlot;
2326
2327 View.VSplitRight(Cut: 15.f, pLeft: &NumberPicker, pRight: &FindEmptySlot);
2328 NumberPicker.VSplitRight(Cut: 2.f, pLeft: &NumberPicker, pRight: nullptr);
2329
2330 FindEmptySlot.HSplitTop(Cut: 13.0f, pTop: &FindFreeTeleSlot, pBottom: &FindEmptySlot);
2331 FindEmptySlot.HSplitTop(Cut: 13.0f, pTop: &FindFreeCheckpointSlot, pBottom: &FindEmptySlot);
2332 FindEmptySlot.HSplitTop(Cut: 13.0f, pTop: &FindFreeViewSlot, pBottom: &FindEmptySlot);
2333
2334 FindFreeTeleSlot.HMargin(Cut: 1.0f, pOtherRect: &FindFreeTeleSlot);
2335 FindFreeCheckpointSlot.HMargin(Cut: 1.0f, pOtherRect: &FindFreeCheckpointSlot);
2336 FindFreeViewSlot.HMargin(Cut: 1.0f, pOtherRect: &FindFreeViewSlot);
2337
2338 auto ViewTele = [](CEditor *pEd) -> bool {
2339 if(!pEd->m_ViewTeleNumber)
2340 return false;
2341 int TeleX, TeleY;
2342 pEd->Map()->m_pTeleLayer->GetPos(Number: pEd->m_ViewTeleNumber, Offset: -1, TeleX, TeleY);
2343 if(TeleX != -1 && TeleY != -1)
2344 {
2345 pEd->MapView()->SetWorldOffset({32.0f * (TeleX + 0.5f), 32.0f * (TeleY + 0.5f)});
2346 return true;
2347 }
2348 return false;
2349 };
2350
2351 static std::vector<ColorRGBA> s_vColors = {
2352 ColorRGBA(0.5f, 1, 0.5f, 0.5f),
2353 ColorRGBA(0.5f, 1, 0.5f, 0.5f),
2354 ColorRGBA(1, 0.5f, 0.5f, 0.5f),
2355 };
2356 enum
2357 {
2358 PROP_TELE = 0,
2359 PROP_TELE_CP,
2360 PROP_TELE_VIEW,
2361 NUM_PROPS,
2362 };
2363
2364 // find next free numbers buttons
2365 {
2366 // Pressing ctrl+f will find next free numbers for both tele and checkpoints
2367
2368 static int s_NextFreeTelePid = 0;
2369 if(pEditor->DoButton_Editor(pId: &s_NextFreeTelePid, pText: "F", Checked: 0, pRect: &FindFreeTeleSlot, Flags: BUTTONFLAG_LEFT, pToolTip: "[Ctrl+F] Find next free tele number.") ||
2370 (Active && pEditor->Input()->ModifierIsPressed() && pEditor->Input()->KeyPress(Key: KEY_F)))
2371 {
2372 int TeleNumber = pEditor->Map()->m_pTeleLayer->FindNextFreeNumber(Checkpoint: false);
2373 if(TeleNumber != -1)
2374 {
2375 pEditor->m_TeleNumber = TeleNumber;
2376 pEditor->AdjustBrushSpecialTiles(UseNextFree: false, AdjustModifiers: 0, AdjustValue: 0);
2377 }
2378 }
2379
2380 static int s_NextFreeCheckpointPid = 0;
2381 if(pEditor->DoButton_Editor(pId: &s_NextFreeCheckpointPid, pText: "F", Checked: 0, pRect: &FindFreeCheckpointSlot, Flags: BUTTONFLAG_LEFT, pToolTip: "[Ctrl+F] Find next free checkpoint number.") ||
2382 (Active && pEditor->Input()->ModifierIsPressed() && pEditor->Input()->KeyPress(Key: KEY_F)))
2383 {
2384 int CheckpointNumber = pEditor->Map()->m_pTeleLayer->FindNextFreeNumber(Checkpoint: true);
2385 if(CheckpointNumber != -1)
2386 {
2387 pEditor->m_TeleCheckpointNumber = CheckpointNumber;
2388 pEditor->AdjustBrushSpecialTiles(UseNextFree: false, AdjustModifiers: 0, AdjustValue: 0);
2389 }
2390 }
2391
2392 static int s_NextFreeViewPid = 0;
2393 if(pEditor->DoButton_Editor(pId: &s_NextFreeViewPid, pText: "N", Checked: 0, pRect: &FindFreeViewSlot, Flags: BUTTONFLAG_LEFT, pToolTip: "[N] Show next tele with this number.") ||
2394 (Active && pEditor->Input()->KeyPress(Key: KEY_N)))
2395 {
2396 s_vColors[PROP_TELE_VIEW] = ViewTele(pEditor) ? ColorRGBA(0.5f, 1, 0.5f, 0.5f) : ColorRGBA(1, 0.5f, 0.5f, 0.5f);
2397 }
2398 }
2399
2400 // number picker
2401 {
2402 CProperty aProps[] = {
2403 {"Number", pEditor->m_TeleNumber, PROPTYPE_INT, 1, 255},
2404 {"Checkpoint", pEditor->m_TeleCheckpointNumber, PROPTYPE_INT, 1, 255},
2405 {"View", pEditor->m_ViewTeleNumber, PROPTYPE_INT, 1, 255},
2406 {nullptr},
2407 };
2408
2409 static int s_aIds[NUM_PROPS] = {0};
2410
2411 int NewVal = 0;
2412 int Prop = pEditor->DoProperties(pToolbox: &NumberPicker, pProps: aProps, pIds: s_aIds, pNewVal: &NewVal, vColors: s_vColors);
2413 if(Prop == PROP_TELE)
2414 {
2415 pEditor->m_TeleNumber = (NewVal - 1 + 255) % 255 + 1;
2416 pEditor->AdjustBrushSpecialTiles(UseNextFree: false, AdjustModifiers: 0, AdjustValue: 0);
2417 }
2418 else if(Prop == PROP_TELE_CP)
2419 {
2420 pEditor->m_TeleCheckpointNumber = (NewVal - 1 + 255) % 255 + 1;
2421 pEditor->AdjustBrushSpecialTiles(UseNextFree: false, AdjustModifiers: 0, AdjustValue: 0);
2422 }
2423 else if(Prop == PROP_TELE_VIEW)
2424 pEditor->m_ViewTeleNumber = (NewVal - 1 + 255) % 255 + 1;
2425
2426 if(s_PreviousTeleNumber == 1 || s_PreviousTeleNumber != pEditor->m_TeleNumber)
2427 s_vColors[PROP_TELE] = pEditor->Map()->m_pTeleLayer->ContainsElementWithId(Id: pEditor->m_TeleNumber, Checkpoint: false) ? ColorRGBA(1, 0.5f, 0.5f, 0.5f) : ColorRGBA(0.5f, 1, 0.5f, 0.5f);
2428
2429 if(s_PreviousCheckpointNumber == 1 || s_PreviousCheckpointNumber != pEditor->m_TeleCheckpointNumber)
2430 s_vColors[PROP_TELE_CP] = pEditor->Map()->m_pTeleLayer->ContainsElementWithId(Id: pEditor->m_TeleCheckpointNumber, Checkpoint: true) ? ColorRGBA(1, 0.5f, 0.5f, 0.5f) : ColorRGBA(0.5f, 1, 0.5f, 0.5f);
2431
2432 if(s_PreviousViewTeleNumber != pEditor->m_ViewTeleNumber)
2433 s_vColors[PROP_TELE_VIEW] = ViewTele(pEditor) ? ColorRGBA(0.5f, 1, 0.5f, 0.5f) : ColorRGBA(1, 0.5f, 0.5f, 0.5f);
2434 }
2435
2436 s_PreviousTeleNumber = pEditor->m_TeleNumber;
2437 s_PreviousCheckpointNumber = pEditor->m_TeleCheckpointNumber;
2438 s_PreviousViewTeleNumber = pEditor->m_ViewTeleNumber;
2439
2440 return CUi::POPUP_KEEP_OPEN;
2441}
2442
2443CUi::EPopupMenuFunctionResult CEditor::PopupSpeedup(void *pContext, CUIRect View, bool Active)
2444{
2445 CEditor *pEditor = static_cast<CEditor *>(pContext);
2446
2447 enum
2448 {
2449 PROP_FORCE = 0,
2450 PROP_MAXSPEED,
2451 PROP_ANGLE,
2452 NUM_PROPS
2453 };
2454
2455 CProperty aProps[] = {
2456 {"Force", pEditor->m_SpeedupForce, PROPTYPE_INT, 1, 255},
2457 {"Max Speed", pEditor->m_SpeedupMaxSpeed, PROPTYPE_INT, 0, 255},
2458 {"Angle", pEditor->m_SpeedupAngle, PROPTYPE_ANGLE_SCROLL, 0, 359},
2459 {nullptr},
2460 };
2461
2462 static int s_aIds[NUM_PROPS] = {0};
2463 int NewVal = 0;
2464 int Prop = pEditor->DoProperties(pToolbox: &View, pProps: aProps, pIds: s_aIds, pNewVal: &NewVal);
2465
2466 if(Prop == PROP_FORCE)
2467 {
2468 pEditor->m_SpeedupForce = std::clamp(val: NewVal, lo: 1, hi: 255);
2469 }
2470 else if(Prop == PROP_MAXSPEED)
2471 {
2472 pEditor->m_SpeedupMaxSpeed = std::clamp(val: NewVal, lo: 0, hi: 255);
2473 }
2474 else if(Prop == PROP_ANGLE)
2475 {
2476 pEditor->m_SpeedupAngle = std::clamp(val: NewVal, lo: 0, hi: 359);
2477 pEditor->AdjustBrushSpecialTiles(UseNextFree: false, AdjustModifiers: 0, AdjustValue: 0);
2478 }
2479
2480 return CUi::POPUP_KEEP_OPEN;
2481}
2482
2483CUi::EPopupMenuFunctionResult CEditor::PopupSwitch(void *pContext, CUIRect View, bool Active)
2484{
2485 CEditor *pEditor = static_cast<CEditor *>(pContext);
2486
2487 if(!pEditor->Map()->m_pSwitchLayer)
2488 return CUi::POPUP_CLOSE_CURRENT;
2489
2490 CUIRect NumberPicker, FindEmptySlot, ViewEmptySlot;
2491
2492 View.VSplitRight(Cut: 15.0f, pLeft: &NumberPicker, pRight: &FindEmptySlot);
2493 NumberPicker.VSplitRight(Cut: 2.0f, pLeft: &NumberPicker, pRight: nullptr);
2494
2495 FindEmptySlot.HSplitTop(Cut: 13.0f, pTop: &FindEmptySlot, pBottom: &ViewEmptySlot);
2496 ViewEmptySlot.HSplitTop(Cut: 13.0f, pTop: nullptr, pBottom: &ViewEmptySlot);
2497
2498 FindEmptySlot.HMargin(Cut: 1.0f, pOtherRect: &FindEmptySlot);
2499 ViewEmptySlot.HMargin(Cut: 1.0f, pOtherRect: &ViewEmptySlot);
2500
2501 auto ViewSwitch = [pEditor]() -> bool {
2502 if(!pEditor->m_ViewSwitch)
2503 return false;
2504 ivec2 SwitchPos;
2505 pEditor->Map()->m_pSwitchLayer->GetPos(Number: pEditor->m_ViewSwitch, Offset: -1, SwitchPos);
2506 if(SwitchPos != ivec2(-1, -1))
2507 {
2508 pEditor->MapView()->SetWorldOffset({32.0f * (SwitchPos.x + 0.5f), 32.0f * (SwitchPos.y + 0.5f)});
2509 return true;
2510 }
2511 return false;
2512 };
2513
2514 static std::vector<ColorRGBA> s_vColors = {
2515 ColorRGBA(1, 1, 1, 0.5f),
2516 ColorRGBA(1, 1, 1, 0.5f),
2517 ColorRGBA(1, 1, 1, 0.5f),
2518 };
2519
2520 enum
2521 {
2522 PROP_SWITCH_NUMBER = 0,
2523 PROP_SWITCH_DELAY,
2524 PROP_SWITCH_VIEW,
2525 NUM_PROPS,
2526 };
2527
2528 // find empty number button
2529 {
2530 static int s_EmptySlotPid = 0;
2531 if(pEditor->DoButton_Editor(pId: &s_EmptySlotPid, pText: "F", Checked: 0, pRect: &FindEmptySlot, Flags: BUTTONFLAG_LEFT, pToolTip: "[Ctrl+F] Find empty slot.") ||
2532 (Active && pEditor->Input()->ModifierIsPressed() && pEditor->Input()->KeyPress(Key: KEY_F)))
2533 {
2534 int Number = pEditor->Map()->m_pSwitchLayer->FindNextFreeNumber();
2535 if(Number != -1)
2536 pEditor->m_SwitchNumber = Number;
2537 }
2538
2539 static int s_NextViewPid = 0;
2540 if(pEditor->DoButton_Editor(pId: &s_NextViewPid, pText: "N", Checked: 0, pRect: &ViewEmptySlot, Flags: BUTTONFLAG_LEFT, pToolTip: "[N] Show next switcher with this number.") ||
2541 (Active && pEditor->Input()->KeyPress(Key: KEY_N)))
2542 {
2543 s_vColors[PROP_SWITCH_VIEW] = ViewSwitch() ? ColorRGBA(0.5f, 1, 0.5f, 0.5f) : ColorRGBA(1, 0.5f, 0.5f, 0.5f);
2544 }
2545 }
2546
2547 // number picker
2548 static int s_PreviousNumber = -1;
2549 static int s_PreviousView = -1;
2550 {
2551 CProperty aProps[] = {
2552 {"Number", pEditor->m_SwitchNumber, PROPTYPE_INT, 0, 255},
2553 {"Delay", pEditor->m_SwitchDelay, PROPTYPE_INT, 0, 255},
2554 {"View", pEditor->m_ViewSwitch, PROPTYPE_INT, 0, 255},
2555 {nullptr},
2556 };
2557
2558 static int s_aIds[NUM_PROPS] = {0};
2559 int NewVal = 0;
2560 int Prop = pEditor->DoProperties(pToolbox: &NumberPicker, pProps: aProps, pIds: s_aIds, pNewVal: &NewVal, vColors: s_vColors);
2561
2562 if(Prop == PROP_SWITCH_NUMBER)
2563 {
2564 pEditor->m_SwitchNumber = (NewVal + 256) % 256;
2565 }
2566 else if(Prop == PROP_SWITCH_DELAY)
2567 {
2568 pEditor->m_SwitchDelay = (NewVal + 256) % 256;
2569 }
2570 else if(Prop == PROP_SWITCH_VIEW)
2571 {
2572 pEditor->m_ViewSwitch = (NewVal + 256) % 256;
2573 }
2574
2575 if(s_PreviousNumber == 1 || s_PreviousNumber != pEditor->m_SwitchNumber)
2576 s_vColors[PROP_SWITCH_NUMBER] = pEditor->Map()->m_pSwitchLayer->ContainsElementWithId(Id: pEditor->m_SwitchNumber) ? ColorRGBA(1, 0.5f, 0.5f, 0.5f) : ColorRGBA(0.5f, 1, 0.5f, 0.5f);
2577 if(s_PreviousView != pEditor->m_ViewSwitch)
2578 s_vColors[PROP_SWITCH_VIEW] = ViewSwitch() ? ColorRGBA(0.5f, 1, 0.5f, 0.5f) : ColorRGBA(1, 0.5f, 0.5f, 0.5f);
2579 }
2580
2581 s_PreviousNumber = pEditor->m_SwitchNumber;
2582 s_PreviousView = pEditor->m_ViewSwitch;
2583 return CUi::POPUP_KEEP_OPEN;
2584}
2585
2586CUi::EPopupMenuFunctionResult CEditor::PopupTune(void *pContext, CUIRect View, bool Active)
2587{
2588 CEditor *pEditor = static_cast<CEditor *>(pContext);
2589
2590 if(!pEditor->Map()->m_pTuneLayer)
2591 return CUi::POPUP_CLOSE_CURRENT;
2592
2593 CUIRect NumberPicker, FindEmptySlot, ViewEmptySlot;
2594
2595 View.VSplitRight(Cut: 15.0f, pLeft: &NumberPicker, pRight: &FindEmptySlot);
2596 NumberPicker.VSplitRight(Cut: 2.0f, pLeft: &NumberPicker, pRight: nullptr);
2597
2598 FindEmptySlot.HSplitTop(Cut: 13.0f, pTop: &FindEmptySlot, pBottom: &ViewEmptySlot);
2599 FindEmptySlot.HMargin(Cut: 1.0f, pOtherRect: &FindEmptySlot);
2600 ViewEmptySlot.HMargin(Cut: 1.0f, pOtherRect: &ViewEmptySlot);
2601
2602 auto ViewTune = [pEditor]() -> bool {
2603 if(!pEditor->m_ViewTuning)
2604 return false;
2605 ivec2 TunePos;
2606 pEditor->Map()->m_pTuneLayer->GetPos(Number: pEditor->m_ViewTuning, Offset: -1, Pos&: TunePos);
2607
2608 if(TunePos != ivec2(-1, -1))
2609 {
2610 pEditor->MapView()->SetWorldOffset({32.0f * (TunePos.x + 0.5f), 32.0f * (TunePos.y + 0.5f)});
2611 return true;
2612 }
2613 return false;
2614 };
2615
2616 static std::vector<ColorRGBA> s_vColors = {
2617 ColorRGBA(1, 1, 1, 0.5f),
2618 ColorRGBA(1, 0.5f, 0.5f, 0.5f),
2619 };
2620
2621 enum
2622 {
2623 PROP_TUNE_NUMBER = 0,
2624 PROP_TUNE_VIEW,
2625 NUM_PROPS,
2626 };
2627
2628 // find empty number button
2629 {
2630 static int s_EmptySlotPid = 0;
2631 if(pEditor->DoButton_Editor(pId: &s_EmptySlotPid, pText: "F", Checked: 0, pRect: &FindEmptySlot, Flags: BUTTONFLAG_LEFT, pToolTip: "[Ctrl+F] Find unused zone.") ||
2632 (Active && pEditor->Input()->ModifierIsPressed() && pEditor->Input()->KeyPress(Key: KEY_F)))
2633 {
2634 int Number = pEditor->Map()->m_pTuneLayer->FindNextFreeNumber();
2635 if(Number != -1)
2636 pEditor->m_TuningNumber = Number;
2637 }
2638
2639 static int s_NextViewPid = 0;
2640 if(pEditor->DoButton_Editor(pId: &s_NextViewPid, pText: "N", Checked: 0, pRect: &ViewEmptySlot, Flags: BUTTONFLAG_LEFT, pToolTip: "[N] Show next tune tile with this number.") ||
2641 (Active && pEditor->Input()->KeyPress(Key: KEY_N)))
2642 {
2643 s_vColors[PROP_TUNE_VIEW] = ViewTune() ? ColorRGBA(0.5f, 1, 0.5f, 0.5f) : ColorRGBA(1, 0.5f, 0.5f, 0.5f);
2644 }
2645 }
2646
2647 // number picker
2648 static int s_PreviousNumber = -1;
2649 static int s_PreviousView = -1;
2650 {
2651 CProperty aProps[] = {
2652 {"Zone", pEditor->m_TuningNumber, PROPTYPE_INT, 1, 255},
2653 {"View", pEditor->m_ViewTuning, PROPTYPE_INT, 1, 255},
2654 {nullptr},
2655 };
2656
2657 static int s_aIds[NUM_PROPS] = {0};
2658 int NewVal = 0;
2659 int Prop = pEditor->DoProperties(pToolbox: &NumberPicker, pProps: aProps, pIds: s_aIds, pNewVal: &NewVal, vColors: s_vColors);
2660
2661 if(Prop == PROP_TUNE_NUMBER)
2662 {
2663 pEditor->m_TuningNumber = (NewVal - 1 + 255) % 255 + 1;
2664 }
2665 else if(Prop == PROP_TUNE_VIEW)
2666 {
2667 pEditor->m_ViewTuning = (NewVal - 1 + 255) % 255 + 1;
2668 }
2669
2670 if(s_PreviousNumber == 1 || s_PreviousNumber != pEditor->m_TuningNumber)
2671 s_vColors[PROP_TUNE_NUMBER] = pEditor->Map()->m_pTuneLayer->ContainsElementWithId(Id: pEditor->m_TuningNumber) ? ColorRGBA(1, 0.5f, 0.5f, 0.5f) : ColorRGBA(0.5f, 1, 0.5f, 0.5f);
2672 if(s_PreviousView != pEditor->m_ViewTuning)
2673 s_vColors[PROP_TUNE_VIEW] = ViewTune() ? ColorRGBA(0.5f, 1, 0.5f, 0.5f) : ColorRGBA(1, 0.5f, 0.5f, 0.5f);
2674 }
2675
2676 s_PreviousNumber = pEditor->m_TuningNumber;
2677 s_PreviousView = pEditor->m_ViewTuning;
2678
2679 return CUi::POPUP_KEEP_OPEN;
2680}
2681
2682CUi::EPopupMenuFunctionResult CEditor::PopupGoto(void *pContext, CUIRect View, bool Active)
2683{
2684 CEditor *pEditor = static_cast<CEditor *>(pContext);
2685
2686 enum
2687 {
2688 PROP_COORD_X = 0,
2689 PROP_COORD_Y,
2690 NUM_PROPS,
2691 };
2692
2693 static ivec2 s_GotoPos(0, 0);
2694
2695 CProperty aProps[] = {
2696 {"X", s_GotoPos.x, PROPTYPE_INT, std::numeric_limits<int>::min(), std::numeric_limits<int>::max()},
2697 {"Y", s_GotoPos.y, PROPTYPE_INT, std::numeric_limits<int>::min(), std::numeric_limits<int>::max()},
2698 {nullptr},
2699 };
2700
2701 static int s_aIds[NUM_PROPS] = {0};
2702 int NewVal = 0;
2703 int Prop = pEditor->DoProperties(pToolbox: &View, pProps: aProps, pIds: s_aIds, pNewVal: &NewVal);
2704
2705 if(Prop == PROP_COORD_X)
2706 {
2707 s_GotoPos.x = NewVal;
2708 }
2709 else if(Prop == PROP_COORD_Y)
2710 {
2711 s_GotoPos.y = NewVal;
2712 }
2713
2714 CUIRect Button;
2715 View.HSplitBottom(Cut: 12.0f, pTop: &View, pBottom: &Button);
2716
2717 static int s_Button;
2718 if(pEditor->DoButton_Editor(pId: &s_Button, pText: "Go", Checked: 0, pRect: &Button, Flags: BUTTONFLAG_LEFT, pToolTip: nullptr))
2719 {
2720 pEditor->MapView()->SetWorldOffset({32.0f * (s_GotoPos.x + 0.5f), 32.0f * (s_GotoPos.y + 0.5f)});
2721 }
2722
2723 return CUi::POPUP_KEEP_OPEN;
2724}
2725
2726CUi::EPopupMenuFunctionResult CEditor::PopupEntities(void *pContext, CUIRect View, bool Active)
2727{
2728 CEditor *pEditor = static_cast<CEditor *>(pContext);
2729
2730 for(size_t i = 0; i < pEditor->m_vSelectEntitiesFiles.size(); i++)
2731 {
2732 CUIRect Button;
2733 View.HSplitTop(Cut: 14.0f, pTop: &Button, pBottom: &View);
2734
2735 const char *pName = pEditor->m_vSelectEntitiesFiles[i].c_str();
2736 if(pEditor->DoButton_MenuItem(pId: pName, pText: pName, Checked: pEditor->m_vSelectEntitiesFiles[i] == pEditor->m_SelectEntitiesImage, pRect: &Button))
2737 {
2738 if(pEditor->m_vSelectEntitiesFiles[i] != pEditor->m_SelectEntitiesImage)
2739 {
2740 if(i == pEditor->m_vSelectEntitiesFiles.size() - 1)
2741 {
2742 pEditor->m_FileBrowser.ShowFileDialog(StorageType: IStorage::TYPE_ALL, FileType: CFileBrowser::EFileType::IMAGE, pTitle: "Load custom entities", pButtonText: "Load", pInitialPath: "assets/entities", pInitialFilename: "", pfnOpenCallback: CallbackCustomEntities, pOpenCallbackUser: pEditor);
2743 return CUi::POPUP_CLOSE_CURRENT;
2744 }
2745
2746 pEditor->m_SelectEntitiesImage = pEditor->m_vSelectEntitiesFiles[i];
2747 pEditor->m_AllowPlaceUnusedTiles = pEditor->m_SelectEntitiesImage == "DDNet" ? EUnusedEntities::NOT_ALLOWED : EUnusedEntities::ALLOWED_IMPLICIT;
2748 pEditor->m_PreventUnusedTilesWasWarned = false;
2749
2750 pEditor->Graphics()->UnloadTexture(pIndex: &pEditor->m_EntitiesTexture);
2751
2752 char aBuf[IO_MAX_PATH_LENGTH];
2753 str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "editor/entities/%s.png", pName);
2754 pEditor->m_EntitiesTexture = pEditor->Graphics()->LoadTexture(pFilename: aBuf, StorageType: IStorage::TYPE_ALL, Flags: pEditor->Graphics()->TextureLoadFlags());
2755 return CUi::POPUP_CLOSE_CURRENT;
2756 }
2757 }
2758 }
2759
2760 return CUi::POPUP_KEEP_OPEN;
2761}
2762
2763CUi::EPopupMenuFunctionResult CEditor::PopupProofMode(void *pContext, CUIRect View, bool Active)
2764{
2765 CEditor *pEditor = static_cast<CEditor *>(pContext);
2766
2767 CUIRect Button;
2768 View.HSplitTop(Cut: 12.0f, pTop: &Button, pBottom: &View);
2769 static int s_ButtonIngame;
2770 if(pEditor->DoButton_MenuItem(pId: &s_ButtonIngame, pText: "Ingame", Checked: pEditor->MapView()->ProofMode()->IsModeIngame(), pRect: &Button, Flags: BUTTONFLAG_LEFT, pToolTip: "These borders represent what a player maximum can see."))
2771 {
2772 pEditor->MapView()->ProofMode()->SetModeIngame();
2773 return CUi::POPUP_CLOSE_CURRENT;
2774 }
2775
2776 View.HSplitTop(Cut: 2.0f, pTop: nullptr, pBottom: &View);
2777 View.HSplitTop(Cut: 12.0f, pTop: &Button, pBottom: &View);
2778 static int s_ButtonMenu;
2779 if(pEditor->DoButton_MenuItem(pId: &s_ButtonMenu, pText: "Menu", Checked: pEditor->MapView()->ProofMode()->IsModeMenu(), pRect: &Button, Flags: BUTTONFLAG_LEFT, pToolTip: "These borders represent what will be shown in the menu."))
2780 {
2781 pEditor->MapView()->ProofMode()->SetModeMenu();
2782 return CUi::POPUP_CLOSE_CURRENT;
2783 }
2784
2785 return CUi::POPUP_KEEP_OPEN;
2786}
2787
2788CUi::EPopupMenuFunctionResult CEditor::PopupAnimateSettings(void *pContext, CUIRect View, bool Active)
2789{
2790 CEditor *pEditor = static_cast<CEditor *>(pContext);
2791 CMapEnvelopeEvaluator &EnvelopeEvaluator = pEditor->Map()->m_EnvelopeEvaluator;
2792
2793 static constexpr float MIN_ANIM_SPEED = 0.001f;
2794 static constexpr float MAX_ANIM_SPEED = 1000000.0f;
2795
2796 CUIRect Row, Label, ButtonDecrease, EditBox, ButtonIncrease, ButtonReset;
2797 View.HSplitTop(Cut: 13.0f, pTop: &Row, pBottom: &View);
2798 Row.VSplitMid(pLeft: &Label, pRight: &Row);
2799 Row.HMargin(Cut: 1.0f, pOtherRect: &Row);
2800 Row.VSplitLeft(Cut: 10.0f, pLeft: &ButtonDecrease, pRight: &Row);
2801 Row.VSplitRight(Cut: 10.0f, pLeft: &EditBox, pRight: &ButtonIncrease);
2802 View.HSplitBottom(Cut: 12.0f, pTop: &View, pBottom: &ButtonReset);
2803 pEditor->Ui()->DoLabel(pRect: &Label, pText: "Speed", Size: 10.0f, Align: TEXTALIGN_ML);
2804
2805 const float OldAnimateSpeed = EnvelopeEvaluator.m_AnimateSpeed;
2806
2807 static char s_DecreaseButton;
2808 if(pEditor->DoButton_FontIcon(pId: &s_DecreaseButton, pText: FontIcon::MINUS, Checked: 0, pRect: &ButtonDecrease, Flags: BUTTONFLAG_LEFT, pToolTip: "Decrease animation speed.", Corners: IGraphics::CORNER_L, FontSize: 7.0f))
2809 {
2810 EnvelopeEvaluator.m_AnimateSpeed -= EnvelopeEvaluator.m_AnimateSpeed <= 1.0f ? 0.1f : 0.5f;
2811 EnvelopeEvaluator.m_AnimateSpeed = std::max(a: EnvelopeEvaluator.m_AnimateSpeed, b: MIN_ANIM_SPEED);
2812 EnvelopeEvaluator.m_AnimateUpdatePopup = true;
2813 }
2814
2815 static char s_IncreaseButton;
2816 if(pEditor->DoButton_FontIcon(pId: &s_IncreaseButton, pText: FontIcon::PLUS, Checked: 0, pRect: &ButtonIncrease, Flags: BUTTONFLAG_LEFT, pToolTip: "Increase animation speed.", Corners: IGraphics::CORNER_R, FontSize: 7.0f))
2817 {
2818 if(EnvelopeEvaluator.m_AnimateSpeed < 0.1f)
2819 EnvelopeEvaluator.m_AnimateSpeed = 0.1f;
2820 else
2821 EnvelopeEvaluator.m_AnimateSpeed += EnvelopeEvaluator.m_AnimateSpeed < 1.0f ? 0.1f : 0.5f;
2822 EnvelopeEvaluator.m_AnimateSpeed = std::min(a: EnvelopeEvaluator.m_AnimateSpeed, b: MAX_ANIM_SPEED);
2823 EnvelopeEvaluator.m_AnimateUpdatePopup = true;
2824 }
2825
2826 static char s_DefaultButton;
2827 if(pEditor->DoButton_Ex(pId: &s_DefaultButton, pText: "Default", Checked: 0, pRect: &ButtonReset, Flags: BUTTONFLAG_LEFT, pToolTip: "Reset to normal animation speed.", Corners: IGraphics::CORNER_ALL))
2828 {
2829 EnvelopeEvaluator.m_AnimateSpeed = 1.0f;
2830 EnvelopeEvaluator.m_AnimateUpdatePopup = true;
2831 }
2832
2833 static CLineInputNumber s_SpeedInput;
2834 if(EnvelopeEvaluator.m_AnimateUpdatePopup)
2835 {
2836 s_SpeedInput.SetFloat(EnvelopeEvaluator.m_AnimateSpeed);
2837 EnvelopeEvaluator.m_AnimateUpdatePopup = false;
2838 }
2839
2840 if(pEditor->DoEditBox(pLineInput: &s_SpeedInput, pRect: &EditBox, FontSize: 10.0f, Corners: IGraphics::CORNER_NONE, pToolTip: "The animation speed."))
2841 {
2842 EnvelopeEvaluator.m_AnimateSpeed = std::clamp(val: s_SpeedInput.GetFloat(), lo: MIN_ANIM_SPEED, hi: MAX_ANIM_SPEED);
2843 }
2844
2845 // adjust start time to avoid jumps in animation
2846 float AnimateSpeedRatio = OldAnimateSpeed / EnvelopeEvaluator.m_AnimateSpeed;
2847 float Time = pEditor->Client()->GlobalTime();
2848 EnvelopeEvaluator.m_AnimateStart = Time + (EnvelopeEvaluator.m_AnimateStart - Time) * AnimateSpeedRatio;
2849 if(!EnvelopeEvaluator.m_Animate)
2850 {
2851 EnvelopeEvaluator.m_AnimateTime *= AnimateSpeedRatio;
2852 }
2853
2854 return CUi::POPUP_KEEP_OPEN;
2855}
2856