(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.

This commit is contained in:
yexo
2009-05-26 11:40:14 +00:00
parent 87dfc2a881
commit 7eb9ad0415
7 changed files with 95 additions and 36 deletions

View File

@@ -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 {