Changeset - r20012:cab061ac4767
[Not reviewed]
master
0 4 0
rubidium - 11 years ago 2013-02-04 20:29:38
rubidium@openttd.org
(svn r24968) -Fix [FS#5379]: company window was not updated when shared were enabled/disabled
4 files changed with 46 insertions and 21 deletions:
0 comments (0 inline, 0 general)
src/company_gui.cpp
Show inline comments
 
@@ -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(
src/economy.cpp
Show inline comments
 
@@ -1818,7 +1818,7 @@ CommandCost CmdBuyShareInCompany(TileInd
 
				break;
 
			}
 
		}
 
		SetWindowDirty(WC_COMPANY, target_company);
 
		InvalidateWindowData(WC_COMPANY, target_company);
 
		CompanyAdminUpdate(c);
 
	}
 
	return cost;
 
@@ -1856,7 +1856,7 @@ CommandCost CmdSellShareInCompany(TileIn
 
		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);
src/settings.cpp
Show inline comments
 
@@ -1038,6 +1038,17 @@ static bool InvalidateCompanyInfrastruct
 
	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()
 
{
src/table/settings.ini
Show inline comments
 
@@ -38,6 +38,7 @@ static bool InvalidateIndustryViewWindow
 
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
0 comments (0 inline, 0 general)