mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-02-03 21:06:58 +00:00
(svn r19541) -Feature: Sort the list of refit options by cargo class / name.
This commit is contained in:
parent
fdc146b3c1
commit
0100def074
@ -234,6 +234,11 @@ struct RefitOption {
|
||||
{
|
||||
return other.cargo != this->cargo || other.value != this->value;
|
||||
}
|
||||
|
||||
FORCEINLINE bool operator == (const RefitOption &other) const
|
||||
{
|
||||
return other.cargo == this->cargo && other.value == this->value;
|
||||
}
|
||||
};
|
||||
|
||||
typedef SmallVector<RefitOption, 32> RefitList;
|
||||
@ -258,7 +263,7 @@ static void BuildRefitList(const Vehicle *v, RefitList *refit_list)
|
||||
|
||||
/* Loop through all cargos in the refit mask */
|
||||
const CargoSpec *cs;
|
||||
FOR_ALL_CARGOSPECS(cs) {
|
||||
FOR_ALL_SORTED_CARGOSPECS(cs) {
|
||||
CargoID cid = cs->Index();
|
||||
/* Skip cargo type if it's not listed */
|
||||
if (!HasBit(cmask, cid)) continue;
|
||||
@ -380,6 +385,35 @@ struct RefitWindow : public Window {
|
||||
this->vscroll.SetCount(this->list.Length());
|
||||
}
|
||||
|
||||
virtual void OnInit()
|
||||
{
|
||||
if (this->cargo != NULL) {
|
||||
/* Store the RefitOption currently in use. */
|
||||
RefitOption current_refit_option = *(this->cargo);
|
||||
|
||||
/* Rebuild the refit list */
|
||||
BuildRefitList(Vehicle::Get(this->window_number), &this->list);
|
||||
this->vscroll.SetCount(this->list.Length());
|
||||
this->sel = -1;
|
||||
this->cargo = NULL;
|
||||
for (uint i = 0; i < this->list.Length(); i++) {
|
||||
if (this->list[i] == current_refit_option) {
|
||||
this->sel = i;
|
||||
this->cargo = &this->list[i];
|
||||
this->vscroll.ScrollTowards(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* If the selected refit option was not found, scroll the window to the initial position. */
|
||||
if (this->sel == -1) this->vscroll.ScrollTowards(0);
|
||||
} else {
|
||||
/* Rebuild the refit list */
|
||||
BuildRefitList(Vehicle::Get(this->window_number), &this->list);
|
||||
this->vscroll.SetCount(this->list.Length());
|
||||
}
|
||||
}
|
||||
|
||||
virtual void OnPaint()
|
||||
{
|
||||
Vehicle *v = Vehicle::Get(this->window_number);
|
||||
|
Loading…
Reference in New Issue
Block a user