1
0
Fork 0

(svn r12638) -Codechange: give order_gui.cpp a touch of coding style.

release/0.7
rubidium 2008-04-09 16:16:04 +00:00
parent ab7b05da50
commit 55f0d01235
1 changed files with 209 additions and 228 deletions

View File

@ -111,23 +111,15 @@ static StringID _station_order_strings[][7] = {
static void DrawOrdersWindow(Window *w)
{
const Vehicle *v;
const Order *order;
StringID str;
int sel;
int y, i;
bool shared_orders;
v = GetVehicle(w->window_number);
shared_orders = v->IsOrderListShared();
const Vehicle *v = GetVehicle(w->window_number);
bool shared_orders = v->IsOrderListShared();
SetVScrollCount(w, v->num_orders + 1);
sel = OrderGetSel(w);
int sel = OrderGetSel(w);
SetDParam(2, STR_8827_FULL_LOAD);
order = GetVehicleOrder(v, sel);
const Order *order = GetVehicleOrder(v, sel);
if (v->owner == _local_player) {
/* skip */
@ -183,10 +175,11 @@ static void DrawOrdersWindow(Window *w)
SetDParam(0, v->index);
DrawWindowWidgets(w);
y = 15;
int y = 15;
i = w->vscroll.pos;
int i = w->vscroll.pos;
order = GetVehicleOrder(v, i);
StringID str;
while (order != NULL) {
str = (v->cur_order_index == i) ? STR_8805 : STR_8804;
SetDParam(3, STR_EMPTY);
@ -222,7 +215,7 @@ static void DrawOrdersWindow(Window *w)
}
}
if (order->GetDepotOrderType() & ODTFB_SERVICE) s++; /* service at */
if (order->GetDepotOrderType() & ODTFB_SERVICE) s++; // service at
SetDParam(1, s);
if (order->IsRefit()) {
@ -264,7 +257,7 @@ static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
order.next = NULL;
order.index = 0;
// check depot first
/* check depot first */
if (_patches.gotodepot) {
switch (GetTileType(tile)) {
case MP_RAILWAY:
@ -306,7 +299,7 @@ static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
}
}
// check waypoint
/* check waypoint */
if (IsTileType(tile, MP_RAILWAY) &&
v->type == VEH_TRAIN &&
IsTileOwner(tile, _local_player) &&
@ -333,7 +326,7 @@ static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
}
}
// not found
/* not found */
order.Free();
return order;
}
@ -347,8 +340,8 @@ static bool HandleOrderVehClick(const Vehicle *v, const Vehicle *u, Window *w)
if (!u->IsPrimaryVehicle()) return false;
}
// v is vehicle getting orders. Only copy/clone orders if vehicle doesn't have any orders yet
// obviously if you press CTRL on a non-empty orders vehicle you know what you are doing
/* v is vehicle getting orders. Only copy/clone orders if vehicle doesn't have any orders yet
* obviously if you press CTRL on a non-empty orders vehicle you know what you are doing */
if (v->num_orders != 0 && _ctrl_pressed == 0) return false;
if (DoCommandP(v->tile, v->index | (u->index << 16), _ctrl_pressed ? CO_SHARE : CO_COPY, NULL,
@ -362,14 +355,11 @@ static bool HandleOrderVehClick(const Vehicle *v, const Vehicle *u, Window *w)
static void OrdersPlaceObj(const Vehicle *v, TileIndex tile, Window *w)
{
Order cmd;
const Vehicle *u;
// check if we're clicking on a vehicle first.. clone orders in that case.
u = CheckMouseOverVehicle();
/* check if we're clicking on a vehicle first.. clone orders in that case. */
const Vehicle *u = CheckMouseOverVehicle();
if (u != NULL && HandleOrderVehClick(v, u, w)) return;
cmd = GetOrderCmdFromTile(v, tile);
const Order cmd = GetOrderCmdFromTile(v, tile);
if (!cmd.IsValid()) return;
if (DoCommandP(v->tile, v->index + (OrderGetSel(w) << 16), cmd.Pack(), NULL, CMD_INSERT_ORDER | CMD_MSG(STR_8833_CAN_T_INSERT_NEW_ORDER))) {
@ -531,13 +521,15 @@ static const uint16 _order_keycodes[] = {
static void OrdersWndProc(Window *w, WindowEvent *e)
{
const Vehicle *v = GetVehicle(w->window_number);
switch (e->event) {
case WE_CREATE:
/* Ensure that the refit and unload buttons always remain at the same location.
* Only one of them can be active at any one time and takes turns on being disabled.
* To ensure that they stay at the same location, we also verify that they behave the same
* when resizing. */
if (GetVehicle(w->window_number)->owner == _local_player) { // only the vehicle owner got these buttons
if (v->owner == _local_player) { // only the vehicle owner got these buttons
assert(w->widget[ORDER_WIDGET_REFIT].left == w->widget[ORDER_WIDGET_UNLOAD].left);
assert(w->widget[ORDER_WIDGET_REFIT].right == w->widget[ORDER_WIDGET_UNLOAD].right);
assert(w->widget[ORDER_WIDGET_REFIT].top == w->widget[ORDER_WIDGET_UNLOAD].top);
@ -557,8 +549,7 @@ static void OrdersWndProc(Window *w, WindowEvent *e)
DrawOrdersWindow(w);
break;
case WE_CLICK: {
const Vehicle *v = GetVehicle(w->window_number);
case WE_CLICK:
switch (e->we.click.widget) {
case ORDER_WIDGET_ORDER_LIST: {
ResetObjectToPlace();
@ -643,11 +634,9 @@ static void OrdersWndProc(Window *w, WindowEvent *e)
ShowVehicleListWindow(v);
break;
}
} break;
case WE_DRAGDROP: {
const Vehicle *v = GetVehicle(w->window_number);
break;
case WE_DRAGDROP:
switch (e->we.click.widget) {
case ORDER_WIDGET_ORDER_LIST: {
int from_order = OrderGetSel(w);
@ -658,8 +647,7 @@ static void OrdersWndProc(Window *w, WindowEvent *e)
WP(w, order_d).sel = -1;
}
break;
}
} break;
case ORDER_WIDGET_DELETE:
OrderClick_Delete(w, v);
@ -668,27 +656,21 @@ static void OrdersWndProc(Window *w, WindowEvent *e)
ResetObjectToPlace();
break;
}
case WE_KEYPRESS: {
Vehicle *v = GetVehicle(w->window_number);
uint i;
case WE_KEYPRESS:
if (v->owner != _local_player) break;
for (i = 0; i < lengthof(_order_keycodes); i++) {
for (uint i = 0; i < lengthof(_order_keycodes); i++) {
if (e->we.keypress.keycode == _order_keycodes[i]) {
e->we.keypress.cont = false;
//see if the button is disabled
/* see if the button is disabled */
if (!w->IsWidgetDisabled(i + ORDER_WIDGET_SKIP)) _order_button_proc[i](w, v);
break;
}
}
break;
}
case WE_RCLICK: {
const Vehicle *v = GetVehicle(w->window_number);
int s = OrderGetSel(w);
if (e->we.click.widget != ORDER_WIDGET_FULL_LOAD) break;
@ -699,18 +681,18 @@ static void OrdersWndProc(Window *w, WindowEvent *e)
}
} break;
case WE_PLACE_OBJ: {
case WE_PLACE_OBJ:
OrdersPlaceObj(GetVehicle(w->window_number), e->we.place.tile, w);
} break;
break;
case WE_ABORT_PLACE_OBJ: {
case WE_ABORT_PLACE_OBJ:
w->RaiseWidget(ORDER_WIDGET_GOTO);
w->InvalidateWidget(ORDER_WIDGET_GOTO);
} break;
break;
// check if a vehicle in a depot was clicked..
case WE_MOUSELOOP: {
const Vehicle *v = _place_clicked_vehicle;
/* check if a vehicle in a depot was clicked.. */
case WE_MOUSELOOP:
v = _place_clicked_vehicle;
/*
* Check if we clicked on a vehicle
* and if the GOTO button of this window is pressed
@ -723,23 +705,22 @@ static void OrdersWndProc(Window *w, WindowEvent *e)
_place_clicked_vehicle = NULL;
HandleOrderVehClick(GetVehicle(w->window_number), v, w);
}
} break;
break;
case WE_RESIZE:
/* Update the scroll + matrix */
w->vscroll.cap = (w->widget[ORDER_WIDGET_ORDER_LIST].bottom - w->widget[ORDER_WIDGET_ORDER_LIST].top) / 10;
break;
case WE_TIMEOUT: { // handle button unclick ourselves...
// unclick all buttons except for the 'goto' button (ORDER_WIDGET_GOTO), which is 'persistent'
uint i;
for (i = 0; i < w->widget_count; i++) {
case WE_TIMEOUT: // handle button unclick ourselves...
/* unclick all buttons except for the 'goto' button (ORDER_WIDGET_GOTO), which is 'persistent' */
for (uint i = 0; i < w->widget_count; i++) {
if (w->IsWidgetLowered(i) && i != ORDER_WIDGET_GOTO) {
w->RaiseWidget(i);
w->InvalidateWidget(i);
}
}
} break;
break;
}
}