1
0
Fork 0

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

release/0.5
bjarni 2006-10-07 09:02:48 +00:00
parent f640eb7302
commit 5df4e234e0
1 changed files with 94 additions and 81 deletions

View File

@ -23,6 +23,18 @@
#include "newgrf_engine.h" #include "newgrf_engine.h"
#include "date.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. * Draw the purchase info details of train engine at a given location.
* @param x,y location where to draw the info * @param x,y location where to draw the info
@ -206,7 +218,7 @@ static void NewRailVehicleWndProc(Window *w, WindowEvent *e)
switch (e->event) { switch (e->event) {
case WE_PAINT: case WE_PAINT:
SetWindowWidgetDisabledState(w, 5, w->window_number == 0); SetWindowWidgetDisabledState(w, BUILD_TRAIN_WIDGET_BUILD, w->window_number == 0);
{ {
int count = 0; int count = 0;
@ -249,10 +261,10 @@ static void NewRailVehicleWndProc(Window *w, WindowEvent *e)
if (!(rvi->flags & RVI_WAGON)) { if (!(rvi->flags & RVI_WAGON)) {
/* it's an engine */ /* 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 { } else {
/* it's a wagon */ /* 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: { case WE_CLICK: {
switch (e->we.click.widget) { switch (e->we.click.widget) {
case 2: { case BUILD_TRAIN_WIDGET_LIST: {
uint i = (e->we.click.pt.y - 14) / 14; uint i = (e->we.click.pt.y - 14) / 14;
if (i < w->vscroll.cap) { if (i < w->vscroll.cap) {
WP(w,buildtrain_d).sel_index = i + w->vscroll.pos; WP(w,buildtrain_d).sel_index = i + w->vscroll.pos;
SetWindowDirty(w); SetWindowDirty(w);
} }
} break; } break;
case 5: {
case BUILD_TRAIN_WIDGET_BUILD: {
EngineID sel_eng = WP(w,buildtrain_d).sel_engine; EngineID sel_eng = WP(w,buildtrain_d).sel_engine;
if (sel_eng != INVALID_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)); 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; } break;
case 6: { /* rename */
case BUILD_TRAIN_WIDGET_RENAME: {
EngineID sel_eng = WP(w,buildtrain_d).sel_engine; EngineID sel_eng = WP(w,buildtrain_d).sel_engine;
if (sel_eng != INVALID_ENGINE) { if (sel_eng != INVALID_ENGINE) {
WP(w,buildtrain_d).rename_engine = sel_eng; WP(w,buildtrain_d).rename_engine = sel_eng;
@ -292,11 +306,10 @@ static void NewRailVehicleWndProc(Window *w, WindowEvent *e)
} break; } break;
case WE_RESIZE: { case WE_RESIZE: {
if (e->we.sizing.diff.y == 0) if (e->we.sizing.diff.y == 0) break;
break;
w->vscroll.cap += e->we.sizing.diff.y / 14; 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; } break;
} }
} }
@ -330,7 +343,7 @@ void ShowBuildTrainWindow(TileIndex tile)
w = AllocateWindowDesc(&_new_rail_vehicle_desc); w = AllocateWindowDesc(&_new_rail_vehicle_desc);
w->window_number = tile; w->window_number = tile;
w->vscroll.cap = 8; 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.step_height = 14;
w->resize.height = w->height - 14 * 4; // Minimum of 4 vehicles in the display w->resize.height = w->height - 14 * 4; // Minimum of 4 vehicles in the display