From cb63d6d56637b887e38a45c6f2cd20044a59bc7c Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 11 Jan 2023 23:40:04 +0100 Subject: Loadout editor is now a function call --- kurator/src/ScenarioEditor.cpp | 78 ++++++++++++++++++------------------------ kurator/src/ScenarioEditor.h | 10 ------ 2 files changed, 33 insertions(+), 55 deletions(-) diff --git a/kurator/src/ScenarioEditor.cpp b/kurator/src/ScenarioEditor.cpp index 5570730..aef2f51 100644 --- a/kurator/src/ScenarioEditor.cpp +++ b/kurator/src/ScenarioEditor.cpp @@ -7,7 +7,6 @@ #include #include -#include #include #include @@ -19,13 +18,15 @@ namespace kurator { +bool loadout_editor(std::shared_ptr repo, campaign::Loadout& loadout); + + ScenarioEditor::ScenarioEditor(std::shared_ptr _session) : session {std::move(_session)}, repository {universe::load_json("resources/universe")}, battle {}, frame {}, - loadout {}, - loadout_editor{repository, loadout} + loadout {} { loadout.type = repository->ship_type("Anvil"); // access to default/first? regenerate(); @@ -36,10 +37,9 @@ void ScenarioEditor::update(float) { frame.update(); - if (loadout_editor.show()) - regenerate(); if (ImGui::Begin("Scenario Editor")) { bool update = false; + update |= loadout_editor(repository, loadout); if (update) regenerate(); if (ImGui::Button("Start")) @@ -84,55 +84,43 @@ ScenarioEditor::regenerate() } -LoadoutEditor::LoadoutEditor(std::shared_ptr _repo, campaign::Loadout& _loadout) : - repo {std::move(_repo)}, - loadout {_loadout} -{ -} - - bool -LoadoutEditor::show() +loadout_editor(std::shared_ptr repo, campaign::Loadout& loadout) { bool changed = false; - ImGui::PushID(this); - if (ImGui::Begin("Loadout Editor")) { - 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; + 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; + } + }); + ImGui::EndCombo(); + } + auto it = loadout.turrets.begin(); + while (it != loadout.turrets.end()) { + ImGui::PushID(it - loadout.turrets.begin()); + ImGui::Indent(); + const bool removed = ImGui::Button("-"); + ImGui::SameLine(); + if (ImGui::BeginCombo("Turret Type", it->name.c_str())) { + repo->for_turret_types([&](const auto& type){ + if (ImGui::Selectable(type.name.c_str(), it->name == type.name)) { + *it = type; changed = true; } }); ImGui::EndCombo(); } - auto it = loadout.turrets.begin(); - while (it != loadout.turrets.end()) { - ImGui::PushID(it - loadout.turrets.begin()); - ImGui::Indent(); - const bool removed = ImGui::Button("-"); - ImGui::SameLine(); - if (ImGui::BeginCombo("Turret Type", it->name.c_str())) { - repo->for_turret_types([&](const auto& type){ - if (ImGui::Selectable(type.name.c_str(), it->name == type.name)) { - *it = type; - changed = true; - } - }); - ImGui::EndCombo(); - } - it = removed ? loadout.turrets.erase(it) : std::next(it); - changed |= removed; - ImGui::Unindent(); - ImGui::PopID(); - } - if (ImGui::Button("Add Turret")) { - loadout.turrets.push_back(repo->turret_type("ChargeLaser")); // access to default or first? - changed = true; - } + it = removed ? loadout.turrets.erase(it) : std::next(it); + changed |= removed; + ImGui::Unindent(); + ImGui::PopID(); + } + if (ImGui::Button("Add Turret")) { + loadout.turrets.push_back(repo->turret_type("ChargeLaser")); // access to default or first? + changed = true; } - ImGui::End(); - ImGui::PopID(); return changed; } diff --git a/kurator/src/ScenarioEditor.h b/kurator/src/ScenarioEditor.h index 85efbd0..daed4b6 100644 --- a/kurator/src/ScenarioEditor.h +++ b/kurator/src/ScenarioEditor.h @@ -14,15 +14,6 @@ namespace kurator { -struct LoadoutEditor -{ - LoadoutEditor(std::shared_ptr _repo, campaign::Loadout& _loadout); - std::shared_ptr repo; - campaign::Loadout& loadout; - bool show(); -}; - - class ScenarioEditor : public Scene { public: @@ -37,7 +28,6 @@ private: std::shared_ptr battle; SceneFrame frame; campaign::Loadout loadout; - LoadoutEditor loadout_editor; }; -- cgit v1.1