summaryrefslogtreecommitdiff
path: root/src/group_gui.cpp
diff options
context:
space:
mode:
authorstormcone <48624099+stormcone@users.noreply.github.com>2019-05-10 18:24:16 +0200
committerCharles Pigott <charlespigott@googlemail.com>2019-12-23 18:04:10 +0000
commit551bde77a49878a984c04c47c280c9681292c84f (patch)
tree39a0b0213ba7061c5fdfa51f776332001917fdb0 /src/group_gui.cpp
parent42144ecd562ee05423e16452cc999929296b138c (diff)
downloadopenttd-551bde77a49878a984c04c47c280c9681292c84f.tar.xz
Add: A function which selects and scrolls to a particular group in the vehicle group window.
Diffstat (limited to 'src/group_gui.cpp')
-rw-r--r--src/group_gui.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/group_gui.cpp b/src/group_gui.cpp
index 256c85ba4..a4c00c129 100644
--- a/src/group_gui.cpp
+++ b/src/group_gui.cpp
@@ -368,6 +368,7 @@ public:
this->groups.ForceRebuild();
this->groups.NeedResort();
this->BuildGroupList(vli.company);
+ this->group_sb->SetCount((uint)this->groups.size());
this->GetWidget<NWidgetCore>(WID_GL_CAPTION)->widget_data = STR_VEHICLE_LIST_TRAIN_CAPTION + this->vli.vtype;
this->GetWidget<NWidgetCore>(WID_GL_LIST_VEHICLE)->tool_tip = STR_VEHICLE_LIST_TRAIN_LIST_TOOLTIP + this->vli.vtype;
@@ -991,6 +992,35 @@ public:
{
if (this->vehicle_sel == vehicle) ResetObjectToPlace();
}
+
+ /**
+ * Selects the specified group in the list
+ *
+ * @param g_id The ID of the group to be selected
+ */
+ void SelectGroup(const GroupID g_id)
+ {
+ if (g_id == INVALID_GROUP || g_id == this->vli.index) return;
+
+ this->vli.index = g_id;
+ if (g_id != ALL_GROUP && g_id != DEFAULT_GROUP) {
+ const Group *g = Group::Get(g_id);
+ int id_g = find_index(this->groups, g);
+ // The group's branch is maybe collapsed, so try to expand it
+ if (id_g == -1) {
+ for (auto pg = Group::GetIfValid(g->parent); pg != nullptr; pg = Group::GetIfValid(pg->parent)) {
+ pg->folded = false;
+ }
+ this->groups.ForceRebuild();
+ this->BuildGroupList(this->owner);
+ id_g = find_index(this->groups, g);
+ }
+ this->group_sb->ScrollTowards(id_g);
+ }
+ this->vehicles.ForceRebuild();
+ this->SetDirty();
+ }
+
};