summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2023-01-11 23:40:04 +0100
committerAki <please@ignore.pl>2023-01-11 23:40:04 +0100
commitcb63d6d56637b887e38a45c6f2cd20044a59bc7c (patch)
treee6c4376f07611f78a42b89cc8b5fea25dde016ba
parent8f76e26c4dfe07079295dee8ca7d58696f532195 (diff)
downloadkurator-cb63d6d56637b887e38a45c6f2cd20044a59bc7c.zip
kurator-cb63d6d56637b887e38a45c6f2cd20044a59bc7c.tar.gz
kurator-cb63d6d56637b887e38a45c6f2cd20044a59bc7c.tar.bz2
Loadout editor is now a function call
-rw-r--r--kurator/src/ScenarioEditor.cpp78
-rw-r--r--kurator/src/ScenarioEditor.h10
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 <imgui.h>
#include <kurator/campaign/Scenario.h>
-#include <kurator/campaign/scenarios.h>
#include <kurator/universe.h>
#include <kurator/universe/Repository.h>
@@ -19,13 +18,15 @@ namespace kurator
{
+bool loadout_editor(std::shared_ptr<universe::Repository> repo, campaign::Loadout& loadout);
+
+
ScenarioEditor::ScenarioEditor(std::shared_ptr<Session> _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<universe::Repository> _repo, campaign::Loadout& _loadout) :
- repo {std::move(_repo)},
- loadout {_loadout}
-{
-}
-
-
bool
-LoadoutEditor::show()
+loadout_editor(std::shared_ptr<universe::Repository> 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<universe::Repository> _repo, campaign::Loadout& _loadout);
- std::shared_ptr<universe::Repository> repo;
- campaign::Loadout& loadout;
- bool show();
-};
-
-
class ScenarioEditor : public Scene
{
public:
@@ -37,7 +28,6 @@ private:
std::shared_ptr<Scene> battle;
SceneFrame frame;
campaign::Loadout loadout;
- LoadoutEditor loadout_editor;
};