changeset 4702:dd2154e7bbb5 draft

(svn r6612) -Codechange: Use accessors for hidden_state. Another step toward merging XTDwidget. The only two files not converted (window.h and widget.c) will be done at the very last commit)
author belugas <belugas@openttd.org>
date Mon, 02 Oct 2006 00:28:31 +0000
parents 9bb6ea735208
children 1a50e6487f02
files aircraft_gui.c depot_gui.c graph_gui.c player_gui.c roadveh_gui.c ship_gui.c train_gui.c vehicle_gui.c
diffstat 8 files changed, 46 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/aircraft_gui.c
+++ b/aircraft_gui.c
@@ -552,10 +552,14 @@
 
 	case WE_MOUSELOOP: {
 		const Vehicle *v = GetVehicle(w->window_number);
-		uint32 h = IsAircraftInHangarStopped(v) ? 1 << 7 : 1 << 11;
+		bool plane_stopped = IsAircraftInHangarStopped(v);
 
-		if (h != w->hidden_state) {
-			w->hidden_state = h;
+		/* Widget 7 (send to hangar) must be hidden if the plane is already stopped in hangar.
+		 * Widget 11 (clone) should then be shown, since cloning is allowed only while in hangar and stopped.
+		 * This sytem allows to have two buttons, on top of each other*/
+		if (plane_stopped != IsWindowWidgetHidden(w, 7) || plane_stopped == IsWindowWidgetHidden(w, 11)) {
+			SetWindowWidgetHiddenState(w,  7, plane_stopped);  // send to hangar
+			SetWindowWidgetHiddenState(w, 11, !plane_stopped); // clone
 			SetWindowDirty(w);
 		}
 	} break;
--- a/depot_gui.c
+++ b/depot_gui.c
@@ -71,7 +71,7 @@
 
 /* Widget array for all depot windows.
  * If a widget is needed in some windows only (like train specific), add it for all windows
- * and use w->hidden_state in ShowDepotWindow() to remove it in the windows where it should not be
+ * and use HideWindowWidget in ShowDepotWindow() to remove it in the windows where it should not be
  * Keep the widget numbers in sync with the enum or really bad stuff will happen!!! */
 
 /* When adding widgets, place them as you would place them for the ship depot and define how you want it to move in widget_moves[]
@@ -968,8 +968,8 @@
 			+ (type == VEH_Train ? 1 : w->hscroll.cap); // number of boxes in each row. Trains always have just one
 
 		if (type != VEH_Train) {
-			SETBIT(w->hidden_state, DEPOT_WIDGET_H_SCROLL);
-			SETBIT(w->hidden_state, DEPOT_WIDGET_SELL_CHAIN);
+			HideWindowWidget(w, DEPOT_WIDGET_H_SCROLL);
+			HideWindowWidget(w, DEPOT_WIDGET_SELL_CHAIN);
 		}
 
 		/* Move the widgets to their right locations */
--- a/graph_gui.c
+++ b/graph_gui.c
@@ -1010,7 +1010,7 @@
 		case WE_CREATE: {
 			int i;
 			Player *p2;
-			w->hidden_state = 0;
+
 			w->disabled_state = 0;
 
 			// Hide the player who are not active
--- a/player_gui.c
+++ b/player_gui.c
@@ -654,7 +654,7 @@
 		if (!IsWindowOfPrototype(w, _other_player_company_widgets)) {
 			AssignWidgetToWindow(w, (p->location_of_house != 0) ? _my_player_company_bh_widgets : _my_player_company_widgets);
 
-			if (!_networking) SETBIT(w->hidden_state, 11); // hide company-password widget
+			SetWindowWidgetHiddenState(w, 11, !_networking); // Hide company-password widget
 		} else {
 			if (p->location_of_house == 0) SETBIT(dis, 7);
 
--- a/roadveh_gui.c
+++ b/roadveh_gui.c
@@ -337,13 +337,19 @@
 		DeleteWindowById(WC_VEHICLE_DETAILS, w->window_number);
 		break;
 
-	case WE_MOUSELOOP:
-		{
+	case WE_MOUSELOOP: {
 			const Vehicle *v = GetVehicle(w->window_number);
-			uint32 h = IsRoadVehInDepotStopped(v) ? 1 << 7 | 1 << 8 : 1 << 11 | 1 << 12;
+			bool rv_stopped = IsRoadVehInDepotStopped(v);
 
-			if (h != w->hidden_state) {
-				w->hidden_state = h;
+			/* Widget 7 (send to depot) must be hidden if the truck/bus is already stopped in depot.
+			 * Widget 11 (clone) should then be shown, since cloning is allowed only while in depot and stopped.
+			 * This sytem allows to have two buttons, on top of each other.
+			 * The same system applies to widget 8 and 12, force turn around and refit. */
+			if (rv_stopped != IsWindowWidgetHidden(w, 7) || rv_stopped == IsWindowWidgetHidden(w, 11)) {
+				SetWindowWidgetHiddenState(w,  7, rv_stopped);  // send to depot
+				SetWindowWidgetHiddenState(w,  8, rv_stopped);  // force turn around
+				SetWindowWidgetHiddenState(w, 11, !rv_stopped); // clone
+				SetWindowWidgetHiddenState(w, 12, !rv_stopped); // refit
 				SetWindowDirty(w);
 			}
 		}
--- a/ship_gui.c
+++ b/ship_gui.c
@@ -477,13 +477,16 @@
 			DeleteWindowById(WC_VEHICLE_DETAILS, w->window_number);
 			break;
 
-		case WE_MOUSELOOP:
-		{
+		case WE_MOUSELOOP: {
 			const Vehicle *v = GetVehicle(w->window_number);
-			uint32 h = IsShipInDepotStopped(v) ? 1 << 7 : 1 << 11;
+			bool ship_stopped = IsShipInDepotStopped(v);
 
-			if (h != w->hidden_state) {
-				w->hidden_state = h;
+			/* Widget 7 (send to depot) must be hidden if the ship is already stopped in depot.
+			 * Widget 11 (clone) should then be shown, since cloning is allowed only while in depot and stopped.
+			 * This sytem allows to have two buttons, on top of each otherother*/
+			if (ship_stopped != IsWindowWidgetHidden(w, 7) || ship_stopped == IsWindowWidgetHidden(w, 11)) {
+				SetWindowWidgetHiddenState(w,  7, ship_stopped);  // send to depot
+				SetWindowWidgetHiddenState(w, 11, !ship_stopped); // clone
 				SetWindowDirty(w);
 			}
 		}
--- a/train_gui.c
+++ b/train_gui.c
@@ -564,12 +564,17 @@
 
 	case WE_MOUSELOOP: {
 		const Vehicle *v = GetVehicle(w->window_number);
-		uint32 h;
+		bool train_stopped = CheckTrainStoppedInDepot(v)  >= 0;
 
-		assert(v->type == VEH_Train);
-		h = CheckTrainStoppedInDepot(v) >= 0 ? (1 << 9)| (1 << 7) : (1 << 12) | (1 << 13);
-		if (h != w->hidden_state) {
-			w->hidden_state = h;
+		/* Widget 7 (send to depot) must be hidden if the train is already stopped in hangar.
+		 * Widget 13 (clone) should then be shown, since cloning is allowed only while in depot and stopped.
+		 * This sytem allows to have two buttons, on top of each other.
+		 * The same system applies to widget 9 and 12, reverse direction and refit*/
+		if (train_stopped != IsWindowWidgetHidden(w, 7) || train_stopped == IsWindowWidgetHidden(w, 13)) {
+			SetWindowWidgetHiddenState(w,  7, train_stopped);  // send to depot
+			SetWindowWidgetHiddenState(w,  9, train_stopped);  // reverse direction
+			SetWindowWidgetHiddenState(w, 12, !train_stopped); // refit
+			SetWindowWidgetHiddenState(w, 13, !train_stopped); // clone
 			SetWindowDirty(w);
 		}
 		break;
--- a/vehicle_gui.c
+++ b/vehicle_gui.c
@@ -1393,12 +1393,12 @@
 	/* Hide the widgets that we will not use in this window
 	 * Some windows contains actions only fit for the owner */
 	if (player == _local_player) {
-		SETBIT(w->hidden_state, VLW_WIDGET_OTHER_PLAYER_FILLER);
+		HideWindowWidget(w, VLW_WIDGET_OTHER_PLAYER_FILLER);
 	} else {
-		SETBIT(w->hidden_state, VLW_WIDGET_SEND_TO_DEPOT);
-		SETBIT(w->hidden_state, VLW_WIDGET_AUTOREPLACE);
-		SETBIT(w->hidden_state, VLW_WIDGET_STOP_ALL);
-		SETBIT(w->hidden_state, VLW_WIDGET_START_ALL);
+		HideWindowWidget(w, VLW_WIDGET_SEND_TO_DEPOT);
+		HideWindowWidget(w, VLW_WIDGET_AUTOREPLACE);
+		HideWindowWidget(w, VLW_WIDGET_STOP_ALL);
+		HideWindowWidget(w, VLW_WIDGET_START_ALL);
 	}
 
 	/* Set up the window widgets */