src/station_gui.cpp
branchNewGRF_ports
changeset 10184 fcf5fb2548eb
parent 6877 889301acc299
child 10242 52b4a9006029
--- a/src/station_gui.cpp	Mon Apr 14 20:32:36 2008 +0000
+++ b/src/station_gui.cpp	Tue Apr 15 00:47:19 2008 +0000
@@ -8,7 +8,7 @@
 #include "gui.h"
 #include "window_gui.h"
 #include "textbuf_gui.h"
-#include "station.h"
+#include "station_base.h"
 #include "player_func.h"
 #include "economy_func.h"
 #include "town.h"
@@ -17,13 +17,14 @@
 #include "vehicle_gui.h"
 #include "cargotype.h"
 #include "station_gui.h"
-#include "station.h"
+#include "station_func.h"
 #include "strings_func.h"
 #include "core/alloc_func.hpp"
 #include "window_func.h"
 #include "viewport_func.h"
 #include "gfx_func.h"
 #include "widgets/dropdown_func.h"
+#include "newgrf_cargo.h"
 
 #include "table/strings.h"
 #include "table/sprites.h"
@@ -387,7 +388,7 @@
 
 				assert(st->xy != 0);
 
- 				/* Do not do the complex check HasStationInUse here, it may be even false
+				/* Do not do the complex check HasStationInUse here, it may be even false
 				 * when the order had been removed and the station list hasn't been removed yet */
 				assert(st->owner == owner || (st->owner == OWNER_NONE && !st->IsBuoy()));
 
@@ -682,19 +683,8 @@
 {   WIDGETS_END},
 };
 
-/**
- * Draws icons of wainting cargo in the StationView window
- *
- * @param i type of cargo
- * @param waiting number of wainting units
- * @param x x on-screen coordinate where to start with drawing icons
- * @param y y coordinate
- */
-static void DrawCargoIcons(CargoID i, uint waiting, int x, int y, uint width)
+SpriteID GetCargoSprite(CargoID i)
 {
-	uint num = min((waiting + 5) / 10, width / 10); // maximum is width / 10 icons so it won't overflow
-	if (num == 0) return;
-
 	const CargoSpec *cs = GetCargo(i);
 	SpriteID sprite;
 
@@ -707,12 +697,36 @@
 
 	if (sprite == 0) sprite = SPR_CARGO_GOODS;
 
+	return sprite;
+}
+
+/**
+ * Draws icons of waiting cargo in the StationView window
+ *
+ * @param i type of cargo
+ * @param waiting number of waiting units
+ * @param x x on-screen coordinate where to start with drawing icons
+ * @param y y coordinate
+ */
+static void DrawCargoIcons(CargoID i, uint waiting, int x, int y, uint width)
+{
+	uint num = min((waiting + 5) / 10, width / 10); // maximum is width / 10 icons so it won't overflow
+	if (num == 0) return;
+
+	SpriteID sprite = GetCargoSprite(i);
+
 	do {
 		DrawSprite(sprite, PAL_NONE, x, y);
 		x += 10;
 	} while (--num);
 }
 
+struct stationview_d {
+	uint32 cargo;                 ///< Bitmask of cargo types to expand
+	uint16 cargo_rows[NUM_CARGO]; ///< Header row for each cargo type
+};
+assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(stationview_d));
+
 struct CargoData {
 	CargoID cargo;
 	StationID source;
@@ -740,13 +754,19 @@
 	int pos;      ///< = w->vscroll.pos
 	StringID str;
 	CargoDataList cargolist;
+	uint32 transfers = 0;
 
 	/* count types of cargos waiting in station */
 	for (CargoID i = 0; i < NUM_CARGO; i++) {
-		if (!st->goods[i].cargo.Empty()) {
+		if (st->goods[i].cargo.Empty()) {
+			WP(w, stationview_d).cargo_rows[i] = 0;
+		} else {
 			/* Add an entry for total amount of cargo of this type waiting. */
 			cargolist.push_back(CargoData(i, INVALID_STATION, st->goods[i].cargo.Count()));
 
+			/* Set the row for this cargo entry for the expand/hide button */
+			WP(w, stationview_d).cargo_rows[i] = cargolist.size();
+
 			/* Add an entry for each distinct cargo source. */
 			const CargoList::List *packets = st->goods[i].cargo.Packets();
 			for (CargoList::List::const_iterator it = packets->begin(); it != packets->end(); it++) {
@@ -754,6 +774,12 @@
 				if (cp->source != station_id) {
 					bool added = false;
 
+					/* Enable the expand/hide button for this cargo type */
+					SetBit(transfers, i);
+
+					/* Don't add cargo lines if not expanded */
+					if (!HasBit(WP(w, stationview_d).cargo, i)) break;
+
 					/* Check if we already have this source in the list */
 					for (CargoDataList::iterator jt = cargolist.begin(); jt != cargolist.end(); jt++) {
 						CargoData *cd = &(*jt);
@@ -807,7 +833,14 @@
 				DrawCargoIcons(cd->cargo, cd->count, x, y, width);
 				SetDParam(0, cd->cargo);
 				SetDParam(1, cd->count);
-				DrawStringRightAligned(x + width, y, STR_0009, TC_FROMSTRING);
+				if (HasBit(transfers, cd->cargo)) {
+					/* This cargo has transfers waiting so show the expand or shrink 'button' */
+					const char *sym = HasBit(WP(w, stationview_d).cargo, cd->cargo) ? "-" : "+";
+					DrawStringRightAligned(x + width - 8, y, STR_0009, TC_FROMSTRING);
+					DoDrawString(sym, x + width - 6, y, TC_YELLOW);
+				} else {
+					DrawStringRightAligned(x + width, y, STR_0009, TC_FROMSTRING);
+				}
 			} else {
 				SetDParam(0, cd->cargo);
 				SetDParam(1, cd->count);
@@ -870,6 +903,19 @@
 	}
 }
 
+static void HandleCargoWaitingClick(Window *w, int row)
+{
+	if (row == 0) return;
+
+	for (CargoID c = 0; c < NUM_CARGO; c++) {
+		if (WP(w, stationview_d).cargo_rows[c] == row) {
+			ToggleBit(WP(w, stationview_d).cargo, c);
+			w->InvalidateWidget(SVW_WAITING);
+			break;
+		}
+	}
+}
+
 
 /**
  * Fuction called when any WindowEvent occurs for any StationView window
@@ -886,6 +932,10 @@
 
 		case WE_CLICK:
 			switch (e->we.click.widget) {
+				case SVW_WAITING:
+					HandleCargoWaitingClick(w, (e->we.click.pt.y - w->widget[SVW_WAITING].top) / 10 + w->vscroll.pos);
+					break;
+
 				case SVW_LOCATION:
 					ScrollMainWindowToTile(GetStation(w->window_number)->xy);
 					break;
@@ -953,7 +1003,7 @@
 
 		case WE_DESTROY: {
 			WindowNumber wno =
-				(w->window_number << 16) | GetStation(w->window_number)->owner;
+				(w->window_number << 16) | VLW_STATION_LIST | GetStation(w->window_number)->owner;
 
 			DeleteWindowById(WC_TRAINS_LIST, wno);
 			DeleteWindowById(WC_ROADVEH_LIST, wno);