| | | @@ -0,0 +1,4504 @@ |
| 1 | + | ////////////////////////////////////////////////////////////////////// |
| 2 | + | // This file is part of Remere's Map Editor |
| 3 | + | ////////////////////////////////////////////////////////////////////// |
| 4 | + | // Remere's Map Editor is free software: you can redistribute it and/or modify |
| 5 | + | // it under the terms of the GNU General Public License as published by |
| 6 | + | // the Free Software Foundation, either version 3 of the License, or |
| 7 | + | // (at your option) any later version. |
| 8 | + | // |
| 9 | + | // Remere's Map Editor is distributed in the hope that it will be useful, |
| 10 | + | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + | // GNU General Public License for more details. |
| 13 | + | // |
| 14 | + | // You should have received a copy of the GNU General Public License |
| 15 | + | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + | ////////////////////////////////////////////////////////////////////// |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | #include "main.h" |
| 23 | + | |
| 24 | + | #include <sstream> |
| 25 | + | #include <time.h> |
| 26 | + | #include <wx/wfstream.h> |
| 27 | + | #include <wx/xml/xml.h> |
| 28 | + | #include <algorithm> |
| 29 | + | #include <queue> |
| 30 | + | #include <set> |
| 31 | + | |
| 32 | + | #include "gui.h" |
| 33 | + | #include "editor.h" |
| 34 | + | #include "brush.h" |
| 35 | + | #include "sprites.h" |
| 36 | + | #include "map.h" |
| 37 | + | #include "tile.h" |
| 38 | + | #include "old_properties_window.h" |
| 39 | + | #include "properties_window.h" |
| 40 | + | #include "tileset_window.h" |
| 41 | + | #include "palette_window.h" |
| 42 | + | #include "map_display.h" |
| 43 | + | #include "map_drawer.h" |
| 44 | + | #include "application.h" |
| 45 | + | #include "live_server.h" |
| 46 | + | #include "browse_tile_window.h" |
| 47 | + | |
| 48 | + | #include "minimap_window.h" |
| 49 | + | |
| 50 | + | #include "doodad_brush.h" |
| 51 | + | #include "house_exit_brush.h" |
| 52 | + | #include "house_brush.h" |
| 53 | + | #include "wall_brush.h" |
| 54 | + | #include "spawn_brush.h" |
| 55 | + | #include "creature_brush.h" |
| 56 | + | #include "ground_brush.h" |
| 57 | + | #include "waypoint_brush.h" |
| 58 | + | #include "raw_brush.h" |
| 59 | + | #include "carpet_brush.h" |
| 60 | + | #include "table_brush.h" |
| 61 | + | #include "materials.h" |
| 62 | + | #include "selection.h" |
| 63 | + | #include "find_item_window.h" |
| 64 | + | |
| 65 | + | BEGIN_EVENT_TABLE(MapCanvas, wxGLCanvas) |
| 66 | + | EVT_KEY_DOWN(MapCanvas::OnKeyDown) |
| 67 | + | EVT_KEY_DOWN(MapCanvas::OnKeyUp) |
| 68 | + | |
| 69 | + | // Mouse events |
| 70 | + | EVT_MOTION(MapCanvas::OnMouseMove) |
| 71 | + | EVT_LEFT_UP(MapCanvas::OnMouseLeftRelease) |
| 72 | + | EVT_LEFT_DOWN(MapCanvas::OnMouseLeftClick) |
| 73 | + | EVT_LEFT_DCLICK(MapCanvas::OnMouseLeftDoubleClick) |
| 74 | + | EVT_MIDDLE_DOWN(MapCanvas::OnMouseCenterClick) |
| 75 | + | EVT_MIDDLE_UP(MapCanvas::OnMouseCenterRelease) |
| 76 | + | EVT_RIGHT_DOWN(MapCanvas::OnMouseRightClick) |
| 77 | + | EVT_RIGHT_UP(MapCanvas::OnMouseRightRelease) |
| 78 | + | EVT_MOUSEWHEEL(MapCanvas::OnWheel) |
| 79 | + | EVT_ENTER_WINDOW(MapCanvas::OnGainMouse) |
| 80 | + | EVT_LEAVE_WINDOW(MapCanvas::OnLoseMouse) |
| 81 | + | |
| 82 | + | // Drawing events |
| 83 | + | EVT_PAINT(MapCanvas::OnPaint) |
| 84 | + | EVT_ERASE_BACKGROUND(MapCanvas::OnEraseBackground) |
| 85 | + | |
| 86 | + | // Menu events |
| 87 | + | EVT_MENU(MAP_POPUP_MENU_CUT, MapCanvas::OnCut) |
| 88 | + | EVT_MENU(MAP_POPUP_MENU_COPY, MapCanvas::OnCopy) |
| 89 | + | EVT_MENU(MAP_POPUP_MENU_COPY_POSITION, MapCanvas::OnCopyPosition) |
| 90 | + | EVT_MENU(MAP_POPUP_MENU_PASTE, MapCanvas::OnPaste) |
| 91 | + | EVT_MENU(MAP_POPUP_MENU_DELETE, MapCanvas::OnDelete) |
| 92 | + | EVT_MENU(MAP_POPUP_MENU_FILL, MapCanvas::OnFill) |
| 93 | + | EVT_MENU(MAP_POPUP_MENU_GENERATE_ISLAND, MapCanvas::OnGenerateIsland) |
| 94 | + | EVT_MENU(MAP_POPUP_MENU_CREATE_HOUSE, MapCanvas::OnCreateHouse) |
| 95 | + | EVT_MENU(MAP_POPUP_MENU_FIND_SIMILAR_ITEMS, MapCanvas::OnFindSimilarItems) |
| 96 | + | //---- |
| 97 | + | EVT_MENU(MAP_POPUP_MENU_COPY_SERVER_ID, MapCanvas::OnCopyServerId) |
| 98 | + | EVT_MENU(MAP_POPUP_MENU_COPY_CLIENT_ID, MapCanvas::OnCopyClientId) |
| 99 | + | EVT_MENU(MAP_POPUP_MENU_COPY_NAME, MapCanvas::OnCopyName) |
| 100 | + | // ---- |
| 101 | + | EVT_MENU(MAP_POPUP_MENU_ROTATE, MapCanvas::OnRotateItem) |
| 102 | + | EVT_MENU(MAP_POPUP_MENU_GOTO, MapCanvas::OnGotoDestination) |
| 103 | + | EVT_MENU(MAP_POPUP_MENU_SWITCH_DOOR, MapCanvas::OnSwitchDoor) |
| 104 | + | // ---- |
| 105 | + | EVT_MENU(MAP_POPUP_MENU_SELECT_RAW_BRUSH, MapCanvas::OnSelectRAWBrush) |
| 106 | + | EVT_MENU(MAP_POPUP_MENU_SELECT_GROUND_BRUSH, MapCanvas::OnSelectGroundBrush) |
| 107 | + | EVT_MENU(MAP_POPUP_MENU_SELECT_DOODAD_BRUSH, MapCanvas::OnSelectDoodadBrush) |
| 108 | + | EVT_MENU(MAP_POPUP_MENU_SELECT_COLLECTION_BRUSH, MapCanvas::OnSelectCollectionBrush) |
| 109 | + | EVT_MENU(MAP_POPUP_MENU_SELECT_DOOR_BRUSH, MapCanvas::OnSelectDoorBrush) |
| 110 | + | EVT_MENU(MAP_POPUP_MENU_SELECT_WALL_BRUSH, MapCanvas::OnSelectWallBrush) |
| 111 | + | EVT_MENU(MAP_POPUP_MENU_SELECT_CARPET_BRUSH, MapCanvas::OnSelectCarpetBrush) |
| 112 | + | EVT_MENU(MAP_POPUP_MENU_SELECT_TABLE_BRUSH, MapCanvas::OnSelectTableBrush) |
| 113 | + | EVT_MENU(MAP_POPUP_MENU_SELECT_CREATURE_BRUSH, MapCanvas::OnSelectCreatureBrush) |
| 114 | + | EVT_MENU(MAP_POPUP_MENU_SELECT_SPAWN_BRUSH, MapCanvas::OnSelectSpawnBrush) |
| 115 | + | EVT_MENU(MAP_POPUP_MENU_SELECT_HOUSE_BRUSH, MapCanvas::OnSelectHouseBrush) |
| 116 | + | EVT_MENU(MAP_POPUP_MENU_MOVE_TO_TILESET, MapCanvas::OnSelectMoveTo) |
| 117 | + | // ---- |
| 118 | + | EVT_MENU(MAP_POPUP_MENU_PROPERTIES, MapCanvas::OnProperties) |
| 119 | + | // ---- |
| 120 | + | EVT_MENU(MAP_POPUP_MENU_BROWSE_TILE, MapCanvas::OnBrowseTile) |
| 121 | + | // Add to the event table after other MAP_POPUP_MENU items |
| 122 | + | EVT_MENU(MAP_POPUP_MENU_SELECTION_TO_DOODAD, MapCanvas::OnSelectionToDoodad) |
| 123 | + | |
| 124 | + | END_EVENT_TABLE() |
| 125 | + | |
| 126 | + | bool MapCanvas::processed[] = { 0 }; |
| 127 | + | |
| 128 | + | MapCanvas::MapCanvas(MapWindow* parent, Editor& editor, int* attriblist) : |
| 129 | + | wxGLCanvas(parent, wxID_ANY, nullptr, wxDefaultPosition, wxDefaultSize, wxWANTS_CHARS), |
| 130 | + | editor(editor), |
| 131 | + | floor(GROUND_LAYER), |
| 132 | + | zoom(1.0), |
| 133 | + | cursor_x(-1), |
| 134 | + | cursor_y(-1), |
| 135 | + | dragging(false), |
| 136 | + | boundbox_selection(false), |
| 137 | + | screendragging(false), |
| 138 | + | drawing(false), |
| 139 | + | dragging_draw(false), |
| 140 | + | replace_dragging(false), |
| 141 | + | |
| 142 | + | screenshot_buffer(nullptr), |
| 143 | + | |
| 144 | + | drag_start_x(-1), |
| 145 | + | drag_start_y(-1), |
| 146 | + | drag_start_z(-1), |
| 147 | + | |
| 148 | + | last_cursor_map_x(-1), |
| 149 | + | last_cursor_map_y(-1), |
| 150 | + | last_cursor_map_z(-1), |
| 151 | + | |
| 152 | + | last_click_map_x(-1), |
| 153 | + | last_click_map_y(-1), |
| 154 | + | last_click_map_z(-1), |
| 155 | + | last_click_abs_x(-1), |
| 156 | + | last_click_abs_y(-1), |
| 157 | + | last_click_x(-1), |
| 158 | + | last_click_y(-1), |
| 159 | + | |
| 160 | + | last_mmb_click_x(-1), |
| 161 | + | last_mmb_click_y(-1) { |
| 162 | + | popup_menu = newd MapPopupMenu(editor); |
| 163 | + | animation_timer = newd AnimationTimer(this); |
| 164 | + | drawer = new MapDrawer(this); |
| 165 | + | keyCode = WXK_NONE; |
| 166 | + | } |
| 167 | + | |
| 168 | + | MapCanvas::~MapCanvas() { |
| 169 | + | delete popup_menu; |
| 170 | + | delete animation_timer; |
| 171 | + | delete drawer; |
| 172 | + | free(screenshot_buffer); |
| 173 | + | } |
| 174 | + | |
| 175 | + | void MapCanvas::Refresh() { |
| 176 | + | if (refresh_watch.Time() > g_settings.getInteger(Config::HARD_REFRESH_RATE)) { |
| 177 | + | refresh_watch.Start(); |
| 178 | + | wxGLCanvas::Update(); |
| 179 | + | } |
| 180 | + | wxGLCanvas::Refresh(); |
| 181 | + | } |
| 182 | + | |
| 183 | + | void MapCanvas::SetZoom(double value) { |
| 184 | + | if (value < 0.125) { |
| 185 | + | value = 0.125; |
| 186 | + | } |
| 187 | + | |
| 188 | + | if (value > 25.00) { |
| 189 | + | value = 25.0; |
| 190 | + | } |
| 191 | + | |
| 192 | + | if (zoom != value) { |
| 193 | + | int center_x, center_y; |
| 194 | + | GetScreenCenter(¢er_x, ¢er_y); |
| 195 | + | |
| 196 | + | zoom = value; |
| 197 | + | static_cast<MapWindow*>(GetParent())->SetScreenCenterPosition(Position(center_x, center_y, floor)); |
| 198 | + | |
| 199 | + | UpdatePositionStatus(); |
| 200 | + | UpdateZoomStatus(); |
| 201 | + | Refresh(); |
| 202 | + | } |
| 203 | + | } |
| 204 | + | |
| 205 | + | void MapCanvas::GetViewBox(int* view_scroll_x, int* view_scroll_y, int* screensize_x, int* screensize_y) const { |
| 206 | + | static_cast<MapWindow*>(GetParent())->GetViewSize(screensize_x, screensize_y); |
| 207 | + | static_cast<MapWindow*>(GetParent())->GetViewStart(view_scroll_x, view_scroll_y); |
| 208 | + | } |
| 209 | + | |
| 210 | + | void MapCanvas::OnPaint(wxPaintEvent& event) { |
| 211 | + | SetCurrent(*g_gui.GetGLContext(this)); |
| 212 | + | |
| 213 | + | if (g_gui.IsRenderingEnabled()) { |
| 214 | + | DrawingOptions& options = drawer->getOptions(); |
| 215 | + | if (screenshot_buffer) { |
| 216 | + | options.SetIngame(); |
| 217 | + | } else { |
| 218 | + | options.transparent_floors = g_settings.getBoolean(Config::TRANSPARENT_FLOORS); |
| 219 | + | options.transparent_items = g_settings.getBoolean(Config::TRANSPARENT_ITEMS); |
| 220 | + | options.show_ingame_box = g_settings.getBoolean(Config::SHOW_INGAME_BOX); |
| 221 | + | options.show_lights = g_settings.getBoolean(Config::SHOW_LIGHTS); |
| 222 | + | options.show_light_str = g_settings.getBoolean(Config::SHOW_LIGHT_STR); |
| 223 | + | options.show_tech_items = g_settings.getBoolean(Config::SHOW_TECHNICAL_ITEMS); |
| 224 | + | options.show_waypoints = g_settings.getBoolean(Config::SHOW_WAYPOINTS); |
| 225 | + | options.show_grid = g_settings.getInteger(Config::SHOW_GRID); |
| 226 | + | options.ingame = !g_settings.getBoolean(Config::SHOW_EXTRA); |
| 227 | + | options.show_all_floors = g_settings.getBoolean(Config::SHOW_ALL_FLOORS); |
| 228 | + | options.show_creatures = g_settings.getBoolean(Config::SHOW_CREATURES); |
| 229 | + | options.show_spawns = g_settings.getBoolean(Config::SHOW_SPAWNS); |
| 230 | + | options.show_houses = g_settings.getBoolean(Config::SHOW_HOUSES); |
| 231 | + | options.show_shade = g_settings.getBoolean(Config::SHOW_SHADE); |
| 232 | + | options.show_special_tiles = g_settings.getBoolean(Config::SHOW_SPECIAL_TILES); |
| 233 | + | options.show_zone_areas = g_settings.getBoolean(Config::SHOW_ZONE_AREAS); |
| 234 | + | options.show_items = g_settings.getBoolean(Config::SHOW_ITEMS); |
| 235 | + | options.highlight_items = g_settings.getBoolean(Config::HIGHLIGHT_ITEMS); |
| 236 | + | options.highlight_locked_doors = g_settings.getBoolean(Config::HIGHLIGHT_LOCKED_DOORS); |
| 237 | + | options.show_blocking = g_settings.getBoolean(Config::SHOW_BLOCKING); |
| 238 | + | options.show_tooltips = g_settings.getBoolean(Config::SHOW_TOOLTIPS); |
| 239 | + | options.show_as_minimap = g_settings.getBoolean(Config::SHOW_AS_MINIMAP); |
| 240 | + | options.show_only_colors = g_settings.getBoolean(Config::SHOW_ONLY_TILEFLAGS); |
| 241 | + | options.show_only_modified = g_settings.getBoolean(Config::SHOW_ONLY_MODIFIED_TILES); |
| 242 | + | options.show_preview = g_settings.getBoolean(Config::SHOW_PREVIEW); |
| 243 | + | options.show_hooks = g_settings.getBoolean(Config::SHOW_WALL_HOOKS); |
| 244 | + | options.hide_items_when_zoomed = g_settings.getBoolean(Config::HIDE_ITEMS_WHEN_ZOOMED); |
| 245 | + | options.show_towns = g_settings.getBoolean(Config::SHOW_TOWNS); |
| 246 | + | options.always_show_zones = g_settings.getBoolean(Config::ALWAYS_SHOW_ZONES); |
| 247 | + | options.extended_house_shader = g_settings.getBoolean(Config::EXT_HOUSE_SHADER); |
| 248 | + | |
| 249 | + | options.experimental_fog = g_settings.getBoolean(Config::EXPERIMENTAL_FOG); |
| 250 | + | } |
| 251 | + | |
| 252 | + | options.dragging = boundbox_selection; |
| 253 | + | |
| 254 | + | if (options.show_preview) { |
| 255 | + | animation_timer->Start(); |
| 256 | + | } else { |
| 257 | + | animation_timer->Stop(); |
| 258 | + | } |
| 259 | + | |
| 260 | + | drawer->SetupVars(); |
| 261 | + | drawer->SetupGL(); |
| 262 | + | drawer->Draw(); |
| 263 | + | |
| 264 | + | if (screenshot_buffer) { |
| 265 | + | drawer->TakeScreenshot(screenshot_buffer); |
| 266 | + | } |
| 267 | + | |
| 268 | + | drawer->Release(); |
| 269 | + | } |
| 270 | + | |
| 271 | + | // Clean unused textures |
| 272 | + | g_gui.gfx.garbageCollection(); |
| 273 | + | |
| 274 | + | // Swap buffer |
| 275 | + | SwapBuffers(); |
| 276 | + | |
| 277 | + | // Send newd node requests |
| 278 | + | editor.SendNodeRequests(); |
| 279 | + | } |
| 280 | + | |
| 281 | + | void MapCanvas::TakeScreenshot(wxFileName path, wxString format) { |
| 282 | + | int screensize_x, screensize_y; |
| 283 | + | GetViewBox(&view_scroll_x, &view_scroll_y, &screensize_x, &screensize_y); |
| 284 | + | |
| 285 | + | delete[] screenshot_buffer; |
| 286 | + | screenshot_buffer = newd uint8_t[3 * screensize_x * screensize_y]; |
| 287 | + | |
| 288 | + | // Draw the window |
| 289 | + | Refresh(); |
| 290 | + | wxGLCanvas::Update(); // Forces immediate redraws the window. |
| 291 | + | |
| 292 | + | // screenshot_buffer should now contain the screenbuffer |
| 293 | + | if (screenshot_buffer == nullptr) { |
| 294 | + | g_gui.PopupDialog("Capture failed", "Image capture failed. Old Video Driver?", wxOK); |
| 295 | + | } else { |
| 296 | + | // We got the shit |
| 297 | + | int screensize_x, screensize_y; |
| 298 | + | static_cast<MapWindow*>(GetParent())->GetViewSize(&screensize_x, &screensize_y); |
| 299 | + | wxImage screenshot(screensize_x, screensize_y, screenshot_buffer); |
| 300 | + | |
| 301 | + | time_t t = time(nullptr); |
| 302 | + | struct tm* current_time = localtime(&t); |
| 303 | + | ASSERT(current_time); |
| 304 | + | |
| 305 | + | wxString date; |
| 306 | + | date << "screenshot_" << (1900 + current_time->tm_year); |
| 307 | + | if (current_time->tm_mon < 9) { |
| 308 | + | date << "-" |
| 309 | + | << "0" << current_time->tm_mon + 1; |
| 310 | + | } else { |
| 311 | + | date << "-" << current_time->tm_mon + 1; |
| 312 | + | } |
| 313 | + | date << "-" << current_time->tm_mday; |
| 314 | + | date << "-" << current_time->tm_hour; |
| 315 | + | date << "-" << current_time->tm_min; |
| 316 | + | date << "-" << current_time->tm_sec; |
| 317 | + | |
| 318 | + | int type = 0; |
| 319 | + | path.SetName(date); |
| 320 | + | if (format == "bmp") { |
| 321 | + | path.SetExt(format); |
| 322 | + | type = wxBITMAP_TYPE_BMP; |
| 323 | + | } else if (format == "png") { |
| 324 | + | path.SetExt(format); |
| 325 | + | type = wxBITMAP_TYPE_PNG; |
| 326 | + | } else if (format == "jpg" || format == "jpeg") { |
| 327 | + | path.SetExt(format); |
| 328 | + | type = wxBITMAP_TYPE_JPEG; |
| 329 | + | } else if (format == "tga") { |
| 330 | + | path.SetExt(format); |
| 331 | + | type = wxBITMAP_TYPE_TGA; |
| 332 | + | } else { |
| 333 | + | g_gui.SetStatusText("Unknown screenshot format \'" + format + "\', switching to default (png)"); |
| 334 | + | path.SetExt("png"); |
| 335 | + | ; |
| 336 | + | type = wxBITMAP_TYPE_PNG; |
| 337 | + | } |
| 338 | + | |
| 339 | + | path.Mkdir(0755, wxPATH_MKDIR_FULL); |
| 340 | + | wxFileOutputStream of(path.GetFullPath()); |
| 341 | + | if (of.IsOk()) { |
| 342 | + | if (screenshot.SaveFile(of, static_cast<wxBitmapType>(type))) { |
| 343 | + | g_gui.SetStatusText("Took screenshot and saved as " + path.GetFullName()); |
| 344 | + | } else { |
| 345 | + | g_gui.PopupDialog("File error", "Couldn't save image file correctly.", wxOK); |
| 346 | + | } |
| 347 | + | } else { |
| 348 | + | g_gui.PopupDialog("File error", "Couldn't open file " + path.GetFullPath() + " for writing.", wxOK); |
| 349 | + | } |
| 350 | + | } |
| 351 | + | |
| 352 | + | Refresh(); |
| 353 | + | |
| 354 | + | screenshot_buffer = nullptr; |
| 355 | + | } |
| 356 | + | |
| 357 | + | void MapCanvas::ScreenToMap(int screen_x, int screen_y, int* map_x, int* map_y) { |
| 358 | + | int start_x, start_y; |
| 359 | + | static_cast<MapWindow*>(GetParent())->GetViewStart(&start_x, &start_y); |
| 360 | + | |
| 361 | + | screen_x *= GetContentScaleFactor(); |
| 362 | + | screen_y *= GetContentScaleFactor(); |
| 363 | + | |
| 364 | + | if (screen_x < 0) { |
| 365 | + | *map_x = (start_x + screen_x) / TileSize; |
| 366 | + | } else { |
| 367 | + | *map_x = int(start_x + (screen_x * zoom)) / TileSize; |
| 368 | + | } |
| 369 | + | |
| 370 | + | if (screen_y < 0) { |
| 371 | + | *map_y = (start_y + screen_y) / TileSize; |
| 372 | + | } else { |
| 373 | + | *map_y = int(start_y + (screen_y * zoom)) / TileSize; |
| 374 | + | } |
| 375 | + | |
| 376 | + | if (floor <= GROUND_LAYER) { |
| 377 | + | *map_x += GROUND_LAYER - floor; |
| 378 | + | *map_y += GROUND_LAYER - floor; |
| 379 | + | } /* else { |
| 380 | + | *map_x += MAP_MAX_LAYER - floor; |
| 381 | + | *map_y += MAP_MAX_LAYER - floor; |
| 382 | + | }*/ |
| 383 | + | } |
| 384 | + | |
| 385 | + | void MapCanvas::GetScreenCenter(int* map_x, int* map_y) { |
| 386 | + | int width, height; |
| 387 | + | static_cast<MapWindow*>(GetParent())->GetViewSize(&width, &height); |
| 388 | + | return ScreenToMap(width / 2, height / 2, map_x, map_y); |
| 389 | + | } |
| 390 | + | |
| 391 | + | Position MapCanvas::GetCursorPosition() const { |
| 392 | + | return Position(last_cursor_map_x, last_cursor_map_y, floor); |
| 393 | + | } |
| 394 | + | |
| 395 | + | void MapCanvas::UpdatePositionStatus(int x, int y) { |
| 396 | + | if (x == -1) { |
| 397 | + | x = cursor_x; |
| 398 | + | } |
| 399 | + | if (y == -1) { |
| 400 | + | y = cursor_y; |
| 401 | + | } |
| 402 | + | |
| 403 | + | int map_x, map_y; |
| 404 | + | ScreenToMap(x, y, &map_x, &map_y); |
| 405 | + | |
| 406 | + | wxString ss; |
| 407 | + | ss << "x: " << map_x << " y:" << map_y << " z:" << floor; |
| 408 | + | g_gui.root->SetStatusText(ss, 2); |
| 409 | + | |
| 410 | + | ss = ""; |
| 411 | + | Tile* tile = editor.map.getTile(map_x, map_y, floor); |
| 412 | + | if (tile) { |
| 413 | + | // Count total items on tile |
| 414 | + | int itemCount = 0; |
| 415 | + | if (tile->ground) itemCount++; |
| 416 | + | itemCount += tile->items.size(); |
| 417 | + | |
| 418 | + | if (tile->spawn && g_settings.getInteger(Config::SHOW_SPAWNS)) { |
| 419 | + | ss << "[" << itemCount << "] Spawn radius: " << tile->spawn->getSize(); |
| 420 | + | } else if (tile->creature && g_settings.getInteger(Config::SHOW_CREATURES)) { |
| 421 | + | ss << "[" << itemCount << "] " << (tile->creature->isNpc() ? "NPC" : "Monster"); |
| 422 | + | ss << " \"" << wxstr(tile->creature->getName()) << "\" spawntime: " << tile->creature->getSpawnTime(); |
| 423 | + | } else if (Item* item = tile->getTopItem()) { |
| 424 | + | ss << "[" << itemCount << "] Item \"" << wxstr(item->getName()) << "\""; |
| 425 | + | ss << " id:" << item->getID(); |
| 426 | + | ss << " cid:" << item->getClientID(); |
| 427 | + | if (item->getUniqueID()) { |
| 428 | + | ss << " uid:" << item->getUniqueID(); |
| 429 | + | } |
| 430 | + | if (item->getActionID()) { |
| 431 | + | ss << " aid:" << item->getActionID(); |
| 432 | + | } |
| 433 | + | if (item->hasWeight()) { |
| 434 | + | wxString s; |
| 435 | + | s.Printf("%.2f", item->getWeight()); |
| 436 | + | ss << " weight: " << s; |
| 437 | + | } |
| 438 | + | } else { |
| 439 | + | ss << "[" << itemCount << "] Nothing"; |
| 440 | + | } |
| 441 | + | } else { |
| 442 | + | ss << "[0] Nothing"; |
| 443 | + | } |
| 444 | + | |
| 445 | + | if (editor.IsLive()) { |
| 446 | + | editor.GetLive().updateCursor(Position(map_x, map_y, floor)); |
| 447 | + | } |
| 448 | + | |
| 449 | + | g_gui.root->SetStatusText(ss, 1); |
| 450 | + | } |
| 451 | + | |
| 452 | + | void MapCanvas::UpdateZoomStatus() { |
| 453 | + | int percentage = (int)((1.0 / zoom) * 100); |
| 454 | + | wxString ss; |
| 455 | + | ss << "zoom: " << percentage << "%"; |
| 456 | + | g_gui.root->SetStatusText(ss, 3); |
| 457 | + | } |
| 458 | + | |
| 459 | + | void MapCanvas::OnMouseMove(wxMouseEvent& event) { |
| 460 | + | if (screendragging) { |
| 461 | + | static_cast<MapWindow*>(GetParent())->ScrollRelative(int(g_settings.getFloat(Config::SCROLL_SPEED) * zoom * (event.GetX() - cursor_x)), int(g_settings.getFloat(Config::SCROLL_SPEED) * zoom * (event.GetY() - cursor_y))); |
| 462 | + | Refresh(); |
| 463 | + | } |
| 464 | + | |
| 465 | + | cursor_x = event.GetX(); |
| 466 | + | cursor_y = event.GetY(); |
| 467 | + | |
| 468 | + | int mouse_map_x, mouse_map_y; |
| 469 | + | MouseToMap(&mouse_map_x, &mouse_map_y); |
| 470 | + | |
| 471 | + | bool map_update = false; |
| 472 | + | if (last_cursor_map_x != mouse_map_x || last_cursor_map_y != mouse_map_y || last_cursor_map_z != floor) { |
| 473 | + | map_update = true; |
| 474 | + | } |
| 475 | + | last_cursor_map_x = mouse_map_x; |
| 476 | + | last_cursor_map_y = mouse_map_y; |
| 477 | + | last_cursor_map_z = floor; |
| 478 | + | |
| 479 | + | if (map_update) { |
| 480 | + | UpdatePositionStatus(cursor_x, cursor_y); |
| 481 | + | UpdateZoomStatus(); |
| 482 | + | } |
| 483 | + | |
| 484 | + | if (g_gui.IsSelectionMode()) { |
| 485 | + | if (map_update && isPasting()) { |
| 486 | + | Refresh(); |
| 487 | + | } else if (map_update && dragging) { |
| 488 | + | wxString ss; |
| 489 | + | |
| 490 | + | int move_x = drag_start_x - mouse_map_x; |
| 491 | + | int move_y = drag_start_y - mouse_map_y; |
| 492 | + | int move_z = drag_start_z - floor; |
| 493 | + | ss << "Dragging " << -move_x << "," << -move_y << "," << -move_z; |
| 494 | + | g_gui.SetStatusText(ss); |
| 495 | + | |
| 496 | + | Refresh(); |
| 497 | + | } else if (boundbox_selection) { |
| 498 | + | if (map_update) { |
| 499 | + | wxString ss; |
| 500 | + | |
| 501 | + | int move_x = std::abs(last_click_map_x - mouse_map_x); |
| 502 | + | int move_y = std::abs(last_click_map_y - mouse_map_y); |
| 503 | + | ss << "Selection " << move_x + 1 << ":" << move_y + 1; |
| 504 | + | g_gui.SetStatusText(ss); |
| 505 | + | } |
| 506 | + | |
| 507 | + | Refresh(); |
| 508 | + | } |
| 509 | + | } else { // Drawing mode |
| 510 | + | Brush* brush = g_gui.GetCurrentBrush(); |
| 511 | + | if (map_update && drawing && brush) { |
| 512 | + | if (brush->isDoodad()) { |
| 513 | + | if (event.ControlDown()) { |
| 514 | + | PositionVector tilestodraw; |
| 515 | + | getTilesToDraw(mouse_map_x, mouse_map_y, floor, &tilestodraw, nullptr); |
| 516 | + | editor.undraw(tilestodraw, event.ShiftDown() || event.AltDown()); |
| 517 | + | } else { |
| 518 | + | editor.draw(Position(mouse_map_x, mouse_map_y, floor), event.ShiftDown() || event.AltDown()); |
| 519 | + | } |
| 520 | + | } else if (brush->isDoor()) { |
| 521 | + | if (!brush->canDraw(&editor.map, Position(mouse_map_x, mouse_map_y, floor))) { |
| 522 | + | // We don't have to waste an action in this case... |
| 523 | + | } else { |
| 524 | + | PositionVector tilestodraw; |
| 525 | + | PositionVector tilestoborder; |
| 526 | + | |
| 527 | + | tilestodraw.push_back(Position(mouse_map_x, mouse_map_y, floor)); |
| 528 | + | |
| 529 | + | tilestoborder.push_back(Position(mouse_map_x, mouse_map_y - 1, floor)); |
| 530 | + | tilestoborder.push_back(Position(mouse_map_x - 1, mouse_map_y, floor)); |
| 531 | + | tilestoborder.push_back(Position(mouse_map_x, mouse_map_y + 1, floor)); |
| 532 | + | tilestoborder.push_back(Position(mouse_map_x + 1, mouse_map_y, floor)); |
| 533 | + | |
| 534 | + | if (event.ControlDown()) { |
| 535 | + | editor.undraw(tilestodraw, tilestoborder, event.AltDown()); |
| 536 | + | } else { |
| 537 | + | editor.draw(tilestodraw, tilestoborder, event.AltDown()); |
| 538 | + | } |
| 539 | + | } |
| 540 | + | } else if (brush->needBorders()) { |
| 541 | + | PositionVector tilestodraw, tilestoborder; |
| 542 | + | |
| 543 | + | getTilesToDraw(mouse_map_x, mouse_map_y, floor, &tilestodraw, &tilestoborder); |
| 544 | + | |
| 545 | + | if (event.ControlDown()) { |
| 546 | + | editor.undraw(tilestodraw, tilestoborder, event.AltDown()); |
| 547 | + | } else { |
| 548 | + | editor.draw(tilestodraw, tilestoborder, event.AltDown()); |
| 549 | + | } |
| 550 | + | } else if (brush->oneSizeFitsAll()) { |
| 551 | + | drawing = true; |
| 552 | + | PositionVector tilestodraw; |
| 553 | + | tilestodraw.push_back(Position(mouse_map_x, mouse_map_y, floor)); |
| 554 | + | |
| 555 | + | if (event.ControlDown()) { |
| 556 | + | editor.undraw(tilestodraw, event.AltDown()); |
| 557 | + | } else { |
| 558 | + | editor.draw(tilestodraw, event.AltDown()); |
| 559 | + | } |
| 560 | + | } else { // No borders |
| 561 | + | PositionVector tilestodraw; |
| 562 | + | |
| 563 | + | for (int y = -g_gui.GetBrushSize(); y <= g_gui.GetBrushSize(); y++) { |
| 564 | + | for (int x = -g_gui.GetBrushSize(); x <= g_gui.GetBrushSize(); x++) { |
| 565 | + | if (g_gui.GetBrushShape() == BRUSHSHAPE_SQUARE) { |
| 566 | + | tilestodraw.push_back(Position(mouse_map_x + x, mouse_map_y + y, floor)); |
| 567 | + | } else if (g_gui.GetBrushShape() == BRUSHSHAPE_CIRCLE) { |
| 568 | + | double distance = sqrt(double(x * x) + double(y * y)); |
| 569 | + | if (distance < g_gui.GetBrushSize() + 0.005) { |
| 570 | + | tilestodraw.push_back(Position(mouse_map_x + x, mouse_map_y + y, floor)); |
| 571 | + | } |
| 572 | + | } |
| 573 | + | } |
| 574 | + | } |
| 575 | + | if (event.ControlDown()) { |
| 576 | + | editor.undraw(tilestodraw, event.AltDown()); |
| 577 | + | } else { |
| 578 | + | editor.draw(tilestodraw, event.AltDown()); |
| 579 | + | } |
| 580 | + | } |
| 581 | + | |
| 582 | + | // Create newd doodad layout (does nothing if a non-doodad brush is selected) |
| 583 | + | g_gui.FillDoodadPreviewBuffer(); |
| 584 | + | |
| 585 | + | g_gui.RefreshView(); |
| 586 | + | } else if (dragging_draw) { |
| 587 | + | g_gui.RefreshView(); |
| 588 | + | } else if (map_update && brush) { |
| 589 | + | Refresh(); |
| 590 | + | } |
| 591 | + | } |
| 592 | + | } |
| 593 | + | |
| 594 | + | void MapCanvas::OnMouseLeftRelease(wxMouseEvent& event) { |
| 595 | + | OnMouseActionRelease(event); |
| 596 | + | } |
| 597 | + | |
| 598 | + | void MapCanvas::OnMouseLeftClick(wxMouseEvent& event) { |
| 599 | + | OnMouseActionClick(event); |
| 600 | + | } |
| 601 | + | |
| 602 | + | void MapCanvas::OnMouseLeftDoubleClick(wxMouseEvent& event) { |
| 603 | + | if (g_settings.getInteger(Config::DOUBLECLICK_PROPERTIES)) { |
| 604 | + | int mouse_map_x, mouse_map_y; |
| 605 | + | ScreenToMap(event.GetX(), event.GetY(), &mouse_map_x, &mouse_map_y); |
| 606 | + | Tile* tile = editor.map.getTile(mouse_map_x, mouse_map_y, floor); |
| 607 | + | |
| 608 | + | if (tile && tile->size() > 0) { |
| 609 | + | Tile* new_tile = tile->deepCopy(editor.map); |
| 610 | + | wxDialog* w = nullptr; |
| 611 | + | if (new_tile->spawn && g_settings.getInteger(Config::SHOW_SPAWNS)) { |
| 612 | + | w = newd OldPropertiesWindow(g_gui.root, &editor.map, new_tile, new_tile->spawn); |
| 613 | + | } else if (new_tile->creature && g_settings.getInteger(Config::SHOW_CREATURES)) { |
| 614 | + | w = newd OldPropertiesWindow(g_gui.root, &editor.map, new_tile, new_tile->creature); |
| 615 | + | } else if (Item* item = new_tile->getTopItem()) { |
| 616 | + | if (editor.map.getVersion().otbm >= MAP_OTBM_4) { |
| 617 | + | w = newd PropertiesWindow(g_gui.root, &editor.map, new_tile, item); |
| 618 | + | } else { |
| 619 | + | w = newd OldPropertiesWindow(g_gui.root, &editor.map, new_tile, item); |
| 620 | + | } |
| 621 | + | } else { |
| 622 | + | return; |
| 623 | + | } |
| 624 | + | |
| 625 | + | int ret = w->ShowModal(); |
| 626 | + | if (ret != 0) { |
| 627 | + | Action* action = editor.actionQueue->createAction(ACTION_CHANGE_PROPERTIES); |
| 628 | + | action->addChange(newd Change(new_tile)); |
| 629 | + | editor.addAction(action); |
| 630 | + | } else { |
| 631 | + | // Cancel!a |
| 632 | + | delete new_tile; |
| 633 | + | } |
| 634 | + | w->Destroy(); |
| 635 | + | } |
| 636 | + | } |
| 637 | + | } |
| 638 | + | |
| 639 | + | void MapCanvas::OnMouseCenterClick(wxMouseEvent& event) { |
| 640 | + | if (g_settings.getInteger(Config::SWITCH_MOUSEBUTTONS)) { |
| 641 | + | OnMousePropertiesClick(event); |
| 642 | + | } else { |
| 643 | + | OnMouseCameraClick(event); |
| 644 | + | } |
| 645 | + | } |
| 646 | + | |
| 647 | + | void MapCanvas::OnMouseCenterRelease(wxMouseEvent& event) { |
| 648 | + | if (g_settings.getInteger(Config::SWITCH_MOUSEBUTTONS)) { |
| 649 | + | OnMousePropertiesRelease(event); |
| 650 | + | } else { |
| 651 | + | OnMouseCameraRelease(event); |
| 652 | + | } |
| 653 | + | } |
| 654 | + | |
| 655 | + | void MapCanvas::OnMouseRightClick(wxMouseEvent& event) { |
| 656 | + | if (g_settings.getInteger(Config::SWITCH_MOUSEBUTTONS)) { |
| 657 | + | OnMouseCameraClick(event); |
| 658 | + | } else { |
| 659 | + | OnMousePropertiesClick(event); |
| 660 | + | } |
| 661 | + | } |
| 662 | + | |
| 663 | + | void MapCanvas::OnMouseRightRelease(wxMouseEvent& event) { |
| 664 | + | if (g_settings.getInteger(Config::SWITCH_MOUSEBUTTONS)) { |
| 665 | + | OnMouseCameraRelease(event); |
| 666 | + | } else { |
| 667 | + | OnMousePropertiesRelease(event); |
| 668 | + | } |
| 669 | + | } |
| 670 | + | |
| 671 | + | void MapCanvas::OnMouseActionClick(wxMouseEvent& event) { |
| 672 | + | SetFocus(); |
| 673 | + | |
| 674 | + | int mouse_map_x, mouse_map_y; |
| 675 | + | ScreenToMap(event.GetX(), event.GetY(), &mouse_map_x, &mouse_map_y); |
| 676 | + | |
| 677 | + | if (event.ControlDown() && event.AltDown()) { |
| 678 | + | Tile* tile = editor.map.getTile(mouse_map_x, mouse_map_y, floor); |
| 679 | + | if (tile && tile->size() > 0) { |
| 680 | + | Item* item = tile->getTopItem(); |
| 681 | + | if (item && item->getRAWBrush()) { |
| 682 | + | g_gui.SelectBrush(item->getRAWBrush(), TILESET_RAW); |
| 683 | + | } |
| 684 | + | } |
| 685 | + | } else if (g_gui.IsSelectionMode()) { |
| 686 | + | if (isPasting()) { |
| 687 | + | // Set paste to false (no rendering etc.) |
| 688 | + | EndPasting(); |
| 689 | + | |
| 690 | + | // Paste to the map |
| 691 | + | editor.copybuffer.paste(editor, Position(mouse_map_x, mouse_map_y, floor)); |
| 692 | + | |
| 693 | + | // Start dragging |
| 694 | + | dragging = true; |
| 695 | + | drag_start_x = mouse_map_x; |
| 696 | + | drag_start_y = mouse_map_y; |
| 697 | + | drag_start_z = floor; |
| 698 | + | } else { |
| 699 | + | do { |
| 700 | + | boundbox_selection = false; |
| 701 | + | if (event.ShiftDown()) { |
| 702 | + | boundbox_selection = true; |
| 703 | + | |
| 704 | + | if (!event.ControlDown()) { |
| 705 | + | editor.selection.start(); // Start selection session |
| 706 | + | editor.selection.clear(); // Clear out selection |
| 707 | + | editor.selection.finish(); // End selection session |
| 708 | + | editor.selection.updateSelectionCount(); |
| 709 | + | } |
| 710 | + | } else if (event.ControlDown()) { |
| 711 | + | Tile* tile = editor.map.getTile(mouse_map_x, mouse_map_y, floor); |
| 712 | + | if (tile) { |
| 713 | + | if (tile->spawn && g_settings.getInteger(Config::SHOW_SPAWNS)) { |
| 714 | + | editor.selection.start(); // Start selection session |
| 715 | + | if (tile->spawn->isSelected()) { |
| 716 | + | editor.selection.remove(tile, tile->spawn); |
| 717 | + | } else { |
| 718 | + | editor.selection.add(tile, tile->spawn); |
| 719 | + | } |
| 720 | + | editor.selection.finish(); // Finish selection session |
| 721 | + | editor.selection.updateSelectionCount(); |
| 722 | + | } else if (tile->creature && g_settings.getInteger(Config::SHOW_CREATURES)) { |
| 723 | + | editor.selection.start(); // Start selection session |
| 724 | + | if (tile->creature->isSelected()) { |
| 725 | + | editor.selection.remove(tile, tile->creature); |
| 726 | + | } else { |
| 727 | + | editor.selection.add(tile, tile->creature); |
| 728 | + | } |
| 729 | + | editor.selection.finish(); // Finish selection session |
| 730 | + | editor.selection.updateSelectionCount(); |
| 731 | + | } else { |
| 732 | + | Item* item = tile->getTopItem(); |
| 733 | + | if (item) { |
| 734 | + | editor.selection.start(); // Start selection session |
| 735 | + | if (item->isSelected()) { |
| 736 | + | editor.selection.remove(tile, item); |
| 737 | + | } else { |
| 738 | + | editor.selection.add(tile, item); |
| 739 | + | } |
| 740 | + | editor.selection.finish(); // Finish selection session |
| 741 | + | editor.selection.updateSelectionCount(); |
| 742 | + | } |
| 743 | + | } |
| 744 | + | } |
| 745 | + | } else { |
| 746 | + | Tile* tile = editor.map.getTile(mouse_map_x, mouse_map_y, floor); |
| 747 | + | if (!tile) { |
| 748 | + | editor.selection.start(); // Start selection session |
| 749 | + | editor.selection.clear(); // Clear out selection |
| 750 | + | editor.selection.finish(); // End selection session |
| 751 | + | editor.selection.updateSelectionCount(); |
| 752 | + | } else if (tile->isSelected()) { |
| 753 | + | dragging = true; |
| 754 | + | drag_start_x = mouse_map_x; |
| 755 | + | drag_start_y = mouse_map_y; |
| 756 | + | drag_start_z = floor; |
| 757 | + | } else { |
| 758 | + | editor.selection.start(); // Start a selection session |
| 759 | + | editor.selection.clear(); |
| 760 | + | editor.selection.commit(); |
| 761 | + | if (tile->spawn && g_settings.getInteger(Config::SHOW_SPAWNS)) { |
| 762 | + | editor.selection.add(tile, tile->spawn); |
| 763 | + | dragging = true; |
| 764 | + | drag_start_x = mouse_map_x; |
| 765 | + | drag_start_y = mouse_map_y; |
| 766 | + | drag_start_z = floor; |
| 767 | + | } else if (tile->creature && g_settings.getInteger(Config::SHOW_CREATURES)) { |
| 768 | + | editor.selection.add(tile, tile->creature); |
| 769 | + | dragging = true; |
| 770 | + | drag_start_x = mouse_map_x; |
| 771 | + | drag_start_y = mouse_map_y; |
| 772 | + | drag_start_z = floor; |
| 773 | + | } else { |
| 774 | + | Item* item = tile->getTopItem(); |
| 775 | + | if (item) { |
| 776 | + | editor.selection.add(tile, item); |
| 777 | + | dragging = true; |
| 778 | + | drag_start_x = mouse_map_x; |
| 779 | + | drag_start_y = mouse_map_y; |
| 780 | + | drag_start_z = floor; |
| 781 | + | } |
| 782 | + | } |
| 783 | + | editor.selection.finish(); // Finish the selection session |
| 784 | + | editor.selection.updateSelectionCount(); |
| 785 | + | } |
| 786 | + | } |
| 787 | + | } while (false); |
| 788 | + | } |
| 789 | + | } else if (g_gui.GetCurrentBrush()) { // Drawing mode |
| 790 | + | Brush* brush = g_gui.GetCurrentBrush(); |
| 791 | + | if (event.ShiftDown() && brush->canDrag()) { |
| 792 | + | dragging_draw = true; |
| 793 | + | } else { |
| 794 | + | if (g_gui.GetBrushSize() == 0 && !brush->oneSizeFitsAll()) { |
| 795 | + | drawing = true; |
| 796 | + | } else { |
| 797 | + | drawing = g_gui.GetCurrentBrush()->canSmear(); |
| 798 | + | } |
| 799 | + | if (brush->isWall()) { |
| 800 | + | if (event.AltDown() && g_gui.GetBrushSize() == 0) { |
| 801 | + | // z0mg, just clicked a tile, shift variaton. |
| 802 | + | if (event.ControlDown()) { |
| 803 | + | editor.undraw(Position(mouse_map_x, mouse_map_y, floor), event.AltDown()); |
| 804 | + | } else { |
| 805 | + | editor.draw(Position(mouse_map_x, mouse_map_y, floor), event.AltDown()); |
| 806 | + | } |
| 807 | + | } else { |
| 808 | + | PositionVector tilestodraw; |
| 809 | + | PositionVector tilestoborder; |
| 810 | + | |
| 811 | + | int start_map_x = mouse_map_x - g_gui.GetBrushSize(); |
| 812 | + | int start_map_y = mouse_map_y - g_gui.GetBrushSize(); |
| 813 | + | int end_map_x = mouse_map_x + g_gui.GetBrushSize(); |
| 814 | + | int end_map_y = mouse_map_y + g_gui.GetBrushSize(); |
| 815 | + | |
| 816 | + | for (int y = start_map_y - 1; y <= end_map_y + 1; ++y) { |
| 817 | + | for (int x = start_map_x - 1; x <= end_map_x + 1; ++x) { |
| 818 | + | if ((x <= start_map_x + 1 || x >= end_map_x - 1) || (y <= start_map_y + 1 || y >= end_map_y - 1)) { |
| 819 | + | tilestoborder.push_back(Position(x, y, floor)); |
| 820 | + | } |
| 821 | + | if (((x == start_map_x || x == end_map_x) || (y == start_map_y || y == end_map_y)) && ((x >= start_map_x && x <= end_map_x) && (y >= start_map_y && y <= end_map_y))) { |
| 822 | + | tilestodraw.push_back(Position(x, y, floor)); |
| 823 | + | } |
| 824 | + | } |
| 825 | + | } |
| 826 | + | if (event.ControlDown()) { |
| 827 | + | editor.undraw(tilestodraw, tilestoborder, event.AltDown()); |
| 828 | + | } else { |
| 829 | + | editor.draw(tilestodraw, tilestoborder, event.AltDown()); |
| 830 | + | } |
| 831 | + | } |
| 832 | + | } else if (brush->isDoor()) { |
| 833 | + | PositionVector tilestodraw; |
| 834 | + | PositionVector tilestoborder; |
| 835 | + | |
| 836 | + | tilestodraw.push_back(Position(mouse_map_x, mouse_map_y, floor)); |
| 837 | + | |
| 838 | + | tilestoborder.push_back(Position(mouse_map_x, mouse_map_y - 1, floor)); |
| 839 | + | tilestoborder.push_back(Position(mouse_map_x - 1, mouse_map_y, floor)); |
| 840 | + | tilestoborder.push_back(Position(mouse_map_x, mouse_map_y + 1, floor)); |
| 841 | + | tilestoborder.push_back(Position(mouse_map_x + 1, mouse_map_y, floor)); |
| 842 | + | |
| 843 | + | if (event.ControlDown()) { |
| 844 | + | editor.undraw(tilestodraw, tilestoborder, event.AltDown()); |
| 845 | + | } else { |
| 846 | + | editor.draw(tilestodraw, tilestoborder, event.AltDown()); |
| 847 | + | } |
| 848 | + | } else if (brush->isDoodad() || brush->isSpawn() || brush->isCreature()) { |
| 849 | + | if (event.ControlDown()) { |
| 850 | + | if (brush->isDoodad()) { |
| 851 | + | PositionVector tilestodraw; |
| 852 | + | getTilesToDraw(mouse_map_x, mouse_map_y, floor, &tilestodraw, nullptr); |
| 853 | + | editor.undraw(tilestodraw, event.AltDown() || event.ShiftDown()); |
| 854 | + | } else { |
| 855 | + | editor.undraw(Position(mouse_map_x, mouse_map_y, floor), event.ShiftDown() || event.AltDown()); |
| 856 | + | } |
| 857 | + | } else { |
| 858 | + | bool will_show_spawn = false; |
| 859 | + | if (brush->isSpawn() || brush->isCreature()) { |
| 860 | + | if (!g_settings.getBoolean(Config::SHOW_SPAWNS)) { |
| 861 | + | Tile* tile = editor.map.getTile(mouse_map_x, mouse_map_y, floor); |
| 862 | + | if (!tile || !tile->spawn) { |
| 863 | + | will_show_spawn = true; |
| 864 | + | } |
| 865 | + | } |
| 866 | + | } |
| 867 | + | |
| 868 | + | editor.draw(Position(mouse_map_x, mouse_map_y, floor), event.ShiftDown() || event.AltDown()); |
| 869 | + | |
| 870 | + | if (will_show_spawn) { |
| 871 | + | Tile* tile = editor.map.getTile(mouse_map_x, mouse_map_y, floor); |
| 872 | + | if (tile && tile->spawn) { |
| 873 | + | g_settings.setInteger(Config::SHOW_SPAWNS, true); |
| 874 | + | g_gui.UpdateMenubar(); |
| 875 | + | } |
| 876 | + | } |
| 877 | + | } |
| 878 | + | } else { |
| 879 | + | if (brush->isGround() && event.AltDown()) { |
| 880 | + | replace_dragging = true; |
| 881 | + | Tile* draw_tile = editor.map.getTile(mouse_map_x, mouse_map_y, floor); |
| 882 | + | if (draw_tile) { |
| 883 | + | editor.replace_brush = draw_tile->getGroundBrush(); |
| 884 | + | } else { |
| 885 | + | editor.replace_brush = nullptr; |
| 886 | + | } |
| 887 | + | } |
| 888 | + | |
| 889 | + | if (brush->needBorders()) { |
| 890 | + | PositionVector tilestodraw; |
| 891 | + | PositionVector tilestoborder; |
| 892 | + | |
| 893 | + | bool fill = keyCode == WXK_CONTROL_D && event.ControlDown() && brush->isGround(); |
| 894 | + | getTilesToDraw(mouse_map_x, mouse_map_y, floor, &tilestodraw, &tilestoborder, fill); |
| 895 | + | |
| 896 | + | if (!fill && event.ControlDown()) { |
| 897 | + | editor.undraw(tilestodraw, tilestoborder, event.AltDown()); |
| 898 | + | } else { |
| 899 | + | editor.draw(tilestodraw, tilestoborder, event.AltDown()); |
| 900 | + | } |
| 901 | + | } else if (brush->oneSizeFitsAll()) { |
| 902 | + | if (brush->isHouseExit() || brush->isWaypoint()) { |
| 903 | + | editor.draw(Position(mouse_map_x, mouse_map_y, floor), event.AltDown()); |
| 904 | + | } else { |
| 905 | + | PositionVector tilestodraw; |
| 906 | + | tilestodraw.push_back(Position(mouse_map_x, mouse_map_y, floor)); |
| 907 | + | if (event.ControlDown()) { |
| 908 | + | editor.undraw(tilestodraw, event.AltDown()); |
| 909 | + | } else { |
| 910 | + | editor.draw(tilestodraw, event.AltDown()); |
| 911 | + | } |
| 912 | + | } |
| 913 | + | } else { |
| 914 | + | PositionVector tilestodraw; |
| 915 | + | |
| 916 | + | getTilesToDraw(mouse_map_x, mouse_map_y, floor, &tilestodraw, nullptr); |
| 917 | + | |
| 918 | + | if (event.ControlDown()) { |
| 919 | + | editor.undraw(tilestodraw, event.AltDown()); |
| 920 | + | } else { |
| 921 | + | editor.draw(tilestodraw, event.AltDown()); |
| 922 | + | } |
| 923 | + | } |
| 924 | + | } |
| 925 | + | // Change the doodad layout brush |
| 926 | + | g_gui.FillDoodadPreviewBuffer(); |
| 927 | + | } |
| 928 | + | } |
| 929 | + | last_click_x = int(event.GetX() * zoom); |
| 930 | + | last_click_y = int(event.GetY() * zoom); |
| 931 | + | |
| 932 | + | int start_x, start_y; |
| 933 | + | static_cast<MapWindow*>(GetParent())->GetViewStart(&start_x, &start_y); |
| 934 | + | last_click_abs_x = last_click_x + start_x; |
| 935 | + | last_click_abs_y = last_click_y + start_y; |
| 936 | + | |
| 937 | + | last_click_map_x = mouse_map_x; |
| 938 | + | last_click_map_y = mouse_map_y; |
| 939 | + | last_click_map_z = floor; |
| 940 | + | g_gui.RefreshView(); |
| 941 | + | g_gui.UpdateMinimap(); |
| 942 | + | } |
| 943 | + | |
| 944 | + | void MapCanvas::OnMouseActionRelease(wxMouseEvent& event) { |
| 945 | + | int mouse_map_x, mouse_map_y; |
| 946 | + | ScreenToMap(event.GetX(), event.GetY(), &mouse_map_x, &mouse_map_y); |
| 947 | + | |
| 948 | + | int move_x = last_click_map_x - mouse_map_x; |
| 949 | + | int move_y = last_click_map_y - mouse_map_y; |
| 950 | + | int move_z = last_click_map_z - floor; |
| 951 | + | |
| 952 | + | if (g_gui.IsSelectionMode()) { |
| 953 | + | if (dragging && (move_x != 0 || move_y != 0 || move_z != 0)) { |
| 954 | + | editor.moveSelection(Position(move_x, move_y, move_z)); |
| 955 | + | } else { |
| 956 | + | if (boundbox_selection) { |
| 957 | + | if (mouse_map_x == last_click_map_x && mouse_map_y == last_click_map_y && event.ControlDown()) { |
| 958 | + | // Mouse hasn't moved, do control+shift thingy! |
| 959 | + | Tile* tile = editor.map.getTile(mouse_map_x, mouse_map_y, floor); |
| 960 | + | if (tile) { |
| 961 | + | editor.selection.start(); // Start a selection session |
| 962 | + | if (tile->isSelected()) { |
| 963 | + | editor.selection.remove(tile); |
| 964 | + | } else { |
| 965 | + | editor.selection.add(tile); |
| 966 | + | } |
| 967 | + | editor.selection.finish(); // Finish the selection session |
| 968 | + | editor.selection.updateSelectionCount(); |
| 969 | + | } |
| 970 | + | } else { |
| 971 | + | // The cursor has moved, do some boundboxing! |
| 972 | + | if (last_click_map_x > mouse_map_x) { |
| 973 | + | int tmp = mouse_map_x; |
| 974 | + | mouse_map_x = last_click_map_x; |
| 975 | + | last_click_map_x = tmp; |
| 976 | + | } |
| 977 | + | if (last_click_map_y > mouse_map_y) { |
| 978 | + | int tmp = mouse_map_y; |
| 979 | + | mouse_map_y = last_click_map_y; |
| 980 | + | last_click_map_y = tmp; |
| 981 | + | } |
| 982 | + | |
| 983 | + | int numtiles = 0; |
| 984 | + | int threadcount = std::max(g_settings.getInteger(Config::WORKER_THREADS), 1); |
| 985 | + | |
| 986 | + | int start_x = 0, start_y = 0, start_z = 0; |
| 987 | + | int end_x = 0, end_y = 0, end_z = 0; |
| 988 | + | |
| 989 | + | switch (g_settings.getInteger(Config::SELECTION_TYPE)) { |
| 990 | + | case SELECT_CURRENT_FLOOR: { |
| 991 | + | start_z = end_z = floor; |
| 992 | + | start_x = last_click_map_x; |
| 993 | + | start_y = last_click_map_y; |
| 994 | + | end_x = mouse_map_x; |
| 995 | + | end_y = mouse_map_y; |
| 996 | + | break; |
| 997 | + | } |
| 998 | + | case SELECT_ALL_FLOORS: { |
| 999 | + | start_x = last_click_map_x; |
| 1000 | + | start_y = last_click_map_y; |
| 1001 | + | start_z = MAP_MAX_LAYER; |
| 1002 | + | end_x = mouse_map_x; |
| 1003 | + | end_y = mouse_map_y; |
| 1004 | + | end_z = floor; |
| 1005 | + | |
| 1006 | + | if (g_settings.getInteger(Config::COMPENSATED_SELECT)) { |
| 1007 | + | start_x -= (floor < GROUND_LAYER ? GROUND_LAYER - floor : 0); |
| 1008 | + | start_y -= (floor < GROUND_LAYER ? GROUND_LAYER - floor : 0); |
| 1009 | + | |
| 1010 | + | end_x -= (floor < GROUND_LAYER ? GROUND_LAYER - floor : 0); |
| 1011 | + | end_y -= (floor < GROUND_LAYER ? GROUND_LAYER - floor : 0); |
| 1012 | + | } |
| 1013 | + | |
| 1014 | + | numtiles = (start_z - end_z) * (end_x - start_x) * (end_y - start_y); |
| 1015 | + | break; |
| 1016 | + | } |
| 1017 | + | case SELECT_VISIBLE_FLOORS: { |
| 1018 | + | start_x = last_click_map_x; |
| 1019 | + | start_y = last_click_map_y; |
| 1020 | + | if (floor <= GROUND_LAYER) { |
| 1021 | + | start_z = GROUND_LAYER; |
| 1022 | + | } else { |
| 1023 | + | start_z = std::min(MAP_MAX_LAYER, floor + 2); |
| 1024 | + | } |
| 1025 | + | end_x = mouse_map_x; |
| 1026 | + | end_y = mouse_map_y; |
| 1027 | + | end_z = floor; |
| 1028 | + | |
| 1029 | + | if (g_settings.getInteger(Config::COMPENSATED_SELECT)) { |
| 1030 | + | start_x -= (floor < GROUND_LAYER ? GROUND_LAYER - floor : 0); |
| 1031 | + | start_y -= (floor < GROUND_LAYER ? GROUND_LAYER - floor : 0); |
| 1032 | + | |
| 1033 | + | end_x -= (floor < GROUND_LAYER ? GROUND_LAYER - floor : 0); |
| 1034 | + | end_y -= (floor < GROUND_LAYER ? GROUND_LAYER - floor : 0); |
| 1035 | + | } |
| 1036 | + | break; |
| 1037 | + | } |
| 1038 | + | } |
| 1039 | + | |
| 1040 | + | if (numtiles < 500) { |
| 1041 | + | // No point in threading for such a small set. |
| 1042 | + | threadcount = 1; |
| 1043 | + | } |
| 1044 | + | // Subdivide the selection area |
| 1045 | + | // We know it's a square, just split it into several areas |
| 1046 | + | int width = end_x - start_x; |
| 1047 | + | if (width < threadcount) { |
| 1048 | + | threadcount = min(1, width); |
| 1049 | + | } |
| 1050 | + | // Let's divide! |
| 1051 | + | int remainder = width; |
| 1052 | + | int cleared = 0; |
| 1053 | + | std::vector<SelectionThread*> threads; |
| 1054 | + | if (width == 0) { |
| 1055 | + | threads.push_back(newd SelectionThread(editor, Position(start_x, start_y, start_z), Position(start_x, end_y, end_z))); |
| 1056 | + | } else { |
| 1057 | + | for (int i = 0; i < threadcount; ++i) { |
| 1058 | + | int chunksize = width / threadcount; |
| 1059 | + | // The last threads takes all the remainder |
| 1060 | + | if (i == threadcount - 1) { |
| 1061 | + | chunksize = remainder; |
| 1062 | + | } |
| 1063 | + | threads.push_back(newd SelectionThread(editor, Position(start_x + cleared, start_y, start_z), Position(start_x + cleared + chunksize, end_y, end_z))); |
| 1064 | + | cleared += chunksize; |
| 1065 | + | remainder -= chunksize; |
| 1066 | + | } |
| 1067 | + | } |
| 1068 | + | ASSERT(cleared == width); |
| 1069 | + | ASSERT(remainder == 0); |
| 1070 | + | |
| 1071 | + | editor.selection.start(); // Start a selection session |
| 1072 | + | for (std::vector<SelectionThread*>::iterator iter = threads.begin(); iter != threads.end(); ++iter) { |
| 1073 | + | (*iter)->Execute(); |
| 1074 | + | } |
| 1075 | + | for (std::vector<SelectionThread*>::iterator iter = threads.begin(); iter != threads.end(); ++iter) { |
| 1076 | + | editor.selection.join(*iter); |
| 1077 | + | } |
| 1078 | + | editor.selection.finish(); // Finish the selection session |
| 1079 | + | editor.selection.updateSelectionCount(); |
| 1080 | + | } |
| 1081 | + | } else if (event.ControlDown()) { |
| 1082 | + | //// |
| 1083 | + | } else { |
| 1084 | + | // User hasn't moved anything, meaning selection/deselection |
| 1085 | + | Tile* tile = editor.map.getTile(mouse_map_x, mouse_map_y, floor); |
| 1086 | + | if (tile) { |
| 1087 | + | if (tile->spawn && g_settings.getInteger(Config::SHOW_SPAWNS)) { |
| 1088 | + | if (!tile->spawn->isSelected()) { |
| 1089 | + | editor.selection.start(); // Start a selection session |
| 1090 | + | editor.selection.add(tile, tile->spawn); |
| 1091 | + | editor.selection.finish(); // Finish the selection session |
| 1092 | + | editor.selection.updateSelectionCount(); |
| 1093 | + | } |
| 1094 | + | } else if (tile->creature && g_settings.getInteger(Config::SHOW_CREATURES)) { |
| 1095 | + | if (!tile->creature->isSelected()) { |
| 1096 | + | editor.selection.start(); // Start a selection session |
| 1097 | + | editor.selection.add(tile, tile->creature); |
| 1098 | + | editor.selection.finish(); // Finish the selection session |
| 1099 | + | editor.selection.updateSelectionCount(); |
| 1100 | + | } |
| 1101 | + | } else { |
| 1102 | + | Item* item = tile->getTopItem(); |
| 1103 | + | if (item && !item->isSelected()) { |
| 1104 | + | editor.selection.start(); // Start a selection session |
| 1105 | + | editor.selection.add(tile, item); |
| 1106 | + | editor.selection.finish(); // Finish the selection session |
| 1107 | + | editor.selection.updateSelectionCount(); |
| 1108 | + | } |
| 1109 | + | } |
| 1110 | + | } |
| 1111 | + | } |
| 1112 | + | } |
| 1113 | + | editor.actionQueue->resetTimer(); |
| 1114 | + | dragging = false; |
| 1115 | + | boundbox_selection = false; |
| 1116 | + | } else if (g_gui.GetCurrentBrush()) { // Drawing mode |
| 1117 | + | Brush* brush = g_gui.GetCurrentBrush(); |
| 1118 | + | if (dragging_draw) { |
| 1119 | + | if (brush->isSpawn()) { |
| 1120 | + | int start_map_x = std::min(last_click_map_x, mouse_map_x); |
| 1121 | + | int start_map_y = std::min(last_click_map_y, mouse_map_y); |
| 1122 | + | int end_map_x = std::max(last_click_map_x, mouse_map_x); |
| 1123 | + | int end_map_y = std::max(last_click_map_y, mouse_map_y); |
| 1124 | + | |
| 1125 | + | int map_x = start_map_x + (end_map_x - start_map_x) / 2; |
| 1126 | + | int map_y = start_map_y + (end_map_y - start_map_y) / 2; |
| 1127 | + | |
| 1128 | + | int width = min(g_settings.getInteger(Config::MAX_SPAWN_RADIUS), ((end_map_x - start_map_x) / 2 + (end_map_y - start_map_y) / 2) / 2); |
| 1129 | + | int old = g_gui.GetBrushSize(); |
| 1130 | + | g_gui.SetBrushSize(width); |
| 1131 | + | editor.draw(Position(map_x, map_y, floor), event.AltDown()); |
| 1132 | + | g_gui.SetBrushSize(old); |
| 1133 | + | } else { |
| 1134 | + | PositionVector tilestodraw; |
| 1135 | + | PositionVector tilestoborder; |
| 1136 | + | if (brush->isWall()) { |
| 1137 | + | int start_map_x = std::min(last_click_map_x, mouse_map_x); |
| 1138 | + | int start_map_y = std::min(last_click_map_y, mouse_map_y); |
| 1139 | + | int end_map_x = std::max(last_click_map_x, mouse_map_x); |
| 1140 | + | int end_map_y = std::max(last_click_map_y, mouse_map_y); |
| 1141 | + | |
| 1142 | + | for (int y = start_map_y - 1; y <= end_map_y + 1; y++) { |
| 1143 | + | for (int x = start_map_x - 1; x <= end_map_x + 1; x++) { |
| 1144 | + | if ((x <= start_map_x + 1 || x >= end_map_x - 1) || (y <= start_map_y + 1 || y >= end_map_y - 1)) { |
| 1145 | + | tilestoborder.push_back(Position(x, y, floor)); |
| 1146 | + | } |
| 1147 | + | if (((x == start_map_x || x == end_map_x) || (y == start_map_y || y == end_map_y)) && ((x >= start_map_x && x <= end_map_x) && (y >= start_map_y && y <= end_map_y))) { |
| 1148 | + | tilestodraw.push_back(Position(x, y, floor)); |
| 1149 | + | } |
| 1150 | + | } |
| 1151 | + | } |
| 1152 | + | } else { |
| 1153 | + | if (g_gui.GetBrushShape() == BRUSHSHAPE_SQUARE) { |
| 1154 | + | if (last_click_map_x > mouse_map_x) { |
| 1155 | + | int tmp = mouse_map_x; |
| 1156 | + | mouse_map_x = last_click_map_x; |
| 1157 | + | last_click_map_x = tmp; |
| 1158 | + | } |
| 1159 | + | if (last_click_map_y > mouse_map_y) { |
| 1160 | + | int tmp = mouse_map_y; |
| 1161 | + | mouse_map_y = last_click_map_y; |
| 1162 | + | last_click_map_y = tmp; |
| 1163 | + | } |
| 1164 | + | |
| 1165 | + | for (int x = last_click_map_x - 1; x <= mouse_map_x + 1; x++) { |
| 1166 | + | for (int y = last_click_map_y - 1; y <= mouse_map_y + 1; y++) { |
| 1167 | + | if ((x <= last_click_map_x || x >= mouse_map_x) || (y <= last_click_map_y || y >= mouse_map_y)) { |
| 1168 | + | tilestoborder.push_back(Position(x, y, floor)); |
| 1169 | + | } |
| 1170 | + | if ((x >= last_click_map_x && x <= mouse_map_x) && (y >= last_click_map_y && y <= mouse_map_y)) { |
| 1171 | + | tilestodraw.push_back(Position(x, y, floor)); |
| 1172 | + | } |
| 1173 | + | } |
| 1174 | + | } |
| 1175 | + | } else { |
| 1176 | + | int start_x, end_x; |
| 1177 | + | int start_y, end_y; |
| 1178 | + | int width = std::max( |
| 1179 | + | std::abs( |
| 1180 | + | std::max(mouse_map_y, last_click_map_y) - std::min(mouse_map_y, last_click_map_y) |
| 1181 | + | ), |
| 1182 | + | std::abs( |
| 1183 | + | std::max(mouse_map_x, last_click_map_x) - std::min(mouse_map_x, last_click_map_x) |
| 1184 | + | ) |
| 1185 | + | ); |
| 1186 | + | if (mouse_map_x < last_click_map_x) { |
| 1187 | + | start_x = last_click_map_x - width; |
| 1188 | + | end_x = last_click_map_x; |
| 1189 | + | } else { |
| 1190 | + | start_x = last_click_map_x; |
| 1191 | + | end_x = last_click_map_x + width; |
| 1192 | + | } |
| 1193 | + | if (mouse_map_y < last_click_map_y) { |
| 1194 | + | start_y = last_click_map_y - width; |
| 1195 | + | end_y = last_click_map_y; |
| 1196 | + | } else { |
| 1197 | + | start_y = last_click_map_y; |
| 1198 | + | end_y = last_click_map_y + width; |
| 1199 | + | } |
| 1200 | + | |
| 1201 | + | int center_x = start_x + (end_x - start_x) / 2; |
| 1202 | + | int center_y = start_y + (end_y - start_y) / 2; |
| 1203 | + | float radii = width / 2.0f + 0.005f; |
| 1204 | + | |
| 1205 | + | for (int y = start_y - 1; y <= end_y + 1; y++) { |
| 1206 | + | float dy = center_y - y; |
| 1207 | + | for (int x = start_x - 1; x <= end_x + 1; x++) { |
| 1208 | + | float dx = center_x - x; |
| 1209 | + | // printf("%f;%f\n", dx, dy); |
| 1210 | + | float distance = sqrt(dx * dx + dy * dy); |
| 1211 | + | if (distance < radii) { |
| 1212 | + | tilestodraw.push_back(Position(x, y, floor)); |
| 1213 | + | } |
| 1214 | + | if (std::abs(distance - radii) < 1.5) { |
| 1215 | + | tilestoborder.push_back(Position(x, y, floor)); |
| 1216 | + | } |
| 1217 | + | } |
| 1218 | + | } |
| 1219 | + | } |
| 1220 | + | } |
| 1221 | + | if (event.ControlDown()) { |
| 1222 | + | editor.undraw(tilestodraw, tilestoborder, event.AltDown()); |
| 1223 | + | } else { |
| 1224 | + | editor.draw(tilestodraw, tilestoborder, event.AltDown()); |
| 1225 | + | } |
| 1226 | + | } |
| 1227 | + | } |
| 1228 | + | editor.actionQueue->resetTimer(); |
| 1229 | + | drawing = false; |
| 1230 | + | dragging_draw = false; |
| 1231 | + | replace_dragging = false; |
| 1232 | + | editor.replace_brush = nullptr; |
| 1233 | + | } |
| 1234 | + | g_gui.RefreshView(); |
| 1235 | + | g_gui.UpdateMinimap(); |
| 1236 | + | } |
| 1237 | + | |
| 1238 | + | void MapCanvas::OnMouseCameraClick(wxMouseEvent& event) { |
| 1239 | + | SetFocus(); |
| 1240 | + | |
| 1241 | + | last_mmb_click_x = event.GetX(); |
| 1242 | + | last_mmb_click_y = event.GetY(); |
| 1243 | + | if (event.ControlDown()) { |
| 1244 | + | int screensize_x, screensize_y; |
| 1245 | + | static_cast<MapWindow*>(GetParent())->GetViewSize(&screensize_x, &screensize_y); |
| 1246 | + | |
| 1247 | + | static_cast<MapWindow*>(GetParent())->ScrollRelative(int(-screensize_x * (1.0 - zoom) * (std::max(cursor_x, 1) / double(screensize_x))), int(-screensize_y * (1.0 - zoom) * (std::max(cursor_y, 1) / double(screensize_y)))); |
| 1248 | + | zoom = 1.0; |
| 1249 | + | Refresh(); |
| 1250 | + | } else { |
| 1251 | + | screendragging = true; |
| 1252 | + | } |
| 1253 | + | } |
| 1254 | + | |
| 1255 | + | void MapCanvas::OnMouseCameraRelease(wxMouseEvent& event) { |
| 1256 | + | SetFocus(); |
| 1257 | + | screendragging = false; |
| 1258 | + | if (event.ControlDown()) { |
| 1259 | + | // ... |
| 1260 | + | // Haven't moved much, it's a click! |
| 1261 | + | } else if (last_mmb_click_x > event.GetX() - 3 && last_mmb_click_x < event.GetX() + 3 && last_mmb_click_y > event.GetY() - 3 && last_mmb_click_y < event.GetY() + 3) { |
| 1262 | + | int screensize_x, screensize_y; |
| 1263 | + | static_cast<MapWindow*>(GetParent())->GetViewSize(&screensize_x, &screensize_y); |
| 1264 | + | static_cast<MapWindow*>(GetParent())->ScrollRelative(int(zoom * (2 * cursor_x - screensize_x)), int(zoom * (2 * cursor_y - screensize_y))); |
| 1265 | + | Refresh(); |
| 1266 | + | } |
| 1267 | + | } |
| 1268 | + | |
| 1269 | + | void MapCanvas::OnMousePropertiesClick(wxMouseEvent& event) { |
| 1270 | + | SetFocus(); |
| 1271 | + | |
| 1272 | + | int mouse_map_x, mouse_map_y; |
| 1273 | + | ScreenToMap(event.GetX(), event.GetY(), &mouse_map_x, &mouse_map_y); |
| 1274 | + | Tile* tile = editor.map.getTile(mouse_map_x, mouse_map_y, floor); |
| 1275 | + | |
| 1276 | + | if (g_gui.IsDrawingMode()) { |
| 1277 | + | g_gui.SetSelectionMode(); |
| 1278 | + | } |
| 1279 | + | |
| 1280 | + | EndPasting(); |
| 1281 | + | |
| 1282 | + | boundbox_selection = false; |
| 1283 | + | if (event.ShiftDown()) { |
| 1284 | + | boundbox_selection = true; |
| 1285 | + | |
| 1286 | + | if (!event.ControlDown()) { |
| 1287 | + | editor.selection.start(); // Start selection session |
| 1288 | + | editor.selection.clear(); // Clear out selection |
| 1289 | + | editor.selection.finish(); // End selection session |
| 1290 | + | editor.selection.updateSelectionCount(); |
| 1291 | + | } |
| 1292 | + | } else if (!tile) { |
| 1293 | + | editor.selection.start(); // Start selection session |
| 1294 | + | editor.selection.clear(); // Clear out selection |
| 1295 | + | editor.selection.finish(); // End selection session |
| 1296 | + | editor.selection.updateSelectionCount(); |
| 1297 | + | } else if (tile->isSelected()) { |
| 1298 | + | // Do nothing! |
| 1299 | + | } else { |
| 1300 | + | editor.selection.start(); // Start a selection session |
| 1301 | + | editor.selection.clear(); |
| 1302 | + | editor.selection.commit(); |
| 1303 | + | if (tile->spawn && g_settings.getInteger(Config::SHOW_SPAWNS)) { |
| 1304 | + | editor.selection.add(tile, tile->spawn); |
| 1305 | + | } else if (tile->creature && g_settings.getInteger(Config::SHOW_CREATURES)) { |
| 1306 | + | editor.selection.add(tile, tile->creature); |
| 1307 | + | } else { |
| 1308 | + | Item* item = tile->getTopItem(); |
| 1309 | + | if (item) { |
| 1310 | + | editor.selection.add(tile, item); |
| 1311 | + | } |
| 1312 | + | } |
| 1313 | + | editor.selection.finish(); // Finish the selection session |
| 1314 | + | editor.selection.updateSelectionCount(); |
| 1315 | + | } |
| 1316 | + | |
| 1317 | + | last_click_x = int(event.GetX() * zoom); |
| 1318 | + | last_click_y = int(event.GetY() * zoom); |
| 1319 | + | |
| 1320 | + | int start_x, start_y; |
| 1321 | + | static_cast<MapWindow*>(GetParent())->GetViewStart(&start_x, &start_y); |
| 1322 | + | last_click_abs_x = last_click_x + start_x; |
| 1323 | + | last_click_abs_y = last_click_y + start_y; |
| 1324 | + | |
| 1325 | + | last_click_map_x = mouse_map_x; |
| 1326 | + | last_click_map_y = mouse_map_y; |
| 1327 | + | g_gui.RefreshView(); |
| 1328 | + | } |
| 1329 | + | |
| 1330 | + | void MapCanvas::OnMousePropertiesRelease(wxMouseEvent& event) { |
| 1331 | + | int mouse_map_x, mouse_map_y; |
| 1332 | + | ScreenToMap(event.GetX(), event.GetY(), &mouse_map_x, &mouse_map_y); |
| 1333 | + | |
| 1334 | + | #ifdef __WXDEBUG__ |
| 1335 | + | printf("DEBUG: Right-click release at map position %d,%d,%d\n", mouse_map_x, mouse_map_y, floor); |
| 1336 | + | Tile* tile = editor.map.getTile(mouse_map_x, mouse_map_y, floor); |
| 1337 | + | if (tile && tile->ground) { |
| 1338 | + | printf("DEBUG: Tile has ground at %p\n", tile->ground); |
| 1339 | + | } |
| 1340 | + | #endif |
| 1341 | + | |
| 1342 | + | if (g_gui.IsDrawingMode()) { |
| 1343 | + | g_gui.SetSelectionMode(); |
| 1344 | + | } |
| 1345 | + | |
| 1346 | + | if (boundbox_selection) { |
| 1347 | + | if (mouse_map_x == last_click_map_x && mouse_map_y == last_click_map_y && event.ControlDown()) { |
| 1348 | + | // Mouse hasn't move, do control+shift thingy! |
| 1349 | + | Tile* tile = editor.map.getTile(mouse_map_x, mouse_map_y, floor); |
| 1350 | + | if (tile) { |
| 1351 | + | editor.selection.start(); // Start a selection session |
| 1352 | + | if (tile->isSelected()) { |
| 1353 | + | editor.selection.remove(tile); |
| 1354 | + | } else { |
| 1355 | + | editor.selection.add(tile); |
| 1356 | + | } |
| 1357 | + | editor.selection.finish(); // Finish the selection session |
| 1358 | + | editor.selection.updateSelectionCount(); |
| 1359 | + | } |
| 1360 | + | } else { |
| 1361 | + | // The cursor has moved, do some boundboxing! |
| 1362 | + | if (last_click_map_x > mouse_map_x) { |
| 1363 | + | int tmp = mouse_map_x; |
| 1364 | + | mouse_map_x = last_click_map_x; |
| 1365 | + | last_click_map_x = tmp; |
| 1366 | + | } |
| 1367 | + | if (last_click_map_y > mouse_map_y) { |
| 1368 | + | int tmp = mouse_map_y; |
| 1369 | + | mouse_map_y = last_click_map_y; |
| 1370 | + | last_click_map_y = tmp; |
| 1371 | + | } |
| 1372 | + | |
| 1373 | + | editor.selection.start(); // Start a selection session |
| 1374 | + | switch (g_settings.getInteger(Config::SELECTION_TYPE)) { |
| 1375 | + | case SELECT_CURRENT_FLOOR: { |
| 1376 | + | for (int x = last_click_map_x; x <= mouse_map_x; x++) { |
| 1377 | + | for (int y = last_click_map_y; y <= mouse_map_y; y++) { |
| 1378 | + | Tile* tile = editor.map.getTile(x, y, floor); |
| 1379 | + | if (!tile) { |
| 1380 | + | continue; |
| 1381 | + | } |
| 1382 | + | editor.selection.add(tile); |
| 1383 | + | } |
| 1384 | + | } |
| 1385 | + | break; |
| 1386 | + | } |
| 1387 | + | case SELECT_ALL_FLOORS: { |
| 1388 | + | int start_x, start_y, start_z; |
| 1389 | + | int end_x, end_y, end_z; |
| 1390 | + | |
| 1391 | + | start_x = last_click_map_x; |
| 1392 | + | start_y = last_click_map_y; |
| 1393 | + | start_z = MAP_MAX_LAYER; |
| 1394 | + | end_x = mouse_map_x; |
| 1395 | + | end_y = mouse_map_y; |
| 1396 | + | end_z = floor; |
| 1397 | + | |
| 1398 | + | if (g_settings.getInteger(Config::COMPENSATED_SELECT)) { |
| 1399 | + | start_x -= (floor < GROUND_LAYER ? GROUND_LAYER - floor : 0); |
| 1400 | + | start_y -= (floor < GROUND_LAYER ? GROUND_LAYER - floor : 0); |
| 1401 | + | |
| 1402 | + | end_x -= (floor < GROUND_LAYER ? GROUND_LAYER - floor : 0); |
| 1403 | + | end_y -= (floor < GROUND_LAYER ? GROUND_LAYER - floor : 0); |
| 1404 | + | } |
| 1405 | + | |
| 1406 | + | for (int z = start_z; z >= end_z; z--) { |
| 1407 | + | for (int x = start_x; x <= end_x; x++) { |
| 1408 | + | for (int y = start_y; y <= end_y; y++) { |
| 1409 | + | Tile* tile = editor.map.getTile(x, y, z); |
| 1410 | + | if (!tile) { |
| 1411 | + | continue; |
| 1412 | + | } |
| 1413 | + | editor.selection.add(tile); |
| 1414 | + | } |
| 1415 | + | } |
| 1416 | + | if (z <= GROUND_LAYER && g_settings.getInteger(Config::COMPENSATED_SELECT)) { |
| 1417 | + | start_x++; |
| 1418 | + | start_y++; |
| 1419 | + | end_x++; |
| 1420 | + | end_y++; |
| 1421 | + | } |
| 1422 | + | } |
| 1423 | + | break; |
| 1424 | + | } |
| 1425 | + | case SELECT_VISIBLE_FLOORS: { |
| 1426 | + | int start_x, start_y, start_z; |
| 1427 | + | int end_x, end_y, end_z; |
| 1428 | + | |
| 1429 | + | start_x = last_click_map_x; |
| 1430 | + | start_y = last_click_map_y; |
| 1431 | + | if (floor <= GROUND_LAYER) { |
| 1432 | + | start_z = GROUND_LAYER; |
| 1433 | + | } else { |
| 1434 | + | start_z = std::min(MAP_MAX_LAYER, floor + 2); |
| 1435 | + | } |
| 1436 | + | end_x = mouse_map_x; |
| 1437 | + | end_y = mouse_map_y; |
| 1438 | + | end_z = floor; |
| 1439 | + | |
| 1440 | + | if (g_settings.getInteger(Config::COMPENSATED_SELECT)) { |
| 1441 | + | start_x -= (floor < GROUND_LAYER ? GROUND_LAYER - floor : 0); |
| 1442 | + | start_y -= (floor < GROUND_LAYER ? GROUND_LAYER - floor : 0); |
| 1443 | + | |
| 1444 | + | end_x -= (floor < GROUND_LAYER ? GROUND_LAYER - floor : 0); |
| 1445 | + | end_y -= (floor < GROUND_LAYER ? GROUND_LAYER - floor : 0); |
| 1446 | + | } |
| 1447 | + | |
| 1448 | + | for (int z = start_z; z >= end_z; z--) { |
| 1449 | + | for (int x = start_x; x <= end_x; x++) { |
| 1450 | + | for (int y = start_y; y <= end_y; y++) { |
| 1451 | + | Tile* tile = editor.map.getTile(x, y, z); |
| 1452 | + | if (!tile) { |
| 1453 | + | continue; |
| 1454 | + | } |
| 1455 | + | editor.selection.add(tile); |
| 1456 | + | } |
| 1457 | + | } |
| 1458 | + | if (z <= GROUND_LAYER && g_settings.getInteger(Config::COMPENSATED_SELECT)) { |
| 1459 | + | start_x++; |
| 1460 | + | start_y++; |
| 1461 | + | end_x++; |
| 1462 | + | end_y++; |
| 1463 | + | } |
| 1464 | + | } |
| 1465 | + | break; |
| 1466 | + | } |
| 1467 | + | } |
| 1468 | + | editor.selection.finish(); // Finish the selection session |
| 1469 | + | editor.selection.updateSelectionCount(); |
| 1470 | + | } |
| 1471 | + | } else if (event.ControlDown()) { |
| 1472 | + | // Nothing |
| 1473 | + | } |
| 1474 | + | |
| 1475 | + | popup_menu->Update(); |
| 1476 | + | |
| 1477 | + | #ifdef __WXDEBUG__ |
| 1478 | + | // Debug the state of the tiles before showing popup menu |
| 1479 | + | int debug_mouse_x, debug_mouse_y; |
| 1480 | + | ScreenToMap(event.GetX(), event.GetY(), &debug_mouse_x, &debug_mouse_y); |
| 1481 | + | Tile* debug_tile = editor.map.getTile(debug_mouse_x, debug_mouse_y, floor); |
| 1482 | + | |
| 1483 | + | printf("DEBUG: Before popup menu - Tile at %d,%d,%d: %p\n", |
| 1484 | + | debug_mouse_x, debug_mouse_y, floor, debug_tile); |
| 1485 | + | if (debug_tile && debug_tile->ground) { |
| 1486 | + | printf("DEBUG: Before popup menu - Tile has ground %p (ID:%d)\n", |
| 1487 | + | debug_tile->ground, debug_tile->ground->getID()); |
| 1488 | + | } |
| 1489 | + | #endif |
| 1490 | + | |
| 1491 | + | PopupMenu(popup_menu); |
| 1492 | + | |
| 1493 | + | #ifdef __WXDEBUG__ |
| 1494 | + | // Debug the state of the tiles after showing popup menu |
| 1495 | + | debug_tile = editor.map.getTile(debug_mouse_x, debug_mouse_y, floor); |
| 1496 | + | printf("DEBUG: After popup menu - Tile at %d,%d,%d: %p\n", |
| 1497 | + | debug_mouse_x, debug_mouse_y, floor, debug_tile); |
| 1498 | + | if (debug_tile && debug_tile->ground) { |
| 1499 | + | printf("DEBUG: After popup menu - Tile has ground %p (ID:%d)\n", |
| 1500 | + | debug_tile->ground, debug_tile->ground->getID()); |
| 1501 | + | } |
| 1502 | + | #endif |
| 1503 | + | |
| 1504 | + | editor.actionQueue->resetTimer(); |
| 1505 | + | dragging = false; |
| 1506 | + | boundbox_selection = false; |
| 1507 | + | |
| 1508 | + | last_cursor_map_x = mouse_map_x; |
| 1509 | + | last_cursor_map_y = mouse_map_y; |
| 1510 | + | last_cursor_map_z = floor; |
| 1511 | + | |
| 1512 | + | g_gui.RefreshView(); |
| 1513 | + | } |
| 1514 | + | |
| 1515 | + | void MapCanvas::OnWheel(wxMouseEvent& event) { |
| 1516 | + | if (event.ControlDown()) { |
| 1517 | + | static double diff = 0.0; |
| 1518 | + | diff += event.GetWheelRotation(); |
| 1519 | + | if (diff <= 1.0 || diff >= 1.0) { |
| 1520 | + | if (diff < 0.0) { |
| 1521 | + | g_gui.ChangeFloor(floor - 1); |
| 1522 | + | } else { |
| 1523 | + | g_gui.ChangeFloor(floor + 1); |
| 1524 | + | } |
| 1525 | + | diff = 0.0; |
| 1526 | + | } |
| 1527 | + | UpdatePositionStatus(); |
| 1528 | + | } else if (event.AltDown()) { |
| 1529 | + | static double diff = 0.0; |
| 1530 | + | diff += event.GetWheelRotation(); |
| 1531 | + | if (diff <= 1.0 || diff >= 1.0) { |
| 1532 | + | if (diff < 0.0) { |
| 1533 | + | g_gui.IncreaseBrushSize(); |
| 1534 | + | } else { |
| 1535 | + | g_gui.DecreaseBrushSize(); |
| 1536 | + | } |
| 1537 | + | diff = 0.0; |
| 1538 | + | } |
| 1539 | + | } else { |
| 1540 | + | double diff = -event.GetWheelRotation() * g_settings.getFloat(Config::ZOOM_SPEED) / 640.0; |
| 1541 | + | double oldzoom = zoom; |
| 1542 | + | zoom += diff; |
| 1543 | + | |
| 1544 | + | if (zoom < 0.125) { |
| 1545 | + | diff = 0.125 - oldzoom; |
| 1546 | + | zoom = 0.125; |
| 1547 | + | } |
| 1548 | + | if (zoom > 25.00) { |
| 1549 | + | diff = 25.00 - oldzoom; |
| 1550 | + | zoom = 25.0; |
| 1551 | + | } |
| 1552 | + | |
| 1553 | + | UpdateZoomStatus(); |
| 1554 | + | |
| 1555 | + | int screensize_x, screensize_y; |
| 1556 | + | static_cast<MapWindow*>(GetParent())->GetViewSize(&screensize_x, &screensize_y); |
| 1557 | + | |
| 1558 | + | // This took a day to figure out! |
| 1559 | + | int scroll_x = int(screensize_x * diff * (std::max(cursor_x, 1) / double(screensize_x))) * GetContentScaleFactor(); |
| 1560 | + | int scroll_y = int(screensize_y * diff * (std::max(cursor_y, 1) / double(screensize_y))) * GetContentScaleFactor(); |
| 1561 | + | |
| 1562 | + | static_cast<MapWindow*>(GetParent())->ScrollRelative(-scroll_x, -scroll_y); |
| 1563 | + | } |
| 1564 | + | |
| 1565 | + | Refresh(); |
| 1566 | + | } |
| 1567 | + | |
| 1568 | + | void MapCanvas::OnLoseMouse(wxMouseEvent& event) { |
| 1569 | + | Refresh(); |
| 1570 | + | } |
| 1571 | + | |
| 1572 | + | void MapCanvas::OnGainMouse(wxMouseEvent& event) { |
| 1573 | + | if (!event.LeftIsDown()) { |
| 1574 | + | dragging = false; |
| 1575 | + | boundbox_selection = false; |
| 1576 | + | drawing = false; |
| 1577 | + | } |
| 1578 | + | if (!event.MiddleIsDown()) { |
| 1579 | + | screendragging = false; |
| 1580 | + | } |
| 1581 | + | |
| 1582 | + | Refresh(); |
| 1583 | + | } |
| 1584 | + | |
| 1585 | + | void MapCanvas::OnKeyDown(wxKeyEvent& event) { |
| 1586 | + | // char keycode = event.GetKeyCode(); |
| 1587 | + | // std::cout << "Keycode " << keycode << std::endl; |
| 1588 | + | switch (event.GetKeyCode()) { |
| 1589 | + | case WXK_NUMPAD_ADD: |
| 1590 | + | case WXK_PAGEUP: { |
| 1591 | + | g_gui.ChangeFloor(floor - 1); |
| 1592 | + | break; |
| 1593 | + | } |
| 1594 | + | case WXK_NUMPAD_SUBTRACT: |
| 1595 | + | case WXK_PAGEDOWN: { |
| 1596 | + | g_gui.ChangeFloor(floor + 1); |
| 1597 | + | break; |
| 1598 | + | } |
| 1599 | + | case WXK_NUMPAD_MULTIPLY: { |
| 1600 | + | double diff = -0.3; |
| 1601 | + | |
| 1602 | + | double oldzoom = zoom; |
| 1603 | + | zoom += diff; |
| 1604 | + | |
| 1605 | + | if (zoom < 0.125) { |
| 1606 | + | diff = 0.125 - oldzoom; |
| 1607 | + | zoom = 0.125; |
| 1608 | + | } |
| 1609 | + | |
| 1610 | + | int screensize_x, screensize_y; |
| 1611 | + | static_cast<MapWindow*>(GetParent())->GetViewSize(&screensize_x, &screensize_y); |
| 1612 | + | |
| 1613 | + | // This took a day to figure out! |
| 1614 | + | int scroll_x = int(screensize_x * diff * (std::max(cursor_x, 1) / double(screensize_x))); |
| 1615 | + | int scroll_y = int(screensize_y * diff * (std::max(cursor_y, 1) / double(screensize_y))); |
| 1616 | + | |
| 1617 | + | static_cast<MapWindow*>(GetParent())->ScrollRelative(-scroll_x, -scroll_y); |
| 1618 | + | |
| 1619 | + | UpdatePositionStatus(); |
| 1620 | + | UpdateZoomStatus(); |
| 1621 | + | Refresh(); |
| 1622 | + | break; |
| 1623 | + | } |
| 1624 | + | case WXK_NUMPAD_DIVIDE: { |
| 1625 | + | double diff = 0.3; |
| 1626 | + | double oldzoom = zoom; |
| 1627 | + | zoom += diff; |
| 1628 | + | |
| 1629 | + | if (zoom > 25.00) { |
| 1630 | + | diff = 25.00 - oldzoom; |
| 1631 | + | zoom = 25.0; |
| 1632 | + | } |
| 1633 | + | |
| 1634 | + | int screensize_x, screensize_y; |
| 1635 | + | static_cast<MapWindow*>(GetParent())->GetViewSize(&screensize_x, &screensize_y); |
| 1636 | + | |
| 1637 | + | // This took a day to figure out! |
| 1638 | + | int scroll_x = int(screensize_x * diff * (std::max(cursor_x, 1) / double(screensize_x))); |
| 1639 | + | int scroll_y = int(screensize_y * diff * (std::max(cursor_y, 1) / double(screensize_y))); |
| 1640 | + | |
| 1641 | + | static_cast<MapWindow*>(GetParent())->ScrollRelative(-scroll_x, -scroll_y); |
| 1642 | + | |
| 1643 | + | UpdatePositionStatus(); |
| 1644 | + | UpdateZoomStatus(); |
| 1645 | + | Refresh(); |
| 1646 | + | break; |
| 1647 | + | } |
| 1648 | + | // This will work like crap with non-us layouts, well, sucks for them until there is another solution. |
| 1649 | + | case '[': |
| 1650 | + | case '+': { |
| 1651 | + | g_gui.IncreaseBrushSize(); |
| 1652 | + | Refresh(); |
| 1653 | + | break; |
| 1654 | + | } |
| 1655 | + | case ']': |
| 1656 | + | case '-': { |
| 1657 | + | g_gui.DecreaseBrushSize(); |
| 1658 | + | Refresh(); |
| 1659 | + | break; |
| 1660 | + | } |
| 1661 | + | case WXK_NUMPAD_UP: |
| 1662 | + | case WXK_UP: { |
| 1663 | + | int start_x, start_y; |
| 1664 | + | static_cast<MapWindow*>(GetParent())->GetViewStart(&start_x, &start_y); |
| 1665 | + | |
| 1666 | + | int tiles = 3; |
| 1667 | + | if (event.ControlDown()) { |
| 1668 | + | tiles = 10; |
| 1669 | + | } else if (zoom == 1.0) { |
| 1670 | + | tiles = 1; |
| 1671 | + | } |
| 1672 | + | |
| 1673 | + | static_cast<MapWindow*>(GetParent())->Scroll(start_x, int(start_y - TileSize * tiles * zoom)); |
| 1674 | + | UpdatePositionStatus(); |
| 1675 | + | g_gui.UpdateMinimap(true); // Add immediate update |
| 1676 | + | Refresh(); |
| 1677 | + | break; |
| 1678 | + | } |
| 1679 | + | case WXK_NUMPAD_DOWN: |
| 1680 | + | case WXK_DOWN: { |
| 1681 | + | int start_x, start_y; |
| 1682 | + | static_cast<MapWindow*>(GetParent())->GetViewStart(&start_x, &start_y); |
| 1683 | + | |
| 1684 | + | int tiles = 3; |
| 1685 | + | if (event.ControlDown()) { |
| 1686 | + | tiles = 10; |
| 1687 | + | } else if (zoom == 1.0) { |
| 1688 | + | tiles = 1; |
| 1689 | + | } |
| 1690 | + | |
| 1691 | + | static_cast<MapWindow*>(GetParent())->Scroll(start_x, int(start_y + TileSize * tiles * zoom)); |
| 1692 | + | UpdatePositionStatus(); |
| 1693 | + | g_gui.UpdateMinimap(true); // Add immediate update |
| 1694 | + | Refresh(); |
| 1695 | + | break; |
| 1696 | + | } |
| 1697 | + | case WXK_NUMPAD_LEFT: |
| 1698 | + | case WXK_LEFT: { |
| 1699 | + | int start_x, start_y; |
| 1700 | + | static_cast<MapWindow*>(GetParent())->GetViewStart(&start_x, &start_y); |
| 1701 | + | |
| 1702 | + | int tiles = 3; |
| 1703 | + | if (event.ControlDown()) { |
| 1704 | + | tiles = 10; |
| 1705 | + | } else if (zoom == 1.0) { |
| 1706 | + | tiles = 1; |
| 1707 | + | } |
| 1708 | + | |
| 1709 | + | static_cast<MapWindow*>(GetParent())->Scroll(int(start_x - TileSize * tiles * zoom), start_y); |
| 1710 | + | UpdatePositionStatus(); |
| 1711 | + | g_gui.UpdateMinimap(true); // Add immediate update |
| 1712 | + | Refresh(); |
| 1713 | + | break; |
| 1714 | + | } |
| 1715 | + | case WXK_NUMPAD_RIGHT: |
| 1716 | + | case WXK_RIGHT: { |
| 1717 | + | int start_x, start_y; |
| 1718 | + | static_cast<MapWindow*>(GetParent())->GetViewStart(&start_x, &start_y); |
| 1719 | + | |
| 1720 | + | int tiles = 3; |
| 1721 | + | if (event.ControlDown()) { |
| 1722 | + | tiles = 10; |
| 1723 | + | } else if (zoom == 1.0) { |
| 1724 | + | tiles = 1; |
| 1725 | + | } |
| 1726 | + | |
| 1727 | + | static_cast<MapWindow*>(GetParent())->Scroll(int(start_x + TileSize * tiles * zoom), start_y); |
| 1728 | + | UpdatePositionStatus(); |
| 1729 | + | g_gui.UpdateMinimap(true); // Add immediate update |
| 1730 | + | Refresh(); |
| 1731 | + | break; |
| 1732 | + | } |
| 1733 | + | case WXK_SPACE: { // Utility keys |
| 1734 | + | if (event.ControlDown()) { |
| 1735 | + | g_gui.FillDoodadPreviewBuffer(); |
| 1736 | + | g_gui.RefreshView(); |
| 1737 | + | } else { |
| 1738 | + | g_gui.SwitchMode(); |
| 1739 | + | } |
| 1740 | + | break; |
| 1741 | + | } |
| 1742 | + | case WXK_TAB: { // Tab switch |
| 1743 | + | if (event.ShiftDown()) { |
| 1744 | + | g_gui.CycleTab(false); |
| 1745 | + | } else { |
| 1746 | + | g_gui.CycleTab(true); |
| 1747 | + | } |
| 1748 | + | break; |
| 1749 | + | } |
| 1750 | + | case WXK_DELETE: { // Delete |
| 1751 | + | editor.destroySelection(); |
| 1752 | + | g_gui.RefreshView(); |
| 1753 | + | break; |
| 1754 | + | } |
| 1755 | + | case 'z': |
| 1756 | + | case 'Z': { // Rotate counterclockwise (actually shift variaton, but whatever... :P) |
| 1757 | + | int nv = g_gui.GetBrushVariation(); |
| 1758 | + | --nv; |
| 1759 | + | if (nv < 0) { |
| 1760 | + | nv = max(0, (g_gui.GetCurrentBrush() ? g_gui.GetCurrentBrush()->getMaxVariation() - 1 : 0)); |
| 1761 | + | } |
| 1762 | + | g_gui.SetBrushVariation(nv); |
| 1763 | + | g_gui.RefreshView(); |
| 1764 | + | break; |
| 1765 | + | } |
| 1766 | + | case 'x': |
| 1767 | + | case 'X': { // Rotate clockwise (actually shift variaton, but whatever... :P) |
| 1768 | + | int nv = g_gui.GetBrushVariation(); |
| 1769 | + | ++nv; |
| 1770 | + | if (nv >= (g_gui.GetCurrentBrush() ? g_gui.GetCurrentBrush()->getMaxVariation() : 0)) { |
| 1771 | + | nv = 0; |
| 1772 | + | } |
| 1773 | + | g_gui.SetBrushVariation(nv); |
| 1774 | + | g_gui.RefreshView(); |
| 1775 | + | break; |
| 1776 | + | } |
| 1777 | + | case 'q': |
| 1778 | + | case 'Q': { // Select previous brush |
| 1779 | + | g_gui.SelectPreviousBrush(); |
| 1780 | + | break; |
| 1781 | + | } |
| 1782 | + | // Hotkeys |
| 1783 | + | case '0': |
| 1784 | + | case '1': |
| 1785 | + | case '2': |
| 1786 | + | case '3': |
| 1787 | + | case '4': |
| 1788 | + | case '5': |
| 1789 | + | case '6': |
| 1790 | + | case '7': |
| 1791 | + | case '8': |
| 1792 | + | case '9': { |
| 1793 | + | int index = event.GetKeyCode() - '0'; |
| 1794 | + | if (event.ControlDown()) { |
| 1795 | + | Hotkey hk; |
| 1796 | + | if (g_gui.IsSelectionMode()) { |
| 1797 | + | int view_start_x, view_start_y; |
| 1798 | + | static_cast<MapWindow*>(GetParent())->GetViewStart(&view_start_x, &view_start_y); |
| 1799 | + | int view_start_map_x = view_start_x / TileSize, view_start_map_y = view_start_y / TileSize; |
| 1800 | + | |
| 1801 | + | int view_screensize_x, view_screensize_y; |
| 1802 | + | static_cast<MapWindow*>(GetParent())->GetViewSize(&view_screensize_x, &view_screensize_y); |
| 1803 | + | |
| 1804 | + | int map_x = int(view_start_map_x + (view_screensize_x * zoom) / TileSize / 2); |
| 1805 | + | int map_y = int(view_start_map_y + (view_screensize_y * zoom) / TileSize / 2); |
| 1806 | + | |
| 1807 | + | hk = Hotkey(Position(map_x, map_y, floor)); |
| 1808 | + | } else if (g_gui.GetCurrentBrush()) { |
| 1809 | + | // Drawing mode |
| 1810 | + | hk = Hotkey(g_gui.GetCurrentBrush()); |
| 1811 | + | } else { |
| 1812 | + | break; |
| 1813 | + | } |
| 1814 | + | g_gui.SetHotkey(index, hk); |
| 1815 | + | } else { |
| 1816 | + | // Click hotkey |
| 1817 | + | Hotkey hk = g_gui.GetHotkey(index); |
| 1818 | + | if (hk.IsPosition()) { |
| 1819 | + | g_gui.SetSelectionMode(); |
| 1820 | + | |
| 1821 | + | int map_x = hk.GetPosition().x; |
| 1822 | + | int map_y = hk.GetPosition().y; |
| 1823 | + | int map_z = hk.GetPosition().z; |
| 1824 | + | |
| 1825 | + | static_cast<MapWindow*>(GetParent())->Scroll(TileSize * map_x, TileSize * map_y, true); |
| 1826 | + | floor = map_z; |
| 1827 | + | |
| 1828 | + | g_gui.SetStatusText("Used hotkey " + i2ws(index)); |
| 1829 | + | g_gui.RefreshView(); |
| 1830 | + | } else if (hk.IsBrush()) { |
| 1831 | + | g_gui.SetDrawingMode(); |
| 1832 | + | |
| 1833 | + | std::string name = hk.GetBrushname(); |
| 1834 | + | Brush* brush = g_brushes.getBrush(name); |
| 1835 | + | if (brush == nullptr) { |
| 1836 | + | g_gui.SetStatusText("Brush \"" + wxstr(name) + "\" not found"); |
| 1837 | + | return; |
| 1838 | + | } |
| 1839 | + | |
| 1840 | + | if (!g_gui.SelectBrush(brush)) { |
| 1841 | + | g_gui.SetStatusText("Brush \"" + wxstr(name) + "\" is not in any palette"); |
| 1842 | + | return; |
| 1843 | + | } |
| 1844 | + | |
| 1845 | + | g_gui.SetStatusText("Used hotkey " + i2ws(index)); |
| 1846 | + | g_gui.RefreshView(); |
| 1847 | + | } else { |
| 1848 | + | g_gui.SetStatusText("Unassigned hotkey " + i2ws(index)); |
| 1849 | + | } |
| 1850 | + | } |
| 1851 | + | break; |
| 1852 | + | } |
| 1853 | + | case 'd': |
| 1854 | + | case 'D': { |
| 1855 | + | keyCode = WXK_CONTROL_D; |
| 1856 | + | break; |
| 1857 | + | } |
| 1858 | + | case 'a': |
| 1859 | + | case 'A': { |
| 1860 | + | bool new_state = !g_settings.getBoolean(Config::USE_AUTOMAGIC); |
| 1861 | + | g_settings.setInteger(Config::USE_AUTOMAGIC, new_state ? 1 : 0); |
| 1862 | + | if (new_state) { |
| 1863 | + | g_gui.SetStatusText("Automagic enabled."); |
| 1864 | + | } else { |
| 1865 | + | g_gui.SetStatusText("Automagic disabled."); |
| 1866 | + | } |
| 1867 | + | break; |
| 1868 | + | } |
| 1869 | + | default: { |
| 1870 | + | event.Skip(); |
| 1871 | + | break; |
| 1872 | + | } |
| 1873 | + | } |
| 1874 | + | } |
| 1875 | + | |
| 1876 | + | void MapCanvas::OnKeyUp(wxKeyEvent& event) { |
| 1877 | + | keyCode = WXK_NONE; |
| 1878 | + | } |
| 1879 | + | |
| 1880 | + | void MapCanvas::OnCopy(wxCommandEvent& WXUNUSED(event)) { |
| 1881 | + | if (g_gui.IsSelectionMode()) { |
| 1882 | + | editor.copybuffer.copy(editor, GetFloor()); |
| 1883 | + | } |
| 1884 | + | } |
| 1885 | + | |
| 1886 | + | void MapCanvas::OnCut(wxCommandEvent& WXUNUSED(event)) { |
| 1887 | + | if (g_gui.IsSelectionMode()) { |
| 1888 | + | editor.copybuffer.cut(editor, GetFloor()); |
| 1889 | + | } |
| 1890 | + | g_gui.RefreshView(); |
| 1891 | + | } |
| 1892 | + | |
| 1893 | + | void MapCanvas::OnPaste(wxCommandEvent& WXUNUSED(event)) { |
| 1894 | + | g_gui.DoPaste(); |
| 1895 | + | g_gui.RefreshView(); |
| 1896 | + | } |
| 1897 | + | |
| 1898 | + | void MapCanvas::OnDelete(wxCommandEvent& WXUNUSED(event)) { |
| 1899 | + | editor.destroySelection(); |
| 1900 | + | g_gui.RefreshView(); |
| 1901 | + | } |
| 1902 | + | |
| 1903 | + | void MapCanvas::OnCopyPosition(wxCommandEvent& WXUNUSED(event)) { |
| 1904 | + | if (editor.selection.size() == 0) { |
| 1905 | + | return; |
| 1906 | + | } |
| 1907 | + | |
| 1908 | + | Position minPos = editor.selection.minPosition(); |
| 1909 | + | Position maxPos = editor.selection.maxPosition(); |
| 1910 | + | |
| 1911 | + | std::ostringstream clip; |
| 1912 | + | if (minPos != maxPos) { |
| 1913 | + | clip << "{"; |
| 1914 | + | clip << "fromx = " << minPos.x << ", "; |
| 1915 | + | clip << "tox = " << maxPos.x << ", "; |
| 1916 | + | clip << "fromy = " << minPos.y << ", "; |
| 1917 | + | clip << "toy = " << maxPos.y << ", "; |
| 1918 | + | if (minPos.z != maxPos.z) { |
| 1919 | + | clip << "fromz = " << minPos.z << ", "; |
| 1920 | + | clip << "toz = " << maxPos.z; |
| 1921 | + | } else { |
| 1922 | + | clip << "z = " << minPos.z; |
| 1923 | + | } |
| 1924 | + | clip << "}"; |
| 1925 | + | } else { |
| 1926 | + | switch (g_settings.getInteger(Config::COPY_POSITION_FORMAT)) { |
| 1927 | + | case 0: |
| 1928 | + | clip << "{x = " << minPos.x << ", y = " << minPos.y << ", z = " << minPos.z << "}"; |
| 1929 | + | break; |
| 1930 | + | case 1: |
| 1931 | + | clip << "{\"x\":" << minPos.x << ",\"y\":" << minPos.y << ",\"z\":" << minPos.z << "}"; |
| 1932 | + | break; |
| 1933 | + | case 2: |
| 1934 | + | clip << minPos.x << ", " << minPos.y << ", " << minPos.z; |
| 1935 | + | break; |
| 1936 | + | case 3: |
| 1937 | + | clip << "(" << minPos.x << ", " << minPos.y << ", " << minPos.z << ")"; |
| 1938 | + | break; |
| 1939 | + | case 4: |
| 1940 | + | clip << "Position(" << minPos.x << ", " << minPos.y << ", " << minPos.z << ")"; |
| 1941 | + | break; |
| 1942 | + | } |
| 1943 | + | } |
| 1944 | + | |
| 1945 | + | if (wxTheClipboard->Open()) { |
| 1946 | + | wxTextDataObject* obj = new wxTextDataObject(); |
| 1947 | + | obj->SetText(wxstr(clip.str())); |
| 1948 | + | wxTheClipboard->SetData(obj); |
| 1949 | + | |
| 1950 | + | wxTheClipboard->Close(); |
| 1951 | + | } |
| 1952 | + | } |
| 1953 | + | |
| 1954 | + | void MapCanvas::OnCopyServerId(wxCommandEvent& WXUNUSED(event)) { |
| 1955 | + | ASSERT(editor.selection.size() == 1); |
| 1956 | + | |
| 1957 | + | if (wxTheClipboard->Open()) { |
| 1958 | + | Tile* tile = editor.selection.getSelectedTile(); |
| 1959 | + | ItemVector selected_items = tile->getSelectedItems(); |
| 1960 | + | ASSERT(selected_items.size() == 1); |
| 1961 | + | |
| 1962 | + | const Item* item = selected_items.front(); |
| 1963 | + | |
| 1964 | + | wxTextDataObject* obj = new wxTextDataObject(); |
| 1965 | + | obj->SetText(i2ws(item->getID())); |
| 1966 | + | wxTheClipboard->SetData(obj); |
| 1967 | + | |
| 1968 | + | wxTheClipboard->Close(); |
| 1969 | + | } |
| 1970 | + | } |
| 1971 | + | |
| 1972 | + | void MapCanvas::OnCopyClientId(wxCommandEvent& WXUNUSED(event)) { |
| 1973 | + | ASSERT(editor.selection.size() == 1); |
| 1974 | + | |
| 1975 | + | if (wxTheClipboard->Open()) { |
| 1976 | + | Tile* tile = editor.selection.getSelectedTile(); |
| 1977 | + | ItemVector selected_items = tile->getSelectedItems(); |
| 1978 | + | ASSERT(selected_items.size() == 1); |
| 1979 | + | |
| 1980 | + | const Item* item = selected_items.front(); |
| 1981 | + | |
| 1982 | + | wxTextDataObject* obj = new wxTextDataObject(); |
| 1983 | + | obj->SetText(i2ws(item->getClientID())); |
| 1984 | + | wxTheClipboard->SetData(obj); |
| 1985 | + | |
| 1986 | + | wxTheClipboard->Close(); |
| 1987 | + | } |
| 1988 | + | } |
| 1989 | + | |
| 1990 | + | void MapCanvas::OnCopyName(wxCommandEvent& WXUNUSED(event)) { |
| 1991 | + | ASSERT(editor.selection.size() == 1); |
| 1992 | + | |
| 1993 | + | if (wxTheClipboard->Open()) { |
| 1994 | + | Tile* tile = editor.selection.getSelectedTile(); |
| 1995 | + | ItemVector selected_items = tile->getSelectedItems(); |
| 1996 | + | ASSERT(selected_items.size() == 1); |
| 1997 | + | |
| 1998 | + | const Item* item = selected_items.front(); |
| 1999 | + | |
| 2000 | + | wxTextDataObject* obj = new wxTextDataObject(); |
| 2001 | + | obj->SetText(wxstr(item->getName())); |
| 2002 | + | wxTheClipboard->SetData(obj); |
| 2003 | + | |
| 2004 | + | wxTheClipboard->Close(); |
| 2005 | + | } |
| 2006 | + | } |
| 2007 | + | |
| 2008 | + | void MapCanvas::OnBrowseTile(wxCommandEvent& WXUNUSED(event)) { |
| 2009 | + | if (editor.selection.size() != 1) { |
| 2010 | + | return; |
| 2011 | + | } |
| 2012 | + | |
| 2013 | + | Tile* tile = editor.selection.getSelectedTile(); |
| 2014 | + | if (!tile) { |
| 2015 | + | return; |
| 2016 | + | } |
| 2017 | + | ASSERT(tile->isSelected()); |
| 2018 | + | |
| 2019 | + | #ifdef __WXDEBUG__ |
| 2020 | + | if (tile->ground) { |
| 2021 | + | printf("DEBUG: Original tile %p has ground %p before deepCopy\n", tile, tile->ground); |
| 2022 | + | } |
| 2023 | + | #endif |
| 2024 | + | |
| 2025 | + | Tile* new_tile = tile->deepCopy(editor.map); |
| 2026 | + | |
| 2027 | + | #ifdef __WXDEBUG__ |
| 2028 | + | if (new_tile->ground) { |
| 2029 | + | printf("DEBUG: New tile %p has ground %p after deepCopy\n", new_tile, new_tile->ground); |
| 2030 | + | } |
| 2031 | + | #endif |
| 2032 | + | |
| 2033 | + | wxDialog* w = new BrowseTileWindow(g_gui.root, new_tile, wxPoint(cursor_x, cursor_y)); |
| 2034 | + | |
| 2035 | + | int ret = w->ShowModal(); |
| 2036 | + | if (ret != 0) { |
| 2037 | + | Action* action = editor.actionQueue->createAction(ACTION_DELETE_TILES); |
| 2038 | + | action->addChange(newd Change(new_tile)); |
| 2039 | + | editor.addAction(action); |
| 2040 | + | } else { |
| 2041 | + | // Cancel |
| 2042 | + | delete new_tile; |
| 2043 | + | } |
| 2044 | + | |
| 2045 | + | w->Destroy(); |
| 2046 | + | } |
| 2047 | + | |
| 2048 | + | void MapCanvas::OnRotateItem(wxCommandEvent& WXUNUSED(event)) { |
| 2049 | + | Tile* tile = editor.selection.getSelectedTile(); |
| 2050 | + | |
| 2051 | + | Action* action = editor.actionQueue->createAction(ACTION_ROTATE_ITEM); |
| 2052 | + | |
| 2053 | + | Tile* new_tile = tile->deepCopy(editor.map); |
| 2054 | + | |
| 2055 | + | ItemVector selected_items = new_tile->getSelectedItems(); |
| 2056 | + | ASSERT(selected_items.size() > 0); |
| 2057 | + | |
| 2058 | + | selected_items.front()->doRotate(); |
| 2059 | + | |
| 2060 | + | action->addChange(newd Change(new_tile)); |
| 2061 | + | |
| 2062 | + | editor.actionQueue->addAction(action); |
| 2063 | + | g_gui.RefreshView(); |
| 2064 | + | } |
| 2065 | + | |
| 2066 | + | void MapCanvas::OnGotoDestination(wxCommandEvent& WXUNUSED(event)) { |
| 2067 | + | Tile* tile = editor.selection.getSelectedTile(); |
| 2068 | + | ItemVector selected_items = tile->getSelectedItems(); |
| 2069 | + | ASSERT(selected_items.size() > 0); |
| 2070 | + | Teleport* teleport = dynamic_cast<Teleport*>(selected_items.front()); |
| 2071 | + | if (teleport) { |
| 2072 | + | Position pos = teleport->getDestination(); |
| 2073 | + | g_gui.SetScreenCenterPosition(pos); |
| 2074 | + | } |
| 2075 | + | } |
| 2076 | + | |
| 2077 | + | void MapCanvas::OnSwitchDoor(wxCommandEvent& WXUNUSED(event)) { |
| 2078 | + | Tile* tile = editor.selection.getSelectedTile(); |
| 2079 | + | |
| 2080 | + | Action* action = editor.actionQueue->createAction(ACTION_SWITCHDOOR); |
| 2081 | + | |
| 2082 | + | Tile* new_tile = tile->deepCopy(editor.map); |
| 2083 | + | |
| 2084 | + | ItemVector selected_items = new_tile->getSelectedItems(); |
| 2085 | + | ASSERT(selected_items.size() > 0); |
| 2086 | + | |
| 2087 | + | DoorBrush::switchDoor(selected_items.front()); |
| 2088 | + | |
| 2089 | + | action->addChange(newd Change(new_tile)); |
| 2090 | + | |
| 2091 | + | editor.actionQueue->addAction(action); |
| 2092 | + | g_gui.RefreshView(); |
| 2093 | + | } |
| 2094 | + | |
| 2095 | + | void MapCanvas::OnSelectRAWBrush(wxCommandEvent& WXUNUSED(event)) { |
| 2096 | + | if (editor.selection.size() != 1) { |
| 2097 | + | return; |
| 2098 | + | } |
| 2099 | + | Tile* tile = editor.selection.getSelectedTile(); |
| 2100 | + | if (!tile) { |
| 2101 | + | return; |
| 2102 | + | } |
| 2103 | + | Item* item = tile->getTopSelectedItem(); |
| 2104 | + | |
| 2105 | + | if (item && item->getRAWBrush()) { |
| 2106 | + | g_gui.SelectBrush(item->getRAWBrush(), TILESET_RAW); |
| 2107 | + | } |
| 2108 | + | } |
| 2109 | + | |
| 2110 | + | void MapCanvas::OnSelectGroundBrush(wxCommandEvent& WXUNUSED(event)) { |
| 2111 | + | if (editor.selection.size() != 1) { |
| 2112 | + | return; |
| 2113 | + | } |
| 2114 | + | Tile* tile = editor.selection.getSelectedTile(); |
| 2115 | + | if (!tile) { |
| 2116 | + | return; |
| 2117 | + | } |
| 2118 | + | GroundBrush* bb = tile->getGroundBrush(); |
| 2119 | + | |
| 2120 | + | if (bb) { |
| 2121 | + | g_gui.SelectBrush(bb, TILESET_TERRAIN); |
| 2122 | + | } |
| 2123 | + | } |
| 2124 | + | |
| 2125 | + | void MapCanvas::OnSelectDoodadBrush(wxCommandEvent& WXUNUSED(event)) { |
| 2126 | + | if (editor.selection.size() != 1) { |
| 2127 | + | return; |
| 2128 | + | } |
| 2129 | + | Tile* tile = editor.selection.getSelectedTile(); |
| 2130 | + | if (!tile) { |
| 2131 | + | return; |
| 2132 | + | } |
| 2133 | + | Item* item = tile->getTopSelectedItem(); |
| 2134 | + | |
| 2135 | + | if (item) { |
| 2136 | + | g_gui.SelectBrush(item->getDoodadBrush(), TILESET_DOODAD); |
| 2137 | + | } |
| 2138 | + | } |
| 2139 | + | |
| 2140 | + | void MapCanvas::OnSelectDoorBrush(wxCommandEvent& WXUNUSED(event)) { |
| 2141 | + | if (editor.selection.size() != 1) { |
| 2142 | + | return; |
| 2143 | + | } |
| 2144 | + | Tile* tile = editor.selection.getSelectedTile(); |
| 2145 | + | if (!tile) { |
| 2146 | + | return; |
| 2147 | + | } |
| 2148 | + | Item* item = tile->getTopSelectedItem(); |
| 2149 | + | |
| 2150 | + | if (item) { |
| 2151 | + | g_gui.SelectBrush(item->getDoorBrush(), TILESET_TERRAIN); |
| 2152 | + | } |
| 2153 | + | } |
| 2154 | + | |
| 2155 | + | void MapCanvas::OnSelectWallBrush(wxCommandEvent& WXUNUSED(event)) { |
| 2156 | + | if (editor.selection.size() != 1) { |
| 2157 | + | return; |
| 2158 | + | } |
| 2159 | + | Tile* tile = editor.selection.getSelectedTile(); |
| 2160 | + | if (!tile) { |
| 2161 | + | return; |
| 2162 | + | } |
| 2163 | + | Item* wall = tile->getWall(); |
| 2164 | + | WallBrush* wb = wall->getWallBrush(); |
| 2165 | + | |
| 2166 | + | if (wb) { |
| 2167 | + | g_gui.SelectBrush(wb, TILESET_TERRAIN); |
| 2168 | + | } |
| 2169 | + | } |
| 2170 | + | |
| 2171 | + | void MapCanvas::OnSelectCarpetBrush(wxCommandEvent& WXUNUSED(event)) { |
| 2172 | + | if (editor.selection.size() != 1) { |
| 2173 | + | return; |
| 2174 | + | } |
| 2175 | + | Tile* tile = editor.selection.getSelectedTile(); |
| 2176 | + | if (!tile) { |
| 2177 | + | return; |
| 2178 | + | } |
| 2179 | + | Item* wall = tile->getCarpet(); |
| 2180 | + | CarpetBrush* cb = wall->getCarpetBrush(); |
| 2181 | + | |
| 2182 | + | if (cb) { |
| 2183 | + | g_gui.SelectBrush(cb); |
| 2184 | + | } |
| 2185 | + | } |
| 2186 | + | |
| 2187 | + | void MapCanvas::OnSelectTableBrush(wxCommandEvent& WXUNUSED(event)) { |
| 2188 | + | if (editor.selection.size() != 1) { |
| 2189 | + | return; |
| 2190 | + | } |
| 2191 | + | Tile* tile = editor.selection.getSelectedTile(); |
| 2192 | + | if (!tile) { |
| 2193 | + | return; |
| 2194 | + | } |
| 2195 | + | Item* wall = tile->getTable(); |
| 2196 | + | TableBrush* tb = wall->getTableBrush(); |
| 2197 | + | |
| 2198 | + | if (tb) { |
| 2199 | + | g_gui.SelectBrush(tb); |
| 2200 | + | } |
| 2201 | + | } |
| 2202 | + | |
| 2203 | + | void MapCanvas::OnSelectHouseBrush(wxCommandEvent& WXUNUSED(event)) { |
| 2204 | + | Tile* tile = editor.selection.getSelectedTile(); |
| 2205 | + | if (!tile) { |
| 2206 | + | return; |
| 2207 | + | } |
| 2208 | + | |
| 2209 | + | if (tile->isHouseTile()) { |
| 2210 | + | House* house = editor.map.houses.getHouse(tile->getHouseID()); |
| 2211 | + | if (house) { |
| 2212 | + | g_gui.house_brush->setHouse(house); |
| 2213 | + | g_gui.SelectBrush(g_gui.house_brush, TILESET_HOUSE); |
| 2214 | + | } |
| 2215 | + | } |
| 2216 | + | } |
| 2217 | + | |
| 2218 | + | void MapCanvas::OnSelectCollectionBrush(wxCommandEvent& WXUNUSED(event)) { |
| 2219 | + | Tile* tile = editor.selection.getSelectedTile(); |
| 2220 | + | if (!tile) { |
| 2221 | + | return; |
| 2222 | + | } |
| 2223 | + | |
| 2224 | + | for (auto* item : tile->items) { |
| 2225 | + | if (item->isWall()) { |
| 2226 | + | WallBrush* wb = item->getWallBrush(); |
| 2227 | + | if (wb && wb->visibleInPalette() && wb->hasCollection()) { |
| 2228 | + | g_gui.SelectBrush(wb, TILESET_COLLECTION); |
| 2229 | + | return; |
| 2230 | + | } |
| 2231 | + | } |
| 2232 | + | if (item->isTable()) { |
| 2233 | + | TableBrush* tb = item->getTableBrush(); |
| 2234 | + | if (tb && tb->visibleInPalette() && tb->hasCollection()) { |
| 2235 | + | g_gui.SelectBrush(tb, TILESET_COLLECTION); |
| 2236 | + | return; |
| 2237 | + | } |
| 2238 | + | } |
| 2239 | + | if (item->isCarpet()) { |
| 2240 | + | CarpetBrush* cb = item->getCarpetBrush(); |
| 2241 | + | if (cb && cb->visibleInPalette() && cb->hasCollection()) { |
| 2242 | + | g_gui.SelectBrush(cb, TILESET_COLLECTION); |
| 2243 | + | return; |
| 2244 | + | } |
| 2245 | + | } |
| 2246 | + | if (Brush* db = item->getDoodadBrush()) { |
| 2247 | + | if (db && db->visibleInPalette() && db->hasCollection()) { |
| 2248 | + | g_gui.SelectBrush(db, TILESET_COLLECTION); |
| 2249 | + | return; |
| 2250 | + | } |
| 2251 | + | } |
| 2252 | + | if (item->isSelected()) { |
| 2253 | + | RAWBrush* rb = item->getRAWBrush(); |
| 2254 | + | if (rb && rb->hasCollection()) { |
| 2255 | + | g_gui.SelectBrush(rb, TILESET_COLLECTION); |
| 2256 | + | return; |
| 2257 | + | } |
| 2258 | + | } |
| 2259 | + | } |
| 2260 | + | GroundBrush* gb = tile->getGroundBrush(); |
| 2261 | + | if (gb && gb->visibleInPalette() && gb->hasCollection()) { |
| 2262 | + | g_gui.SelectBrush(gb, TILESET_COLLECTION); |
| 2263 | + | return; |
| 2264 | + | } |
| 2265 | + | } |
| 2266 | + | |
| 2267 | + | void MapCanvas::OnSelectCreatureBrush(wxCommandEvent& WXUNUSED(event)) { |
| 2268 | + | Tile* tile = editor.selection.getSelectedTile(); |
| 2269 | + | if (!tile) { |
| 2270 | + | return; |
| 2271 | + | } |
| 2272 | + | |
| 2273 | + | if (tile->creature) { |
| 2274 | + | g_gui.SelectBrush(tile->creature->getBrush(), TILESET_CREATURE); |
| 2275 | + | } |
| 2276 | + | } |
| 2277 | + | |
| 2278 | + | void MapCanvas::OnSelectSpawnBrush(wxCommandEvent& WXUNUSED(event)) { |
| 2279 | + | g_gui.SelectBrush(g_gui.spawn_brush, TILESET_CREATURE); |
| 2280 | + | } |
| 2281 | + | |
| 2282 | + | void MapCanvas::OnSelectMoveTo(wxCommandEvent& WXUNUSED(event)) { |
| 2283 | + | if (editor.selection.size() != 1) { |
| 2284 | + | return; |
| 2285 | + | } |
| 2286 | + | |
| 2287 | + | Tile* tile = editor.selection.getSelectedTile(); |
| 2288 | + | if (!tile) { |
| 2289 | + | return; |
| 2290 | + | } |
| 2291 | + | ASSERT(tile->isSelected()); |
| 2292 | + | Tile* new_tile = tile->deepCopy(editor.map); |
| 2293 | + | |
| 2294 | + | wxDialog* w = nullptr; |
| 2295 | + | |
| 2296 | + | ItemVector selected_items = new_tile->getSelectedItems(); |
| 2297 | + | |
| 2298 | + | Item* item = nullptr; |
| 2299 | + | int count = 0; |
| 2300 | + | for (ItemVector::iterator it = selected_items.begin(); it != selected_items.end(); ++it) { |
| 2301 | + | ++count; |
| 2302 | + | if ((*it)->isSelected()) { |
| 2303 | + | item = *it; |
| 2304 | + | } |
| 2305 | + | } |
| 2306 | + | |
| 2307 | + | if (item) { |
| 2308 | + | w = newd TilesetWindow(g_gui.root, &editor.map, new_tile, item); |
| 2309 | + | } else { |
| 2310 | + | return; |
| 2311 | + | } |
| 2312 | + | |
| 2313 | + | int ret = w->ShowModal(); |
| 2314 | + | if (ret != 0) { |
| 2315 | + | Action* action = editor.actionQueue->createAction(ACTION_CHANGE_PROPERTIES); |
| 2316 | + | action->addChange(newd Change(new_tile)); |
| 2317 | + | editor.addAction(action); |
| 2318 | + | |
| 2319 | + | g_gui.RebuildPalettes(); |
| 2320 | + | } else { |
| 2321 | + | // Cancel! |
| 2322 | + | delete new_tile; |
| 2323 | + | } |
| 2324 | + | w->Destroy(); |
| 2325 | + | } |
| 2326 | + | |
| 2327 | + | void MapCanvas::OnProperties(wxCommandEvent& WXUNUSED(event)) { |
| 2328 | + | if (editor.selection.size() != 1) { |
| 2329 | + | return; |
| 2330 | + | } |
| 2331 | + | |
| 2332 | + | Tile* tile = editor.selection.getSelectedTile(); |
| 2333 | + | if (!tile) { |
| 2334 | + | return; |
| 2335 | + | } |
| 2336 | + | ASSERT(tile->isSelected()); |
| 2337 | + | Tile* new_tile = tile->deepCopy(editor.map); |
| 2338 | + | |
| 2339 | + | wxDialog* w = nullptr; |
| 2340 | + | |
| 2341 | + | if (new_tile->spawn && g_settings.getInteger(Config::SHOW_SPAWNS)) { |
| 2342 | + | w = newd OldPropertiesWindow(g_gui.root, &editor.map, new_tile, new_tile->spawn); |
| 2343 | + | } else if (new_tile->creature && g_settings.getInteger(Config::SHOW_CREATURES)) { |
| 2344 | + | w = newd OldPropertiesWindow(g_gui.root, &editor.map, new_tile, new_tile->creature); |
| 2345 | + | } else { |
| 2346 | + | ItemVector selected_items = new_tile->getSelectedItems(); |
| 2347 | + | |
| 2348 | + | Item* item = nullptr; |
| 2349 | + | int count = 0; |
| 2350 | + | for (ItemVector::iterator it = selected_items.begin(); it != selected_items.end(); ++it) { |
| 2351 | + | ++count; |
| 2352 | + | if ((*it)->isSelected()) { |
| 2353 | + | item = *it; |
| 2354 | + | } |
| 2355 | + | } |
| 2356 | + | |
| 2357 | + | if (item) { |
| 2358 | + | if (editor.map.getVersion().otbm >= MAP_OTBM_4) { |
| 2359 | + | w = newd PropertiesWindow(g_gui.root, &editor.map, new_tile, item); |
| 2360 | + | } else { |
| 2361 | + | w = newd OldPropertiesWindow(g_gui.root, &editor.map, new_tile, item); |
| 2362 | + | } |
| 2363 | + | } else { |
| 2364 | + | return; |
| 2365 | + | } |
| 2366 | + | } |
| 2367 | + | |
| 2368 | + | int ret = w->ShowModal(); |
| 2369 | + | if (ret != 0) { |
| 2370 | + | Action* action = editor.actionQueue->createAction(ACTION_CHANGE_PROPERTIES); |
| 2371 | + | action->addChange(newd Change(new_tile)); |
| 2372 | + | editor.addAction(action); |
| 2373 | + | } else { |
| 2374 | + | // Cancel! |
| 2375 | + | delete new_tile; |
| 2376 | + | } |
| 2377 | + | w->Destroy(); |
| 2378 | + | } |
| 2379 | + | |
| 2380 | + | void MapCanvas::ChangeFloor(int new_floor) { |
| 2381 | + | ASSERT(new_floor >= 0 || new_floor < MAP_LAYERS); |
| 2382 | + | int old_floor = floor; |
| 2383 | + | floor = new_floor; |
| 2384 | + | |
| 2385 | + | // Check if crossing between underground and ground level (but no longer clearing cache) |
| 2386 | + | bool crossing_ground_level = (old_floor > GROUND_LAYER && new_floor <= GROUND_LAYER) || |
| 2387 | + | (old_floor <= GROUND_LAYER && new_floor > GROUND_LAYER); |
| 2388 | + | |
| 2389 | + | if (old_floor != new_floor) { |
| 2390 | + | UpdatePositionStatus(); |
| 2391 | + | g_gui.root->UpdateFloorMenu(); |
| 2392 | + | |
| 2393 | + | // No longer clearing cache or updating minimap on floor changes |
| 2394 | + | // This allows the minimap to maintain its cache across floor changes |
| 2395 | + | // for better performance |
| 2396 | + | } |
| 2397 | + | Refresh(); |
| 2398 | + | } |
| 2399 | + | |
| 2400 | + | void MapCanvas::EnterDrawingMode() { |
| 2401 | + | dragging = false; |
| 2402 | + | boundbox_selection = false; |
| 2403 | + | EndPasting(); |
| 2404 | + | Refresh(); |
| 2405 | + | } |
| 2406 | + | |
| 2407 | + | void MapCanvas::EnterSelectionMode() { |
| 2408 | + | drawing = false; |
| 2409 | + | dragging_draw = false; |
| 2410 | + | replace_dragging = false; |
| 2411 | + | editor.replace_brush = nullptr; |
| 2412 | + | Refresh(); |
| 2413 | + | } |
| 2414 | + | |
| 2415 | + | bool MapCanvas::isPasting() const { |
| 2416 | + | return g_gui.IsPasting(); |
| 2417 | + | } |
| 2418 | + | |
| 2419 | + | void MapCanvas::StartPasting() { |
| 2420 | + | g_gui.StartPasting(); |
| 2421 | + | } |
| 2422 | + | |
| 2423 | + | void MapCanvas::EndPasting() { |
| 2424 | + | g_gui.EndPasting(); |
| 2425 | + | } |
| 2426 | + | |
| 2427 | + | void MapCanvas::Reset() { |
| 2428 | + | cursor_x = 0; |
| 2429 | + | cursor_y = 0; |
| 2430 | + | |
| 2431 | + | zoom = 1.0; |
| 2432 | + | floor = GROUND_LAYER; |
| 2433 | + | |
| 2434 | + | dragging = false; |
| 2435 | + | boundbox_selection = false; |
| 2436 | + | screendragging = false; |
| 2437 | + | drawing = false; |
| 2438 | + | dragging_draw = false; |
| 2439 | + | |
| 2440 | + | replace_dragging = false; |
| 2441 | + | editor.replace_brush = nullptr; |
| 2442 | + | |
| 2443 | + | drag_start_x = -1; |
| 2444 | + | drag_start_y = -1; |
| 2445 | + | drag_start_z = -1; |
| 2446 | + | |
| 2447 | + | last_click_map_x = -1; |
| 2448 | + | last_click_map_y = -1; |
| 2449 | + | last_click_map_z = -1; |
| 2450 | + | |
| 2451 | + | last_mmb_click_x = -1; |
| 2452 | + | last_mmb_click_y = -1; |
| 2453 | + | |
| 2454 | + | editor.selection.clear(); |
| 2455 | + | editor.actionQueue->clear(); |
| 2456 | + | } |
| 2457 | + | |
| 2458 | + | MapPopupMenu::MapPopupMenu(Editor& editor) : |
| 2459 | + | wxMenu(""), editor(editor) { |
| 2460 | + | //// |
| 2461 | + | } |
| 2462 | + | |
| 2463 | + | MapPopupMenu::~MapPopupMenu() { |
| 2464 | + | //// |
| 2465 | + | } |
| 2466 | + | |
| 2467 | + | void MapPopupMenu::Update() { |
| 2468 | + | // Clear the menu of all items |
| 2469 | + | while (GetMenuItemCount() != 0) { |
| 2470 | + | wxMenuItem* m_item = FindItemByPosition(0); |
| 2471 | + | // If you add a submenu, this won't delete it. |
| 2472 | + | Delete(m_item); |
| 2473 | + | } |
| 2474 | + | |
| 2475 | + | bool anything_selected = editor.selection.size() != 0; |
| 2476 | + | |
| 2477 | + | wxMenuItem* cutItem = Append(MAP_POPUP_MENU_CUT, "&Cut\tCTRL+X", "Cut out all selected items"); |
| 2478 | + | cutItem->Enable(anything_selected); |
| 2479 | + | |
| 2480 | + | wxMenuItem* copyItem = Append(MAP_POPUP_MENU_COPY, "&Copy\tCTRL+C", "Copy all selected items"); |
| 2481 | + | copyItem->Enable(anything_selected); |
| 2482 | + | |
| 2483 | + | wxMenuItem* copyPositionItem = Append(MAP_POPUP_MENU_COPY_POSITION, "&Copy Position", "Copy the position as a lua table"); |
| 2484 | + | copyPositionItem->Enable(anything_selected); |
| 2485 | + | |
| 2486 | + | wxMenuItem* pasteItem = Append(MAP_POPUP_MENU_PASTE, "&Paste\tCTRL+V", "Paste items in the copybuffer here"); |
| 2487 | + | pasteItem->Enable(editor.copybuffer.canPaste()); |
| 2488 | + | |
| 2489 | + | wxMenuItem* deleteItem = Append(MAP_POPUP_MENU_DELETE, "&Delete\tDEL", "Removes all seleceted items"); |
| 2490 | + | deleteItem->Enable(anything_selected); |
| 2491 | + | |
| 2492 | + | // Add the Fill option |
| 2493 | + | wxMenuItem* fillItem = Append(MAP_POPUP_MENU_FILL, "&Fill Area", "Fill enclosed area with current brush"); |
| 2494 | + | fillItem->Enable(g_gui.GetCurrentBrush() != nullptr); |
| 2495 | + | |
| 2496 | + | // Add the Generate Island option |
| 2497 | + | Append(MAP_POPUP_MENU_GENERATE_ISLAND, "Generate &Island", "Generate an island at this location"); |
| 2498 | + | |
| 2499 | + | // Add the Create House option |
| 2500 | + | Append(MAP_POPUP_MENU_CREATE_HOUSE, "Create &House", "Auto-detect house boundaries based on walls and doors"); |
| 2501 | + | |
| 2502 | + | // Add the Find Similar option |
| 2503 | + | wxMenuItem* findSimilarItem = Append(MAP_POPUP_MENU_FIND_SIMILAR_ITEMS, "Find &Similar Items", "Find similar items on the map"); |
| 2504 | + | findSimilarItem->Enable(anything_selected); |
| 2505 | + | |
| 2506 | + | wxMenuItem* selectionToDoodadItem = Append(MAP_POPUP_MENU_SELECTION_TO_DOODAD, "&Selection to Doodad", "Create a doodad brush from the selected items"); |
| 2507 | + | selectionToDoodadItem->Enable(anything_selected); |
| 2508 | + | |
| 2509 | + | if (anything_selected) { |
| 2510 | + | if (editor.selection.size() == 1) { |
| 2511 | + | Tile* tile = editor.selection.getSelectedTile(); |
| 2512 | + | ItemVector selected_items = tile->getSelectedItems(); |
| 2513 | + | |
| 2514 | + | bool hasWall = false; |
| 2515 | + | bool hasCarpet = false; |
| 2516 | + | bool hasTable = false; |
| 2517 | + | bool hasCollection = false; |
| 2518 | + | Item* topItem = nullptr; |
| 2519 | + | //this is where we have info about whats selected |
| 2520 | + | Item* topSelectedItem = (selected_items.size() == 1 ? selected_items.back() : nullptr); |
| 2521 | + | // With a valid single selected item, trigger auto-select RAW if enabled. |
| 2522 | + | if (g_settings.getBoolean(Config::AUTO_SELECT_RAW_ON_RIGHTCLICK) && |
| 2523 | + | topSelectedItem && topSelectedItem->getRAWBrush()) { |
| 2524 | + | // Call the existing handler to change the current brush to RAW. |
| 2525 | + | // This reuses the logic in OnSelectRAWBrush and maintains consistent behavior. |
| 2526 | + | if (editor.selection.size() == 1) { |
| 2527 | + | Tile* tile = editor.selection.getSelectedTile(); |
| 2528 | + | if (tile) { |
| 2529 | + | Item* item = tile->getTopSelectedItem(); |
| 2530 | + | if (item && item->getRAWBrush()) { |
| 2531 | + | g_gui.SelectBrush(item->getRAWBrush(), TILESET_RAW); |
| 2532 | + | } |
| 2533 | + | } |
| 2534 | + | } |
| 2535 | + | } |
| 2536 | + | |
| 2537 | + | Creature* topCreature = tile->creature; |
| 2538 | + | Spawn* topSpawn = tile->spawn; |
| 2539 | + | |
| 2540 | + | for (auto* item : tile->items) { |
| 2541 | + | if (item->isWall()) { |
| 2542 | + | Brush* wb = item->getWallBrush(); |
| 2543 | + | if (wb && wb->visibleInPalette()) { |
| 2544 | + | hasWall = true; |
| 2545 | + | hasCollection = hasCollection || wb->hasCollection(); |
| 2546 | + | } |
| 2547 | + | } |
| 2548 | + | if (item->isTable()) { |
| 2549 | + | Brush* tb = item->getTableBrush(); |
| 2550 | + | if (tb && tb->visibleInPalette()) { |
| 2551 | + | hasTable = true; |
| 2552 | + | hasCollection = hasCollection || tb->hasCollection(); |
| 2553 | + | } |
| 2554 | + | } |
| 2555 | + | if (item->isCarpet()) { |
| 2556 | + | Brush* cb = item->getCarpetBrush(); |
| 2557 | + | if (cb && cb->visibleInPalette()) { |
| 2558 | + | hasCarpet = true; |
| 2559 | + | hasCollection = hasCollection || cb->hasCollection(); |
| 2560 | + | } |
| 2561 | + | } |
| 2562 | + | if (Brush* db = item->getDoodadBrush()) { |
| 2563 | + | hasCollection = hasCollection || db->hasCollection(); |
| 2564 | + | } |
| 2565 | + | if (item->isSelected()) { |
| 2566 | + | topItem = item; |
| 2567 | + | } |
| 2568 | + | } |
| 2569 | + | if (!topItem) { |
| 2570 | + | topItem = tile->ground; |
| 2571 | + | } |
| 2572 | + | |
| 2573 | + | AppendSeparator(); |
| 2574 | + | |
| 2575 | + | if (topSelectedItem) { |
| 2576 | + | Append(MAP_POPUP_MENU_COPY_SERVER_ID, "Copy Item Server Id", "Copy the server id of this item"); |
| 2577 | + | Append(MAP_POPUP_MENU_COPY_CLIENT_ID, "Copy Item Client Id", "Copy the client id of this item"); |
| 2578 | + | Append(MAP_POPUP_MENU_COPY_NAME, "Copy Item Name", "Copy the name of this item"); |
| 2579 | + | AppendSeparator(); |
| 2580 | + | } |
| 2581 | + | |
| 2582 | + | if (topSelectedItem || topCreature || topItem) { |
| 2583 | + | Teleport* teleport = dynamic_cast<Teleport*>(topSelectedItem); |
| 2584 | + | if (topSelectedItem && (topSelectedItem->isBrushDoor() || topSelectedItem->isRoteable() || teleport)) { |
| 2585 | + | |
| 2586 | + | if (topSelectedItem->isRoteable()) { |
| 2587 | + | Append(MAP_POPUP_MENU_ROTATE, "&Rotate item", "Rotate this item"); |
| 2588 | + | } |
| 2589 | + | |
| 2590 | + | if (teleport && teleport->hasDestination()) { |
| 2591 | + | Append(MAP_POPUP_MENU_GOTO, "&Go To Destination", "Go to the destination of this teleport"); |
| 2592 | + | } |
| 2593 | + | |
| 2594 | + | if (topSelectedItem->isDoor()) { |
| 2595 | + | if (topSelectedItem->isOpen()) { |
| 2596 | + | Append(MAP_POPUP_MENU_SWITCH_DOOR, "&Close door", "Close this door"); |
| 2597 | + | } else { |
| 2598 | + | Append(MAP_POPUP_MENU_SWITCH_DOOR, "&Open door", "Open this door"); |
| 2599 | + | } |
| 2600 | + | AppendSeparator(); |
| 2601 | + | } |
| 2602 | + | } |
| 2603 | + | |
| 2604 | + | if (topCreature) { |
| 2605 | + | Append(MAP_POPUP_MENU_SELECT_CREATURE_BRUSH, "Select Creature", "Uses the current creature as a creature brush"); |
| 2606 | + | } |
| 2607 | + | |
| 2608 | + | if (topSpawn) { |
| 2609 | + | Append(MAP_POPUP_MENU_SELECT_SPAWN_BRUSH, "Select Spawn", "Select the spawn brush"); |
| 2610 | + | } |
| 2611 | + | |
| 2612 | + | Append(MAP_POPUP_MENU_SELECT_RAW_BRUSH, "Select RAW", "Uses the top item as a RAW brush"); |
| 2613 | + | |
| 2614 | + | if (g_settings.getBoolean(Config::SHOW_TILESET_EDITOR)) { |
| 2615 | + | Append(MAP_POPUP_MENU_MOVE_TO_TILESET, "Move To Tileset", "Move this item to any tileset"); |
| 2616 | + | } |
| 2617 | + | |
| 2618 | + | if (hasWall) { |
| 2619 | + | Append(MAP_POPUP_MENU_SELECT_WALL_BRUSH, "Select Wallbrush", "Uses the current item as a wallbrush"); |
| 2620 | + | } |
| 2621 | + | |
| 2622 | + | if (hasCarpet) { |
| 2623 | + | Append(MAP_POPUP_MENU_SELECT_CARPET_BRUSH, "Select Carpetbrush", "Uses the current item as a carpetbrush"); |
| 2624 | + | } |
| 2625 | + | |
| 2626 | + | if (hasTable) { |
| 2627 | + | Append(MAP_POPUP_MENU_SELECT_TABLE_BRUSH, "Select Tablebrush", "Uses the current item as a tablebrush"); |
| 2628 | + | } |
| 2629 | + | |
| 2630 | + | if (topSelectedItem && topSelectedItem->getDoodadBrush() && topSelectedItem->getDoodadBrush()->visibleInPalette()) { |
| 2631 | + | Append(MAP_POPUP_MENU_SELECT_DOODAD_BRUSH, "Select Doodadbrush", "Use this doodad brush"); |
| 2632 | + | } |
| 2633 | + | |
| 2634 | + | if (topSelectedItem && topSelectedItem->isBrushDoor() && topSelectedItem->getDoorBrush()) { |
| 2635 | + | Append(MAP_POPUP_MENU_SELECT_DOOR_BRUSH, "Select Doorbrush", "Use this door brush"); |
| 2636 | + | } |
| 2637 | + | |
| 2638 | + | if (tile->hasGround() && tile->getGroundBrush() && tile->getGroundBrush()->visibleInPalette()) { |
| 2639 | + | Append(MAP_POPUP_MENU_SELECT_GROUND_BRUSH, "Select Groundbrush", "Uses the current item as a groundbrush"); |
| 2640 | + | } |
| 2641 | + | |
| 2642 | + | if (hasCollection || topSelectedItem && topSelectedItem->hasCollectionBrush() || tile->getGroundBrush() && tile->getGroundBrush()->hasCollection()) { |
| 2643 | + | Append(MAP_POPUP_MENU_SELECT_COLLECTION_BRUSH, "Select Collection", "Use this collection"); |
| 2644 | + | } |
| 2645 | + | |
| 2646 | + | if (tile->isHouseTile()) { |
| 2647 | + | Append(MAP_POPUP_MENU_SELECT_HOUSE_BRUSH, "Select House", "Draw with the house on this tile."); |
| 2648 | + | } |
| 2649 | + | |
| 2650 | + | AppendSeparator(); |
| 2651 | + | |
| 2652 | + | Append(MAP_POPUP_MENU_PROPERTIES, "&Properties", "Properties for the current object"); |
| 2653 | + | } else { |
| 2654 | + | |
| 2655 | + | if (topCreature) { |
| 2656 | + | Append(MAP_POPUP_MENU_SELECT_CREATURE_BRUSH, "Select Creature", "Uses the current creature as a creature brush"); |
| 2657 | + | } |
| 2658 | + | |
| 2659 | + | if (topSpawn) { |
| 2660 | + | Append(MAP_POPUP_MENU_SELECT_SPAWN_BRUSH, "Select Spawn", "Select the spawn brush"); |
| 2661 | + | } |
| 2662 | + | |
| 2663 | + | Append(MAP_POPUP_MENU_SELECT_RAW_BRUSH, "Select RAW", "Uses the top item as a RAW brush"); |
| 2664 | + | if (hasWall) { |
| 2665 | + | Append(MAP_POPUP_MENU_SELECT_WALL_BRUSH, "Select Wallbrush", "Uses the current item as a wallbrush"); |
| 2666 | + | } |
| 2667 | + | if (tile->hasGround() && tile->getGroundBrush() && tile->getGroundBrush()->visibleInPalette()) { |
| 2668 | + | Append(MAP_POPUP_MENU_SELECT_GROUND_BRUSH, "Select Groundbrush", "Uses the current tile as a groundbrush"); |
| 2669 | + | } |
| 2670 | + | |
| 2671 | + | if (hasCollection || tile->getGroundBrush() && tile->getGroundBrush()->hasCollection()) { |
| 2672 | + | Append(MAP_POPUP_MENU_SELECT_COLLECTION_BRUSH, "Select Collection", "Use this collection"); |
| 2673 | + | } |
| 2674 | + | |
| 2675 | + | if (tile->isHouseTile()) { |
| 2676 | + | Append(MAP_POPUP_MENU_SELECT_HOUSE_BRUSH, "Select House", "Draw with the house on this tile."); |
| 2677 | + | } |
| 2678 | + | |
| 2679 | + | if (tile->hasGround() || topCreature || topSpawn) { |
| 2680 | + | AppendSeparator(); |
| 2681 | + | Append(MAP_POPUP_MENU_PROPERTIES, "&Properties", "Properties for the current object"); |
| 2682 | + | } |
| 2683 | + | } |
| 2684 | + | |
| 2685 | + | AppendSeparator(); |
| 2686 | + | |
| 2687 | + | wxMenuItem* browseTile = Append(MAP_POPUP_MENU_BROWSE_TILE, "Browse Field", "Navigate from tile items"); |
| 2688 | + | browseTile->Enable(anything_selected); |
| 2689 | + | } |
| 2690 | + | } |
| 2691 | + | |
| 2692 | + | |
| 2693 | + | } |
| 2694 | + | |
| 2695 | + | void MapCanvas::getTilesToDraw(int mouse_map_x, int mouse_map_y, int floor, PositionVector* tilestodraw, PositionVector* tilestoborder, bool fill /*= false*/) { |
| 2696 | + | if (fill) { |
| 2697 | + | Brush* brush = g_gui.GetCurrentBrush(); |
| 2698 | + | if (!brush || !brush->isGround()) { |
| 2699 | + | return; |
| 2700 | + | } |
| 2701 | + | |
| 2702 | + | GroundBrush* newBrush = brush->asGround(); |
| 2703 | + | Position position(mouse_map_x, mouse_map_y, floor); |
| 2704 | + | |
| 2705 | + | Tile* tile = editor.map.getTile(position); |
| 2706 | + | GroundBrush* oldBrush = nullptr; |
| 2707 | + | if (tile) { |
| 2708 | + | oldBrush = tile->getGroundBrush(); |
| 2709 | + | } |
| 2710 | + | |
| 2711 | + | if (oldBrush && oldBrush->getID() == newBrush->getID()) { |
| 2712 | + | return; |
| 2713 | + | } |
| 2714 | + | |
| 2715 | + | if ((tile && tile->ground && !oldBrush) || (!tile && oldBrush)) { |
| 2716 | + | return; |
| 2717 | + | } |
| 2718 | + | |
| 2719 | + | if (tile && oldBrush) { |
| 2720 | + | GroundBrush* groundBrush = tile->getGroundBrush(); |
| 2721 | + | if (!groundBrush || groundBrush->getID() != oldBrush->getID()) { |
| 2722 | + | return; |
| 2723 | + | } |
| 2724 | + | } |
| 2725 | + | |
| 2726 | + | std::fill(std::begin(processed), std::end(processed), false); |
| 2727 | + | floodFill(&editor.map, position, BLOCK_SIZE / 2, BLOCK_SIZE / 2, oldBrush, tilestodraw); |
| 2728 | + | |
| 2729 | + | } else { |
| 2730 | + | for (int y = -g_gui.GetBrushSize() - 1; y <= g_gui.GetBrushSize() + 1; y++) { |
| 2731 | + | for (int x = -g_gui.GetBrushSize() - 1; x <= g_gui.GetBrushSize() + 1; x++) { |
| 2732 | + | if (g_gui.GetBrushShape() == BRUSHSHAPE_SQUARE) { |
| 2733 | + | if (x >= -g_gui.GetBrushSize() && x <= g_gui.GetBrushSize() && y >= -g_gui.GetBrushSize() && y <= g_gui.GetBrushSize()) { |
| 2734 | + | if (tilestodraw) { |
| 2735 | + | tilestodraw->push_back(Position(mouse_map_x + x, mouse_map_y + y, floor)); |
| 2736 | + | } |
| 2737 | + | } |
| 2738 | + | if (std::abs(x) - g_gui.GetBrushSize() < 2 && std::abs(y) - g_gui.GetBrushSize() < 2) { |
| 2739 | + | if (tilestoborder) { |
| 2740 | + | tilestoborder->push_back(Position(mouse_map_x + x, mouse_map_y + y, floor)); |
| 2741 | + | } |
| 2742 | + | } |
| 2743 | + | } else if (g_gui.GetBrushShape() == BRUSHSHAPE_CIRCLE) { |
| 2744 | + | double distance = sqrt(double(x * x) + double(y * y)); |
| 2745 | + | if (distance < g_gui.GetBrushSize() + 0.005) { |
| 2746 | + | if (tilestodraw) { |
| 2747 | + | tilestodraw->push_back(Position(mouse_map_x + x, mouse_map_y + y, floor)); |
| 2748 | + | } |
| 2749 | + | } |
| 2750 | + | if (std::abs(distance - g_gui.GetBrushSize()) < 1.5) { |
| 2751 | + | if (tilestoborder) { |
| 2752 | + | tilestoborder->push_back(Position(mouse_map_x + x, mouse_map_y + y, floor)); |
| 2753 | + | } |
| 2754 | + | } |
| 2755 | + | } |
| 2756 | + | } |
| 2757 | + | } |
| 2758 | + | } |
| 2759 | + | } |
| 2760 | + | |
| 2761 | + | bool MapCanvas::floodFill(Map* map, const Position& center, int x, int y, GroundBrush* brush, PositionVector* positions) { |
| 2762 | + | countMaxFills++; |
| 2763 | + | if (countMaxFills > (BLOCK_SIZE * 4 * 4)) { |
| 2764 | + | countMaxFills = 0; |
| 2765 | + | return true; |
| 2766 | + | } |
| 2767 | + | |
| 2768 | + | if (x <= 0 || y <= 0 || x >= BLOCK_SIZE || y >= BLOCK_SIZE) { |
| 2769 | + | return false; |
| 2770 | + | } |
| 2771 | + | |
| 2772 | + | processed[getFillIndex(x, y)] = true; |
| 2773 | + | |
| 2774 | + | int px = (center.x + x) - (BLOCK_SIZE / 2); |
| 2775 | + | int py = (center.y + y) - (BLOCK_SIZE / 2); |
| 2776 | + | if (px <= 0 || py <= 0 || px >= map->getWidth() || py >= map->getHeight()) { |
| 2777 | + | return false; |
| 2778 | + | } |
| 2779 | + | |
| 2780 | + | Tile* tile = map->getTile(px, py, center.z); |
| 2781 | + | if ((tile && tile->ground && !brush) || (!tile && brush)) { |
| 2782 | + | return false; |
| 2783 | + | } |
| 2784 | + | |
| 2785 | + | if (tile && brush) { |
| 2786 | + | GroundBrush* groundBrush = tile->getGroundBrush(); |
| 2787 | + | if (!groundBrush || groundBrush->getID() != brush->getID()) { |
| 2788 | + | return false; |
| 2789 | + | } |
| 2790 | + | } |
| 2791 | + | |
| 2792 | + | positions->push_back(Position(px, py, center.z)); |
| 2793 | + | |
| 2794 | + | bool deny = false; |
| 2795 | + | if (!processed[getFillIndex(x - 1, y)]) { |
| 2796 | + | deny = floodFill(map, center, x - 1, y, brush, positions); |
| 2797 | + | } |
| 2798 | + | |
| 2799 | + | if (!deny && !processed[getFillIndex(x, y - 1)]) { |
| 2800 | + | deny = floodFill(map, center, x, y - 1, brush, positions); |
| 2801 | + | } |
| 2802 | + | |
| 2803 | + | if (!deny && !processed[getFillIndex(x + 1, y)]) { |
| 2804 | + | deny = floodFill(map, center, x + 1, y, brush, positions); |
| 2805 | + | } |
| 2806 | + | |
| 2807 | + | if (!deny && !processed[getFillIndex(x, y + 1)]) { |
| 2808 | + | deny = floodFill(map, center, x, y + 1, brush, positions); |
| 2809 | + | } |
| 2810 | + | |
| 2811 | + | return deny; |
| 2812 | + | } |
| 2813 | + | |
| 2814 | + | // ============================================================================ |
| 2815 | + | // AnimationTimer |
| 2816 | + | |
| 2817 | + | AnimationTimer::AnimationTimer(MapCanvas* canvas) : |
| 2818 | + | wxTimer(), |
| 2819 | + | map_canvas(canvas), |
| 2820 | + | started(false) { |
| 2821 | + | //// |
| 2822 | + | }; |
| 2823 | + | |
| 2824 | + | AnimationTimer::~AnimationTimer() { |
| 2825 | + | //// |
| 2826 | + | }; |
| 2827 | + | |
| 2828 | + | void AnimationTimer::Notify() { |
| 2829 | + | if (map_canvas->GetZoom() <= 2.0) { |
| 2830 | + | map_canvas->Refresh(); |
| 2831 | + | } |
| 2832 | + | }; |
| 2833 | + | |
| 2834 | + | void AnimationTimer::Start() { |
| 2835 | + | if (!started) { |
| 2836 | + | started = true; |
| 2837 | + | wxTimer::Start(100); |
| 2838 | + | } |
| 2839 | + | }; |
| 2840 | + | |
| 2841 | + | void AnimationTimer::Stop() { |
| 2842 | + | if (started) { |
| 2843 | + | started = false; |
| 2844 | + | wxTimer::Stop(); |
| 2845 | + | } |
| 2846 | + | }; |
| 2847 | + | |
| 2848 | + | void MapCanvas::OnFill(wxCommandEvent& WXUNUSED(event)) { |
| 2849 | + | OutputDebugStringA("INITIATING IMPROVED FILL PROTOCOL! NOW WITH BORDER AWARENESS!\n"); |
| 2850 | + | |
| 2851 | + | |
| 2852 | + | |
| 2853 | + | // Check if we should show the warning do not remove this warning functionality |
| 2854 | + | if (show_fill_warning) { |
| 2855 | + | wxDialog* dialog = new wxDialog(g_gui.root, wxID_ANY, "Fill Area", |
| 2856 | + | wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE); |
| 2857 | + | |
| 2858 | + | wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL); |
| 2859 | + | |
| 2860 | + | // Add message text |
| 2861 | + | wxStaticText* message = new wxStaticText(dialog, wxID_ANY, |
| 2862 | + | "This operation might take a while if the area is large.\nDo you want to continue?"); |
| 2863 | + | sizer->Add(message, 0, wxALL, 10); |
| 2864 | + | |
| 2865 | + | // Add checkbox |
| 2866 | + | wxCheckBox* checkbox = new wxCheckBox(dialog, wxID_ANY, "Don't show this warning again"); |
| 2867 | + | sizer->Add(checkbox, 0, wxALL, 10); |
| 2868 | + | |
| 2869 | + | // Add buttons |
| 2870 | + | wxBoxSizer* buttonSizer = new wxBoxSizer(wxHORIZONTAL); |
| 2871 | + | wxButton* okButton = new wxButton(dialog, wxID_OK, "Continue"); |
| 2872 | + | wxButton* cancelButton = new wxButton(dialog, wxID_CANCEL, "Cancel"); |
| 2873 | + | buttonSizer->Add(okButton, 0, wxALL, 5); |
| 2874 | + | buttonSizer->Add(cancelButton, 0, wxALL, 5); |
| 2875 | + | sizer->Add(buttonSizer, 0, wxALIGN_CENTER | wxALL, 5); |
| 2876 | + | |
| 2877 | + | dialog->SetSizer(sizer); |
| 2878 | + | sizer->Fit(dialog); |
| 2879 | + | |
| 2880 | + | int answer = dialog->ShowModal(); |
| 2881 | + | |
| 2882 | + | if (answer != wxID_OK) { |
| 2883 | + | dialog->Destroy(); |
| 2884 | + | return; |
| 2885 | + | } |
| 2886 | + | |
| 2887 | + | // Save preference if checkbox was checked |
| 2888 | + | if (checkbox->GetValue()) { |
| 2889 | + | show_fill_warning = false; |
| 2890 | + | } |
| 2891 | + | dialog->Destroy(); |
| 2892 | + | } |
| 2893 | + | // DONT TOUCH this warning box pls |
| 2894 | + | |
| 2895 | + | if (!g_gui.GetCurrentBrush()) { |
| 2896 | + | OutputDebugStringA("NO BRUSH SELECTED! THE VOID CANNOT BE FILLED!\n"); |
| 2897 | + | return; |
| 2898 | + | } |
| 2899 | + | |
| 2900 | + | PositionVector tilestodraw; |
| 2901 | + | PositionVector tilestoborder; |
| 2902 | + | |
| 2903 | + | // Get cursor position |
| 2904 | + | int map_x, map_y; |
| 2905 | + | ScreenToMap(cursor_x, cursor_y, &map_x, &map_y); |
| 2906 | + | Position start(map_x, map_y, floor); |
| 2907 | + | |
| 2908 | + | Tile* start_tile = editor.map.getTile(start); |
| 2909 | + | bool is_border_fill = false; |
| 2910 | + | |
| 2911 | + | // Check if we have a border item on the starting tile |
| 2912 | + | if(start_tile) { |
| 2913 | + | for(Item* item : start_tile->items) { |
| 2914 | + | if(item && item->isBorder()) { |
| 2915 | + | is_border_fill = true; |
| 2916 | + | break; |
| 2917 | + | } |
| 2918 | + | } |
| 2919 | + | } |
| 2920 | + | |
| 2921 | + | if(is_border_fill) { |
| 2922 | + | OutputDebugStringA("BORDER DETECTED! INITIATING SNAKE-LIKE BORDER FILL!\n"); |
| 2923 | + | |
| 2924 | + | const int MAX_BORDERS_PER_BATCH = BLOCK_SIZE * 4; // Safety limit per batch |
| 2925 | + | std::queue<Position> border_queue; |
| 2926 | + | std::set<Position> processed_borders; |
| 2927 | + | std::set<Position> to_fill; |
| 2928 | + | std::set<Position> remaining_borders; // Store borders for next batch |
| 2929 | + | |
| 2930 | + | border_queue.push(start); |
| 2931 | + | bool continue_filling = true; |
| 2932 | + | |
| 2933 | + | while(continue_filling) { |
| 2934 | + | int current_batch_count = 0; |
| 2935 | + | |
| 2936 | + | while(!border_queue.empty() && current_batch_count < MAX_BORDERS_PER_BATCH) { |
| 2937 | + | Position current = border_queue.front(); |
| 2938 | + | border_queue.pop(); |
| 2939 | + | |
| 2940 | + | if(processed_borders.count(current) > 0) continue; |
| 2941 | + | processed_borders.insert(current); |
| 2942 | + | to_fill.insert(current); |
| 2943 | + | current_batch_count++; |
| 2944 | + | |
| 2945 | + | // Check adjacent tiles for more borders (8 directions) |
| 2946 | + | Position adjacent[8] = { |
| 2947 | + | Position(current.x + 1, current.y, floor), // Right |
| 2948 | + | Position(current.x - 1, current.y, floor), // Left |
| 2949 | + | Position(current.x, current.y + 1, floor), // Down |
| 2950 | + | Position(current.x, current.y - 1, floor), // Up |
| 2951 | + | Position(current.x + 1, current.y + 1, floor), // Bottom-right |
| 2952 | + | Position(current.x - 1, current.y - 1, floor), // Top-left |
| 2953 | + | Position(current.x - 1, current.y + 1, floor), // Bottom-left |
| 2954 | + | Position(current.x + 1, current.y - 1, floor) // Top-right |
| 2955 | + | }; |
| 2956 | + | |
| 2957 | + | for(const Position& pos : adjacent) { |
| 2958 | + | if(processed_borders.count(pos) > 0) continue; |
| 2959 | + | |
| 2960 | + | Tile* tile = editor.map.getTile(pos); |
| 2961 | + | if(!tile) continue; |
| 2962 | + | |
| 2963 | + | for(Item* item : tile->items) { |
| 2964 | + | if(item && item->isBorder()) { |
| 2965 | + | if(current_batch_count >= MAX_BORDERS_PER_BATCH) { |
| 2966 | + | remaining_borders.insert(pos); |
| 2967 | + | } else { |
| 2968 | + | border_queue.push(pos); |
| 2969 | + | } |
| 2970 | + | break; |
| 2971 | + | } |
| 2972 | + | } |
| 2973 | + | } |
| 2974 | + | } |
| 2975 | + | |
| 2976 | + | // Process current batch |
| 2977 | + | if(!to_fill.empty()) { |
| 2978 | + | OutputDebugStringA(wxString::Format("PROCESSING BATCH OF %d BORDERS...\n", to_fill.size()).c_str()); |
| 2979 | + | |
| 2980 | + | Action* action = editor.actionQueue->createAction(ACTION_DRAW); |
| 2981 | + | for(const Position& pos : to_fill) { |
| 2982 | + | Tile* tile = editor.map.getTile(pos); |
| 2983 | + | if(!tile) { |
| 2984 | + | tile = editor.map.createTile(pos.x, pos.y, pos.z); |
| 2985 | + | } |
| 2986 | + | Tile* new_tile = tile->deepCopy(editor.map); |
| 2987 | + | g_gui.GetCurrentBrush()->draw(&editor.map, new_tile, nullptr); |
| 2988 | + | action->addChange(newd Change(new_tile)); |
| 2989 | + | } |
| 2990 | + | editor.addAction(action); |
| 2991 | + | g_gui.RefreshView(); |
| 2992 | + | } |
| 2993 | + | |
| 2994 | + | // Check if we should continue with remaining borders |
| 2995 | + | if(!remaining_borders.empty()) { |
| 2996 | + | wxString message = wxString::Format( |
| 2997 | + | "Processed %d borders. There are %d more borders to process.\nContinue filling?", |
| 2998 | + | processed_borders.size(), remaining_borders.size()); |
| 2999 | + | |
| 3000 | + | int answer = g_gui.PopupDialog( |
| 3001 | + | "Continue Border Fill?", |
| 3002 | + | message, |
| 3003 | + | wxYES_NO |
| 3004 | + | ); |
| 3005 | + | |
| 3006 | + | if(answer == wxID_YES) { |
| 3007 | + | OutputDebugStringA("CONTINUING WITH NEXT BATCH OF BORDERS...\n"); |
| 3008 | + | // Move remaining borders to queue for next batch |
| 3009 | + | for(const Position& pos : remaining_borders) { |
| 3010 | + | border_queue.push(pos); |
| 3011 | + | } |
| 3012 | + | remaining_borders.clear(); |
| 3013 | + | to_fill.clear(); |
| 3014 | + | } else { |
| 3015 | + | OutputDebugStringA("BORDER FILL STOPPED BY USER!\n"); |
| 3016 | + | continue_filling = false; |
| 3017 | + | } |
| 3018 | + | } else { |
| 3019 | + | OutputDebugStringA("ALL BORDERS PROCESSED! THE SNAKE IS SATISFIED!\n"); |
| 3020 | + | continue_filling = false; |
| 3021 | + | } |
| 3022 | + | } |
| 3023 | + | } else { |
| 3024 | + | // Normal fill with area validation |
| 3025 | + | OutputDebugStringA("NORMAL FILL INITIATED! VALIDATING AREA...\n"); |
| 3026 | + | |
| 3027 | + | std::queue<Position> to_check; |
| 3028 | + | std::set<Position> checked; |
| 3029 | + | to_check.push(start); |
| 3030 | + | bool escape_found = false; |
| 3031 | + | |
| 3032 | + | while (!to_check.empty() && !escape_found) { |
| 3033 | + | Position pos = to_check.front(); |
| 3034 | + | to_check.pop(); |
| 3035 | + | |
| 3036 | + | if (checked.count(pos) > 0) continue; |
| 3037 | + | checked.insert(pos); |
| 3038 | + | |
| 3039 | + | // Check map boundaries |
| 3040 | + | if (pos.x <= 0 || pos.y <= 0 || |
| 3041 | + | pos.x >= editor.map.getWidth() - 1 || |
| 3042 | + | pos.y >= editor.map.getHeight() - 1) { |
| 3043 | + | escape_found = true; |
| 3044 | + | break; |
| 3045 | + | } |
| 3046 | + | |
| 3047 | + | Tile* tile = editor.map.getTile(pos); |
| 3048 | + | bool is_empty = (!tile || |
| 3049 | + | (!tile->spawn || !g_settings.getInteger(Config::SHOW_SPAWNS)) && |
| 3050 | + | (!tile->creature || !g_settings.getInteger(Config::SHOW_CREATURES)) && |
| 3051 | + | !tile->getTopItem()); |
| 3052 | + | |
| 3053 | + | if (!is_empty) continue; |
| 3054 | + | |
| 3055 | + | // Check adjacent tiles (4-directional) |
| 3056 | + | Position adjacent[4] = { |
| 3057 | + | Position(pos.x + 1, pos.y, floor), |
| 3058 | + | Position(pos.x - 1, pos.y, floor), |
| 3059 | + | Position(pos.x, pos.y + 1, floor), |
| 3060 | + | Position(pos.x, pos.y - 1, floor) |
| 3061 | + | }; |
| 3062 | + | |
| 3063 | + | for (const Position& next : adjacent) { |
| 3064 | + | if (checked.count(next) > 0) continue; |
| 3065 | + | |
| 3066 | + | Tile* next_tile = editor.map.getTile(next); |
| 3067 | + | bool next_is_empty = (!next_tile || |
| 3068 | + | (!next_tile->spawn || !g_settings.getInteger(Config::SHOW_SPAWNS)) && |
| 3069 | + | (!next_tile->creature || !g_settings.getInteger(Config::SHOW_CREATURES)) && |
| 3070 | + | !next_tile->getTopItem()); |
| 3071 | + | |
| 3072 | + | if (next_is_empty) { |
| 3073 | + | to_check.push(next); |
| 3074 | + | } |
| 3075 | + | } |
| 3076 | + | } |
| 3077 | + | |
| 3078 | + | if (escape_found) { |
| 3079 | + | OutputDebugStringA("AREA NOT ENCLOSED! THE VOID LEAKS!\n"); |
| 3080 | + | g_gui.PopupDialog("Error", "Cannot fill - area is not enclosed.", wxOK); |
| 3081 | + | return; |
| 3082 | + | } |
| 3083 | + | |
| 3084 | + | OutputDebugStringA(wxString::Format("FOUND %d TILES TO FILL NORMALLY!\n", checked.size()).c_str()); |
| 3085 | + | |
| 3086 | + | Action* action = editor.actionQueue->createAction(ACTION_DRAW); |
| 3087 | + | for (const Position& pos : checked) { |
| 3088 | + | Tile* tile = editor.map.getTile(pos); |
| 3089 | + | if (!tile) { |
| 3090 | + | tile = editor.map.createTile(pos.x, pos.y, pos.z); |
| 3091 | + | } |
| 3092 | + | Tile* new_tile = tile->deepCopy(editor.map); |
| 3093 | + | g_gui.GetCurrentBrush()->draw(&editor.map, new_tile, nullptr); |
| 3094 | + | action->addChange(newd Change(new_tile)); |
| 3095 | + | } |
| 3096 | + | |
| 3097 | + | editor.addAction(action); |
| 3098 | + | g_gui.RefreshView(); |
| 3099 | + | OutputDebugStringA("NORMAL FILL COMPLETE! THE VOID HAS BEEN FILLED!\n"); |
| 3100 | + | } |
| 3101 | + | } |
| 3102 | + | |
| 3103 | + | /* |
| 3104 | + | ============================================================================ |
| 3105 | + | SELECTION TO DOODAD BRUSH TASK - COMPLETED ✓ |
| 3106 | + | ============================================================================ |
| 3107 | + | |
| 3108 | + | OBJECTIVE: |
| 3109 | + | Ensure proper handling of ground tiles and borders when converting area selections |
| 3110 | + | to doodad brushes. |
| 3111 | + | |
| 3112 | + | FINAL BEHAVIOR: |
| 3113 | + | ✓ Individual item selection works correctly |
| 3114 | + | ✓ Ground tiles are only included when explicitly selected |
| 3115 | + | ✓ Border items are properly preserved |
| 3116 | + | ✓ Collections.xml integration working |
| 3117 | + | ✓ Doodads.xml saving working |
| 3118 | + | ✓ Layer-specific selection preserved (no unwanted grounds under borders) |
| 3119 | + | ✓ Item stacking order maintained |
| 3120 | + | ✓ All selected items included correctly |
| 3121 | + | ✓ No unselected items included in brush |
| 3122 | + | |
| 3123 | + | IMPLEMENTATION DETAILS: |
| 3124 | + | - Uses tile->ground for ground layer items |
| 3125 | + | - Checks isBorder() for border items |
| 3126 | + | - Maintains proper XML structure in doodads.xml |
| 3127 | + | - Updates collections.xml name reference |
| 3128 | + | - Preserves all item properties |
| 3129 | + | - Only includes explicitly selected items |
| 3130 | + | - Proper debug logging added |
| 3131 | + | |
| 3132 | + | ============================================================================ |
| 3133 | + | */ |
| 3134 | + | |
| 3135 | + | |
| 3136 | + | void MapCanvas::OnSelectionToDoodad(wxCommandEvent& WXUNUSED(event)) { |
| 3137 | + | OutputDebugStringA("INITIATING DOODAD CREATION PROTOCOL! MUAHAHAHA!\n"); |
| 3138 | + | |
| 3139 | + | if (editor.selection.size() == 0) { |
| 3140 | + | OutputDebugStringA("OH THE HUMANITY! THE SELECTION IS AS EMPTY AS MY SOUL!\n"); |
| 3141 | + | g_gui.PopupDialog(this, "Error", "Y U GIVE EMPTY SELECTION?! (╯°□°)╯︵ ┻━┻", wxOK); |
| 3142 | + | return; |
| 3143 | + | } |
| 3144 | + | |
| 3145 | + | OutputDebugStringA(wxString::Format("DETECTED %d TILES! TIME TO PERFORM UNSPEAKABLE ACTS OF XML CREATION!\n", |
| 3146 | + | editor.selection.size()).c_str()); |
| 3147 | + | |
| 3148 | + | Position minPos(0xFFFF, 0xFFFF, 0xFFFF); |
| 3149 | + | Position maxPos(0, 0, 0); |
| 3150 | + | |
| 3151 | + | int tileCount = 0; |
| 3152 | + | int totalItems = 0; |
| 3153 | + | // Use a map with Position as key to store items by their 3D coordinates |
| 3154 | + | std::map<Position, std::vector<Item*>> tileItems; |
| 3155 | + | |
| 3156 | + | OutputDebugStringA("COMMENCING TILE INSPECTION! RESISTANCE IS FUTILE!\n"); |
| 3157 | + | |
| 3158 | + | // First, analyze what's actually in the selection |
| 3159 | + | for(auto tile : editor.selection) { |
| 3160 | + | if(!tile) continue; |
| 3161 | + | |
| 3162 | + | Position tilePos(tile->getX(), tile->getY(), tile->getZ()); |
| 3163 | + | OutputDebugStringA(wxString::Format("\nTile at %d,%d,%d:\n", |
| 3164 | + | tilePos.x, tilePos.y, tilePos.z).c_str()); |
| 3165 | + | |
| 3166 | + | // Check if the tile itself is selected (vs just items on the tile) |
| 3167 | + | bool tileSelected = editor.selection.getTiles().count(tile) > 0; |
| 3168 | + | |
| 3169 | + | // If entire tile is selected, add all its items |
| 3170 | + | if(tileSelected) { |
| 3171 | + | if(tile->ground) { |
| 3172 | + | tileItems[tilePos].push_back(tile->ground); |
| 3173 | + | totalItems++; |
| 3174 | + | OutputDebugStringA(wxString::Format("Adding ground %d from selected tile at %d,%d,%d\n", |
| 3175 | + | tile->ground->getID(), tilePos.x, tilePos.y, tilePos.z).c_str()); |
| 3176 | + | } |
| 3177 | + | |
| 3178 | + | for(Item* item : tile->items) { |
| 3179 | + | if(!item) continue; |
| 3180 | + | if(!item->isBorder()) { |
| 3181 | + | tileItems[tilePos].push_back(item); |
| 3182 | + | totalItems++; |
| 3183 | + | OutputDebugStringA(wxString::Format("Adding item %d from selected tile at %d,%d,%d\n", |
| 3184 | + | item->getID(), tilePos.x, tilePos.y, tilePos.z).c_str()); |
| 3185 | + | } |
| 3186 | + | } |
| 3187 | + | } |
| 3188 | + | // Otherwise, only add individually selected items |
| 3189 | + | else { |
| 3190 | + | // First check if ground is selected |
| 3191 | + | if(tile->ground && tile->ground->isSelected()) { |
| 3192 | + | tileItems[tilePos].push_back(tile->ground); |
| 3193 | + | totalItems++; |
| 3194 | + | OutputDebugStringA(wxString::Format("Adding selected ground %d at %d,%d,%d\n", |
| 3195 | + | tile->ground->getID(), tilePos.x, tilePos.y, tilePos.z).c_str()); |
| 3196 | + | } |
| 3197 | + | |
| 3198 | + | // Then add selected items |
| 3199 | + | for(Item* item : tile->items) { |
| 3200 | + | if(item && item->isSelected()) { |
| 3201 | + | tileItems[tilePos].push_back(item); |
| 3202 | + | totalItems++; |
| 3203 | + | OutputDebugStringA(wxString::Format("Adding selected item %d at %d,%d,%d\n", |
| 3204 | + | item->getID(), tilePos.x, tilePos.y, tilePos.z).c_str()); |
| 3205 | + | } |
| 3206 | + | } |
| 3207 | + | } |
| 3208 | + | |
| 3209 | + | // Only count this as a tile if we added items from it |
| 3210 | + | if(!tileItems[tilePos].empty()) { |
| 3211 | + | tileCount++; |
| 3212 | + | |
| 3213 | + | // Update min/max positions |
| 3214 | + | if(tilePos.x < minPos.x) minPos.x = tilePos.x; |
| 3215 | + | if(tilePos.y < minPos.y) minPos.y = tilePos.y; |
| 3216 | + | if(tilePos.z < minPos.z) minPos.z = tilePos.z; |
| 3217 | + | if(tilePos.x > maxPos.x) maxPos.x = tilePos.x; |
| 3218 | + | if(tilePos.y > maxPos.y) maxPos.y = tilePos.y; |
| 3219 | + | if(tilePos.z > maxPos.z) maxPos.z = tilePos.z; |
| 3220 | + | } else { |
| 3221 | + | // Remove empty position entry |
| 3222 | + | tileItems.erase(tilePos); |
| 3223 | + | } |
| 3224 | + | } |
| 3225 | + | |
| 3226 | + | OutputDebugStringA(wxString::Format("MWAHAHAHA! ACQUIRED %d ITEMS FROM %d TILES! THE COLLECTION GROWS!\n", |
| 3227 | + | totalItems, tileCount).c_str()); |
| 3228 | + | |
| 3229 | + | // Display multi-floor information |
| 3230 | + | if (minPos.z != maxPos.z) { |
| 3231 | + | OutputDebugStringA(wxString::Format("MULTI-FLOOR SELECTION DETECTED! FROM FLOOR %d TO %d\n", |
| 3232 | + | minPos.z, maxPos.z).c_str()); |
| 3233 | + | } |
| 3234 | + | |
| 3235 | + | if(totalItems == 0) { |
| 3236 | + | OutputDebugStringA("WHAT IS THIS MADNESS?! NO ITEMS TO STEAL?! INCONCEIVABLE!\n"); |
| 3237 | + | g_gui.PopupDialog(this, "Error", "WHERE ARE THE ITEMS?! ┻━┻ ︵ヽ(`Д´)ノ︵ ┻━┻", wxOK); |
| 3238 | + | return; |
| 3239 | + | } |
| 3240 | + | |
| 3241 | + | // Get the proper data directory paths |
| 3242 | + | wxString versionString = g_gui.GetCurrentVersion().getName(); |
| 3243 | + | std::string versionStr = std::string(versionString.mb_str()); |
| 3244 | + | |
| 3245 | + | // Convert version number to data directory format |
| 3246 | + | // Remove dots first |
| 3247 | + | versionStr.erase(std::remove(versionStr.begin(), versionStr.end(), '.'), versionStr.end()); |
| 3248 | + | |
| 3249 | + | // Handle special cases for 2-digit versions (add 0) |
| 3250 | + | if(versionStr.length() == 2) { |
| 3251 | + | versionStr += "0"; |
| 3252 | + | } |
| 3253 | + | // Handle special case for 10.10 -> 10100 |
| 3254 | + | else if(versionStr == "1010") { |
| 3255 | + | versionStr = "10100"; |
| 3256 | + | } |
| 3257 | + | |
| 3258 | + | OutputDebugStringA(wxString::Format("CONVERTED VERSION %s TO DIRECTORY %s\n", |
| 3259 | + | versionString, versionStr).c_str()); |
| 3260 | + | |
| 3261 | + | FileName doodadsPath = g_gui.GetDataDirectory(); |
| 3262 | + | doodadsPath.SetPath(doodadsPath.GetPath() + "/" + versionStr); |
| 3263 | + | doodadsPath.SetName("doodads.xml"); |
| 3264 | + | |
| 3265 | + | wxString doodadsPathStr = doodadsPath.GetFullPath(); |
| 3266 | + | OutputDebugStringA(wxString::Format("ATTEMPTING TO ACCESS DOODADS AT: %s\n", doodadsPathStr).c_str()); |
| 3267 | + | |
| 3268 | + | FileName collectionsPath = g_gui.GetDataDirectory(); |
| 3269 | + | collectionsPath.SetPath(collectionsPath.GetPath() + "/" + versionStr); |
| 3270 | + | collectionsPath.SetName("collections.xml"); |
| 3271 | + | |
| 3272 | + | wxString collectionsPathStr = collectionsPath.GetFullPath(); |
| 3273 | + | |
| 3274 | + | // After loading paths but before creating the brush... |
| 3275 | + | // Load collections.xml to get existing tilesets |
| 3276 | + | std::vector<wxString> tilesetNames; |
| 3277 | + | wxXmlDocument collectionsDoc; |
| 3278 | + | if (collectionsDoc.Load(collectionsPathStr)) { |
| 3279 | + | wxXmlNode* root = collectionsDoc.GetRoot(); |
| 3280 | + | if (root) { |
| 3281 | + | for (wxXmlNode* node = root->GetChildren(); node; node = node->GetNext()) { |
| 3282 | + | if (node->GetName() == "tileset") { |
| 3283 | + | tilesetNames.push_back(node->GetAttribute("name")); |
| 3284 | + | } |
| 3285 | + | } |
| 3286 | + | } |
| 3287 | + | } else { |
| 3288 | + | OutputDebugStringA("THE COLLECTIONS TOME IS MISSING! CREATING A NEW ONE!\n"); |
| 3289 | + | wxXmlNode* root = new wxXmlNode(wxXML_ELEMENT_NODE, "materials"); |
| 3290 | + | collectionsDoc.SetRoot(root); |
| 3291 | + | } |
| 3292 | + | |
| 3293 | + | if (tilesetNames.empty()) { |
| 3294 | + | g_gui.PopupDialog(this, "Error", "No tilesets found in collections.xml!", wxOK); |
| 3295 | + | return; |
| 3296 | + | } |
| 3297 | + | |
| 3298 | + | // Create tileset selection dialog |
| 3299 | + | wxDialog* dialog = new wxDialog(g_gui.root, wxID_ANY, "Select Collection", |
| 3300 | + | wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE); |
| 3301 | + | |
| 3302 | + | wxBoxSizer* dialogSizer = new wxBoxSizer(wxVERTICAL); |
| 3303 | + | |
| 3304 | + | // Add dropdown for existing collections |
| 3305 | + | wxBoxSizer* choiceSizer = new wxBoxSizer(wxHORIZONTAL); |
| 3306 | + | wxStaticText* choiceLabel = new wxStaticText(dialog, wxID_ANY, "Collection:"); |
| 3307 | + | wxChoice* collectionChoice = new wxChoice(dialog, wxID_ANY); |
| 3308 | + | |
| 3309 | + | for (const wxString& name : tilesetNames) { |
| 3310 | + | collectionChoice->Append(name); |
| 3311 | + | } |
| 3312 | + | collectionChoice->SetSelection(0); |
| 3313 | + | |
| 3314 | + | choiceSizer->Add(choiceLabel, 0, wxALL | wxALIGN_CENTER_VERTICAL, 5); |
| 3315 | + | choiceSizer->Add(collectionChoice, 1, wxALL | wxEXPAND, 5); |
| 3316 | + | dialogSizer->Add(choiceSizer, 0, wxEXPAND); |
| 3317 | + | |
| 3318 | + | // Add buttons |
| 3319 | + | wxBoxSizer* buttonSizer = new wxBoxSizer(wxHORIZONTAL); |
| 3320 | + | wxButton* okButton = new wxButton(dialog, wxID_OK, "OK"); |
| 3321 | + | wxButton* cancelButton = new wxButton(dialog, wxID_CANCEL, "Cancel"); |
| 3322 | + | buttonSizer->Add(okButton, 0, wxALL, 5); |
| 3323 | + | buttonSizer->Add(cancelButton, 0, wxALL, 5); |
| 3324 | + | dialogSizer->Add(buttonSizer, 0, wxALIGN_CENTER | wxALL, 5); |
| 3325 | + | |
| 3326 | + | dialog->SetSizer(dialogSizer); |
| 3327 | + | dialogSizer->Fit(dialog); |
| 3328 | + | |
| 3329 | + | if (dialog->ShowModal() != wxID_OK) { |
| 3330 | + | dialog->Destroy(); |
| 3331 | + | return; |
| 3332 | + | } |
| 3333 | + | |
| 3334 | + | wxString selectedTileset = collectionChoice->GetString(collectionChoice->GetSelection()); |
| 3335 | + | dialog->Destroy(); |
| 3336 | + | |
| 3337 | + | // Create doodad brush |
| 3338 | + | wxXmlDocument doodadsDoc; |
| 3339 | + | if(!doodadsDoc.Load(doodadsPathStr)) { |
| 3340 | + | OutputDebugStringA("THE DOODADS TOME DOES NOT EXIST! CREATING A NEW ONE!\n"); |
| 3341 | + | wxXmlNode* root = new wxXmlNode(wxXML_ELEMENT_NODE, "materials"); |
| 3342 | + | doodadsDoc.SetRoot(root); |
| 3343 | + | } |
| 3344 | + | |
| 3345 | + | // Continue with existing doodad creation code... |
| 3346 | + | wxXmlNode* collectionsRoot = collectionsDoc.GetRoot(); |
| 3347 | + | wxXmlNode* firstTileset = nullptr; |
| 3348 | + | |
| 3349 | + | for(wxXmlNode* node = collectionsRoot->GetChildren(); node; node = node->GetNext()) { |
| 3350 | + | if(node->GetName() == "tileset" && node->GetAttribute("name") == selectedTileset) { |
| 3351 | + | firstTileset = node; |
| 3352 | + | break; |
| 3353 | + | } |
| 3354 | + | } |
| 3355 | + | |
| 3356 | + | if(!firstTileset) { |
| 3357 | + | g_gui.PopupDialog(this, "Error", "Selected tileset not found!", wxOK); |
| 3358 | + | return; |
| 3359 | + | } |
| 3360 | + | |
| 3361 | + | // Find or create collections node |
| 3362 | + | wxXmlNode* collections = firstTileset->GetChildren(); |
| 3363 | + | if(!collections || collections->GetName() != "collections") { |
| 3364 | + | OutputDebugStringA("NO COLLECTIONS NODE FOUND! CREATING ONE FROM THE VOID!\n"); |
| 3365 | + | collections = new wxXmlNode(wxXML_ELEMENT_NODE, "collections"); |
| 3366 | + | firstTileset->AddChild(collections); |
| 3367 | + | } |
| 3368 | + | |
| 3369 | + | // Find highest custom number |
| 3370 | + | int highestNum = 0; |
| 3371 | + | wxXmlNode* doodadsRoot = doodadsDoc.GetRoot(); |
| 3372 | + | for(wxXmlNode* node = doodadsRoot->GetChildren(); node; node = node->GetNext()) { |
| 3373 | + | if(node->GetName() == "brush") { |
| 3374 | + | wxString name = node->GetAttribute("name"); |
| 3375 | + | if(name.StartsWith("custom_")) { |
| 3376 | + | long num; |
| 3377 | + | if(name.Mid(7).ToLong(&num)) { |
| 3378 | + | highestNum = std::max(highestNum, (int)num); |
| 3379 | + | } |
| 3380 | + | } |
| 3381 | + | } |
| 3382 | + | } |
| 3383 | + | |
| 3384 | + | wxString newBrushName = wxString::Format("custom_%d", highestNum + 1); |
| 3385 | + | OutputDebugStringA(wxString::Format("BEHOLD! NEW BRUSH SHALL BE NAMED %s!\n", newBrushName).c_str()); |
| 3386 | + | |
| 3387 | + | // Create the ULTIMATE BRUSH NODE with full pattern |
| 3388 | + | wxXmlNode* newBrushNode = new wxXmlNode(wxXML_ELEMENT_NODE, "brush"); |
| 3389 | + | newBrushNode->AddAttribute("name", newBrushName); |
| 3390 | + | newBrushNode->AddAttribute("type", "doodad"); |
| 3391 | + | newBrushNode->AddAttribute("server_lookid", wxString::Format("%d", tileItems.begin()->second.front()->getID())); |
| 3392 | + | newBrushNode->AddAttribute("draggable", "true"); |
| 3393 | + | newBrushNode->AddAttribute("on_blocking", "true"); |
| 3394 | + | newBrushNode->AddAttribute("thickness", "100/100"); |
| 3395 | + | |
| 3396 | + | // Add multi-floor support attribute if this is a multi-floor doodad |
| 3397 | + | if (minPos.z != maxPos.z) { |
| 3398 | + | newBrushNode->AddAttribute("multi_floor", "true"); |
| 3399 | + | } |
| 3400 | + | |
| 3401 | + | // Create the alternate/composite structure |
| 3402 | + | wxXmlNode* alternateNode = new wxXmlNode(wxXML_ELEMENT_NODE, "alternate"); |
| 3403 | + | wxXmlNode* compositeNode = new wxXmlNode(wxXML_ELEMENT_NODE, "composite"); |
| 3404 | + | compositeNode->AddAttribute("chance", "10"); |
| 3405 | + | |
| 3406 | + | OutputDebugStringA("\n=== GENERATING XML ===\n"); |
| 3407 | + | |
| 3408 | + | // Add ALL the items to their relative positions |
| 3409 | + | for(const auto& tilePair : tileItems) { |
| 3410 | + | const Position& pos = tilePair.first; |
| 3411 | + | int relX = pos.x - minPos.x; |
| 3412 | + | int relY = pos.y - minPos.y; |
| 3413 | + | int relZ = pos.z - minPos.z; // Calculate relative Z |
| 3414 | + | |
| 3415 | + | // Create tile node once per position |
| 3416 | + | wxXmlNode* tileNode = new wxXmlNode(wxXML_ELEMENT_NODE, "tile"); |
| 3417 | + | tileNode->AddAttribute("x", wxString::Format("%d", relX)); |
| 3418 | + | tileNode->AddAttribute("y", wxString::Format("%d", relY)); |
| 3419 | + | tileNode->AddAttribute("z", wxString::Format("%d", relZ)); // Add Z coordinate |
| 3420 | + | |
| 3421 | + | OutputDebugStringA(wxString::Format("Creating tile node at x=%d y=%d z=%d\n", |
| 3422 | + | relX, relY, relZ).c_str()); |
| 3423 | + | |
| 3424 | + | // Add all collected items for this position |
| 3425 | + | for(Item* item : tilePair.second) { |
| 3426 | + | wxXmlNode* itemNode = new wxXmlNode(wxXML_ELEMENT_NODE, "item"); |
| 3427 | + | itemNode->AddAttribute("id", wxString::Format("%d", item->getID())); |
| 3428 | + | tileNode->AddChild(itemNode); |
| 3429 | + | OutputDebugStringA(wxString::Format(" Adding item id=%d\n", item->getID()).c_str()); |
| 3430 | + | } |
| 3431 | + | |
| 3432 | + | compositeNode->AddChild(tileNode); |
| 3433 | + | } |
| 3434 | + | |
| 3435 | + | OutputDebugStringA("=== XML GENERATION COMPLETE ===\n"); |
| 3436 | + | |
| 3437 | + | alternateNode->AddChild(compositeNode); |
| 3438 | + | newBrushNode->AddChild(alternateNode); |
| 3439 | + | doodadsDoc.GetRoot()->AddChild(newBrushNode); |
| 3440 | + | |
| 3441 | + | // Save doodads.xml |
| 3442 | + | if(!doodadsDoc.Save(doodadsPathStr)) { |
| 3443 | + | OutputDebugStringA("THE DOODADS TOME RESISTS OUR CHANGES!\n"); |
| 3444 | + | g_gui.PopupDialog(this, "Error", "Could not write to doodads.xml!", wxOK); |
| 3445 | + | return; |
| 3446 | + | } |
| 3447 | + | |
| 3448 | + | // Find or create collections node in the selected tileset |
| 3449 | + | collections = firstTileset->GetChildren(); |
| 3450 | + | if(!collections || collections->GetName() != "collections") { |
| 3451 | + | OutputDebugStringA("NO COLLECTIONS NODE FOUND! CREATING ONE FROM THE VOID!\n"); |
| 3452 | + | collections = new wxXmlNode(wxXML_ELEMENT_NODE, "collections"); |
| 3453 | + | firstTileset->AddChild(collections); |
| 3454 | + | } |
| 3455 | + | |
| 3456 | + | // Add brush reference to the selected tileset |
| 3457 | + | wxXmlNode* brushRef = new wxXmlNode(wxXML_ELEMENT_NODE, "brush"); |
| 3458 | + | brushRef->AddAttribute("name", newBrushName); |
| 3459 | + | collections->AddChild(brushRef); |
| 3460 | + | |
| 3461 | + | // Save collections.xml |
| 3462 | + | if(!collectionsDoc.Save(collectionsPathStr)) { |
| 3463 | + | OutputDebugStringA("THE COLLECTIONS TOME RESISTS OUR CHANGES!\n"); |
| 3464 | + | g_gui.PopupDialog(this, "Error", "Could not write to collections.xml!", wxOK); |
| 3465 | + | return; |
| 3466 | + | } |
| 3467 | + | OutputDebugStringA(wxString::Format("THE BRUSH HAS BEEN BOUND TO THE %s TILESET!\n", selectedTileset).c_str()); |
| 3468 | + | |
| 3469 | + | OutputDebugStringA("THE RITUAL IS COMPLETE! THE DOODAD HAS BEEN BOUND!\n"); |
| 3470 | + | |
| 3471 | + | // Create success dialog with two buttons |
| 3472 | + | wxDialog* successDoodadDialog = new wxDialog(g_gui.root, wxID_ANY, "Success!", |
| 3473 | + | wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE); |
| 3474 | + | |
| 3475 | + | wxBoxSizer* doodadDialogSizer = new wxBoxSizer(wxVERTICAL); |
| 3476 | + | |
| 3477 | + | // Add message text |
| 3478 | + | wxStaticText* doodadMessage = new wxStaticText(successDoodadDialog, wxID_ANY, |
| 3479 | + | "IT'S ALIVE! IT'S ALIVE!\nCreated: " + newBrushName); |
| 3480 | + | doodadDialogSizer->Add(doodadMessage, 0, wxALL | wxALIGN_CENTER, 10); |
| 3481 | + | |
| 3482 | + | // Add buttons |
| 3483 | + | wxBoxSizer* doodadButtonSizer = new wxBoxSizer(wxHORIZONTAL); |
| 3484 | + | wxButton* doodadContinueButton = new wxButton(successDoodadDialog, wxID_OK, "Continue"); |
| 3485 | + | wxButton* doodadRefreshButton = new wxButton(successDoodadDialog, wxID_APPLY, "Refresh Palette"); |
| 3486 | + | doodadButtonSizer->Add(doodadContinueButton, 0, wxALL, 5); |
| 3487 | + | doodadButtonSizer->Add(doodadRefreshButton, 0, wxALL, 5); |
| 3488 | + | doodadDialogSizer->Add(doodadButtonSizer, 0, wxALIGN_CENTER | wxALL, 5); |
| 3489 | + | |
| 3490 | + | successDoodadDialog->SetSizer(doodadDialogSizer); |
| 3491 | + | doodadDialogSizer->Fit(successDoodadDialog); |
| 3492 | + | |
| 3493 | + | // Handle button clicks |
| 3494 | + | doodadRefreshButton->Bind(wxEVT_BUTTON, [&](wxCommandEvent&) { |
| 3495 | + | OutputDebugStringA("INITIATING DARK RITUAL OF PALETTE RECONSTRUCTION!\n"); |
| 3496 | + | wxString error; |
| 3497 | + | wxArrayString warnings; |
| 3498 | + | if(!g_gui.LoadVersion(g_gui.GetCurrentVersionID(), error, warnings, true)) { |
| 3499 | + | OutputDebugStringA("THE RITUAL HAS FAILED! FALLING BACK TO PLAN B!\n"); |
| 3500 | + | PaletteWindow* palette = dynamic_cast<PaletteWindow*>(g_gui.GetPalette()); |
| 3501 | + | if(palette) { |
| 3502 | + | OutputDebugStringA("COMMANDING THE PALETTE TO RECONSTRUCT ITSELF!\n"); |
| 3503 | + | palette->InvalidateContents(); |
| 3504 | + | palette->SelectPage(TILESET_DOODAD); |
| 3505 | + | g_gui.RefreshPalettes(); |
| 3506 | + | } |
| 3507 | + | } else { |
| 3508 | + | PaletteWindow* palette = dynamic_cast<PaletteWindow*>(g_gui.GetPalette()); |
| 3509 | + | if(palette) { |
| 3510 | + | palette->SelectPage(TILESET_DOODAD); |
| 3511 | + | g_gui.RefreshPalettes(); |
| 3512 | + | } |
| 3513 | + | } |
| 3514 | + | successDoodadDialog->EndModal(wxID_APPLY); |
| 3515 | + | }); |
| 3516 | + | |
| 3517 | + | doodadContinueButton->Bind(wxEVT_BUTTON, [&](wxCommandEvent&) { |
| 3518 | + | OutputDebugStringA("CONTINUING WITHOUT PALETTE REFRESH!\n"); |
| 3519 | + | successDoodadDialog->EndModal(wxID_OK); |
| 3520 | + | }); |
| 3521 | + | |
| 3522 | + | successDoodadDialog->ShowModal(); |
| 3523 | + | successDoodadDialog->Destroy(); |
| 3524 | + | } |
| 3525 | + | |
| 3526 | + | void MapCanvas::OnFindSimilarItems(wxCommandEvent& WXUNUSED(event)) { |
| 3527 | + | if (editor.selection.size() == 0) { |
| 3528 | + | return; |
| 3529 | + | } |
| 3530 | + | |
| 3531 | + | // Get the selected tile and items |
| 3532 | + | Tile* tile = editor.selection.getSelectedTile(); |
| 3533 | + | if (!tile) { |
| 3534 | + | return; |
| 3535 | + | } |
| 3536 | + | |
| 3537 | + | ItemVector selected_items = tile->getSelectedItems(); |
| 3538 | + | if (selected_items.empty()) { |
| 3539 | + | return; |
| 3540 | + | } |
| 3541 | + | |
| 3542 | + | // Create and configure the find dialog |
| 3543 | + | FindItemDialog* dialog = new FindItemDialog(g_gui.root, "Find Similar Items", false); |
| 3544 | + | |
| 3545 | + | if (selected_items.size() == 1) { |
| 3546 | + | // Single item selected - search by exact ID |
| 3547 | + | Item* item = selected_items[0]; |
| 3548 | + | dialog->setSearchMode(FindItemDialog::SearchMode::ServerIDs); |
| 3549 | + | |
| 3550 | + | // Set the server ID using the spin control |
| 3551 | + | if (wxSpinCtrl* server_id_spin = (wxSpinCtrl*)dialog->FindWindow(wxID_ANY)) { |
| 3552 | + | server_id_spin->SetValue(item->getID()); |
| 3553 | + | } |
| 3554 | + | } else { |
| 3555 | + | // Multiple items selected - use range search |
| 3556 | + | dialog->setSearchMode(FindItemDialog::SearchMode::ServerIDs); |
| 3557 | + | |
| 3558 | + | // Build range string from selected items |
| 3559 | + | std::ostringstream range; |
| 3560 | + | bool first = true; |
| 3561 | + | for (Item* item : selected_items) { |
| 3562 | + | if (!first) { |
| 3563 | + | range << ","; |
| 3564 | + | } |
| 3565 | + | range << item->getID(); |
| 3566 | + | first = false; |
| 3567 | + | } |
| 3568 | + | |
| 3569 | + | // Enable range searching |
| 3570 | + | if (wxCheckBox* use_range = (wxCheckBox*)dialog->FindWindow(wxID_ANY)) { |
| 3571 | + | use_range->SetValue(true); |
| 3572 | + | } |
| 3573 | + | |
| 3574 | + | // Set the range text |
| 3575 | + | if (wxTextCtrl* range_input = (wxTextCtrl*)dialog->FindWindow(wxID_ANY)) { |
| 3576 | + | range_input->SetValue(wxString(range.str())); |
| 3577 | + | } |
| 3578 | + | } |
| 3579 | + | |
| 3580 | + | // Show dialog |
| 3581 | + | dialog->ShowModal(); |
| 3582 | + | dialog->Destroy(); |
| 3583 | + | } |
| 3584 | + | |
| 3585 | + | void MapCanvas::OnGenerateIsland(wxCommandEvent& event) { |
| 3586 | + | // Get cursor position for island generation |
| 3587 | + | int map_x, map_y; |
| 3588 | + | MouseToMap(&map_x, &map_y); |
| 3589 | + | |
| 3590 | + | // Create and show the island generator dialog |
| 3591 | + | IslandGeneratorDialog dialog(this); |
| 3592 | + | |
| 3593 | + | // Set the initial position to the clicked location |
| 3594 | + | dialog.SetStartPosition(Position(map_x, map_y, floor)); |
| 3595 | + | |
| 3596 | + | dialog.ShowModal(); |
| 3597 | + | Refresh(); |
| 3598 | + | } |
| 3599 | + | |
| 3600 | + | void MapCanvas::OnCreateHouse(wxCommandEvent& event) { |
| 3601 | + | int start_map_x = last_click_map_x; |
| 3602 | + | int start_map_y = last_click_map_y; |
| 3603 | + | int current_floor = floor; |
| 3604 | + | |
| 3605 | + | if (start_map_x == -1 || start_map_y == -1) { |
| 3606 | + | g_gui.PopupDialog("Error", "You must click on a tile inside the house you want to create.", wxOK); |
| 3607 | + | return; |
| 3608 | + | } |
| 3609 | + | |
| 3610 | + | // Check if we're already on a house tile |
| 3611 | + | Tile* start_tile = editor.map.getTile(start_map_x, start_map_y, current_floor); |
| 3612 | + | if (start_tile && start_tile->isHouseTile()) { |
| 3613 | + | g_gui.PopupDialog("Warning", "This tile already belongs to a house. Please select a tile that doesn't belong to any house.", wxOK); |
| 3614 | + | return; |
| 3615 | + | } |
| 3616 | + | |
| 3617 | + | // Structure to hold detected house data by floor |
| 3618 | + | struct HouseFloorData { |
| 3619 | + | std::set<Position> wall_positions; |
| 3620 | + | std::set<Position> interior_positions; |
| 3621 | + | Position exit_pos; |
| 3622 | + | bool has_exit = false; |
| 3623 | + | }; |
| 3624 | + | |
| 3625 | + | std::map<int, HouseFloorData> house_floors; |
| 3626 | + | auto& current_floor_data = house_floors[current_floor]; |
| 3627 | + | |
| 3628 | + | // Step 1: First, detect the house from the clicked position |
| 3629 | + | // We'll look for walls in a small radius to determine if we're inside a house |
| 3630 | + | const int WALL_SEARCH_RADIUS = 10; |
| 3631 | + | bool found_wall = false; |
| 3632 | + | |
| 3633 | + | for (int r = 1; r <= WALL_SEARCH_RADIUS && !found_wall; r++) { |
| 3634 | + | for (int y = -r; y <= r; y++) { |
| 3635 | + | for (int x = -r; x <= r; x++) { |
| 3636 | + | // Only check perimeter |
| 3637 | + | if (std::abs(x) != r && std::abs(y) != r) continue; |
| 3638 | + | |
| 3639 | + | Position pos(start_map_x + x, start_map_y + y, current_floor); |
| 3640 | + | Tile* tile = editor.map.getTile(pos); |
| 3641 | + | |
| 3642 | + | if (tile && hasHouseWall(tile)) { |
| 3643 | + | found_wall = true; |
| 3644 | + | break; |
| 3645 | + | } |
| 3646 | + | } |
| 3647 | + | if (found_wall) break; |
| 3648 | + | } |
| 3649 | + | } |
| 3650 | + | |
| 3651 | + | if (!found_wall) { |
| 3652 | + | g_gui.PopupDialog("Error", "Could not find any walls near the selected position. Please click inside a house.", wxOK); |
| 3653 | + | return; |
| 3654 | + | } |
| 3655 | + | |
| 3656 | + | // Step 2: Find a door - it's likely that a house has at least one door |
| 3657 | + | Position door_pos; |
| 3658 | + | bool found_door = false; |
| 3659 | + | const int DOOR_SEARCH_RADIUS = 15; |
| 3660 | + | |
| 3661 | + | for (int r = 1; r <= DOOR_SEARCH_RADIUS && !found_door; r++) { |
| 3662 | + | for (int y = -r; y <= r; y++) { |
| 3663 | + | for (int x = -r; x <= r; x++) { |
| 3664 | + | // Only check perimeter |
| 3665 | + | if (std::abs(x) != r && std::abs(y) != r) continue; |
| 3666 | + | |
| 3667 | + | Position pos(start_map_x + x, start_map_y + y, current_floor); |
| 3668 | + | Tile* tile = editor.map.getTile(pos); |
| 3669 | + | |
| 3670 | + | if (tile && hasDoor(tile)) { |
| 3671 | + | door_pos = pos; |
| 3672 | + | found_door = true; |
| 3673 | + | break; |
| 3674 | + | } |
| 3675 | + | } |
| 3676 | + | if (found_door) break; |
| 3677 | + | } |
| 3678 | + | } |
| 3679 | + | |
| 3680 | + | // If no door is found, we'll just use the start position |
| 3681 | + | if (!found_door) { |
| 3682 | + | door_pos = Position(start_map_x, start_map_y, current_floor); |
| 3683 | + | } |
| 3684 | + | |
| 3685 | + | // Step 3: First pass - identify all walls |
| 3686 | + | std::set<Position> all_walls; |
| 3687 | + | std::queue<Position> wall_queue; |
| 3688 | + | |
| 3689 | + | // Begin by finding walls around the start position |
| 3690 | + | const int INITIAL_WALL_RADIUS = 3; |
| 3691 | + | for (int y = -INITIAL_WALL_RADIUS; y <= INITIAL_WALL_RADIUS; y++) { |
| 3692 | + | for (int x = -INITIAL_WALL_RADIUS; x <= INITIAL_WALL_RADIUS; x++) { |
| 3693 | + | Position pos(start_map_x + x, start_map_y + y, current_floor); |
| 3694 | + | Tile* tile = editor.map.getTile(pos); |
| 3695 | + | |
| 3696 | + | if (tile && hasHouseWall(tile)) { |
| 3697 | + | wall_queue.push(pos); |
| 3698 | + | all_walls.insert(pos); |
| 3699 | + | } |
| 3700 | + | } |
| 3701 | + | } |
| 3702 | + | |
| 3703 | + | // BFS to find all connected walls (limited depth to prevent crossing to adjacent houses) |
| 3704 | + | const int MAX_WALL_EXPANSION = 25; // Limit how far we expand from start |
| 3705 | + | std::set<Position> visited_walls; |
| 3706 | + | |
| 3707 | + | while (!wall_queue.empty()) { |
| 3708 | + | Position current = wall_queue.front(); |
| 3709 | + | wall_queue.pop(); |
| 3710 | + | |
| 3711 | + | if (visited_walls.count(current) > 0) continue; |
| 3712 | + | visited_walls.insert(current); |
| 3713 | + | |
| 3714 | + | current_floor_data.wall_positions.insert(current); |
| 3715 | + | |
| 3716 | + | // Check for door exits |
| 3717 | + | Tile* tile = editor.map.getTile(current); |
| 3718 | + | if (tile && hasDoor(tile)) { |
| 3719 | + | // Check outside the door |
| 3720 | + | const int dirs[4][2] = {{0,-1}, {1,0}, {0,1}, {-1,0}}; |
| 3721 | + | for (int d = 0; d < 4; d++) { |
| 3722 | + | Position exit_pos(current.x + dirs[d][0], current.y + dirs[d][1], current.z); |
| 3723 | + | Tile* exit_tile = editor.map.getTile(exit_pos); |
| 3724 | + | |
| 3725 | + | // Skip walls and existing house tiles |
| 3726 | + | if (!exit_tile || hasHouseWall(exit_tile) || exit_tile->isHouseTile()) continue; |
| 3727 | + | |
| 3728 | + | // Found a potential exit |
| 3729 | + | current_floor_data.exit_pos = exit_pos; |
| 3730 | + | current_floor_data.has_exit = true; |
| 3731 | + | break; |
| 3732 | + | } |
| 3733 | + | } |
| 3734 | + | |
| 3735 | + | // Only expand to nearby walls |
| 3736 | + | if (std::abs(current.x - start_map_x) <= MAX_WALL_EXPANSION && |
| 3737 | + | std::abs(current.y - start_map_y) <= MAX_WALL_EXPANSION) { |
| 3738 | + | |
| 3739 | + | // Check adjacent positions for more walls (including diagonals for better connectivity) |
| 3740 | + | for (int y = -1; y <= 1; y++) { |
| 3741 | + | for (int x = -1; x <= 1; x++) { |
| 3742 | + | if (x == 0 && y == 0) continue; |
| 3743 | + | |
| 3744 | + | Position next(current.x + x, current.y + y, current.z); |
| 3745 | + | |
| 3746 | + | // Only visit each wall once |
| 3747 | + | if (visited_walls.count(next) > 0) continue; |
| 3748 | + | |
| 3749 | + | Tile* next_tile = editor.map.getTile(next); |
| 3750 | + | if (next_tile && hasHouseWall(next_tile)) { |
| 3751 | + | wall_queue.push(next); |
| 3752 | + | } |
| 3753 | + | } |
| 3754 | + | } |
| 3755 | + | } |
| 3756 | + | } |
| 3757 | + | |
| 3758 | + | // Step 4: Calculate bounding box of house walls |
| 3759 | + | int min_x = std::numeric_limits<int>::max(); |
| 3760 | + | int min_y = std::numeric_limits<int>::max(); |
| 3761 | + | int max_x = std::numeric_limits<int>::min(); |
| 3762 | + | int max_y = std::numeric_limits<int>::min(); |
| 3763 | + | |
| 3764 | + | for (const Position& pos : current_floor_data.wall_positions) { |
| 3765 | + | min_x = std::min(min_x, pos.x); |
| 3766 | + | min_y = std::min(min_y, pos.y); |
| 3767 | + | max_x = std::max(max_x, pos.x); |
| 3768 | + | max_y = std::max(max_y, pos.y); |
| 3769 | + | } |
| 3770 | + | |
| 3771 | + | // Expand bounds slightly |
| 3772 | + | min_x = std::max(0, min_x - 1); |
| 3773 | + | min_y = std::max(0, min_y - 1); |
| 3774 | + | max_x = std::min(editor.map.getWidth(), max_x + 1); |
| 3775 | + | max_y = std::min(editor.map.getHeight(), max_y + 1); |
| 3776 | + | |
| 3777 | + | // Step 5: Flood fill interior from clicked position |
| 3778 | + | std::set<Position> visited_interior; |
| 3779 | + | std::queue<Position> interior_queue; |
| 3780 | + | |
| 3781 | + | // Start from the user's click position |
| 3782 | + | Position fill_start(start_map_x, start_map_y, current_floor); |
| 3783 | + | interior_queue.push(fill_start); |
| 3784 | + | |
| 3785 | + | while (!interior_queue.empty()) { |
| 3786 | + | Position current = interior_queue.front(); |
| 3787 | + | interior_queue.pop(); |
| 3788 | + | |
| 3789 | + | // Skip if outside bounds, already visited, or a wall |
| 3790 | + | if (current.x < min_x || current.x > max_x || |
| 3791 | + | current.y < min_y || current.y > max_y || |
| 3792 | + | visited_interior.count(current) > 0 || |
| 3793 | + | current_floor_data.wall_positions.count(current) > 0) { |
| 3794 | + | continue; |
| 3795 | + | } |
| 3796 | + | |
| 3797 | + | // Mark as visited |
| 3798 | + | visited_interior.insert(current); |
| 3799 | + | |
| 3800 | + | // For interior, we require being inside the wall boundary |
| 3801 | + | // Check if this position is inside using a smarter approach |
| 3802 | + | |
| 3803 | + | // Use a more reliable method to check if point is inside |
| 3804 | + | bool is_inside = true; |
| 3805 | + | |
| 3806 | + | // Cast rays in 8 directions to better detect enclosed spaces |
| 3807 | + | const int directions[8][2] = { |
| 3808 | + | {1, 0}, // right |
| 3809 | + | {-1, 0}, // left |
| 3810 | + | {0, 1}, // down |
| 3811 | + | {0, -1}, // up |
| 3812 | + | {1, 1}, // down-right |
| 3813 | + | {-1, -1}, // up-left |
| 3814 | + | {1, -1}, // up-right |
| 3815 | + | {-1, 1} // down-left |
| 3816 | + | }; |
| 3817 | + | |
| 3818 | + | int wall_hits = 0; |
| 3819 | + | for (int d = 0; d < 8; d++) { |
| 3820 | + | bool found_wall = false; |
| 3821 | + | int ray_dist = 0; |
| 3822 | + | int max_ray_dist = 2 * std::max(max_x - min_x, max_y - min_y); // Increase ray distance |
| 3823 | + | |
| 3824 | + | for (int dist = 1; dist <= max_ray_dist; dist++) { |
| 3825 | + | int ray_x = current.x + (directions[d][0] * dist); |
| 3826 | + | int ray_y = current.y + (directions[d][1] * dist); |
| 3827 | + | |
| 3828 | + | // Stop if we're outside the bounding box with larger margin |
| 3829 | + | if (ray_x < min_x - 5 || ray_x > max_x + 5 || ray_y < min_y - 5 || ray_y > max_y + 5) { |
| 3830 | + | break; |
| 3831 | + | } |
| 3832 | + | |
| 3833 | + | Position ray_pos(ray_x, ray_y, current.z); |
| 3834 | + | if (current_floor_data.wall_positions.count(ray_pos) > 0) { |
| 3835 | + | found_wall = true; |
| 3836 | + | ray_dist = dist; |
| 3837 | + | break; |
| 3838 | + | } |
| 3839 | + | } |
| 3840 | + | |
| 3841 | + | if (found_wall) { |
| 3842 | + | wall_hits++; |
| 3843 | + | } |
| 3844 | + | } |
| 3845 | + | |
| 3846 | + | // More permissive check - if we hit walls in at least 5 of 8 directions for diagonal rays |
| 3847 | + | // or at least 2 of 4 cardinal directions, consider it inside |
| 3848 | + | if (wall_hits >= 5 || ( |
| 3849 | + | (current_floor_data.wall_positions.count(Position(current.x + 1, current.y, current.z)) > 0 ? 1 : 0) + |
| 3850 | + | (current_floor_data.wall_positions.count(Position(current.x - 1, current.y, current.z)) > 0 ? 1 : 0) + |
| 3851 | + | (current_floor_data.wall_positions.count(Position(current.x, current.y + 1, current.z)) > 0 ? 1 : 0) + |
| 3852 | + | (current_floor_data.wall_positions.count(Position(current.x, current.y - 1, current.z)) > 0 ? 1 : 0) >= 2 |
| 3853 | + | )) { |
| 3854 | + | current_floor_data.interior_positions.insert(current); |
| 3855 | + | |
| 3856 | + | // Use only cardinal directions (4-way) for expanding the fill |
| 3857 | + | const int fillDirections[4][2] = { |
| 3858 | + | {1, 0}, {-1, 0}, {0, 1}, {0, -1} |
| 3859 | + | }; |
| 3860 | + | |
| 3861 | + | // Add neighboring tiles |
| 3862 | + | for (int d = 0; d < 4; d++) { |
| 3863 | + | Position next(current.x + fillDirections[d][0], |
| 3864 | + | current.y + fillDirections[d][1], |
| 3865 | + | current.z); |
| 3866 | + | |
| 3867 | + | // Only queue if we haven't visited and it's not a wall |
| 3868 | + | if (visited_interior.count(next) == 0 && |
| 3869 | + | current_floor_data.wall_positions.count(next) == 0) { |
| 3870 | + | interior_queue.push(next); |
| 3871 | + | } |
| 3872 | + | } |
| 3873 | + | } |
| 3874 | + | } |
| 3875 | + | |
| 3876 | + | // Step 6: Check for floors above and below (expanded to handle multiple floors) |
| 3877 | + | std::set<int> processed_floors; |
| 3878 | + | processed_floors.insert(current_floor); |
| 3879 | + | std::queue<int> floors_to_check; |
| 3880 | + | |
| 3881 | + | // First add adjacent floors |
| 3882 | + | if (current_floor - 1 >= 0) floors_to_check.push(current_floor - 1); |
| 3883 | + | if (current_floor + 1 < MAP_LAYERS) floors_to_check.push(current_floor + 1); |
| 3884 | + | |
| 3885 | + | // Process floors in queue and potentially add more |
| 3886 | + | while (!floors_to_check.empty()) { |
| 3887 | + | int check_floor = floors_to_check.front(); |
| 3888 | + | floors_to_check.pop(); |
| 3889 | + | |
| 3890 | + | // Skip if already processed or outside valid range |
| 3891 | + | if (processed_floors.count(check_floor) > 0 || check_floor < 0 || check_floor >= MAP_LAYERS) |
| 3892 | + | continue; |
| 3893 | + | |
| 3894 | + | processed_floors.insert(check_floor); |
| 3895 | + | auto& floor_data = house_floors[check_floor]; |
| 3896 | + | |
| 3897 | + | // Connect via walls/stairs from already processed floors |
| 3898 | + | bool floor_connected = false; |
| 3899 | + | |
| 3900 | + | // Try to find connections from any previously processed floor |
| 3901 | + | for (int processed_floor : processed_floors) { |
| 3902 | + | if (processed_floor == check_floor) continue; |
| 3903 | + | |
| 3904 | + | Position stair_pos; |
| 3905 | + | bool found_stair_connection = false; |
| 3906 | + | |
| 3907 | + | // Check for stair connections only if floors are not adjacent |
| 3908 | + | if (std::abs(processed_floor - check_floor) > 1) { |
| 3909 | + | // Look for stairs in the processed floor |
| 3910 | + | for (const Position& pos : house_floors[processed_floor].interior_positions) { |
| 3911 | + | Position check_stair_pos(pos.x, pos.y, processed_floor); |
| 3912 | + | Tile* tile = editor.map.getTile(check_stair_pos); |
| 3913 | + | |
| 3914 | + | if (tile && hasStairsOrLadder(tile)) { |
| 3915 | + | // Check if there's a corresponding stair/ladder on target floor |
| 3916 | + | Position target_stair_pos(pos.x, pos.y, check_floor); |
| 3917 | + | Tile* target_tile = editor.map.getTile(target_stair_pos); |
| 3918 | + | |
| 3919 | + | if (target_tile && hasStairsOrLadder(target_tile)) { |
| 3920 | + | found_stair_connection = true; |
| 3921 | + | stair_pos = target_stair_pos; |
| 3922 | + | break; |
| 3923 | + | } |
| 3924 | + | } |
| 3925 | + | } |
| 3926 | + | |
| 3927 | + | if (found_stair_connection) { |
| 3928 | + | floor_connected = true; |
| 3929 | + | // Start wall and interior detection from stair position |
| 3930 | + | Position start_point = stair_pos; |
| 3931 | + | |
| 3932 | + | // Find walls around stair position |
| 3933 | + | std::set<Position> floor_visited_walls; |
| 3934 | + | std::queue<Position> floor_wall_queue; |
| 3935 | + | |
| 3936 | + | for (int y = -2; y <= 2; y++) { |
| 3937 | + | for (int x = -2; x <= 2; x++) { |
| 3938 | + | Position pos(start_point.x + x, start_point.y + y, check_floor); |
| 3939 | + | Tile* tile = editor.map.getTile(pos); |
| 3940 | + | |
| 3941 | + | if (tile && hasHouseWall(tile)) { |
| 3942 | + | floor_wall_queue.push(pos); |
| 3943 | + | break; |
| 3944 | + | } |
| 3945 | + | } |
| 3946 | + | if (!floor_wall_queue.empty()) break; |
| 3947 | + | } |
| 3948 | + | |
| 3949 | + | // If no walls found near stairs, just use the stair position |
| 3950 | + | if (floor_wall_queue.empty()) { |
| 3951 | + | floor_wall_queue.push(start_point); |
| 3952 | + | } |
| 3953 | + | |
| 3954 | + | // Continue with wall detection... |
| 3955 | + | // Rest of code similar to the original detection for other floors |
| 3956 | + | } |
| 3957 | + | } else { |
| 3958 | + | // For adjacent floors, use wall matching as before |
| 3959 | + | for (const Position& wall_pos : house_floors[processed_floor].wall_positions) { |
| 3960 | + | Position check_pos(wall_pos.x, wall_pos.y, check_floor); |
| 3961 | + | Tile* tile = editor.map.getTile(check_pos); |
| 3962 | + | |
| 3963 | + | if (tile && hasHouseWall(tile)) { |
| 3964 | + | floor_connected = true; |
| 3965 | + | Position start_point = check_pos; |
| 3966 | + | |
| 3967 | + | // Find walls |
| 3968 | + | std::set<Position> floor_visited_walls; |
| 3969 | + | std::queue<Position> floor_wall_queue; |
| 3970 | + | floor_wall_queue.push(start_point); |
| 3971 | + | |
| 3972 | + | while (!floor_wall_queue.empty()) { |
| 3973 | + | Position current = floor_wall_queue.front(); |
| 3974 | + | floor_wall_queue.pop(); |
| 3975 | + | |
| 3976 | + | if (floor_visited_walls.count(current) > 0) continue; |
| 3977 | + | floor_visited_walls.insert(current); |
| 3978 | + | |
| 3979 | + | floor_data.wall_positions.insert(current); |
| 3980 | + | |
| 3981 | + | // Check for door exits |
| 3982 | + | Tile* tile = editor.map.getTile(current); |
| 3983 | + | if (tile && hasDoor(tile)) { |
| 3984 | + | // Check outside the door |
| 3985 | + | const int dirs[4][2] = {{0,-1}, {1,0}, {0,1}, {-1,0}}; |
| 3986 | + | for (int d = 0; d < 4; d++) { |
| 3987 | + | Position exit_pos(current.x + dirs[d][0], current.y + dirs[d][1], current.z); |
| 3988 | + | Tile* exit_tile = editor.map.getTile(exit_pos); |
| 3989 | + | |
| 3990 | + | if (!exit_tile || hasHouseWall(exit_tile) || exit_tile->isHouseTile()) continue; |
| 3991 | + | |
| 3992 | + | floor_data.exit_pos = exit_pos; |
| 3993 | + | floor_data.has_exit = true; |
| 3994 | + | break; |
| 3995 | + | } |
| 3996 | + | } |
| 3997 | + | |
| 3998 | + | // Only expand within the same bounds as the current floor |
| 3999 | + | if (current.x >= min_x && current.x <= max_x && |
| 4000 | + | current.y >= min_y && current.y <= max_y) { |
| 4001 | + | |
| 4002 | + | for (int y = -1; y <= 1; y++) { |
| 4003 | + | for (int x = -1; x <= 1; x++) { |
| 4004 | + | if (x == 0 && y == 0) continue; |
| 4005 | + | |
| 4006 | + | Position next(current.x + x, current.y + y, current.z); |
| 4007 | + | |
| 4008 | + | if (floor_visited_walls.count(next) > 0) continue; |
| 4009 | + | |
| 4010 | + | Tile* next_tile = editor.map.getTile(next); |
| 4011 | + | if (next_tile && hasHouseWall(next_tile)) { |
| 4012 | + | floor_wall_queue.push(next); |
| 4013 | + | } |
| 4014 | + | } |
| 4015 | + | } |
| 4016 | + | } |
| 4017 | + | } |
| 4018 | + | |
| 4019 | + | // Find interior |
| 4020 | + | std::set<Position> floor_visited_interior; |
| 4021 | + | std::queue<Position> floor_interior_queue; |
| 4022 | + | |
| 4023 | + | // Try to find a good interior starting point |
| 4024 | + | Position floor_fill_start; |
| 4025 | + | bool found_interior_start = false; |
| 4026 | + | |
| 4027 | + | // First try to match with a stair position from the previous floor |
| 4028 | + | for (const Position& interior_pos : house_floors[processed_floor].interior_positions) { |
| 4029 | + | Position check_pos(interior_pos.x, interior_pos.y, check_floor); |
| 4030 | + | Tile* tile = editor.map.getTile(check_pos); |
| 4031 | + | |
| 4032 | + | if (tile && !hasHouseWall(tile)) { |
| 4033 | + | // If there's a stair here, this is an ideal starting point |
| 4034 | + | if (hasStairsOrLadder(tile)) { |
| 4035 | + | floor_fill_start = check_pos; |
| 4036 | + | found_interior_start = true; |
| 4037 | + | break; |
| 4038 | + | } |
| 4039 | + | |
| 4040 | + | // Otherwise remember this as a potential start |
| 4041 | + | if (!found_interior_start) { |
| 4042 | + | floor_fill_start = check_pos; |
| 4043 | + | found_interior_start = true; |
| 4044 | + | } |
| 4045 | + | } |
| 4046 | + | } |
| 4047 | + | |
| 4048 | + | // If we didn't find a good start point, use same x,y as original start |
| 4049 | + | if (!found_interior_start) { |
| 4050 | + | floor_fill_start = Position(start_map_x, start_map_y, check_floor); |
| 4051 | + | } |
| 4052 | + | |
| 4053 | + | Tile* start_floor_tile = editor.map.getTile(floor_fill_start); |
| 4054 | + | if (start_floor_tile && !hasHouseWall(start_floor_tile)) { |
| 4055 | + | floor_interior_queue.push(floor_fill_start); |
| 4056 | + | |
| 4057 | + | // Similar interior flood fill as before... |
| 4058 | + | while (!floor_interior_queue.empty()) { |
| 4059 | + | Position current = floor_interior_queue.front(); |
| 4060 | + | floor_interior_queue.pop(); |
| 4061 | + | |
| 4062 | + | if (current.x < min_x || current.x > max_x || |
| 4063 | + | current.y < min_y || current.y > max_y || |
| 4064 | + | floor_visited_interior.count(current) > 0 || |
| 4065 | + | floor_data.wall_positions.count(current) > 0) { |
| 4066 | + | continue; |
| 4067 | + | } |
| 4068 | + | |
| 4069 | + | floor_visited_interior.insert(current); |
| 4070 | + | |
| 4071 | + | // Cast rays to check if inside |
| 4072 | + | int wall_hits = 0; |
| 4073 | + | // Define directions array |
| 4074 | + | const int directions[8][2] = { |
| 4075 | + | {1, 0}, // right |
| 4076 | + | {-1, 0}, // left |
| 4077 | + | {0, 1}, // down |
| 4078 | + | {0, -1}, // up |
| 4079 | + | {1, 1}, // down-right |
| 4080 | + | {-1, -1}, // up-left |
| 4081 | + | {1, -1}, // up-right |
| 4082 | + | {-1, 1} // down-left |
| 4083 | + | }; |
| 4084 | + | |
| 4085 | + | for (int d = 0; d < 8; d++) { |
| 4086 | + | bool found_wall = false; |
| 4087 | + | int max_ray_dist = 2 * std::max(max_x - min_x, max_y - min_y); |
| 4088 | + | |
| 4089 | + | for (int dist = 1; dist <= max_ray_dist; dist++) { |
| 4090 | + | int ray_x = current.x + (directions[d][0] * dist); |
| 4091 | + | int ray_y = current.y + (directions[d][1] * dist); |
| 4092 | + | |
| 4093 | + | if (ray_x < min_x - 5 || ray_x > max_x + 5 || ray_y < min_y - 5 || ray_y > max_y + 5) { |
| 4094 | + | break; |
| 4095 | + | } |
| 4096 | + | |
| 4097 | + | Position ray_pos(ray_x, ray_y, current.z); |
| 4098 | + | if (floor_data.wall_positions.count(ray_pos) > 0) { |
| 4099 | + | found_wall = true; |
| 4100 | + | break; |
| 4101 | + | } |
| 4102 | + | } |
| 4103 | + | |
| 4104 | + | if (found_wall) { |
| 4105 | + | wall_hits++; |
| 4106 | + | } |
| 4107 | + | } |
| 4108 | + | |
| 4109 | + | // More permissive check - if we hit walls in at least 5 of 8 directions for diagonal rays |
| 4110 | + | // or at least 2 of 4 cardinal directions, consider it inside |
| 4111 | + | if (wall_hits >= 5 || ( |
| 4112 | + | (floor_data.wall_positions.count(Position(current.x + 1, current.y, current.z)) > 0 ? 1 : 0) + |
| 4113 | + | (floor_data.wall_positions.count(Position(current.x - 1, current.y, current.z)) > 0 ? 1 : 0) + |
| 4114 | + | (floor_data.wall_positions.count(Position(current.x, current.y + 1, current.z)) > 0 ? 1 : 0) + |
| 4115 | + | (floor_data.wall_positions.count(Position(current.x, current.y - 1, current.z)) > 0 ? 1 : 0) >= 2 |
| 4116 | + | )) { |
| 4117 | + | floor_data.interior_positions.insert(current); |
| 4118 | + | |
| 4119 | + | // Define directions array for neighbors - use only cardinal directions for expansion |
| 4120 | + | const int fillDirections[4][2] = { |
| 4121 | + | {1, 0}, // right |
| 4122 | + | {-1, 0}, // left |
| 4123 | + | {0, 1}, // down |
| 4124 | + | {0, -1} // up |
| 4125 | + | }; |
| 4126 | + | |
| 4127 | + | for (int d = 0; d < 4; d++) { |
| 4128 | + | Position next(current.x + fillDirections[d][0], |
| 4129 | + | current.y + fillDirections[d][1], |
| 4130 | + | current.z); |
| 4131 | + | |
| 4132 | + | // Only queue if we haven't visited and it's not a wall |
| 4133 | + | if (floor_visited_interior.count(next) == 0 && |
| 4134 | + | floor_data.wall_positions.count(next) == 0) { |
| 4135 | + | floor_interior_queue.push(next); |
| 4136 | + | } |
| 4137 | + | } |
| 4138 | + | } |
| 4139 | + | } |
| 4140 | + | } |
| 4141 | + | break; // Found a connection, no need to check more walls |
| 4142 | + | } |
| 4143 | + | } |
| 4144 | + | } |
| 4145 | + | |
| 4146 | + | if (floor_connected) { |
| 4147 | + | // Once we connect a floor, check for floors above and below that one as well |
| 4148 | + | if (check_floor - 1 >= 0 && processed_floors.count(check_floor - 1) == 0) |
| 4149 | + | floors_to_check.push(check_floor - 1); |
| 4150 | + | if (check_floor + 1 < MAP_LAYERS && processed_floors.count(check_floor + 1) == 0) |
| 4151 | + | floors_to_check.push(check_floor + 1); |
| 4152 | + | break; |
| 4153 | + | } |
| 4154 | + | } |
| 4155 | + | } |
| 4156 | + | |
| 4157 | + | // Step 7: Create the house |
| 4158 | + | std::set<Position> all_house_tiles; |
| 4159 | + | int total_floors = 0; |
| 4160 | + | int total_tiles = 0; |
| 4161 | + | Position exit_position(0, 0, 0); |
| 4162 | + | |
| 4163 | + | // Add a second pass of aggressive fill for enclosed rooms |
| 4164 | + | for (auto& [floor_z, floor_data] : house_floors) { |
| 4165 | + | if (!floor_data.wall_positions.empty()) { |
| 4166 | + | // Find min/max bounds for this floor |
| 4167 | + | int local_min_x = std::numeric_limits<int>::max(); |
| 4168 | + | int local_min_y = std::numeric_limits<int>::max(); |
| 4169 | + | int local_max_x = std::numeric_limits<int>::min(); |
| 4170 | + | int local_max_y = std::numeric_limits<int>::min(); |
| 4171 | + | |
| 4172 | + | for (const Position& pos : floor_data.wall_positions) { |
| 4173 | + | local_min_x = std::min(local_min_x, pos.x); |
| 4174 | + | local_min_y = std::min(local_min_y, pos.y); |
| 4175 | + | local_max_x = std::max(local_max_x, pos.x); |
| 4176 | + | local_max_y = std::max(local_max_y, pos.y); |
| 4177 | + | } |
| 4178 | + | |
| 4179 | + | // Expand bounds slightly inward for safety |
| 4180 | + | local_min_x = local_min_x + 1; |
| 4181 | + | local_min_y = local_min_y + 1; |
| 4182 | + | local_max_x = local_max_x - 1; |
| 4183 | + | local_max_y = local_max_y - 1; |
| 4184 | + | |
| 4185 | + | // Create a map of enclosed cells |
| 4186 | + | std::vector<std::vector<bool>> enclosed_map(local_max_y - local_min_y + 3, |
| 4187 | + | std::vector<bool>(local_max_x - local_min_x + 3, false)); |
| 4188 | + | |
| 4189 | + | // Mark all wall positions on the map |
| 4190 | + | for (const Position& wall : floor_data.wall_positions) { |
| 4191 | + | int map_x = wall.x - local_min_x + 1; |
| 4192 | + | int map_y = wall.y - local_min_y + 1; |
| 4193 | + | |
| 4194 | + | if (map_x >= 0 && map_y >= 0 && |
| 4195 | + | map_x < enclosed_map[0].size() && map_y < enclosed_map.size()) { |
| 4196 | + | enclosed_map[map_y][map_x] = true; |
| 4197 | + | } |
| 4198 | + | } |
| 4199 | + | |
| 4200 | + | // Do a simple flood fill from outside to mark external cells |
| 4201 | + | std::vector<std::vector<bool>> external(enclosed_map.size(), |
| 4202 | + | std::vector<bool>(enclosed_map[0].size(), false)); |
| 4203 | + | std::queue<std::pair<int, int>> fill_queue; |
| 4204 | + | |
| 4205 | + | // Add border points |
| 4206 | + | for (int y = 0; y < enclosed_map.size(); y++) { |
| 4207 | + | fill_queue.push({0, y}); |
| 4208 | + | fill_queue.push({enclosed_map[0].size() - 1, y}); |
| 4209 | + | } |
| 4210 | + | for (int x = 0; x < enclosed_map[0].size(); x++) { |
| 4211 | + | fill_queue.push({x, 0}); |
| 4212 | + | fill_queue.push({x, enclosed_map.size() - 1}); |
| 4213 | + | } |
| 4214 | + | |
| 4215 | + | while (!fill_queue.empty()) { |
| 4216 | + | auto [x, y] = fill_queue.front(); |
| 4217 | + | fill_queue.pop(); |
| 4218 | + | |
| 4219 | + | if (x < 0 || y < 0 || x >= enclosed_map[0].size() || y >= enclosed_map.size() || |
| 4220 | + | external[y][x] || enclosed_map[y][x]) { |
| 4221 | + | continue; |
| 4222 | + | } |
| 4223 | + | |
| 4224 | + | external[y][x] = true; |
| 4225 | + | |
| 4226 | + | fill_queue.push({x+1, y}); |
| 4227 | + | fill_queue.push({x-1, y}); |
| 4228 | + | fill_queue.push({x, y+1}); |
| 4229 | + | fill_queue.push({x, y-1}); |
| 4230 | + | } |
| 4231 | + | |
| 4232 | + | // Any cell not marked as external and not a wall is internal |
| 4233 | + | for (int y = 1; y < enclosed_map.size()-1; y++) { |
| 4234 | + | for (int x = 1; x < enclosed_map[0].size()-1; x++) { |
| 4235 | + | if (!enclosed_map[y][x] && !external[y][x]) { |
| 4236 | + | Position interior_pos(x + local_min_x - 1, y + local_min_y - 1, floor_z); |
| 4237 | + | floor_data.interior_positions.insert(interior_pos); |
| 4238 | + | } |
| 4239 | + | } |
| 4240 | + | } |
| 4241 | + | } |
| 4242 | + | } |
| 4243 | + | |
| 4244 | + | // Now assemble all house tiles |
| 4245 | + | for (const auto& [floor_z, floor_data] : house_floors) { |
| 4246 | + | if (!floor_data.wall_positions.empty() || !floor_data.interior_positions.empty()) { |
| 4247 | + | total_floors++; |
| 4248 | + | |
| 4249 | + | // Add walls |
| 4250 | + | all_house_tiles.insert(floor_data.wall_positions.begin(), floor_data.wall_positions.end()); |
| 4251 | + | total_tiles += floor_data.wall_positions.size(); |
| 4252 | + | |
| 4253 | + | // Add interior |
| 4254 | + | all_house_tiles.insert(floor_data.interior_positions.begin(), floor_data.interior_positions.end()); |
| 4255 | + | total_tiles += floor_data.interior_positions.size(); |
| 4256 | + | |
| 4257 | + | // Store exit if found |
| 4258 | + | if (floor_data.has_exit) { |
| 4259 | + | exit_position = floor_data.exit_pos; |
| 4260 | + | } |
| 4261 | + | } |
| 4262 | + | } |
| 4263 | + | |
| 4264 | + | if (all_house_tiles.empty() || total_tiles < 4) { |
| 4265 | + | g_gui.PopupDialog("Error", "Could not detect any valid house area. Please ensure you clicked inside a house with proper walls.", wxOK); |
| 4266 | + | return; |
| 4267 | + | } |
| 4268 | + | |
| 4269 | + | // Create house dialog |
| 4270 | + | wxDialog* dialog = new wxDialog(this, wxID_ANY, "Create House", wxDefaultPosition, wxSize(300, 200)); |
| 4271 | + | wxBoxSizer* topsizer = new wxBoxSizer(wxVERTICAL); |
| 4272 | + | |
| 4273 | + | // House name |
| 4274 | + | wxBoxSizer* name_sizer = new wxBoxSizer(wxHORIZONTAL); |
| 4275 | + | name_sizer->Add(new wxStaticText(dialog, wxID_ANY, "Name:"), 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 5); |
| 4276 | + | wxTextCtrl* name_field = new wxTextCtrl(dialog, wxID_ANY, "New House"); |
| 4277 | + | name_sizer->Add(name_field, 1, wxEXPAND); |
| 4278 | + | topsizer->Add(name_sizer, 0, wxEXPAND | wxALL, 5); |
| 4279 | + | |
| 4280 | + | // Town selection |
| 4281 | + | wxBoxSizer* town_sizer = new wxBoxSizer(wxHORIZONTAL); |
| 4282 | + | town_sizer->Add(new wxStaticText(dialog, wxID_ANY, "Town:"), 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 5); |
| 4283 | + | wxChoice* town_field = new wxChoice(dialog, wxID_ANY); |
| 4284 | + | |
| 4285 | + | const Towns& towns = editor.map.towns; |
| 4286 | + | if (towns.count() > 0) { |
| 4287 | + | for (TownMap::const_iterator town_iter = towns.begin(); |
| 4288 | + | town_iter != towns.end(); ++town_iter) { |
| 4289 | + | town_field->Append(wxstr(town_iter->second->getName()), |
| 4290 | + | (void*)(intptr_t)town_iter->second->getID()); |
| 4291 | + | } |
| 4292 | + | town_field->SetSelection(0); |
| 4293 | + | } else { |
| 4294 | + | town_field->Append("No towns available"); |
| 4295 | + | town_field->Enable(false); |
| 4296 | + | } |
| 4297 | + | |
| 4298 | + | town_sizer->Add(town_field, 1, wxEXPAND); |
| 4299 | + | topsizer->Add(town_sizer, 0, wxEXPAND | wxALL, 5); |
| 4300 | + | |
| 4301 | + | // Rent |
| 4302 | + | wxBoxSizer* rent_sizer = new wxBoxSizer(wxHORIZONTAL); |
| 4303 | + | rent_sizer->Add(new wxStaticText(dialog, wxID_ANY, "Rent:"), 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 5); |
| 4304 | + | wxSpinCtrl* rent_field = new wxSpinCtrl(dialog, wxID_ANY, "0", |
| 4305 | + | wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 0, 100000, 0); |
| 4306 | + | rent_sizer->Add(rent_field, 1, wxEXPAND); |
| 4307 | + | topsizer->Add(rent_sizer, 0, wxEXPAND | wxALL, 5); |
| 4308 | + | |
| 4309 | + | // Guildhall checkbox |
| 4310 | + | wxCheckBox* guildhall_field = new wxCheckBox(dialog, wxID_ANY, "Guildhall"); |
| 4311 | + | topsizer->Add(guildhall_field, 0, wxEXPAND | wxALL, 5); |
| 4312 | + | |
| 4313 | + | // Size and floor info display |
| 4314 | + | wxBoxSizer* info_sizer = new wxBoxSizer(wxHORIZONTAL); |
| 4315 | + | info_sizer->Add(new wxStaticText(dialog, wxID_ANY, |
| 4316 | + | wxString::Format("Size: %d tiles on %d floors", total_tiles, total_floors)), |
| 4317 | + | 1, wxEXPAND); |
| 4318 | + | topsizer->Add(info_sizer, 0, wxEXPAND | wxALL, 5); |
| 4319 | + | |
| 4320 | + | // Dialog buttons |
| 4321 | + | wxStdDialogButtonSizer* buttons = new wxStdDialogButtonSizer(); |
| 4322 | + | buttons->AddButton(new wxButton(dialog, wxID_OK, "OK")); |
| 4323 | + | buttons->AddButton(new wxButton(dialog, wxID_CANCEL, "Cancel")); |
| 4324 | + | buttons->Realize(); |
| 4325 | + | topsizer->Add(buttons, 0, wxALIGN_CENTER | wxALL, 5); |
| 4326 | + | |
| 4327 | + | dialog->SetSizer(topsizer); |
| 4328 | + | topsizer->Fit(dialog); |
| 4329 | + | |
| 4330 | + | if (dialog->ShowModal() == wxID_OK) { |
| 4331 | + | // Create new house |
| 4332 | + | House* house = new House(editor.map); |
| 4333 | + | house->name = nstr(name_field->GetValue()); |
| 4334 | + | |
| 4335 | + | if (towns.count() > 0) { |
| 4336 | + | int sel = town_field->GetSelection(); |
| 4337 | + | if (sel != wxNOT_FOUND) { |
| 4338 | + | house->townid = (uint32_t)(intptr_t)town_field->GetClientData(sel); |
| 4339 | + | } |
| 4340 | + | } |
| 4341 | + | |
| 4342 | + | house->rent = rent_field->GetValue(); |
| 4343 | + | house->guildhall = guildhall_field->GetValue(); |
| 4344 | + | |
| 4345 | + | // Add house to map |
| 4346 | + | house->setID(editor.map.houses.getEmptyID()); |
| 4347 | + | editor.map.houses.addHouse(house); |
| 4348 | + | |
| 4349 | + | // Add all tiles to house |
| 4350 | + | for (const Position& pos : all_house_tiles) { |
| 4351 | + | Tile* tile = editor.map.getTile(pos); |
| 4352 | + | if (!tile) { |
| 4353 | + | tile = editor.map.createTile(pos.x, pos.y, pos.z); |
| 4354 | + | } |
| 4355 | + | house->addTile(tile); |
| 4356 | + | } |
| 4357 | + | |
| 4358 | + | // Set exit position |
| 4359 | + | if (exit_position != Position(0, 0, 0)) { |
| 4360 | + | house->setExit(exit_position); |
| 4361 | + | } |
| 4362 | + | |
| 4363 | + | g_gui.PopupDialog("Success", |
| 4364 | + | wxString::Format("Created house '%s' with %d tiles on %d floors.", |
| 4365 | + | wxstr(house->name).c_str(), total_tiles, total_floors), wxOK); |
| 4366 | + | |
| 4367 | + | editor.map.doChange(); |
| 4368 | + | } |
| 4369 | + | |
| 4370 | + | dialog->Destroy(); |
| 4371 | + | Refresh(); |
| 4372 | + | } |
| 4373 | + | |
| 4374 | + | // Helper function to check if a tile has house walls or blocking items |
| 4375 | + | bool MapCanvas::hasHouseWall(Tile* tile) { |
| 4376 | + | if (!tile) return false; |
| 4377 | + | |
| 4378 | + | for (Item* item : tile->items) { |
| 4379 | + | if (!item) continue; |
| 4380 | + | |
| 4381 | + | // Direct checks for brush properties - most reliable |
| 4382 | + | if (item->getWallBrush() || item->isDoor() || item->isBrushDoor()) { |
| 4383 | + | return true; |
| 4384 | + | } |
| 4385 | + | |
| 4386 | + | // Name-based identification for common boundary elements |
| 4387 | + | const std::string& name = item->getName(); |
| 4388 | + | std::string lowerName = name; |
| 4389 | + | std::transform(lowerName.begin(), lowerName.end(), lowerName.begin(), ::tolower); |
| 4390 | + | |
| 4391 | + | // Only use specific wall-related terms |
| 4392 | + | if (lowerName.find("wall") != std::string::npos || |
| 4393 | + | lowerName.find("door") != std::string::npos || |
| 4394 | + | lowerName.find("window") != std::string::npos || |
| 4395 | + | lowerName.find("fence") != std::string::npos || |
| 4396 | + | lowerName.find("gate") != std::string::npos || |
| 4397 | + | lowerName.find("rail") != std::string::npos || |
| 4398 | + | lowerName.find("pillar") != std::string::npos || |
| 4399 | + | lowerName.find("archway") != std::string::npos) { |
| 4400 | + | return true; |
| 4401 | + | } |
| 4402 | + | } |
| 4403 | + | |
| 4404 | + | return false; |
| 4405 | + | } |
| 4406 | + | |
| 4407 | + | |
| 4408 | + | // Check if tile has a door |
| 4409 | + | bool MapCanvas::hasDoor(Tile* tile) { |
| 4410 | + | if (!tile) return false; |
| 4411 | + | |
| 4412 | + | for (Item* item : tile->items) { |
| 4413 | + | if (!item) continue; |
| 4414 | + | |
| 4415 | + | if (item->isDoor() || item->isBrushDoor()) { |
| 4416 | + | return true; |
| 4417 | + | } |
| 4418 | + | |
| 4419 | + | const std::string& name = item->getName(); |
| 4420 | + | std::string lowerName = name; |
| 4421 | + | std::transform(lowerName.begin(), lowerName.end(), lowerName.begin(), ::tolower); |
| 4422 | + | |
| 4423 | + | if (lowerName.find("door") != std::string::npos || |
| 4424 | + | lowerName.find("gate") != std::string::npos) { |
| 4425 | + | return true; |
| 4426 | + | } |
| 4427 | + | } |
| 4428 | + | |
| 4429 | + | return false; |
| 4430 | + | } |
| 4431 | + | |
| 4432 | + | // Check if tile has stairs or a ladder |
| 4433 | + | bool MapCanvas::hasStairsOrLadder(Tile* tile) { |
| 4434 | + | // Check if the tile is null |
| 4435 | + | if (!tile) return false; |
| 4436 | + | |
| 4437 | + | // First pass: check for obviously visible stairs/ladders |
| 4438 | + | for (Item* item : tile->items) { |
| 4439 | + | if (!item) continue; |
| 4440 | + | |
| 4441 | + | // Check special types of stairs and ladders |
| 4442 | + | if (item->isStairs() || item->isLadder()) { |
| 4443 | + | return true; |
| 4444 | + | } |
| 4445 | + | |
| 4446 | + | // Check names for various stair and ladder types |
| 4447 | + | std::string lowerName = item->getName(); |
| 4448 | + | std::transform(lowerName.begin(), lowerName.end(), lowerName.begin(), ::tolower); |
| 4449 | + | |
| 4450 | + | if (lowerName.find("stair") != std::string::npos || |
| 4451 | + | lowerName.find("ladder") != std::string::npos || |
| 4452 | + | lowerName.find("ramp") != std::string::npos || |
| 4453 | + | lowerName.find("elevator") != std::string::npos || |
| 4454 | + | lowerName.find("escalator") != std::string::npos) { |
| 4455 | + | return true; |
| 4456 | + | } |
| 4457 | + | } |
| 4458 | + | |
| 4459 | + | // Second pass: check for railings that might be on top of stairs |
| 4460 | + | bool has_railing = false; |
| 4461 | + | for (Item* item : tile->items) { |
| 4462 | + | if (!item) continue; |
| 4463 | + | |
| 4464 | + | std::string lowerName = item->getName(); |
| 4465 | + | std::transform(lowerName.begin(), lowerName.end(), lowerName.begin(), ::tolower); |
| 4466 | + | |
| 4467 | + | if (lowerName.find("rail") != std::string::npos) { |
| 4468 | + | has_railing = true; |
| 4469 | + | break; |
| 4470 | + | } |
| 4471 | + | } |
| 4472 | + | |
| 4473 | + | // If we found a railing, we need to check the floor below for stairs |
| 4474 | + | if (has_railing && tile->getPosition().z > 0) { |
| 4475 | + | Position pos_below(tile->getPosition().x, tile->getPosition().y, tile->getPosition().z - 1); |
| 4476 | + | Tile* tile_below = editor.map.getTile(pos_below); |
| 4477 | + | |
| 4478 | + | if (tile_below) { |
| 4479 | + | for (Item* item : tile_below->items) { |
| 4480 | + | if (!item) continue; |
| 4481 | + | |
| 4482 | + | if (item->isStairs() || item->isLadder()) { |
| 4483 | + | return true; |
| 4484 | + | } |
| 4485 | + | |
| 4486 | + | std::string lowerName = item->getName(); |
| 4487 | + | std::transform(lowerName.begin(), lowerName.end(), lowerName.begin(), ::tolower); |
| 4488 | + | |
| 4489 | + | if (lowerName.find("stair") != std::string::npos || |
| 4490 | + | lowerName.find("ladder") != std::string::npos || |
| 4491 | + | lowerName.find("ramp") != std::string::npos) { |
| 4492 | + | return true; |
| 4493 | + | } |
| 4494 | + | } |
| 4495 | + | } |
| 4496 | + | } |
| 4497 | + | |
| 4498 | + | // Check for possible floor transition items underneath |
| 4499 | + | if (tile->ground && (tile->ground->isStairs() || tile->ground->isLadder())) { |
| 4500 | + | return true; |
| 4501 | + | } |
| 4502 | + | |
| 4503 | + | return false; |
| 4504 | + | } |