summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--aircraft_gui.c16
-rw-r--r--airport_gui.c12
-rw-r--r--depot_gui.c21
-rw-r--r--genworld_gui.c33
-rw-r--r--graph_gui.c16
-rw-r--r--main_gui.c52
-rw-r--r--music_gui.c2
-rw-r--r--network_gui.c28
-rw-r--r--news_gui.c37
-rw-r--r--order_gui.c64
-rw-r--r--player_gui.c41
-rw-r--r--rail_gui.c33
-rw-r--r--road_gui.c7
-rw-r--r--roadveh_gui.c15
-rw-r--r--settings_gui.c26
-rw-r--r--ship_gui.c17
-rw-r--r--smallmap_gui.c2
-rw-r--r--station_gui.c12
-rw-r--r--town_gui.c4
-rw-r--r--train_gui.c37
-rw-r--r--vehicle_gui.c20
21 files changed, 233 insertions, 262 deletions
diff --git a/aircraft_gui.c b/aircraft_gui.c
index 97b88c062..0a16fb793 100644
--- a/aircraft_gui.c
+++ b/aircraft_gui.c
@@ -121,7 +121,7 @@ static void NewAircraftWndProc(Window *w, WindowEvent *e)
byte acc_planes;
if (tile == 0) {
- SETBIT(w->disabled_state, 5);
+ DisableWindowWidget(w, 5);
acc_planes = ALL;
} else {
acc_planes = GetAirport(GetStationByTile(tile)->airport_type)->acc_planes;
@@ -269,9 +269,11 @@ static void AircraftDetailsWndProc(Window *w, WindowEvent *e)
case WE_PAINT: {
const Vehicle *v = GetVehicle(w->window_number);
- w->disabled_state = v->owner == _local_player ? 0 : (1 << 2);
- if (!_patches.servint_aircraft) // disable service-scroller when interval is set to disabled
- w->disabled_state |= (1 << 5) | (1 << 6);
+ SetWindowWidgetDisabledState(w, 2, v->owner != _local_player);
+
+ /* Disable service-scroller when interval is set to disabled */
+ SetWindowWidgetDisabledState(w, 5, !_patches.servint_aircraft);
+ SetWindowWidgetDisabledState(w, 6, !_patches.servint_aircraft);
SetDParam(0, v->string_id);
SetDParam(1, v->unitnumber);
@@ -451,13 +453,11 @@ static void AircraftViewWndProc(Window *w, WindowEvent *e)
switch (e->event) {
case WE_PAINT: {
const Vehicle *v = GetVehicle(w->window_number);
- uint32 disabled = 1 << 8;
StringID str;
- if (IsAircraftInHangarStopped(v)) disabled = 0;
+ SetWindowWidgetDisabledState(w, 7, v->owner != _local_player);
+ SetWindowWidgetDisabledState(w, 8, !IsAircraftInHangarStopped(v) || v->owner != _local_player);
- if (v->owner != _local_player) disabled |= 1 << 8 | 1 << 7;
- w->disabled_state = disabled;
/* draw widgets & caption */
SetDParam(0, v->string_id);
diff --git a/airport_gui.c b/airport_gui.c
index de039ad71..b35bfb740 100644
--- a/airport_gui.c
+++ b/airport_gui.c
@@ -143,6 +143,7 @@ static void BuildAirportPickerWndProc(Window *w, WindowEvent *e)
{
switch (e->event) {
case WE_PAINT: {
+ int i; // airport enabling loop
int sel;
int rad = 4; // default catchment radious
uint32 avail_airports;
@@ -156,10 +157,13 @@ static void BuildAirportPickerWndProc(Window *w, WindowEvent *e)
if (!HASBIT(avail_airports, 0) && sel == AT_SMALL) sel = AT_LARGE;
if (!HASBIT(avail_airports, 1) && sel == AT_LARGE) sel = AT_SMALL;
- /* 'Country Airport' starts at widget 3, and if its bit is set, it is
- * available, so take its opposite value to set the disabled_state. There
- * are 9 buildable airports, so XOR with 0x01FF (1 1111 1111) */
- w->disabled_state = (avail_airports ^ 0x01FF) << 7;
+ /* 'Country Airport' starts at widget 7, and if its bit is set, it is
+ * available, so take its opposite value to set the disabled state.
+ * There are 9 buildable airports
+ * XXX TODO : all airports should be held in arrays, with all relevant data.
+ * This should be part of newgrf-airports, i suppose
+ */
+ for (i = 0; i < 9; i++) SetWindowWidgetDisabledState(w, i + 7, !HASBIT(avail_airports, i));
_selected_airport_type = sel;
// select default the coverage area to 'Off' (16)
diff --git a/depot_gui.c b/depot_gui.c
index 83554a89d..c52dfed7a 100644
--- a/depot_gui.c
+++ b/depot_gui.c
@@ -258,17 +258,20 @@ static void ShowDepotSellAllWindow(TileIndex tile, byte type)
static void DrawDepotWindow(Window *w)
{
Vehicle **vl = WP(w, depot_d).vehicle_list;
- TileIndex tile;
+ TileIndex tile = w->window_number;
int x, y, i, hnum, max;
uint16 num = WP(w, depot_d).engine_count;
-
- tile = w->window_number;
+ bool is_localplayer = IsTileOwner(tile, _local_player);
/* setup disabled buttons */
- w->disabled_state =
- IsTileOwner(tile, _local_player) ? 0 : ( (1 << DEPOT_WIDGET_STOP_ALL) | (1 << DEPOT_WIDGET_START_ALL) |
- (1 << DEPOT_WIDGET_SELL) | (1 << DEPOT_WIDGET_SELL_CHAIN) | (1 << DEPOT_WIDGET_SELL_ALL) |
- (1 << DEPOT_WIDGET_BUILD) | (1 << DEPOT_WIDGET_CLONE) | (1 << DEPOT_WIDGET_AUTOREPLACE));
+ SetWindowWidgetDisabledState(w, DEPOT_WIDGET_STOP_ALL, !is_localplayer);
+ SetWindowWidgetDisabledState(w, DEPOT_WIDGET_START_ALL, !is_localplayer);
+ SetWindowWidgetDisabledState(w, DEPOT_WIDGET_SELL, !is_localplayer);
+ SetWindowWidgetDisabledState(w, DEPOT_WIDGET_SELL_CHAIN, !is_localplayer);
+ SetWindowWidgetDisabledState(w, DEPOT_WIDGET_SELL_ALL, !is_localplayer);
+ SetWindowWidgetDisabledState(w, DEPOT_WIDGET_BUILD, !is_localplayer);
+ SetWindowWidgetDisabledState(w, DEPOT_WIDGET_CLONE, !is_localplayer);
+ SetWindowWidgetDisabledState(w, DEPOT_WIDGET_AUTOREPLACE, !is_localplayer);
/* determine amount of items for scroller */
if (WP(w, depot_d).type == VEH_Train) {
@@ -740,14 +743,14 @@ static void DepotWndProc(Window *w, WindowEvent *e)
} break;
case DEPOT_WIDGET_SELL: case DEPOT_WIDGET_SELL_CHAIN:
- if (!HASBIT(w->disabled_state, DEPOT_WIDGET_SELL) &&
+ if (!IsWindowWidgetDisabled(w, DEPOT_WIDGET_SELL) &&
WP(w, depot_d).sel != INVALID_VEHICLE) {
Vehicle *v;
uint command;
int sell_cmd;
bool is_engine;
- if (HASBIT(w->disabled_state, e->we.click.widget)) return;
+ if (IsWindowWidgetDisabled(w, e->we.click.widget)) return;
if (WP(w, depot_d).sel == INVALID_VEHICLE) return;
HandleButtonClick(w, e->we.click.widget);
diff --git a/genworld_gui.c b/genworld_gui.c
index 0c33a8125..1c406cbe3 100644
--- a/genworld_gui.c
+++ b/genworld_gui.c
@@ -209,7 +209,6 @@ void GenerateLandscapeWndProc(Window *w, WindowEvent *e)
switch (e->event) {
case WE_PAINT:
- w->disabled_state = 0;
/* TODO -- Above and below you see some lines commented out with '//' in
* front of it. This is because currently the widget system can't handle
* more than 32 widgets per window, and we need 34. Therefor we draw
@@ -223,18 +222,23 @@ void GenerateLandscapeWndProc(Window *w, WindowEvent *e)
/* You can't select smoothness if not terragenesis */
// if (_patches_newgame.land_generator == 0) w->disabled_state |= (1 << 32 | 1 << 33);
- if (_patches_newgame.land_generator == 0) w->disabled_state |= (1 << 30 | 1 << 31);
+ SetWindowWidgetDisabledState(w, 30, _patches_newgame.land_generator == 0);
+ SetWindowWidgetDisabledState(w, 31, _patches_newgame.land_generator == 0);
/* Disable snowline if not hilly */
- if (_opt_newgame.landscape != LT_HILLY) w->disabled_state |= (1 << 21 | 1 << 22 | 1 << 23);
+ SetWindowWidgetDisabledState(w, 22, _opt_newgame.landscape != LT_HILLY);
/* Disable town and industry in SE */
- if (_game_mode == GM_EDITOR) w->disabled_state |= (1 << 11 | 1 << 12 | 1 << 13 | 1 << 14 | 1 << 24 | 1 << 25);
+ SetWindowWidgetDisabledState(w, 11, _game_mode == GM_EDITOR);
+ SetWindowWidgetDisabledState(w, 12, _game_mode == GM_EDITOR);
+ SetWindowWidgetDisabledState(w, 13, _game_mode == GM_EDITOR);
+ SetWindowWidgetDisabledState(w, 14, _game_mode == GM_EDITOR);
+ SetWindowWidgetDisabledState(w, 24, _game_mode == GM_EDITOR);
+ SetWindowWidgetDisabledState(w, 25, _game_mode == GM_EDITOR);
+
+ SetWindowWidgetDisabledState(w, 18, _patches_newgame.starting_year <= MIN_YEAR);
+ SetWindowWidgetDisabledState(w, 20, _patches_newgame.starting_year >= MAX_YEAR);
+ SetWindowWidgetDisabledState(w, 21, _patches_newgame.snow_line_height <= 2 || _opt_newgame.landscape != LT_HILLY);
+ SetWindowWidgetDisabledState(w, 23, _patches_newgame.snow_line_height >= 13 || _opt_newgame.landscape != LT_HILLY);
- if (_patches_newgame.starting_year <= MIN_YEAR) SETBIT(w->disabled_state, 18);
- if (_patches_newgame.starting_year >= MAX_YEAR) SETBIT(w->disabled_state, 20);
- if (_patches_newgame.snow_line_height <= 2 ) SETBIT(w->disabled_state, 21);
- if (_patches_newgame.snow_line_height >= 13) SETBIT(w->disabled_state, 23);
-
- w->click_state = (w->click_state & ~(0xF << 3)) | (1 << (_opt_newgame.landscape + 3));
DrawWindowWidgets(w);
y = (mode == GLWP_HEIGHTMAP) ? 22 : 0;
@@ -576,11 +580,10 @@ void CreateScenarioWndProc(Window *w, WindowEvent *e)
switch (e->event) {
case WE_PAINT:
- w->disabled_state = 0;
- if (_patches_newgame.starting_year <= MIN_YEAR) SETBIT(w->disabled_state, 14);
- if (_patches_newgame.starting_year >= MAX_YEAR) SETBIT(w->disabled_state, 16);
- if (_patches_newgame.se_flat_world_height <= 0) SETBIT(w->disabled_state, 17);
- if (_patches_newgame.se_flat_world_height >= 15) SETBIT(w->disabled_state, 19);
+ SetWindowWidgetDisabledState(w, 14, _patches_newgame.starting_year <= MIN_YEAR);
+ SetWindowWidgetDisabledState(w, 16, _patches_newgame.starting_year >= MAX_YEAR);
+ SetWindowWidgetDisabledState(w, 17, _patches_newgame.se_flat_world_height <= 0);
+ SetWindowWidgetDisabledState(w, 19, _patches_newgame.se_flat_world_height >= 15);
w->click_state = (w->click_state & ~(0xF << 3)) | (1 << (_opt_newgame.landscape + 3));
DrawWindowWidgets(w);
diff --git a/graph_gui.c b/graph_gui.c
index ee725b526..8e7e2ea32 100644
--- a/graph_gui.c
+++ b/graph_gui.c
@@ -899,9 +899,9 @@ static void PerformanceRatingDetailWndProc(Window *w, WindowEvent *e)
for (i = 0; i < MAX_PLAYERS; i++) {
if (!GetPlayer(i)->is_active) {
// Check if we have the player as an active player
- if (!(w->disabled_state & (1 << (i + 13)))) {
+ if (!IsWindowWidgetDisabled(w, i + 13)) {
// Bah, player gone :(
- w->disabled_state += 1 << (i + 13);
+ DisableWindowWidget(w, i + 13);
// Is this player selected? If so, select first player (always save? :s)
if (w->click_state == 1U << (i + 13)) w->click_state = 1 << 13;
// We need a repaint
@@ -911,9 +911,9 @@ static void PerformanceRatingDetailWndProc(Window *w, WindowEvent *e)
}
// Check if we have the player marked as inactive
- if (w->disabled_state & (1 << (i + 13))) {
+ if (IsWindowWidgetDisabled(w, i + 13)) {
// New player! Yippie :p
- w->disabled_state -= 1 << (i + 13);
+ EnableWindowWidget(w, i + 13);
// We need a repaint
SetWindowDirty(w);
}
@@ -1000,7 +1000,7 @@ static void PerformanceRatingDetailWndProc(Window *w, WindowEvent *e)
// Check which button is clicked
if (IS_INT_INSIDE(e->we.click.widget, 13, 21)) {
// Is it no on disable?
- if ((w->disabled_state & (1 << e->we.click.widget)) == 0) {
+ if (!IsWindowWidgetDisabled(w, e->we.click.widget)) {
w->click_state = 1 << e->we.click.widget;
SetWindowDirty(w);
}
@@ -1011,11 +1011,9 @@ static void PerformanceRatingDetailWndProc(Window *w, WindowEvent *e)
int i;
Player *p2;
- w->disabled_state = 0;
-
- // Hide the player who are not active
+ /* Disable the players who are not active */
for (i = 0; i < MAX_PLAYERS; i++) {
- if (!GetPlayer(i)->is_active) w->disabled_state += 1 << (i + 13);
+ SetWindowWidgetDisabledState(w, i + 13, !GetPlayer(i)->is_active);
}
// Update all player stats with the current data
// (this is because _score_info is not saved to a savegame)
diff --git a/main_gui.c b/main_gui.c
index e8fed0744..3bdab15aa 100644
--- a/main_gui.c
+++ b/main_gui.c
@@ -107,7 +107,7 @@ bool HandlePlacePushButton(Window *w, int widget, CursorID cursor, int mode, Pla
{
uint32 mask = 1 << widget;
- if (w->disabled_state & mask) return false;
+ if (IsWindowWidgetDisabled(w, widget)) return false;
SndPlayFx(SND_15_BEEP);
SetWindowDirty(w);
@@ -869,12 +869,9 @@ bool DoZoomInOutWindow(int how, Window *w)
assert(wt);
// update the toolbar button too
- CLRBIT(wt->disabled_state, button);
- CLRBIT(wt->disabled_state, button + 1);
- switch (vp->zoom) {
- case 0: SETBIT(wt->disabled_state, button); break;
- case 2: SETBIT(wt->disabled_state, button + 1); break;
- }
+ SetWindowWidgetDisabledState(wt, button, vp->zoom == 0);
+ SetWindowWidgetDisabledState(wt, button + 1, vp->zoom == 2);
+
SetWindowDirty(wt);
}
@@ -1754,24 +1751,27 @@ static void MainToolbarWndProc(Window *w, WindowEvent *e)
{
switch (e->event) {
case WE_PAINT: {
+ bool is_spectator = _current_player == OWNER_SPECTATOR;
// Draw brown-red toolbar bg.
GfxFillRect(0, 0, w->width-1, w->height-1, 0xB2);
GfxFillRect(0, 0, w->width-1, w->height-1, 0xB4 | PALETTE_MODIFIER_GREYOUT);
- // if spectator, disable things
- if (_current_player == OWNER_SPECTATOR){
- w->disabled_state |= (1 << 19) | (1<<20) | (1<<21) | (1<<22) | (1<<23);
- } else {
- w->disabled_state &= ~((1 << 19) | (1<<20) | (1<<21) | (1<<22) | (1<<23));
- }
+ /* If spectator, disable all construction buttons
+ * ie : Build road, rail, ships, airports and landscaping
+ * Since enabled state is the default, just disable when needed */
+ SetWindowWidgetDisabledState(w, 19, is_spectator);
+ SetWindowWidgetDisabledState(w, 20, is_spectator);
+ SetWindowWidgetDisabledState(w, 21, is_spectator);
+ SetWindowWidgetDisabledState(w, 22, is_spectator);
+ SetWindowWidgetDisabledState(w, 23, is_spectator);
DrawWindowWidgets(w);
break;
}
case WE_CLICK: {
- if (_game_mode != GM_MENU && !HASBIT(w->disabled_state, e->we.click.widget))
+ if (_game_mode != GM_MENU && !IsWindowWidgetDisabled(w, e->we.click.widget))
_toolbar_button_procs[e->we.click.widget](w);
} break;
@@ -1961,16 +1961,8 @@ static void ScenEditToolbarWndProc(Window *w, WindowEvent *e)
{
switch (e->event) {
case WE_PAINT:
- if (_patches_newgame.starting_year <= MIN_YEAR) {
- SETBIT(w->disabled_state, 6);
- } else {
- CLRBIT(w->disabled_state, 6);
- }
- if (_patches_newgame.starting_year >= MAX_YEAR) {
- SETBIT(w->disabled_state, 7);
- } else {
- CLRBIT(w->disabled_state, 7);
- }
+ SetWindowWidgetDisabledState(w, 6, _patches_newgame.starting_year <= MIN_YEAR);
+ SetWindowWidgetDisabledState(w, 7, _patches_newgame.starting_year >= MAX_YEAR);
// Draw brown-red toolbar bg.
GfxFillRect(0, 0, w->width-1, w->height-1, 0xB2);
@@ -2368,19 +2360,15 @@ void ShowVitalWindows(void)
if (_game_mode != GM_EDITOR) {
w = AllocateWindowDesc(&_toolb_normal_desc);
- w->disabled_state = 1 << 18;
+ DisableWindowWidget(w, 18);
} else {
w = AllocateWindowDesc(&_toolb_scen_desc);
- w->disabled_state = 1 << 10;
+ DisableWindowWidget(w, 10);
}
CLRBITS(w->flags4, WF_WHITE_BORDER_MASK);
- if (_networking) {
- /* If networking, disable fast-forward button */
- SETBIT(w->disabled_state, 1);
- /* If not server, disable pause button */
- if (!_network_server) SETBIT(w->disabled_state, 0);
- }
+ SetWindowWidgetDisabledState(w, 0, _networking && !_network_server); // if not server, disable pause button
+ SetWindowWidgetDisabledState(w, 1, _networking); // if networking, disable fast-forward button
/* 'w' is for sure a WC_MAIN_TOOLBAR */
PositionMainToolbar(w);
diff --git a/music_gui.c b/music_gui.c
index c98ead015..6174337c0 100644
--- a/music_gui.c
+++ b/music_gui.c
@@ -199,7 +199,7 @@ static void MusicTrackSelectionWndProc(Window *w, WindowEvent *e)
uint i;
int y;
- w->disabled_state = (msf.playlist <= 3) ? (1 << 11) : 0;
+ SetWindowWidgetDisabledState(w, 11, msf.playlist <= 3);
w->click_state |= 0x18;
DrawWindowWidgets(w);
diff --git a/network_gui.c b/network_gui.c
index 5f843c05a..c3b36693c 100644
--- a/network_gui.c
+++ b/network_gui.c
@@ -238,18 +238,12 @@ static void NetworkGameWindowWndProc(Window *w, WindowEvent *e)
}
if (ld->flags & VL_RESORT) SortNetworkGameList(&WP(w, network_ql_d));
- w->disabled_state = 0;
-
- if (sel == NULL) {
- SETBIT(w->disabled_state, 16); SETBIT(w->disabled_state, 17);
- } else if (!sel->online) {
- SETBIT(w->disabled_state, 16); // Server offline, join button disabled
- } else if (sel->info.clients_on >= sel->info.clients_max) {
- SETBIT(w->disabled_state, 16); // Server full, join button disabled
- } else if (!sel->info.compatible) {
- // revisions don't match, check if server has no revision; then allow connection
- SETBIT(w->disabled_state, 16); // Revision mismatch, join button disabled
- }
+ SetWindowWidgetDisabledState(w, 17, sel == NULL);
+ /* Join Button disabling conditions */
+ SetWindowWidgetDisabledState(w, 16, sel == NULL || // no Selected Server
+ !sel->online || // Server offline
+ sel->info.clients_on >= sel->info.clients_max || // Server full
+ !sel->info.compatible); // Revision mismatch
SetDParam(0, 0x00);
SetDParam(7, _lan_internet_types_dropdown[_network_lan_internet]);
@@ -823,14 +817,12 @@ static void NetworkLobbyWindowWndProc(Window *w, WindowEvent *e)
const NetworkGameInfo *gi = &nd->server->info;
int y = NET_PRC__OFFSET_TOP_WIDGET_COMPANY, pos;
- w->disabled_state = 0;
-
- if (nd->company == (byte)-1) SETBIT(w->disabled_state, 7);
- if (gi->companies_on >= gi->companies_max) SETBIT(w->disabled_state, 8);
- if (gi->spectators_on >= gi->spectators_max) SETBIT(w->disabled_state, 9);
+ SetWindowWidgetDisabledState(w, 7, nd->company == (byte)-1);
+ SetWindowWidgetDisabledState(w, 8, gi->companies_on >= gi->companies_max);
/* You can not join a server as spectator when it has no companies active..
* it causes some nasty crashes */
- if (gi->companies_on == 0) SETBIT(w->disabled_state, 9);
+ SetWindowWidgetDisabledState(w, 9, gi->spectators_on >= gi->spectators_max ||
+ gi->companies_on == 0);
DrawWindowWidgets(w);
diff --git a/news_gui.c b/news_gui.c
index 2dbe63294..63e42a725 100644
--- a/news_gui.c
+++ b/news_gui.c
@@ -685,32 +685,14 @@ void ShowMessageHistory(void)
static void SetMessageButtonStates(Window *w, byte value, int element)
{
element *= 2;
- switch (value) {
- case 0: /* Off */
- SETBIT(w->disabled_state, element + 3);
- CLRBIT(w->disabled_state, element + 3 + 1);
- break;
- case 1: /* Summary */
- CLRBIT(w->disabled_state, element + 3);
- CLRBIT(w->disabled_state, element + 3 + 1);
- break;
- case 2: /* Full */
- SETBIT(w->disabled_state, element + 3 + 1);
- CLRBIT(w->disabled_state, element + 3);
- break;
- default: NOT_REACHED();
- }
+
+ SetWindowWidgetDisabledState(w, element + 3, value == 0);
+ SetWindowWidgetDisabledState(w, element + 3 + 1, value == 2);
}
static void MessageOptionsWndProc(Window *w, WindowEvent *e)
{
static const StringID message_opt[] = {STR_OFF, STR_SUMMARY, STR_FULL, INVALID_STRING_ID};
- static const uint32 message_val[] = {0x0, 0x55555555, 0xAAAAAAAA}; // 0x555.. = 01010101010101010101 (all summary), 286.. 1010... (full)
- static const uint32 message_dis[] = {
- (1 << 3) | (1 << 5) | (1 << 7) | (1 << 9) | (1 << 11) | (1 << 13) | (1 << 15) | (1 << 17) | (1 << 19) | (1 << 21),
- 0,
- (1 << 4) | (1 << 6) | (1 << 8) | (1 << 10) | (1 << 12) | (1 << 14) | (1 << 16) | (1 << 18) | (1 << 20) | (1 << 22),
- };
/* WP(w, def_d).data_1 are stores the clicked state of the fake widgets
* WP(w, def_d).data_2 stores state of the ALL on/off/summary button */
@@ -784,18 +766,23 @@ static void MessageOptionsWndProc(Window *w, WindowEvent *e)
} break;
} break;
- case WE_DROPDOWN_SELECT: /* Select all settings for newsmessages */
+ case WE_DROPDOWN_SELECT: {/* Select all settings for newsmessages */
+ int i;
+
WP(w, def_d).data_2 = e->we.dropdown.index;
- _news_display_opt = message_val[WP(w, def_d).data_2];
- w->disabled_state = message_dis[WP(w, def_d).data_2];
+
+ for (i = 0; i != 10; i++) {
+ SB(_news_display_opt, i*2, 2, e->we.dropdown.index);
+ SetMessageButtonStates(w, e->we.dropdown.index, i);
+ }
SetWindowDirty(w);
break;
+ }
case WE_TIMEOUT: /* XXX - Hack to animate 'fake' buttons */
WP(w, def_d).data_1 = 0;
SetWindowDirty(w);
break;
-
}
}
diff --git a/order_gui.c b/order_gui.c
index c1b262a72..403d6ab62 100644
--- a/order_gui.c
+++ b/order_gui.c
@@ -57,22 +57,13 @@ static void DrawOrdersWindow(Window *w)
int sel;
int y, i;
bool shared_orders;
+ bool not_localplayer;
byte color;
v = GetVehicle(w->window_number);
-
- w->disabled_state = (v->owner == _local_player) ? 0 : (
- 1 << 4 | //skip
- 1 << 5 | //delete
- 1 << 6 | //non-stop
- 1 << 7 | //go-to
- 1 << 8 | //full load
- 1 << 9 | //unload
- 1 << 10 //transfer
- );
+ not_localplayer = v->owner != _local_player;
if (v->type != VEH_Train) {
- SETBIT(w->disabled_state, 6); // Disable non-stop for non-trains
switch (v->type) {
case VEH_Road: w->widget[11].data = STR_LORRY; break;
case VEH_Ship: w->widget[11].data = STR_SHIP; break;
@@ -83,16 +74,6 @@ static void DrawOrdersWindow(Window *w)
shared_orders = IsOrderListShared(v);
- if (!shared_orders || v->orders == NULL) {
- SETBIT(w->disabled_state, 11); // Disable list of vehicles with the same shared orders if there are no list
- }
-
- if ((uint)v->num_orders + (shared_orders?1:0) <= (uint)WP(w,order_d).sel)
- SETBIT(w->disabled_state, 5); /* delete */
-
- if (v->num_orders == 0)
- SETBIT(w->disabled_state, 4); /* skip */
-
SetVScrollCount(w, v->num_orders + 1);
sel = OrderGetSel(w);
@@ -100,33 +81,44 @@ static void DrawOrdersWindow(Window *w)
order = GetVehicleOrder(v, sel);
+ /* skip */
+ SetWindowWidgetDisabledState(w, 4, not_localplayer || v->num_orders == 0);
+
+ /* delete */
+ SetWindowWidgetDisabledState(w, 5, not_localplayer ||
+ (uint)v->num_orders + (shared_orders ? 1 : 0) <= (uint)WP(w, order_d).sel);
+
+ /* non-stop only for trains */
+ SetWindowWidgetDisabledState(w, 6, not_localplayer || v->type != VEH_Train
+ || order == NULL);
+ SetWindowWidgetDisabledState(w, 7, not_localplayer); // go-to
+ SetWindowWidgetDisabledState(w, 8, not_localplayer || order == NULL); // full load
+ SetWindowWidgetDisabledState(w, 9, not_localplayer || order == NULL); // unload
+ SetWindowWidgetDisabledState(w, 10, not_localplayer || order == NULL); // transfer
+ SetWindowWidgetDisabledState(w, 11, !shared_orders || v->orders == NULL); // Disable list of vehicles with the same shared orders if there are no list
+
if (order != NULL) {
switch (order->type) {
case OT_GOTO_STATION:
break;
case OT_GOTO_DEPOT:
- SETBIT(w->disabled_state, 9); /* unload */
- SETBIT(w->disabled_state, 10); /* transfer */
+ DisableWindowWidget(w, 9);
+ DisableWindowWidget(w, 10);
SetDParam(2,STR_SERVICE);
break;
case OT_GOTO_WAYPOINT:
- SETBIT(w->disabled_state, 8); /* full load */
- SETBIT(w->disabled_state, 9); /* unload */
- SETBIT(w->disabled_state, 10); /* transfer */
+ DisableWindowWidget(w, 8);
+ DisableWindowWidget(w, 9);
+ DisableWindowWidget(w, 10);
break;
- default:
- SETBIT(w->disabled_state, 6); /* nonstop */
- SETBIT(w->disabled_state, 8); /* full load */
- SETBIT(w->disabled_state, 9); /* unload */
+ default: // every other orders
+ DisableWindowWidget(w, 6);
+ DisableWindowWidget(w, 8);
+ DisableWindowWidget(w, 9);
}
- } else {
- SETBIT(w->disabled_state, 6); /* nonstop */
- SETBIT(w->disabled_state, 8); /* full load */
- SETBIT(w->disabled_state, 9); /* unload */
- SETBIT(w->disabled_state, 10); /* transfer */
}
SetDParam(0, v->string_id);
@@ -477,7 +469,7 @@ static void OrdersWndProc(Window *w, WindowEvent *e)
if (e->we.keypress.keycode == _order_keycodes[i]) {
e->we.keypress.cont = false;
//see if the button is disabled
- if (!HASBIT(w->disabled_state, i + 4)) _order_button_proc[i](w, v);
+ if (!IsWindowWidgetDisabled(w, i + 4)) _order_button_proc[i](w, v);
break;
}
}
diff --git a/player_gui.c b/player_gui.c
index d227f485f..9c2a89bb2 100644
--- a/player_gui.c
+++ b/player_gui.c
@@ -154,7 +154,7 @@ static void PlayerFinancesWndProc(Window *w, WindowEvent *e)
PlayerID player = w->window_number;
const Player *p = GetPlayer(player);
- w->disabled_state = p->current_loan != 0 ? 0 : (1 << 7);
+ SetWindowWidgetDisabledState(w, 7, p->current_loan == 0);
SetDParam(0, p->name_1);
SetDParam(1, p->name_2);
@@ -322,11 +322,13 @@ static void SelectPlayerLiveryWndProc(Window *w, WindowEvent *e)
LiveryScheme scheme = LS_DEFAULT;
int y = 51;
- if ((WP(w, livery_d).sel == 0)) {
- /* Disable dropdown controls if no scheme is selected */
- w->disabled_state = 1 << 9 | 1 << 10 | 1 << 11 | 1 << 12;
- } else {
- w->disabled_state = 0;
+ /* Disable dropdown controls if no scheme is selected */
+ SetWindowWidgetDisabledState(w, 9, (WP(w, livery_d).sel == 0));
+ SetWindowWidgetDisabledState(w, 10, (WP(w, livery_d).sel == 0));
+ SetWindowWidgetDisabledState(w, 11, (WP(w, livery_d).sel == 0));
+ SetWindowWidgetDisabledState(w, 12, (WP(w, livery_d).sel == 0));
+
+ if (!(WP(w, livery_d).sel == 0)) {
for (scheme = 0; scheme < LS_END; scheme++) {
if (HASBIT(WP(w, livery_d).sel, scheme)) break;
}
@@ -649,29 +651,29 @@ static void PlayerCompanyWndProc(Window *w, WindowEvent *e)
switch (e->event) {
case WE_PAINT: {
const Player *p = GetPlayer(w->window_number);
- uint32 dis = 0;
if (!IsWindowOfPrototype(w, _other_player_company_widgets)) {
AssignWidgetToWindow(w, (p->location_of_house != 0) ? _my_player_company_bh_widgets : _my_player_company_widgets);
SetWindowWidgetHiddenState(w, 11, !_networking); // Hide company-password widget
} else {
- if (p->location_of_house == 0) SETBIT(dis, 7);
+ SetWindowWidgetDisabledState(w, 7, p->location_of_house == 0);
- if (_patches.allow_shares) { /* shares are allowed */
+ if (_patches.allow_shares) { // Shares are allowed
/* If all shares are owned by someone (none by nobody), disable buy button */
- if (GetAmountOwnedBy(p, OWNER_SPECTATOR) == 0) SETBIT(dis, 9);
-
- /* Only 25% left to buy. If the player is human, disable buying it up.. TODO issues! */
- if (GetAmountOwnedBy(p, OWNER_SPECTATOR) == 1 && !p->is_ai) SETBIT(dis, 9);
+ SetWindowWidgetDisabledState(w, 9, GetAmountOwnedBy(p, OWNER_SPECTATOR) == 0 ||
+ /* Only 25% left to buy. If the player is human, disable buying it up.. TODO issues! */
+ (GetAmountOwnedBy(p, OWNER_SPECTATOR) == 1 && !p->is_ai) ||
+ /* Spectators cannot do anything of course */
+ _local_player == OWNER_SPECTATOR);
/* If the player doesn't own any shares, disable sell button */
- if (GetAmountOwnedBy(p, _local_player) == 0) SETBIT(dis, 10);
-
- /* Spectators cannot do anything of course */
- if (_local_player == OWNER_SPECTATOR) dis |= (1 << 9) | (1 << 10);
- } else { /* shares are not allowed, disable buy/sell buttons */
- dis |= (1 << 9) | (1 << 10);
+ SetWindowWidgetDisabledState(w, 10, (GetAmountOwnedBy(p, _local_player) == 0) ||
+ /* Spectators cannot do anything of course */
+ _local_player == OWNER_SPECTATOR);
+ } else { // Shares are not allowed, disable buy/sell buttons
+ DisableWindowWidget(w, 9);
+ DisableWindowWidget(w, 10);
}
}
@@ -679,7 +681,6 @@ static void PlayerCompanyWndProc(Window *w, WindowEvent *e)
SetDParam(1, p->name_2);
SetDParam(2, GetPlayerNameString((byte)w->window_number, 3));
- w->disabled_state = dis;
DrawWindowWidgets(w);
SetDParam(0, p->inaugurated_year);
diff --git a/rail_gui.c b/rail_gui.c
index 25d9b2f6a..635c63e2b 100644
--- a/rail_gui.c
+++ b/rail_gui.c
@@ -292,7 +292,7 @@ static void BuildRailClick_Tunnel(Window *w)
static void BuildRailClick_Remove(Window *w)
{
- if (HASBIT(w->disabled_state, 16)) return;
+ if (IsWindowWidgetDisabled(w, 16)) return;
SetWindowDirty(w);
SndPlayFx(SND_15_BEEP);
@@ -405,24 +405,25 @@ static const uint16 _rail_keycodes[] = {
};
+static void UpdateRemoveWidgetStatus(Window *w, int clicked_widget)
+{
+ switch (clicked_widget) {
+ case 4: case 5: case 6: case 7: case 8: case 11: case 12: case 13: EnableWindowWidget(w, 16); break;
+ default: DisableWindowWidget(w, 16); w->click_state &= ~(1 << 16); break;
+ }
+}
+
static void BuildRailToolbWndProc(Window *w, WindowEvent *e)
{
switch (e->event) {
- case WE_PAINT:
- w->disabled_state &= ~(1 << 16);
- if (!(w->click_state & ((1<<4)|(1<<5)|(1<<6)|(1<<7)|(1<<8)|(1<<11)|(1<<12)|(1<<13)))) {
- w->disabled_state |= (1 << 16);
- w->click_state &= ~(1<<16);
- }
- DrawWindowWidgets(w);
- break;
-
+ case WE_PAINT: DrawWindowWidgets(w); break;
case WE_CLICK:
if (e->we.click.widget >= 4) {
_remove_button_clicked = false;
_build_railroad_button_proc[e->we.click.widget - 4](w);
}
- break;
+ UpdateRemoveWidgetStatus(w, e->we.click.widget);
+ break;
case WE_KEYPRESS: {
uint i;
@@ -432,6 +433,7 @@ static void BuildRailToolbWndProc(Window *w, WindowEvent *e)
e->we.keypress.cont = false;
_remove_button_clicked = false;
_build_railroad_button_proc[i](w);
+ UpdateRemoveWidgetStatus(w, i);
break;
}
}
@@ -651,10 +653,9 @@ static void StationBuildWndProc(Window *w, WindowEvent *e)
SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
/* Update buttons for correct spread value */
- w->disabled_state = 0;
for (bits = _patches.station_spread; bits < 7; bits++) {
- SETBIT(w->disabled_state, bits + 5);
- SETBIT(w->disabled_state, bits + 12);
+ DisableWindowWidget(w, bits + 5);
+ DisableWindowWidget(w, bits + 12);
}
if (newstations) {
@@ -662,8 +663,8 @@ static void StationBuildWndProc(Window *w, WindowEvent *e)
if (statspec != NULL) {
for (bits = 0; bits < 7; bits++) {
- if (HASBIT(statspec->disallowed_platforms, bits)) SETBIT(w->disabled_state, bits + 5);
- if (HASBIT(statspec->disallowed_lengths, bits)) SETBIT(w->disabled_state, bits + 12);
+ SetWindowWidgetDisabledState(w, bits + 5, HASBIT(statspec->disallowed_platforms, bits));
+ SetWindowWidgetDisabledState(w, bits + 12, HASBIT(statspec->disallowed_lengths, bits));
}
}
}
diff --git a/road_gui.c b/road_gui.c
index 332842e3d..380940935 100644
--- a/road_gui.c
+++ b/road_gui.c
@@ -155,7 +155,7 @@ static void BuildRoadClick_Tunnel(Window *w)
static void BuildRoadClick_Remove(Window *w)
{
- if (HASBIT(w->disabled_state, 11)) return;
+ if (IsWindowWidgetDisabled(w, 11)) return;
SetWindowDirty(w);
SndPlayFx(SND_15_BEEP);
TOGGLEBIT(w->click_state, 11);
@@ -184,10 +184,11 @@ static void BuildRoadToolbWndProc(Window *w, WindowEvent *e)
{
switch (e->event) {
case WE_PAINT:
- w->disabled_state &= ~(1 << 11);
if (!(w->click_state & ((1<<3)|(1<<4)))) {
- w->disabled_state |= (1 << 11);
+ DisableWindowWidget(w, 11);
w->click_state &= ~(1<<11);
+ } else {
+ EnableWindowWidget(w, 11);
}
DrawWindowWidgets(w);
break;
diff --git a/roadveh_gui.c b/roadveh_gui.c
index 2a5066c1f..fa073b343 100644
--- a/roadveh_gui.c
+++ b/roadveh_gui.c
@@ -86,9 +86,10 @@ static void RoadVehDetailsWndProc(Window *w, WindowEvent *e)
const Vehicle *v = GetVehicle(w->window_number);
StringID str;
- w->disabled_state = v->owner == _local_player ? 0 : (1 << 2);
+ SetWindowWidgetDisabledState(w, 2, v->owner != _local_player);
// disable service-scroller when interval is set to disabled
- if (!_patches.servint_roadveh) w->disabled_state |= (1 << 5) | (1 << 6);
+ SetWindowWidgetDisabledState(w, 5, !_patches.servint_roadveh);
+ SetWindowWidgetDisabledState(w, 6, !_patches.servint_roadveh);
SetDParam(0, v->string_id);
SetDParam(1, v->unitnumber);
@@ -236,10 +237,11 @@ static void RoadVehViewWndProc(Window *w, WindowEvent *e)
Vehicle *v = GetVehicle(w->window_number);
StringID str;
- w->disabled_state = (v->owner != _local_player) ? (1 << 8 | 1 << 7 | 1 << 12) : 0;
-
+ SetWindowWidgetDisabledState(w, 7, v->owner != _local_player);
+ SetWindowWidgetDisabledState(w, 8, v->owner != _local_player);
/* Disable refit button if vehicle not refittable */
- if (_engine_info[v->engine_type].refit_mask == 0) SETBIT(w->disabled_state, 12);
+ SetWindowWidgetDisabledState(w, 12, v->owner != _local_player ||
+ _engine_info[v->engine_type].refit_mask == 0);
/* draw widgets & caption */
SetDParam(0, v->string_id);
@@ -403,7 +405,7 @@ static void DrawNewRoadVehWindow(Window *w)
int sel;
int y;
- if (w->window_number == 0) w->disabled_state = 1 << 5;
+ SetWindowWidgetDisabledState(w, 5, w->window_number == 0);
count = 0;
for (e = ROAD_ENGINES_INDEX; e < ROAD_ENGINES_INDEX + NUM_ROAD_ENGINES; e++) {
@@ -541,3 +543,4 @@ void ShowBuildRoadVehWindow(TileIndex tile)
}
}
+
diff --git a/settings_gui.c b/settings_gui.c
index cbe3b5f79..f5d100b63 100644
--- a/settings_gui.c
+++ b/settings_gui.c
@@ -95,7 +95,9 @@ static void GameOptionsWndProc(Window *w, WindowEvent *e)
case WE_PAINT: {
int i;
StringID str = STR_02BE_DEFAULT;
- w->disabled_state = (_vehicle_design_names & 1) ? (++str, 0) : (1 << 21);
+
+ SetWindowWidgetDisabledState(w, 21, !(_vehicle_design_names & 1));
+ if (!IsWindowWidgetDisabled(w, 21)) str = STR_02BF_CUSTOM;
SetDParam(0, str);
SetDParam(1, _currency_specs[_opt_ptr->currency].name);
SetDParam(2, STR_UNITS_IMPERIAL + _opt_ptr->units);
@@ -381,17 +383,15 @@ static GameOptions _opt_mod_temp;
static void GameDifficultyWndProc(Window *w, WindowEvent *e)
{
switch (e->event) {
- case WE_CREATE: /* Setup disabled buttons when creating window */
- // disable all other difficulty buttons during gameplay except for 'custom'
- w->disabled_state = (_game_mode != GM_NORMAL) ? 0 : (1 << 3) | (1 << 4) | (1 << 5) | (1 << 6);
-
- if (_game_mode == GM_EDITOR) SETBIT(w->disabled_state, 7);
+ case WE_CREATE: // Setup disabled buttons when creating window
+ /* disable all other difficulty buttons during gameplay except for 'custom' */
+ SetWindowWidgetDisabledState(w, 3, _game_mode == GM_NORMAL);
+ SetWindowWidgetDisabledState(w, 4, _game_mode == GM_NORMAL);
+ SetWindowWidgetDisabledState(w, 5, _game_mode == GM_NORMAL);
+ SetWindowWidgetDisabledState(w, 6, _game_mode == GM_NORMAL);
+ SetWindowWidgetDisabledState(w, 7, _game_mode == GM_EDITOR || _networking); // highscore chart in multiplayer
+ SetWindowWidgetDisabledState(w, 10, _networking && !_network_server); // Save-button in multiplayer (and if client)
- if (_networking) {
- SETBIT(w->disabled_state, 7); // disable highscore chart in multiplayer
- if (!_network_server)
- SETBIT(w->disabled_state, 10); // Disable save-button in multiplayer (and if client)
- }
break;
case WE_PAINT: {
uint32 click_a, click_b, disabled;
@@ -1049,7 +1049,9 @@ void ShowNewgrf(void)
w->vscroll.cap = 12;
w->vscroll.count = count;
w->vscroll.pos = 0;
- w->disabled_state = (1 << 5) | (1 << 6) | (1 << 7);
+ DisableWindowWidget(w, 5); // Small up arrow
+ DisableWindowWidget(w, 6); // Small sown arrow
+ DisableWindowWidget(w, 7); // Set parameter button
}
/**
diff --git a/ship_gui.c b/ship_gui.c
index 7d8cfa868..9f6064317 100644
--- a/ship_gui.c
+++ b/ship_gui.c
@@ -85,9 +85,10 @@ static void ShipDetailsWndProc(Window *w, WindowEvent *e)
const Vehicle *v = GetVehicle(w->window_number);
StringID str;
- w->disabled_state = v->owner == _local_player ? 0 : (1 << 2);
+ SetWindowWidgetDisabledState(w, 2, v->owner != _local_player);
// disable service-scroller when interval is set to disabled
- if (!_patches.servint_ships) w->disabled_state |= (1 << 5) | (1 << 6);
+ SetWindowWidgetDisabledState(w, 5, !_patches.servint_ships);
+ SetWindowWidgetDisabledState(w, 6, !_patches.servint_ships);
SetDParam(0, v->string_id);
SetDParam(1, v->unitnumber);
@@ -251,7 +252,7 @@ static void NewShipWndProc(Window *w, WindowEvent *e)
int sel;
int y;
- if (w->window_number == 0) w->disabled_state = 1 << 5;
+ SetWindowWidgetDisabledState(w, 5, w->window_number == 0);
count = 0;
for (eid = SHIP_ENGINES_INDEX; eid < SHIP_ENGINES_INDEX + NUM_SHIP_ENGINES; eid++) {
@@ -374,16 +375,16 @@ static void ShipViewWndProc(Window *w, WindowEvent *e)
switch (e->event) {
case WE_PAINT: {
Vehicle *v = GetVehicle(w->window_number);
- uint32 disabled = 1<<8;
StringID str;
- // Possible to refit?
+ /* Possible to refit? */
if (ShipVehInfo(v->engine_type)->refittable && IsShipInDepotStopped(v)) {
- disabled = 0;
+ EnableWindowWidget(w, 7);
+ EnableWindowWidget(w, 8);
}
- if (v->owner != _local_player) disabled |= 1<<8 | 1<<7;
- w->disabled_state = disabled;
+ SetWindowWidgetDisabledState(w, 7, v->owner != _local_player);
+ SetWindowWidgetDisabledState(w, 8, v->owner != _local_player);
/* draw widgets & caption */
SetDParam(0, v->string_id);
diff --git a/smallmap_gui.c b/smallmap_gui.c
index 248b2c604..d08f772a1 100644
--- a/smallmap_gui.c
+++ b/smallmap_gui.c
@@ -1010,7 +1010,7 @@ static void ExtraViewPortWndProc(Window *w, WindowEvent *e)
{
switch (e->event) {
case WE_CREATE: /* Disable zoom in button */
- w->disabled_state = (1 << 5);
+ DisableWindowWidget(w, 5);
break;
case WE_PAINT:
diff --git a/station_gui.c b/station_gui.c
index 4c4dad665..c687e5b2e 100644
--- a/station_gui.c
+++ b/station_gui.c
@@ -541,13 +541,11 @@ static void DrawStationViewWindow(Window *w)
}
SetVScrollCount(w, num);
- w->disabled_state = st->owner == _local_player ? 0 : (1 << 9);
-
- if (!(st->facilities & FACIL_TRAIN)) SETBIT(w->disabled_state, 10);
- if (!(st->facilities & FACIL_TRUCK_STOP) &&
- !(st->facilities & FACIL_BUS_STOP)) SETBIT(w->disabled_state, 11);
- if (!(st->facilities & FACIL_AIRPORT)) SETBIT(w->disabled_state, 12);
- if (!(st->facilities & FACIL_DOCK)) SETBIT(w->disabled_state, 13);
+ SetWindowWidgetDisabledState(w, 9, st->owner != _local_player);
+ SetWindowWidgetDisabledState(w, 10, !(st->facilities & FACIL_TRAIN));
+ SetWindowWidgetDisabledState(w, 11, !(st->facilities & FACIL_TRUCK_STOP) && !(st->facilities & FACIL_BUS_STOP));
+ SetWindowWidgetDisabledState(w, 12, !(st->facilities & FACIL_AIRPORT));
+ SetWindowWidgetDisabledState(w, 13, !(st->facilities & FACIL_DOCK));
SetDParam(0, st->index);
SetDParam(1, st->facilities);
diff --git a/town_gui.c b/town_gui.c
index f83b1c077..a523b2b06 100644
--- a/town_gui.c
+++ b/town_gui.c
@@ -106,7 +106,7 @@ static void TownAuthorityWndProc(Window *w, WindowEvent *e)
if (WP(w,def_d).data_1 != -1 && !HASBIT(buttons, WP(w,def_d).data_1))
WP(w,def_d).data_1 = -1;
- w->disabled_state = (WP(w,def_d).data_1 == -1) ? (1 << 6) : 0;
+ SetWindowWidgetDisabledState(w, 6, WP(w, def_d).data_1 == -1);
{
int y;
@@ -234,7 +234,7 @@ static void TownViewWndProc(Window *w, WindowEvent *e)
switch (e->event) {
case WE_PAINT:
// disable renaming town in network games if you are not the server
- if (_networking && !_network_server) SETBIT(w->disabled_state, 8);
+ SetWindowWidgetDisabledState(w, 8, _networking && !_network_server);
SetDParam(0, t->index);
DrawWindowWidgets(w);
diff --git a/train_gui.c b/train_gui.c
index 9e5a6986f..98376a878 100644
--- a/train_gui.c
+++ b/train_gui.c
@@ -206,7 +206,7 @@ static void NewRailVehicleWndProc(Window *w, WindowEvent *e)
switch (e->event) {
case WE_PAINT:
- if (w->window_number == 0) SETBIT(w->disabled_state, 5);
+ SetWindowWidgetDisabledState(w, 5, w->window_number == 0);
{
int count = 0;
@@ -424,21 +424,23 @@ static void TrainViewWndProc(Window *w, WindowEvent *e)
case WE_PAINT: {
const Vehicle *v, *u;
StringID str;
+ bool is_localplayer;
v = GetVehicle(w->window_number);
- if (v->owner != _local_player) {
- w->disabled_state = 0x3380;
- } else {
- w->disabled_state = 0;
-
- SETBIT(w->disabled_state, 12);
+ is_localplayer = v->owner == _local_player;
+ SetWindowWidgetDisabledState(w, 7, !is_localplayer);
+ SetWindowWidgetDisabledState(w, 8, !is_localplayer);
+ SetWindowWidgetDisabledState(w, 9, !is_localplayer);
+ SetWindowWidgetDisabledState(w, 12, !is_localplayer);
+ SetWindowWidgetDisabledState(w, 13, !is_localplayer);
+ if (is_localplayer) {
/* See if any vehicle can be refitted */
for (u = v; u != NULL; u = u->next) {
if (EngInfo(u->engine_type)->refit_mask != 0 ||
(!(RailVehInfo(v->engine_type)->flags & RVI_WAGON) && v->cargo_cap != 0)) {
- CLRBIT(w->disabled_state, 12);
+ EnableWindowWidget(w, 12);
/* We have a refittable carriage, bail out */
break;
}
@@ -682,11 +684,12 @@ static void DrawTrainDetailsWindow(Window *w)
SetVScrollCount(w, num);
- w->disabled_state = 1 << (det_tab + 9);
- if (v->owner != _local_player) w->disabled_state |= (1 << 2);
+ DisableWindowWidget(w, det_tab + 9);
+ SetWindowWidgetDisabledState(w, 2, v->owner != _local_player);
- // disable service-scroller when interval is set to disabled
- if (!_patches.servint_trains) w->disabled_state |= (1 << 6) | (1 << 7);
+ /* disable service-scroller when interval is set to disabled */
+ SetWindowWidgetDisabledState(w, 6, !_patches.servint_trains);
+ SetWindowWidgetDisabledState(w, 7, !_patches.servint_trains);
SetDParam(0, v->string_id);
SetDParam(1, v->unitnumber);
@@ -801,11 +804,11 @@ do_change_service_int:
case 10: // Information
case 11: // Capacities
case 12: // Total cargo
- CLRBIT(w->disabled_state, 9);
- CLRBIT(w->disabled_state, 10);
- CLRBIT(w->disabled_state, 11);
- CLRBIT(w->disabled_state, 12);
- SETBIT(w->disabled_state, e->we.click.widget);
+ EnableWindowWidget(w, 9);
+ EnableWindowWidget(w, 10);
+ EnableWindowWidget(w, 11);
+ EnableWindowWidget(w, 12);
+ EnableWindowWidget(w, e->we.click.widget);
WP(w,traindetails_d).tab = e->we.click.widget - 9;
SetWindowDirty(w);
break;
diff --git a/vehicle_gui.c b/vehicle_gui.c
index 93bb054a6..9fab39658 100644
--- a/vehicle_gui.c
+++ b/vehicle_gui.c
@@ -1020,25 +1020,19 @@ static void ReplaceVehicleWndProc(Window *w, WindowEvent *e)
// or Both lists have the same vehicle selected
// or The selected replacement engine has a replacement (to prevent loops)
// or The right list (new replacement) has the existing replacement vehicle selected
- if (selected_id[0] == INVALID_ENGINE ||
+ SetWindowWidgetDisabledState(w, 4,
+ selected_id[0] == INVALID_ENGINE ||
selected_id[1] == INVALID_ENGINE ||
selected_id[0] == selected_id[1] ||
EngineReplacementForPlayer(p, selected_id[1]) != INVALID_ENGINE ||
- EngineReplacementForPlayer(p, selected_id[0]) == selected_id[1]) {
- SETBIT(w->disabled_state, 4);
- } else {
- CLRBIT(w->disabled_state, 4);
- }
+ EngineReplacementForPlayer(p, selected_id[0]) == selected_id[1]);
// Disable the "Stop Replacing" button if:
// The left list (existing vehicle) is empty
// or The selected vehicle has no replacement set up
- if (selected_id[0] == INVALID_ENGINE ||
- !EngineHasReplacementForPlayer(p, selected_id[0])) {
- SETBIT(w->disabled_state, 6);
- } else {
- CLRBIT(w->disabled_state, 6);
- }
+ SetWindowWidgetDisabledState(w, 6,
+ selected_id[0] == INVALID_ENGINE ||
+ !EngineHasReplacementForPlayer(p, selected_id[0]));
// now the actual drawing of the window itself takes place
SetDParam(0, _vehicle_type_names[WP(w, replaceveh_d).vehicletype - VEH_Train]);
@@ -1577,7 +1571,7 @@ static void DrawVehicleListWindow(Window *w)
DrawWindowWidgets(w);
- if (owner == _local_player && vl->l.list_length == 0) SETBIT(w->disabled_state, 9);
+ if (owner == _local_player && vl->l.list_length == 0) DisableWindowWidget(w, 9);
/* draw sorting criteria string */
DrawString(85, 15, _vehicle_sort_listing[vl->l.sort_type], 0x10);