diff --git a/MOD.Scripts.UI/MODMenuCommon.cs b/MOD.Scripts.UI/MODMenuCommon.cs index 34c0f27b..5cbb5881 100644 --- a/MOD.Scripts.UI/MODMenuCommon.cs +++ b/MOD.Scripts.UI/MODMenuCommon.cs @@ -62,6 +62,15 @@ public static bool Button(GUIContent guiContent, bool selected = false, bool stl return false; } } + public static string TextField(string text, params GUILayoutOption[] options) + { + return GUILayout.TextField(text, MODStyleManager.OnGUIInstance.Group.textField, options); + } + + public static string TextField(string text, int maxLength, params GUILayoutOption[] options) + { + return GUILayout.TextField(text, maxLength, MODStyleManager.OnGUIInstance.Group.textField, options); + } public static int GetGlobal(string flagName) => BurikoMemory.Instance.GetGlobalFlag(flagName).IntValue(); public static void SetGlobal(string flagName, int flagValue) => BurikoMemory.Instance.SetGlobalFlag(flagName, flagValue); diff --git a/MOD.Scripts.UI/MODMenuResolution.cs b/MOD.Scripts.UI/MODMenuResolution.cs index a2642049..dd1ab1d1 100644 --- a/MOD.Scripts.UI/MODMenuResolution.cs +++ b/MOD.Scripts.UI/MODMenuResolution.cs @@ -53,7 +53,7 @@ public void OnGUI() if (Button(new GUIContent(Loc.MODMenuResolution_6, Loc.MODMenuResolution_7))) { SetAndSaveResolution(1080); } //1080p | Set resolution to 1920 x 1080 if (Button(new GUIContent(Loc.MODMenuResolution_8, Loc.MODMenuResolution_9))) { SetAndSaveResolution(1440); } //1440p | Set resolution to 2560 x 1440 - screenHeightString = GUILayout.TextField(screenHeightString); + screenHeightString = TextField(screenHeightString); if (Button(new GUIContent(Loc.MODMenuResolution_10, Loc.MODMenuResolution_11))) //Set | Sets a custom resolution - mainly for windowed mode.\n\nHeight set automatically to maintain 16:9 aspect ratio. { if (int.TryParse(screenHeightString, out int new_height)) @@ -106,12 +106,12 @@ public void OnGUI() GUILayout.BeginHorizontal(); LabelRightAlign(Loc.MODMenuResolution_21); //Width: - fullscreenWidthOverrideString = GUILayout.TextField(fullscreenWidthOverrideString, 5); + fullscreenWidthOverrideString = TextField(fullscreenWidthOverrideString, 5); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); LabelRightAlign(Loc.MODMenuResolution_22); //Height: - fullscreenHeightOverrideString = GUILayout.TextField(fullscreenHeightOverrideString, 5); + fullscreenHeightOverrideString = TextField(fullscreenHeightOverrideString, 5); GUILayout.EndHorizontal(); diff --git a/MOD.Scripts.UI/MODStyleManager.cs b/MOD.Scripts.UI/MODStyleManager.cs index f13b0090..2ecd9303 100644 --- a/MOD.Scripts.UI/MODStyleManager.cs +++ b/MOD.Scripts.UI/MODStyleManager.cs @@ -18,6 +18,7 @@ public class StyleGroup public int menuHeight; public int menuWidth; public float toolTipShrinkage; + public float toastWidth; public GUIStyle modMenuSelectionGrid; // Used for SelectionGrid widgets public GUIStyle errorLabel; public GUIStyle button; @@ -26,12 +27,11 @@ public class StyleGroup public GUIStyle labelRightAlign; public GUIStyle headingLabel; public GUIStyle upperLeftHeadingLabel; + public GUIStyle bigToastLabelStyle; // Styles used for Toasts (text popups) + public GUIStyle smallToastLabelStyle; + public GUIStyle textField; } - // Styles used for Toasts - public GUIStyle bigToastLabelStyle; - public GUIStyle smallToastLabelStyle; - // Styles used for the Mod menu public GUIStyle modMenuAreaStyle; //Used for Area widgets public GUIStyle modMenuAreaStyleLight; @@ -48,12 +48,17 @@ public class StyleGroup StyleGroup style720_960x660; StyleGroup style480_850x480; StyleGroup style480_640x480; + StyleGroup style2160_2400x1900; public StyleGroup Group { get { - if (Screen.height >= 1080 && Screen.width >= 1200) + if (Screen.height >= 2160 && Screen.width >= 2400) + { + return style2160_2400x1900; + } + else if (Screen.height >= 1080 && Screen.width >= 1200) { return style1080_1200x950; } @@ -169,28 +174,16 @@ private MODStyleManager() padding: new RectOffset(2, 2, 2, 2) ); - OnGUIGetLabelStyle(); - OnGUIGetModStyle(); - } - - // This sets up the style of the toast notification (mostly to make the font bigger and the text anchor location) - // From what I've read, The GUIStyle must be initialized in OnGUI(), otherwise - // GUI.skin.label will not be defined, so please do not move this part elsewhere without testing it. - private void OnGUIGetLabelStyle() - { - bigToastLabelStyle = new GUIStyle(GUI.skin.box) //Copy the default style for 'box' as a base - { - alignment = TextAnchor.UpperCenter, - fontSize = 40, - fontStyle = FontStyle.Bold, - }; - bigToastLabelStyle.normal.background = modGUIBackgroundTexture; - bigToastLabelStyle.normal.textColor = Color.white; + style2160_2400x1900 = GenerateWidgetStyles( + menuWidth: 2400, + menuHeight: 1900, + guiScale: 2.5f, + margin: new RectOffset(4, 4, 4, 4), + padding: new RectOffset(4, 4, 4, 4) + ); - smallToastLabelStyle = new GUIStyle(bigToastLabelStyle) - { - fontSize = 20, - }; + //OnGUIGetLabelStyle(); + OnGUIGetModStyle(); } private void OnGUIGetModStyle() @@ -236,6 +229,14 @@ private StyleGroup GenerateWidgetStyles(int menuWidth, int menuHeight, float gui alignment = TextAnchor.MiddleRight, }; + // Textfield style + GUIStyle textFieldStyle = new GUIStyle(GUI.skin.textField) + { + fontSize = Mathf.RoundToInt(guiScale * baseFontSize), + margin = margin, + padding = padding, + }; + // Heading text style GUIStyle headingLabelStyle = new GUIStyle(labelStyle) { @@ -261,10 +262,27 @@ private StyleGroup GenerateWidgetStyles(int menuWidth, int menuHeight, float gui errorLabelStyle.normal.textColor = Color.red; errorLabelStyle.fontSize = Mathf.RoundToInt(guiScale * baseFontSize); + // Toast popup styles + GUIStyle bigToastLabelStyle = new GUIStyle(GUI.skin.box) //Copy the default style for 'box' as a base + { + alignment = TextAnchor.UpperCenter, + fontSize = Mathf.RoundToInt(guiScale * 3 * baseFontSize), + fontStyle = FontStyle.Bold, + wordWrap = true, + }; + bigToastLabelStyle.normal.background = modGUIBackgroundTexture; + bigToastLabelStyle.normal.textColor = Color.white; + + GUIStyle smallToastLabelStyle = new GUIStyle(bigToastLabelStyle) + { + fontSize = bigToastLabelStyle.fontSize / 2, + }; + return new StyleGroup() { menuWidth = menuWidth, menuHeight = menuHeight, + toastWidth = menuWidth, modMenuSelectionGrid = modMenuSelectionGrid, errorLabel = errorLabelStyle, button = buttonStyle, @@ -274,6 +292,9 @@ private StyleGroup GenerateWidgetStyles(int menuWidth, int menuHeight, float gui headingLabel = headingLabelStyle, upperLeftHeadingLabel = upperLeftHeadingLabelStyle, toolTipShrinkage = toolTipShrinkage, + bigToastLabelStyle = bigToastLabelStyle, + smallToastLabelStyle = smallToastLabelStyle, + textField = textFieldStyle, }; } } diff --git a/MOD.Scripts.UI/MODToaster.cs b/MOD.Scripts.UI/MODToaster.cs index 1c00a462..379de0e5 100644 --- a/MOD.Scripts.UI/MODToaster.cs +++ b/MOD.Scripts.UI/MODToaster.cs @@ -36,10 +36,10 @@ public void OnGUIFragment() { // This scrolls the toast notification off the window when it's nearly finished float toastYPosition = Math.Min(50f, 200f * toastNotificationTimer.timeLeft - 50f); - float toastWidth = 700f; + float toastWidth = styleManager.Group.toastWidth; float toastXPosition = (Screen.width - toastWidth) / 2.0f; - GUILayout.BeginArea(new Rect(toastXPosition, toastYPosition, 700f, 200f)); - GUILayout.Box(toastText, toastText.Length > 30 ? styleManager.smallToastLabelStyle : styleManager.bigToastLabelStyle); + GUILayout.BeginArea(new Rect(toastXPosition, toastYPosition, toastWidth, Screen.height)); + GUILayout.TextArea(toastText, styleManager.Group.bigToastLabelStyle); GUILayout.EndArea(); } }