1
0
Fork 0

Compare commits

...

4 Commits

Author SHA1 Message Date
Peter Nelson 75b3b994d8
Merge 13f24c25ca into 03f5f7145f 2025-07-18 17:24:29 +00:00
Peter Nelson 03f5f7145f
Fix f6e78a480d: Truncation ellipsis always drawn in initial colour. (#14451)
Truncation ellipsis is now a layouted line, so we can no longer rely on implicitly using the last set colour.
2025-07-18 18:24:19 +01:00
Peter Nelson 0dc40877fd
Codechange: Initialise/reset font cache with FontSizes bitset. (#14448)
Instead of choosing either "Normal/Small/Large" or "Monospace", use an EnumBitSet to allow any combination.
2025-07-18 18:23:28 +01:00
Peter Nelson 13f24c25ca
Add: Variable to test for a badge on a nearby tile. 2025-05-21 22:10:13 +01:00
20 changed files with 243 additions and 38 deletions

View File

@ -2369,7 +2369,7 @@ static bool ConFont(std::span<std::string_view> argv)
FontCacheSubSetting *setting = GetFontCacheSubSetting(fs); FontCacheSubSetting *setting = GetFontCacheSubSetting(fs);
/* Make sure all non sprite fonts are loaded. */ /* Make sure all non sprite fonts are loaded. */
if (!setting->font.empty() && !fc->HasParent()) { if (!setting->font.empty() && !fc->HasParent()) {
InitFontCache(fs == FS_MONO); InitFontCache(fs);
fc = FontCache::Get(fs); fc = FontCache::Get(fs);
} }
IConsolePrint(CC_DEFAULT, "{} font:", FontSizeToName(fs)); IConsolePrint(CC_DEFAULT, "{} font:", FontSizeToName(fs));

View File

@ -126,10 +126,10 @@ void SetFont(FontSize fontsize, const std::string &font, uint size)
CheckForMissingGlyphs(); CheckForMissingGlyphs();
_fcsettings = std::move(backup); _fcsettings = std::move(backup);
} else { } else {
InitFontCache(true); InitFontCache(fontsize);
} }
LoadStringWidthTable(fontsize == FS_MONO); LoadStringWidthTable(fontsize);
UpdateAllVirtCoords(); UpdateAllVirtCoords();
ReInitAllWindows(true); ReInitAllWindows(true);
@ -213,15 +213,13 @@ std::string GetFontCacheFontName(FontSize fs)
/** /**
* (Re)initialize the font cache related things, i.e. load the non-sprite fonts. * (Re)initialize the font cache related things, i.e. load the non-sprite fonts.
* @param monospace Whether to initialise the monospace or regular fonts. * @param fontsizes Font sizes to be initialised.
*/ */
void InitFontCache(bool monospace) void InitFontCache(FontSizes fontsizes)
{ {
FontCache::InitializeFontCaches(); FontCache::InitializeFontCaches();
for (FontSize fs = FS_BEGIN; fs < FS_END; fs++) { for (FontSize fs : fontsizes) {
if (monospace != (fs == FS_MONO)) continue;
FontCache *fc = FontCache::Get(fs); FontCache *fc = FontCache::Get(fs);
if (fc->HasParent()) delete fc; if (fc->HasParent()) delete fc;

View File

@ -167,9 +167,9 @@ inline void InitializeUnicodeGlyphMap()
} }
} }
inline void ClearFontCache() inline void ClearFontCache(FontSizes fontsizes)
{ {
for (FontSize fs = FS_BEGIN; fs < FS_END; fs++) { for (FontSize fs : fontsizes) {
FontCache::Get(fs)->ClearFontCache(); FontCache::Get(fs)->ClearFontCache();
} }
} }
@ -231,7 +231,7 @@ inline FontCacheSubSetting *GetFontCacheSubSetting(FontSize fs)
uint GetFontCacheFontSize(FontSize fs); uint GetFontCacheFontSize(FontSize fs);
std::string GetFontCacheFontName(FontSize fs); std::string GetFontCacheFontName(FontSize fs);
void InitFontCache(bool monospace); void InitFontCache(FontSizes fontsizes);
void UninitFontCache(); void UninitFontCache();
bool GetFontAAState(); bool GetFontAAState();

View File

@ -8,6 +8,7 @@
/** @file gfx.cpp Handling of drawing text and other gfx related stuff. */ /** @file gfx.cpp Handling of drawing text and other gfx related stuff. */
#include "stdafx.h" #include "stdafx.h"
#include "gfx_func.h"
#include "gfx_layout.h" #include "gfx_layout.h"
#include "progress.h" #include "progress.h"
#include "zoom_func.h" #include "zoom_func.h"
@ -579,7 +580,7 @@ static int DrawLayoutLine(const ParagraphLayouter::Line &line, int y, int left,
const uint shadow_offset = ScaleGUITrad(1); const uint shadow_offset = ScaleGUITrad(1);
auto draw_line = [&](const ParagraphLayouter::Line &line, bool do_shadow, int left, int min_x, int max_x, bool truncation) { auto draw_line = [&](const ParagraphLayouter::Line &line, bool do_shadow, int left, int min_x, int max_x, bool truncation, TextColour &last_colour) {
const DrawPixelInfo *dpi = _cur_dpi; const DrawPixelInfo *dpi = _cur_dpi;
int dpi_left = dpi->left; int dpi_left = dpi->left;
int dpi_right = dpi->left + dpi->width - 1; int dpi_right = dpi->left + dpi->width - 1;
@ -592,10 +593,15 @@ static int DrawLayoutLine(const ParagraphLayouter::Line &line, int y, int left,
FontCache *fc = f->fc; FontCache *fc = f->fc;
TextColour colour = f->colour; TextColour colour = f->colour;
if (colour == TC_INVALID || HasFlag(default_colour, TC_FORCED)) colour = default_colour; if (colour == TC_INVALID || HasFlag(last_colour, TC_FORCED)) {
colour = last_colour;
} else {
/* Update the last colour for the truncation ellipsis. */
last_colour = colour;
}
bool colour_has_shadow = (colour & TC_NO_SHADE) == 0 && colour != TC_BLACK; bool colour_has_shadow = (colour & TC_NO_SHADE) == 0 && colour != TC_BLACK;
SetColourRemap(do_shadow ? TC_BLACK : colour); // the last run also sets the colour for the truncation dots
if (do_shadow && (!fc->GetDrawGlyphShadow() || !colour_has_shadow)) continue; if (do_shadow && (!fc->GetDrawGlyphShadow() || !colour_has_shadow)) continue;
SetColourRemap(do_shadow ? TC_BLACK : colour);
for (int i = 0; i < run.GetGlyphCount(); i++) { for (int i = 0; i < run.GetGlyphCount(); i++) {
GlyphID glyph = glyphs[i]; GlyphID glyph = glyphs[i];
@ -623,11 +629,12 @@ static int DrawLayoutLine(const ParagraphLayouter::Line &line, int y, int left,
/* Draw shadow, then foreground */ /* Draw shadow, then foreground */
for (bool do_shadow : {true, false}) { for (bool do_shadow : {true, false}) {
draw_line(line, do_shadow, left - offset_x, min_x, max_x, truncation); TextColour last_colour = default_colour;
draw_line(line, do_shadow, left - offset_x, min_x, max_x, truncation, last_colour);
if (truncation) { if (truncation) {
int x = (_current_text_dir == TD_RTL) ? left : (right - truncation_width); int x = (_current_text_dir == TD_RTL) ? left : (right - truncation_width);
draw_line(*truncation_layout->front(), do_shadow, x, INT32_MIN, INT32_MAX, false); draw_line(*truncation_layout->front(), do_shadow, x, INT32_MIN, INT32_MAX, false, last_colour);
} }
} }
@ -1240,14 +1247,14 @@ static void GfxMainBlitter(const Sprite *sprite, int x, int y, BlitterMode mode,
} }
/** /**
* Initialize _stringwidth_table cache * Initialize _stringwidth_table cache for the specified font sizes.
* @param monospace Whether to load the monospace cache or the normal fonts. * @param fontsizes Font sizes to initialise.
*/ */
void LoadStringWidthTable(bool monospace) void LoadStringWidthTable(FontSizes fontsizes)
{ {
ClearFontCache(); ClearFontCache(fontsizes);
for (FontSize fs = monospace ? FS_MONO : FS_BEGIN; fs < (monospace ? FS_END : FS_MONO); fs++) { for (FontSize fs : fontsizes) {
for (uint i = 0; i != 224; i++) { for (uint i = 0; i != 224; i++) {
_stringwidth_table[fs][i] = GetGlyphWidth(fs, i + 32); _stringwidth_table[fs][i] = GetGlyphWidth(fs, i + 32);
} }
@ -1812,7 +1819,7 @@ bool AdjustGUIZoom(bool automatic)
if (old_font_zoom != _font_zoom) { if (old_font_zoom != _font_zoom) {
GfxClearFontSpriteCache(); GfxClearFontSpriteCache();
} }
ClearFontCache(); ClearFontCache(FONTSIZES_ALL);
LoadStringWidthTable(); LoadStringWidthTable();
SetupWidgetDimensions(); SetupWidgetDimensions();

View File

@ -149,7 +149,7 @@ int GetStringHeight(StringID str, int maxw);
int GetStringLineCount(std::string_view str, int maxw); int GetStringLineCount(std::string_view str, int maxw);
Dimension GetStringMultiLineBoundingBox(StringID str, const Dimension &suggestion); Dimension GetStringMultiLineBoundingBox(StringID str, const Dimension &suggestion);
Dimension GetStringMultiLineBoundingBox(std::string_view str, const Dimension &suggestion, FontSize fontsize = FS_NORMAL); Dimension GetStringMultiLineBoundingBox(std::string_view str, const Dimension &suggestion, FontSize fontsize = FS_NORMAL);
void LoadStringWidthTable(bool monospace = false); void LoadStringWidthTable(FontSizes fontsizes = FONTSIZES_REQUIRED);
void DrawDirtyBlocks(); void DrawDirtyBlocks();
void AddDirtyBlock(int left, int top, int right, int bottom); void AddDirtyBlock(int left, int top, int right, int bottom);

View File

@ -258,6 +258,13 @@ enum FontSize : uint8_t {
}; };
DECLARE_INCREMENT_DECREMENT_OPERATORS(FontSize) DECLARE_INCREMENT_DECREMENT_OPERATORS(FontSize)
using FontSizes = EnumBitSet<FontSize, uint8_t>;
/** Mask of all possible font sizes. */
constexpr FontSizes FONTSIZES_ALL{FS_NORMAL, FS_SMALL, FS_LARGE, FS_MONO};
/** Mask of font sizes required to be present. */
constexpr FontSizes FONTSIZES_REQUIRED{FS_NORMAL, FS_SMALL, FS_LARGE};
inline std::string_view FontSizeToName(FontSize fs) inline std::string_view FontSizeToName(FontSize fs)
{ {
static const std::string_view SIZE_TO_NAME[] = { "medium", "small", "large", "mono" }; static const std::string_view SIZE_TO_NAME[] = { "medium", "small", "large", "mono" };

View File

@ -245,7 +245,7 @@ static void RealChangeBlitter(std::string_view repl_blitter)
/* Clear caches that might have sprites for another blitter. */ /* Clear caches that might have sprites for another blitter. */
VideoDriver::GetInstance()->ClearSystemSprites(); VideoDriver::GetInstance()->ClearSystemSprites();
ClearFontCache(); ClearFontCache(FONTSIZES_ALL);
GfxClearSpriteCache(); GfxClearSpriteCache();
ReInitAllWindows(false); ReInitAllWindows(false);
} }
@ -326,7 +326,7 @@ void CheckBlitter()
{ {
if (!SwitchNewGRFBlitter()) return; if (!SwitchNewGRFBlitter()) return;
ClearFontCache(); ClearFontCache(FONTSIZES_ALL);
GfxClearSpriteCache(); GfxClearSpriteCache();
ReInitAllWindows(false); ReInitAllWindows(false);
} }
@ -338,7 +338,7 @@ void GfxLoadSprites()
SwitchNewGRFBlitter(); SwitchNewGRFBlitter();
VideoDriver::GetInstance()->ClearSystemSprites(); VideoDriver::GetInstance()->ClearSystemSprites();
ClearFontCache(); ClearFontCache(FONTSIZES_ALL);
GfxInitSpriteMem(); GfxInitSpriteMem();
LoadSpriteTables(); LoadSpriteTables();
GfxInitPalettes(); GfxInitPalettes();

View File

@ -193,6 +193,7 @@ static uint32_t GetAirportTileIDAtOffset(TileIndex tile, const Station *st, uint
/* Get airport tile ID at offset */ /* Get airport tile ID at offset */
case 0x62: return GetAirportTileIDAtOffset(GetNearbyTile(parameter, this->tile), this->st, this->ro.grffile->grfid); case 0x62: return GetAirportTileIDAtOffset(GetNearbyTile(parameter, this->tile), this->st, this->ro.grffile->grfid);
case 0x79: return GetNearbyBadgeVariableResult(*this->ro.grffile, GetNearbyTile(parameter, this->tile), this->ro);
case 0x7A: return GetBadgeVariableResult(*this->ro.grffile, this->ats->badges, parameter); case 0x7A: return GetBadgeVariableResult(*this->ro.grffile, this->ats->badges, parameter);
} }

View File

@ -8,13 +8,25 @@
/** @file newgrf_badge.cpp Functionality for NewGRF badges. */ /** @file newgrf_badge.cpp Functionality for NewGRF badges. */
#include "stdafx.h" #include "stdafx.h"
#include "house.h"
#include "industry_map.h"
#include "newgrf.h" #include "newgrf.h"
#include "newgrf_airporttiles.h"
#include "newgrf_badge.h" #include "newgrf_badge.h"
#include "newgrf_badge_type.h" #include "newgrf_badge_type.h"
#include "newgrf_object.h"
#include "newgrf_roadstop.h"
#include "newgrf_station.h"
#include "newgrf_spritegroup.h" #include "newgrf_spritegroup.h"
#include "rail.h"
#include "rail_map.h"
#include "station_map.h"
#include "stringfilter_type.h" #include "stringfilter_type.h"
#include "strings_func.h" #include "strings_func.h"
#include "tile_map.h"
#include "timer/timer_game_calendar.h" #include "timer/timer_game_calendar.h"
#include "town_map.h"
#include "tunnelbridge_map.h"
#include "table/strings.h" #include "table/strings.h"
@ -216,7 +228,173 @@ BadgeResolverObject::BadgeResolverObject(const Badge &badge, GrfSpecFeature feat
} }
/** /**
* Test for a matching badge in a list of badges, returning the number of matching bits. * Test if a list of badges contains a badge.
* @param badges List of badges.
* @param badge Badge to find.
* @returns true iff the badge appears in the list.
*/
static bool BadgesContains(std::span<const BadgeID> badges, BadgeID badge)
{
return std::ranges::find(badges, badge) != std::end(badges);
}
/**
* Test if a rail type has a badge.
* @param rt Rail type to test.
* @param badge Badge to find.
* @returns true iff the rail type has the badge.
*/
static bool RailTypeHasBadge(RailType rt, BadgeID badge)
{
return rt != INVALID_RAILTYPE && BadgesContains(GetRailTypeInfo(rt)->badges, badge);
}
/**
* Test if a road type has a badge.
* @param rt Road type to test.
* @param badge Badge to find.
* @returns true iff the road type has the badge.
*/
static bool RoadTypeHasBadge(RoadType rt, BadgeID badge)
{
return rt != INVALID_ROADTYPE && BadgesContains(GetRoadTypeInfo(rt)->badges, badge);
}
using TileHasBadgeProc = bool(*)(TileIndex tile, BadgeID badge, GrfSpecFeatures features);
static bool TileHasBadge_Rail(TileIndex tile, BadgeID badge, GrfSpecFeatures features)
{
if (features.Test(GrfSpecFeature::GSF_RAILTYPES) && RailTypeHasBadge(GetRailType(tile), badge)) return true;
return false;
}
static bool TileHasBadge_Road(TileIndex tile, BadgeID badge, GrfSpecFeatures features)
{
if (features.Test(GrfSpecFeature::GSF_ROADTYPES) && RoadTypeHasBadge(GetRoadTypeRoad(tile), badge)) return true;
if (features.Test(GrfSpecFeature::GSF_TRAMTYPES) && RoadTypeHasBadge(GetRoadTypeTram(tile), badge)) return true;
if (features.Test(GrfSpecFeature::GSF_RAILTYPES) && IsLevelCrossing(tile) && RailTypeHasBadge(GetRailType(tile), badge)) return true;
return false;
}
static bool TileHasBadge_Town(TileIndex tile, BadgeID badge, GrfSpecFeatures features)
{
if (features.Test(GrfSpecFeature::GSF_HOUSES) && BadgesContains(HouseSpec::Get(GetHouseType(tile))->badges, badge)) return true;
return false;
}
static bool TileHasBadge_Station(TileIndex tile, BadgeID badge, GrfSpecFeatures features)
{
switch (GetStationType(tile)) {
case StationType::Rail:
case StationType::RailWaypoint:
if (features.Test(GrfSpecFeature::GSF_STATIONS)) {
if (const StationSpec *spec = GetStationSpec(tile); spec != nullptr && BadgesContains(spec->badges, badge)) return true;
}
if (features.Test(GrfSpecFeature::GSF_RAILTYPES) && RailTypeHasBadge(GetRailType(tile), badge)) return true;
return false;
case StationType::Bus:
case StationType::Truck:
case StationType::RoadWaypoint:
if (features.Test(GrfSpecFeature::GSF_ROADSTOPS)) {
if (const RoadStopSpec *spec = GetRoadStopSpec(tile); spec != nullptr && BadgesContains(spec->badges, badge)) return true;
}
if (features.Test(GrfSpecFeature::GSF_ROADTYPES) && RoadTypeHasBadge(GetRoadTypeRoad(tile), badge)) return true;
if (features.Test(GrfSpecFeature::GSF_TRAMTYPES) && RoadTypeHasBadge(GetRoadTypeTram(tile), badge)) return true;
return false;
case StationType::Airport:
if (features.Test(GrfSpecFeature::GSF_AIRPORTTILES) && BadgesContains(AirportTileSpec::GetByTile(tile)->badges, badge)) return true;
return false;
default:
return false;
}
}
static bool TileHasBadge_Industry(TileIndex tile, BadgeID badge, GrfSpecFeatures features)
{
if (features.Test(GrfSpecFeature::GSF_INDUSTRYTILES) && BadgesContains(GetIndustryTileSpec(GetIndustryGfx(tile))->badges, badge)) return true;
if (features.Test(GrfSpecFeature::GSF_INDUSTRIES) && BadgesContains(GetIndustrySpec(GetIndustryType(tile))->badges, badge)) return true;
return false;
}
static bool TileHasBadge_TunnelBridge(TileIndex tile, BadgeID badge, GrfSpecFeatures features)
{
switch (GetTunnelBridgeTransportType(tile)) {
case TransportType::TRANSPORT_RAIL:
if (features.Test(GrfSpecFeature::GSF_RAILTYPES) && RailTypeHasBadge(GetRailType(tile), badge)) return true;
return false;
case TransportType::TRANSPORT_ROAD:
if (features.Test(GrfSpecFeature::GSF_ROADTYPES) && RoadTypeHasBadge(GetRoadTypeRoad(tile), badge)) return true;
if (features.Test(GrfSpecFeature::GSF_TRAMTYPES) && RoadTypeHasBadge(GetRoadTypeTram(tile), badge)) return true;
return false;
default:
return false;
}
}
static bool TileHasBadge_Object(TileIndex tile, BadgeID badge, GrfSpecFeatures features)
{
if (features.Test(GrfSpecFeature::GSF_OBJECTS) && BadgesContains(ObjectSpec::GetByTile(tile)->badges, badge)) return true;
return false;
}
/**
* Test if a tile has an item containing the specified badge.
* @param tile Tile to query.
* @param badge Badge to search for.
* @param features GRF features to include in the test.
* @returns true iff the badge 'is on' the tile.
*/
static bool TileHasBadge(TileIndex tile, BadgeID badge, GrfSpecFeatures features)
{
/* Per-tiletype functions for badge testing. Like _tile_type_procs, this is 16 entries as GetTileType() reads 4 bits. */
static constexpr std::array<TileHasBadgeProc, 16> tile_procs = {
nullptr,
TileHasBadge_Rail,
TileHasBadge_Road,
TileHasBadge_Town,
nullptr,
TileHasBadge_Station,
nullptr,
nullptr,
TileHasBadge_Industry,
TileHasBadge_TunnelBridge,
TileHasBadge_Object,
};
TileHasBadgeProc proc = tile_procs[GetTileType(tile)];
return proc != nullptr && proc(tile, badge, features);
}
/**
* Test for a matching badge 'on' a specific map tile.
* @param grffile GRF file of the current varaction.
* @param tile Tile to test.
* @param parameter GRF-local badge index.
* @param features GRF features to include in the test.
* @returns true iff the badge is present.
*/
uint32_t GetNearbyBadgeVariableResult(const GRFFile &grffile, TileIndex tile, const ResolverObject &object)
{
GrfSpecFeatures features = static_cast<GrfSpecFeatures>(object.GetRegister(0x101));
if (features.None()) return 0;
uint32_t parameter = object.GetRegister(0x100);
if (parameter >= std::size(grffile.badge_list)) return UINT_MAX;
/* NewGRF cannot be expected to know the bounds of the map. If the tile is invalid it doesn't have the queried badge. */
if (!IsValidTile(tile)) return 0;
BadgeID index = grffile.badge_list[parameter];
return TileHasBadge(tile, index, features);
}
/**
* Test for a matching badge in a list of badges.
* @param grffile GRF file of the current varaction. * @param grffile GRF file of the current varaction.
* @param badges List of badges to test. * @param badges List of badges to test.
* @param parameter GRF-local badge index. * @param parameter GRF-local badge index.
@ -227,7 +405,7 @@ uint32_t GetBadgeVariableResult(const GRFFile &grffile, std::span<const BadgeID>
if (parameter >= std::size(grffile.badge_list)) return UINT_MAX; if (parameter >= std::size(grffile.badge_list)) return UINT_MAX;
BadgeID index = grffile.badge_list[parameter]; BadgeID index = grffile.badge_list[parameter];
return std::ranges::find(badges, index) != std::end(badges); return BadgesContains(badges, index);
} }
/** /**

View File

@ -64,6 +64,7 @@ Badge *GetBadgeByLabel(std::string_view label);
Badge *GetClassBadge(BadgeClassID class_index); Badge *GetClassBadge(BadgeClassID class_index);
std::span<const BadgeID> GetClassBadges(); std::span<const BadgeID> GetClassBadges();
uint32_t GetNearbyBadgeVariableResult(const GRFFile &grffile, TileIndex tile, const ResolverObject &object);
uint32_t GetBadgeVariableResult(const struct GRFFile &grffile, std::span<const BadgeID> badges, uint32_t parameter); uint32_t GetBadgeVariableResult(const struct GRFFile &grffile, std::span<const BadgeID> badges, uint32_t parameter);
PalSpriteID GetBadgeSprite(const Badge &badge, GrfSpecFeature feature, std::optional<TimerGameCalendar::Date> introduction_date, PaletteID remap); PalSpriteID GetBadgeSprite(const Badge &badge, GrfSpecFeature feature, std::optional<TimerGameCalendar::Date> introduction_date, PaletteID remap);

View File

@ -444,6 +444,7 @@ static uint32_t GetDistanceFromNearbyHouse(uint8_t parameter, TileIndex start_ti
return _house_mngr.GetGRFID(house_id); return _house_mngr.GetGRFID(house_id);
} }
case 0x79: return GetNearbyBadgeVariableResult(*this->ro.grffile, GetNearbyTile(parameter, this->tile), this->ro);
case 0x7A: return GetBadgeVariableResult(*this->ro.grffile, HouseSpec::Get(this->house_id)->badges, parameter); case 0x7A: return GetBadgeVariableResult(*this->ro.grffile, HouseSpec::Get(this->house_id)->badges, parameter);
} }

View File

@ -168,6 +168,7 @@ static uint32_t GetCountAndDistanceOfClosestInstance(const ResolverObject &objec
/* Variables available during construction check. */ /* Variables available during construction check. */
switch (variable) { switch (variable) {
case 0x79: return GetNearbyBadgeVariableResult(*this->ro.grffile, GetNearbyTile(parameter, this->tile), this->ro);
case 0x7A: return GetBadgeVariableResult(*this->ro.grffile, GetIndustrySpec(this->type)->badges, parameter); case 0x7A: return GetBadgeVariableResult(*this->ro.grffile, GetIndustrySpec(this->type)->badges, parameter);
case 0x80: return this->tile.base(); case 0x80: return this->tile.base();
@ -354,6 +355,7 @@ static uint32_t GetCountAndDistanceOfClosestInstance(const ResolverObject &objec
NOT_REACHED(); NOT_REACHED();
} }
case 0x79: return GetNearbyBadgeVariableResult(*this->ro.grffile, GetNearbyTile(parameter, this->tile), this->ro);
case 0x7A: return GetBadgeVariableResult(*this->ro.grffile, GetIndustrySpec(this->type)->badges, parameter); case 0x7A: return GetBadgeVariableResult(*this->ro.grffile, GetIndustrySpec(this->type)->badges, parameter);
/* Get a variable from the persistent storage */ /* Get a variable from the persistent storage */

View File

@ -93,6 +93,7 @@ uint32_t GetRelativePosition(TileIndex tile, TileIndex ind_tile)
/* Get industry tile ID at offset */ /* Get industry tile ID at offset */
case 0x62: return GetIndustryIDAtOffset(GetNearbyTile(parameter, this->tile), this->industry, this->ro.grffile->grfid); case 0x62: return GetIndustryIDAtOffset(GetNearbyTile(parameter, this->tile), this->industry, this->ro.grffile->grfid);
case 0x79: return GetNearbyBadgeVariableResult(*this->ro.grffile, GetNearbyTile(parameter, this->tile), this->ro);
case 0x7A: return GetBadgeVariableResult(*this->ro.grffile, GetIndustryTileSpec(GetIndustryGfx(this->tile))->badges, parameter); case 0x7A: return GetBadgeVariableResult(*this->ro.grffile, GetIndustryTileSpec(GetIndustryGfx(this->tile))->badges, parameter);
} }

View File

@ -291,6 +291,7 @@ static uint32_t GetCountAndDistanceOfClosestInstance(const ResolverObject &objec
/* Object view */ /* Object view */
case 0x48: return this->view; case 0x48: return this->view;
case 0x79: return GetNearbyBadgeVariableResult(*this->ro.grffile, GetNearbyTile(parameter, this->tile), this->ro);
case 0x7A: return GetBadgeVariableResult(*this->ro.grffile, this->spec->badges, parameter); case 0x7A: return GetBadgeVariableResult(*this->ro.grffile, this->spec->badges, parameter);
/* /*
@ -364,6 +365,7 @@ static uint32_t GetCountAndDistanceOfClosestInstance(const ResolverObject &objec
/* Count of object, distance of closest instance */ /* Count of object, distance of closest instance */
case 0x64: return GetCountAndDistanceOfClosestInstance(this->ro, parameter, this->ro.grffile->grfid, this->tile, this->obj); case 0x64: return GetCountAndDistanceOfClosestInstance(this->ro, parameter, this->ro.grffile->grfid, this->tile, this->obj);
case 0x79: return GetNearbyBadgeVariableResult(*this->ro.grffile, GetNearbyTile(parameter, this->tile), this->ro);
case 0x7A: return GetBadgeVariableResult(*this->ro.grffile, this->spec->badges, parameter); case 0x7A: return GetBadgeVariableResult(*this->ro.grffile, this->spec->badges, parameter);
} }

View File

@ -205,6 +205,7 @@ uint32_t RoadStopScopeResolver::GetVariable(uint8_t variable, [[maybe_unused]] u
return 0xFFFE; return 0xFFFE;
} }
case 0x79: return GetNearbyBadgeVariableResult(*this->ro.grffile, GetNearbyTile(parameter, this->tile), this->ro);
case 0x7A: return GetBadgeVariableResult(*this->ro.grffile, this->roadstopspec->badges, parameter); case 0x7A: return GetBadgeVariableResult(*this->ro.grffile, this->roadstopspec->badges, parameter);
case 0xF0: return this->st == nullptr ? 0 : this->st->facilities.base(); // facilities case 0xF0: return this->st == nullptr ? 0 : this->st->facilities.base(); // facilities

View File

@ -295,6 +295,12 @@ TownScopeResolver *StationResolverObject::GetTown()
} }
break; break;
case 0x79:
if (this->axis != INVALID_AXIS && this->tile != INVALID_TILE) {
return GetNearbyBadgeVariableResult(*this->ro.grffile, GetNearbyTile(parameter, this->tile, true, this->axis), this->ro);
}
break;
case 0x7A: return GetBadgeVariableResult(*this->ro.grffile, this->statspec->badges, parameter); case 0x7A: return GetBadgeVariableResult(*this->ro.grffile, this->statspec->badges, parameter);
case 0xFA: return ClampTo<uint16_t>(TimerGameCalendar::date - CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR); // Build date, clamped to a 16 bit value case 0xFA: return ClampTo<uint16_t>(TimerGameCalendar::date - CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR); // Build date, clamped to a 16 bit value
@ -398,6 +404,7 @@ TownScopeResolver *StationResolverObject::GetTown()
return 0xFFFE; return 0xFFFE;
} }
case 0x79: return GetNearbyBadgeVariableResult(*this->ro.grffile, GetNearbyTile(parameter, this->tile), this->ro);
case 0x7A: return GetBadgeVariableResult(*this->ro.grffile, this->statspec->badges, parameter); case 0x7A: return GetBadgeVariableResult(*this->ro.grffile, this->statspec->badges, parameter);
/* General station variables */ /* General station variables */

View File

@ -700,7 +700,7 @@ int openttd_main(std::span<std::string_view> arguments)
InitializeLanguagePacks(); InitializeLanguagePacks();
/* Initialize the font cache */ /* Initialize the font cache */
InitFontCache(false); InitFontCache(FONTSIZES_REQUIRED);
/* This must be done early, since functions use the SetWindowDirty* calls */ /* This must be done early, since functions use the SetWindowDirty* calls */
InitWindowSystem(); InitWindowSystem();

View File

@ -182,6 +182,6 @@ bool SetFallbackFont(FontCacheSettings *settings, const std::string &language_is
if (best_font == nullptr) return false; if (best_font == nullptr) return false;
callback->SetFontNames(settings, best_font, &best_index); callback->SetFontNames(settings, best_font, &best_index);
InitFontCache(callback->Monospace()); InitFontCache(callback->Monospace() ? FontSizes{FS_MONO} : FONTSIZES_REQUIRED);
return true; return true;
} }

View File

@ -1036,9 +1036,8 @@ struct GameOptionsWindow : Window {
this->SetWidgetDisabledState(WID_GO_GUI_FONT_AA, _fcsettings.prefer_sprite); this->SetWidgetDisabledState(WID_GO_GUI_FONT_AA, _fcsettings.prefer_sprite);
this->SetDirty(); this->SetDirty();
InitFontCache(false); InitFontCache(FONTSIZES_ALL);
InitFontCache(true); ClearFontCache(FONTSIZES_ALL);
ClearFontCache();
CheckForMissingGlyphs(); CheckForMissingGlyphs();
SetupWidgetDimensions(); SetupWidgetDimensions();
UpdateAllVirtCoords(); UpdateAllVirtCoords();
@ -1051,7 +1050,7 @@ struct GameOptionsWindow : Window {
this->SetWidgetLoweredState(WID_GO_GUI_FONT_AA, _fcsettings.global_aa); this->SetWidgetLoweredState(WID_GO_GUI_FONT_AA, _fcsettings.global_aa);
MarkWholeScreenDirty(); MarkWholeScreenDirty();
ClearFontCache(); ClearFontCache(FONTSIZES_ALL);
break; break;
#endif /* HAS_TRUETYPE_FONT */ #endif /* HAS_TRUETYPE_FONT */

View File

@ -2278,7 +2278,7 @@ std::string_view GetCurrentLanguageIsoCode()
*/ */
bool MissingGlyphSearcher::FindMissingGlyphs() bool MissingGlyphSearcher::FindMissingGlyphs()
{ {
InitFontCache(this->Monospace()); InitFontCache(this->Monospace() ? FontSizes{FS_MONO} : FONTSIZES_REQUIRED);
this->Reset(); this->Reset();
for (auto text = this->NextString(); text.has_value(); text = this->NextString()) { for (auto text = this->NextString(); text.has_value(); text = this->NextString()) {
@ -2395,7 +2395,7 @@ void CheckForMissingGlyphs(bool base_font, MissingGlyphSearcher *searcher)
/* Our fallback font does miss characters too, so keep the /* Our fallback font does miss characters too, so keep the
* user chosen font as that is more likely to be any good than * user chosen font as that is more likely to be any good than
* the wild guess we made */ * the wild guess we made */
InitFontCache(searcher->Monospace()); InitFontCache(searcher->Monospace() ? FontSizes{FS_MONO} : FONTSIZES_REQUIRED);
} }
} }
#endif #endif
@ -2412,12 +2412,12 @@ void CheckForMissingGlyphs(bool base_font, MissingGlyphSearcher *searcher)
ShowErrorMessage(GetEncodedString(STR_JUST_RAW_STRING, std::move(err_str)), {}, WL_WARNING); ShowErrorMessage(GetEncodedString(STR_JUST_RAW_STRING, std::move(err_str)), {}, WL_WARNING);
/* Reset the font width */ /* Reset the font width */
LoadStringWidthTable(searcher->Monospace()); LoadStringWidthTable(searcher->Monospace() ? FontSizes{FS_MONO} : FONTSIZES_REQUIRED);
return; return;
} }
/* Update the font with cache */ /* Update the font with cache */
LoadStringWidthTable(searcher->Monospace()); LoadStringWidthTable(searcher->Monospace() ? FontSizes{FS_MONO} : FONTSIZES_REQUIRED);
#if !(defined(WITH_ICU_I18N) && defined(WITH_HARFBUZZ)) && !defined(WITH_UNISCRIBE) && !defined(WITH_COCOA) #if !(defined(WITH_ICU_I18N) && defined(WITH_HARFBUZZ)) && !defined(WITH_UNISCRIBE) && !defined(WITH_COCOA)
/* /*