override public Object Clone() { //TODO: make cloning work properly for duplication of entire plot fragments and author goals //- add a new clone method or something to //stop the creation of new unique names/variable names ActionCalculation newClone = (ActionCalculation)MemberwiseClone(); newClone.Id = StoryWorldDataProvider.getStoryData().getNewId(); newClone.Result = (Trait)_resultVar.Clone(); newClone.ParamLeft = (Parameter)_paramLeft.Clone(); newClone.ParamRight = (Parameter)_paramRight.Clone(); //Give the new var a unique name, making sure the new name is actually unique. //If name is not unique, keep increment suffix number until it is string newName = newClone.ResultVarName; int cloneCount = 1; PlotFragment parentFrag = StoryWorldDataProvider.getStoryData().findPlotFragmentById(_parentPlotFragmentId); Action nullAction = null; List <string> prevVars = parentFrag.getAllPreviouslyBoundVariableNames(nullAction, true); while (prevVars.Contains(newName)) { newName = newClone.ResultVarName + cloneCount.ToString(); cloneCount++; } newClone.ResultVarName = newName; return(newClone); }
public WindowActionCalculationEditor(PlotFragment parentPlotFragment, ActionCalculation calc, StoryData world) { InitializeComponent(); _currentEntity = calc; _parentPlotFragment = parentPlotFragment; _currentStoryData = world; textBoxNumericLeft.NullValue = 0.0; textBoxNumericRight.NullValue = 0.0; }
private void btNewAction_Click(object sender, RoutedEventArgs e) { List <string> editChoices = new List <string>(); editChoices.Add("Output Text"); editChoices.Add("Pursue a Subgoal"); editChoices.Add("Make a Calculation"); editChoices.Add("Create a new Character/Environment/Plot Point"); editChoices.Add("Edit a saved Character/Environment/Plot Point"); editChoices.Add("Delete a saved Character/Environment/Plot Point"); int result = -1; result = Utilities.MakeListChoiceDialog("What type of Action would you like to create?", editChoices, this); if (result < 0) { return; } else if (result == 0) //Output Text { ActionTextOutput newTextOutputAction = new ActionTextOutput(_currentEntity.Id, "", _currentStoryData); _currentEntity.Actions.Add(newTextOutputAction); Window newWin = new WindowActionTextOutput(_currentEntity, newTextOutputAction); newWin.Owner = this; newWin.ShowDialog(); } else if (result == 1) //Pursue Subgoal { List <string> choiceList = new List <string>(); foreach (AuthorGoal goal in _currentStoryData.AuthorGoals) { choiceList.Add(goal.Description); } result = Utilities.MakeListChoiceDialog("Select an Author Goal to pursue", choiceList, this); if (result > -1) { AuthorGoal goalToPursue = _currentStoryData.AuthorGoals[result]; ActionSubgoal newAction = new ActionSubgoal(_currentEntity.Id, goalToPursue.Id, _currentStoryData); _currentEntity.Actions.Add(newAction); if (goalToPursue.Parameters.Count > 0) { Window newWin = new WindowActionSubgoalEditor(false, _currentEntity, newAction, _currentStoryData); newWin.Owner = this; newWin.ShowDialog(); } } } else if (result == 2) //Make a calculation { Action nullAction = null; List <string> existingVarNames = _currentEntity.getAllPreviouslyBoundVariableNames(nullAction, true); string varName = Utilities.MakeConstrainedTextDialog( "Please enter a name for the variable that will store the data in this calculation:", "That variable name has already been used.", existingVarNames, this); if (varName != null) { ActionCalculation newCalc = new ActionCalculation(_currentEntity.Id, varName, _currentStoryData); _currentEntity.Actions.Add(newCalc); Window newWin = new WindowActionCalculationEditor(_currentEntity, newCalc, _currentStoryData); newWin.Owner = this; newWin.ShowDialog(); } } else if (result == 3) //Create a new object { List <string> newObjectChoices = new List <string>(); newObjectChoices.Add("Character"); newObjectChoices.Add("Environment"); foreach (PlotPointType pp in _currentStoryData.PlotPointTypes) { newObjectChoices.Add(pp.Description); } int resultCreateObject = Utilities.MakeListChoiceDialog("What type of object would you like to create?", newObjectChoices, this); if (resultCreateObject < 0) { return; } Action nullAction = null; List <string> existingVarNames = _currentEntity.getAllPreviouslyBoundVariableNames(nullAction, true); string varName = Utilities.MakeConstrainedTextDialog( "Please enter a name for the variable that will store your new Object", "That variable name has already been used.", existingVarNames, this); if (varName == null) { return; } if (resultCreateObject == 0) { string entityName = Utilities.MakeTextDialog("Please enter a name for the new Character:", this); if (entityName == null) { return; } ActionCreateCharacter newCreateEntityAction = new ActionCreateCharacter(_currentEntity.Id, entityName, varName, _currentStoryData); _currentEntity.Actions.Add(newCreateEntityAction); //Synchronize all traits and relationships if (_currentStoryData.Characters.Count > 1) { Utilities.SynchronizeTwoCharacters(_currentStoryData.Characters[0], newCreateEntityAction.NewCharacter, _currentStoryData); } clearDataBindings(); dataBind(); Window newWin = new WindowCharacterEditor(newCreateEntityAction.NewCharacter, _currentStoryData); newWin.Owner = this; newWin.ShowDialog(); } else if (resultCreateObject == 1) { string entityName = Utilities.MakeTextDialog("Please enter a name for the new Environment:", this); if (entityName == null) { return; } ActionCreateEnvironment newCreateEntityAction = new ActionCreateEnvironment(_currentEntity.Id, entityName, varName, _currentStoryData); _currentEntity.Actions.Add(newCreateEntityAction); //Synchronize all traits and relationships if (_currentStoryData.Environments.Count > 1) { Utilities.SynchronizeTwoEnvironments(_currentStoryData.Environments[0], newCreateEntityAction.NewEnvironment, _currentStoryData); } clearDataBindings(); dataBind(); Window newWin = new WindowEnvironmentEditor(newCreateEntityAction.NewEnvironment, _currentStoryData); newWin.Owner = this; newWin.ShowDialog(); } else { int plotPointIndex = resultCreateObject - 2; PlotPointType currType = _currentStoryData.PlotPointTypes[plotPointIndex]; ActionCreatePlotPoint newCreateEntityAction = new ActionCreatePlotPoint(_currentEntity.Id, currType, varName, _currentStoryData); _currentEntity.Actions.Add(newCreateEntityAction); clearDataBindings(); dataBind(); Window newWin = new WindowPlotPointEditor(newCreateEntityAction.NewPlotPoint, _currentStoryData); newWin.Owner = this; newWin.ShowDialog(); } } else if (result == 4) //Edit a saved object { List <string> editObjectChoices = new List <string>(); editObjectChoices.Add("Character"); editObjectChoices.Add("Environment"); foreach (PlotPointType pp in _currentStoryData.PlotPointTypes) { editObjectChoices.Add(pp.Description); } int resultEditObject = Utilities.MakeListChoiceDialog("What type of object would you like to edit?", editObjectChoices, this); if (resultEditObject < 0) { return; } else if (resultEditObject == 0) //Edit character { List <string> editObjVarChoices = _currentEntity.getPreviouslyBoundCharacterVarNames(null); if (editObjVarChoices.Count == 0) { Utilities.MakeErrorDialog("There are no saved Character variables to edit", this); return; } int resultChooseEditTarget = Utilities.MakeListChoiceDialog( "What saved Character would you like to edit?", editObjVarChoices, this); if (resultChooseEditTarget < 0) { return; } ActionEditObject newEditObj = new ActionEditObject( _currentEntity.Id, editObjVarChoices[resultChooseEditTarget], _currentStoryData.CharTypeId, ObjectEditingMode.Trait, _currentStoryData); _currentEntity.Actions.Add(newEditObj); clearDataBindings(); dataBind(); Window newWin = new WindowActionEditEntity(_currentEntity, newEditObj, _currentStoryData); newWin.Owner = this; newWin.ShowDialog(); } else if (resultEditObject == 1) //Edit Environment { List <string> editObjVarChoices = _currentEntity.getPreviouslyBoundEnvironmentVarNames(null); if (editObjVarChoices.Count == 0) { Utilities.MakeErrorDialog("There are no saved Environment variables to edit", this); return; } int resultChooseEditTarget = Utilities.MakeListChoiceDialog( "What saved Environment would you like to edit?", editObjVarChoices, this); if (resultChooseEditTarget < 0) { return; } ActionEditObject newEditObj = new ActionEditObject( _currentEntity.Id, editObjVarChoices[resultChooseEditTarget], _currentStoryData.EnvTypeId, ObjectEditingMode.Trait, _currentStoryData); _currentEntity.Actions.Add(newEditObj); clearDataBindings(); dataBind(); Window newWin = new WindowActionEditEntity(_currentEntity, newEditObj, _currentStoryData); newWin.Owner = this; newWin.ShowDialog(); } else if (resultEditObject > 1) //Edit a Plot Point { int plotPointIndex = resultEditObject - 2; PlotPointType currType = _currentStoryData.PlotPointTypes[plotPointIndex]; if (currType.Traits.Count == 0) { Utilities.MakeErrorDialog("The " + currType.Description + " type has no traits to edit.", this); return; } List <string> editObjVarChoices = _currentEntity.getPreviouslyBoundPlotPointTypeVarNames(currType, null); if (editObjVarChoices.Count == 0) { Utilities.MakeErrorDialog("There are no saved " + currType.Description + " variables to edit", this); return; } int resultChooseEditTarget = Utilities.MakeListChoiceDialog( "What saved " + currType.Description + " would you like to edit?", editObjVarChoices, this); if (resultChooseEditTarget < 0) { return; } ActionEditObject newEditObj = new ActionEditObject( _currentEntity.Id, editObjVarChoices[resultChooseEditTarget], currType.Id, ObjectEditingMode.Trait, _currentStoryData); _currentEntity.Actions.Add(newEditObj); clearDataBindings(); dataBind(); Window newWin = new WindowActionEditEntity(_currentEntity, newEditObj, _currentStoryData); newWin.Owner = this; newWin.ShowDialog(); } } else if (result == 5) //Delete a saved object { List <string> editObjectChoices = new List <string>(); editObjectChoices.Add("Character"); editObjectChoices.Add("Environment"); foreach (PlotPointType pp in _currentStoryData.PlotPointTypes) { editObjectChoices.Add("Plot Point: " + pp.Name); } int resultDelObject = Utilities.MakeListChoiceDialog("What type of object would you like to delete?", editObjectChoices, this); if (resultDelObject < 0) { return; } else if (resultDelObject == 0) //Delete character { List <string> deleteObjectChoices = _currentEntity.getPreviouslyBoundCharacterVarNames(null); if (deleteObjectChoices.Count == 0) { Utilities.MakeErrorDialog("There are no saved Character variables to delete", this); return; } int resultChooseDeletionTarget = Utilities.MakeListChoiceDialog( "What saved Character would you like to delete?", deleteObjectChoices, this); if (resultChooseDeletionTarget < 0) { return; } ActionDeleteEntity newDelEntity = new ActionDeleteEntity( _currentEntity.Id, deleteObjectChoices[resultChooseDeletionTarget], _currentStoryData.CharTypeId, _currentStoryData); _currentEntity.Actions.Add(newDelEntity); } else if (resultDelObject == 1) //Delete Environment { List <string> deleteObjectChoices = _currentEntity.getPreviouslyBoundEnvironmentVarNames(null); if (deleteObjectChoices.Count == 0) { Utilities.MakeErrorDialog("There are no saved Environment variables to delete", this); return; } int resultChooseDeletionTarget = Utilities.MakeListChoiceDialog( "What saved Environment would you like to delete?", deleteObjectChoices, this); if (resultChooseDeletionTarget < 0) { return; } ActionDeleteEntity newDelEntity = new ActionDeleteEntity( _currentEntity.Id, deleteObjectChoices[resultChooseDeletionTarget], _currentStoryData.EnvTypeId, _currentStoryData); _currentEntity.Actions.Add(newDelEntity); } else if (resultDelObject > 1) //Delete a Plot Point { int plotPointIndex = resultDelObject - 2; PlotPointType currType = _currentStoryData.PlotPointTypes[plotPointIndex]; List <string> deleteObjectChoices = _currentEntity.getPreviouslyBoundPlotPointTypeVarNames(currType, null); if (deleteObjectChoices.Count == 0) { Utilities.MakeErrorDialog("There are no saved " + currType.Description + " variables to delete", this); return; } int resultChooseDeletionTarget = Utilities.MakeListChoiceDialog( "What saved " + currType.Description + " would you like to delete?", deleteObjectChoices, this); if (resultChooseDeletionTarget < 0) { return; } ActionDeleteEntity newDelEntity = new ActionDeleteEntity( _currentEntity.Id, deleteObjectChoices[resultChooseDeletionTarget], currType.Id, _currentStoryData); _currentEntity.Actions.Add(newDelEntity); } } clearDataBindings(); dataBind(); }
private void btNewAction_Click(object sender, RoutedEventArgs e) { List<string> editChoices = new List<string>(); editChoices.Add("Output Text"); editChoices.Add("Pursue a Subgoal"); editChoices.Add("Make a Calculation"); editChoices.Add("Create a new Character/Environment/Plot Point"); editChoices.Add("Edit a saved Character/Environment/Plot Point"); editChoices.Add("Delete a saved Character/Environment/Plot Point"); int result = -1; result = Utilities.MakeListChoiceDialog("What type of Action would you like to create?", editChoices, this); if (result < 0) { return; } else if (result == 0) //Output Text { ActionTextOutput newTextOutputAction = new ActionTextOutput(_currentEntity.Id, "", _currentStoryData); _currentEntity.Actions.Add(newTextOutputAction); Window newWin = new WindowActionTextOutput(_currentEntity, newTextOutputAction); newWin.Owner = this; newWin.ShowDialog(); } else if (result == 1) //Pursue Subgoal { List<string> choiceList = new List<string>(); foreach (AuthorGoal goal in _currentStoryData.AuthorGoals) { choiceList.Add(goal.Description); } result = Utilities.MakeListChoiceDialog("Select an Author Goal to pursue", choiceList, this); if (result > -1) { AuthorGoal goalToPursue = _currentStoryData.AuthorGoals[result]; ActionSubgoal newAction = new ActionSubgoal(_currentEntity.Id, goalToPursue.Id, _currentStoryData); _currentEntity.Actions.Add(newAction); if(goalToPursue.Parameters.Count > 0) { Window newWin = new WindowActionSubgoalEditor(false, _currentEntity, newAction, _currentStoryData); newWin.Owner = this; newWin.ShowDialog(); } } } else if (result == 2) //Make a calculation { Action nullAction = null; List<string> existingVarNames = _currentEntity.getAllPreviouslyBoundVariableNames(nullAction, true); string varName = Utilities.MakeConstrainedTextDialog( "Please enter a name for the variable that will store the data in this calculation:", "That variable name has already been used.", existingVarNames, this); if(varName != null) { ActionCalculation newCalc = new ActionCalculation(_currentEntity.Id, varName, _currentStoryData); _currentEntity.Actions.Add(newCalc); Window newWin = new WindowActionCalculationEditor(_currentEntity, newCalc, _currentStoryData); newWin.Owner = this; newWin.ShowDialog(); } } else if (result == 3) //Create a new object { List<string> newObjectChoices = new List<string>(); newObjectChoices.Add("Character"); newObjectChoices.Add("Environment"); foreach (PlotPointType pp in _currentStoryData.PlotPointTypes) { newObjectChoices.Add(pp.Description); } int resultCreateObject = Utilities.MakeListChoiceDialog("What type of object would you like to create?", newObjectChoices, this); if (resultCreateObject < 0) { return; } Action nullAction = null; List<string> existingVarNames = _currentEntity.getAllPreviouslyBoundVariableNames(nullAction, true); string varName = Utilities.MakeConstrainedTextDialog( "Please enter a name for the variable that will store your new Object", "That variable name has already been used.", existingVarNames, this); if(varName == null) return; if(resultCreateObject == 0) { string entityName = Utilities.MakeTextDialog("Please enter a name for the new Character:", this); if (entityName == null) return; ActionCreateCharacter newCreateEntityAction = new ActionCreateCharacter(_currentEntity.Id, entityName, varName, _currentStoryData); _currentEntity.Actions.Add(newCreateEntityAction); //Synchronize all traits and relationships if (_currentStoryData.Characters.Count > 1) { Utilities.SynchronizeTwoCharacters(_currentStoryData.Characters[0], newCreateEntityAction.NewCharacter, _currentStoryData); } clearDataBindings(); dataBind(); Window newWin = new WindowCharacterEditor(newCreateEntityAction.NewCharacter, _currentStoryData); newWin.Owner = this; newWin.ShowDialog(); } else if(resultCreateObject == 1) { string entityName = Utilities.MakeTextDialog("Please enter a name for the new Environment:", this); if (entityName == null) return; ActionCreateEnvironment newCreateEntityAction = new ActionCreateEnvironment(_currentEntity.Id, entityName, varName, _currentStoryData); _currentEntity.Actions.Add(newCreateEntityAction); //Synchronize all traits and relationships if (_currentStoryData.Environments.Count > 1) { Utilities.SynchronizeTwoEnvironments(_currentStoryData.Environments[0], newCreateEntityAction.NewEnvironment, _currentStoryData); } clearDataBindings(); dataBind(); Window newWin = new WindowEnvironmentEditor(newCreateEntityAction.NewEnvironment, _currentStoryData); newWin.Owner = this; newWin.ShowDialog(); } else { int plotPointIndex = resultCreateObject - 2; PlotPointType currType = _currentStoryData.PlotPointTypes[plotPointIndex]; ActionCreatePlotPoint newCreateEntityAction = new ActionCreatePlotPoint(_currentEntity.Id, currType, varName, _currentStoryData); _currentEntity.Actions.Add(newCreateEntityAction); clearDataBindings(); dataBind(); Window newWin = new WindowPlotPointEditor(newCreateEntityAction.NewPlotPoint, _currentStoryData); newWin.Owner = this; newWin.ShowDialog(); } } else if (result == 4) //Edit a saved object { List<string> editObjectChoices = new List<string>(); editObjectChoices.Add("Character"); editObjectChoices.Add("Environment"); foreach (PlotPointType pp in _currentStoryData.PlotPointTypes) { editObjectChoices.Add(pp.Description); } int resultEditObject = Utilities.MakeListChoiceDialog("What type of object would you like to edit?", editObjectChoices, this); if (resultEditObject < 0) { return; } else if (resultEditObject == 0) //Edit character { List<string> editObjVarChoices = _currentEntity.getPreviouslyBoundCharacterVarNames(null); if (editObjVarChoices.Count == 0) { Utilities.MakeErrorDialog("There are no saved Character variables to edit", this); return; } int resultChooseEditTarget = Utilities.MakeListChoiceDialog( "What saved Character would you like to edit?", editObjVarChoices, this); if (resultChooseEditTarget < 0) { return; } ActionEditObject newEditObj = new ActionEditObject( _currentEntity.Id, editObjVarChoices[resultChooseEditTarget], _currentStoryData.CharTypeId, ObjectEditingMode.Trait, _currentStoryData); _currentEntity.Actions.Add(newEditObj); clearDataBindings(); dataBind(); Window newWin = new WindowActionEditEntity(_currentEntity, newEditObj, _currentStoryData); newWin.Owner = this; newWin.ShowDialog(); } else if (resultEditObject == 1) //Edit Environment { List<string> editObjVarChoices = _currentEntity.getPreviouslyBoundEnvironmentVarNames(null); if (editObjVarChoices.Count == 0) { Utilities.MakeErrorDialog("There are no saved Environment variables to edit", this); return; } int resultChooseEditTarget = Utilities.MakeListChoiceDialog( "What saved Environment would you like to edit?", editObjVarChoices, this); if (resultChooseEditTarget < 0) { return; } ActionEditObject newEditObj = new ActionEditObject( _currentEntity.Id, editObjVarChoices[resultChooseEditTarget], _currentStoryData.EnvTypeId, ObjectEditingMode.Trait, _currentStoryData); _currentEntity.Actions.Add(newEditObj); clearDataBindings(); dataBind(); Window newWin = new WindowActionEditEntity(_currentEntity, newEditObj, _currentStoryData); newWin.Owner = this; newWin.ShowDialog(); } else if (resultEditObject > 1) //Edit a Plot Point { int plotPointIndex = resultEditObject - 2; PlotPointType currType = _currentStoryData.PlotPointTypes[plotPointIndex]; if(currType.Traits.Count == 0) { Utilities.MakeErrorDialog("The " + currType.Description + " type has no traits to edit.", this); return; } List<string> editObjVarChoices = _currentEntity.getPreviouslyBoundPlotPointTypeVarNames(currType, null); if (editObjVarChoices.Count == 0) { Utilities.MakeErrorDialog("There are no saved " + currType.Description + " variables to edit", this); return; } int resultChooseEditTarget = Utilities.MakeListChoiceDialog( "What saved " + currType.Description + " would you like to edit?", editObjVarChoices, this); if (resultChooseEditTarget < 0) { return; } ActionEditObject newEditObj = new ActionEditObject( _currentEntity.Id, editObjVarChoices[resultChooseEditTarget], currType.Id, ObjectEditingMode.Trait, _currentStoryData); _currentEntity.Actions.Add(newEditObj); clearDataBindings(); dataBind(); Window newWin = new WindowActionEditEntity(_currentEntity, newEditObj, _currentStoryData); newWin.Owner = this; newWin.ShowDialog(); } } else if (result == 5) //Delete a saved object { List<string> editObjectChoices = new List<string>(); editObjectChoices.Add("Character"); editObjectChoices.Add("Environment"); foreach (PlotPointType pp in _currentStoryData.PlotPointTypes) { editObjectChoices.Add("Plot Point: " + pp.Name); } int resultDelObject = Utilities.MakeListChoiceDialog("What type of object would you like to delete?", editObjectChoices, this); if (resultDelObject < 0) { return; } else if (resultDelObject == 0) //Delete character { List<string> deleteObjectChoices = _currentEntity.getPreviouslyBoundCharacterVarNames(null); if (deleteObjectChoices.Count == 0) { Utilities.MakeErrorDialog("There are no saved Character variables to delete", this); return; } int resultChooseDeletionTarget = Utilities.MakeListChoiceDialog( "What saved Character would you like to delete?", deleteObjectChoices, this); if (resultChooseDeletionTarget < 0) { return; } ActionDeleteEntity newDelEntity = new ActionDeleteEntity( _currentEntity.Id, deleteObjectChoices[resultChooseDeletionTarget], _currentStoryData.CharTypeId, _currentStoryData); _currentEntity.Actions.Add(newDelEntity); } else if (resultDelObject == 1) //Delete Environment { List<string> deleteObjectChoices = _currentEntity.getPreviouslyBoundEnvironmentVarNames(null); if (deleteObjectChoices.Count == 0) { Utilities.MakeErrorDialog("There are no saved Environment variables to delete", this); return; } int resultChooseDeletionTarget = Utilities.MakeListChoiceDialog( "What saved Environment would you like to delete?", deleteObjectChoices, this); if (resultChooseDeletionTarget < 0) { return; } ActionDeleteEntity newDelEntity = new ActionDeleteEntity( _currentEntity.Id, deleteObjectChoices[resultChooseDeletionTarget], _currentStoryData.EnvTypeId, _currentStoryData); _currentEntity.Actions.Add(newDelEntity); } else if (resultDelObject > 1) //Delete a Plot Point { int plotPointIndex = resultDelObject - 2; PlotPointType currType = _currentStoryData.PlotPointTypes[plotPointIndex]; List<string> deleteObjectChoices = _currentEntity.getPreviouslyBoundPlotPointTypeVarNames(currType,null); if (deleteObjectChoices.Count == 0) { Utilities.MakeErrorDialog("There are no saved " + currType.Description + " variables to delete", this); return; } int resultChooseDeletionTarget = Utilities.MakeListChoiceDialog( "What saved " + currType.Description + " would you like to delete?", deleteObjectChoices, this); if (resultChooseDeletionTarget < 0) { return; } ActionDeleteEntity newDelEntity = new ActionDeleteEntity( _currentEntity.Id, deleteObjectChoices[resultChooseDeletionTarget], currType.Id, _currentStoryData); _currentEntity.Actions.Add(newDelEntity); } } clearDataBindings(); dataBind(); }