From 77ee09921217eac1540b82978178779eb839d08e Mon Sep 17 00:00:00 2001 From: belugas Date: Wed, 20 Aug 2008 01:29:05 +0000 Subject: [PATCH] (svn r14104) -Feature: Add a window for waypoints, allowing to view all the trains having the selected waypoint in their orders. Changing its name is also supported from the same new window. Gui based on work done by Satyap, on FS#2025. --- projects/openttd_vs80.vcproj | 4 ++ projects/openttd_vs90.vcproj | 4 ++ source.list | 1 + src/lang/english.txt | 3 + src/main_gui.cpp | 21 ------- src/rail_cmd.cpp | 4 +- src/vehicle_gui.cpp | 16 +++++ src/vehicle_gui.h | 3 + src/vehiclelist.cpp | 16 +++++ src/viewport.cpp | 6 +- src/waypoint.h | 2 +- src/waypoints_gui.cpp | 111 +++++++++++++++++++++++++++++++++++ src/window_type.h | 1 + 13 files changed, 165 insertions(+), 27 deletions(-) create mode 100644 src/waypoints_gui.cpp diff --git a/projects/openttd_vs80.vcproj b/projects/openttd_vs80.vcproj index 006c69fbf2..e30657dbc7 100644 --- a/projects/openttd_vs80.vcproj +++ b/projects/openttd_vs80.vcproj @@ -1867,6 +1867,10 @@ RelativePath=".\..\src\vehicle_gui.cpp" > + + + + index; - - /* Are we allowed to change the name of the waypoint? */ - if (!CheckTileOwnership(wp->xy)) { - ShowErrorMessage(_error_message, STR_CANT_CHANGE_WAYPOINT_NAME, - TileX(wp->xy) * TILE_SIZE, TileY(wp->xy) * TILE_SIZE); - return; - } - - _rename_id = id; - _rename_what = 1; - SetDParam(0, id); - ShowQueryString(STR_WAYPOINT_RAW, STR_EDIT_WAYPOINT_NAME, MAX_LENGTH_WAYPOINT_NAME_BYTES, MAX_LENGTH_WAYPOINT_NAME_PIXELS, NULL, CS_ALPHANUMERAL); -} - /* Zooms a viewport in a window in or out */ /* No button handling or what so ever */ diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp index 26b24da8b1..2b5227c034 100644 --- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -2307,8 +2307,8 @@ static TrackStatus GetTileTrackStatus_Track(TileIndex tile, TransportType mode, static void ClickTile_Track(TileIndex tile) { switch (GetRailTileType(tile)) { - case RAIL_TILE_DEPOT: ShowDepotWindow(tile, VEH_TRAIN); break; - case RAIL_TILE_WAYPOINT: ShowRenameWaypointWindow(GetWaypointByTile(tile)); break; + case RAIL_TILE_DEPOT: ShowDepotWindow(tile, VEH_TRAIN); break; + case RAIL_TILE_WAYPOINT: ShowWaypointWindow(GetWaypointByTile(tile)); break; default: break; } } diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index 84ff470b9e..d2e2626663 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -789,6 +789,7 @@ struct VehicleListWindow : public Window, public VehicleListBase { case VLW_SHARED_ORDERS: this->widget[VLW_WIDGET_CAPTION].data = STR_VEH_WITH_SHARED_ORDERS_LIST; break; + case VLW_STANDARD: /* Company Name - standard widget setup */ switch (this->vehicle_type) { case VEH_TRAIN: this->widget[VLW_WIDGET_CAPTION].data = STR_881B_TRAINS; break; @@ -798,6 +799,11 @@ struct VehicleListWindow : public Window, public VehicleListBase { default: NOT_REACHED(); break; } break; + + case VLM_WAYPOINT_LIST: + this->widget[VLW_WIDGET_CAPTION].data = STR_WAYPOINT_VIEWPORT; + break; + case VLW_STATION_LIST: /* Station Name */ switch (this->vehicle_type) { case VEH_TRAIN: this->widget[VLW_WIDGET_CAPTION].data = STR_SCHEDULED_TRAINS; break; @@ -893,6 +899,10 @@ struct VehicleListWindow : public Window, public VehicleListBase { SetDParam(1, this->vscroll.count); break; + case VLM_WAYPOINT_LIST: + SetDParam(0, index); + break; + case VLW_STATION_LIST: /* Station Name */ SetDParam(0, index); SetDParam(1, this->vscroll.count); @@ -1167,6 +1177,12 @@ void ShowVehicleListWindow(PlayerID player, VehicleType vehicle_type) } } +void ShowVehicleListWindow(const Waypoint *wp) +{ + if (wp == NULL) return; + ShowVehicleListWindowLocal(GetTileOwner(wp->xy), VLM_WAYPOINT_LIST, VEH_TRAIN, wp->index); +} + void ShowVehicleListWindow(const Vehicle *v) { ShowVehicleListWindowLocal(v->owner, VLW_SHARED_ORDERS, v->type, v->FirstShared()->index); diff --git a/src/vehicle_gui.h b/src/vehicle_gui.h index 43a99c9194..a6c35cdc76 100644 --- a/src/vehicle_gui.h +++ b/src/vehicle_gui.h @@ -11,6 +11,7 @@ #include "order_type.h" #include "station_type.h" #include "engine_type.h" +#include "waypoint.h" void DrawVehicleProfitButton(const Vehicle *v, int x, int y); void ShowVehicleRefitWindow(const Vehicle *v, VehicleOrderID order); @@ -51,6 +52,7 @@ enum { VLW_STATION_LIST = 2 << 8, VLW_DEPOT_LIST = 3 << 8, VLW_GROUP_LIST = 4 << 8, + VLM_WAYPOINT_LIST = 5 << 8, VLW_MASK = 0x700, }; @@ -72,6 +74,7 @@ uint ShowAdditionalText(int x, int y, uint w, EngineID engine); uint ShowRefitOptionsList(int x, int y, uint w, EngineID engine); void ShowVehicleListWindow(const Vehicle *v); +void ShowVehicleListWindow(const Waypoint *wp); void ShowVehicleListWindow(PlayerID player, VehicleType vehicle_type); void ShowVehicleListWindow(PlayerID player, VehicleType vehicle_type, StationID station); void ShowVehicleListWindow(PlayerID player, VehicleType vehicle_type, TileIndex depot_tile); diff --git a/src/vehiclelist.cpp b/src/vehiclelist.cpp index 2341a31ada..14798b6558 100644 --- a/src/vehiclelist.cpp +++ b/src/vehiclelist.cpp @@ -67,6 +67,7 @@ void BuildDepotVehicleList(VehicleType type, TileIndex tile, VehicleList *engine *
  • VLW_STANDARD: not used
  • *
  • VLW_DEPOT_LIST: TileIndex of the depot/hangar to make the list for
  • *
  • VLW_GROUP_LIST: index of group to generate a list for
  • + *
  • VLM_WAYPOINT_LIST: index of waypoint to generate a list for
  • * * @param window_type The type of window the list is for, using the VLW_ flags in vehicle_gui.h */ @@ -122,6 +123,21 @@ void GenerateVehicleSortList(VehicleList *list, VehicleType type, PlayerID owner } break; + case VLM_WAYPOINT_LIST: + FOR_ALL_VEHICLES(v) { + if (v->type == type && v->IsPrimaryVehicle()) { + const Order *order; + + FOR_VEHICLE_ORDERS(v, order) { + if (order->IsType(OT_GOTO_WAYPOINT) && order->GetDestination() == index) { + *list->Append() = v; + break; + } + } + } + } + break; + case VLW_GROUP_LIST: FOR_ALL_VEHICLES(v) { if (v->type == type && v->IsPrimaryVehicle() && diff --git a/src/viewport.cpp b/src/viewport.cpp index 552ccf1778..9e54e21d73 100644 --- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -1934,7 +1934,7 @@ static bool CheckClickOnWaypoint(const ViewPort *vp, int x, int y) y < wp->sign.top + 12 && x >= wp->sign.left && x < wp->sign.left + wp->sign.width_1) { - ShowRenameWaypointWindow(wp); + ShowWaypointWindow(wp); return true; } } @@ -1948,7 +1948,7 @@ static bool CheckClickOnWaypoint(const ViewPort *vp, int x, int y) y < wp->sign.top + 24 && x >= wp->sign.left && x < wp->sign.left + wp->sign.width_1 * 2) { - ShowRenameWaypointWindow(wp); + ShowWaypointWindow(wp); return true; } } @@ -1964,7 +1964,7 @@ static bool CheckClickOnWaypoint(const ViewPort *vp, int x, int y) y < wp->sign.top + ScaleByZoom(12, vp->zoom) && x >= wp->sign.left && x < wp->sign.left + ScaleByZoom(wp->sign.width_2, vp->zoom)) { - ShowRenameWaypointWindow(wp); + ShowWaypointWindow(wp); return true; } } diff --git a/src/waypoint.h b/src/waypoint.h index 36014f7cad..ee664e6056 100644 --- a/src/waypoint.h +++ b/src/waypoint.h @@ -65,7 +65,7 @@ static inline Waypoint *GetWaypointByTile(TileIndex tile) CommandCost RemoveTrainWaypoint(TileIndex tile, uint32 flags, bool justremove); Station *ComposeWaypointStation(TileIndex tile); -void ShowRenameWaypointWindow(const Waypoint *cp); +void ShowWaypointWindow(const Waypoint *wp); void DrawWaypointSprite(int x, int y, int stat_id, RailType railtype); void FixOldWaypoints(); void UpdateAllWaypointSigns(); diff --git a/src/waypoints_gui.cpp b/src/waypoints_gui.cpp new file mode 100644 index 0000000000..bf95ee8d15 --- /dev/null +++ b/src/waypoints_gui.cpp @@ -0,0 +1,111 @@ +/* $Id$ */ + +/** @file waypoint_gui.cpp Handling of waypoints gui. */ + +#include "stdafx.h" +#include "openttd.h" +#include "window_gui.h" +#include "gui.h" +#include "textbuf_gui.h" +#include "vehicle_gui.h" +#include "waypoint.h" +#include "viewport_func.h" +#include "string_func.h" +#include "strings_func.h" +#include "gfx_func.h" +#include "command_func.h" +#include "functions.h" + +#include "table/strings.h" + +struct WaypointWindow : Window { +private: + Waypoint *wp; + + enum WaypointViewWidget { + WAYPVW_CLOSEBOX = 0, + WAYPVW_CAPTION, + WAYPVW_STICKY, + WAYPVW_VIEWPORTPANEL, + WAYPVW_SPACER, + WAYPVW_CENTERVIEW, + WAYPVW_RENAME, + WAYPVW_SHOW_TRAINS, + }; + +public: + WaypointWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number) + { + this->wp = GetWaypoint(this->window_number); + + this->flags4 |= WF_DISABLE_VP_SCROLL; + InitializeWindowViewport(this, 3, 17, 254, 86, this->wp->xy, ZOOM_LVL_MIN); + + this->FindWindowPlacementAndResize(desc); + } + + virtual void OnPaint() + { + /* You can only change your own waypoints */ + this->SetWidgetDisabledState(WAYPVW_RENAME, !CheckTileOwnership(this->wp->xy)); + SetDParam(0, this->wp->index); + this->DrawWidgets(); + + this->DrawViewport(); + } + + virtual void OnClick(Point pt, int widget) + { + switch (widget) { + case WAYPVW_CENTERVIEW: /* scroll to location */ + if (_ctrl_pressed) { + ShowExtraViewPortWindow(this->wp->xy); + } else { + ScrollMainWindowToTile(this->wp->xy); + } + break; + + case WAYPVW_RENAME: /* rename */ + SetDParam(0, this->wp->index); + ShowQueryString(STR_WAYPOINT_RAW, STR_EDIT_WAYPOINT_NAME, MAX_LENGTH_WAYPOINT_NAME_BYTES, MAX_LENGTH_WAYPOINT_NAME_PIXELS, this, CS_ALPHANUMERAL); + break; + + case WAYPVW_SHOW_TRAINS: /* show list of trains having this waypoint in their orders*/ + ShowVehicleListWindow(this->wp); + break; + } + } + + virtual void OnQueryTextFinished(char *str) + { + if (!StrEmpty(str)) { + _cmd_text = str; + DoCommandP(0, this->window_number, 0, NULL, CMD_RENAME_WAYPOINT | CMD_MSG(STR_CANT_CHANGE_WAYPOINT_NAME)); + } + } + +}; + +static const Widget _waypoint_view_widgets[] = { +{ WWT_CLOSEBOX, RESIZE_NONE, COLOUR_GREY, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, // WAYPVW_CLOSEBOX +{ WWT_CAPTION, RESIZE_NONE, COLOUR_GREY, 11, 247, 0, 13, STR_WAYPOINT_VIEWPORT, STR_018C_WINDOW_TITLE_DRAG_THIS}, // WAYPVW_CAPTION +{ WWT_STICKYBOX, RESIZE_NONE, COLOUR_GREY, 248, 259, 0, 13, 0x0, STR_STICKY_BUTTON}, // WAYPVW_STICKY +{ WWT_PANEL, RESIZE_NONE, COLOUR_GREY, 0, 259, 14, 105, 0x0, STR_NULL}, // WAYPVW_VIEWPORTPANEL +{ WWT_INSET, RESIZE_NONE, COLOUR_GREY, 2, 257, 16, 103, 0x0, STR_NULL}, // WAYPVW_SPACER +{ WWT_PUSHTXTBTN, RESIZE_NONE, COLOUR_GREY, 0, 121, 106, 117, STR_00E4_LOCATION, STR_3053_CENTER_MAIN_VIEW_ON_STATION}, // WAYPVW_CENTERVIEW +{ WWT_PUSHTXTBTN, RESIZE_NONE, COLOUR_GREY, 122, 244, 106, 117, STR_0130_RENAME, STR_CHANGE_WAYPOINT_NAME}, // WAYPVW_RENAME +{ WWT_PUSHTXTBTN, RESIZE_NONE, COLOUR_GREY, 245, 259, 106, 117, STR_TRAIN, STR_SCHEDULED_TRAINS_TIP }, // WAYPVW_SHOW_TRAINS +{ WIDGETS_END}, +}; + +static const WindowDesc _waypoint_view_desc = { + WDP_AUTO, WDP_AUTO, 260, 118, 260, 118, + WC_WAYPOINT_VIEW, WC_NONE, + WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON, + _waypoint_view_widgets, +}; + +void ShowWaypointWindow(const Waypoint *wp) +{ + AllocateWindowDescFront(&_waypoint_view_desc, wp->index); +} diff --git a/src/window_type.h b/src/window_type.h index 2dc4ba5847..0150f64da5 100644 --- a/src/window_type.h +++ b/src/window_type.h @@ -94,6 +94,7 @@ enum WindowClass { WC_BUILD_SIGNAL, WC_COMPANY_PASSWORD_WINDOW, WC_OSK, + WC_WAYPOINT_VIEW, WC_INVALID = 0xFFFF };