(svn r6678) -Code cleanup: [train build window] made an enum with widget names and fixed some incorrect indents

pull/155/head
bjarni 18 years ago
parent 757ffb8821
commit 1aa41be3e2

@ -23,6 +23,18 @@
#include "newgrf_engine.h"
#include "date.h"
typedef enum BuildTrainWidgets {
BUILD_TRAIN_WIDGET_CLOSEBOX = 0,
BUILD_TRAIN_WIDGET_CAPTION,
BUILD_TRAIN_WIDGET_LIST,
BUILD_TRAIN_WIDGET_SCROLLBAR,
BUILD_TRAIN_WIDGET_PANEL,
BUILD_TRAIN_WIDGET_BUILD,
BUILD_TRAIN_WIDGET_RENAME,
BUILD_TRAIN_WIDGET_RESIZE,
} BuildTrainWidget;
/**
* Draw the purchase info details of train engine at a given location.
* @param x,y location where to draw the info
@ -206,7 +218,7 @@ static void NewRailVehicleWndProc(Window *w, WindowEvent *e)
switch (e->event) {
case WE_PAINT:
SetWindowWidgetDisabledState(w, 5, w->window_number == 0);
SetWindowWidgetDisabledState(w, BUILD_TRAIN_WIDGET_BUILD, w->window_number == 0);
{
int count = 0;
@ -249,10 +261,10 @@ static void NewRailVehicleWndProc(Window *w, WindowEvent *e)
if (!(rvi->flags & RVI_WAGON)) {
/* it's an engine */
DrawTrainEnginePurchaseInfo(2, w->widget[4].top + 1,selected_id);
DrawTrainEnginePurchaseInfo(2, w->widget[BUILD_TRAIN_WIDGET_PANEL].top + 1,selected_id);
} else {
/* it's a wagon */
DrawTrainWagonPurchaseInfo(2, w->widget[4].top + 1, selected_id);
DrawTrainWagonPurchaseInfo(2, w->widget[BUILD_TRAIN_WIDGET_PANEL].top + 1, selected_id);
}
}
}
@ -260,19 +272,21 @@ static void NewRailVehicleWndProc(Window *w, WindowEvent *e)
case WE_CLICK: {
switch (e->we.click.widget) {
case 2: {
case BUILD_TRAIN_WIDGET_LIST: {
uint i = (e->we.click.pt.y - 14) / 14;
if (i < w->vscroll.cap) {
WP(w,buildtrain_d).sel_index = i + w->vscroll.pos;
SetWindowDirty(w);
}
} break;
case 5: {
case BUILD_TRAIN_WIDGET_BUILD: {
EngineID sel_eng = WP(w,buildtrain_d).sel_engine;
if (sel_eng != INVALID_ENGINE)
DoCommandP(w->window_number, sel_eng, 0, (RailVehInfo(sel_eng)->flags & RVI_WAGON) ? CcBuildWagon : CcBuildLoco, CMD_BUILD_RAIL_VEHICLE | CMD_MSG(STR_882B_CAN_T_BUILD_RAILROAD_VEHICLE));
} break;
case 6: { /* rename */
case BUILD_TRAIN_WIDGET_RENAME: {
EngineID sel_eng = WP(w,buildtrain_d).sel_engine;
if (sel_eng != INVALID_ENGINE) {
WP(w,buildtrain_d).rename_engine = sel_eng;
@ -292,11 +306,10 @@ static void NewRailVehicleWndProc(Window *w, WindowEvent *e)
} break;
case WE_RESIZE: {
if (e->we.sizing.diff.y == 0)
break;
if (e->we.sizing.diff.y == 0) break;
w->vscroll.cap += e->we.sizing.diff.y / 14;
w->widget[2].data = (w->vscroll.cap << 8) + 1;
w->widget[BUILD_TRAIN_WIDGET_LIST].data = (w->vscroll.cap << 8) + 1;
} break;
}
}
@ -330,7 +343,7 @@ void ShowBuildTrainWindow(TileIndex tile)
w = AllocateWindowDesc(&_new_rail_vehicle_desc);
w->window_number = tile;
w->vscroll.cap = 8;
w->widget[2].data = (w->vscroll.cap << 8) + 1;
w->widget[BUILD_TRAIN_WIDGET_LIST].data = (w->vscroll.cap << 8) + 1;
w->resize.step_height = 14;
w->resize.height = w->height - 14 * 4; // Minimum of 4 vehicles in the display

Loading…
Cancel
Save