mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r24968) -Fix [FS#5379]: company window was not updated when shared were enabled/disabled
This commit is contained in:
parent
26adb854e0
commit
99a08e1e8c
|
@ -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(
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue