diff options
author | frosch <frosch@openttd.org> | 2020-12-27 22:41:06 +0100 |
---|---|---|
committer | frosch <github@elsenhans.name> | 2021-01-11 22:15:58 +0100 |
commit | 589feba0ebd5215138a339b81a6124e6d0e16ec5 (patch) | |
tree | 79194a26361153682ebe6cc1f8eee9de7c4bb088 | |
parent | 8dda0ec4ff5bd0eb78a5c4672a470046e8c680d7 (diff) | |
download | openttd-589feba0ebd5215138a339b81a6124e6d0e16ec5.tar.xz |
Change: Relocate vehicle rename and location buttons.
-rw-r--r-- | src/lang/english.txt | 18 | ||||
-rw-r--r-- | src/vehicle_gui.cpp | 81 | ||||
-rw-r--r-- | src/widgets/vehicle_widget.h | 5 |
3 files changed, 58 insertions, 46 deletions
diff --git a/src/lang/english.txt b/src/lang/english.txt index 6f2168f20..f04639fd1 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -3758,10 +3758,10 @@ STR_REPLACE_REMOVE_WAGON_HELP :{BLACK}Make aut # Vehicle view STR_VEHICLE_VIEW_CAPTION :{WHITE}{VEHICLE} -STR_VEHICLE_VIEW_TRAIN_LOCATION_TOOLTIP :{BLACK}Centre main view on train's location. Ctrl+Click will follow train in main view -STR_VEHICLE_VIEW_ROAD_VEHICLE_LOCATION_TOOLTIP :{BLACK}Centre main view on vehicle's location. Ctrl+Click will follow vehicle in main view -STR_VEHICLE_VIEW_SHIP_LOCATION_TOOLTIP :{BLACK}Centre main view on ship's location. Ctrl+Click will follow ship in main view -STR_VEHICLE_VIEW_AIRCRAFT_LOCATION_TOOLTIP :{BLACK}Centre main view on aircraft's location. Ctrl+Click will follow aircraft in main view +STR_VEHICLE_VIEW_TRAIN_CENTER_TOOLTIP :{BLACK}Centre main view on train's location. Double click will follow train in main view. Ctrl+Click opens a new viewport on train's location +STR_VEHICLE_VIEW_ROAD_VEHICLE_CENTER_TOOLTIP :{BLACK}Centre main view on vehicle's location. Double click will follow vehicle in main view. Ctrl+Click opens a new viewport on vehicle's location +STR_VEHICLE_VIEW_SHIP_CENTER_TOOLTIP :{BLACK}Centre main view on ship's location. Double click will follow ship in main view. Ctrl+Click opens a new viewport on ship's location +STR_VEHICLE_VIEW_AIRCRAFT_CENTER_TOOLTIP :{BLACK}Centre main view on aircraft's location. Double click will follow aircraft in main view. Ctrl+Click opens a new viewport on aircraft's location STR_VEHICLE_VIEW_TRAIN_SEND_TO_DEPOT_TOOLTIP :{BLACK}Send train to depot. Ctrl+Click will only service STR_VEHICLE_VIEW_ROAD_VEHICLE_SEND_TO_DEPOT_TOOLTIP :{BLACK}Send vehicle to depot. Ctrl+Click will only service @@ -3793,10 +3793,12 @@ STR_VEHICLE_VIEW_ROAD_VEHICLE_SHOW_DETAILS_TOOLTIP :{BLACK}Show roa STR_VEHICLE_VIEW_SHIP_SHOW_DETAILS_TOOLTIP :{BLACK}Show ship details STR_VEHICLE_VIEW_AIRCRAFT_SHOW_DETAILS_TOOLTIP :{BLACK}Show aircraft details -STR_VEHICLE_VIEW_TRAIN_STATE_START_STOP_TOOLTIP :{BLACK}Current train action - click to stop/start train. Ctrl+Click to scroll to destination -STR_VEHICLE_VIEW_ROAD_VEHICLE_STATE_START_STOP_TOOLTIP :{BLACK}Current vehicle action - click to stop/start vehicle. Ctrl+Click to scroll to destination -STR_VEHICLE_VIEW_SHIP_STATE_START_STOP_TOOLTIP :{BLACK}Current ship action - click to stop/start ship. Ctrl+Click to scroll to destination -STR_VEHICLE_VIEW_AIRCRAFT_STATE_START_STOP_TOOLTIP :{BLACK}Current aircraft action - click to stop/start aircraft. Ctrl+Click to scroll to destination +STR_VEHICLE_VIEW_TRAIN_STATUS_START_STOP_TOOLTIP :{BLACK}Current train action - click to stop/start train +STR_VEHICLE_VIEW_ROAD_VEHICLE_STATUS_START_STOP_TOOLTIP :{BLACK}Current vehicle action - click to stop/start vehicle +STR_VEHICLE_VIEW_SHIP_STATE_STATUS_STOP_TOOLTIP :{BLACK}Current ship action - click to stop/start ship +STR_VEHICLE_VIEW_AIRCRAFT_STATUS_START_STOP_TOOLTIP :{BLACK}Current aircraft action - click to stop/start aircraft + +STR_VEHICLE_VIEW_ORDER_LOCATION_TOOLTIP :{BLACK}Centre main view on order destination. Ctrl+Click opens a new viewport on the order destination's location # Messages in the start stop button in the vehicle view STR_VEHICLE_STATUS_LOADING_UNLOADING :{LTBLUE}Loading / Unloading diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index 1e558373b..a9be8e5b8 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -2017,7 +2017,6 @@ static const NWidgetPart _nested_nontrain_vehicle_details_widgets[] = { NWidget(NWID_HORIZONTAL), NWidget(WWT_CLOSEBOX, COLOUR_GREY), NWidget(WWT_CAPTION, COLOUR_GREY, WID_VD_CAPTION), SetDataTip(STR_VEHICLE_DETAILS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS), - NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_VD_RENAME_VEHICLE), SetMinimalSize(40, 0), SetMinimalTextLines(1, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM + 2), SetDataTip(STR_VEHICLE_NAME_BUTTON, STR_NULL /* filled in later */), NWidget(WWT_SHADEBOX, COLOUR_GREY), NWidget(WWT_DEFSIZEBOX, COLOUR_GREY), NWidget(WWT_STICKYBOX, COLOUR_GREY), @@ -2041,7 +2040,6 @@ static const NWidgetPart _nested_train_vehicle_details_widgets[] = { NWidget(NWID_HORIZONTAL), NWidget(WWT_CLOSEBOX, COLOUR_GREY), NWidget(WWT_CAPTION, COLOUR_GREY, WID_VD_CAPTION), SetDataTip(STR_VEHICLE_DETAILS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS), - NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_VD_RENAME_VEHICLE), SetMinimalSize(40, 0), SetMinimalTextLines(1, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM + 2), SetDataTip(STR_VEHICLE_NAME_BUTTON, STR_NULL /* filled in later */), NWidget(WWT_SHADEBOX, COLOUR_GREY), NWidget(WWT_DEFSIZEBOX, COLOUR_GREY), NWidget(WWT_STICKYBOX, COLOUR_GREY), @@ -2101,8 +2099,6 @@ struct VehicleDetailsWindow : Window { this->vscroll = (v->type == VEH_TRAIN ? this->GetScrollbar(WID_VD_SCROLLBAR) : nullptr); this->FinishInitNested(window_number); - this->GetWidget<NWidgetCore>(WID_VD_RENAME_VEHICLE)->tool_tip = STR_VEHICLE_DETAILS_TRAIN_RENAME + v->type; - this->owner = v->owner; this->tab = TDW_TAB_CARGO; } @@ -2366,8 +2362,6 @@ struct VehicleDetailsWindow : Window { { const Vehicle *v = Vehicle::Get(this->window_number); - this->SetWidgetDisabledState(WID_VD_RENAME_VEHICLE, v->owner != _local_company); - if (v->type == VEH_TRAIN) { this->DisableWidget(this->tab + WID_VD_DETAILS_CARGO_CARRIED); this->vscroll->SetCount(GetTrainDetailsWndVScroll(v->index, this->tab)); @@ -2390,14 +2384,6 @@ struct VehicleDetailsWindow : Window { void OnClick(Point pt, int widget, int click_count) override { switch (widget) { - case WID_VD_RENAME_VEHICLE: { // rename - const Vehicle *v = Vehicle::Get(this->window_number); - SetDParam(0, v->index); - ShowQueryString(STR_VEHICLE_NAME, STR_QUERY_RENAME_TRAIN_CAPTION + v->type, - MAX_LENGTH_VEHICLE_NAME_CHARS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT | QSF_LEN_IN_CHARS); - break; - } - case WID_VD_INCREASE_SERVICING_INTERVAL: // increase int case WID_VD_DECREASE_SERVICING_INTERVAL: { // decrease int int mod = _ctrl_pressed ? 5 : 10; @@ -2449,13 +2435,6 @@ struct VehicleDetailsWindow : Window { } } - void OnQueryTextFinished(char *str) override - { - if (str == nullptr) return; - - DoCommandP(0, this->window_number, 0, CMD_RENAME_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_RENAME_TRAIN + Vehicle::Get(this->window_number)->type), nullptr, str); - } - void OnResize() override { NWidgetCore *nwi = this->GetWidget<NWidgetCore>(WID_VD_MATRIX); @@ -2496,7 +2475,9 @@ static void ShowVehicleDetailsWindow(const Vehicle *v) static const NWidgetPart _nested_vehicle_view_widgets[] = { NWidget(NWID_HORIZONTAL), NWidget(WWT_CLOSEBOX, COLOUR_GREY), + NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_VV_RENAME), SetMinimalSize(12, 14), SetDataTip(SPR_RENAME, STR_NULL /* filled in later */), NWidget(WWT_CAPTION, COLOUR_GREY, WID_VV_CAPTION), SetDataTip(STR_VEHICLE_VIEW_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS), + NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_VV_LOCATION), SetMinimalSize(12, 14), SetDataTip(SPR_GOTO_LOCATION, STR_NULL /* filled in later */), NWidget(WWT_DEBUGBOX, COLOUR_GREY), NWidget(WWT_SHADEBOX, COLOUR_GREY), NWidget(WWT_DEFSIZEBOX, COLOUR_GREY), @@ -2509,7 +2490,6 @@ static const NWidgetPart _nested_vehicle_view_widgets[] = { EndContainer(), EndContainer(), NWidget(NWID_VERTICAL), - NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_VV_CENTER_MAIN_VIEW), SetMinimalSize(18, 18), SetDataTip(SPR_CENTRE_VIEW_VEHICLE, 0x0 /* filled later */), NWidget(NWID_SELECTION, INVALID_COLOUR, WID_VV_SELECT_DEPOT_CLONE), NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_VV_GOTO_DEPOT), SetMinimalSize(18, 18), SetDataTip(0x0 /* filled later */, 0x0 /* filled later */), NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_VV_CLONE), SetMinimalSize(18, 18), SetDataTip(0x0 /* filled later */, 0x0 /* filled later */), @@ -2529,6 +2509,7 @@ static const NWidgetPart _nested_vehicle_view_widgets[] = { EndContainer(), NWidget(NWID_HORIZONTAL), NWidget(WWT_PUSHBTN, COLOUR_GREY, WID_VV_START_STOP), SetMinimalTextLines(1, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM + 2), SetResize(1, 0), SetFill(1, 0), + NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_VV_ORDER_LOCATION), SetMinimalSize(12, 14), SetDataTip(SPR_GOTO_LOCATION, STR_VEHICLE_VIEW_ORDER_LOCATION_TOOLTIP), NWidget(WWT_RESIZEBOX, COLOUR_GREY), EndContainer(), }; @@ -2726,8 +2707,9 @@ public: this->owner = v->owner; this->GetWidget<NWidgetViewport>(WID_VV_VIEWPORT)->InitializeViewport(this, this->window_number | (1 << 31), _vehicle_view_zoom_levels[v->type]); - this->GetWidget<NWidgetCore>(WID_VV_START_STOP)->tool_tip = STR_VEHICLE_VIEW_TRAIN_STATE_START_STOP_TOOLTIP + v->type; - this->GetWidget<NWidgetCore>(WID_VV_CENTER_MAIN_VIEW)->tool_tip = STR_VEHICLE_VIEW_TRAIN_LOCATION_TOOLTIP + v->type; + this->GetWidget<NWidgetCore>(WID_VV_START_STOP)->tool_tip = STR_VEHICLE_VIEW_TRAIN_STATUS_START_STOP_TOOLTIP + v->type; + this->GetWidget<NWidgetCore>(WID_VV_RENAME)->tool_tip = STR_VEHICLE_DETAILS_TRAIN_RENAME + v->type; + this->GetWidget<NWidgetCore>(WID_VV_LOCATION)->tool_tip = STR_VEHICLE_VIEW_TRAIN_CENTER_TOOLTIP + v->type; this->GetWidget<NWidgetCore>(WID_VV_REFIT)->tool_tip = STR_VEHICLE_VIEW_TRAIN_REFIT_TOOLTIP + v->type; this->GetWidget<NWidgetCore>(WID_VV_GOTO_DEPOT)->tool_tip = STR_VEHICLE_VIEW_TRAIN_SEND_TO_DEPOT_TOOLTIP + v->type; this->GetWidget<NWidgetCore>(WID_VV_SHOW_ORDERS)->tool_tip = STR_VEHICLE_VIEW_TRAIN_ORDERS_TOOLTIP + v->type; @@ -2773,6 +2755,7 @@ public: bool is_localcompany = v->owner == _local_company; bool refitable_and_stopped_in_depot = IsVehicleRefitable(v); + this->SetWidgetDisabledState(WID_VV_RENAME, !is_localcompany); this->SetWidgetDisabledState(WID_VV_GOTO_DEPOT, !is_localcompany); this->SetWidgetDisabledState(WID_VV_REFIT, !refitable_and_stopped_in_depot || !is_localcompany); this->SetWidgetDisabledState(WID_VV_CLONE, !is_localcompany); @@ -2783,6 +2766,8 @@ public: this->SetWidgetDisabledState(WID_VV_TURN_AROUND, !is_localcompany); } + this->SetWidgetDisabledState(WID_VV_ORDER_LOCATION, v->current_order.GetLocation(v) == INVALID_TILE); + this->DrawWidgets(); } @@ -2906,26 +2891,43 @@ public: const Vehicle *v = Vehicle::Get(this->window_number); switch (widget) { + case WID_VV_RENAME: { // rename + SetDParam(0, v->index); + ShowQueryString(STR_VEHICLE_NAME, STR_QUERY_RENAME_TRAIN_CAPTION + v->type, + MAX_LENGTH_VEHICLE_NAME_CHARS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT | QSF_LEN_IN_CHARS); + break; + } + case WID_VV_START_STOP: // start stop + StartStopVehicle(v, false); + break; + + case WID_VV_ORDER_LOCATION: { + /* Scroll to current order destination */ + TileIndex tile = v->current_order.GetLocation(v); + if (tile == INVALID_TILE) break; + if (_ctrl_pressed) { - /* Scroll to current order destination */ - TileIndex tile = v->current_order.GetLocation(v); - if (tile != INVALID_TILE) ScrollMainWindowToTile(tile); + ShowExtraViewportWindow(tile); } else { - /* Start/Stop */ - StartStopVehicle(v, false); + ScrollMainWindowToTile(tile); } break; - case WID_VV_CENTER_MAIN_VIEW: {// center main view - const Window *mainwindow = FindWindowById(WC_MAIN_WINDOW, 0); - /* code to allow the main window to 'follow' the vehicle if the ctrl key is pressed */ - if (_ctrl_pressed && mainwindow->viewport->zoom <= ZOOM_LVL_OUT_4X) { - mainwindow->viewport->follow_vehicle = v->index; + } + + case WID_VV_LOCATION: // center main view + if (_ctrl_pressed) { + ShowExtraViewportWindow(TileVirtXY(v->x_pos, v->y_pos)); } else { - ScrollMainWindowTo(v->x_pos, v->y_pos, v->z_pos); + const Window *mainwindow = FindWindowById(WC_MAIN_WINDOW, 0); + if (click_count > 1 && mainwindow->viewport->zoom <= ZOOM_LVL_OUT_4X) { + /* main window 'follows' vehicle */ + mainwindow->viewport->follow_vehicle = v->index; + } else { + ScrollMainWindowTo(v->x_pos, v->y_pos, v->z_pos); + } } break; - } case WID_VV_GOTO_DEPOT: // goto hangar DoCommandP(v->tile, v->index | (_ctrl_pressed ? DEPOT_SERVICE : 0U), 0, GetCmdSendToDepot(v)); @@ -2968,6 +2970,13 @@ public: } } + void OnQueryTextFinished(char *str) override + { + if (str == nullptr) return; + + DoCommandP(0, this->window_number, 0, CMD_RENAME_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_RENAME_TRAIN + Vehicle::Get(this->window_number)->type), nullptr, str); + } + void OnMouseOver(Point pt, int widget) override { bool start_stop = widget == WID_VV_START_STOP; diff --git a/src/widgets/vehicle_widget.h b/src/widgets/vehicle_widget.h index 0ee1b2624..698a32bcf 100644 --- a/src/widgets/vehicle_widget.h +++ b/src/widgets/vehicle_widget.h @@ -15,7 +15,9 @@ enum VehicleViewWidgets { WID_VV_CAPTION, ///< Caption of window. WID_VV_VIEWPORT, ///< Viewport widget. WID_VV_START_STOP, ///< Start or stop this vehicle, and show information about the current state. - WID_VV_CENTER_MAIN_VIEW, ///< Center the main view on this vehicle. + WID_VV_RENAME, ///< Rename vehicle + WID_VV_LOCATION, ///< Center the main view on this vehicle. + WID_VV_ORDER_LOCATION, ///< Center the main view on the order's target location. WID_VV_GOTO_DEPOT, ///< Order this vehicle to go to the depot. WID_VV_REFIT, ///< Open the refit window. WID_VV_SHOW_ORDERS, ///< Show the orders of this vehicle. @@ -43,7 +45,6 @@ enum VehicleRefitWidgets { /** Widgets of the #VehicleDetailsWindow class. */ enum VehicleDetailsWidgets { WID_VD_CAPTION, ///< Caption of window. - WID_VD_RENAME_VEHICLE, ///< Rename this vehicle. WID_VD_TOP_DETAILS, ///< Panel with generic details. WID_VD_INCREASE_SERVICING_INTERVAL, ///< Increase the servicing interval. WID_VD_DECREASE_SERVICING_INTERVAL, ///< Decrease the servicing interval. |