mirror of https://github.com/OpenTTD/OpenTTD
(svn r12638) -Codechange: give order_gui.cpp a touch of coding style.
parent
ab7b05da50
commit
55f0d01235
|
@ -111,23 +111,15 @@ static StringID _station_order_strings[][7] = {
|
||||||
|
|
||||||
static void DrawOrdersWindow(Window *w)
|
static void DrawOrdersWindow(Window *w)
|
||||||
{
|
{
|
||||||
const Vehicle *v;
|
const Vehicle *v = GetVehicle(w->window_number);
|
||||||
const Order *order;
|
bool shared_orders = v->IsOrderListShared();
|
||||||
StringID str;
|
|
||||||
int sel;
|
|
||||||
int y, i;
|
|
||||||
bool shared_orders;
|
|
||||||
|
|
||||||
v = GetVehicle(w->window_number);
|
|
||||||
|
|
||||||
shared_orders = v->IsOrderListShared();
|
|
||||||
|
|
||||||
SetVScrollCount(w, v->num_orders + 1);
|
SetVScrollCount(w, v->num_orders + 1);
|
||||||
|
|
||||||
sel = OrderGetSel(w);
|
int sel = OrderGetSel(w);
|
||||||
SetDParam(2, STR_8827_FULL_LOAD);
|
SetDParam(2, STR_8827_FULL_LOAD);
|
||||||
|
|
||||||
order = GetVehicleOrder(v, sel);
|
const Order *order = GetVehicleOrder(v, sel);
|
||||||
|
|
||||||
if (v->owner == _local_player) {
|
if (v->owner == _local_player) {
|
||||||
/* skip */
|
/* skip */
|
||||||
|
@ -183,10 +175,11 @@ static void DrawOrdersWindow(Window *w)
|
||||||
SetDParam(0, v->index);
|
SetDParam(0, v->index);
|
||||||
DrawWindowWidgets(w);
|
DrawWindowWidgets(w);
|
||||||
|
|
||||||
y = 15;
|
int y = 15;
|
||||||
|
|
||||||
i = w->vscroll.pos;
|
int i = w->vscroll.pos;
|
||||||
order = GetVehicleOrder(v, i);
|
order = GetVehicleOrder(v, i);
|
||||||
|
StringID str;
|
||||||
while (order != NULL) {
|
while (order != NULL) {
|
||||||
str = (v->cur_order_index == i) ? STR_8805 : STR_8804;
|
str = (v->cur_order_index == i) ? STR_8805 : STR_8804;
|
||||||
SetDParam(3, STR_EMPTY);
|
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);
|
SetDParam(1, s);
|
||||||
if (order->IsRefit()) {
|
if (order->IsRefit()) {
|
||||||
|
@ -264,7 +257,7 @@ static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
|
||||||
order.next = NULL;
|
order.next = NULL;
|
||||||
order.index = 0;
|
order.index = 0;
|
||||||
|
|
||||||
// check depot first
|
/* check depot first */
|
||||||
if (_patches.gotodepot) {
|
if (_patches.gotodepot) {
|
||||||
switch (GetTileType(tile)) {
|
switch (GetTileType(tile)) {
|
||||||
case MP_RAILWAY:
|
case MP_RAILWAY:
|
||||||
|
@ -306,7 +299,7 @@ static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// check waypoint
|
/* check waypoint */
|
||||||
if (IsTileType(tile, MP_RAILWAY) &&
|
if (IsTileType(tile, MP_RAILWAY) &&
|
||||||
v->type == VEH_TRAIN &&
|
v->type == VEH_TRAIN &&
|
||||||
IsTileOwner(tile, _local_player) &&
|
IsTileOwner(tile, _local_player) &&
|
||||||
|
@ -333,7 +326,7 @@ static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// not found
|
/* not found */
|
||||||
order.Free();
|
order.Free();
|
||||||
return order;
|
return order;
|
||||||
}
|
}
|
||||||
|
@ -347,8 +340,8 @@ static bool HandleOrderVehClick(const Vehicle *v, const Vehicle *u, Window *w)
|
||||||
if (!u->IsPrimaryVehicle()) return false;
|
if (!u->IsPrimaryVehicle()) return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// v is vehicle getting orders. Only copy/clone orders if vehicle doesn't have any orders yet
|
/* 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
|
* 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 (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,
|
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)
|
static void OrdersPlaceObj(const Vehicle *v, TileIndex tile, Window *w)
|
||||||
{
|
{
|
||||||
Order cmd;
|
/* check if we're clicking on a vehicle first.. clone orders in that case. */
|
||||||
const Vehicle *u;
|
const Vehicle *u = CheckMouseOverVehicle();
|
||||||
|
|
||||||
// check if we're clicking on a vehicle first.. clone orders in that case.
|
|
||||||
u = CheckMouseOverVehicle();
|
|
||||||
if (u != NULL && HandleOrderVehClick(v, u, w)) return;
|
if (u != NULL && HandleOrderVehClick(v, u, w)) return;
|
||||||
|
|
||||||
cmd = GetOrderCmdFromTile(v, tile);
|
const Order cmd = GetOrderCmdFromTile(v, tile);
|
||||||
if (!cmd.IsValid()) return;
|
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))) {
|
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)
|
static void OrdersWndProc(Window *w, WindowEvent *e)
|
||||||
{
|
{
|
||||||
|
const Vehicle *v = GetVehicle(w->window_number);
|
||||||
|
|
||||||
switch (e->event) {
|
switch (e->event) {
|
||||||
case WE_CREATE:
|
case WE_CREATE:
|
||||||
/* Ensure that the refit and unload buttons always remain at the same location.
|
/* 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.
|
* 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
|
* To ensure that they stay at the same location, we also verify that they behave the same
|
||||||
* when resizing. */
|
* 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].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].right == w->widget[ORDER_WIDGET_UNLOAD].right);
|
||||||
assert(w->widget[ORDER_WIDGET_REFIT].top == w->widget[ORDER_WIDGET_UNLOAD].top);
|
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);
|
DrawOrdersWindow(w);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WE_CLICK: {
|
case WE_CLICK:
|
||||||
const Vehicle *v = GetVehicle(w->window_number);
|
|
||||||
switch (e->we.click.widget) {
|
switch (e->we.click.widget) {
|
||||||
case ORDER_WIDGET_ORDER_LIST: {
|
case ORDER_WIDGET_ORDER_LIST: {
|
||||||
ResetObjectToPlace();
|
ResetObjectToPlace();
|
||||||
|
@ -643,11 +634,9 @@ static void OrdersWndProc(Window *w, WindowEvent *e)
|
||||||
ShowVehicleListWindow(v);
|
ShowVehicleListWindow(v);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} break;
|
break;
|
||||||
|
|
||||||
case WE_DRAGDROP: {
|
|
||||||
const Vehicle *v = GetVehicle(w->window_number);
|
|
||||||
|
|
||||||
|
case WE_DRAGDROP:
|
||||||
switch (e->we.click.widget) {
|
switch (e->we.click.widget) {
|
||||||
case ORDER_WIDGET_ORDER_LIST: {
|
case ORDER_WIDGET_ORDER_LIST: {
|
||||||
int from_order = OrderGetSel(w);
|
int from_order = OrderGetSel(w);
|
||||||
|
@ -658,8 +647,7 @@ static void OrdersWndProc(Window *w, WindowEvent *e)
|
||||||
WP(w, order_d).sel = -1;
|
WP(w, order_d).sel = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
} break;
|
||||||
}
|
|
||||||
|
|
||||||
case ORDER_WIDGET_DELETE:
|
case ORDER_WIDGET_DELETE:
|
||||||
OrderClick_Delete(w, v);
|
OrderClick_Delete(w, v);
|
||||||
|
@ -668,27 +656,21 @@ static void OrdersWndProc(Window *w, WindowEvent *e)
|
||||||
|
|
||||||
ResetObjectToPlace();
|
ResetObjectToPlace();
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
case WE_KEYPRESS: {
|
|
||||||
Vehicle *v = GetVehicle(w->window_number);
|
|
||||||
uint i;
|
|
||||||
|
|
||||||
|
case WE_KEYPRESS:
|
||||||
if (v->owner != _local_player) break;
|
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]) {
|
if (e->we.keypress.keycode == _order_keycodes[i]) {
|
||||||
e->we.keypress.cont = false;
|
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);
|
if (!w->IsWidgetDisabled(i + ORDER_WIDGET_SKIP)) _order_button_proc[i](w, v);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
case WE_RCLICK: {
|
case WE_RCLICK: {
|
||||||
const Vehicle *v = GetVehicle(w->window_number);
|
|
||||||
int s = OrderGetSel(w);
|
int s = OrderGetSel(w);
|
||||||
|
|
||||||
if (e->we.click.widget != ORDER_WIDGET_FULL_LOAD) break;
|
if (e->we.click.widget != ORDER_WIDGET_FULL_LOAD) break;
|
||||||
|
@ -699,18 +681,18 @@ static void OrdersWndProc(Window *w, WindowEvent *e)
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case WE_PLACE_OBJ: {
|
case WE_PLACE_OBJ:
|
||||||
OrdersPlaceObj(GetVehicle(w->window_number), e->we.place.tile, w);
|
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->RaiseWidget(ORDER_WIDGET_GOTO);
|
||||||
w->InvalidateWidget(ORDER_WIDGET_GOTO);
|
w->InvalidateWidget(ORDER_WIDGET_GOTO);
|
||||||
} break;
|
break;
|
||||||
|
|
||||||
// check if a vehicle in a depot was clicked..
|
/* check if a vehicle in a depot was clicked.. */
|
||||||
case WE_MOUSELOOP: {
|
case WE_MOUSELOOP:
|
||||||
const Vehicle *v = _place_clicked_vehicle;
|
v = _place_clicked_vehicle;
|
||||||
/*
|
/*
|
||||||
* Check if we clicked on a vehicle
|
* Check if we clicked on a vehicle
|
||||||
* and if the GOTO button of this window is pressed
|
* 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;
|
_place_clicked_vehicle = NULL;
|
||||||
HandleOrderVehClick(GetVehicle(w->window_number), v, w);
|
HandleOrderVehClick(GetVehicle(w->window_number), v, w);
|
||||||
}
|
}
|
||||||
} break;
|
break;
|
||||||
|
|
||||||
case WE_RESIZE:
|
case WE_RESIZE:
|
||||||
/* Update the scroll + matrix */
|
/* Update the scroll + matrix */
|
||||||
w->vscroll.cap = (w->widget[ORDER_WIDGET_ORDER_LIST].bottom - w->widget[ORDER_WIDGET_ORDER_LIST].top) / 10;
|
w->vscroll.cap = (w->widget[ORDER_WIDGET_ORDER_LIST].bottom - w->widget[ORDER_WIDGET_ORDER_LIST].top) / 10;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WE_TIMEOUT: { // handle button unclick ourselves...
|
case WE_TIMEOUT: // handle button unclick ourselves...
|
||||||
// unclick all buttons except for the 'goto' button (ORDER_WIDGET_GOTO), which is 'persistent'
|
/* unclick all buttons except for the 'goto' button (ORDER_WIDGET_GOTO), which is 'persistent' */
|
||||||
uint i;
|
for (uint i = 0; i < w->widget_count; i++) {
|
||||||
for (i = 0; i < w->widget_count; i++) {
|
|
||||||
if (w->IsWidgetLowered(i) && i != ORDER_WIDGET_GOTO) {
|
if (w->IsWidgetLowered(i) && i != ORDER_WIDGET_GOTO) {
|
||||||
w->RaiseWidget(i);
|
w->RaiseWidget(i);
|
||||||
w->InvalidateWidget(i);
|
w->InvalidateWidget(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue