(svn r6518) -Codechange: unified the vehicle refit windows

This was requested by peter1138
This commit is contained in:
bjarni
2006-09-27 07:23:38 +00:00
parent d88e1a218e
commit 0739d0c6f6
6 changed files with 122 additions and 316 deletions

View File

@@ -79,85 +79,6 @@ void DrawRoadVehImage(const Vehicle *v, int x, int y, VehicleID selection)
}
}
static void RoadVehRefitWndProc(Window *w, WindowEvent *e)
{
switch (e->event) {
case WE_PAINT: {
const Vehicle *v = GetVehicle(w->window_number);
SetDParam(0, v->string_id);
SetDParam(1, v->unitnumber);
DrawWindowWidgets(w);
WP(w,refit_d).cargo = DrawVehicleRefitWindow(v, WP(w,refit_d).sel);
if (WP(w,refit_d).cargo != CT_INVALID) {
int32 cost = DoCommand(v->tile, v->index, WP(w,refit_d).cargo, DC_QUERY_COST, CMD_REFIT_ROAD_VEH);
if (!CmdFailed(cost)) {
SetDParam(0, _cargoc.names_long[WP(w,refit_d).cargo]);
SetDParam(1, _returned_refit_capacity);
SetDParam(2, cost);
DrawString(1, 137, STR_9840_NEW_CAPACITY_COST_OF_REFIT, 0);
}
}
break;
}
case WE_CLICK:
switch (e->we.click.widget) {
case 2: { /* List box */
int y = e->we.click.pt.y - 25;
if (y >= 0) {
WP(w,refit_d).sel = y / 10;
SetWindowDirty(w);
}
break;
}
case 4: /* Refit button */
if (WP(w,refit_d).cargo != CT_INVALID) {
const Vehicle *v = GetVehicle(w->window_number);
if (DoCommandP(v->tile, v->index, WP(w,refit_d).cargo, NULL, CMD_REFIT_ROAD_VEH | CMD_MSG(STR_REFIT_ROAD_VEHICLE_CAN_T)))
DeleteWindow(w);
}
break;
}
break;
}
}
static const Widget _road_veh_refit_widgets[] = {
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW },
{ WWT_CAPTION, RESIZE_NONE, 14, 11, 239, 0, 13, STR_983B_REFIT, STR_018C_WINDOW_TITLE_DRAG_THIS },
{ WWT_IMGBTN, RESIZE_NONE, 14, 0, 239, 14, 135, 0x0, STR_983D_SELECT_TYPE_OF_CARGO_FOR },
{ WWT_IMGBTN, RESIZE_NONE, 14, 0, 239, 136, 157, 0x0, STR_NULL },
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 239, 158, 169, STR_REFIT_ROAD_VEHICLE, STR_REFIT_ROAD_VEHICLE_TO_CARRY_HIGHLIGHTED },
{ WWT_LABEL, RESIZE_NONE, 0, 0, 239, 13, 26, STR_983F_SELECT_CARGO_TYPE_TO_CARRY, STR_NULL},
{ WIDGETS_END },
};
static const WindowDesc _road_veh_refit_desc = {
-1, -1, 240, 170,
WC_VEHICLE_REFIT, WC_VEHICLE_VIEW,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
_road_veh_refit_widgets,
RoadVehRefitWndProc,
};
static void ShowRoadVehRefitWindow(const Vehicle *v)
{
Window *w;
DeleteWindowById(WC_VEHICLE_REFIT, v->index);
_alloc_wnd_parent_num = v->index;
w = AllocateWindowDesc(&_road_veh_refit_desc);
w->window_number = v->index;
w->caption_color = v->owner;
WP(w,refit_d).sel = -1;
}
static void RoadVehDetailsWndProc(Window *w, WindowEvent *e)
{
switch (e->event) {
@@ -398,7 +319,7 @@ static void RoadVehViewWndProc(Window *w, WindowEvent *e)
DoCommandP(v->tile, v->index, _ctrl_pressed ? 1 : 0, CcCloneRoadVeh, CMD_CLONE_VEHICLE | CMD_MSG(STR_9009_CAN_T_BUILD_ROAD_VEHICLE));
break;
case 12: /* Refit vehicle */
ShowRoadVehRefitWindow(v);
ShowVehicleRefitWindow(v);
break;
}
} break;