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