Esempio n. 1
0
    private void DrawNeedsSave()
    {
        if (HistoryManager.needsSave)
        {
            mod = '*';
        }
        else
        {
            mod = ' ';
        }

        tempContent = new GUIContent(fileName + mod);
        if (GUI.Button(new Rect(2, 2, Mathf.Min(position.width - 200, SDEStyles.textButtonDefault.CalcSize(tempContent).x + 20), 24), fileName + mod, SDEStyles.textButtonDefault))
        {
            Debug.Log("saving...");
            SDEXMLManager.SaveItems(false);
        }
    }
Esempio n. 2
0
    /*
     * ProcessKeyboardInput() takes a given key and triggers a process based on the hotkey.
     *
     * Returns true if a hotkey was given, false otherwise.
     */
    private bool ProcessKeyboardInput(KeyCode key)
    {
        // check modifiers
        if (Event.current.shift)
        {
            // shift + 'S' save entry as
            if (key == KeyCode.S)
            {
                Debug.Log("saving as...");
                bool saved = SDEXMLManager.SaveItems(true);
                if (saved)
                {
                    HistoryManager.needsSave = false;
                }

                return(true);
            }

            // shift + 'N' open new
            if (key == KeyCode.N)
            {
                if (!EditorUtility.DisplayDialog("Start new entry", "Are you sure you want to start a new entry and close the current one?", "yes", "no"))
                {
                    return(true);
                }

                DestroyScene();
                HistoryManager.needsSave = false;

                return(true);
            }
        }
        else
        {
            // 'C' center on node positions
            if (key == KeyCode.C)
            {
                if (nodes != null && nodes.Count > 0)
                {
                    Debug.Log("centering on nodes...");
                    // calculate current average
                    Vector2 avgPosition = new Vector2();
                    for (int i = 0; i < nodes.Count; i++)
                    {
                        avgPosition += nodes[i].rect.center;
                    }
                    avgPosition /= nodes.Count;

                    // reshift everything by this new average, including window size
                    OnDrag(-avgPosition + (position.size / 2));
                }
                else
                {
                    Debug.Log("no nodes to center on");
                }

                return(true);
            }

            // 'D' delete the selected node
            if (key == KeyCode.D)
            {
                if (nodes != null && SelectionManager.SelectedComponent() != null)
                {
                    Debug.Log("deleting selected node...");
                    SDEComponent component = SelectionManager.SelectedComponent();
                    while (component != null)
                    {
                        if (component.componentType == SDEComponentType.Node)
                        {
                            // if a match is found, remove the Node if it's not an Interrupt and return
                            if (((Node)component).nodeType != NodeType.Interrupt)
                            {
                                NodeManager.RemoveNode((Node)component);
                            }
                            return(true);
                        }
                        component = component.parent;
                    }

                    // if no match was found, that means the component had no Node parent!
                    throw new UnityException("tried to delete SDEComponent with no parent Node!");
                }
                else
                {
                    Debug.Log("Ignoring 'D'elete, no Node selected!");
                }

                return(true);
            }

            // 'H' show/hide the help box
            if (key == KeyCode.H)
            {
                if (drawHelp)
                {
                    Debug.Log("Hiding Help menu");
                    drawHelp = false;
                }
                else
                {
                    Debug.Log("Displaying Help menu");
                    drawHelp = true;
                }

                return(true);
            }

            // 'Q' show/hide debug information
            if (key == KeyCode.Q)
            {
                if (drawDebug)
                {
                    Debug.Log("Hiding Debug info");
                    drawDebug = false;
                }
                else
                {
                    Debug.Log("Displaying Debug info");
                    drawDebug = true;
                }

                return(true);
            }

            // 'S' saves entry
            if (key == KeyCode.S)
            {
                Debug.Log("saving...");
                bool saved = SDEXMLManager.SaveItems(false);
                if (saved)
                {
                    HistoryManager.needsSave = false;
                }

                return(true);
            }
        }

        return(false);
    }