Skip to content

Commit

Permalink
version 1.1.0, create toggle on pnlmenu is much more easier
Browse files Browse the repository at this point in the history
  • Loading branch information
lxymahatma committed Feb 12, 2023
1 parent 9cf8aa5 commit 1edab08
Show file tree
Hide file tree
Showing 6 changed files with 367 additions and 45 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public override void OnSceneWasLoaded(int buildIndex, string sceneName)
{
YourMethod();
}
}
}

// New way to do
// Same with patching events, in the OnInitializeMelon method
Expand Down
2 changes: 2 additions & 0 deletions src/Main.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
global using HarmonyLib;
using MelonLoader;
using MuseDashMirror.UICreate;
using static MuseDashMirror.SceneInfo;

namespace MuseDashMirror
Expand Down Expand Up @@ -40,6 +41,7 @@ public override void OnSceneWasUnloaded(int buildIndex, string sceneName)
{
isGameScene = false;
ExitGameSceneInvoke();
ToggleCreate.Reset();
}

if (sceneName == "UISystem_PC")
Expand Down
2 changes: 1 addition & 1 deletion src/MelonBuildInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ internal static class MelonBuildInfo

public const string Author = "lxy";

public const string Version = "1.0.2";
public const string Version = "1.1.0";
}
}
24 changes: 17 additions & 7 deletions src/UICreate/CanvasCreate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,18 @@ namespace MuseDashMirror.UICreate
{
public static class CanvasCreate
{
// 去掉最后,parent设置两个重载,名字和gameobject

/// <summary>
/// Create a screenspace overlay canvas
/// </summary>

public static void CreateCanvas(string canvasName)
public static GameObject CreateCanvas(string canvasName)
{
var canvas = new GameObject();
canvas.name = canvasName;
canvas.AddComponent<Canvas>();
canvas.AddComponent<CanvasScaler>();
canvas.AddComponent<GraphicRaycaster>();
canvas.GetComponent<Canvas>().renderMode = RenderMode.ScreenSpaceOverlay;
return canvas;
}

/// <summary>
Expand All @@ -40,12 +38,24 @@ public static GameObject CreateCanvas(string canvasName, string cameraName)
}

/// <summary>
/// Create a screenspace camera canvas with specified reference resolution
/// Create a screenspace camera canvas with specified parent using name
/// </summary>
public static void CreateCanvas(string canvasName, string cameraName, Vector2 referenceResolution)
public static GameObject CreateCanvas(string canvasName, string cameraName, string parentName)
{
var canvas = CreateCanvas(canvasName, cameraName);
canvas.GetComponent<CanvasScaler>().referenceResolution = referenceResolution;
var parent = GameObject.Find(parentName);
canvas.transform.SetParent(parent.transform);
return canvas;
}

/// <summary>
/// Create a screenspace camera canvas with specified parent
/// </summary>
public static GameObject CreateCanvas(string canvasName, string cameraName, GameObject parent)
{
var canvas = CreateCanvas(canvasName, cameraName);
canvas.transform.SetParent(parent.transform);
return canvas;
}
}
}
86 changes: 72 additions & 14 deletions src/UICreate/TextGameObjectCreate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,74 @@ namespace MuseDashMirror.UICreate
{
public static class TextGameObjectCreate
{
// 去掉最后,parent设置两个重载,名字和gameobject
/// <summary>
/// Create GameObject with specified parent using name, with normal and white font and custom fontsize
/// </summary>
public static GameObject CreateTextGameObject(string parentName, string gameObjectName, string text, TextAnchor alignment, bool isLocalPosition, Vector3 position, Vector2 sizeDelta, int fontSize)
{
var parent = GameObject.Find(parentName);
var gameobject = new GameObject(gameObjectName);
gameobject.transform.SetParent(parent.transform);
Text gameobject_text = gameobject.AddComponent<Text>();
gameobject_text.text = text;
gameobject_text.alignment = alignment;
gameobject_text.font = Fonts.NormalFont;
gameobject_text.fontSize = fontSize;
gameobject_text.color = Color.white;
if (isLocalPosition)
{
gameobject_text.transform.localPosition = position;
}
else
{
gameobject_text.transform.position = position;
}
RectTransform rectTransform = gameobject_text.GetComponent<RectTransform>();
rectTransform.sizeDelta = sizeDelta;
rectTransform.localScale = new Vector3(1, 1, 1);
return gameobject;
}

/// <summary>
/// Create GameObject with specified parent using name, with white font, custom fontsize and font
/// </summary>
public static GameObject CreateTextGameObject(string parentName, string gameObjectName, string text, TextAnchor alignment, bool isLocalPosition, Vector3 position, Vector2 sizeDelta, int fontSize, Font font)
{
var gameobject = CreateTextGameObject(parentName, gameObjectName, text, alignment, isLocalPosition, position, sizeDelta, fontSize);
Text gameobject_text = gameobject.GetComponent<Text>();
gameobject_text.font = font;
return gameobject;
}

/// <summary>
/// Create GameObject with specified parent using name, with custom fontsize, font and color
/// </summary>
public static GameObject CreateTextGameObject(string parentName, string gameObjectName, string text, TextAnchor alignment, bool isLocalPosition, Vector3 position, Vector2 sizeDelta, int fontSize, Font font, Color color)
{
var gameobject = CreateTextGameObject(parentName, gameObjectName, text, alignment, isLocalPosition, position, sizeDelta, fontSize, font);
Text gameobject_text = gameobject.GetComponent<Text>();
gameobject_text.color = color;
return gameobject;
}

/// <summary>
/// Create GameObject with specified parent using name, with custom font, fontsize and color, custom local scale
/// </summary>
public static GameObject CreateTextGameObject(string parentName, string gameObjectName, string text, TextAnchor alignment, bool isLocalPosition, Vector3 position, Vector2 sizeDelta, int fontSize, Font font, Color color, Vector3 localScale)
{
var gameobject = CreateTextGameObject(parentName, gameObjectName, text, alignment, isLocalPosition, position, sizeDelta, fontSize, font, color);
RectTransform rectTransform = gameobject.GetComponent<Text>().GetComponent<RectTransform>();
rectTransform.localScale = localScale;
return gameobject;
}

/// <summary>
/// Create GameObject with specified canvas, with normal and white font and custom fontsize
/// Create GameObject with specified parent, with normal and white font and custom fontsize
/// </summary>
public static GameObject CreateTextGameObject(string canvasName, string gameObjectName, string text, TextAnchor alignment, bool isLocalPosition, Vector3 position, Vector2 sizeDelta, int fontSize)
public static GameObject CreateTextGameObject(GameObject parent, string gameObjectName, string text, TextAnchor alignment, bool isLocalPosition, Vector3 position, Vector2 sizeDelta, int fontSize)
{
var canvas = GameObject.Find(canvasName);
var gameobject = new GameObject(gameObjectName);
gameobject.transform.SetParent(canvas.transform);
gameobject.transform.SetParent(parent.transform);
Text gameobject_text = gameobject.AddComponent<Text>();
gameobject_text.text = text;
gameobject_text.alignment = alignment;
Expand All @@ -36,33 +94,33 @@ public static GameObject CreateTextGameObject(string canvasName, string gameObje
}

/// <summary>
/// Create GameObject with specified canvas, with white font and custom fontsize
/// Create GameObject with specified parent, with white font, custom fontsize and font
/// </summary>
public static GameObject CreateTextGameObject(string canvasName, string gameObjectName, string text, TextAnchor alignment, bool isLocalPosition, Vector3 position, Vector2 sizeDelta, int fontSize, Font font)
public static GameObject CreateTextGameObject(GameObject parent, string gameObjectName, string text, TextAnchor alignment, bool isLocalPosition, Vector3 position, Vector2 sizeDelta, int fontSize, Font font)
{
var gameobject = CreateTextGameObject(canvasName, gameObjectName, text, alignment, isLocalPosition, position, sizeDelta, fontSize);
var gameobject = CreateTextGameObject(parent, gameObjectName, text, alignment, isLocalPosition, position, sizeDelta, fontSize);
Text gameobject_text = gameobject.GetComponent<Text>();
gameobject_text.font = font;
return gameobject;
}

/// <summary>
/// Create GameObject with specified canvas, with custom font, fontsize and color
/// Create GameObject with specified parent, with custom fontsize, font and color
/// </summary>
public static GameObject CreateTextGameObject(string canvasName, string gameObjectName, string text, TextAnchor alignment, bool isLocalPosition, Vector3 position, Vector2 sizeDelta, int fontSize, Font font, Color color)
public static GameObject CreateTextGameObject(GameObject parent, string gameObjectName, string text, TextAnchor alignment, bool isLocalPosition, Vector3 position, Vector2 sizeDelta, int fontSize, Font font, Color color)
{
var gameobject = CreateTextGameObject(canvasName, gameObjectName, text, alignment, isLocalPosition, position, sizeDelta, fontSize, font);
var gameobject = CreateTextGameObject(parent, gameObjectName, text, alignment, isLocalPosition, position, sizeDelta, fontSize, font);
Text gameobject_text = gameobject.GetComponent<Text>();
gameobject_text.color = color;
return gameobject;
}

/// <summary>
/// Create GameObject with specified canvas, with custom font, fontsize and color, custom local scale
/// Create GameObject with specified parent, with custom font, fontsize and color, custom local scale
/// </summary>
public static GameObject CreateTextGameObject(string canvasName, string gameObjectName, string text, TextAnchor alignment, bool isLocalPosition, Vector3 position, Vector2 sizeDelta, int fontSize, Font font, Color color, Vector3 localScale)
public static GameObject CreateTextGameObject(GameObject parent, string gameObjectName, string text, TextAnchor alignment, bool isLocalPosition, Vector3 position, Vector2 sizeDelta, int fontSize, Font font, Color color, Vector3 localScale)
{
var gameobject = CreateTextGameObject(canvasName, gameObjectName, text, alignment, isLocalPosition, position, sizeDelta, fontSize, font, color);
var gameobject = CreateTextGameObject(parent, gameObjectName, text, alignment, isLocalPosition, position, sizeDelta, fontSize, font, color);
RectTransform rectTransform = gameobject.GetComponent<Text>().GetComponent<RectTransform>();
rectTransform.localScale = localScale;
return gameobject;
Expand Down
Loading

0 comments on commit 1edab08

Please sign in to comment.