1
0
Fork 0

(svn r20899) -Codechange: Switch order of if-tests in IndustryViewWindow::OnClick().

release/1.1
frosch 2010-10-04 20:00:23 +00:00
parent 168b0a733f
commit 286aba3492
1 changed files with 51 additions and 35 deletions

View File

@ -802,46 +802,62 @@ public:
Industry *i = Industry::Get(this->window_number); Industry *i = Industry::Get(this->window_number);
InfoLine line = IL_NONE; InfoLine line = IL_NONE;
if (pt.y >= this->production_offset_y) { switch (this->editable) {
int row = (pt.y - this->production_offset_y) / FONT_HEIGHT_NORMAL; case EA_NONE: break;
for (uint j = 0; j < lengthof(i->produced_cargo); j++) {
if (i->produced_cargo[j] == CT_INVALID) continue; case EA_RATE:
row--; if (pt.y >= this->production_offset_y) {
if (row < 0) { int row = (pt.y - this->production_offset_y) / FONT_HEIGHT_NORMAL;
line = (InfoLine)(IL_RATE1 + j); for (uint j = 0; j < lengthof(i->produced_cargo); j++) {
break; if (i->produced_cargo[j] == CT_INVALID) continue;
row--;
if (row < 0) {
line = (InfoLine)(IL_RATE1 + j);
break;
}
}
} }
} break;
} }
if (line == IL_NONE) return; if (line == IL_NONE) return;
uint x = pt.x; NWidgetBase *nwi = this->GetWidget<NWidgetBase>(widget);
if (this->editable == EA_RATE) { int left = nwi->pos_x + WD_FRAMETEXT_LEFT;
NWidgetBase *nwi = this->GetWidget<NWidgetBase>(widget); int right = nwi->pos_x + nwi->current_x - 1 - WD_FRAMERECT_RIGHT;
uint left = nwi->pos_x + WD_FRAMETEXT_LEFT; if (IsInsideMM(pt.x, left, left + 20) ) {
uint right = nwi->pos_x + nwi->current_x - 1 - WD_FRAMERECT_RIGHT; /* Clicked buttons, decrease or increase production */
if (IsInsideMM(x, left, left + 20) ) { byte button = (pt.x < left + 10) ? 1 : 2;
/* Clicked buttons, decrease or increase production */ switch (this->editable) {
if (x < left + 10) { case EA_RATE:
if (i->production_rate[line - IL_RATE1] <= 0) return; if (button == 1) {
i->production_rate[line - IL_RATE1] = max(i->production_rate[line - IL_RATE1] / 2, 0); if (i->production_rate[line - IL_RATE1] <= 0) return;
} else { i->production_rate[line - IL_RATE1] = max(i->production_rate[line - IL_RATE1] / 2, 0);
if (i->production_rate[line - IL_RATE1] >= 255) return; } else {
/* a zero production industry is unlikely to give anything but zero, so push it a little bit */ if (i->production_rate[line - IL_RATE1] >= 255) return;
int new_prod = i->production_rate[line - IL_RATE1] == 0 ? 1 : i->production_rate[line - IL_RATE1] * 2; /* a zero production industry is unlikely to give anything but zero, so push it a little bit */
i->production_rate[line - IL_RATE1] = minu(new_prod, 255); int new_prod = i->production_rate[line - IL_RATE1] == 0 ? 1 : i->production_rate[line - IL_RATE1] * 2;
} i->production_rate[line - IL_RATE1] = minu(new_prod, 255);
}
break;
UpdateIndustryProduction(i); default: NOT_REACHED();
this->SetDirty(); }
this->flags4 |= WF_TIMEOUT_BEGIN;
this->clicked_line = line; UpdateIndustryProduction(i);
this->clicked_button = (x < left + 10 ? 1 : 2); this->SetDirty();
} else if (IsInsideMM(x, left + 30, right)) { this->flags4 |= WF_TIMEOUT_BEGIN;
/* clicked the text */ this->clicked_line = line;
this->editbox_line = line; this->clicked_button = button;
SetDParam(0, i->production_rate[line - IL_RATE1] * 8); } else if (IsInsideMM(pt.x, left + 30, right)) {
ShowQueryString(STR_JUST_INT, STR_CONFIG_GAME_PRODUCTION, 10, 100, this, CS_ALPHANUMERAL, QSF_NONE); /* clicked the text */
this->editbox_line = line;
switch (this->editable) {
case EA_RATE:
SetDParam(0, i->production_rate[line - IL_RATE1] * 8);
ShowQueryString(STR_JUST_INT, STR_CONFIG_GAME_PRODUCTION, 10, 100, this, CS_ALPHANUMERAL, QSF_NONE);
break;
default: NOT_REACHED();
} }
} }
break; break;