Esempio n. 1
0
        private static void FillWithCurrentState(ElementSave element, StringBuilder stringBuilder, int tabCount)
        {
            foreach (var category in element.Categories)
            {
                stringBuilder.AppendLine();
                string enumName = category.Name;

                stringBuilder.AppendLine(ToTabs(tabCount) + $"{category.Name} m{category.Name}State;");
                stringBuilder.AppendLine(ToTabs(tabCount) + $"public {category.Name} {category.Name}State");

                stringBuilder.AppendLine(ToTabs(tabCount) + "{");
                tabCount++;
                stringBuilder.AppendLine(ToTabs(tabCount) + $"get => m{category.Name}State;");
                stringBuilder.AppendLine(ToTabs(tabCount) + $"set");

                stringBuilder.AppendLine(ToTabs(tabCount) + "{");
                tabCount++;
                stringBuilder.AppendLine(ToTabs(tabCount) + $"m{category.Name}State = value;");

                stringBuilder.AppendLine(ToTabs(tabCount) + $"switch (value)");
                stringBuilder.AppendLine(ToTabs(tabCount) + "{");
                tabCount++;

                foreach (var state in category.States)
                {
                    stringBuilder.AppendLine(ToTabs(tabCount) + $"case {category.Name}.{state.Name}:");
                    tabCount++;

                    FillWithVariablesInState(element, state, stringBuilder, tabCount);

                    stringBuilder.AppendLine(ToTabs(tabCount) + $"break;");
                    tabCount--;
                }


                tabCount--;
                stringBuilder.AppendLine(ToTabs(tabCount) + "}");


                tabCount--;
                stringBuilder.AppendLine(ToTabs(tabCount) + "}");

                tabCount--;
                stringBuilder.AppendLine(ToTabs(tabCount) + "}");
            }
        }
Esempio n. 2
0
        private void HandleInstanceRenamed(ElementSave container, InstanceSave instance, string oldName)
        {
            var elementsInheritingFromContainer =
                ObjectFinder.Self.GetElementsInheritingFrom(container);

            foreach (var inheritingElement in elementsInheritingFromContainer)
            {
                var toRename = inheritingElement.GetInstance(oldName);

                if (toRename != null)
                {
                    toRename.Name = instance.Name;
                    GumCommands.Self.FileCommands.TryAutoSaveElement(inheritingElement);
                    GumCommands.Self.GuiCommands.RefreshElementTreeView(inheritingElement);
                }
            }
        }
Esempio n. 3
0
        private static void HandleInstanceVariableBaseTypeSet(ElementSave container, InstanceSave instance)
        {
            var elementsInheritingFromContainer =
                ObjectFinder.Self.GetElementsInheritingFrom(container);

            foreach (var inheritingElement in elementsInheritingFromContainer)
            {
                var toChange = inheritingElement.GetInstance(instance.Name);

                if (toChange != null)
                {
                    toChange.BaseType = instance.BaseType;

                    GumCommands.Self.FileCommands.TryAutoSaveElement(inheritingElement);
                }
            }
        }
Esempio n. 4
0
        private static void AddTreeNodeForElement(ElementSave element, TreeNode parentNode, int defaultImageIndex)
        {
            TreeNode treeNode = new TreeNode();

            if (element.IsSourceFileMissing)
            {
                treeNode.ImageIndex = ExclamationIndex;
            }
            else
            {
                treeNode.ImageIndex = defaultImageIndex;
            }

            treeNode.Tag = element;

            parentNode.Nodes.Add(treeNode);
        }
Esempio n. 5
0
        private void ReactIfChangedMemberIsParent(ElementSave parentElement, InstanceSave instance, string changedMember, object oldValue)
        {
            bool isValidAssignment = true;

            VariableSave variable = SelectedState.Self.SelectedVariableSave;

            // Eventually need to handle tunneled variables
            if (variable != null && changedMember == "Parent")
            {
                if ((variable.Value as string) == "<NONE>")
                {
                    variable.Value = null;
                }

                if (variable.Value != null)
                {
                    var newParent = parentElement.Instances.FirstOrDefault(item => item.Name == variable.Value as string);
                    var newValue  = variable.Value;
                    // unset it before finding recursive children, in case there is a circular reference:
                    variable.Value = null;
                    var childrenInstances = GetRecursiveChildrenOf(parentElement, instance);

                    if (childrenInstances.Contains(newParent))
                    {
                        // uh oh, circular referenced detected, don't allow it!
                        MessageBox.Show("This parent assignment would produce a circular reference, which is not allowed.");
                        variable.Value    = oldValue;
                        isValidAssignment = false;
                    }
                    else
                    {
                        // set it back:
                        variable.Value = newValue;
                    }
                }

                if (isValidAssignment)
                {
                    GumCommands.Self.GuiCommands.RefreshElementTreeView(parentElement);
                }
                else
                {
                    GumCommands.Self.GuiCommands.RefreshPropertyGrid(force: true);
                }
            }
        }
Esempio n. 6
0
        private void GetMemberCategoriesForStateCategory(ElementSave element, InstanceSave instance, List <MemberCategory> categories, StateSaveCategory stateCategory)
        {
            categories.Clear();

            List <string> commonMembers = new List <string>();

            var firstState = stateCategory.States.FirstOrDefault();

            if (firstState != null)
            {
                foreach (var variable in firstState.Variables)
                {
                    bool canAdd = variable.ExcludeFromInstances == false || instance == null;

                    if (canAdd)
                    {
                        commonMembers.Add(variable.Name);
                    }
                }
            }

            if (commonMembers.Any())
            {
                var memberCategory = new MemberCategory();
                memberCategory.Name = $"{stateCategory.Name} Variables";
                categories.Add(memberCategory);

                foreach (var commonMember in commonMembers)
                {
                    var instanceMember = new InstanceMember();

                    instanceMember.Name = commonMember;
                    instanceMember.CustomGetTypeEvent += (member) => typeof(string);
                    instanceMember.CustomGetEvent     += (member) => commonMember;
                    instanceMember.CustomSetEvent     += (not, used) =>
                    {
                        VariableInCategoryPropagationLogic.Self
                        .AskRemoveVariableFromAllStatesInCategory(commonMember, stateCategory);
                    };

                    instanceMember.PreferredDisplayer = typeof(VariableRemoveButton);

                    memberCategory.Members.Add(instanceMember);
                }
            }
        }
Esempio n. 7
0
        private ICodeBlock GenerateClassHeader(ICodeBlock codeBlock, ElementSave elementSave)
        {
            string runtimeClassName = GetUnqualifiedRuntimeTypeFor(elementSave);

            string inheritance = "Gum.Wireframe.GraphicalUiElement";

            if (elementSave.BaseType != "Component" && !string.IsNullOrEmpty(elementSave.BaseType))
            {
                inheritance = GueRuntimeNamespace + "." + elementSave.BaseType + "Runtime";
            }

            var asComponentSave = elementSave as ComponentSave;

            if (asComponentSave != null)
            {
                var project   = AppState.Self.GumProjectSave;
                var behaviors = project.Behaviors;

                foreach (var behaviorReference in asComponentSave.Behaviors)
                {
                    inheritance += $", {GueRuntimeNamespace}.I{behaviorReference.BehaviorName}";

                    var behavior = behaviors.FirstOrDefault(item => item.Name == behaviorReference.BehaviorName);

                    string behaviorInheritance = null;
                    if (behavior != null)
                    {
                        behaviorInheritance = BehaviorCodeGenerator.GetInterfacesFromBehaviors(behavior);
                    }

                    if (!string.IsNullOrEmpty(behaviorInheritance))
                    {
                        inheritance += $", {behaviorInheritance}";
                    }
                }
            }


            // If it's not public then exposing an instance in a public class makes the project not compile
            //ICodeBlock currentBlock = codeBlock.Class("partial", runtimeClassName, " : " + inheritance);
            ICodeBlock currentBlock = codeBlock.Class("public partial", runtimeClassName, " : " + inheritance);



            return(currentBlock);
        }
Esempio n. 8
0
        // Discussion about Selection
        // Selection is a rather complicated
        // system in Gum because tree nodes can
        // be selected in a number of ways:
        // 1.  The user can push/release (click)
        // 2.  The user can select an item in the
        //     wireframe window which in turn selects
        //     the appropriate tree node.
        // 3.  The user pushes on a tree node, but then
        //     drags off of it to do a drag+drop somewhere
        //     else.
        // We want the app to refresh what it is displaying
        // in scenario 1 and 2, but not in 3.  Therefore the
        // MultiSelectTreeView class has an event called AfterClickSelect
        // which only fires when the user actually clicks on an item (1) so
        // that #3 doesn't fire off an event.  However, this means that #2 will
        // no longer fire off the event either.  We need to then make sure that #2
        // does still fire off an event, so we'll do this by manually raising the event
        // in the Select methods where a Save object is selected.
        public void Select(InstanceSave instanceSave, ElementSave parent)
        {
            if (instanceSave != null)
            {
                TreeNode parentTreeNode = GetTreeNodeFor(parent);

                // This could be null if the user started a new project or loaded a different project.
                if (parentTreeNode != null)
                {
                    Select(GetTreeNodeFor(instanceSave, parentTreeNode));
                }
            }
            else
            {
                Select((TreeNode)null);
            }
        }
        public static VariableSave GetVariableRecursive(this StateSave stateSave, string variableName)
        {
            VariableSave variableSave = stateSave.GetVariableSave(variableName);

            if (variableSave == null)
            {
                // Is this thing the default?
                ElementSave parent = stateSave.ParentContainer;

                if (parent != null && stateSave != parent.DefaultState)
                {
                    variableSave = stateSave.GetVariableSave(variableName);

                    if (variableSave == null)
                    {
                        variableSave = parent.DefaultState.GetVariableSave(variableName);
                    }
                }

                if (variableSave == null && parent != null)
                {
                    ElementSave baseElement = GetBaseElementFromVariable(variableName, parent);

                    if (baseElement != null)
                    {
                        string nameInBase = variableName;

                        if (variableName.Contains('.'))
                        {
                            // this variable is set on an instance, but we're going into the
                            // base type, so we want to get the raw variable and not the variable
                            // as tied to an instance.
                            nameInBase = variableName.Substring(nameInBase.IndexOf('.') + 1);
                        }

                        return(baseElement.DefaultState.GetVariableRecursive(nameInBase));
                    }
                }

                return(variableSave);
            }
            else
            {
                return(variableSave);
            }
        }
        private bool TryHandleCustomGetter(VariableSave variable, ElementSave elementSave, ICodeBlock getter)
        {
            if (variable.GetRootName() == "SourceFile" && elementSave.Name == "NineSlice")
            {
                getter.Line("return ContainedNineSlice.TopLeftTexture;");

                return(true);
            }
            // handle colors:

            if (elementSave.Name == "Circle" || elementSave.Name == "Rectangle")
            {
                string containedObject;

                if (elementSave.Name == "Circle")
                {
                    containedObject = "ContainedCircle";
                }
                else
                {
                    containedObject = "ContainedRectangle";
                }
                if (variable.Name == "Alpha")
                {
                    getter.Line($"return {containedObject}.Color.A;");
                    return(true);
                }
                else if (variable.Name == "Red")
                {
                    getter.Line($"return {containedObject}.Color.R;");
                    return(true);
                }
                else if (variable.Name == "Green")
                {
                    getter.Line($"return {containedObject}.Color.G;");
                    return(true);
                }
                else if (variable.Name == "Blue")
                {
                    getter.Line($"return {containedObject}.Color.B;");
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 11
0
        private static void PastedCopiedState()
        {
            ElementSave container      = SelectedState.Self.SelectedElement;
            var         targetCategory = SelectedState.Self.SelectedStateCategorySave;

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

            StateSave newStateSave = mCopiedState.Clone();

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


            newStateSave.ParentContainer = container;

            string name = mCopiedState.Name + "Copy";


            if (targetCategory != null)
            {
                name = StringFunctions.MakeStringUnique(name, targetCategory.States.Select(item => item.Name));
                newStateSave.Name = name;

                targetCategory.States.Add(newStateSave);
            }
            else
            {
                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. 12
0
        private void HandleDroppedElementSave(object draggedComponentOrElement, TreeNode treeNodeDroppedOn, object targetTag)
        {
            ElementSave draggedAsElementSave = draggedComponentOrElement as ElementSave;

            // User dragged an element save - so they want to take something like a
            // text object and make an instance in another element like a Screen
            bool handled;

            if (targetTag is ElementSave)
            {
                HandleDroppedElementInElement(draggedAsElementSave, targetTag as ElementSave, out handled);
            }
            else if (targetTag is InstanceSave)
            {
                // The user dropped it on an instance save, but he likely meant to drop
                // it as an object under the current element.

                InstanceSave targetInstance = targetTag as InstanceSave;


                var newInstance = HandleDroppedElementInElement(draggedAsElementSave, targetInstance.ParentContainer, out handled);

                if (newInstance != null)
                {
                    // Since the user dropped on another instance, let's try to parent it:
                    HandleDroppingInstanceOnTarget(targetInstance, newInstance, targetInstance.ParentContainer);
                }
            }
            else if (treeNodeDroppedOn.IsTopComponentContainerTreeNode())
            {
                HandleDroppedElementOnTopComponentTreeNode(draggedAsElementSave, out handled);
            }
            else if (draggedAsElementSave is ComponentSave && treeNodeDroppedOn.IsPartOfComponentsFolderStructure())
            {
                HandleDroppedElementOnFolder(draggedAsElementSave, treeNodeDroppedOn, out handled);
            }
            else if (draggedAsElementSave is ScreenSave && treeNodeDroppedOn.IsPartOfScreensFolderStructure())
            {
                HandleDroppedElementOnFolder(draggedAsElementSave, treeNodeDroppedOn, out handled);
            }
            else
            {
                MessageBox.Show("You must drop " + draggedAsElementSave.Name + " on either a Screen or an Component");
            }
        }
Esempio n. 13
0
        static StateSave GetStateFromCategorizedName(string categorizedName, ElementSave element)
        {
            if (categorizedName.Contains("/"))
            {
                var names = categorizedName.Split('/');

                string category  = names[0];
                string stateName = names[1];

                return(element
                       .Categories.FirstOrDefault(item => item.Name == category)
                       ?.States.FirstOrDefault(item => item.Name == stateName));
            }
            else
            {
                return(element.States.FirstOrDefault(item => item.Name == categorizedName));
            }
        }
Esempio n. 14
0
        void OnMoveBackward(object sender, EventArgs e)
        {
            InstanceSave instance = SelectedState.Self.SelectedInstance;
            ElementSave  element  = SelectedState.Self.SelectedElement;

            if (instance != null)
            {
                int index = element.Instances.IndexOf(instance);

                if (index != 0)
                {
                    element.Instances.RemoveAt(index);
                    element.Instances.Insert(index - 1, instance);

                    RefreshInResponseToReorder();
                }
            }
        }
Esempio n. 15
0
        private void GenerateStateInterpolateBetween(ElementSave elementSave, ICodeBlock currentBlock)
        {
            currentBlock.Line("#region State Interpolation");

            string enumType = "VariableState";
            IEnumerable <StateSave> states = elementSave.States;

            GenerateInterpolateBetween(elementSave, currentBlock, enumType, states);

            foreach (var category in elementSave.Categories)
            {
                enumType = category.Name;
                states   = category.States;
                GenerateInterpolateBetween(elementSave, currentBlock, enumType, states);
            }

            currentBlock.Line("#endregion");
        }
Esempio n. 16
0
        public GraphicalUiElement GetRepresentation(ElementSave elementSave)
        {
#if DEBUG
            if (elementSave == null)
            {
                throw new NullReferenceException("The argument elementSave is null");
            }
#endif
            foreach (GraphicalUiElement ipso in AllIpsos)
            {
                if (ipso.Tag == elementSave)
                {
                    return(ipso);
                }
            }

            return(null);
        }
Esempio n. 17
0
        private void GenerateCurrentStateFields(ElementSave elementSave, ICodeBlock currentBlock)
        {
            currentBlock.Line("#region State Fields");
            string propertyName = "CurrentVariableState";
            string propertyType = "VariableState";

            currentBlock.Line(propertyType + " m" + propertyName + ";");


            foreach (var category in elementSave.Categories)
            {
                propertyName = "Current" + category.Name + "State";
                propertyType = category.Name;

                currentBlock.Line(propertyType + " m" + propertyName + ";");
            }
            currentBlock.Line("#endregion");
        }
Esempio n. 18
0
        private void FillListWithReferencedFiles(List <string> files, ElementSave element)
        {
            RecursiveVariableFinder rvf;
            string value;

            foreach (var state in element.AllStates)
            {
                rvf = new RecursiveVariableFinder(element.DefaultState);

                value = rvf.GetValue <string>("SourceFile");
                if (!string.IsNullOrEmpty(value))
                {
                    files.Add(value);
                }

                value = rvf.GetValue <string>("CustomFontFile");
                if (!string.IsNullOrEmpty(value))
                {
                    files.Add(value);
                }

                List <Gum.Wireframe.ElementWithState> elementStack = new List <Wireframe.ElementWithState>();
                var elementWithState = new Gum.Wireframe.ElementWithState(element);
                elementWithState.StateName = state.Name;
                elementStack.Add(elementWithState);

                foreach (InstanceSave instance in element.Instances)
                {
                    rvf = new RecursiveVariableFinder(instance, elementStack);

                    value = rvf.GetValue <string>("SourceFile");
                    if (!string.IsNullOrEmpty(value))
                    {
                        files.Add(value);
                    }

                    value = rvf.GetValue <string>("CustomFontFile");
                    if (!string.IsNullOrEmpty(value))
                    {
                        files.Add(value);
                    }
                }
            }
        }
        public static string MemberNameInCode(this VariableSave variableSave, ElementSave container, Dictionary <string, string> replacements = null)
        {
            if (replacements == null)
            {
                replacements = StateCodeGenerator.VariableNamesToReplaceForStates;
            }
            var rootName   = variableSave.GetRootName();
            var objectName = variableSave.SourceObject;

            if (replacements.ContainsKey(rootName))
            {
                rootName = replacements[rootName];
            }
            else
            {
                rootName = rootName.Replace(" ", "_");
            }

            ElementSave       throwaway1;
            StateSaveCategory throwaway2;

            // recursive is false because we only want to prepend "Current" if it's not an exposed variable
            if (variableSave.IsState(container, out throwaway1, out throwaway2, recursive: false))
            {
                if (rootName == "State")
                {
                    rootName = "CurrentVariableState";
                }
                else
                {
                    rootName = "Current" + rootName;
                }
            }

            if (string.IsNullOrEmpty(objectName))
            {
                return(rootName);
            }
            else
            {
                objectName = InstanceNameInCode(objectName);
                return(objectName + '.' + rootName);
            }
        }
Esempio n. 20
0
        private bool TryAskForRemovalConfirmation(StateSave stateSave, ElementSave elementSave)
        {
            bool shouldContinue = true;
            // See if the element is used anywhere

            List <InstanceSave> foundInstances = new List <InstanceSave>();

            ObjectFinder.Self.GetElementsReferencing(elementSave, null, foundInstances);

            foreach (var instance in foundInstances)
            {
                // We don't want to go recursively, just top level because
                // I *think* that the lists will include copies of the instances
                // recursively
                ElementSave parent = instance.ParentContainer;

                string variableToLookFor = instance.Name + ".State";

                // loop through all of the states to see if any of the parents' states
                // reference the state that is being removed.
                foreach (var stateInContainer in parent.AllStates)
                {
                    var foundVariable = stateInContainer.Variables.FirstOrDefault(item => item.Name == variableToLookFor);

                    if (foundVariable != null && foundVariable.Value == stateSave.Name)
                    {
                        MultiButtonMessageBox mbmb = new MultiButtonMessageBox();
                        mbmb.MessageText = "The state " + stateSave.Name + " is used in the element " +
                                           elementSave + " in its state " + stateInContainer + ".\n  What would you like to do?";

                        mbmb.AddButton("Do nothing - project may be in an invalid state", System.Windows.Forms.DialogResult.No);
                        mbmb.AddButton("Change variable to default", System.Windows.Forms.DialogResult.OK);
                        // eventually will want to add a cancel option

                        if (mbmb.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                        {
                            foundVariable.Value = "Default";
                        }
                    }
                }
            }

            return(shouldContinue);
        }
        public static GraphicalUiElement ToGraphicalUiElement(this InstanceSave instanceSave, SystemManagers systemManagers)
        {
#if DEBUG
            if (ObjectFinder.Self.GumProjectSave == null)
            {
                throw new InvalidOperationException("You need to set the ObjectFinder's GumProjectSave first so it can track references");
            }
#endif
            ElementSave instanceElement = ObjectFinder.Self.GetElementSave(instanceSave.BaseType);

            GraphicalUiElement toReturn = null;
            if (instanceElement != null)
            {
                toReturn = ElementSaveExtensions.CreateGueForElement(instanceElement, true);

                // If we get here but there's no contained graphical object then that means we don't
                // have a strongly-typed system (like when a game is running in FRB). Therefore, we'll
                // just fall back to the regular creation of graphical objects, like is done in the Gum tool:
                if (toReturn.RenderableComponent == null)
                {
                    instanceElement.SetGraphicalUiElement(toReturn, systemManagers);
                }


                toReturn.Name = instanceSave.Name;
                toReturn.Tag  = instanceSave;

                var state = instanceSave.ParentContainer.DefaultState;



                foreach (var variable in state.Variables.Where(item => item.SetsValue && item.SourceObject == instanceSave.Name))
                {
                    string propertyOnInstance = variable.Name.Substring(variable.Name.LastIndexOf('.') + 1);

                    if (toReturn.IsExposedVariable(propertyOnInstance))
                    {
                        toReturn.SetProperty(propertyOnInstance, variable.Value);
                    }
                }
            }

            return(toReturn);
        }
Esempio n. 22
0
        public string GetCustomCodeTemplateCode(ElementSave element)
        {
            // Example:

            /*
             * using System;
             * using System.Collections.Generic;
             * using System.Linq;
             *
             * namespace DesktopGlForms.GumRuntimes.DefaultForms
             * {
             * public partial class ButtonRuntime
             * {
             * partial void CustomInitialize()
             * {
             *
             * }
             * }
             * }
             *
             */

            var        codeBlockBase = new CodeBlockBaseNoIndent(null);
            ICodeBlock codeBlock     = codeBlockBase;

            var toReturn = codeBlock;

            codeBlock.Line("using System;");
            codeBlock.Line("using System.Collections.Generic;");
            codeBlock.Line("using System.Linq;");
            codeBlock.Line();
            codeBlock = codeBlock.Namespace(
                GueDerivingClassCodeGenerator.Self.GetFullRuntimeNamespaceFor(element));
            {
                string runtimeClassName =
                    GueDerivingClassCodeGenerator.Self.GetUnqualifiedRuntimeTypeFor(element);

                codeBlock = codeBlock.Class("public partial", runtimeClassName);
                {
                    codeBlock = codeBlock.Function("partial void", "CustomInitialize");
                }
            }
            return(toReturn.ToString());
        }
Esempio n. 23
0
        private void GenerateAssignReferencesMethod(ElementSave elementSave, ICodeBlock currentBlock)
        {
            currentBlock = currentBlock.Function("public override void", "AssignReferences", "");
            {
                currentBlock.Line("base.AssignReferences();");


                foreach (var instance in elementSave.Instances)
                {
                    var foundBase = Gum.Managers.ObjectFinder.Self.GetElementSave(instance.BaseType);

                    if (foundBase != null)
                    {
                        currentBlock.Line(instance.MemberNameInCode() +
                                          " = this.GetGraphicalUiElementByName(\"" + instance.MemberNameInCode() + "\") as " +
                                          GueDerivingClassCodeGenerator.GetQualifiedRuntimeTypeFor(instance) + ";");

                        ElementSave baseElement = Gum.Managers.ObjectFinder.Self.GetElementSave(instance.BaseType);

                        if (baseElement != null && (baseElement is StandardElementSave) == false)
                        {
                            currentBlock.Line(instance.MemberNameInCode() + ".AssignReferences();");
                        }

                        foreach (var eventSave in elementSave.Events.Where(item =>
                                                                           item.GetSourceObject() == instance.Name && !string.IsNullOrEmpty(item.ExposedAsName)))
                        {
                            currentBlock.Line(eventSave.Name + " += Raise" + eventSave.ExposedAsName + ";");
                        }
                    }
                }

                List <EventSave> exposedChildrenEvents = EventCodeGenerator.Self.GetExposedChildrenEvents(elementSave);

                foreach (var exposedChildEvent in exposedChildrenEvents)
                {
                    currentBlock.Line($"{exposedChildEvent.Name} += (unused) => {exposedChildEvent.ExposedAsName}?.Invoke(this);");
                }

                // must be done after instances are assigned, since beahvior code may reference instances
                GenerateStandardFrbBehaviorCode(elementSave, currentBlock);
                currentBlock.Line("CallCustomInitialize();");
            }
        }
Esempio n. 24
0
        private ICodeBlock AssignValuesUsingStartingValues(ElementSave element, ICodeBlock curBlock, Dictionary <VariableSave, InterpolationCharacteristic> mInterpolationCharacteristics)
        {
            foreach (KeyValuePair <VariableSave, InterpolationCharacteristic> kvp in mInterpolationCharacteristics)
            {
                var variable = kvp.Key;

                if (kvp.Value != InterpolationCharacteristic.CantInterpolate)
                {
                    string stringSuffix = variable.MemberNameInCode(element, VariableNamesToReplaceForStates).Replace(".", "");

                    curBlock = curBlock.If("set" + stringSuffix + FirstValue + " && set" + stringSuffix + SecondValue);

                    AddAssignmentForInterpolationForVariable(curBlock, variable, element);

                    curBlock = curBlock.End();
                }
            }
            return(curBlock);
        }
        private void GenerateCurrentStateFields(ElementSave elementSave, ICodeBlock currentBlock)
        {
            currentBlock.Line("#region State Fields");
            string propertyName = "CurrentVariableState";
            string propertyType = "VariableState";

            currentBlock.Line(propertyType + " m" + propertyName + ";");


            foreach (var category in elementSave.Categories)
            {
                propertyName = "Current" + category.Name + "State";
                propertyType = category.Name;

                // Make these nullable because categorized states may not be set at all
                currentBlock.Line($"{propertyType}? m{propertyName};");
            }
            currentBlock.Line("#endregion");
        }
Esempio n. 26
0
        private static void FillWithExposedVariable(VariableSave exposedVariable, ElementSave container, StringBuilder stringBuilder, int tabCount)
        {
            var type = exposedVariable.Type;

            if (exposedVariable.IsState(container, out ElementSave stateContainer, out StateSaveCategory category))
            {
                var stateContainerType = GetClassNameForType(stateContainer.Name, VisualApi.Gum);
                type = $"{stateContainerType}.{category.Name}";
            }

            stringBuilder.AppendLine(ToTabs(tabCount) + $"public {type} {exposedVariable.ExposedAsName}");
            stringBuilder.AppendLine(ToTabs(tabCount) + "{");
            tabCount++;
            stringBuilder.AppendLine(ToTabs(tabCount) + $"get => {exposedVariable.Name};");
            stringBuilder.AppendLine(ToTabs(tabCount) + $"set => {exposedVariable.Name} = value;");
            tabCount--;

            stringBuilder.AppendLine(ToTabs(tabCount) + "}");
        }
Esempio n. 27
0
        private void RefreshErrors(ElementSave element)
        {
            var asComponent = element as ComponentSave;

            if (asComponent != null)
            {
                var behaviors          = ProjectState.Self.GumProjectSave.Behaviors;
                var behaviorReferences = asComponent.Behaviors;

                string message = null;

                foreach (var behaviorReference in behaviorReferences)
                {
                    var foundBehavior = behaviors.FirstOrDefault(item => item.Name == behaviorReference.BehaviorName);

                    if (foundBehavior != null)
                    {
                        var requiredVariables = foundBehavior.RequiredVariables.Variables;

                        foreach (var requiredVariable in requiredVariables)
                        {
                            bool existsInComponent = asComponent.DefaultState.Variables
                                                     .Any(item =>
                                                          (item.Name == requiredVariable.Name || item.ExposedAsName == requiredVariable.Name) &&
                                                          item.Type == requiredVariable.Type);

                            if (!existsInComponent)
                            {
                                message += $"Variable {requiredVariable.Name} of type {requiredVariable.Type} is required.\n";
                            }
                        }
                    }
                }

                bool showError = !string.IsNullOrEmpty(message);
                this.variableViewModel.HasErrors = showError ?
                                                   System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed;



                this.variableViewModel.ErrorInformation = message;
            }
        }
Esempio n. 28
0
        private PropertyDescriptorCollection DisplayCurrentInstance(PropertyDescriptorCollection pdc, InstanceSave instanceSave)
        {
            ElementSave elementSave = instanceSave.GetBaseElementSave();

            StateSave stateToDisplay;

            if (elementSave != null)
            {
                stateToDisplay = elementSave.States[0];
            }
            else
            {
                stateToDisplay = new StateSave();
            }

            pdc = DisplayCurrentElement(pdc, elementSave, instanceSave, stateToDisplay, instanceSave.Name, AmountToDisplay.ElementAndExposedOnly);

            return(pdc);
        }
Esempio n. 29
0
        private void RefreshElementTreeNode(TreeNode node, ElementSave elementSave)
        {
            List <InstanceSave> expandedInstances = new List <InstanceSave>();
            List <InstanceSave> allInstances      = elementSave.Instances;

            foreach (InstanceSave instance in allInstances)
            {
                var treeNode = GetTreeNodeFor(instance, node);

                if (treeNode?.Nodes.Count > 0 && treeNode?.IsExpanded == true)
                {
                    expandedInstances.Add(instance);
                }
            }

            node.Text = FileManager.RemovePath(elementSave.Name);
            node.Nodes.Clear();

            foreach (InstanceSave instance in allInstances)
            {
                TreeNode nodeForInstance = GetTreeNodeFor(instance, node);

                if (nodeForInstance == null)
                {
                    nodeForInstance = AddTreeNodeForInstance(instance, node);
                }

                if (expandedInstances.Contains(instance))
                {
                    nodeForInstance.Expand();
                }

                var siblingInstances = instance.GetSiblingsIncludingThis();
                var desiredIndex     = siblingInstances.IndexOf(instance);

                var nodeParent = nodeForInstance.Parent;
                if (desiredIndex != nodeParent.Nodes.IndexOf(nodeForInstance))
                {
                    nodeParent.Nodes.Remove(nodeForInstance);
                    nodeParent.Nodes.Insert(desiredIndex, nodeForInstance);
                }
            }
        }
Esempio n. 30
0
 private string GetElementPrefix(ElementSave element)
 {
     if (element is ScreenSave)
     {
         return(ElementReference.ScreenSubfolder + "/");
     }
     else if (element is ComponentSave)
     {
         return(ElementReference.ComponentSubfolder + "/");
     }
     else if (element is StandardElementSave)
     {
         return(ElementReference.StandardSubfolder + "/");
     }
     else
     {
         return(null);
     }
 }