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);
        }
Exemple #2
0
        private void Constructor(string name, TraitDataType type, Object Value, UInt64 traitTypeId, StoryData world)
        {
            if (world == null)
            {
                _traitId = 0;
            }
            else
            {
                _traitId = world.getNewId();
            }
            _traitTypeId = traitTypeId;

            //default values of the traits, just in case the given value
            //is not valid
            _name         = name;
            _type         = type;
            _booleanValue = false;
            _numValue     = 0.0;
            _textValue    = "";

            Type valType = Value.GetType();

            if (valType == typeof(Boolean))
            {
                _booleanValue = (Boolean)Value;
            }
            else if (valType == typeof(Double))
            {
                _numValue = (Double)Value;
            }
            else if (valType == typeof(String))
            {
                _textValue = (String)Value;
            }
        }
        public List <Trait> getPreviouslyBoundPrimitiveVariables(TraitDataType variableType, bool allTypes, Action currentAction)
        {
            //Get bound variable names in parameters and preconditions by passing
            //a non-existent PreconditionStatement reference (null) to the other variable
            //name collection function

            PreconditionStatement nullPrecStatement = null;
            List <Trait>          varsToReturn      = getPreviouslyBoundPrimitiveVariables(variableType, allTypes, nullPrecStatement);



            foreach (Action action in _actions)
            {
                if (action == currentAction)
                {
                    //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(action.getBoundPrimitiveVariables(variableType, allTypes));
                }
            }

            return(varsToReturn);
        }
        public List <Trait> getPreviouslyBoundPrimitiveVariables(TraitDataType variableType, bool allTypes, Constraint currentConstraint)
        {
            PlotFragment parentFrag   = StoryWorldDataProvider.getStoryData().findPlotFragmentById(_parentPlotFragmentId);
            List <Trait> varsToReturn = parentFrag.getPreviouslyBoundPrimitiveVariables(variableType, allTypes, this);


            foreach (Constraint cons in Constraints)
            {
                if (cons == currentConstraint)
                {
                    //We have found where to stop looking, can now return variable list
                    return(varsToReturn);
                }
                else if (cons.ContainsSavedVariable)
                {
                    if (allTypes || (cons.SavedVariable.Type == variableType))
                    {
                        //Add the variable names bound in this constraint to the running list
                        varsToReturn.Add(cons.SavedVariable);
                    }
                }
            }

            return(varsToReturn);
        }
        //Return ordered list of bound variable names
        virtual public List <Trait> getBoundPrimitiveVariables(TraitDataType type, bool allTypes)
        {
            List <Trait> newVars = new List <Trait>();

            foreach (Constraint cons in _constraints)
            {
                newVars.AddRange(cons.getBoundPrimitiveVariables(type, allTypes));
            }

            return(newVars);
        }
        private void saveData()
        {
            //Save value/variable name
            if (_currentlySelectedConstraint == null)
            {
                return;
            }

            if (comboBoxTraitRelationship.SelectedIndex == 0)
            {
                TraitDataType type = _currentlySelectedConstraint.ComparisonValue.Type;

                if (_currentlySelectedConstraint.ComparisonValue.ValueIsBoundToVariable)
                {
                    _currentlySelectedConstraint.ComparisonValue.LiteralValueOrBoundVarName = ((Trait)comboChoiceVariables.SelectedItem).Name;
                }
                else if (type == TraitDataType.Number)
                {
                    _currentlySelectedConstraint.ComparisonValue.LiteralValueOrBoundVarName = txtBoxNumberInput.Value;
                }
                else if (type == TraitDataType.Text)
                {
                    _currentlySelectedConstraint.ComparisonValue.LiteralValueOrBoundVarName = textBoxTextInput.Text;
                }
                else if (type == TraitDataType.TrueFalse)
                {
                    _currentlySelectedConstraint.ComparisonValue.LiteralValueOrBoundVarName = (comboBoxTrueFalse.SelectedIndex == 0);
                }
            }
            else if (comboBoxTraitRelationship.SelectedIndex == 1) //relationship target name
            {
                if (_currentlySelectedConstraint.ComparisonValue.ValueIsBoundToVariable)
                {
                    _currentlySelectedConstraint.ComparisonValue.LiteralValueOrBoundVarName = ((Trait)comboChoiceVariables.SelectedItem).Name;
                }

                else //get literal text value
                {
                    _currentlySelectedConstraint.ComparisonValue.LiteralValueOrBoundVarName = textBoxTextInput.Text;
                }
            }
            else if (comboBoxTraitRelationship.SelectedIndex == 2) //relationship strength
            {
                if (_currentlySelectedConstraint.ComparisonValue.ValueIsBoundToVariable)
                {
                    _currentlySelectedConstraint.ComparisonValue.LiteralValueOrBoundVarName = ((Trait)comboChoiceVariables.SelectedItem).Name;
                }

                else //get literal number value
                {
                    _currentlySelectedConstraint.ComparisonValue.LiteralValueOrBoundVarName = txtBoxNumberInput.Value;
                }
            }
        }
Exemple #7
0
 //Return ordered list of bound variable names
 virtual public List <Trait> getBoundPrimitiveVariables(TraitDataType type, bool allTypes)
 {
     if (_saveAttribute && (allTypes || (_savedVariable.Type == type)))
     {
         List <Trait> newVarList = new List <Trait>();
         newVarList.Add(_savedVariable);
         return(newVarList);
     }
     else
     {
         return(new List <Trait>());
     }
 }
Exemple #8
0
 //Return ordered list of bound variable names
 override public List <Trait> getBoundPrimitiveVariables(TraitDataType type, bool allTypes)
 {
     if (allTypes || (type == TraitDataType.Number))
     {
         List <Trait> varResultList = new List <Trait>();
         varResultList.Add(_resultVar);
         return(varResultList);
     }
     else
     {
         return(new List <Trait>());
     }
 }
Exemple #9
0
        private void saveData()
        {
            //Save trait/rel name and type if necessary
            Object itemSelected = comboBoxSelectTraitRel.SelectedItem;

            if (_currentEntity.Mode == ObjectEditingMode.Trait)
            {
                _currentEntity.NewValue.Name = ((Trait)itemSelected).Name;
                _currentEntity.NewValue.Type = ((Trait)itemSelected).Type;
                _currentEntity.NewValue.ValueIsBoundToVariable = (bool)checkBoxUseVariable.IsChecked;
                TraitDataType type = _currentEntity.NewValue.Type;
                if (_currentEntity.NewValue.ValueIsBoundToVariable)
                {
                    _currentEntity.NewValue.LiteralValueOrBoundVarName = ((Trait)comboChoiceVariables.SelectedItem).Name;
                }
                else if (type == TraitDataType.Number)
                {
                    _currentEntity.NewValue.LiteralValueOrBoundVarName = txtBoxNumberInput.Value;
                }
                else if (type == TraitDataType.Text)
                {
                    _currentEntity.NewValue.LiteralValueOrBoundVarName = textBoxTextInput.Text;
                }
                else if (type == TraitDataType.TrueFalse)
                {
                    _currentEntity.NewValue.LiteralValueOrBoundVarName = (comboBoxTrueFalse.SelectedIndex == 0);
                }
            }
            else if (_currentEntity.Mode == ObjectEditingMode.RelationshipTarget)
            {
                _currentEntity.NewValue.Name  = ((Relationship)itemSelected).Name;
                _currentEntity.NewTarget.Name = ((Relationship)itemSelected).Name;
                _currentEntity.NewTarget.LiteralValueOrBoundVarName = (string)comboChoiceVariables.SelectedItem;
            }
            else if (_currentEntity.Mode == ObjectEditingMode.RelationshipStrength)
            {
                _currentEntity.NewValue.Name  = ((Relationship)itemSelected).Name;
                _currentEntity.NewTarget.Name = ((Relationship)itemSelected).Name;
                _currentEntity.NewValue.ValueIsBoundToVariable = (bool)checkBoxUseVariable.IsChecked;
                if (_currentEntity.NewValue.ValueIsBoundToVariable)
                {
                    _currentEntity.NewValue.LiteralValueOrBoundVarName = ((Trait)comboChoiceVariables.SelectedItem).Name;
                }
                else
                {
                    _currentEntity.NewValue.LiteralValueOrBoundVarName = txtBoxNumberInput.Value;
                }
            }
        }
Exemple #10
0
        public static string TraitDataTypeToString(TraitDataType input)
        {
            switch (input)
            {
            case TraitDataType.Number:
                return(NumberString);

            case TraitDataType.TrueFalse:
                return(TrueFalseString);

            case TraitDataType.Text:
                return(TextString);
            }
            return("");
        }
Exemple #11
0
 public Trait(string name, TraitDataType type, UInt64 traitTypeId, StoryData world)
 {
     switch (type)
     {
         case TraitDataType.TrueFalse:
             Constructor(name, type, false, traitTypeId, world);
             break;
         case TraitDataType.Number:
             Constructor(name, type, 0.0, traitTypeId, world);
             break;
         case TraitDataType.Text:
             Constructor(name, type, "", traitTypeId, world);
             break;
     }
 }
Exemple #12
0
        public Trait(string name, TraitDataType type, UInt64 traitTypeId, StoryData world)
        {
            switch (type)
            {
            case TraitDataType.TrueFalse:
                Constructor(name, type, false, traitTypeId, world);
                break;

            case TraitDataType.Number:
                Constructor(name, type, 0.0, traitTypeId, world);
                break;

            case TraitDataType.Text:
                Constructor(name, type, "", traitTypeId, world);
                break;
            }
        }
        private void ComboBox_DropDownClosed(object sender, EventArgs e)
        {
            //Handle null sender
            if (sender == null)
            {
                return;
            }

            //Handle null selections
            if ((((ComboBox)sender).SelectedItem == null) || (charDataGrid.SelectedItem == null))
            {
                return;
            }

            Trait selectedTrait = (Trait)charDataGrid.SelectedItem;


            //Handle unexpected data type
            if ((((ComboBox)sender).SelectedItem).GetType() != typeof(TraitDataType))
            {
                return;
            }


            TraitDataType selectedType = (TraitDataType)(((ComboBox)sender).SelectedItem);

            if (selectedTrait.Type == selectedType)
            {
                return;
            }


            charDataGrid.ClearValue(DataGridControl.ItemsSourceProperty);
            charDataGrid.Items.Clear();

            selectedTrait.Type = selectedType;

            dataBindWindow();
        }
Exemple #14
0
 public static Parameter findParameterByNameAndType(List <Parameter> inputList, string name, TraitDataType type)
 {
     foreach (Parameter param in inputList)
     {
         if (param.Name.Equals(name) && (param.Type == type))
         {
             return(param);
         }
     }
     return(null);
 }
Exemple #15
0
 public static Trait findTraitByNameAndType(List <Trait> inputList, string name, TraitDataType type)
 {
     foreach (Trait traitItem in inputList)
     {
         if (traitItem.Name.Equals(name) && (traitItem.Type == type))
         {
             return(traitItem);
         }
     }
     return(null);
 }
        private void setupDataInputBoxes(TraitDataType type, bool variable)
        {
            if (variable)
            {
                textBoxTextInput.Visibility     = Visibility.Hidden;
                txtBoxNumberInput.Visibility    = Visibility.Hidden;
                comboBoxTrueFalse.Visibility    = Visibility.Hidden;
                comboChoiceVariables.Visibility = Visibility.Visible;
                List <Trait> prevVars = _parentPlotFragment.getPreviouslyBoundPrimitiveVariables(_currentlySelectedParameter.Type, false, _currentEntity);
                comboChoiceVariables.ClearValue(ComboBox.ItemsSourceProperty);
                comboChoiceVariables.Items.Clear();
                comboChoiceVariables.ItemsSource = prevVars;

                //Find variable in combobox list by name
                int  choiceIndex = 0;
                bool foundVar    = false;
                foreach (Trait traitItem in prevVars)
                {
                    if (traitItem.Name == (string)_currentlySelectedParameter.LiteralValueOrBoundVarName)
                    {
                        foundVar = true;
                        break;
                    }
                    choiceIndex++;
                }
                if (foundVar)
                {
                    comboChoiceVariables.SelectedIndex = choiceIndex;
                }
                else
                {
                    comboChoiceVariables.SelectedIndex = 0;
                }
            }
            else
            {
                if (type == TraitDataType.Text)
                {
                    textBoxTextInput.Visibility = Visibility.Visible;
                    textBoxTextInput.Text       = (string)_currentlySelectedParameter.Value;

                    txtBoxNumberInput.Visibility    = Visibility.Hidden;
                    comboBoxTrueFalse.Visibility    = Visibility.Hidden;
                    comboChoiceVariables.Visibility = Visibility.Hidden;
                }
                else if (type == TraitDataType.Number)
                {
                    textBoxTextInput.Visibility = Visibility.Hidden;

                    txtBoxNumberInput.Visibility    = Visibility.Visible;
                    txtBoxNumberInput.Value         = _currentlySelectedParameter.Value;
                    comboBoxTrueFalse.Visibility    = Visibility.Hidden;
                    comboChoiceVariables.Visibility = Visibility.Hidden;
                }
                else if (type == TraitDataType.TrueFalse)
                {
                    textBoxTextInput.Visibility = Visibility.Hidden;

                    txtBoxNumberInput.Visibility = Visibility.Hidden;

                    comboBoxTrueFalse.Visibility = Visibility.Visible;
                    if ((bool)_currentlySelectedParameter.Value == true)
                    {
                        comboBoxTrueFalse.SelectedIndex = 0;
                    }
                    else
                    {
                        comboBoxTrueFalse.SelectedIndex = 1;
                    }
                    comboChoiceVariables.Visibility = Visibility.Hidden;
                }
            }
        }
        public List<Trait> getPreviouslyBoundPrimitiveVariables(TraitDataType variableType, bool allTypes, Action currentAction)
        {
            //Get bound variable names in parameters and preconditions by passing
            //a non-existent PreconditionStatement reference (null) to the other variable
            //name collection function

            PreconditionStatement nullPrecStatement = null;
            List<Trait> varsToReturn = getPreviouslyBoundPrimitiveVariables(variableType, allTypes, nullPrecStatement);

            foreach (Action action in _actions)
            {
                if (action == currentAction)
                {
                    //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(action.getBoundPrimitiveVariables(variableType, allTypes));
                }
            }

            return varsToReturn;
        }
 //Return ordered list of bound variable names
 public virtual List<Trait> getBoundPrimitiveVariables(TraitDataType type, bool allTypes)
 {
     if(_saveAttribute && (allTypes || (_savedVariable.Type == type)))
     {
         List<Trait> newVarList = new List<Trait>();
         newVarList.Add(_savedVariable);
         return newVarList;
     }
     else
     {
         return new List<Trait>();
     }
 }
Exemple #19
0
 //Return ordered list of bound variable names
 virtual public List <Trait> getBoundPrimitiveVariables(TraitDataType type, bool allTypes)
 {
     //By default, nothing is bound
     return(new List <Trait>());
 }
Exemple #20
0
 public static Parameter findParameterByNameAndType(List<Parameter> inputList, string name, TraitDataType type)
 {
     foreach (Parameter param in inputList)
     {
         if ( param.Name.Equals(name) && (param.Type == type))
         {
             return param;
         }
     }
     return null;
 }
Exemple #21
0
 public static string TraitDataTypeToString(TraitDataType input)
 {
     switch (input)
     {
         case TraitDataType.Number:
             return NumberString;
         case TraitDataType.TrueFalse:
             return TrueFalseString;
         case TraitDataType.Text:
             return TextString;
     }
     return "";
 }
Exemple #22
0
 public Trait(string name, TraitDataType type, Object Value, UInt64 traitTypeId, StoryData world)
 {
     Constructor(name, type, Value, traitTypeId, world);
 }
Exemple #23
0
        private void Constructor(string name, TraitDataType type, Object Value, UInt64 traitTypeId, StoryData world)
        {
            if (world == null)
            {
                _traitId = 0;

            }
            else {
                _traitId = world.getNewId();

            }
            _traitTypeId = traitTypeId;

            //default values of the traits, just in case the given value
            //is not valid
            _name = name;
            _type = type;
            _booleanValue = false;
            _numValue = 0.0;
            _textValue = "";

            Type valType = Value.GetType();

            if (valType == typeof(Boolean))
            {
                _booleanValue = (Boolean)Value;
            }
            else if (valType == typeof(Double))
            {
                _numValue = (Double)Value;
            }
            else if (valType == typeof(String))
            {
                _textValue = (String)Value;
            }
        }
Exemple #24
0
 public Trait(string name, TraitDataType type, Object Value, UInt64 traitTypeId, StoryData world)
 {
     Constructor(name, type, Value, traitTypeId, world);
 }
Exemple #25
0
        private void dataBind()
        {
            _currentlyDataBinding = true;

            switch (_editingMode)
            {
            case 0:
                titleTextBlock.Text = "Edit Character: " + _currentEntity.VariableObjectName;
                break;

            case 1:
                titleTextBlock.Text = "Edit Environment: " + _currentEntity.VariableObjectName;
                break;

            case 2:
                titleTextBlock.Text = "Edit " + _ppType.Description + ": " + _currentEntity.VariableObjectName;
                break;
            }

            //Top combobox
            List <string> attributeOptions = new List <string>();

            attributeOptions.Add("Edit Trait");

            //Only add relationship editors if there relationships that can be edited
            if ((_editingMode == 0) && (Utilities.getGlobalCharacterList(_currentStoryData)[0].Relationships.Count > 0))
            {
                attributeOptions.Add("Edit Relationship Target");
                attributeOptions.Add("Edit Relationship Strength");
            }
            else if ((_editingMode == 1) && (Utilities.getGlobalEnvironmentList(_currentStoryData)[0].Relationships.Count > 0))
            {
                attributeOptions.Add("Edit Relationship Target");
                attributeOptions.Add("Edit Relationship Strength");
            }

            comboBoxTraitRelationship.ClearValue(ComboBox.ItemsSourceProperty);
            comboBoxTraitRelationship.Items.Clear();
            comboBoxTraitRelationship.ItemsSource = attributeOptions;

            switch (_currentEntity.Mode)
            {
            case ObjectEditingMode.Trait:
                comboBoxTraitRelationship.SelectedIndex = 0;
                break;

            case ObjectEditingMode.RelationshipTarget:
                comboBoxTraitRelationship.SelectedIndex = 1;
                break;

            case ObjectEditingMode.RelationshipStrength:
                comboBoxTraitRelationship.SelectedIndex = 2;
                break;
            }

            //Left combobox

            if (_currentEntity.Mode == ObjectEditingMode.Trait)
            {
                if (_editingMode == 0)
                {
                    comboBoxSelectTraitRel.ItemsSource = Utilities.getGlobalCharacterList(_currentStoryData)[0].Traits;
                }
                else if (_editingMode == 1)
                {
                    comboBoxSelectTraitRel.ItemsSource = Utilities.getGlobalEnvironmentList(_currentStoryData)[0].Traits;
                }
                else if (_editingMode == 2)
                {
                    comboBoxSelectTraitRel.ItemsSource = _ppType.Traits;
                }
            }
            else if (_currentEntity.Mode == ObjectEditingMode.RelationshipTarget)
            {
                if (_editingMode == 0)
                {                                       // Using get GLOBAL list (includes not just static characters, but ones
                                                        //created within plot fragments. This way the user doesn't need to
                                                        //have created any static character lists to make plot fragment actions
                                                        //that edit dynamically generated objects
                    comboBoxSelectTraitRel.ItemsSource = Utilities.getGlobalCharacterList(_currentStoryData)[0].Relationships;
                }
                else if (_editingMode == 1)
                {
                    comboBoxSelectTraitRel.ItemsSource = Utilities.getGlobalEnvironmentList(_currentStoryData)[0].Relationships;
                }
            }
            else if (_currentEntity.Mode == ObjectEditingMode.RelationshipStrength)
            {
                if (_editingMode == 0)
                {
                    comboBoxSelectTraitRel.ItemsSource = Utilities.getGlobalCharacterList(_currentStoryData)[0].Relationships;
                }
                else if (_editingMode == 1)
                {
                    comboBoxSelectTraitRel.ItemsSource = Utilities.getGlobalEnvironmentList(_currentStoryData)[0].Relationships;
                }
            }

            //checkbox
            if (_currentEntity.Mode == ObjectEditingMode.Trait)
            {
                checkBoxUseVariable.IsChecked = _currentEntity.NewValue.ValueIsBoundToVariable;
            }
            else if (_currentEntity.Mode == ObjectEditingMode.RelationshipTarget)
            {
                checkBoxUseVariable.IsChecked = _currentEntity.NewTarget.ValueIsBoundToVariable;
            }
            else if (_currentEntity.Mode == ObjectEditingMode.RelationshipStrength)
            {
                checkBoxUseVariable.IsChecked = _currentEntity.NewValue.ValueIsBoundToVariable;
            }

            //Value boxes
            if (_currentEntity.Mode == ObjectEditingMode.Trait)
            {
                if (_currentEntity.NewValue.ValueIsBoundToVariable)
                {
                    textBoxTextInput.Visibility     = Visibility.Hidden;
                    txtBoxNumberInput.Visibility    = Visibility.Hidden;
                    comboBoxTrueFalse.Visibility    = Visibility.Hidden;
                    comboChoiceVariables.Visibility = Visibility.Visible;
                    checkBoxUseVariable.Visibility  = Visibility.Visible;

                    //Data bind variable list
                    comboChoiceVariables.ItemsSource  = _parentPlotFragment.getPreviouslyBoundPrimitiveVariables(_currentEntity.NewValue.Type, false, _currentEntity);
                    comboChoiceVariables.ItemTemplate = this.FindResource("comboBoxDataTemplate") as DataTemplate;
                }
                else
                {
                    TraitDataType type = _currentEntity.NewValue.Type;
                    if (type == TraitDataType.Number)
                    {
                        textBoxTextInput.Visibility     = Visibility.Hidden;
                        txtBoxNumberInput.Visibility    = Visibility.Visible;
                        comboBoxTrueFalse.Visibility    = Visibility.Hidden;
                        comboChoiceVariables.Visibility = Visibility.Hidden;

                        //Only show checkbox if there are actual variables to select
                        List <Trait> varList = _parentPlotFragment.getPreviouslyBoundPrimitiveVariables(_currentEntity.NewValue.Type, false, _currentEntity);
                        if (varList.Count > 0)
                        {
                            checkBoxUseVariable.Visibility = Visibility.Visible;
                        }
                        else
                        {
                            checkBoxUseVariable.Visibility = Visibility.Hidden;
                        }

                        //Data bind Number
                        txtBoxNumberInput.Value = (double)_currentEntity.NewValue.LiteralValueOrBoundVarName;
                    }
                    else if (type == TraitDataType.Text)
                    {
                        textBoxTextInput.Visibility     = Visibility.Visible;
                        txtBoxNumberInput.Visibility    = Visibility.Hidden;
                        comboBoxTrueFalse.Visibility    = Visibility.Hidden;
                        comboChoiceVariables.Visibility = Visibility.Hidden;

                        //Only show checkbox if there are actual variables to select
                        List <Trait> varList = _parentPlotFragment.getPreviouslyBoundPrimitiveVariables(_currentEntity.NewValue.Type, false, _currentEntity);
                        if (varList.Count > 0)
                        {
                            checkBoxUseVariable.Visibility = Visibility.Visible;
                        }
                        else
                        {
                            checkBoxUseVariable.Visibility = Visibility.Hidden;
                        }

                        //Data bind text
                        textBoxTextInput.Text = (string)_currentEntity.NewValue.LiteralValueOrBoundVarName;
                    }
                    else if (type == TraitDataType.TrueFalse)
                    {
                        textBoxTextInput.Visibility     = Visibility.Hidden;
                        txtBoxNumberInput.Visibility    = Visibility.Hidden;
                        comboBoxTrueFalse.Visibility    = Visibility.Visible;
                        comboChoiceVariables.Visibility = Visibility.Hidden;

                        //Only show checkbox if there are actual variables to select
                        List <Trait> varList = _parentPlotFragment.getPreviouslyBoundPrimitiveVariables(_currentEntity.NewValue.Type, false, _currentEntity);
                        if (varList.Count > 0)
                        {
                            checkBoxUseVariable.Visibility = Visibility.Visible;
                        }
                        else
                        {
                            checkBoxUseVariable.Visibility = Visibility.Hidden;
                        }

                        //Data bind true/false
                        comboBoxTrueFalse.SelectedIndex = ((bool)_currentEntity.NewValue.LiteralValueOrBoundVarName) ? 0 : 1;
                    }
                }
            }
            else if (_currentEntity.Mode == ObjectEditingMode.RelationshipTarget)
            {
                textBoxTextInput.Visibility     = Visibility.Hidden;
                txtBoxNumberInput.Visibility    = Visibility.Hidden;
                comboBoxTrueFalse.Visibility    = Visibility.Hidden;
                comboChoiceVariables.Visibility = Visibility.Visible;
                checkBoxUseVariable.Visibility  = Visibility.Hidden;

                //Data bind variable list
                if (_editingMode == 0)
                {
                    comboChoiceVariables.ItemsSource  = _parentPlotFragment.getPreviouslyBoundCharacterVarNames(_currentEntity);
                    comboChoiceVariables.ItemTemplate = this.FindResource("comboBoxDataTemplateString") as DataTemplate;
                }
                else if (_editingMode == 1)
                {
                    comboChoiceVariables.ItemsSource  = _parentPlotFragment.getPreviouslyBoundEnvironmentVarNames(_currentEntity);
                    comboChoiceVariables.ItemTemplate = this.FindResource("comboBoxDataTemplateString") as DataTemplate;
                }
            }
            else if (_currentEntity.Mode == ObjectEditingMode.RelationshipStrength)
            {
                if (_currentEntity.NewValue.ValueIsBoundToVariable)
                {
                    textBoxTextInput.Visibility     = Visibility.Hidden;
                    txtBoxNumberInput.Visibility    = Visibility.Hidden;
                    comboBoxTrueFalse.Visibility    = Visibility.Hidden;
                    comboChoiceVariables.Visibility = Visibility.Visible;
                    checkBoxUseVariable.Visibility  = Visibility.Visible;

                    //Data bind variable list
                    comboChoiceVariables.ItemsSource  = _parentPlotFragment.getPreviouslyBoundPrimitiveVariables(_currentEntity.NewValue.Type, false, _currentEntity);
                    comboChoiceVariables.ItemTemplate = this.FindResource("comboBoxDataTemplate") as DataTemplate;
                }
                else
                {
                    textBoxTextInput.Visibility     = Visibility.Hidden;
                    txtBoxNumberInput.Visibility    = Visibility.Visible;
                    comboBoxTrueFalse.Visibility    = Visibility.Hidden;
                    comboChoiceVariables.Visibility = Visibility.Hidden;

                    //Only show checkbox if there are actual variables to select
                    List <Trait> varList = _parentPlotFragment.getPreviouslyBoundPrimitiveVariables(_currentEntity.NewValue.Type, false, _currentEntity);
                    if (varList.Count > 0)
                    {
                        checkBoxUseVariable.Visibility = Visibility.Visible;
                    }
                    else
                    {
                        checkBoxUseVariable.Visibility = Visibility.Hidden;
                    }
                    //Data bind Number
                    txtBoxNumberInput.Value = (double)_currentEntity.NewValue.LiteralValueOrBoundVarName;
                }
            }



            syncDataBoundComboBoxes();
            _currentlyDataBinding = false;
        }
 //Return ordered list of bound variable names
 public override List<Trait> getBoundPrimitiveVariables(TraitDataType type, bool allTypes)
 {
     if(allTypes || (type == TraitDataType.Number))
     {
         List<Trait> varResultList = new List<Trait>();
         varResultList.Add(_resultVar);
         return varResultList;
     }
     else
     {
         return new List<Trait>();
     }
 }
Exemple #27
0
 public static Trait findTraitByNameAndType(List<Trait> inputList, string name, TraitDataType type)
 {
     foreach (Trait traitItem in inputList)
     {
         if (traitItem.Name.Equals(name) && (traitItem.Type == type))
         {
             return traitItem;
         }
     }
     return null;
 }
        //Return ordered list of bound variable names
        public virtual List<Trait> getBoundPrimitiveVariables(TraitDataType type, bool allTypes)
        {
            List<Trait> newVars = new List<Trait>();

            foreach(Constraint cons in _constraints)
            {
                newVars.AddRange(cons.getBoundPrimitiveVariables(type, allTypes));
            }

            return newVars;
        }
Exemple #29
0
        private bool _valueIsBoundToVariable; //Use text value as variable name instead of literal string

        #endregion Fields

        #region Constructors

        public Parameter(string name, TraitDataType type, bool valueIsBoundToVariable, StoryData world)
            : base(name, type, world.getNewId(), world)
        {
            _valueIsBoundToVariable = valueIsBoundToVariable;
        }
 private static string dataTypeToJavaTypeString(TraitDataType type)
 {
     switch(type)
     {
         case TraitDataType.Number:
             return "float";
         case TraitDataType.Text:
             return "String";
         case TraitDataType.TrueFalse:
             return "boolean";
     }
     return "";
 }
Exemple #31
0
 //Return ordered list of bound variable names
 public virtual List<Trait> getBoundPrimitiveVariables(TraitDataType type, bool allTypes)
 {
     //By default, nothing is bound
     return new List<Trait>();
 }
Exemple #32
0
        private bool _valueIsBoundToVariable; //Use text value as variable name instead of literal string


        public Parameter(string name, TraitDataType type, bool valueIsBoundToVariable, StoryData world) :
            base(name, type, world.getNewId(), world)
        {
            _valueIsBoundToVariable = valueIsBoundToVariable;
        }
        public List<Trait> getPreviouslyBoundPrimitiveVariables(TraitDataType variableType, bool allTypes, Constraint currentConstraint)
        {
            PlotFragment parentFrag = StoryWorldDataProvider.getStoryData().findPlotFragmentById(_parentPlotFragmentId);
            List<Trait> varsToReturn = parentFrag.getPreviouslyBoundPrimitiveVariables(variableType, allTypes, this);

            foreach (Constraint cons in Constraints)
            {
                if (cons == currentConstraint)
                {
                    //We have found where to stop looking, can now return variable list
                    return varsToReturn;
                }
                else if (cons.ContainsSavedVariable)
                {
                    if (allTypes || (cons.SavedVariable.Type == variableType))
                    {
                        //Add the variable names bound in this constraint to the running list
                        varsToReturn.Add(cons.SavedVariable);
                    }

                }
            }

            return varsToReturn;
        }
        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 setupDataInputBoxes(TraitDataType type, bool variable)
        {
            if (variable)
            {
                textBoxTextInput.Visibility = Visibility.Hidden;
                txtBoxNumberInput.Visibility = Visibility.Hidden;
                comboBoxTrueFalse.Visibility = Visibility.Hidden;
                comboChoiceVariables.Visibility = Visibility.Visible;
                List<Trait> prevVars = _parentPlotFragment.getPreviouslyBoundPrimitiveVariables(_currentlySelectedParameter.Type, false, _currentEntity);
                comboChoiceVariables.ClearValue(ComboBox.ItemsSourceProperty);
                comboChoiceVariables.Items.Clear();
                comboChoiceVariables.ItemsSource = prevVars;

                //Find variable in combobox list by name
                int choiceIndex = 0;
                bool foundVar = false;
                foreach(Trait traitItem in prevVars)
                {
                    if(traitItem.Name == (string)_currentlySelectedParameter.LiteralValueOrBoundVarName)
                    {
                        foundVar = true;
                        break;
                    }
                    choiceIndex++;
                }
                if (foundVar)
                {
                    comboChoiceVariables.SelectedIndex = choiceIndex;
                }
                else
                {
                    comboChoiceVariables.SelectedIndex = 0;
                }

            }
            else
            {
                if(type == TraitDataType.Text)
                {
                    textBoxTextInput.Visibility = Visibility.Visible;
                    textBoxTextInput.Text = (string)_currentlySelectedParameter.Value;

                    txtBoxNumberInput.Visibility = Visibility.Hidden;
                    comboBoxTrueFalse.Visibility = Visibility.Hidden;
                    comboChoiceVariables.Visibility = Visibility.Hidden;

                }
                else if (type == TraitDataType.Number)
                {
                    textBoxTextInput.Visibility = Visibility.Hidden;

                    txtBoxNumberInput.Visibility = Visibility.Visible;
                    txtBoxNumberInput.Value = _currentlySelectedParameter.Value;
                    comboBoxTrueFalse.Visibility = Visibility.Hidden;
                    comboChoiceVariables.Visibility = Visibility.Hidden;
                }
                else if (type == TraitDataType.TrueFalse)
                {
                    textBoxTextInput.Visibility = Visibility.Hidden;

                    txtBoxNumberInput.Visibility = Visibility.Hidden;

                    comboBoxTrueFalse.Visibility = Visibility.Visible;
                    if((bool)_currentlySelectedParameter.Value == true)
                    {
                        comboBoxTrueFalse.SelectedIndex = 0;
                    }
                    else
                    {
                        comboBoxTrueFalse.SelectedIndex = 1;
                    }
                    comboChoiceVariables.Visibility = Visibility.Hidden;
                }

            }
        }
        private void dataBindDetails()
        {
            _currentlyDataBinding = true;


            if (_currentlySelectedConstraint == null)
            {
                //gridPrecondDetails.Visibility = Visibility.Hidden;
                gridPrecondDetails.IsEnabled = false;
                return;
            }
            else
            {
                //gridPrecondDetails.Visibility = Visibility.Visible;
                gridPrecondDetails.IsEnabled = true;
            }



            //Top combobox
            List <string> attributeOptions = new List <string>();

            attributeOptions.Add("Trait");

            //Only add relationship editors if there relationships that can be edited
            if ((_editingMode == 0) && (Utilities.getGlobalCharacterList(_currentStoryData)[0].Relationships.Count > 0))
            {
                attributeOptions.Add("Relationship Target Name");
                attributeOptions.Add("Relationship Strength");
            }
            else if ((_editingMode == 1) && (Utilities.getGlobalEnvironmentList(_currentStoryData)[0].Relationships.Count > 0))
            {
                attributeOptions.Add("Relationship Target Name");
                attributeOptions.Add("Relationship Strength");
            }

            comboBoxTraitRelationship.ClearValue(ComboBox.ItemsSourceProperty);
            comboBoxTraitRelationship.Items.Clear();
            comboBoxTraitRelationship.ItemsSource = attributeOptions;

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



            //Left combobox

            if (comboBoxTraitRelationship.SelectedIndex == 0) //Trait
            {
                if (_editingMode == 0)
                {
                    comboBoxSelectTraitRel.ItemsSource = Utilities.getGlobalCharacterList(_currentStoryData)[0].Traits;
                }
                else if (_editingMode == 1)
                {
                    comboBoxSelectTraitRel.ItemsSource = Utilities.getGlobalEnvironmentList(_currentStoryData)[0].Traits;
                }
                else if (_editingMode == 2)
                {
                    comboBoxSelectTraitRel.ItemsSource = _ppType.Traits;
                }
            }
            else if (comboBoxTraitRelationship.SelectedIndex > 0) //relationship target name or strength
            {
                if (_editingMode == 0)
                {   // Using get GLOBAL list (includes not just static characters, but ones
                    //created within plot fragments. This way the user doesn't need to
                    //have created any static character lists to make plot fragment actions
                    //that edit dynamically generated objects
                    comboBoxSelectTraitRel.ItemsSource = Utilities.getGlobalCharacterList(_currentStoryData)[0].Relationships;
                }
                else if (_editingMode == 1)
                {
                    comboBoxSelectTraitRel.ItemsSource = Utilities.getGlobalEnvironmentList(_currentStoryData)[0].Relationships;
                }
            }

            //comparison operation dropdown list
            List <string> allowedOperations = new List <string>();

            allowedOperations.Add(Constraint.ConstraintComparisonTypeToString(ConstraintComparisonType.Equals));
            allowedOperations.Add(Constraint.ConstraintComparisonTypeToString(ConstraintComparisonType.NotEquals));

            if (_currentlySelectedConstraint.ComparisonValue.Type == TraitDataType.Number)
            {
                allowedOperations.Add(Constraint.ConstraintComparisonTypeToString(ConstraintComparisonType.GreaterThan));
                allowedOperations.Add(Constraint.ConstraintComparisonTypeToString(ConstraintComparisonType.LessThan));
                allowedOperations.Add(Constraint.ConstraintComparisonTypeToString(ConstraintComparisonType.GreaterThanEqualTo));
                allowedOperations.Add(Constraint.ConstraintComparisonTypeToString(ConstraintComparisonType.LessThanEqualTo));
            }

            if (_currentlySelectedConstraint.AllowedToSave)
            {
                allowedOperations.Add(Constraint.ConstraintComparisonTypeToString(ConstraintComparisonType.None));
            }
            comboBoxComparisonOp.ItemsSource = allowedOperations;

            checkBoxAlwaysTrue.IsChecked = (bool)_currentlySelectedConstraint.MustAlwaysBeTrue;

            switch (_currentlySelectedConstraint.ConstraintType)
            {
            case ConstraintComparisonType.Equals:
                comboBoxComparisonOp.SelectedIndex = 0;
                break;

            case ConstraintComparisonType.NotEquals:
                comboBoxComparisonOp.SelectedIndex = 1;
                break;

            case ConstraintComparisonType.GreaterThan:
                comboBoxComparisonOp.SelectedIndex = 2;
                break;

            case ConstraintComparisonType.LessThan:
                comboBoxComparisonOp.SelectedIndex = 3;
                break;

            case ConstraintComparisonType.GreaterThanEqualTo:
                comboBoxComparisonOp.SelectedIndex = 4;
                break;

            case ConstraintComparisonType.LessThanEqualTo:
                comboBoxComparisonOp.SelectedIndex = 5;
                break;

            case ConstraintComparisonType.None:
                if (_currentlySelectedConstraint.ComparisonValue.Type == TraitDataType.Number)
                {
                    comboBoxComparisonOp.SelectedIndex = 6;
                }
                else
                {
                    comboBoxComparisonOp.SelectedIndex = 2;
                }

                break;
            }

            if (_currentlySelectedConstraint.ConstraintType == ConstraintComparisonType.None)
            {
                //check box and values are irrelevant for this comparison
                checkBoxUseVariable.IsEnabled  = false;
                textBoxTextInput.IsEnabled     = false;
                txtBoxNumberInput.IsEnabled    = false;
                comboBoxTrueFalse.IsEnabled    = false;
                comboChoiceVariables.IsEnabled = false;

                checkBoxUseVariable.IsChecked = false;
                checkBoxAlwaysTrue.IsEnabled  = false;
                checkBoxAlwaysTrue.IsChecked  = false;
            }
            else
            {
                checkBoxUseVariable.IsEnabled  = true;
                textBoxTextInput.IsEnabled     = true;
                txtBoxNumberInput.IsEnabled    = true;
                comboBoxTrueFalse.IsEnabled    = true;
                comboChoiceVariables.IsEnabled = true;

                checkBoxAlwaysTrue.IsEnabled = true;


                //checkbox
                checkBoxUseVariable.IsChecked = _currentlySelectedConstraint.ComparisonValue.ValueIsBoundToVariable;

                //value boxes
                if (_currentlySelectedConstraint.ComparisonValue.ValueIsBoundToVariable)
                {
                    textBoxTextInput.Visibility     = Visibility.Hidden;
                    txtBoxNumberInput.Visibility    = Visibility.Hidden;
                    comboBoxTrueFalse.Visibility    = Visibility.Hidden;
                    comboChoiceVariables.Visibility = Visibility.Visible;
                    checkBoxUseVariable.Visibility  = Visibility.Visible;

                    //Data bind variable list
                    comboChoiceVariables.ItemsSource  = _currentEntity.getPreviouslyBoundPrimitiveVariables(_currentlySelectedConstraint.ComparisonValue.Type, false, _currentlySelectedConstraint);
                    comboChoiceVariables.ItemTemplate = this.FindResource("comboBoxDataTemplate") as DataTemplate;
                }
                else
                {
                    TraitDataType type = _currentlySelectedConstraint.ComparisonValue.Type;
                    if (type == TraitDataType.Number)
                    {
                        textBoxTextInput.Visibility     = Visibility.Hidden;
                        txtBoxNumberInput.Visibility    = Visibility.Visible;
                        comboBoxTrueFalse.Visibility    = Visibility.Hidden;
                        comboChoiceVariables.Visibility = Visibility.Hidden;

                        //Only show checkbox if there are actual variables to select
                        List <Trait> varList = _currentEntity.getPreviouslyBoundPrimitiveVariables(type, false, _currentlySelectedConstraint);
                        if (varList.Count > 0)
                        {
                            checkBoxUseVariable.Visibility = Visibility.Visible;
                        }
                        else
                        {
                            checkBoxUseVariable.Visibility = Visibility.Hidden;
                        }

                        //Data bind Number
                        txtBoxNumberInput.Value = (double)_currentlySelectedConstraint.ComparisonValue.LiteralValueOrBoundVarName;
                    }
                    else if (type == TraitDataType.Text)
                    {
                        textBoxTextInput.Visibility     = Visibility.Visible;
                        txtBoxNumberInput.Visibility    = Visibility.Hidden;
                        comboBoxTrueFalse.Visibility    = Visibility.Hidden;
                        comboChoiceVariables.Visibility = Visibility.Hidden;

                        //Only show checkbox if there are actual variables to select
                        List <Trait> varList = _currentEntity.getPreviouslyBoundPrimitiveVariables(type, false, _currentlySelectedConstraint);
                        if (varList.Count > 0)
                        {
                            checkBoxUseVariable.Visibility = Visibility.Visible;
                        }
                        else
                        {
                            checkBoxUseVariable.Visibility = Visibility.Hidden;
                        }

                        //Data bind text
                        textBoxTextInput.Text = (string)_currentlySelectedConstraint.ComparisonValue.LiteralValueOrBoundVarName;
                    }
                    else if (type == TraitDataType.TrueFalse)
                    {
                        textBoxTextInput.Visibility     = Visibility.Hidden;
                        txtBoxNumberInput.Visibility    = Visibility.Hidden;
                        comboBoxTrueFalse.Visibility    = Visibility.Visible;
                        comboChoiceVariables.Visibility = Visibility.Hidden;

                        //Only show checkbox if there are actual variables to select
                        List <Trait> varList = _currentEntity.getPreviouslyBoundPrimitiveVariables(type, false, _currentlySelectedConstraint);
                        if (varList.Count > 0)
                        {
                            checkBoxUseVariable.Visibility = Visibility.Visible;
                        }
                        else
                        {
                            checkBoxUseVariable.Visibility = Visibility.Hidden;
                        }

                        //Data bind true/false
                        comboBoxTrueFalse.SelectedIndex = ((bool)_currentlySelectedConstraint.ComparisonValue.LiteralValueOrBoundVarName) ? 0 : 1;
                    }
                }
            }

            if (_currentlySelectedConstraint.AllowedToSave)
            {
                //bottom text and button
                if (_currentlySelectedConstraint.ContainsSavedVariable)
                {
                    textBlockSavedStatus.Visibility = Visibility.Visible;
                    textBlockSavedStatus.Text       = "Value saved as: " + _currentlySelectedConstraint.SavedVariable.Name;
                    btSaveValButton.Content         = "Edit this Variable ...";
                    btSaveValButton.Visibility      = Visibility.Visible;
                }
                else
                {
                    textBlockSavedStatus.Visibility = Visibility.Hidden;
                    btSaveValButton.Content         = "Save this Value ...";
                    btSaveValButton.Visibility      = Visibility.Visible;
                }
            }
            else
            {
                textBlockSavedStatus.Visibility = Visibility.Hidden;
                btSaveValButton.Visibility      = Visibility.Hidden;
            }



            syncDataBoundComboBoxes();
            _currentlyDataBinding = false;
        }