Changeset - r1246:1fc4189e63a6
[Not reviewed]
master
0 8 0
darkvater - 20 years ago 2005-01-31 11:03:23
darkvater@openttd.org
(svn r1750) - Feature: [ 1093261 ] Saving vehicle sorting criteria for each vehicle type (bociusz)
8 files changed with 51 insertions and 25 deletions:
0 comments (0 inline, 0 general)
aircraft_gui.c
Show inline comments
 
@@ -1018,14 +1018,13 @@ static void PlayerAircraftWndProc(Window
 
			}
 
			DrawWindowWidgets(w);
 
		}
 
		/* draw sorting criteria string */
 
		DrawString(85, 15, _vehicle_sort_listing[vl->sort_type], 0x10);
 
		/* draw arrow pointing up/down for ascending/descending sorting */
 
		DoDrawString(
 
			vl->flags & VL_DESC ? "\xAA" : "\xA0", 69, 15, 0x10);
 
		DoDrawString(vl->flags & VL_DESC ? "\xAA" : "\xA0", 69, 15, 0x10);
 

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

	
 
@@ -1058,12 +1057,13 @@ static void PlayerAircraftWndProc(Window
 

	
 
	case WE_CLICK: {
 
		switch(e->click.widget) {
 
		case 3: /* Flip sorting method ascending/descending */
 
			vl->flags ^= VL_DESC;
 
			vl->flags |= VL_RESORT;
 
			_sorting.aircraft.order = !!(vl->flags & VL_DESC);
 
			SetWindowDirty(w);
 
			break;
 

	
 
		case 4: case 5:/* Select sorting criteria dropdown menu */
 
			ShowDropDownMenu(w, _vehicle_sort_listing, vl->sort_type, 5, 0, 0);
 
			return;
 
@@ -1120,24 +1120,25 @@ static void PlayerAircraftWndProc(Window
 

	
 
	case WE_DROPDOWN_SELECT: /* we have selected a dropdown item in the list */
 
		if (vl->sort_type != e->dropdown.index) {
 
			// value has changed -> resort
 
			vl->flags |= VL_RESORT;
 
			vl->sort_type = e->dropdown.index;
 
			_sorting.aircraft.criteria = vl->sort_type;
 

	
 
			// enable 'Sort By' if a sorter criteria is chosen
 
			if (vl->sort_type != SORT_BY_UNSORTED)
 
				w->disabled_state &= ~(1 << 3);
 
				CLRBIT(w->disabled_state, 3);
 
		}
 
		SetWindowDirty(w);
 
		break;
 

	
 
	case WE_CREATE: /* set up resort timer */
 
		vl->sort_list = NULL;
 
		vl->flags = VL_REBUILD;
 
		vl->sort_type = SORT_BY_UNSORTED;
 
		vl->flags = VL_REBUILD | (_sorting.aircraft.order << (VL_DESC - 1));
 
		vl->sort_type = _sorting.aircraft.criteria;
 
		vl->resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS;
 
		break;
 

	
 
	case WE_DESTROY:
 
		free(vl->sort_list);
 
		break;
gui.h
Show inline comments
 
@@ -123,7 +123,10 @@ void ShowMusicWindow(void);
 
VARDEF byte _newspaper_flag;
 
VARDEF byte _construct_mode;
 
VARDEF byte _station_show_coverage;
 
VARDEF PlaceProc *_place_proc;
 
VARDEF bool _no_button_sound;
 

	
 
/* vehicle_gui.c */
 
void InitializeGUI(void);
 

	
 
#endif /* GUI_H */
roadveh_gui.c
Show inline comments
 
@@ -805,14 +805,13 @@ static void PlayerRoadVehWndProc(Window 
 
			}
 
			DrawWindowWidgets(w);
 
		}
 
		/* draw sorting criteria string */
 
		DrawString(85, 15, _vehicle_sort_listing[vl->sort_type], 0x10);
 
		/* draw arrow pointing up/down for ascending/descending sorting */
 
		DoDrawString(
 
			vl->flags & VL_DESC ? "\xAA" : "\xA0", 69, 15, 0x10);
 
		DoDrawString(vl->flags & VL_DESC ? "\xAA" : "\xA0", 69, 15, 0x10);
 

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

	
 
@@ -843,12 +842,13 @@ static void PlayerRoadVehWndProc(Window 
 

	
 
	case WE_CLICK: {
 
		switch(e->click.widget) {
 
		case 3: /* Flip sorting method ascending/descending */
 
			vl->flags ^= VL_DESC;
 
			vl->flags |= VL_RESORT;
 
			_sorting.roadveh.order = !!(vl->flags & VL_DESC);
 
			SetWindowDirty(w);
 
			break;
 

	
 
		case 4: case 5:/* Select sorting criteria dropdown menu */
 
			ShowDropDownMenu(w, _vehicle_sort_listing, vl->sort_type, 5, 0, 0);
 
			return;
 
@@ -903,24 +903,25 @@ static void PlayerRoadVehWndProc(Window 
 

	
 
	case WE_DROPDOWN_SELECT: /* we have selected a dropdown item in the list */
 
		if (vl->sort_type != e->dropdown.index) {
 
			// value has changed -> resort
 
			vl->flags |= VL_RESORT;
 
			vl->sort_type = e->dropdown.index;
 
			_sorting.roadveh.criteria = vl->sort_type;
 

	
 
			// enable 'Sort By' if a sorter criteria is chosen
 
			if (vl->sort_type != SORT_BY_UNSORTED)
 
				w->disabled_state &= ~(1 << 3);
 
				CLRBIT(w->disabled_state, 3);
 
		}
 
		SetWindowDirty(w);
 
		break;
 

	
 
	case WE_CREATE: /* set up resort timer */
 
		vl->sort_list = NULL;
 
		vl->flags = VL_REBUILD;
 
		vl->sort_type = SORT_BY_UNSORTED;
 
		vl->flags = VL_REBUILD | (_sorting.roadveh.order << (VL_DESC - 1));
 
		vl->sort_type = _sorting.roadveh.criteria;
 
		vl->resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS;
 
		break;
 

	
 
	case WE_DESTROY:
 
		free(vl->sort_list);
 
		break;
 
@@ -932,13 +933,12 @@ static void PlayerRoadVehWndProc(Window 
 
			vl->resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS;
 
			vl->flags |= VL_RESORT;
 
			SetWindowDirty(w);
 
		}
 
		break;
 

	
 

	
 
	case WE_RESIZE:
 
		/* Update the scroll + matrix */
 
		w->vscroll.cap += e->sizing.diff.y / PLY_WND_PRC__SIZE_OF_ROW_SMALL;
 
		w->widget[7].unkA = (w->vscroll.cap << 8) + 1;
 
		break;
 
	}
ship_gui.c
Show inline comments
 
@@ -962,14 +962,13 @@ static void PlayerShipsWndProc(Window *w
 
			}
 
			DrawWindowWidgets(w);
 
		}
 
		/* draw sorting criteria string */
 
		DrawString(85, 15, _vehicle_sort_listing[vl->sort_type], 0x10);
 
		/* draw arrow pointing up/down for ascending/descending sorting */
 
		DoDrawString(
 
			vl->flags & VL_DESC ? "\xAA" : "\xA0", 69, 15, 0x10);
 
		DoDrawString(vl->flags & VL_DESC ? "\xAA" : "\xA0", 69, 15, 0x10);
 

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

	
 
@@ -1002,12 +1001,13 @@ static void PlayerShipsWndProc(Window *w
 

	
 
	case WE_CLICK: {
 
		switch(e->click.widget) {
 
		case 3: /* Flip sorting method ascending/descending */
 
			vl->flags ^= VL_DESC;
 
			vl->flags |= VL_RESORT;
 
			_sorting.ship.order = !!(vl->flags & VL_DESC);
 
			SetWindowDirty(w);
 
			break;
 
		case 4: case 5:/* Select sorting criteria dropdown menu */
 
			ShowDropDownMenu(w, _vehicle_sort_listing, vl->sort_type, 5, 0, 0);
 
			return;
 
		case 7: { /* Matrix to show vehicles */
 
@@ -1063,24 +1063,25 @@ static void PlayerShipsWndProc(Window *w
 

	
 
	case WE_DROPDOWN_SELECT: /* we have selected a dropdown item in the list */
 
		if (vl->sort_type != e->dropdown.index) {
 
			// value has changed -> resort
 
			vl->flags |= VL_RESORT;
 
			vl->sort_type = e->dropdown.index;
 
			_sorting.ship.criteria = vl->sort_type;
 

	
 
			// enable 'Sort By' if a sorter criteria is chosen
 
			if (vl->sort_type != SORT_BY_UNSORTED)
 
				w->disabled_state &= ~(1 << 3);
 
				CLRBIT(w->disabled_state, 3);
 
		}
 
		SetWindowDirty(w);
 
		break;
 

	
 
	case WE_CREATE: /* set up resort timer */
 
		vl->sort_list = NULL;
 
		vl->flags = VL_REBUILD;
 
		vl->sort_type = SORT_BY_UNSORTED;
 
		vl->flags = VL_REBUILD | (_sorting.ship.order << (VL_DESC - 1));
 
		vl->sort_type = _sorting.ship.criteria;
 
		vl->resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS;
 
		break;
 

	
 
	case WE_DESTROY:
 
		free(vl->sort_list);
 
		break;
train_gui.c
Show inline comments
 
@@ -1304,14 +1304,13 @@ static void PlayerTrainsWndProc(Window *
 
			}
 
			DrawWindowWidgets(w);
 
		}
 
		/* draw sorting criteria string */
 
		DrawString(85, 15, _vehicle_sort_listing[vl->sort_type], 0x10);
 
		/* draw arrow pointing up/down for ascending/descending sorting */
 
		DoDrawString(
 
			vl->flags & VL_DESC ? "\xAA" : "\xA0", 69, 15, 0x10);
 
		DoDrawString(vl->flags & VL_DESC ? "\xAA" : "\xA0", 69, 15, 0x10);
 

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

	
 
@@ -1344,12 +1343,13 @@ static void PlayerTrainsWndProc(Window *
 

	
 
	case WE_CLICK: {
 
		switch(e->click.widget) {
 
		case 3: /* Flip sorting method ascending/descending */
 
			vl->flags ^= VL_DESC;
 
			vl->flags |= VL_RESORT;
 
			_sorting.train.order = !!(vl->flags & VL_DESC);
 
			SetWindowDirty(w);
 
			break;
 

	
 
		case 4: case 5:/* Select sorting criteria dropdown menu */
 
			ShowDropDownMenu(w, _vehicle_sort_listing, vl->sort_type, 5, 0, 0);
 
			return;
 
@@ -1406,24 +1406,25 @@ static void PlayerTrainsWndProc(Window *
 

	
 
	case WE_DROPDOWN_SELECT: /* we have selected a dropdown item in the list */
 
		if (vl->sort_type != e->dropdown.index) {
 
			// value has changed -> resort
 
			vl->flags |= VL_RESORT;
 
			vl->sort_type = e->dropdown.index;
 
			_sorting.train.criteria = vl->sort_type;
 

	
 
			// enable 'Sort By' if a sorter criteria is chosen
 
			if (vl->sort_type != SORT_BY_UNSORTED)
 
				w->disabled_state &= ~(1 << 3);
 
				CLRBIT(w->disabled_state, 3);
 
		}
 
		SetWindowDirty(w);
 
		break;
 

	
 
	case WE_CREATE: /* set up resort timer */
 
		vl->sort_list = NULL;
 
		vl->flags = VL_REBUILD;
 
		vl->sort_type = SORT_BY_UNSORTED;
 
		vl->flags = VL_REBUILD | (_sorting.train.order << (VL_DESC - 1));
 
		vl->sort_type = _sorting.train.criteria;
 
		vl->resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS;
 
		break;
 

	
 
	case WE_DESTROY:
 
		free(vl->sort_list);
 
		break;
ttd.c
Show inline comments
 
@@ -718,12 +718,13 @@ int ttd_main(int argc, char* argv[])
 
	// ugly hack, if diff_level is 9, it means we got no setting from the config file, so we load the default settings.
 
	if (_opt_mod_ptr->diff_level == 9)
 
		SetDifficultyLevel(0, _opt_mod_ptr);
 

	
 
	// initialize the ingame console
 
	IConsoleInit();
 
	InitializeGUI();
 
	IConsoleCmdExec("exec scripts/autoexec.scr 0");
 

	
 
	InitPlayerRandoms();
 

	
 
#ifdef ENABLE_NETWORK
 
	if ((network) && (_network_available)) {
vehicle_gui.c
Show inline comments
 
@@ -1008,6 +1008,11 @@ void ShowReplaceVehicleWindow(byte vehic
 
		default: return;
 
	}
 
	w->caption_color = _local_player;
 
	WP(w,replaceveh_d).vehicletype = vehicletype;
 
	w->vscroll2.cap = w->vscroll.cap;   // these two are always the same
 
}
 

	
 
void InitializeGUI(void)
 
{
 
	memset(&_sorting, 0, sizeof(_sorting));
 
}
vehicle_gui.h
Show inline comments
 
@@ -42,18 +42,32 @@ typedef DEF_SORTER(VehicleSortListingTyp
 
#define SORT_BY_UNSORTED 0
 
extern VehicleSortListingTypeFunctions * const _vehicle_sorter[];
 
extern const StringID _vehicle_sort_listing[];
 
extern const StringID _rail_types_list[];
 

	
 
enum VehicleSortTypes {
 
	VEHTRAIN		= 0,
 
	VEHROAD			= 1,
 
	VEHSHIP			= 2,
 
	VEHAIRCRAFT		= 3
 
	VEHTRAIN     = 0,
 
	VEHROAD      = 1,
 
	VEHSHIP      = 2,
 
	VEHAIRCRAFT  = 3
 
};
 

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

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

	
 
VARDEF Sorting _sorting;
 

	
 
enum {
 
  PLY_WND_PRC__OFFSET_TOP_WIDGET	= 26,
 
	PLY_WND_PRC__SIZE_OF_ROW_SMALL	= 26,
 
  PLY_WND_PRC__SIZE_OF_ROW_BIG		= 36,
 
};
 

	
0 comments (0 inline, 0 general)