mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-06 14:27:16 +00:00
(svn r20895) -Codechange: Use an enum to identify the rows of buttons in the industryview.
This commit is contained in:
parent
2e8e148262
commit
a0a51c2ac1
@ -639,8 +639,15 @@ enum IndustryViewWidgets {
|
|||||||
|
|
||||||
class IndustryViewWindow : public Window
|
class IndustryViewWindow : public Window
|
||||||
{
|
{
|
||||||
byte editbox_line; ///< The line clicked to open the edit box
|
/** Specific lines in the info panel */
|
||||||
byte clicked_line; ///< The line of the button that has been clicked
|
enum InfoLine {
|
||||||
|
IL_NONE, ///< No line
|
||||||
|
IL_RATE1, ///< Production rate of cargo 1
|
||||||
|
IL_RATE2, ///< Production rate of cargo 2
|
||||||
|
};
|
||||||
|
|
||||||
|
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)
|
byte clicked_button; ///< The button that has been clicked (to raise)
|
||||||
int production_offset_y; ///< The offset of the production texts/buttons
|
int production_offset_y; ///< The offset of the production texts/buttons
|
||||||
int info_height; ///< Height needed for the #IVW_INFO panel
|
int info_height; ///< Height needed for the #IVW_INFO panel
|
||||||
@ -649,8 +656,8 @@ public:
|
|||||||
IndustryViewWindow(const WindowDesc *desc, WindowNumber window_number) : Window()
|
IndustryViewWindow(const WindowDesc *desc, WindowNumber window_number) : Window()
|
||||||
{
|
{
|
||||||
this->flags4 |= WF_DISABLE_VP_SCROLL;
|
this->flags4 |= WF_DISABLE_VP_SCROLL;
|
||||||
this->editbox_line = 0;
|
this->editbox_line = IL_NONE;
|
||||||
this->clicked_line = 0;
|
this->clicked_line = IL_NONE;
|
||||||
this->clicked_button = 0;
|
this->clicked_button = 0;
|
||||||
this->info_height = WD_FRAMERECT_TOP + 2 * FONT_HEIGHT_NORMAL + WD_FRAMERECT_BOTTOM + 1; // Info panel has at least two lines text.
|
this->info_height = WD_FRAMERECT_TOP + 2 * FONT_HEIGHT_NORMAL + WD_FRAMERECT_BOTTOM + 1; // Info panel has at least two lines text.
|
||||||
|
|
||||||
@ -743,7 +750,7 @@ public:
|
|||||||
DrawString(x, right - WD_FRAMERECT_RIGHT, y, STR_INDUSTRY_VIEW_TRANSPORTED);
|
DrawString(x, right - WD_FRAMERECT_RIGHT, y, STR_INDUSTRY_VIEW_TRANSPORTED);
|
||||||
/* Let's put out those buttons.. */
|
/* Let's put out those buttons.. */
|
||||||
if (IsProductionAlterable(i)) {
|
if (IsProductionAlterable(i)) {
|
||||||
DrawArrowButtons(left + WD_FRAMETEXT_LEFT, y, COLOUR_YELLOW, (this->clicked_line == j + 1) ? this->clicked_button : 0,
|
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);
|
i->production_rate[j] > 0, i->production_rate[j] < 255);
|
||||||
}
|
}
|
||||||
y += FONT_HEIGHT_NORMAL;
|
y += FONT_HEIGHT_NORMAL;
|
||||||
@ -784,36 +791,47 @@ public:
|
|||||||
switch (widget) {
|
switch (widget) {
|
||||||
case IVW_INFO: {
|
case IVW_INFO: {
|
||||||
Industry *i = Industry::Get(this->window_number);
|
Industry *i = Industry::Get(this->window_number);
|
||||||
|
InfoLine line = IL_NONE;
|
||||||
|
|
||||||
|
if (pt.y >= this->production_offset_y) {
|
||||||
|
int row = (pt.y - this->production_offset_y) / FONT_HEIGHT_NORMAL;
|
||||||
|
for (uint j = 0; j < lengthof(i->produced_cargo); j++) {
|
||||||
|
if (i->produced_cargo[j] == CT_INVALID) continue;
|
||||||
|
row--;
|
||||||
|
if (row < 0) {
|
||||||
|
line = (InfoLine)(IL_RATE1 + j);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (line == IL_NONE) return;
|
||||||
|
|
||||||
/* We should work if needed.. */
|
|
||||||
if (!IsProductionAlterable(i)) return;
|
|
||||||
uint x = pt.x;
|
uint x = pt.x;
|
||||||
int line = (pt.y - this->production_offset_y) / FONT_HEIGHT_NORMAL;
|
if (IsProductionAlterable(i)) {
|
||||||
if (pt.y >= this->production_offset_y && IsInsideMM(line, 0, 2) && i->produced_cargo[line] != CT_INVALID) {
|
|
||||||
NWidgetBase *nwi = this->GetWidget<NWidgetBase>(widget);
|
NWidgetBase *nwi = this->GetWidget<NWidgetBase>(widget);
|
||||||
uint left = nwi->pos_x + WD_FRAMETEXT_LEFT;
|
uint left = nwi->pos_x + WD_FRAMETEXT_LEFT;
|
||||||
uint right = nwi->pos_x + nwi->current_x - 1 - WD_FRAMERECT_RIGHT;
|
uint right = nwi->pos_x + nwi->current_x - 1 - WD_FRAMERECT_RIGHT;
|
||||||
if (IsInsideMM(x, left, left + 20) ) {
|
if (IsInsideMM(x, left, left + 20) ) {
|
||||||
/* Clicked buttons, decrease or increase production */
|
/* Clicked buttons, decrease or increase production */
|
||||||
if (x < left + 10) {
|
if (x < left + 10) {
|
||||||
if (i->production_rate[line] <= 0) return;
|
if (i->production_rate[line - IL_RATE1] <= 0) return;
|
||||||
i->production_rate[line] = max(i->production_rate[line] / 2, 0);
|
i->production_rate[line - IL_RATE1] = max(i->production_rate[line - IL_RATE1] / 2, 0);
|
||||||
} else {
|
} else {
|
||||||
|
if (i->production_rate[line - IL_RATE1] >= 255) return;
|
||||||
/* a zero production industry is unlikely to give anything but zero, so push it a little bit */
|
/* a zero production industry is unlikely to give anything but zero, so push it a little bit */
|
||||||
int new_prod = i->production_rate[line] == 0 ? 1 : i->production_rate[line] * 2;
|
int new_prod = i->production_rate[line - IL_RATE1] == 0 ? 1 : i->production_rate[line - IL_RATE1] * 2;
|
||||||
if (i->production_rate[line] >= 255) return;
|
i->production_rate[line - IL_RATE1] = minu(new_prod, 255);
|
||||||
i->production_rate[line] = minu(new_prod, 255);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateIndustryProduction(i);
|
UpdateIndustryProduction(i);
|
||||||
this->SetDirty();
|
this->SetDirty();
|
||||||
this->flags4 |= WF_TIMEOUT_BEGIN;
|
this->flags4 |= WF_TIMEOUT_BEGIN;
|
||||||
this->clicked_line = line + 1;
|
this->clicked_line = line;
|
||||||
this->clicked_button = (x < left + 10 ? 1 : 2);
|
this->clicked_button = (x < left + 10 ? 1 : 2);
|
||||||
} else if (IsInsideMM(x, left + 30, right)) {
|
} else if (IsInsideMM(x, left + 30, right)) {
|
||||||
/* clicked the text */
|
/* clicked the text */
|
||||||
this->editbox_line = line;
|
this->editbox_line = line;
|
||||||
SetDParam(0, i->production_rate[line] * 8);
|
SetDParam(0, i->production_rate[line - IL_RATE1] * 8);
|
||||||
ShowQueryString(STR_JUST_INT, STR_CONFIG_GAME_PRODUCTION, 10, 100, this, CS_ALPHANUMERAL, QSF_NONE);
|
ShowQueryString(STR_JUST_INT, STR_CONFIG_GAME_PRODUCTION, 10, 100, this, CS_ALPHANUMERAL, QSF_NONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -840,7 +858,7 @@ public:
|
|||||||
|
|
||||||
virtual void OnTimeout()
|
virtual void OnTimeout()
|
||||||
{
|
{
|
||||||
this->clicked_line = 0;
|
this->clicked_line = IL_NONE;
|
||||||
this->clicked_button = 0;
|
this->clicked_button = 0;
|
||||||
this->SetDirty();
|
this->SetDirty();
|
||||||
}
|
}
|
||||||
@ -858,9 +876,8 @@ public:
|
|||||||
if (StrEmpty(str)) return;
|
if (StrEmpty(str)) return;
|
||||||
|
|
||||||
Industry *i = Industry::Get(this->window_number);
|
Industry *i = Industry::Get(this->window_number);
|
||||||
int line = this->editbox_line;
|
|
||||||
|
|
||||||
i->production_rate[line] = ClampU(atoi(str) / 8, 0, 255);
|
i->production_rate[this->editbox_line - IL_RATE1] = ClampU(atoi(str) / 8, 0, 255);
|
||||||
UpdateIndustryProduction(i);
|
UpdateIndustryProduction(i);
|
||||||
this->SetDirty();
|
this->SetDirty();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user