(svn r11745) -Codechange: Unify the spinner widget drawing of the difficulty settings window and make its disabled state min max aware.

replace/41b28d7194a279bdc17475d4fbe2ea6ec885a466
skidd13 17 years ago
parent 6f7f4adffc
commit ade37de6c6

@ -489,29 +489,27 @@ static void GameDifficultyWndProc(Window *w, WindowEvent *e)
case WE_PAINT: { case WE_PAINT: {
DrawWindowWidgets(w); DrawWindowWidgets(w);
uint32 click_a = _difficulty_click_a; /* XXX - Disabled buttons in normal gameplay or during muliplayer as non server.
uint32 click_b = _difficulty_click_b; * Bitshifted for each button to see if that bit is set. If it is set, the
* button is disabled */
/* XXX - Disabled buttons in normal gameplay. Bitshifted for each button to see if uint32 disabled = 0;
* that bit is set. If it is set, the button is disabled */ if (_networking && !_network_server) {
uint32 disabled = (_game_mode == GM_NORMAL) ? DIFF_INGAME_DISABLED_BUTTONS : 0; disabled = MAX_UVALUE(uint32); // Disable all
} else if (_game_mode == GM_NORMAL) {
disabled = DIFF_INGAME_DISABLED_BUTTONS;
}
int value; int value;
int y = GAMEDIFF_WND_TOP_OFFSET; int y = GAMEDIFF_WND_TOP_OFFSET;
for (uint i = 0; i != GAME_DIFFICULTY_NUM; i++) { for (uint i = 0; i != GAME_DIFFICULTY_NUM; i++) {
DrawFrameRect( 5, y, 5 + 8, y + 8, 3, HasBit(click_a, i) ? FR_LOWERED : FR_NONE); const GameSettingData *gsd = &_game_setting_info[i];
DrawFrameRect(15, y, 15 + 8, y + 8, 3, HasBit(click_b, i) ? FR_LOWERED : FR_NONE); value = ((GDType*)&_opt_mod_temp.diff)[i];
if (HasBit(disabled, i) || (_networking && !_network_server)) {
int color = (1 << PALETTE_MODIFIER_GREYOUT) | _colour_gradient[COLOUR_YELLOW][2];
GfxFillRect( 6, y + 1, 6 + 8, y + 8, color);
GfxFillRect(16, y + 1, 16 + 8, y + 8, color);
}
DrawStringCentered(10, y, STR_6819, TC_FROMSTRING); DrawArrowButtons(5, y, 3, HasBit(_difficulty_click_a, i) | HasBit(_difficulty_click_b, i) << 1,
DrawStringCentered(20, y, STR_681A, TC_FROMSTRING); !(HasBit(disabled, i) || gsd->min == value),
!(HasBit(disabled, i) || gsd->max == value));
value += _game_setting_info[i].str;
value = _game_setting_info[i].str + ((GDType*)&_opt_mod_temp.diff)[i];
if (i == 4) value *= 1000; // XXX - handle currency option if (i == 4) value *= 1000; // XXX - handle currency option
SetDParam(0, value); SetDParam(0, value);
DrawString(30, y, STR_6805_MAXIMUM_NO_COMPETITORS + i, TC_FROMSTRING); DrawString(30, y, STR_6805_MAXIMUM_NO_COMPETITORS + i, TC_FROMSTRING);
@ -526,22 +524,20 @@ static void GameDifficultyWndProc(Window *w, WindowEvent *e)
/* Don't allow clients to make any changes */ /* Don't allow clients to make any changes */
if (_networking && !_network_server) return; if (_networking && !_network_server) return;
int x = e->we.click.pt.x - 5; const int x = e->we.click.pt.x - 5;
if (!IsInsideMM(x, 0, 21)) // Button area if (!IsInsideMM(x, 0, 21)) // Button area
return; return;
int y = e->we.click.pt.y - GAMEDIFF_WND_TOP_OFFSET; const int y = e->we.click.pt.y - GAMEDIFF_WND_TOP_OFFSET;
if (y < 0) return; if (y < 0) return;
/* Get button from Y coord. */ /* Get button from Y coord. */
uint btn = y / (GAMEDIFF_WND_ROWSIZE + 2); const uint btn = y / (GAMEDIFF_WND_ROWSIZE + 2);
if (btn >= GAME_DIFFICULTY_NUM || y % (GAMEDIFF_WND_ROWSIZE + 2) >= 9) if (btn >= GAME_DIFFICULTY_NUM || y % (GAMEDIFF_WND_ROWSIZE + 2) >= 9)
return; return;
/* Clicked disabled button? */ /* Clicked disabled button? */
uint dis = (_game_mode == GM_NORMAL) ? DIFF_INGAME_DISABLED_BUTTONS : 0; if (_game_mode == GM_NORMAL && HasBit(DIFF_INGAME_DISABLED_BUTTONS, btn))
if (HasBit(dis, btn))
return; return;
_difficulty_timeout = 5; _difficulty_timeout = 5;
@ -564,7 +560,7 @@ static void GameDifficultyWndProc(Window *w, WindowEvent *e)
((GDType*)&_opt_mod_temp.diff)[btn] = val; ((GDType*)&_opt_mod_temp.diff)[btn] = val;
w->RaiseWidget(GDW_LVL_EASY + _opt_mod_temp.diff_level); w->RaiseWidget(GDW_LVL_EASY + _opt_mod_temp.diff_level);
SetDifficultyLevel(3, &_opt_mod_temp); // set difficulty level to custom SetDifficultyLevel(3, &_opt_mod_temp); // set difficulty level to custom
w->LowerWidget(GDW_LVL_EASY + _opt_mod_temp.diff_level); w->LowerWidget(GDW_LVL_CUSTOM);
SetWindowDirty(w); SetWindowDirty(w);
} break; } break;
case GDW_LVL_EASY: case GDW_LVL_EASY:

Loading…
Cancel
Save