1
0
Fork 0

(svn r11978) -Codechange: Replace some global variables with window owned ones

release/0.6
skidd13 2008-01-24 18:35:35 +00:00
parent 44d085af6c
commit 4991dcecc7
1 changed files with 23 additions and 12 deletions

View File

@ -30,10 +30,6 @@
#include "table/sprites.h" #include "table/sprites.h"
#include "table/strings.h" #include "table/strings.h"
static uint32 _difficulty_click_a;
static uint32 _difficulty_click_b;
static byte _difficulty_timeout;
static const StringID _units_dropdown[] = { static const StringID _units_dropdown[] = {
STR_UNITS_IMPERIAL, STR_UNITS_IMPERIAL,
STR_UNITS_METRIC, STR_UNITS_METRIC,
@ -489,6 +485,16 @@ static GameOptions _opt_mod_temp;
// 0x383E = (1 << 13) | (1 << 12) | (1 << 11) | (1 << 5) | (1 << 4) | (1 << 3) | (1 << 2) | (1 << 1) // 0x383E = (1 << 13) | (1 << 12) | (1 << 11) | (1 << 5) | (1 << 4) | (1 << 3) | (1 << 2) | (1 << 1)
#define DIFF_INGAME_DISABLED_BUTTONS 0x383E #define DIFF_INGAME_DISABLED_BUTTONS 0x383E
#define NO_SETTINGS_BUTTON 0xFF
/** Carriage for the game settings window data */
struct difficulty_d {
bool clicked_increase;
uint8 clicked_button;
uint8 timeout;
};
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(difficulty_d));
/* Names of the game difficulty settings window */ /* Names of the game difficulty settings window */
enum GameDifficultyWidgets { enum GameDifficultyWidgets {
GDW_CLOSEBOX = 0, GDW_CLOSEBOX = 0,
@ -507,8 +513,12 @@ enum GameDifficultyWidgets {
static void GameDifficultyWndProc(Window *w, WindowEvent *e) static void GameDifficultyWndProc(Window *w, WindowEvent *e)
{ {
difficulty_d *diffic_d = &WP(w, difficulty_d);
switch (e->event) { switch (e->event) {
case WE_CREATE: case WE_CREATE:
diffic_d->clicked_increase = false;
diffic_d->clicked_button = NO_SETTINGS_BUTTON;
diffic_d->timeout = 0;
/* Hide the closebox to make sure that the user aborts or confirms his changes */ /* Hide the closebox to make sure that the user aborts or confirms his changes */
w->HideWidget(GDW_CLOSEBOX); w->HideWidget(GDW_CLOSEBOX);
w->widget[GDW_CAPTION].left = 0; w->widget[GDW_CAPTION].left = 0;
@ -545,7 +555,7 @@ static void GameDifficultyWndProc(Window *w, WindowEvent *e)
value = ((GDType*)&_opt_mod_temp.diff)[i]; value = ((GDType*)&_opt_mod_temp.diff)[i];
DrawArrowButtons(5, y, 3, DrawArrowButtons(5, y, 3,
!!HasBit(_difficulty_click_a, i) | !!HasBit(_difficulty_click_b, i) << 1, (diffic_d->clicked_button == i) ? 1 << diffic_d->clicked_increase : 0,
!(HasBit(disabled, i) || gsd->min == value), !(HasBit(disabled, i) || gsd->min == value),
!(HasBit(disabled, i) || gsd->max == value)); !(HasBit(disabled, i) || gsd->max == value));
@ -572,7 +582,7 @@ static void GameDifficultyWndProc(Window *w, WindowEvent *e)
if (y < 0) return; if (y < 0) return;
/* Get button from Y coord. */ /* Get button from Y coord. */
const uint btn = y / (GAMEDIFF_WND_ROWSIZE + 2); const uint8 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;
@ -580,7 +590,7 @@ static void GameDifficultyWndProc(Window *w, WindowEvent *e)
if (_game_mode == GM_NORMAL && HasBit(DIFF_INGAME_DISABLED_BUTTONS, btn)) if (_game_mode == GM_NORMAL && HasBit(DIFF_INGAME_DISABLED_BUTTONS, btn))
return; return;
_difficulty_timeout = 5; diffic_d->timeout = 5;
int16 val = ((GDType*)&_opt_mod_temp.diff)[btn]; int16 val = ((GDType*)&_opt_mod_temp.diff)[btn];
@ -588,13 +598,14 @@ static void GameDifficultyWndProc(Window *w, WindowEvent *e)
if (x >= 10) { if (x >= 10) {
/* Increase button clicked */ /* Increase button clicked */
val = min(val + info->step, info->max); val = min(val + info->step, info->max);
SetBit(_difficulty_click_b, btn); diffic_d->clicked_increase = true;
} else { } else {
/* Decrease button clicked */ /* Decrease button clicked */
val -= info->step; val -= info->step;
val = max(val, info->min); val = max(val, info->min);
SetBit(_difficulty_click_a, btn); diffic_d->clicked_increase = false;
} }
diffic_d->clicked_button = btn;
/* save value in temporary variable */ /* save value in temporary variable */
((GDType*)&_opt_mod_temp.diff)[btn] = val; ((GDType*)&_opt_mod_temp.diff)[btn] = val;
@ -642,9 +653,9 @@ static void GameDifficultyWndProc(Window *w, WindowEvent *e)
} break; } break;
case WE_MOUSELOOP: /* Handle the visual 'clicking' of the buttons */ case WE_MOUSELOOP: /* Handle the visual 'clicking' of the buttons */
if (_difficulty_timeout != 0 && !--_difficulty_timeout) { if (diffic_d->timeout != 0) {
_difficulty_click_a = 0; diffic_d->timeout--;
_difficulty_click_b = 0; if (diffic_d->timeout == 0) diffic_d->clicked_button = NO_SETTINGS_BUTTON;
SetWindowDirty(w); SetWindowDirty(w);
} }
break; break;