changeset 16197:20c23fbf0eb4 draft

(svn r20897) -Codechange: Store the result of IsProductionAlterable() in a member variable of IndustryViewWindow.
author frosch <frosch@openttd.org>
date Mon, 04 Oct 2010 19:35:40 +0000
parents cf1a59716f59
children 33c9c2277e70
files src/cheat_gui.cpp src/industry_gui.cpp
diffstat 2 files changed, 25 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/cheat_gui.cpp
+++ b/src/cheat_gui.cpp
@@ -66,8 +66,9 @@
  */
 static int32 ClickSetProdCheat(int32 p1, int32 p2)
 {
-	SetWindowClassesDirty(WC_INDUSTRY_VIEW);
-	return p1;
+	_cheats.setup_prod.value = p1;
+	InvalidateWindowClassesData(WC_INDUSTRY_VIEW);
+	return _cheats.setup_prod.value;
 }
 
 /**
--- a/src/industry_gui.cpp
+++ b/src/industry_gui.cpp
@@ -639,6 +639,12 @@
 
 class IndustryViewWindow : public Window
 {
+	/** Modes for changing production */
+	enum Editability {
+		EA_NONE,              ///< Not alterable
+		EA_RATE,              ///< Allow changing the production rates
+	};
+
 	/** Specific lines in the info panel */
 	enum InfoLine {
 		IL_NONE,              ///< No line
@@ -646,6 +652,7 @@
 		IL_RATE2,             ///< Production rate of cargo 2
 	};
 
+	Editability editable;     ///< Mode for changing production
 	InfoLine editbox_line;    ///< The line clicked to open the edit box
 	InfoLine clicked_line;    ///< The line of the button that has been clicked
 	byte clicked_button;      ///< The button that has been clicked (to raise)
@@ -664,6 +671,8 @@
 		this->InitNested(desc, window_number);
 		NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(IVW_VIEWPORT);
 		nvp->InitializeViewport(this, Industry::Get(window_number)->location.tile + TileDiffXY(1, 1), ZOOM_LVL_INDUSTRY);
+
+		this->InvalidateData();
 	}
 
 	virtual void OnPaint()
@@ -746,10 +755,10 @@
 			SetDParam(1, i->last_month_production[j]);
 			SetDParamStr(2, cargo_suffix[j]);
 			SetDParam(3, ToPercent8(i->last_month_pct_transported[j]));
-			uint x = left + WD_FRAMETEXT_LEFT + (IsProductionAlterable(i) ? 30 : 0);
+			uint x = left + WD_FRAMETEXT_LEFT + (this->editable == EA_RATE ? 30 : 0);
 			DrawString(x, right - WD_FRAMERECT_RIGHT, y, STR_INDUSTRY_VIEW_TRANSPORTED);
 			/* Let's put out those buttons.. */
-			if (IsProductionAlterable(i)) {
+			if (this->editable == EA_RATE) {
 				DrawArrowButtons(left + WD_FRAMETEXT_LEFT, y, COLOUR_YELLOW, (this->clicked_line == IL_RATE1 + j) ? this->clicked_button : 0,
 						i->production_rate[j] > 0, i->production_rate[j] < 255);
 			}
@@ -807,7 +816,7 @@
 				if (line == IL_NONE) return;
 
 				uint x = pt.x;
-				if (IsProductionAlterable(i)) {
+				if (this->editable == EA_RATE) {
 					NWidgetBase *nwi = this->GetWidget<NWidgetBase>(widget);
 					uint left = nwi->pos_x + WD_FRAMETEXT_LEFT;
 					uint right = nwi->pos_x + nwi->current_x - 1 - WD_FRAMERECT_RIGHT;
@@ -882,6 +891,16 @@
 		this->SetDirty();
 	}
 
+	virtual void OnInvalidateData(int data)
+	{
+		const Industry *i = Industry::Get(this->window_number);
+		if (IsProductionAlterable(i)) {
+			this->editable = EA_RATE;
+		} else {
+			this->editable = EA_NONE;
+		}
+	}
+
 	virtual bool IsNewGRFInspectable() const
 	{
 		return ::IsNewGRFInspectable(GSF_INDUSTRIES, this->window_number);