Example #1
0
		void OnGUI()
		{
			scroll = GUILayout.BeginScrollView(scroll, false, true);
			{
				if (asset.graphs.Count > 0)
				{
					foreach (DiaQGraph q in asset.graphs)
					{
						if (GUILayout.Toggle(selected == q, q.name, GUI.skin.button, GUILayout.Width(275))) selected = q;
					}
				}
				else
				{
					GUILayout.Label("No Quests found");
				}
			}
			GUILayout.EndScrollView();

			EditorGUILayout.BeginHorizontal();
			{
				GUILayout.FlexibleSpace();

				if (selected == null) GUI.enabled = false;
				if (GUILayout.Button("Accept", GUILayout.Width(60), GUILayout.Height(20))) accepted = true;
				GUI.enabled = true;

				if (GUILayout.Button("Cancel", GUILayout.Width(60), GUILayout.Height(20))) this.Close();
				GUILayout.FlexibleSpace();
			}
			EditorGUILayout.EndHorizontal();
			GUILayout.Space(10);
		}
Example #2
0
		// ------------------------------------------------------------------------------------------------------------

		public bool Evaluate(DiaQGraph graph)
		{
			bool ret = true;

			switch (varType)
			{
				case VarType.HasSeenPlayer:
				{
					if (graph == null)
					{
						Debug.LogError("DiaQ Decision: Invalid Graph was provided for test (Has Seen Player)");
						return true;
					}
					else
					{
						bool b_val = (valType == ValType.False ? false : true);
						if (testType == TestType.Equal) ret = graph.HasSeenPlayer == b_val;
						else if (testType == TestType.NotEqual) ret = graph.HasSeenPlayer != b_val;
					}
				} break;

				case VarType.AcceptedQuest:
				case VarType.CompletedQuest:
				case VarType.HandedInQuest:
				{
					ret = QuestTest();
				} break;

				case VarType.DiaQVariable:
				{
					ret = DiaQVariableTest();
				} break;

				default: Debug.LogError("Decision Node encountered unknown test."); break;
			}

			return ret;
		}
Example #3
0
		// ============================================================================================================
		#region inspector

		private void DrawInspector()
		{
			// toolbar
			GUILayout.BeginHorizontal();
			{
				if (inspectorArea != 0 && inspectorArea != 2) GUI.enabled = false;
				if (GUILayout.Button("+", EditorStyles.toolbarButton, GUILayout.Width(25)))
				{
					if (inspectorArea == 0)
					{	// new dialogue graph
						currGraph = new DiaQGraph();
						currGraph.name = "Dialogue";
						currGraph.CreateNode(DiaQNode.Type.Start, new Vector2(100f, 70f));
						asset.graphs.Add(currGraph);
						EditorUtility.SetDirty(asset);
					}
					else
					{	// new quest
						currQuest = new DiaQuest();
						currQuest.name = "Quest";
						asset.quests.Add(currQuest);
						EditorUtility.SetDirty(asset);
					}
				}
				GUI.enabled = true;

				if (DiaQEdGUI.ToggleButton(inspectorArea == 0, "Graphs", EditorStyles.toolbarButton))
				{
					currQuest = null;
					inspectorArea = 0;
					inspectorScroll[0] = Vector2.zero;
				}

				if (DiaQEdGUI.ToggleButton(inspectorArea == 2, "Quests", EditorStyles.toolbarButton))
				{
					currGraph = null;
					currNode = null;
					inspectorArea = 2;
					inspectorScroll[0] = Vector2.zero;
				}

				if (DiaQEdGUI.ToggleButton(inspectorArea == 1, "Settings", EditorStyles.toolbarButton))
				{
					currGraph = null;
					currNode = null;
					currQuest = null;
					inspectorArea = 1;
					inspectorScroll[0] = Vector2.zero;
				}

				if (GUILayout.Button(new GUIContent(DiaQEdGUI.Icon_Help), EditorStyles.toolbarButton, GUILayout.Width(25)))
				{
					DiaQVersion.ShowAbout();
				}
			}
			GUILayout.EndHorizontal();
			DiaQEdGUI.DrawHorizontalLine(2f, DiaQEdGUI.Col_Back, 0f, 2f);

			if (inspectorArea == 0)
			{
				// list of graphs
				inspectorScroll[0] = GUILayout.BeginScrollView(inspectorScroll[0], false, true, GUILayout.Width(inspectorRect.width), GUILayout.Height(splitterPos[1] - 18));
				{
					foreach (DiaQGraph g in asset.graphs)
					{
						if (g == null) continue;
						if (DiaQEdGUI.ToggleButton(g == currGraph, g.name, EditorStyles.miniButton))
						{
							currNode = null;
							currGraph = g;
							UpdateGraphCachedStrings();
							GUI.FocusControl("");
						}
					}
				}
				GUILayout.EndScrollView();

				// splitter
				if (splitterPos[1] == 0f) splitterPos[1] = this.position.height * 0.5f;
				splitterRect[1] = new Rect(0f, splitterPos[1], this.position.width, 5f);
				GUI.Box(splitterRect[1], GUIContent.none, DiaQEdGUI.SplitterStyle);
				GUILayout.Space(1);

				// properties of selected node/ graph
				inspectorScroll[1] = GUILayout.BeginScrollView(inspectorScroll[1], false, true, GUILayout.Width(inspectorRect.width));
				{
					if (currNode != null) DrawNodeProperties();
					else if (currGraph != null) DrawGraphProperties();
				}
				GUILayout.EndScrollView();
				//GUILayout.Space(23);
			}

			else if (inspectorArea == 1)
			{	// show settings/ tools
				inspectorScroll[0] = GUILayout.BeginScrollView(inspectorScroll[0], false, true, GUILayout.Width(inspectorRect.width));
				{
					DrawInspectorTools();
				}
				GUILayout.EndScrollView();
				//GUILayout.Space(23);
			}

			else if (inspectorArea == 2)
			{	// show list of quests
				inspectorScroll[0] = GUILayout.BeginScrollView(inspectorScroll[0], false, true, GUILayout.Width(inspectorRect.width));
				{
					DrawQuestList();
				}
				GUILayout.EndScrollView();
				//GUILayout.Space(23);
			}
		}
Example #4
0
		public bool Evaluate(DiaQGraph graph)
		{
			bool ret = true;
			foreach (DiaQDecisionTest t in tests)
			{
				bool res = t.Evaluate(graph);
				if (t.combineWithPrev == 0) ret = ret && res;
				else ret = ret || res;
			}
			return ret;
		}
Example #5
0
		public Vector2 InputPositionInGraph(DiaQGraph graph)
		{
			Vector2 v = GetPositionInGraph(graph);
			v.y += 8;
			return v;
		}
Example #6
0
		// ============================================================================================================

		/// <summary>
		/// return the node that is linked to the given slot
		/// </summary>
		public DiaQNode GetLinkedNode(DiaQGraph graph, int onOutSlot)
		{
			NodeLink link = outputs.FirstOrDefault(l => l.outSlot == onOutSlot);
			if (link != null) return graph.GetNode(link.targetNodeId);
			return null;
		}
Example #7
0
		public Vector2 GetCenterPositionInGraph(DiaQGraph graph)
		{
			Vector2 p = GetPositionInGraph(graph);
			return new Vector2(p.x + position.width * 0.5f, p.y + position.height * 0.5f);
		}
Example #8
0
		public Vector2 OutputPositionInGraph(DiaQGraph graph, int slot)
		{
			return GetPositionInGraph(graph) + OutputPosition(slot);
		}
Example #9
0
		public void SetRectInGraph(DiaQGraph graph, Rect r)
		{
			position = r;
			position.x -= graph.DrawOffset.x;
			position.y -= graph.DrawOffset.y;
		}
Example #10
0
		public Vector2 GetPositionInGraph(DiaQGraph graph)
		{
			return new Vector2 (position.x + graph.DrawOffset.x,position.y + graph.DrawOffset.y);
		}
Example #11
0
		public Rect GetRectInGraph(DiaQGraph graph)
		{
			if (type == Type.Random) position.height = 30 + (i_data[0] * 20);
			Rect p = position;
			p.x += graph.DrawOffset.x;
			p.y += graph.DrawOffset.y;
			return p;
		}
Example #12
0
		/// <summary>
		/// Called on a Decision (Tru/False) type node. It will execute the test(s) and then return the 
		/// node that was linked to either true or false, depending on result
		/// </summary>
		public DiaQNode ExecuteDecision(DiaQGraph graph)
		{
			int slot = 0;
			if (decision != null)
			{
				if (false == decision.Evaluate(graph)) slot = 1;
			}
			return GetLinkedNode(graph, slot);
		}
Example #13
0
		// ============================================================================================================
		#region graph/dialogue

		/// <summary>
		/// Start a Dialogue Graph of the specified name. This will use the first graph that has the name.
		/// </summary>
		public DiaQConversation StartGraph(string byName, bool ignoreCase)
		{
			if (asset == null)
			{
				Debug.LogError("Error: DiaQ assets are not loaded.");
				return null;
			}

			DiaQGraph graph = null;
			if (ignoreCase) graph = asset.graphs.FirstOrDefault(g => g.name.Equals(byName, System.StringComparison.OrdinalIgnoreCase));
			else graph = asset.graphs.FirstOrDefault(g => g.name.Equals(byName));

			if (graph == null)
			{
				Debug.LogError(string.Format("Error: Could not find graph by name ({0}).", byName));
				return null;
			}

			activeGraph = graph;
			return activeGraph.GetData(true);
		}
Example #14
0
		/// <summary>
		/// End the current Dialogue Graph. This is an optional call. Any call to StartGraph will overwrite what
		/// the currently "active" graph is, as used by SubmitChoice() and others
		/// </summary>
		public void EndGraph()
		{
			activeGraph = null;
		}
Example #15
0
		/// <summary>
		/// Start a Dialogue Graph of the specified Ident.
		/// </summary>
		public DiaQConversation StartGraph(System.Guid byIdent)
		{
			if (asset == null)
			{
				Debug.LogError("Error: DiaQ assets are not loaded.");
				return null;
			}

			DiaQGraph graph = asset.graphs.FirstOrDefault(g => g.Ident == byIdent);

			if (graph == null)
			{
				Debug.LogError(string.Format("Error: Could not find graph by Ident ({0}).", byIdent));
				return null;
			}

			activeGraph = graph;
			return activeGraph.GetData(true);
		}