diff --git a/Modules/Extensions/ObjectHelper.cs b/Modules/Extensions/ObjectHelper.cs new file mode 100644 index 000000000..668ecbeef --- /dev/null +++ b/Modules/Extensions/ObjectHelper.cs @@ -0,0 +1,22 @@ +using HarmonyLib; +using UnityEngine; + +namespace EHR; + +public static class ObjectHelper +{ + /// + /// オブジェクトのコンポーネントを破棄します + /// + public static void DestroyTranslator(this GameObject obj) + { + if (obj == null) return; + obj.ForEachChild((Il2CppSystem.Action)DestroyTranslator); + TextTranslatorTMP[] translator = obj.GetComponentsInChildren(true); + translator?.Do(Object.Destroy); + } + /// + /// オブジェクトのコンポーネントを破棄します + /// + public static void DestroyTranslator(this MonoBehaviour obj) => obj?.gameObject?.DestroyTranslator(); +} diff --git a/Modules/SimpleButton.cs b/Modules/SimpleButton.cs new file mode 100644 index 000000000..46954293c --- /dev/null +++ b/Modules/SimpleButton.cs @@ -0,0 +1,99 @@ +using System; +using TMPro; +using UnityEngine; +using Object = UnityEngine.Object; + +namespace EHR; + +public class SimpleButton +{ + /// 新しいボタンを作成する + /// 親オブジェクト + /// オブジェクト名 + /// 通常時の背景色 + /// マウスホバー時の背景色 + /// クリック時に発火するアクション + /// ボタンのラベル + /// ボタンの大きさ + /// 初期状態でアクティブにするかどうか(デフォルトtrue) + public SimpleButton( + Transform parent, + string name, + Vector3 localPosition, + Color32 normalColor, + Color32 hoverColor, + Action action, + string label, + bool isActive = true) + { + if (baseButton == null) + { + throw new InvalidOperationException("baseButtonが未設定"); + } + + Button = Object.Instantiate(baseButton, parent); + Label = Button.transform.Find("FontPlacer/Text_TMP").GetComponent(); + NormalSprite = Button.inactiveSprites.GetComponent(); + HoverSprite = Button.activeSprites.GetComponent(); + buttonCollider = Button.GetComponent(); + + // ラベルをセンタリング + var container = Label.transform.parent; + Object.Destroy(Label.GetComponent()); + container.SetLocalX(0f); + Label.transform.SetLocalX(0f); + Label.horizontalAlignment = HorizontalAlignmentOptions.Center; + + Button.name = name; + Button.transform.localPosition = localPosition; + NormalSprite.color = normalColor; + HoverSprite.color = hoverColor; + Button.OnClick.AddListener(action); + Label.text = label; + Button.gameObject.SetActive(isActive); + } + public PassiveButton Button { get; } + public TextMeshPro Label { get; } + public SpriteRenderer NormalSprite { get; } + public SpriteRenderer HoverSprite { get; } + private readonly BoxCollider2D buttonCollider; + private Vector2 _scale; + public Vector2 Scale + { + get => _scale; + set => _scale = NormalSprite.size = HoverSprite.size = buttonCollider.size = value; + } + private float _fontSize; + public float FontSize + { + get => _fontSize; + set => _fontSize = Label.fontSize = Label.fontSizeMin = Label.fontSizeMax = value; + } + + private static PassiveButton baseButton; + public static void SetBase(PassiveButton passiveButton) + { + if (baseButton != null || passiveButton == null) + { + return; + } + // 複製 + baseButton = Object.Instantiate(passiveButton); + var label = baseButton.transform.Find("FontPlacer/Text_TMP").GetComponent(); + baseButton.gameObject.SetActive(false); + // シーン切替時に破棄されないようにする + Object.DontDestroyOnLoad(baseButton); + baseButton.name = "EHR_SimpleButtonBase"; + // 不要なコンポーネントを無効化 + Object.Destroy(baseButton.GetComponent()); + label.DestroyTranslator(); + label.fontSize = label.fontSizeMax = label.fontSizeMin = 3.5f; + label.enableWordWrapping = false; + label.text = "EHR SIMPLE BUTTON BASE"; + // 当たり判定がズレてるのを直す + var buttonCollider = baseButton.GetComponent(); + buttonCollider.offset = new(0f, 0f); + baseButton.OnClick = new(); + } + public static bool IsNullOrDestroyed(SimpleButton button) => button == null || button.Button == null; +} diff --git a/Patches/CredentialsPatch.cs b/Patches/CredentialsPatch.cs index 929069b59..f248f9165 100644 --- a/Patches/CredentialsPatch.cs +++ b/Patches/CredentialsPatch.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Linq; using System.Text; using EHR.Modules; @@ -80,52 +81,28 @@ internal class VersionShowerStartPatch } } -[HarmonyPatch(typeof(MainMenuManager), nameof(MainMenuManager.Start))] +[HarmonyPatch(typeof(MainMenuManager), nameof(MainMenuManager.Start)), HarmonyPriority(Priority.First)] internal class TitleLogoPatch { + public static GameObject ModStamp; public static GameObject Ambience; public static GameObject LoadingHint; + public static GameObject LeftPanel; + public static GameObject RightPanel; + public static GameObject CloseRightButton; + public static GameObject Tint; + public static GameObject BottomButtonBounds; - //private static readonly Color themeColor1 = new(0.99f, 0.55f, 0.56f); - //private static readonly Color themeColor2 = new(1f, 0.31f, 0.09f); - //private static readonly Color themeColor3 = new(0.08f, 0.03f, 0.12f); - //private static readonly Color themeColor4 = new(0.11f, 0.13f, 0.59f); - //private static readonly Color themeColor5 = new(0.63f, 0.53f, 0.89f); - //private static readonly Color themeColor6 = new(0.69f, 0.2f, 0.65f); - //private static readonly Color themeColor7 = new(0.97f, 0.41f, 0.61f); - //private static readonly Color themeColor8 = new(0.27f, 0.21f, 0.7f); - //private static readonly Color themeColor9 = new(0.42f, 0.3f, 0.8f); - //private static readonly Color themeColor10 = new(0.18f, 0.2f, 0.59f); - //private static readonly Color themeColor11 = new(0.96f, 0.88f, 0.86f); - - // Winter BG - // private static readonly Color ThemeColor1 = new(0.98f, 0.7f, 0.44f); - // private static readonly Color ThemeColor2 = new(0.98f, 0.61f, 0.42f); - // private static readonly Color ThemeColor3 = new(0.04f, 0.41f, 0.75f); - // private static readonly Color ThemeColor4 = new(0.12f, 0.17f, 0.47f); - // private static readonly Color ThemeColor5 = new(0.38f, 0.44f, 0.66f); - // private static readonly Color ThemeColor6 = new(0.72f, 0.68f, 0.79f); - // private static readonly Color ThemeColor7 = ThemeColor1.ShadeColor(0.1f); - // private static readonly Color ThemeColor8 = new(0.19f, 0.24f, 0.37f); - // private static readonly Color ThemeColor9 = ThemeColor5.ShadeColor(0.1f); - // private static readonly Color ThemeColor10 = ThemeColor4.ShadeColor(0.1f); - // private static readonly Color ThemeColor11 = ThemeColor6.ShadeColor(0.1f); - - // Summer BG - private static readonly Color ThemeColor1 = new(0.706f, 0.588f, 0.455f); - private static readonly Color ThemeColor2 = new(0.827f, 0.827f, 0.643f); - private static readonly Color ThemeColor3 = new(0.196f, 0.196f, 0.067f); - private static readonly Color ThemeColor4 = new(0.145f, 0.655f, 0.859f); - private static readonly Color ThemeColor5 = new(0.580f, 0.780f, 0.820f); - private static readonly Color ThemeColor6 = new(0.435f, 0.776f, 0.925f); - private static readonly Color ThemeColor7 = new(0.161f, 0.439f, 0.588f); - private static readonly Color ThemeColor8 = new(0.388f, 0.565f, 0.537f); - private static readonly Color ThemeColor9 = new(0.463f, 0.471f, 0.188f); - private static readonly Color ThemeColor10 = Color.black; - private static readonly Color ThemeColor11 = ThemeColor4.ShadeColor(0.1f); + public static Vector3 RightPanelOp; private static void Postfix(MainMenuManager __instance) { + + GameObject.Find("BackgroundTexture")?.SetActive(!MainMenuManagerPatch.ShowedBak); + + if (!(ModStamp = GameObject.Find("ModStamp"))) return; + ModStamp.transform.localScale = new Vector3(0.3f, 0.3f, 0.3f); + if (!Options.IsLoaded) { LoadingHint = new("LoadingHint") @@ -148,114 +125,86 @@ internal class TitleLogoPatch try { if (Options.IsLoaded) __instance.playButton.transform.gameObject.SetActive(true); - - SpriteRenderer activeSpriteRender = __instance.playButton.activeSprites.GetComponent(); - activeSpriteRender.color = ThemeColor1; - - SpriteRenderer inactiveSpriteRender = __instance.playButton.inactiveSprites.GetComponent(); - inactiveSpriteRender.color = ThemeColor2; - inactiveSpriteRender.sprite = activeSpriteRender.sprite; - - __instance.playLocalButton.activeSprites.GetComponent().color = Color.yellow; - __instance.PlayOnlineButton.activeSprites.GetComponent().color = Color.yellow; - - __instance.howToPlayButton.activeSprites.GetComponent().color = Color.magenta; - __instance.howToPlayButton.inactiveSprites.GetComponent().color = Color.blue; - __instance.howToPlayButton.activeTextColor = Color.white; - __instance.howToPlayButton.inactiveTextColor = Color.white; - __instance.accountCTAButton.activeSprites.GetComponent().color = Color.yellow; - - __instance.playButton.activeTextColor = ThemeColor3; - __instance.playButton.inactiveTextColor = ThemeColor3; - - __instance.inventoryButton.inactiveSprites.GetComponent().color = ThemeColor4; - __instance.inventoryButton.activeSprites.GetComponent().color = ThemeColor5; - __instance.inventoryButton.activeTextColor = Color.white; - __instance.inventoryButton.inactiveTextColor = Color.white; - - __instance.shopButton.inactiveSprites.GetComponent().color = ThemeColor4; - __instance.shopButton.activeSprites.GetComponent().color = ThemeColor5; - __instance.shopButton.activeTextColor = Color.white; - __instance.shopButton.inactiveTextColor = Color.white; - - __instance.newsButton.inactiveSprites.GetComponent().color = ThemeColor6; - __instance.newsButton.activeSprites.GetComponent().color = ThemeColor7; - __instance.newsButton.activeTextColor = Color.white; - __instance.newsButton.inactiveTextColor = Color.white; - - __instance.myAccountButton.inactiveSprites.GetComponent().color = ThemeColor6; - __instance.myAccountButton.activeSprites.GetComponent().color = ThemeColor7; - __instance.myAccountButton.activeTextColor = Color.white; - __instance.myAccountButton.inactiveTextColor = Color.white; - - __instance.settingsButton.inactiveSprites.GetComponent().color = ThemeColor6; - __instance.settingsButton.activeSprites.GetComponent().color = ThemeColor7; - __instance.settingsButton.activeTextColor = Color.white; - __instance.settingsButton.inactiveTextColor = Color.white; - - __instance.quitButton.inactiveSprites.GetComponent().color = ThemeColor8; - __instance.quitButton.activeSprites.GetComponent().color = ThemeColor9; - __instance.quitButton.activeTextColor = Color.white; - __instance.quitButton.inactiveTextColor = Color.white; - - __instance.creditsButton.inactiveSprites.GetComponent().color = ThemeColor10; - __instance.creditsButton.activeSprites.GetComponent().color = ThemeColor11; - __instance.creditsButton.activeTextColor = Color.white; - __instance.creditsButton.inactiveTextColor = Color.white; - - GameObject.Find("WindowShine")?.transform.gameObject.SetActive(false); - GameObject.Find("ScreenCover")?.transform.gameObject.SetActive(false); - GameObject.Find("BackgroundTexture")?.transform.gameObject.SetActive(false); - - Ambience.SetActive(false); - var customBg = new GameObject("CustomBG") - { - transform = - { - position = new(0f, 0f, 520f) - } - }; - var bgRenderer = customBg.AddComponent(); - bgRenderer.sprite = Utils.LoadSprite("EHR.Resources.Images.SummerBG.jpg", 180f); - - if (__instance.screenTint != null) - { - __instance.screenTint.gameObject.transform.localPosition += new Vector3(1000f, 0f); - __instance.screenTint.enabled = false; - } - - __instance.rightPanelMask?.SetActive(true); - - GameObject leftPanel = GameObject.Find("LeftPanel")?.transform.gameObject; - GameObject rightPanel = GameObject.Find("RightPanel")?.transform.gameObject; - if (rightPanel != null) - { - rightPanel.gameObject.GetComponent().enabled = false; - } - - GameObject maskedBlackScreen = GameObject.Find("MaskedBlackScreen")?.transform.gameObject; - if (maskedBlackScreen != null) - { - maskedBlackScreen.GetComponent().enabled = false; - maskedBlackScreen.transform.localPosition = new(-2.5f, 0.6f); - maskedBlackScreen.transform.localScale = new(7.35f, 4.5f, 4f); - } - - GameObject.Find("Shine")?.transform.gameObject.SetActive(false); - - leftPanel?.GetComponentsInChildren(true).Where(r => r.name == "Shine").Do(r => r.color = new(0f, 0f, 1f, 0.1f)); - - if (leftPanel != null) leftPanel.gameObject.GetComponent().enabled = false; - GameObject.Find("LeftPanel")?.transform.Find("Divider")?.gameObject.SetActive(false); - - PlayerParticles particles = Object.FindObjectOfType(); - particles?.gameObject.SetActive(false); } catch (Exception ex) { Logger.Warn(ex.ToString(), "MainMenuLoader"); } } + + if (!(LeftPanel = GameObject.Find("LeftPanel"))) return; + LeftPanel.transform.localScale = new Vector3(0.7f, 0.7f, 0.7f); + static void ResetParent(GameObject obj) => obj.transform.SetParent(LeftPanel.transform.parent); + LeftPanel.ForEachChild((Il2CppSystem.Action)ResetParent); + LeftPanel.SetActive(false); + + Color shade = new(0f, 0f, 0f, 0f); + var standardActiveSprite = __instance.newsButton.activeSprites.GetComponent().sprite; + var minorActiveSprite = __instance.quitButton.activeSprites.GetComponent().sprite; + + Dictionary, (Sprite, Color, Color, Color, Color)> mainButtons = new() + { + {new List() {__instance.playButton, __instance.inventoryButton, __instance.shopButton}, + (standardActiveSprite, new(1f, 0.524f, 0.549f, 0.8f), shade, Color.white, Color.white) }, + {new List() {__instance.newsButton, __instance.myAccountButton, __instance.settingsButton}, + (minorActiveSprite, new(1f, 0.825f, 0.686f, 0.8f), shade, Color.white, Color.white) }, + {new List() {__instance.creditsButton, __instance.quitButton}, + (minorActiveSprite, new(0.526f, 1f, 0.792f, 0.8f), shade, Color.white, Color.white) }, + }; + + void FormatButtonColor(PassiveButton button, Sprite borderType, Color inActiveColor, Color activeColor, Color inActiveTextColor, Color activeTextColor) + { + button.activeSprites.transform.FindChild("Shine")?.gameObject?.SetActive(false); + button.inactiveSprites.transform.FindChild("Shine")?.gameObject?.SetActive(false); + var activeRenderer = button.activeSprites.GetComponent(); + var inActiveRenderer = button.inactiveSprites.GetComponent(); + activeRenderer.sprite = minorActiveSprite; + inActiveRenderer.sprite = minorActiveSprite; + activeRenderer.color = activeColor.a == 0f ? new Color(inActiveColor.r, inActiveColor.g, inActiveColor.b, 1f) : activeColor; + inActiveRenderer.color = inActiveColor; + button.activeTextColor = activeTextColor; + button.inactiveTextColor = inActiveTextColor; + } + + foreach (var kvp in mainButtons) + kvp.Key.Do(button => FormatButtonColor(button, kvp.Value.Item1, kvp.Value.Item2, kvp.Value.Item3, kvp.Value.Item4, kvp.Value.Item5)); + + GameObject.Find("Divider")?.SetActive(false); + + if (!(RightPanel = GameObject.Find("RightPanel"))) return; + var rpap = RightPanel.GetComponent(); + if (rpap) Object.Destroy(rpap); + RightPanelOp = RightPanel.transform.localPosition; + RightPanel.transform.localPosition = RightPanelOp + new Vector3(10f, 0f, 0f); + RightPanel.GetComponent().color = new(1f, 0.78f, 0.9f, 1f); + + CloseRightButton = new GameObject("CloseRightPanelButton"); + CloseRightButton.transform.SetParent(RightPanel.transform); + CloseRightButton.transform.localPosition = new Vector3(-4.78f, 1.3f, 1f); + CloseRightButton.transform.localScale = new(1f, 1f, 1f); + CloseRightButton.AddComponent().size = new(0.6f, 1.5f); + var closeRightSpriteRenderer = CloseRightButton.AddComponent(); + closeRightSpriteRenderer.sprite = Utils.LoadSprite("EHR.Resources.Images.RightPanelCloseButton.png", 100f); + closeRightSpriteRenderer.color = new(1f, 0.78f, 0.9f, 1f); + var closeRightPassiveButton = CloseRightButton.AddComponent(); + closeRightPassiveButton.OnClick = new(); + closeRightPassiveButton.OnClick.AddListener((System.Action)MainMenuManagerPatch.HideRightPanel); + closeRightPassiveButton.OnMouseOut = new(); + closeRightPassiveButton.OnMouseOut.AddListener((System.Action)(() => closeRightSpriteRenderer.color = new(1f, 0.78f, 0.9f, 1f))); + closeRightPassiveButton.OnMouseOver = new(); + closeRightPassiveButton.OnMouseOver.AddListener((System.Action)(() => closeRightSpriteRenderer.color = new(1f, 0.68f, 0.99f, 1f))); + + Tint = __instance.screenTint.gameObject; + var ttap = Tint.GetComponent(); + if (ttap) Object.Destroy(ttap); + Tint.transform.SetParent(RightPanel.transform); + Tint.transform.localPosition = new Vector3(-0.0824f, 0.0513f, Tint.transform.localPosition.z); + Tint.transform.localScale = new Vector3(1f, 1f, 1f); + __instance.howToPlayButton.gameObject.SetActive(false); + __instance.howToPlayButton.transform.parent.Find("FreePlayButton").gameObject.SetActive(false); + + if (!(BottomButtonBounds = GameObject.Find("BottomButtonBounds"))) return; + BottomButtonBounds.transform.localPosition -= new Vector3(0f, 0.1f, 0f); } } diff --git a/Patches/MainMenuManagerPatch.cs b/Patches/MainMenuManagerPatch.cs index 7d2626c69..11c93d0b4 100644 --- a/Patches/MainMenuManagerPatch.cs +++ b/Patches/MainMenuManagerPatch.cs @@ -2,7 +2,6 @@ using System; using HarmonyLib; using TMPro; using UnityEngine; -using static EHR.Translator; using Object = UnityEngine.Object; namespace EHR; @@ -10,101 +9,177 @@ namespace EHR; [HarmonyPatch] public class MainMenuManagerPatch { - public static GameObject Template; + public static MainMenuManager Instance { get; private set; } - //public static GameObject qqButton; - //public static GameObject discordButton; - public static GameObject UpdateButton; + public static PassiveButton Template; + public static PassiveButton UpdateButton; + private static PassiveButton gitHubButton; + private static PassiveButton discordButton; + private static PassiveButton websiteButton; - [HarmonyPatch(typeof(MainMenuManager), nameof(MainMenuManager.LateUpdate)), HarmonyPostfix] - public static void Postfix(MainMenuManager __instance) + [HarmonyPatch(typeof(MainMenuManager), nameof(MainMenuManager.OpenGameModeMenu))] + [HarmonyPatch(typeof(MainMenuManager), nameof(MainMenuManager.OpenAccountMenu))] + [HarmonyPatch(typeof(MainMenuManager), nameof(MainMenuManager.OpenCredits))] + [HarmonyPrefix, HarmonyPriority(Priority.Last)] + public static void ShowRightPanel() => ShowingPanel = true; + + [HarmonyPatch(typeof(MainMenuManager), nameof(MainMenuManager.Start))] + [HarmonyPatch(typeof(OptionsMenuBehaviour), nameof(OptionsMenuBehaviour.Open))] + [HarmonyPatch(typeof(AnnouncementPopUp), nameof(AnnouncementPopUp.Show))] + [HarmonyPrefix, HarmonyPriority(Priority.Last)] + public static void HideRightPanel() { - if (__instance == null) return; - try - { - __instance.playButton.transform.gameObject.SetActive(Options.IsLoaded); - if (TitleLogoPatch.LoadingHint == null) return; - TitleLogoPatch.LoadingHint.SetActive(!Options.IsLoaded); - TitleLogoPatch.LoadingHint.GetComponent().text = string.Format(GetString("LoadingWithPercentage"), Options.LoadingPercentage, Options.MainLoadingText, Options.RoleLoadingText); - } - catch - { - } + ShowingPanel = false; + AccountManager.Instance?.transform?.FindChild("AccountTab/AccountWindow")?.gameObject?.SetActive(false); } + public static void ShowRightPanelImmediately() + { + ShowingPanel = true; + TitleLogoPatch.RightPanel.transform.localPosition = TitleLogoPatch.RightPanelOp; + Instance.OpenGameModeMenu(); + } + + private static bool isOnline = false; + public static bool ShowedBak = false; + private static bool ShowingPanel = false; + [HarmonyPatch(typeof(SignInStatusComponent), nameof(SignInStatusComponent.SetOnline)), HarmonyPostfix] + public static void SetOnline_Postfix() {LateTask.New(() => { isOnline = true; }, 0.1f, "Set Online Status"); } [HarmonyPatch(typeof(MainMenuManager), nameof(MainMenuManager.Start)), HarmonyPrefix] public static void Start_Prefix(MainMenuManager __instance) { - if (Template == null) Template = GameObject.Find("/MainUI/ExitGameButton"); + if (Template == null) Template = __instance.quitButton; if (Template == null) return; - //if (CultureInfo.CurrentCulture.Name == "zh-CN") - //{ - // //生成QQ群按钮 - // if (qqButton == null) qqButton = Object.Instantiate(template, template.transform.parent); - // qqButton.name = "qqButton"; - // qqButton.transform.position = Vector3.Reflect(template.transform.position, Vector3.left); - - // var qqText = qqButton.transform.GetChild(0).GetComponent(); - // Color qqColor = new Color32(0, 164, 255, byte.MaxValue); - // PassiveButton qqPassiveButton = qqButton.GetComponent(); - // SpriteRenderer qqButtonSprite = qqButton.GetComponent(); - // qqPassiveButton.OnClick = new(); - // qqPassiveButton.OnClick.AddListener((Action)(() => Application.OpenURL(Main.QQInviteUrl))); - // qqPassiveButton.OnMouseOut.AddListener((Action)(() => qqButtonSprite.color = qqText.color = qqColor)); - // __instance.StartCoroutine(Effects.Lerp(0.01f, new Action((p) => qqText.SetText("QQ群")))); - // qqButtonSprite.color = qqText.color = qqColor; - // qqButton.gameObject.SetActive(Main.ShowQQButton && !Main.IsAprilFools); - //} - //else - //{ - // //Discordボタンを生成 - // if (discordButton == null) discordButton = Object.Instantiate(template, template.transform.parent); - // discordButton.name = "DiscordButton"; - // discordButton.transform.position = Vector3.Reflect(template.transform.position, Vector3.left); - - // var discordText = discordButton.transform.GetChild(0).GetComponent(); - // Color discordColor = new Color32(86, 98, 246, byte.MaxValue); - // PassiveButton discordPassiveButton = discordButton.GetComponent(); - // SpriteRenderer discordButtonSprite = discordButton.GetComponent(); - // discordPassiveButton.OnClick = new(); - // discordPassiveButton.OnClick.AddListener((Action)(() => Application.OpenURL(Main.DiscordInviteUrl))); - // discordPassiveButton.OnMouseOut.AddListener((Action)(() => discordButtonSprite.color = discordText.color = discordColor)); - // __instance.StartCoroutine(Effects.Lerp(0.01f, new Action((p) => discordText.SetText("Discord")))); - // discordButtonSprite.color = discordText.color = discordColor; - // discordButton.gameObject.SetActive(Main.ShowDiscordButton && !Main.IsAprilFools); - //} - - if (UpdateButton == null) UpdateButton = Object.Instantiate(Template, Template.transform.parent); - UpdateButton.name = "UpdateButton"; - UpdateButton.transform.position = Template.transform.position + new Vector3(0.25f, 0.75f); - UpdateButton.transform.GetChild(0).GetComponent().localScale *= 1.5f; - - var updateText = UpdateButton.transform.GetChild(0).GetComponent(); - Color updateColor = new Color32(247, 56, 23, byte.MaxValue); - PassiveButton updatePassiveButton = UpdateButton.GetComponent(); - SpriteRenderer updateButtonSprite = UpdateButton.GetComponent(); - updatePassiveButton.OnClick = new(); - updatePassiveButton.OnClick.AddListener((Action)(() => + if (UpdateButton == null) { - UpdateButton.SetActive(false); - ModUpdater.StartUpdate(ModUpdater.downloadUrl, true); - })); - updatePassiveButton.OnMouseOut.AddListener((Action)(() => updateButtonSprite.color = updateText.color = updateColor)); - updateButtonSprite.color = updateText.color = updateColor; - updateButtonSprite.size *= 1.5f; + UpdateButton = CreateButton( + "updateButton", + new(4.2f, -1.3f, 1f), + new(255, 165, 0, byte.MaxValue), + new(255, 200, 0, byte.MaxValue), + () => ModUpdater.StartUpdate(ModUpdater.downloadUrl, true), + Translator.GetString("updateButton")); + UpdateButton.transform.localScale = Vector3.one; + } UpdateButton.gameObject.SetActive(ModUpdater.hasUpdate); -#if RELEASE - var freeplayButton = GameObject.Find("/MainUI/FreePlayButton"); - if (freeplayButton != null) - { - freeplayButton.GetComponent().OnClick = new(); - freeplayButton.GetComponent().OnClick.AddListener((Action)(() => Application.OpenURL("https://tohe.cc"))); - __instance.StartCoroutine(Effects.Lerp(0.01f, new Action(p => freeplayButton.transform.GetChild(0).GetComponent().SetText(GetString("Website"))))); - } -#endif + Application.targetFrameRate = Main.UnlockFps.Value ? 9999 : 60; + } + [HarmonyPatch(typeof(MainMenuManager), nameof(MainMenuManager.LateUpdate)), HarmonyPostfix] + public static void MainMenuManager_LateUpdate() + { - Application.targetFrameRate = Main.UnlockFps.Value ? 165 : 60; + if (GameObject.Find("MainUI") == null) ShowingPanel = false; + + if (TitleLogoPatch.RightPanel != null) + { + var pos1 = TitleLogoPatch.RightPanel.transform.localPosition; + Vector3 lerp1 = Vector3.Lerp(pos1, TitleLogoPatch.RightPanelOp + new Vector3(ShowingPanel ? 0f : 10f, 0f, 0f), Time.deltaTime * (ShowingPanel ? 3f : 2f)); + if (ShowingPanel + ? TitleLogoPatch.RightPanel.transform.localPosition.x > TitleLogoPatch.RightPanelOp.x + 0.03f + : TitleLogoPatch.RightPanel.transform.localPosition.x < TitleLogoPatch.RightPanelOp.x + 9f + ) TitleLogoPatch.RightPanel.transform.localPosition = lerp1; + } + + if (ShowedBak || !isOnline) return; + var bak = GameObject.Find("BackgroundTexture"); + if (bak == null || !bak.active) return; + var pos2 = bak.transform.position; + Vector3 lerp2 = Vector3.Lerp(pos2, new Vector3(pos2.x, 7.1f, pos2.z), Time.deltaTime * 1.4f); + bak.transform.position = lerp2; + if (pos2.y > 7f) ShowedBak = true; + } + public static SpriteRenderer MG_Logo; + [HarmonyPatch(typeof(MainMenuManager), nameof(MainMenuManager.Start)), HarmonyPostfix, HarmonyPriority(Priority.VeryHigh)] + public static void Start_Postfix(MainMenuManager __instance) + { + Instance = __instance; + + SimpleButton.SetBase(__instance.quitButton); + var logoObject = new GameObject("titleLogo_MG"); + var logoTransform = logoObject.transform; + MG_Logo = logoObject.AddComponent(); + logoTransform.localPosition = new(2f, -0.5f, 1f); + logoTransform.localScale *= 1.2f; + MG_Logo.sprite = Utils.LoadSprite("EHR.Resources.Images.EHR-Icon.png", 400f); + + // GitHub Button + if (gitHubButton == null) + { + gitHubButton = CreateButton( + "GitHubButton", + new Vector3(-2.3f, -1.3f, 1f), + new Color32(153, 153, 153, byte.MaxValue), + new Color32(209, 209, 209, byte.MaxValue), + () => Application.OpenURL("https://github.com/Gurge44/EndlessHostRoles"), + Translator.GetString("GitHub")); //"GitHub" + } + gitHubButton.gameObject.SetActive(true); + + // Discord Button + if (discordButton == null) + { + discordButton = CreateButton( + "DiscordButton", + new Vector3(-0.5f, -1.3f, 1f), + new Color32(88, 101, 242, byte.MaxValue), + new Color32(148, 161, byte.MaxValue, byte.MaxValue), + () => Application.OpenURL("https://discord.com/invite/m3ayxfumC8"), + Translator.GetString("Discord")); //"Discord" + } + discordButton.gameObject.SetActive(true); + + // Website Button + if (websiteButton == null) + { + websiteButton = CreateButton( + "WebsiteButton", + new Vector3(1.3f, -1.3f, 1f), + new Color32(251, 81, 44, byte.MaxValue), + new Color32(211, 77, 48, byte.MaxValue), + () => Application.OpenURL("https://sites.google.com/view/ehr-au"), + Translator.GetString("Website")); //"Website" + } + websiteButton.gameObject.SetActive(true); + + Application.targetFrameRate = Main.UnlockFps.Value ? 9999 : 60; + } + public static PassiveButton CreateButton(string name, Vector3 localPosition, Color32 normalColor, Color32 hoverColor, Action action, string label, Vector2? scale = null) + { + var button = Object.Instantiate(Template, Template.transform.parent); + button.name = name; + Object.Destroy(button.GetComponent()); + button.transform.localPosition = localPosition; + + button.OnClick = new(); + button.OnClick.AddListener(action); + + var buttonText = button.transform.Find("FontPlacer/Text_TMP").GetComponent(); + buttonText.DestroyTranslator(); + buttonText.fontSize = buttonText.fontSizeMax = buttonText.fontSizeMin = 3.5f; + buttonText.enableWordWrapping = false; + buttonText.text = label; + var normalSprite = button.inactiveSprites.GetComponent(); + var hoverSprite = button.activeSprites.GetComponent(); + normalSprite.color = normalColor; + hoverSprite.color = hoverColor; + + var container = buttonText.transform.parent; + Object.Destroy(container.GetComponent()); + Object.Destroy(buttonText.GetComponent()); + container.SetLocalX(0f); + buttonText.transform.SetLocalX(0f); + buttonText.horizontalAlignment = HorizontalAlignmentOptions.Center; + + var buttonCollider = button.GetComponent(); + if (scale.HasValue) + { + normalSprite.size = hoverSprite.size = buttonCollider.size = scale.Value; + } + + buttonCollider.offset = new(0f, 0f); + + return button; } } \ No newline at end of file diff --git a/README.md b/README.md index d03ace39a..fa626c0d5 100644 --- a/README.md +++ b/README.md @@ -240,6 +240,7 @@ > > - Our repo is a continuation of TOHE > - TONX reference: Modify character limit for chat messages +> - TONX reference: Modify and apply cool animations on Main Menu > ### :star: [TOH](https://github.com/tukasa0001/TownOfHost) : > @@ -298,6 +299,11 @@ > - Reference: Store message history > +### :star: [MoreGamemodes](https://github.com/Rabek009/MoreGamemodes) : +> +> - Reference: Part of the code used for the Endless Host Roles Image in the Main Menu +> + ### Endless Host Roles (EHR), with Endless Possibilities, brought to you by the Endless Network. ##### Developers: - Gurge44 diff --git a/Resources/Images/EHR-Icon.png b/Resources/Images/EHR-Icon.png new file mode 100644 index 000000000..600d5a7d0 Binary files /dev/null and b/Resources/Images/EHR-Icon.png differ diff --git a/Resources/Images/RightPanelCloseButton.png b/Resources/Images/RightPanelCloseButton.png new file mode 100644 index 000000000..0ca9f81d3 Binary files /dev/null and b/Resources/Images/RightPanelCloseButton.png differ diff --git a/Resources/Lang/en_US.json b/Resources/Lang/en_US.json index d4711bfda..14b7b695e 100644 --- a/Resources/Lang/en_US.json +++ b/Resources/Lang/en_US.json @@ -2379,6 +2379,8 @@ "AntiBlackOutLoggerSendInGame": "Because of an unknown error, the game will end to prevent black screen.", "AntiBlackOutRequestHostToForceEnd": "You were the reason of the black screen, you are asking the host to stop the game...", "AntiBlackOutHostRejectForceEnd": "You were the reason of the black screen, and the host is not going to end the game, we will disconnect you soon.", + "GitHub": "GitHub", + "Discord": "Discord", "Website": "Website", "NextPage": "Next Page", "PreviousPage": "Previous Page", diff --git a/Resources/Lang/pt_BR.json b/Resources/Lang/pt_BR.json index 5f02423dc..f4c22f0f8 100644 --- a/Resources/Lang/pt_BR.json +++ b/Resources/Lang/pt_BR.json @@ -2399,6 +2399,8 @@ "AntiBlackOutLoggerSendInGame": "Por causa de um erro desconhecido, o Jogo irá acabar para evitar telas pretas.", "AntiBlackOutRequestHostToForceEnd": "Você foi o motivo da tela preta, você está pedindo para o Anfitrião encerrar o jogo...", "AntiBlackOutHostRejectForceEnd": "Você foi o motivo pra tela preta, e o Anfitrião não irá encerrar o jogo, você será desconectado em breve.", + "GitHub": "GitHub", + "Discord": "Discord", "Website": "Página", "NextPage": "Próxima Página", "PreviousPage": "Página Anterior",