diff options
author | peter1138 <peter1138@openttd.org> | 2008-03-27 15:51:11 +0000 |
---|---|---|
committer | peter1138 <peter1138@openttd.org> | 2008-03-27 15:51:11 +0000 |
commit | 9676d90a9571a73e9954f8df090c475bd478c0b0 (patch) | |
tree | 701c3fde3988936cb81aa2af9822a955b8db1941 | |
parent | ffe07b929283461b2bc3bf8bd92d2f4dba4fb985 (diff) | |
download | openttd-9676d90a9571a73e9954f8df090c475bd478c0b0.tar.xz |
(svn r12446) -Feature: Add +/- toggle buttons to station cargo waiting list to show/hide the detailed transferred cargo information.
-rw-r--r-- | src/station_gui.cpp | 46 |
1 files changed, 44 insertions, 2 deletions
diff --git a/src/station_gui.cpp b/src/station_gui.cpp index 5dad18a43..82fe883c9 100644 --- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -713,6 +713,12 @@ static void DrawCargoIcons(CargoID i, uint waiting, int x, int y, uint width) } 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 +746,19 @@ static void DrawStationViewWindow(Window *w) 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 +766,12 @@ static void DrawStationViewWindow(Window *w) 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 +825,14 @@ static void DrawStationViewWindow(Window *w) 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 +895,19 @@ static void DrawStationViewWindow(Window *w) } } +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 +924,10 @@ static void StationViewWndProc(Window *w, WindowEvent *e) 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; |