Changeset - r24234:a6aa4b6a9c2b
[Not reviewed]
master
0 1 0
Yexo - 4 years ago 2020-05-31 22:43:47
yexo@openttd.org
Codechange: replace custom timer and OnGameTick() with OnHundrethTick()
1 file changed with 12 insertions and 25 deletions:
0 comments (0 inline, 0 general)
src/industry_gui.cpp
Show inline comments
 
@@ -267,14 +267,12 @@ static WindowDesc _build_industry_desc(
 
);
 

	
 
/** Build (fund or prospect) a new industry, */
 
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)
 
	Scrollbar *vscroll;
 

	
 
	/** The offset for the text in the matrix. */
 
@@ -292,13 +290,12 @@ class BuildIndustryWindow : public Windo
 
		}
 

	
 
		if (_game_mode == GM_EDITOR) { // give room for the Many Random "button"
 
			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
 
		 * In the same way they are inserted by grf (if any)
 
		 */
 
		for (IndustryType ind : _sorted_industry_types) {
 
@@ -384,19 +381,15 @@ class BuildIndustryWindow : public Windo
 
		return cargostring;
 
	}
 

	
 
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);
 

	
 
		this->SetButtons();
 
	}
 
@@ -670,31 +663,25 @@ public:
 
		}
 

	
 
		/* If an industry has been built, just reset the cursor and the system */
 
		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
 

	
 
			const IndustrySpec *indsp = GetIndustrySpec(this->selected_type);
 

	
 
			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();
 
				}
 
		if (_game_mode == GM_EDITOR) return;
 
		const IndustrySpec *indsp = GetIndustrySpec(this->selected_type);
 

	
 
		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();
 
			}
 
		}
 
	}
 

	
 
	void OnTimeout() override
 
	{
0 comments (0 inline, 0 general)