1
0
Fork 0
Commit Graph

524 Commits (b28dca222227105044acb06e8c731284aeee6e16)

Author SHA1 Message Date
Peter Nelson b28dca2222
Codechange: Preprocess text ref stack parameters. (#13642)
NewGRF text ref stack is now processed in advance, creating parameters as necessary, and then encoding this into an EncodedString.
2025-02-22 22:03:38 +00:00
Peter Nelson 0428f8c667 Codechange: Add AppendStringWithArgsInPlace() function. 2025-02-22 10:33:22 +00:00
Peter Nelson 04a16a6b68 Codechange: Add GetParamMaxDigits/Value() functions.
Similar to SetDParamMaxDigits/Value(), except the value is returned instead of being set into a parameter.
2025-02-22 10:33:22 +00:00
Peter Nelson 4c99b5b368 Codechange: Return pair from GetBroadestDigit instead of out parameters. 2025-02-22 10:33:22 +00:00
Peter Nelson 2d7d085e8e
Codechange: Use EncodedString for error messages. (#13569) 2025-02-16 10:04:32 +00:00
Peter Nelson 75387b9e2b Codechange: Use EnumBitSet for StationFacility. 2025-02-13 18:03:13 +00:00
Peter Nelson 1f21e9dc74 Codechange: String parameter encoding for regular strings.
This allows a string and its parameters to be encoded and stored as just one string, instead of juggling with capturing and restoring string parameters.

The advantage of EncodedStrings over raw strings is they use current language and parameter values at the point of decoding.
2025-02-10 22:49:14 +00:00
Peter Nelson dccc6185b9
Codechange: Change internal format of encoded strings to improve robustness and allow expansion. (#13499) 2025-02-09 12:45:50 +00:00
Peter Nelson be00fd4447 Codechange: Use std::array as simple string parameter container.
ArrayStringParameters contains extra state that is used when formatting strings which isn't needed when creating parameter lists.

MakeParameters() now returns a std::array which contains only the parameter data. This simpler container is more widely available than before.
2025-02-07 12:30:34 +00:00
Peter Nelson 59354576d4
Codechange: Use EnumBitSet for LandscapeTypes and remove LandscapeID. (#13436) 2025-02-01 23:09:18 +00:00
merni-ns 9ff485b329 Fix #13304: Refer to font document in font error message
Instead of referring to readme which doesn't say anything about this anymore
2025-02-01 23:51:26 +01:00
Peter Nelson 40aeedeade Codechange: Use EnumBitSet for callback masks. 2025-01-31 17:08:24 +00:00
Rubidium e894a5880c Codechange: rename CargoID to CargoType and amend related variables/comments 2025-01-26 18:07:10 +01:00
Loïc Guilloux ef826a048a
Codechange: [WIN32] Use language isocode for fallback font detection (#13310) 2025-01-21 15:57:09 +01:00
Rubidium fe4ca52059 Codechange: replace magic numbers with named constants 2025-01-04 23:20:33 +01:00
Rubidium 76cc3438bf Codechange: make GetSpecialNameString less magic-number heavy 2025-01-04 21:06:07 +01:00
Rubidium 65731bb964 Codechange: use SPECSTR_..._END over _LAST, to prevent + 1 everywhere 2025-01-04 21:06:07 +01:00
Rubidium fd7a883cbd Codechange: make the StringIndex (within a StringTab) a strong type 2025-01-02 21:19:00 +01:00
Peter Nelson 2d372fa516 Codechange: NewGRF strings are not StringIDs.
Add GRFStringID type and use it when dealing with GRF-local string IDs.
2025-01-02 20:03:40 +00:00
Rubidium fedfacf472 Codechange: always do StringID + offset, instead of offset + StringID 2025-01-02 17:09:31 +01:00
Peter Nelson 3d73c95080
Fix: Potential out-of-bounds reads due to uninitialised string parameters. (#13153)
If string parameters are not set correctly, FormatString can read out of bounds and crash the game.

This does not fix the root cause, just a nasty symptom.
2024-12-07 15:48:49 +00:00
Peter Nelson cba329d9e2
Add: Translatable list separator. (#13149)
Some languages should use a separator other than ", " to separate list items, so it is now a translatable string.
2024-12-06 12:32:36 +00:00
Peter Nelson 14b986609b
Add: AppendStringInPlace() to append translated string ID into an existing string. (#12969)
This allows avoiding a string copy when building strings.
2024-10-07 19:05:38 +01:00
Peter Nelson 16b4e737a3
Fix 3d8d0e0d26: Don't assume plural parameter is valid. (#12954)
A crash can occur if the parameter used for a plural isn't a numeric value.
2024-09-21 15:04:35 +01:00
Peter Nelson 908ee7292b
Codechange: Replace all FILE * with FileHandle RAII class. (#12718)
This removes the need to manually ensure all files are closed.
2024-09-16 08:45:26 +01:00
Peter Nelson d1463f415f Codechange: Treat reading incorrect parameter type as a string error.
Previously reading a string as a number would return 0 instead.
2024-09-14 15:31:05 +01:00
Peter Nelson 3d8d0e0d26 Codechange: Use std::variant to store string parameter data.
This avoids storing two separate values and makes the test for which type is held clearer.

This replaces use of unique_ptr for conditionally storing a string, and is also used in place of StringParameterBackup.
2024-09-14 15:31:05 +01:00
Peter Nelson b449839538 Codechange: Pass span instead of vector to HaveDParamChanged. 2024-09-14 15:31:05 +01:00
Peter Nelson 9eb28def57 Codechange: Return reference from GetNextParameterPointer.
GetNextParameterPointer can no longer return nullptr, and the callers do not check for nullptr, so return a reference instead.
2024-09-14 15:31:05 +01:00
Peter Nelson aee04e7bc6
Codechange: Pass span to StrValid instead of first and last - 1. (#12846)
`std::span` is used instead of `std::string_view` as this is only used for fixed-length buffers.

This removes some callers of `lastof()`
2024-07-08 08:36:57 +01:00
Peter Nelson b4b2fad8e0
Fix #12648: Ensure all uses of std::filesystem::path use native encoding. (#12650)
std::filesystem::path does not expect UTF-8 strings, so they must be converted to native format first (and back to utf-8 after.)
2024-06-09 10:23:47 +01:00
Peter Nelson 7e914a0568 Fix #12738, de16655f: Fallback font searcher failure since ? substitution removed.
Fallback font searcher looked for the substituted ? glyph, which was removed by #12736.

Instead of comparing against a sprite, test against the font returning a missing glyph.

This should also improve performance of fallback font searching, as previously glyphs were actually rendered while searching.
2024-05-31 21:47:47 +01:00
Peter Nelson 9008d793ab
Change: Use per-company group numbers. (#12297)
This is used by the default group name, replacing the use of group index.
2024-05-07 19:01:28 +00:00
dP f5a50a874f
Codechange: Update doxygen comment to reflect removed parameter (#12499) 2024-04-15 12:40:50 +02:00
Peter Nelson 839f486074
Codechange: Use directory_iterator to find language files. (#12495)
This avoids using custom ttd_opendir, along with C-style string comparisons against file names.
2024-04-14 23:57:26 +01:00
Rubidium 21b640b5ff Codechange: simplify president name generation 2024-04-10 18:57:53 +02:00
Peter Nelson 8d312b305b
Codechange: Replace currency macros with functions. (#12396) 2024-03-29 14:49:48 +00:00
Patric Stout a3cfd23cf9
Codechange: rename byte to uint8_t (#12308) 2024-03-16 23:59:32 +01:00
Rubidium 4c117dd2d8 Revert #11993: new number format system does not and cannot work for CJK languages
There are too many intricacies that I am unaware of that are popping up after
asking whether things are right or not.
I do not want to keep playing whack-a-mole, so just revert the whole thing.

This reverts:
15be383b93
360fe8b0b6
1aa9a5c0ab
59f56941e5
7e2eefb91f
b741b2ba6f
609d0071d5
9f8fd80112
a253205b93
819c6c756e
2024-02-22 20:40:12 +01:00
Rubidium 5d2e6e4efa Fix #12148, fca8166: Do not draw decimals when number of digits is 0 2024-02-21 19:32:53 +01:00
Rubidium 360fe8b0b6 Fix a253205: division by zero when attempting to format some short currencies 2024-02-17 22:45:48 +01:00
Rubidium 7e2eefb91f Cleanup: Remove digit group separators from strgen and languages 2024-02-17 14:33:16 +01:00
Rubidium b741b2ba6f Feature: Fully user configurable number format and abbreviations 2024-02-17 14:33:16 +01:00
Rubidium 609d0071d5 Change: Remove saving of digit group and decimal separator configurations from the savegame 2024-02-17 14:33:16 +01:00
Rubidium 9f8fd80112 Feature: Fully customisable number abbreviations per translation 2024-02-17 14:33:16 +01:00
Rubidium a253205b93 Feature: Fully customisable number format per translation 2024-02-17 14:33:16 +01:00
Rubidium 819c6c756e Codechange: Add support for number format and abbreviations pragmas/attributes to strgen 2024-02-17 14:33:16 +01:00
Rubidium fca8166087 Codechange: Simplify FormatNumber by moving out zero fill and decimal support 2024-02-17 14:33:16 +01:00
Rubidium a44bd81280 Codechange: Move determining the decimal separator to a separate function 2024-02-17 14:33:16 +01:00
Patric Stout f1842f9144
Add: {CURRENCY_SHORT} only did k / m suffix. Add bn / tn and make translatable. (#11921)
64bit numbers are REALLY large, but our compact method was build
for 32bit numbers. Extend it to 64bit.
2024-01-29 20:20:35 +00:00