private static void UIBinderLoadPostfix(UIBinder __instance, TranslationHookState __state) { var gameObject = __instance.gameObject; var path = __state.Path; var components = (List <Component>)__state.Context[0]; var scopes = (List <int>)__state.Context[1]; var origValues = (List <string>)__state.Context[2]; var origResizers = (List <XuaResizerResult>)__state.Context[3]; var items = EnumerateTextComponents(gameObject).ToList(); if (items.Count != components.Count) { BaseTextDumpPlugin.Logger.LogWarning( $"UIBinder {gameObject}: Component count has changed, may not be able to get all translations"); } else { components = items.Select(t => t.Value).ToList(); } var results = new TranslationDictionary(); var resizers = new ResizerCollection(); for (var i = 0; i < components.Count; i++) { var key = origValues[i]; var val = GetTextFromSupportedComponent(components[i]); var scope = scopes[i]; _instance.AddLocalizationToResults(results.GetScope(scope), key, val); var currentResizer = GetTextResizerFromComponent(components[i]); var resizePath = components[i].GetXuaResizerPath(); if (!string.IsNullOrEmpty(resizePath)) { var delta = currentResizer.Delta(origResizers[i]); var scopedResizers = resizers.GetScope(scope); scopedResizers[resizePath] = delta.GetDirectives().ToList(); } } var outputName = CombinePaths("Bind/UI", path); HookedTextLocalizationGenerators.Add(new StringTranslationDumper(outputName, () => results)); HookedTextLocalizationGenerators.Add(new ResizerDumper(outputName, () => resizers)); }
private List <string> CreateResizerLines(ResizerCollection resizers) { var lines = new List <string>(); var scopeLines = new List <string>(); foreach (var scope in resizers.Scopes) { scopeLines.Clear(); foreach (var resizer in resizers.GetScope(scope)) { foreach (var rule in resizer.Value) { scopeLines.Add($"{resizer.Key}={rule}"); } } if (scopeLines.Count <= 0) { continue; } if (lines.Count > 0) { lines.Add(""); } if (scope != -1) { lines.Add($"#set level {scope}"); } lines.AddRange(scopeLines); if (scope != -1) { lines.Add($"#unset level {scope}"); } } return(lines); }