Fixed bug caused by reckless code

Changed how regions menu is displayed
This commit is contained in:
Daemon committed 2021-04-11 14:15:05 +01:00
1 parent 5b63d7cd0c
commit fd5a11394a
3 files changed
+33 -10

No files matched your search

+30 -9
View File
@@ -102,8 +102,8 @@ namespace Unify.Patches
DirectConnect.OnEnter = new Button.ButtonClickedEvent();
DirectConnect.OnEnter.AddListener((Action) UpdateRegion);
int offset = ((ServerManager.DefaultRegions.Length + 1) / 2) + 1;
DirectConnect.transform.localPosition = new Vector3(0, 2f - (offset / 2f), -100f);
int offset = _newRegions.Length + ModRegions.Count;
DirectConnect.transform.localPosition = new Vector3(0, 1f - (offset / 2f), -100f);
}
}
@@ -115,15 +115,35 @@ namespace Unify.Patches
DirectConnect.gameObject.SetActive(true);
var regionButtons = __instance.ButtonPool.activeChildren.ToArray();
int half = (regionButtons.Length + 1) / 2;
for (int x = 0; x < regionButtons.Length; x++)
{
ServerListButton regionButton = regionButtons[x].Cast<ServerListButton>();
regionButton.transform.localPosition = new Vector3(1.25f * ((x < half)? -1: 1), 2f - 0.5f * (x - ((x < half)? 0 : half)), 0f);
for (int i = 0; i < regionButtons.Length; i++)
{
ServerListButton regionButton = regionButtons[i].Cast<ServerListButton>();
(float x, float y) = CalculatePosition(i);
regionButton.transform.localPosition = new Vector3(1.25f + x, 2f - 0.5f * y, 0f);
}
}
private static (float x, float y) CalculatePosition(int index)
{
// currently broken
/*if (DirectRegion != null && ServerManager.DefaultRegions[index].Name == DirectRegion.Name)
{
int offset = Math.Max(
Math.Max(LoadCustomUserRegions().Length, _newRegions.Length + ModRegions.Count),
_oldRegions.Length);
return (1.25f, 2f - offset);
}*/
bool isCustomRegion = index >= _oldRegions.Length;
bool isCustomUserRegion = index >= _oldRegions.Length + _newRegions.Length + ModRegions.Count;
float x = (isCustomRegion ? 3f : 0) + (isCustomUserRegion ? 3f : 0) - 4.25f;
float y = index - (isCustomRegion ? _oldRegions.Length : 0) -
(isCustomUserRegion ? _newRegions.Length + ModRegions.Count : 0);
return (x, y);
}
}
[HarmonyPatch(typeof(JoinGameButton), nameof(JoinGameButton.OnClick))]
@@ -161,4 +181,5 @@ namespace Unify.Patches
}
// TODO:
// Store custom servers in a JSON file
// Store custom servers in a JSON file
// Mention `AddRegion` method in README
+3 -1
View File
@@ -6,6 +6,7 @@ using BepInEx;
using BepInEx.Configuration;
using BepInEx.IL2CPP;
using HarmonyLib;
using Hazel.Udp;
using Reactor;
using Unify.Patches;
@@ -42,7 +43,8 @@ namespace Unify
RegionsPatch.Patch();
Harmony.UnpatchAll(ReactorPlugin.Id);
// Unpatches the modded handshake, because Impostor is STILL not fully updated yet
Harmony.Unpatch(typeof(UdpConnection).GetMethod("HandleSend"), HarmonyPatchType.Prefix, ReactorPlugin.Id);
Harmony.PatchAll();
}
Binary file not shown.