aircraft_gui.c
changeset 1246 eb66ff34348f
parent 1209 2e00193652b2
child 1294 4cdf0e76c093
equal deleted inserted replaced
1245:3822f77cbc53 1246:eb66ff34348f
  1019 			DrawWindowWidgets(w);
  1019 			DrawWindowWidgets(w);
  1020 		}
  1020 		}
  1021 		/* draw sorting criteria string */
  1021 		/* draw sorting criteria string */
  1022 		DrawString(85, 15, _vehicle_sort_listing[vl->sort_type], 0x10);
  1022 		DrawString(85, 15, _vehicle_sort_listing[vl->sort_type], 0x10);
  1023 		/* draw arrow pointing up/down for ascending/descending sorting */
  1023 		/* draw arrow pointing up/down for ascending/descending sorting */
  1024 		DoDrawString(
  1024 		DoDrawString(vl->flags & VL_DESC ? "\xAA" : "\xA0", 69, 15, 0x10);
  1025 			vl->flags & VL_DESC ? "\xAA" : "\xA0", 69, 15, 0x10);
       
  1026 
  1025 
  1027 		max = min(w->vscroll.pos + w->vscroll.cap, vl->list_length);
  1026 		max = min(w->vscroll.pos + w->vscroll.cap, vl->list_length);
  1028 		for (i = w->vscroll.pos; i < max; ++i) {
  1027 		for (i = w->vscroll.pos; i < max; ++i) {
  1029 			Vehicle *v = GetVehicle(vl->sort_list[i].index);
  1028 			Vehicle *v = GetVehicle(vl->sort_list[i].index);
  1030 			StringID str;
  1029 			StringID str;
  1059 	case WE_CLICK: {
  1058 	case WE_CLICK: {
  1060 		switch(e->click.widget) {
  1059 		switch(e->click.widget) {
  1061 		case 3: /* Flip sorting method ascending/descending */
  1060 		case 3: /* Flip sorting method ascending/descending */
  1062 			vl->flags ^= VL_DESC;
  1061 			vl->flags ^= VL_DESC;
  1063 			vl->flags |= VL_RESORT;
  1062 			vl->flags |= VL_RESORT;
       
  1063 			_sorting.aircraft.order = !!(vl->flags & VL_DESC);
  1064 			SetWindowDirty(w);
  1064 			SetWindowDirty(w);
  1065 			break;
  1065 			break;
  1066 
  1066 
  1067 		case 4: case 5:/* Select sorting criteria dropdown menu */
  1067 		case 4: case 5:/* Select sorting criteria dropdown menu */
  1068 			ShowDropDownMenu(w, _vehicle_sort_listing, vl->sort_type, 5, 0, 0);
  1068 			ShowDropDownMenu(w, _vehicle_sort_listing, vl->sort_type, 5, 0, 0);
  1121 	case WE_DROPDOWN_SELECT: /* we have selected a dropdown item in the list */
  1121 	case WE_DROPDOWN_SELECT: /* we have selected a dropdown item in the list */
  1122 		if (vl->sort_type != e->dropdown.index) {
  1122 		if (vl->sort_type != e->dropdown.index) {
  1123 			// value has changed -> resort
  1123 			// value has changed -> resort
  1124 			vl->flags |= VL_RESORT;
  1124 			vl->flags |= VL_RESORT;
  1125 			vl->sort_type = e->dropdown.index;
  1125 			vl->sort_type = e->dropdown.index;
       
  1126 			_sorting.aircraft.criteria = vl->sort_type;
  1126 
  1127 
  1127 			// enable 'Sort By' if a sorter criteria is chosen
  1128 			// enable 'Sort By' if a sorter criteria is chosen
  1128 			if (vl->sort_type != SORT_BY_UNSORTED)
  1129 			if (vl->sort_type != SORT_BY_UNSORTED)
  1129 				w->disabled_state &= ~(1 << 3);
  1130 				CLRBIT(w->disabled_state, 3);
  1130 		}
  1131 		}
  1131 		SetWindowDirty(w);
  1132 		SetWindowDirty(w);
  1132 		break;
  1133 		break;
  1133 
  1134 
  1134 	case WE_CREATE: /* set up resort timer */
  1135 	case WE_CREATE: /* set up resort timer */
  1135 		vl->sort_list = NULL;
  1136 		vl->sort_list = NULL;
  1136 		vl->flags = VL_REBUILD;
  1137 		vl->flags = VL_REBUILD | (_sorting.aircraft.order << (VL_DESC - 1));
  1137 		vl->sort_type = SORT_BY_UNSORTED;
  1138 		vl->sort_type = _sorting.aircraft.criteria;
  1138 		vl->resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS;
  1139 		vl->resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS;
  1139 		break;
  1140 		break;
  1140 
  1141 
  1141 	case WE_DESTROY:
  1142 	case WE_DESTROY:
  1142 		free(vl->sort_list);
  1143 		free(vl->sort_list);