Merge branch 'master' into jgrpp

# Conflicts:
#	src/town_cmd.cpp
This commit is contained in:
Jonathan G Rennison
2020-06-05 17:07:58 +01:00
10 changed files with 48 additions and 65 deletions

View File

@@ -270,8 +270,6 @@ static WindowDesc _build_industry_desc(
class BuildIndustryWindow : public Window {
int selected_index; ///< index of the element in the matrix
IndustryType selected_type; ///< industry corresponding to the above index
uint16 callback_timer; ///< timer counter for callback eventual verification
bool timer_enabled; ///< timer can be used
uint16 count; ///< How many industries are loaded
IndustryType index[NUM_INDUSTRYTYPES + 1]; ///< Type of industry, in the order it was loaded
bool enabled[NUM_INDUSTRYTYPES + 1]; ///< availability state, coming from CBID_INDUSTRY_PROBABILITY (if ever)
@@ -295,7 +293,6 @@ class BuildIndustryWindow : public Window {
this->index[this->count] = INVALID_INDUSTRYTYPE;
this->enabled[this->count] = true;
this->count++;
this->timer_enabled = false;
}
/* Fill the arrays with industries.
* The tests performed after the enabled allow to load the industries
@@ -387,13 +384,9 @@ class BuildIndustryWindow : public Window {
public:
BuildIndustryWindow() : Window(&_build_industry_desc)
{
this->timer_enabled = _loaded_newgrf_features.has_newindustries;
this->selected_index = -1;
this->selected_type = INVALID_INDUSTRYTYPE;
this->callback_timer = DAY_TICKS;
this->CreateNestedTree();
this->vscroll = this->GetScrollbar(WID_DPI_SCROLLBAR);
this->FinishInitNested(0);
@@ -423,10 +416,11 @@ public:
}
case WID_DPI_INFOPANEL: {
/* Extra line for cost outside of editor + extra lines for 'extra' information for NewGRFs. */
int height = 2 + (_game_mode == GM_EDITOR ? 0 : 1) + (_loaded_newgrf_features.has_newindustries ? 4 : 0);
/* Extra line for cost outside of editor. */
int height = 2 + (_game_mode == GM_EDITOR ? 0 : 1);
uint extra_lines_req = 0;
uint extra_lines_prd = 0;
uint extra_lines_newgrf = 0;
uint max_minwidth = FONT_HEIGHT_NORMAL * MAX_MINWIDTH_LINEHEIGHTS;
Dimension d = {0, 0};
for (byte i = 0; i < this->count; i++) {
@@ -454,10 +448,15 @@ public:
strdim.width = max_minwidth;
}
d = maxdim(d, strdim);
if (indsp->grf_prop.grffile != nullptr) {
/* Reserve a few extra lines for text from an industry NewGRF. */
extra_lines_newgrf = 4;
}
}
/* Set it to something more sane :) */
height += extra_lines_prd + extra_lines_req;
height += extra_lines_prd + extra_lines_req + extra_lines_newgrf;
size->height = height * FONT_HEIGHT_NORMAL + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
size->width = d.width + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
break;
@@ -673,25 +672,19 @@ public:
if (success && !_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
}
void OnGameTick() override
void OnHundredthTick() override
{
if (!this->timer_enabled) return;
if (--this->callback_timer == 0) {
/* We have just passed another day.
* See if we need to update availability of currently selected industry */
this->callback_timer = DAY_TICKS; // restart counter
if (_game_mode == GM_EDITOR) return;
const IndustrySpec *indsp = GetIndustrySpec(this->selected_type);
const IndustrySpec *indsp = GetIndustrySpec(this->selected_type);
if (indsp->enabled) {
bool call_back_result = GetIndustryProbabilityCallback(this->selected_type, IACT_USERCREATION, 1) > 0;
if (indsp->enabled) {
bool call_back_result = GetIndustryProbabilityCallback(this->selected_type, IACT_USERCREATION, 1) > 0;
/* Only if result does match the previous state would it require a redraw. */
if (call_back_result != this->enabled[this->selected_index]) {
this->enabled[this->selected_index] = call_back_result;
this->SetButtons();
this->SetDirty();
}
/* Only if result does match the previous state would it require a redraw. */
if (call_back_result != this->enabled[this->selected_index]) {
this->enabled[this->selected_index] = call_back_result;
this->SetButtons();
this->SetDirty();
}
}
}