Merge branch 'tooltip_extension' into jgrpp

pull/564/head
RoqueDeicide 12 months ago
commit 733f53dc9a

@ -1194,3 +1194,67 @@ void DeleteDepotHighlightOfVehicle(const Vehicle *v)
if (w->sel == v->index) ResetObjectToPlace();
}
}
enum DepotTooltipMode : uint8 {
DTM_OFF,
DTM_SIMPLE,
DTM_DETAILED
};
bool GetDepotTooltipString(const TileIndex tile, char *buffer_position, const char *buffer_tail)
{
if (_settings_client.gui.depot_tooltip_mode == DTM_OFF) {
return false;
}
size_t total_vehicle_count = 0;
size_t stopped_vehicle_count = 0;
size_t waiting_vehicle_count = 0;
size_t consist_count = 0;
for (const Vehicle *v : Vehicle::Iterate()) {
if (v->tile == tile && !HasBit(v->subtype, GVSF_VIRTUAL) && v->IsInDepot()) {
if (v->IsPrimaryVehicle()) {
++total_vehicle_count;
if (v->IsWaitingInDepot()) ++waiting_vehicle_count;
if (v->IsStoppedInDepot()) ++stopped_vehicle_count;
}
if (v->type == VEH_TRAIN) {
const Train *loco_or_wago = Train::From(v);
if (loco_or_wago->IsFreeWagon()) {
++consist_count;
++total_vehicle_count;
}
}
}
}
buffer_position[0] = '\0';
if (total_vehicle_count == 0) {
return false;
}
SetDParam(0, total_vehicle_count);
if (_settings_client.gui.depot_tooltip_mode == DTM_SIMPLE || stopped_vehicle_count == 0 && waiting_vehicle_count == 0 && consist_count == 0) {
GetString(buffer_position, STR_DEPOT_VIEW_COUNT_TOOLTIP, buffer_tail);
} else {
buffer_position = GetString(buffer_position, STR_DEPOT_VIEW_TOTAL_TOOLTIP, buffer_tail);
if (stopped_vehicle_count > 0) {
SetDParam(0, stopped_vehicle_count);
buffer_position = GetString(buffer_position, STR_DEPOT_VIEW_STOPPED_TOOLTIP, buffer_tail);
}
if (waiting_vehicle_count > 0) {
SetDParam(0, waiting_vehicle_count);
buffer_position = GetString(buffer_position, STR_DEPOT_VIEW_WAITING_TOOLTIP, buffer_tail);
}
if (consist_count > 0) {
SetDParam(0, consist_count);
GetString(buffer_position, STR_DEPOT_VIEW_CONSISTS_TOOLTIP, buffer_tail);
}
}
return true;
}

@ -3238,3 +3238,139 @@ void ShowIndustryCargoesWindow()
{
ShowIndustryCargoesWindow(NUM_INDUSTRYTYPES);
}
/**
* Fills given data buffer with a string of characters that describe given industry, to be used to display a tooltip, when hovering over the industry tile.
* @param tile Index of the industry tile.
* @param buffer_position Pointer to the beginning of the data buffer to output the string into.
* @param buffer_tail Pointer to the last byte of the data buffer to output the string into.
* @returns A boolean value that indicates whether to show the tooltip.
*/
bool GetIndustryTooltipString(const TileIndex tile, char *buffer_position, const char *buffer_tail)
{
const Industry *industry = Industry::GetByTile(tile);
const IndustrySpec *industry_spec = GetIndustrySpec(industry->type);
buffer_position[0] = 0;
auto current_buffer_position = buffer_position;
auto next = false;
if (_settings_client.gui.industry_tooltip_show_name) {
// Print out the name of the industry.
SetDParam(0, industry_spec->name);
current_buffer_position = GetString(current_buffer_position, STR_INDUSTRY_VIEW_NAME_TOOLTIP, buffer_tail);
next = true;
}
if (_settings_client.gui.industry_tooltip_show_required || _settings_client.gui.industry_tooltip_show_stockpiled) {
constexpr auto accepted_cargo_count = lengthof(industry->accepts_cargo);
CargoSuffix suffixes[accepted_cargo_count];
GetAllCargoSuffixes(CARGOSUFFIX_IN, CST_VIEW, industry, industry->type, industry_spec, industry->accepts_cargo, suffixes);
// Have to query the stockpiling right now, in case callback 37 returns fail.
bool stockpiling = HasBit(industry_spec->callback_mask, CBM_IND_PRODUCTION_CARGO_ARRIVAL) ||
HasBit(industry_spec->callback_mask, CBM_IND_PRODUCTION_256_TICKS);
if (_settings_client.gui.industry_tooltip_show_required) {
// Print out required cargo.
bool first = true;
std::string required_cargo_list;
auto cargo_list_start_buffer_position = current_buffer_position;
for (byte i = 0; i < accepted_cargo_count; ++i) {
auto required_cargo = industry->accepts_cargo[i];
if (required_cargo == CT_INVALID ) {
continue;
}
auto suffix = &suffixes[i];
bool isStockpileWithSuffix = suffix->display == CSD_CARGO_AMOUNT_TEXT;
bool isStockpileWithoutSuffix = suffix->display == CSD_CARGO_AMOUNT;
bool isProperStockpileWithoutSuffix = isStockpileWithoutSuffix && stockpiling; // If callback 37 fails, the result is interpreted as a stockpile, for some reason.
if (isStockpileWithSuffix || isProperStockpileWithoutSuffix) {
if (_settings_client.gui.industry_tooltip_show_stockpiled || !_settings_client.gui.industry_tooltip_show_stockpiled_as_required) continue;
}
auto format = STR_INDUSTRY_VIEW_REQUIRED_TOOLTIP_NEXT;
if (first) {
format = STR_INDUSTRY_VIEW_REQUIRED_TOOLTIP_FIRST;
first = false;
}
SetDParam(0, CargoSpec::Get(required_cargo)->name);
SetDParamStr(1, suffix->text);
GetString(cargo_list_start_buffer_position, format, buffer_tail);
required_cargo_list += cargo_list_start_buffer_position;
}
if (next && !required_cargo_list.empty()) {
current_buffer_position = GetString(current_buffer_position, STR_NEW_LINE, buffer_tail);
}
current_buffer_position += required_cargo_list.copy(current_buffer_position, required_cargo_list.size());
current_buffer_position[0] = '\0';
//++current_buffer_position;
if (!required_cargo_list.empty()) {
next = true;
}
}
// Print out stockpiled cargo.
if (stockpiling && _settings_client.gui.industry_tooltip_show_stockpiled) {
for (byte i = 0; i < accepted_cargo_count; ++i) {
auto stockpiled_cargo = industry->accepts_cargo[i];
if (stockpiled_cargo == CT_INVALID) continue;
auto suffix = &suffixes[i];
if (suffix->display == CSD_CARGO || suffix->display == CSD_CARGO_TEXT) {
continue;
}
if (next) {
current_buffer_position = GetString(current_buffer_position, STR_NEW_LINE, buffer_tail);
}
next = true;
SetDParam(0, stockpiled_cargo);
SetDParam(1, industry->incoming_cargo_waiting[i]);
SetDParamStr(2, suffix->text);
current_buffer_position = GetString(current_buffer_position, STR_INDUSTRY_VIEW_STOCKPILED_TOOLTIP, buffer_tail);
}
}
}
if (_settings_client.gui.industry_tooltip_show_produced) {
constexpr auto produced_cargo_count = lengthof(industry->produced_cargo);
CargoSuffix suffixes[produced_cargo_count];
GetAllCargoSuffixes(CARGOSUFFIX_OUT, CST_VIEW, industry, industry->type, industry_spec, industry->produced_cargo, suffixes);
// Print out amounts of produced cargo.
for (byte i = 0; i < produced_cargo_count; i++) {
auto produced_cargo = industry->produced_cargo[i];
if (produced_cargo == CT_INVALID) continue;
if (next) {
current_buffer_position = GetString(current_buffer_position, STR_NEW_LINE, buffer_tail);
}
next = true;
SetDParam(0, produced_cargo);
SetDParam(1, industry->last_month_production[i]);
SetDParamStr(2, suffixes[i].text);
SetDParam(3, ToPercent8(industry->last_month_pct_transported[i]));
current_buffer_position = GetString(current_buffer_position, STR_INDUSTRY_VIEW_TRANSPORTED_TOOLTIP_EXTENSION, buffer_tail);
}
}
return next;
}

@ -292,12 +292,6 @@ STR_CONFIG_SETTING_VEHICLE_NAMES_LONG :Long
STR_CONFIG_SETTING_SHADED_TREES_ON_SLOPES :Shade trees on slopes: {STRING2}
STR_CONFIG_SETTING_SHADED_TREES_ON_SLOPES_HELPTEXT :Change brightness of trees drawn on slopes. Improves the look of tree cover in mountainous areas.
STR_CONFIG_SETTING_STATION_RATING_TOOLTIP_MODE :Station rating tooltips: {STRING2}
STR_CONFIG_SETTING_STATION_RATING_TOOLTIP_MODE_HELPTEXT :Set whether station rating tooltips are shown and the level of information detail.
STR_CONFIG_SETTING_STATION_RATING_TOOLTIP_MODE_OFF :Off
STR_CONFIG_SETTING_STATION_RATING_TOOLTIP_MODE_SIMPLE :Simple
STR_CONFIG_SETTING_STATION_RATING_TOOLTIP_MODE_DETAILED :Detailed
STR_CONFIG_SETTING_DEMOLISH_CONFIRM_MODE :Ask before demolishing structures: {STRING2}
STR_CONFIG_SETTING_DEMOLISH_CONFIRM_MODE_HELPTEXT :Ask for confirmation before irreversibly demolishing structures.
STR_CONFIG_SETTING_DEMOLISH_CONFIRM_MODE_OFF :Off
@ -1406,11 +1400,30 @@ STR_FINANCES_REPAY_TOOLTIP_EXTRA :{BLACK}{STRING}
STR_FINANCES_BORROW_QUERY_CAPT :{WHITE}Enter the amount of money to borrow
STR_FINANCES_REPAY_QUERY_CAPT :{WHITE}Enter the amount of money to repay
STR_INDUSTRY_VIEW_TRANSPORTED_TOOLTIP :{BLACK}{STRING}{RAW_STRING}
STR_INDUSTRY_VIEW_TRANSPORTED_TOOLTIP_EXTENSION :{}{BLACK}{CARGO_LONG} ({COMMA}%)
STR_NEW_LINE :{}
# Town tooltip
STR_TOWN_NAME_TOOLTIP :{BLACK}{TOWN}
STR_TOWN_NAME_TOOLTIP :{BLACK}{TOWN}{RAW_STRING}
STR_TOWN_NAME_POP_TOOLTIP :{BLACK}{TOWN}: {COMMA}{RAW_STRING}
STR_TOWN_NAME_RATING_TOOLTIP :{}Your rating is {STRING}
STR_INDUSTRY_VIEW_NAME_TOOLTIP :{STRING}
STR_INDUSTRY_VIEW_REQUIRED_TOOLTIP_FIRST :{STRING}{RAW_STRING}
STR_INDUSTRY_VIEW_REQUIRED_TOOLTIP_NEXT :, {STRING}{RAW_STRING}
STR_INDUSTRY_VIEW_STOCKPILED_TOOLTIP :{CARGO_LONG} waiting{RAW_STRING}
STR_INDUSTRY_VIEW_TRANSPORTED_TOOLTIP_EXTENSION :{CARGO_LONG}{RAW_STRING} ({COMMA}%)
STR_INDUSTRY_VIEW_INFO_TOOLTIP :{BLACK}{RAW_STRING}
STR_DEPOT_VIEW_COUNT_TOOLTIP :{COMMA} indside
STR_DEPOT_VIEW_TOTAL_TOOLTIP :Of {COMMA} inside:
STR_DEPOT_VIEW_STOPPED_TOOLTIP :{}{COMMA} {P is are} stopped
STR_DEPOT_VIEW_WAITING_TOOLTIP :{}{COMMA} {P is are} waiting
STR_DEPOT_VIEW_CONSISTS_TOOLTIP :{}{COMMA} {P is are} {P "a " ""}consist{P "" s}
STR_DEPOT_VIEW_INFO_TOOLTIP :{BLACK}{RAW_STRING}
STR_STATION_VIEW_NAME_TOOLTIP :{STATION}{NBSP}
STR_STATION_VIEW_CARGO_LINE_TOOLTIP :{STRING} ({COMMA}%): {CARGO_SHORT}
STR_STATION_VIEW_INFO_TOOLTIP :{BLACK}{RAW_STRING}
STR_VEHICLE_LIST_AGE :{STRING2}, Age: {COMMA} year{P "" s} ({COMMA})
STR_VEHICLE_LIST_AGE_RED :{STRING2}, Age: {RED}{COMMA} {BLACK}year{P "" s} ({COMMA})
@ -2139,5 +2152,46 @@ STR_TOWN_DIRECTORY_INFO :{BLACK}{STRING1
STR_GAME_OPTIONS_GUI_SCALE_MAIN_TOOLBAR :{BLACK}Bigger main toolbar
STR_GAME_OPTIONS_GUI_SCALE_MAIN_TOOLBAR_TOOLTIP :{BLACK}Check this box to increase the scale of the main toolbar
STR_CONFIG_SETTING_INTERFACE_TOOLTIPS :{ORANGE}Tooltips
STR_CONFIG_SETTING_INSTANT_TILE_TOOLTIP :Show viewport tooltips for tiles without a right-click: {STRING2}
STR_CONFIG_SETTING_INSTANT_TILE_TOOLTIP_HELPTEXT :Show viewport tooltips for tile types such as industries without requiring a right-click, when the show tooltips setting is set to right-click.
STR_CONFIG_SETTING_TOWN_NAME_TOOLTIP_MODE :Show viewport tooltips with town names: {STRING2}
STR_CONFIG_SETTING_TOWN_NAME_TOOLTIP_MODE_HELPTEXT :Show viewport tooltips for road and house tiles that belong to towns.
STR_CONFIG_SETTING_TOWN_NAME_TOOLTIP_MODE_OFF :Off
STR_CONFIG_SETTING_TOWN_NAME_TOOLTIP_MODE_ON_IF_HIDDEN :On, if town names are hidden
STR_CONFIG_SETTING_TOWN_NAME_TOOLTIP_MODE_ALWAYS_ON :Always on
STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_SHOW :Show viewport tooltips for industries: {STRING2}
STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_SHOW_HELPTEXT :Show tooltips when hovering over industry tiles.
STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_NAME :Show names in industry viewport tooltips: {STRING2}
STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_NAME_HELPTEXT :Show names of industries in viewport tooltips when hovering over industry tiles.
STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_REQUIRED :Show required cargoes in industry viewport tooltips: {STRING2}
STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_REQUIRED_HELPTEXT :Show a list of cargoes required by industries in viewport tooltips when hovering over industry tiles.
STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_STOCKPILED :Show stockpiled cargoes in industry viewport tooltips: {STRING2}
STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_STOCKPILED_HELPTEXT :Show a list of cargoes stockpiled by industries in viewport tooltips when hovering over industry tiles.
STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_STOCKPILED_AS_REQUIRED :Show stockpiled cargoes as required in viewport tooltips: {STRING2}
STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_STOCKPILED_AS_REQUIRED_HELPTEXT:If normal display of stockpiled cargoes in viewport tooltips is disabled, then allow them to, at least, be displayed as required ones.
STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_PRODUCED :Show produced cargoes in industry viewport tooltips: {STRING2}
STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_PRODUCED_HELPTEXT :Show a list of cargoes produced by industries in viewport tooltips when hovering over industry tiles.
STR_CONFIG_SETTING_DEPOT_TOOLTIP_MODE :Depot viewport tooltips: {STRING2}
STR_CONFIG_SETTING_DEPOT_TOOLTIP_MODE_HELPTEXT :Set whether to show viewport tooltips when hovering over depot tiles and how much information to display.
STR_CONFIG_SETTING_DEPOT_TOOLTIP_MODE_OFF :Off
STR_CONFIG_SETTING_DEPOT_TOOLTIP_MODE_SIMPLE :Simple
STR_CONFIG_SETTING_DEPOT_TOOLTIP_MODE_DETAILED :Detailed
STR_CONFIG_SETTING_STATION_VIEWPORT_TOOLTIP_NAME :Show names in station viewport tooltips: {STRING2}
STR_CONFIG_SETTING_STATION_VIEWPORT_TOOLTIP_NAME_HELPTEXT :Show the name of the station in a viewport tooltip when hovering over it.
STR_CONFIG_SETTING_STATION_VIEWPORT_TOOLTIP_CARGO :Show cargo details in station viewport tooltips: {STRING2}
STR_CONFIG_SETTING_STATION_VIEWPORT_TOOLTIP_CARGO_HELPTEXT :Show the list of amounts and ratings of cargo that had ever been delivered to the station by industries, towns or by vehicles via unload/transfer order that doesn't result in the final delivery.
STR_CONFIG_SETTING_STATION_VIEWPORT_TOOLTIP_NAME_OFF :Off
STR_CONFIG_SETTING_STATION_VIEWPORT_TOOLTIP_NAME_ON_IF_HIDDEN :On, if station names are hidden
STR_CONFIG_SETTING_STATION_VIEWPORT_TOOLTIP_NAME_ALWAYS_ON :Always on
STR_CONFIG_SETTING_STATION_RATING_TOOLTIP_MODE :Station rating tooltips: {STRING2}
STR_CONFIG_SETTING_STATION_RATING_TOOLTIP_MODE_HELPTEXT :Set whether station rating tooltips are shown and the level of information detail.
STR_CONFIG_SETTING_STATION_RATING_TOOLTIP_MODE_OFF :Off
STR_CONFIG_SETTING_STATION_RATING_TOOLTIP_MODE_SIMPLE :Simple
STR_CONFIG_SETTING_STATION_RATING_TOOLTIP_MODE_DETAILED :Detailed

@ -1967,14 +1967,29 @@ static SettingsContainer &GetSettingsTree()
SettingsPage *general = interface->Add(new SettingsPage(STR_CONFIG_SETTING_INTERFACE_GENERAL));
{
general->Add(new SettingEntry("gui.osk_activation"));
general->Add(new SettingEntry("gui.hover_delay_ms"));
general->Add(new ConditionallyHiddenSettingEntry("gui.instant_tile_tooltip", []() -> bool { return _settings_client.gui.hover_delay_ms != 0; }));
general->Add(new SettingEntry("gui.errmsg_duration"));
general->Add(new SettingEntry("gui.window_snap_radius"));
general->Add(new SettingEntry("gui.window_soft_limit"));
general->Add(new SettingEntry("gui.right_mouse_wnd_close"));
}
SettingsPage *tooltips = interface->Add(new SettingsPage(STR_CONFIG_SETTING_INTERFACE_TOOLTIPS));
{
tooltips->Add(new SettingEntry("gui.hover_delay_ms"));
tooltips->Add(new ConditionallyHiddenSettingEntry("gui.instant_tile_tooltip", []() -> bool { return _settings_client.gui.hover_delay_ms != 0; }));
tooltips->Add(new SettingEntry("gui.town_name_tooltip_mode"));
tooltips->Add(new SettingEntry("gui.industry_tooltip_show"));
tooltips->Add(new ConditionallyHiddenSettingEntry("gui.industry_tooltip_show_name", []() -> bool { return !_settings_client.gui.industry_tooltip_show; }));
tooltips->Add(new ConditionallyHiddenSettingEntry("gui.industry_tooltip_show_required", []() -> bool { return !_settings_client.gui.industry_tooltip_show; }));
tooltips->Add(new ConditionallyHiddenSettingEntry("gui.industry_tooltip_show_stockpiled", []() -> bool { return !_settings_client.gui.industry_tooltip_show; }));
tooltips->Add(new ConditionallyHiddenSettingEntry("gui.industry_tooltip_show_stockpiled_as_required", []() -> bool { return !_settings_client.gui.industry_tooltip_show || _settings_client.gui.industry_tooltip_show_stockpiled || !_settings_client.gui.industry_tooltip_show_required; }));
tooltips->Add(new ConditionallyHiddenSettingEntry("gui.industry_tooltip_show_produced", []() -> bool { return !_settings_client.gui.industry_tooltip_show; }));
tooltips->Add(new SettingEntry("gui.depot_tooltip_mode"));
tooltips->Add(new SettingEntry("gui.station_viewport_tooltip_name"));
tooltips->Add(new SettingEntry("gui.station_viewport_tooltip_cargo"));
tooltips->Add(new SettingEntry("gui.station_rating_tooltip_mode"));
}
SettingsPage *save = interface->Add(new SettingsPage(STR_CONFIG_SETTING_INTERFACE_SAVE));
{
save->Add(new SettingEntry("gui.autosave"));
@ -2134,7 +2149,6 @@ static SettingsContainer &GetSettingsTree()
interface->Add(new SettingEntry("gui.prefer_teamchat"));
interface->Add(new SettingEntry("gui.sort_track_types_by_speed"));
interface->Add(new SettingEntry("gui.allow_hiding_waypoint_labels"));
interface->Add(new SettingEntry("gui.station_rating_tooltip_mode"));
}
SettingsPage *advisors = main->Add(new SettingsPage(STR_CONFIG_SETTING_ADVISORS));

@ -140,6 +140,17 @@ struct GUISettings : public TimeSettings {
byte errmsg_duration; ///< duration of error message
uint16 hover_delay_ms; ///< time required to activate a hover event, in milliseconds
bool instant_tile_tooltip; ///< don't require a right click to activate a hover event to show a tooltip for an in-game tile (e.g. industry).
uint8 town_name_tooltip_mode; ///< when to display town names when hovering over roads and houses. (0 = never, 1 = only if town names are hidden, 2 = always)
bool industry_tooltip_show; ///< whether to display tooltips, when hovering over industry tiles.
bool industry_tooltip_show_name; ///< whether to display the name of the industry, when hovering over one of its tiles.
bool industry_tooltip_show_required; ///< whether to display cargoes required by the industry, when hovering over one of its tiles.
bool industry_tooltip_show_stockpiled; ///< whether to display cargoes stockpiled by the industry, when hovering over one of its tiles.
bool industry_tooltip_show_stockpiled_as_required; ///< whether to display cargoes stockpiled by the industry as ones required by the industry, when hovering over one of its tiles and normal display of stockpiled cargoes in viewport tooltips is turned off.
bool industry_tooltip_show_produced; ///< whether to display cargoes produced by the industry, when hovering over one of its tiles.
uint8 depot_tooltip_mode; ///< Display mode for depot viewport tooltips. (0 = never, 1 = just a total number of vehicles, 2 = total number of vehicles in the depot along with a breakdown of numbers)
uint8 station_viewport_tooltip_name; ///< Show the name of the station in a viewport tooltip. (0 = never, 1 = only if station names are hidden, 2 = always)
bool station_viewport_tooltip_cargo; ///< Show a list of cargo details at the station in a viewport tooltip.
uint8 station_rating_tooltip_mode; ///< Station rating tooltip mode
bool link_terraform_toolbar; ///< display terraform toolbar when displaying rail, road, water and airport toolbars
uint8 smallmap_land_colour; ///< colour used for land and heightmap at the smallmap
uint8 scroll_mode; ///< viewport scroll mode
@ -256,7 +267,6 @@ struct GUISettings : public TimeSettings {
uint8 linkgraph_colours; ///< linkgraph overlay colours
uint8 vehicle_names; ///< Vehicle naming scheme
bool shade_trees_on_slopes; ///< Shade trees on slopes
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 dual_pane_train_purchase_window_dual_buttons; ///< Dual pane train purchase window: dual buttons

@ -3096,3 +3096,51 @@ bool ShouldShowBaseStationViewportLabel(const BaseStation *bst)
!HasBit(_extra_display_opt, XDO_SHOW_HIDDEN_SIGNS)) return false;
return true;
}
enum StationTooltipNameMode : uint8 {
STNM_OFF,
STNM_ON_IF_HIDDEN,
STNM_ALWAYS_ON
};
char *StationGetSpecialStringExternal(char *buff, int x, const char *last);
bool GetStationViewportTooltipString(const TileIndex tile, char *buffer_position, const char *buffer_tail)
{
const StationID station_id = GetStationIndex(tile);
const Station *station = Station::Get(station_id);
bool next = false;
if (_settings_client.gui.station_viewport_tooltip_name == STNM_ALWAYS_ON ||
_settings_client.gui.station_viewport_tooltip_name == STNM_ON_IF_HIDDEN && !HasBit(_display_opt, DO_SHOW_STATION_NAMES)) {
SetDParam(0, station_id);
buffer_position = GetString(buffer_position, STR_STATION_VIEW_NAME_TOOLTIP, buffer_tail);
buffer_position = StationGetSpecialStringExternal(buffer_position, station->facilities, buffer_tail);
next = true;
}
if (_settings_client.gui.station_viewport_tooltip_cargo) {
constexpr size_t goods_entry_count = lengthof(station->goods);
for (size_t i = 0; i < goods_entry_count; ++i) {
const GoodsEntry *goods_entry = station->goods + i;
if (!HasBit(goods_entry->status, GoodsEntry::GES_RATING)) continue;
if (next) {
buffer_position = GetString(buffer_position, STR_NEW_LINE, buffer_tail);
}
SetDParam(0, CargoSpec::Get(i)->name);
SetDParam(1, ToPercent8(goods_entry->rating));
SetDParam(2, i);
SetDParam(3, goods_entry->cargo.TotalCount());
buffer_position = GetString(buffer_position, STR_STATION_VIEW_CARGO_LINE_TOOLTIP, buffer_tail);
next = true;
}
}
return next;
}

@ -2047,6 +2047,11 @@ static char *StationGetSpecialString(char *buff, int x, const char *last)
return buff;
}
char *StationGetSpecialStringExternal(char *buff, int x, const char *last)
{
return StationGetSpecialString(buff, x, last);
}
static char *GetSpecialTownNameString(char *buff, int ind, uint32 seed, const char *last)
{
return GenerateTownNameString(buff, last, ind, seed);

@ -4552,6 +4552,102 @@ def = false
str = STR_CONFIG_SETTING_INSTANT_TILE_TOOLTIP
strhelp = STR_CONFIG_SETTING_INSTANT_TILE_TOOLTIP_HELPTEXT
[SDTC_VAR]
var = gui.town_name_tooltip_mode
type = SLE_UINT8
flags = SF_NOT_IN_SAVE | SF_NO_NETWORK_SYNC | SF_GUI_DROPDOWN
def = 1
min = 0
max = 2
str = STR_CONFIG_SETTING_TOWN_NAME_TOOLTIP_MODE
strhelp = STR_CONFIG_SETTING_TOWN_NAME_TOOLTIP_MODE_HELPTEXT
strval = STR_CONFIG_SETTING_TOWN_NAME_TOOLTIP_MODE_OFF
[SDTC_BOOL]
var = gui.industry_tooltip_show
flags = SF_NOT_IN_SAVE | SF_NO_NETWORK_SYNC
def = true
str = STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_SHOW
strhelp = STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_SHOW_HELPTEXT
post_cb = [](auto) { InvalidateWindowClassesData(WC_GAME_OPTIONS); }
[SDTC_BOOL]
var = gui.industry_tooltip_show_name
flags = SF_NOT_IN_SAVE | SF_NO_NETWORK_SYNC
def = true
str = STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_NAME
strhelp = STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_NAME_HELPTEXT
[SDTC_BOOL]
var = gui.industry_tooltip_show_required
flags = SF_NOT_IN_SAVE | SF_NO_NETWORK_SYNC
def = false
str = STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_REQUIRED
strhelp = STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_REQUIRED_HELPTEXT
post_cb = [](auto) { InvalidateWindowClassesData(WC_GAME_OPTIONS); }
[SDTC_BOOL]
var = gui.industry_tooltip_show_stockpiled
flags = SF_NOT_IN_SAVE | SF_NO_NETWORK_SYNC
def = false
str = STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_STOCKPILED
strhelp = STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_STOCKPILED_HELPTEXT
post_cb = [](auto) { InvalidateWindowClassesData(WC_GAME_OPTIONS); }
[SDTC_BOOL]
var = gui.industry_tooltip_show_stockpiled_as_required
flags = SF_NOT_IN_SAVE | SF_NO_NETWORK_SYNC
def = true
str = STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_STOCKPILED_AS_REQUIRED
strhelp = STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_STOCKPILED_AS_REQUIRED_HELPTEXT
[SDTC_BOOL]
var = gui.industry_tooltip_show_produced
flags = SF_NOT_IN_SAVE | SF_NO_NETWORK_SYNC
def = true
str = STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_PRODUCED
strhelp = STR_CONFIG_SETTING_INDUSTRY_TOOLTIP_PRODUCED_HELPTEXT
[SDTC_VAR]
var = gui.depot_tooltip_mode
type = SLE_UINT8
flags = SF_NOT_IN_SAVE | SF_NO_NETWORK_SYNC | SF_GUI_DROPDOWN
def = 1
min = 0
max = 2
str = STR_CONFIG_SETTING_DEPOT_TOOLTIP_MODE
strhelp = STR_CONFIG_SETTING_DEPOT_TOOLTIP_MODE_HELPTEXT
strval = STR_CONFIG_SETTING_DEPOT_TOOLTIP_MODE_OFF
[SDTC_VAR]
var = gui.station_viewport_tooltip_name
type = SLE_UINT8
flags = SF_NOT_IN_SAVE | SF_NO_NETWORK_SYNC | SF_GUI_DROPDOWN
def = 1
min = 0
max = 2
str = STR_CONFIG_SETTING_STATION_VIEWPORT_TOOLTIP_NAME
strhelp = STR_CONFIG_SETTING_STATION_VIEWPORT_TOOLTIP_NAME_HELPTEXT
strval = STR_CONFIG_SETTING_STATION_VIEWPORT_TOOLTIP_NAME_OFF
[SDTC_BOOL]
var = gui.station_viewport_tooltip_cargo
flags = SF_NOT_IN_SAVE | SF_NO_NETWORK_SYNC
def = true
str = STR_CONFIG_SETTING_STATION_VIEWPORT_TOOLTIP_CARGO
strhelp = STR_CONFIG_SETTING_STATION_VIEWPORT_TOOLTIP_CARGO_HELPTEXT
[SDTC_VAR]
var = gui.station_rating_tooltip_mode
type = SLE_UINT8
flags = SF_NOT_IN_SAVE | SF_NO_NETWORK_SYNC | SF_GUI_DROPDOWN
def = 1
min = 0
max = 2
str = STR_CONFIG_SETTING_STATION_RATING_TOOLTIP_MODE
strhelp = STR_CONFIG_SETTING_STATION_RATING_TOOLTIP_MODE_HELPTEXT
strval = STR_CONFIG_SETTING_STATION_RATING_TOOLTIP_MODE_OFF
[SDTC_OMANY]
var = gui.osk_activation
type = SLE_UINT8
@ -5732,17 +5828,6 @@ strhelp = STR_CONFIG_SETTING_SHADED_TREES_ON_SLOPES_HELPTEXT
post_cb = [](auto) { MarkWholeScreenDirty(); }
cat = SC_BASIC
[SDTC_VAR]
var = gui.station_rating_tooltip_mode
type = SLE_UINT8
flags = SF_NOT_IN_SAVE | SF_NO_NETWORK_SYNC | SF_GUI_DROPDOWN
def = 1
min = 0
max = 2
str = STR_CONFIG_SETTING_STATION_RATING_TOOLTIP_MODE
strhelp = STR_CONFIG_SETTING_STATION_RATING_TOOLTIP_MODE_HELPTEXT
strval = STR_CONFIG_SETTING_STATION_RATING_TOOLTIP_MODE_OFF
[SDTC_VAR]
var = gui.demolish_confirm_mode
type = SLE_UINT8

@ -18,6 +18,7 @@
#include "window_func.h"
#include "gfx_func.h"
#include "industry.h"
#include "town.h"
#include "town_map.h"
#include "widgets/viewport_widget.h"
@ -219,37 +220,117 @@ void ShowExtraViewportWindowForTileUnderCursor()
ShowExtraViewportWindow(pt.x != -1 ? TileVirtXY(pt.x, pt.y) : INVALID_TILE);
}
enum TownNameTooltipMode : uint8 {
TNTM_OFF,
TNTM_ON_IF_HIDDEN,
TNTM_ALWAYS_ON
};
void ShowTownNameTooltip(Window *w, const TileIndex tile, char *buffer_position, const char *buffer_tail)
{
if (_settings_client.gui.town_name_tooltip_mode == TNTM_OFF) return;
if (HasBit(_display_opt, DO_SHOW_TOWN_NAMES) && _settings_client.gui.town_name_tooltip_mode == TNTM_ON_IF_HIDDEN) return; // No need for a town name tooltip when it is already displayed
StringID tooltip_string = STR_TOWN_NAME_TOOLTIP;
TownID town_id = GetTownIndex(tile);
const Town *town = Town::Get(town_id);
*buffer_position = '\0';
if (_game_mode != GM_EDITOR && _local_company < MAX_COMPANIES && HasBit(town->have_ratings, _local_company)) {
int local_authority_rating_thresholds[] = { RATING_APPALLING, RATING_VERYPOOR, RATING_POOR, RATING_MEDIOCRE, RATING_GOOD, RATING_VERYGOOD,
RATING_EXCELLENT, RATING_OUTSTANDING };
constexpr size_t threshold_count = lengthof(local_authority_rating_thresholds);
auto local_rating = town->ratings[_local_company];
auto rating_string = STR_CARGO_RATING_APPALLING;
for (int i = 0; i < threshold_count && local_rating > local_authority_rating_thresholds[i]; ++i) ++rating_string;
SetDParam(0, rating_string);
GetString(buffer_position, STR_TOWN_NAME_RATING_TOOLTIP, buffer_tail);
}
uint rating_string_parameter_index = 1;
SetDParam(0, town_id);
if (_settings_client.gui.population_in_label) {
tooltip_string = STR_TOWN_NAME_POP_TOOLTIP;
SetDParam(1, town->cache.population);
rating_string_parameter_index = 2;
}
SetDParamStr(rating_string_parameter_index, buffer_position);
GuiShowTooltips(w, tooltip_string, 0, nullptr, TCC_HOVER_VIEWPORT);
}
bool GetIndustryTooltipString(TileIndex tile, char *buffer_position, const char *buffer_tail);
void ShowIndustryTooltip(Window *w, const TileIndex tile, char *buffer_position, const char *buffer_tail)
{
if (!_settings_client.gui.industry_tooltip_show ||
!(_settings_client.gui.industry_tooltip_show_name || _settings_client.gui.industry_tooltip_show_produced ||
_settings_client.gui.industry_tooltip_show_required || _settings_client.gui.industry_tooltip_show_stockpiled)) return;
if (!GetIndustryTooltipString(tile, buffer_position, buffer_tail)) return;
SetDParamStr(0, buffer_position);
GuiShowTooltips(w, STR_INDUSTRY_VIEW_INFO_TOOLTIP, 0, nullptr, TCC_HOVER_VIEWPORT);
}
bool GetDepotTooltipString(TileIndex tile, char *buffer_position, const char *buffer_tail);
void ShowDepotTooltip(Window *w, const TileIndex tile, char *buffer_position, const char *buffer_tail)
{
if (!GetDepotTooltipString(tile, buffer_position, buffer_tail)) return;
SetDParamStr(0, buffer_position);
GuiShowTooltips(w, STR_DEPOT_VIEW_INFO_TOOLTIP, 0, nullptr, TCC_HOVER_VIEWPORT);
}
bool GetStationViewportTooltipString(TileIndex tile, char *buffer_position, const char *buffer_tail);
void ShowStationViewportTooltip(Window *w, const TileIndex tile, char *buffer_position, const char *buffer_tail)
{
if (!GetStationViewportTooltipString(tile, buffer_position, buffer_tail)) return;
SetDParamStr(0, buffer_position);
GuiShowTooltips(w, STR_STATION_VIEW_INFO_TOOLTIP, 0, nullptr, TCC_HOVER_VIEWPORT);
}
void ShowTooltipForTile(Window *w, const TileIndex tile)
{
static char buffer[1024];
char *buffer_start = buffer;
char *buffer_tail = lastof(buffer);
switch (GetTileType(tile)) {
case MP_ROAD:
if (IsRoadDepot(tile)) return;
if (IsRoadDepot(tile)) {
ShowDepotTooltip(w, tile, buffer_start, buffer_tail);
return;
}
/* FALL THROUGH */
case MP_HOUSE: {
if (HasBit(_display_opt, DO_SHOW_TOWN_NAMES)) return; // No need for a town name tooltip when it is already displayed
SetDParam(0, GetTownIndex(tile));
GuiShowTooltips(w, STR_TOWN_NAME_TOOLTIP, 0, nullptr, TCC_HOVER_VIEWPORT);
ShowTownNameTooltip(w, tile, buffer_start, buffer_tail);
break;
}
case MP_INDUSTRY: {
static char buffer[1024];
const Industry *ind = Industry::GetByTile(tile);
const IndustrySpec *indsp = GetIndustrySpec(ind->type);
buffer[0] = 0;
char *buf_pos = buffer;
for (byte i = 0; i < lengthof(ind->produced_cargo); i++) {
if (ind->produced_cargo[i] != CT_INVALID) {
SetDParam(0, ind->produced_cargo[i]);
SetDParam(1, ind->last_month_production[i]);
SetDParam(2, ToPercent8(ind->last_month_pct_transported[i]));
buf_pos = GetString(buf_pos, STR_INDUSTRY_VIEW_TRANSPORTED_TOOLTIP_EXTENSION, lastof(buffer));
}
ShowIndustryTooltip(w, tile, buffer_start, buffer_tail);
break;
}
case MP_RAILWAY: {
if (!IsRailDepot(tile)) return;
ShowDepotTooltip(w, tile, buffer_start, buffer_tail);
break;
}
case MP_WATER: {
if (!IsShipDepot(tile)) return;
ShowDepotTooltip(w, tile, buffer_start, buffer_tail);
break;
}
case MP_STATION: {
if (IsHangar(tile)) {
ShowDepotTooltip(w, tile, buffer_start, buffer_tail);
} else {
ShowStationViewportTooltip(w, tile, buffer_start, buffer_tail);
}
SetDParam(0, indsp->name);
SetDParamStr(1, buffer);
GuiShowTooltips(w, STR_INDUSTRY_VIEW_TRANSPORTED_TOOLTIP, 0, nullptr, TCC_HOVER_VIEWPORT);
break;
}
default:

Loading…
Cancel
Save