mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r21866) -Feature [FS#4394]: [NewGRF] Rail type property to influence sorting of rail types in the drop down list
This commit is contained in:
parent
6a2ae92811
commit
2f6c840ebf
|
@ -3263,6 +3263,10 @@ static ChangeInfoResult RailTypeChangeInfo(uint id, int numinfo, int prop, ByteR
|
||||||
rti->introduction_date = buf->ReadDWord();
|
rti->introduction_date = buf->ReadDWord();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 0x1A: // Sort order
|
||||||
|
rti->sorting_order = buf->ReadByte();
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
ret = CIR_UNKNOWN;
|
ret = CIR_UNKNOWN;
|
||||||
break;
|
break;
|
||||||
|
@ -3320,6 +3324,7 @@ static ChangeInfoResult RailTypeReserveInfo(uint id, int numinfo, int prop, Byte
|
||||||
case 0x12: // Station graphic
|
case 0x12: // Station graphic
|
||||||
case 0x15: // Acceleration model
|
case 0x15: // Acceleration model
|
||||||
case 0x16: // Map colour
|
case 0x16: // Map colour
|
||||||
|
case 0x1A: // Sort order
|
||||||
buf->ReadByte();
|
buf->ReadByte();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -237,6 +237,11 @@ struct RailtypeInfo {
|
||||||
*/
|
*/
|
||||||
RailTypes introduces_railtypes;
|
RailTypes introduces_railtypes;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The sorting order of this railtype for the toolbar dropdown.
|
||||||
|
*/
|
||||||
|
byte sorting_order;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sprite groups for resolving sprites
|
* Sprite groups for resolving sprites
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -106,6 +106,14 @@ RailType AllocateRailType(RailTypeLabel label)
|
||||||
|
|
||||||
/* We also introduce ourself. */
|
/* We also introduce ourself. */
|
||||||
rti->introduces_railtypes = (RailTypes)(1 << rt);
|
rti->introduces_railtypes = (RailTypes)(1 << rt);
|
||||||
|
|
||||||
|
/* Default sort order; order of allocation, but with some
|
||||||
|
* offsets so it's easier for NewGRF to pick a spot without
|
||||||
|
* changing the order of other (original) rail types.
|
||||||
|
* The << is so you can place other railtypes in between the
|
||||||
|
* other railtypes, the 7 is to be able to place something
|
||||||
|
* before the first (default) rail type. */
|
||||||
|
rti->sorting_order = rt << 4 | 7;
|
||||||
return rt;
|
return rt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,6 +104,9 @@ static const RailtypeInfo _original_railtypes[] = {
|
||||||
/* introduction rail types */
|
/* introduction rail types */
|
||||||
RAILTYPES_RAIL,
|
RAILTYPES_RAIL,
|
||||||
|
|
||||||
|
/* sort order */
|
||||||
|
0 << 4 | 7,
|
||||||
|
|
||||||
{ NULL },
|
{ NULL },
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -196,6 +199,9 @@ static const RailtypeInfo _original_railtypes[] = {
|
||||||
/* introduction rail types */
|
/* introduction rail types */
|
||||||
RAILTYPES_ELECTRIC,
|
RAILTYPES_ELECTRIC,
|
||||||
|
|
||||||
|
/* sort order */
|
||||||
|
1 << 4 | 7,
|
||||||
|
|
||||||
{ NULL },
|
{ NULL },
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -284,6 +290,9 @@ static const RailtypeInfo _original_railtypes[] = {
|
||||||
/* introduction rail types */
|
/* introduction rail types */
|
||||||
RAILTYPES_MONO,
|
RAILTYPES_MONO,
|
||||||
|
|
||||||
|
/* sort order */
|
||||||
|
2 << 4 | 7,
|
||||||
|
|
||||||
{ NULL },
|
{ NULL },
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -372,6 +381,9 @@ static const RailtypeInfo _original_railtypes[] = {
|
||||||
/* introduction rail types */
|
/* introduction rail types */
|
||||||
RAILTYPES_MAGLEV,
|
RAILTYPES_MAGLEV,
|
||||||
|
|
||||||
|
/* sort order */
|
||||||
|
3 << 4 | 7,
|
||||||
|
|
||||||
{ NULL },
|
{ NULL },
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -691,6 +691,17 @@ static CallBackFunction ToolbarZoomOutClick(Window *w)
|
||||||
|
|
||||||
/* --- Rail button menu --- */
|
/* --- Rail button menu --- */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compare railtypes based on their sorting order.
|
||||||
|
* @param first The railtype to compare to.
|
||||||
|
* @param second The railtype to compare.
|
||||||
|
* @return True iff the first should be sorted before the second.
|
||||||
|
*/
|
||||||
|
static bool CompareRailTypes(const DropDownListItem *first, const DropDownListItem *second)
|
||||||
|
{
|
||||||
|
return GetRailTypeInfo((RailType)first->result)->sorting_order < GetRailTypeInfo((RailType)second->result)->sorting_order;
|
||||||
|
}
|
||||||
|
|
||||||
static CallBackFunction ToolbarBuildRailClick(Window *w)
|
static CallBackFunction ToolbarBuildRailClick(Window *w)
|
||||||
{
|
{
|
||||||
RailTypes used_railtypes = RAILTYPES_NONE;
|
RailTypes used_railtypes = RAILTYPES_NONE;
|
||||||
|
@ -722,6 +733,7 @@ static CallBackFunction ToolbarBuildRailClick(Window *w)
|
||||||
item->SetParam(1, rti->max_speed);
|
item->SetParam(1, rti->max_speed);
|
||||||
list->push_back(item);
|
list->push_back(item);
|
||||||
}
|
}
|
||||||
|
list->sort(CompareRailTypes);
|
||||||
ShowDropDownList(w, list, _last_built_railtype, TBN_RAILS, 140, true, true);
|
ShowDropDownList(w, list, _last_built_railtype, TBN_RAILS, 140, true, true);
|
||||||
SndPlayFx(SND_15_BEEP);
|
SndPlayFx(SND_15_BEEP);
|
||||||
return CBF_NONE;
|
return CBF_NONE;
|
||||||
|
|
Loading…
Reference in New Issue