summaryrefslogtreecommitdiff
path: root/aircraft_gui.c
diff options
context:
space:
mode:
authorbjarni <bjarni@openttd.org>2006-08-29 17:41:13 +0000
committerbjarni <bjarni@openttd.org>2006-08-29 17:41:13 +0000
commitecf8edf033e9cc2abab0fd3e7e5ee25a62a045a4 (patch)
tree6bd7b8dec4df9ca775c81f928c7666eaeb156301 /aircraft_gui.c
parenta9501bef85b0af20b5026eea32b8b79fdf4fab8c (diff)
downloadopenttd-ecf8edf033e9cc2abab0fd3e7e5ee25a62a045a4.tar.xz
(svn r6215) -Codechange: [vehicle list windows] unified Player(vehicle)WndProc into PlayerVehWndProc
Those 4 unified functions were really much alike, so there was no reason to have so much dublicated code
Diffstat (limited to 'aircraft_gui.c')
-rw-r--r--aircraft_gui.c197
1 files changed, 13 insertions, 184 deletions
diff --git a/aircraft_gui.c b/aircraft_gui.c
index df16249ce..245bb4eb0 100644
--- a/aircraft_gui.c
+++ b/aircraft_gui.c
@@ -81,7 +81,7 @@ void DrawAircraftPurchaseInfo(int x, int y, EngineID engine_number)
y += ShowAdditionalText(x, y, 227, engine_number);
}
-static void DrawAircraftImage(const Vehicle *v, int x, int y, VehicleID selection)
+void DrawAircraftImage(const Vehicle *v, int x, int y, VehicleID selection)
{
PalSpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);
DrawSprite(GetAircraftImage(v, DIR_W) | pal, x + 25, y + 10);
@@ -243,7 +243,7 @@ static const WindowDesc _new_aircraft_desc = {
NewAircraftWndProc
};
-static void ShowBuildAircraftWindow(TileIndex tile)
+void ShowBuildAircraftWindow(TileIndex tile)
{
Window *w;
@@ -953,7 +953,7 @@ void ShowAircraftDepotWindow(TileIndex tile)
}
}
-static void DrawSmallOrderList(const Vehicle *v, int x, int y)
+void DrawSmallOrderListAircraft(const Vehicle *v, int x, int y)
{
const Order *order;
int sel, i = 0;
@@ -975,7 +975,7 @@ static void DrawSmallOrderList(const Vehicle *v, int x, int y)
}
-static const Widget _player_aircraft_widgets[] = {
+const Widget _player_aircraft_widgets[] = {
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW },
{ WWT_CAPTION, RESIZE_RIGHT, 14, 11, 247, 0, 13, STR_A009_AIRCRAFT, STR_018C_WINDOW_TITLE_DRAG_THIS },
{ WWT_STICKYBOX, RESIZE_LR, 14, 248, 259, 0, 13, 0x0, STR_STICKY_BUTTON },
@@ -1007,187 +1007,12 @@ static const Widget _other_player_aircraft_widgets[] = {
{ WIDGETS_END},
};
-static void PlayerAircraftWndProc(Window *w, WindowEvent *e)
-{
- OrderID order = INVALID_ORDER;
- StationID station = INVALID_STATION;
- PlayerID owner = GB(w->window_number, 0, 8);
- vehiclelist_d *vl = &WP(w, vehiclelist_d);
-
- if (w->window_number & SHARE_FLAG) {
- order = GB(w->window_number, 16, 16);
- } else {
- station = GB(w->window_number, 16, 16);
- }
-
- switch (e->event) {
- case WE_PAINT: {
- int x = 2;
- int y = PLY_WND_PRC__OFFSET_TOP_WIDGET;
- int max;
- int i;
-
- BuildVehicleList(vl, VEH_Aircraft, owner, station, order);
- SortVehicleList(vl);
- SetVScrollCount(w, vl->list_length);
-
- // disable 'Sort By' tooltip on Unsorted sorting criteria
- if (vl->sort_type == SORT_BY_UNSORTED) w->disabled_state |= (1 << 3);
-
- /* draw the widgets */
- {
- const Player *p = GetPlayer(owner);
- if (order != INVALID_ORDER) {
- /* Shared Orders -- (###) Aircraft */
- SetDParam(0, w->vscroll.count);
- w->widget[1].unkA = STR_VEH_WITH_SHARED_ORDERS_LIST;
- w->widget[9].unkA = STR_EMPTY;
- w->widget[10].unkA = STR_EMPTY;
- SETBIT(w->disabled_state, 9);
- SETBIT(w->disabled_state, 10);
- } else if (station == INVALID_STATION) {
- /* Company Name -- (###) Aircraft */
- SetDParam(0, p->name_1);
- SetDParam(1, p->name_2);
- SetDParam(2, w->vscroll.count);
- w->widget[1].unkA = STR_A009_AIRCRAFT;
- } else {
- /* Station Name -- (###) Aircraft */
- SetDParam(0, station);
- SetDParam(1, w->vscroll.count);
- w->widget[1].unkA = STR_SCHEDULED_AIRCRAFT;
- }
- DrawWindowWidgets(w);
- }
- /* draw sorting criteria string */
- DrawString(85, 15, _vehicle_sort_listing[vl->sort_type], 0x10);
- /* draw arrow pointing up/down for ascending/descending sorting */
- DoDrawString(vl->flags & VL_DESC ? DOWNARROW : UPARROW, 69, 15, 0x10);
-
- max = min(w->vscroll.pos + w->vscroll.cap, vl->list_length);
- for (i = w->vscroll.pos; i < max; ++i) {
- const Vehicle* v = vl->sort_list[i];
- StringID str;
-
- assert(v->type == VEH_Aircraft && v->subtype <= 2);
-
- DrawAircraftImage(v, x + 19, y + 6, INVALID_VEHICLE);
- DrawVehicleProfitButton(v, x, y + 13);
-
- SetDParam(0, v->unitnumber);
- if (IsAircraftInHangar(v)) {
- str = STR_021F;
- } else {
- str = v->age > v->max_age - 366 ? STR_00E3 : STR_00E2;
- }
- DrawString(x, y + 2, str, 0);
-
- SetDParam(0, v->profit_this_year);
- SetDParam(1, v->profit_last_year);
- DrawString(x + 19, y + 28, STR_0198_PROFIT_THIS_YEAR_LAST_YEAR, 0);
-
- if (v->string_id != STR_SV_AIRCRAFT_NAME) {
- SetDParam(0, v->string_id);
- DrawString(x + 19, y, STR_01AB, 0);
- }
-
- DrawSmallOrderList(v, x + 136, y);
-
- y += PLY_WND_PRC__SIZE_OF_ROW_BIG;
- }
- } break;
-
- case WE_CLICK: {
- switch (e->click.widget) {
- case 3: /* Flip sorting method ascending/descending */
- vl->flags ^= VL_DESC;
- vl->flags |= VL_RESORT;
- _sorting.aircraft.order = !!(vl->flags & VL_DESC);
- SetWindowDirty(w);
- break;
-
- case 4: case 5:/* Select sorting criteria dropdown menu */
- ShowDropDownMenu(w, _vehicle_sort_listing, vl->sort_type, 5, 0, 0);
- return;
-
- case 7: { /* Matrix to show vehicles */
- uint32 id_v = (e->click.pt.y - PLY_WND_PRC__OFFSET_TOP_WIDGET) / PLY_WND_PRC__SIZE_OF_ROW_BIG;
- const Vehicle *v;
-
- if (id_v >= w->vscroll.cap) return; // click out of bounds
-
- id_v += w->vscroll.pos;
-
- if (id_v >= vl->list_length) return; // click out of list bound
-
- v = vl->sort_list[id_v];
-
- assert(v->type == VEH_Aircraft && v->subtype <= 2);
-
- ShowAircraftViewWindow(v);
- } break;
-
- case 9: /* Build new Vehicle */
- if (!IsWindowOfPrototype(w, _player_aircraft_widgets)) break;
- ShowBuildAircraftWindow(0);
- break;
-
- case 10:
- if (!IsWindowOfPrototype(w, _player_aircraft_widgets)) break;
- ShowReplaceVehicleWindow(VEH_Aircraft);
- break;
-
- }
- } break;
-
- case WE_DROPDOWN_SELECT: /* we have selected a dropdown item in the list */
- if (vl->sort_type != e->dropdown.index) {
- // value has changed -> resort
- vl->flags |= VL_RESORT;
- vl->sort_type = e->dropdown.index;
- _sorting.aircraft.criteria = vl->sort_type;
-
- // enable 'Sort By' if a sorter criteria is chosen
- if (vl->sort_type != SORT_BY_UNSORTED) CLRBIT(w->disabled_state, 3);
- }
- SetWindowDirty(w);
- break;
-
- case WE_CREATE: /* set up resort timer */
- vl->sort_list = NULL;
- vl->flags = VL_REBUILD | (_sorting.aircraft.order << (VL_DESC - 1));
- vl->sort_type = _sorting.aircraft.criteria;
- vl->resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS;
- break;
-
- case WE_DESTROY:
- free((void*)vl->sort_list);
- break;
-
- case WE_TICK: /* resort the list every 20 seconds orso (10 days) */
- if (--vl->resort_timer == 0) {
- DEBUG(misc, 1) ("Periodic resort aircraft list player %d station %d",
- owner, station);
- vl->resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS;
- vl->flags |= VL_RESORT;
- SetWindowDirty(w);
- }
- break;
-
- case WE_RESIZE:
- /* Update the scroll + matrix */
- w->vscroll.cap += e->sizing.diff.y / PLY_WND_PRC__SIZE_OF_ROW_BIG;
- w->widget[7].unkA = (w->vscroll.cap << 8) + 1;
- break;
- }
-}
-
static const WindowDesc _player_aircraft_desc = {
-1, -1, 260, 182,
WC_AIRCRAFT_LIST,0,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
_player_aircraft_widgets,
- PlayerAircraftWndProc
+ PlayerVehWndProc
};
static const WindowDesc _other_player_aircraft_desc = {
@@ -1195,7 +1020,7 @@ static const WindowDesc _other_player_aircraft_desc = {
WC_AIRCRAFT_LIST,0,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
_other_player_aircraft_widgets,
- PlayerAircraftWndProc
+ PlayerVehWndProc
};
void ShowPlayerAircraftLocal(PlayerID player, StationID station, OrderID order, bool show_shared)
@@ -1203,16 +1028,20 @@ void ShowPlayerAircraftLocal(PlayerID player, StationID station, OrderID order,
Window *w;
if (show_shared) {
- w = AllocateWindowDescFront(&_player_aircraft_desc, (order << 16) | SHARE_FLAG);
+ w = AllocateWindowDescFront(&_player_aircraft_desc, (order << 16) | (VEH_Aircraft << 11) | SHARE_FLAG);
} else {
if (player == _local_player) {
- w = AllocateWindowDescFront(&_player_aircraft_desc, (station << 16) | player);
+ w = AllocateWindowDescFront(&_player_aircraft_desc, (station << 16) | (VEH_Aircraft << 11) | player);
} else {
- w = AllocateWindowDescFront(&_other_player_aircraft_desc, (station << 16) | player);
+ w = AllocateWindowDescFront(&_other_player_aircraft_desc, (station << 16) | (VEH_Aircraft << 11) | player);
}
}
if (w != NULL) {
+ vehiclelist_d *vl = &WP(w, vehiclelist_d);
+ vl->flags = VL_REBUILD | (_sorting.aircraft.order << (VL_DESC - 1));
+ vl->sort_type = _sorting.aircraft.criteria;
+
w->caption_color = player;
w->vscroll.cap = 4;
w->widget[7].unkA = (w->vscroll.cap << 8) + 1;