equal
deleted
inserted
replaced
16 #include "command.h" |
16 #include "command.h" |
17 #include "variables.h" |
17 #include "variables.h" |
18 #include "vehicle_gui.h" |
18 #include "vehicle_gui.h" |
19 #include "date.h" |
19 #include "date.h" |
20 #include "vehicle.h" |
20 #include "vehicle.h" |
|
21 #include "helpers.hpp" |
21 |
22 |
22 enum StationListWidgets { |
23 enum StationListWidgets { |
23 STATIONLIST_WIDGET_CLOSEBOX = 0, |
24 STATIONLIST_WIDGET_CLOSEBOX = 0, |
24 STATIONLIST_WIDGET_LIST = 3, |
25 STATIONLIST_WIDGET_LIST = 3, |
25 STATIONLIST_WIDGET_TRAIN =6, |
26 STATIONLIST_WIDGET_TRAIN =6, |
154 SL_ORDER = 0x01, |
155 SL_ORDER = 0x01, |
155 SL_RESORT = 0x02, |
156 SL_RESORT = 0x02, |
156 SL_REBUILD = 0x04, |
157 SL_REBUILD = 0x04, |
157 } StationListFlags; |
158 } StationListFlags; |
158 |
159 |
|
160 DECLARE_ENUM_AS_BIT_SET(StationListFlags); |
|
161 |
159 typedef struct plstations_d { |
162 typedef struct plstations_d { |
160 const Station** sort_list; |
163 const Station** sort_list; |
161 uint16 list_length; |
164 uint16 list_length; |
162 byte sort_type; |
165 byte sort_type; |
163 StationListFlags flags; |
166 StationListFlags flags; |
199 const Station *st; |
202 const Station *st; |
200 |
203 |
201 if (!(sl->flags & SL_REBUILD)) return; |
204 if (!(sl->flags & SL_REBUILD)) return; |
202 |
205 |
203 /* Create array for sorting */ |
206 /* Create array for sorting */ |
204 station_sort = malloc((GetMaxStationIndex() + 1) * sizeof(station_sort[0])); |
207 MallocT(&station_sort, GetMaxStationIndex() + 1); |
205 if (station_sort == NULL) error("Could not allocate memory for the station-sorting-list"); |
208 if (station_sort == NULL) error("Could not allocate memory for the station-sorting-list"); |
206 |
209 |
207 DEBUG(misc, 3, "Building station list for player %d", owner); |
210 DEBUG(misc, 3, "Building station list for player %d", owner); |
208 |
211 |
209 FOR_ALL_STATIONS(st) { |
212 FOR_ALL_STATIONS(st) { |
226 } |
229 } |
227 } |
230 } |
228 } |
231 } |
229 |
232 |
230 free((void*)sl->sort_list); |
233 free((void*)sl->sort_list); |
231 sl->sort_list = malloc(n * sizeof(sl->sort_list[0])); |
234 MallocT(&sl->sort_list, n); |
232 if (n != 0 && sl->sort_list == NULL) error("Could not allocate memory for the station-sorting-list"); |
235 if (n != 0 && sl->sort_list == NULL) error("Could not allocate memory for the station-sorting-list"); |
233 sl->list_length = n; |
236 sl->list_length = n; |
234 |
237 |
235 for (i = 0; i < n; ++i) sl->sort_list[i] = station_sort[i]; |
238 for (i = 0; i < n; ++i) sl->sort_list[i] = station_sort[i]; |
236 |
239 |
258 sl->flags &= ~SL_RESORT; |
261 sl->flags &= ~SL_RESORT; |
259 } |
262 } |
260 |
263 |
261 static void PlayerStationsWndProc(Window *w, WindowEvent *e) |
264 static void PlayerStationsWndProc(Window *w, WindowEvent *e) |
262 { |
265 { |
263 const PlayerID owner = w->window_number; |
266 const PlayerID owner = (PlayerID)w->window_number; |
264 static byte facilities = FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK; |
267 static byte facilities = FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK; |
265 static uint16 cargo_filter = CARGO_ALL_SELECTED; |
268 static uint16 cargo_filter = CARGO_ALL_SELECTED; |
266 plstations_d *sl = &WP(w, plstations_d); |
269 plstations_d *sl = &WP(w, plstations_d); |
267 |
270 |
268 switch (e->event) { |
271 switch (e->event) { |
430 sl->flags |= SL_REBUILD; |
433 sl->flags |= SL_REBUILD; |
431 SetWindowDirty(w); |
434 SetWindowDirty(w); |
432 break; |
435 break; |
433 } |
436 } |
434 case STATIONLIST_WIDGET_SORTBY: /*flip sorting method asc/desc*/ |
437 case STATIONLIST_WIDGET_SORTBY: /*flip sorting method asc/desc*/ |
435 TOGGLEBIT(sl->flags, 0); //DESC-flag |
438 sl->flags ^= SL_ORDER; //DESC-flag |
436 sl->flags |= SL_RESORT; |
439 sl->flags |= SL_RESORT; |
437 w->flags4 |= 5 << WF_TIMEOUT_SHL; |
440 w->flags4 |= 5 << WF_TIMEOUT_SHL; |
438 LowerWindowWidget(w, STATIONLIST_WIDGET_SORTBY); |
441 LowerWindowWidget(w, STATIONLIST_WIDGET_SORTBY); |
439 SetWindowDirty(w); |
442 SetWindowDirty(w); |
440 break; |
443 break; |
475 |
478 |
476 case WE_TICK: |
479 case WE_TICK: |
477 if (--sl->resort_timer == 0) { |
480 if (--sl->resort_timer == 0) { |
478 DEBUG(misc, 3, "Periodic rebuild station list player %d", owner); |
481 DEBUG(misc, 3, "Periodic rebuild station list player %d", owner); |
479 sl->resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS; |
482 sl->resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS; |
480 sl->flags |= VL_REBUILD; |
483 sl->flags |= SL_REBUILD; |
481 SetWindowDirty(w); |
484 SetWindowDirty(w); |
482 } |
485 } |
483 break; |
486 break; |
484 |
487 |
485 case WE_TIMEOUT: |
488 case WE_TIMEOUT: |