public DeferredCommand(ScenimaticEvent eventData, Connection connection, DeferredCommandType commandType) { this.eventData = eventData; this.connection = connection; this.commandType = commandType; }
public void NextEventInQueue() { if (eventQueue.Count == 0) { // load next branch if (!currentBranch.connectionOutputs[0].hide) { if (currentBranch.connectionOutputs[0].connectedToGUIDs == null || currentBranch.connectionOutputs[0].connectedToGUIDs.Count == 0) { throw new System.Exception("Scenimatic came to an ungraceful end!"); } nextGUID = currentBranch.connectionOutputs[0].connectedToGUIDs[0]; } LoadBranch(nextGUID); return; } currentEvent = eventQueue.Dequeue(); switch (currentEvent.eventType) { case ScenimaticEvent.ScenimaticEventType.Dialog: dialogPanel.NextTextBlock(currentEvent.image, currentEvent.text); break; case ScenimaticEvent.ScenimaticEventType.Query: queryPanel.SetOptionList(currentEvent.options, 0); break; default: Debug.LogWarning("Event type " + currentEvent.eventType + " unrecognized or un-implemented"); break; } }
public static ScenimaticSerializedNode CreateNewBranch(Vector2 windowPosition) { return(new ScenimaticSerializedNode() { GUID = System.Guid.NewGuid().ToString(), position = windowPosition, data = new ScenimaticBranch() { branchName = "New Branch", connectionInputs = new List <Connection>() { new Connection() { GUID = System.Guid.NewGuid().ToString(), type = ConnectionType.ControlFlow, variableName = Connection.ControlFlowInName, } }, connectionOutputs = new List <Connection>() { new Connection() { GUID = System.Guid.NewGuid().ToString(), type = ConnectionType.ControlFlow, variableName = Connection.ControlFlowOutName, } }, events = new List <ScenimaticEvent>() { ScenimaticEvent.CreateDialogEvent("", "no image"), }, } }); }
private void DialogEventEdit(ScenimaticEvent eventData) { eventData.text = WithoutSelectAll(() => EditorGUILayout.TextArea(eventData.text)); if (eventData.sprite == null && nodeGraph.spriteAtlas != null) { eventData.sprite = nodeGraph.spriteAtlas.GetSprite(eventData.image); } Sprite newSprite = (Sprite)EditorGUILayout.ObjectField("", // this space won't go away :/ eventData.sprite, typeof(Sprite), false, GUILayout.MaxWidth(65)); // so's shrinks it I does if (newSprite != eventData.sprite && newSprite != null) { if (nodeGraph.spriteAtlas == null) { string path = EditorUtility.OpenFilePanelWithFilters( "No Sprite Atlas selected. A Sprite Atlas must be selected to continue.", "", new string[] { "SpriteAtlas", "spriteatlas" }); if (string.IsNullOrEmpty(path)) { Debug.LogError("Sprite Atlas not set. Sprite Atlas must be set to select images."); return; } nodeGraph.spriteAtlas = AssetDatabase.LoadAssetAtPath <SpriteAtlas>( path.Substring(path.IndexOf(@"Assets/"))); } if (nodeGraph.spriteAtlas.GetPackables().Contains(newSprite)) { eventData.sprite = newSprite; eventData.image = newSprite.name; } else { eventData.sprite = newSprite; // prompt to add sprite to sprite atlas if (EditorUtility.DisplayDialog("Add to SpriteAtlas?", "This sprite is not in the selected Sprite Atlas." + "\nAdd it to " + nodeGraph.spriteAtlas.name + "?" + "\n(If no is selected, the image will not be saved.)", "Yes", "No")) { eventData.image = newSprite.name; SpriteAtlasExtensions.Add( nodeGraph.spriteAtlas, new Object[] { eventData.sprite }); // unfortunately the following lines don't seem to have the desired effect // that is, an automatic push of the "Pack Preview" button AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); } } } }
private void DeleteEvent(ScenimaticEvent eventData) { deferredCommandQueue.Enqueue(new DeferredCommand( eventData, DeferredCommandType.DeleteEvent)); }
private void QueryEventEdit(ScenimaticEvent eventData) { if (eventData.connections == null || eventData.connections.Count == 0) { if (eventData.outputGUIDs == null) { return; } List <Connection> connections = new List <Connection>(); foreach (string guid in eventData.outputGUIDs) { Connection conn = branch.GetOutputConnectionByGUID(guid); if (conn == null) // this will be null the first time { return; } connections.Add(conn); } eventData.connections = connections; } EditorGUILayout.BeginVertical(); { int size = eventData.options.Count; EditorGUILayout.BeginHorizontal(); { GUILayout.Label("Choices:"); if (eventData.connections[0].type == ConnectionType.Bool) { GUI.enabled = false; } size = EditorGUILayout.DelayedIntField(size, GUILayout.MaxWidth(20)); if (eventData.connections[0].type == ConnectionType.Bool) { size = 2; GUI.enabled = true; } if (size > 1 && size < MAX_QUERY_CHOICES && size != eventData.options.Count) { ConnectionType outputType = eventData.connections[0].type; while (size > eventData.options.Count) { char c = (char)((int)'A' + eventData.options.Count); eventData.options.Add(c.ToString()); if (outputType == ConnectionType.ControlFlow) { // add new output deferredCommandQueue.Enqueue( new DeferredCommand( eventData, DeferredCommandType.CreateControlFlowOutputConnection)); } } while (size < eventData.options.Count) { if (outputType == ConnectionType.ControlFlow) { // remove output deferredCommandQueue.Enqueue( new DeferredCommand(eventData, eventData.connections[eventData.options.Count - 1], DeferredCommandType.DeleteControlFlowOutputConnection)); } eventData.options.RemoveAt(eventData.options.Count - 1); } } } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { for (int i = 0; i < eventData.options.Count; ++i) { if (i % 4 == 0) { EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); } string newChoiceText = ""; switch (eventData.connections[0].type) { case ConnectionType.String: eventData.options[i] = WithoutSelectAll( () => EditorGUILayout.DelayedTextField(eventData.options[i])); break; case ConnectionType.ControlFlow: newChoiceText = WithoutSelectAll( () => EditorGUILayout.DelayedTextField(eventData.options[i])); break; case ConnectionType.Int: if (!int.TryParse(eventData.options[i], out int intResult)) { intResult = 0; } newChoiceText = EditorGUILayout.DelayedIntField(intResult).ToString(); eventData.options[i] = newChoiceText; break; case ConnectionType.Float: if (!float.TryParse(eventData.options[i], out float floatResult)) { floatResult = 0; } newChoiceText = EditorGUILayout.DelayedFloatField(floatResult).ToString(); eventData.options[i] = newChoiceText; break; case ConnectionType.Bool: if (!bool.TryParse(eventData.options[i], out bool boolResult)) { boolResult = i == 0 ? false : true; } GUI.enabled = false; newChoiceText = WithoutSelectAll( () => EditorGUILayout.DelayedTextField(boolResult.ToString())); eventData.options[i] = newChoiceText; GUI.enabled = true; break; } if (eventData.connections[0].type == ConnectionType.ControlFlow && eventData.connections.Count == eventData.options.Count) { if (newChoiceText != eventData.options[i]) { eventData.options[i] = CheckForDuplicateNameInQueryList(newChoiceText, eventData.options, i); } eventData.connections[i].variableName = newChoiceText; } } } EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(rectStyle); { EditorGUILayout.LabelField("Output as:", GUILayout.Width(70)); ConnectionType originalConnType = eventData.connections[0].type; ConnectionType newConnType = (ConnectionType)EditorGUILayout.EnumPopup( (SelectableQueryOutputConnectionType)originalConnType, GUILayout.Width(100)); if (newConnType != originalConnType) { if (ConfirmChangeOutputType(eventData.connections)) { if (originalConnType == ConnectionType.ControlFlow) { // if output was ControlFlow, delete extra outputs and unhide the default out ControlFlow for (int i = eventData.outputGUIDs.Count - 1; i > 0; --i) // first one will still be used { deferredCommandQueue.Enqueue( new DeferredCommand(eventData, branch.GetOutputConnectionByGUID(eventData.outputGUIDs[i]), DeferredCommandType.DeleteControlFlowOutputConnection)); } if (eventData.connections[0].type == ConnectionType.ControlFlow) { branch.connectionOutputs[0].hide = false; } } else if (newConnType == ConnectionType.ControlFlow) { // check if this branch already has a control flow if (branch.connectionOutputs[0].hide) { // a popup would be better here, no? Debug.LogWarning("Cannot have more than one ControlFlow Query in a branch."); return; } // add extra outputs and hide the default out ControlFlow for (int i = 1; i < eventData.options.Count; ++i) // first one is already made { deferredCommandQueue.Enqueue( new DeferredCommand( eventData, DeferredCommandType.CreateControlFlowOutputConnection)); } nodeGraph.connectionPoints[branch.connectionOutputs[0].GUID].RemoveAllConnections(); branch.connectionOutputs[0].hide = true; } nodeGraph.connectionPoints[eventData.connections[0].GUID].RemoveAllConnections(); Connection conn = eventData.connections[0]; conn.type = newConnType; nodeGraph.RefreshConnectionData(conn); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); } } if (originalConnType != ConnectionType.ControlFlow) { EditorGUILayout.LabelField("Output Variable Name", GUILayout.Width(135)); string newName = WithoutSelectAll( () => EditorGUILayout.DelayedTextField( eventData.connections[0].variableName)); if (newName != eventData.connections[0].variableName) { eventData.connections[0].variableName = newName; CheckForDuplicateNameInConnections( eventData.connections[0], branch.connectionOutputs); } } } // !this Layout is purposefully left un-Ended! (it's ended after the function ends) }
private ScenimaticEvent ParseEvent(ScenimaticEvent eventData) { Rect clickArea = EditorGUILayout.BeginHorizontal(rectStyle); { // move up/down buttons EditorGUILayout.BeginVertical(GUILayout.Width(10)); { if (GUILayout.Button(upArrow, GUILayout.Width(20), GUILayout.Height(20))) { if (branch.events.IndexOf(eventData) != 0) { deferredCommandQueue.Enqueue( new DeferredCommand( eventData, DeferredCommandType.MoveUp)); } } if (GUILayout.Button(downArrow, GUILayout.Width(20), GUILayout.Height(20))) { if (branch.events.IndexOf(eventData) != branch.events.Count - 1) { deferredCommandQueue.Enqueue( new DeferredCommand( eventData, DeferredCommandType.MoveDown)); } } } EditorGUILayout.EndVertical(); ScenimaticEventType newEventType = (ScenimaticEventType) EditorGUILayout.EnumPopup(eventData.eventType, GUILayout.Width(90)); if (newEventType != eventData.eventType) { if (eventData.eventType == ScenimaticEventType.Unknown || EditorUtility.DisplayDialog("Event Type Changing!", "WARNING: You area attempting to change the event type" + " which will destroy this current events data. Proceed?", "Change Event Type", "Oops")) { switch (newEventType) { case ScenimaticEventType.Dialog: if (eventData.eventType == ScenimaticEventType.Query) { if (ConfirmChangeOutputType(eventData.connections)) { // cleanup outputs, especially if it was a Control Flow for (int i = eventData.outputGUIDs.Count - 1; i >= 0; --i) { deferredCommandQueue.Enqueue( new DeferredCommand( eventData, branch.GetOutputConnectionByGUID(eventData.outputGUIDs[i]), DeferredCommandType.DeleteControlFlowOutputConnection)); } // turn default Out ControlFlow back on if was ControlFlow Query if (eventData.connections[0].type == ConnectionType.ControlFlow) { branch.connectionOutputs[0].hide = false; } } } eventData = CreateDialogEvent("Dialog Text here", "Image name here"); break; case ScenimaticEventType.Query: eventData = CreateQueryEvent(new List <string>() { "A", "B" }); deferredCommandQueue.Enqueue( new DeferredCommand( eventData, DeferredCommandType.CreateOutputConnection)); break; default: Debug.LogWarning(newEventType + " not yet implemented"); break; } } } switch (eventData.eventType) { case ScenimaticEventType.Dialog: DialogEventEdit(eventData); break; case ScenimaticEventType.Query: QueryEventEdit(eventData); break; default: NotImplementedEvent(); break; } } EditorGUILayout.EndHorizontal(); if (Event.current.type == EventType.ContextClick && clickArea.Contains(Event.current.mousePosition)) { GenericMenu menu = new GenericMenu(); menu.AddItem(new GUIContent("Delete Event"), false, () => DeleteEvent(eventData)); menu.ShowAsContext(); Event.current.Use(); } return(eventData); }
private void BranchEventView() { EditorGUILayout.BeginHorizontal(rectStyle); { branch.branchName = GUILayout.TextField(branch.branchName); GUILayout.FlexibleSpace(); if (GUILayout.Button("Add Event")) { // add empty event branch.events.Add(ScenimaticEvent.CreateEmpytEvent()); } } EditorGUILayout.EndHorizontal(); // inputs GUILayout.BeginVertical(rectStyle); { EditorGUILayout.BeginHorizontal(); { GUILayout.Label("Inputs:"); ResizableInputBlock(branch.connectionInputs, ConnectionPointDirection.In); if (branch.connectionInputs.Count > 1) { GUILayout.Label("Insert a variable into dialog text " + "by writing the variable name in curly braces. Ex: {" + branch.connectionInputs[1].variableName + "}."); } } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); Color defaultColor = GUI.backgroundColor; EditorGUILayout.BeginHorizontal(); { int rowCount = -1; for (int i = 0; i < branch.connectionInputs.Count; ++i) { if (branch.connectionInputs[i].type != ConnectionType.ControlFlow) { ++rowCount; } if (rowCount % 5 == 0) { GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); } DrawInputBox(branch.connectionInputs[i]); } GUI.backgroundColor = defaultColor; if (GUILayout.Button(new GUIContent("+", "Creates new Input"))) { Connection newConn = CreateNewConnection(ConnectionType.Int); CheckForDuplicateNameInConnections(newConn, branch.connectionInputs); entityData.AddNewConnectionPoint(newConn, ConnectionPointDirection.In); } } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndVertical(); scrollPos = EditorGUILayout.BeginScrollView(scrollPos, rectStyle); { for (int i = 0; i < branch.events.Count; ++i) { branch.events[i] = ParseEvent(branch.events[i]); } } EditorGUILayout.EndScrollView(); }
public DeferredCommand(ScenimaticEvent eventData, DeferredCommandType commandType) { this.eventData = eventData; this.commandType = commandType; }