1
0
Fork 0

Compare commits

...

5 Commits

Author SHA1 Message Date
Peter Nelson 530c2d0a54
Merge b96da4d7a0 into 7546c1acab 2025-07-14 08:03:52 +00:00
Peter Nelson 7546c1acab
Codefix f220ed179d: GetUnicodeGlyph takes a unicode character. (#14438)
Previous change erroneously changed type to GlyphID, based on naming. It should actually be char32_t.
2025-07-14 08:01:42 +00:00
Peter Nelson a6143eea21
Codechange: Include more relevant headers for script_storage. (#14437) 2025-07-14 07:49:50 +01:00
Peter Nelson b96da4d7a0
Change: Automatically push/pop colours when formatting a sub-string.
Reverts 226a44bf86.

This universally prevents the sub-string from changing colours in the outer string.
2025-04-15 19:31:09 +01:00
Peter Nelson ffed3c7f1c
Change: Don't replace stripped control codes with '?' for scripts. 2025-04-15 19:31:08 +01:00
6 changed files with 31 additions and 26 deletions

View File

@ -43,26 +43,26 @@ SpriteFontCache::SpriteFontCache(FontSize fs) : FontCache(fs)
} }
/** /**
* Get SpriteID associated with a GlyphID. * Get SpriteID associated with a character.
* @param key Glyph to find. * @param key Character to find.
* @return SpriteID of glyph, or 0 if not present. * @return SpriteID for character, or 0 if not present.
*/ */
SpriteID SpriteFontCache::GetUnicodeGlyph(GlyphID key) SpriteID SpriteFontCache::GetUnicodeGlyph(char32_t key)
{ {
const auto found = this->glyph_to_spriteid_map.find(key & ~SPRITE_GLYPH); const auto found = this->char_map.find(key);
if (found == std::end(this->glyph_to_spriteid_map)) return 0; if (found == std::end(this->char_map)) return 0;
return found->second; return found->second;
} }
void SpriteFontCache::SetUnicodeGlyph(char32_t key, SpriteID sprite) void SpriteFontCache::SetUnicodeGlyph(char32_t key, SpriteID sprite)
{ {
this->glyph_to_spriteid_map[key] = sprite; this->char_map[key] = sprite;
} }
void SpriteFontCache::InitializeUnicodeGlyphMap() void SpriteFontCache::InitializeUnicodeGlyphMap()
{ {
/* Clear out existing glyph map if it exists */ /* Clear out existing glyph map if it exists */
this->glyph_to_spriteid_map.clear(); this->char_map.clear();
SpriteID base; SpriteID base;
switch (this->fs) { switch (this->fs) {

View File

@ -28,8 +28,8 @@ public:
bool IsBuiltInFont() override { return true; } bool IsBuiltInFont() override { return true; }
private: private:
std::unordered_map<GlyphID, SpriteID> glyph_to_spriteid_map{}; ///< Mapping of glyphs to sprite IDs. std::unordered_map<char32_t, SpriteID> char_map{}; ///< Mapping of characters to sprite IDs.
SpriteID GetUnicodeGlyph(GlyphID key); SpriteID GetUnicodeGlyph(char32_t key);
}; };
#endif /* SPRITEFONTCACHE_H */ #endif /* SPRITEFONTCACHE_H */

View File

@ -1231,7 +1231,7 @@ STR_CONFIG_SETTING_EXPAND_ALL :Expand all
STR_CONFIG_SETTING_COLLAPSE_ALL :Collapse all STR_CONFIG_SETTING_COLLAPSE_ALL :Collapse all
STR_CONFIG_SETTING_RESET_ALL :Reset all values STR_CONFIG_SETTING_RESET_ALL :Reset all values
STR_CONFIG_SETTING_NO_EXPLANATION_AVAILABLE_HELPTEXT :(no explanation available) STR_CONFIG_SETTING_NO_EXPLANATION_AVAILABLE_HELPTEXT :(no explanation available)
STR_CONFIG_SETTING_VALUE :{PUSH_COLOUR}{ORANGE}{STRING1}{POP_COLOUR} STR_CONFIG_SETTING_VALUE :{ORANGE}{STRING1}
STR_CONFIG_SETTING_DEFAULT_VALUE :{LTBLUE}Default value: {ORANGE}{STRING1} STR_CONFIG_SETTING_DEFAULT_VALUE :{LTBLUE}Default value: {ORANGE}{STRING1}
STR_CONFIG_SETTING_TYPE :{LTBLUE}Setting type: {ORANGE}{STRING} STR_CONFIG_SETTING_TYPE :{LTBLUE}Setting type: {ORANGE}{STRING}
STR_CONFIG_SETTING_TYPE_CLIENT :Client setting (not stored in saves; affects all games) STR_CONFIG_SETTING_TYPE_CLIENT :Client setting (not stored in saves; affects all games)
@ -3624,17 +3624,17 @@ STR_NEWGRF_LIST_COMPATIBLE :{YELLOW}Found c
STR_NEWGRF_LIST_MISSING :{RED}Missing files STR_NEWGRF_LIST_MISSING :{RED}Missing files
# NewGRF 'it's broken' warnings # NewGRF 'it's broken' warnings
STR_NEWGRF_BROKEN :{WHITE}Behaviour of NewGRF '{PUSH_COLOUR}{0:RAW_STRING}{POP_COLOUR}' is likely to cause desyncs and/or crashes STR_NEWGRF_BROKEN :{WHITE}Behaviour of NewGRF '{0:RAW_STRING}' is likely to cause desyncs and/or crashes
STR_NEWGRF_BROKEN_POWERED_WAGON :{WHITE}It changed powered-wagon state for '{PUSH_COLOUR}{1:ENGINE}{POP_COLOUR}' when not inside a depot STR_NEWGRF_BROKEN_POWERED_WAGON :{WHITE}It changed powered-wagon state for '{1:ENGINE}' when not inside a depot
STR_NEWGRF_BROKEN_VEHICLE_LENGTH :{WHITE}It changed vehicle length for '{PUSH_COLOUR}{1:ENGINE}{POP_COLOUR}' when not inside a depot STR_NEWGRF_BROKEN_VEHICLE_LENGTH :{WHITE}It changed vehicle length for '{1:ENGINE}' when not inside a depot
STR_NEWGRF_BROKEN_CAPACITY :{WHITE}It changed vehicle capacity for '{PUSH_COLOUR}{1:ENGINE}{POP_COLOUR}' when not inside a depot or refitting STR_NEWGRF_BROKEN_CAPACITY :{WHITE}It changed vehicle capacity for '{1:ENGINE}' when not inside a depot or refitting
STR_BROKEN_VEHICLE_LENGTH :{WHITE}Train '{VEHICLE}' belonging to '{COMPANY}' has invalid length. It is probably caused by problems with NewGRFs. Game may desync or crash STR_BROKEN_VEHICLE_LENGTH :{WHITE}Train '{VEHICLE}' belonging to '{COMPANY}' has invalid length. It is probably caused by problems with NewGRFs. Game may desync or crash
STR_NEWGRF_BUGGY :{WHITE}NewGRF '{PUSH_COLOUR}{0:RAW_STRING}{POP_COLOUR}' provides incorrect information STR_NEWGRF_BUGGY :{WHITE}NewGRF '{0:RAW_STRING}' provides incorrect information
STR_NEWGRF_BUGGY_ARTICULATED_CARGO :{WHITE}Cargo/refit information for '{PUSH_COLOUR}{1:ENGINE}{POP_COLOUR}' differs from purchase list after construction. This might cause autorenew/-replace to fail refitting correctly STR_NEWGRF_BUGGY_ARTICULATED_CARGO :{WHITE}Cargo/refit information for '{1:ENGINE}' differs from purchase list after construction. This might cause autorenew/-replace to fail refitting correctly
STR_NEWGRF_BUGGY_ENDLESS_PRODUCTION_CALLBACK :{WHITE}'{PUSH_COLOUR}{1:STRING}{POP_COLOUR}' caused an endless loop in the production callback STR_NEWGRF_BUGGY_ENDLESS_PRODUCTION_CALLBACK :{WHITE}'{1:STRING}' caused an endless loop in the production callback
STR_NEWGRF_BUGGY_UNKNOWN_CALLBACK_RESULT :{WHITE}Callback {1:HEX} returned unknown/invalid result {2:HEX} STR_NEWGRF_BUGGY_UNKNOWN_CALLBACK_RESULT :{WHITE}Callback {1:HEX} returned unknown/invalid result {2:HEX}
STR_NEWGRF_BUGGY_INVALID_CARGO_PRODUCTION_CALLBACK :{WHITE}'{PUSH_COLOUR}{1:STRING}{POP_COLOUR}' returned invalid cargo type in the production callback at {2:HEX} STR_NEWGRF_BUGGY_INVALID_CARGO_PRODUCTION_CALLBACK :{WHITE}'{1:STRING}' returned invalid cargo type in the production callback at {2:HEX}
# 'User removed essential NewGRFs'-placeholders for stuff without specs # 'User removed essential NewGRFs'-placeholders for stuff without specs
STR_NEWGRF_INVALID_CARGO :<invalid cargo> STR_NEWGRF_INVALID_CARGO :<invalid cargo>

View File

@ -24,10 +24,12 @@
#include "api/script_event.hpp" #include "api/script_event.hpp"
#include "api/script_log.hpp" #include "api/script_log.hpp"
#include "../company_base.h" #include "../company_type.h"
#include "../company_func.h"
#include "../fileio_func.h" #include "../fileio_func.h"
#include "../goal_type.h"
#include "../league_type.h" #include "../league_type.h"
#include "../signs_type.h"
#include "../story_type.h"
#include "../misc/endian_buffer.hpp" #include "../misc/endian_buffer.hpp"
#include "../safeguards.h" #include "../safeguards.h"

View File

@ -12,12 +12,10 @@
#include <queue> #include <queue>
#include "../signs_func.h" #include "../command_type.h"
#include "../vehicle_func.h" #include "../company_type.h"
#include "../rail_type.h"
#include "../road_type.h" #include "../road_type.h"
#include "../group.h"
#include "../goal_type.h"
#include "../story_type.h"
#include "script_types.hpp" #include "script_types.hpp"
#include "script_log_types.hpp" #include "script_log_types.hpp"

View File

@ -1112,6 +1112,9 @@ static void FormatString(StringBuilder &builder, std::string_view str_arg, Strin
std::stack<StrStackItem, std::vector<StrStackItem>> str_stack; std::stack<StrStackItem, std::vector<StrStackItem>> str_stack;
str_stack.emplace(str_arg, orig_first_param_offset, orig_case_index); str_stack.emplace(str_arg, orig_first_param_offset, orig_case_index);
bool appending = builder.AnyBytesWritten();
if (appending) builder.PutUtf8(SCC_PUSH_COLOUR);
for (;;) { for (;;) {
try { try {
while (!str_stack.empty() && !str_stack.top().consumer.AnyBytesLeft()) { while (!str_stack.empty() && !str_stack.top().consumer.AnyBytesLeft()) {
@ -1839,6 +1842,8 @@ static void FormatString(StringBuilder &builder, std::string_view str_arg, Strin
builder += "(invalid parameter)"; builder += "(invalid parameter)";
} }
} }
if (appending) builder.PutUtf8(SCC_POP_COLOUR);
} }