public StateReferencingInstanceMember(InstanceSavePropertyDescriptor ispd, StateSave stateSave, 
            string variableName, InstanceSave instanceSave, ElementSave elementSave)
            : base(variableName, stateSave)
        {
            mInstanceSave = instanceSave;
            mStateSave = stateSave;
            mVariableName = variableName;
            mPropertyDescriptor = ispd;
            mElementSave = elementSave;
            this.CustomGetEvent += GetEvent;
            this.CustomSetEvent += SetEvent;
            this.CustomGetTypeEvent += GetTypeEvent;

            this.SortValue = int.MaxValue;

            if (instanceSave != null)
            {
                this.Instance = instanceSave;
            }
            else
            {
                this.Instance = elementSave;
            }

            DisplayName = RootVariableName;

            TryAddExposeVariableMenuOptions(instanceSave);

            // This could be slow since we have to check it for every variable in an object.
            // Maybe we'll want to pass this in to the function?
            StandardElementSave standardElement = null;
            if (instanceSave != null)
            {
                standardElement = ObjectFinder.Self.GetRootStandardElementSave(instanceSave);
            }
            else
            {
                standardElement = ObjectFinder.Self.GetRootStandardElementSave(elementSave);
            }

            VariableSave standardVariable = null;

            if (standardElement != null)
            {
                standardVariable = standardElement.DefaultState.Variables.FirstOrDefault(item => item.Name == RootVariableName);
            }

            if (standardVariable != null)
            {
                this.SortValue = standardVariable.DesiredOrder;
            }
        }
Esempio n. 2
0
        public RecursiveVariableFinder(StateSave stateSave)
        {
            ContainerType = VariableContainerType.StateSave;
            mStateSave    = stateSave;

            mElementStack = new List <ElementWithState>();

#if DEBUG
            if (stateSave.ParentContainer == null)
            {
                throw new NullReferenceException("The state passed in to the RecursiveVariableFinder has a null ParentContainer and it shouldn't");
            }
#endif

            mElementStack.Add(new ElementWithState(stateSave.ParentContainer)
            {
                StateName = stateSave.Name
            });
        }
Esempio n. 3
0
        public static UndoObject CreateUndoObject(StateSave objectToSave, List<InstanceSave> instances, object parent)
        {
            StateSave cloned = FileManager.CloneSaveObject(objectToSave);
            List<InstanceSave> instancesCloned = null;
            if (instances != null)
            {
                instancesCloned = new List<InstanceSave>();
                foreach (var instance in instances)
                {
                    instancesCloned.Add(instance); // no need to clone this, I don't think
                }
            }
            UndoObject undoObject = new UndoObject(
                cloned,
                instancesCloned,
                parent);

            return undoObject;
        }
Esempio n. 4
0
        private static void FixStateVariableTypes(ElementSave elementSave, StateSave state, ref bool wasModified)
        {
            foreach (var variable in state.Variables.Where(item => item.Type == "string" && item.Name.Contains("State")))
            {
                string name = variable.Name;

                var withoutState = name.Substring(0, name.Length - "State".Length);
                if (variable.Name == "State")
                {
                    variable.Type = "State";
                    wasModified   = true;
                }
                else if (elementSave.Categories.Any(item => item.Name == withoutState))
                {
                    variable.Type = withoutState;
                    wasModified   = true;
                }
            }
        }
Esempio n. 5
0
        private static void RemoveDuplicateVariables(StateSave state)
        {
            List <string> alreadyVisitedVariables = new List <string>();

            for (int i = 0; i < state.Variables.Count; i++)
            {
                string variableName = state.Variables[i].Name;

                if (alreadyVisitedVariables.Contains(variableName))
                {
                    state.Variables.RemoveAt(i);
                    i--;
                }
                else
                {
                    alreadyVisitedVariables.Add(variableName);
                }
            }
        }
        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");
            }

        }
Esempio n. 7
0
        public static UndoObject CreateUndoObject(StateSave objectToSave, List <InstanceSave> instances, object parent)
        {
            StateSave           cloned          = FileManager.CloneSaveObject(objectToSave);
            List <InstanceSave> instancesCloned = null;

            if (instances != null)
            {
                instancesCloned = new List <InstanceSave>();
                foreach (var instance in instances)
                {
                    instancesCloned.Add(instance); // no need to clone this, I don't think
                }
            }
            UndoObject undoObject = new UndoObject(
                cloned,
                instancesCloned,
                parent);

            return(undoObject);
        }
Esempio n. 8
0
        public void SetValue(object component, object value)
        {
            ElementSave  elementSave  = SelectedState.Self.SelectedElement;
            StateSave    stateSave    = SelectedState.Self.SelectedStateSave;
            InstanceSave instanceSave = SelectedState.Self.SelectedInstance;

            //////////////// Early Out/////////////
            if (stateSave == null || elementSave == null)
            {
                return;
            }


            ///////////////End Early Out///////////

            string name = GetVariableNameConsideringSelection();



            // <None> is a reserved
            // value for when we want
            // to allow the user to reset
            // a value through a combo box.
            // If the value is "<None>" then
            // let's set it to null
            if (value is string && ((string)value) == "<None>")
            {
                value = null;
            }

            string variableType     = null;
            var    existingVariable = elementSave.GetVariableFromThisOrBase(name);

            if (existingVariable != null)
            {
                variableType = existingVariable.Type;
            }


            stateSave.SetValue(name, value, instanceSave, variableType);
        }
Esempio n. 9
0
        private void PastedCopiedState()
        {
            ElementSave container = SelectedState.Self.SelectedElement;

            /////////////////////Early Out//////////////////
            if (container == null)
            {
                return;
            }
            //////////////////End Early Out////////////////

            if (container.Categories.Count != 0)
            {
                MessageBox.Show("Pasting into elements with state categories may cause unexpected results.  Please complain on codeplex!");
            }


            StateSave newStateSave = mCopiedState.Clone();

            newStateSave.Variables.RemoveAll(item => item.CanOnlyBeSetInDefaultState);


            newStateSave.ParentContainer = container;

            string name = mCopiedState.Name + "Copy";

            name = StringFunctions.MakeStringUnique(name, container.States.Select(item => item.Name));

            newStateSave.Name = name;

            container.States.Add(newStateSave);

            StateTreeViewManager.Self.RefreshUI(container);



            //SelectedState.Self.SelectedInstance = targetInstance;
            SelectedState.Self.SelectedStateSave = newStateSave;

            GumCommands.Self.FileCommands.TryAutoSaveElement(container);
        }
Esempio n. 10
0
        public override System.ComponentModel.PropertyDescriptorCollection GetProperties(Attribute[] attributes)
        {
            PropertyDescriptorCollection pdc =
                TypeDescriptor.GetProperties(this, true);


            StateSave    stateSave    = SelectedState.Self.SelectedStateSave;
            ElementSave  elementSave  = SelectedState.Self.SelectedElement;
            InstanceSave instanceSave = SelectedState.Self.SelectedInstance;

            if (instanceSave != null && stateSave != null)
            {
                pdc = DisplayCurrentInstance(pdc, instanceSave);
            }
            else if (elementSave != null && stateSave != null)
            {
                pdc = DisplayCurrentElement(pdc, elementSave, null, elementSave.States[0], null);
            }

            return(pdc);
        }
Esempio n. 11
0
        public StateViewModel(StateSave state, StateSaveCategory category, IElement element)
        {
            this.category = category;
            this.element  = element;

            BackingData = state;

            Variables = new ObservableCollection <object>();
            Name      = state?.Name;

            for (int i = 0; i < element.CustomVariables.Count; i++)
            {
                var variable = element.CustomVariables[i];

                // see if there is a value for this variable
                var instruction =
                    state?.InstructionSaves.FirstOrDefault(item => item.Member == variable.Name);

                this.Variables.Add(instruction?.Value);
            }
        }
        private static void FillWithDefaultRecursively(ElementSave element, StateSave stateSave)
        {
            foreach (var variable in element.DefaultState.Variables)
            {
                var alreadyExists = stateSave.Variables.Any(item => item.Name == variable.Name);

                if (!alreadyExists)
                {
                    stateSave.Variables.Add(variable);
                }
            }

            if (!string.IsNullOrEmpty(element.BaseType))
            {
                var baseElement = ObjectFinder.Self.GetElementSave(element.BaseType);
                if (baseElement != null)
                {
                    FillWithDefaultRecursively(baseElement, stateSave);
                }
            }
        }
Esempio n. 13
0
        private List <MemberCategory> GetMemberCategories(ElementSave element, StateSave state, StateSaveCategory stateCategory, InstanceSave instance)
        {
            List <MemberCategory> categories = new List <MemberCategory>();

            mLastElement  = element;
            mLastState    = state;
            mLastInstance = instance;
            mLastCategory = stateCategory;

            var stateSave = SelectedState.Self.SelectedStateSave;

            if (stateSave != null)
            {
                GetMemberCategoriesForState(element, instance, categories, stateSave, stateCategory);
            }
            else if (stateCategory != null)
            {
                GetMemberCategoriesForStateCategory(element, instance, categories, stateCategory);
            }
            return(categories);
        }
Esempio n. 14
0
        public void Deserialize(ScriptData instance, StateSave save)
        {
            instance.State                      = save.State;
            instance.Running                    = save.Running;
            instance.EventDelayTicks            = (long)save.MinEventDelay;
            instance.AssemblyName               = save.AssemblyName;
            instance.Disabled                   = save.Disabled;
            instance.UserInventoryItemID        = save.UserInventoryID;
            instance.PluginData                 = save.Plugins;
            instance.Source                     = save.Source;
            instance.InventoryItem.PermsGranter = save.PermsGranter;
            instance.InventoryItem.PermsMask    = save.PermsMask;
            instance.TargetOmegaWasSet          = save.TargetOmegaWasSet;

            Dictionary <string, object> vars = WebUtils.ParseXmlResponse(save.Variables);

            if (vars != null && vars.Count != 0 || instance.Script != null)
            {
                instance.Script.SetStoreVars(vars);
            }
        }
Esempio n. 15
0
        bool GetIfCanMoveUp(StateSave state, StateSaveCategory category)
        {
            var list = SelectedState.Self.SelectedElement.States;

            if (category != null)
            {
                list = category.States;
            }

            int stateIndex = list.IndexOf(state);

            int indexToBeGreaterThan = 0;

            if (category == null)
            {
                // Uncategorized, so it can't move up above the Default state
                indexToBeGreaterThan = 1;
            }

            return(stateIndex > indexToBeGreaterThan);
        }
Esempio n. 16
0
        private void HandlePropertyOnStateChanged(object sender, PropertyChangedEventArgs e)
        {
            if (e.PropertyName == nameof(StateViewModel.Name))
            {
                StateViewModel selectedViewModel = sender as StateViewModel;
                StateSave      stateSave         = selectedViewModel.BackingData;

                var needsToCreateNewState = selectedViewModel.BackingData == null &&
                                            !string.IsNullOrEmpty(selectedViewModel.Name) &&
                                            selectedViewModel.IsNameInvalid == false;

                if (needsToCreateNewState)
                {
                    stateSave      = new StateSave();
                    stateSave.Name = selectedViewModel.Name;
                    var category = GlueState.Self.CurrentStateSaveCategory;
                    category.States.Add(stateSave);
                    selectedViewModel.BackingData = stateSave;

                    // Add a new entry so the user can create more states easily:
                    CreateBlankViewModelAtEnd(GlueState.Self.CurrentElement);

                    CopyViewModelValuesToState(selectedViewModel, stateSave);
                }

                if (selectedViewModel.IsNameInvalid == false)
                {
                    stateSave.Name = selectedViewModel.Name;

                    GlueCommands.Self.GenerateCodeCommands.GenerateAllCodeTask();
                    GlueCommands.Self.GluxCommands.SaveGluxTask();
                }
                GlueCommands.Self.RefreshCommands.RefreshUi(this.category);

                if (string.IsNullOrEmpty(selectedViewModel.Name))
                {
                    CheckForStateRemoval(selectedViewModel);
                }
            }
        }
Esempio n. 17
0
        public void ApplyValueToModel(object value, StateViewModel stateViewModel, StateSave stateSave, CustomVariable variable)
        {
            if (value == null || value as string == String.Empty)
            {
                var existingInstruction = stateSave?.InstructionSaves.FirstOrDefault(item => item.Member == variable.Name);

                if (existingInstruction != null)
                {
                    stateSave.InstructionSaves.Remove(existingInstruction);
                }

                CheckForStateRemoval(stateViewModel);
            }
            else
            {
                try
                {
                    var convertedValue = Convert(value, variable);
                    // This could have converted incorrectly.
                    if (convertedValue != null)
                    {
                        stateSave.SetValue(variable.Name, convertedValue);
                    }
                    else
                    {
                        var existingInstruction = stateSave?.InstructionSaves.FirstOrDefault(item => item.Member == variable.Name);

                        if (existingInstruction != null)
                        {
                            stateSave.InstructionSaves.Remove(existingInstruction);
                        }
                    }
                }
                catch (Exception e)
                {
                    GlueCommands.Self.PrintError(
                        $"Could not assign variable {variable.Name} ({variable.Type}) to \"{value}\":\n{e.ToString()}");
                }
            }
        }
Esempio n. 18
0
        public static void AddDimensionsVariables(StateSave stateSave, float defaultWidth, float defaultHeight, DimensionVariableAction dimensionVariableAction)
        {
            stateSave.Variables.Add(new VariableSave {
                SetsValue = true, Type = "float", Value = defaultWidth, Name = "Width", Category = "Dimensions"
            });

            var defaultValue = DimensionUnitType.Absolute;

            if (dimensionVariableAction == DimensionVariableAction.DefaultToPercentageOfFile)
            {
                defaultValue = DimensionUnitType.PercentageOfSourceFile;
            }

            VariableSave variableSave = new VariableSave {
                SetsValue = true, Type = typeof(DimensionUnitType).Name, Value = defaultValue, Name = "Width Units", Category = "Dimensions"
            };

            if (dimensionVariableAction == DimensionVariableAction.ExcludeFileOptions)
            {
                variableSave.ExcludedValuesForEnum.Add(DimensionUnitType.PercentageOfSourceFile);
                variableSave.ExcludedValuesForEnum.Add(DimensionUnitType.MaintainFileAspectRatio);
            }
            stateSave.Variables.Add(variableSave);



            stateSave.Variables.Add(new VariableSave {
                SetsValue = true, Type = "float", Value = defaultHeight, Name = "Height", Category = "Dimensions"
            });

            variableSave = new VariableSave {
                SetsValue = true, Type = typeof(DimensionUnitType).Name, Value = defaultValue, Name = "Height Units", Category = "Dimensions"
            };
            if (dimensionVariableAction == DimensionVariableAction.ExcludeFileOptions)
            {
                variableSave.ExcludedValuesForEnum.Add(DimensionUnitType.PercentageOfSourceFile);
                variableSave.ExcludedValuesForEnum.Add(DimensionUnitType.MaintainFileAspectRatio);
            }
            stateSave.Variables.Add(variableSave);
        }
Esempio n. 19
0
        private void HandleElementBaseType(ElementSave asElementSave)
        {
            string newValue = asElementSave.BaseType;

            // kill the old instances:
            asElementSave.Instances.RemoveAll(item => item.DefinedByBase);

            if (StandardElementsManager.Self.IsDefaultType(newValue))
            {
                StateSave defaultStateSave = StandardElementsManager.Self.GetDefaultStateFor(newValue);

                asElementSave.Initialize(defaultStateSave);
            }
            else
            {
                var baseElement = ObjectFinder.Self.GetElementSave(asElementSave.BaseType);

                StateSave stateSave = new StateSave();
                if (baseElement != null)
                {
                    // This copies the values to this explicitly, which we don't want
                    //FillWithDefaultRecursively(baseElement, stateSave);


                    foreach (var instance in baseElement.Instances)
                    {
                        var derivedInstance = instance.Clone();
                        derivedInstance.DefinedByBase = true;
                        asElementSave.Instances.Add(derivedInstance);
                    }
                    asElementSave.Initialize(stateSave);
                }
            }
            const bool fullRefresh = true;

            // since the type might change:
            GumCommands.Self.GuiCommands.RefreshElementTreeView(asElementSave);
            PropertyGridManager.Self.RefreshUI(fullRefresh);
            StateTreeViewManager.Self.RefreshUI(asElementSave);
        }
        public void ReactToStateSaveChangedValue(StateSave stateSave, StateSaveCategory category, string changedMember, object oldValue, IElement parentObject, ref bool updateTreeView)
        {
            if (changedMember != "Name")
            {
                updateTreeView = false;
            }

            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);
                }
            }
        }
        public static object GetValueFromThisOrBase(this ElementSave element, string variable, bool forceDefault = false)
        {
            StateSave stateToPullFrom = element.DefaultState;

#if GUM
            if (element == SelectedState.Self.SelectedElement &&
                SelectedState.Self.SelectedStateSave != null &&
                !forceDefault)
            {
                stateToPullFrom = SelectedState.Self.SelectedStateSave;
            }
#endif
            VariableSave variableSave = stateToPullFrom.GetVariableRecursive(variable);
            if (variableSave != null)
            {
                return(variableSave.Value);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 22
0
        public object GetValue(string variableName)
        {
            StateSave stateSave = Instance as StateSave;

            foreach (InstructionSave instructionSave in stateSave.InstructionSaves)
            {
                if (instructionSave.Member == variableName)
                {
                    return(instructionSave.Value);
                }
            }

            //NamedObjectPropertyOverride propertyOverride = stateSave.GetNamedObjectOverride(variableName);

            //if (propertyOverride != null)
            //{
            //    return propertyOverride;
            //}
            //else
            //{
            //    IElement element = ObjectFinder.Self.GetElementContaining(stateSave);

            //    if (element != null)
            //    {
            //        NamedObjectSave namedObject = element.GetNamedObjectRecursively(variableName);
            //        if (namedObject != null)
            //        {
            //            propertyOverride = new NamedObjectPropertyOverride();

            //            propertyOverride.Name = variableName;

            //            return propertyOverride;
            //        }
            //    }
            //}


            return(null);
        }
Esempio n. 23
0
        public StateSave FindScriptStateSave(ScriptData script)
        {
            OSDMap component = m_manager.GetComponentState(script.Part, m_componentName) as OSDMap;

            //Attempt to find the state saves we have
            if (component != null)
            {
                OSD o;
                //If we have one for this item, deserialize it
                if (!component.TryGetValue(script.ItemID.ToString(), out o))
                {
                    if (!component.TryGetValue(script.InventoryItem.OldItemID.ToString(), out o))
                    {
                        return(null);
                    }
                }
                StateSave save = new StateSave();
                save.FromOSD((OSDMap)o);
                return(save);
            }
            return(null);
        }
Esempio n. 24
0
        private static StateSave GetRecursiveStateFor(ElementSave elementSave, StateSave stateToAddTo = null)
        {
            // go bottom up
            var baseElement = ObjectFinder.Self.GetElementSave(elementSave.BaseType);

            if (baseElement != null)
            {
                stateToAddTo = GetRecursiveStateFor(baseElement, stateToAddTo);
            }
            if (stateToAddTo == null)
            {
                stateToAddTo = new StateSave();
            }


            var existingVariableNames = stateToAddTo.Variables.Select(item => item.Name);

            if (elementSave is StandardElementSave)
            {
                var defaultStates  = StandardElementsManager.Self.GetDefaultStateFor(elementSave.Name);
                var variablesToAdd = defaultStates.Variables
                                     .Select(item => item.Clone())
                                     .Where(item => existingVariableNames.Contains(item.Name) == false);

                stateToAddTo.Variables.AddRange(variablesToAdd);
            }
            else
            {
                var variablesToAdd = elementSave.DefaultState.Variables
                                     .Select(item => item.Clone())
                                     .Where(item => existingVariableNames.Contains(item.Name) == false);

                stateToAddTo.Variables.AddRange(variablesToAdd);
            }



            return(stateToAddTo);
        }
Esempio n. 25
0
        public void SaveStateTo(ScriptData script)
        {
            StateSave stateSave = new StateSave();

            stateSave.State           = script.State;
            stateSave.ItemID          = script.ItemID;
            stateSave.Running         = script.Running;
            stateSave.MinEventDelay   = script.EventDelayTicks;
            stateSave.Disabled        = script.Disabled;
            stateSave.UserInventoryID = script.UserInventoryItemID;
            //Allow for the full path to be put down, not just the assembly name itself
            stateSave.AssemblyName = script.AssemblyName;
            stateSave.Source       = script.Source;
            if (script.InventoryItem != null)
            {
                stateSave.PermsGranter = script.InventoryItem.PermsGranter;
                stateSave.PermsMask    = script.InventoryItem.PermsMask;
            }
            else
            {
                stateSave.PermsGranter = UUID.Zero;
                stateSave.PermsMask    = 0;
            }
            stateSave.TargetOmegaWasSet = script.TargetOmegaWasSet;

            //Vars
            Dictionary <string, Object> vars = new Dictionary <string, object> ();

            if (script.Script != null)
            {
                vars = script.Script.GetStoreVars();
            }
            stateSave.Variables = WebUtils.BuildXmlResponse(vars);

            //Plugins
            stateSave.Plugins = m_module.GetSerializationData(script.ItemID, script.Part.UUID);

            CreateOSDMapForState(script, stateSave);
        }
Esempio n. 26
0
        public void InterpolateToRatio(float ratio, bool isLevelUp)
        {
            var currentRatio = Bar.Height / MaxHeight;

            var currentState = new StateSave();

            currentState.SetValue(nameof(Bar.Height), Bar.Height, "float");

            float newHeight;

            if (!isLevelUp)
            {
                newHeight = ratio * MaxHeight;
            }
            else
            {
                newHeight = MaxHeight;
            }

            var newState = new StateSave();

            newState.SetValue(nameof(Bar.Height), newHeight, "float");

            Bar.InterpolateTo(currentState, newState, 1, FlatRedBall.Glue.StateInterpolation.InterpolationType.Exponential, FlatRedBall.Glue.StateInterpolation.Easing.Out);

            if (isLevelUp)
            {
                CurrentScreen.Call(() =>
                {
                    Bar.Height = 0;
                    if (ratio > 0)
                    {
                        InterpolateToRatio(ratio, false);
                    }
                })
                .After(1.1f);
            }
        }
Esempio n. 27
0
        internal void RenameState(StateSave stateSave, IStateContainer stateContainer)
        {
            var behaviorNeedingState = GetBehaviorsNeedingState(stateSave);

            if (behaviorNeedingState.Any())
            {
                string message =
                    "This state cannot be removed because it is needed by the following behavior(s):";

                foreach (var behavior in behaviorNeedingState)
                {
                    message += "\n" + behavior.Name;
                }

                MessageBox.Show(message);
            }
            else
            {
                TextInputWindow tiw = new TextInputWindow();
                tiw.Message = "Enter new state name";
                tiw.Result  = SelectedState.Self.SelectedStateSave.Name;
                var result = tiw.ShowDialog();

                if (result == DialogResult.OK)
                {
                    string oldName = stateSave.Name;

                    stateSave.Name = tiw.Result;
                    GumCommands.Self.GuiCommands.RefreshStateTreeView();
                    // I don't think we need to save the project when renaming a state:
                    //GumCommands.Self.FileCommands.TryAutoSaveProject();

                    PluginManager.Self.StateRename(stateSave, oldName);

                    GumCommands.Self.FileCommands.TryAutoSaveCurrentElement();
                }
            }
        }
Esempio n. 28
0
        private static void DuplicateStateClick()
        {
            // Is there a "custom" current state save, like an interpolation or animation?
            if (SelectedState.Self.CustomCurrentStateSave != null)
            {
                GumCommands.Self.GuiCommands.ShowMessage("Cannot duplicate state while a custom state is displaying. Are you creating or playing animations?");
                return;
            }
            ////////End Early Out///////////////

            StateSave newState = SelectedState.Self.SelectedStateSave.Clone();


            newState.ParentContainer = SelectedState.Self.SelectedElement;

            if (SelectedState.Self.SelectedStateCategorySave == null)
            {
                int index = SelectedState.Self.SelectedElement.States.IndexOf(SelectedState.Self.SelectedStateSave);
                SelectedState.Self.SelectedElement.States.Insert(index + 1, newState);
            }
            else
            {
                int index = SelectedState.Self.SelectedStateCategorySave.States.IndexOf(SelectedState.Self.SelectedStateSave);
                SelectedState.Self.SelectedStateCategorySave.States.Insert(index + 1, newState);
            }


            while (SelectedState.Self.SelectedStateContainer.AllStates.Any(item => item != newState && item.Name == newState.Name))
            {
                newState.Name = StringFunctions.IncrementNumberAtEnd(newState.Name);
            }

            StateTreeViewManager.Self.RefreshUI(SelectedState.Self.SelectedElement);

            SelectedState.Self.SelectedStateSave = newState;

            GumCommands.Self.FileCommands.TryAutoSaveCurrentElement();
        }
Esempio n. 29
0
        private static void StoreCopiedInstances()
        {
            if (SelectedState.Self.SelectedInstance != null)
            {
                var element = SelectedState.Self.SelectedElement;

                List <InstanceSave> selected = new List <InstanceSave>();
                // When copying we want to grab all instances in the order that they are in their container.
                // That way when they're pasted they are pasted in the right order
                foreach (var instance in SelectedState.Self.SelectedInstances.OrderBy(item => element.Instances.IndexOf(item)))
                {
                    selected.Add(instance.Clone());
                }

                mCopiedInstances =
                    GetAllInstancesAndChildrenOf(selected, selected.FirstOrDefault()?.ParentContainer);

                mCopiedState = SelectedState.Self.SelectedStateSave?.Clone() ?? SelectedState.Self.SelectedElement.DefaultState.Clone();

                // Clear out any variables that don't pertain to the selected instance:
                for (int i = mCopiedState.Variables.Count - 1; i > -1; i--)
                {
                    if (mCopiedInstances.Any(item => item.Name == mCopiedState.Variables[i].SourceObject) == false)
                    {
                        mCopiedState.Variables.RemoveAt(i);
                    }
                }

                // And also any VariableLists:
                for (int i = mCopiedState.VariableLists.Count - 1; i > -1; i--)
                {
                    if (mCopiedInstances.Any(item => item.Name == mCopiedState.VariableLists[i].SourceObject) == false)
                    {
                        mCopiedState.VariableLists.RemoveAt(i);
                    }
                }
            }
        }
Esempio n. 30
0
        public List <InstanceSavePropertyDescriptor> GetProperties(Attribute[] attributes)
        {
            // search terms: display properties, display variables, show variables, variable display, variable displayer
            List <InstanceSavePropertyDescriptor> pdc = new List <InstanceSavePropertyDescriptor>();


            StateSave    stateSave    = SelectedState.Self.SelectedStateSave;
            ElementSave  elementSave  = SelectedState.Self.SelectedElement;
            InstanceSave instanceSave = SelectedState.Self.SelectedInstance;

            if (instanceSave != null && stateSave != null)
            {
                DisplayCurrentInstance(pdc, instanceSave);
            }
            else if (elementSave != null && stateSave != null)
            {
                StateSave defaultState = GetRecursiveStateFor(elementSave);

                DisplayCurrentElement(pdc, elementSave, null, defaultState, null);
            }

            return(pdc);
        }
        private static void MakeDefaultClick()
        {
            StateSave state = SelectedState.Self.SelectedStateSave;

            var element = SelectedState.Self.SelectedElement;

            if (!element.States.Contains(state))
            {
                // It's categorized
                MessageBox.Show("Categorized states cannot be made default");
            }
            else
            {
                element.States.Remove(state);
                element.States.Insert(0, state);

                StateTreeViewManager.Self.RefreshUI(SelectedState.Self.SelectedElement);

                SelectedState.Self.SelectedStateSave = state;

                GumCommands.Self.FileCommands.TryAutoSaveCurrentElement();
            }
        }
Esempio n. 32
0
        public void PasteInstanceSaves(List <InstanceSave> copiedInstances, StateSave copiedState, ElementSave targetElement)
        {
            List <InstanceSave> newInstances = new List <InstanceSave>();

            foreach (var instanceAsObject in copiedInstances)
            {
                InstanceSave sourceInstance = instanceAsObject as InstanceSave;
                ElementSave  sourceElement  = sourceInstance.ParentContainer;

                InstanceSave targetInstance = sourceInstance.Clone();
                newInstances.Add(targetInstance);

                if (targetElement != null)
                {
                    PastedCopiedInstance(sourceInstance, sourceElement, targetElement, targetInstance, copiedState);
                }
            }

            if (newInstances.Count > 1)
            {
                SelectedState.Self.SelectedInstances = newInstances;
            }
        }
Esempio n. 33
0
        public void RemoveState(StateSave stateSave, ElementSave elementToRemoveFrom)
        {
            elementToRemoveFrom.States.Remove(stateSave);

            foreach (var category in elementToRemoveFrom.Categories.Where(item => item.States.Contains(stateSave)))
            {
                category.States.Remove(stateSave);
            }

            GumCommands.Self.FileCommands.TryAutoSaveCurrentElement();
        }
        private static void AddPositioningVariables(StateSave stateSave)
        {
            List<object> xUnitsExclusions = new List<object>();
            xUnitsExclusions.Add(PositionUnitType.PixelsFromTop);
            xUnitsExclusions.Add(PositionUnitType.PercentageHeight);
            xUnitsExclusions.Add(PositionUnitType.PixelsFromBottom);
            xUnitsExclusions.Add(PositionUnitType.PixelsFromCenterY);
            xUnitsExclusions.Add(PositionUnitType.PixelsFromCenterYInverted);

            List<object> yUnitsExclusions = new List<object>();
            yUnitsExclusions.Add(PositionUnitType.PixelsFromLeft);
            yUnitsExclusions.Add(PositionUnitType.PixelsFromCenterX);
            yUnitsExclusions.Add(PositionUnitType.PercentageWidth);
            yUnitsExclusions.Add(PositionUnitType.PixelsFromRight);


            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "float", Value = 0.0f, Name = "X", Category = "Position" });
            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = typeof(PositionUnitType).Name, Value = PositionUnitType.PixelsFromLeft, Name = "X Units", Category = "Position", ExcludedValuesForEnum = xUnitsExclusions });

            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "float", Value = 0.0f, Name = "Y", Category = "Position" });
            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = typeof(PositionUnitType).Name, Value = PositionUnitType.PixelsFromTop, Name = "Y Units", Category = "Position", ExcludedValuesForEnum = yUnitsExclusions });

            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "HorizontalAlignment", Value = HorizontalAlignment.Left, Name = "X Origin", Category = "Position" });
            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "VerticalAlignment", Value = VerticalAlignment.Top, Name = "Y Origin", Category = "Position" });

            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "string", Value = null, Name = "Guide", Category = "Position" });
#if GUM
            AddParentVariables(stateSave);
#endif
        }
 private static void AddParentVariables(StateSave variables)
 {
     VariableSave variableSave = new VariableSave();
     variableSave.SetsValue = true;
     variableSave.Type = "string";
     variableSave.Name = "Parent";
     variableSave.CanOnlyBeSetInDefaultState = true;
     variableSave.CustomTypeConverter = new AvailableInstancesConverter() { IncludeScreenBounds = true };
     variables.Variables.Add(variableSave);
 }
Esempio n. 36
0
        public void Deserialize(ScriptData instance, StateSave save)
        {
            instance.State = save.State;
            instance.Running = save.Running;
            instance.EventDelayTicks = (long) save.MinEventDelay;
            instance.AssemblyName = save.AssemblyName;
            instance.Disabled = save.Disabled;
            instance.UserInventoryItemID = save.UserInventoryID;
            if (save.Plugins != "")
                instance.PluginData = (OSDMap) OSDParser.DeserializeJson(save.Plugins);
            m_module.CreateFromData(instance.Part.UUID, instance.ItemID, instance.Part.UUID,
                                    instance.PluginData);
            instance.Source = save.Source;
            instance.InventoryItem.PermsGranter = save.PermsGranter;
            instance.InventoryItem.PermsMask = save.PermsMask;
            instance.TargetOmegaWasSet = save.TargetOmegaWasSet;

            if (save.Variables != null && instance.Script != null)
                instance.Script.SetStoreVars(XMLUtils.ParseXmlResponse(save.Variables));
        }
        private static void AddDimensionsVariables(StateSave stateSave, float defaultWidth, float defaultHeight, DimensionVariableAction dimensionVariableAction)
        {
            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "float", Value = defaultWidth, Name = "Width", Category = "Dimensions" });

            var defaultValue = DimensionUnitType.Absolute;

            if(dimensionVariableAction == DimensionVariableAction.DefaultToPercentageOfFile)
            {
                defaultValue = DimensionUnitType.PercentageOfSourceFile;
            }

            VariableSave variableSave = new VariableSave { SetsValue = true, Type = typeof(DimensionUnitType).Name, Value = defaultValue, Name = "Width Units", Category = "Dimensions" };
            if (dimensionVariableAction == DimensionVariableAction.ExcludeFileOptions)
            {
                variableSave.ExcludedValuesForEnum.Add(DimensionUnitType.PercentageOfSourceFile);
            }
            stateSave.Variables.Add(variableSave);



            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "float", Value = defaultHeight, Name = "Height", Category = "Dimensions" });

            variableSave = new VariableSave { SetsValue = true, Type = typeof(DimensionUnitType).Name, Value = defaultValue, Name = "Height Units", Category = "Dimensions" };
            if (dimensionVariableAction == DimensionVariableAction.ExcludeFileOptions)
            {
                variableSave.ExcludedValuesForEnum.Add(DimensionUnitType.PercentageOfSourceFile);
            }
            stateSave.Variables.Add(variableSave);
        }
Esempio n. 38
0
        public void Select(StateSave stateSave)
        {
            TreeNode treeNode = GetTreeNodeForTag(stateSave);

            Select(treeNode);
        }
Esempio n. 39
0
 UndoObject(StateSave objectToSave, List<InstanceSave> instances, object parent)
 {
     mStateSave = objectToSave;
     Instances = instances;
     Parent = parent;
 }
Esempio n. 40
0
        internal void ModifyDefaultStandardState(string type, StateSave stateSave)
        {
            CallMethodOnPlugin(
                delegate(PluginBase plugin)
                {
                    plugin.CallAddAndRemoveVariablesForType(type, stateSave);

                },
                "ModifyDefaultStandardState"
                );
        }
        public void Initialize()
        {
            mDefaults = new Dictionary<string, StateSave>();

            // Eventually this would get read from somewhere like an XML file
            // or a CSV file, but for
            // now we'll just use hard values.
            


            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //                                                     Text                                                           //
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            StateSave stateSave = new StateSave();
            stateSave.Name = "Default";
            AddPositioningVariables(stateSave);
            AddDimensionsVariables(stateSave, 100, 50, DimensionVariableAction.ExcludeFileOptions);
            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "bool", Value = true, Name = "Visible" });
            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "string", Value = "Hello", Name = "Text", Category = "Text" });
            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "VerticalAlignment", Value = VerticalAlignment.Top, Name = "VerticalAlignment", Category = "Text" });
            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "HorizontalAlignment", Value = HorizontalAlignment.Left, Name = "HorizontalAlignment", Category = "Text" });

            // font:
            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "bool", Value = false, Name = "UseCustomFont", Category = "Font" });
            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "string", Value = "Arial", Name = "Font", IsFont = true, Category = "Font" });
            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "int", Value = 18, Name = "FontSize", Category = "Font" });
            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "int", Value = 0, Name = "OutlineThickness", Category = "Font" });
            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "string", Value = "", Name = "CustomFontFile", Category = "Font", IsFile = true });
            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "float", Value = 1.0f, Name = "Font Scale", Category = "Font" });

            stateSave.Variables.Add(new VariableSave { Type = "float", Value = 0.0f, Category = "Flip and Rotation", Name = "Rotation" });
            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "bool", Value = false, Name = "HasEvents", Category = "Behavior", CanOnlyBeSetInDefaultState = true });

            AddStateVariable(stateSave);

            AddColorVariables(stateSave, includeAlpha:true);

#if GUM
            PluginManager.Self.ModifyDefaultStandardState("Text", stateSave);
#endif

            ApplySortValuesFromOrderInState(stateSave);

            mDefaults.Add("Text", stateSave);
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////






            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //                                                     Sprite                                                         //
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            stateSave = new StateSave();
            stateSave.Name = "Default";
            AddPositioningVariables(stateSave);
            AddDimensionsVariables(stateSave, 100, 100, DimensionVariableAction.DefaultToPercentageOfFile);
            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "string", Value = "", Name = "SourceFile", IsFile = true });
            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "bool", Value = true, Name = "Visible" });
            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "bool", Value = false, Category = "Animation", Name = "Animate" });

            stateSave.Variables.Add(new VariableSave { Type = "float", Value = 0.0f, Category = "Flip and Rotation", Name = "Rotation" });
            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "bool", Value = false, Category = "Flip", Name = "FlipHorizontal" });
            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "bool", Value = false, Category = "Flip", Name = "FlipVertical" });


            //stateSave.Variables.Add(new VariableSave { Type = "bool", Value = false, Name = "Custom Texture Coordinates", Category="Source" });
            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "TextureAddress", Value = Gum.Managers.TextureAddress.EntireTexture, Name = "Texture Address", Category = "Source" });

            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "int", Value = 0, Name = "Texture Top", Category = "Source" });
            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "int", Value = 0, Name = "Texture Left", Category = "Source" });
            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "int", Value = 0, Name = "Texture Width", Category = "Source" });
            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "int", Value = 0, Name = "Texture Height", Category = "Source" });

            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "float", Value = 0.0f, Name = "Texture Width Scale", Category = "Source" });
            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "float", Value = 0.0f, Name = "Texture Height Scale", Category = "Source" });

            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "bool", Value = false, Name = "Wrap", Category = "Source" });
            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "bool", Value = false, Name = "HasEvents", Category = "Behavior", CanOnlyBeSetInDefaultState = true });


            AddColorVariables(stateSave);


            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "Blend", Value = Blend.Normal, Name = "Blend", Category = "Rendering" });

            AddStateVariable(stateSave);


            List<string> list = new List<string>();
            stateSave.VariableLists.Add(new VariableListSave<string> { Type = "string", Value = list, Category = "Animation", Name = "AnimationFrames"});
#if GUM
            PluginManager.Self.ModifyDefaultStandardState("Sprite", stateSave);
#endif
            ApplySortValuesFromOrderInState(stateSave);


            mDefaults.Add("Sprite", stateSave);
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////








            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //                                                   Container                                                        //
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            stateSave = new StateSave();
            stateSave.Name = "Default";

            AddPositioningVariables(stateSave);

            AddDimensionsVariables(stateSave, 150, 150, DimensionVariableAction.ExcludeFileOptions);

            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "bool", Value = true, Name = "Visible" });
            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "ChildrenLayout", Value = ChildrenLayout.Regular, Name = "Children Layout" });
            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "bool", Value = false, Name = "Wraps Children" });
            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "bool", Value = false, Name = "Clips Children" });

            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "bool", Value = false, Name = "HasEvents", Category = "Behavior", CanOnlyBeSetInDefaultState = true });
#if GUM
            PluginManager.Self.ModifyDefaultStandardState("Container", stateSave);
#endif
            ApplySortValuesFromOrderInState(stateSave);

            mDefaults.Add("Container", stateSave);
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////







            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //                                               ColoredRectangle                                                     //
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            stateSave = new StateSave();
            stateSave.Name = "Default";

            AddPositioningVariables(stateSave);

            AddDimensionsVariables(stateSave, 50, 50, DimensionVariableAction.ExcludeFileOptions);

            stateSave.Variables.Add(new VariableSave { Type = "float", Value = 0.0f, Category = "Flip and Rotation", Name = "Rotation" });


            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "bool", Value = true, Name = "Visible" });
            AddColorVariables(stateSave, true);

            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "Blend", Value = Blend.Normal, Name = "Blend", Category = "Rendering" });
            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "bool", Value = false, Name = "HasEvents", Category = "Behavior", CanOnlyBeSetInDefaultState = true });
            AddStateVariable(stateSave);

#if GUM
            PluginManager.Self.ModifyDefaultStandardState("ColoredRectangle", stateSave);
#endif
            ApplySortValuesFromOrderInState(stateSave);

            mDefaults.Add("ColoredRectangle", stateSave);
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////






            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //                                               Circle                                                               //
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            stateSave = new StateSave();
            stateSave.Name = "Default";

            AddPositioningVariables(stateSave);

            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "float", Value = 16.0f, Name = "Radius" });
            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "float", Value = 16.0f, Name = "Width", IsHiddenInPropertyGrid = true });
            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "float", Value = 16.0f, Name = "Height", IsHiddenInPropertyGrid = true });

            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "bool", Value = true, Name = "Visible" });
            //AddColorVariables(stateSave, true);
            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "bool", Value = false, Name = "HasEvents", Category = "Behavior", CanOnlyBeSetInDefaultState = true });
            AddStateVariable(stateSave);

#if GUM
            PluginManager.Self.ModifyDefaultStandardState("Circle", stateSave);
#endif
            ApplySortValuesFromOrderInState(stateSave);

            mDefaults.Add("Circle", stateSave);
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////



            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //                                               Rectangle                                                            //
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            stateSave = new StateSave();
            stateSave.Name = "Default";

            AddPositioningVariables(stateSave);

            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "float", Value = 16.0f, Name = "Width" });
            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "float", Value = 16.0f, Name = "Height" });

            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "bool", Value = true, Name = "Visible" });
            //AddColorVariables(stateSave, true);
            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "bool", Value = false, Name = "HasEvents", Category = "Behavior", CanOnlyBeSetInDefaultState = true });
            AddStateVariable(stateSave);

#if GUM
            PluginManager.Self.ModifyDefaultStandardState("Rectangle", stateSave);
#endif
            ApplySortValuesFromOrderInState(stateSave);

            mDefaults.Add("Rectangle", stateSave);
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////






            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //                                                    NineSlice                                                         //
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            stateSave = new StateSave();
            stateSave.Name = "Default";
            AddPositioningVariables(stateSave);
            AddDimensionsVariables(stateSave, 64, 64, DimensionVariableAction.ExcludeFileOptions);
            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "string", Value = "", Name = "SourceFile", IsFile = true });
            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "bool", Value = true, Name = "Visible" });

            AddColorVariables(stateSave);
            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "Blend", Value = Blend.Normal, Name = "Blend", Category = "Rendering" });

            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "TextureAddress", Value = Gum.Managers.TextureAddress.EntireTexture, Name = "Texture Address", Category = "Source" });

            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "int", Value = 0, Name = "Texture Top", Category = "Source" });
            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "int", Value = 0, Name = "Texture Left", Category = "Source" });
            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "int", Value = 0, Name = "Texture Width", Category = "Source" });
            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "int", Value = 0, Name = "Texture Height", Category = "Source" });
            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "bool", Value = false, Name = "HasEvents", Category = "Behavior", CanOnlyBeSetInDefaultState = true });
            AddStateVariable(stateSave);


#if GUM

            PluginManager.Self.ModifyDefaultStandardState("NineSlice", stateSave);
#endif
            ApplySortValuesFromOrderInState(stateSave);

            mDefaults.Add("NineSlice", stateSave);
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////



            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //                                                     Component                                                      //
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            stateSave = new StateSave();
            stateSave.Name = "Default";
#if GUM
            PluginManager.Self.ModifyDefaultStandardState("Component", stateSave);
#endif

#if GUM
            // Victor Chelaru
            // August 21, 2014
            // Not sure why we have
            // this here.  Doing so would
            // create an endless loop...
            //stateSave.Variables.Add(new VariableSave { Type = "string", Value = "Default", Name = "State", CustomTypeConverter = new AvailableStatesConverter(null)});
            // The type used to be "string" but we want to differentiate it from actual strings so we use "State"
            stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "State", Value = null, Name = "State", CustomTypeConverter = new AvailableStatesConverter(null) });
#endif

            ApplySortValuesFromOrderInState(stateSave);

            mDefaults.Add("Component", stateSave);
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////




            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //                                                    Screen                                                          //
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            stateSave = new StateSave();
            stateSave.Name = "Default";
#if GUM
            PluginManager.Self.ModifyDefaultStandardState("Screen", stateSave);
#endif

            ApplySortValuesFromOrderInState(stateSave);

            mDefaults.Add("Screen", stateSave);
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


            // We shouldn't do this because states above may explicitly not want to set values - like the variable for state
            //foreach (var defaultState in mDefaults.Values)
            //{
            //    foreach (var variable in defaultState.Variables)
            //    {
            //        variable.SetsValue = true;
            //    }
            //}





            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //                                                    Events                                                          //
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

            mStandardEvents.Add("Click");
            mStandardEvents.Add("RollOn");
            mStandardEvents.Add("RollOver");
            mStandardEvents.Add("RollOff");

            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


        }
Esempio n. 42
0
        public void AddState(ElementSave elementToAddTo, StateSaveCategory category, StateSave stateSave)
        {
            stateSave.ParentContainer = elementToAddTo;

            if (category == null)
            {
                elementToAddTo.States.Add(stateSave);
            }
            else
            {
                category.States.Add(stateSave);
            }
        }
Esempio n. 43
0
        public StateSave AddState(ElementSave elementToAddTo, StateSaveCategory category, string name)
        {
            if (elementToAddTo == null)
            {
                throw new Exception("Could not add state named " + name + " because no element is selected");
            }

            StateSave stateSave = new StateSave();
            stateSave.Name = name;
            AddState(elementToAddTo, category, stateSave);
            return stateSave;
        }
Esempio n. 44
0
        public void PasteInstanceSaves(List<InstanceSave> copiedInstances, StateSave copiedState, ElementSave targetElement)
        {
            List<InstanceSave> newInstances = new List<InstanceSave>();
            foreach (var instanceAsObject in copiedInstances)
            {
                InstanceSave sourceInstance = instanceAsObject as InstanceSave;
                ElementSave sourceElement = sourceInstance.ParentContainer;

                InstanceSave targetInstance = sourceInstance.Clone();
                newInstances.Add(targetInstance);

                if (targetElement != null)
                {
                    PastedCopiedInstance(sourceInstance, sourceElement, targetElement, targetInstance, copiedState);
                }
            }

            if (newInstances.Count > 1)
            {
                SelectedState.Self.SelectedInstances = newInstances;
            }
        }
Esempio n. 45
0
        private void PastedCopiedInstance(InstanceSave sourceInstance, ElementSave sourceElement, ElementSave targetElement, InstanceSave targetInstance, StateSave copiedState)
        {
            targetInstance.Name = StringFunctions.MakeStringUnique(targetInstance.Name, targetElement.Instances.Select(item=>item.Name));

            targetElement.Instances.Add(targetInstance);

            // We now have to copy over the states
            if (targetElement != sourceElement)
            {
                if (sourceElement.States.Count != 1)
                {
                    MessageBox.Show("Only the default state variables will be copied since the source and target elements differ.");
                }

                StateSave stateSave = copiedState;

                // Why do we reverse loop here?
                for (int i = stateSave.Variables.Count - 1; i > -1; i--)
                {
                    VariableSave sourceVariable = stateSave.Variables[i];

                    VariableSave copiedVariable = sourceVariable.Clone();
                    // Only copy over the variables that apply to the object that was dropped
                    if (sourceVariable.SourceObject == sourceInstance.Name)
                    {
                        copiedVariable.Name = targetInstance.Name + "." + copiedVariable.GetRootName();

                        // We don't want to copy exposed variables.
                        // If we did, the user would have 2 variables exposed with the same.
                        copiedVariable.ExposedAsName = null;

                        targetElement.DefaultState.Variables.Add(copiedVariable);
                    }
                }

                for(int i = 0; i < stateSave.VariableLists.Count; i++)
                {
                    var sourceVariableList = stateSave.VariableLists[i];

                    var copiedVariableList = sourceVariableList.Clone();
                    // Only copy over the variables that apply to the object that was dropped
                    if (sourceVariableList.SourceObject == sourceInstance.Name)
                    {
                        copiedVariableList.Name = targetInstance.Name + "." + copiedVariableList.GetRootName();
                        copiedVariableList.SourceObject = targetInstance.Name;
                        targetElement.DefaultState.VariableLists.Add(copiedVariableList);
                    }
                }
            }
            else
            {
                StateSave stateSave = copiedState;

                for (int i = stateSave.Variables.Count - 1; i > -1; i--)
                {
                    // We may have copied over a group of instances.  If so
                    // the copied state may have variables for multiple instances.
                    // We only want to apply the variables that work for the selected
                    // object.
                    VariableSave sourceVariable = stateSave.Variables[i];
                    if (sourceVariable.SourceObject == sourceInstance.Name)
                    {

                        VariableSave copiedVariable = sourceVariable.Clone();
                        copiedVariable.Name = targetInstance.Name + "." + copiedVariable.GetRootName();

                        // We don't want to copy exposed variables.
                        // If we did, the user would have 2 variables exposed with the same.
                        copiedVariable.ExposedAsName = null;

                        SelectedState.Self.SelectedStateSave.Variables.Add(copiedVariable);
                    }
                }
                // Copy over the VariableLists too
                for (int i = stateSave.VariableLists.Count - 1; i > -1; i--)
                {

                    VariableListSave sourceList = stateSave.VariableLists[i];
                    if (sourceList.SourceObject == sourceInstance.Name)
                    {
                        VariableListSave copiedList = sourceList.Clone();
                        copiedList.Name = targetInstance.Name + "." + copiedList.GetRootName();
                        copiedList.SourceObject = targetInstance.Name;

                        SelectedState.Self.SelectedStateSave.VariableLists.Add(copiedList);
                    }
                }
            }

            // This used to be done here when we paste, but now we're
            // going to remove it when the cut happens - just like text
            // editors.  Undo will handle this if we mess up.
            // bool shouldSaveSource = false;
            //if (mIsCtrlXCut)
            //{
            //    if (sourceElement.Instances.Contains(sourceInstance))
            //    {
            //        // Not sure why we weren't just using
            //        // ElementCommands here - maybe an oversight?
            //        // This should improve things like
            //        //sourceElement.Instances.Remove(sourceInstance);

            //        ElementCommands.Self.RemoveInstance(sourceInstance, sourceElement);
            //        shouldSaveSource = true;
            //    }
            //}

            targetInstance.ParentContainer = targetElement;
            // We need to call InstanceAdd before we select the new object - the Undo manager expects it
            // This includes before other managers refresh
            PluginManager.Self.InstanceAdd(targetElement, targetInstance);
            WireframeObjectManager.Self.RefreshAll(true);

            GumCommands.Self.GuiCommands.RefreshElementTreeView(targetElement);

            SelectedState.Self.SelectedInstance = targetInstance;

            GumCommands.Self.FileCommands.TryAutoSaveElement(targetElement);
        }
Esempio n. 46
0
        private void StoreCopiedInstances()
        {
            if (SelectedState.Self.SelectedInstance != null)
            {
                var element = SelectedState.Self.SelectedElement;

                // When copying we want to grab all instances in the order that they are in their container.
                // That way when they're pasted they are pasted in the right order
                foreach (var instance in SelectedState.Self.SelectedInstances.OrderBy(item=>element.Instances.IndexOf(item)))
                {
                    mCopiedInstances.Add(instance.Clone());
                }
                mCopiedState = SelectedState.Self.SelectedStateSave.Clone();

                // Clear out any variables that don't pertain to the selected instance:
                for (int i = mCopiedState.Variables.Count - 1; i > -1; i--)
                {
                    if (mCopiedInstances.Any(item=>item.Name == mCopiedState.Variables[i].SourceObject) == false)
                    {
                        mCopiedState.Variables.RemoveAt(i);
                    }
                }

                // And also any VariableLists:
                for (int i = mCopiedState.VariableLists.Count - 1; i > -1; i--)
                {
                    if (mCopiedInstances.Any(item=>item.Name == mCopiedState.VariableLists[i].SourceObject) == false)
                    {
                        mCopiedState.VariableLists.RemoveAt(i);
                    }
                }
            }
        }
Esempio n. 47
0
        private List<MemberCategory> GetCategories(ElementSave element, StateSave state, InstanceSave instance)
        {
            List<MemberCategory> categories = new List<MemberCategory>();

            mLastElement = element;
            mLastState = state;
            mLastInstance = instance;

            var stateSave = SelectedState.Self.SelectedStateSave;
            if (stateSave != null)
            {
                categories.Clear();
                var properties = mPropertyGridDisplayer.GetProperties(null);
                foreach (InstanceSavePropertyDescriptor propertyDescriptor in properties)
                {
                    StateReferencingInstanceMember srim;
                    if (instance != null)
                    {
                        srim =
                            new StateReferencingInstanceMember(propertyDescriptor, stateSave, instance.Name + "." + propertyDescriptor.Name, instance, element);
                    }
                    else
                    {
                        srim =
                            new StateReferencingInstanceMember(propertyDescriptor, stateSave, propertyDescriptor.Name, instance, element);
                    }

                    srim.SetToDefault += ResetVariableToDefault;

                    string category = propertyDescriptor.Category.Trim();

                    var categoryToAddTo = categories.FirstOrDefault(item => item.Name == category);

                    if (categoryToAddTo == null)
                    {
                        categoryToAddTo = new MemberCategory(category);
                        categories.Add(categoryToAddTo);
                    }

                    categoryToAddTo.Members.Add(srim);

                }

                foreach (var category in categories)
                {
                    var enumerable = category.Members.OrderBy(item => ((StateReferencingInstanceMember)item).SortValue).ToList();
                    category.Members.Clear();

                    foreach (var value in enumerable)
                    {
                        category.Members.Add(value);
                    }
                }


                MemberCategory categoryToMove = categories.FirstOrDefault(item => item.Name == "Position");
                if (categoryToMove != null)
                {
                    categories.Remove(categoryToMove);
                    categories.Insert(1, categoryToMove);
                }

                categoryToMove = categories.FirstOrDefault(item => item.Name == "Dimensions");
                if (categoryToMove != null)
                {
                    categories.Remove(categoryToMove);
                    categories.Insert(2, categoryToMove);
                }

                UpdateColorCategory(categories);
            }
            return categories;

        }
        private static void AddStateVariable(StateSave stateSave)
        {
            stateSave.Variables.Add(new VariableSave
            {
                // Don't want it to set the value...
                SetsValue = false, 
                Type = "State",
                Value = "Default",
                Name = "State"
#if GUM
,
                CustomTypeConverter = new AvailableStatesConverter(null)
#endif
            });
        }
Esempio n. 49
0
        private void RefreshDataGrid(ElementSave element, StateSave state, InstanceSave instance, bool force = false)
        {

            bool hasChangedObjectShowing = element != mLastElement || instance != mLastInstance || state != mLastState ||
                force;


            if (hasChangedObjectShowing)
            {
                List<MemberCategory> categories = GetCategories(element, state, instance);
                Application.DoEvents();
                SimultaneousCalls ++;
                lock (lockObject)
                {
                    if(SimultaneousCalls > 1)
                    {
                        SimultaneousCalls--;
                        return;
                    }
                    records.Add("in");

                    mVariablesDataGrid.Instance = SelectedState.Self.SelectedStateSave;

                    mVariablesDataGrid.Visibility = System.Windows.Visibility.Hidden;

                    mVariablesDataGrid.Categories.Clear();

                    // There's a bug here where drag+dropping a new instance will create 
                    // duplicate UI members.  I am going to deal with it now because it is


                    foreach (var category in categories)
                    {

                        // We used to do this:
                        // Application.DoEvents();
                        // That made things go faster,
                        // but it made the "lock" not work, which could make duplicate UI show up.
                        mVariablesDataGrid.Categories.Add(category);
                        if(SimultaneousCalls > 1)
                        {
                            SimultaneousCalls--;
                            // EARLY OUT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                            return;
                        }
                    }

                }

                SimultaneousCalls--;
                Application.DoEvents();

                mVariablesDataGrid.Visibility = System.Windows.Visibility.Visible;

            }
            else
            {
                // let's see if any variables have been added/removed
                var categories = GetCategories(element, state, instance);

                foreach (var newCategory in categories)
                {
                    // let's see if any variables have changed
                    var oldCategory = mVariablesDataGrid.Categories.FirstOrDefault(item => item.Name == newCategory.Name);

                    if ( oldCategory != null && DoCategoriesDiffer(oldCategory.Members, newCategory.Members))
                    {
                        int index = mVariablesDataGrid.Categories.IndexOf(oldCategory);

                        mVariablesDataGrid.Categories.RemoveAt(index);
                        mVariablesDataGrid.Categories.Insert(index, newCategory);
                    }
                }
            }


            mVariablesDataGrid.Refresh();
            
        }
 private void ApplySortValuesFromOrderInState(StateSave stateSave)
 {
     for (int i = 0; i < stateSave.Variables.Count; i++)
     {
         stateSave.Variables[i].DesiredOrder = i;
     }
 }
Esempio n. 51
0
 public void CallAddAndRemoveVariablesForType(string type, StateSave standardDefaultStateSave)
 {
     if (AddAndRemoveVariablesForType != null)
     {
         AddAndRemoveVariablesForType(type, standardDefaultStateSave);
     }
 }
 private static void AddColorVariables(StateSave stateSave, bool includeAlpha = true)
 {
     if (includeAlpha)
     {
         stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "int", Value = 255, Name = "Alpha", Category = "Rendering" });
     }
     stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "int", Value = 255, Name = "Red", Category = "Rendering" });
     stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "int", Value = 255, Name = "Green", Category = "Rendering" });
     stateSave.Variables.Add(new VariableSave { SetsValue = true, Type = "int", Value = 255, Name = "Blue", Category = "Rendering" });
 }
Esempio n. 53
0
 private void StoreCopiedState()
 {
     if (SelectedState.Self.SelectedStateSave != null)
     {
         mCopiedState = SelectedState.Self.SelectedStateSave.Clone();
     }
 }
        private static VariableSave TryGetVariableFromStateOnInstance(InstanceSave instance, string variable, IEnumerable<StateSave> statesToPullFrom, string stateVariableName, StateSave fallbackState, List<StateSave> statesToLoopThrough)
        {
            VariableSave foundVariableSave = null;

            // Let's see if this is in a non-default state
            string thisState = null;
            foreach (var stateToPullFrom in statesToPullFrom)
            {
                var foundStateVariable = stateToPullFrom.GetVariableSave(instance.Name + "." + stateVariableName);
                if (foundStateVariable != null && foundStateVariable.SetsValue)
                {
                    thisState = foundStateVariable.Value as string;
                }
            }
            StateSave instanceStateToPullFrom = fallbackState;

            // if thisState is not null, then the state is being explicitly set, so let's try to get that state
            if (!string.IsNullOrEmpty(thisState) && statesToLoopThrough.Any(item => item.Name == thisState))
            {
                instanceStateToPullFrom = statesToLoopThrough.First(item => item.Name == thisState);
            }

            if (instanceStateToPullFrom != null)
            {
                // Eventually use the instanceBase's current state value
                foundVariableSave = instanceStateToPullFrom.GetVariableRecursive(variable);
            }
            return foundVariableSave;
        }
        private static void GetStatesToUse(InstanceSave instance, List<ElementWithState> elementStack, bool forceDefault, ElementSave instanceBase, RecursiveVariableFinder rvf, out List<StateSave> statesToPullFrom, out StateSave defaultState)
        {
            statesToPullFrom = null;
            defaultState = null;

#if GUM
            if (SelectedState.Self.SelectedElement != null)
            {
                statesToPullFrom = new List<StateSave> { SelectedState.Self.SelectedElement.DefaultState };
                defaultState = SelectedState.Self.SelectedElement.DefaultState;
            }
#endif

            if (elementStack.Count != 0)
            {
                if (elementStack.Last().Element == null)
                {
                    throw new InvalidOperationException("The ElementStack contains an ElementWithState with no Element");
                }
                statesToPullFrom = elementStack.Last().AllStates.ToList();
                defaultState = elementStack.Last().Element.DefaultState;
            }


#if GUM
            if (elementStack.Count != 0 && elementStack.Last().Element == SelectedState.Self.SelectedElement &&
                SelectedState.Self.SelectedStateSave != null &&
                !forceDefault)
            {
                statesToPullFrom = new List<StateSave> { SelectedState.Self.SelectedStateSave };
            }
#endif

        }
Esempio n. 56
0
        public void SaveStateTo(ScriptData script, bool forced, bool saveBackup)
        {
            if (!forced)
            {
                if (script.Script == null)
                    return; //If it didn't compile correctly, this happens
                if (!script.Script.NeedsStateSaved)
                    return; //If it doesn't need a state save, don't save one
            }
            if (script.Script != null)
                script.Script.NeedsStateSaved = false;
            StateSave stateSave = new StateSave
                                      {
                                          State = script.State,
                                          ItemID = script.ItemID,
                                          Running = script.Running,
                                          MinEventDelay = script.EventDelayTicks,
                                          Disabled = script.Disabled,
                                          UserInventoryID = script.UserInventoryItemID,
                                          AssemblyName = script.AssemblyName,
                                          Compiled = script.Compiled,
                                          Source = script.Source == null ? "" : script.Source
                                      };
            //Allow for the full path to be put down, not just the assembly name itself
            if (script.InventoryItem != null)
            {
                stateSave.PermsGranter = script.InventoryItem.PermsGranter;
                stateSave.PermsMask = script.InventoryItem.PermsMask;
            }
            else
            {
                stateSave.PermsGranter = UUID.Zero;
                stateSave.PermsMask = 0;
            }
            stateSave.TargetOmegaWasSet = script.TargetOmegaWasSet;

            //Vars
            Dictionary<string, object> vars = new Dictionary<string, object>();
            if (script.Script != null)
                vars = script.Script.GetStoreVars();
            stateSave.Variables = XMLUtils.BuildXmlResponse(vars);

            //Plugins
            stateSave.Plugins =
                OSDParser.SerializeJsonString(m_module.GetSerializationData(script.ItemID, script.Part.UUID));

            lock (StateSaveLock)
                script.Part.StateSaves[script.ItemID] = stateSave;
            if (saveBackup)
                script.Part.ParentEntity.HasGroupChanged = true;
        }