Exemplo n.º 1
0
        public void checkAndUpdateDependencesAsInteraction(Interaction parentInteraction, List <Trait> previouslyBoundVars, StoryData world)
        {
            AuthorGoal goalToPursue = world.findAuthorGoalById(_subGoalId);

            if (goalToPursue == null)
            {
                //clear out parameter list
                _parametersToPass.Clear();

                throw new Exception("Interaction \"" + parentInteraction.Title + "\" refers to an Author Goal which does not exist.");
            }

            if (goalToPursue.PlotFragments.Count == 0)
            {
                throw new Exception("Interaction \"" + parentInteraction.Title + "\" refers to an Author Goal which has no child plot fragments that fulfill it." +
                                    "\nAll Interactions must have at least one Plot Fragment associated with the goal they pursue before generation can begin.");
            }



            bool dataUpdated = syncParametersWithSubgoal();

            if (dataUpdated)
            {
                throw new Exception("Interaction \"" + parentInteraction.Title + "\" refers to an Author Goal that has had its parameters changed.\n" +
                                    "Wide Ruled has corrected the changes, but you should look at the Interaction to make sure the newly updated parameters have the correct value.");
            }
        }
 public WindowPlotFragmentEditor(PlotFragment currEntity, StoryData currStoryData)
 {
     InitializeComponent();
     _currentEntity    = currEntity;
     _currentStoryData = currStoryData;
     _parentGoal       = currStoryData.findAuthorGoalById(currEntity.ParentAuthorGoalId);
 }
Exemplo n.º 3
0
        public List <Trait> getPreviouslyBoundPrimitiveVariables(TraitDataType variableType, bool allTypes, PreconditionStatement currentPrecStatement)
        {
            List <Trait> varsToReturn = new List <Trait>();


            AuthorGoal parentGoal = StoryWorldDataProvider.findAuthorGoalById(_parentAuthorGoalId);

            // Add parameter variable names
            foreach (Parameter param in parentGoal.Parameters)
            {
                if (allTypes || (param.Type == variableType))
                {
                    varsToReturn.Add(param);
                }
            }

            foreach (PreconditionStatement precondStmt in _precStatements)
            {
                if (precondStmt == currentPrecStatement)
                {
                    //We have found where to stop looking, can now return variable list
                    return(varsToReturn);
                }
                else
                {
                    //Add the variable names bound in this statement to the running list
                    varsToReturn.AddRange(precondStmt.getBoundPrimitiveVariables(variableType, allTypes));
                }
            }

            return(varsToReturn);
        }
        private void btEditFragName_Click(object sender, RoutedEventArgs e)
        {
            // Get name
            List <string> choiceConstraints = new List <string>();
            AuthorGoal    parentGoal        = _currentStoryData.findAuthorGoalById(_currentEntity.ParentAuthorGoalId);

            if (parentGoal == null)
            {
                return;
            }

            foreach (PlotFragment frag in parentGoal.PlotFragments)
            {
                if (frag != _currentEntity) //Allow user to name this fragment to the old name, so don't add the current name to the list
                {
                    choiceConstraints.Add(frag.Name);
                }
            }

            string newName = Utilities.MakeConstrainedTextDialog(
                "Please enter a new name for this Plot Fragment:",
                "That name is already in use by another Plot Fragment.",
                choiceConstraints, this);

            if (newName == null)
            {
                return;
            }

            _currentEntity.Name = newName;
            clearDataBindings();
            dataBind();
        }
 public WindowPlotFragmentEditor(PlotFragment currEntity, StoryData currStoryData)
 {
     InitializeComponent();
     _currentEntity = currEntity;
     _currentStoryData = currStoryData;
     _parentGoal = currStoryData.findAuthorGoalById(currEntity.ParentAuthorGoalId);
 }
Exemplo n.º 6
0
        public static void SaveAuthorGoalParams(AuthorGoal currGoal, List <Parameter> newList, StoryData world)
        {
            List <Parameter> properList = new List <Parameter>();

            foreach (Parameter newParam in newList)
            {
                // Parameter oldParam = currGoal.getParameterByTypeId(newParam.TypeId);
                // if (oldParam == null)
                // {

                Parameter convertedParam = new Parameter(newParam, world);

                Parameter oldParam = currGoal.findParameterByName(newParam.Name);
                if ((oldParam != null) && (oldParam.Type == newParam.Type))
                {
                    convertedParam.Value = oldParam.Value;
                }


                properList.Add(convertedParam);

                //  properList.Add(newParam);

                // }
                // else
                // {
                // oldParam.Name = newParam.Name;
                // oldParam.Type = newParam.Type;
                //properList.Add(oldParam);
                //}
            }
            currGoal.Parameters = properList;
        }
Exemplo n.º 7
0
        public List <string> getAllPreviouslyBoundVariableNames(PreconditionStatement currentPrecStatement, bool includeAuthorGoalParameters)
        {
            List <string> varsToReturn = new List <string>();

            if (includeAuthorGoalParameters)
            {
                AuthorGoal parentGoal = StoryWorldDataProvider.findAuthorGoalById(_parentAuthorGoalId);


                // Add parameter variable names
                foreach (Parameter param in parentGoal.Parameters)
                {
                    varsToReturn.Add(param.Name);
                }
            }


            foreach (PreconditionStatement precondStmt in _precStatements)
            {
                if (precondStmt == currentPrecStatement)
                {
                    //We have found where to stop looking, can now return variable list
                    return(varsToReturn);
                }
                else
                {
                    //Add the variable names bound in this statement to the running list
                    varsToReturn.AddRange(precondStmt.getAllBoundVariableNames());
                }
            }

            return(varsToReturn);
        }
        private void btChangeAuthGoal_Click(object sender, RoutedEventArgs e)
        {
            int oldIndex = 0;
            int count = 0;
            List<string> choiceList = new List<string>();
            foreach (AuthorGoal goal in _currentStoryData.AuthorGoals)
            {
                choiceList.Add(goal.Description);
                if(goal.Id == _currentEntity.ParentAuthorGoalId)
                {
                    oldIndex = count;
                }
                count++;
            }

            int result = Utilities.MakeListChoiceDialog("Select a parent Author Goal", choiceList, this);
            if(result > -1)
            {
                if(result != oldIndex)
                {
                    _currentStoryData.AuthorGoals[oldIndex].PlotFragments.Remove(_currentEntity);

                    _parentGoal = _currentStoryData.AuthorGoals[result];
                    _parentGoal.PlotFragments.Add(_currentEntity);

                    _currentEntity.ParentAuthorGoalId = _parentGoal.Id;

                    dataBind();
                }

            }
        }
Exemplo n.º 9
0
        private void btGoalFragDelete_Click(object sender, RoutedEventArgs e)
        {
            Object itemToEdit = goalFragsTreeView.SelectedItem;

            if (itemToEdit == null)
            {
                return;
            }


            if (itemToEdit.GetType() == typeof(AuthorGoal))
            {
                if (Utilities.MakeYesNoWarningDialog("Are you sure you want to delete Author Goal \"" + ((AuthorGoal)itemToEdit).Name + "\" and all of its Plot Fragments?", "Confirm Deletion", this) == MessageBoxResult.No)
                {
                    return;
                }

                AuthorGoal goalToDelete = (AuthorGoal)itemToEdit;


                _currentStoryData.AuthorGoals.Remove(goalToDelete);

                clearDataElements();
                dataBindWindow();
            }
            else if (itemToEdit.GetType() == typeof(PlotFragment))
            {
                if (Utilities.MakeYesNoWarningDialog("Are you sure you want to delete Plot Fragment \"" + ((PlotFragment)itemToEdit).Name + "\"?", "Confirm Deletion", this) == MessageBoxResult.No)
                {
                    return;
                }
                AuthorGoal parentGoal = _currentStoryData.findAuthorGoalById(((PlotFragment)itemToEdit).ParentAuthorGoalId);
                parentGoal.PlotFragments.Remove((PlotFragment)itemToEdit);
                clearDataElements();
                dataBindWindow();
            }
            else if (itemToEdit.GetType() == typeof(ActionSubgoal))
            {
                //Find the parent plot fragment using its stored id, then use that plot fragment to look up
                //the parent author goal id, which is then used to get the actual AuthorGoal object (whew!)
                AuthorGoal goalToDelete = _currentStoryData.findAuthorGoalById(_currentStoryData.findPlotFragmentById(((ActionSubgoal)itemToEdit).ParentPlotFragmentId).ParentAuthorGoalId);


                if (Utilities.MakeYesNoWarningDialog("Are you sure you want to delete Author Goal \"" + ((AuthorGoal)goalToDelete).Name + "\" and all of its Plot Fragments?", "Confirm Deletion", this) == MessageBoxResult.No)
                {
                    return;
                }



                _currentStoryData.AuthorGoals.Remove(goalToDelete);

                clearDataElements();
                dataBindWindow();
            }
            else
            {
                return;
            }
        }
        private void btChangeAuthGoal_Click(object sender, RoutedEventArgs e)
        {
            int           oldIndex   = 0;
            int           count      = 0;
            List <string> choiceList = new List <string>();

            foreach (AuthorGoal goal in _currentStoryData.AuthorGoals)
            {
                choiceList.Add(goal.Description);
                if (goal.Id == _currentEntity.ParentAuthorGoalId)
                {
                    oldIndex = count;
                }
                count++;
            }

            int result = Utilities.MakeListChoiceDialog("Select a parent Author Goal", choiceList, this);

            if (result > -1)
            {
                if (result != oldIndex)
                {
                    _currentStoryData.AuthorGoals[oldIndex].PlotFragments.Remove(_currentEntity);

                    _parentGoal = _currentStoryData.AuthorGoals[result];
                    _parentGoal.PlotFragments.Add(_currentEntity);

                    _currentEntity.ParentAuthorGoalId = _parentGoal.Id;

                    dataBind();
                }
            }
        }
        public WindowAuthorGoalEditor(AuthorGoal currEntity, StoryData currStoryData)
        {
            InitializeComponent();
            _currentEntity = currEntity;
            _currentStoryData = currStoryData;
            _newList = new List<Parameter>();
            _isStartGoal = (_currentStoryData.StartGoalId == _currentEntity.Id);

            this.Closing += new System.ComponentModel.CancelEventHandler(MainWindow_Closing);
        }
        public WindowAuthorGoalEditor(AuthorGoal currEntity, StoryData currStoryData)
        {
            InitializeComponent();
            _currentEntity    = currEntity;
            _currentStoryData = currStoryData;
            _newList          = new List <Parameter>();
            _isStartGoal      = (_currentStoryData.StartGoalId == _currentEntity.Id);

            this.Closing += new System.ComponentModel.CancelEventHandler(MainWindow_Closing);
        }
        private void btChangeAuthGoal_Click(object sender, RoutedEventArgs e)
        {
            List <string> choiceList = new List <string>();

            foreach (AuthorGoal goal in _currentStoryData.AuthorGoals)
            {
                choiceList.Add(goal.Description);
            }
            int result = Utilities.MakeListChoiceDialog("Select a new Author Goal to pursue", choiceList, this);

            if (result > -1)
            {
                AuthorGoal newSubgoal = _currentStoryData.AuthorGoals[result];
                _currentEntity.SubGoalId = newSubgoal.Id;
                dataBind();
            }
        }
Exemplo n.º 14
0
        private void btGoalFragEdit_Click(object sender, RoutedEventArgs e)
        {
            Object itemToEdit = goalFragsTreeView.SelectedItem;

            if (itemToEdit == null)
            {
                return;
            }


            if (itemToEdit.GetType() == typeof(AuthorGoal))
            {
                Window newWin = new WindowAuthorGoalEditor((AuthorGoal)itemToEdit, _currentStoryData);
                newWin.Owner = this;
                newWin.ShowDialog();
                clearDataElements();
                dataBindWindow();
            }
            else if (itemToEdit.GetType() == typeof(PlotFragment))
            {
                Window newWin = new WindowPlotFragmentEditor((PlotFragment)itemToEdit, _currentStoryData);
                newWin.Owner = this;
                newWin.ShowDialog();
                clearDataElements();
                dataBindWindow();
            }
            else if (itemToEdit.GetType() == typeof(ActionSubgoal))
            {
                //Find the parent plot fragment using its stored id, then use that plot fragment to look up
                //the parent author goal id, which is then used to get the actual AuthorGoal object (whew!)
                AuthorGoal goalToEdit = _currentStoryData.findAuthorGoalById(((ActionSubgoal)itemToEdit).SubGoalId);

                if (goalToEdit != null)
                {
                    Window newWin = new WindowAuthorGoalEditor(goalToEdit, _currentStoryData);
                    newWin.Owner = this;
                    newWin.ShowDialog();
                    clearDataElements();
                    dataBindWindow();
                }
            }
            else
            {
                return;
            }
        }
Exemplo n.º 15
0
        public ActionSubgoal(UInt64 parentPlotFragmentId, UInt64 subgoalId, StoryData world) :
            base(parentPlotFragmentId, world)
        {
            _subGoalId        = subgoalId;
            _parametersToPass = new List <Parameter>();


            AuthorGoal subGoal = world.findAuthorGoalById(subgoalId);

            if (subGoal != null)
            {
                List <Parameter> parameters = subGoal.Parameters;
                foreach (Parameter param in parameters)
                {
                    // Add all parameters from the subgoal, which will later be filled in
                    // with literals or variables
                    _parametersToPass.Add(new Parameter(param.Name, param.Type, false, world));
                }
            }
        }
Exemplo n.º 16
0
        private void btAddNew_Click(object sender, RoutedEventArgs e)
        {
            if (_currentStoryData.AuthorGoals.Count == 0)
            {
                Utilities.MakeErrorDialog("There must be at least one Author Goal in this story for you to make a new Interactive Action.", this);
                return;
            }
            interactionsDataGrid.EndEdit();
            string newName = Utilities.MakeTextDialog("Please enter a title for this new Interactive Action:", this);

            if (newName != null)
            {
                List <string> goalChoices = new List <string>();
                //Get author goal to activate
                foreach (AuthorGoal goal in _currentStoryData.AuthorGoals)
                {
                    goalChoices.Add(goal.Description);
                }

                int result = Utilities.MakeListChoiceDialog("Choose the Author Goal you would like to activate for this Interactive Action.", goalChoices, this);
                if (result < 0)
                {
                    return;
                }

                AuthorGoal authorGoalSelection = _currentStoryData.AuthorGoals[result];


                ActionSubgoal newSubGoal     = new ActionSubgoal(0, authorGoalSelection.Id, _currentStoryData);
                Interaction   newInteraction = new Interaction(newName, newSubGoal, _currentStoryData);
                _currentStoryData.Interactions.Add(newInteraction);
                dataBind();

                WindowActionSubgoalEditor newWin = new WindowActionSubgoalEditor(true, null, newSubGoal, _currentStoryData);
                newWin.Owner = this;
                newWin.ShowDialog();
            }
        }
Exemplo n.º 17
0
        override public void checkAndUpdateDependences(List <Trait> previouslyBoundVars, StoryData world)
        {
            PlotFragment parentFrag = world.findPlotFragmentById(_parentPlotFragmentId);

            if (parentFrag == null)
            {
                throw new Exception("Pursue Subgoal Action does not have parent Plot Fragment");
            }


            AuthorGoal goalToPursue = world.findAuthorGoalById(_subGoalId);

            if (goalToPursue == null)
            {
                //clear out parameter list
                //_parametersToPass.Clear();

                throw new Exception("Pursue Subgoal Action in Plot Fragment \"" + parentFrag.Name + "\" refers to an Author Goal which does not exist.");
            }

            if (goalToPursue.PlotFragments.Count == 0)
            {
                throw new Exception("Pursue Subgoal Action in Plot Fragment \"" + parentFrag.Name + "\" refers to an Author Goal which has no child plot fragments that fulfill it." +
                                    "\nAll goals which are used during story creation must have at least one Plot Fragment associated with them before generation can begin.");
            }


            //Check variable references from previous plot fragment preconditions and actions

            foreach (Parameter param in _parametersToPass)
            {
                if (param.ValueIsBoundToVariable)
                {
                    bool foundIt = false;
                    foreach (Trait traitItem in previouslyBoundVars)
                    {
                        if (
                            (traitItem.Name == (string)param.LiteralValueOrBoundVarName) &&
                            (traitItem.Type == param.Type)
                            )
                        {
                            foundIt = true;
                            break;
                        }
                    }

                    if (!foundIt)
                    {
                        throw new Exception("Pursue Subgoal Action in Plot Fragment \"" +
                                            parentFrag.Name + "\" refers to variable \"" + param.LiteralValueOrBoundVarName +
                                            "\", \nwhich has a different type or does not exist in any previous Author Goal parameters, precondition statements, or actions .");
                    }
                }
            }


            bool dataUpdated = syncParametersWithSubgoal();

            if (dataUpdated)
            {
                throw new Exception("Pursue Subgoal Action in Plot Fragment \"" + parentFrag.Name + "\" refers to an Author Goal that has had its parameters changed.\n" +
                                    "Wide Ruled has corrected the changes, but you should look at the Action to make sure the newly updated parameters have the correct value.");
            }
        }
Exemplo n.º 18
0
        private void btGoalFragNew_Click(object sender, RoutedEventArgs e)
        {
            List<string> editChoices = new List<string>();
            editChoices.Add("Author Goal");
            editChoices.Add("Plot Fragment");

            int result = -1;
            if(_currentStoryData.AuthorGoals.Count > 0)
                result = Utilities.MakeListChoiceDialog("What type of Story Object would you like to create?", editChoices, this);
            else
            {
                result = 0;
            }
            if(result < 0)
            {
                return;
            }
            else if(result == 0) //Author Goal
            {
                List<string> choiceConstraints = new List<string>();
                foreach (AuthorGoal goal in _currentStoryData.AuthorGoals)
                {
                    choiceConstraints.Add(goal.Name);

                }
                string newName = Utilities.MakeConstrainedTextDialog(
                    "Please enter a name for your new Author Goal:",
                    "That name is already in use by another Author Goal.",
                    choiceConstraints, this);

                if(newName == null)
                {
                    return;
                }

                AuthorGoal newAuthGoal = new AuthorGoal(newName, _currentStoryData);
                _currentStoryData.AuthorGoals.Add(newAuthGoal);
                //If first author goal, set it to the start goal
                if (_currentStoryData.AuthorGoals.Count == 1)
                {
                    _currentStoryData.StartGoalId = newAuthGoal.Id;
                }
                clearDataElements();
                dataBindWindow();

                Window newWin = new WindowAuthorGoalEditor(newAuthGoal, _currentStoryData);
                newWin.Owner = this;
                newWin.ShowDialog();
                clearDataElements();
                dataBindWindow();
            }
            else if(result == 1) //Plot Fragment
            {
                //Get parent author goal
                editChoices.Clear();
                foreach (AuthorGoal goal in _currentStoryData.AuthorGoals)
                {

                    editChoices.Add(goal.Description);
                }

                result = Utilities.MakeListChoiceDialog("Choose the Author Goal for this new Plot Fragment:", editChoices, this);
                if(result < 0)
                {
                    return;
                }

                AuthorGoal parentAuthorGoal = _currentStoryData.AuthorGoals[result];

                // Get name
                List<string> choiceConstraints = new List<string>();

                foreach (PlotFragment frag in parentAuthorGoal.PlotFragments)
                {
                    choiceConstraints.Add(frag.Name);

                }
                string newName = Utilities.MakeConstrainedTextDialog(
                    "Please enter a name for your new Plot Fragment:",
                    "That name is already in use by another Plot Fragment.",
                    choiceConstraints, this);

                if(newName == null)
                {
                    return;
                }

                PlotFragment newPlotFrag = new PlotFragment(newName, parentAuthorGoal.Id, _currentStoryData);
                parentAuthorGoal.PlotFragments.Add(newPlotFrag);

                clearDataElements();
                dataBindWindow();

                Window newWin = new WindowPlotFragmentEditor(newPlotFrag, _currentStoryData);
                newWin.Owner = this;
                newWin.ShowDialog();
                clearDataElements();
                dataBindWindow();

            }
        }
Exemplo n.º 19
0
        private static void measureGoalDepth(StoryData inputStory, Stack goalStack, Hashtable goalTable, AuthorGoal currentGoal, ArrayList pathDepths, int currentDepth)
        {
            if(currentDepth > 50)
            {
                return;
            }
            if(goalStack.Contains(currentGoal))
            {
                //recursion occurring, end search
                return;
            }
            if(currentGoal == null)
            {
                //Null author goal

                pathDepths.Add(currentDepth);
                return;

            }

            if(currentGoal.PlotFragments.Count == 0)
            {
                //No plot fragment for subgoal, count as leaf of tree

                pathDepths.Add(currentDepth);
                return;
            }

            foreach (PlotFragment f in currentGoal.PlotFragments)
            {
                int numSubgoals = 0;
                foreach(Action a in f.Actions)
                {

                    if(a is ActionSubgoal)
                    {
                        numSubgoals++;
                        AuthorGoal goalToSearch = (AuthorGoal)goalTable[((ActionSubgoal)a).SubGoalId];
                        goalStack.Push(currentGoal);
                        measureGoalDepth(inputStory,goalStack, goalTable, goalToSearch, pathDepths, currentDepth + 1);
                        goalStack.Pop();

                    }
                }
                if (numSubgoals == 0)
                {
                    //No subgoaling occured, so this path is a leaf of the tree
                    pathDepths.Add(currentDepth);
                }
            }
        }
Exemplo n.º 20
0
        public static void SaveAuthorGoalParams(AuthorGoal currGoal, List<Parameter> newList, StoryData world)
        {
            List<Parameter> properList = new List<Parameter>();

            foreach (Parameter newParam in newList)
            {
               // Parameter oldParam = currGoal.getParameterByTypeId(newParam.TypeId);
               // if (oldParam == null)
               // {

                Parameter convertedParam = new Parameter(newParam, world);

                Parameter oldParam = currGoal.findParameterByName(newParam.Name);
                if ((oldParam != null) && (oldParam.Type == newParam.Type))
                {
                    convertedParam.Value = oldParam.Value;
                }

                properList.Add(convertedParam);

                  //  properList.Add(newParam);

               // }
               // else
               // {
                   // oldParam.Name = newParam.Name;
                   // oldParam.Type = newParam.Type;
                    //properList.Add(oldParam);
                //}
            }
            currGoal.Parameters = properList;
        }
        private void btEditAction_Click(object sender, RoutedEventArgs e)
        {
            Object itemToEdit = actionsDataGrid.SelectedItem;

            if ((itemToEdit == null) || !(itemToEdit is Action))
            {
                return;
            }


            if (itemToEdit.GetType() == typeof(ActionSubgoal))
            {
                AuthorGoal subGoal = _currentStoryData.findAuthorGoalById(((ActionSubgoal)itemToEdit).SubGoalId);
                if (subGoal == null)
                {
                    Utilities.MakeErrorDialog("This Pursue Subgoal Action refers to an Author Goal that no longer exists. You cannot edit its contents. Please delete it in order to generate a story.", this);
                    return;
                }
                else
                {
                    Window newWin = new WindowActionSubgoalEditor(false, _currentEntity, (ActionSubgoal)itemToEdit, _currentStoryData);
                    newWin.Owner = this;
                    newWin.ShowDialog();
                }
            }
            else if (itemToEdit.GetType() == typeof(ActionEditObject))
            {
                UInt64 editObjTypeId = ((ActionEditObject)itemToEdit).ObjectTypeId;


                if ((editObjTypeId == _currentStoryData.CharTypeId) || (editObjTypeId == _currentStoryData.EnvTypeId))
                {
                }
                else
                {
                    PlotPointType currType = _currentStoryData.findPlotPointTypeById(editObjTypeId);
                    if (currType == null)
                    {
                        //Very bad - precondition statement has no associated type. The user
                        //is not allowed to edit this, and must delete it
                        Utilities.MakeErrorDialog("This Edit Plot Point Action refers to a Plot Point Type that no longer exists. You cannot edit its contents. Please delete it in order to generate a story.", this);
                        return;
                    }
                }

                Window newWin = new WindowActionEditEntity(_currentEntity, (ActionEditObject)itemToEdit, _currentStoryData);
                newWin.Owner = this;
                newWin.ShowDialog();
            }
            else if (itemToEdit.GetType() == typeof(ActionTextOutput))
            {
                Window newWin = new WindowActionTextOutput(_currentEntity, (ActionTextOutput)itemToEdit);
                newWin.Owner = this;
                newWin.ShowDialog();
            }
            else if (itemToEdit.GetType() == typeof(ActionCalculation))
            {
                Window newWin = new WindowActionCalculationEditor(_currentEntity, (ActionCalculation)itemToEdit, _currentStoryData);
                newWin.Owner = this;
                newWin.ShowDialog();
            }
            else if (itemToEdit.GetType() == typeof(ActionCreatePlotPoint))
            {
                if (null == _currentStoryData.findPlotPointTypeById(((ActionCreatePlotPoint)itemToEdit).NewPlotPoint.TypeId))
                {
                    //Very bad - precondition statement has no associated type. The user
                    //is not allowed to edit this, and must delete it
                    Utilities.MakeErrorDialog("This Create Plot Point Action refers to a Plot Point Type that no longer exists. You cannot edit its contents. Please delete it in order to generate a story.", this);
                    return;
                }

                Window newWin = new WindowPlotPointEditor(((ActionCreatePlotPoint)itemToEdit).NewPlotPoint, _currentStoryData);
                newWin.Owner = this;
                newWin.ShowDialog();
            }
            else if (itemToEdit.GetType() == typeof(ActionCreateEnvironment))
            {
                Window newWin = new WindowEnvironmentEditor(((ActionCreateEnvironment)itemToEdit).NewEnvironment, _currentStoryData);
                newWin.Owner = this;
                newWin.ShowDialog();
            }
            else if (itemToEdit.GetType() == typeof(ActionCreateCharacter))
            {
                Window newWin = new WindowCharacterEditor(((ActionCreateCharacter)itemToEdit).NewCharacter, _currentStoryData);
                newWin.Owner = this;
                newWin.ShowDialog();
            }
            else if (itemToEdit.GetType() == typeof(ActionDeleteEntity)) //Edit an object deletion action
            {
                ActionDeleteEntity deletionAction = (ActionDeleteEntity)itemToEdit;

                if (deletionAction.TypeId == _currentStoryData.CharTypeId) //Edit char deletion
                {
                    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;
                    }

                    deletionAction.VariableName = deleteObjectChoices[resultChooseDeletionTarget];
                }
                else if (deletionAction.TypeId == _currentStoryData.EnvTypeId) //Edit environment deletion
                {
                    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;
                    }

                    deletionAction.VariableName = deleteObjectChoices[resultChooseDeletionTarget];
                }
                else //Edit some plot point type deletion
                {
                    PlotPointType currType = _currentStoryData.findPlotPointTypeById(deletionAction.TypeId);

                    if (currType == null)
                    {
                        Utilities.MakeErrorDialog("This Delete Plot Point Action refers to a Plot Point Type that no longer exists. You cannot edit its contents. Please delete it in order to generate a story.", this);
                        return;
                    }
                    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;
                    }

                    deletionAction.VariableName = deleteObjectChoices[resultChooseDeletionTarget];
                }
            }



            clearDataBindings();
            dataBind();
        }
Exemplo n.º 22
0
        private void btGoalFragNew_Click(object sender, RoutedEventArgs e)
        {
            List <string> editChoices = new List <string>();

            editChoices.Add("Author Goal");
            editChoices.Add("Plot Fragment");

            int result = -1;

            if (_currentStoryData.AuthorGoals.Count > 0)
            {
                result = Utilities.MakeListChoiceDialog("What type of Story Object would you like to create?", editChoices, this);
            }
            else
            {
                result = 0;
            }
            if (result < 0)
            {
                return;
            }
            else if (result == 0) //Author Goal
            {
                List <string> choiceConstraints = new List <string>();
                foreach (AuthorGoal goal in _currentStoryData.AuthorGoals)
                {
                    choiceConstraints.Add(goal.Name);
                }
                string newName = Utilities.MakeConstrainedTextDialog(
                    "Please enter a name for your new Author Goal:",
                    "That name is already in use by another Author Goal.",
                    choiceConstraints, this);

                if (newName == null)
                {
                    return;
                }

                AuthorGoal newAuthGoal = new AuthorGoal(newName, _currentStoryData);
                _currentStoryData.AuthorGoals.Add(newAuthGoal);
                //If first author goal, set it to the start goal
                if (_currentStoryData.AuthorGoals.Count == 1)
                {
                    _currentStoryData.StartGoalId = newAuthGoal.Id;
                }
                clearDataElements();
                dataBindWindow();

                Window newWin = new WindowAuthorGoalEditor(newAuthGoal, _currentStoryData);
                newWin.Owner = this;
                newWin.ShowDialog();
                clearDataElements();
                dataBindWindow();
            }
            else if (result == 1) //Plot Fragment
            {
                //Get parent author goal
                editChoices.Clear();
                foreach (AuthorGoal goal in _currentStoryData.AuthorGoals)
                {
                    editChoices.Add(goal.Description);
                }

                result = Utilities.MakeListChoiceDialog("Choose the Author Goal for this new Plot Fragment:", editChoices, this);
                if (result < 0)
                {
                    return;
                }

                AuthorGoal parentAuthorGoal = _currentStoryData.AuthorGoals[result];

                // Get name
                List <string> choiceConstraints = new List <string>();

                foreach (PlotFragment frag in parentAuthorGoal.PlotFragments)
                {
                    choiceConstraints.Add(frag.Name);
                }
                string newName = Utilities.MakeConstrainedTextDialog(
                    "Please enter a name for your new Plot Fragment:",
                    "That name is already in use by another Plot Fragment.",
                    choiceConstraints, this);

                if (newName == null)
                {
                    return;
                }


                PlotFragment newPlotFrag = new PlotFragment(newName, parentAuthorGoal.Id, _currentStoryData);
                parentAuthorGoal.PlotFragments.Add(newPlotFrag);

                clearDataElements();
                dataBindWindow();

                Window newWin = new WindowPlotFragmentEditor(newPlotFrag, _currentStoryData);
                newWin.Owner = this;
                newWin.ShowDialog();
                clearDataElements();
                dataBindWindow();
            }
        }
        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();
        }