* 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. */
| 165 | * @param veh_type Vehicle type of groups. |
| 166 | */ |
| 167 | void 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 */ |
| 196 | enum VehicleGroupColumns : uint8_t { |
no test coverage detected