public UIResizeAttachment()
        {
            Descendants = new Dictionary <string, UIResizeAttachment>();

            Result        = new UIResizeResult();
            ScopedResults = new Dictionary <int, UIResizeResult>();

            _commandTypes = new Dictionary <string, Type>(StringComparer.OrdinalIgnoreCase);

            try
            {
                var commands = typeof(UIResizeAttachment).Assembly.GetTypes()
                               .Where(x => (typeof(IFontResizeCommand).IsAssignableFrom(x) ||
                                            typeof(IFontAutoResizeCommand).IsAssignableFrom(x) ||
                                            typeof(IUGUI_LineSpacingCommand).IsAssignableFrom(x) ||
                                            typeof(IUGUI_HorizontalOverflow).IsAssignableFrom(x) ||
                                            typeof(IUGUI_VerticalOverflow).IsAssignableFrom(x)
                                            ) && !x.IsInterface && !x.IsAbstract)
                               .ToList();

                foreach (var command in commands)
                {
                    _commandTypes[command.Name] = command;
                }
            }
            catch (Exception e)
            {
                XuaLogger.AutoTranslator.Error(e, "An error occurred while loading ui resize commands.");
            }
        }
 private UIResizeResult GetOrCreateResultFor(int scope)
 {
     if (!ScopedResults.TryGetValue(scope, out var result))
     {
         result = new UIResizeResult();
         ScopedResults[scope] = result;
     }
     return(result);
 }
        public void Trim()
        {
            if (Result != null && Result.IsEmpty())
            {
                Result = null;
            }

            foreach (var descendant in Descendants.Values)
            {
                descendant.Trim();
            }
        }
        public bool TryGetUIResize(string[] segments, int scope, out UIResizeResult result)
        {
            UIResizeAttachment attachment = this;

            result = null;

            var len = segments.Length;

            for (int i = 0; i < len; i++)
            {
                var segment = segments[i];
                if (attachment.Descendants.TryGetValue(segment, out var newAttachment))
                {
                    if (result == null)
                    {
                        result = newAttachment.Result?.Copy();
                    }
                    else
                    {
                        result.MergeInto(newAttachment.Result);
                    }

                    if (scope != TranslationScopes.None)
                    {
                        if (result == null)
                        {
                            if (newAttachment.ScopedResults.TryGetValue(scope, out var scopedResult))
                            {
                                result = scopedResult.Copy();
                            }
                        }
                        else
                        {
                            if (newAttachment.ScopedResults.TryGetValue(scope, out var scopedResult))
                            {
                                result.MergeInto(scopedResult);
                            }
                        }
                    }

                    attachment = newAttachment;
                }
                else
                {
                    return(result != null);
                }
            }

            return(result != null);
        }
 public bool TryGetUIResize(string[] paths, int scope, out UIResizeResult result)
 {
     return(_root.TryGetUIResize(paths, 0, scope, out result));
 }
Exemplo n.º 6
0
 public UIResizeAttachment()
 {
     Descendants   = new Dictionary <string, UIResizeAttachment>();
     Result        = new UIResizeResult();
     ScopedResults = new Dictionary <int, UIResizeResult>();
 }
Exemplo n.º 7
0
        public bool TryGetUIResize(string[] segments, int startIndex, int scope, out UIResizeResult result)
        {
            UIResizeAttachment attachment = this;

            result = null;

            var len = segments.Length;

            for (int i = startIndex; i < len; i++)
            {
                var segment = segments[i];
                if (attachment.Descendants.TryGetValue(segment, out var newAttachment))
                {
                    if (result == null)
                    {
                        result = newAttachment.Result?.Copy();
                    }
                    else
                    {
                        result.MergeInto(newAttachment.Result);
                    }

                    if (scope != TranslationScopes.None)
                    {
                        if (result == null)
                        {
                            if (newAttachment.ScopedResults.TryGetValue(scope, out var scopedResult))
                            {
                                result = scopedResult.Copy();
                            }
                        }
                        else
                        {
                            if (newAttachment.ScopedResults.TryGetValue(scope, out var scopedResult))
                            {
                                result.MergeInto(scopedResult);
                            }
                        }
                    }

                    //if( attachment.HasWildcardBelow )
                    //{
                    //   // we have to iterate all descendants of this attachment
                    //   foreach( var childAttachment in attachment.Descendants.Values )
                    //   {
                    //      if( childAttachment.TryGetUIResize( segments, i + 1, scope, out var otherResult ) )
                    //      {
                    //         if( result == null )
                    //         {
                    //            result = otherResult.Copy();
                    //         }
                    //         else
                    //         {
                    //            result.MergeInto( otherResult );
                    //         }
                    //      }
                    //   }
                    //}

                    attachment = newAttachment;
                }
                else
                {
                    return(result != null);
                }
            }

            return(result != null);
        }