From 586adb53ecbbf4eff924fd145cd0f5a72797e021 Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 11 Jan 2023 00:30:25 +0100 Subject: Created a naive loadout editor interface --- kurator/src/ScenarioEditor.cpp | 39 +++++++++++++++++++++++++++++++++++++++ kurator/src/ScenarioEditor.h | 12 ++++++++++++ 2 files changed, 51 insertions(+) diff --git a/kurator/src/ScenarioEditor.cpp b/kurator/src/ScenarioEditor.cpp index 45e594f..29e275e 100644 --- a/kurator/src/ScenarioEditor.cpp +++ b/kurator/src/ScenarioEditor.cpp @@ -8,6 +8,7 @@ #include #include +#include #include "Battle.h" #include "Session.h" @@ -26,6 +27,8 @@ ScenarioEditor::ScenarioEditor(std::shared_ptr _session) : distance {12000} { regenerate(); + loadout_editor.repo = universe::load_json("resources/universe"); + loadout_editor.loadout.type = loadout_editor.repo->ship_type("Anvil"); // access to default or first? } @@ -33,6 +36,7 @@ void ScenarioEditor::update(float) { frame.update(); + loadout_editor.show(); if (ImGui::Begin("Scenario Editor")) { bool update = false; update |= ImGui::SliderInt("Teams", &teams, 2, 6); @@ -79,4 +83,39 @@ ScenarioEditor::regenerate() } +void +LoadoutEditor::show() +{ + 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; + }); + ImGui::EndCombo(); + } + auto it = loadout.turrets.begin(); + while (it != loadout.turrets.end()) { + ImGui::PushID(it - loadout.turrets.begin()); + 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; + }); + ImGui::EndCombo(); + } + it = removed ? loadout.turrets.erase(it) : std::next(it); + ImGui::PopID(); + } + if (ImGui::Button("Add Turret")) + loadout.turrets.push_back(repo->turret_type("ChargeLaser")); // access to default or first? + } + ImGui::End(); + ImGui::PopID(); +} + + } // namespace kurator \ No newline at end of file diff --git a/kurator/src/ScenarioEditor.h b/kurator/src/ScenarioEditor.h index cec4783..d8a7a72 100644 --- a/kurator/src/ScenarioEditor.h +++ b/kurator/src/ScenarioEditor.h @@ -2,6 +2,9 @@ #include +#include +#include + #include "Scene.h" #include "SceneFrame.h" #include "Session.h" @@ -11,6 +14,14 @@ namespace kurator { +struct LoadoutEditor +{ + std::shared_ptr repo; + campaign::Loadout loadout; + void show(); +}; + + class ScenarioEditor : public Scene { public: @@ -28,6 +39,7 @@ private: float distance; std::shared_ptr battle; SceneFrame frame; + LoadoutEditor loadout_editor; }; -- cgit v1.1