MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / BuildGuiGroupList

Function BuildGuiGroupList

src/group_gui.cpp:167–193  ·  view source on GitHub ↗

* Build GUI group list, a sorted hierarchical list of groups for owner and vehicle type. * @param dst Destination list, owned by the caller. * @param fold Whether to handle group folding/hiding. * @param owner Owner of groups. * @param veh_type Vehicle type of groups. */

Source from the content-addressed store, hash-verified

165 * @param veh_type Vehicle type of groups.
166 */
167void BuildGuiGroupList(GUIGroupList &list, bool fold, Owner owner, VehicleType veh_type)
168{
169 /* Make a temporary list of parent groups */
170 std::vector<GUIGroupListItem> sublist;
171 for (const Group *g : Group::Iterate()) {
172 if (g->parent != GroupID::Invalid()) continue;
173 if (g->owner != owner) continue;
174 if (g->vehicle_type != veh_type) continue;
175 sublist.emplace_back(g, 0);
176 }
177 SortGUIGroupList(sublist);
178
179 /* Now add each parent group, and its children if necessary, to the list. */
180 for (auto &item : sublist) {
181 GuiGroupListAddChildren(list, list.emplace_back(item), fold);
182 }
183
184 if (list.empty()) return;
185
186 /* Hierarchy is complete, traverse in reverse to find where indentation levels continue. */
187 uint16_t level_mask = 0;
188 for (auto it = std::rbegin(list); std::next(it) != std::rend(list); ++it) {
189 auto next_it = std::next(it);
190 AssignBit(level_mask, it->indent, it->indent <= next_it->indent);
191 next_it->level_mask = level_mask;
192 }
193}
194
195/* Columns in the group list */
196enum VehicleGroupColumns : uint8_t {

Callers 2

BuildGroupListMethod · 0.85
BuildGroupListMethod · 0.85

Calls 7

InvalidFunction · 0.85
SortGUIGroupListFunction · 0.85
GuiGroupListAddChildrenFunction · 0.85
rbeginFunction · 0.85
rendFunction · 0.85
AssignBitFunction · 0.85
emptyMethod · 0.45

Tested by

no test coverage detected