src/order_gui.cpp
branchnoai
changeset 9723 eee46cb39750
parent 9722 ebf0ece7d8f6
child 9724 b39bc69bb2f2
--- a/src/order_gui.cpp	Fri Nov 23 16:59:30 2007 +0000
+++ b/src/order_gui.cpp	Wed Jan 09 18:11:12 2008 +0000
@@ -8,18 +8,13 @@
 #include "station_map.h"
 #include "table/sprites.h"
 #include "table/strings.h"
-#include "strings.h"
-#include "functions.h"
-#include "map.h"
-#include "tile.h"
-#include "window.h"
 #include "gui.h"
-#include "gfx.h"
-#include "vehicle.h"
+#include "window_gui.h"
 #include "station.h"
 #include "town.h"
-#include "command.h"
-#include "viewport.h"
+#include "command_func.h"
+#include "viewport_func.h"
+#include "gfx_func.h"
 #include "depot.h"
 #include "waypoint.h"
 #include "train.h"
@@ -27,6 +22,11 @@
 #include "vehicle_gui.h"
 #include "timetable.h"
 #include "cargotype.h"
+#include "order.h"
+#include "strings_func.h"
+#include "window_func.h"
+#include "vehicle_func.h"
+#include "settings_type.h"
 
 enum OrderWindowWidgets {
 	ORDER_WIDGET_CLOSEBOX = 0,
@@ -57,7 +57,7 @@
 static int OrderGetSel(const Window *w)
 {
 	const Vehicle *v = GetVehicle(w->window_number);
-	int num = WP(w,order_d).sel;
+	int num = WP(w, order_d).sel;
 
 	return (num >= 0 && num < v->num_orders) ? num : v->num_orders;
 }
@@ -129,50 +129,52 @@
 
 	if (v->owner == _local_player) {
 		/* skip */
-		SetWindowWidgetDisabledState(w, ORDER_WIDGET_SKIP, v->num_orders <= 1);
+		w->SetWidgetDisabledState(ORDER_WIDGET_SKIP, v->num_orders <= 1);
 
 		/* delete */
-		SetWindowWidgetDisabledState(w, ORDER_WIDGET_DELETE,
+		w->SetWidgetDisabledState(ORDER_WIDGET_DELETE,
 				(uint)v->num_orders + ((shared_orders || v->num_orders != 0) ? 1 : 0) <= (uint)WP(w, order_d).sel);
 
 		/* non-stop only for trains */
-		SetWindowWidgetDisabledState(w, ORDER_WIDGET_NON_STOP,  v->type != VEH_TRAIN || order == NULL);
-		SetWindowWidgetDisabledState(w, ORDER_WIDGET_FULL_LOAD, order == NULL); // full load
-		SetWindowWidgetDisabledState(w, ORDER_WIDGET_UNLOAD,    order == NULL); // unload
-		SetWindowWidgetDisabledState(w, ORDER_WIDGET_TRANSFER,  order == NULL); // transfer
+		w->SetWidgetDisabledState(ORDER_WIDGET_NON_STOP,  v->type != VEH_TRAIN || order == NULL);
+		w->SetWidgetDisabledState(ORDER_WIDGET_FULL_LOAD, order == NULL); // full load
+		w->SetWidgetDisabledState(ORDER_WIDGET_UNLOAD,    order == NULL); // unload
+		w->SetWidgetDisabledState(ORDER_WIDGET_TRANSFER,  order == NULL); // transfer
 		/* Disable list of vehicles with the same shared orders if there is no list */
-		SetWindowWidgetDisabledState(w, ORDER_WIDGET_SHARED_ORDER_LIST, !shared_orders || v->orders == NULL);
-		SetWindowWidgetDisabledState(w, ORDER_WIDGET_REFIT,     order == NULL); // Refit
-		HideWindowWidget(w, ORDER_WIDGET_REFIT); // Refit
+		w->SetWidgetDisabledState(ORDER_WIDGET_SHARED_ORDER_LIST, !shared_orders || v->orders == NULL);
+		w->SetWidgetDisabledState(ORDER_WIDGET_REFIT,     order == NULL); // Refit
+		w->HideWidget(ORDER_WIDGET_REFIT); // Refit
 	} else {
-		DisableWindowWidget(w, ORDER_WIDGET_TRANSFER);
+		w->DisableWidget(ORDER_WIDGET_TRANSFER);
 	}
 
-	ShowWindowWidget(w, ORDER_WIDGET_UNLOAD); // Unload
+	w->ShowWidget(ORDER_WIDGET_UNLOAD); // Unload
 
 	if (order != NULL) {
 		switch (order->type) {
-			case OT_GOTO_STATION: break;
+			case OT_GOTO_STATION:
+				if (!GetStation(order->dest)->IsBuoy()) break;
+				/* Fall-through */
+
+			case OT_GOTO_WAYPOINT:
+				w->DisableWidget(ORDER_WIDGET_FULL_LOAD);
+				w->DisableWidget(ORDER_WIDGET_UNLOAD);
+				w->DisableWidget(ORDER_WIDGET_TRANSFER);
+				break;
 
 			case OT_GOTO_DEPOT:
-				DisableWindowWidget(w, ORDER_WIDGET_TRANSFER);
+				w->DisableWidget(ORDER_WIDGET_TRANSFER);
 
 				/* Remove unload and replace it with refit */
-				HideWindowWidget(w, ORDER_WIDGET_UNLOAD);
-				ShowWindowWidget(w, ORDER_WIDGET_REFIT);
+				w->HideWidget(ORDER_WIDGET_UNLOAD);
+				w->ShowWidget(ORDER_WIDGET_REFIT);
 				SetDParam(2,STR_SERVICE);
 				break;
 
-			case OT_GOTO_WAYPOINT:
-				DisableWindowWidget(w, ORDER_WIDGET_FULL_LOAD);
-				DisableWindowWidget(w, ORDER_WIDGET_UNLOAD);
-				DisableWindowWidget(w, ORDER_WIDGET_TRANSFER);
-				break;
-
 			default: // every other orders
-				DisableWindowWidget(w, ORDER_WIDGET_NON_STOP);
-				DisableWindowWidget(w, ORDER_WIDGET_FULL_LOAD);
-				DisableWindowWidget(w, ORDER_WIDGET_UNLOAD);
+				w->DisableWidget(ORDER_WIDGET_NON_STOP);
+				w->DisableWidget(ORDER_WIDGET_FULL_LOAD);
+				w->DisableWidget(ORDER_WIDGET_UNLOAD);
 		}
 	}
 
@@ -239,7 +241,7 @@
 			}
 
 			SetDParam(0, i + 1);
-			DrawString(2, y, str, (i == WP(w,order_d).sel) ? TC_WHITE : TC_BLACK);
+			DrawString(2, y, str, (i == WP(w, order_d).sel) ? TC_WHITE : TC_BLACK);
 
 			y += 10;
 		}
@@ -250,7 +252,7 @@
 
 	if (i - w->vscroll.pos < w->vscroll.cap) {
 		str = shared_orders ? STR_END_OF_SHARED_ORDERS : STR_882A_END_OF_ORDERS;
-		DrawString(2, y, str, (i == WP(w,order_d).sel) ? TC_WHITE : TC_BLACK);
+		DrawString(2, y, str, (i == WP(w, order_d).sel) ? TC_WHITE : TC_BLACK);
 	}
 }
 
@@ -362,9 +364,9 @@
 	// obviously if you press CTRL on a non-empty orders vehicle you know what you are doing
 	if (v->num_orders != 0 && _ctrl_pressed == 0) return false;
 
-	if (DoCommandP(v->tile, v->index | (u->index << 16), _ctrl_pressed ? 0 : 1, NULL,
+	if (DoCommandP(v->tile, v->index | (u->index << 16), _ctrl_pressed ? CO_SHARE : CO_COPY, NULL,
 		_ctrl_pressed ? CMD_CLONE_ORDER | CMD_MSG(STR_CANT_SHARE_ORDER_LIST) : CMD_CLONE_ORDER | CMD_MSG(STR_CANT_COPY_ORDER_LIST))) {
-		WP(w,order_d).sel = -1;
+		WP(w, order_d).sel = -1;
 		ResetObjectToPlace();
 	}
 
@@ -384,7 +386,7 @@
 	if (!cmd.IsValid()) return;
 
 	if (DoCommandP(v->tile, v->index + (OrderGetSel(w) << 16), PackOrder(&cmd), NULL, CMD_INSERT_ORDER | CMD_MSG(STR_8833_CAN_T_INSERT_NEW_ORDER))) {
-		if (WP(w,order_d).sel != -1) WP(w,order_d).sel++;
+		if (WP(w, order_d).sel != -1) WP(w,order_d).sel++;
 		ResetObjectToPlace();
 	}
 }
@@ -397,9 +399,9 @@
  */
 static void OrderClick_Goto(Window *w, const Vehicle *v)
 {
-	InvalidateWidget(w, ORDER_WIDGET_GOTO);
-	ToggleWidgetLoweredState(w, ORDER_WIDGET_GOTO);
-	if (IsWindowWidgetLowered(w, ORDER_WIDGET_GOTO)) {
+	w->InvalidateWidget(ORDER_WIDGET_GOTO);
+	w->ToggleWidgetLoweredState(ORDER_WIDGET_GOTO);
+	if (w->IsWidgetLowered(ORDER_WIDGET_GOTO)) {
 		_place_clicked_vehicle = NULL;
 		SetObjectToPlaceWnd(ANIMCURSOR_PICKSTATION, PAL_NONE, VHM_RECT, w);
 	} else {
@@ -491,9 +493,9 @@
 {
 	if (_ctrl_pressed) {
 		/* Cancel refitting */
-		DoCommandP(v->tile, v->index, (WP(w,order_d).sel << 16) | (CT_NO_REFIT << 8) | CT_NO_REFIT, NULL, CMD_ORDER_REFIT);
+		DoCommandP(v->tile, v->index, (WP(w, order_d).sel << 16) | (CT_NO_REFIT << 8) | CT_NO_REFIT, NULL, CMD_ORDER_REFIT);
 	} else {
-		ShowVehicleRefitWindow(v, WP(w,order_d).sel);
+		ShowVehicleRefitWindow(v, WP(w, order_d).sel);
 	}
 }
 
@@ -543,7 +545,7 @@
 			if (_patches.timetabling) {
 				w->widget[ORDER_WIDGET_CAPTION].right -= 61;
 			} else {
-				HideWindowWidget(w, ORDER_WIDGET_TIMETABLE_VIEW);
+				w->HideWidget(ORDER_WIDGET_TIMETABLE_VIEW);
 			}
 
 			break;
@@ -563,7 +565,7 @@
 			if (sel == INVALID_ORDER) {
 				/* This was a click on an empty part of the orders window, so
 				 * deselect the currently selected order. */
-				WP(w,order_d).sel = -1;
+				WP(w, order_d).sel = -1;
 				SetWindowDirty(w);
 				return;
 			}
@@ -582,12 +584,12 @@
 				if (xy != 0) ScrollMainWindowToTile(xy);
 				return;
 			} else {
-				if (sel == WP(w,order_d).sel) {
+				if (sel == WP(w, order_d).sel) {
 					/* Deselect clicked order */
-					WP(w,order_d).sel = -1;
+					WP(w, order_d).sel = -1;
 				} else {
 					/* Select clicked order */
-					WP(w,order_d).sel = sel;
+					WP(w, order_d).sel = sel;
 
 					if (v->owner == _local_player) {
 						/* Activate drag and drop */
@@ -675,7 +677,7 @@
 			if (e->we.keypress.keycode == _order_keycodes[i]) {
 				e->we.keypress.cont = false;
 				//see if the button is disabled
-				if (!IsWindowWidgetDisabled(w, i + ORDER_WIDGET_SKIP)) _order_button_proc[i](w, v);
+				if (!w->IsWidgetDisabled(i + ORDER_WIDGET_SKIP)) _order_button_proc[i](w, v);
 				break;
 			}
 		}
@@ -699,8 +701,8 @@
 	} break;
 
 	case WE_ABORT_PLACE_OBJ: {
-		RaiseWindowWidget(w, ORDER_WIDGET_GOTO);
-		InvalidateWidget( w, ORDER_WIDGET_GOTO);
+		w->RaiseWidget(ORDER_WIDGET_GOTO);
+		w->InvalidateWidget(ORDER_WIDGET_GOTO);
 	} break;
 
 	// check if a vehicle in a depot was clicked..
@@ -714,7 +716,7 @@
 		 * the order is copied to the last open window instead of the
 		 * one where GOTO is enabled
 		 */
-		if (v != NULL && IsWindowWidgetLowered(w, ORDER_WIDGET_GOTO)) {
+		if (v != NULL && w->IsWidgetLowered(ORDER_WIDGET_GOTO)) {
 			_place_clicked_vehicle = NULL;
 			HandleOrderVehClick(GetVehicle(w->window_number), v, w);
 		}
@@ -729,9 +731,9 @@
 		// unclick all buttons except for the 'goto' button (ORDER_WIDGET_GOTO), which is 'persistent'
 		uint i;
 		for (i = 0; i < w->widget_count; i++) {
-			if (IsWindowWidgetLowered(w, i) && i != ORDER_WIDGET_GOTO) {
-				RaiseWindowWidget(w, i);
-				InvalidateWidget(w, i);
+			if (w->IsWidgetLowered(i) && i != ORDER_WIDGET_GOTO) {
+				w->RaiseWidget(i);
+				w->InvalidateWidget(i);
 			}
 		}
 	} break;
@@ -867,6 +869,6 @@
 		w->caption_color = v->owner;
 		w->vscroll.cap = 6;
 		w->resize.step_height = 10;
-		WP(w,order_d).sel = -1;
+		WP(w, order_d).sel = -1;
 	}
 }