From 624656875f9bc4c36ef2cc53948a158709487c20 Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 26 Jan 2023 00:47:07 +0100 Subject: Extracted ship type combo box to a function --- kurator/src/ScenarioEditor.cpp | 47 +++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/kurator/src/ScenarioEditor.cpp b/kurator/src/ScenarioEditor.cpp index 2df55c9..b657230 100644 --- a/kurator/src/ScenarioEditor.cpp +++ b/kurator/src/ScenarioEditor.cpp @@ -21,6 +21,7 @@ namespace kurator bool groups_editor(std::shared_ptr repo, std::vector& groups); bool loadout_editor(std::shared_ptr repo, campaign::Loadout& loadout); +bool ship_type_combo(const char* id, std::shared_ptr repo, universe::ShipType& type); ScenarioEditor::ScenarioEditor(std::shared_ptr _session) : @@ -135,24 +136,7 @@ groups_editor(std::shared_ptr repo, std::vector& gr bool loadout_editor(std::shared_ptr repo, campaign::Loadout& loadout) { - bool changed = false; - if (ImGui::BeginCombo("Ship Type", loadout.type.name.c_str())) { - repo->for_ship_types([&](const auto& type){ - if (ImGui::Selectable(type.name.c_str(), loadout.type.name == type.name)) { - loadout.type = type; - changed = true; - } - if (ImGui::IsItemHovered()) { - ImGui::BeginTooltip(); - ImGui::Text("Shield: %.0f", type.base_shield_points); - ImGui::Text("Armour: %.0f", type.base_armour_points); - ImGui::Text("Structure: %.0f", type.base_structure_points); - ImGui::Text("Speed: %.0f m/s", type.max_speed); - ImGui::EndTooltip(); - } - }); - ImGui::EndCombo(); - } + bool changed = ship_type_combo("Ship Type", repo, loadout.type); ImGui::Indent(); auto it = loadout.turrets.begin(); while (it != loadout.turrets.end()) { @@ -181,4 +165,29 @@ loadout_editor(std::shared_ptr repo, campaign::Loadout& lo } -} // namespace kurator \ No newline at end of file +bool +ship_type_combo(const char* id, std::shared_ptr repo, universe::ShipType& type) +{ + bool changed = false; + if (ImGui::BeginCombo(id, type.name.c_str())) { + repo->for_ship_types([&](const auto& opt){ + if (ImGui::Selectable(opt.name.c_str(), opt.name == type.name)) { + type = opt; + changed = true; + } + if (ImGui::IsItemHovered()) { + ImGui::BeginTooltip(); + ImGui::Text("Shield: %.0f", opt.base_shield_points); + ImGui::Text("Armour: %.0f", opt.base_armour_points); + ImGui::Text("Structure: %.0f", opt.base_structure_points); + ImGui::Text("Speed: %.0f m/s", opt.max_speed); + ImGui::EndTooltip(); + } + }); + ImGui::EndCombo(); + } + return changed; +} + + +} // namespace kurator -- cgit v1.1