private static void LoadFromRoot(string name, JsonArray root) { foreach (var vl in root) { ImNode.Create(name, vl); } }
public static void Load() { var dir = FileHandle.FromRoot("Dialogs"); foreach (var f in dir.ListFileHandles()) { if (f.Extension == ".json") { try { var name = f.NameWithoutExtension; var root = JsonValue.Parse(f.ReadAll()); // Create nodes foreach (var vl in root.AsJsonArray) { try { ImNode.Create(name, vl); } catch (Exception e) { } } // Connect em foreach (var node in ImNodes.Nodes) { node.Value.ReadOutputs(); } // Parse foreach (var node in ImNodes.Nodes) { ParseNode(node.Value); } ImNodes.Nodes.Clear(); ImNode.LastId = 0; } catch (Exception e) { Log.Error(e); } } } }
public static bool BeforeRender() { if (grid) { var list = ImGui.GetBackgroundDrawList(); var width = Engine.Instance.GetScreenWidth(); var height = Engine.Instance.GetScreenHeight(); var off = ImNode.Offset; for (float x = off.X % gridSize; x <= width - off.X % gridSize; x += gridSize) { list.AddLine(new Vector2(x, 0), new Vector2(x, height), ((int)(off.X - x) == 0 ? gridMainColor : gridColor).PackedValue); } for (float y = off.Y % gridSize; y <= height - off.Y % gridSize; y += gridSize) { list.AddLine(new Vector2(0, y), new Vector2(width, y), ((int)(off.Y - y) == 0 ? gridMainColor : gridColor).PackedValue); } } RenderVoidMenu(); if (target.HasValue) { ImNode.Offset += (target.Value - ImNode.Offset) * Engine.Delta * 10f; if ((target.Value - ImNode.Offset).Length() <= 3f) { target = null; } } else if (ImGui.IsMouseDragging(2) || Input.Keyboard.IsDown(Keys.Space, true)) { ImNode.Offset += ImGui.GetIO().MouseDelta; } foreach (var n in ImNodes.Nodes) { var node = n.Value; if (!hideFiltred || filter.PassFilter(node.GetName())) { node.Render(); } if (node.Done) { toRemove.Add(n.Key); } } CurrentActive?.RemoveEmptyConnection(); if (toRemove.Count > 0) { var c = ImNodes.Nodes.Count - 1; foreach (var k in toRemove) { if (ImNodes.Nodes[k].Id == c) { ImNode.LastId--; } ImNodes.Nodes.Remove(k); } toRemove.Clear(); } if (pasted != null) { try { var root = JsonValue.Parse(pasted); if (root.IsJsonObject) { var val = root["imnode"]; var node = ImNode.Create(val, true); if (node != null) { node.New = true; node.Position = ImGui.GetIO().MousePos; ImNode.Focused = node; } } } catch (Exception e) { Log.Error(e); } pasted = null; } if (toAdd != null) { var node = ImNodeRegistry.Create(toAdd); if (node != null) { node.New = true; node.Position = ImGui.GetIO().MousePos; node.File = DialogEditor.Current; ImNode.Focused = node; } Node(node); toAdd = null; } ImGui.SetNextWindowSize(size, ImGuiCond.Once); if (!ImGui.Begin("Nodes")) { ImGui.End(); return(false); } return(true); }