Merge branch 'master' into jgrpp
# Conflicts: # src/company_gui.cpp # src/group_gui.cpp # src/newgrf.cpp # src/newgrf_debug_gui.cpp # src/saveload/saveload.cpp
This commit is contained in:
@@ -29,6 +29,7 @@
|
||||
#include "gfx_func.h"
|
||||
#include "tbtr_template_gui_main.h"
|
||||
#include "newgrf_debug.h"
|
||||
#include "group_gui_list.h"
|
||||
|
||||
#include "widgets/group_widget.h"
|
||||
|
||||
@@ -36,8 +37,6 @@
|
||||
|
||||
#include "safeguards.h"
|
||||
|
||||
typedef GUIList<const Group*> GUIGroupList;
|
||||
|
||||
static const NWidgetPart _nested_group_widgets[] = {
|
||||
NWidget(NWID_HORIZONTAL), // Window header
|
||||
NWidget(WWT_CLOSEBOX, COLOUR_GREY),
|
||||
@@ -117,29 +116,28 @@ static const NWidgetPart _nested_group_widgets[] = {
|
||||
EndContainer(),
|
||||
};
|
||||
|
||||
/* cached values for GroupNameSorter to spare many GetString() calls */
|
||||
static const Group *_last_group[2] = { nullptr, nullptr };
|
||||
|
||||
/** Sort the groups by their name */
|
||||
bool GroupNameSorter(const Group * const &a, const Group * const &b)
|
||||
void SortGUIGroupList(GUIGroupList &list)
|
||||
{
|
||||
static char last_name[2][64] = { "", "" };
|
||||
/* Sort the groups by their name */
|
||||
const Group *last_group[2] = { nullptr, nullptr };
|
||||
std::string last_name[2] = { {}, {} };
|
||||
list.Sort([&](const Group * const &a, const Group * const &b) {
|
||||
if (a != last_group[0]) {
|
||||
last_group[0] = a;
|
||||
SetDParam(0, a->index);
|
||||
last_name[0] = GetString(STR_GROUP_NAME);
|
||||
}
|
||||
|
||||
if (a != _last_group[0]) {
|
||||
_last_group[0] = a;
|
||||
SetDParam(0, a->index);
|
||||
GetString(last_name[0], STR_GROUP_NAME, lastof(last_name[0]));
|
||||
}
|
||||
if (b != last_group[1]) {
|
||||
last_group[1] = b;
|
||||
SetDParam(0, b->index);
|
||||
last_name[1] = GetString(STR_GROUP_NAME);
|
||||
}
|
||||
|
||||
if (b != _last_group[1]) {
|
||||
_last_group[1] = b;
|
||||
SetDParam(0, b->index);
|
||||
GetString(last_name[1], STR_GROUP_NAME, lastof(last_name[1]));
|
||||
}
|
||||
|
||||
int r = StrNaturalCompare(last_name[0], last_name[1]); // Sort by name (natural sorting).
|
||||
if (r == 0) return a->index < b->index;
|
||||
return r < 0;
|
||||
int r = StrNaturalCompare(last_name[0], last_name[1]); // Sort by name (natural sorting).
|
||||
if (r == 0) return a->index < b->index;
|
||||
return r < 0;
|
||||
});
|
||||
}
|
||||
|
||||
class VehicleGroupWindow : public BaseVehicleListWindow {
|
||||
@@ -222,11 +220,7 @@ private:
|
||||
this->SetWidgetDisabledState(WID_GL_COLLAPSE_ALL_GROUPS, !enable_collapse_all);
|
||||
|
||||
list.ForceResort();
|
||||
|
||||
/* invalidate cached values for name sorter - group names could change */
|
||||
_last_group[0] = _last_group[1] = nullptr;
|
||||
|
||||
list.Sort(&GroupNameSorter);
|
||||
SortGUIGroupList(list);
|
||||
|
||||
AddChildren(list, INVALID_GROUP, 0);
|
||||
|
||||
|
Reference in New Issue
Block a user