From 33b1bacf07d8209bf157319bcaa7f9b7ce1db678 Mon Sep 17 00:00:00 2001 From: nexicturbo Date: Sat, 7 Feb 2026 00:54:02 -0600 Subject: [PATCH] Fix encoding artifacts in GuiStyles and add EditorConfig --- .editorconfig | 15 ++ ModMenuCrew/GuiStyles.cs | 286 +++++++++++++++++++-------------------- 2 files changed, 158 insertions(+), 143 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..07d3077 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,15 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true + +[*.{cs,csproj,sln,md,yml,yaml,json,ps1,sh}] +indent_style = space +indent_size = 2 + +[*.cs] +indent_size = 4 + diff --git a/ModMenuCrew/GuiStyles.cs b/ModMenuCrew/GuiStyles.cs index a98d164..2a7654b 100644 --- a/ModMenuCrew/GuiStyles.cs +++ b/ModMenuCrew/GuiStyles.cs @@ -3,44 +3,44 @@ namespace ModMenuCrew.UI.Styles; -public static class GuiStyles -{ - /// - /// Defini��es de cores para o tema visual do mod. - /// - public static class Theme - { - // === SHOWCASE VERSION BADGE === - public static readonly Color ShowcaseBadge = new Color(1f, 0.5f, 0f, 1f); // Orange badge - public static readonly Color ShowcaseGlow = new Color(1f, 0.6f, 0.1f, 0.3f); // Orange glow - // Cores de Fundo - public static readonly Color BgDarkA = new Color(0.07f, 0.07f, 0.07f, 0.92f); // Fundo principal mais escuro - public static readonly Color BgDarkB = new Color(0.06f, 0.06f, 0.06f, 0.92f); // Fundo principal mais claro - public static readonly Color BgSection = new Color(0.05f, 0.05f, 0.06f, 0.85f); // Fundo para se��es - - // Cores de Cabe�alho - public static readonly Color HeaderTop = new Color(0.10f, 0.02f, 0.04f, 0.95f); // Gradiente superior do cabe�alho - public static readonly Color HeaderBottom = new Color(0.06f, 0.01f, 0.03f, 0.95f); // Gradiente inferior do cabe�alho - - // Cores de Destaque e Acentua��o - public static readonly Color Accent = new Color(1f, 0.5f, 0f, 1f); // Laranja vitrine - public static readonly Color AccentSoft = new Color(1f, 0.6f, 0.2f, 1f); // Laranja suave - public static readonly Color AccentDim = new Color(0.7f, 0.35f, 0f, 1f); // Laranja escuro - public static readonly Color AccentHover = new Color(1f, 0.55f, 0.1f, 1f); // Laranja hover - public static readonly Color AccentActive = new Color(0.85f, 0.42f, 0f, 1f); // Laranja ativo - - // Cores de Bot�o - public static readonly Color ButtonTop = new Color(0.11f, 0.11f, 0.12f, 0.95f); // Gradiente superior do bot�o - public static readonly Color ButtonBottom = new Color(0.08f, 0.08f, 0.10f, 0.95f); // Gradiente inferior do bot�o - public static readonly Color ButtonHoverTop = new Color(0.13f, 0.13f, 0.16f, 0.95f); // Gradiente superior do bot�o em hover - public static readonly Color ButtonHoverBottom = new Color(0.10f, 0.10f, 0.13f, 0.95f); // Gradiente inferior do bot�o em hover - public static readonly Color ButtonActiveTop = new Color(0.12f, 0.02f, 0.05f, 0.95f); // Gradiente superior do bot�o ativo - public static readonly Color ButtonActiveBottom = new Color(0.09f, 0.02f, 0.04f, 0.95f); // Gradiente inferior do bot�o ativo - - // Cores de Texto - public static readonly Color TextPrimary = new Color(0.96f, 0.96f, 0.98f, 1f); // Texto principal claro - public static readonly Color TextMuted = new Color(0.78f, 0.78f, 0.82f, 1f); // Texto secund�rio mais claro - public static readonly Color TextDisabled = new Color(0.5f, 0.5f, 0.55f, 1f); // Texto para itens desabilitados +public static class GuiStyles +{ + /// + /// Color definitions for the mod theme. + /// + public static class Theme + { + // === SHOWCASE VERSION BADGE === + public static readonly Color ShowcaseBadge = new Color(1f, 0.5f, 0f, 1f); // Orange badge + public static readonly Color ShowcaseGlow = new Color(1f, 0.6f, 0.1f, 0.3f); // Orange glow + // Background colors + public static readonly Color BgDarkA = new Color(0.07f, 0.07f, 0.07f, 0.92f); // Fundo principal mais escuro + public static readonly Color BgDarkB = new Color(0.06f, 0.06f, 0.06f, 0.92f); // Fundo principal mais claro + public static readonly Color BgSection = new Color(0.05f, 0.05f, 0.06f, 0.85f); // Background for sections + + // Header colors + public static readonly Color HeaderTop = new Color(0.10f, 0.02f, 0.04f, 0.95f); // Header top gradient + public static readonly Color HeaderBottom = new Color(0.06f, 0.01f, 0.03f, 0.95f); // Header bottom gradient + + // Highlight/accent colors + public static readonly Color Accent = new Color(1f, 0.5f, 0f, 1f); // Laranja vitrine + public static readonly Color AccentSoft = new Color(1f, 0.6f, 0.2f, 1f); // Laranja suave + public static readonly Color AccentDim = new Color(0.7f, 0.35f, 0f, 1f); // Laranja escuro + public static readonly Color AccentHover = new Color(1f, 0.55f, 0.1f, 1f); // Laranja hover + public static readonly Color AccentActive = new Color(0.85f, 0.42f, 0f, 1f); // Laranja ativo + + // Button colors + public static readonly Color ButtonTop = new Color(0.11f, 0.11f, 0.12f, 0.95f); // Button top gradient + public static readonly Color ButtonBottom = new Color(0.08f, 0.08f, 0.10f, 0.95f); // Button bottom gradient + public static readonly Color ButtonHoverTop = new Color(0.13f, 0.13f, 0.16f, 0.95f); // Button top gradient (hover) + public static readonly Color ButtonHoverBottom = new Color(0.10f, 0.10f, 0.13f, 0.95f); // Button bottom gradient (hover) + public static readonly Color ButtonActiveTop = new Color(0.12f, 0.02f, 0.05f, 0.95f); // Button top gradient (active) + public static readonly Color ButtonActiveBottom = new Color(0.09f, 0.02f, 0.04f, 0.95f); // Button bottom gradient (active) + + // Cores de Texto + public static readonly Color TextPrimary = new Color(0.96f, 0.96f, 0.98f, 1f); // Texto principal claro + public static readonly Color TextMuted = new Color(0.78f, 0.78f, 0.82f, 1f); // Secondary text + public static readonly Color TextDisabled = new Color(0.5f, 0.5f, 0.55f, 1f); // Texto para itens desabilitados // Cores de Estado e Feedback public static readonly Color Error = new Color(1f, 0.15f, 0.15f, 1f); // Cor para erros @@ -48,12 +48,12 @@ public static class Theme public static readonly Color Warning = new Color(0.9f, 0.7f, 0.2f, 1f); // Cor para avisos } - #region Textura Helpers (Otimizados) - // Texturas s�o geradas uma vez e reutilizadas, ou criadas sob demanda e armazenadas em cache. - // Usando HideFlags.HideAndDontSave para evitar que apare�am no Hierarchy/Inspector do Unity. - private static Texture2D _cachedPixelDarkTexture; - private static Texture2D _cachedPixelAccentTexture; - private static Texture2D _cachedPixelErrorTexture; + #region Textura Helpers (Otimizados) + // Textures are generated once and reused, or created on demand and cached. + // HideFlags.HideAndDontSave prevents them from appearing in the Unity hierarchy/inspector. + private static Texture2D _cachedPixelDarkTexture; + private static Texture2D _cachedPixelAccentTexture; + private static Texture2D _cachedPixelErrorTexture; /// /// Cria uma textura vertical gradiente. @@ -108,17 +108,17 @@ private static Texture2D MakeFrameTexture(int width, int height, Color innerTop, tex.SetPixels(pixels); tex.Apply(); return tex; - } - - /// - /// Cria uma textura monocrom�tica de tamanho espec�fico. - /// - private static Texture2D MakeTexture(int width, int height, Color color) - { - var tex = new Texture2D(width, height, TextureFormat.RGBA32, false); - tex.wrapMode = TextureWrapMode.Clamp; - tex.filterMode = FilterMode.Bilinear; // Bilinear para suavizar levemente bordas se necess�rio - tex.hideFlags = HideFlags.HideAndDontSave; + } + + /// + /// Creates a solid-color texture of a specific size. + /// + private static Texture2D MakeTexture(int width, int height, Color color) + { + var tex = new Texture2D(width, height, TextureFormat.RGBA32, false); + tex.wrapMode = TextureWrapMode.Clamp; + tex.filterMode = FilterMode.Bilinear; // Slightly softens edges if needed + tex.hideFlags = HideFlags.HideAndDontSave; Color[] pixels = new Color[width * height]; for (int i = 0; i < pixels.Length; i++) @@ -128,30 +128,30 @@ private static Texture2D MakeTexture(int width, int height, Color color) tex.SetPixels(pixels); tex.Apply(); return tex; - } - - /// - /// Cria uma textura monocrom�tica 1x1, reutiliz�vel. Caching para as mais comuns. - /// - private static Texture2D MakeTexture(Color color) - { - // Caching para texturas muito comuns para evitar recria��o - if (color == Theme.BgDarkB) { if (_cachedPixelDarkTexture == null) _cachedPixelDarkTexture = MakeTexture(1, 1, color); return _cachedPixelDarkTexture; } - if (color == Theme.Accent) { if (_cachedPixelAccentTexture == null) _cachedPixelAccentTexture = MakeTexture(1, 1, color); return _cachedPixelAccentTexture; } - if (color == Theme.Error) { if (_cachedPixelErrorTexture == null) _cachedPixelErrorTexture = MakeTexture(1, 1, color); return _cachedPixelErrorTexture; } - - var texture = new Texture2D(1, 1, TextureFormat.RGBA32, false); - texture.SetPixel(0, 0, color); - texture.filterMode = FilterMode.Bilinear; // Bilinear para texturas de cor s�lida tamb�m pode suavizar visualmente - texture.hideFlags = HideFlags.HideAndDontSave; - texture.Apply(); - return texture; - } - - /// - /// Cria um RectOffset reutiliz�vel. - /// - private static RectOffset CreateRectOffset(int left, int right, int top, int bottom) + } + + /// + /// Creates a reusable 1x1 solid-color texture (with caching for common colors). + /// + private static Texture2D MakeTexture(Color color) + { + // Cache common textures to avoid recreating them + if (color == Theme.BgDarkB) { if (_cachedPixelDarkTexture == null) _cachedPixelDarkTexture = MakeTexture(1, 1, color); return _cachedPixelDarkTexture; } + if (color == Theme.Accent) { if (_cachedPixelAccentTexture == null) _cachedPixelAccentTexture = MakeTexture(1, 1, color); return _cachedPixelAccentTexture; } + if (color == Theme.Error) { if (_cachedPixelErrorTexture == null) _cachedPixelErrorTexture = MakeTexture(1, 1, color); return _cachedPixelErrorTexture; } + + var texture = new Texture2D(1, 1, TextureFormat.RGBA32, false); + texture.SetPixel(0, 0, color); + texture.filterMode = FilterMode.Bilinear; // Can look slightly smoother even for solid colors + texture.hideFlags = HideFlags.HideAndDontSave; + texture.Apply(); + return texture; + } + + /// + /// Creates a RectOffset instance. + /// + private static RectOffset CreateRectOffset(int left, int right, int top, int bottom) { var offset = new RectOffset(); offset.left = left; @@ -162,9 +162,9 @@ private static RectOffset CreateRectOffset(int left, int right, int top, int bot } #endregion - #region Estilos Privados (Lentamente Inicializados) - // Estilos s�o inicializados sob demanda para evitar overhead na inicializa��o do jogo. - private static GUIStyle _headerStyle; + #region Estilos Privados (Lentamente Inicializados) + // Styles are lazily initialized to reduce startup overhead. + private static GUIStyle _headerStyle; private static GUIStyle _subHeaderStyle; private static GUIStyle _buttonStyle; private static GUIStyle _toggleStyle; @@ -187,10 +187,10 @@ private static RectOffset CreateRectOffset(int left, int right, int top, int bot private static GUIStyle _headerBackgroundStyle; private static GUIStyle _titleLabelStyle; private static GUIStyle _titleBarButtonStyle; - private static GUIStyle _textFieldStyle; - #endregion - - #region Estilos P�blicos (Propriedades com Inicializa��o Pregui�osa) + private static GUIStyle _textFieldStyle; + #endregion + + #region Public Styles (Lazy-Initialized Properties) public static GUIStyle HeaderStyle { get @@ -254,11 +254,11 @@ public static GUIStyle ButtonStyle _buttonStyle.focused.background = _buttonStyle.hover.background; // Adicionado _buttonStyle.richText = true; } - else if (_buttonStyle.normal?.background == null || _buttonStyle.hover?.background == null || _buttonStyle.active?.background == null) - { - // Recupera��o de falha de inicializa��o, se necess�rio - _buttonStyle.normal.background = MakeFrameTexture(16, 64, Theme.ButtonTop, Theme.ButtonBottom, Theme.AccentDim, 1); - _buttonStyle.hover.background = MakeFrameTexture(16, 64, Theme.ButtonHoverTop, Theme.ButtonHoverBottom, Theme.AccentHover, 1); + else if (_buttonStyle.normal?.background == null || _buttonStyle.hover?.background == null || _buttonStyle.active?.background == null) + { + // Fallback if initialization failed (e.g., missing textures) + _buttonStyle.normal.background = MakeFrameTexture(16, 64, Theme.ButtonTop, Theme.ButtonBottom, Theme.AccentDim, 1); + _buttonStyle.hover.background = MakeFrameTexture(16, 64, Theme.ButtonHoverTop, Theme.ButtonHoverBottom, Theme.AccentHover, 1); _buttonStyle.active.background = MakeFrameTexture(16, 64, Theme.ButtonActiveTop, Theme.ButtonActiveBottom, Theme.AccentActive, 1); _buttonStyle.focused.background = _buttonStyle.hover.background; } @@ -274,9 +274,9 @@ public static GUIStyle ToggleStyle { _toggleStyle = new GUIStyle(GUI.skin.toggle) { - fontSize = 14, // Ajustado - fontStyle = FontStyle.Normal, // Removido Bold para consist�ncia visual - alignment = TextAnchor.MiddleLeft, + fontSize = 14, // Ajustado + fontStyle = FontStyle.Normal, // Removed Bold for visual consistency + alignment = TextAnchor.MiddleLeft, normal = { textColor = Theme.TextMuted, background = MakeTexture(new Color(0.09f, 0.09f, 0.11f, 0.95f)) }, // Fundo mais escuro onNormal = { textColor = Theme.TextPrimary, background = MakeTexture(new Color(0.18f, 0.09f, 0.02f, 0.95f)) }, // Orange when on hover = { textColor = Theme.TextPrimary, background = MakeTexture(new Color(0.11f, 0.11f, 0.14f, 0.95f)) }, // Fundo hover @@ -290,11 +290,11 @@ public static GUIStyle ToggleStyle }; _toggleStyle.richText = true; } - else if (_toggleStyle.normal?.background == null || _toggleStyle.onNormal?.background == null || _toggleStyle.hover?.background == null || _toggleStyle.onHover?.background == null || _toggleStyle.active?.background == null || _toggleStyle.onActive?.background == null) - { - // Recupera��o de falha de inicializa��o - _toggleStyle.normal.background = MakeTexture(new Color(0.09f, 0.09f, 0.11f, 0.95f)); - _toggleStyle.onNormal.background = MakeTexture(new Color(0.12f, 0.03f, 0.06f, 0.95f)); + else if (_toggleStyle.normal?.background == null || _toggleStyle.onNormal?.background == null || _toggleStyle.hover?.background == null || _toggleStyle.onHover?.background == null || _toggleStyle.active?.background == null || _toggleStyle.onActive?.background == null) + { + // Fallback if initialization failed + _toggleStyle.normal.background = MakeTexture(new Color(0.09f, 0.09f, 0.11f, 0.95f)); + _toggleStyle.onNormal.background = MakeTexture(new Color(0.12f, 0.03f, 0.06f, 0.95f)); _toggleStyle.hover.background = MakeTexture(new Color(0.11f, 0.11f, 0.14f, 0.95f)); _toggleStyle.onHover.background = MakeTexture(new Color(0.14f, 0.04f, 0.08f, 0.95f)); _toggleStyle.active.background = MakeTexture(new Color(0.09f, 0.09f, 0.11f, 0.95f)); @@ -414,8 +414,8 @@ public static GUIStyle ContainerStyle padding = CreateRectOffset(8, 8, 8, 8), // Reduzido de 12 para 8 margin = CreateRectOffset(4, 4, 4, 4) // Reduzido de 8 para 4 }; - _containerStyle.normal.background = MakeTexture(2, 2, new Color(0.07f, 0.07f, 0.09f, 0.80f)); // Fundo mais claro e com mais transpar�ncia - } + _containerStyle.normal.background = MakeTexture(2, 2, new Color(0.07f, 0.07f, 0.09f, 0.80f)); // Slightly lighter and more transparent background + } else if (_containerStyle.normal?.background == null) { _containerStyle.normal.background = MakeTexture(2, 2, new Color(0.07f, 0.07f, 0.09f, 0.80f)); @@ -733,14 +733,14 @@ public static GUIStyle TextFieldStyle } #endregion - #region Fun��es P�blicas de Utilidade - /// - /// Garante que todos os estilos sejam inicializados. Chamado uma vez, idealmente na inicializa��o do mod. - /// - public static void EnsureInitialized() - { - // Acessa cada estilo uma vez para for�ar a inicializa��o pregui�osa. - _ = WindowStyle; + #region Public Utility Functions + /// + /// Ensures all styles are initialized. Ideally called once during startup. + /// + public static void EnsureInitialized() + { + // Touch each style once to force lazy initialization. + _ = WindowStyle; _ = HeaderBackgroundStyle; _ = TitleLabelStyle; _ = TitleBarButtonStyle; @@ -764,12 +764,12 @@ public static void EnsureInitialized() _ = SeparatorStyle; _ = BetterToggleStyle; _ = TextFieldStyle; - } - - /// - /// Desenha um tooltip na posi��o do mouse se o ret�ngulo fornecido cont�m o mouse. - /// - public static void DrawTooltip(string tooltip, Rect rect) + } + + /// + /// Draws a tooltip at the mouse position if the provided rect contains the mouse. + /// + public static void DrawTooltip(string tooltip, Rect rect) { if (!string.IsNullOrEmpty(tooltip) && rect.Contains(Event.current.mousePosition)) { @@ -777,18 +777,18 @@ public static void DrawTooltip(string tooltip, Rect rect) Rect tooltipRect = new Rect(Event.current.mousePosition.x + 15, Event.current.mousePosition.y, size.x + 16, size.y + 12); // Ajustado offset e padding GUI.Label(tooltipRect, tooltip, TooltipStyle); } - } - - /// - /// Desenha um indicador de status (c�rculo colorido). - /// - public static void DrawStatusIndicator(bool isActive) + } + + /// + /// Draws a status indicator (colored circle). + /// + public static void DrawStatusIndicator(bool isActive) { Color color = isActive ? Theme.Success : Theme.Error; // Usa cores do tema GUIStyle style = new GUIStyle(StatusIndicatorStyle); style.normal.background = MakeTexture(1, 1, color); GUILayout.Box(GUIContent.none, style); - } + } /// /// Desenha um separador horizontal. @@ -798,13 +798,13 @@ public static void DrawSeparator() GUILayout.Box(GUIContent.none, SeparatorStyle, GUILayout.ExpandWidth(true), GUILayout.Height(2)); // Ajustado altura } - /// - /// Desenha um bot�o de aba estilizado. - /// - public static bool DrawTab(string label, bool selected) + /// + /// Draws a styled tab button. + /// + public static bool DrawTab(string label, bool selected) { return GUILayout.Toggle(selected, label, selected ? SelectedTabStyle : TabStyle); - } + } /// /// Desenha um toggle com tooltip opcional. @@ -818,23 +818,23 @@ public static bool DrawBetterToggle(bool value, string label, string tooltip = n return result; } - /// - /// Gera o texto do cabe�alho com o sufixo de hora atual. - /// - public static string GetHeaderText(string text) + /// + /// Builds header text with a current time suffix. + /// + public static string GetHeaderText(string text) { return $"{text} - {DateTime.Now:HH:mm:ss}"; - } - - /// - /// Retorna um estilo de cabe�alho com cor animada (varia��o do acento). - /// - public static GUIStyle GetAnimatedHeaderStyle() - { - var style = new GUIStyle(HeaderStyle); - style.normal.textColor = Color.Lerp(Theme.Accent, Theme.AccentSoft, Mathf.PingPong(Time.time * 2f, 1f)); // Anima��o de cor - return style; - } + } + + /// + /// Returns a header style with an animated accent color. + /// + public static GUIStyle GetAnimatedHeaderStyle() + { + var style = new GUIStyle(HeaderStyle); + style.normal.textColor = Color.Lerp(Theme.Accent, Theme.AccentSoft, Mathf.PingPong(Time.time * 2f, 1f)); // Color animation + return style; + } /// /// Retorna a hora atual formatada. @@ -844,4 +844,4 @@ public static string GetCurrentTime() return DateTime.Now.ToString("HH:mm:ss"); } #endregion -} \ No newline at end of file +}