public override void OnActivate() { bool firstTimeLaunch = !SettingsHandler.Has("firstTimeLaunch"); if (firstTimeLaunch) //if (true) { GUIWindow firstTimeWindow = WindowManager.SpawnWindow(); firstTimeWindow.Show(); firstTimeWindow.SetTitle("FirstTimeWindowTitle".LocDef("First time? Neat!")); firstTimeWindow.ShowCentered = true; firstTimeWindow.MinSize = new Vector2(Screen.width / 2 - 5f, 32 + 32 + 5 + 5 + 5); Text description = WindowManager.SpawnLabel(); description.text = GetSteamUsernameText(); Text description2 = WindowManager.SpawnLabel(); description2.text = "FirstTimeWindowDescription2".LocDef("The wiki also contains useful info on how to configure your server, set passwords on your server, and lots more! It also contains some useful infomation on how to debug/fix problems related to multiplayer."); Button openWikiButton = WindowManager.SpawnButton(); openWikiButton.GetComponentInChildren <Text>().text = "FirstTimeWindow_OpenWiki".LocDef("Open Wiki"); openWikiButton.onClick.AddListener(OpenWiki); Button closeWindowButton = WindowManager.SpawnButton(); closeWindowButton.GetComponentInChildren <Text>().text = "FirstTimeWindow_OK".LocDef("Ok"); closeWindowButton.onClick.AddListener(() => firstTimeWindow.gameObject.SetActive(false)); firstTimeWindow.SizeButton.SetActive(false); WindowManager.AddElementToWindow(description.gameObject, firstTimeWindow, new Rect(5, 15, (Screen.width / 2) - 15f, 32), Rect.zero); WindowManager.AddElementToWindow(openWikiButton.gameObject, firstTimeWindow, new Rect(5, (32 * 2) + 25, (Screen.width / 2) - 15f, 60f), Rect.zero); WindowManager.AddElementToWindow(closeWindowButton.gameObject, firstTimeWindow, new Rect(5, (32 * 2) + 90, (Screen.width / 2) - 15f, 60f), Rect.zero); WindowManager.AddElementToWindow(description2.gameObject, firstTimeWindow, new Rect(5, 42 + 5, (Screen.width / 2) - 15f, 32), Rect.zero); SettingsHandler.Set("firstTimeLaunch", false); } }
private void CreateBaseMultiplayerWindow() { Logging.Info("Opened multiplayer window."); if (MPWindow != null) { MPWindow.Show(); return; } MPWindow = WindowManager.SpawnWindow(); MPWindow.SetTitle("MultiplayerButton".LocDef("Multiplayer")); MPWindow.ShowCentered = true; MPWindow.MinSize = new Vector2(730, 500); MPWindow.SizeButton.SetActive(false); new Utils.Controls.Element.UIButton("ConnectButtonText".LocDef("Connect"), new Rect(30, 30, 159, 25), () => { #region Connect Window MPWindow.gameObject.SetActive(false); /** * Box 200, 200, 750, 200 "Multiplayer - Connect" * Button 230, 275, 159, 25 "Go Back" * Label 230, 230, 700, 45 "Connect to a multiplayer server via IP and Port, specify a password if the server has a password set." * Input 230, 310, 159, 25 "IP Address" * Input 399, 310, 159, 25 "Port" * Input 230, 345, 159, 25 "Password" * Button 588, 310, 159, 25 "Connect" **/ GUIWindow connectWindow = WindowManager.SpawnWindow(); connectWindow.SetTitle("MultiplayerButtonConnect".LocDef("Multiplayer - Connect")); connectWindow.ShowCentered = true; connectWindow.MinSize = new Vector2(750, 200); connectWindow.SizeButton.SetActive(false); Utils.Controls.Element.UIButton goBackButton = new Utils.Controls.Element.UIButton("GoBackButton".LocDef("Go Back"), new Rect(30, 75, 159, 25), () => { connectWindow.gameObject.SetActive(false); MPWindow.gameObject.SetActive(true); }, connectWindow.MainPanel, "GoBackButton", "GoBackTooltip".LocDef("Go back to the main multiplayer window.")); new Utils.Controls.Element.UILabel( "ConnectLabel".LocDef("Connect to a multiplayer server via IP and Port, specify a password if the server has a password set."), new Rect(30, 30, 700, 45), connectWindow.MainPanel); Utils.Controls.Element.UITextbox IpTextBox = new Utils.Controls.Element.UITextbox(new Rect(30, 110, 159, 25), connectWindow.MainPanel, "IP", "", null, 12); Utils.Controls.Element.UITextbox PortTextBox = new Utils.Controls.Element.UITextbox(new Rect(35 + 159, 110, 159, 25), connectWindow.MainPanel, "PortInput".LocDef("Port"), "", null, 12); Utils.Controls.Element.UITextbox PasswordTextBox = new Utils.Controls.Element.UITextbox(new Rect(30, 145, 159, 25), connectWindow.MainPanel, "PasswordInput".LocDef("Password"), "", null, 12, true); new Utils.Controls.Element.UIButton("ConnectButtonText".LocDef("Connect"), new Rect(488, 110, 159, 25), () => { if (String.IsNullOrWhiteSpace(IpTextBox.obj.text)) { WindowManager.SpawnDialog("NoIPText".LocDef("Please enter a IP into the text box labeled \"Server IP\""), true, DialogWindow.DialogType.Error); return; } else if (String.IsNullOrWhiteSpace(PortTextBox.obj.text)) { WindowManager.SpawnDialog("NoPortText".LocDef("Please enter a Port into the text box labeled \"Server Port\""), true, DialogWindow.DialogType.Error); return; } else { if (Client.Connected) { // If user is already connected to a server. GameObject diagObj = UnityEngine.Object.Instantiate(WindowManager.Instance.DialogPrefab); diagObj.transform.SetParent(WindowManager.Instance.Canvas.transform, worldPositionStays: false); DialogWindow diag = gameObject.GetComponent <DialogWindow>(); KeyValuePair <string, Action>[] actions = new KeyValuePair <string, Action>[] { new KeyValuePair <string, Action>("DisconnnectButton".LocDef("Disconnect"), delegate { Client.Disconnect(); }), new KeyValuePair <string, Action>("CancelButton".LocDef("Cancel"), delegate { diag.Window.Close(); return; }), }; diag.Show("AlreadyConnectedToServer".LocDef("You are already connected to a server, would you like to disconnect?"), !true, DialogWindow.DialogType.Warning, actions); } try { Client.Connect(IpTextBox.obj.text, ushort.Parse(PortTextBox.obj.text)); WindowManager.SpawnDialog("SuccessfullyConnected".LocDef("Successfully connected to the server!"), true, DialogWindow.DialogType.Error); } catch (Exception e) { WindowManager.SpawnDialog($"There was an error trying to connect to {IpTextBox.obj.text}:{PortTextBox.obj.text}, see console for error.", true, DialogWindow.DialogType.Error); Logging.Error(e); return; } } }, connectWindow.MainPanel); #region Window Show management. connectWindow.Show(); #endregion #endregion }, MPWindow.MainPanel); new Utils.Controls.Element.UIButton("ServerButtonText".LocDef("Create Server"), new Rect(199, 30, 159, 25), () => { #region Create Server Window MPWindow.gameObject.SetActive(false); GUIWindow connectWindow = WindowManager.SpawnWindow(); connectWindow.SetTitle("MultiplayerButtonSS".LocDef("Multiplayer - Create Server")); connectWindow.ShowCentered = true; connectWindow.MinSize = new Vector2(750, 200); connectWindow.SizeButton.SetActive(false); Utils.Controls.Element.UIButton goBackButton = new Utils.Controls.Element.UIButton("GoBackButton".LocDef("Go Back"), new Rect(30, 75, 159, 25), () => { connectWindow.gameObject.SetActive(false); MPWindow.gameObject.SetActive(true); }, connectWindow.MainPanel, "GoBackButton", "GoBackTooltip".LocDef("Go back to the main multiplayer window.")); new Utils.Controls.Element.UILabel( "CreateLabel".LocDef("Create a multiplayer server on the specified port, leave password blank to disable password verification."), new Rect(30, 30, 700, 45), connectWindow.MainPanel); Utils.Controls.Element.UITextbox PortTextBox = new Utils.Controls.Element.UITextbox(new Rect(30, 110, 159, 25), connectWindow.MainPanel, "PortInput".LocDef("Port"), "", null, 12); Utils.Controls.Element.UITextbox PasswordTextBox = new Utils.Controls.Element.UITextbox(new Rect(35 + 159, 110, 159, 25), connectWindow.MainPanel, "PasswordInput".LocDef("Password"), "", null, 12, true); Utils.Controls.Element.UIButton ConnectButton = new Utils.Controls.Element.UIButton("StartButtonText".LocDef("Start"), new Rect(488, 110, 159, 25), () => { DialogWindow dia2g = WindowManager.SpawnDialog(); if (string.IsNullOrWhiteSpace(PortTextBox.obj.text) || !ushort.TryParse(PortTextBox.obj.text, out ushort nedfro)) { WindowManager.SpawnDialog("NoPortText".LocDef("Please enter a valid Port into the text box labeled \"Port\""), true, DialogWindow.DialogType.Error); return; } else { KeyValuePair <string, Action>[] action2s = new KeyValuePair <string, Action>[] { new KeyValuePair <string, Action>("Yes".LocDef("Yes"), delegate { if (Client.Connected) { Client.Disconnect(); } dia2g.Window.Close(); try { Client.Connect("127.0.0.1", ushort.Parse(PortTextBox.obj.text)); } catch (Exception e) { WindowManager.SpawnDialog($"There was an error trying to connect to the server. See console for error.", true, DialogWindow.DialogType.Error); Logging.Error(e); return; } WindowManager.SpawnDialog("SuccessfullyCreated".LocDef("Successfully created server!"), true, DialogWindow.DialogType.Information); }), new KeyValuePair <string, Action>("No".LocDef("No"), delegate { dia2g.Window.Close(); }), }; if (Client.Connected) { Client.Disconnect(); } if (Networking.Server.isRunning) { // If user is already connected to a server. DialogWindow diag = WindowManager.SpawnDialog(); KeyValuePair <string, Action>[] actions = new KeyValuePair <string, Action>[] { new KeyValuePair <string, Action>("StopButtonText".LocDef("Stop Server"), delegate { Networking.Server.Stop(); diag.Window.Close(); try { Networking.Server.Start(ushort.Parse(PortTextBox.obj.text)); } catch (Exception e) { WindowManager.SpawnDialog($"There was an error trying to create a server at port {PortTextBox.obj.text}, see console for error.", true, DialogWindow.DialogType.Error); Logging.Error(e); return; } dia2g.Show("LikeToConnect".LocDef("Would you like to connect to the server you have created?"), !true, DialogWindow.DialogType.Question, action2s); }), new KeyValuePair <string, Action>("CancelButton".LocDef("Cancel"), delegate { diag.Window.Close(); }), }; diag.Show("AlreadyServer".LocDef("You already have a server started, would you like to stop it?"), !true, DialogWindow.DialogType.Warning, actions); return; } Networking.Server.Start(ushort.Parse(PortTextBox.obj.text)); dia2g.Show("LikeToConnect".LocDef("Would you like to connect to the server you have created?"), !true, DialogWindow.DialogType.Question, action2s); } connectWindow.gameObject.SetActive(false); }, connectWindow.MainPanel); connectWindow.Show(); #endregion }, MPWindow.MainPanel); new Utils.Controls.Element.UIButton("GameplayButtonText".LocDef("Gameplay"), new Rect(369, 30, 159, 25), () => { WindowManager.SpawnDialog("ComingSoon".LocDef("Coming soon!"), true, DialogWindow.DialogType.Error); }, MPWindow.MainPanel); Client.chatWindow = WindowManager.SpawnLabel(); Client.chatWindow.text = "NoMessages".LocDef("Its pretty quiet in here, seems to be no sign of chat messages anywhere!"); MPWindow.AddElement(Client.chatWindow.gameObject, new Rect(30, 75, 670, 255), Rect.zero); Utils.Controls.Element.UITextbox chatBox = new Utils.Controls.Element.UITextbox(new Rect(30, 390, 471, 45), MPWindow.MainPanel, "TypeToChat".LocDef("Type here to chat..."), "chatBox", null, 15, false); Utils.Controls.Element.UIButton sendButton = new Utils.Controls.Element.UIButton("Send", new Rect(541, 390, 159, 45), () => { if (!Client.Connected) { WindowManager.SpawnDialog("NotConnectedToServer".LocDef("You aren't connected to a server!"), true, DialogWindow.DialogType.Error); return; } var tmpUser = new Helpers.User(); tmpUser.Username = Client.Username; Helpers.TcpChat chatClass = new Helpers.TcpChat(chatBox.obj.text, tmpUser); chatBox.obj.text = ""; Client.Send(chatClass); }, MPWindow.MainPanel); MPWindow.Show(); }
public void Show() { mainWindow.Show(); }