Compare commits
2 Commits
hotkeymenu
...
editor
| Author | SHA1 | Date | |
|---|---|---|---|
| 390bc79dbc | |||
| 07f3c9b852 |
127
include/td/display/state/NodeEditorState.h
Normal file
127
include/td/display/state/NodeEditorState.h
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <td/display/DisplayState.h>
|
||||||
|
|
||||||
|
#include <imgui_node_editor.h>
|
||||||
|
|
||||||
|
namespace ed = ax::NodeEditor;
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
|
||||||
|
class NodeEditorState : public DisplayState {
|
||||||
|
public:
|
||||||
|
enum class PinType {
|
||||||
|
Flow,
|
||||||
|
Bool,
|
||||||
|
Int,
|
||||||
|
Float,
|
||||||
|
String,
|
||||||
|
Object,
|
||||||
|
Function,
|
||||||
|
Delegate,
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class PinKind { Output, Input };
|
||||||
|
|
||||||
|
enum class NodeType { Blueprint, Simple, Tree, Comment, Houdini };
|
||||||
|
|
||||||
|
struct Pin;
|
||||||
|
|
||||||
|
struct Node {
|
||||||
|
ed::NodeId ID;
|
||||||
|
std::string Name;
|
||||||
|
std::vector<Pin> Inputs;
|
||||||
|
std::vector<Pin> Outputs;
|
||||||
|
ImColor Color;
|
||||||
|
NodeType Type;
|
||||||
|
ImVec2 Size;
|
||||||
|
|
||||||
|
std::string State;
|
||||||
|
std::string SavedState;
|
||||||
|
|
||||||
|
Node(int id, const char* name, ImColor color = ImColor(255, 255, 255)) :
|
||||||
|
ID(id), Name(name), Color(color), Type(NodeType::Blueprint), Size(0, 0) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Pin {
|
||||||
|
ed::PinId ID;
|
||||||
|
::td::NodeEditorState::Node* Node;
|
||||||
|
std::string Name;
|
||||||
|
PinType Type;
|
||||||
|
PinKind Kind;
|
||||||
|
|
||||||
|
Pin(int id, const char* name, PinType type) : ID(id), Node(nullptr), Name(name), Type(type), Kind(PinKind::Input) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Link {
|
||||||
|
ed::LinkId ID;
|
||||||
|
|
||||||
|
ed::PinId StartPinID;
|
||||||
|
ed::PinId EndPinID;
|
||||||
|
|
||||||
|
ImColor Color;
|
||||||
|
|
||||||
|
Link(ed::LinkId id, ed::PinId startPinId, ed::PinId endPinId) :
|
||||||
|
ID(id), StartPinID(startPinId), EndPinID(endPinId), Color(255, 255, 255) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct NodeIdLess {
|
||||||
|
bool operator()(const ed::NodeId& lhs, const ed::NodeId& rhs) const {
|
||||||
|
return lhs.AsPointer() < rhs.AsPointer();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
int m_NextId = 1;
|
||||||
|
const int m_PinIconSize = 24;
|
||||||
|
std::vector<Node> m_Nodes;
|
||||||
|
std::vector<Link> m_Links;
|
||||||
|
ImTextureID m_HeaderBackground = 0;
|
||||||
|
ImTextureID m_SaveIcon = 0;
|
||||||
|
ImTextureID m_RestoreIcon = 0;
|
||||||
|
const float m_TouchTime = 1.0f;
|
||||||
|
std::map<ed::NodeId, float, NodeIdLess> m_NodeTouchTime;
|
||||||
|
bool m_ShowOrdinals = false;
|
||||||
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
NodeEditorState(Display& a_Display);
|
||||||
|
~NodeEditorState();
|
||||||
|
|
||||||
|
virtual void Update(float a_Delta) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
int GetNextId();
|
||||||
|
ed::LinkId GetNextLinkId();
|
||||||
|
void TouchNode(ed::NodeId id);
|
||||||
|
float GetTouchProgress(ed::NodeId id);
|
||||||
|
void UpdateTouch();
|
||||||
|
Node* FindNode(ed::NodeId id);
|
||||||
|
Link* FindLink(ed::LinkId id);
|
||||||
|
Pin* FindPin(ed::PinId id);
|
||||||
|
bool IsPinLinked(ed::PinId id);
|
||||||
|
bool CanCreateLink(Pin* a, Pin* b);
|
||||||
|
void BuildNode(Node* node);
|
||||||
|
Node* SpawnInputActionNode();
|
||||||
|
Node* SpawnBranchNode();
|
||||||
|
Node* SpawnDoNNode();
|
||||||
|
Node* SpawnOutputActionNode();
|
||||||
|
Node* SpawnPrintStringNode();
|
||||||
|
Node* SpawnMessageNode();
|
||||||
|
Node* SpawnSetTimerNode();
|
||||||
|
Node* SpawnLessNode();
|
||||||
|
Node* SpawnWeirdNode();
|
||||||
|
Node* SpawnTraceByChannelNode();
|
||||||
|
Node* SpawnTreeSequenceNode();
|
||||||
|
Node* SpawnTreeTaskNode();
|
||||||
|
Node* SpawnTreeTask2Node();
|
||||||
|
Node* SpawnComment();
|
||||||
|
Node* SpawnHoudiniTransformNode();
|
||||||
|
Node* SpawnHoudiniGroupNode();
|
||||||
|
void BuildNodes();
|
||||||
|
ImColor GetIconColor(PinType type);
|
||||||
|
void DrawPinIcon(const Pin& pin, bool connected, int alpha);
|
||||||
|
void ShowStyleEditor(bool* show = nullptr);
|
||||||
|
void ShowLeftPane(float paneWidth);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace td
|
||||||
6
lib/imgui-node.lua
Normal file
6
lib/imgui-node.lua
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
|
||||||
|
target("imgui-node-editor")
|
||||||
|
set_kind("static")
|
||||||
|
add_files("imgui-node-editor/**.cpp")
|
||||||
|
add_includedirs("imgui-node-editor", {public = true})
|
||||||
|
add_packages("imgui")
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <td/display/state/MainMenuState.h>
|
#include <td/display/state/NodeEditorState.h>
|
||||||
#include <td/misc/Time.h>
|
#include <td/misc/Time.h>
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
// init GL context
|
// init GL context
|
||||||
td::Display display(1920, 1080, "Tower-Defense 2");
|
td::Display display(1920, 1080, "Tower-Defense 2");
|
||||||
|
|
||||||
display.ChangeState<td::MainMenuState>();
|
display.ChangeState<td::NodeEditorState>();
|
||||||
|
|
||||||
td::Timer timer;
|
td::Timer timer;
|
||||||
while (!display.IsCloseRequested()) {
|
while (!display.IsCloseRequested()) {
|
||||||
|
|||||||
1700
src/td/display/state/NodeEditorState.cpp
Normal file
1700
src/td/display/state/NodeEditorState.cpp
Normal file
File diff suppressed because it is too large
Load Diff
7988
src/td/display/state/stb_image.h
Normal file
7988
src/td/display/state/stb_image.h
Normal file
File diff suppressed because it is too large
Load Diff
@@ -2,8 +2,7 @@ add_rules("mode.debug", "mode.release")
|
|||||||
|
|
||||||
add_repositories("persson-repo https://git.ale-pri.com/Persson-dev/xmake-repo.git")
|
add_repositories("persson-repo https://git.ale-pri.com/Persson-dev/xmake-repo.git")
|
||||||
|
|
||||||
add_requires("imgui 1.92.0", {configs = {sdl3 = true, opengl3 = true}})
|
add_requires("imgui[sdl3,opengl3] 1.92.1", "splib 2.3.2", "zlib", "glew", "fpm", "enet6")
|
||||||
add_requires("libsdl3 3.2.16", "splib 2.3.2", "zlib", "glew", "fpm", "enet6")
|
|
||||||
|
|
||||||
set_languages("c++20")
|
set_languages("c++20")
|
||||||
|
|
||||||
@@ -17,6 +16,8 @@ else
|
|||||||
set_policy("build.sanitizer.undefined", true)
|
set_policy("build.sanitizer.undefined", true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
includes("lib/*.lua")
|
||||||
|
|
||||||
target("Tower-Defense2")
|
target("Tower-Defense2")
|
||||||
add_includedirs("include", {public = true})
|
add_includedirs("include", {public = true})
|
||||||
set_kind("binary")
|
set_kind("binary")
|
||||||
@@ -24,6 +25,7 @@ target("Tower-Defense2")
|
|||||||
add_packages("libsdl3", "imgui", "glew", "splib", "zlib", "fpm", "enet6", {public = true})
|
add_packages("libsdl3", "imgui", "glew", "splib", "zlib", "fpm", "enet6", {public = true})
|
||||||
set_rundir(".")
|
set_rundir(".")
|
||||||
add_defines("TD_GL_LOADER_GLEW")
|
add_defines("TD_GL_LOADER_GLEW")
|
||||||
|
add_deps("imgui-node-editor")
|
||||||
|
|
||||||
|
|
||||||
-- Tests
|
-- Tests
|
||||||
|
|||||||
Reference in New Issue
Block a user