Add: Ability to toggle visibility of station signs by facility. (#13207)

This commit is contained in:
Peter Nelson 2025-01-14 21:23:35 +00:00 committed by GitHub
parent 74bd064d10
commit 4c8f1b0f81
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 69 additions and 5 deletions

View File

@ -47,9 +47,9 @@ std::unique_ptr<DropDownListItem> MakeDropDownListIconItem(const Dimension &dim,
return std::make_unique<DropDownListIconItem>(dim, sprite, palette, str, value, masked, shaded);
}
std::unique_ptr<DropDownListItem> MakeDropDownListCheckedItem(bool checked, StringID str, int value, bool masked, bool shaded)
std::unique_ptr<DropDownListItem> MakeDropDownListCheckedItem(bool checked, StringID str, int value, bool masked, bool shaded, uint indent)
{
return std::make_unique<DropDownListCheckedItem>(checked, str, value, masked, shaded);
return std::make_unique<DropDownListCheckedItem>(indent, checked, str, value, masked, shaded);
}
static constexpr NWidgetPart _nested_dropdown_menu_widgets[] = {

View File

@ -169,10 +169,31 @@ public:
}
};
/**
* Drop down indent component.
* @tparam TBase Base component.
* @tparam TEnd Position checkmark at end if true, or start if false.
*/
template <class TBase, bool TEnd = false>
class DropDownIndent : public TBase {
uint indent;
public:
template <typename... Args>
explicit DropDownIndent(uint indent, Args&&... args) : TBase(std::forward<Args>(args)...), indent(indent) {}
uint Width() const override { return this->indent * WidgetDimensions::scaled.hsep_indent + this->TBase::Width(); }
void Draw(const Rect &full, const Rect &r, bool sel, Colours bg_colour) const override
{
bool rtl = TEnd ^ (_current_text_dir == TD_RTL);
this->TBase::Draw(full, r.Indent(this->indent * WidgetDimensions::scaled.hsep_indent, rtl), sel, bg_colour);
}
};
/* Commonly used drop down list items. */
using DropDownListDividerItem = DropDownDivider<DropDownListItem>;
using DropDownListStringItem = DropDownString<DropDownListItem>;
using DropDownListIconItem = DropDownIcon<DropDownString<DropDownListItem>>;
using DropDownListCheckedItem = DropDownCheck<DropDownString<DropDownListItem>>;
using DropDownListCheckedItem = DropDownIndent<DropDownCheck<DropDownString<DropDownListItem>>>;
#endif /* DROPDOWN_COMMON_TYPE_H */

View File

@ -21,6 +21,6 @@ std::unique_ptr<DropDownListItem> MakeDropDownListStringItem(StringID str, int v
std::unique_ptr<DropDownListItem> MakeDropDownListStringItem(const std::string &str, int value, bool masked = false, bool shaded = false);
std::unique_ptr<DropDownListItem> MakeDropDownListIconItem(SpriteID sprite, PaletteID palette, StringID str, int value, bool masked = false, bool shaded = false);
std::unique_ptr<DropDownListItem> MakeDropDownListIconItem(const Dimension &dim, SpriteID sprite, PaletteID palette, StringID str, int value, bool masked = false, bool shaded = false);
std::unique_ptr<DropDownListItem> MakeDropDownListCheckedItem(bool checked, StringID str, int value, bool masked = false, bool shaded = false);
std::unique_ptr<DropDownListItem> MakeDropDownListCheckedItem(bool checked, StringID str, int value, bool masked = false, bool shaded = false, uint indent = 0);
#endif /* DROPDOWN_FUNC_H */

View File

@ -443,7 +443,6 @@ STR_SCENEDIT_TOWN_MENU_BUILD_TOWN :Generate towns
STR_SCENEDIT_TOWN_MENU_PACE_HOUSE :Place houses
# Settings menu
###length 16
STR_SETTINGS_MENU_GAME_OPTIONS :Game options
STR_SETTINGS_MENU_CONFIG_SETTINGS_TREE :Settings
STR_SETTINGS_MENU_AI_SETTINGS :AI settings
@ -453,6 +452,11 @@ STR_SETTINGS_MENU_SANDBOX_OPTIONS :Sandbox options
STR_SETTINGS_MENU_TRANSPARENCY_OPTIONS :Transparency options
STR_SETTINGS_MENU_TOWN_NAMES_DISPLAYED :Town names displayed
STR_SETTINGS_MENU_STATION_NAMES_DISPLAYED :Station names displayed
STR_SETTINGS_MENU_STATION_NAMES_TRAIN :{TRAIN} Train stations
STR_SETTINGS_MENU_STATION_NAMES_LORRY :{LORRY} Lorry stops
STR_SETTINGS_MENU_STATION_NAMES_BUS :{BUS} Bus stops
STR_SETTINGS_MENU_STATION_NAMES_SHIP :{SHIP} Docks
STR_SETTINGS_MENU_STATION_NAMES_PLANE :{PLANE} Airports
STR_SETTINGS_MENU_WAYPOINTS_DISPLAYED :Waypoint names displayed
STR_SETTINGS_MENU_SIGNS_DISPLAYED :Signs displayed
STR_SETTINGS_MENU_SHOW_COMPETITOR_SIGNS :Competitor signs and names displayed

View File

@ -12,6 +12,7 @@ extern std::string _config_language_file;
static constexpr std::initializer_list<const char*> _support8bppmodes{"no", "system", "hardware"};
static constexpr std::initializer_list<const char*> _display_opt_modes{"SHOW_TOWN_NAMES", "SHOW_STATION_NAMES", "SHOW_SIGNS", "FULL_ANIMATION", "", "FULL_DETAIL", "WAYPOINTS", "SHOW_COMPETITOR_SIGNS"};
static constexpr std::initializer_list<const char*> _facility_display_opt_modes{"TRAIN", "TRUCK_STOP", "BUS_STOP", "AIRPORT", "DOCK"};
#ifdef WITH_COCOA
extern bool _allow_hidpi_window;
@ -64,6 +65,13 @@ var = _display_opt
def = (1 << DO_SHOW_TOWN_NAMES | 1 << DO_SHOW_STATION_NAMES | 1 << DO_SHOW_SIGNS | 1 << DO_FULL_ANIMATION | 1 << DO_FULL_DETAIL | 1 << DO_SHOW_WAYPOINT_NAMES | 1 << DO_SHOW_COMPETITOR_SIGNS)
full = _display_opt_modes
[SDTG_MMANY]
name = ""facility_display_opt""
type = SLE_UINT8
var = _facility_display_opt
def = (1 << FACIL_TRAIN | 1 << FACIL_TRUCK_STOP | 1 << FACIL_BUS_STOP | 1 << FACIL_AIRPORT | 1 << FACIL_DOCK)
full = _facility_display_opt_modes
[SDTG_BOOL]
name = ""fullscreen""
var = _fullscreen

View File

@ -236,6 +236,11 @@ enum OptionMenuEntries {
OME_TRANSPARENCIES,
OME_SHOW_TOWNNAMES,
OME_SHOW_STATIONNAMES,
OME_SHOW_STATIONNAMES_TRAIN,
OME_SHOW_STATIONNAMES_LORRY,
OME_SHOW_STATIONNAMES_BUS,
OME_SHOW_STATIONNAMES_SHIP,
OME_SHOW_STATIONNAMES_PLANE,
OME_SHOW_WAYPOINTNAMES,
OME_SHOW_SIGNS,
OME_SHOW_COMPETITOR_SIGNS,
@ -271,6 +276,11 @@ static CallBackFunction ToolbarOptionsClick(Window *w)
list.push_back(MakeDropDownListDividerItem());
list.push_back(MakeDropDownListCheckedItem(HasBit(_display_opt, DO_SHOW_TOWN_NAMES), STR_SETTINGS_MENU_TOWN_NAMES_DISPLAYED, OME_SHOW_TOWNNAMES));
list.push_back(MakeDropDownListCheckedItem(HasBit(_display_opt, DO_SHOW_STATION_NAMES), STR_SETTINGS_MENU_STATION_NAMES_DISPLAYED, OME_SHOW_STATIONNAMES));
list.push_back(MakeDropDownListCheckedItem((_facility_display_opt & FACIL_TRAIN) != 0, STR_SETTINGS_MENU_STATION_NAMES_TRAIN, OME_SHOW_STATIONNAMES_TRAIN, false, false, 1));
list.push_back(MakeDropDownListCheckedItem((_facility_display_opt & FACIL_TRUCK_STOP) != 0, STR_SETTINGS_MENU_STATION_NAMES_LORRY, OME_SHOW_STATIONNAMES_LORRY, false, false, 1));
list.push_back(MakeDropDownListCheckedItem((_facility_display_opt & FACIL_BUS_STOP) != 0, STR_SETTINGS_MENU_STATION_NAMES_BUS, OME_SHOW_STATIONNAMES_BUS, false, false, 1));
list.push_back(MakeDropDownListCheckedItem((_facility_display_opt & FACIL_DOCK) != 0, STR_SETTINGS_MENU_STATION_NAMES_SHIP, OME_SHOW_STATIONNAMES_SHIP, false, false, 1));
list.push_back(MakeDropDownListCheckedItem((_facility_display_opt & FACIL_AIRPORT) != 0, STR_SETTINGS_MENU_STATION_NAMES_PLANE, OME_SHOW_STATIONNAMES_PLANE, false, false, 1));
list.push_back(MakeDropDownListCheckedItem(HasBit(_display_opt, DO_SHOW_WAYPOINT_NAMES), STR_SETTINGS_MENU_WAYPOINTS_DISPLAYED, OME_SHOW_WAYPOINTNAMES));
list.push_back(MakeDropDownListCheckedItem(HasBit(_display_opt, DO_SHOW_SIGNS), STR_SETTINGS_MENU_SIGNS_DISPLAYED, OME_SHOW_SIGNS));
list.push_back(MakeDropDownListCheckedItem(HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS), STR_SETTINGS_MENU_SHOW_COMPETITOR_SIGNS, OME_SHOW_COMPETITOR_SIGNS));
@ -284,6 +294,19 @@ static CallBackFunction ToolbarOptionsClick(Window *w)
return CBF_NONE;
}
/**
* Toggle display station names for a facility.
* @param facility Facility to toggle.
*/
static void ToggleFacilityDisplay(const uint8_t facility)
{
if ((_facility_display_opt & facility) == 0) {
SETBITS(_facility_display_opt, facility);
} else {
CLRBITS(_facility_display_opt, facility);
}
}
/**
* Handle click on one of the entries in the Options button menu.
*
@ -303,6 +326,11 @@ static CallBackFunction MenuClickSettings(int index)
case OME_SHOW_TOWNNAMES: ToggleBit(_display_opt, DO_SHOW_TOWN_NAMES); break;
case OME_SHOW_STATIONNAMES: ToggleBit(_display_opt, DO_SHOW_STATION_NAMES); break;
case OME_SHOW_STATIONNAMES_TRAIN: ToggleFacilityDisplay(FACIL_TRAIN); break;
case OME_SHOW_STATIONNAMES_LORRY: ToggleFacilityDisplay(FACIL_TRUCK_STOP); break;
case OME_SHOW_STATIONNAMES_BUS: ToggleFacilityDisplay(FACIL_BUS_STOP); break;
case OME_SHOW_STATIONNAMES_SHIP: ToggleFacilityDisplay(FACIL_DOCK); break;
case OME_SHOW_STATIONNAMES_PLANE: ToggleFacilityDisplay(FACIL_AIRPORT); break;
case OME_SHOW_WAYPOINTNAMES: ToggleBit(_display_opt, DO_SHOW_WAYPOINT_NAMES); break;
case OME_SHOW_SIGNS: ToggleBit(_display_opt, DO_SHOW_SIGNS); break;
case OME_SHOW_COMPETITOR_SIGNS:

View File

@ -38,6 +38,7 @@ extern TransparencyOptionBits _transparency_opt;
extern TransparencyOptionBits _transparency_lock;
extern TransparencyOptionBits _invisibility_opt;
extern uint8_t _display_opt;
extern uint8_t _facility_display_opt;
/**
* Check if the transparency option bit is set

View File

@ -24,6 +24,7 @@ TransparencyOptionBits _transparency_opt; ///< The bits that should be transpar
TransparencyOptionBits _transparency_lock; ///< Prevent these bits from flipping with X.
TransparencyOptionBits _invisibility_opt; ///< The bits that should be invisible.
uint8_t _display_opt; ///< What do we want to draw/do?
uint8_t _facility_display_opt; ///< What station facilities to draw.
class TransparenciesWindow : public Window
{

View File

@ -1448,6 +1448,7 @@ static void ViewportAddKdtreeSigns(DrawPixelInfo *dpi)
case ViewportSignKdtreeItem::VKI_STATION: {
if (!show_stations) break;
const BaseStation *st = BaseStation::Get(item.id.station);
if ((_facility_display_opt & st->facilities) == 0) break;
/* 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;