public void OnBagUpdate() { Godot.Array previews = GetNode("PiecePreviews").GetChildren(); for (int i = 0; i < previews.Count; i++) { PreviewRect preview = (PreviewRect)previews[i]; preview.PieceType = board.BagGen.ElementAt(i).Type; } }
private void OnGUI() { if (disabled) { GUI.Label(position, "Diagram editor is disabled while in play mode."); return; } if (normalNodeStyle == null) { InitializeStyles(); } if (diagram == null) { // No diagram to show. return; } if (diagram.nodes.Length > 0 && diagram.nodes[0].Function == null) { // Intialize if needed. diagram.Init(); } if (Event.current.type == EventType.ValidateCommand && Event.current.commandName == "UndoRedoPerformed") { // Start from scratch after detecting undo or redo. diagramSO = null; Repaint(); return; } if (diagramSO == null) { InitializeWindow(); } diagramSO.Update(); diagramEvent.Reset(windowNodes, scrollPosition, selectedNodeIndex); for (int i = 0; i < transactions.Count; i++) { if (!transactions[i].OnGUI(diagramEvent)) { transactions.RemoveAt(i--); } } if (diagramEvent.type == DiagramWindowEventType.ContextClick) { if (diagramEvent.targetWindowNode != null) { DoNodeContextMenu(diagramEvent.targetWindowNode); diagramEvent.Use(); return; } if (PreviewRect.Contains(diagramEvent.touchPosition)) { ShowPreviewContextMenu(); } else { contextMenuPosition = diagramEvent.scrolledTouchPosition; DoContextMenu(); } diagramEvent.Use(); return; } if (diagramEvent.type == DiagramWindowEventType.TouchBegin) { // Clear input focus. GUI.FocusControl(""); } if (diagramEvent.type == DiagramWindowEventType.TouchBegin && diagramEvent.targetWindowNode != null) { if (selectedNodeIndex != diagramEvent.targetWindowNode.index) { if (selectedNodeIndex >= 0) { windowNodes[selectedNodeIndex].IsFocused = false; } selectedNodeIndex = diagramEvent.targetWindowNode.index; diagramEvent.targetWindowNode.IsFocused = true; Repaint(); } selectedNodeIndex = diagramEvent.targetWindowNode.index; StartTransaction(new NodeDragTransaction(diagramEvent.targetWindowNode, diagramEvent.touchPosition)); } GUI.Label(new Rect(0f, 0f, position.width, 20f), diagram.name, nameLabelStyle); scrollPosition = GUI.BeginScrollView(new Rect(0f, 0f, position.width, position.height), scrollPosition, canvas); for (int i = 0; i < windowNodes.Length; i++) { windowNodes[i].OnNodeGUI(diagramEvent); } GUI.EndScrollView(); if (selectedNodeIndex >= 0 && selectedNodeIndex < nodesSP.arraySize) { windowNodes[selectedNodeIndex].OnSelectedWindowGUI(diagramEvent); } if (diagramSO != null && diagramSO.ApplyModifiedProperties()) { diagram.prepared = false; } if (diagramEvent.type == DiagramWindowEventType.Used) { // Something happened, request a repaint. ComputeCanvas(); Repaint(); return; } if (diagramEvent.type == DiagramWindowEventType.Repaint && diagram.outputs != null && diagram.outputs.Length > 0) { System.Action <Rect, Texture2D> drawMethod = drawMethods[(int)diagram.outputs[diagram.previewOutputIndex].type, (int)diagram.outputs[diagram.previewOutputIndex].previewType]; GUI.BeginGroup(PreviewRect, diagram.outputs[diagram.previewOutputIndex].name, normalNodeStyle); Rect r; if (diagram.isCubemap) { // Flip preview. if (diagram.previewCubemapType == DiagramCubemapPreviewType.Inside) { r = new Rect(1f, 16f + diagram.height, diagram.width, -diagram.height); } else { r = new Rect(1f + diagram.width, 16f + diagram.height, -diagram.width, -diagram.height); } } else { r = new Rect(1f, 16f, diagram.width, diagram.height); } drawMethod(r, previewTexture); if (diagram.tilePreviewHorizontally) { r.x += diagram.width; drawMethod(r, previewTexture); } if (diagram.tilePreviewVertically) { r.y += diagram.height; drawMethod(r, previewTexture); if (diagram.tilePreviewHorizontally) { r.x -= diagram.width; drawMethod(r, previewTexture); } } GUI.EndGroup(); } }
public InteractiveGraphViewer() { _PreviewRectangle = new PreviewRect(this); _DistanceLine = new DistanceMeasurer(this); InitializeComponent(); }