Changeset - r9182:0d593e61d67e
[Not reviewed]
master
0 5 0
rubidium - 17 years ago 2008-05-11 14:23:45
rubidium@openttd.org
(svn r13045) -Codechange: make list_d (now GUIList) more generic and uniform.
5 files changed with 177 insertions and 188 deletions:
0 comments (0 inline, 0 general)
src/group_gui.cpp
Show inline comments
 
@@ -25,59 +25,45 @@
 
#include "widgets/dropdown_func.h"
 
#include "tilehighlight_func.h"
 

	
 
#include "table/strings.h"
 
#include "table/sprites.h"
 

	
 
struct grouplist_d {
 
	const Group **sort_list;
 
	list_d l;                   // General list struct
 
};
 
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(grouplist_d));
 
typedef GUIList<const Group*> GUIGroupList;
 

	
 
struct groupveh_d : vehiclelist_d {
 
	GroupID group_sel;
 
	VehicleID vehicle_sel;
 

	
 
	grouplist_d gl;
 
	GUIGroupList groups;
 
};
 
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(groupveh_d));
 

	
 
struct Sorting {
 
	Listing aircraft;
 
	Listing roadveh;
 
	Listing ship;
 
	Listing train;
 
};
 

	
 
static Sorting _sorting;
 
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(vehiclelist_d));
 

	
 

	
 
static void BuildGroupList(grouplist_d* gl, PlayerID owner, VehicleType vehicle_type)
 
static void BuildGroupList(GUIGroupList *gl, PlayerID owner, VehicleType vehicle_type)
 
{
 
	const Group** list;
 
	const Group *g;
 
	uint n = 0;
 

	
 
	if (!(gl->l.flags & VL_REBUILD)) return;
 
	if (!(gl->flags & VL_REBUILD)) return;
 

	
 
	list = MallocT<const Group*>(GetGroupArraySize());
 
	const Group **list = MallocT<const Group*>(GetGroupArraySize());
 

	
 
	const Group *g;
 
	FOR_ALL_GROUPS(g) {
 
		if (g->owner == owner && g->vehicle_type == vehicle_type) list[n++] = g;
 
	}
 

	
 
	free((void*)gl->sort_list);
 
	gl->sort_list = MallocT<const Group *>(n);
 
	gl->l.list_length = n;
 
	gl->sort_list = ReallocT(gl->sort_list, n);
 
	gl->list_length = n;
 

	
 
	for (uint i = 0; i < n; ++i) gl->sort_list[i] = list[i];
 
	free((void*)list);
 
	free(list);
 

	
 
	gl->l.flags &= ~VL_REBUILD;
 
	gl->l.flags |= VL_RESORT;
 
	gl->flags &= ~VL_REBUILD;
 
	gl->flags |= VL_RESORT;
 
}
 

	
 

	
 
static int CDECL GroupNameSorter(const void *a, const void *b)
 
{
 
	static const Group *last_group[2] = { NULL, NULL };
 
@@ -104,20 +90,20 @@ static int CDECL GroupNameSorter(const v
 
	if (r == 0) return ga->index - gb->index;
 

	
 
	return r;
 
}
 

	
 

	
 
static void SortGroupList(grouplist_d *gl)
 
static void SortGroupList(GUIGroupList *gl)
 
{
 
	if (!(gl->l.flags & VL_RESORT)) return;
 
	if (!(gl->flags & VL_RESORT)) return;
 

	
 
	qsort((void*)gl->sort_list, gl->l.list_length, sizeof(gl->sort_list[0]), GroupNameSorter);
 
	qsort((void*)gl->sort_list, gl->list_length, sizeof(gl->sort_list[0]), GroupNameSorter);
 

	
 
	gl->l.resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS;
 
	gl->l.flags &= ~VL_RESORT;
 
	gl->resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS;
 
	gl->flags &= ~VL_RESORT;
 
}
 

	
 

	
 
enum GroupListWidgets {
 
	GRP_WIDGET_CLOSEBOX = 0,
 
	GRP_WIDGET_CAPTION,
 
@@ -177,14 +163,15 @@ static const Widget _group_widgets[] = {
 
};
 

	
 

	
 
static void CreateVehicleGroupWindow(Window *w)
 
{
 
	const PlayerID owner = (PlayerID)GB(w->window_number, 0, 8);
 
	groupveh_d *gv = &WP(w, groupveh_d);
 
	grouplist_d *gl = &WP(w, groupveh_d).gl;
 
	groupveh_d     *gv = &WP(w, groupveh_d);
 
	GUIVehicleList *vl = &gv->vehicles;
 
	GUIGroupList   *gl = &gv->groups;
 

	
 
	w->caption_color = owner;
 
	w->hscroll.cap = 224;
 
	w->resize.step_width = 1;
 

	
 
	switch (gv->vehicle_type) {
 
@@ -205,27 +192,28 @@ static void CreateVehicleGroupWindow(Win
 

	
 
	w->widget[GRP_WIDGET_LIST_GROUP].data = (w->vscroll.cap << 8) + 1;
 
	w->widget[GRP_WIDGET_LIST_VEHICLE].data = (w->vscroll2.cap << 8) + 1;
 

	
 
	switch (gv->vehicle_type) {
 
		default: NOT_REACHED();
 
		case VEH_TRAIN:    gv->_sorting = &_sorting.train;    break;
 
		case VEH_ROAD:     gv->_sorting = &_sorting.roadveh;  break;
 
		case VEH_SHIP:     gv->_sorting = &_sorting.ship;     break;
 
		case VEH_AIRCRAFT: gv->_sorting = &_sorting.aircraft; break;
 
		case VEH_TRAIN:    gv->sorting = &_sorting.train;    break;
 
		case VEH_ROAD:     gv->sorting = &_sorting.roadveh;  break;
 
		case VEH_SHIP:     gv->sorting = &_sorting.ship;     break;
 
		case VEH_AIRCRAFT: gv->sorting = &_sorting.aircraft; break;
 
	}
 

	
 
	gv->sort_list = NULL;
 
	gv->vehicle_type = (VehicleType)GB(w->window_number, 11, 5);
 
	gv->l.sort_type = gv->_sorting->criteria;
 
	gv->l.flags = VL_REBUILD | (gv->_sorting->order ? VL_DESC : VL_NONE);
 
	gv->l.resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS; // Set up resort timer
 

	
 
	vl->sort_list = NULL;
 
	vl->sort_type = gv->sorting->criteria;
 
	vl->flags = VL_REBUILD | (gv->sorting->order ? VL_DESC : VL_NONE);
 
	vl->resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS; // Set up resort timer
 

	
 
	gl->sort_list = NULL;
 
	gl->l.flags = VL_REBUILD | VL_NONE;
 
	gl->l.resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS; // Set up resort timer
 
	gl->flags = VL_REBUILD | VL_NONE;
 
	gl->resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS; // Set up resort timer
 

	
 
	gv->group_sel = ALL_GROUP;
 
	gv->vehicle_sel = INVALID_VEHICLE;
 

	
 
	switch (gv->vehicle_type) {
 
		case VEH_TRAIN:
 
@@ -302,21 +290,22 @@ static void ShowGroupActionDropdown(Wind
 
 * 0-7   PlayerID (owner)
 
 * 11-15 vehicle type
 
 **/
 
static void GroupWndProc(Window *w, WindowEvent *e)
 
{
 
	const PlayerID owner = (PlayerID)GB(w->window_number, 0, 8);
 
	groupveh_d *gv = &WP(w, groupveh_d);
 
	grouplist_d *gl = &WP(w, groupveh_d).gl;
 
	groupveh_d     *gv = &WP(w, groupveh_d);
 
	GUIVehicleList *vl = &gv->vehicles;
 
	GUIGroupList   *gl = &gv->groups;
 

	
 
	gv->vehicle_type = (VehicleType)GB(w->window_number, 11, 5);
 

	
 
	switch(e->event) {
 
		case WE_INVALIDATE_DATA:
 
			gv->l.flags |= VL_REBUILD;
 
			gl->l.flags |= VL_REBUILD;
 
			vl->flags |= VL_REBUILD;
 
			gl->flags |= VL_REBUILD;
 
			if (!(IsAllGroupID(gv->group_sel) || IsDefaultGroupID(gv->group_sel) || IsValidGroupID(gv->group_sel))) {
 
				gv->group_sel = ALL_GROUP;
 
				HideDropDownMenu(w);
 
			}
 
			w->SetDirty();
 
			break;
 
@@ -338,23 +327,23 @@ static void GroupWndProc(Window *w, Wind
 
			SortVehicleList(gv);
 

	
 

	
 
			BuildGroupList(gl, owner, gv->vehicle_type);
 
			SortGroupList(gl);
 

	
 
			SetVScrollCount(w, gl->l.list_length);
 
			SetVScroll2Count(w, gv->l.list_length);
 
			SetVScrollCount(w, gl->list_length);
 
			SetVScroll2Count(w, vl->list_length);
 

	
 
			/* The drop down menu is out, *but* it may not be used, retract it. */
 
			if (gv->l.list_length == 0 && w->IsWidgetLowered(GRP_WIDGET_MANAGE_VEHICLES_DROPDOWN)) {
 
			if (vl->list_length == 0 && w->IsWidgetLowered(GRP_WIDGET_MANAGE_VEHICLES_DROPDOWN)) {
 
				w->RaiseWidget(GRP_WIDGET_MANAGE_VEHICLES_DROPDOWN);
 
				HideDropDownMenu(w);
 
			}
 

	
 
			/* Disable all lists management button when the list is empty */
 
			w->SetWidgetsDisabledState(gv->l.list_length == 0 || _local_player != owner,
 
			w->SetWidgetsDisabledState(vl->list_length == 0 || _local_player != owner,
 
					GRP_WIDGET_STOP_ALL,
 
					GRP_WIDGET_START_ALL,
 
					GRP_WIDGET_MANAGE_VEHICLES_DROPDOWN,
 
					WIDGET_LIST_END);
 

	
 
			/* Disable the group specific function when we select the default group or all vehicles */
 
@@ -377,13 +366,13 @@ static void GroupWndProc(Window *w, Wind
 

	
 

	
 
			/* If selected_group == DEFAULT_GROUP || ALL_GROUP, draw the standard caption
 
			   We list all vehicles or ungrouped vehicles */
 
			if (IsDefaultGroupID(gv->group_sel) || IsAllGroupID(gv->group_sel)) {
 
				SetDParam(0, owner);
 
				SetDParam(1, gv->l.list_length);
 
				SetDParam(1, vl->list_length);
 

	
 
				switch (gv->vehicle_type) {
 
					case VEH_TRAIN:
 
						w->widget[GRP_WIDGET_CAPTION].data = STR_881B_TRAINS;
 
						w->widget[GRP_WIDGET_REPLACE_PROTECTION].data = SPR_GROUP_REPLACE_OFF_TRAIN;
 
						break;
 
@@ -426,13 +415,13 @@ static void GroupWndProc(Window *w, Wind
 
						break;
 
					default: NOT_REACHED();
 
				}
 
			}
 

	
 
			/* Set text of sort by dropdown */
 
			w->widget[GRP_WIDGET_SORT_BY_DROPDOWN].data = _vehicle_sort_listing[gv->l.sort_type];
 
			w->widget[GRP_WIDGET_SORT_BY_DROPDOWN].data = _vehicle_sort_listing[vl->sort_type];
 

	
 
			DrawWindowWidgets(w);
 

	
 
			/* Draw Matrix Group
 
			 * The selected group is drawn in white */
 
			StringID str_all_veh, str_no_group_veh;
 
@@ -459,13 +448,13 @@ static void GroupWndProc(Window *w, Wind
 
			DrawString(10, y1, str_all_veh, IsAllGroupID(gv->group_sel) ? TC_WHITE : TC_BLACK);
 

	
 
			y1 += 13;
 

	
 
			DrawString(10, y1, str_no_group_veh, IsDefaultGroupID(gv->group_sel) ? TC_WHITE : TC_BLACK);
 

	
 
			max = min(w->vscroll.pos + w->vscroll.cap, gl->l.list_length);
 
			max = min(w->vscroll.pos + w->vscroll.cap, gl->list_length);
 
			for (i = w->vscroll.pos ; i < max ; ++i) {
 
				const Group *g = gl->sort_list[i];
 

	
 
				assert(g->owner == owner);
 

	
 
				y1 += PLY_WND_PRC__SIZE_OF_ROW_TINY;
 
@@ -476,18 +465,18 @@ static void GroupWndProc(Window *w, Wind
 

	
 
				/* draw the number of vehicles of the group */
 
				SetDParam(0, g->num_vehicle);
 
				DrawStringRightAligned(187, y1 + 1, STR_GROUP_TINY_NUM, (gv->group_sel == g->index) ? TC_WHITE : TC_BLACK);
 
			}
 

	
 
			DrawSortButtonState(w, GRP_WIDGET_SORT_BY_ORDER, gv->l.flags & VL_DESC ? SBS_DOWN : SBS_UP);
 
			DrawSortButtonState(w, GRP_WIDGET_SORT_BY_ORDER, vl->flags & VL_DESC ? SBS_DOWN : SBS_UP);
 

	
 
			/* Draw Matrix Vehicle according to the vehicle list built before */
 
			max = min(w->vscroll2.pos + w->vscroll2.cap, gv->l.list_length);
 
			max = min(w->vscroll2.pos + w->vscroll2.cap, vl->list_length);
 
			for (i = w->vscroll2.pos ; i < max ; ++i) {
 
				const Vehicle* v = gv->sort_list[i];
 
				const Vehicle* v = vl->sort_list[i];
 

	
 
				assert(v->type == gv->vehicle_type && v->owner == owner);
 

	
 
				DrawVehicleImage(v, x + 19, y2 + 6, gv->vehicle_sel, w->hscroll.cap, 0);
 
				DrawVehicleProfitButton(v, x, y2 + 13);
 

	
 
@@ -513,66 +502,66 @@ static void GroupWndProc(Window *w, Wind
 

	
 
		case WE_CLICK:
 
			if (e->we.click.widget != GRP_WIDGET_SORT_BY_DROPDOWN && e->we.click.widget != GRP_WIDGET_MANAGE_VEHICLES_DROPDOWN) HideDropDownMenu(w);
 

	
 
			switch(e->we.click.widget) {
 
				case GRP_WIDGET_SORT_BY_ORDER: // Flip sorting method ascending/descending
 
					gv->l.flags ^= VL_DESC;
 
					gv->l.flags |= VL_RESORT;
 
					vl->flags ^= VL_DESC;
 
					vl->flags |= VL_RESORT;
 

	
 
					gv->_sorting->order = !!(gv->l.flags & VL_DESC);
 
					gv->sorting->order = !!(vl->flags & VL_DESC);
 
					w->SetDirty();
 
					break;
 

	
 
				case GRP_WIDGET_SORT_BY_DROPDOWN: // Select sorting criteria dropdown menu
 
					ShowDropDownMenu(w, _vehicle_sort_listing, gv->l.sort_type,  GRP_WIDGET_SORT_BY_DROPDOWN, 0, (gv->vehicle_type == VEH_TRAIN || gv->vehicle_type == VEH_ROAD) ? 0 : (1 << 10));
 
					ShowDropDownMenu(w, _vehicle_sort_listing, vl->sort_type,  GRP_WIDGET_SORT_BY_DROPDOWN, 0, (gv->vehicle_type == VEH_TRAIN || gv->vehicle_type == VEH_ROAD) ? 0 : (1 << 10));
 
					return;
 

	
 
				case GRP_WIDGET_ALL_VEHICLES: // All vehicles button
 
					if (!IsAllGroupID(gv->group_sel)) {
 
						gv->group_sel = ALL_GROUP;
 
						gv->l.flags |= VL_REBUILD;
 
						vl->flags |= VL_REBUILD;
 
						w->SetDirty();
 
					}
 
					break;
 

	
 
				case GRP_WIDGET_DEFAULT_VEHICLES: // Ungrouped vehicles button
 
					if (!IsDefaultGroupID(gv->group_sel)) {
 
						gv->group_sel = DEFAULT_GROUP;
 
						gv->l.flags |= VL_REBUILD;
 
						vl->flags |= VL_REBUILD;
 
						w->SetDirty();
 
					}
 
					break;
 

	
 
				case GRP_WIDGET_LIST_GROUP: { // Matrix Group
 
					uint16 id_g = (e->we.click.pt.y - PLY_WND_PRC__OFFSET_TOP_WIDGET - 26) / PLY_WND_PRC__SIZE_OF_ROW_TINY;
 

	
 
					if (id_g >= w->vscroll.cap) return;
 

	
 
					id_g += w->vscroll.pos;
 

	
 
					if (id_g >= gl->l.list_length) return;
 
					if (id_g >= gl->list_length) return;
 

	
 
					gv->group_sel = gl->sort_list[id_g]->index;;
 

	
 
					gv->l.flags |= VL_REBUILD;
 
					vl->flags |= VL_REBUILD;
 
					w->SetDirty();
 
					break;
 
				}
 

	
 
				case GRP_WIDGET_LIST_VEHICLE: { // Matrix Vehicle
 
					uint32 id_v = (e->we.click.pt.y - PLY_WND_PRC__OFFSET_TOP_WIDGET) / (int)w->resize.step_height;
 
					const Vehicle *v;
 

	
 
					if (id_v >= w->vscroll2.cap) return; // click out of bounds
 

	
 
					id_v += w->vscroll2.pos;
 

	
 
					if (id_v >= gv->l.list_length) return; // click out of list bound
 
					if (id_v >= vl->list_length) return; // click out of list bound
 

	
 
					v = gv->sort_list[id_v];
 
					v = vl->sort_list[id_v];
 

	
 
					gv->vehicle_sel = v->index;
 

	
 
					if (v->IsValid()) {
 
						SetObjectToPlaceWnd(v->GetImage(DIR_W), GetVehiclePalette(v), VHM_DRAG, w);
 
						_cursor.vehchain = true;
 
@@ -654,13 +643,13 @@ static void GroupWndProc(Window *w, Wind
 
					w->SetDirty();
 

	
 
					if (id_g >= w->vscroll.cap) return;
 

	
 
					id_g += w->vscroll.pos;
 

	
 
					if (id_g >= gl->l.list_length) return;
 
					if (id_g >= gl->list_length) return;
 

	
 
					DoCommandP(0, gl->sort_list[id_g]->index, vindex, NULL, CMD_ADD_VEHICLE_GROUP | CMD_MSG(STR_GROUP_CAN_T_ADD_VEHICLE));
 

	
 
					break;
 
				}
 

	
 
@@ -674,15 +663,15 @@ static void GroupWndProc(Window *w, Wind
 
					w->SetDirty();
 

	
 
					if (id_v >= w->vscroll2.cap) return; // click out of bounds
 

	
 
					id_v += w->vscroll2.pos;
 

	
 
					if (id_v >= gv->l.list_length) return; // click out of list bound
 
					if (id_v >= vl->list_length) return; // click out of list bound
 

	
 
					v = gv->sort_list[id_v];
 
					v = vl->sort_list[id_v];
 

	
 
					if (vindex == v->index) {
 
						ShowVehicleViewWindow(v);
 
					}
 

	
 
					break;
 
@@ -710,21 +699,21 @@ static void GroupWndProc(Window *w, Wind
 
			break;
 

	
 

	
 
		case WE_DROPDOWN_SELECT: // we have selected a dropdown item in the list
 
			switch (e->we.dropdown.button) {
 
				case GRP_WIDGET_SORT_BY_DROPDOWN:
 
					if (gv->l.sort_type != e->we.dropdown.index) {
 
						gv->l.flags |= VL_RESORT;
 
						gv->l.sort_type = e->we.dropdown.index;
 
						gv->_sorting->criteria = gv->l.sort_type;
 
					if (vl->sort_type != e->we.dropdown.index) {
 
						vl->flags |= VL_RESORT;
 
						vl->sort_type = e->we.dropdown.index;
 
						gv->sorting->criteria = vl->sort_type;
 
					}
 
					break;
 

	
 
				case GRP_WIDGET_MANAGE_VEHICLES_DROPDOWN:
 
					assert(gv->l.list_length != 0);
 
					assert(vl->list_length != 0);
 

	
 
					switch (e->we.dropdown.index) {
 
						case GALF_REPLACE: // Replace window
 
							ShowReplaceGroupVehicleWindow(gv->group_sel, gv->vehicle_type);
 
							break;
 
						case GALF_SERVICE: // Send for servicing
 
@@ -755,27 +744,27 @@ static void GroupWndProc(Window *w, Wind
 

	
 
			w->SetDirty();
 
			break;
 

	
 

	
 
		case WE_DESTROY:
 
			free((void*)gv->sort_list);
 
			free((void*)vl->sort_list);
 
			free((void*)gl->sort_list);
 
			break;
 

	
 

	
 
		case WE_TICK: // resort the lists every 20 seconds orso (10 days)
 
			if (_pause_game != 0) break;
 
			if (--gv->l.resort_timer == 0) {
 
				gv->l.resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS;
 
				gv->l.flags |= VL_RESORT;
 
			if (--vl->resort_timer == 0) {
 
				vl->resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS;
 
				vl->flags |= VL_RESORT;
 
				w->SetDirty();
 
			}
 
			if (--gl->l.resort_timer == 0) {
 
				gl->l.resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS;
 
				gl->l.flags |= VL_RESORT;
 
			if (--gl->resort_timer == 0) {
 
				gl->resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS;
 
				gl->flags |= VL_RESORT;
 
				w->SetDirty();
 
			}
 
			break;
 

	
 
		case WE_ABORT_PLACE_OBJ: // called when new object to place is selected from keyboard
 
			/* abort drag & drop */
src/network/network_gui.cpp
Show inline comments
 
@@ -165,17 +165,18 @@ enum NetworkGameWindowWidgets {
 
	NGWW_FIND,          ///< 'Find server' button
 
	NGWW_ADD,           ///< 'Add server' button
 
	NGWW_START,         ///< 'Start server' button
 
	NGWW_CANCEL,        ///< 'Cancel' button
 
};
 

	
 
typedef GUIList<NetworkGameList*> GUIGameServerList;
 

	
 
struct NetworkGameWindow : public QueryStringBaseWindow {
 
	byte field;                  ///< selected text-field
 
	NetworkGameList *server;     ///< selected server
 
	NetworkGameList **sort_list; ///< list of games (sorted)
 
	list_d ld;                   ///< accompanying list-administration
 
	GUIGameServerList servers;   ///< list with game servers.
 

	
 
	NetworkGameWindow(const WindowDesc *desc) : QueryStringBaseWindow(desc)
 
	{
 
		ttd_strlcpy(this->edit_str_buf, _network_player_name, lengthof(this->edit_str_buf));
 
		this->afilter = CS_ALPHANUMERAL;
 
		InitializeTextBuffer(&this->text, this->edit_str_buf, lengthof(this->edit_str_buf), 120);
 
@@ -185,50 +186,50 @@ struct NetworkGameWindow : public QueryS
 
		this->vscroll.cap = 11;
 
		this->resize.step_height = NET_PRC__SIZE_OF_ROW;
 

	
 
		this->field = NGWW_PLAYER;
 
		this->server = NULL;
 

	
 
		this->sort_list = NULL;
 
		this->ld.flags = VL_REBUILD | (_ng_sorting.order ? VL_DESC : VL_NONE);
 
		this->ld.sort_type = _ng_sorting.criteria;
 
		this->servers.sort_list = NULL;
 
		this->servers.flags = VL_REBUILD | (_ng_sorting.order ? VL_DESC : VL_NONE);
 
		this->servers.sort_type = _ng_sorting.criteria;
 

	
 
		this->FindWindowPlacementAndResize(desc);
 
	}
 

	
 
	~NetworkGameWindow()
 
	{
 
		free(this->sort_list);
 
		free(this->servers.sort_list);
 
	}
 

	
 
	/**
 
	 * (Re)build the network game list as its amount has changed because
 
	 * an item has been added or deleted for example
 
	 */
 
	void BuildNetworkGameList()
 
	{
 
		NetworkGameList *ngl_temp;
 
		uint n = 0;
 

	
 
		if (!(this->ld.flags & VL_REBUILD)) return;
 
		if (!(this->servers.flags & VL_REBUILD)) return;
 

	
 
		/* Count the number of games in the list */
 
		for (ngl_temp = _network_game_list; ngl_temp != NULL; ngl_temp = ngl_temp->next) n++;
 
		if (n == 0) return;
 

	
 
		/* Create temporary array of games to use for listing */
 
		this->sort_list = ReallocT(this->sort_list, n);
 
		this->ld.list_length = n;
 
		this->servers.sort_list = ReallocT(this->servers.sort_list, n);
 
		this->servers.list_length = n;
 

	
 
		for (n = 0, ngl_temp = _network_game_list; ngl_temp != NULL; ngl_temp = ngl_temp->next) {
 
			this->sort_list[n++] = ngl_temp;
 
			this->servers.sort_list[n++] = ngl_temp;
 
		}
 

	
 
		/* Force resort */
 
		this->ld.flags &= ~VL_REBUILD;
 
		this->ld.flags |= VL_RESORT;
 
		this->servers.flags &= ~VL_REBUILD;
 
		this->servers.flags |= VL_RESORT;
 
	}
 

	
 
	void SortNetworkGameList()
 
	{
 
		static NGameNameSortFunction * const ngame_sorter[] = {
 
			&NGameNameSorter,
 
@@ -236,29 +237,29 @@ struct NetworkGameWindow : public QueryS
 
			&NGameAllowedSorter
 
		};
 

	
 
		NetworkGameList *item;
 
		uint i;
 

	
 
		if (!(this->ld.flags & VL_RESORT)) return;
 
		if (this->ld.list_length == 0) return;
 
		if (!(this->servers.flags & VL_RESORT)) return;
 
		if (this->servers.list_length == 0) return;
 

	
 
		_internal_sort_order = !!(this->ld.flags & VL_DESC);
 
		qsort(this->sort_list, this->ld.list_length, sizeof(this->sort_list[0]), ngame_sorter[this->ld.sort_type]);
 
		_internal_sort_order = !!(this->servers.flags & VL_DESC);
 
		qsort(this->servers.sort_list, this->servers.list_length, sizeof(this->servers.sort_list[0]), ngame_sorter[this->servers.sort_type]);
 

	
 
		/* After sorting ngl->sort_list contains the sorted items. Put these back
 
		 * into the original list. Basically nothing has changed, we are only
 
		 * shuffling the ->next pointers */
 
		_network_game_list = this->sort_list[0];
 
		for (item = _network_game_list, i = 1; i != this->ld.list_length; i++) {
 
			item->next = this->sort_list[i];
 
		_network_game_list = this->servers.sort_list[0];
 
		for (item = _network_game_list, i = 1; i != this->servers.list_length; i++) {
 
			item->next = this->servers.sort_list[i];
 
			item = item->next;
 
		}
 
		item->next = NULL;
 

	
 
		this->ld.flags &= ~VL_RESORT;
 
		this->servers.flags &= ~VL_RESORT;
 
	}
 

	
 
	/**
 
	 * Draw a single server line.
 
	 * @param cur_item  the server to draw.
 
	 * @param y         from where to draw?
 
@@ -291,19 +292,19 @@ struct NetworkGameWindow : public QueryS
 
		}
 
	}
 

	
 
	virtual void OnPaint()
 
	{
 
		const NetworkGameList *sel = this->server;
 
		const SortButtonState arrow = (this->ld.flags & VL_DESC) ? SBS_DOWN : SBS_UP;
 
		const SortButtonState arrow = (this->servers.flags & VL_DESC) ? SBS_DOWN : SBS_UP;
 

	
 
		if (this->ld.flags & VL_REBUILD) {
 
		if (this->servers.flags & VL_REBUILD) {
 
			this->BuildNetworkGameList();
 
			SetVScrollCount(this, this->ld.list_length);
 
			SetVScrollCount(this, this->servers.list_length);
 
		}
 
		if (this->ld.flags & VL_RESORT) this->SortNetworkGameList();
 
		if (this->servers.flags & VL_RESORT) this->SortNetworkGameList();
 

	
 
		/* 'Refresh' button invisible if no server selected */
 
		this->SetWidgetDisabledState(NGWW_REFRESH, sel == NULL);
 
		/* 'Join' button disabling conditions */
 
		this->SetWidgetDisabledState(NGWW_JOIN, sel == NULL || // no Selected Server
 
				!sel->online || // Server offline
 
@@ -322,13 +323,13 @@ struct NetworkGameWindow : public QueryS
 
		/* Edit box to set player name */
 
		this->DrawEditBox(NGWW_PLAYER);
 

	
 
		DrawString(this->widget[NGWW_PLAYER].left - 100, 23, STR_NETWORK_PLAYER_NAME, TC_GOLD);
 

	
 
		/* Sort based on widgets: name, clients, compatibility */
 
		switch (this->ld.sort_type) {
 
		switch (this->servers.sort_type) {
 
			case NGWW_NAME    - NGWW_NAME: DrawSortButtonState(this, NGWW_NAME,    arrow); break;
 
			case NGWW_CLIENTS - NGWW_NAME: DrawSortButtonState(this, NGWW_CLIENTS, arrow); break;
 
			case NGWW_INFO    - NGWW_NAME: DrawSortButtonState(this, NGWW_INFO,    arrow); break;
 
		}
 

	
 
		uint16 y = NET_PRC__OFFSET_TOP_WIDGET + 3;
 
@@ -443,18 +444,18 @@ struct NetworkGameWindow : public QueryS
 
				ShowDropDownMenu(this, _lan_internet_types_dropdown, _network_lan_internet, NGWW_CONN_BTN, 0, 0); // do it for widget NSSW_CONN_BTN
 
				break;
 

	
 
			case NGWW_NAME: // Sort by name
 
			case NGWW_CLIENTS: // Sort by connected clients
 
			case NGWW_INFO: // Connectivity (green dot)
 
				if (this->ld.sort_type == widget - NGWW_NAME) this->ld.flags ^= VL_DESC;
 
				this->ld.flags |= VL_RESORT;
 
				this->ld.sort_type = widget - NGWW_NAME;
 
				if (this->servers.sort_type == widget - NGWW_NAME) this->servers.flags ^= VL_DESC;
 
				this->servers.flags |= VL_RESORT;
 
				this->servers.sort_type = widget - NGWW_NAME;
 

	
 
				_ng_sorting.order = !!(this->ld.flags & VL_DESC);
 
				_ng_sorting.criteria = this->ld.sort_type;
 
				_ng_sorting.order = !!(this->servers.flags & VL_DESC);
 
				_ng_sorting.criteria = this->servers.sort_type;
 
				this->SetDirty();
 
				break;
 

	
 
			case NGWW_MATRIX: { // Matrix to show networkgames
 
				NetworkGameList *cur_item;
 
				uint32 id_v = (pt.y - NET_PRC__OFFSET_TOP_WIDGET) / NET_PRC__SIZE_OF_ROW;
 
@@ -534,13 +535,13 @@ struct NetworkGameWindow : public QueryS
 
		if (this->field == NGWW_PLAYER) this->HandleEditBox(NGWW_PLAYER);
 
	}
 

	
 
	virtual void OnInvalidateData(int data)
 
	{
 
		if (data != 0) this->server = NULL;
 
		this->ld.flags |= VL_REBUILD;
 
		this->servers.flags |= VL_REBUILD;
 
		this->SetDirty();
 
	}
 

	
 
	virtual bool OnKeyPress(uint16 key, uint16 keycode)
 
	{
 
		bool cont = true;
 
@@ -577,13 +578,13 @@ struct NetworkGameWindow : public QueryS
 
	virtual void OnResize(Point new_size, Point delta)
 
	{
 
		this->vscroll.cap += delta.y / (int)this->resize.step_height;
 

	
 
		this->widget[NGWW_MATRIX].data = (this->vscroll.cap << 8) + 1;
 

	
 
		SetVScrollCount(this, this->ld.list_length);
 
		SetVScrollCount(this, this->servers.list_length);
 

	
 
		int widget_width = this->widget[NGWW_FIND].right - this->widget[NGWW_FIND].left;
 
		int space = (this->width - 4 * widget_width - 25) / 3;
 

	
 
		int offset = 10;
 
		for (uint i = 0; i < 4; i++) {
src/vehicle_gui.cpp
Show inline comments
 
@@ -51,21 +51,13 @@ struct refit_d {
 
	struct RefitList *list;
 
	uint length;
 
	VehicleOrderID order;
 
};
 
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(refit_d));
 

	
 
struct Sorting {
 
	Listing aircraft;
 
	Listing roadveh;
 
	Listing ship;
 
	Listing train;
 
};
 

	
 
static Sorting _sorting;
 

	
 
Sorting _sorting;
 
static bool   _internal_sort_order;     // descending/ascending
 

	
 
typedef int CDECL VehicleSortListingTypeFunction(const void*, const void*);
 

	
 
static VehicleSortListingTypeFunction VehicleNumberSorter;
 
static VehicleSortListingTypeFunction VehicleNameSorter;
 
@@ -121,13 +113,13 @@ static void SetVehicleListsFlag(SortList
 

	
 
		switch (w->window_class) {
 
			case WC_TRAINS_LIST:
 
			case WC_ROADVEH_LIST:
 
			case WC_SHIPS_LIST:
 
			case WC_AIRCRAFT_LIST:
 
				WP(w, vehiclelist_d).l.flags |= sl_flag;
 
				WP(w, vehiclelist_d).vehicles.flags |= sl_flag;
 
				w->SetDirty();
 
				break;
 

	
 
			default: break;
 
		}
 
	}
 
@@ -148,39 +140,39 @@ void ResortVehicleLists()
 
{
 
	SetVehicleListsFlag(VL_RESORT);
 
}
 

	
 
void BuildVehicleList(vehiclelist_d *vl, PlayerID owner, uint16 index, uint16 window_type)
 
{
 
	if (!(vl->l.flags & VL_REBUILD)) return;
 
	if (!(vl->vehicles.flags & VL_REBUILD)) return;
 

	
 
	DEBUG(misc, 3, "Building vehicle list for player %d at station %d", owner, index);
 

	
 
	vl->l.list_length = GenerateVehicleSortList(&vl->sort_list, &vl->length_of_sort_list, vl->vehicle_type, owner, index, window_type);
 
	vl->vehicles.list_length = GenerateVehicleSortList(&vl->vehicles.sort_list, &vl->vehicles.list_length, vl->vehicle_type, owner, index, window_type);
 

	
 
	vl->l.flags &= ~VL_REBUILD;
 
	vl->l.flags |= VL_RESORT;
 
	vl->vehicles.flags &= ~VL_REBUILD;
 
	vl->vehicles.flags |= VL_RESORT;
 
}
 

	
 
/* cached values for VehicleNameSorter to spare many GetString() calls */
 
static const Vehicle *_last_vehicle[2] = { NULL, NULL };
 
static char           _last_name[2][64] = { "", "" };
 

	
 
void SortVehicleList(vehiclelist_d *vl)
 
{
 
	if (!(vl->l.flags & VL_RESORT)) return;
 
	if (!(vl->vehicles.flags & VL_RESORT)) return;
 

	
 
	/* invalidate cached values for name sorter - vehicle names could change */
 
	_last_vehicle[0] = _last_vehicle[1] = NULL;
 

	
 
	_internal_sort_order = (vl->l.flags & VL_DESC) != 0;
 
	qsort((void*)vl->sort_list, vl->l.list_length, sizeof(vl->sort_list[0]),
 
		_vehicle_sorter[vl->l.sort_type]);
 
	_internal_sort_order = (vl->vehicles.flags & VL_DESC) != 0;
 
	qsort((void*)vl->vehicles.sort_list, vl->vehicles.list_length, sizeof(vl->vehicles.sort_list[0]),
 
		_vehicle_sorter[vl->vehicles.sort_type]);
 

	
 
	vl->l.resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS;
 
	vl->l.flags &= ~VL_RESORT;
 
	vl->vehicles.resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS;
 
	vl->vehicles.flags &= ~VL_RESORT;
 
}
 

	
 
void DepotSortList(Vehicle **v, uint16 length)
 
{
 
	_internal_sort_order = 0;
 
	qsort((void*)v, length, sizeof(v[0]), _vehicle_sorter[0]);
 
@@ -819,14 +811,14 @@ static void CreateVehicleListWindow(Wind
 
{
 
	vehiclelist_d *vl = &WP(w, vehiclelist_d);
 
	uint16 window_type = w->window_number & VLW_MASK;
 
	PlayerID player = (PlayerID)GB(w->window_number, 0, 8);
 

	
 
	vl->vehicle_type = (VehicleType)GB(w->window_number, 11, 5);
 
	vl->length_of_sort_list = 0;
 
	vl->sort_list = NULL;
 
	vl->vehicles.list_length = 0;
 
	vl->vehicles.sort_list = NULL;
 
	w->caption_color = player;
 

	
 
	/* Hide the widgets that we will not use in this window
 
	 * Some windows contains actions only fit for the owner */
 
	if (player == _local_player) {
 
		w->HideWidget(VLW_WIDGET_OTHER_PLAYER_FILLER);
 
@@ -921,23 +913,22 @@ static void CreateVehicleListWindow(Wind
 
	w->widget[VLW_WIDGET_LIST].data = (w->vscroll.cap << 8) + 1;
 

	
 
	/* Set up sorting. Make the window-specific _sorting variable
 
		* point to the correct global _sorting struct so we are freed
 
		* from having conditionals during window operation */
 
	switch (vl->vehicle_type) {
 
		case VEH_TRAIN:    vl->_sorting = &_sorting.train; break;
 
		case VEH_ROAD:     vl->_sorting = &_sorting.roadveh; break;
 
		case VEH_SHIP:     vl->_sorting = &_sorting.ship; break;
 
		case VEH_AIRCRAFT: vl->_sorting = &_sorting.aircraft; break;
 
		case VEH_TRAIN:    vl->sorting = &_sorting.train; break;
 
		case VEH_ROAD:     vl->sorting = &_sorting.roadveh; break;
 
		case VEH_SHIP:     vl->sorting = &_sorting.ship; break;
 
		case VEH_AIRCRAFT: vl->sorting = &_sorting.aircraft; break;
 
		default: NOT_REACHED(); break;
 
	}
 

	
 
	vl->l.flags = VL_REBUILD | (vl->_sorting->order ? VL_DESC : VL_NONE);
 
	vl->l.sort_type = vl->_sorting->criteria;
 
	vl->sort_list = NULL;
 
	vl->l.resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS; // Set up resort timer
 
	vl->vehicles.flags = VL_REBUILD | (vl->sorting->order ? VL_DESC : VL_NONE);
 
	vl->vehicles.sort_type = vl->sorting->criteria;
 
	vl->vehicles.resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS; // Set up resort timer
 
}
 

	
 
void DrawSmallOrderList(const Vehicle *v, int x, int y)
 
{
 
	const Order *order;
 
	int sel, i = 0;
 
@@ -970,18 +961,18 @@ static void DrawVehicleListWindow(Window
 
	const PlayerID owner = (PlayerID)w->caption_color;
 
	const uint16 window_type = w->window_number & VLW_MASK;
 
	const uint16 index = GB(w->window_number, 16, 16);
 

	
 
	BuildVehicleList(vl, owner, index, window_type);
 
	SortVehicleList(vl);
 
	SetVScrollCount(w, vl->l.list_length);
 
	SetVScrollCount(w, vl->vehicles.list_length);
 

	
 
	/* draw the widgets */
 
	switch (window_type) {
 
		case VLW_SHARED_ORDERS: /* Shared Orders */
 
			if (vl->l.list_length == 0) {
 
			if (vl->vehicles.list_length == 0) {
 
				/* We can't open this window without vehicles using this order
 
				 * and we should close the window when deleting the order      */
 
				NOT_REACHED();
 
			}
 
			SetDParam(0, w->vscroll.count);
 
			break;
 
@@ -1011,28 +1002,28 @@ static void DrawVehicleListWindow(Window
 
			}
 
			SetDParam(2, w->vscroll.count);
 
			break;
 
		default: NOT_REACHED(); break;
 
	}
 

	
 
	w->SetWidgetsDisabledState(vl->l.list_length == 0,
 
	w->SetWidgetsDisabledState(vl->vehicles.list_length == 0,
 
		VLW_WIDGET_MANAGE_VEHICLES_DROPDOWN,
 
		VLW_WIDGET_STOP_ALL,
 
		VLW_WIDGET_START_ALL,
 
		WIDGET_LIST_END);
 

	
 
	DrawWindowWidgets(w);
 

	
 
	/* draw sorting criteria string */
 
	DrawString(85, 15, _vehicle_sort_listing[vl->l.sort_type], TC_BLACK);
 
	DrawString(85, 15, _vehicle_sort_listing[vl->vehicles.sort_type], TC_BLACK);
 
	/* draw arrow pointing up/down for ascending/descending sorting */
 
	DrawSortButtonState(w, VLW_WIDGET_SORT_ORDER, vl->l.flags & VL_DESC ? SBS_DOWN : SBS_UP);
 
	DrawSortButtonState(w, VLW_WIDGET_SORT_ORDER, vl->vehicles.flags & VL_DESC ? SBS_DOWN : SBS_UP);
 

	
 
	max = min(w->vscroll.pos + w->vscroll.cap, vl->l.list_length);
 
	max = min(w->vscroll.pos + w->vscroll.cap, vl->vehicles.list_length);
 
	for (i = w->vscroll.pos; i < max; ++i) {
 
		const Vehicle *v = vl->sort_list[i];
 
		const Vehicle *v = vl->vehicles.sort_list[i];
 
		StringID str;
 

	
 
		SetDParam(0, v->GetDisplayProfitThisYear());
 
		SetDParam(1, v->GetDisplayProfitLastYear());
 

	
 
		DrawVehicleImage(v, x + 19, y + 6, INVALID_VEHICLE, w->widget[VLW_WIDGET_LIST].right - w->widget[VLW_WIDGET_LIST].left - 20, 0);
 
@@ -1081,32 +1072,32 @@ void PlayerVehWndProc(Window *w, WindowE
 
			DrawVehicleListWindow(w);
 
			break;
 

	
 
		case WE_CLICK: {
 
			switch (e->we.click.widget) {
 
				case VLW_WIDGET_SORT_ORDER: /* Flip sorting method ascending/descending */
 
					vl->l.flags ^= VL_DESC;
 
					vl->l.flags |= VL_RESORT;
 
					vl->vehicles.flags ^= VL_DESC;
 
					vl->vehicles.flags |= VL_RESORT;
 

	
 
					vl->_sorting->order = !!(vl->l.flags & VL_DESC);
 
					vl->sorting->order = !!(vl->vehicles.flags & VL_DESC);
 
					w->SetDirty();
 
					break;
 
				case VLW_WIDGET_SORT_BY_PULLDOWN:/* Select sorting criteria dropdown menu */
 
					ShowDropDownMenu(w, _vehicle_sort_listing, vl->l.sort_type, VLW_WIDGET_SORT_BY_PULLDOWN, 0, (vl->vehicle_type == VEH_TRAIN || vl->vehicle_type == VEH_ROAD) ? 0 : (1 << 10));
 
					ShowDropDownMenu(w, _vehicle_sort_listing, vl->vehicles.sort_type, VLW_WIDGET_SORT_BY_PULLDOWN, 0, (vl->vehicle_type == VEH_TRAIN || vl->vehicle_type == VEH_ROAD) ? 0 : (1 << 10));
 
					return;
 
				case VLW_WIDGET_LIST: { /* Matrix to show vehicles */
 
					uint32 id_v = (e->we.click.pt.y - PLY_WND_PRC__OFFSET_TOP_WIDGET) / w->resize.step_height;
 
					const Vehicle *v;
 

	
 
					if (id_v >= w->vscroll.cap) return; // click out of bounds
 

	
 
					id_v += w->vscroll.pos;
 

	
 
					if (id_v >= vl->l.list_length) return; // click out of list bound
 
					if (id_v >= vl->vehicles.list_length) return; // click out of list bound
 

	
 
					v = vl->sort_list[id_v];
 
					v = vl->vehicles.sort_list[id_v];
 

	
 
					ShowVehicleViewWindow(v);
 
				} break;
 

	
 
				case VLW_WIDGET_AVAILABLE_VEHICLES:
 
					ShowBuildVehicleWindow(0, vl->vehicle_type);
 
@@ -1140,21 +1131,21 @@ void PlayerVehWndProc(Window *w, WindowE
 
			}
 
		} break;
 

	
 
		case WE_DROPDOWN_SELECT: /* we have selected a dropdown item in the list */
 
			switch (e->we.dropdown.button) {
 
				case VLW_WIDGET_SORT_BY_PULLDOWN:
 
					if (vl->l.sort_type != e->we.dropdown.index) {
 
					if (vl->vehicles.sort_type != e->we.dropdown.index) {
 
						/* value has changed -> resort */
 
						vl->l.flags |= VL_RESORT;
 
						vl->l.sort_type = e->we.dropdown.index;
 
						vl->_sorting->criteria = vl->l.sort_type;
 
						vl->vehicles.flags |= VL_RESORT;
 
						vl->vehicles.sort_type = e->we.dropdown.index;
 
						vl->sorting->criteria = vl->vehicles.sort_type;
 
					}
 
					break;
 
				case VLW_WIDGET_MANAGE_VEHICLES_DROPDOWN:
 
					assert(vl->l.list_length != 0);
 
					assert(vl->vehicles.list_length != 0);
 

	
 
					switch (e->we.dropdown.index) {
 
						case 0: /* Replace window */
 
							ShowReplaceGroupVehicleWindow(DEFAULT_GROUP, vl->vehicle_type);
 
							break;
 
						case 1: /* Send for servicing */
 
@@ -1176,24 +1167,24 @@ void PlayerVehWndProc(Window *w, WindowE
 
				default: NOT_REACHED();
 
			}
 
			w->SetDirty();
 
			break;
 

	
 
		case WE_DESTROY:
 
			free((void*)vl->sort_list);
 
			free((void*)vl->vehicles.sort_list);
 
			break;
 

	
 
		case WE_TICK: /* resort the list every 20 seconds orso (10 days) */
 
			if (_pause_game != 0) break;
 
			if (--vl->l.resort_timer == 0) {
 
			if (--vl->vehicles.resort_timer == 0) {
 
				StationID station = ((w->window_number & VLW_MASK) == VLW_STATION_LIST) ? GB(w->window_number, 16, 16) : INVALID_STATION;
 
				PlayerID owner = (PlayerID)w->caption_color;
 

	
 
				DEBUG(misc, 3, "Periodic resort %d list player %d at station %d", vl->vehicle_type, owner, station);
 
				vl->l.resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS;
 
				vl->l.flags |= VL_RESORT;
 
				vl->vehicles.resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS;
 
				vl->vehicles.flags |= VL_RESORT;
 
				w->SetDirty();
 
			}
 
			break;
 

	
 
		case WE_RESIZE: /* Update the scroll + matrix */
 
			w->vscroll.cap += e->we.sizing.diff.y / (int)w->resize.step_height;
src/vehicle_gui.h
Show inline comments
 
@@ -12,18 +12,12 @@
 
#include "engine_type.h"
 
#include "vehicle_base.h"
 

	
 
void DrawVehicleProfitButton(const Vehicle *v, int x, int y);
 
void ShowVehicleRefitWindow(const Vehicle *v, VehicleOrderID order);
 

	
 
/* sorter stuff */
 
void RebuildVehicleLists();
 
void ResortVehicleLists();
 
void SortVehicleList(vehiclelist_d *vl);
 
void BuildVehicleList(vehiclelist_d *vl, PlayerID owner, uint16 index, uint16 window_type);
 

	
 
#define PERIODIC_RESORT_DAYS 10
 

	
 
extern const StringID _vehicle_sort_listing[];
 

	
 
/** Constants of vehicle view widget indices */
 
enum VehicleViewWindowWidgets {
 
@@ -66,13 +60,13 @@ enum {
 

	
 
static inline bool ValidVLWFlags(uint16 flags)
 
{
 
	return (flags == VLW_STANDARD || flags == VLW_SHARED_ORDERS || flags == VLW_STATION_LIST || flags == VLW_DEPOT_LIST || flags == VLW_GROUP_LIST);
 
}
 

	
 
void PlayerVehWndProc(Window *w, WindowEvent *e);
 
void PlayerVehWndProc(Window *w, struct WindowEvent *e);
 

	
 
int DrawVehiclePurchaseInfo(int x, int y, uint w, EngineID engine_number);
 

	
 
void DrawTrainImage(const Vehicle *v, int x, int y, VehicleID selection, int count, int skip);
 
void DrawRoadVehImage(const Vehicle *v, int x, int y, VehicleID selection, int count);
 
void DrawShipImage(const Vehicle *v, int x, int y, VehicleID selection);
 
@@ -133,9 +127,32 @@ static inline WindowClass GetWindowClass
 
	}
 
}
 

	
 
/* Unified window procedure */
 
void ShowVehicleViewWindow(const Vehicle *v);
 

	
 
Vehicle *CheckClickOnVehicle(const ViewPort *vp, int x, int y);
 
Vehicle *CheckClickOnVehicle(const struct ViewPort *vp, int x, int y);
 

	
 
typedef GUIList<const Vehicle*> GUIVehicleList;
 

	
 
struct vehiclelist_d {
 
	GUIVehicleList vehicles;  ///< The list of vehicles
 
	Listing *sorting;         ///< Pointer to the vehicle type related sorting.
 
	VehicleType vehicle_type; ///< The vehicle type that is sorted
 
};
 

	
 
struct Sorting {
 
	Listing aircraft;
 
	Listing roadveh;
 
	Listing ship;
 
	Listing train;
 
};
 

	
 
extern Sorting _sorting;
 

	
 
/* sorter stuff */
 
void RebuildVehicleLists();
 
void ResortVehicleLists();
 
void SortVehicleList(vehiclelist_d *vl);
 
void BuildVehicleList(vehiclelist_d *vl, PlayerID owner, uint16 index, uint16 window_type);
 

	
 
#endif /* VEHICLE_GUI_H */
src/window_gui.h
Show inline comments
 
@@ -554,36 +554,27 @@ enum SortListFlags {
 
	VL_NONE    = 0,      ///< no sort
 
	VL_DESC    = 1 << 0, ///< sort descending or ascending
 
	VL_RESORT  = 1 << 1, ///< instruct the code to resort the list in the next loop
 
	VL_REBUILD = 1 << 2, ///< create sort-listing to use for qsort and friends
 
	VL_END     = 1 << 3,
 
};
 

	
 
DECLARE_ENUM_AS_BIT_SET(SortListFlags);
 

	
 
struct Listing {
 
	bool order;    ///< Ascending/descending
 
	byte criteria; ///< Sorting criteria
 
};
 

	
 
struct list_d {
 
template <typename T>
 
struct GUIList {
 
	T* sort_list;        ///< The items to sort.
 
	SortListFlags flags; ///< used to control sorting/resorting/etc.
 
	uint16 list_length;  ///< length of the list being sorted
 
	uint16 resort_timer; ///< resort list after a given amount of ticks if set
 
	byte sort_type;      ///< what criteria to sort on
 
	SortListFlags flags; ///< used to control sorting/resorting/etc.
 
	uint16 resort_timer; ///< resort list after a given amount of ticks if set
 
};
 
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(list_d));
 

	
 
struct vehiclelist_d {
 
	const Vehicle** sort_list;  // List of vehicles (sorted)
 
	Listing *_sorting;          // pointer to the appropiate subcategory of _sorting
 
	uint16 length_of_sort_list; // Keeps track of how many vehicle pointers sort list got space for
 
	VehicleType vehicle_type;   // The vehicle type that is sorted
 
	list_d l;                   // General list struct
 
};
 
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(vehiclelist_d));
 

	
 
/****************** THESE ARE NOT WIDGET TYPES!!!!! *******************/
 
enum WindowWidgetBehaviours {
 
	WWB_PUSHBUTTON  = 1 << 5,
 

	
 
	WWB_MASK        = 0xE0,
0 comments (0 inline, 0 general)