Beispiel #1
0
	public static void Unpack(out HamTimelineNode node, DataUnpacker unpacker)
	{
		byte typeByte;
		unpacker.Unpack(out typeByte);
		TimelineNodeType type = (TimelineNodeType)typeByte;

		int id;
		unpacker.Unpack(out id);

		int numPrevIDs;
		unpacker.Unpack(out numPrevIDs);
		List<int> previousNodeIDs = new List<int>();
		for (int i = 0; i < numPrevIDs; ++i)
		{
			int prevID;
			unpacker.Unpack(out prevID);
			previousNodeIDs.Add(prevID);
		}

		switch (type)
		{
		case TimelineNodeType.Dialog:
			node = new HamDialogNode();
			break;
		case TimelineNodeType.Branch:
			node = new HamBranchNode();
			break;
		case TimelineNodeType.Decision:
			node = new HamDecisionNode();
			break;
		case TimelineNodeType.Consequence:
			node = new HamConsequenceNode();
			break;
		default:
			node = null;
			return;
		}
		node.ID = id;
		node.Type = type;
		node.PreviousNodeIDs = previousNodeIDs;

		node.Unpack(unpacker);
	}
Beispiel #2
0
	public HamTimelineNode AddBranchNode()
	{
		int id = this.IDCount++;
		HamTimelineNode node = new HamBranchNode(id);
		this.Nodes[id] = node;
		this.NodeLinkageDirty = true;
		return node;
	}
Beispiel #3
0
    private void RenderBranchNode(Vector2 nodePosition, Vector2 offset, HamBranchNode node)
    {
        // Determine dimensions of various components
        float branchChunkSize = kNodeSizeX / (node.Predicates.Count + 1);
        Vector2 ulCorner = new Vector2(
            nodePosition.x + offset.x - kNodeSizeX / 2f,
            nodePosition.y + offset.y - kNodeSizeY / 2f
        );
        float yMax = ulCorner.y + kNodeSizeY;

        // Node title
        GUILayout.BeginHorizontal(Style("BranchNode"));
        GUILayout.Label("(" + node.ID + ") Branch");
        GUILayout.EndHorizontal();
        if (GUI.Button(GUILayoutUtility.GetLastRect(), GUIContent.none, Style("InvisibleButton")))
        {
            if (Event.current.button == 0)
            {
                this.selection.ClickedNode(this.activeTimeline, node);
            }
            else if (Event.current.button == 1)
            {
                RightClickNodeContext(node, -1);
            }
        }

        // Branch area
        GUILayout.BeginHorizontal();
        for (int i = 0; i <= node.Predicates.Count; ++i)
        {
            float branchX = ulCorner.x + (branchChunkSize * i);

            GUILayout.BeginVertical(Style("GenericNode"), GUILayout.ExpandHeight(true), GUILayout.MaxWidth(branchChunkSize));
            if (i == node.Predicates.Count)
            {
                GUILayout.Label("Default");
            }
            else
            {
                GUILayout.Label(node.Predicates[i].Label(this.activeTimeline));
            }
            GUILayout.EndVertical();

            if (GUI.Button(GUILayoutUtility.GetLastRect(), GUIContent.none, Style("InvisibleButton")))
            {
                if (Event.current.button == 0)
                {
                    this.selection.ClickedNode(this.activeTimeline, node);
                }
                else if (Event.current.button == 1)
                {
                    RightClickNodeContext(node, i);
                }
            }

            int nextNodeID = (i == node.Predicates.Count) ? node.DefaultNextID : node.Predicates[i].NextNodeID;

            if (nextNodeID != HamTimeline.InvalidID)
            {
 #if LINKAGE_DEBUG
                Debug.Log("Node " + node.ID + " transitions to " + nextNodeID);
#endif
                HamTimelineNode nextNode = this.activeTimeline.Nodes[nextNodeID];
                Vector2 nextNodePosition = GetOverviewPosition(nextNode);
                Vector2 inputPosition  = nextNodePosition + offset - new Vector2(0f, kNodeSizeY / 2f);
                Vector2 outputPosition = new Vector2(branchX + (branchChunkSize / 2f), yMax);
                Color connectionColor = Color.white;
                if (this.selection.NodeSelected(node.ID))
                {
                    connectionColor = Color.green;
                }
                else if (this.selection.NodeSelected(nextNodeID))
                {
                    connectionColor = Color.red;
                }
                this.connections.Add(new NodeConnection(outputPosition, inputPosition, connectionColor));
            }
        }
        GUILayout.EndHorizontal();
    }
Beispiel #4
0
    private void PredicateEditing(HamBranchNode node, int index)
    {
        HamPredicate p = node.Predicates[index];
        GUILayout.BeginVertical(Style("box"));

        // Variable Selection / Creation
        if (GUILayout.Button((p.VariableID == HamTimeline.InvalidID) ? "---" : this.activeTimeline.Variables[p.VariableID].Name))
        {
            GenericMenu menu = new GenericMenu();
            foreach (HamTimelineVariable v in this.activeTimeline.Variables.Values)
            {
                menu.AddItem(
                    new GUIContent(v.Name),
                    (v.ID == p.VariableID),
                    (userData) =>
                    {
                        p.SetVariable(this.activeTimeline, (int)userData);
                    },
                    v.ID 
                );
            }
            for (int i = 0; i < (int)VariableType.NumTypes; ++i)
            {
                VariableType varType = (VariableType)i;
                string varLabel = varType.ToString();
                menu.AddItem(
                    new GUIContent("Add New " + varLabel + " Variable"),
                    false,
                    () =>
                    {
                        ModalTextWindow.Popup("New " + varLabel + " Name", (name) =>
                        {
                            HamTimelineVariable newVar = this.activeTimeline.AddVariable(name, varType);
                            p.SetVariable(this.activeTimeline, newVar.ID);
                        });
                    }
                );
            }
            menu.ShowAsContext(); 
        }

        // Comparison Selection
        if (GUILayout.Button(p.Comparison.ToString()))
        {
            GenericMenu menu = new GenericMenu();
            for (int i = 0; i < (int)VariableComparison.NumComparisons; ++i)
            {
                int thisIndex = i;
                menu.AddItem(
                    new GUIContent(((VariableComparison)i).ToString()),
                    (VariableComparison)i == p.Comparison,
                    (userData) =>
                    {
                        p.Comparison = (VariableComparison)userData;
                    },
                    thisIndex
                );
            }
            menu.ShowAsContext(); 
        }

        // Value Setting
        if (p.VariableID != HamTimeline.InvalidID)
        {
            VariableValueField(p.CompareValue);
        }

        GUILayout.EndVertical(); 
    }
Beispiel #5
0
    private void BranchNodeEditing(HamBranchNode node)
    {
        GUILayout.Label("Branch Node", Style("SubTitle"));

        GUILayout.BeginVertical();
        for (int i = 0; i < node.Predicates.Count; ++i)
        {
            PredicateEditing(node, i);
        }
        GUILayout.BeginHorizontal(Style("box"));
        if (GUILayout.Button("Add Predicate", Style("FlexButton")))
        {
            node.AddPredicate();
        }
        GUILayout.EndHorizontal();
        GUILayout.EndVertical();
    }