summaryrefslogtreecommitdiff
path: root/src/industry_gui.cpp
diff options
context:
space:
mode:
authorglx <glx@openttd.org>2008-05-12 14:54:33 +0000
committerglx <glx@openttd.org>2008-05-12 14:54:33 +0000
commiteb70da38d036772993c86159a8b5875ff963c46a (patch)
treea5fd97cf67935dc57ffe31f16f8b01af032a699b /src/industry_gui.cpp
parent9f11d3089a8cd14117c6ff8f9c75fa1a65a56811 (diff)
downloadopenttd-eb70da38d036772993c86159a8b5875ff963c46a.tar.xz
(svn r13060) -Codechange: update build industry window when raw_industry_construction setting is modified
Diffstat (limited to 'src/industry_gui.cpp')
-rw-r--r--src/industry_gui.cpp76
1 files changed, 49 insertions, 27 deletions
diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp
index fa0401e7d..23ec1ceac 100644
--- a/src/industry_gui.cpp
+++ b/src/industry_gui.cpp
@@ -103,45 +103,25 @@ class BuildIndustryWindow : public Window {
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)
-public:
- BuildIndustryWindow() : Window(&_build_industry_desc)
+ void SetupArrays()
{
IndustryType ind;
const IndustrySpec *indsp;
- /* Shorten the window to the equivalant of the additionnal purchase
- * info coming from the callback. SO it will only be available to tis full
- * height when newindistries are loaded */
- if (!_loaded_newgrf_features.has_newindustries) {
- this->widget[DPIW_INFOPANEL].bottom -= 44;
- this->widget[DPIW_FUND_WIDGET].bottom -= 44;
- this->widget[DPIW_FUND_WIDGET].top -= 44;
- this->widget[DPIW_RESIZE_WIDGET].bottom -= 44;
- this->widget[DPIW_RESIZE_WIDGET].top -= 44;
- this->resize.height = this->height -= 44;
- }
-
- 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->index[i] = INVALID_INDUSTRYTYPE;
this->text[i] = STR_NULL;
this->enabled[i] = false;
}
- this->vscroll.cap = 8; // rows in grid, same in scroller
- this->resize.step_height = 13;
-
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 _fund_gui structure with industries.
+ /* 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)
*/
@@ -151,17 +131,53 @@ public:
/* 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;
+ 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.
+ /* first indutry type is selected if the current selection is invalid.
* I'll be damned if there are none available ;) */
- this->selected_index = 0;
- this->selected_type = this->index[0];
+ 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
+ * info coming from the callback. SO it will only be available to its full
+ * height when newindistries are loaded */
+ if (!_loaded_newgrf_features.has_newindustries) {
+ this->widget[DPIW_INFOPANEL].bottom -= 44;
+ this->widget[DPIW_FUND_WIDGET].bottom -= 44;
+ this->widget[DPIW_FUND_WIDGET].top -= 44;
+ this->widget[DPIW_RESIZE_WIDGET].bottom -= 44;
+ this->widget[DPIW_RESIZE_WIDGET].top -= 44;
+ this->resize.height = this->height -= 44;
+ }
+
+ this->timer_enabled = _loaded_newgrf_features.has_newindustries;
+
+ this->vscroll.cap = 8; // rows in grid, same in scroller
+ this->resize.step_height = 13;
+
+ this->selected_index = -1;
+ this->selected_type = INVALID_INDUSTRYTYPE;
+
+ /* Initialize arrays */
+ this->SetupArrays();
+
this->callback_timer = DAY_TICKS;
this->FindWindowPlacementAndResize(&_build_industry_desc);
@@ -392,6 +408,12 @@ public:
{
this->RaiseButtons();
}
+
+ virtual void OnInvalidateData(int data = 0)
+ {
+ this->SetupArrays();
+ this->SetDirty();
+ }
};
void ShowBuildIndustryWindow()