mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r3098) static, const, uint -> TileIndex, indentation, bracing, unused return values, ... mostly related to the clone vehicle GUI
This commit is contained in:
parent
9bbf8ea9d0
commit
9e957ff80b
|
@ -328,7 +328,7 @@ bool IsAircraftHangarTile(TileIndex tile)
|
|||
(_m[tile].m5 == 32 || _m[tile].m5 == 65 || _m[tile].m5 == 86);
|
||||
}
|
||||
|
||||
bool CheckStoppedInHangar(Vehicle *v)
|
||||
bool CheckStoppedInHangar(const Vehicle* v)
|
||||
{
|
||||
if (!(v->vehstatus & VS_STOPPED) || !IsAircraftHangarTile(v->tile)) {
|
||||
_error_message = STR_A01B_AIRCRAFT_MUST_BE_STOPPED;
|
||||
|
|
102
aircraft_gui.c
102
aircraft_gui.c
|
@ -91,10 +91,9 @@ void CcBuildAircraft(bool success, TileIndex tile, uint32 p1, uint32 p2)
|
|||
|
||||
void CcCloneAircraft(bool success, uint tile, uint32 p1, uint32 p2)
|
||||
{
|
||||
Vehicle *v;
|
||||
|
||||
if (success) {
|
||||
v = GetVehicle(_new_aircraft_id);
|
||||
const Vehicle* v = GetVehicle(_new_aircraft_id);
|
||||
|
||||
ShowAircraftViewWindow(v);
|
||||
}
|
||||
}
|
||||
|
@ -303,7 +302,7 @@ static const WindowDesc _aircraft_refit_desc = {
|
|||
AircraftRefitWndProc
|
||||
};
|
||||
|
||||
static void ShowAircraftRefitWindow(Vehicle *v)
|
||||
static void ShowAircraftRefitWindow(const Vehicle* v)
|
||||
{
|
||||
Window *w;
|
||||
|
||||
|
@ -468,7 +467,7 @@ static const WindowDesc _aircraft_details_desc = {
|
|||
};
|
||||
|
||||
|
||||
static void ShowAircraftDetailsWindow(Vehicle *v)
|
||||
static void ShowAircraftDetailsWindow(const Vehicle* v)
|
||||
{
|
||||
Window *w;
|
||||
VehicleID veh = v->index;
|
||||
|
@ -503,7 +502,7 @@ static const Widget _aircraft_view_widgets[] = {
|
|||
{ WIDGETS_END }
|
||||
};
|
||||
|
||||
bool CheckStoppedInHangar(Vehicle *v);
|
||||
bool CheckStoppedInHangar(const Vehicle* v); /* XXX extern function declaration in .c */
|
||||
|
||||
static void AircraftViewWndProc(Window *w, WindowEvent *e)
|
||||
{
|
||||
|
@ -570,9 +569,9 @@ static void AircraftViewWndProc(Window *w, WindowEvent *e)
|
|||
} break;
|
||||
|
||||
case WE_CLICK: {
|
||||
Vehicle *v = GetVehicle(w->window_number);
|
||||
const Vehicle* v = GetVehicle(w->window_number);
|
||||
|
||||
switch(e->click.widget) {
|
||||
switch (e->click.widget) {
|
||||
case 5: /* start stop */
|
||||
DoCommandP(v->tile, v->index, 0, NULL, CMD_START_STOP_AIRCRAFT | CMD_MSG(STR_A016_CAN_T_STOP_START_AIRCRAFT));
|
||||
break;
|
||||
|
@ -591,12 +590,10 @@ static void AircraftViewWndProc(Window *w, WindowEvent *e)
|
|||
case 10: /* show details */
|
||||
ShowAircraftDetailsWindow(v);
|
||||
break;
|
||||
case 11: {
|
||||
case 11:
|
||||
/* clone vehicle */
|
||||
Vehicle *v;
|
||||
v = GetVehicle(w->window_number);
|
||||
DoCommandP(v->tile, v->index, _ctrl_pressed ? 1 : 0, CcCloneAircraft, CMD_CLONE_VEHICLE | CMD_MSG(STR_A008_CAN_T_BUILD_AIRCRAFT));
|
||||
} break;
|
||||
break;
|
||||
}
|
||||
} break;
|
||||
|
||||
|
@ -613,18 +610,15 @@ static void AircraftViewWndProc(Window *w, WindowEvent *e)
|
|||
DeleteWindowById(WC_VEHICLE_DETAILS, w->window_number);
|
||||
break;
|
||||
|
||||
case WE_MOUSELOOP:
|
||||
{
|
||||
Vehicle *v;
|
||||
uint32 h;
|
||||
v = GetVehicle(w->window_number);
|
||||
h = CheckStoppedInHangar(v) ? (1<< 7) : (1 << 11);
|
||||
if (h != w->hidden_state) {
|
||||
w->hidden_state = h;
|
||||
SetWindowDirty(w);
|
||||
}
|
||||
} break;
|
||||
case WE_MOUSELOOP: {
|
||||
const Vehicle* v = GetVehicle(w->window_number);
|
||||
uint32 h = CheckStoppedInHangar(v) ? (1 << 7) : (1 << 11);
|
||||
|
||||
if (h != w->hidden_state) {
|
||||
w->hidden_state = h;
|
||||
SetWindowDirty(w);
|
||||
}
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -638,12 +632,11 @@ static const WindowDesc _aircraft_view_desc = {
|
|||
};
|
||||
|
||||
|
||||
void ShowAircraftViewWindow(Vehicle *v)
|
||||
void ShowAircraftViewWindow(const Vehicle* v)
|
||||
{
|
||||
Window *w;
|
||||
Window* w = AllocateWindowDescFront(&_aircraft_view_desc, v->index);
|
||||
|
||||
w = AllocateWindowDescFront(&_aircraft_view_desc, v->index);
|
||||
if (w) {
|
||||
if (w != NULL) {
|
||||
w->caption_color = v->owner;
|
||||
AssignWindowViewport(w, 3, 17, 0xE2, 0x54, w->window_number | (1 << 31), 0);
|
||||
}
|
||||
|
@ -769,34 +762,22 @@ static void AircraftDepotClickAircraft(Window *w, int x, int y)
|
|||
* @param *v is the original vehicle to clone
|
||||
* @param *w is the window of the hangar where the clone is build
|
||||
*/
|
||||
static bool HandleCloneVehClick(Vehicle *v, Window *w)
|
||||
static void HandleCloneVehClick(const Vehicle* v, const Window* w)
|
||||
{
|
||||
if (v == NULL || v->type != VEH_Aircraft) return;
|
||||
|
||||
if (!v){
|
||||
return false;
|
||||
}
|
||||
|
||||
if (v->type != VEH_Aircraft) {
|
||||
// it's not an aircraft, do nothing
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
DoCommandP(w->window_number, v->index, _ctrl_pressed ? 1 : 0,CcCloneAircraft,CMD_CLONE_VEHICLE | CMD_MSG(STR_A008_CAN_T_BUILD_AIRCRAFT));
|
||||
DoCommandP(w->window_number, v->index, _ctrl_pressed ? 1 : 0,
|
||||
CcCloneAircraft, CMD_CLONE_VEHICLE | CMD_MSG(STR_A008_CAN_T_BUILD_AIRCRAFT)
|
||||
);
|
||||
|
||||
ResetObjectToPlace();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void ClonePlaceObj(uint tile, Window *w)
|
||||
static void ClonePlaceObj(TileIndex tile, const Window* w)
|
||||
{
|
||||
Vehicle *v;
|
||||
const Vehicle* v = CheckMouseOverVehicle();
|
||||
|
||||
|
||||
v = CheckMouseOverVehicle();
|
||||
if (v && HandleCloneVehClick(v, w))
|
||||
return;
|
||||
if (v != NULL) HandleCloneVehClick(v, w);
|
||||
}
|
||||
|
||||
|
||||
|
@ -817,17 +798,18 @@ static void AircraftDepotWndProc(Window *w, WindowEvent *e)
|
|||
ShowBuildAircraftWindow(w->window_number);
|
||||
break;
|
||||
|
||||
case 8: /* clone button */
|
||||
case 8: /* clone button */
|
||||
InvalidateWidget(w, 8);
|
||||
TOGGLEBIT(w->click_state, 8);
|
||||
TOGGLEBIT(w->click_state, 8);
|
||||
|
||||
if (HASBIT(w->click_state, 8)) {
|
||||
_place_clicked_vehicle = NULL;
|
||||
SetObjectToPlaceWnd(SPR_CURSOR_CLONE, VHM_RECT, w);
|
||||
} else {
|
||||
ResetObjectToPlace();
|
||||
}
|
||||
break;
|
||||
|
||||
if (HASBIT(w->click_state, 8)) {
|
||||
_place_clicked_vehicle = NULL;
|
||||
SetObjectToPlaceWnd(SPR_CURSOR_CLONE, VHM_RECT, w);
|
||||
} else {
|
||||
ResetObjectToPlace();
|
||||
}
|
||||
break;
|
||||
case 9: /* scroll to tile */
|
||||
ResetObjectToPlace();
|
||||
ScrollMainWindowToTile(w->window_number);
|
||||
|
@ -835,8 +817,7 @@ static void AircraftDepotWndProc(Window *w, WindowEvent *e)
|
|||
}
|
||||
break;
|
||||
|
||||
|
||||
case WE_PLACE_OBJ: {
|
||||
case WE_PLACE_OBJ: {
|
||||
ClonePlaceObj(e->place.tile, w);
|
||||
} break;
|
||||
|
||||
|
@ -847,11 +828,12 @@ case WE_PLACE_OBJ: {
|
|||
|
||||
// check if a vehicle in a depot was clicked..
|
||||
case WE_MOUSELOOP: {
|
||||
Vehicle *v = _place_clicked_vehicle;
|
||||
const Vehicle* v = _place_clicked_vehicle;
|
||||
|
||||
// since OTTD checks all open depot windows, we will make sure that it triggers the one with a clicked clone button
|
||||
if (v != NULL && HASBIT(w->click_state, 8)) {
|
||||
_place_clicked_vehicle = NULL;
|
||||
HandleCloneVehClick( v, w);
|
||||
HandleCloneVehClick(v, w);
|
||||
}
|
||||
} break;
|
||||
|
||||
|
|
7
gui.h
7
gui.h
|
@ -40,11 +40,10 @@ void PlaceProc_BuyLand(TileIndex tile);
|
|||
|
||||
/* train_gui.c */
|
||||
void ShowPlayerTrains(PlayerID player, StationID station);
|
||||
void ShowTrainViewWindow(Vehicle *v);
|
||||
void ShowTrainDetailsWindow(Vehicle *v);
|
||||
void ShowTrainViewWindow(const Vehicle *v);
|
||||
void ShowOrdersWindow(const Vehicle* v);
|
||||
|
||||
void ShowRoadVehViewWindow(Vehicle *v);
|
||||
void ShowRoadVehViewWindow(const Vehicle* v);
|
||||
|
||||
/* road_gui.c */
|
||||
void ShowBuildRoadToolbar(void);
|
||||
|
@ -55,7 +54,7 @@ void ShowPlayerRoadVehicles(PlayerID player, StationID station);
|
|||
void ShowBuildDocksToolbar(void);
|
||||
void ShowPlayerShips(PlayerID player, StationID station);
|
||||
|
||||
void ShowShipViewWindow(Vehicle *v);
|
||||
void ShowShipViewWindow(const Vehicle* v);
|
||||
|
||||
/* aircraft_gui.c */
|
||||
void ShowBuildAirToolbar(void);
|
||||
|
|
|
@ -211,7 +211,7 @@ static const WindowDesc _roadveh_details_desc = {
|
|||
RoadVehDetailsWndProc
|
||||
};
|
||||
|
||||
static void ShowRoadVehDetailsWindow(Vehicle *v)
|
||||
static void ShowRoadVehDetailsWindow(const Vehicle* v)
|
||||
{
|
||||
Window *w;
|
||||
VehicleID veh = v->index;
|
||||
|
@ -225,12 +225,11 @@ static void ShowRoadVehDetailsWindow(Vehicle *v)
|
|||
|
||||
void CcCloneRoadVeh(bool success, uint tile, uint32 p1, uint32 p2)
|
||||
{
|
||||
Vehicle *v;
|
||||
if (success) {
|
||||
const Vehicle* v = GetVehicle(_new_aircraft_id);
|
||||
|
||||
if (!success) return;
|
||||
|
||||
v = GetVehicle(_new_roadveh_id);
|
||||
ShowRoadVehViewWindow(v);
|
||||
ShowRoadVehViewWindow(v);
|
||||
}
|
||||
}
|
||||
|
||||
static void RoadVehViewWndProc(Window *w, WindowEvent *e)
|
||||
|
@ -290,9 +289,9 @@ static void RoadVehViewWndProc(Window *w, WindowEvent *e)
|
|||
} break;
|
||||
|
||||
case WE_CLICK: {
|
||||
Vehicle *v = GetVehicle(w->window_number);
|
||||
const Vehicle* v = GetVehicle(w->window_number);
|
||||
|
||||
switch(e->click.widget) {
|
||||
switch (e->click.widget) {
|
||||
case 5: /* start stop */
|
||||
DoCommandP(v->tile, v->index, 0, NULL, CMD_START_STOP_ROADVEH | CMD_MSG(STR_9015_CAN_T_STOP_START_ROAD_VEHICLE));
|
||||
break;
|
||||
|
@ -313,8 +312,6 @@ static void RoadVehViewWndProc(Window *w, WindowEvent *e)
|
|||
break;
|
||||
case 11: {
|
||||
/* clone vehicle */
|
||||
Vehicle *v;
|
||||
v = GetVehicle(w->window_number);
|
||||
DoCommandP(v->tile, v->index, _ctrl_pressed ? 1 : 0, CcCloneRoadVeh, CMD_CLONE_VEHICLE | CMD_MSG(STR_9009_CAN_T_BUILD_ROAD_VEHICLE));
|
||||
} break;
|
||||
}
|
||||
|
@ -372,12 +369,11 @@ static const WindowDesc _roadveh_view_desc = {
|
|||
RoadVehViewWndProc,
|
||||
};
|
||||
|
||||
void ShowRoadVehViewWindow(Vehicle *v)
|
||||
void ShowRoadVehViewWindow(const Vehicle* v)
|
||||
{
|
||||
Window *w;
|
||||
Window* w = AllocateWindowDescFront(&_roadveh_view_desc, v->index);
|
||||
|
||||
w = AllocateWindowDescFront(&_roadveh_view_desc, v->index);
|
||||
if (w) {
|
||||
if (w != NULL) {
|
||||
w->caption_color = v->owner;
|
||||
AssignWindowViewport(w, 3, 17, 0xE2, 0x54, w->window_number | (1 << 31), 0);
|
||||
}
|
||||
|
@ -667,34 +663,22 @@ static void RoadDepotClickVeh(Window *w, int x, int y)
|
|||
* @param *v is the original vehicle to clone
|
||||
* @param *w is the window of the depot where the clone is build
|
||||
*/
|
||||
static bool HandleCloneVehClick(Vehicle *v, Window *w)
|
||||
static void HandleCloneVehClick(const Vehicle* v, const Window* w)
|
||||
{
|
||||
if (v == NULL || v->type != VEH_Road) return;
|
||||
|
||||
if (!v){
|
||||
return false;
|
||||
}
|
||||
|
||||
if (v->type != VEH_Road) {
|
||||
// it's not a road vehicle, do nothing
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
DoCommandP(w->window_number, v->index, _ctrl_pressed ? 1 : 0,CcCloneRoadVeh,CMD_CLONE_VEHICLE | CMD_MSG(STR_9009_CAN_T_BUILD_ROAD_VEHICLE));
|
||||
DoCommandP(w->window_number, v->index, _ctrl_pressed ? 1 : 0, CcCloneRoadVeh,
|
||||
CMD_CLONE_VEHICLE | CMD_MSG(STR_9009_CAN_T_BUILD_ROAD_VEHICLE)
|
||||
);
|
||||
|
||||
ResetObjectToPlace();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void ClonePlaceObj(uint tile, Window *w)
|
||||
static void ClonePlaceObj(TileIndex tile, const Window* w)
|
||||
{
|
||||
Vehicle *v;
|
||||
const Vehicle* v = CheckMouseOverVehicle();
|
||||
|
||||
|
||||
v = CheckMouseOverVehicle();
|
||||
if (v && HandleCloneVehClick(v, w))
|
||||
return;
|
||||
if (v != NULL) HandleCloneVehClick(v, w);
|
||||
}
|
||||
|
||||
static void RoadDepotWndProc(Window *w, WindowEvent *e)
|
||||
|
@ -734,7 +718,7 @@ static void RoadDepotWndProc(Window *w, WindowEvent *e)
|
|||
}
|
||||
} break;
|
||||
|
||||
case WE_PLACE_OBJ: {
|
||||
case WE_PLACE_OBJ: {
|
||||
ClonePlaceObj(e->place.tile, w);
|
||||
} break;
|
||||
|
||||
|
@ -745,11 +729,12 @@ static void RoadDepotWndProc(Window *w, WindowEvent *e)
|
|||
|
||||
// check if a vehicle in a depot was clicked..
|
||||
case WE_MOUSELOOP: {
|
||||
Vehicle *v = _place_clicked_vehicle;
|
||||
// since OTTD checks all open depot windows, we will make sure that it triggers the one with a clicked clone button
|
||||
const Vehicle* v = _place_clicked_vehicle;
|
||||
|
||||
// since OTTD checks all open depot windows, we will make sure that it triggers the one with a clicked clone button
|
||||
if (v != NULL && HASBIT(w->click_state, 8)) {
|
||||
_place_clicked_vehicle = NULL;
|
||||
HandleCloneVehClick( v, w);
|
||||
HandleCloneVehClick(v, w);
|
||||
}
|
||||
} break;
|
||||
|
||||
|
|
58
ship_gui.c
58
ship_gui.c
|
@ -138,7 +138,7 @@ static const WindowDesc _ship_refit_desc = {
|
|||
ShipRefitWndProc,
|
||||
};
|
||||
|
||||
static void ShowShipRefitWindow(Vehicle *v)
|
||||
static void ShowShipRefitWindow(const Vehicle* v)
|
||||
{
|
||||
Window *w;
|
||||
|
||||
|
@ -287,7 +287,7 @@ static const WindowDesc _ship_details_desc = {
|
|||
ShipDetailsWndProc
|
||||
};
|
||||
|
||||
static void ShowShipDetailsWindow(Vehicle *v)
|
||||
static void ShowShipDetailsWindow(const Vehicle* v)
|
||||
{
|
||||
Window *w;
|
||||
VehicleID veh = v->index;
|
||||
|
@ -314,11 +314,11 @@ void CcBuildShip(bool success, TileIndex tile, uint32 p1, uint32 p2)
|
|||
|
||||
void CcCloneShip(bool success, uint tile, uint32 p1, uint32 p2)
|
||||
{
|
||||
Vehicle *v;
|
||||
if (!success) return;
|
||||
if (success) {
|
||||
const Vehicle* v = GetVehicle(_new_aircraft_id);
|
||||
|
||||
v = GetVehicle(_new_ship_id);
|
||||
ShowShipViewWindow(v);
|
||||
ShowShipViewWindow(v);
|
||||
}
|
||||
}
|
||||
|
||||
static void NewShipWndProc(Window *w, WindowEvent *e)
|
||||
|
@ -528,9 +528,9 @@ static void ShipViewWndProc(Window *w, WindowEvent *e) {
|
|||
} break;
|
||||
|
||||
case WE_CLICK: {
|
||||
Vehicle *v = GetVehicle(w->window_number);
|
||||
const Vehicle* v = GetVehicle(w->window_number);
|
||||
|
||||
switch(e->click.widget) {
|
||||
switch (e->click.widget) {
|
||||
case 5: /* start stop */
|
||||
DoCommandP(v->tile, v->index, 0, NULL, CMD_START_STOP_SHIP | CMD_MSG(STR_9818_CAN_T_STOP_START_SHIP));
|
||||
break;
|
||||
|
@ -551,8 +551,6 @@ static void ShipViewWndProc(Window *w, WindowEvent *e) {
|
|||
break;
|
||||
case 11: {
|
||||
/* clone vehicle */
|
||||
Vehicle *v;
|
||||
v = GetVehicle(w->window_number);
|
||||
DoCommandP(v->tile, v->index, _ctrl_pressed ? 1 : 0, CcCloneShip, CMD_CLONE_VEHICLE | CMD_MSG(STR_980D_CAN_T_BUILD_SHIP));
|
||||
} break;
|
||||
}
|
||||
|
@ -611,12 +609,11 @@ static const WindowDesc _ship_view_desc = {
|
|||
ShipViewWndProc
|
||||
};
|
||||
|
||||
void ShowShipViewWindow(Vehicle *v)
|
||||
void ShowShipViewWindow(const Vehicle* v)
|
||||
{
|
||||
Window *w;
|
||||
Window* w = AllocateWindowDescFront(&_ship_view_desc, v->index);
|
||||
|
||||
w = AllocateWindowDescFront(&_ship_view_desc, v->index);
|
||||
if (w) {
|
||||
if (w != NULL) {
|
||||
w->caption_color = v->owner;
|
||||
AssignWindowViewport(w, 3, 17, 0xE2, 0x54, w->window_number | (1 << 31), 0);
|
||||
}
|
||||
|
@ -745,34 +742,22 @@ static void ShipDepotClick(Window *w, int x, int y)
|
|||
* @param *v is the original vehicle to clone
|
||||
* @param *w is the window of the depot where the clone is build
|
||||
*/
|
||||
static bool HandleCloneVehClick(Vehicle *v, Window *w)
|
||||
static void HandleCloneVehClick(const Vehicle* v, const Window* w)
|
||||
{
|
||||
if (v == NULL || v->type != VEH_Ship) return;
|
||||
|
||||
if (!v){
|
||||
return false;
|
||||
}
|
||||
|
||||
if (v->type != VEH_Ship) {
|
||||
// it's not a ship, do nothing
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
DoCommandP(w->window_number, v->index, _ctrl_pressed ? 1 : 0,CcCloneShip,CMD_CLONE_VEHICLE | CMD_MSG(STR_980D_CAN_T_BUILD_SHIP));
|
||||
DoCommandP(w->window_number, v->index, _ctrl_pressed ? 1 : 0, CcCloneShip,
|
||||
CMD_CLONE_VEHICLE | CMD_MSG(STR_980D_CAN_T_BUILD_SHIP)
|
||||
);
|
||||
|
||||
ResetObjectToPlace();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void ClonePlaceObj(uint tile, Window *w)
|
||||
static void ClonePlaceObj(TileIndex tile, const Window* w)
|
||||
{
|
||||
Vehicle *v;
|
||||
Vehicle* v = CheckMouseOverVehicle();
|
||||
|
||||
|
||||
v = CheckMouseOverVehicle();
|
||||
if (v && HandleCloneVehClick(v, w))
|
||||
return;
|
||||
if (v != NULL) HandleCloneVehClick(v, w);
|
||||
}
|
||||
|
||||
static void ShipDepotWndProc(Window *w, WindowEvent *e) {
|
||||
|
@ -812,7 +797,6 @@ static void ShipDepotWndProc(Window *w, WindowEvent *e) {
|
|||
break;
|
||||
|
||||
case WE_PLACE_OBJ: {
|
||||
//ClonePlaceObj(e->place.tile, w);
|
||||
ClonePlaceObj(w->window_number, w);
|
||||
} break;
|
||||
|
||||
|
@ -823,9 +807,9 @@ static void ShipDepotWndProc(Window *w, WindowEvent *e) {
|
|||
|
||||
// check if a vehicle in a depot was clicked..
|
||||
case WE_MOUSELOOP: {
|
||||
Vehicle *v = _place_clicked_vehicle;
|
||||
const Vehicle* v = _place_clicked_vehicle;
|
||||
|
||||
// since OTTD checks all open depot windows, we will make sure that it triggers the one with a clicked clone button
|
||||
// since OTTD checks all open depot windows, we will make sure that it triggers the one with a clicked clone button
|
||||
if (v != NULL && HASBIT(w->click_state, 8)) {
|
||||
_place_clicked_vehicle = NULL;
|
||||
HandleCloneVehClick(v, w);
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "openttd.h"
|
||||
#include "debug.h"
|
||||
#include "functions.h"
|
||||
#include "gui.h"
|
||||
#include "table/strings.h"
|
||||
#include "map.h"
|
||||
#include "tile.h"
|
||||
|
@ -27,7 +28,6 @@
|
|||
|
||||
static bool TrainCheckIfLineEnds(Vehicle *v);
|
||||
static void TrainController(Vehicle *v);
|
||||
extern void ShowTrainViewWindow(Vehicle *v);
|
||||
|
||||
static const byte _vehicle_initial_x_fract[4] = {10,8,4,8};
|
||||
static const byte _vehicle_initial_y_fract[4] = {8,4,8,10};
|
||||
|
|
61
train_gui.c
61
train_gui.c
|
@ -163,13 +163,11 @@ void CcBuildLoco(bool success, TileIndex tile, uint32 p1, uint32 p2)
|
|||
|
||||
void CcCloneTrain(bool success, uint tile, uint32 p1, uint32 p2)
|
||||
{
|
||||
Vehicle *v;
|
||||
if (success) {
|
||||
const Vehicle* v = GetVehicle(_new_aircraft_id);
|
||||
|
||||
if (!success)
|
||||
return;
|
||||
|
||||
v = GetVehicle(_new_train_id);
|
||||
ShowTrainViewWindow(v);
|
||||
ShowTrainViewWindow(v);
|
||||
}
|
||||
}
|
||||
|
||||
static void engine_drawing_loop(int *x, int *y, int *pos, int *sel,
|
||||
|
@ -604,40 +602,29 @@ static void TrainDepotClickTrain(Window *w, int x, int y)
|
|||
* @param *v is the original vehicle to clone
|
||||
* @param *w is the window of the depot where the clone is build
|
||||
*/
|
||||
static bool HandleCloneVehClick(Vehicle *v, Window *w)
|
||||
static void HandleCloneVehClick(const Vehicle* v, const Window* w)
|
||||
{
|
||||
|
||||
if (!v){
|
||||
return false;
|
||||
}
|
||||
if (v == NULL || v->type != VEH_Train) return;
|
||||
|
||||
// for train vehicles: subtype 0 for locs and not zero for others
|
||||
if (v->type == VEH_Train && v->subtype != 0) {
|
||||
if (v->subtype != TS_Front_Engine) {
|
||||
v = GetFirstVehicleInChain(v);
|
||||
if (v->subtype != 0) // This happens when clicking on a train in depot with no loc attached
|
||||
return false;
|
||||
}else{
|
||||
if (v->type != VEH_Train) {
|
||||
// it's not a train, Do Nothing
|
||||
return false;
|
||||
}
|
||||
// Do nothing when clicking on a train in depot with no loc attached
|
||||
if (v->subtype != TS_Front_Engine) return;
|
||||
}
|
||||
|
||||
DoCommandP(w->window_number, v->index, _ctrl_pressed ? 1 : 0, CcCloneTrain, CMD_CLONE_VEHICLE | CMD_MSG(STR_882B_CAN_T_BUILD_RAILROAD_VEHICLE));
|
||||
DoCommandP(w->window_number, v->index, _ctrl_pressed ? 1 : 0, CcCloneTrain,
|
||||
CMD_CLONE_VEHICLE | CMD_MSG(STR_882B_CAN_T_BUILD_RAILROAD_VEHICLE)
|
||||
);
|
||||
|
||||
ResetObjectToPlace();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void ClonePlaceObj(uint tile, Window *w)
|
||||
static void ClonePlaceObj(TileIndex tile, const Window* w)
|
||||
{
|
||||
Vehicle *v;
|
||||
Vehicle* v = CheckMouseOverVehicle();
|
||||
|
||||
|
||||
v = CheckMouseOverVehicle();
|
||||
if (v && HandleCloneVehClick(v, w))
|
||||
return;
|
||||
if (v != NULL) HandleCloneVehClick(v, w);
|
||||
}
|
||||
|
||||
static void TrainDepotWndProc(Window *w, WindowEvent *e)
|
||||
|
@ -686,11 +673,12 @@ static void TrainDepotWndProc(Window *w, WindowEvent *e)
|
|||
|
||||
// check if a vehicle in a depot was clicked..
|
||||
case WE_MOUSELOOP: {
|
||||
Vehicle *v = _place_clicked_vehicle;
|
||||
// since OTTD checks all open depot windows, we will make sure that it triggers the one with a clicked clone button
|
||||
const Vehicle* v = _place_clicked_vehicle;
|
||||
|
||||
// since OTTD checks all open depot windows, we will make sure that it triggers the one with a clicked clone button
|
||||
if (v != NULL && HASBIT(w->click_state, 9)) {
|
||||
_place_clicked_vehicle = NULL;
|
||||
HandleCloneVehClick( v, w);
|
||||
HandleCloneVehClick(v, w);
|
||||
}
|
||||
} break;
|
||||
|
||||
|
@ -907,6 +895,8 @@ static const Widget _train_view_widgets[] = {
|
|||
{ WIDGETS_END }
|
||||
};
|
||||
|
||||
static void ShowTrainDetailsWindow(const Vehicle* v);
|
||||
|
||||
static void TrainViewWndProc(Window *w, WindowEvent *e)
|
||||
{
|
||||
switch (e->event) {
|
||||
|
@ -1063,12 +1053,11 @@ static const WindowDesc _train_view_desc = {
|
|||
TrainViewWndProc
|
||||
};
|
||||
|
||||
void ShowTrainViewWindow(Vehicle *v)
|
||||
void ShowTrainViewWindow(const Vehicle* v)
|
||||
{
|
||||
Window *w;
|
||||
Window* w = AllocateWindowDescFront(&_train_view_desc,v->index);
|
||||
|
||||
w = AllocateWindowDescFront(&_train_view_desc,v->index);
|
||||
if (w) {
|
||||
if (w != NULL) {
|
||||
w->caption_color = v->owner;
|
||||
AssignWindowViewport(w, 3, 17, 0xE2, 0x66, w->window_number | (1 << 31), 0);
|
||||
}
|
||||
|
@ -1320,7 +1309,7 @@ static const WindowDesc _train_details_desc = {
|
|||
};
|
||||
|
||||
|
||||
void ShowTrainDetailsWindow(Vehicle *v)
|
||||
static void ShowTrainDetailsWindow(const Vehicle* v)
|
||||
{
|
||||
Window *w;
|
||||
VehicleID veh = v->index;
|
||||
|
|
Loading…
Reference in New Issue