Minor refactor.
parent
698abbce4b
commit
99d5a5eb0f
|
@ -46,16 +46,23 @@ ImNodesPinShape sGetSocketShapeFromSocketType(const SocketType& socket_type) {
|
|||
return ImNodesPinShape_Quad;
|
||||
}
|
||||
|
||||
void NodeSocketEditor(Socket& socket) {
|
||||
bool NodeSocketEditor(Socket& socket) {
|
||||
bool modified = false;
|
||||
int mode_current = static_cast<int>(socket.m_type);
|
||||
ImGui::InputText("Name", &socket.m_name);
|
||||
if (ImGui::InputText("Name", &socket.m_name)) {
|
||||
modified = true;
|
||||
}
|
||||
if (ImGui::Combo(
|
||||
"Type",
|
||||
&mode_current,
|
||||
SocketTypeNames,
|
||||
sizeof(SocketTypeNames) / sizeof(char*))) {
|
||||
socket.m_type = static_cast<SocketType>(mode_current);
|
||||
|
||||
modified = true;
|
||||
}
|
||||
|
||||
return modified;
|
||||
}
|
||||
|
||||
void RemoveBlendTreeConnectionsForSocket(
|
||||
|
@ -227,7 +234,12 @@ void AnimGraphEditorRenderSidebar(
|
|||
while (iter != outputs.end()) {
|
||||
Socket& output = *iter;
|
||||
ImGui::PushID(&output);
|
||||
NodeSocketEditor(output);
|
||||
if (NodeSocketEditor(output)) {
|
||||
AnimGraphResource* current_graph_resource =
|
||||
sEditorState.hierarchyStack[sEditorState.hierarchyStackIndex];
|
||||
current_graph_resource->m_socket_accessor->m_inputs = outputs;
|
||||
}
|
||||
|
||||
if (ImGui::Button("X")) {
|
||||
RemoveBlendTreeConnectionsForSocket(
|
||||
blend_tree_resource,
|
||||
|
@ -239,6 +251,13 @@ void AnimGraphEditorRenderSidebar(
|
|||
}
|
||||
ImGui::PopID();
|
||||
}
|
||||
|
||||
if (ImGui::Button("+")) {
|
||||
AnimGraphResource* current_graph_resource =
|
||||
sEditorState.hierarchyStack[sEditorState.hierarchyStackIndex];
|
||||
current_graph_resource->RegisterBlendTreeOutputSocket<float>(
|
||||
"GraphFloatOutput");
|
||||
}
|
||||
}
|
||||
|
||||
if (node_resource == blend_tree_resource.GetGraphInputNode()) {
|
||||
|
@ -251,7 +270,11 @@ void AnimGraphEditorRenderSidebar(
|
|||
while (iter != inputs.end()) {
|
||||
Socket& input = *iter;
|
||||
ImGui::PushID(&input);
|
||||
NodeSocketEditor(input);
|
||||
if (NodeSocketEditor(input)) {
|
||||
AnimGraphResource* current_graph_resource =
|
||||
sEditorState.hierarchyStack[sEditorState.hierarchyStackIndex];
|
||||
current_graph_resource->m_socket_accessor->m_inputs = inputs;
|
||||
}
|
||||
if (ImGui::Button("X")) {
|
||||
RemoveBlendTreeConnectionsForSocket(
|
||||
blend_tree_resource,
|
||||
|
@ -263,6 +286,13 @@ void AnimGraphEditorRenderSidebar(
|
|||
}
|
||||
ImGui::PopID();
|
||||
}
|
||||
|
||||
if (ImGui::Button("+")) {
|
||||
AnimGraphResource* current_graph_resource =
|
||||
sEditorState.hierarchyStack[sEditorState.hierarchyStackIndex];
|
||||
current_graph_resource->RegisterBlendTreeInputSocket<float>(
|
||||
"GraphFloatInput");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -271,12 +301,16 @@ void AnimGraphEditorClear() {
|
|||
ax::NodeEditor::ClearSelection();
|
||||
}
|
||||
|
||||
if (sEditorState.rootGraphResource) {
|
||||
delete sEditorState.rootGraphResource->m_socket_accessor;
|
||||
}
|
||||
delete sEditorState.rootGraphResource;
|
||||
|
||||
sEditorState.rootGraphResource = new AnimGraphResource();
|
||||
sEditorState.rootGraphResource->m_name = "Root";
|
||||
sEditorState.rootGraphResource->m_graph_type_name = "BlendTree";
|
||||
sEditorState.rootGraphResource->m_blend_tree_resource.InitGraphConnectors();
|
||||
sEditorState.rootGraphResource->m_socket_accessor = new NodeDescriptorBase;
|
||||
|
||||
sEditorState.hierarchyStack.clear();
|
||||
sEditorState.hierarchyStack.push_back(sEditorState.rootGraphResource);
|
||||
|
@ -456,17 +490,18 @@ void AnimGraphEditorUpdate(ax::NodeEditor::EditorContext* context) {
|
|||
if (ax::NodeEditor::BeginCreate()) {
|
||||
ax::NodeEditor::PinId input_pin_id, output_pin_id;
|
||||
if (ax::NodeEditor::QueryNewLink(&input_pin_id, &output_pin_id)) {
|
||||
if (input_pin_id && output_pin_id) {
|
||||
int source_node_index;
|
||||
int source_node_socket_index;
|
||||
const Socket* source_socket = nullptr;
|
||||
int source_node_index;
|
||||
int source_node_socket_index;
|
||||
const AnimNodeResource* source_node = nullptr;
|
||||
const Socket* source_socket = nullptr;
|
||||
|
||||
if (input_pin_id) {
|
||||
OutputPinIdToNodeIndexAndSocketIndex(
|
||||
input_pin_id.Get(),
|
||||
&source_node_index,
|
||||
&source_node_socket_index);
|
||||
|
||||
const AnimNodeResource* source_node =
|
||||
source_node =
|
||||
sEditorState.hierarchyStack[sEditorState.hierarchyStackIndex]
|
||||
->m_blend_tree_resource.GetNode(source_node_index);
|
||||
if (source_node->m_socket_accessor->m_outputs.size()
|
||||
|
@ -479,17 +514,20 @@ void AnimGraphEditorUpdate(ax::NodeEditor::EditorContext* context) {
|
|||
source_node,
|
||||
source_node_socket_index);
|
||||
}
|
||||
}
|
||||
|
||||
int target_node_index;
|
||||
int target_node_socket_index;
|
||||
const Socket* target_socket = nullptr;
|
||||
int target_node_index;
|
||||
int target_node_socket_index;
|
||||
const AnimNodeResource* target_node = nullptr;
|
||||
const Socket* target_socket = nullptr;
|
||||
|
||||
if (output_pin_id) {
|
||||
InputPinIdToNodeIndexAndSocketIndex(
|
||||
output_pin_id.Get(),
|
||||
&target_node_index,
|
||||
&target_node_socket_index);
|
||||
|
||||
const AnimNodeResource* target_node =
|
||||
target_node =
|
||||
sEditorState.hierarchyStack[sEditorState.hierarchyStackIndex]
|
||||
->m_blend_tree_resource.GetNode(target_node_index);
|
||||
if (target_node->m_socket_accessor->m_inputs.size()
|
||||
|
@ -502,7 +540,9 @@ void AnimGraphEditorUpdate(ax::NodeEditor::EditorContext* context) {
|
|||
target_node,
|
||||
target_node_socket_index);
|
||||
}
|
||||
}
|
||||
|
||||
if (input_pin_id && output_pin_id) {
|
||||
if (source_socket == nullptr || target_socket == nullptr
|
||||
|| !sEditorState.hierarchyStack[sEditorState.hierarchyStackIndex]
|
||||
->m_blend_tree_resource.IsConnectionValid(
|
||||
|
|
|
@ -182,6 +182,7 @@ AnimNodeResource* sAnimGraphNodeFromJson(
|
|||
|
||||
if (node_type == "BlendTree") {
|
||||
AnimGraphResource* result = new AnimGraphResource();
|
||||
result->m_socket_accessor = new NodeDescriptorBase;
|
||||
sAnimGraphResourceBlendTreeFromJson(json_node, result);
|
||||
return result;
|
||||
}
|
||||
|
@ -330,8 +331,7 @@ static bool sAnimGraphResourceBlendTreeFromJson(
|
|||
if (json_data["nodes"][0].contains("inputs")) {
|
||||
const json& graph_outputs = json_data["nodes"][0]["inputs"];
|
||||
for (const auto& graph_output : graph_outputs) {
|
||||
AnimNodeResource* graph_node = blend_tree_resource.GetNode(0);
|
||||
graph_node->m_socket_accessor->m_inputs.push_back(
|
||||
result_graph_resource->RegisterBlendTreeOutputSocket(
|
||||
sJsonToSocket(graph_output));
|
||||
}
|
||||
}
|
||||
|
@ -340,8 +340,7 @@ static bool sAnimGraphResourceBlendTreeFromJson(
|
|||
if (json_data["nodes"][1].contains("outputs")) {
|
||||
const json& graph_inputs = json_data["nodes"][1]["outputs"];
|
||||
for (const auto& graph_input : graph_inputs) {
|
||||
AnimNodeResource* graph_node = blend_tree_resource.GetNode(1);
|
||||
graph_node->m_socket_accessor->m_outputs.push_back(
|
||||
result_graph_resource->RegisterBlendTreeInputSocket(
|
||||
sJsonToSocket(graph_input));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue