Skip to content

Commit

Permalink
Reposition BGM info button and width
Browse files Browse the repository at this point in the history
  • Loading branch information
drojf committed Oct 13, 2022
1 parent d954d6c commit a5e7fa1
Showing 1 changed file with 56 additions and 4 deletions.
60 changes: 56 additions & 4 deletions MOD.Scripts.UI/MODMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,16 @@ private void OnGUIDebugWindow(int windowID)
GUI.DragWindow(new Rect(0, 0, 10000, 10000));
}

private void OnGUIExistingUIOverlay(string text, float? alpha, Action action, bool alignBottom=false)
enum ButtonPosition
{
TopLeftColumn,
BottomLeftColumn,
BottomEntireUIWidth,
BottomHalfUIWidthBottomPadded,
UnderSystemMenu,
}

private void OnGUIExistingUIOverlay(string text, float? alpha, Action action, ButtonPosition position = ButtonPosition.TopLeftColumn)
{
MODStyleManager styleManager = MODStyleManager.OnGUIInstance;

Expand All @@ -200,10 +209,47 @@ private void OnGUIExistingUIOverlay(string text, float? alpha, Action action, bo
GUI.color = new Color(1.0f, 1.0f, 1.0f, alpha.Value);
}

float existingUIWidth = Screen.width * 3 / 4;

// Figure out the width and height of the area where the overlay will be displayed
float areaWidth = Screen.width / 8;
if(position == ButtonPosition.BottomEntireUIWidth)
{
// This will overlay just the existing UI part of the screen
areaWidth = existingUIWidth;
}
else if(position == ButtonPosition.BottomHalfUIWidthBottomPadded)
{
areaWidth = existingUIWidth / 2;
}
else if(position == ButtonPosition.UnderSystemMenu)
{
areaWidth = Screen.width / 4;
}

float areaHeight = Mathf.Round(styleManager.Group.button.CalcHeight(new GUIContent(text, ""), areaWidth)) + 10;

// Figure out the position of the overlay's top left hand corner
float xOffset = 0;
float yOffset = alignBottom ? Screen.height - areaHeight : 0;
if (position == ButtonPosition.BottomEntireUIWidth || position == ButtonPosition.BottomHalfUIWidthBottomPadded || position == ButtonPosition.UnderSystemMenu)
{
// This will offset the overlay so it starts at where the existing UI starts
xOffset = Screen.width / 8;
}

float yOffset = 0;
if(position == ButtonPosition.BottomLeftColumn || position == ButtonPosition.BottomEntireUIWidth)
{
yOffset = Screen.height - areaHeight;
}
else if(position == ButtonPosition.UnderSystemMenu)
{
yOffset = Screen.height / 16 + Screen.height / 32;
}
else if(position == ButtonPosition.BottomHalfUIWidthBottomPadded)
{
yOffset = Screen.height * 11 / 16;
}

GUILayout.BeginArea(new Rect(xOffset, yOffset, areaWidth, areaHeight), styleManager.modMenuAreaStyle);
if (GUILayout.Button(text, styleManager.Group.button))
Expand Down Expand Up @@ -259,7 +305,8 @@ public void OnGUIFragment()
if (gameSystem.GameState == GameState.RightClickMenu)
{
string lastBGM = AssetManager.Instance.lastBGM;
string text = $"BGM: {MODBGMInfo.GetBGMName(lastBGM)}\nFile: {lastBGM}";
string text = $"BGM Name: {MODBGMInfo.GetBGMName(lastBGM)}\n" +
$"File Path: {lastBGM}";

// On Windows, add note about explorer .ogg file bug
if(lastBGMButtonPressed && Application.platform == RuntimePlatform.WindowsPlayer)
Expand All @@ -271,7 +318,12 @@ public void OnGUIFragment()
{
lastBGMButtonPressed = true;
Application.OpenURL(Path.GetDirectoryName(Path.Combine(Application.streamingAssetsPath, lastBGM)));
});
},
ButtonPosition.BottomHalfUIWidthBottomPadded);
}
else
{
lastBGMButtonPressed = false;
}

// The rest of this function assumes currentMenu does not change while the function is executing,
Expand Down

0 comments on commit a5e7fa1

Please sign in to comment.