private GumState ToGumState(FlatRedBall.Glue.SaveClasses.StateSave glueState, GlueElement glueElement) { var gumState = new GumState(); gumState.Name = glueState.Name; VariableGroupDictionary variableGroups = new VariableGroupDictionary(); foreach (var glueVariable in glueState.InstructionSaves) { AddGumVariables(glueVariable, null, glueElement, gumState.Variables, gumState.VariableLists, variableGroups, isInState: true); } ApplyVariableGroups(variableGroups, glueElement, gumState.Variables); // everything should set value foreach (var gumVariable in gumState.Variables) { gumVariable.SetsValue = true; } return(gumState); }
public void Initialize() { Container.Set(new StateSaveCategorySetVariableLogic()); mEntitySave = new EntitySave(); mCategory = new StateSaveCategory(); mCategory.Name = "Category1"; mCategory.SharesVariablesWithOtherCategories = true; mEntitySave.StateCategoryList.Add(mCategory); mCategory2 = new StateSaveCategory(); mCategory2.Name = "Category2"; mCategory2.SharesVariablesWithOtherCategories = true; mEntitySave.StateCategoryList.Add(mCategory); StateSave state1 = new StateSave(); state1.Name = "State1"; mCategory.States.Add(state1); StateSave stateInCategory2 = new StateSave(); stateInCategory2.Name = "State1InCategory2"; mCategory2.States.Add(stateInCategory2); mCustomVariable = new CustomVariable(); mCustomVariable.Name = "CurrentState"; mCustomVariable.Type = "VariableState"; mCustomVariable.DefaultValue = "State1"; mEntitySave.CustomVariables.Add(mCustomVariable); //need to test the case where a variable shouldn't be changed because it's not part of the category that got changed. //Also, need to handle a case where the variable becomes an uncategorized variable, but there alread is one...do we allow it? }
public static StateSave CreateCombinedState(StateSave firstState, StateSave secondState, float interpolationValue) { StateSave stateSave = new StateSave(); float firstPercentage = 1 - interpolationValue;// PercentageTrackBar.Value / 100.0f; float secondPercentage = interpolationValue; foreach (InstructionSave instruction in firstState.InstructionSaves) { // Does the 2nd also have this? InstructionSave matchingInstruction = secondState.GetInstruction(instruction.Member); if (matchingInstruction != null) { InstructionSave combinedInstruction = instruction.Clone(); object value = null; if (combinedInstruction.Value is int) { value = (int) ((int)instruction.Value * firstPercentage + (int)matchingInstruction.Value * secondPercentage); } else if (combinedInstruction.Value is float) { value = (float)((float)instruction.Value * firstPercentage + (float)matchingInstruction.Value * secondPercentage); } else if (combinedInstruction.Value is double) { value = (double)((double)instruction.Value * firstPercentage + (double)matchingInstruction.Value * secondPercentage); } else if (combinedInstruction.Value is long) { value = (long)((long)instruction.Value * firstPercentage + (long)matchingInstruction.Value * secondPercentage); } else { if (secondPercentage == 1.0f) { value = matchingInstruction.Value; } else { value = instruction.Value; } } combinedInstruction.Value = value; stateSave.InstructionSaves.Add(combinedInstruction); } } return stateSave; }
public AvailableStates(NamedObjectSave currentNamedObject, IElement currentElement, CustomVariable currentCustomVariable, StateSave currentStateSave) : base() { CurrentNamedObject = currentNamedObject; CurrentElement = currentElement; CurrentCustomVariable = currentCustomVariable; CurrentStateSave = currentStateSave; }
public AvailableAnimationChainsStringConverter(CustomVariable customVariable, StateSave stateSave = null) { IElement element = ObjectFinder.Self.GetVariableContainer(customVariable); NamedObjectSave referencedNos = element.GetNamedObjectRecursively(customVariable.SourceObject); Initialize(element, referencedNos, stateSave); }
public StateSaveCategory GetContainingCategory(StateSave instance, IElement containingElement) { foreach (StateSaveCategory category in containingElement.StateCategoryList) { if (category.States.Contains(instance)) { return category; } } return null; }
void Initialize(IElement element, NamedObjectSave referencedNos, StateSave stateSave = null) { this.element = element; this.stateSave = stateSave; this.referencedNos = referencedNos; RefreshList(); }
TreeNode GetTreeNodeFor(StateSave stateSave, TreeNode parent) { foreach (TreeNode treeNode in parent.Nodes) { if (treeNode.Tag == stateSave) { return treeNode; } } return null; }
public void ReactToStateSaveChangedValue(StateSave stateSave, StateSaveCategory category, string changedMember, object oldValue, IElement parentObject, ref bool updateTreeView) { if (changedMember != "Name") { updateTreeView = false; } // See if this is an Unmodified object // We don't support NamedObjectPropertyOverrides anymore //NamedObjectPropertyOverride propertyOverride = parentObject as NamedObjectPropertyOverride; //if (propertyOverride != null) //{ // if (stateSave.NamedObjectPropertyOverrides.Contains(propertyOverride)) // { // if (changedMember == "SourceFile" && propertyOverride.SourceFile == AvailableFileStringConverter.UseDefaultString) // { // propertyOverride.SourceFile = null; // } // if (propertyOverride.IsNulledOut) // { // stateSave.NamedObjectPropertyOverrides.Remove(propertyOverride); // } // } // else // { // switch (changedMember) // { // case "SourceFile": // propertyOverride.SourceFile = NamedObjectPropertyOverride.SourceFileBuffer; // break; // } // stateSave.NamedObjectPropertyOverrides.Add(propertyOverride); // } //} if (changedMember == "Name") { string whyItIsntValid; if (!NameVerifier.IsStateNameValid(stateSave.Name, EditorLogic.CurrentElement, EditorLogic.CurrentStateSaveCategory, EditorLogic.CurrentStateSave, out whyItIsntValid)) { stateSave.Name = (string)oldValue; updateTreeView = false; AutomatedGlue.GlueGui.ShowMessageBox(whyItIsntValid); } else { ReactToStateNameChange(oldValue, stateSave, category, parentObject); } } }
// This method indicates to the design environment that // the type editor will paint additional content in the // LightShape entry in the PropertyGrid. public override bool GetPaintValueSupported( ITypeDescriptorContext context) { FlatRedBall.Glue.SaveClasses.StateSave stateSave = ((StateSavePropertyGridDisplayer)context.Instance).Instance as StateSave; //if (context.PropertyDescriptor.) //{ // int m = 3; //} return(mPaintIcon); }
private static ICodeBlock GenerateInterpolateForIndividualState(IElement element, ICodeBlock codeBlock, ICodeBlock otherBlock, StateSave stateSave, string enumType) { codeBlock = codeBlock.Case(enumType + "." + stateSave.Name); otherBlock = otherBlock.Case(enumType + "." + stateSave.Name); foreach (InstructionSave instruction in stateSave.InstructionSaves) { CustomVariable customVariable = null; customVariable = element.GetCustomVariable(instruction.Member); string valueAsString = CodeParser.ParseObjectValue(instruction.Value); if (customVariable != null && !string.IsNullOrEmpty(valueAsString)) { NamedObjectSave sourceNamedObjectSave = element.GetNamedObjectRecursively(customVariable.SourceObject); if (sourceNamedObjectSave == null || sourceNamedObjectSave.IsDisabled == false) { if (sourceNamedObjectSave != null) { NamedObjectSaveCodeGenerator.AddIfConditionalSymbolIfNecesssary(codeBlock, sourceNamedObjectSave); NamedObjectSaveCodeGenerator.AddIfConditionalSymbolIfNecesssary(otherBlock, sourceNamedObjectSave); } string timeCastString = ""; if (instruction.Value is float) { timeCastString = "(float)"; } if (string.IsNullOrEmpty(customVariable.SourceObject)) { GenerateInterpolateForIndividualStateNoSource(ref codeBlock, element, ref otherBlock, instruction, customVariable, valueAsString, timeCastString); } else { GenerateInterpolateForIndividualStateWithSource(ref codeBlock, element, ref otherBlock, customVariable, valueAsString, sourceNamedObjectSave, timeCastString); } if (sourceNamedObjectSave != null) { NamedObjectSaveCodeGenerator.AddEndIfIfNecessary(codeBlock, sourceNamedObjectSave); NamedObjectSaveCodeGenerator.AddEndIfIfNecessary(otherBlock, sourceNamedObjectSave); } } } } return codeBlock; }
public void Initialize() { OverallInitializer.Initialize(); ExposedVariableManager.Initialize(); mEntitySave = CreateEntitySaveWithStates("ExposedVariableEntity"); mEntitySave.ImplementsIVisible = true; ObjectFinder.Self.GlueProject.Entities.Add(mEntitySave); mDerivedEntitySave = new EntitySave(); mDerivedEntitySave.BaseEntity = mEntitySave.Name; mDerivedEntitySave.Name = "DerivedExposedVariableEntity"; ObjectFinder.Self.GlueProject.Entities.Add(mDerivedEntitySave); mEntityWithCategorizedThatShareVariables = new EntitySave(); mEntityWithCategorizedThatShareVariables.Name = "ExposedVariableTestEntityWithCategorizedThatShareVariables"; ObjectFinder.Self.GlueProject.Entities.Add(mEntityWithCategorizedThatShareVariables); StateSaveCategory category = new StateSaveCategory(); category.SharesVariablesWithOtherCategories = true; // this is important - it means that it won't make a new enum or property, so it is just the "CurrentState" variable category.Name = "Category1"; mEntityWithCategorizedThatShareVariables.StateCategoryList.Add(category); StateSave stateSave = new StateSave(); stateSave.Name = "CategorizedState1"; category.States.Add(stateSave); mContainerBaseEntity = new EntitySave(); mContainerBaseEntity.Name = "ExposedVariableTestContainerBaseEntity"; ObjectFinder.Self.GlueProject.Entities.Add(mContainerBaseEntity); NamedObjectSave namedObjectSave = new NamedObjectSave(); namedObjectSave.InstanceName = mEntitySave.Name + "Instance"; namedObjectSave.SourceType = SourceType.Entity; namedObjectSave.SourceClassType = mEntitySave.Name; mContainerBaseEntity.NamedObjects.Add(namedObjectSave); CustomVariable tunneledVariable = new CustomVariable(); tunneledVariable.Name = "TunneledStateVariable"; tunneledVariable.SourceObject = namedObjectSave.InstanceName; tunneledVariable.SourceObjectProperty = "Current" + mEntitySave.StateCategoryList[0].Name + "State"; tunneledVariable.Type = mEntitySave.StateCategoryList[0].Name; tunneledVariable.SetByDerived = true; mContainerBaseEntity.CustomVariables.Add(tunneledVariable); mContainerDerivedEntity = new EntitySave(); mContainerDerivedEntity.Name = "ExposedVariableTestContainerDerivedEntity"; ObjectFinder.Self.GlueProject.Entities.Add(mContainerDerivedEntity); mContainerDerivedEntity.BaseEntity = mContainerBaseEntity.Name; mContainerDerivedEntity.UpdateFromBaseType(); mContainerDerivedEntity.GetCustomVariable(tunneledVariable.Name).DefaultValue = mEntitySave.StateCategoryList[0].States[0].Name; CreateCsvContainerEntitySave(); }
public void ShowState(StateSave stateSave) { if (GluxManager.CurrentElement != null) { // We used to reset positioned values // because states would get set, undo, then // a different state would get set. Now all // current states are set, including initial values // by the State plugin, therefore we shouldn't reset // position values unless there is no state. GluxManager.CurrentElement.SetState(stateSave, stateSave == null, GluxManager.CurrentElement.AssociatedIElement); } }
// This method paints a graphical representation of the // selected value of the LightShpae property. public override void PaintValue(PaintValueEventArgs e) { if (e.Bounds.Left == 1 && e.Bounds.Top == 1) { if (e.Context.Instance is StateSavePropertyGridDisplayer) { FlatRedBall.Glue.SaveClasses.StateSave stateSave = ((StateSavePropertyGridDisplayer)e.Context.Instance).Instance as StateSave; PropertyInfo[] properties = e.Context.GetType().GetProperties(); PropertyInfo info = e.Context.GetType().GetProperty("PropertyName"); string variableName = (string)info.GetValue(e.Context, null); CustomVariable variable = GlueState.Self.CurrentElement.GetCustomVariable(variableName); if (variable != null) { InterpolationCharacteristic interpolationCharacteristic = CustomVariableHelper.GetInterpolationCharacteristic(variable, GlueState.Self.CurrentElement); Image bitmap = null; if (interpolationCharacteristic == InterpolationCharacteristic.CanInterpolate || (interpolationCharacteristic == InterpolationCharacteristic.NeedsVelocityVariable && variable.HasAccompanyingVelocityProperty)) { bitmap = mCanInterpolate; } else if (interpolationCharacteristic == InterpolationCharacteristic.NeedsVelocityVariable) { bitmap = mNeedsVelocityVariable; } else { bitmap = mCantInterpolate; } e.Graphics.DrawImage(bitmap, e.Bounds.Left, e.Bounds.Top, bitmap.Width, bitmap.Height); } } } else { //e.Graphics.DrawEllipse(Pens.Yellow, e.Bounds); } }
public void TestStateVariables() { EntitySave entitySave = new EntitySave(); entitySave.Name = "CustomVariableTestStateVariableEntity"; ObjectFinder.Self.GlueProject.Entities.Add(entitySave); StateSaveCategory category1 = new StateSaveCategory(); category1.Name = "Category1"; category1.SharesVariablesWithOtherCategories = false; StateSave stateSave = new StateSave(); stateSave.Name = "Disabled"; category1.States.Add(stateSave); StateSaveCategory category2 = new StateSaveCategory(); category2.Name = "Category2"; category2.SharesVariablesWithOtherCategories = false; stateSave = new StateSave(); stateSave.Name = "Disabled"; category2.States.Add(stateSave); entitySave.StateCategoryList.Add(category1); entitySave.StateCategoryList.Add(category2); CustomVariable customVariable = new CustomVariable(); customVariable.Type = "Category2"; customVariable.DefaultValue = "Disabled"; customVariable.Name = "CurrentCategory2State"; entitySave.CustomVariables.Add(customVariable); ElementRuntime elementRuntime = new ElementRuntime(entitySave, null, null, null, null); StateSave foundStateSave = elementRuntime.GetStateSaveFromCustomVariableValue(customVariable, customVariable.DefaultValue); if (foundStateSave != category2.States[0]) { throw new Exception("States in categories are not being found properly when referenced through custom variables"); } }
private void CreateEntitySaves() { mEntitySave = new EntitySave(); mEntitySave.Name = "NamedObjectSaveTestsEntity"; mEntitySave.ImplementsIVisible = true; mEntitySave.ImplementsIWindow = true; CustomVariable customVariable = new CustomVariable(); customVariable.Type = "float"; customVariable.Name = "X"; mEntitySave.CustomVariables.Add(customVariable); customVariable = new CustomVariable(); customVariable.Type = "float"; customVariable.Name = "Y"; customVariable.SetByDerived = true; mEntitySave.CustomVariables.Add(customVariable); StateSave stateSave = new StateSave(); stateSave.Name = "TestState"; mEntitySave.States.Add(stateSave); StateSaveCategory stateSaveCategory = new StateSaveCategory(); stateSaveCategory.Name = "TestCategory"; mEntitySave.StateCategoryList.Add(stateSaveCategory); StateSave categorizedState = new StateSave(); categorizedState.Name = "CategorizedState"; stateSaveCategory.States.Add(categorizedState); ObjectFinder.Self.GlueProject.Entities.Add(mEntitySave); mDerivedEntitySave = new EntitySave(); mDerivedEntitySave.BaseEntity = mEntitySave.Name; mDerivedEntitySave.Name = "NamedObjectSaveTestDerivedEntity"; ObjectFinder.Self.GlueProject.Entities.Add(mDerivedEntitySave); }
public static StateSave GetStateRecursively(this IElement element, string stateName, string categoryName = null) { StateSave stateSave = element.GetState(stateName, categoryName); if (stateSave != null) { return(stateSave); } else if (stateSave == null && !string.IsNullOrEmpty(element.BaseElement)) { IElement baseElement = GlueState.CurrentGlueProject.GetElement(element.BaseElement); if (baseElement != null) { return(GetStateRecursively(baseElement, stateName, categoryName)); } } return(null); }
public StateSave Clone() { StateSave newStateSave = this.MemberwiseClone() as StateSave; newStateSave.InstructionSaves = new List <InstructionSave>(); // I don't think we're going to use these anymore //newStateSave.NamedObjectPropertyOverrides = new List<NamedObjectPropertyOverride>(); foreach (InstructionSave instructionSave in InstructionSaves) { newStateSave.InstructionSaves.Add(instructionSave.Clone()); } // I don't think we're going to use these anymore //foreach (NamedObjectPropertyOverride nopo in NamedObjectPropertyOverrides) //{ // newStateSave.NamedObjectPropertyOverrides.Add(nopo.Clone()); //} return(newStateSave); }
public static string GetEnumTypeName(this StateSave stateSave, IElement container) { if (container.States.Contains(stateSave)) { return("VariableState"); } else { foreach (var category in container.StateCategoryList.Where(item => item.States.Contains(stateSave))) { if (category.SharesVariablesWithOtherCategories) { return("VariableState"); } else { return(category.Name); } } } return("VariableState"); }
void Initialize(IElement element, NamedObjectSave referencedNos, StateSave stateSave = null) { AnimationChainListSave acls = null; acls = GetAnimationChainListFile(element, referencedNos, stateSave); if (acls == null) { mAvailableChains = new string[0]; } else { mAvailableChains = new string[acls.AnimationChains.Count]; for (int i = 0; i < acls.AnimationChains.Count; i++) { mAvailableChains[i] = acls.AnimationChains[i].Name; } } }
public void Add(string containerName, StateSave stateSave) { throw new NotImplementedException(); }
public void Update(string containerName, StateSave stateSave) { var container = ObjectFinder.Self.GetIElement(containerName); var currentNos = container.GetState(stateSave.Name); CopyObject(stateSave, currentNos); RefreshElement(container); //GlueCommand.GluxCommands.SaveGlux(); }
private static void ReactToStateNameChange(object oldValue, StateSave stateSave, StateSaveCategory category, IElement parentObject) { PluginManager.ReactToStateNameChange(parentObject as IElement, (string)oldValue, stateSave.Name); IElement parentAsElement = parentObject as IElement; string name = parentObject.Name; string typeToMatch = "VariableState"; if (category != null && category.SharesVariablesWithOtherCategories == false) { typeToMatch = "Current" + category.Name + "State"; } var matchingVariables = from variable in parentAsElement.CustomVariables where variable.DefaultValue == oldValue && variable.Type == typeToMatch select variable; foreach (CustomVariable variable in matchingVariables) { variable.DefaultValue = stateSave.Name; } string variableName = stateSave.GetExposedVariableName(parentObject); string variableType = stateSave.GetEnumTypeName(parentObject); // Find any NOSs that use the ParentObject as their type foreach (ScreenSave screenSave in ObjectFinder.Self.GlueProject.Screens) { var customQuery = from nos in screenSave.AllNamedObjects where nos.SourceType == SourceType.Entity && nos.SourceClassType == name select nos; foreach (var nos in customQuery) { if (nos.CurrentState == (oldValue as string)) { nos.CurrentState = stateSave.Name; } foreach (var variable in nos.InstructionSaves.Where(item => item.Member == variableName && (item.Value as string) == (oldValue as string))) { variable.Value = stateSave.Name; } } } foreach (EntitySave entitySave in ObjectFinder.Self.GlueProject.Entities) { var customQuery = from nos in entitySave.AllNamedObjects where nos.SourceType == SourceType.Entity && nos.SourceClassType == name select nos; foreach (var nos in customQuery) { if (nos.CurrentState == (oldValue as string)) { nos.CurrentState = stateSave.Name; } foreach (var variable in nos.InstructionSaves.Where(item => item.Member == variableName && (item.Value as string) == (oldValue as string))) { variable.Value = stateSave.Name; } } } }
public void ApplyInterpolateToState(StateSave firstState, StateSave secondState, float time, InterpolationType interpolationType, Easing easing) { this.StateComboBox.Text = InterpolateBetweenConst; this.InterpolateFromComboBox.Text = firstState.Name; this.InterpolateToComboBox.Text = secondState.Name; this.InterpolationPanel.Visible = (this.StateComboBox.Text == InterpolateBetweenConst); this.AdvancedInterpolationPanel.Visible = InterpolationPanel.Visible && DoesCurrentElementHaveAdvancedInterpolation(); mTweener.Start(0, 1, time, Tweener.GetInterpolationFunction(interpolationType, easing)); mTweenTimer.Start(); }
private void UpdateIncludedAndExcluded(StateSave instance) { ResetToDefault(); ExcludeMember("InstructionSaves"); ExcludeMember("NamedObjectPropertyOverrides"); IElement element = ObjectFinder.Self.GetElementContaining(instance); for (int i = 0; i < element.CustomVariables.Count; i++) { CustomVariable customVariable = element.CustomVariables[i]; StateSave stateSaveOwningVariable = null; // This doesn't share variables, so it may own the variable StateSaveCategory thisCategory = GetContainingCategory(instance, element); List<StateSave> statesInThisCategory = null; if (thisCategory != null) { statesInThisCategory = thisCategory.States; } else { statesInThisCategory = element.States; } foreach (StateSave stateInThisCategory in statesInThisCategory) { if (stateInThisCategory.AssignsVariable(customVariable)) { stateSaveOwningVariable = instance; } } if (stateSaveOwningVariable == null) { stateSaveOwningVariable = GetStateThatVariableBelongsTo(customVariable, element); } Type type = TypeManager.GetTypeFromString(customVariable.Type); TypeConverter typeConverter = customVariable.GetTypeConverter(CurrentElement, instance, null); Attribute[] customAttributes; if (stateSaveOwningVariable == instance || stateSaveOwningVariable == null || GetContainingCategory(instance, element) == GetContainingCategory(stateSaveOwningVariable, element)) { customAttributes = new Attribute[] { new CategoryAttribute("State Variable"), new EditorAttribute(typeof(StateValueEditor), typeof(System.Drawing.Design.UITypeEditor)) }; } else { StateSaveCategory category = GetContainingCategory(stateSaveOwningVariable, element); string categoryName = "Uncategorized"; if (category != null) { categoryName = category.Name; } customAttributes = new Attribute[] { // Do we want it to be readonly? I think this may be too restrictive //new ReadOnlyAttribute(true), new CategoryAttribute("Variables set by other states"), new DisplayNameAttribute(customVariable.Name + " set in " + categoryName) //, //new EditorAttribute(typeof(StateValueEditor), typeof(System.Drawing.Design.UITypeEditor)) }; } Type typeToPass = customVariable.GetRuntimeType(); if (typeToPass == null) { typeToPass = typeof(string); } IncludeMember( customVariable.Name, typeToPass, delegate(object sender, MemberChangeArgs args) { object value = args.Value; // May 16, 2012 // This crashed if // the type was a Texture2D. // I don't think we ever want // to set the value on a StateSave // to an actual Texture2D - rather it // should be a string. I don't think it // should ever be any loaded file, in fact, // so we should prob make sure it's not a file // by adding a check. if (CustomVariablePropertyGridDisplayer.GetShouldCustomVariableBeConvertedToType(args, customVariable)) { value = PropertyValuePair.ConvertStringToType((string)args.Value, customVariable.GetRuntimeType()); } instance.SetValue(args.Member, value); } , delegate() { return GetValue(customVariable.Name); }, typeConverter, customAttributes ); } //if (false) //{ // #region Add the Object Overrides // Type namedObjectPropertyOverrideType = typeof(NamedObjectPropertyOverride); // TypeConverter expandableTypeConverter = new ExpandableObjectConverter(); // List<NamedObjectSave> namedObjectList = element.NamedObjects; // pdc = AddNamedObjectOverrides(pdc, namedObjectPropertyOverrideType, expandableTypeConverter, namedObjectList); // #endregion //} }
private static bool GetDoesStateAssignAbsoluteValues(StateSave stateSave, IElement element) { bool returnValue = false; foreach (InstructionSave instruction in stateSave.InstructionSaves) { CustomVariable customVariable = element.GetCustomVariableRecursively(instruction.Member); if (customVariable != null) { returnValue |= !string.IsNullOrEmpty(RelativeValueForInstruction(instruction, customVariable, element)); } } return returnValue; }
private void CreateEntitySaveState() { StateSave stateSave = new StateSave(); stateSave.Name = "FirstState"; InstructionSave instructionSave = new InstructionSave(); instructionSave.Member = "X"; instructionSave.Value = 10.0f; stateSave.InstructionSaves.Add(instructionSave); instructionSave = new InstructionSave(); instructionSave.Member = "SpriteScaleX"; instructionSave.Value = 4.0f; stateSave.InstructionSaves.Add(instructionSave); mEntitySave.States.Add(stateSave); }
private void CreateContainerEntityState() { StateSave stateSave = new StateSave(); stateSave.Name = "SetContainedFirstState"; InstructionSave instructionSave = new InstructionSave(); instructionSave.Type = "VariableState"; instructionSave.Value = "FirstState"; instructionSave.Member = "StateTunnelVariable"; stateSave.InstructionSaves.Add(instructionSave); mContainer.States.Add(stateSave); }
static void AddStateClick(object sender, EventArgs e) { // search: addstate, add new state, addnewstate, add state TextInputWindow tiw = new TextInputWindow(); tiw.DisplayText = "Enter a name for the new state"; tiw.Text = "New State"; DialogResult result = tiw.ShowDialog(MainGlueWindow.Self); if (result == DialogResult.OK) { string whyItIsntValid; if (!NameVerifier.IsStateNameValid(tiw.Result, EditorLogic.CurrentElement, EditorLogic.CurrentStateSaveCategory, EditorLogic.CurrentStateSave, out whyItIsntValid)) { GlueGui.ShowMessageBox(whyItIsntValid); } else { StateSave newState = new StateSave(); newState.Name = tiw.Result; if (EditorLogic.CurrentStateSaveCategory != null) { EditorLogic.CurrentStateSaveCategory.States.Add(newState); } else { IElement element = EditorLogic.CurrentElement; element.States.Add(newState); } EditorLogic.CurrentElementTreeNode.UpdateReferencedTreeNodes(); ElementViewWindow.GenerateSelectedElementCode(); GlueCommands.Self.TreeNodeCommands.SelectTreeNode(newState); GluxCommands.Self.SaveGlux(); ProjectManager.SaveProjects(); } } }
public static bool IsStateNameValid(string name, IElement element, StateSaveCategory category, StateSave currentStateSave, out string whyItIsntValid) { whyItIsntValid = null; CheckForCommonImproperNames(name, ref whyItIsntValid); if(!string.IsNullOrEmpty(whyItIsntValid)) return false; //Check if shared if (element != null) { if (category == null || category.SharesVariablesWithOtherCategories) { //Check states not in category if (element.States.Any(otherState => otherState.Name == name && otherState != currentStateSave)) { whyItIsntValid = "Conflicts with existing state"; return false; } //Check categories that have sharing on foreach (var stateSaveCategory in from stateSaveCategory in element.StateCategoryList where stateSaveCategory.SharesVariablesWithOtherCategories from stateSave in stateSaveCategory.States where name == stateSave.Name && stateSave != currentStateSave select stateSaveCategory) { whyItIsntValid = "Conflicts with existing state in category " + stateSaveCategory.Name; return false; } } else if (category != null) { if (category.States.Any(state => state.Name == name && state != currentStateSave)) { whyItIsntValid = "The name " + name + " is already being used in the category " + category.Name; return false; } } } if (!string.IsNullOrEmpty(element.BaseElement)) { IElement baseElement = ObjectFinder.Self.GetIElement(element.BaseElement); if (baseElement != null) { string categoryName = null; if (category != null && category.SharesVariablesWithOtherCategories == false) { categoryName = category.Name; } if (baseElement.GetState(name, categoryName) != null) { string screenOrEntity = "screen"; if(baseElement is EntitySave) { screenOrEntity = "entity"; } whyItIsntValid = "This state name \"" + name + "\" is already used in a base " + screenOrEntity; } } } return string.IsNullOrEmpty(whyItIsntValid); }
internal static string StateSaveToString(StateSave stateSave) { return(stateSave.Name + "(State in " + ObjectFinder.Self.GetElementContaining(stateSave) + ")"); throw new NotImplementedException(); }
public void TestStateSave() { EntitySave baseEntity = new EntitySave(); baseEntity.Name = "BaseForStateSaveNameTest"; ObjectFinder.Self.GlueProject.Entities.Add(baseEntity); EntitySave derivedEntity = new EntitySave(); derivedEntity.Name = "DerivedForStateSaveNameTest"; ObjectFinder.Self.GlueProject.Entities.Add(derivedEntity); derivedEntity.BaseEntity = baseEntity.Name; StateSave stateSave = new StateSave(); stateSave.Name = "NameOfState"; baseEntity.States.Add(stateSave); string whyItIsntValid; NameVerifier.IsStateNameValid("NameOfState", baseEntity, null, null, out whyItIsntValid); if (string.IsNullOrEmpty(whyItIsntValid)) { throw new Exception("Name verifier should not allow duplicate names"); } NameVerifier.IsStateNameValid("NameOfState", derivedEntity, null, null, out whyItIsntValid); if (string.IsNullOrEmpty(whyItIsntValid)) { throw new Exception("Name verifier should not allow derived to duplicate state names"); } baseEntity.StateCategoryList.Add(new StateSaveCategory() { Name = "Category1", SharesVariablesWithOtherCategories = false }); baseEntity.StateCategoryList[0].States.Add(new StateSave() { Name = "StateInCategory" }); NameVerifier.IsStateNameValid("StateInCategory", baseEntity, baseEntity.StateCategoryList[0], null, out whyItIsntValid); if(string.IsNullOrEmpty(whyItIsntValid)) { throw new Exception("Categories should not allow multiple states with the same name in them"); } }
private static ICodeBlock GenerateCurrentStateCodeForIndividualState(IElement element, ICodeBlock codeBlock, StateSave stateSave, string enumType) { var curBlock = codeBlock.Case(enumType + "." + stateSave.Name); bool doesStateAssignAbsoluteValues = GetDoesStateAssignAbsoluteValues(stateSave, element); foreach (InstructionSave instruction in stateSave.InstructionSaves) { if (instruction.Value != null) { // Get the valueAsString, which is the right-side of the equals sign string rightSideOfEquals = GetRightSideAssignmentValueAsString(element, instruction); if (!string.IsNullOrEmpty(rightSideOfEquals)) { CustomVariable customVariable = element.GetCustomVariableRecursively(instruction.Member); NamedObjectSave referencedNos = element.GetNamedObjectRecursively(customVariable.SourceObject); if (referencedNos != null) { NamedObjectSaveCodeGenerator.AddIfConditionalSymbolIfNecesssary(curBlock, referencedNos); } string leftSideOfEquals = GetLeftSideOfEquals(element, customVariable, instruction, false); string leftSideOfEqualsWithRelative = GetLeftSideOfEquals(element, customVariable, instruction, true); if (leftSideOfEquals != leftSideOfEqualsWithRelative) { string objectWithParent = null; if (string.IsNullOrEmpty(customVariable.SourceObject)) { objectWithParent = "this"; } else { objectWithParent = customVariable.SourceObject; } curBlock .If(objectWithParent + ".Parent == null") .Line(leftSideOfEquals + " = " + rightSideOfEquals + ";") .End() .Else() .Line(leftSideOfEqualsWithRelative + " = " + rightSideOfEquals + ";"); } else { curBlock.Line(leftSideOfEquals + " = " + rightSideOfEquals + ";"); } if (referencedNos != null) { NamedObjectSaveCodeGenerator.AddEndIfIfNecessary(curBlock, referencedNos); } } } } return codeBlock; }
public void Test() { StateSave firstState = new StateSave(); InstructionSave instructionSave = new InstructionSave(); instructionSave.Type = "float"; instructionSave.Value = 0.0f; instructionSave.Member = "X"; firstState.InstructionSaves.Add(instructionSave); StateSave secondState = new StateSave(); instructionSave = instructionSave.Clone(); instructionSave.Value = 10.0f; secondState.InstructionSaves.Add(instructionSave); StateSave combined = StateSaveExtensionMethodsGlueView.CreateCombinedState(firstState, secondState, .5f); if (MathFunctions.RoundToInt((float)combined.InstructionSaves[0].Value) != 5) { throw new Exception("CreateCombined is not properly combining States"); } }
public static TypeConverter GetTypeConverter(this CustomVariable customVariable, IElement containingElement, StateSave stateSave, FlatRedBall.Glue.Plugins.ExportedInterfaces.IGlueState glueState) { TypeConverter typeConverter = null; if (customVariable.GetIsVariableState()) { typeConverter = new AvailableStates( FacadeContainer.Self.GlueState.CurrentNamedObjectSave, FacadeContainer.Self.GlueState.CurrentElement, FacadeContainer.Self.GlueState.CurrentCustomVariable, FacadeContainer.Self.GlueState.CurrentStateSave ); } else { Type runtimeType = customVariable.GetRuntimeType(); if (runtimeType != null) { if (runtimeType.IsEnum) { typeConverter = new EnumConverter(runtimeType); } else if (runtimeType == typeof(Color)) { return(new AvailableColorTypeConverter()); } else if ((runtimeType == typeof(string) || runtimeType == typeof(AnimationChainList)) && customVariable.SourceObjectProperty == "CurrentChainName") { typeConverter = new AvailableAnimationChainsStringConverter(customVariable, stateSave); } else if (customVariable.GetIsFile()) { AvailableFileStringConverter converter = new AvailableFileStringConverter(containingElement); converter.QualifiedRuntimeTypeName = runtimeType.FullName; converter.ShowNewFileOption = false; converter.RemovePathAndExtension = true; typeConverter = converter; } } else if (customVariable.GetIsCsv()) { if (FacadeContainer.Self.ProjectValues == null) { throw new NullReferenceException("The ProjectValues property in FAcadeContainer.Self.ProjectValues must be set before trying to get the CSV type converter for the variable " + customVariable.ToString()); } ReferencedFileSave rfs = ObjectFinder.Self.GetAllReferencedFiles().FirstOrDefault(item => item.IsCsvOrTreatedAsCsv && item.GetTypeForCsvFile() == customVariable.Type); AvailableSpreadsheetValueTypeConverter converter = null; if (rfs != null) { converter = new AvailableSpreadsheetValueTypeConverter( FacadeContainer.Self.ProjectValues.ContentDirectory + rfs.Name, containingElement); } else { converter = new AvailableSpreadsheetValueTypeConverter( FacadeContainer.Self.ProjectValues.ContentDirectory + customVariable.Type, containingElement); } converter.ShouldAppendFileName = true; typeConverter = converter; } else if (customVariable.GetIsFile()) { // If we got here, that means that the // CustomVariable is a file, but it doesn't // have a System.Type, so it only knows its runtime // type; AvailableFileStringConverter converter = new AvailableFileStringConverter(containingElement); converter.UnqualifiedRuntimeTypeName = customVariable.Type; converter.ShowNewFileOption = false; converter.RemovePathAndExtension = true; typeConverter = converter; } } return(typeConverter); }
public bool ContainsState(StateSave state) { return mStates.Contains(state); }
public TreeNode StateTreeNode(StateSave stateSave) { TreeNode treeNode = TreeNodeByTagIn(stateSave, ElementViewWindow.ScreensTreeNode.Nodes); if (treeNode == null) { treeNode = TreeNodeByTagIn(stateSave, ElementViewWindow.EntitiesTreeNode.Nodes); } return treeNode; }
public static void SetValue(this StateSave stateSave, string variableName, object valueToSet) { #if GLUE if (variableName.Contains(" set in ")) { string withoutSpace = variableName.Substring(0, variableName.IndexOf(' ')); DialogResult result = MessageBox.Show("The variable " + withoutSpace + " is set in other categories that do not share states. Are you sure you want to set it?", "Set variable?", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { variableName = withoutSpace; } } #endif bool wasFound = false; // See if there is an instructionD #region Set the existing instruction's value if there is one already foreach (InstructionSave instructionSave in stateSave.InstructionSaves) { if (instructionSave.Member == variableName) { wasFound = true; instructionSave.Value = valueToSet; break; } } #endregion if (!wasFound) { IElement container = ObjectFinder.Self.GetElementContaining(stateSave); CustomVariable variable = null; foreach (CustomVariable containedVariable in container.CustomVariables) { if (containedVariable.Name == variableName) { variable = containedVariable; break; } } InstructionSave instructionSave = new InstructionSave(); instructionSave.Value = valueToSet; // make it the default instructionSave.Type = valueToSet.GetType().Name; instructionSave.Member = variableName; // Create a new instruction stateSave.InstructionSaves.Add(instructionSave); stateSave.SortInstructionSaves(container.CustomVariables); } }
public static bool IsStateNameValid(string name, IElement element, StateSaveCategory category, StateSave currentStateSave, out string whyItIsntValid) { whyItIsntValid = null; CheckForCommonImproperNames(name, ref whyItIsntValid); if (!string.IsNullOrEmpty(whyItIsntValid)) { return(false); } //Check if shared if (element != null) { if (category == null || category.SharesVariablesWithOtherCategories) { //Check states not in category if (element.States.Any(otherState => otherState.Name == name && otherState != currentStateSave)) { whyItIsntValid = "Conflicts with existing state"; return(false); } //Check categories that have sharing on foreach (var stateSaveCategory in from stateSaveCategory in element.StateCategoryList where stateSaveCategory.SharesVariablesWithOtherCategories from stateSave in stateSaveCategory.States where name == stateSave.Name && stateSave != currentStateSave select stateSaveCategory) { whyItIsntValid = "Conflicts with existing state in category " + stateSaveCategory.Name; return(false); } } else if (category != null) { if (category.States.Any(state => state.Name == name && state != currentStateSave)) { whyItIsntValid = "The name " + name + " is already being used in the category " + category.Name; return(false); } } } if (!string.IsNullOrEmpty(element.BaseElement)) { IElement baseElement = ObjectFinder.Self.GetIElement(element.BaseElement); if (baseElement != null) { string categoryName = null; if (category != null && category.SharesVariablesWithOtherCategories == false) { categoryName = category.Name; } if (baseElement.GetState(name, categoryName) != null) { string screenOrEntity = "screen"; if (baseElement is EntitySave) { screenOrEntity = "entity"; } whyItIsntValid = "This state name \"" + name + "\" is already used in a base " + screenOrEntity; } } } return(string.IsNullOrEmpty(whyItIsntValid)); }
void CreateElementRuntime() { mEntitySave = new EntitySave { Name = "VariableSettingEntity" }; ObjectFinder.Self.GlueProject.Entities.Add(mEntitySave); var xVariable = new CustomVariable { Name = "X", Type = "float", DefaultValue = 0 }; mEntitySave.CustomVariables.Add(xVariable); // Needs the Z variable exposed so that the uncategorized state below can use it: var zVariable = new CustomVariable { Name = "Z", Type = "float", DefaultValue = 0 }; mEntitySave.CustomVariables.Add(zVariable); CustomVariable stateVariable = new CustomVariable { Name = "CurrentStateSaveCategoryState", Type = "StateSaveCategory", DefaultValue = "FirstState" }; stateVariable.SetByDerived = true; mEntitySave.CustomVariables.Add(stateVariable); CustomVariable uncategorizedStateVariable = new CustomVariable { Name = "CurrentState", Type = "VariableState", //DefaultValue = "Uncategorized", // Don't set a default value - the derived will do this SetByDerived = true }; mEntitySave.CustomVariables.Add(uncategorizedStateVariable); StateSave uncategorized = new StateSave(); uncategorized.Name = "Uncategorized"; InstructionSave instruction = new InstructionSave(); instruction.Member = "Z"; instruction.Value = 8.0f; uncategorized.InstructionSaves.Add(instruction); mEntitySave.States.Add(uncategorized); StateSave stateSave = new StateSave(); stateSave.Name = "FirstState"; instruction = new InstructionSave(); instruction.Member = "X"; instruction.Value = 10; stateSave.InstructionSaves.Add(instruction); StateSave secondStateSave = new StateSave(); secondStateSave.Name = "SecondState"; instruction = new InstructionSave(); instruction.Member = "X"; instruction.Value = -10; secondStateSave.InstructionSaves.Add(instruction); StateSaveCategory category = new StateSaveCategory(); category.Name = "StateSaveCategory"; category.States.Add(stateSave); category.States.Add(secondStateSave); mEntitySave.StateCategoryList.Add(category); mElementRuntime = new ElementRuntime(mEntitySave, null, null, null, null); mElementRuntime.AfterVariableApply += AfterVariableSet; }