Split config transparency settings into base and extra fields

This is to avoid incorrect settings when loading in trunk,
as the min/max clamping is not bitwise.
In particular having all options set in trunk when transparent vehicles
in tunnels was set.
This commit is contained in:
Jonathan G Rennison 2021-11-21 22:10:31 +00:00
parent 5c0c057dda
commit 9ff8643fd9
4 changed files with 58 additions and 4 deletions

View File

@ -2123,6 +2123,8 @@ static void RemoveEntriesFromIni(IniFile &ini, const SettingTable &table)
*/
void LoadFromConfig(bool startup)
{
PreTransparencyOptionSave();
ConfigIniFile generic_ini(_config_file, &_config_file_text);
ConfigIniFile private_ini(_private_file);
ConfigIniFile secrets_ini(_secrets_file);
@ -2171,12 +2173,16 @@ void LoadFromConfig(bool startup)
extern void ScheduleErrorMessage(ErrorList &datas);
ScheduleErrorMessage(_settings_error_list);
if (FindWindowById(WC_ERRMSG, 0) == nullptr) ShowFirstError();
} else {
PostTransparencyOptionLoad();
}
}
/** Save the values to the configuration file */
void SaveToConfig()
{
PreTransparencyOptionSave();
ConfigIniFile generic_ini(_config_file);
ConfigIniFile private_ini(_private_file);
ConfigIniFile secrets_ini(_secrets_file);

View File

@ -295,19 +295,37 @@ cat = SC_BASIC
[SDTG_VAR]
name = ""transparency_options""
type = SLE_UINT
var = _transparency_opt
var = _transparency_opt_base
def = 0
min = 0
max = 0x3FF
max = 0xFFFFFFFF
cat = SC_BASIC
[SDTG_VAR]
name = ""extra_transparency_options""
type = SLE_UINT
var = _transparency_opt_extra
def = 0
min = 0
max = 0xFFFFFFFF
cat = SC_BASIC
[SDTG_VAR]
name = ""transparency_locks""
type = SLE_UINT
var = _transparency_lock
var = _transparency_lock_base
def = 0
min = 0
max = 0x3FF
max = 0xFFFFFFFF
cat = SC_BASIC
[SDTG_VAR]
name = ""extra_transparency_locks""
type = SLE_UINT
var = _transparency_lock_extra
def = 0
min = 0
max = 0xFFFFFFFF
cat = SC_BASIC
[SDTG_VAR]

View File

@ -37,10 +37,17 @@ enum TransparencyOption {
typedef uint TransparencyOptionBits; ///< transparency option bits
extern TransparencyOptionBits _transparency_opt;
extern TransparencyOptionBits _transparency_lock;
extern TransparencyOptionBits _transparency_opt_base;
extern TransparencyOptionBits _transparency_lock_base;
extern TransparencyOptionBits _transparency_opt_extra;
extern TransparencyOptionBits _transparency_lock_extra;
extern TransparencyOptionBits _invisibility_opt;
extern byte _display_opt;
extern byte _extra_display_opt;
void PreTransparencyOptionSave();
void PostTransparencyOptionLoad();
/**
* Check if the transparency option bit is set
* and if we aren't in the game menu (there's never transparency)

View File

@ -22,10 +22,33 @@
TransparencyOptionBits _transparency_opt; ///< The bits that should be transparent.
TransparencyOptionBits _transparency_lock; ///< Prevent these bits from flipping with X.
TransparencyOptionBits _transparency_opt_base; ///< Separate base and extra fields for config save/load.
TransparencyOptionBits _transparency_lock_base; ///< "
TransparencyOptionBits _transparency_opt_extra; ///< "
TransparencyOptionBits _transparency_lock_extra; ///< "
TransparencyOptionBits _invisibility_opt; ///< The bits that should be invisible.
byte _display_opt; ///< What do we want to draw/do?
byte _extra_display_opt;
void PreTransparencyOptionSave()
{
auto handler = [](TransparencyOptionBits value, TransparencyOptionBits &base, TransparencyOptionBits &extra) {
base = value & 0x1FF;
extra = (value >> 9) & 0x1;
};
handler(_transparency_opt, _transparency_opt_base, _transparency_opt_extra);
handler(_transparency_lock, _transparency_lock_base, _transparency_lock_extra);
}
void PostTransparencyOptionLoad()
{
auto handler = [](TransparencyOptionBits base, TransparencyOptionBits extra) -> TransparencyOptionBits {
return (base & 0x3FF) | ((extra & 0x1) << 9);
};
_transparency_opt = handler(_transparency_opt_base, _transparency_opt_extra);
_transparency_lock = handler(_transparency_lock_base, _transparency_lock_extra);
}
class TransparenciesWindow : public Window
{
public: