<commit_before>﻿using Facepunch.Steamworks;
using PlayGroup;
using UnityEngine;
using UnityEngine.UI;


namespace UI
{
    public class GUI_LobbyDialogue : MonoBehaviour
    {

        private const string DefaultServer = "localhost";
        private const int DefaultPort = 7777;
        private const string UserNamePlayerPref = "PlayerName";

        public GameObject startGamePanel;
        public GameObject informationPanel;
        public GameObject wrongVersionPanel;

        public InputField playerNameInput;
        public InputField serverAddressInput;
        public InputField serverPortInput;
        public Text dialogueTitle;
        public Toggle hostServerToggle;

        private CustomNetworkManager networkManager;

        // Lifecycle
        void Start()
        {
            networkManager = CustomNetworkManager.Instance;

            // OnChange handler for toggle to 
            // disable server address and port
            // input fields
            hostServerToggle.onValueChanged.AddListener(isOn =>
                {
                    serverAddressInput.interactable = !isOn;
                    serverPortInput.interactable = !isOn;
                }
            );

            InitPlayerName();
            ShowStartGamePanel();
        }

        // Button handlers
        public void OnStartGame()
        {
            SoundManager.Play("Click01");

            // Return if no player name or incorrect screen
            if (string.IsNullOrEmpty(playerNameInput.text.Trim()))
            {
                return;
            }
            if (!startGamePanel.activeInHierarchy)
            {
                return;
            }

            // Return if no network address is specified
            if (string.IsNullOrEmpty(serverAddressInput.text))
            {
                return;
            }

            // Set and cache player name
            PlayerPrefs.SetString(UserNamePlayerPref, playerNameInput.text);
            PlayerManager.PlayerNameCache = playerNameInput.text;

            // Start game
            dialogueTitle.text = "Starting Game...";
            if (Managers.instance.isForRelease || !hostServerToggle.isOn)
            {
                ConnectToServer();
            }
            else
            {
                networkManager.StartHost();
            }

            // Hide dialogue and show status text
            gameObject.SetActive(false);
            UIManager.Chat.CurrentChannelText.text = "<color=green>Loading game please wait..</color>\r\n";
        }

        public void OnShowInformationPanel()
        {
            SoundManager.Play("Click01");
            ShowInformationPanel();
        }

        public void OnTryAgain()
        {
            SoundManager.Play("Click01");
            ShowStartGamePanel();
        }

        public void OnReturnToPlayerLogin()
        {
            SoundManager.Play("Click01");
            ShowStartGamePanel();
        }

        // Game handlers
        void ConnectToServer()
        {
            if (Managers.instance.isForRelease)
            {
                networkManager.networkAddress = Managers.instance.serverIP;
                networkManager.networkPort = DefaultPort;
                networkManager.StartClient();
                return;
            }

            // Set network address
            networkManager.networkAddress = serverAddressInput.text;

            // Set network port
            int port = 0;
            if (serverPortInput.text.Length >= 4)
            {
                int.TryParse(serverPortInput.text, out port);
            }
            if (port == 0)
            {
                networkManager.networkPort = DefaultPort;
            }<commit_msg>Renamed "DefaultPort" to "DefaultServerPort" in LobbyDialogue script for better clarity<commit_after>﻿using Facepunch.Steamworks;
using PlayGroup;
using UnityEngine;
using UnityEngine.UI;


namespace UI
{
    public class GUI_LobbyDialogue : MonoBehaviour
    {

        private const int DefaultServerPort = 7777;
        private const string UserNamePlayerPref = "PlayerName";

        public GameObject startGamePanel;
        public GameObject informationPanel;
        public GameObject wrongVersionPanel;

        public InputField playerNameInput;
        public InputField serverAddressInput;
        public InputField serverPortInput;
        public Text dialogueTitle;
        public Toggle hostServerToggle;

        private CustomNetworkManager networkManager;

        // Lifecycle
        void Start()
        {
            networkManager = CustomNetworkManager.Instance;

            // OnChange handler for toggle to 
            // disable server address and port
            // input fields
            hostServerToggle.onValueChanged.AddListener(isOn =>
                {
                    serverAddressInput.interactable = !isOn;
                    serverPortInput.interactable = !isOn;
                }
            );

            InitPlayerName();
            ShowStartGamePanel();
        }

        // Button handlers
        public void OnStartGame()
        {
            SoundManager.Play("Click01");

            // Return if no player name or incorrect screen
            if (string.IsNullOrEmpty(playerNameInput.text.Trim()))
            {
                return;
            }
            if (!startGamePanel.activeInHierarchy)
            {
                return;
            }

            // Return if no network address is specified
            if (string.IsNullOrEmpty(serverAddressInput.text))
            {
                return;
            }

            // Set and cache player name
            PlayerPrefs.SetString(UserNamePlayerPref, playerNameInput.text);
            PlayerManager.PlayerNameCache = playerNameInput.text;

            // Start game
            dialogueTitle.text = "Starting Game...";
            if (Managers.instance.isForRelease || !hostServerToggle.isOn)
            {
                ConnectToServer();
            }
            else
            {
                networkManager.StartHost();
            }

            // Hide dialogue and show status text
            gameObject.SetActive(false);
            UIManager.Chat.CurrentChannelText.text = "<color=green>Loading game please wait..</color>\r\n";
        }

        public void OnShowInformationPanel()
        {
            SoundManager.Play("Click01");
            ShowInformationPanel();
        }

        public void OnTryAgain()
        {
            SoundManager.Play("Click01");
            ShowStartGamePanel();
        }

        public void OnReturnToPlayerLogin()
        {
            SoundManager.Play("Click01");
            ShowStartGamePanel();
        }

        // Game handlers
        void ConnectToServer()
        {
            if (Managers.instance.isForRelease)
            {
                networkManager.networkAddress = Managers.instance.serverIP;
                networkManager.networkPort = DefaultServerPort;
                networkManager.StartClient();
                return;
            }

            // Set network address
            networkManager.networkAddress = serverAddressInput.text;

            // Set network port
            int port = 0;
            if (serverPortInput.text.Length >= 4)
            {
                int.TryParse(serverPortInput.text, out port);
            }
            if (port == 0)
            {
                networkManager.networkPort = DefaultServerPort;
            }
{'fraction_non_alphanumeric': 0.07283359914938863, 'fraction_numerical': 0.003987240829346092, 'mean_word_length': 1.5083333333333333, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1560787', 'n_tokens_mistral': 1792, 'n_tokens_neox': 1693, 'n_words': 386}