(svn r6372) -Codechange: static, unneeded decleration in headers, superfluous header includes

-Codechange: Unify the Sorting struct both for vehicle-lists and network-lists.
This commit is contained in:
Darkvater 2006-09-03 23:27:38 +00:00
parent e42d819b6a
commit 794cc6d55e
4 changed files with 43 additions and 53 deletions

View File

@ -47,13 +47,8 @@ typedef struct network_ql_d {
} network_ql_d; } network_ql_d;
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(network_ql_d)); assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(network_ql_d));
typedef struct NetworkGameSorting {
bool order; // Ascending / Descending
byte criteria; // Sorted by name/clients/connectivity
} NetworkGameSorting;
/* Global to remember sorting after window has been closed */ /* Global to remember sorting after window has been closed */
static NetworkGameSorting _ng_sorting; static Listing _ng_sorting;
static char _edit_str_buf[64]; static char _edit_str_buf[64];
static bool _chat_tab_completion_active; static bool _chat_tab_completion_active;

View File

@ -28,7 +28,23 @@
#include "roadveh.h" #include "roadveh.h"
#include "depot.h" #include "depot.h"
Sorting _sorting; typedef struct Sorting {
Listing aircraft;
Listing roadveh;
Listing ship;
Listing train;
} Sorting;
static Sorting _sorting;
typedef struct vehiclelist_d {
const Vehicle** sort_list; // list of vehicles (sorted)
uint16 list_length;
byte sort_type;
SortListFlags flags;
uint16 resort_timer;
} vehiclelist_d;
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(vehiclelist_d));
static uint32 _internal_name_sorter_id; // internal StringID for default vehicle-names static uint32 _internal_name_sorter_id; // internal StringID for default vehicle-names
static const Vehicle* _last_vehicle; // cached vehicle to hopefully speed up name-sorting static const Vehicle* _last_vehicle; // cached vehicle to hopefully speed up name-sorting
@ -1074,7 +1090,7 @@ static const WindowDesc _replace_ship_aircraft_vehicle_desc = {
}; };
void ShowReplaceVehicleWindow(byte vehicletype) static void ShowReplaceVehicleWindow(byte vehicletype)
{ {
Window *w; Window *w;
@ -1100,8 +1116,9 @@ void ShowReplaceVehicleWindow(byte vehicletype)
break; break;
default: return; default: return;
} }
w->caption_color = _local_player; w->caption_color = _local_player;
WP(w,replaceveh_d).vehicletype = vehicletype; WP(w, replaceveh_d).vehicletype = vehicletype;
w->vscroll2.cap = w->vscroll.cap; // these two are always the same w->vscroll2.cap = w->vscroll.cap; // these two are always the same
} }
@ -1153,7 +1170,6 @@ void ChangeVehicleViewWindow(const Vehicle *from_v, const Vehicle *to_v)
* 11-15 vehicle type (using VEH_, but can be compressed to fewer bytes if needed) * 11-15 vehicle type (using VEH_, but can be compressed to fewer bytes if needed)
* 16-31 StationID or OrderID depending on window type (bit 8-10) * 16-31 StationID or OrderID depending on window type (bit 8-10)
**/ **/
void PlayerVehWndProc(Window *w, WindowEvent *e) void PlayerVehWndProc(Window *w, WindowEvent *e)
{ {
vehiclelist_d *vl = &WP(w, vehiclelist_d); vehiclelist_d *vl = &WP(w, vehiclelist_d);
@ -1237,10 +1253,9 @@ void PlayerVehWndProc(Window *w, WindowEvent *e)
max = min(w->vscroll.pos + w->vscroll.cap, vl->list_length); max = min(w->vscroll.pos + w->vscroll.cap, vl->list_length);
for (i = w->vscroll.pos; i < max; ++i) { for (i = w->vscroll.pos; i < max; ++i) {
const Vehicle* v = vl->sort_list[i]; const Vehicle *v = vl->sort_list[i];
StringID str; StringID str = (v->age > v->max_age - 366) ? STR_00E3 : STR_00E2;
str = v->age > v->max_age - 366 ? STR_00E3 : STR_00E2;
SetDParam(0, v->profit_this_year); SetDParam(0, v->profit_this_year);
SetDParam(1, v->profit_last_year); SetDParam(1, v->profit_last_year);
switch (vehicle_type) { switch (vehicle_type) {
@ -1248,6 +1263,7 @@ void PlayerVehWndProc(Window *w, WindowEvent *e)
DrawTrainImage(v, x + 21, y + 6, w->hscroll.cap, 0, INVALID_VEHICLE); DrawTrainImage(v, x + 21, y + 6, w->hscroll.cap, 0, INVALID_VEHICLE);
DrawString(x + 21, y + 18, STR_0198_PROFIT_THIS_YEAR_LAST_YEAR, 0); DrawString(x + 21, y + 18, STR_0198_PROFIT_THIS_YEAR_LAST_YEAR, 0);
if (IsTileDepotType(v->tile, TRANSPORT_RAIL) && (v->vehstatus & VS_HIDDEN)) str = STR_021F; if (IsTileDepotType(v->tile, TRANSPORT_RAIL) && (v->vehstatus & VS_HIDDEN)) str = STR_021F;
if (v->string_id != STR_SV_TRAIN_NAME) { if (v->string_id != STR_SV_TRAIN_NAME) {
SetDParam(0, v->string_id); SetDParam(0, v->string_id);
DrawString(x + 21, y, STR_01AB, 0); DrawString(x + 21, y, STR_01AB, 0);
@ -1257,6 +1273,7 @@ void PlayerVehWndProc(Window *w, WindowEvent *e)
DrawRoadVehImage(v, x + 22, y + 6, INVALID_VEHICLE); DrawRoadVehImage(v, x + 22, y + 6, INVALID_VEHICLE);
DrawString(x + 24, y + 18, STR_0198_PROFIT_THIS_YEAR_LAST_YEAR, 0); DrawString(x + 24, y + 18, STR_0198_PROFIT_THIS_YEAR_LAST_YEAR, 0);
if (IsRoadVehInDepot(v)) str = STR_021F; if (IsRoadVehInDepot(v)) str = STR_021F;
if (v->string_id != STR_SV_ROADVEH_NAME) { if (v->string_id != STR_SV_ROADVEH_NAME) {
SetDParam(0, v->string_id); SetDParam(0, v->string_id);
DrawString(x + 24, y, STR_01AB, 0); DrawString(x + 24, y, STR_01AB, 0);
@ -1266,21 +1283,25 @@ void PlayerVehWndProc(Window *w, WindowEvent *e)
DrawShipImage(v, x + 19, y + 6, INVALID_VEHICLE); DrawShipImage(v, x + 19, y + 6, INVALID_VEHICLE);
DrawString(x + 12, y + 28, STR_0198_PROFIT_THIS_YEAR_LAST_YEAR, 0); DrawString(x + 12, y + 28, STR_0198_PROFIT_THIS_YEAR_LAST_YEAR, 0);
if (IsShipInDepot(v)) str = STR_021F; if (IsShipInDepot(v)) str = STR_021F;
if (v->string_id != STR_SV_SHIP_NAME) { if (v->string_id != STR_SV_SHIP_NAME) {
SetDParam(0, v->string_id); SetDParam(0, v->string_id);
DrawString(x + 12, y, STR_01AB, 0); DrawString(x + 12, y, STR_01AB, 0);
} }
DrawSmallOrderListShip(v, x + 138, y); DrawSmallOrderListShip(v, x + 138, y);
break; break;
case VEH_Aircraft: case VEH_Aircraft:
DrawAircraftImage(v, x + 19, y + 6, INVALID_VEHICLE); DrawAircraftImage(v, x + 19, y + 6, INVALID_VEHICLE);
DrawString(x + 19, y + 28, STR_0198_PROFIT_THIS_YEAR_LAST_YEAR, 0); DrawString(x + 19, y + 28, STR_0198_PROFIT_THIS_YEAR_LAST_YEAR, 0);
if (IsAircraftInHangar(v)) str = STR_021F; if (IsAircraftInHangar(v)) str = STR_021F;
if (v->string_id != STR_SV_AIRCRAFT_NAME) { if (v->string_id != STR_SV_AIRCRAFT_NAME) {
SetDParam(0, v->string_id); SetDParam(0, v->string_id);
DrawString(x + 19, y, STR_01AB, 0); DrawString(x + 19, y, STR_01AB, 0);
} }
DrawSmallOrderListAircraft(v, x + 136, y); DrawSmallOrderListAircraft(v, x + 136, y);
break; break;
default: NOT_REACHED(); break; default: NOT_REACHED(); break;
} }
@ -1414,8 +1435,7 @@ void PlayerVehWndProc(Window *w, WindowEvent *e)
} }
break; break;
case WE_RESIZE: case WE_RESIZE: /* Update the scroll + matrix */
/* Update the scroll + matrix */
if (vehicle_type == VEH_Train) w->hscroll.cap += e->sizing.diff.x; if (vehicle_type == VEH_Train) w->hscroll.cap += e->sizing.diff.x;
w->vscroll.cap += e->sizing.diff.y / (int)w->resize.step_height; w->vscroll.cap += e->sizing.diff.y / (int)w->resize.step_height;
w->widget[7].unkA = (w->vscroll.cap << 8) + 1; w->widget[7].unkA = (w->vscroll.cap << 8) + 1;

View File

@ -3,12 +3,8 @@
#ifndef VEHICLE_GUI_H #ifndef VEHICLE_GUI_H
#define VEHICLE_GUI_H #define VEHICLE_GUI_H
#include "station.h"
#include "vehicle.h"
#include "window.h" #include "window.h"
struct vehiclelist_d;
void DrawVehicleProfitButton(const Vehicle *v, int x, int y); void DrawVehicleProfitButton(const Vehicle *v, int x, int y);
CargoID DrawVehicleRefitWindow(const Vehicle *v, int sel); CargoID DrawVehicleRefitWindow(const Vehicle *v, int sel);
void InitializeVehiclesGuiList(void); void InitializeVehiclesGuiList(void);
@ -19,20 +15,6 @@ void ResortVehicleLists(void);
#define PERIODIC_RESORT_DAYS 10 #define PERIODIC_RESORT_DAYS 10
typedef struct Listing {
bool order; // Ascending/descending?
byte criteria; // Sorting criteria
} Listing;
typedef struct Sorting {
Listing aircraft;
Listing roadveh;
Listing ship;
Listing train;
} Sorting;
extern Sorting _sorting;
enum { enum {
PLY_WND_PRC__OFFSET_TOP_WIDGET = 26, PLY_WND_PRC__OFFSET_TOP_WIDGET = 26,
PLY_WND_PRC__SIZE_OF_ROW_SMALL = 26, PLY_WND_PRC__SIZE_OF_ROW_SMALL = 26,
@ -54,8 +36,6 @@ static inline bool ValidVLWFlags(uint16 flags)
void PlayerVehWndProc(Window *w, WindowEvent *e); void PlayerVehWndProc(Window *w, WindowEvent *e);
void ShowReplaceVehicleWindow(byte vehicletype);
void DrawTrainEnginePurchaseInfo(int x, int y, EngineID engine_number); void DrawTrainEnginePurchaseInfo(int x, int y, EngineID engine_number);
void DrawTrainWagonPurchaseInfo(int x, int y, EngineID engine_number); void DrawTrainWagonPurchaseInfo(int x, int y, EngineID engine_number);
void DrawRoadVehPurchaseInfo(int x, int y, EngineID engine_number); void DrawRoadVehPurchaseInfo(int x, int y, EngineID engine_number);
@ -66,17 +46,16 @@ void DrawTrainImage(const Vehicle *v, int x, int y, int count, int skip, Vehicle
void DrawRoadVehImage(const Vehicle *v, int x, int y, VehicleID selection); void DrawRoadVehImage(const Vehicle *v, int x, int y, VehicleID selection);
void DrawShipImage(const Vehicle *v, int x, int y, VehicleID selection); void DrawShipImage(const Vehicle *v, int x, int y, VehicleID selection);
void DrawSmallOrderListShip(const Vehicle *v, int x, int y); void DrawSmallOrderListShip(const Vehicle *v, int x, int y);
void DrawAircraftImage(const Vehicle *v, int x, int y, VehicleID selection);
void DrawSmallOrderListAircraft(const Vehicle *v, int x, int y);
void ShowBuildTrainWindow(TileIndex tile); void ShowBuildTrainWindow(TileIndex tile);
void ShowBuildRoadVehWindow(TileIndex tile); void ShowBuildRoadVehWindow(TileIndex tile);
void ShowBuildShipWindow(TileIndex tile); void ShowBuildShipWindow(TileIndex tile);
void ShowBuildAircraftWindow(TileIndex tile); void ShowBuildAircraftWindow(TileIndex tile);
void DrawAircraftImage(const Vehicle *v, int x, int y, VehicleID selection);
void DrawSmallOrderListAircraft(const Vehicle *v, int x, int y);
void ChangeVehicleViewWindow(const Vehicle *from_v, const Vehicle *to_v); void ChangeVehicleViewWindow(const Vehicle *from_v, const Vehicle *to_v);
int ShowAdditionalText(int x, int y, int w, EngineID engine_number); int ShowAdditionalText(int x, int y, int w, EngineID engine);
#endif /* VEHICLE_GUI_H */ #endif /* VEHICLE_GUI_H */

View File

@ -449,26 +449,22 @@ typedef struct {
} scroller_d; } scroller_d;
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(scroller_d)); assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(scroller_d));
typedef enum VehicleListFlags { typedef enum SortListFlags {
VL_DESC = 0x01, // sort descending or ascending VL_DESC = 0x01, // sort descending or ascending
VL_RESORT = 0x02, // instruct the code to resort the list in the next loop VL_RESORT = 0x02, // instruct the code to resort the list in the next loop
VL_REBUILD = 0x04 // create sort-listing to use for qsort and friends VL_REBUILD = 0x04 // create sort-listing to use for qsort and friends
} VehicleListFlags; } SortListFlags;
typedef struct vehiclelist_d { typedef struct Listing {
const Vehicle** sort_list; bool order; // Ascending/descending
uint16 list_length; byte criteria; // Sorting criteria
byte sort_type; } Listing;
VehicleListFlags flags;
uint16 resort_timer;
} vehiclelist_d;
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(vehiclelist_d));
typedef struct list_d { typedef struct list_d {
uint16 list_length; // length of the list being sorted uint16 list_length; // length of the list being sorted
byte sort_type; // what criteria to sort on byte sort_type; // what criteria to sort on
VehicleListFlags flags;// used to control sorting/resorting/etc. SortListFlags flags; // used to control sorting/resorting/etc.
uint16 resort_timer; // resort list after a given amount of ticks if set uint16 resort_timer; // resort list after a given amount of ticks if set
} list_d; } list_d;
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(list_d)); assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(list_d));