(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
This commit is contained in:
190
roadveh_gui.c
190
roadveh_gui.c
@@ -69,7 +69,7 @@ void DrawRoadVehPurchaseInfo(int x, int y, EngineID engine_number)
|
||||
y += ShowAdditionalText(x, y, 227, engine_number);
|
||||
}
|
||||
|
||||
static void DrawRoadVehImage(const Vehicle *v, int x, int y, VehicleID selection)
|
||||
void DrawRoadVehImage(const Vehicle *v, int x, int y, VehicleID selection)
|
||||
{
|
||||
PalSpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);
|
||||
DrawSprite(GetRoadVehImage(v, DIR_W) | pal, x + 14, y + 6);
|
||||
@@ -602,7 +602,7 @@ static const WindowDesc _new_road_veh_desc = {
|
||||
NewRoadVehWndProc
|
||||
};
|
||||
|
||||
static void ShowBuildRoadVehWindow(TileIndex tile)
|
||||
void ShowBuildRoadVehWindow(TileIndex tile)
|
||||
{
|
||||
Window *w;
|
||||
|
||||
@@ -912,7 +912,7 @@ void ShowRoadDepotWindow(TileIndex tile)
|
||||
}
|
||||
}
|
||||
|
||||
static const Widget _player_roadveh_widgets[] = {
|
||||
const Widget _player_roadveh_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_9001_ROAD_VEHICLES, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
||||
{ WWT_STICKYBOX, RESIZE_LR, 14, 248, 259, 0, 13, 0x0, STR_STICKY_BUTTON},
|
||||
@@ -945,182 +945,12 @@ static const Widget _other_player_roadveh_widgets[] = {
|
||||
{ WIDGETS_END},
|
||||
};
|
||||
|
||||
static void PlayerRoadVehWndProc(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_Road, 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 */
|
||||
if (order != INVALID_ORDER) {
|
||||
/* Shared Orders -- (##) Road vehicles */
|
||||
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) {
|
||||
const Player *p = GetPlayer(owner);
|
||||
/* Company Name -- (###) Road vehicles */
|
||||
SetDParam(0, p->name_1);
|
||||
SetDParam(1, p->name_2);
|
||||
SetDParam(2, w->vscroll.count);
|
||||
w->widget[1].unkA = STR_9001_ROAD_VEHICLES;
|
||||
} else {
|
||||
/* Station Name -- (###) Road vehicles */
|
||||
SetDParam(0, station);
|
||||
SetDParam(1, w->vscroll.count);
|
||||
w->widget[1].unkA = STR_SCHEDULED_ROAD_VEHICLES;
|
||||
}
|
||||
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_Road && v->owner == owner);
|
||||
|
||||
DrawRoadVehImage(v, x + 22, y + 6, INVALID_VEHICLE);
|
||||
DrawVehicleProfitButton(v, x, y + 13);
|
||||
|
||||
SetDParam(0, v->unitnumber);
|
||||
if (IsRoadVehInDepot(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 + 24, y + 18, STR_0198_PROFIT_THIS_YEAR_LAST_YEAR, 0);
|
||||
|
||||
if (v->string_id != STR_SV_ROADVEH_NAME) {
|
||||
SetDParam(0, v->string_id);
|
||||
DrawString(x + 24, y, STR_01AB, 0);
|
||||
}
|
||||
|
||||
y += PLY_WND_PRC__SIZE_OF_ROW_SMALL;
|
||||
}
|
||||
} break;
|
||||
|
||||
case WE_CLICK: {
|
||||
switch (e->click.widget) {
|
||||
case 3: /* Flip sorting method ascending/descending */
|
||||
vl->flags ^= VL_DESC;
|
||||
vl->flags |= VL_RESORT;
|
||||
_sorting.roadveh.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_SMALL;
|
||||
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_Road && v->owner == owner);
|
||||
|
||||
ShowRoadVehViewWindow(v);
|
||||
} break;
|
||||
|
||||
case 9: /* Build new Vehicle */
|
||||
if (!IsWindowOfPrototype(w, _player_roadveh_widgets)) break;
|
||||
ShowBuildRoadVehWindow(0);
|
||||
break;
|
||||
|
||||
case 10: {
|
||||
if (!IsWindowOfPrototype(w, _player_roadveh_widgets)) break;
|
||||
ShowReplaceVehicleWindow(VEH_Road);
|
||||
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.roadveh.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.roadveh.order << (VL_DESC - 1));
|
||||
vl->sort_type = _sorting.roadveh.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 road vehicles 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_SMALL;
|
||||
w->widget[7].unkA = (w->vscroll.cap << 8) + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static const WindowDesc _player_roadveh_desc = {
|
||||
-1, -1, 260, 220,
|
||||
WC_ROADVEH_LIST,0,
|
||||
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
|
||||
_player_roadveh_widgets,
|
||||
PlayerRoadVehWndProc
|
||||
PlayerVehWndProc
|
||||
};
|
||||
|
||||
static const WindowDesc _other_player_roadveh_desc = {
|
||||
@@ -1128,7 +958,7 @@ static const WindowDesc _other_player_roadveh_desc = {
|
||||
WC_ROADVEH_LIST,0,
|
||||
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
|
||||
_other_player_roadveh_widgets,
|
||||
PlayerRoadVehWndProc
|
||||
PlayerVehWndProc
|
||||
};
|
||||
|
||||
|
||||
@@ -1137,15 +967,19 @@ static void ShowPlayerRoadVehiclesLocal(PlayerID player, StationID station, Orde
|
||||
Window *w;
|
||||
|
||||
if (show_shared) {
|
||||
w = AllocateWindowDescFront(&_player_roadveh_desc, (order << 16) | SHARE_FLAG);
|
||||
w = AllocateWindowDescFront(&_player_roadveh_desc, (order << 16) | (VEH_Road << 11) | SHARE_FLAG);
|
||||
} else {
|
||||
if ( player == _local_player) {
|
||||
w = AllocateWindowDescFront(&_player_roadveh_desc, (station << 16) | player);
|
||||
w = AllocateWindowDescFront(&_player_roadveh_desc, (station << 16) | (VEH_Road << 11) | player);
|
||||
} else {
|
||||
w = AllocateWindowDescFront(&_other_player_roadveh_desc, (station << 16) | player);
|
||||
w = AllocateWindowDescFront(&_other_player_roadveh_desc, (station << 16) | (VEH_Road << 11) | player);
|
||||
}
|
||||
}
|
||||
if (w != NULL) {
|
||||
vehiclelist_d *vl = &WP(w, vehiclelist_d);
|
||||
vl->flags = VL_REBUILD | (_sorting.roadveh.order << (VL_DESC - 1));
|
||||
vl->sort_type = _sorting.roadveh.criteria;
|
||||
|
||||
w->caption_color = player;
|
||||
w->vscroll.cap = 7; // maximum number of vehicles shown
|
||||
w->widget[7].unkA = (w->vscroll.cap << 8) + 1;
|
||||
|
||||
Reference in New Issue
Block a user