using System; using System.IO; using BepInEx; using CoreNet.Utils; using GB.Platform.Lobby; using UnityEngine; #pragma warning disable IDE0051 // Private member is unused namespace GBSU.Addons; public class GBSUGui : MonoBehaviour { private bool menu_shown; private bool error_shown; //private string _currentMap; public Rect gmenu = new(Screen.width / 2, 0, 385f, 690f); public Rect error_dialog = new(Screen.width / 2, 0, 520f, 175f); private string error_msg = "Unknown error!"; readonly IInputSystem inputSystem = UnityInput.Current; private void Update() { if (inputSystem.GetKeyDown(KeyCode.RightShift)) { //Plugin.Log.LogInfo("Toggling GBSU menu..."); ToggleMenu(); } } private void ToggleMenu() { if (menu_shown == true) { menu_shown = false; //Plugin.Log.LogInfo("GBSU menu hidden"); } else { menu_shown = true; //Plugin.Log.LogInfo("GBSU menu shown"); } } private void ShowOurWindow(int window) { GUI.skin.label.alignment = TextAnchor.UpperLeft; GUILayout.Label($@"==Guide== Set CLI arguments: -ip, -port [Hosting] 1. Create a config in Gang Beasts_Data/Config/Rotation/config.json 2. Press the 'Host' button while in the Main Menu [Joining] 1. Go to Online 2. Press the 'Join' button"); if (GUI.Button(new Rect(320f, 10f, 55f, 30f), "KILL")) { Application.Quit(0); } if (Helper.serverip != null) { if (GUI.Button(new Rect(20f, 260f, 170f, 30f), "Host")) { if (LobbyManager.Instance.LobbyStates.SelfState == LobbyState.Game.Menu) { if (File.Exists(Helper.RotationFolderPath + "config.json")) { Helper.hosting = true; AudioListener.volume = 0; // mute game audio try { Plugin.AddServerComp(); // add custom GBSU server component GBSUServer.StartServer(); } catch (Exception e) { PushError("Looks like you've caught a bug! Please send your log file to us :)\n" + e); } } else { PushError(@$"No config.json could be found in {Helper.RotationFolderPath} Make sure to download a file from the examples given and rename it to config.json. {Helper.FilesInRotationDir()}"); } } else { PushError("Please stay on the main menu to begin hosting. Tip: You might need to exit your lobby."); } } if (GUI.Button(new Rect(195f, 260f, 170f, 30f), "Join")) { if (LobbyManager.Instance.LobbyStates.SelfState == LobbyState.Game.Online) { if (!Helper.hosting) { GBSUClient.JoinServer(Helper.serverip, Helper.serverport); } else { PushError("You are currently hosting a match! Please restart the game before attempting to join."); } } else { PushError("Failed to join lobby! Please select the Online option in-game before joining."); } } } else { PushError("Couldn't find the -ip CLI argument. Please refer to the documentation."); } if (GUI.Button(new Rect(20f, 295f, 170f, 30f), "Cap FPS to 60")) { Application.targetFrameRate = 60; } if (GUI.Button(new Rect(195f, 295f, 170f, 30f), "Cap FPS to 240")) { Application.targetFrameRate = 240; } if (GUI.Button(new Rect(20f, 330f, 170f, 30f), "Toggle VSync")) { Helper.FlipVSync(); } GUI.Label(new Rect(20f, 365f, 365f, 400f), $@" Current map: {UnityEngine.SceneManagement.SceneManager.GetActiveScene().name} Lobby State: {LobbyManager.Instance.LobbyStates.SelfState} VSync: {QualitySettings.vSyncCount} Target FPS: {Application.targetFrameRate} {UpdateScoreDisplay()} Made with <3 by anavoi at Gaboule Community Free and open-source software under GPLv3. Our source code is available at git.gaboule.com/Gaboule/GBSU Please refer to the documentation for more information."); GUI.DragWindow(new Rect(0, 0, 10000, 10000)); } private void ShowError(int window) { GUI.skin.label.alignment = TextAnchor.MiddleCenter; GUILayout.Label(error_msg); if (GUI.Button(new Rect(420f, 135f, 85f, 30f), "Close")) { error_shown = false; } GUI.DragWindow(new Rect(0, 0, 10000, 10000)); } private string UpdateScoreDisplay() { if (Helper.hosting) { string scoreString = "Score:\n"; foreach (var pair in Plugin.GameScore) { scoreString += $"{pair.Key}: {pair.Value}\n"; } return scoreString; } return null; } private void PushError(string message) { Plugin.Log.LogError(message); // Push this error to the UI error_msg = message; error_shown = true; } public void OnGUI() { if (menu_shown) { gmenu = GUILayout.Window(121, gmenu, ShowOurWindow, $"{MyPluginInfo.PLUGIN_NAME} [{MyPluginInfo.PLUGIN_VERSION}]"); } if (error_shown) { error_dialog = GUILayout.Window(122, error_dialog, ShowError, "An error occurred!"); } } }