summaryrefslogtreecommitdiff
path: root/src/settings_gui.cpp
diff options
context:
space:
mode:
authoryexo <yexo@openttd.org>2009-05-26 11:40:14 +0000
committeryexo <yexo@openttd.org>2009-05-26 11:40:14 +0000
commita10e5f707a4dd893b5cf80faa189f669291a4906 (patch)
treeb3d88922ca83a9ab23f903e1db4c40781f3137fe /src/settings_gui.cpp
parentb19d0e0254883d0db9d8f3d01dacd94e0229f9ac (diff)
downloadopenttd-a10e5f707a4dd893b5cf80faa189f669291a4906.tar.xz
(svn r16429) -Change: Make the company settings behave like all others settings: the default set in the main menu / config file is now really the default for a new company, and changing the value in game will no longer change the default for new companies.
Diffstat (limited to 'src/settings_gui.cpp')
-rw-r--r--src/settings_gui.cpp25
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 {