From c632d5e6824603eb420a874095e8b30b9713e918 Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 12 Jan 2023 00:24:37 +0100 Subject: Implemented naive scenario editor based on groups and loadouts --- campaign/include/kurator/campaign/Loadout.h | 2 +- kurator/src/ScenarioEditor.cpp | 54 +++++++++++++++++++++++------ kurator/src/ScenarioEditor.h | 12 ++++++- 3 files changed, 55 insertions(+), 13 deletions(-) diff --git a/campaign/include/kurator/campaign/Loadout.h b/campaign/include/kurator/campaign/Loadout.h index e528fd9..7a9bb9c 100644 --- a/campaign/include/kurator/campaign/Loadout.h +++ b/campaign/include/kurator/campaign/Loadout.h @@ -15,7 +15,7 @@ namespace campaign struct Loadout { universe::ShipType type; - std::vector turrets; + std::vector turrets = {}; }; diff --git a/kurator/src/ScenarioEditor.cpp b/kurator/src/ScenarioEditor.cpp index aef2f51..ab4832b 100644 --- a/kurator/src/ScenarioEditor.cpp +++ b/kurator/src/ScenarioEditor.cpp @@ -18,6 +18,7 @@ namespace kurator { +bool groups_editor(std::shared_ptr repo, std::vector& groups); bool loadout_editor(std::shared_ptr repo, campaign::Loadout& loadout); @@ -26,9 +27,8 @@ ScenarioEditor::ScenarioEditor(std::shared_ptr _session) : repository {universe::load_json("resources/universe")}, battle {}, frame {}, - loadout {} + radius {12000.0f} { - loadout.type = repository->ship_type("Anvil"); // access to default/first? regenerate(); } @@ -38,9 +38,10 @@ ScenarioEditor::update(float) { frame.update(); if (ImGui::Begin("Scenario Editor")) { - bool update = false; - update |= loadout_editor(repository, loadout); - if (update) + bool changed = false; + changed |= ImGui::SliderFloat("Distance", &radius, 8000.0f, 20000.0f); + changed |= groups_editor(repository, groups); + if (changed) regenerate(); if (ImGui::Button("Start")) start_battle(); @@ -74,10 +75,13 @@ void ScenarioEditor::regenerate() { int id = 0; - campaign::Scenario scenario {"Player Encounter", 12000, {}}; - for (int i = 0; i < 2; ++i) { - for (int n = 0; n < 5; ++n) - scenario.ships.push_back(campaign::ShipConfig{{id++}, i, loadout}); + campaign::Scenario scenario {"Player Encounter", radius, {}}; + for (const auto& group : groups) { + for (auto it = group.counts.begin(); it != group.counts.end(); ++it) { + const int team = it - group.counts.begin(); + for (int n = 0; n < *it; ++n) + scenario.ships.push_back(campaign::ShipConfig{{id++}, team, group.loadout}); + } } battle = std::make_shared(session, std::move(scenario)); frame.reset(battle); @@ -85,6 +89,34 @@ ScenarioEditor::regenerate() bool +groups_editor(std::shared_ptr repo, std::vector& groups) +{ + bool changed = false; + auto it = groups.begin(); + while (it != groups.end()) { + ImGui::PushID(it - groups.begin()); + const bool removed = ImGui::Button("-"); + ImGui::SameLine(); + changed |= loadout_editor(repo, it->loadout); + changed |= removed; + changed |= ImGui::SliderInt("Team 1", &it->counts[0], 0, 10); // yeah no + changed |= ImGui::SliderInt("Team 2", &it->counts[1], 0, 10); + changed |= ImGui::SliderInt("Team 3", &it->counts[2], 0, 10); + changed |= ImGui::SliderInt("Team 4", &it->counts[3], 0, 10); + changed |= ImGui::SliderInt("Team 5", &it->counts[4], 0, 10); + changed |= ImGui::SliderInt("Team 6", &it->counts[5], 0, 10); + it = removed ? groups.erase(it) : std::next(it); + ImGui::PopID(); + } + if (ImGui::Button("Add Group")) { + groups.push_back(Group{{repo->ship_type("Anvil")}}); // access to default/first? + changed = true; + } + return changed; +} + + +bool loadout_editor(std::shared_ptr repo, campaign::Loadout& loadout) { bool changed = false; @@ -97,10 +129,10 @@ loadout_editor(std::shared_ptr repo, campaign::Loadout& lo }); ImGui::EndCombo(); } + ImGui::Indent(); 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())) { @@ -114,13 +146,13 @@ loadout_editor(std::shared_ptr repo, campaign::Loadout& lo } 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::Unindent(); return changed; } diff --git a/kurator/src/ScenarioEditor.h b/kurator/src/ScenarioEditor.h index daed4b6..9222a64 100644 --- a/kurator/src/ScenarioEditor.h +++ b/kurator/src/ScenarioEditor.h @@ -1,6 +1,8 @@ #pragma once +#include #include +#include #include #include @@ -14,6 +16,13 @@ namespace kurator { +struct Group +{ + campaign::Loadout loadout; + std::array counts = {0}; +}; + + class ScenarioEditor : public Scene { public: @@ -27,7 +36,8 @@ private: std::shared_ptr repository; std::shared_ptr battle; SceneFrame frame; - campaign::Loadout loadout; + float radius; + std::vector groups; }; -- cgit v1.1