private void CreateConnectUi() { // Now we can start adding individual components to our UI // Keep track of current x and y of objects we want to place var x = 1920f - 210.0f; var y = 1080f - 75.0f; new TextComponent( _connectGroup, new Vector2(x, y), new Vector2(200, 30), "Multiplayer", FontManager.UIFontRegular, 24 ); y -= 30; new DividerComponent( _connectGroup, new Vector2(x, y), new Vector2(200, 1) ); y -= 30; new TextComponent( _connectGroup, new Vector2(x, y), new Vector2(200, 30), "Join Server", FontManager.UIFontRegular, 18 ); y -= 40; _addressInput = new HiddenInputComponent( _connectGroup, new Vector2(x, y), _modSettings.JoinAddress, "IP Address" ); y -= 40; var joinPort = _modSettings.JoinPort; _portInput = new InputComponent( _connectGroup, new Vector2(x, y), joinPort == -1 ? "" : joinPort.ToString(), "Port", characterValidation: InputField.CharacterValidation.Integer ); y -= 40; var username = _modSettings.Username; _usernameInput = new InputComponent( _connectGroup, new Vector2(x, y), username, "Username" ); y -= 40; var clientSettingsButton = new ButtonComponent( _connectGroup, new Vector2(x, y), "Settings" ); clientSettingsButton.SetOnPress(() => { _connectGroup.SetActive(false); _clientSettingsGroup.SetActive(true); }); y -= 40; _connectButton = new ButtonComponent( _connectGroup, new Vector2(x, y), "Connect" ); _connectButton.SetOnPress(OnConnectButtonPressed); _disconnectButton = new ButtonComponent( _connectGroup, new Vector2(x, y), "Disconnect" ); _disconnectButton.SetOnPress(OnDisconnectButtonPressed); _disconnectButton.SetActive(false); y -= 40; _clientFeedbackText = new TextComponent( _connectGroup, new Vector2(x, y), new Vector2(200, 30), "", FontManager.UIFontBold, 15 ); _clientFeedbackText.SetActive(false); y -= 30; new DividerComponent( _connectGroup, new Vector2(x, y), new Vector2(200, 1) ); y -= 30; new TextComponent( _connectGroup, new Vector2(x, y), new Vector2(200, 30), "Host Server", FontManager.UIFontRegular, 18 ); y -= 40; var serverSettingsButton = new ButtonComponent( _connectGroup, new Vector2(x, y), "Host Settings" ); serverSettingsButton.SetOnPress(() => { _connectGroup.SetActive(false); _serverSettingsGroup.SetActive(true); }); y -= 40; _startButton = new ButtonComponent( _connectGroup, new Vector2(x, y), "Start Hosting" ); _startButton.SetOnPress(OnStartButtonPressed); _stopButton = new ButtonComponent( _connectGroup, new Vector2(x, y), "Stop Hosting" ); _stopButton.SetOnPress(OnStopButtonPressed); _stopButton.SetActive(false); y -= 40; _serverFeedbackText = new TextComponent( _connectGroup, new Vector2(x, y), new Vector2(200, 30), "", FontManager.UIFontBold, 15 ); _serverFeedbackText.SetActive(false); // Register a callback for when the connection is successful or failed or disconnects _clientManager.RegisterOnDisconnect(OnClientDisconnect); _clientManager.RegisterOnConnect(OnSuccessfulConnect); _clientManager.RegisterOnConnectFailed(OnFailedConnect); }
private void CreateSettingsUI() { _settingsGroup.SetActive(false); const float pageYLimit = 250; var x = 1920f - 210.0f; var y = pageYLimit; const int boolMargin = 75; const int doubleBoolMargin = 100; const int intMargin = 100; const int doubleIntMargin = 125; var settingsUIEntries = new List <SettingsEntryInterface>(); var pages = new Dictionary <int, ComponentGroup>(); var currentPage = 0; ComponentGroup currentPageGroup = null; foreach (var settingsEntry in _settingsEntries) { if (y <= pageYLimit) { currentPage++; currentPageGroup = new ComponentGroup(currentPage == 1, _settingsGroup); pages.Add(currentPage, currentPageGroup); y = 1080f - 75.0f; } var nameChars = settingsEntry.Name.ToCharArray(); var font = FontManager.UIFontRegular; var nameWidth = 0; foreach (var nameChar in nameChars) { font.GetCharacterInfo(nameChar, out var characterInfo, 18); nameWidth += characterInfo.advance; } var doubleLine = nameWidth >= SettingsEntryInterface.TextWidth; settingsUIEntries.Add(new SettingsEntryInterface( currentPageGroup, new Vector2(x, y), settingsEntry.Name, settingsEntry.Type, settingsEntry.DefaultValue, settingsEntry.InitialValue, settingsEntry.ApplySetting, doubleLine )); if (doubleLine) { y -= settingsEntry.Type == typeof(bool) ? doubleBoolMargin : doubleIntMargin; } else { y -= settingsEntry.Type == typeof(bool) ? boolMargin : intMargin; } } y = pageYLimit - 80; var nextPageButton = new ButtonComponent( _settingsGroup, new Vector2(x, y), "Next page" ); nextPageButton.SetOnPress(() => { // Disable old current page pages[_currentPage].SetActive(false); // Increment page if we can if (_currentPage < pages.Count) { _currentPage++; } // Enable new current page pages[_currentPage].SetActive(true); }); y -= 40; var previousPageButton = new ButtonComponent( _settingsGroup, new Vector2(x, y), "Previous page" ); previousPageButton.SetOnPress(() => { // Disable old current page pages[_currentPage].SetActive(false); // Decrement page if we can if (_currentPage > 1) { _currentPage--; } // Enable new current page pages[_currentPage].SetActive(true); }); y -= 40; var saveSettingsButton = new ButtonComponent( _settingsGroup, new Vector2(x, y), "Save settings" ); saveSettingsButton.SetOnPress(() => { // TODO: check if there are actually changes, otherwise this button will // bombard clients with packets foreach (var settingsUIEntry in settingsUIEntries) { settingsUIEntry.ApplySetting(); } _modSettings.GameSettings = _gameSettings; _serverManager.OnUpdateGameSettings(); }); y -= 40; new ButtonComponent( _settingsGroup, new Vector2(x, y), "Back" ).SetOnPress(() => { _settingsGroup.SetActive(false); _connectGroup.SetActive(true); }); }
/// <summary> /// Create the connection UI. /// </summary> private void CreateConnectUi() { // Now we can start adding individual components to our UI // Keep track of current x and y of objects we want to place var x = 1920f - 210f; var y = 1080f - 100f; const float labelHeight = 20f; const float logoHeight = 74f; new ImageComponent( _connectGroup, new Vector2(x, y), new Vector2(240f, logoHeight), TextureManager.HkmpLogo ); y -= logoHeight / 2f + 20f; new TextComponent( _connectGroup, new Vector2(x + TextIndentWidth, y), new Vector2(212f, labelHeight), "Username", UiManager.NormalFontSize, alignment: TextAnchor.MiddleLeft ); y -= labelHeight + 14f; _usernameInput = new InputComponent( _connectGroup, new Vector2(x, y), _modSettings.Username, "Username", characterLimit: 20 ); y -= InputComponent.DefaultHeight + 20f; new TextComponent( _connectGroup, new Vector2(x + TextIndentWidth, y), new Vector2(212f, labelHeight), "Server IP and port", UiManager.NormalFontSize, alignment: TextAnchor.MiddleLeft ); y -= labelHeight + 14f; _addressInput = new IpInputComponent( _connectGroup, new Vector2(x, y), _modSettings.ConnectAddress, "IP Address" ); y -= InputComponent.DefaultHeight + 8f; var joinPort = _modSettings.ConnectPort; _portInput = new PortInputComponent( _connectGroup, new Vector2(x, y), joinPort == -1 ? "" : joinPort.ToString(), "Port" ); y -= InputComponent.DefaultHeight + 20f; _connectionButton = new ButtonComponent( _connectGroup, new Vector2(x, y), ConnectText ); _connectionButton.SetOnPress(OnConnectButtonPressed); y -= ButtonComponent.DefaultHeight + 8f; _serverButton = new ButtonComponent( _connectGroup, new Vector2(x, y), StartHostingText ); _serverButton.SetOnPress(OnStartButtonPressed); y -= ButtonComponent.DefaultHeight + 8f; var settingsButton = new ButtonComponent( _connectGroup, new Vector2(x, y), "Settings" ); settingsButton.SetOnPress(() => { _connectGroup.SetActive(false); _settingsGroup.SetActive(true); }); y -= ButtonComponent.DefaultHeight + 8f; _feedbackText = new TextComponent( _connectGroup, new Vector2(x, y), new Vector2(240f, labelHeight), new Vector2(0.5f, 1f), "", UiManager.SubTextFontSize, alignment: TextAnchor.UpperCenter ); _feedbackText.SetActive(false); }
public ClientSettingsInterface( ModSettings modSettings, Game.Settings.GameSettings clientGameSettings, ComponentGroup settingsGroup, ComponentGroup connectGroup, PingInterface pingInterface ) { settingsGroup.SetActive(false); _clientGameSettings = clientGameSettings; var x = 1920f - 210f; var y = 1080f - 100f; new TextComponent( settingsGroup, new Vector2(x, y), new Vector2(240f, ButtonComponent.DefaultHeight), "Settings", UiManager.HeaderFontSize, alignment: TextAnchor.MiddleLeft ); var closeButton = new ButtonComponent( settingsGroup, new Vector2(x + 240f / 2f - ButtonComponent.DefaultHeight / 2f, y), new Vector2(ButtonComponent.DefaultHeight, ButtonComponent.DefaultHeight), "", TextureManager.CloseButtonBg, FontManager.UIFontRegular, UiManager.NormalFontSize ); closeButton.SetOnPress(() => { settingsGroup.SetActive(false); connectGroup.SetActive(true); }); y -= ButtonComponent.DefaultHeight + 30f; var skinSetting = new SettingsEntryInterface( settingsGroup, new Vector2(x, y), "Player skin ID", typeof(byte), 0, 0, o => { OnSkinIdChange?.Invoke((byte)o); }, true ); skinSetting.SetInteractable(false); _skinCondition = new CompoundCondition( () => skinSetting.SetInteractable(true), () => skinSetting.SetInteractable(false), false, true ); y -= InputComponent.DefaultHeight + 8f; new SettingsEntryInterface( settingsGroup, new Vector2(x, y), "Display ping", typeof(bool), false, modSettings.DisplayPing, o => { var newValue = (bool)o; modSettings.DisplayPing = newValue; pingInterface.SetEnabled(newValue); }, true ); y -= SettingsEntryInterface.CheckboxSize + 8f; var teamRadioButton = new RadioButtonBoxComponent( settingsGroup, new Vector2(x, y), "Team selection", new[] { "None", "Moss", "Hive", "Grimm", "Lifeblood", }, 0 ); // Make it non-interactable by default teamRadioButton.SetInteractable(false); _teamCondition = new CompoundCondition( () => teamRadioButton.SetInteractable(true), () => { teamRadioButton.SetInteractable(false); teamRadioButton.Reset(); }, false, false, true ); teamRadioButton.SetOnChange(value => { if (!_clientGameSettings.TeamsEnabled) { return; } OnTeamRadioButtonChange?.Invoke((Team)value); }); }