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