Merge branch 'tooltip_extension' into jgrpp
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user