diff --git a/src/airport_gui.cpp b/src/airport_gui.cpp --- a/src/airport_gui.cpp +++ b/src/airport_gui.cpp @@ -39,7 +39,7 @@ static void PlaceAirport(TileIndex tile) static void PlaceAir_DemolishArea(TileIndex tile) { - VpStartPlaceSizing(tile, 4); + VpStartPlaceSizing(tile, VPM_X_AND_Y, GUI_PlaceProc_None); } @@ -91,7 +91,7 @@ static void BuildAirToolbWndProc(Window break; case WE_PLACE_DRAG: - VpSelectTilesWithMethod(e->we.place.pt.x, e->we.place.pt.y, e->we.place.userdata); + VpSelectTilesWithMethod(e->we.place.pt.x, e->we.place.pt.y, e->we.place.select_method); break; case WE_PLACE_MOUSEUP: diff --git a/src/dock_gui.cpp b/src/dock_gui.cpp --- a/src/dock_gui.cpp +++ b/src/dock_gui.cpp @@ -53,12 +53,12 @@ static void PlaceDocks_Buoy(TileIndex ti static void PlaceDocks_DemolishArea(TileIndex tile) { - VpStartPlaceSizing(tile, VPM_X_AND_Y | GUI_PlaceProc_DemolishArea); + VpStartPlaceSizing(tile, VPM_X_AND_Y, GUI_PlaceProc_DemolishArea); } static void PlaceDocks_BuildCanal(TileIndex tile) { - VpStartPlaceSizing(tile, VPM_X_OR_Y); + VpStartPlaceSizing(tile, VPM_X_OR_Y, GUI_PlaceProc_None); } static void PlaceDocks_BuildLock(TileIndex tile) @@ -147,16 +147,20 @@ static void BuildDocksToolbWndProc(Windo break; case WE_PLACE_DRAG: { - VpSelectTilesWithMethod(e->we.place.pt.x, e->we.place.pt.y, e->we.place.userdata); + VpSelectTilesWithMethod(e->we.place.pt.x, e->we.place.pt.y, e->we.place.select_method); return; } case WE_PLACE_MOUSEUP: if (e->we.place.pt.x != -1) { - if ((e->we.place.userdata & 0xF) == VPM_X_AND_Y) { // dragged actions - GUIPlaceProcDragXY(e); - } else if (e->we.place.userdata == VPM_X_OR_Y) { - DoCommandP(e->we.place.tile, e->we.place.starttile, 0, CcBuildCanal, CMD_BUILD_CANAL | CMD_AUTO | CMD_MSG(STR_CANT_BUILD_CANALS)); + switch (e->we.place.select_method) { + case VPM_X_AND_Y: + GUIPlaceProcDragXY(e); + break; + case VPM_X_OR_Y: + DoCommandP(e->we.place.tile, e->we.place.starttile, 0, CcBuildCanal, CMD_BUILD_CANAL | CMD_AUTO | CMD_MSG(STR_CANT_BUILD_CANALS)); + break; + default: break; } } break; diff --git a/src/gui.h b/src/gui.h --- a/src/gui.h +++ b/src/gui.h @@ -68,14 +68,15 @@ void PlaceProc_DemolishArea(TileIndex ti void PlaceProc_LevelLand(TileIndex tile); bool GUIPlaceProcDragXY(const WindowEvent *e); -enum { // max 32 - 4 = 28 types - GUI_PlaceProc_DemolishArea = 0 << 4, - GUI_PlaceProc_LevelArea = 1 << 4, - GUI_PlaceProc_DesertArea = 2 << 4, - GUI_PlaceProc_WaterArea = 3 << 4, - GUI_PlaceProc_ConvertRailArea = 4 << 4, - GUI_PlaceProc_RockyArea = 5 << 4, - GUI_PlaceProc_RemoveFromStation = 6 << 4, +enum { + GUI_PlaceProc_None, + GUI_PlaceProc_DemolishArea, + GUI_PlaceProc_LevelArea, + GUI_PlaceProc_DesertArea, + GUI_PlaceProc_WaterArea, + GUI_PlaceProc_ConvertRailArea, + GUI_PlaceProc_RockyArea, + GUI_PlaceProc_RemoveFromStation, }; /* misc_gui.cpp */ diff --git a/src/main_gui.cpp b/src/main_gui.cpp --- a/src/main_gui.cpp +++ b/src/main_gui.cpp @@ -1131,7 +1131,7 @@ static void PlaceProc_LowerBigLand(TileI static void PlaceProc_RockyArea(TileIndex tile) { - VpStartPlaceSizing(tile, VPM_X_AND_Y | GUI_PlaceProc_RockyArea); + VpStartPlaceSizing(tile, VPM_X_AND_Y, GUI_PlaceProc_RockyArea); } static void PlaceProc_LightHouse(TileIndex tile) @@ -1158,12 +1158,12 @@ static void PlaceProc_Transmitter(TileIn static void PlaceProc_DesertArea(TileIndex tile) { - VpStartPlaceSizing(tile, VPM_X_AND_Y | GUI_PlaceProc_DesertArea); + VpStartPlaceSizing(tile, VPM_X_AND_Y, GUI_PlaceProc_DesertArea); } static void PlaceProc_WaterArea(TileIndex tile) { - VpStartPlaceSizing(tile, VPM_X_AND_Y | GUI_PlaceProc_WaterArea); + VpStartPlaceSizing(tile, VPM_X_AND_Y, GUI_PlaceProc_WaterArea); } static const Widget _scen_edit_land_gen_widgets[] = { @@ -1377,12 +1377,12 @@ static void ScenEditLandGenWndProc(Windo _place_proc(e->we.place.tile); break; case WE_PLACE_DRAG: - VpSelectTilesWithMethod(e->we.place.pt.x, e->we.place.pt.y, e->we.place.userdata & 0xF); + VpSelectTilesWithMethod(e->we.place.pt.x, e->we.place.pt.y, e->we.place.select_method); break; case WE_PLACE_MOUSEUP: if (e->we.place.pt.x != -1) { - if ((e->we.place.userdata & 0xF) == VPM_X_AND_Y) // dragged actions + if (e->we.place.select_method == VPM_X_AND_Y) // dragged actions GUIPlaceProcDragXY(e); } break; diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -382,12 +382,12 @@ static void BuildTreesWndProc(Window *w, } break; case WE_PLACE_OBJ: - VpStartPlaceSizing(e->we.place.tile, VPM_X_AND_Y_LIMITED); + VpStartPlaceSizing(e->we.place.tile, VPM_X_AND_Y_LIMITED, GUI_PlaceProc_None); VpSetPlaceSizingLimit(20); break; case WE_PLACE_DRAG: - VpSelectTilesWithMethod(e->we.place.pt.x, e->we.place.pt.y, e->we.place.userdata); + VpSelectTilesWithMethod(e->we.place.pt.x, e->we.place.pt.y, e->we.place.select_method); return; case WE_PLACE_MOUSEUP: diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp --- a/src/rail_gui.cpp +++ b/src/rail_gui.cpp @@ -72,7 +72,7 @@ static void PlaceRail_N(TileIndex tile) static void PlaceRail_NE(TileIndex tile) { - VpStartPlaceSizing(tile, VPM_FIX_Y); + VpStartPlaceSizing(tile, VPM_FIX_Y, GUI_PlaceProc_None); } static void PlaceRail_E(TileIndex tile) @@ -83,12 +83,12 @@ static void PlaceRail_E(TileIndex tile) static void PlaceRail_NW(TileIndex tile) { - VpStartPlaceSizing(tile, VPM_FIX_X); + VpStartPlaceSizing(tile, VPM_FIX_X, GUI_PlaceProc_None); } static void PlaceRail_AutoRail(TileIndex tile) { - VpStartPlaceSizing(tile, VPM_RAILDIRS); + VpStartPlaceSizing(tile, VPM_RAILDIRS, GUI_PlaceProc_None); } static void PlaceExtraDepotRail(TileIndex tile, uint16 extra) @@ -151,9 +151,9 @@ void CcStation(bool success, TileIndex t static void PlaceRail_Station(TileIndex tile) { if (_remove_button_clicked) { - VpStartPlaceSizing(tile, VPM_X_AND_Y | GUI_PlaceProc_RemoveFromStation); + VpStartPlaceSizing(tile, VPM_X_AND_Y, GUI_PlaceProc_RemoveFromStation); } else if (_railstation.dragdrop) { - VpStartPlaceSizing(tile, VPM_X_AND_Y_LIMITED); + VpStartPlaceSizing(tile, VPM_X_AND_Y_LIMITED, GUI_PlaceProc_None); VpSetPlaceSizingLimit(_patches.station_spread); } else { DoCommandP(tile, @@ -197,7 +197,7 @@ static void GenericPlaceSignals(TileInde static void PlaceRail_Bridge(TileIndex tile) { - VpStartPlaceSizing(tile, VPM_X_OR_Y); + VpStartPlaceSizing(tile, VPM_X_OR_Y, GUI_PlaceProc_None); } void CcBuildRailTunnel(bool success, TileIndex tile, uint32 p1, uint32 p2) @@ -223,12 +223,12 @@ void PlaceProc_BuyLand(TileIndex tile) static void PlaceRail_ConvertRail(TileIndex tile) { - VpStartPlaceSizing(tile, VPM_X_AND_Y | GUI_PlaceProc_ConvertRailArea); + VpStartPlaceSizing(tile, VPM_X_AND_Y, GUI_PlaceProc_ConvertRailArea); } static void PlaceRail_AutoSignals(TileIndex tile) { - VpStartPlaceSizing(tile, VPM_SIGNALDIRS); + VpStartPlaceSizing(tile, VPM_SIGNALDIRS, GUI_PlaceProc_None); } @@ -492,7 +492,7 @@ static void BuildRailToolbWndProc(Window return; case WE_PLACE_DRAG: { - VpSelectTilesWithMethod(e->we.place.pt.x, e->we.place.pt.y, e->we.place.userdata & 0xF); + VpSelectTilesWithMethod(e->we.place.pt.x, e->we.place.pt.y, e->we.place.select_method); return; } @@ -501,30 +501,45 @@ static void BuildRailToolbWndProc(Window TileIndex start_tile = e->we.place.starttile; TileIndex end_tile = e->we.place.tile; - if (e->we.place.userdata == VPM_X_OR_Y) { - ResetObjectToPlace(); - ShowBuildBridgeWindow(start_tile, end_tile, _cur_railtype); - } else if (e->we.place.userdata == VPM_RAILDIRS) { - bool old = _remove_button_clicked; - if (_ctrl_pressed) _remove_button_clicked = true; - HandleAutodirPlacement(); - _remove_button_clicked = old; - } else if (e->we.place.userdata == VPM_SIGNALDIRS) { - HandleAutoSignalPlacement(); - } else if ((e->we.place.userdata & 0xF) == VPM_X_AND_Y) { - if (GUIPlaceProcDragXY(e)) break; + switch (e->we.place.select_method) { + case VPM_X_OR_Y: + ResetObjectToPlace(); + ShowBuildBridgeWindow(start_tile, end_tile, _cur_railtype); + break; - if ((e->we.place.userdata >> 4) == GUI_PlaceProc_RemoveFromStation >> 4) { - DoCommandP(end_tile, start_tile, 0, CcPlaySound1E, CMD_REMOVE_FROM_RAILROAD_STATION | CMD_MSG(STR_CANT_REMOVE_PART_OF_STATION)); + case VPM_RAILDIRS: { + bool old = _remove_button_clicked; + if (_ctrl_pressed) _remove_button_clicked = true; + HandleAutodirPlacement(); + _remove_button_clicked = old; + break; } - if ((e->we.place.userdata >> 4) == GUI_PlaceProc_ConvertRailArea >> 4) { - DoCommandP(end_tile, start_tile, _cur_railtype, CcPlaySound10, CMD_CONVERT_RAIL | CMD_MSG(STR_CANT_CONVERT_RAIL)); - } - } else if (e->we.place.userdata == VPM_X_AND_Y_LIMITED) { - HandleStationPlacement(start_tile, end_tile); - } else { - DoRailroadTrack(e->we.place.userdata & 1); + case VPM_SIGNALDIRS: + HandleAutoSignalPlacement(); + break; + + case VPM_X_AND_Y: + if (GUIPlaceProcDragXY(e)) break; + + switch (e->we.place.select_proc) { + case GUI_PlaceProc_RemoveFromStation: + DoCommandP(end_tile, start_tile, 0, CcPlaySound1E, CMD_REMOVE_FROM_RAILROAD_STATION | CMD_MSG(STR_CANT_REMOVE_PART_OF_STATION)); + break; + + case GUI_PlaceProc_ConvertRailArea: + DoCommandP(end_tile, start_tile, _cur_railtype, CcPlaySound10, CMD_CONVERT_RAIL | CMD_MSG(STR_CANT_CONVERT_RAIL)); + break; + } + break; + + case VPM_X_AND_Y_LIMITED: + HandleStationPlacement(start_tile, end_tile); + break; + + default: + DoRailroadTrack(e->we.place.select_method == VPM_FIX_Y ? TRACK_X : TRACK_Y); + break; } } break; diff --git a/src/road_gui.cpp b/src/road_gui.cpp --- a/src/road_gui.cpp +++ b/src/road_gui.cpp @@ -45,18 +45,18 @@ void CcPlaySound1D(bool success, TileInd static void PlaceRoad_NE(TileIndex tile) { _place_road_flag = (_tile_fract_coords.y >= 8) + 4; - VpStartPlaceSizing(tile, VPM_FIX_X); + VpStartPlaceSizing(tile, VPM_FIX_X, GUI_PlaceProc_None); } static void PlaceRoad_NW(TileIndex tile) { _place_road_flag = (_tile_fract_coords.x >= 8) + 0; - VpStartPlaceSizing(tile, VPM_FIX_Y); + VpStartPlaceSizing(tile, VPM_FIX_Y, GUI_PlaceProc_None); } static void PlaceRoad_Bridge(TileIndex tile) { - VpStartPlaceSizing(tile, VPM_X_OR_Y); + VpStartPlaceSizing(tile, VPM_X_OR_Y, GUI_PlaceProc_None); } @@ -134,7 +134,7 @@ static void PlaceRoad_TruckStation(TileI static void PlaceRoad_DemolishArea(TileIndex tile) { - VpStartPlaceSizing(tile, 4); + VpStartPlaceSizing(tile, VPM_X_AND_Y, GUI_PlaceProc_None); } @@ -270,47 +270,41 @@ static void BuildRoadToolbWndProc(Window if (w != NULL) WP(w, def_d).close = true; break; - case WE_PLACE_DRAG: { - int sel_method; - switch (e->we.place.userdata) { - case 1: - sel_method = VPM_FIX_X; + case WE_PLACE_DRAG: + switch (e->we.place.select_method) { + case VPM_FIX_X: _place_road_flag = (_place_road_flag & ~2) | ((e->we.place.pt.y & 8) >> 2); break; - case 2: - sel_method = VPM_FIX_Y; + case VPM_FIX_Y: _place_road_flag = (_place_road_flag & ~2) | ((e->we.place.pt.x & 8) >> 2); break; - - case 4: - sel_method = VPM_X_AND_Y; - break; - - default: - sel_method = VPM_X_OR_Y; - break; } - VpSelectTilesWithMethod(e->we.place.pt.x, e->we.place.pt.y, sel_method); + VpSelectTilesWithMethod(e->we.place.pt.x, e->we.place.pt.y, e->we.place.select_method); return; - } case WE_PLACE_MOUSEUP: if (e->we.place.pt.x != -1) { TileIndex start_tile = e->we.place.starttile; TileIndex end_tile = e->we.place.tile; - if (e->we.place.userdata == 0) { - ResetObjectToPlace(); - ShowBuildBridgeWindow(start_tile, end_tile, 0x80 | RoadTypeToRoadTypes(_cur_roadtype)); - } else if (e->we.place.userdata != 4) { - DoCommandP(end_tile, start_tile, _place_road_flag | (_cur_roadtype << 3), CcPlaySound1D, - _remove_button_clicked ? - CMD_REMOVE_LONG_ROAD | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_1805_CAN_T_REMOVE_ROAD_FROM) : - CMD_BUILD_LONG_ROAD | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_1804_CAN_T_BUILD_ROAD_HERE)); - } else { - DoCommandP(end_tile, start_tile, 0, CcPlaySound10, CMD_CLEAR_AREA | CMD_MSG(STR_00B5_CAN_T_CLEAR_THIS_AREA)); + switch (e->we.place.select_method) { + case VPM_X_OR_Y: + ResetObjectToPlace(); + ShowBuildBridgeWindow(start_tile, end_tile, 0x80 | RoadTypeToRoadTypes(_cur_roadtype)); + break; + + case VPM_X_AND_Y: + DoCommandP(end_tile, start_tile, 0, CcPlaySound10, CMD_CLEAR_AREA | CMD_MSG(STR_00B5_CAN_T_CLEAR_THIS_AREA)); + break; + + default: + DoCommandP(end_tile, start_tile, _place_road_flag | (_cur_roadtype << 3), CcPlaySound1D, + _remove_button_clicked ? + CMD_REMOVE_LONG_ROAD | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_1805_CAN_T_REMOVE_ROAD_FROM) : + CMD_BUILD_LONG_ROAD | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_1804_CAN_T_BUILD_ROAD_HERE)); + break; } } break; diff --git a/src/terraform_gui.cpp b/src/terraform_gui.cpp --- a/src/terraform_gui.cpp +++ b/src/terraform_gui.cpp @@ -104,23 +104,24 @@ bool GUIPlaceProcDragXY(const WindowEven TileIndex start_tile = e->we.place.starttile; TileIndex end_tile = e->we.place.tile; - switch (e->we.place.userdata >> 4) { - case GUI_PlaceProc_DemolishArea >> 4: - DoCommandP(end_tile, start_tile, 0, CcPlaySound10, CMD_CLEAR_AREA | CMD_MSG(STR_00B5_CAN_T_CLEAR_THIS_AREA)); - break; - case GUI_PlaceProc_LevelArea >> 4: - DoCommandP(end_tile, start_tile, 0, CcPlaySound10, CMD_LEVEL_LAND | CMD_AUTO); - break; - case GUI_PlaceProc_RockyArea >> 4: - GenerateRockyArea(end_tile, start_tile); - break; - case GUI_PlaceProc_DesertArea >> 4: - GenerateDesertArea(end_tile, start_tile); - break; - case GUI_PlaceProc_WaterArea >> 4: - DoCommandP(end_tile, start_tile, _ctrl_pressed, CcBuildCanal, CMD_BUILD_CANAL | CMD_AUTO | CMD_MSG(STR_CANT_BUILD_CANALS)); - break; - default: return false; + switch (e->we.place.select_proc) { + case GUI_PlaceProc_DemolishArea: + DoCommandP(end_tile, start_tile, 0, CcPlaySound10, CMD_CLEAR_AREA | CMD_MSG(STR_00B5_CAN_T_CLEAR_THIS_AREA)); + break; + case GUI_PlaceProc_LevelArea: + DoCommandP(end_tile, start_tile, 0, CcPlaySound10, CMD_LEVEL_LAND | CMD_AUTO); + break; + case GUI_PlaceProc_RockyArea: + GenerateRockyArea(end_tile, start_tile); + break; + case GUI_PlaceProc_DesertArea: + GenerateDesertArea(end_tile, start_tile); + break; + case GUI_PlaceProc_WaterArea: + DoCommandP(end_tile, start_tile, _ctrl_pressed, CcBuildCanal, CMD_BUILD_CANAL | CMD_AUTO | CMD_MSG(STR_CANT_BUILD_CANALS)); + break; + default: + return false; } return true; @@ -140,7 +141,7 @@ static const uint16 _terraform_keycodes[ void PlaceProc_DemolishArea(TileIndex tile) { - VpStartPlaceSizing(tile, VPM_X_AND_Y | GUI_PlaceProc_DemolishArea); + VpStartPlaceSizing(tile, VPM_X_AND_Y, GUI_PlaceProc_DemolishArea); } static void PlaceProc_RaiseLand(TileIndex tile) @@ -161,7 +162,7 @@ static void PlaceProc_LowerLand(TileInde void PlaceProc_LevelLand(TileIndex tile) { - VpStartPlaceSizing(tile, VPM_X_AND_Y | GUI_PlaceProc_LevelArea); + VpStartPlaceSizing(tile, VPM_X_AND_Y, GUI_PlaceProc_LevelArea); } static void TerraformClick_Lower(Window *w) @@ -239,12 +240,11 @@ static void TerraformToolbWndProc(Window return; case WE_PLACE_DRAG: - VpSelectTilesWithMethod(e->we.place.pt.x, e->we.place.pt.y, e->we.place.userdata & 0xF); + VpSelectTilesWithMethod(e->we.place.pt.x, e->we.place.pt.y, e->we.place.select_method); break; case WE_PLACE_MOUSEUP: - if (e->we.place.pt.x != -1 && - (e->we.place.userdata & 0xF) == VPM_X_AND_Y) { // dragged actions + if (e->we.place.pt.x != -1 && e->we.place.select_method == VPM_X_AND_Y) { GUIPlaceProcDragXY(e); } break; diff --git a/src/viewport.cpp b/src/viewport.cpp --- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -1985,9 +1985,10 @@ void UpdateTileSelection() } /** highlighting tiles while only going over them with the mouse */ -void VpStartPlaceSizing(TileIndex tile, int user) +void VpStartPlaceSizing(TileIndex tile, byte method, byte process) { - _thd.userdata = user; + _thd.select_method = method; + _thd.select_proc = process; _thd.selend.x = TileX(tile) * TILE_SIZE; _thd.selstart.x = TileX(tile) * TILE_SIZE; _thd.selend.y = TileY(tile) * TILE_SIZE; @@ -2445,7 +2446,8 @@ bool VpHandlePlaceSizingDrag() if (_special_mouse_mode != WSM_SIZING) return true; - e.we.place.userdata = _thd.userdata; + e.we.place.select_method = _thd.select_method; + e.we.place.select_proc = _thd.select_proc; /* stop drag mode if the window has been closed */ w = FindWindowById(_thd.window_class, _thd.window_number); @@ -2467,7 +2469,7 @@ bool VpHandlePlaceSizingDrag() _special_mouse_mode = WSM_NONE; if (_thd.next_drawstyle == HT_RECT) { _thd.place_mode = VHM_RECT; - } else if ((e.we.place.userdata & 0xF) == VPM_SIGNALDIRS) { // some might call this a hack... -- Dominik + } else if (e.we.place.select_method == VPM_SIGNALDIRS) { // some might call this a hack... -- Dominik _thd.place_mode = VHM_RECT; } else if (_thd.next_drawstyle & HT_LINE) { _thd.place_mode = VHM_RAIL; diff --git a/src/viewport.h b/src/viewport.h --- a/src/viewport.h +++ b/src/viewport.h @@ -62,7 +62,7 @@ void SetRedErrorSquare(TileIndex tile); void SetTileSelectSize(int w, int h); void SetTileSelectBigSize(int ox, int oy, int sx, int sy); -void VpStartPlaceSizing(TileIndex tile, int user); +void VpStartPlaceSizing(TileIndex tile, byte method, byte process); void VpSetPresizeRange(uint from, uint to); void VpSetPlaceSizingLimit(int limit); @@ -137,7 +137,9 @@ struct TileHighlightData { WindowClass window_class; WindowNumber window_number; - int userdata; + byte select_method; + byte select_proc; + TileIndex redsq; }; diff --git a/src/window.h b/src/window.h --- a/src/window.h +++ b/src/window.h @@ -135,7 +135,8 @@ struct WindowEvent { Point pt; TileIndex tile; TileIndex starttile; - int userdata; + byte select_method; + byte select_proc; } place; struct {