コード例 #1
0
ファイル: ControlLogic.cs プロジェクト: gitter-badger/Gum
        public void RefreshSelector(ImageRegionSelectionControl control)
        {
            // early out
            if (control.RectangleSelector != null &&
                control.RectangleSelector.SideGrabbed != FlatRedBall.SpecializedXnaControls.RegionSelection.ResizeSide.None)
            {
                return;
            }

            if (shouldRefreshAccordingToVariableSets == false)
            {
                return;
            }

            //////////////end early out///////////////////////////////

            var shouldClearOut = true;

            if (SelectedState.Self.SelectedStateSave != null)
            {
                var graphicalUiElement = SelectedState.Self.SelectedIpso as GraphicalUiElement;
                var rfv            = new RecursiveVariableFinder(SelectedState.Self.SelectedStateSave);
                var instancePrefix = SelectedState.Self.SelectedInstance?.Name;

                if (!string.IsNullOrEmpty(instancePrefix))
                {
                    instancePrefix += ".";
                }

                var textureAddress = rfv.GetValue <Gum.Managers.TextureAddress>($"{instancePrefix}Texture Address");
                if (textureAddress == Gum.Managers.TextureAddress.Custom)
                {
                    shouldClearOut = false;
                    control.DesiredSelectorCount = 1;

                    var selector = control.RectangleSelector;


                    selector.Left  = rfv.GetValue <int>($"{instancePrefix}Texture Left");
                    selector.Width = rfv.GetValue <int>($"{instancePrefix}Texture Width");

                    selector.Top    = rfv.GetValue <int>($"{instancePrefix}Texture Top");
                    selector.Height = rfv.GetValue <int>($"{instancePrefix}Texture Height");

                    selector.Visible                = true;
                    selector.ShowHandles            = true;
                    selector.ShowMoveCursorWhenOver = true;

                    control.SystemManagers.Renderer.Camera.X =
                        selector.Left + selector.Width / 2.0f;
                    control.SystemManagers.Renderer.Camera.Y =
                        selector.Top + selector.Height / 2.0f;
                }
            }

            if (shouldClearOut)
            {
                control.DesiredSelectorCount = 0;
            }
        }
コード例 #2
0
        private static bool GetIfShouldInclude(VariableSave defaultVariable, ElementSave container, InstanceSave currentInstance, StandardElementSave rootElementSave)
        {
            bool shouldInclude = GetIfShouldIncludeAccordingToDefaultState(defaultVariable, container, currentInstance);

            if (shouldInclude)
            {
                shouldInclude = GetShouldIncludeBasedOnAttachments(defaultVariable, container, currentInstance);
            }

            if (shouldInclude)
            {
                shouldInclude = GetShouldIncludeBasedOnBaseType(defaultVariable, container, currentInstance, rootElementSave);
            }

            if (shouldInclude)
            {
                RecursiveVariableFinder rvf;
                if (currentInstance != null)
                {
                    rvf = new RecursiveVariableFinder(currentInstance, container);
                }
                else
                {
                    rvf = new RecursiveVariableFinder(container.DefaultState);
                }

                shouldInclude = !PluginManager.Self.ShouldExclude(defaultVariable, rvf);
            }

            return(shouldInclude);
        }
コード例 #3
0
ファイル: SetVariableLogic.cs プロジェクト: gitter-badger/Gum
        private void ReactIfChangedMemberIsSourceFile(ElementSave parentElement, InstanceSave instance, string changedMember, object oldValue)
        {
            string variableFullName;

            if (instance != null)
            {
                variableFullName = $"{instance.Name}.{changedMember}";
            }
            else
            {
                variableFullName = changedMember;
            }

            VariableSave variable = SelectedState.Self.SelectedStateSave?.GetVariableSave(variableFullName);

            bool isSourcefile = variable?.GetRootName() == "SourceFile";

            string errorMessage = null;

            if (isSourcefile)
            {
                errorMessage = GetWhySourcefileIsInvalid(variable.Value as string);

                if (!string.IsNullOrEmpty(errorMessage))
                {
                    MessageBox.Show(errorMessage);

                    variable.Value = oldValue;
                }
                else
                {
                    string value;

                    value = variable.Value as string;

                    if (!string.IsNullOrEmpty(value))
                    {
                        // See if this is relative to the project
                        var isRelativeToProject = FileManager.IsRelativeTo(
                            value,
                            ProjectState.Self.ProjectDirectory);

                        if (!isRelativeToProject)
                        {
                            bool shouldCopy = AskIfShouldCopy(variable, value);
                            if (shouldCopy)
                            {
                                PerformCopy(variable, value);
                            }
                        }
                    }

                    StateSave stateSave = SelectedState.Self.SelectedStateSave;

                    RecursiveVariableFinder rvf = new RecursiveVariableFinder(stateSave);

                    stateSave.SetValue("AnimationFrames", new List <string>());
                }
            }
        }
コード例 #4
0
        private static void TryGetFontReferences(TopLevelOrRecursive topLevelOrRecursive, List <string> listToFill, Gum.DataTypes.Variables.StateSave state)
        {
            Gum.DataTypes.RecursiveVariableFinder rvf = new RecursiveVariableFinder(state);

            foreach (var variable in state.Variables.Where(item =>
                                                           (item.GetRootName() == "Font" ||
                                                            item.GetRootName() == "FontSize" ||
                                                            item.GetRootName() == "OutlineThickness") &&
                                                           item.Value != null
                                                           ))
            {
                string prefix = null;

                if (variable.Name.Contains('.'))
                {
                    prefix = FileManager.RemoveExtension(variable.Name) + ".";
                }

                bool useCustomFont = rvf.GetValue <bool>(prefix + "UseCustomFont");
                if (!useCustomFont)
                {
                    var fontSizeVariableName    = prefix + "FontSize";
                    var fontNameVariableName    = prefix + "Font";
                    var fontOutlineVariableName = prefix + "OutlineThickness";

                    int    fontSizeValue    = rvf.GetValue <int>(fontSizeVariableName);
                    string fontNameValue    = rvf.GetValue <string>(fontNameVariableName);
                    int    outlineThickness = rvf.GetValue <int>(fontOutlineVariableName);

                    TryAddFontFromSizeAndName(topLevelOrRecursive, listToFill, fontSizeValue, fontNameValue, outlineThickness);
                }
            }
        }
コード例 #5
0
 private static void SetAlphaAndColorValues(Text text, RecursiveVariableFinder rvf)
 {
     Microsoft.Xna.Framework.Color color = ColorFromRvf(rvf);
     text.Red   = color.R;
     text.Green = color.G;
     text.Blue  = color.B;
     text.Alpha = color.A;  //Is alpha supported?
 }
コード例 #6
0
 static Microsoft.Xna.Framework.Color ColorFromRvf(RecursiveVariableFinder rvf)
 {
     Microsoft.Xna.Framework.Color color = new Microsoft.Xna.Framework.Color(
         rvf.GetValue <int>("Red"),
         rvf.GetValue <int>("Green"),
         rvf.GetValue <int>("Blue"),
         rvf.GetValue <int>("Alpha")
         );
     return(color);
 }
コード例 #7
0
ファイル: CodeGenerator.cs プロジェクト: derKosi/Gum
        private static void FillWithVariableAssignments(ElementSave element, VisualApi visualApi, StringBuilder stringBuilder, int tabCount = 0)
        {
            #region Get variables to consider
            var defaultState = SelectedState.Self.SelectedElement.DefaultState;

            var baseElement = ObjectFinder.Self.GetElementSave(element.BaseType);
            RecursiveVariableFinder recursiveVariableFinder = null;

            // This is null if it's a screen, or there's some bad reference
            if (baseElement != null)
            {
                recursiveVariableFinder = new RecursiveVariableFinder(baseElement.DefaultState);
            }


            var variablesToConsider = defaultState.Variables
                                      .Where(item =>
            {
                var shouldInclude =
                    item.Value != null &&
                    item.SetsValue &&
                    string.IsNullOrEmpty(item.SourceObject);

                if (shouldInclude && recursiveVariableFinder != null)
                {
                    // We want to make sure that the variable is defined in the base object. If it isn't, then
                    // it could be a leftover variable caused by having this object be of one type, using a variable
                    // specific to that type, then changing it to another type. Gum holds on to these varibles in case
                    // the type change was accidental, but it means we have to watch for these orphan variables when generating.
                    var foundVariable = recursiveVariableFinder.GetVariable(item.Name);
                    shouldInclude     = foundVariable != null;
                }

                return(shouldInclude);
            })
                                      .ToList();

            #endregion

            var tabs = new String(' ', 4 * tabCount);

            ProcessVariableGroups(variablesToConsider, defaultState, null, element, visualApi, stringBuilder, tabCount);

            foreach (var variable in variablesToConsider)
            {
                var codeLine = GetCodeLine(null, variable, element, visualApi, defaultState);
                stringBuilder.AppendLine(tabs + codeLine);

                var suffixCodeLine = GetSuffixCodeLine(null, variable, visualApi);
                if (!string.IsNullOrEmpty(suffixCodeLine))
                {
                    stringBuilder.AppendLine(tabs + suffixCodeLine);
                }
            }
        }
コード例 #8
0
ファイル: PluginBase.cs プロジェクト: Kr3m/Gum
 internal bool GetIfVariableIsExcluded(VariableSave defaultVariable, RecursiveVariableFinder rvf)
 {
     if (VariableExcluded == null)
     {
         return(false);
     }
     else
     {
         return(VariableExcluded(defaultVariable, rvf));
     }
 }
コード例 #9
0
        private float GetParentHeight(InstanceSave instance)
        {
            string parent = new RecursiveVariableFinder(instance, instance.ParentContainer).GetValue <string>("Parent");

            if (string.IsNullOrEmpty(parent))
            {
                return(GumProjectSave.DefaultCanvasHeight);
            }
            else
            {
                throw new NotImplementedException();
            }
        }
コード例 #10
0
ファイル: VariableSaveLogic.cs プロジェクト: patridge/Gum
        public static bool GetIfVariableIsActive(VariableSave defaultVariable, ElementSave container, InstanceSave currentInstance)
        {
            bool shouldInclude = GetIfShouldIncludeAccordingToDefaultState(defaultVariable, container, currentInstance);

            if (shouldInclude)
            {
                shouldInclude = GetShouldIncludeBasedOnAttachments(defaultVariable, container, currentInstance);
            }

            if (shouldInclude)
            {
                StandardElementSave rootElementSave = null;

                if (currentInstance != null)
                {
                    rootElementSave = ObjectFinder.Self.GetRootStandardElementSave(currentInstance);
                }
                else if ((container is ScreenSave) == false)
                {
                    rootElementSave = ObjectFinder.Self.GetRootStandardElementSave(container);
                }

                shouldInclude = GetShouldIncludeBasedOnBaseType(defaultVariable, container, currentInstance, rootElementSave);
            }

            if (shouldInclude)
            {
                if (currentInstance != null && defaultVariable.ExcludeFromInstances)
                {
                    shouldInclude = false;
                }
            }

            if (shouldInclude)
            {
                RecursiveVariableFinder rvf;
                if (currentInstance != null)
                {
                    rvf = new RecursiveVariableFinder(currentInstance, container);
                }
                else
                {
                    rvf = new RecursiveVariableFinder(container.DefaultState);
                }

                shouldInclude = !PluginManager.Self.ShouldExclude(defaultVariable, rvf);
            }

            return(shouldInclude);
        }
コード例 #11
0
        public void UpdateSelectedObjectsPositionAndDimensions()
        {
            var elementStack = SelectedState.Self.GetTopLevelElementStack();

            if (SelectedState.Self.SelectedInstances.GetCount() != 0)
            {
                foreach (var instance in SelectedState.Self.SelectedInstances)
                {
                    RefreshPositionsAndScalesForInstance(instance, elementStack);
                }

                foreach (var ipso in SelectedState.Self.SelectedIpsos)
                {
                    GraphicalUiElement asGue = ipso as GraphicalUiElement;
                    if (asGue != null)
                    {
                        RecursiveVariableFinder rvf = new RecursiveVariableFinder(asGue.Tag as InstanceSave, SelectedState.Self.SelectedElement);
                        asGue.SetGueValues(rvf);
                    }
                }
            }
            else
            {
                GraphicalUiElement ipso = WireframeObjectManager.Self.GetSelectedRepresentation();

                if (ipso != null)
                {
                    ElementSave elementSave = SelectedState.Self.SelectedElement;

                    var state = elementSave.DefaultState;
                    if (SelectedState.Self.SelectedStateSave != null)
                    {
                        state = SelectedState.Self.SelectedStateSave;
                    }
                    RecursiveVariableFinder rvf = new RecursiveVariableFinder(state);
                    (ipso as GraphicalUiElement).SetGueValues(rvf);
                }
                else if (SelectedState.Self.SelectedElement != null)
                {
                    foreach (var instance in SelectedState.Self.SelectedElement.Instances)
                    {
                        RefreshPositionsAndScalesForInstance(instance, elementStack);
                    }
                }
            }

            GuiCommands.Self.RefreshWireframe();
        }
コード例 #12
0
        private NamedObjectSave CreateNosFor(InstanceSave instance, IElement container)
        {
            NamedObjectSave nos = new NamedObjectSave();

            string name = instance.Name;

            // See if this name is already used by RFS's
            var allRfss = container.GetAllReferencedFileSavesRecursively();

            while (allRfss.Any(item => item.GetInstanceName() == name) || container.ReferencedFiles.Any(item => item.Name == name))
            {
                name = name + instance.BaseType;
            }

            nos.InstanceName = name;
            RecursiveVariableFinder rvf = new RecursiveVariableFinder(instance, instance.ParentContainer);

            if (instance.BaseType == "Sprite")
            {
                nos.SourceType      = SourceType.FlatRedBallType;
                nos.SourceClassType = "Sprite";

                float width  = rvf.GetValue <float>("Width");
                float height = rvf.GetValue <float>("Height");

                if (width == 0 && height == 0)
                {
                    nos.SetPropertyValue("TextureScale", 1.0f);
                }
                else
                {
                    // Eventually handle width/height
                    nos.SetPropertyValue("Width", width);
                    nos.SetPropertyValue("Height", height);
                }

                SetPositionValuesOn(nos, instance);

                string texture = rvf.GetValue <string>("SourceFile");

                string fileInstanceName = FileManager.RemoveExtension(FileManager.RemovePath(texture));

                var added = nos.SetPropertyValue("Texture", fileInstanceName);
                added.Type = "Texture2D";
            }
            return(nos);
        }
コード例 #13
0
ファイル: CodeGenerator.cs プロジェクト: derKosi/Gum
        private static void ProcessColorForLabel(List <VariableSave> variablesToConsider, StateSave defaultState, InstanceSave instance, StringBuilder stringBuilder)
        {
            var instanceName = instance.Name;
            var rfv          = new RecursiveVariableFinder(defaultState);

            var red   = rfv.GetValue <int>(instanceName + ".Red");
            var green = rfv.GetValue <int>(instanceName + ".Green");
            var blue  = rfv.GetValue <int>(instanceName + ".Blue");
            var alpha = rfv.GetValue <int>(instanceName + ".Alpha");

            variablesToConsider.RemoveAll(item => item.Name == instanceName + ".Red");
            variablesToConsider.RemoveAll(item => item.Name == instanceName + ".Green");
            variablesToConsider.RemoveAll(item => item.Name == instanceName + ".Blue");
            variablesToConsider.RemoveAll(item => item.Name == instanceName + ".Alpha");

            stringBuilder.AppendLine($"{instanceName}.TextColor = Color.FromRgba({red}, {green}, {blue}, {alpha});");
        }
コード例 #14
0
        private NamedObjectSave CreateNosFor(InstanceSave instance, IElement container)
        {

            NamedObjectSave nos = new NamedObjectSave();

            string name = instance.Name;

            // See if this name is already used by RFS's
            var allRfss = container.GetAllReferencedFileSavesRecursively();
            while (allRfss.Any(item => item.GetInstanceName() == name) || container.ReferencedFiles.Any(item => item.Name == name))
            {
                name = name + instance.BaseType;
            }

            nos.InstanceName = name;
            RecursiveVariableFinder rvf = new RecursiveVariableFinder(instance, instance.ParentContainer);
            if (instance.BaseType == "Sprite")
            {
                nos.SourceType = SourceType.FlatRedBallType;
                nos.SourceClassType = "Sprite";

                float width = rvf.GetValue<float>("Width");
                float height = rvf.GetValue<float>("Height");

                if (width == 0 && height == 0)
                {
                    nos.SetPropertyValue("TextureScale", 1.0f);
                }
                else
                {
                    // Eventually handle width/height
                    nos.SetPropertyValue("Width", width);
                    nos.SetPropertyValue("Height", height);
                }

                SetPositionValuesOn(nos, instance);

                string texture = rvf.GetValue<string>("SourceFile");

                string fileInstanceName = FileManager.RemoveExtension(FileManager.RemovePath(texture));

                var added = nos.SetPropertyValue("Texture", fileInstanceName);
                added.Type = "Texture2D";
            }
            return nos;
        }
コード例 #15
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);
                    }
                }
            }
        }
コード例 #16
0
        public static bool IsParentASibling(this InstanceSave instanceSave, List<ElementWithState> elementStack)
        {
            if (instanceSave == null)
            {
                throw new ArgumentException("InstanceSave must not be null");
            }

            RecursiveVariableFinder rvf = new RecursiveVariableFinder(instanceSave, elementStack);

            string parent = rvf.GetValue<string>("Parent");
            bool found = false;
            if (!string.IsNullOrEmpty(parent) && parent != AvailableInstancesConverter.ScreenBoundsName)
            {
                ElementSave parentElement = instanceSave.ParentContainer;

                found = parentElement.Instances.Any(item => item.Name == parent);
            }

            return found;
        }
コード例 #17
0
        public float GetEffectiveHeight(InstanceSave instance)
        {
            RecursiveVariableFinder rvf = new RecursiveVariableFinder(instance, instance.ParentContainer);

            float height = rvf.GetValue <float>("Height");


            if (height == 0)
            {
                string sourceFile = rvf.GetValue <string>("SourceFile");
                if (instance.BaseType == "Sprite")
                {
                    if (!string.IsNullOrEmpty(sourceFile))
                    {
                        string fullFileName = FileManager.GetDirectory(GumProjectSave.FullFileName) + sourceFile;
                        height = ImageHeader.GetDimensions(fullFileName).Height;
                    }
                }
            }

            return(height);
        }
コード例 #18
0
ファイル: PluginManager.cs プロジェクト: Kr3m/Gum
        internal bool ShouldExclude(VariableSave defaultVariable, RecursiveVariableFinder rvf)
        {
            bool shouldExclude = false;

            foreach (var plugin in this.Plugins.Where(item => this.PluginContainers[item].IsEnabled))
            {
                PluginContainer container = this.PluginContainers[plugin];

                if (container.Plugin is PluginBase)
                {
                    try
                    {
                        shouldExclude |= ((PluginBase)container.Plugin).GetIfVariableIsExcluded(defaultVariable, rvf);
                    }
                    catch (Exception e)
                    {
                        container.Fail(e, "Failed in GetIfVariableIsExcluded");
                    }
                }
            }
            return(shouldExclude);
        }
コード例 #19
0
 private static void SetAlphaAndColorValues(Text text, RecursiveVariableFinder rvf)
 {
     Microsoft.Xna.Framework.Color color = ColorFromRvf(rvf);
     text.Red = color.R;
     text.Green = color.G;
     text.Blue = color.B;
     text.Alpha = color.A;  //Is alpha supported?
 }
コード例 #20
0
 private static void SetAlphaAndColorValues(Sprite sprite, RecursiveVariableFinder rvf)
 {
     sprite.Color = ColorFromRvf(rvf);
 }
コード例 #21
0
 private static void SetAlphaAndColorValues(NineSlice nineSlice, RecursiveVariableFinder rvf)
 {
     nineSlice.Color = ColorFromRvf(rvf);
 }
コード例 #22
0
ファイル: EditingManager.cs プロジェクト: jiailiuyan/Gum
        public void UpdateSelectedObjectsPositionAndDimensions()
        {
            var elementStack = SelectedState.Self.GetTopLevelElementStack();
            if (SelectedState.Self.SelectedInstances.GetCount() != 0)
            {
                foreach (var instance in SelectedState.Self.SelectedInstances)
                {
                    RefreshPositionsAndScalesForInstance(instance, elementStack);
                }

                foreach (var ipso in SelectedState.Self.SelectedIpsos)
                {
                    GraphicalUiElement asGue = ipso as GraphicalUiElement;
                    if (asGue != null)
                    {
                        RecursiveVariableFinder rvf = new RecursiveVariableFinder(asGue.Tag as InstanceSave, SelectedState.Self.SelectedElement);
                        asGue.SetGueValues(rvf);
                    }
                }
            }
            else
            {
                GraphicalUiElement ipso = WireframeObjectManager.Self.GetSelectedRepresentation();

                if (ipso != null)
                {
                    ElementSave elementSave = SelectedState.Self.SelectedElement;

                    var state = elementSave.DefaultState;
                    if(SelectedState.Self.SelectedStateSave != null)
                    {
                        state = SelectedState.Self.SelectedStateSave;
                    }
                    RecursiveVariableFinder rvf = new RecursiveVariableFinder(state);
                    (ipso as GraphicalUiElement).SetGueValues(rvf);
                }
                else if(SelectedState.Self.SelectedElement != null)
                {
                    foreach (var instance in SelectedState.Self.SelectedElement.Instances)
                    {
                        RefreshPositionsAndScalesForInstance(instance, elementStack);
                    }
                }
            }

            GuiCommands.Self.RefreshWireframe();
        }
コード例 #23
0
ファイル: CodeGenerator.cs プロジェクト: derKosi/Gum
        private static void ProcessPositionAndSize(List <VariableSave> variablesToConsider, StateSave defaultState, InstanceSave instance, StringBuilder stringBuilder, int tabCount)
        {
            string prefix = instance?.Name == null ? "" : instance.Name + ".";

            var setsAny =
                defaultState.Variables.Any(item =>
                                           item.Name == prefix + "X" ||
                                           item.Name == prefix + "Y" ||
                                           item.Name == prefix + "Width" ||
                                           item.Name == prefix + "Height" ||

                                           item.Name == prefix + "X Units" ||
                                           item.Name == prefix + "Y Units" ||
                                           item.Name == prefix + "Width Units" ||
                                           item.Name == prefix + "Height Units" ||
                                           item.Name == prefix + "X Origin" ||
                                           item.Name == prefix + "Y Origin"

                                           );

            if (setsAny)
            {
                var variableFinder = new RecursiveVariableFinder(defaultState);

                var x      = variableFinder.GetValue <float>(prefix + "X");
                var y      = variableFinder.GetValue <float>(prefix + "Y");
                var width  = variableFinder.GetValue <float>(prefix + "Width");
                var height = variableFinder.GetValue <float>(prefix + "Height");

                var xUnits      = variableFinder.GetValue <PositionUnitType>(prefix + "X Units");
                var yUnits      = variableFinder.GetValue <PositionUnitType>(prefix + "Y Units");
                var widthUnits  = variableFinder.GetValue <DimensionUnitType>(prefix + "Width Units");
                var heightUnits = variableFinder.GetValue <DimensionUnitType>(prefix + "Height Units");

                var xOrigin = variableFinder.GetValue <HorizontalAlignment>(prefix + "X Origin");
                var yOrigin = variableFinder.GetValue <VerticalAlignment>(prefix + "Y Origin");

                variablesToConsider.RemoveAll(item => item.Name == prefix + "X");
                variablesToConsider.RemoveAll(item => item.Name == prefix + "Y");
                variablesToConsider.RemoveAll(item => item.Name == prefix + "Width");
                variablesToConsider.RemoveAll(item => item.Name == prefix + "Height");
                variablesToConsider.RemoveAll(item => item.Name == prefix + "X Units");
                variablesToConsider.RemoveAll(item => item.Name == prefix + "Y Units");
                variablesToConsider.RemoveAll(item => item.Name == prefix + "Width Units");
                variablesToConsider.RemoveAll(item => item.Name == prefix + "Height Units");

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

                const string WidthProportionalFlag  = "AbsoluteLayoutFlags.WidthProportional";
                const string HeightProportionalFlag = "AbsoluteLayoutFlags.HeightProportional";
                const string XProportionalFlag      = "AbsoluteLayoutFlags.XProportional";
                const string YProportionalFlag      = "AbsoluteLayoutFlags.YProportional";

                if (widthUnits == DimensionUnitType.Percentage)
                {
                    width /= 100.0f;
                    proportionalFlags.Add(WidthProportionalFlag);
                }
                else if (widthUnits == DimensionUnitType.RelativeToContainer)
                {
                    if (width == 0)
                    {
                        width = 1;
                        proportionalFlags.Add(WidthProportionalFlag);
                    }
                    else
                    {
                        // not allowed!!!
                    }
                }
                if (heightUnits == DimensionUnitType.Percentage)
                {
                    height /= 100.0f;
                    proportionalFlags.Add(HeightProportionalFlag);
                }
                else if (heightUnits == DimensionUnitType.RelativeToContainer)
                {
                    if (height == 0)
                    {
                        height = 1;
                        proportionalFlags.Add(HeightProportionalFlag);
                    }
                    else
                    {
                        // not allowed!
                    }
                }

                // special case
                // If we're using the center with x=0 we'll pretend it's the same as 50%
                if (xUnits == PositionUnitType.PixelsFromCenterX && widthUnits == DimensionUnitType.Absolute && xOrigin == HorizontalAlignment.Center)
                {
                    if (x == 0)
                    {
                        // treat it like it's 50%:
                        x = .5f;
                        proportionalFlags.Add(XProportionalFlag);
                    }
                }
                // Xamarin forms uses a weird anchoring system to combine both position and anchor into one value. Gum splits those into two values
                // We need to convert from the gum units to xamforms units:
                // for now assume it's all %'s:

                else if (xUnits == PositionUnitType.PercentageWidth)
                {
                    x /= 100.0f;
                    var adjustedCanvasWidth = 1 - width;
                    if (adjustedCanvasWidth > 0)
                    {
                        x /= adjustedCanvasWidth;
                    }
                    proportionalFlags.Add(XProportionalFlag);
                }
                else if (xUnits == PositionUnitType.PixelsFromLeft)
                {
                }
                else if (xUnits == PositionUnitType.PixelsFromCenterX)
                {
                    if (widthUnits == DimensionUnitType.Absolute)
                    {
                        x = (CanvasWidth - width) / 2.0f;
                    }
                }

                if (yUnits == PositionUnitType.PixelsFromCenterY && heightUnits == DimensionUnitType.Absolute && yOrigin == VerticalAlignment.Center)
                {
                    if (y == 0)
                    {
                        y = .5f;
                        proportionalFlags.Add(YProportionalFlag);
                    }
                }
                else if (yUnits == PositionUnitType.PercentageHeight)
                {
                    y /= 100.0f;
                    var adjustedCanvasHeight = 1 - height;
                    if (adjustedCanvasHeight > 0)
                    {
                        y /= adjustedCanvasHeight;
                    }
                    proportionalFlags.Add(YProportionalFlag);
                }
                else if (yUnits == PositionUnitType.PixelsFromCenterY)
                {
                    if (heightUnits == DimensionUnitType.Absolute)
                    {
                        y = (CanvasHeight - height) / 2.0f;
                    }
                }
                else if (yUnits == PositionUnitType.PixelsFromBottom)
                {
                    y += CanvasHeight;

                    if (yOrigin == VerticalAlignment.Bottom)
                    {
                        y -= height;
                    }
                }



                var xString      = x.ToString(CultureInfo.InvariantCulture) + "f";
                var yString      = y.ToString(CultureInfo.InvariantCulture) + "f";
                var widthString  = width.ToString(CultureInfo.InvariantCulture) + "f";
                var heightString = height.ToString(CultureInfo.InvariantCulture) + "f";

                if (AdjustPixelValuesForDensity)
                {
                    if (proportionalFlags.Contains(XProportionalFlag) == false)
                    {
                        xString += "/Xamarin.Essentials.DeviceDisplay.MainDisplayInfo.Density";
                    }
                    if (proportionalFlags.Contains(YProportionalFlag) == false)
                    {
                        yString += "/Xamarin.Essentials.DeviceDisplay.MainDisplayInfo.Density";
                    }
                    if (proportionalFlags.Contains(WidthProportionalFlag) == false)
                    {
                        widthString += "/Xamarin.Essentials.DeviceDisplay.MainDisplayInfo.Density";
                    }
                    if (proportionalFlags.Contains(HeightProportionalFlag) == false)
                    {
                        heightString += "/Xamarin.Essentials.DeviceDisplay.MainDisplayInfo.Density";
                    }
                }

                string boundsText =
                    $"{ToTabs(tabCount)}AbsoluteLayout.SetLayoutBounds({instance?.Name ?? "this"}, new Rectangle({xString}, {yString}, {widthString}, {heightString}));";
                string flagsText = null;
                if (proportionalFlags.Count > 0)
                {
                    string flagsArguments = null;
                    for (int i = 0; i < proportionalFlags.Count; i++)
                    {
                        if (i > 0)
                        {
                            flagsArguments += " | ";
                        }
                        flagsArguments += proportionalFlags[i];
                    }
                    flagsText = $"{ToTabs(tabCount)}AbsoluteLayout.SetLayoutFlags({instance?.Name ?? "this"}, {flagsArguments});";
                }
                // assume every object has X, which it won't, so we will have to improve this
                if (string.IsNullOrWhiteSpace(flagsText))
                {
                    stringBuilder.AppendLine(boundsText);
                }
                else
                {
                    stringBuilder.AppendLine($"{boundsText}\n{flagsText}");
                }
            }
        }
コード例 #24
0
ファイル: SetVariableLogic.cs プロジェクト: Kr3m/Gum
        private void ReactIfChangedMemberIsTextureAddress(ElementSave parentElement, string changedMember, object oldValue)
        {
            if (changedMember == "Texture Address")
            {
                RecursiveVariableFinder rvf;

                var instance = SelectedState.Self.SelectedInstance;
                if (instance != null)
                {
                    rvf = new RecursiveVariableFinder(SelectedState.Self.SelectedInstance, parentElement);
                }
                else
                {
                    rvf = new RecursiveVariableFinder(parentElement.DefaultState);
                }

                var textureAddress = rvf.GetValue <TextureAddress>("Texture Address");

                if (textureAddress == TextureAddress.Custom)
                {
                    string sourceFile = rvf.GetValue <string>("SourceFile");

                    if (!string.IsNullOrEmpty(sourceFile))
                    {
                        string absolute = ProjectManager.Self.MakeAbsoluteIfNecessary(sourceFile);

                        if (System.IO.File.Exists(absolute))
                        {
                            var texture = LoaderManager.Self.LoadContent <Texture2D>(absolute);

                            if (texture != null && instance != null)
                            {
                                parentElement.DefaultState.SetValue(instance.Name + ".Texture Top", 0);
                                parentElement.DefaultState.SetValue(instance.Name + ".Texture Left", 0);
                                parentElement.DefaultState.SetValue(instance.Name + ".Texture Width", texture.Width);
                                parentElement.DefaultState.SetValue(instance.Name + ".Texture Height", texture.Height);
                            }
                        }
                    }
                }
                if (textureAddress == TextureAddress.DimensionsBased)
                {
                    // if the values are 0, then we should set them to 1:
                    float widthScale  = rvf.GetValue <float>("Texture Width Scale");
                    float heightScale = rvf.GetValue <float>("Texture Height Scale");

                    if (widthScale == 0)
                    {
                        if (instance != null)
                        {
                            SelectedState.Self.SelectedStateSave.SetValue(instance.Name + ".Texture Width Scale", 1.0f);
                        }
                        else
                        {
                            SelectedState.Self.SelectedStateSave.SetValue("Texture Width Scale", 1.0f);
                        }
                    }

                    if (heightScale == 0)
                    {
                        if (instance != null)
                        {
                            SelectedState.Self.SelectedStateSave.SetValue(instance.Name + ".Texture Height Scale", 1.0f);
                        }
                        else
                        {
                            SelectedState.Self.SelectedStateSave.SetValue("Texture Height Scale", 1.0f);
                        }
                    }
                }
            }
        }
コード例 #25
0
ファイル: PluginBase.cs プロジェクト: jiailiuyan/Gum
 internal bool GetIfVariableIsExcluded(VariableSave defaultVariable, RecursiveVariableFinder rvf)
 {
     if (VariableExcluded == null)
     {
         return false;
     }
     else
     {
         return VariableExcluded(defaultVariable, rvf);
     }
 }
コード例 #26
0
 private static void SetAlphaAndColorValues(SolidRectangle solidRectangle, RecursiveVariableFinder rvf)
 {
     solidRectangle.Color = ColorFromRvf(rvf);
 }
コード例 #27
0
 private static void SetAlphaAndColorValues(NineSlice nineSlice, RecursiveVariableFinder rvf)
 {
     nineSlice.Color = ColorFromRvf(rvf);
 }
コード例 #28
0
        private bool GetIfShouldGenerateStateVariable(Gum.DataTypes.Variables.VariableSave variable, ElementSave container)
        {
            bool toReturn = true;

            string variableName = variable.GetRootName();



            if (variable.Value == null || !variable.SetsValue)
            {
                toReturn = false;
            }
            // states can't set states on this
            if (variable.IsState(container) && string.IsNullOrEmpty(variable.SourceObject))
            {
                toReturn = false;
            }

            if (toReturn && mVariableNamesToSkipForStates.Contains(variableName))
            {
                toReturn = false;
            }

            bool hasSourceObject = !string.IsNullOrEmpty(variable.SourceObject);

            if (toReturn && hasSourceObject)
            {
                InstanceSave instanceSave = container.GetInstance(variable.SourceObject);

                if (instanceSave == null)
                {
                    toReturn = false;
                }
                else
                {
                    var baseElement = Gum.Managers.ObjectFinder.Self.GetElementSave(instanceSave.BaseType);

                    if (baseElement == null)
                    {
                        toReturn = false;
                    }

                    if (toReturn)
                    {
                        // Gum (just like Glue) keeps variables that aren't needed around.  This allows users to rename things and not lose
                        // important information accidentally.  But because of that we have to make sure that the variable we're working with is
                        // valid for the type of object we're dealing with.
                        var defaultState = baseElement.DefaultState;

                        RecursiveVariableFinder rvf = new RecursiveVariableFinder(defaultState);

                        var foundVariable = rvf.GetVariable(variable.GetRootName());

                        if (foundVariable == null)
                        {
                            // This doesn't exist anywhere in the inheritance chain, so we don't want to generate it:
                            toReturn = false;
                        }
                    }
                }
            }

            if (toReturn && !hasSourceObject)
            {
                // If a variable is part of a component, it better be defined in the base type or else we won't generate it.
                // For example, consider a component that used to inherit from Text. It will have variables for fonts. If that
                // component switches to inheriting from Sprite, those variables will still exist in the XML for that component,
                // but we shouldn't generate any state variables for those variables. So we'll go to the base type and see if those
                // variables exist
                bool isComponent = container is ComponentSave;

                var rootComponent = Gum.Managers.ObjectFinder.Self.GetRootStandardElementSave(container);

                // If the Container is a Screen, then rootComponent will be null, so we don't need to do anything
                if (rootComponent == null)
                {
                    toReturn = false;
                }
                else
                {
                    IEnumerable <VariableSave> variablesToCheck;

                    if (isComponent)
                    {
                        var component = Gum.Managers.ObjectFinder.Self.GetStandardElement("Component");

                        variablesToCheck = rootComponent.DefaultState.Variables.Concat(component.DefaultState.Variables);
                    }
                    else
                    {
                        var defaultState = rootComponent.DefaultState;

                        variablesToCheck = defaultState.Variables;
                    }


                    bool wasMatchFound = variablesToCheck.Any(item => item.Name == variable.GetRootName());
                    toReturn = wasMatchFound;
                }
            }



            return(toReturn);
        }
コード例 #29
0
ファイル: VariableSetLogic.cs プロジェクト: patridge/Gum
        private static bool TryHandleAssigningMultipleVariables(ElementSave gumElement, GumInstance gumInstance, string variableName, GlueElement glueElement, FlatRedBall.Glue.SaveClasses.NamedObjectSave foundNos, object gumValue)
        {
            var isTextureValue = variableName == "Texture Address" ||
                                 variableName == "Texture Left" ||
                                 variableName == "Texture Top" ||
                                 variableName == "Texture Width" ||
                                 variableName == "Texture Height";

            var handled = false;

            if (isTextureValue)
            {
                string variablePrefix = null;
                if (gumInstance != null)
                {
                    variablePrefix = $"{gumInstance.Name}.";
                }
                var state = SelectedState.Self.SelectedStateSave;
                var addressValueGumCurrent       = state.GetValue($"{variablePrefix}Texture Address");
                var textureLeftValueGumCurrent   = state.GetValue($"{variablePrefix}Texture Left");
                var textureWidthValueGumCurrent  = state.GetValue($"{variablePrefix}Texture Width");
                var textureTopValueGumCurrent    = state.GetValue($"{variablePrefix}Texture Top");
                var textureHeightValueGumCurrent = state.GetValue($"{variablePrefix}Texture Height");

                var setsAny = addressValueGumCurrent != null ||
                              textureLeftValueGumCurrent != null ||
                              textureWidthValueGumCurrent != null ||
                              textureTopValueGumCurrent != null ||
                              textureHeightValueGumCurrent != null;

                if (setsAny)
                {
                    var rvf = new RecursiveVariableFinder(state);
                    var addressValueGumRecursive = rvf.GetValue <TextureAddress>($"{variablePrefix}Texture Address");

                    // set them all

                    if (addressValueGumRecursive == TextureAddress.EntireTexture)
                    {
                        // null them out:
                        HandleIndividualVariableAssignment(gumElement, gumInstance, "Texture Left", glueElement, foundNos, null);
                        HandleIndividualVariableAssignment(gumElement, gumInstance, "Texture Right", glueElement, foundNos, null);
                        HandleIndividualVariableAssignment(gumElement, gumInstance, "Texture Top", glueElement, foundNos, null);
                        HandleIndividualVariableAssignment(gumElement, gumInstance, "Texture Bottom", glueElement, foundNos, null);
                    }
                    else
                    {
                        // set the values:
                        HandleIndividualVariableAssignment(gumElement, gumInstance, "Texture Left", glueElement, foundNos, IntToNullOrFloat(textureLeftValueGumCurrent));
                        HandleIndividualVariableAssignment(gumElement, gumInstance, "Texture Top", glueElement, foundNos, IntToNullOrFloat(textureTopValueGumCurrent));

                        // right and bottom depend on left/top plus width/height
                        if (textureLeftValueGumCurrent != null && textureWidthValueGumCurrent != null)
                        {
                            var combined = (int)textureLeftValueGumCurrent + (int)textureWidthValueGumCurrent;
                            HandleIndividualVariableAssignment(gumElement, gumInstance, "Texture Right", glueElement, foundNos, (float)combined);
                        }
                        else
                        {
                            HandleIndividualVariableAssignment(gumElement, gumInstance, "Texture Right", glueElement, foundNos, IntToNullOrFloat(null));
                        }

                        if (textureTopValueGumCurrent != null && textureHeightValueGumCurrent != null)
                        {
                            var combined = (int)textureTopValueGumCurrent + (int)textureHeightValueGumCurrent;
                            HandleIndividualVariableAssignment(gumElement, gumInstance, "Texture Bottom", glueElement, foundNos, (float)combined);
                        }
                        else
                        {
                            HandleIndividualVariableAssignment(gumElement, gumInstance, "Texture Bottom", glueElement, foundNos, null);
                        }
                    }
                }
                else
                {
                    // null them all
                    HandleIndividualVariableAssignment(gumElement, gumInstance, "Texture Left", glueElement, foundNos, null);
                    HandleIndividualVariableAssignment(gumElement, gumInstance, "Texture Right", glueElement, foundNos, null);
                    HandleIndividualVariableAssignment(gumElement, gumInstance, "Texture Top", glueElement, foundNos, null);
                    HandleIndividualVariableAssignment(gumElement, gumInstance, "Texture Bottom", glueElement, foundNos, null);
                }



                handled = true;
            }

            return(handled);
        }
コード例 #30
0
        public static VariableSave GetVariableFromThisOrBase(this InstanceSave instance,
            List<ElementWithState> elementStack, RecursiveVariableFinder rvf, string variable, bool forceDefault, bool onlyIfSetsValue)
        {
            ElementSave instanceBase = ObjectFinder.Self.GetElementSave(instance.BaseType);

            List<StateSave> statesToPullFrom;
            StateSave defaultState;
            GetStatesToUse(instance, elementStack, forceDefault, instanceBase, rvf, out statesToPullFrom, out defaultState);


            VariableSave variableSave = null;

            // See if the variable is set by the container of the instance:
            foreach (var stateToPullFrom in statesToPullFrom)
            {
                var possibleVariable = stateToPullFrom.GetVariableSave(instance.Name + "." + variable);
                if (possibleVariable != null)
                {
                    variableSave = possibleVariable;
                }
            }
            // non-default states can override the default state, so first
            // let's see if the selected state is non-default and has a value
            // for a given variable.  If not, we'll fall back to the default.
            if ((variableSave == null || (onlyIfSetsValue && variableSave.SetsValue == false)) && !statesToPullFrom.Contains(defaultState))
            {
                variableSave = defaultState.GetVariableSave(instance.Name + "." + variable);
            }

            // Still haven't found a variable yet, so look in the instanceBase if one exists
            if ((variableSave == null || 
                (onlyIfSetsValue && (variableSave.SetsValue == false || variableSave.Value == null))) && instanceBase != null)
            {
                VariableSave foundVariableSave = TryGetVariableFromStatesOnInstance(instance, variable, instanceBase, statesToPullFrom);

                if (foundVariableSave != null)
                {
                    variableSave = foundVariableSave;
                }
            }

            // I don't think we have to do this because we're going to copy over
            // the variables to all components on load.
            //if (variableSave == null && instanceBase != null && instanceBase is ComponentSave)
            //{
            //    variableSave = StandardElementsManager.Self.DefaultStates["Component"].GetVariableSave(variable);
            //}

            if (variableSave != null && variableSave.Value == null && instanceBase != null && onlyIfSetsValue)
            {
                // This can happen if there is a tunneled variable that is null
                VariableSave possibleVariable = instanceBase.DefaultState.GetVariableSave(variable);
                if (possibleVariable != null && possibleVariable.Value != null && (!onlyIfSetsValue || possibleVariable.SetsValue))
                {
                    variableSave = possibleVariable;
                }
                else if (!string.IsNullOrEmpty(instanceBase.BaseType))
                {
                    ElementSave element = ObjectFinder.Self.GetElementSave(instanceBase.BaseType);

                    if (element != null)
                    {
                        variableSave = element.GetVariableFromThisOrBase(variable, forceDefault);
                    }
                }
            }

            return variableSave;

        }
コード例 #31
0
        private void ReactIfChangedMemberIsTexture(ElementSave parentElement, string changedMember, object oldValue)
        {
            VariableSave variable = SelectedState.Self.SelectedVariableSave;

            // Eventually need to handle tunneled variables
            if (variable != null && variable.GetRootName() == "SourceFile")
            {
                string value = variable.Value as string;

                if (!string.IsNullOrEmpty(value))
                {
                    // See if this is relative to the project
                    bool isRelativeToProject = !value.StartsWith("../") && !value.StartsWith("..\\");

                    if (!isRelativeToProject)
                    {
                        // Ask the user what to do - make it relative?
                        MultiButtonMessageBox mbmb = new
                                                     MultiButtonMessageBox();

                        mbmb.MessageText = "The file\n" + value + "\nis not relative to the project.  What would you like to do?";
                        mbmb.AddButton("Reference the file in its current location", DialogResult.OK);
                        mbmb.AddButton("Copy the file relative to the Gum project and reference the copy", DialogResult.Yes);

                        var dialogResult = mbmb.ShowDialog();

                        bool shouldCopy = false;

                        string directory          = FileManager.GetDirectory(ProjectManager.Self.GumProjectSave.FullFileName);
                        string targetAbsoluteFile = directory + FileManager.RemovePath(value);

                        if (dialogResult == DialogResult.Yes)
                        {
                            shouldCopy = true;

                            // If the destination already exists, we gotta ask the user what they want to do.
                            if (System.IO.File.Exists(targetAbsoluteFile))
                            {
                                mbmb             = new MultiButtonMessageBox();
                                mbmb.MessageText = "The destination file already exists.  Would you like to overwrite it?";
                                mbmb.AddButton("Yes", DialogResult.Yes);
                                mbmb.AddButton("No, use the original file", DialogResult.No);

                                shouldCopy = mbmb.ShowDialog() == DialogResult.Yes;
                            }
                        }

                        if (shouldCopy)
                        {
                            try
                            {
                                string sourceAbsoluteFile =
                                    directory + value;
                                sourceAbsoluteFile = FileManager.RemoveDotDotSlash(sourceAbsoluteFile);

                                System.IO.File.Copy(sourceAbsoluteFile, targetAbsoluteFile, overwrite: true);

                                variable.Value = FileManager.RemovePath(value);
                            }
                            catch (Exception e)
                            {
                                MessageBox.Show("Error copying file:\n" + e.ToString());
                            }
                        }
                    }
                }


                StateSave stateSave = SelectedState.Self.SelectedStateSave;

                RecursiveVariableFinder rvf = new RecursiveVariableFinder(stateSave);

                stateSave.SetValue("AnimationFrames", new List <string>());
            }
        }
コード例 #32
0
        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

        }
コード例 #33
0
        private void SetPositionValuesOn(Glue.SaveClasses.NamedObjectSave nos, InstanceSave instance)
        {
            RecursiveVariableFinder rvf = new RecursiveVariableFinder(instance, instance.ParentContainer);
            float x = rvf.GetValue<float>("X");
            float y = rvf.GetValue<float>("Y");

            #region Adjust values according to object origin

            float effectiveWidth = GetEffectiveWidth(instance);
            float effectiveHeight = GetEffectiveHeight(instance);

            HorizontalAlignment horizontalOrigin = rvf.GetValue<HorizontalAlignment>("X Origin");
            VerticalAlignment verticalOrigin = rvf.GetValue<VerticalAlignment>("Y Origin");

            switch (horizontalOrigin)
            {
                case HorizontalAlignment.Left:
                    x += effectiveWidth / 2.0f;
                    break;
                case HorizontalAlignment.Right:
                    x -= effectiveWidth / 2.0f;
                    break;

            }

            switch (verticalOrigin)
            {
                case VerticalAlignment.Top:
                    y += effectiveHeight / 2.0f;
                    break;
                case VerticalAlignment.Bottom:
                    y -= effectiveHeight / 2.0f;
                    break;
            }

            #endregion

            #region Adjust values according to alignment

            float parentWidth = GetParentWidth(instance);
            float parentHeight = GetParentHeight(instance);

            PositionUnitType xUnits = rvf.GetValue<PositionUnitType>("X Units");
            PositionUnitType yUnits = rvf.GetValue<PositionUnitType>("Y Units");

            switch (xUnits)
            {
                case PositionUnitType.PixelsFromLeft:

                    x -= parentWidth / 2.0f;

                    break;
                case PositionUnitType.PixelsFromCenterX:
                    // do nothing
                    break;
                default:
                    throw new NotImplementedException();
                    break;
            }

            switch (yUnits)
            {
                case PositionUnitType.PixelsFromTop:
                    y -= parentHeight / 2.0f;
                    break;
                case PositionUnitType.PixelsFromCenterY:
                    // do nothing
                    break;
                default:

                    break;

            }

            #endregion

            nos.SetPropertyValue("X", x);
            // Invert Y because FRB uses positive Y is up
            nos.SetPropertyValue("Y", -y);


        }
コード例 #34
0
        private float GetParentHeight(InstanceSave instance)
        {
            string parent = new RecursiveVariableFinder(instance, instance.ParentContainer).GetValue<string>("Parent");

            if (string.IsNullOrEmpty(parent))
            {
                return GumProjectSave.DefaultCanvasHeight;
            }
            else
            {
                throw new NotImplementedException();
            }
        }
コード例 #35
0
        private bool GetIfShouldGenerateStateVariable(Gum.DataTypes.Variables.VariableSave variable, ElementSave container)
        {
            bool toReturn = true;

            string variableName = variable.GetRootName();



            if (variable.Value == null || !variable.SetsValue)
            {
                toReturn = false;
            }
            // states can't set states on this
            if (variable.IsState(container) && string.IsNullOrEmpty(variable.SourceObject))
            {
                toReturn = false;
            }

            if (toReturn && mVariableNamesToSkipForStates.Contains(variableName))
            {
                toReturn = false;
            }

            bool hasSourceObject = !string.IsNullOrEmpty(variable.SourceObject);

            if (toReturn && hasSourceObject)
            {
                InstanceSave instanceSave = container.GetInstance(variable.SourceObject);

                if (instanceSave == null)
                {
                    toReturn = false;
                }
                else
                {
                    var baseElement = Gum.Managers.ObjectFinder.Self.GetElementSave(instanceSave.BaseType);

                    if (baseElement == null)
                    {
                        toReturn = false;
                    }

                    if (toReturn)
                    {
                        // Gum (just like Glue) keeps variables that aren't needed around.  This allows users to rename things and not lose
                        // important information accidentally.  But because of that we have to make sure that the variable we're working with is
                        // valid for the type of object we're dealing with.
                        var defaultState = baseElement.DefaultState;

                        // October 26, 2018
                        // Bernardo reported
                        // a crash caused by the
                        // RecursiveVariableFinder
                        // being given a state without
                        // a ParentContainer. This is a
                        // sign that the element hasn't
                        // been initialized yet. Elements
                        // should be initialized, but if they're
                        // not, we could just catch it here and initialize
                        // it on the spot. Not sure if I like this solution
                        // or not. It allows code to behave a little unpredictably,
                        // but at the same time, we could simply solve the problem by
                        // initializing here, so I'm going to do that:
                        if (defaultState.ParentContainer == null)
                        {
                            baseElement.Initialize(null);
                        }

                        RecursiveVariableFinder rvf = new RecursiveVariableFinder(defaultState);

                        var foundVariable = rvf.GetVariable(variable.GetRootName());

                        if (foundVariable == null)
                        {
                            // This doesn't exist anywhere in the inheritance chain, so we don't want to generate it:
                            toReturn = false;
                        }
                    }
                }
            }

            if (toReturn && !hasSourceObject)
            {
                // If a variable is part of a component, it better be defined in the base type or else we won't generate it.
                // For example, consider a component that used to inherit from Text. It will have variables for fonts. If that
                // component switches to inheriting from Sprite, those variables will still exist in the XML for that component,
                // but we shouldn't generate any state variables for those variables. So we'll go to the base type and see if those
                // variables exist
                bool isComponent = container is ComponentSave;

                var rootStandardElementSave = Gum.Managers.ObjectFinder.Self.GetRootStandardElementSave(container);

                // If the Container is a Screen, then rootComponent will be null, so we don't need to do anything
                if (rootStandardElementSave == null)
                {
                    toReturn = false;
                }
                else
                {
                    IEnumerable <VariableSave> variablesToCheck;

                    // This code used to get the default state from the rootStandardElementSave,
                    // but the standard element save can have variables missing from the Gum XML,
                    // but it should still support them based on the definition in the StandardElementsManager,
                    // especially if new variables have been added in the future. Therefore, use the StandardElementsManager
                    // rather than the DefaultState:
                    //var rootStandardElementVariables = rootStandardElementSave.DefaultState.Variables;
                    var rootStandardElementVariables = StandardElementsManager.Self
                                                       .DefaultStates[rootStandardElementSave.Name].Variables;

                    if (isComponent)
                    {
                        var component = Gum.Managers.ObjectFinder.Self.GetStandardElement("Component");

                        variablesToCheck = rootStandardElementVariables.Concat(component.DefaultState.Variables).ToList();
                    }
                    else
                    {
                        variablesToCheck = rootStandardElementVariables.ToList();
                    }


                    bool wasMatchFound = variablesToCheck.Any(item => item.Name == variable.GetRootName());
                    toReturn = wasMatchFound;
                }
            }



            return(toReturn);
        }
コード例 #36
0
        private void SetPositionValuesOn(Glue.SaveClasses.NamedObjectSave nos, InstanceSave instance)
        {
            RecursiveVariableFinder rvf = new RecursiveVariableFinder(instance, instance.ParentContainer);
            float x = rvf.GetValue <float>("X");
            float y = rvf.GetValue <float>("Y");

            #region Adjust values according to object origin

            float effectiveWidth  = GetEffectiveWidth(instance);
            float effectiveHeight = GetEffectiveHeight(instance);

            HorizontalAlignment horizontalOrigin = rvf.GetValue <HorizontalAlignment>("X Origin");
            VerticalAlignment   verticalOrigin   = rvf.GetValue <VerticalAlignment>("Y Origin");

            switch (horizontalOrigin)
            {
            case HorizontalAlignment.Left:
                x += effectiveWidth / 2.0f;
                break;

            case HorizontalAlignment.Right:
                x -= effectiveWidth / 2.0f;
                break;
            }

            switch (verticalOrigin)
            {
            case VerticalAlignment.Top:
                y += effectiveHeight / 2.0f;
                break;

            case VerticalAlignment.Bottom:
                y -= effectiveHeight / 2.0f;
                break;
            }

            #endregion

            #region Adjust values according to alignment

            float parentWidth  = GetParentWidth(instance);
            float parentHeight = GetParentHeight(instance);

            PositionUnitType xUnits = rvf.GetValue <PositionUnitType>("X Units");
            PositionUnitType yUnits = rvf.GetValue <PositionUnitType>("Y Units");

            switch (xUnits)
            {
            case PositionUnitType.PixelsFromLeft:

                x -= parentWidth / 2.0f;

                break;

            case PositionUnitType.PixelsFromCenterX:
                // do nothing
                break;

            default:
                throw new NotImplementedException();
                break;
            }

            switch (yUnits)
            {
            case PositionUnitType.PixelsFromTop:
                y -= parentHeight / 2.0f;
                break;

            case PositionUnitType.PixelsFromCenterY:
                // do nothing
                break;

            default:

                break;
            }

            #endregion

            nos.SetPropertyValue("X", x);
            // Invert Y because FRB uses positive Y is up
            nos.SetPropertyValue("Y", -y);
        }
コード例 #37
0
 private static void SetAlphaAndColorValues(Sprite sprite, RecursiveVariableFinder rvf)
 {
     sprite.Color = ColorFromRvf(rvf);
 }
コード例 #38
0
        private void ReactIfChangedMemberIsTextureAddress(ElementSave parentElement, string changedMember, object oldValue)
        {
            if (changedMember == "Texture Address")
            {
                RecursiveVariableFinder rvf;

                var instance = SelectedState.Self.SelectedInstance;
                if (instance != null)
                {
                    rvf = new RecursiveVariableFinder(SelectedState.Self.SelectedInstance, parentElement);
                }
                else
                {
                    rvf = new RecursiveVariableFinder(parentElement.DefaultState);
                }

                var textureAddress = rvf.GetValue <TextureAddress>("Texture Address");

                if (textureAddress == TextureAddress.Custom)
                {
                    string sourceFile = rvf.GetValue <string>("SourceFile");

                    if (!string.IsNullOrEmpty(sourceFile))
                    {
                        string absolute = ProjectManager.Self.MakeAbsoluteIfNecessary(sourceFile);

                        if (System.IO.File.Exists(absolute))
                        {
                            if (absolute.ToLowerInvariant().EndsWith(".achx"))
                            {
                                // I think this is already loaded here, because when the GUE has
                                // its ACXH set, the texture and texture coordinate values are set
                                // immediately...
                                // But I'm not 100% certain.
                                // update: okay, so it turns out what this does is it sets values on the Element itself
                                // so those values get saved to disk and displayed in the property grid. I could update the
                                // property grid here, but doing so would possibly immediately make the values be out-of-date
                                // because the animation chain can change the coordinates constantly as it animates. I'm not sure
                                // what to do here...
                            }
                            else
                            {
                                var texture = LoaderManager.Self.LoadContent <Texture2D>(absolute);

                                if (texture != null && instance != null)
                                {
                                    parentElement.DefaultState.SetValue(instance.Name + ".Texture Top", 0);
                                    parentElement.DefaultState.SetValue(instance.Name + ".Texture Left", 0);
                                    parentElement.DefaultState.SetValue(instance.Name + ".Texture Width", texture.Width);
                                    parentElement.DefaultState.SetValue(instance.Name + ".Texture Height", texture.Height);
                                }
                            }
                        }
                    }
                }
                if (textureAddress == TextureAddress.DimensionsBased)
                {
                    // if the values are 0, then we should set them to 1:
                    float widthScale  = rvf.GetValue <float>("Texture Width Scale");
                    float heightScale = rvf.GetValue <float>("Texture Height Scale");

                    if (widthScale == 0)
                    {
                        if (instance != null)
                        {
                            SelectedState.Self.SelectedStateSave.SetValue(instance.Name + ".Texture Width Scale", 1.0f);
                        }
                        else
                        {
                            SelectedState.Self.SelectedStateSave.SetValue("Texture Width Scale", 1.0f);
                        }
                    }

                    if (heightScale == 0)
                    {
                        if (instance != null)
                        {
                            SelectedState.Self.SelectedStateSave.SetValue(instance.Name + ".Texture Height Scale", 1.0f);
                        }
                        else
                        {
                            SelectedState.Self.SelectedStateSave.SetValue("Texture Height Scale", 1.0f);
                        }
                    }
                }
            }
        }
コード例 #39
0
        public float GetEffectiveHeight(InstanceSave instance)
        {
            RecursiveVariableFinder rvf = new RecursiveVariableFinder(instance, instance.ParentContainer);

            float height = rvf.GetValue<float>("Height");


            if (height == 0)
            {
                string sourceFile = rvf.GetValue<string>("SourceFile");
                if (instance.BaseType == "Sprite")
                {
                    if (!string.IsNullOrEmpty(sourceFile))
                    {
                        string fullFileName = FileManager.GetDirectory(GumProjectSave.FullFileName) + sourceFile;
                        height = ImageHeader.GetDimensions(fullFileName).Height;

                    }
                }
            }

            return height;

        }
コード例 #40
0
ファイル: PluginManager.cs プロジェクト: jiailiuyan/Gum
        internal bool ShouldExclude(VariableSave defaultVariable, RecursiveVariableFinder rvf)
        {
            bool shouldExclude = false;
            foreach (var plugin in this.Plugins.Where(item=>this.PluginContainers[item].IsEnabled))
            {
                PluginContainer container = this.PluginContainers[plugin];

                if (container.Plugin is PluginBase)
                {

                    try
                    {
                        shouldExclude |= ((PluginBase)container.Plugin).GetIfVariableIsExcluded(defaultVariable, rvf);
                    }
                    catch (Exception e)
                    {
                        container.Fail(e, "Failed in GetIfVariableIsExcluded");
                    }
                }
            }
            return shouldExclude;
        }
コード例 #41
0
 private static void SetAlignmentValues(Text text, RecursiveVariableFinder rvf)
 {
     //Could these potentially be out of bounds?
     text.HorizontalAlignment = rvf.GetValue <HorizontalAlignment>("HorizontalAlignment");
     text.VerticalAlignment   = rvf.GetValue <VerticalAlignment>("VerticalAlignment");
 }
コード例 #42
0
 static Microsoft.Xna.Framework.Color ColorFromRvf(RecursiveVariableFinder rvf)
 {
     Microsoft.Xna.Framework.Color color = new Microsoft.Xna.Framework.Color(
         rvf.GetValue<int>("Red"),
         rvf.GetValue<int>("Green"),
         rvf.GetValue<int>("Blue"),
         rvf.GetValue<int>("Alpha")
         );
     return color;
 }
コード例 #43
0
ファイル: ObjectFinder.cs プロジェクト: vchelaru/BrakeNeck
        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)
                {
                    // August 5, 2018 - why are we not considering
                    // the file name of the element? Isn't that a referenced
                    // file?
                    var instanceElement = GetElementSave(instance);
                    if (instanceElement != null)
                    {
                        string prefix = FileManager.GetDirectory(GumProjectSave.FullFileName);
                        if (instanceElement is ComponentSave)
                        {
                            prefix += "Components/";
                        }
                        else // standard element
                        {
                            prefix += "Standards/";
                        }
                        files.Add(prefix + instanceElement.Name + "." + instanceElement.FileExtension);
                    }


                    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);
                    }
                }
            }
        }
コード例 #44
0
 private static void SetAlignmentValues(Text text, RecursiveVariableFinder rvf)
 {
     //Could these potentially be out of bounds?
     text.HorizontalAlignment = rvf.GetValue<HorizontalAlignment>("HorizontalAlignment");
     text.VerticalAlignment = rvf.GetValue<VerticalAlignment>("VerticalAlignment");
 }
コード例 #45
0
 private static void SetAlphaAndColorValues(SolidRectangle solidRectangle, RecursiveVariableFinder rvf)
 {
     solidRectangle.Color = ColorFromRvf(rvf);
 }
コード例 #46
0
ファイル: CodeGenerator.cs プロジェクト: derKosi/Gum
        private static void FillWithVariablesInState(ElementSave container, StateSave stateSave, StringBuilder stringBuilder, int tabCount)
        {
            VariableSave[] variablesToConsider = stateSave.Variables
                                                 // make "Parent" first
                                                 .Where(item => item.GetRootName() != "Parent")
                                                 .ToArray();

            var variableGroups = variablesToConsider.GroupBy(item => item.SourceObject);


            foreach (var group in variableGroups)
            {
                InstanceSave instance     = null;
                var          instanceName = group.Key;

                if (instanceName != null)
                {
                    instance = container.GetInstance(instanceName);
                }

                #region Determine visual API (Gum or Forms)

                VisualApi visualApi = VisualApi.Gum;

                var  defaultState = container.DefaultState;
                bool?isXamForms   = false;
                if (instance == null)
                {
                    isXamForms = defaultState.GetValueRecursive($"IsXamarinFormsControl") as bool?;
                }
                else
                {
                    isXamForms = defaultState.GetValueRecursive($"{instance.Name}.IsXamarinFormsControl") as bool?;
                }
                if (isXamForms == true)
                {
                    visualApi = VisualApi.XamarinForms;
                }

                #endregion

                ElementSave baseElement = null;
                if (instance == null)
                {
                    baseElement = Gum.Managers.ObjectFinder.Self.GetElementSave(container.BaseType) ?? container;
                }
                else
                {
                    baseElement = Gum.Managers.ObjectFinder.Self.GetElementSave(instance?.BaseType);
                }
                var baseDefaultState = baseElement?.DefaultState;
                RecursiveVariableFinder baseRecursiveVariableFinder = new RecursiveVariableFinder(baseDefaultState);


                List <VariableSave> variablesForThisInstance = group
                                                               .Where(item => GetIfVariableShouldBeIncludedForInstance(instance, item, baseRecursiveVariableFinder))
                                                               .ToList();


                ProcessVariableGroups(variablesForThisInstance, stateSave, instance, container, visualApi, stringBuilder, tabCount);

                // Now that they've been processed, we can process the remainder regularly
                foreach (var variable in variablesForThisInstance)
                {
                    var codeLine = GetCodeLine(instance, variable, container, visualApi, stateSave);
                    stringBuilder.AppendLine(ToTabs(tabCount) + codeLine);
                    var suffixCodeLine = GetSuffixCodeLine(instance, variable, visualApi);
                    if (!string.IsNullOrEmpty(suffixCodeLine))
                    {
                        stringBuilder.AppendLine(ToTabs(tabCount) + suffixCodeLine);
                    }
                }
            }
        }