Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix GUI and Toast Scaling #115

Merged
merged 3 commits into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions MOD.Scripts.UI/MODMenuCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions MOD.Scripts.UI/MODMenuResolution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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();


Expand Down
73 changes: 47 additions & 26 deletions MOD.Scripts.UI/MODStyleManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
{
Expand All @@ -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,
Expand All @@ -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,
};
}
}
Expand Down
6 changes: 3 additions & 3 deletions MOD.Scripts.UI/MODToaster.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down