[Feature] Extended functionality of industry viewport tooltips.

Added ability to turn them off or to show any combination of the following: name, required, stockpiled or produced cargoes.
pull/564/head
RoqueDeicide 11 months ago
parent 8eea01717f
commit 33ee78f9ac

@ -3244,3 +3244,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;
}

@ -1383,12 +1383,18 @@ 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_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_VEHICLE_LIST_AGE :{STRING2}, Age: {COMMA} year{P "" s} ({COMMA})
STR_VEHICLE_LIST_AGE_RED :{STRING2}, Age: {RED}{COMMA} {BLACK}year{P "" s} ({COMMA})
STR_VEHICLE_LIST_CARGO_LIST :{STRING2}, Cargoes: {CARGO_LIST}
@ -2127,6 +2133,19 @@ 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_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

@ -1934,6 +1934,12 @@ static SettingsContainer &GetSettingsTree()
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.station_rating_tooltip_mode"));
}

@ -134,6 +134,12 @@ struct GUISettings : public TimeSettings {
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 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

@ -4563,6 +4563,51 @@ 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.station_rating_tooltip_mode
type = SLE_UINT8

@ -233,8 +233,26 @@ void ShowTownNameTooltip(Window *w, const TileIndex tile)
GuiShowTooltips(w, STR_TOWN_NAME_TOOLTIP, 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);
}
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;
@ -244,24 +262,7 @@ void ShowTooltipForTile(Window *w, const TileIndex tile)
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));
}
}
SetDParam(0, indsp->name);
SetDParamStr(1, buffer);
GuiShowTooltips(w, STR_INDUSTRY_VIEW_TRANSPORTED_TOOLTIP, 0, nullptr, TCC_HOVER_VIEWPORT);
ShowIndustryTooltip(w, tile, buffer_start, buffer_tail);
break;
}
default:

Loading…
Cancel
Save