From d81cbc25b80dad6cf84b217bd5557a78947971a5 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Fri, 21 Jan 2022 23:37:53 +0000 Subject: [PATCH] Add setting to allow hiding viewport labels of inidivudal waypoints --- src/command.cpp | 2 ++ src/command_type.h | 1 + src/lang/english.txt | 9 ++++++- src/openttd.h | 1 + src/saveload/extended_ver_sl.cpp | 1 + src/saveload/extended_ver_sl.h | 1 + src/saveload/station_sl.cpp | 1 + src/settings_gui.cpp | 1 + src/settings_type.h | 1 + src/station.cpp | 7 ++---- src/station_cmd.cpp | 3 +-- src/station_func.h | 2 ++ src/station_gui.cpp | 9 +++++++ src/table/settings/misc_settings.ini | 2 +- src/table/settings/settings.ini | 8 +++++++ src/toolbar_gui.cpp | 5 ++++ src/viewport.cpp | 4 ++++ src/waypoint.cpp | 2 ++ src/waypoint_base.h | 12 ++++++++-- src/waypoint_cmd.cpp | 35 ++++++++++++++++++++++++++-- src/waypoint_gui.cpp | 20 ++++++++++++++++ src/widgets/waypoint_widget.h | 2 ++ 22 files changed, 116 insertions(+), 13 deletions(-) diff --git a/src/command.cpp b/src/command.cpp index edaffc2f45..fcfff1a10f 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -68,6 +68,7 @@ CommandProc CmdBuildTunnel; CommandProc CmdBuildTrainDepot; CommandProcEx CmdBuildRailWaypoint; CommandProc CmdRenameWaypoint; +CommandProc CmdSetWaypointLabelHidden; CommandProc CmdRemoveFromRailWaypoint; CommandProc CmdBuildRoadStop; @@ -316,6 +317,7 @@ static const Command _command_proc_table[] = { DEF_CMD(CmdConvertRail, 0, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_CONVERT_RAIL DEF_CMD(CmdBuildRailWaypoint, 0, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_BUILD_RAIL_WAYPOINT DEF_CMD(CmdRenameWaypoint, 0, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_WAYPOINT + DEF_CMD(CmdSetWaypointLabelHidden, 0, CMDT_OTHER_MANAGEMENT ), // CMD_SET_WAYPOINT_LABEL_HIDDEN DEF_CMD(CmdRemoveFromRailWaypoint, 0, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_REMOVE_FROM_RAIL_WAYPOINT DEF_CMD(CmdBuildRoadStop, CMD_NO_WATER | CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_BUILD_ROAD_STOP diff --git a/src/command_type.h b/src/command_type.h index 2ef016c499..1bc924b428 100644 --- a/src/command_type.h +++ b/src/command_type.h @@ -252,6 +252,7 @@ enum Commands { CMD_BUILD_RAIL_WAYPOINT, ///< build a waypoint CMD_RENAME_WAYPOINT, ///< rename a waypoint + CMD_SET_WAYPOINT_LABEL_HIDDEN, ///< set whether waypoint label is hidden CMD_REMOVE_FROM_RAIL_WAYPOINT, ///< remove a (rectangle of) tiles from a rail waypoint CMD_BUILD_ROAD_STOP, ///< build a road stop diff --git a/src/lang/english.txt b/src/lang/english.txt index e46f062af4..fbc68a61f9 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -420,9 +420,11 @@ STR_SETTINGS_MENU_FULL_ANIMATION :Full animation STR_SETTINGS_MENU_FULL_DETAIL :Full detail STR_SETTINGS_MENU_TRANSPARENT_BUILDINGS :Transparent buildings STR_SETTINGS_MENU_TRANSPARENT_SIGNS :Transparent signs -STR_SETTINGS_MENU_MONEY_TEXT_EFFECTS :Income/cost texts displayed ############ range ends here +STR_SETTINGS_MENU_MONEY_TEXT_EFFECTS :Income/cost texts displayed +STR_SETTINGS_MENU_SHOW_HIDDEN_SIGNS :Hidden signs and names displayed + # File menu ###length 5 STR_FILE_MENU_SAVE_GAME :Save game @@ -1611,6 +1613,9 @@ STR_CONFIG_SETTING_DEMOLISH_CONFIRM_MODE_ALL :Industries and STR_CONFIG_SETTING_DUAL_PANE_TRAIN_PURCHASE_WINDOW :Separate locomotives and wagons in train purchase window: {STRING2} STR_CONFIG_SETTING_DUAL_PANE_TRAIN_PURCHASE_WINDOW_HELPTEXT :When enabled, the train purchase window shows locomotives and wagons in separate side-by-side lists. +STR_CONFIG_SETTING_ALLOW_HIDE_WAYPOINT_LABEL :Allow hiding waypoint viewport labels: {STRING2} +STR_CONFIG_SETTING_ALLOW_HIDE_WAYPOINT_LABEL_HELPTEXT :When enabled, waypoints can have their viewport labels individually hidden.{}This is useful when waypoints are used decoratively or when minor waypoints do not require a label. + STR_CONFIG_SETTING_ADV_SIG_BRIDGE_TUN_MODES :Enable signals on bridges/tunnels advanced modes: {STRING2} STR_CONFIG_SETTING_ADV_SIG_BRIDGE_TUN_MODES_HELPTEXT :Enables use of advanced modes of signal simulation on bridges and tunnels. When disabled, bridges/tunnels which are not already in an advanced mode cannot be changed to an advanced mode, however other players may choose to enable this setting and use an advanced mode. @@ -4611,6 +4616,8 @@ STR_BUOY_VIEW_CHANGE_BUOY_NAME :{BLACK}Change b STR_EDIT_WAYPOINT_NAME :{WHITE}Edit waypoint name +STR_WAYPOINT_VIEW_HIDE_VIEWPORT_LABEL :{BLACK}Hide the name label for this waypoint + # Finances window STR_FINANCES_CAPTION :{WHITE}{COMPANY} Finances {BLACK}{COMPANY_NUM} STR_FINANCES_EXPENDITURE_INCOME_TITLE :{WHITE}Expenditure/Income diff --git a/src/openttd.h b/src/openttd.h index 32a0fa7404..0adf90a203 100644 --- a/src/openttd.h +++ b/src/openttd.h @@ -54,6 +54,7 @@ enum DisplayOptions { /** Extra Display Options */ enum ExtraDisplayOptions { XDO_SHOW_MONEY_TEXT_EFFECTS = 0, ///< Display money text effects. + XDO_SHOW_HIDDEN_SIGNS = 1, ///< Show hidden signs }; extern GameMode _game_mode; diff --git a/src/saveload/extended_ver_sl.cpp b/src/saveload/extended_ver_sl.cpp index 6423b4da7d..25038310d3 100644 --- a/src/saveload/extended_ver_sl.cpp +++ b/src/saveload/extended_ver_sl.cpp @@ -165,6 +165,7 @@ const SlxiSubChunkInfo _sl_xv_sub_chunk_infos[] = { { XSLFI_COMPANY_PW, XSCF_IGNORABLE_ALL, 1, 1, "company_password", nullptr, nullptr, "PLYP" }, { XSLFI_ST_INDUSTRY_CARGO_MODE, XSCF_IGNORABLE_UNKNOWN, 1, 1, "st_industry_cargo_mode", nullptr, nullptr, nullptr }, { XSLFI_TL_SPEED_LIMIT, XSCF_IGNORABLE_UNKNOWN, 1, 1, "tl_speed_limit", nullptr, nullptr, nullptr }, + { XSLFI_WAYPOINT_FLAGS, XSCF_NULL, 1, 1, "waypoint_flags", nullptr, nullptr, nullptr }, { XSLFI_SCRIPT_INT64, XSCF_NULL, 1, 1, "script_int64", nullptr, nullptr, nullptr }, { XSLFI_NULL, XSCF_NULL, 0, 0, nullptr, nullptr, nullptr, nullptr },// This is the end marker }; diff --git a/src/saveload/extended_ver_sl.h b/src/saveload/extended_ver_sl.h index 17450d9d6a..9366be442d 100644 --- a/src/saveload/extended_ver_sl.h +++ b/src/saveload/extended_ver_sl.h @@ -119,6 +119,7 @@ enum SlXvFeatureIndex { XSLFI_COMPANY_PW, ///< Company passwords XSLFI_ST_INDUSTRY_CARGO_MODE, ///< Station industry cargo mode setting XSLFI_TL_SPEED_LIMIT, ///< Through load maximum speed setting + XSLFI_WAYPOINT_FLAGS, ///< Waypoint flags XSLFI_SCRIPT_INT64, ///< See: SLV_SCRIPT_INT64 diff --git a/src/saveload/station_sl.cpp b/src/saveload/station_sl.cpp index 6e0f72cdf7..81be8b1e28 100644 --- a/src/saveload/station_sl.cpp +++ b/src/saveload/station_sl.cpp @@ -461,6 +461,7 @@ static const SaveLoad _waypoint_desc[] = { SLE_CONDVAR(Waypoint, train_station.tile, SLE_UINT32, SLV_124, SL_MAX_VERSION), SLE_CONDVAR(Waypoint, train_station.w, SLE_FILE_U8 | SLE_VAR_U16, SLV_124, SL_MAX_VERSION), SLE_CONDVAR(Waypoint, train_station.h, SLE_FILE_U8 | SLE_VAR_U16, SLV_124, SL_MAX_VERSION), + SLE_CONDVAR_X(Waypoint, waypoint_flags, SLE_UINT16, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_WAYPOINT_FLAGS)), }; /** diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index 7e02350b63..29242804b1 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -1923,6 +1923,7 @@ static SettingsContainer &GetSettingsTree() interface->Add(new SettingEntry("gui.vehicle_names")); interface->Add(new SettingEntry("gui.station_rating_tooltip_mode")); interface->Add(new SettingEntry("gui.dual_pane_train_purchase_window")); + interface->Add(new SettingEntry("gui.allow_hiding_waypoint_labels")); } SettingsPage *advisors = main->Add(new SettingsPage(STR_CONFIG_SETTING_ADVISORS)); diff --git a/src/settings_type.h b/src/settings_type.h index 48961beb62..5899719ed3 100644 --- a/src/settings_type.h +++ b/src/settings_type.h @@ -246,6 +246,7 @@ struct GUISettings : public TimeSettings { uint8 station_rating_tooltip_mode; ///< Station rating tooltip mode uint8 demolish_confirm_mode; ///< Demolition confirmation mode bool dual_pane_train_purchase_window; ///< Dual pane train purchase window + bool allow_hiding_waypoint_labels; ///< Allow hiding waypoint viewport labels uint16 console_backlog_timeout; ///< the minimum amount of time items should be in the console backlog before they will be removed in ~3 seconds granularity. uint16 console_backlog_length; ///< the minimum amount of items in the console backlog before items will be removed. diff --git a/src/station.cpp b/src/station.cpp index e623963c6b..a99bf26bb6 100644 --- a/src/station.cpp +++ b/src/station.cpp @@ -66,11 +66,6 @@ BaseStation::~BaseStation() DeleteWindowById(WC_AIRCRAFT_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_AIRCRAFT, this->owner, this->index).Pack()); DeleteWindowById(WC_DEPARTURES_BOARD, this->index); DeleteWindowById(WC_STATION_CARGO, this->index); - - if (HasBit(_display_opt, Station::IsExpected(this) ? DO_SHOW_STATION_NAMES : DO_SHOW_WAYPOINT_NAMES) && - !(_local_company != this->owner && this->owner != OWNER_NONE && !HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS))) { - this->sign.MarkDirty(ZOOM_LVL_DRAW_SPR); - } } Station::Station(TileIndex tile) : @@ -174,6 +169,8 @@ Station::~Station() _station_kdtree.Remove(this->index); if (_viewport_sign_kdtree_valid && this->sign.kdtree_valid) _viewport_sign_kdtree.Remove(ViewportSignKdtreeItem::MakeStation(this->index)); + + if (ShouldShowBaseStationViewportLabel(this)) this->sign.MarkDirty(ZOOM_LVL_DRAW_SPR); } diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index 20513663a5..f0a8dda687 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -478,8 +478,7 @@ void Station::UpdateVirtCoord() SetDParam(0, this->index); SetDParam(1, this->facilities); - bool shown = HasBit(_display_opt, DO_SHOW_STATION_NAMES) && !(_local_company != this->owner && this->owner != OWNER_NONE && !HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS)); - this->sign.UpdatePosition(shown ? ZOOM_LVL_DRAW_SPR : ZOOM_LVL_END, pt.x, pt.y, STR_VIEWPORT_STATION); + this->sign.UpdatePosition(ShouldShowBaseStationViewportLabel(this) ? ZOOM_LVL_DRAW_SPR : ZOOM_LVL_END, pt.x, pt.y, STR_VIEWPORT_STATION); if (_viewport_sign_kdtree_valid) _viewport_sign_kdtree.Insert(ViewportSignKdtreeItem::MakeStation(this->index)); diff --git a/src/station_func.h b/src/station_func.h index fdad0e64e0..51eb8a3ff2 100644 --- a/src/station_func.h +++ b/src/station_func.h @@ -69,4 +69,6 @@ static inline Money StationMaintenanceCost(uint32 num) Money AirportMaintenanceCost(Owner owner); +bool ShouldShowBaseStationViewportLabel(const BaseStation *bst); + #endif /* STATION_FUNC_H */ diff --git a/src/station_gui.cpp b/src/station_gui.cpp index 5257df092c..541cdb0984 100644 --- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -3018,3 +3018,12 @@ void GuiShowStationRatingTooltip(Window *parent, const Station *st, const CargoS DeleteWindowById(WC_STATION_RATING_TOOLTIP, 0); new StationRatingTooltipWindow(parent, st, cs); } + +bool ShouldShowBaseStationViewportLabel(const BaseStation *bst) +{ + if (!HasBit(_display_opt, Station::IsExpected(bst) ? DO_SHOW_STATION_NAMES : DO_SHOW_WAYPOINT_NAMES)) return false; + if (HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS) && (_local_company != bst->owner && bst->owner != OWNER_NONE)) return false; + if (Waypoint::IsExpected(bst) && HasBit(Waypoint::From(bst)->waypoint_flags, WPF_HIDE_LABEL) && _settings_client.gui.allow_hiding_waypoint_labels && + !HasBit(_extra_display_opt, XDO_SHOW_HIDDEN_SIGNS)) return false; + return true; +} diff --git a/src/table/settings/misc_settings.ini b/src/table/settings/misc_settings.ini index 82a6e31a77..40e22681b0 100644 --- a/src/table/settings/misc_settings.ini +++ b/src/table/settings/misc_settings.ini @@ -12,7 +12,7 @@ extern std::string _config_language_file; static std::initializer_list _support8bppmodes{"no", "system" , "hardware"}; static std::initializer_list _display_opt_modes{"SHOW_TOWN_NAMES", "SHOW_STATION_NAMES", "SHOW_SIGNS", "FULL_ANIMATION", "", "FULL_DETAIL", "WAYPOINTS", "SHOW_COMPETITOR_SIGNS"}; -static std::initializer_list _extra_display_opt_modes{"SHOW_MONEY_TEXT_EFFECTS"}; +static std::initializer_list _extra_display_opt_modes{"SHOW_MONEY_TEXT_EFFECTS", "SHOW_HIDDEN_SIGNS"}; #ifdef WITH_COCOA extern bool _allow_hidpi_window; diff --git a/src/table/settings/settings.ini b/src/table/settings/settings.ini index 0c69448290..ef763792b1 100644 --- a/src/table/settings/settings.ini +++ b/src/table/settings/settings.ini @@ -5428,6 +5428,14 @@ def = true str = STR_CONFIG_SETTING_DUAL_PANE_TRAIN_PURCHASE_WINDOW strhelp = STR_CONFIG_SETTING_DUAL_PANE_TRAIN_PURCHASE_WINDOW_HELPTEXT +[SDTC_BOOL] +var = gui.allow_hiding_waypoint_labels +flags = SF_NOT_IN_SAVE | SF_NO_NETWORK_SYNC +def = false +str = STR_CONFIG_SETTING_ALLOW_HIDE_WAYPOINT_LABEL +strhelp = STR_CONFIG_SETTING_ALLOW_HIDE_WAYPOINT_LABEL_HELPTEXT +post_cb = [](auto) { MarkWholeScreenDirty(); InvalidateWindowClassesData(WC_WAYPOINT_VIEW, 0); } + ; For the dedicated build we'll enable dates in logs by default. [SDTC_BOOL] ifdef = DEDICATED diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp index d464ff39ce..dbb808beb5 100644 --- a/src/toolbar_gui.cpp +++ b/src/toolbar_gui.cpp @@ -312,6 +312,7 @@ enum OptionMenuEntries { OME_TRANSPARENTBUILDINGS, OME_SHOW_STATIONSIGNS, OME_SHOW_MONEYTEXT, + OME_SHOW_HIDDEN_SIGNS, }; /** @@ -338,6 +339,9 @@ static CallBackFunction ToolbarOptionsClick(Window *w) list.emplace_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_WAYPOINTS_DISPLAYED, OME_SHOW_WAYPOINTNAMES, false, HasBit(_display_opt, DO_SHOW_WAYPOINT_NAMES))); list.emplace_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_SIGNS_DISPLAYED, OME_SHOW_SIGNS, false, HasBit(_display_opt, DO_SHOW_SIGNS))); list.emplace_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_SHOW_COMPETITOR_SIGNS, OME_SHOW_COMPETITOR_SIGNS, false, HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS))); + if (_settings_client.gui.allow_hiding_waypoint_labels) { + list.emplace_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_SHOW_HIDDEN_SIGNS, OME_SHOW_HIDDEN_SIGNS, false, HasBit(_extra_display_opt, XDO_SHOW_HIDDEN_SIGNS))); + } list.emplace_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_FULL_ANIMATION, OME_FULL_ANIMATION, false, HasBit(_display_opt, DO_FULL_ANIMATION))); list.emplace_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_FULL_DETAIL, OME_FULL_DETAILS, false, HasBit(_display_opt, DO_FULL_DETAIL))); list.emplace_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_TRANSPARENT_BUILDINGS, OME_TRANSPARENTBUILDINGS, false, IsTransparencySet(TO_HOUSES))); @@ -378,6 +382,7 @@ static CallBackFunction MenuClickSettings(int index) case OME_TRANSPARENTBUILDINGS: ToggleTransparency(TO_HOUSES); break; case OME_SHOW_STATIONSIGNS: ToggleTransparency(TO_SIGNS); break; case OME_SHOW_MONEYTEXT: ToggleBit(_extra_display_opt, XDO_SHOW_MONEY_TEXT_EFFECTS); break; + case OME_SHOW_HIDDEN_SIGNS: ToggleBit(_extra_display_opt, XDO_SHOW_HIDDEN_SIGNS); break; } MarkWholeScreenDirty(); return CBF_NONE; diff --git a/src/viewport.cpp b/src/viewport.cpp index 44f915949f..18d6b159d9 100644 --- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -1748,6 +1748,7 @@ static void ViewportAddKdtreeSigns(DrawPixelInfo *dpi, bool towns_only) bool show_towns = HasBit(_display_opt, DO_SHOW_TOWN_NAMES) && _game_mode != GM_MENU; bool show_signs = HasBit(_display_opt, DO_SHOW_SIGNS) && !IsInvisibilitySet(TO_SIGNS) && !towns_only; bool show_competitors = HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS) && !towns_only; + bool hide_hidden_waypoints = _settings_client.gui.allow_hiding_waypoint_labels && !HasBit(_extra_display_opt, XDO_SHOW_HIDDEN_SIGNS); const BaseStation *st; const Sign *si; @@ -1775,6 +1776,7 @@ static void ViewportAddKdtreeSigns(DrawPixelInfo *dpi, bool towns_only) /* Don't draw if station is owned by another company and competitor station names are hidden. Stations owned by none are never ignored. */ if (!show_competitors && _local_company != st->owner && st->owner != OWNER_NONE) break; + if (hide_hidden_waypoints && HasBit(Waypoint::From(st)->waypoint_flags, WPF_HIDE_LABEL)) break; stations.push_back(st); break; @@ -4056,6 +4058,7 @@ static bool CheckClickOnViewportSign(const Viewport *vp, int x, int y) bool show_towns = HasBit(_display_opt, DO_SHOW_TOWN_NAMES); bool show_signs = HasBit(_display_opt, DO_SHOW_SIGNS) && !IsInvisibilitySet(TO_SIGNS); bool show_competitors = HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS); + bool hide_hidden_waypoints = _settings_client.gui.allow_hiding_waypoint_labels && !HasBit(_extra_display_opt, XDO_SHOW_HIDDEN_SIGNS); /* Topmost of each type that was hit */ BaseStation *st = nullptr, *last_st = nullptr; @@ -4076,6 +4079,7 @@ static bool CheckClickOnViewportSign(const Viewport *vp, int x, int y) if (!show_waypoints) break; st = BaseStation::Get(item.id.station); if (!show_competitors && _local_company != st->owner && st->owner != OWNER_NONE) break; + if (hide_hidden_waypoints && HasBit(Waypoint::From(st)->waypoint_flags, WPF_HIDE_LABEL)) break; if (CheckClickOnViewportSign(vp, x, y, &st->sign)) last_st = st; break; diff --git a/src/waypoint.cpp b/src/waypoint.cpp index 3d04f1113a..eb9ef17ac6 100644 --- a/src/waypoint.cpp +++ b/src/waypoint.cpp @@ -62,4 +62,6 @@ Waypoint::~Waypoint() /* Remove all news items */ DeleteStationNews(this->index); + + if (ShouldShowBaseStationViewportLabel(this)) this->sign.MarkDirty(ZOOM_LVL_DRAW_SPR); } diff --git a/src/waypoint_base.h b/src/waypoint_base.h index 2c7cc530f6..f2419972aa 100644 --- a/src/waypoint_base.h +++ b/src/waypoint_base.h @@ -12,15 +12,23 @@ #include "base_station_base.h" +/** + * Enum to handle waypoint flags. + */ +enum WaypointFlags { + WPF_HIDE_LABEL = 0, ///< Hide waypoint label +}; + /** Representation of a waypoint. */ struct Waypoint FINAL : SpecializedStation { - uint16 town_cn; ///< The N-1th waypoint for this town (consecutive number) + uint16 town_cn; ///< The N-1th waypoint for this town (consecutive number) + uint16 waypoint_flags; ///< Waypoint flags, see WaypointFlags /** * Create a waypoint at the given tile. * @param tile The location of the waypoint. */ - Waypoint(TileIndex tile = INVALID_TILE) : SpecializedStation(tile) { } + Waypoint(TileIndex tile = INVALID_TILE) : SpecializedStation(tile), waypoint_flags(0) { } ~Waypoint(); void UpdateVirtCoord() override; diff --git a/src/waypoint_cmd.cpp b/src/waypoint_cmd.cpp index 5fc6449f09..40c4e49a91 100644 --- a/src/waypoint_cmd.cpp +++ b/src/waypoint_cmd.cpp @@ -42,8 +42,7 @@ void Waypoint::UpdateVirtCoord() if (_viewport_sign_kdtree_valid && this->sign.kdtree_valid) _viewport_sign_kdtree.Remove(ViewportSignKdtreeItem::MakeWaypoint(this->index)); SetDParam(0, this->index); - bool shown = HasBit(_display_opt, DO_SHOW_WAYPOINT_NAMES) && !(_local_company != this->owner && this->owner != OWNER_NONE && !HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS)); - this->sign.UpdatePosition(shown ? ZOOM_LVL_DRAW_SPR : ZOOM_LVL_END, pt.x, pt.y - 32 * ZOOM_LVL_BASE, STR_VIEWPORT_WAYPOINT); + this->sign.UpdatePosition(ShouldShowBaseStationViewportLabel(this) ? ZOOM_LVL_DRAW_SPR : ZOOM_LVL_END, pt.x, pt.y - 32 * ZOOM_LVL_BASE, STR_VIEWPORT_WAYPOINT); if (_viewport_sign_kdtree_valid) _viewport_sign_kdtree.Insert(ViewportSignKdtreeItem::MakeWaypoint(this->index)); @@ -450,3 +449,35 @@ CommandCost CmdRenameWaypoint(TileIndex tile, DoCommandFlag flags, uint32 p1, ui } return CommandCost(); } + +/** + * Set whether waypoint label is hidden + * @param tile unused + * @param flags type of operation + * @param p1 id of waypoint + * @param p2 hidden state + * @param text the new name or an empty string when resetting to the default + * @return the cost of this operation or an error + */ +CommandCost CmdSetWaypointLabelHidden(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) +{ + Waypoint *wp = Waypoint::GetIfValid(p1); + if (wp == nullptr) return CMD_ERROR; + + if (wp->owner != OWNER_NONE) { + CommandCost ret = CheckOwnership(wp->owner); + if (ret.Failed()) return ret; + } + + if (flags & DC_EXEC) { + SB(wp->waypoint_flags, WPF_HIDE_LABEL, 1, p2 != 0 ? 1 : 0); + + if (HasBit(_display_opt, DO_SHOW_WAYPOINT_NAMES) && + !(_local_company != wp->owner && wp->owner != OWNER_NONE && !HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS))) { + wp->sign.MarkDirty(ZOOM_LVL_DRAW_SPR); + } + + InvalidateWindowData(WC_WAYPOINT_VIEW, wp->index); + } + return CommandCost(); +} diff --git a/src/waypoint_gui.cpp b/src/waypoint_gui.cpp index 618cd8cfeb..44a75a9a27 100644 --- a/src/waypoint_gui.cpp +++ b/src/waypoint_gui.cpp @@ -34,6 +34,7 @@ struct WaypointWindow : Window { private: VehicleType vt; ///< Vehicle type using the waypoint. Waypoint *wp; ///< Waypoint displayed by the window. + bool show_hide_label; ///< Show hide label button /** * Get the center tile of the waypoint. @@ -65,6 +66,8 @@ public: this->GetWidget(WID_W_CENTER_VIEW)->tool_tip = STR_WAYPOINT_VIEW_CENTER_TOOLTIP; this->GetWidget(WID_W_RENAME)->tool_tip = STR_WAYPOINT_VIEW_CHANGE_WAYPOINT_NAME; } + this->show_hide_label = (this->vt == VEH_TRAIN && _settings_client.gui.allow_hiding_waypoint_labels); + this->GetWidget(WID_W_TOGGLE_HIDDEN_SEL)->SetDisplayedPlane(this->show_hide_label ? 0 : SZSP_NONE); this->FinishInitNested(window_number); this->owner = this->wp->owner; @@ -109,6 +112,10 @@ public: case WID_W_DEPARTURES: // show departure times of vehicles ShowWaypointDepartures((StationID)this->wp->index); break; + + case WID_W_TOGGLE_HIDDEN: + DoCommandP(0, this->window_number, HasBit(this->wp->waypoint_flags, WPF_HIDE_LABEL) ? 0 : 1, CMD_SET_WAYPOINT_LABEL_HIDDEN | CMD_MSG(STR_ERROR_CAN_T_CHANGE_WAYPOINT_NAME)); + break; } } @@ -122,9 +129,19 @@ public: if (!gui_scope) return; /* You can only change your own waypoints */ this->SetWidgetDisabledState(WID_W_RENAME, !this->wp->IsInUse() || (this->wp->owner != _local_company && this->wp->owner != OWNER_NONE)); + this->SetWidgetDisabledState(WID_W_TOGGLE_HIDDEN, !this->wp->IsInUse() || this->wp->owner != _local_company); /* Disable the widget for waypoints with no use */ this->SetWidgetDisabledState(WID_W_SHOW_VEHICLES, !this->wp->IsInUse()); + this->SetWidgetLoweredState(WID_W_TOGGLE_HIDDEN, HasBit(this->wp->waypoint_flags, WPF_HIDE_LABEL)); + + bool show_hide_label = (this->vt == VEH_TRAIN && _settings_client.gui.allow_hiding_waypoint_labels); + if (show_hide_label != this->show_hide_label) { + this->show_hide_label = show_hide_label; + this->GetWidget(WID_W_TOGGLE_HIDDEN_SEL)->SetDisplayedPlane(this->show_hide_label ? 0 : SZSP_NONE); + this->ReInit(); + } + ScrollWindowToTile(this->GetCenterTile(), this, true); } @@ -176,6 +193,9 @@ static const NWidgetPart _nested_waypoint_view_widgets[] = { EndContainer(), NWidget(NWID_HORIZONTAL), NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_W_DEPARTURES), SetMinimalSize(100, 12), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_STATION_VIEW_DEPARTURES_BUTTON, STR_STATION_VIEW_DEPARTURES_TOOLTIP), + NWidget(NWID_SELECTION, INVALID_COLOUR, WID_W_TOGGLE_HIDDEN_SEL), + NWidget(WWT_IMGBTN, COLOUR_GREY, WID_W_TOGGLE_HIDDEN), SetMinimalSize(15, 12), SetDataTip(SPR_MISC_GUI_BASE, STR_WAYPOINT_VIEW_HIDE_VIEWPORT_LABEL), + EndContainer(), NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_W_SHOW_VEHICLES), SetMinimalSize(15, 12), SetDataTip(STR_SHIP, STR_STATION_VIEW_SCHEDULED_SHIPS_TOOLTIP), NWidget(WWT_RESIZEBOX, COLOUR_GREY), EndContainer(), diff --git a/src/widgets/waypoint_widget.h b/src/widgets/waypoint_widget.h index 24c6572d38..cf10dd8185 100644 --- a/src/widgets/waypoint_widget.h +++ b/src/widgets/waypoint_widget.h @@ -18,6 +18,8 @@ enum WaypointWidgets { WID_W_RENAME, ///< Rename this waypoint. WID_W_SHOW_VEHICLES, ///< Show the vehicles visiting this waypoint. WID_W_DEPARTURES, ///< Departures button. + WID_W_TOGGLE_HIDDEN, ///< Toggle label hidden. + WID_W_TOGGLE_HIDDEN_SEL, ///< Toggle label hidden selector. }; #endif /* WIDGETS_WAYPOINT_WIDGET_H */