summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2010-10-04 19:35:40 +0000
committerfrosch <frosch@openttd.org>2010-10-04 19:35:40 +0000
commit566ba0fcccbf414c5128bc596486b90ba985c7b5 (patch)
treed1823906c030a95e4bd709ca813b47f59b418d71
parent7f060bdaf5ae6ad0ae0b354eb04ad63a8b34ffa6 (diff)
downloadopenttd-566ba0fcccbf414c5128bc596486b90ba985c7b5.tar.xz
(svn r20897) -Codechange: Store the result of IsProductionAlterable() in a member variable of IndustryViewWindow.
-rw-r--r--src/cheat_gui.cpp5
-rw-r--r--src/industry_gui.cpp25
2 files changed, 25 insertions, 5 deletions
diff --git a/src/cheat_gui.cpp b/src/cheat_gui.cpp
index cc7bbd574..7b561673b 100644
--- a/src/cheat_gui.cpp
+++ b/src/cheat_gui.cpp
@@ -66,8 +66,9 @@ static int32 ClickChangeCompanyCheat(int32 p1, int32 p2)
*/
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;
}
/**
diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp
index 49715b6a1..f55a896e2 100644
--- a/src/industry_gui.cpp
+++ b/src/industry_gui.cpp
@@ -639,6 +639,12 @@ enum IndustryViewWidgets {
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 @@ class IndustryViewWindow : public Window
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 @@ public:
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 @@ public:
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 @@ public:
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 @@ public:
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);