mirror of
https://github.com/Gurge44/EndlessHostRoles.git
synced 2026-10-20 01:46:25 +00:00
Improve and Fix some features (#266)
* Update GameStartManagerPatch.cs * Fix Show Modded Client Text option not working * Fix non host modded not seeing "Game Over" victory screen as GM * Improve CientOptionMenu Just if we run out of space for Client Options
This commit is contained in:
1 parent
1b9dcf2dbd
commit
5cd1dd070f
4 files changed
+54
-17
No files matched your search
+48
-11
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using BepInEx.Configuration;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -8,7 +9,7 @@ namespace EHR;
|
||||
public class ClientOptionItem
|
||||
{
|
||||
public static SpriteRenderer CustomBackground;
|
||||
private static int NumOptions;
|
||||
private static List<ToggleButtonBehaviour> OptionButtons;
|
||||
private readonly ConfigEntry<bool> Config;
|
||||
public readonly ToggleButtonBehaviour ToggleButton;
|
||||
|
||||
@@ -26,15 +27,15 @@ public class ClientOptionItem
|
||||
|
||||
if (CustomBackground == null)
|
||||
{
|
||||
NumOptions = 0;
|
||||
CustomBackground = Object.Instantiate(optionsMenuBehaviour.Background, optionsMenuBehaviour.transform);
|
||||
CustomBackground.name = "CustomBackground";
|
||||
CustomBackground.transform.localScale = new(0.9f, 0.9f, 1f);
|
||||
CustomBackground.transform.localPosition += Vector3.back * 8;
|
||||
CustomBackground.size += new Vector2(3f, 0f);
|
||||
CustomBackground.gameObject.SetActive(false);
|
||||
|
||||
ToggleButtonBehaviour closeButton = Object.Instantiate(mouseMoveToggle, CustomBackground.transform);
|
||||
closeButton.transform.localPosition = new(1.3f, -2.3f, -6f);
|
||||
closeButton.transform.localPosition = new(2.6f, -2.3f, -6f);
|
||||
closeButton.name = "Back";
|
||||
closeButton.Text.text = Translator.GetString("Back");
|
||||
closeButton.Background.color = Palette.DisabledGrey;
|
||||
@@ -70,20 +71,26 @@ public class ClientOptionItem
|
||||
modOptionsButton.Background.color = new Color32(0, 165, 255, byte.MaxValue);
|
||||
var modOptionsPassiveButton = modOptionsButton.GetComponent<PassiveButton>();
|
||||
modOptionsPassiveButton.OnClick = new();
|
||||
modOptionsPassiveButton.OnClick.AddListener(new Action(() => CustomBackground.gameObject.SetActive(true)));
|
||||
modOptionsPassiveButton.OnClick.AddListener(new Action(() =>
|
||||
{
|
||||
AdjustButtonPositions();
|
||||
CustomBackground.gameObject.SetActive(true);
|
||||
}));
|
||||
|
||||
if (leaveButton != null && leaveButton.transform != null) leaveButton.transform.localPosition = new(-1.35f, -2.411f, -1f);
|
||||
|
||||
if (returnButton != null) returnButton.transform.localPosition = new(1.35f, -2.411f, -1f);
|
||||
|
||||
OptionButtons = [];
|
||||
}
|
||||
|
||||
ToggleButton = Object.Instantiate(mouseMoveToggle, CustomBackground.transform);
|
||||
OptionButtons.Add(ToggleButton);
|
||||
|
||||
ToggleButton.transform.localPosition = new(
|
||||
NumOptions % 2 == 0 ? -1.3f : 1.3f,
|
||||
// ReSharper disable once PossibleLossOfFraction
|
||||
2.2f - (0.5f * (NumOptions / 2)),
|
||||
-6f);
|
||||
(OptionButtons.Count - 1) % 3 == 0 ? -2.6f : ((OptionButtons.Count - 1) % 3 == 1 ? 0f : 2.6f),
|
||||
2.2f - (0.5f * ((OptionButtons.Count - 1) / 3)),
|
||||
-6f);
|
||||
|
||||
ToggleButton.name = name;
|
||||
ToggleButton.Text.text = Translator.GetString(name);
|
||||
@@ -100,7 +107,10 @@ public class ClientOptionItem
|
||||
|
||||
UpdateToggle();
|
||||
}
|
||||
finally { NumOptions++; }
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Error(e.ToString(), "ClientOptionItem.Create");
|
||||
}
|
||||
}
|
||||
|
||||
public static ClientOptionItem Create(
|
||||
@@ -112,6 +122,33 @@ public class ClientOptionItem
|
||||
return new(name, config, optionsMenuBehaviour, additionalOnClickAction);
|
||||
}
|
||||
|
||||
public static void AdjustButtonPositions()
|
||||
{
|
||||
if (OptionButtons == null || OptionButtons.Count == 0) return;
|
||||
|
||||
int totalRows = (OptionButtons.Count + 2) / 3;
|
||||
|
||||
float topPosition = 2.2f;
|
||||
float bottomLimit = -1.6f;
|
||||
float availableHeight = topPosition - bottomLimit;
|
||||
float rowSpacing = totalRows > 1 ? availableHeight / (totalRows - 1) : 0f;
|
||||
|
||||
for (int i = 0; i < OptionButtons.Count; i++)
|
||||
{
|
||||
var button = OptionButtons[i];
|
||||
if (button == null) continue;
|
||||
|
||||
int row = i / 3;
|
||||
int col = i % 3;
|
||||
|
||||
float xPos = col == 0 ? -2.6f : (col == 1 ? 0f : 2.6f);
|
||||
|
||||
float yPos = topPosition - (row * rowSpacing);
|
||||
|
||||
button.transform.localPosition = new Vector3(xPos, yPos, -6f);
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateToggle()
|
||||
{
|
||||
if (ToggleButton == null) return;
|
||||
@@ -120,4 +157,4 @@ public class ClientOptionItem
|
||||
ToggleButton.Background.color = color;
|
||||
ToggleButton.Rollover?.ChangeOutColor(color);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -67,7 +67,7 @@ public static class GameStartManagerPatch
|
||||
}
|
||||
else
|
||||
{
|
||||
__instance.ClientViewButton.activeTextColor = __instance.HostViewButton.inactiveTextColor = Color.black;
|
||||
__instance.ClientViewButton.activeTextColor = __instance.ClientViewButton.inactiveTextColor = Color.black;
|
||||
__instance.ClientViewButton.inactiveSprites.GetComponent<SpriteRenderer>().color = new(0f, 0.647f, 1f, 1f);
|
||||
__instance.ClientViewButton.activeSprites.GetComponent<SpriteRenderer>().color = new(0f, 0.847f, 1f, 1f);
|
||||
__instance.ClientViewButton.inactiveSprites.transform.Find("Shine").GetComponent<SpriteRenderer>().color = new(0f, 1f, 1f, 0.5f);
|
||||
@@ -563,4 +563,4 @@ public static class GameStartManagerBeginPatch
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -345,7 +345,7 @@ internal static class SetEverythingUpPatch
|
||||
__instance.BackgroundBar.material.color = Utils.GetRoleColor(winnerRole);
|
||||
}
|
||||
|
||||
if (AmongUsClient.Instance.AmHost && Main.PlayerStates[PlayerControl.LocalPlayer.PlayerId].MainRole == CustomRoles.GM)
|
||||
if (Main.PlayerStates[PlayerControl.LocalPlayer.PlayerId].MainRole == CustomRoles.GM)
|
||||
{
|
||||
__instance.WinText.text = GetString("GameOver");
|
||||
__instance.WinText.color = Utils.GetRoleColor(CustomRoles.GM);
|
||||
@@ -608,4 +608,4 @@ internal static class SetEverythingUpPatch
|
||||
return name;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1547,7 +1547,7 @@ internal static class FixedUpdatePatch
|
||||
{
|
||||
if (!__instance.IsHost())
|
||||
{
|
||||
if (Main.PlayerVersion.TryGetValue(playerId, out PlayerVersion ver))
|
||||
if (Main.ShowModdedClientText.Value && Main.PlayerVersion.TryGetValue(playerId, out PlayerVersion ver))
|
||||
{
|
||||
if (Main.ForkId != ver.forkId)
|
||||
__instance.cosmetics.nameText.text = $"<color=#ff0000><size=1.4>{ver.forkId}</size>\n{__instance.name}</color>";
|
||||
@@ -2408,4 +2408,4 @@ internal static class BootFromVentPatch
|
||||
{
|
||||
return !GameStates.IsInTask || ExileController.Instance || __instance == null || __instance.myPlayer == null || !__instance.myPlayer.IsAlive() || !__instance.myPlayer.Is(CustomRoles.Nimble);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user