fix: Data processor nodes not remembering their positions correctly
This commit is contained in:
parent
5ace199dc4
commit
e0c35e0002
@ -27,32 +27,32 @@ namespace hex::dp {
|
|||||||
Attribute(IOType ioType, Type type, std::string unlocalizedName);
|
Attribute(IOType ioType, Type type, std::string unlocalizedName);
|
||||||
~Attribute();
|
~Attribute();
|
||||||
|
|
||||||
[[nodiscard]] u32 getId() const { return this->m_id; }
|
[[nodiscard]] int getId() const { return this->m_id; }
|
||||||
void setId(u32 id) { this->m_id = id; }
|
void setId(int id) { this->m_id = id; }
|
||||||
|
|
||||||
[[nodiscard]] IOType getIOType() const { return this->m_ioType; }
|
[[nodiscard]] IOType getIOType() const { return this->m_ioType; }
|
||||||
[[nodiscard]] Type getType() const { return this->m_type; }
|
[[nodiscard]] Type getType() const { return this->m_type; }
|
||||||
[[nodiscard]] const std::string &getUnlocalizedName() const { return this->m_unlocalizedName; }
|
[[nodiscard]] const std::string &getUnlocalizedName() const { return this->m_unlocalizedName; }
|
||||||
|
|
||||||
void addConnectedAttribute(u32 linkId, Attribute *to) { this->m_connectedAttributes.insert({ linkId, to }); }
|
void addConnectedAttribute(int linkId, Attribute *to) { this->m_connectedAttributes.insert({ linkId, to }); }
|
||||||
void removeConnectedAttribute(u32 linkId) { this->m_connectedAttributes.erase(linkId); }
|
void removeConnectedAttribute(int linkId) { this->m_connectedAttributes.erase(linkId); }
|
||||||
[[nodiscard]] std::map<u32, Attribute *> &getConnectedAttributes() { return this->m_connectedAttributes; }
|
[[nodiscard]] std::map<int, Attribute *> &getConnectedAttributes() { return this->m_connectedAttributes; }
|
||||||
|
|
||||||
[[nodiscard]] Node *getParentNode() { return this->m_parentNode; }
|
[[nodiscard]] Node *getParentNode() { return this->m_parentNode; }
|
||||||
|
|
||||||
[[nodiscard]] std::optional<std::vector<u8>> &getOutputData() { return this->m_outputData; }
|
[[nodiscard]] std::optional<std::vector<u8>> &getOutputData() { return this->m_outputData; }
|
||||||
|
|
||||||
static void setIdCounter(u32 id) {
|
static void setIdCounter(int id) {
|
||||||
if (id > Attribute::s_idCounter)
|
if (id > Attribute::s_idCounter)
|
||||||
Attribute::s_idCounter = id;
|
Attribute::s_idCounter = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
u32 m_id;
|
int m_id;
|
||||||
IOType m_ioType;
|
IOType m_ioType;
|
||||||
Type m_type;
|
Type m_type;
|
||||||
std::string m_unlocalizedName;
|
std::string m_unlocalizedName;
|
||||||
std::map<u32, Attribute *> m_connectedAttributes;
|
std::map<int, Attribute *> m_connectedAttributes;
|
||||||
Node *m_parentNode = nullptr;
|
Node *m_parentNode = nullptr;
|
||||||
|
|
||||||
std::optional<std::vector<u8>> m_outputData;
|
std::optional<std::vector<u8>> m_outputData;
|
||||||
@ -60,7 +60,7 @@ namespace hex::dp {
|
|||||||
friend class Node;
|
friend class Node;
|
||||||
void setParentNode(Node *node) { this->m_parentNode = node; }
|
void setParentNode(Node *node) { this->m_parentNode = node; }
|
||||||
|
|
||||||
static u32 s_idCounter;
|
static int s_idCounter;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
@ -6,24 +6,24 @@ namespace hex::dp {
|
|||||||
|
|
||||||
class Link {
|
class Link {
|
||||||
public:
|
public:
|
||||||
Link(u32 from, u32 to);
|
Link(int from, int to);
|
||||||
|
|
||||||
[[nodiscard]] u32 getId() const { return this->m_id; }
|
[[nodiscard]] int getId() const { return this->m_id; }
|
||||||
void setID(u32 id) { this->m_id = id; }
|
void setID(int id) { this->m_id = id; }
|
||||||
|
|
||||||
[[nodiscard]] u32 getFromId() const { return this->m_from; }
|
[[nodiscard]] int getFromId() const { return this->m_from; }
|
||||||
[[nodiscard]] u32 getToId() const { return this->m_to; }
|
[[nodiscard]] int getToId() const { return this->m_to; }
|
||||||
|
|
||||||
static void setIdCounter(u32 id) {
|
static void setIdCounter(int id) {
|
||||||
if (id > Link::s_idCounter)
|
if (id > Link::s_idCounter)
|
||||||
Link::s_idCounter = id;
|
Link::s_idCounter = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
u32 m_id;
|
int m_id;
|
||||||
u32 m_from, m_to;
|
int m_from, m_to;
|
||||||
|
|
||||||
static u32 s_idCounter;
|
static int s_idCounter;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
@ -9,6 +9,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <nlohmann/json_fwd.hpp>
|
#include <nlohmann/json_fwd.hpp>
|
||||||
|
#include <imgui.h>
|
||||||
|
|
||||||
namespace hex::prv {
|
namespace hex::prv {
|
||||||
class Provider;
|
class Provider;
|
||||||
@ -23,8 +24,8 @@ namespace hex::dp {
|
|||||||
|
|
||||||
virtual ~Node() = default;
|
virtual ~Node() = default;
|
||||||
|
|
||||||
[[nodiscard]] u32 getId() const { return this->m_id; }
|
[[nodiscard]] int getId() const { return this->m_id; }
|
||||||
void setId(u32 id) { this->m_id = id; }
|
void setId(int id) { this->m_id = id; }
|
||||||
|
|
||||||
[[nodiscard]] const std::string &getUnlocalizedName() const { return this->m_unlocalizedName; }
|
[[nodiscard]] const std::string &getUnlocalizedName() const { return this->m_unlocalizedName; }
|
||||||
void setUnlocalizedName(const std::string &unlocalizedName) { this->m_unlocalizedName = unlocalizedName; }
|
void setUnlocalizedName(const std::string &unlocalizedName) { this->m_unlocalizedName = unlocalizedName; }
|
||||||
@ -56,19 +57,28 @@ namespace hex::dp {
|
|||||||
this->m_processedInputs.clear();
|
this->m_processedInputs.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setIdCounter(u32 id) {
|
void setPosition(ImVec2 pos) {
|
||||||
|
this->m_position = pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] ImVec2 getPosition() const {
|
||||||
|
return this->m_position;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void setIdCounter(int id) {
|
||||||
if (id > Node::s_idCounter)
|
if (id > Node::s_idCounter)
|
||||||
Node::s_idCounter = id;
|
Node::s_idCounter = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
u32 m_id;
|
int m_id;
|
||||||
std::string m_unlocalizedTitle, m_unlocalizedName;
|
std::string m_unlocalizedTitle, m_unlocalizedName;
|
||||||
std::vector<Attribute> m_attributes;
|
std::vector<Attribute> m_attributes;
|
||||||
std::set<u32> m_processedInputs;
|
std::set<u32> m_processedInputs;
|
||||||
prv::Overlay *m_overlay = nullptr;
|
prv::Overlay *m_overlay = nullptr;
|
||||||
|
ImVec2 m_position;
|
||||||
|
|
||||||
static u32 s_idCounter;
|
static int s_idCounter;
|
||||||
|
|
||||||
Attribute *getConnectedInputAttribute(u32 index) {
|
Attribute *getConnectedInputAttribute(u32 index) {
|
||||||
if (index >= this->getAttributes().size())
|
if (index >= this->getAttributes().size())
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
namespace hex::dp {
|
namespace hex::dp {
|
||||||
|
|
||||||
u32 Attribute::s_idCounter = 1;
|
int Attribute::s_idCounter = 1;
|
||||||
|
|
||||||
Attribute::Attribute(IOType ioType, Type type, std::string unlocalizedName) : m_id(Attribute::s_idCounter++), m_ioType(ioType), m_type(type), m_unlocalizedName(std::move(unlocalizedName)) {
|
Attribute::Attribute(IOType ioType, Type type, std::string unlocalizedName) : m_id(Attribute::s_idCounter++), m_ioType(ioType), m_type(type), m_unlocalizedName(std::move(unlocalizedName)) {
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,9 @@
|
|||||||
|
|
||||||
namespace hex::dp {
|
namespace hex::dp {
|
||||||
|
|
||||||
u32 Link::s_idCounter = 1;
|
int Link::s_idCounter = 1;
|
||||||
|
|
||||||
Link::Link(u32 from, u32 to) : m_id(Link::s_idCounter++), m_from(from), m_to(to) { }
|
Link::Link(int from, int to) : m_id(Link::s_idCounter++), m_from(from), m_to(to) { }
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
namespace hex::dp {
|
namespace hex::dp {
|
||||||
|
|
||||||
u32 Node::s_idCounter = 1;
|
int Node::s_idCounter = 1;
|
||||||
|
|
||||||
Node::Node(std::string unlocalizedTitle, std::vector<Attribute> attributes) : m_id(Node::s_idCounter++), m_unlocalizedTitle(std::move(unlocalizedTitle)), m_attributes(std::move(attributes)) {
|
Node::Node(std::string unlocalizedTitle, std::vector<Attribute> attributes) : m_id(Node::s_idCounter++), m_unlocalizedTitle(std::move(unlocalizedTitle)), m_attributes(std::move(attributes)) {
|
||||||
for (auto &attr : this->m_attributes)
|
for (auto &attr : this->m_attributes)
|
||||||
|
@ -20,12 +20,13 @@ namespace hex::plugin::builtin {
|
|||||||
void drawContent() override;
|
void drawContent() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool m_justSwitchedProvider = false;
|
||||||
int m_rightClickedId = -1;
|
int m_rightClickedId = -1;
|
||||||
ImVec2 m_rightClickedCoords;
|
ImVec2 m_rightClickedCoords;
|
||||||
|
|
||||||
bool m_continuousEvaluation = false;
|
bool m_continuousEvaluation = false;
|
||||||
|
|
||||||
void eraseLink(u32 id);
|
void eraseLink(int id);
|
||||||
void eraseNodes(const std::vector<int> &ids);
|
void eraseNodes(const std::vector<int> &ids);
|
||||||
void processNodes();
|
void processNodes();
|
||||||
|
|
||||||
|
@ -49,12 +49,13 @@ namespace hex::plugin::builtin {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
EventManager::subscribe<EventProviderChanged>(this, [](const auto &, const auto &) {
|
EventManager::subscribe<EventProviderChanged>(this, [this](const auto &, const auto &) {
|
||||||
auto &data = ProviderExtraData::getCurrent().dataProcessor;
|
auto &data = ProviderExtraData::getCurrent().dataProcessor;
|
||||||
for (auto &node : data.nodes) {
|
for (auto &node : data.nodes) {
|
||||||
node->setCurrentOverlay(nullptr);
|
node->setCurrentOverlay(nullptr);
|
||||||
}
|
}
|
||||||
data.dataOverlays.clear();
|
data.dataOverlays.clear();
|
||||||
|
this->m_justSwitchedProvider = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
EventManager::subscribe<EventDataChanged>(this, [this] {
|
EventManager::subscribe<EventDataChanged>(this, [this] {
|
||||||
@ -103,7 +104,7 @@ namespace hex::plugin::builtin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ViewDataProcessor::eraseLink(u32 id) {
|
void ViewDataProcessor::eraseLink(int id) {
|
||||||
auto &data = ProviderExtraData::getCurrent().dataProcessor;
|
auto &data = ProviderExtraData::getCurrent().dataProcessor;
|
||||||
|
|
||||||
auto link = std::find_if(data.links.begin(), data.links.end(), [&id](auto link) { return link.getId() == id; });
|
auto link = std::find_if(data.links.begin(), data.links.end(), [&id](auto link) { return link.getId() == id; });
|
||||||
@ -124,14 +125,14 @@ namespace hex::plugin::builtin {
|
|||||||
|
|
||||||
void ViewDataProcessor::eraseNodes(const std::vector<int> &ids) {
|
void ViewDataProcessor::eraseNodes(const std::vector<int> &ids) {
|
||||||
auto &data = ProviderExtraData::getCurrent().dataProcessor;
|
auto &data = ProviderExtraData::getCurrent().dataProcessor;
|
||||||
for (u32 id : ids) {
|
for (int id : ids) {
|
||||||
auto node = std::find_if(data.nodes.begin(), data.nodes.end(),
|
auto node = std::find_if(data.nodes.begin(), data.nodes.end(),
|
||||||
[&id](const auto &node) {
|
[&id](const auto &node) {
|
||||||
return node->getId() == id;
|
return node->getId() == id;
|
||||||
});
|
});
|
||||||
|
|
||||||
for (auto &attr : (*node)->getAttributes()) {
|
for (auto &attr : (*node)->getAttributes()) {
|
||||||
std::vector<u32> linksToRemove;
|
std::vector<int> linksToRemove;
|
||||||
for (auto &[linkId, connectedAttr] : attr.getConnectedAttributes())
|
for (auto &[linkId, connectedAttr] : attr.getConnectedAttributes())
|
||||||
linksToRemove.push_back(linkId);
|
linksToRemove.push_back(linkId);
|
||||||
|
|
||||||
@ -140,7 +141,7 @@ namespace hex::plugin::builtin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (u32 id : ids) {
|
for (int id : ids) {
|
||||||
auto node = std::find_if(data.nodes.begin(), data.nodes.end(), [&id](const auto &node) { return node->getId() == id; });
|
auto node = std::find_if(data.nodes.begin(), data.nodes.end(), [&id](const auto &node) { return node->getId() == id; });
|
||||||
|
|
||||||
std::erase_if(data.endNodes, [&id](const auto &node) { return node->getId() == id; });
|
std::erase_if(data.endNodes, [&id](const auto &node) { return node->getId() == id; });
|
||||||
@ -287,7 +288,7 @@ namespace hex::plugin::builtin {
|
|||||||
|
|
||||||
{
|
{
|
||||||
int nodeId;
|
int nodeId;
|
||||||
if (ImNodes::IsNodeHovered(&nodeId) && data.currNodeError.has_value() && data.currNodeError->node->getId() == static_cast<u32>(nodeId)) {
|
if (ImNodes::IsNodeHovered(&nodeId) && data.currNodeError.has_value() && data.currNodeError->node->getId() == nodeId) {
|
||||||
ImGui::BeginTooltip();
|
ImGui::BeginTooltip();
|
||||||
ImGui::TextUnformatted("hex.builtin.common.error"_lang);
|
ImGui::TextUnformatted("hex.builtin.common.error"_lang);
|
||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
@ -305,7 +306,13 @@ namespace hex::plugin::builtin {
|
|||||||
if (hasError)
|
if (hasError)
|
||||||
ImNodes::PushColorStyle(ImNodesCol_NodeOutline, 0xFF0000FF);
|
ImNodes::PushColorStyle(ImNodesCol_NodeOutline, 0xFF0000FF);
|
||||||
|
|
||||||
ImNodes::BeginNode(node->getId());
|
int nodeId = node->getId();
|
||||||
|
if (!this->m_justSwitchedProvider)
|
||||||
|
node->setPosition(ImNodes::GetNodeGridSpacePos(nodeId));
|
||||||
|
else
|
||||||
|
ImNodes::SetNodeGridSpacePos(nodeId, node->getPosition());
|
||||||
|
|
||||||
|
ImNodes::BeginNode(nodeId);
|
||||||
|
|
||||||
ImNodes::BeginNodeTitleBar();
|
ImNodes::BeginNodeTitleBar();
|
||||||
ImGui::TextUnformatted(LangEntry(node->getUnlocalizedTitle()));
|
ImGui::TextUnformatted(LangEntry(node->getUnlocalizedTitle()));
|
||||||
@ -342,6 +349,8 @@ namespace hex::plugin::builtin {
|
|||||||
|
|
||||||
ImNodes::EndNode();
|
ImNodes::EndNode();
|
||||||
|
|
||||||
|
ImNodes::SetNodeGridSpacePos(nodeId, node->getPosition());
|
||||||
|
|
||||||
if (hasError)
|
if (hasError)
|
||||||
ImNodes::PopColorStyle();
|
ImNodes::PopColorStyle();
|
||||||
}
|
}
|
||||||
@ -379,9 +388,9 @@ namespace hex::plugin::builtin {
|
|||||||
dp::Attribute *fromAttr = nullptr, *toAttr = nullptr;
|
dp::Attribute *fromAttr = nullptr, *toAttr = nullptr;
|
||||||
for (auto &node : data.nodes) {
|
for (auto &node : data.nodes) {
|
||||||
for (auto &attribute : node->getAttributes()) {
|
for (auto &attribute : node->getAttributes()) {
|
||||||
if (attribute.getId() == static_cast<u32>(from))
|
if (attribute.getId() == from)
|
||||||
fromAttr = &attribute;
|
fromAttr = &attribute;
|
||||||
else if (attribute.getId() == static_cast<u32>(to))
|
else if (attribute.getId() == to)
|
||||||
toAttr = &attribute;
|
toAttr = &attribute;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -429,6 +438,8 @@ namespace hex::plugin::builtin {
|
|||||||
this->eraseNodes(selectedNodes);
|
this->eraseNodes(selectedNodes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this->m_justSwitchedProvider = false;
|
||||||
}
|
}
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
@ -443,7 +454,7 @@ namespace hex::plugin::builtin {
|
|||||||
for (auto &node : data.nodes) {
|
for (auto &node : data.nodes) {
|
||||||
auto id = node->getId();
|
auto id = node->getId();
|
||||||
auto &currNodeOutput = output["nodes"][std::to_string(id)];
|
auto &currNodeOutput = output["nodes"][std::to_string(id)];
|
||||||
auto pos = ImNodes::GetNodeGridSpacePos(id);
|
auto pos = node->getPosition();
|
||||||
|
|
||||||
currNodeOutput["type"] = node->getUnlocalizedName();
|
currNodeOutput["type"] = node->getUnlocalizedName();
|
||||||
currNodeOutput["pos"] = {
|
currNodeOutput["pos"] = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user