diff options
Diffstat (limited to 'src/settings_gui.cpp')
-rw-r--r-- | src/settings_gui.cpp | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index 6b834cf34..202e2e8d0 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -26,6 +26,8 @@ #include "station_func.h" #include "highscore.h" #include "gfxinit.h" +#include "company_base.h" +#include "company_func.h" #include <map> #include "table/sprites.h" @@ -981,6 +983,19 @@ uint SettingEntry::Draw(GameSettings *settings_ptr, int base_x, int base_y, int return cur_row; } +const void *ResolveVariableAddress(const GameSettings *settings_ptr, const SettingDesc *sd) +{ + if ((sd->desc.flags & SGF_PER_COMPANY) != 0) { + if (Company::IsValidID(_local_company) && _game_mode != GM_MENU) { + return GetVariableAddress(&Company::Get(_local_company)->settings, &sd->save); + } else { + return GetVariableAddress(&_settings_client.company, &sd->save); + } + } else { + return GetVariableAddress(settings_ptr, &sd->save); + } +} + /** * Private function to draw setting value (button + text + current value) * @param settings_ptr Pointer to current values of all settings @@ -993,7 +1008,7 @@ uint SettingEntry::Draw(GameSettings *settings_ptr, int base_x, int base_y, int void SettingEntry::DrawSetting(GameSettings *settings_ptr, const SettingDesc *sd, int x, int y, int max_x, int state) { const SettingDescBase *sdb = &sd->desc; - const void *var = GetVariableAddress(settings_ptr, &sd->save); + const void *var = ResolveVariableAddress(settings_ptr, sd); bool editable = true; bool disabled = false; @@ -1435,7 +1450,7 @@ struct GameSettingsWindow : Window { if ((sd->desc.flags & SGF_NETWORK_ONLY) && !_networking) return; if ((sd->desc.flags & SGF_NO_NETWORK) && _networking) return; - void *var = GetVariableAddress(settings_ptr, &sd->save); + const void *var = ResolveVariableAddress(settings_ptr, sd); int32 value = (int32)ReadValue(var, sd->save.conv); /* clicked on the icon on the left side. Either scroller or bool on/off */ @@ -1486,7 +1501,11 @@ struct GameSettingsWindow : Window { } if (value != oldvalue) { - SetSettingValue(pe->d.entry.index, value); + if ((sd->desc.flags & SGF_PER_COMPANY) != 0) { + SetCompanySetting(pe->d.entry.index, value); + } else { + SetSettingValue(pe->d.entry.index, value); + } this->SetDirty(); } } else { |