mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-10 08:00:05 +00:00
(svn r13060) -Codechange: update build industry window when raw_industry_construction setting is modified
This commit is contained in:
parent
cffb7a834c
commit
18c33e1569
@ -103,14 +103,60 @@ class BuildIndustryWindow : public Window {
|
|||||||
StringID text[NUM_INDUSTRYTYPES + 1]; ///< Text coming from CBM_IND_FUND_MORE_TEXT (if ever)
|
StringID text[NUM_INDUSTRYTYPES + 1]; ///< Text coming from CBM_IND_FUND_MORE_TEXT (if ever)
|
||||||
bool enabled[NUM_INDUSTRYTYPES + 1]; ///< availability state, coming from CBID_INDUSTRY_AVAILABLE (if ever)
|
bool enabled[NUM_INDUSTRYTYPES + 1]; ///< availability state, coming from CBID_INDUSTRY_AVAILABLE (if ever)
|
||||||
|
|
||||||
public:
|
void SetupArrays()
|
||||||
BuildIndustryWindow() : Window(&_build_industry_desc)
|
|
||||||
{
|
{
|
||||||
IndustryType ind;
|
IndustryType ind;
|
||||||
const IndustrySpec *indsp;
|
const IndustrySpec *indsp;
|
||||||
|
|
||||||
|
this->count = 0;
|
||||||
|
|
||||||
|
for (uint i = 0; i < lengthof(this->index); i++) {
|
||||||
|
this->index[i] = INVALID_INDUSTRYTYPE;
|
||||||
|
this->text[i] = STR_NULL;
|
||||||
|
this->enabled[i] = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_game_mode == GM_EDITOR) { // give room for the Many Random "button"
|
||||||
|
this->index[this->count] = INVALID_INDUSTRYTYPE;
|
||||||
|
this->count++;
|
||||||
|
this->timer_enabled = false;
|
||||||
|
}
|
||||||
|
/* Fill the arrays with industries.
|
||||||
|
* The tests performed after the enabled allow to load the industries
|
||||||
|
* In the same way they are inserted by grf (if any)
|
||||||
|
*/
|
||||||
|
for (ind = 0; ind < NUM_INDUSTRYTYPES; ind++) {
|
||||||
|
indsp = GetIndustrySpec(ind);
|
||||||
|
if (indsp->enabled){
|
||||||
|
/* Rule is that editor mode loads all industries.
|
||||||
|
* In game mode, all non raw industries are loaded too
|
||||||
|
* and raw ones are loaded only when setting allows it */
|
||||||
|
if (_game_mode != GM_EDITOR && indsp->IsRawIndustry() && _patches.raw_industry_construction == 0) {
|
||||||
|
/* Unselect if the industry is no longer in the list */
|
||||||
|
if (this->selected_type == ind) this->selected_index = -1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
this->index[this->count] = ind;
|
||||||
|
this->enabled[this->count] = (_game_mode == GM_EDITOR) || CheckIfCallBackAllowsAvailability(ind, IACT_USERCREATION);
|
||||||
|
/* Keep the selection to the correct line */
|
||||||
|
if (this->selected_type == ind) this->selected_index = this->count;
|
||||||
|
this->count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* first indutry type is selected if the current selection is invalid.
|
||||||
|
* I'll be damned if there are none available ;) */
|
||||||
|
if (this->selected_index == -1) {
|
||||||
|
this->selected_index = 0;
|
||||||
|
this->selected_type = this->index[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
BuildIndustryWindow() : Window(&_build_industry_desc)
|
||||||
|
{
|
||||||
/* Shorten the window to the equivalant of the additionnal purchase
|
/* Shorten the window to the equivalant of the additionnal purchase
|
||||||
* info coming from the callback. SO it will only be available to tis full
|
* info coming from the callback. SO it will only be available to its full
|
||||||
* height when newindistries are loaded */
|
* height when newindistries are loaded */
|
||||||
if (!_loaded_newgrf_features.has_newindustries) {
|
if (!_loaded_newgrf_features.has_newindustries) {
|
||||||
this->widget[DPIW_INFOPANEL].bottom -= 44;
|
this->widget[DPIW_INFOPANEL].bottom -= 44;
|
||||||
@ -123,45 +169,15 @@ public:
|
|||||||
|
|
||||||
this->timer_enabled = _loaded_newgrf_features.has_newindustries;
|
this->timer_enabled = _loaded_newgrf_features.has_newindustries;
|
||||||
|
|
||||||
/* Initialize structures */
|
|
||||||
this->count = 0;
|
|
||||||
|
|
||||||
for (uint i = 0; i < lengthof(this->index); i++) {
|
|
||||||
this->index[i] = 0xFF;
|
|
||||||
this->text[i] = STR_NULL;
|
|
||||||
this->enabled[i] = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
this->vscroll.cap = 8; // rows in grid, same in scroller
|
this->vscroll.cap = 8; // rows in grid, same in scroller
|
||||||
this->resize.step_height = 13;
|
this->resize.step_height = 13;
|
||||||
|
|
||||||
if (_game_mode == GM_EDITOR) { // give room for the Many Random "button"
|
this->selected_index = -1;
|
||||||
this->index[this->count] = INVALID_INDUSTRYTYPE;
|
this->selected_type = INVALID_INDUSTRYTYPE;
|
||||||
this->count++;
|
|
||||||
this->timer_enabled = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Fill the _fund_gui structure with industries.
|
/* Initialize arrays */
|
||||||
* The tests performed after the enabled allow to load the industries
|
this->SetupArrays();
|
||||||
* In the same way they are inserted by grf (if any)
|
|
||||||
*/
|
|
||||||
for (ind = 0; ind < NUM_INDUSTRYTYPES; ind++) {
|
|
||||||
indsp = GetIndustrySpec(ind);
|
|
||||||
if (indsp->enabled){
|
|
||||||
/* Rule is that editor mode loads all industries.
|
|
||||||
* In game mode, all non raw industries are loaded too
|
|
||||||
* and raw ones are loaded only when setting allows it */
|
|
||||||
if (_game_mode != GM_EDITOR && indsp->IsRawIndustry() && _patches.raw_industry_construction == 0) continue;
|
|
||||||
this->index[this->count] = ind;
|
|
||||||
this->enabled[this->count] = (_game_mode == GM_EDITOR) || CheckIfCallBackAllowsAvailability(ind, IACT_USERCREATION);
|
|
||||||
this->count++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* first indutry type is selected.
|
|
||||||
* I'll be damned if there are none available ;) */
|
|
||||||
this->selected_index = 0;
|
|
||||||
this->selected_type = this->index[0];
|
|
||||||
this->callback_timer = DAY_TICKS;
|
this->callback_timer = DAY_TICKS;
|
||||||
|
|
||||||
this->FindWindowPlacementAndResize(&_build_industry_desc);
|
this->FindWindowPlacementAndResize(&_build_industry_desc);
|
||||||
@ -392,6 +408,12 @@ public:
|
|||||||
{
|
{
|
||||||
this->RaiseButtons();
|
this->RaiseButtons();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void OnInvalidateData(int data = 0)
|
||||||
|
{
|
||||||
|
this->SetupArrays();
|
||||||
|
this->SetDirty();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void ShowBuildIndustryWindow()
|
void ShowBuildIndustryWindow()
|
||||||
|
@ -1147,6 +1147,12 @@ static int32 InvalidateStationBuildWindow(int32 p1)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32 InvalidateBuildIndustryWindow(int32 p1)
|
||||||
|
{
|
||||||
|
InvalidateWindowData(WC_BUILD_INDUSTRY, 0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int32 CloseSignalGUI(int32 p1)
|
static int32 CloseSignalGUI(int32 p1)
|
||||||
{
|
{
|
||||||
if (p1 == 0) {
|
if (p1 == 0) {
|
||||||
@ -1488,7 +1494,7 @@ const SettingDesc _patch_settings[] = {
|
|||||||
/***************************************************************************/
|
/***************************************************************************/
|
||||||
/* Economy section of the GUI-configure patches window */
|
/* Economy section of the GUI-configure patches window */
|
||||||
SDT_BOOL(Patches, inflation, 0, 0, true, STR_CONFIG_PATCHES_INFLATION, NULL),
|
SDT_BOOL(Patches, inflation, 0, 0, true, STR_CONFIG_PATCHES_INFLATION, NULL),
|
||||||
SDT_VAR(Patches, raw_industry_construction,SLE_UINT8,0,MS,0,0, 2, 0, STR_CONFIG_PATCHES_RAW_INDUSTRY_CONSTRUCTION_METHOD, NULL),
|
SDT_VAR(Patches, raw_industry_construction,SLE_UINT8,0,MS,0,0, 2, 0, STR_CONFIG_PATCHES_RAW_INDUSTRY_CONSTRUCTION_METHOD, InvalidateBuildIndustryWindow),
|
||||||
SDT_BOOL(Patches, multiple_industry_per_town, 0, 0, false, STR_CONFIG_PATCHES_MULTIPINDTOWN, NULL),
|
SDT_BOOL(Patches, multiple_industry_per_town, 0, 0, false, STR_CONFIG_PATCHES_MULTIPINDTOWN, NULL),
|
||||||
SDT_BOOL(Patches, same_industry_close, 0, 0, false, STR_CONFIG_PATCHES_SAMEINDCLOSE, NULL),
|
SDT_BOOL(Patches, same_industry_close, 0, 0, false, STR_CONFIG_PATCHES_SAMEINDCLOSE, NULL),
|
||||||
SDT_BOOL(Patches, bribe, 0, 0, true, STR_CONFIG_PATCHES_BRIBE, NULL),
|
SDT_BOOL(Patches, bribe, 0, 0, true, STR_CONFIG_PATCHES_BRIBE, NULL),
|
||||||
|
Loading…
Reference in New Issue
Block a user