mirror of https://github.com/OpenTTD/OpenTTD.git
Feature: Fully user configurable number format and abbreviations
This commit is contained in:
parent
609d0071d5
commit
b741b2ba6f
|
@ -50,6 +50,7 @@
|
||||||
#include "void_map.h"
|
#include "void_map.h"
|
||||||
#include "station_func.h"
|
#include "station_func.h"
|
||||||
#include "station_base.h"
|
#include "station_base.h"
|
||||||
|
#include "language.h"
|
||||||
|
|
||||||
#include "table/strings.h"
|
#include "table/strings.h"
|
||||||
#include "table/settings.h"
|
#include "table/settings.h"
|
||||||
|
|
|
@ -222,6 +222,8 @@ struct GUISettings {
|
||||||
|
|
||||||
bool scale_bevels; ///< bevels are scaled with GUI scale.
|
bool scale_bevels; ///< bevels are scaled with GUI scale.
|
||||||
|
|
||||||
|
std::string number_format; ///< formatting string for numbers (like "thousands" grouping)
|
||||||
|
std::string number_abbreviations; ///< mapping to number formats for different powers of ten/thresholds
|
||||||
std::string digit_decimal_separator; ///< decimal separator
|
std::string digit_decimal_separator; ///< decimal separator
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -389,8 +389,21 @@ static const char *GetDecimalSeparator()
|
||||||
|
|
||||||
void InitializeNumberFormats()
|
void InitializeNumberFormats()
|
||||||
{
|
{
|
||||||
ParseNumberFormatSeparators(_number_format_separators, _current_language->number_format);
|
bool loaded_number_format = false;
|
||||||
ParseNumberAbbreviations(_number_abbreviations, _current_language->number_abbreviations);
|
if (!_settings_client.gui.number_format.empty()) {
|
||||||
|
auto res = ParseNumberFormatSeparators(_number_format_separators, _settings_client.gui.number_format);
|
||||||
|
if (res.has_value()) UserError("The setting 'number_format' under 'gui' is invalid: {}", *res);
|
||||||
|
loaded_number_format = !res.has_value();
|
||||||
|
}
|
||||||
|
if (!loaded_number_format) ParseNumberFormatSeparators(_number_format_separators, _current_language->number_format);
|
||||||
|
|
||||||
|
bool loaded_number_abbreviations = false;
|
||||||
|
if (!_settings_client.gui.number_abbreviations.empty()) {
|
||||||
|
auto res = ParseNumberAbbreviations(_number_abbreviations, _settings_client.gui.number_abbreviations);
|
||||||
|
if (res.has_value()) UserError("The setting 'number_abbreviations' under 'gui' is invalid: {}", *res);
|
||||||
|
loaded_number_abbreviations = !res.has_value();
|
||||||
|
}
|
||||||
|
if (!loaded_number_abbreviations) ParseNumberAbbreviations(_number_abbreviations, _current_language->number_abbreviations);
|
||||||
_number_abbreviations.emplace_back(0, _number_format_separators);
|
_number_abbreviations.emplace_back(0, _number_format_separators);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@ static void InvalidateCompanyLiveryWindow(int32_t new_value);
|
||||||
static void InvalidateNewGRFChangeWindows(int32_t new_value);
|
static void InvalidateNewGRFChangeWindows(int32_t new_value);
|
||||||
static void ZoomMinMaxChanged(int32_t new_value);
|
static void ZoomMinMaxChanged(int32_t new_value);
|
||||||
static void SpriteZoomMinChanged(int32_t new_value);
|
static void SpriteZoomMinChanged(int32_t new_value);
|
||||||
|
void InitializeNumberFormats();
|
||||||
|
|
||||||
static constexpr std::initializer_list<const char*> _osk_activation{"disabled", "double", "single", "immediately"};
|
static constexpr std::initializer_list<const char*> _osk_activation{"disabled", "double", "single", "immediately"};
|
||||||
static constexpr std::initializer_list<const char*> _savegame_date{"long", "short", "iso"};
|
static constexpr std::initializer_list<const char*> _savegame_date{"long", "short", "iso"};
|
||||||
|
@ -904,6 +905,24 @@ post_cb = [](auto) { SetupWidgetDimensions(); ReInitAllWindows(true); }
|
||||||
cat = SC_BASIC
|
cat = SC_BASIC
|
||||||
startup = true
|
startup = true
|
||||||
|
|
||||||
|
[SDTC_SSTR]
|
||||||
|
var = gui.number_format
|
||||||
|
flags = SF_NOT_IN_SAVE | SF_NO_NETWORK_SYNC
|
||||||
|
type = SLE_STRQ
|
||||||
|
def = nullptr
|
||||||
|
pre_cb = [](auto format) { NumberFormatSeparators separators; return !ParseNumberFormatSeparators(separators, format).has_value(); }
|
||||||
|
post_cb = [](auto) { InitializeNumberFormats(); MarkWholeScreenDirty(); }
|
||||||
|
startup = true
|
||||||
|
|
||||||
|
[SDTC_SSTR]
|
||||||
|
var = gui.number_abbreviations
|
||||||
|
flags = SF_NOT_IN_SAVE | SF_NO_NETWORK_SYNC
|
||||||
|
type = SLE_STRQ
|
||||||
|
def = nullptr
|
||||||
|
pre_cb = [](auto format) { NumberAbbreviations abbreviations; return !ParseNumberAbbreviations(abbreviations, format).has_value(); }
|
||||||
|
post_cb = [](auto) { InitializeNumberFormats(); MarkWholeScreenDirty(); }
|
||||||
|
startup = true
|
||||||
|
|
||||||
[SDTC_SSTR]
|
[SDTC_SSTR]
|
||||||
var = gui.digit_decimal_separator
|
var = gui.digit_decimal_separator
|
||||||
flags = SF_NOT_IN_SAVE | SF_NO_NETWORK_SYNC
|
flags = SF_NOT_IN_SAVE | SF_NO_NETWORK_SYNC
|
||||||
|
|
Loading…
Reference in New Issue