summaryrefslogtreecommitdiff
path: root/ui/editNetwork.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2025-03-19 01:44:18 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2025-03-19 01:44:18 +0000
commitced16a1bb9ef735a2fe44b64ac594bf9b4a7f9bf (patch)
tree760cc03a9796eaa123b8f85acf2eceed3e8b5bcd /ui/editNetwork.cpp
parentAdd operator to get ImTextureID from an Icon (diff)
downloadilt-ced16a1bb9ef735a2fe44b64ac594bf9b4a7f9bf.tar.bz2
ilt-ced16a1bb9ef735a2fe44b64ac594bf9b4a7f9bf.tar.xz
ilt-ced16a1bb9ef735a2fe44b64ac594bf9b4a7f9bf.zip
Replace basic rail builder UI with a ImGui version
Diffstat (limited to 'ui/editNetwork.cpp')
-rw-r--r--ui/editNetwork.cpp35
1 files changed, 18 insertions, 17 deletions
diff --git a/ui/editNetwork.cpp b/ui/editNetwork.cpp
index 2887491..a11fe3c 100644
--- a/ui/editNetwork.cpp
+++ b/ui/editNetwork.cpp
@@ -2,6 +2,7 @@
#include "builders/freeExtend.h"
#include "builders/join.h"
#include "builders/straight.h"
+#include "imgui_wrap.h"
#include "text.h"
#include <game/gamestate.h>
#include <game/terrain.h>
@@ -11,16 +12,7 @@
const std::filesystem::path fontpath {"/usr/share/fonts/hack/Hack-Regular.ttf"};
constexpr const glm::u8vec4 TRANSPARENT_BLUE {30, 50, 255, 200};
-EditNetwork::EditNetwork(Network * n) :
- network {n},
- builderToolbar {
- {"ui/icon/network.png", mode.toggle<BuilderStraight>()},
- {"ui/icon/network.png", mode.toggle<BuilderJoin>()},
- {"ui/icon/network.png", mode.toggle<BuilderFreeExtend>()},
- },
- blue {1, 1, &TRANSPARENT_BLUE}, font {fontpath, 15}
-{
-}
+EditNetwork::EditNetwork(Network * n) : network {n}, blue {1, 1, &TRANSPARENT_BLUE}, font {fontpath, 15} { }
bool
EditNetwork::click(const SDL_MouseButtonEvent & e, const Ray<GlobalPosition3D> & ray)
@@ -42,9 +34,9 @@ EditNetwork::move(const SDL_MouseMotionEvent & e, const Ray<GlobalPosition3D> &
}
bool
-EditNetwork::handleInput(const SDL_Event & e, const UIComponent::Position & parentPos)
+EditNetwork::handleInput(const SDL_Event &, const UIComponent::Position &)
{
- return builderToolbar.handleInput(e, parentPos);
+ return false;
}
void
@@ -75,10 +67,19 @@ EditNetwork::Builder::setHeightsFor(Network * network, const Link::CCollection &
}
void
-EditNetwork::render(const UIShader & shader, const UIComponent::Position & parentPos) const
+EditNetwork::render(const UIShader &, const UIComponent::Position &)
{
- if (builder) {
- Text {builder->hint(), font, {{50, 10}, {0, 15}}, {1, 1, 0}}.render(shader, parentPos);
- }
- builderToolbar.render(shader, parentPos);
+ ImGui::Begin("Edit Network");
+
+ auto builderChoice = [this]<typename Impl>(const char * name) {
+ if (ImGui::RadioButton(name, dynamic_cast<Impl *>(builder.get()))) {
+ builder = std::make_unique<Impl>();
+ }
+ };
+ builderChoice.operator()<BuilderStraight>("Straight");
+ builderChoice.operator()<BuilderJoin>("Join");
+ builderChoice.operator()<BuilderFreeExtend>("Free Extend");
+ ImGui::TextUnformatted(builder ? builder->hint().c_str() : "Select a build mode");
+
+ ImGui::End();
}