예제 #1
0
 public TraitConstraint(RelationshipConstraint cons, StoryData world) :
     base(cons.ParentPlotFragmentId, cons.ParentPreconditionStatementId, cons.AllowedToSave, cons.MatchingEntityTypeId, world)
 {
     _constraintType  = cons.ConstraintType;
     _comparisonValue = (Parameter)cons.ComparisonValue.Clone();
     _saveAttribute   = cons.ContainsSavedVariable;
     _savedVariable   = (Trait)cons.SavedVariable.Clone();
 }
예제 #2
0
 public TraitConstraint(RelationshipConstraint cons, StoryData world)
     : base(cons.ParentPlotFragmentId, cons.ParentPreconditionStatementId, cons.AllowedToSave, cons.MatchingEntityTypeId, world)
 {
     _constraintType = cons.ConstraintType;
     _comparisonValue = (Parameter)cons.ComparisonValue.Clone();
     _saveAttribute = cons.ContainsSavedVariable;
     _savedVariable = (Trait)cons.SavedVariable.Clone();
 }
        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
            RelationshipConstraint newClone = (RelationshipConstraint)MemberwiseClone();

            newClone.Id = StoryWorldDataProvider.getStoryData().getNewId();

            newClone.ComparisonValue = (Parameter)_comparisonValue.Clone();
            newClone.SavedVariable   = (Trait)_savedVariable.Clone();


            //Make a new unique variable name
            if (newClone.ContainsSavedVariable)
            {
                string newName    = newClone.SavedVariable.Name;
                int    cloneCount = 1;

                Action        nullAction = null;
                List <string> prevVars   = StoryWorldDataProvider.getStoryData().findPlotFragmentById(_parentPlotFragmentId).getAllPreviouslyBoundVariableNames(nullAction, true);



                while (prevVars.Contains(newName))
                {
                    newName = newClone.SavedVariable.Name + cloneCount.ToString();
                    cloneCount++;
                }

                newClone.SavedVariable.Name = newName;
            }


            return(newClone);
        }
        private void comboBoxTraitRelationship_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (_currentlyDataBinding) return;

            if (comboBoxTraitRelationship.SelectedIndex < 0) { return; }

            //First check for no changes

            if (
                (_currentlySelectedConstraint is TraitConstraint) &&
                (comboBoxTraitRelationship.SelectedIndex == 0)
                )
            {
                return;
            }
            else if (
                (_currentlySelectedConstraint is RelationshipConstraint) &&
                (((RelationshipConstraint)_currentlySelectedConstraint).TargetNameMode == true) &&
                (comboBoxTraitRelationship.SelectedIndex == 1)
                )
            {
                return;
            }
            else if (
                (_currentlySelectedConstraint is RelationshipConstraint) &&
                (((RelationshipConstraint)_currentlySelectedConstraint).TargetNameMode == false) &&
                (comboBoxTraitRelationship.SelectedIndex == 2)
                )
            {
                return;
            }

               if(comboBoxTraitRelationship.SelectedIndex == 0) //Trait type constraint
               {
                if (_currentlySelectedConstraint is RelationshipConstraint)
                {
                    //convert relationship constraint to trait constraint
                    TraitConstraint newCons = new TraitConstraint((RelationshipConstraint)_currentlySelectedConstraint, _currentStoryData);
                    newCons.ComparisonValue.ValueIsBoundToVariable = false;

                    if(_editingMode == 0) //characters
                    {
                        List<Character> globalChars = Utilities.getGlobalCharacterList(_currentStoryData);
                        newCons.ComparisonValue.Name = globalChars[0].Traits[0].Name;
                        newCons.ComparisonValue.Type = globalChars[0].Traits[0].Type;
                        newCons.SavedVariable.Type = globalChars[0].Traits[0].Type;
                    }
                    else if(_editingMode == 1) //environments
                    {
                        List<Environment> globalEnv = Utilities.getGlobalEnvironmentList(_currentStoryData);
                        newCons.ComparisonValue.Name = globalEnv[0].Traits[0].Name;
                        newCons.ComparisonValue.Type = globalEnv[0].Traits[0].Type;
                        newCons.SavedVariable.Type = globalEnv[0].Traits[0].Type;
                    }
                    else
                    {
                        newCons.ComparisonValue.Name = _ppType.Traits[0].Name;
                        newCons.ComparisonValue.Type = _ppType.Traits[0].Type;
                        newCons.SavedVariable.Type = _ppType.Traits[0].Type;
                    }

                    // Replace constraint in the constraint list
                    _currentEntity.Constraints[
                        _currentEntity.Constraints.IndexOf(_currentlySelectedConstraint)]
                         = newCons;
                    clearDataElements();
                    dataBind();
                    constraintDataGrid.SelectedItem = newCons;
                    constraintDataGrid_MouseUp(null, null);

                }
               }
               else if ((comboBoxTraitRelationship.SelectedIndex == 1) || (comboBoxTraitRelationship.SelectedIndex == 2)) //Relationship type constraint
               {
               if (_currentlySelectedConstraint is TraitConstraint)
               {
                   //convert trait constraint to rel constraint
                    RelationshipConstraint newCons = new RelationshipConstraint((TraitConstraint)_currentlySelectedConstraint, _currentStoryData);
                    if(_editingMode == 0) //characters
                    {
                        List<Character> globalChars = Utilities.getGlobalCharacterList(_currentStoryData);
                        newCons.ComparisonValue.Name = globalChars[0].Relationships[0].Name;
                        newCons.ComparisonValue.ValueIsBoundToVariable = false;
                        if(comboBoxTraitRelationship.SelectedIndex == 1)
                        {
                            newCons.ComparisonValue.Type = TraitDataType.Text;
                            newCons.SavedVariable.Type = TraitDataType.Text;
                            newCons.TargetNameMode = true; // relationship target name

                        }
                        else
                        {
                            newCons.ComparisonValue.Type = TraitDataType.Number;
                            newCons.SavedVariable.Type = TraitDataType.Number;
                            newCons.TargetNameMode = false; // relationship strength
                        }
                    }
                    else if(_editingMode == 1) //environments
                    {
                        List<Environment> globalEnv = Utilities.getGlobalEnvironmentList(_currentStoryData);
                        newCons.ComparisonValue.Name = globalEnv[0].Relationships[0].Name;
                        newCons.ComparisonValue.ValueIsBoundToVariable = false;
                        if(comboBoxTraitRelationship.SelectedIndex == 1)
                        {
                            newCons.ComparisonValue.Type = TraitDataType.Text;
                            newCons.SavedVariable.Type = TraitDataType.Text;
                            newCons.TargetNameMode = true; // relationship target name

                        }
                        else
                        {

                            newCons.ComparisonValue.Type = TraitDataType.Number;
                            newCons.SavedVariable.Type = TraitDataType.Number;
                            newCons.TargetNameMode = false; // relationship strength
                        }
                    }

                    // Replace constraint in the constraint list
                    _currentEntity.Constraints[
                        _currentEntity.Constraints.IndexOf(_currentlySelectedConstraint)]
                         = newCons;
                    clearDataElements();
                    dataBind();
                    constraintDataGrid.SelectedItem = newCons;
                    constraintDataGrid_MouseUp(null, null);

               }
               else if (
                        ((RelationshipConstraint)_currentlySelectedConstraint).TargetNameMode &&
                        (comboBoxTraitRelationship.SelectedIndex == 2)
                        )
               {
                   //Convert relationship target name constraint to strength constraint
                   ((RelationshipConstraint)_currentlySelectedConstraint).TargetNameMode = false;
                   ((RelationshipConstraint)_currentlySelectedConstraint).ComparisonValue.Type = TraitDataType.Number;
                   ((RelationshipConstraint)_currentlySelectedConstraint).SavedVariable.Type = TraitDataType.Number;
                   ((RelationshipConstraint)_currentlySelectedConstraint).ComparisonValue.ValueIsBoundToVariable = false;
                   //((RelationshipConstraint)_currentlySelectedConstraint).ContainsSavedVariable = false;
                   //((RelationshipConstraint)_currentlySelectedConstraint).ConstraintType = ConstraintComparisonType.Equals;
                   //((RelationshipConstraint)_currentlySelectedConstraint).SavedVariable.Name = "";
                   clearDataElements();
                   dataBind();
                   constraintDataGrid.SelectedItem = _currentlySelectedConstraint;
                   constraintDataGrid_MouseUp(null, null);
               }
               else if (
                        ((!(((RelationshipConstraint)_currentlySelectedConstraint).TargetNameMode) )) &&
                        (comboBoxTraitRelationship.SelectedIndex == 1)
                        )
               {
                   //Convert relationship strength constraint to target name constraint
                   ((RelationshipConstraint)_currentlySelectedConstraint).TargetNameMode = true;
                   ((RelationshipConstraint)_currentlySelectedConstraint).ComparisonValue.Type = TraitDataType.Text;
                   ((RelationshipConstraint)_currentlySelectedConstraint).SavedVariable.Type = TraitDataType.Text;
                   //((RelationshipConstraint)_currentlySelectedConstraint).ContainsSavedVariable = false;
                   ((RelationshipConstraint)_currentlySelectedConstraint).ComparisonValue.ValueIsBoundToVariable = false;
                   //((RelationshipConstraint)_currentlySelectedConstraint).ConstraintType = ConstraintComparisonType.Equals;
                   //((RelationshipConstraint)_currentlySelectedConstraint).SavedVariable.Name = "";
                   clearDataElements();
                   dataBind();
                   constraintDataGrid.SelectedItem = _currentlySelectedConstraint;
                   constraintDataGrid_MouseUp(null, null);
               }

               }
        }
        private void comboBoxTraitRelationship_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (_currentlyDataBinding)
            {
                return;
            }

            if (comboBoxTraitRelationship.SelectedIndex < 0)
            {
                return;
            }


            //First check for no changes

            if (
                (_currentlySelectedConstraint is TraitConstraint) &&
                (comboBoxTraitRelationship.SelectedIndex == 0)
                )
            {
                return;
            }
            else if (
                (_currentlySelectedConstraint is RelationshipConstraint) &&
                (((RelationshipConstraint)_currentlySelectedConstraint).TargetNameMode == true) &&
                (comboBoxTraitRelationship.SelectedIndex == 1)
                )
            {
                return;
            }
            else if (
                (_currentlySelectedConstraint is RelationshipConstraint) &&
                (((RelationshipConstraint)_currentlySelectedConstraint).TargetNameMode == false) &&
                (comboBoxTraitRelationship.SelectedIndex == 2)
                )
            {
                return;
            }



            if (comboBoxTraitRelationship.SelectedIndex == 0) //Trait type constraint
            {
                if (_currentlySelectedConstraint is RelationshipConstraint)
                {
                    //convert relationship constraint to trait constraint
                    TraitConstraint newCons = new TraitConstraint((RelationshipConstraint)_currentlySelectedConstraint, _currentStoryData);
                    newCons.ComparisonValue.ValueIsBoundToVariable = false;

                    if (_editingMode == 0) //characters
                    {
                        List <Character> globalChars = Utilities.getGlobalCharacterList(_currentStoryData);
                        newCons.ComparisonValue.Name = globalChars[0].Traits[0].Name;
                        newCons.ComparisonValue.Type = globalChars[0].Traits[0].Type;
                        newCons.SavedVariable.Type   = globalChars[0].Traits[0].Type;
                    }
                    else if (_editingMode == 1) //environments
                    {
                        List <Environment> globalEnv = Utilities.getGlobalEnvironmentList(_currentStoryData);
                        newCons.ComparisonValue.Name = globalEnv[0].Traits[0].Name;
                        newCons.ComparisonValue.Type = globalEnv[0].Traits[0].Type;
                        newCons.SavedVariable.Type   = globalEnv[0].Traits[0].Type;
                    }
                    else
                    {
                        newCons.ComparisonValue.Name = _ppType.Traits[0].Name;
                        newCons.ComparisonValue.Type = _ppType.Traits[0].Type;
                        newCons.SavedVariable.Type   = _ppType.Traits[0].Type;
                    }

                    // Replace constraint in the constraint list
                    _currentEntity.Constraints[
                        _currentEntity.Constraints.IndexOf(_currentlySelectedConstraint)]
                        = newCons;
                    clearDataElements();
                    dataBind();
                    constraintDataGrid.SelectedItem = newCons;
                    constraintDataGrid_MouseUp(null, null);
                }
            }
            else if ((comboBoxTraitRelationship.SelectedIndex == 1) || (comboBoxTraitRelationship.SelectedIndex == 2)) //Relationship type constraint
            {
                if (_currentlySelectedConstraint is TraitConstraint)
                {
                    //convert trait constraint to rel constraint
                    RelationshipConstraint newCons = new RelationshipConstraint((TraitConstraint)_currentlySelectedConstraint, _currentStoryData);
                    if (_editingMode == 0) //characters
                    {
                        List <Character> globalChars = Utilities.getGlobalCharacterList(_currentStoryData);
                        newCons.ComparisonValue.Name = globalChars[0].Relationships[0].Name;
                        newCons.ComparisonValue.ValueIsBoundToVariable = false;
                        if (comboBoxTraitRelationship.SelectedIndex == 1)
                        {
                            newCons.ComparisonValue.Type = TraitDataType.Text;
                            newCons.SavedVariable.Type   = TraitDataType.Text;
                            newCons.TargetNameMode       = true; // relationship target name
                        }
                        else
                        {
                            newCons.ComparisonValue.Type = TraitDataType.Number;
                            newCons.SavedVariable.Type   = TraitDataType.Number;
                            newCons.TargetNameMode       = false; // relationship strength
                        }
                    }
                    else if (_editingMode == 1) //environments
                    {
                        List <Environment> globalEnv = Utilities.getGlobalEnvironmentList(_currentStoryData);
                        newCons.ComparisonValue.Name = globalEnv[0].Relationships[0].Name;
                        newCons.ComparisonValue.ValueIsBoundToVariable = false;
                        if (comboBoxTraitRelationship.SelectedIndex == 1)
                        {
                            newCons.ComparisonValue.Type = TraitDataType.Text;
                            newCons.SavedVariable.Type   = TraitDataType.Text;
                            newCons.TargetNameMode       = true; // relationship target name
                        }
                        else
                        {
                            newCons.ComparisonValue.Type = TraitDataType.Number;
                            newCons.SavedVariable.Type   = TraitDataType.Number;
                            newCons.TargetNameMode       = false; // relationship strength
                        }
                    }


                    // Replace constraint in the constraint list
                    _currentEntity.Constraints[
                        _currentEntity.Constraints.IndexOf(_currentlySelectedConstraint)]
                        = newCons;
                    clearDataElements();
                    dataBind();
                    constraintDataGrid.SelectedItem = newCons;
                    constraintDataGrid_MouseUp(null, null);
                }
                else if (
                    ((RelationshipConstraint)_currentlySelectedConstraint).TargetNameMode &&
                    (comboBoxTraitRelationship.SelectedIndex == 2)
                    )
                {
                    //Convert relationship target name constraint to strength constraint
                    ((RelationshipConstraint)_currentlySelectedConstraint).TargetNameMode       = false;
                    ((RelationshipConstraint)_currentlySelectedConstraint).ComparisonValue.Type = TraitDataType.Number;
                    ((RelationshipConstraint)_currentlySelectedConstraint).SavedVariable.Type   = TraitDataType.Number;
                    ((RelationshipConstraint)_currentlySelectedConstraint).ComparisonValue.ValueIsBoundToVariable = false;
                    //((RelationshipConstraint)_currentlySelectedConstraint).ContainsSavedVariable = false;
                    //((RelationshipConstraint)_currentlySelectedConstraint).ConstraintType = ConstraintComparisonType.Equals;
                    //((RelationshipConstraint)_currentlySelectedConstraint).SavedVariable.Name = "";
                    clearDataElements();
                    dataBind();
                    constraintDataGrid.SelectedItem = _currentlySelectedConstraint;
                    constraintDataGrid_MouseUp(null, null);
                }
                else if (
                    ((!(((RelationshipConstraint)_currentlySelectedConstraint).TargetNameMode))) &&
                    (comboBoxTraitRelationship.SelectedIndex == 1)
                    )
                {
                    //Convert relationship strength constraint to target name constraint
                    ((RelationshipConstraint)_currentlySelectedConstraint).TargetNameMode       = true;
                    ((RelationshipConstraint)_currentlySelectedConstraint).ComparisonValue.Type = TraitDataType.Text;
                    ((RelationshipConstraint)_currentlySelectedConstraint).SavedVariable.Type   = TraitDataType.Text;
                    //((RelationshipConstraint)_currentlySelectedConstraint).ContainsSavedVariable = false;
                    ((RelationshipConstraint)_currentlySelectedConstraint).ComparisonValue.ValueIsBoundToVariable = false;
                    //((RelationshipConstraint)_currentlySelectedConstraint).ConstraintType = ConstraintComparisonType.Equals;
                    //((RelationshipConstraint)_currentlySelectedConstraint).SavedVariable.Name = "";
                    clearDataElements();
                    dataBind();
                    constraintDataGrid.SelectedItem = _currentlySelectedConstraint;
                    constraintDataGrid_MouseUp(null, null);
                }
            }
        }