summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2013-02-04 20:29:38 +0000
committerrubidium <rubidium@openttd.org>2013-02-04 20:29:38 +0000
commit99a08e1e8cec3d73bf802e64b9e460e71f47cb43 (patch)
treebe103dfa43a828c12444678bce7fe67c679b372f
parent26adb854e05d781f05f29c4584c5c58d92461cce (diff)
downloadopenttd-99a08e1e8cec3d73bf802e64b9e460e71f47cb43.tar.xz
(svn r24968) -Fix [FS#5379]: company window was not updated when shared were enabled/disabled
-rw-r--r--src/company_gui.cpp50
-rw-r--r--src/economy.cpp4
-rw-r--r--src/settings.cpp11
-rw-r--r--src/table/settings.ini2
4 files changed, 46 insertions, 21 deletions
diff --git a/src/company_gui.cpp b/src/company_gui.cpp
index c6ddd6bd0..7a6f93a20 100644
--- a/src/company_gui.cpp
+++ b/src/company_gui.cpp
@@ -1987,6 +1987,7 @@ struct CompanyWindow : Window
{
this->InitNested(desc, window_number);
this->owner = (Owner)this->window_number;
+ this->OnInvalidateData();
}
virtual void OnPaint()
@@ -2055,25 +2056,6 @@ struct CompanyWindow : Window
}
}
- if (!local) {
- if (_settings_game.economy.allow_shares) { // Shares are allowed
- /* If all shares are owned by someone (none by nobody), disable buy button */
- this->SetWidgetDisabledState(WID_C_BUY_SHARE, GetAmountOwnedBy(c, INVALID_OWNER) == 0 ||
- /* Only 25% left to buy. If the company is human, disable buying it up.. TODO issues! */
- (GetAmountOwnedBy(c, INVALID_OWNER) == 1 && !c->is_ai) ||
- /* Spectators cannot do anything of course */
- _local_company == COMPANY_SPECTATOR);
-
- /* If the company doesn't own any shares, disable sell button */
- this->SetWidgetDisabledState(WID_C_SELL_SHARE, (GetAmountOwnedBy(c, _local_company) == 0) ||
- /* Spectators cannot do anything of course */
- _local_company == COMPANY_SPECTATOR);
- } else { // Shares are not allowed, disable buy/sell buttons
- this->DisableWidget(WID_C_BUY_SHARE);
- this->DisableWidget(WID_C_SELL_SHARE);
- }
- }
-
this->DrawWidgets();
}
@@ -2396,6 +2378,36 @@ struct CompanyWindow : Window
#endif /* ENABLE_NETWORK */
}
}
+
+
+ /**
+ * Some data on this window has become invalid.
+ * @param data Information about the changed data.
+ * @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
+ */
+ virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
+ {
+ if (this->window_number == _local_company) return;
+
+ if (_settings_game.economy.allow_shares) { // Shares are allowed
+ const Company *c = Company::Get(this->window_number);
+
+ /* If all shares are owned by someone (none by nobody), disable buy button */
+ this->SetWidgetDisabledState(WID_C_BUY_SHARE, GetAmountOwnedBy(c, INVALID_OWNER) == 0 ||
+ /* Only 25% left to buy. If the company is human, disable buying it up.. TODO issues! */
+ (GetAmountOwnedBy(c, INVALID_OWNER) == 1 && !c->is_ai) ||
+ /* Spectators cannot do anything of course */
+ _local_company == COMPANY_SPECTATOR);
+
+ /* If the company doesn't own any shares, disable sell button */
+ this->SetWidgetDisabledState(WID_C_SELL_SHARE, (GetAmountOwnedBy(c, _local_company) == 0) ||
+ /* Spectators cannot do anything of course */
+ _local_company == COMPANY_SPECTATOR);
+ } else { // Shares are not allowed, disable buy/sell buttons
+ this->DisableWidget(WID_C_BUY_SHARE);
+ this->DisableWidget(WID_C_SELL_SHARE);
+ }
+ }
};
static const WindowDesc _company_desc(
diff --git a/src/economy.cpp b/src/economy.cpp
index cebe8c479..f1b5c9666 100644
--- a/src/economy.cpp
+++ b/src/economy.cpp
@@ -1818,7 +1818,7 @@ CommandCost CmdBuyShareInCompany(TileIndex tile, DoCommandFlag flags, uint32 p1,
break;
}
}
- SetWindowDirty(WC_COMPANY, target_company);
+ InvalidateWindowData(WC_COMPANY, target_company);
CompanyAdminUpdate(c);
}
return cost;
@@ -1856,7 +1856,7 @@ CommandCost CmdSellShareInCompany(TileIndex tile, DoCommandFlag flags, uint32 p1
OwnerByte *b = c->share_owners;
while (*b != _current_company) b++; // share owners is guaranteed to contain company
*b = COMPANY_SPECTATOR;
- SetWindowDirty(WC_COMPANY, target_company);
+ InvalidateWindowData(WC_COMPANY, target_company);
CompanyAdminUpdate(c);
}
return CommandCost(EXPENSES_OTHER, cost);
diff --git a/src/settings.cpp b/src/settings.cpp
index c871688d3..9ca7cb094 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -1038,6 +1038,17 @@ static bool InvalidateCompanyInfrastructureWindow(int32 p1)
return true;
}
+/**
+ * Invalidate the company details window after the shares setting changed.
+ * @param p1 Unused.
+ * @return Always true.
+ */
+static bool InvalidateCompanyWindow(int32 p1)
+{
+ InvalidateWindowClassesData(WC_COMPANY);
+ return true;
+}
+
/** Checks if any settings are set to incorrect values, and sets them to correct values in that case. */
static void ValidateSettings()
{
diff --git a/src/table/settings.ini b/src/table/settings.ini
index eafbee3a1..b39d29a54 100644
--- a/src/table/settings.ini
+++ b/src/table/settings.ini
@@ -38,6 +38,7 @@ static bool InvalidateIndustryViewWindow(int32 p1);
static bool InvalidateAISettingsWindow(int32 p1);
static bool RedrawTownAuthority(int32 p1);
static bool InvalidateCompanyInfrastructureWindow(int32 p1);
+static bool InvalidateCompanyWindow(int32 p1);
static bool ZoomMinMaxChanged(int32 p1);
#ifdef ENABLE_NETWORK
@@ -1227,6 +1228,7 @@ var = economy.allow_shares
def = false
str = STR_CONFIG_SETTING_ALLOW_SHARES
strhelp = STR_CONFIG_SETTING_ALLOW_SHARES_HELPTEXT
+proc = InvalidateCompanyWindow
[SDT_VAR]
base = GameSettings