diff --git a/plugins/listcolumn.h b/plugins/listcolumn.h index 5c96b4594..9914c8ea7 100644 --- a/plugins/listcolumn.h +++ b/plugins/listcolumn.h @@ -317,6 +317,18 @@ public: return results[0]; } + bool hasSelection() + { + for (auto item : list) + { + if (item.selected) + { + return true; + } + } + return false; + } + void clearSelection() { for_each_(list, clear_fn); diff --git a/plugins/manipulator.cpp b/plugins/manipulator.cpp index dfc7c1f0d..2bbb9d8c3 100644 --- a/plugins/manipulator.cpp +++ b/plugins/manipulator.cpp @@ -954,6 +954,7 @@ public: viewscreen_unitprofessionset(vector &base_units, bool filter_selected = true ) + :menu_options(-1) // default { menu_options.multiselect = false; menu_options.auto_select = true; @@ -967,7 +968,7 @@ public: std::string name = manager.templates[i].name; if (manager.templates[i].mask) name += " (mask)"; - ListEntry elem(name, i+1); + ListEntry elem(name, i); menu_options.add(elem); } menu_options.filterDisplay(); @@ -1001,20 +1002,22 @@ public: } if (events->count(interface_key::SELECT)) { - select_profession(menu_options.getFirstSelectedElem()); + if (menu_options.hasSelection()) + { + select_profession(menu_options.getFirstSelectedElem()); + } Screen::dismiss(this); return; } } void select_profession(size_t selected) { - if (selected > manager.templates.size()) + if (manager.templates.empty() || selected >= manager.templates.size()) return; - ProfessionTemplate prof = manager.templates[selected - 1]; + ProfessionTemplate prof = manager.templates[selected]; - for (auto it = units.begin(); it != units.end(); ++it) + for (UnitInfo *u : units) { - UnitInfo* u = (*it); if (!u || !u->unit || !u->allowEdit) continue; prof.apply(u); }