From e2bbe487d05df370f74ed80133f943738eda77d5 Mon Sep 17 00:00:00 2001 From: Oznogon Date: Tue, 31 Mar 2026 15:21:06 -0700 Subject: [PATCH] Enforce GM info k/v order, add Faction --- src/screens/gm/gameMasterScreen.cpp | 75 ++++++++++++++++++----------- 1 file changed, 48 insertions(+), 27 deletions(-) diff --git a/src/screens/gm/gameMasterScreen.cpp b/src/screens/gm/gameMasterScreen.cpp index d990b1b234..300d4be229 100644 --- a/src/screens/gm/gameMasterScreen.cpp +++ b/src/screens/gm/gameMasterScreen.cpp @@ -16,6 +16,7 @@ #include "components/collision.h" #include "components/gravity.h" #include "components/hull.h" +#include "components/shields.h" #include "components/comms.h" #include "components/player.h" #include "components/name.h" @@ -35,20 +36,20 @@ #include "gui/gui2_keyvaluedisplay.h" #include "gui/gui2_textentry.h" -static std::unordered_map getGMInfo(sp::ecs::Entity entity) +static std::vector> getGMInfo(sp::ecs::Entity entity) { - std::unordered_map result; + std::vector> result; if (auto cs = entity.getComponent()) - result[trMark("gm_info", "CallSign")] = cs->callsign; + result.emplace_back(trMark("gm_info", "Callsign"), cs->callsign); + if (entity.hasComponent()) + result.emplace_back(trMark("gm_info", "Faction"), Faction::getInfo(entity).locale_name); if (auto tn = entity.getComponent()) - result[trMark("gm_info", "Type")] = tn->localized; + result.emplace_back(trMark("gm_info", "Type"), tn->localized); + if (auto shields = entity.getComponent()) + for (size_t n = 0; n < shields->entries.size(); n++) + result.emplace_back(trMark("gm_info", "Shield {n}").format({{"n", string(static_cast(n) + 1)}}), string(shields->entries[n].level) + "/" + string(shields->entries[n].max)); if (auto hull = entity.getComponent()) - result[trMark("gm_info", "Hull")] = string(hull->current) + "/" + string(hull->max); - //for(int n=0; ncurrent) + "/" + string(hull->max)); /* from missile weapons if (owner) { @@ -424,39 +425,59 @@ void GameMasterScreen::update(float delta) // Update mission clock info_clock->setValue(gameGlobalInfo->getMissionTime()); - std::unordered_map selection_info; + // Store k/vs in order. + std::vector> selection_info; + // Track selection indices to determine "*mixed*" state. + std::unordered_map selection_info_index; - // For each selected object, determine and report their type. - for (auto entity : targets.getTargets()) + // List position if only one entity is selected. + if (targets.getTargets().size() == 1) { - auto info = getGMInfo(entity); - for (auto i = info.begin(); i != info.end(); i++) + if (auto t = targets.get().getComponent()) { - if (selection_info.find(i->first) == selection_info.end()) - selection_info[i->first] = i->second; - else if (selection_info[i->first] != i->second) - selection_info[i->first] = tr("*mixed*"); + string pos_key = trMark("gm_info", "Position"); + string pos_val = string(t->getPosition().x, 0) + "," + string(t->getPosition().y, 0); + auto it = selection_info_index.find(pos_key); + if (it == selection_info_index.end()) + { + selection_info_index[pos_key] = selection_info.size(); + selection_info.emplace_back(pos_key, pos_val); + } + else + selection_info[it->second].second = pos_val; } } - if (targets.getTargets().size() == 1) + // For each selected object, determine and report their type. + for (auto entity : targets.getTargets()) { - if (auto t = targets.get().getComponent()) - selection_info[trMark("gm_info", "Position")] = string(t->getPosition().x, 0) + "," + string(t->getPosition().y, 0); + for (auto& [key, value] : getGMInfo(entity)) + { + auto it = selection_info_index.find(key); + if (it == selection_info_index.end()) + { + selection_info_index[key] = selection_info.size(); + selection_info.emplace_back(key, value); + } + else if (selection_info[it->second].second != value) + selection_info[it->second].second = tr("*mixed*"); + } } + // List GM info items for selection, if any. unsigned int cnt = 0; - for (std::unordered_map::iterator i = selection_info.begin(); i != selection_info.end(); i++) + for (auto& [key, value] : selection_info) { if (cnt == info_items.size()) { - info_items.push_back(new GuiKeyValueDisplay(info_layout, "INFO_" + string(cnt), 0.5, i->first, i->second)); - info_items[cnt]->setSize(GuiElement::GuiSizeMax, 30); + info_items.push_back(new GuiKeyValueDisplay(info_layout, "INFO_" + string(cnt), 0.5f, key, value)); + info_items[cnt]->setSize(GuiElement::GuiSizeMax, 30.0f); } else { - info_items[cnt]->show(); - info_items[cnt]->setKey(tr("gm_info", i->first))->setValue(i->second); + info_items[cnt] + ->setKey(tr("gm_info", key))->setValue(value) + ->show(); } cnt++; }