summaryrefslogtreecommitdiff
path: root/ui
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
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')
-rw-r--r--ui/editNetwork.cpp35
-rw-r--r--ui/editNetwork.h5
-rw-r--r--ui/gameMainSelector.cpp2
-rw-r--r--ui/gameMainSelector.h2
-rw-r--r--ui/gameMainWindow.cpp32
5 files changed, 45 insertions, 31 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();
}
diff --git a/ui/editNetwork.h b/ui/editNetwork.h
index ae887bd..805e7ec 100644
--- a/ui/editNetwork.h
+++ b/ui/editNetwork.h
@@ -2,7 +2,6 @@
#include "game/geoData.h"
#include "gameMainSelector.h"
-#include "modeHelper.h"
#include "toolbar.h"
#include "worldOverlay.h"
#include <game/gamestate.h>
@@ -19,7 +18,7 @@ public:
bool move(const SDL_MouseMotionEvent & e, const Ray<GlobalPosition3D> &) override;
bool handleInput(const SDL_Event & e, const UIComponent::Position &) override;
void render(const SceneShader &, const Frustum &) const override;
- void render(const UIShader & shader, const UIComponent::Position & pos) const override;
+ void render(const UIShader & shader, const UIComponent::Position & pos) override;
using NetworkClickPos = std::variant<GlobalPosition3D, Node::Ptr>;
@@ -42,8 +41,6 @@ public:
private:
Network * network;
Builder::Ptr builder;
- Mode<Builder::Ptr, ModeSecondClick::NoAction> mode {builder};
- Toolbar builderToolbar;
Texture blue;
const Font font;
};
diff --git a/ui/gameMainSelector.cpp b/ui/gameMainSelector.cpp
index 23ae8c0..d5cbf62 100644
--- a/ui/gameMainSelector.cpp
+++ b/ui/gameMainSelector.cpp
@@ -110,7 +110,7 @@ GameMainSelector::Component::handleInput(const SDL_Event &, const Position &)
}
void
-GameMainSelector::Component::render(const UIShader &, const UIComponent::Position &) const
+GameMainSelector::Component::render(const UIShader &, const UIComponent::Position &)
{
}
diff --git a/ui/gameMainSelector.h b/ui/gameMainSelector.h
index e715823..16f70eb 100644
--- a/ui/gameMainSelector.h
+++ b/ui/gameMainSelector.h
@@ -23,7 +23,7 @@ public:
virtual bool click(const SDL_MouseButtonEvent &, const Ray<GlobalPosition3D> &);
virtual bool move(const SDL_MouseMotionEvent &, const Ray<GlobalPosition3D> &);
virtual bool handleInput(const SDL_Event &, const Position & pos);
- virtual void render(const UIShader & shader, const Position & pos) const;
+ virtual void render(const UIShader & shader, const Position & pos);
virtual void render(const SceneShader &, const Frustum &) const;
};
diff --git a/ui/gameMainWindow.cpp b/ui/gameMainWindow.cpp
index d88bab5..c1e135b 100644
--- a/ui/gameMainWindow.cpp
+++ b/ui/gameMainWindow.cpp
@@ -1,10 +1,8 @@
#include "gameMainWindow.h"
#include "editNetwork.h"
#include "gameMainSelector.h"
+#include "imgui_extras.h"
#include "manualCameraController.h"
-#include "modeHelper.h"
-#include "toolbar.h"
-#include "window.h"
#include <SDL2/SDL.h>
#include <collection.h>
#include <game/environment.h>
@@ -17,15 +15,33 @@
#include <glm/glm.hpp>
#include <memory>
-class GameMainToolbar : Mode<decltype(GameMainSelector::target)>, public Toolbar {
+class GameMainToolbar : public UIComponent {
public:
- explicit GameMainToolbar(GameMainSelector * gms_) :
- Mode<decltype(GameMainSelector::target)> {gms_->target},
- Toolbar {
- {"ui/icon/network.png", toggle<EditNetworkOf<RailLinks>>()},
+ static constexpr auto TOOLBAR_HEIGHT = 54.F;
+ static constexpr ImVec2 TOOLBAR_ICON_SIZE {32, 32};
+
+ explicit GameMainToolbar(GameMainSelector * gms) : UIComponent {{{}, {}}}, gms {gms} { }
+
+ void
+ render(const UIShader &, const Position &) const override
+ {
+ if (IltGui::BeginToolbar("bottomBar", ImGuiDir_Down, TOOLBAR_HEIGHT)) {
+ if (ImGui::ImageButton("Build rails", *buildRailsIcon, TOOLBAR_ICON_SIZE)) {
+ gms->target = std::make_unique<EditNetworkOf<RailLinks>>();
+ }
+ IltGui::EndToolbar();
}
+ }
+
+ bool
+ handleInput(const SDL_Event &, const Position &) override
{
+ return false;
}
+
+private:
+ Icon buildRailsIcon {"ui/icon/network.png"};
+ GameMainSelector * gms;
};
GameMainWindow::GameMainWindow(size_t w, size_t h) : WindowContent {w, h}, SceneRenderer {{w, h}, 0}