コード例 #1
0
        public MultiplayerServerSelectionState(GuiPanoramaSkyBox skyBox) : base()
        {
            _skyBox = skyBox;
            CancellationTokenSource = new CancellationTokenSource();

            _listProvider = GetService <IListStorageProvider <SavedServerEntry> >();

            Title = "Multiplayer";
            TitleTranslationKey = "multiplayer.title";

            Footer.AddRow(row =>
            {
                row.AddChild(JoinServerButton = new GuiButton("Join Server",
                                                              OnJoinServerButtonPressed)
                {
                    TranslationKey = "selectServer.select",
                    Enabled        = false
                });
                row.AddChild(DirectConnectButton = new GuiButton("Direct Connect",
                                                                 () => Alex.GameStateManager.SetActiveState <MultiplayerConnectState>())
                {
                    TranslationKey = "selectServer.direct",
                    Enabled        = false
                });
                row.AddChild(AddServerButton = new GuiButton("Add Server",
                                                             OnAddItemButtonPressed)
                {
                    TranslationKey = "selectServer.add"
                });
            });
            Footer.AddRow(row =>
            {
                row.AddChild(EditServerButton = new GuiButton("Edit", OnEditItemButtonPressed)
                {
                    TranslationKey = "selectServer.edit",
                    Enabled        = false
                });
                row.AddChild(DeleteServerButton = new GuiButton("Delete", OnDeleteItemButtonPressed)
                {
                    TranslationKey = "selectServer.delete",
                    Enabled        = false
                });
                row.AddChild(new GuiButton("Refresh", OnRefreshButtonPressed)
                {
                    TranslationKey = "selectServer.refresh"
                });
                row.AddChild(new GuiBackButton()
                {
                    TranslationKey = "gui.cancel"
                });
            });

            Background = new GuiTexture2D(_skyBox, TextureRepeatMode.Stretch);
        }
コード例 #2
0
        public MultiplayerAddEditServerState(ServerType serverType, string name, string address,
                                             Action <SavedServerEntry> callbackAction,
                                             GuiPanoramaSkyBox skyBox) :
            base(callbackAction)
        {
            _savedServersStorage = GetService <IListStorageProvider <SavedServerEntry> >();
            _skyBox = skyBox;

            Title = "Add Server";
            TitleTranslationKey = "addServer.title";

            base.HeaderTitle.Anchor    = Alignment.MiddleCenter;
            base.HeaderTitle.FontStyle = FontStyle.Bold | FontStyle.DropShadow;
            Body.BackgroundOverlay     = new Color(Color.Black, 0.5f);

            Body.ChildAnchor = Alignment.MiddleCenter;

            var usernameRow = AddGuiRow(new GuiTextElement()
            {
                Text           = "Server Name:",
                TranslationKey = "addServer.enterName",
                Margin         = new Thickness(0, 0, 5, 0)
            }, _nameInput = new GuiTextInput()
            {
                TabIndex = 1,

                Width = 200,

                PlaceHolder = "Name of the server",
                Margin      = new Thickness(23, 5, 5, 5),
            });

            usernameRow.ChildAnchor = Alignment.MiddleCenter;
            usernameRow.Orientation = Orientation.Horizontal;

            var hostnameRow = AddGuiRow(new GuiTextElement()
            {
                Text           = "Server Address:",
                TranslationKey = "addServer.enterIp",
                Margin         = new Thickness(0, 0, 5, 0)
            }, _hostnameInput = new GuiTextInput()
            {
                TabIndex = 2,

                Width = 200,

                PlaceHolder = "Hostname or IP",
                Margin      = new Thickness(5),
            });

            hostnameRow.ChildAnchor = Alignment.MiddleCenter;
            hostnameRow.Orientation = Orientation.Horizontal;

            var typeLabelRow = AddGuiRow(_serverTypeLabel = new GuiTextElement()
            {
                Text   = "Server Type:",
                Margin = new Thickness(0, 0, 5, 0)
            });

            typeLabelRow.ChildAnchor = Alignment.MiddleCenter;
            typeLabelRow.Orientation = Orientation.Horizontal;

            AddGuiRow(_serverTypeGroup = new GuiButtonGroup()
            {
                Orientation = Orientation.Horizontal,
                ChildAnchor = Alignment.MiddleCenter
            });
            _serverTypeGroup.AddChild(_javaEditionButton = new GuiToggleButton("Java")
            {
                Margin  = new Thickness(5),
                Modern  = true,
                Width   = 50,
                Checked = serverType == ServerType.Java,
                CheckedOutlineThickness = new Thickness(1),
                DisplayFormat           = new ValueFormatter <bool>((val) => $"Java {(val ? "[Active]" : "")}"),
                TabIndex = 3
            });
            _serverTypeGroup.AddChild(_bedrockEditionButton = new GuiToggleButton("Bedrock")
            {
                Margin  = new Thickness(5),
                Modern  = true,
                Width   = 50,
                Checked = serverType == ServerType.Bedrock,
                CheckedOutlineThickness = new Thickness(1),
                DisplayFormat           = new ValueFormatter <bool>((val) => $"Bedrock {(val ? "[Active]" : "")}"),
                TabIndex = 4
            });

            //	var portRow = AddGuiRow();
            //  portRow.ChildAnchor = Alignment.MiddleCenter;

            var buttonRow = AddGuiRow(_saveButton = new GuiButton(OnSaveButtonPressed)
            {
                AccessKey = Keys.Enter,

                TranslationKey = "addServer.add",
                Margin         = new Thickness(5),
                Modern         = false,
                Width          = 100,
                TabIndex       = 5
            }, new GuiButton(OnCancelButtonPressed)
            {
                AccessKey = Keys.Escape,

                TranslationKey = "gui.cancel",
                Margin         = new Thickness(5),
                Modern         = false,
                Width          = 100,
                TabIndex       = 6
            });

            buttonRow.ChildAnchor = Alignment.MiddleCenter;


            AddGuiElement(_errorMessage = new GuiTextElement()
            {
                TextColor = TextColor.Red
            });

            if (!string.IsNullOrWhiteSpace(name))
            {
                _nameInput.Value = name;
            }

            if (!string.IsNullOrWhiteSpace(address))
            {
                _hostnameInput.Value = address;
            }

            if (_entry != null)
            {
                //EnableButtonsFor(_entry.ServerType);
            }

            Background = new GuiTexture2D(_skyBox, TextureRepeatMode.Stretch);
        }