Esempio n. 1
0
        public static void CreateMultiplayer()
        {
            WObject mainPanel = MultiPanel = new WObject("Multi UI Panel")
            {
                Parent = MenuWobject
            };
            Image mainPanelImg = mainPanel.AddModule <Image>();

            mainPanelImg.Color     = new Color256(1.0, 0.0, 1.0, 0.0);
            mainPanelImg.MinAnchor = new Vector2F(0.225F, 0.10F);
            mainPanelImg.MaxAnchor = new Vector2F(0.775F, 0.95F);
            mainPanelImg.MinSize   = new Vector3F(400.0F, 400.0F, Single.PositiveInfinity);
            mainPanelImg.MaxSize   = new Vector3F(800.0F, 800.0F, Single.PositiveInfinity);
            mainPanelImg.KeepRatio = true;

            WObject btnPanel = new WObject("Main UI Button Panel")
            {
                Parent = mainPanel
            };
            Image btnPanelImg = btnPanel.AddModule <Image>();

            btnPanelImg.Color     = new Color256(1.0, 0.0, 1.0, 0.0);
            btnPanelImg.MinAnchor = new Vector2F(0.075F, 0.0F);
            btnPanelImg.MaxAnchor = new Vector2F(0.925F, 0.6F);

            WObject multiTitle = new WObject("Multi Main Label")
            {
                Parent = btnPanel
            };
            LocalizedLabel mainLb = multiTitle.AddModule <LocalizedLabel>();

            mainLb.Localization = "#winecrash:ui.mutliplayer.title";
            mainLb.MinAnchor    = new Vector2F(0.0F, 1.0F);
            mainLb.MaxAnchor    = new Vector2F(1.0F, 1.1F);
            mainLb.AutoSize     = true;
            mainLb.Aligns       = TextAligns.Middle;

            WObject error = new WObject("Multi Error Label")
            {
                Parent = btnPanel
            };
            LocalizedLabel errLb = MultiErrorLabel = error.AddModule <LocalizedLabel>();

            errLb.Localization = "#winecrash:error";
            errLb.MinAnchor    = new Vector2F(0.0F, 0.82F);
            errLb.MaxAnchor    = new Vector2F(1.0F, 0.88F);
            errLb.AutoSize     = true;
            errLb.Color        = Color256.Red;
            errLb.Enabled      = false;

            WObject addressTif = new WObject("Multi Address Input")
            {
                Parent = btnPanel
            };

            GUI.LargeTextField taddress = addressTif.AddModule <LargeTextField>();
            taddress.MinAnchor    = new Vector2F(0.0F, 0.7F);
            taddress.MaxAnchor    = new Vector2F(1.0F, 0.8F);
            taddress.Localization = "#winecrash:ui.multiplayer.address";
            taddress.Text         = Game.LastAddress;


            WObject back = new WObject("Multi Back")
            {
                Parent = btnPanel
            };

            GUI.SmallButton btnBack = back.AddModule <GUI.SmallButton>();
            btnBack.Button.MinAnchor   = new Vector2F(0.0F, 0.5F);
            btnBack.Button.MaxAnchor   = new Vector2F(0.45F, 0.6F);
            btnBack.Label.Localization = "#winecrash:ui.back";
            btnBack.Button.OnClick    += () =>
            {
                HideMulti();
                ShowMain();
            };

            WObject connect = new WObject("Multi Connect")
            {
                Parent = btnPanel
            };

            GUI.SmallButton btnConnect = connect.AddModule <GUI.SmallButton>();
            btnConnect.Button.MinAnchor   = new Vector2F(0.55F, 0.5F);
            btnConnect.Button.MaxAnchor   = new Vector2F(1.0F, 0.6F);
            btnConnect.Label.Localization = "#winecrash:ui.multiplayer.connect";

            void ShowConnectError(string reason)
            {
                errLb.LocalizationArgs = new[] { reason };
                errLb.Localization     = "#winecrash:error";
                errLb.Enabled          = true;
            }

            btnConnect.Button.OnClick += () =>
            {
                Task.Run(() =>
                {
                    errLb.LocalizationArgs = null;
                    errLb.Enabled          = false;

                    string address = "localhost";
                    int port       = Networking.DefaultPort;

                    string input     = taddress.Text;
                    Game.LastAddress = input;

                    if (string.IsNullOrEmpty(input) | string.IsNullOrWhiteSpace(input))
                    {
                        ShowConnectError(Game.Language.GetText("#winecrash:error.noaddress"));
                        return;
                    }

                    int separatorPos = input.IndexOf(':');
                    if (separatorPos > 0) // custom port
                    {
                        address = input.Substring(0, separatorPos);

                        if (int.TryParse(input.Substring(separatorPos + 1, input.Length - 1 - separatorPos), out port))
                        {
                            if (port < 0 || port > Networking.MaxPort)
                            {
                                ShowConnectError(Game.Language.GetText("#winecrash:error.invalidport"));
                                return;
                            }
                        }
                        else
                        {
                            ShowConnectError(Game.Language.GetText("#winecrash:error.invalidport"));
                            return;
                        }
                    }
                    else
                    {
                        address = input;
                    }

                    btnConnect.Button.Locked      = true;
                    btnBack.Button.Locked         = true;
                    taddress.Locked               = true;
                    btnConnect.Label.Localization = "#winecrash:ui.multiplayer.connecting";

                    try
                    {
                        Program.Client.Connect(address, port);
                        Game.InvokePartyJoined(PartyType.Multiplayer);
                        MainMenu.Hide();
                    }
                    catch (SocketException e)
                    {
                        switch (e.SocketErrorCode)
                        {
                        case SocketError.HostNotFound:
                            ShowConnectError(Game.Language.GetText("#winecrash:error.socket.hostnotfound"));
                            break;

                        case SocketError.ConnectionRefused:
                            ShowConnectError(Game.Language.GetText("#winecrash:error.socket.connectionrefused"));
                            break;

                        case SocketError.TryAgain:
                            ShowConnectError(Game.Language.GetText(("#winecrash:error.socket.tryagain")));
                            break;

                        default:
                            ShowConnectError(e.Message);
                            break;
                        }
                    }
                    finally
                    {
                        btnConnect.Button.Locked      = false;
                        btnBack.Button.Locked         = false;
                        taddress.Locked               = false;
                        btnConnect.Label.Localization = "#winecrash:ui.multiplayer.connect";
                    }
                });
            };
        }
Esempio n. 2
0
        private static void CreateMain()
        {
            WObject mainPanel = MainMenuPanel = new WObject("Main UI Panel")
            {
                Parent = MenuWobject
            };
            Image mainPanelImg = mainPanel.AddModule <Image>();

            mainPanelImg.Color     = new Color256(1.0, 0.0, 1.0, 0.0);
            mainPanelImg.MinAnchor = new Vector2F(0.225F, 0.10F);
            mainPanelImg.MaxAnchor = new Vector2F(0.775F, 0.95F);
            mainPanelImg.MinSize   = new Vector3F(400.0F, 400.0F, Single.PositiveInfinity);
            mainPanelImg.MaxSize   = new Vector3F(800.0F, 800.0F, Single.PositiveInfinity);
            mainPanelImg.KeepRatio = true;

            WObject logo = new WObject("Game Text Logo")
            {
                Parent = mainPanel
            };
            Image logoImage = logo.AddModule <Image>();

            logoImage.Picture   = new Texture("assets/textures/logo.png");
            logoImage.MinAnchor = new Vector2F(0.0F, 0.8F);
            logoImage.MaxAnchor = new Vector2F(1.0F, 1.0F);
            logoImage.KeepRatio = true;

            Label lbTip = mainPanel.AddModule <Label>();

            lbTip.ParentGUI = logoImage;
            lbTip.Text      = "Minecraft";
            lbTip.Color     = new Color256(1.0, 1.0, 0.0, 1.0);
            lbTip.Aligns    = TextAligns.Middle;
            lbTip.AutoSize  = true;
            lbTip.MinAnchor = new Vector2F(0.7F, 0.0F);
            lbTip.MaxAnchor = new Vector2F(1.1F, 0.4F);
            lbTip.Rotation  = -20.0D;


            MenuTip tip = MenuWobject.AddModule <MenuTip>();

            tip.ReferenceLabel = lbTip;
            lbTip.Text         = tip.SelectRandom();


            WObject btnPanel = new WObject("Main UI Button Panel")
            {
                Parent = mainPanel
            };
            Image btnPanelImg = btnPanel.AddModule <Image>();

            btnPanelImg.Color     = new Color256(1.0, 0.0, 1.0, 0.0);
            btnPanelImg.MinAnchor = new Vector2F(0.075F, 0.0F);
            btnPanelImg.MaxAnchor = new Vector2F(0.925F, 0.6F);

            WObject single = new WObject("Singleplayer Button")
            {
                Parent = btnPanel
            };

            GUI.LargeButton btnSingle = single.AddModule <GUI.LargeButton>();
            btnSingle.Button.MinAnchor   = new Vector2F(0.0F, 0.9F);
            btnSingle.Button.MaxAnchor   = new Vector2F(1.0F, 1.0F);
            btnSingle.Label.Localization = "#winecrash:ui.mainmenu.singleplayer";
            btnSingle.Button.Locked      = false;
            //btnSingle.Button.OnClick += () => { Graphics.Window.InvokeUpdate(() => Program.RunGameDebug()); };
            btnSingle.Button.OnClick += () =>
            {
                Game.InvokePartyJoined(PartyType.Singleplayer);
                Task.Run(() =>
                {
                    //Parallel.ForEach()
                    //IntegratedServer server = IntegratedServer.CurrentIntegratedServer = new IntegratedServer(new Player("Arthur"));
                    //server.Run();
                });
            };

            WObject mult = new WObject("Multiplayer Button")
            {
                Parent = btnPanel
            };

            GUI.LargeButton btnMult = mult.AddModule <GUI.LargeButton>();
            btnMult.Button.MinAnchor   = new Vector2F(0.0F, 0.7F);
            btnMult.Button.MaxAnchor   = new Vector2F(1.0F, 0.8F);
            btnMult.Label.Localization = "#winecrash:ui.mainmenu.multiplayer";
            btnMult.Button.Locked      = true;
            btnMult.Button.OnClick    += () =>
            {
                ShowMulti();
            };

            WObject mods = new WObject("Mods Button")
            {
                Parent = btnPanel
            };

            GUI.LargeButton btnMods = mods.AddModule <GUI.LargeButton>();
            btnMods.Button.MinAnchor   = new Vector2F(0.0F, 0.5F);
            btnMods.Button.MaxAnchor   = new Vector2F(1.0F, 0.6F);
            btnMods.Label.Localization = "#winecrash:ui.mainmenu.addons";
            btnMods.Button.Locked      = true;

            WObject options = new WObject("Options Button")
            {
                Parent = btnPanel
            };

            GUI.SmallButton btnOptions = options.AddModule <GUI.SmallButton>();
            btnOptions.Button.MinAnchor   = new Vector2F(0.0F, 0.2F);
            btnOptions.Button.MaxAnchor   = new Vector2F(0.45F, 0.3F);
            btnOptions.Label.Localization = "#winecrash:ui.mainmenu.settings";
            btnOptions.Button.OnClick    += () => ShowOptions();
            btnOptions.Button.Locked      = false;

            WObject quit = new WObject("Quit Button")
            {
                Parent = btnPanel
            };

            GUI.SmallButton btnQuit = quit.AddModule <GUI.SmallButton>();
            btnQuit.Button.MinAnchor   = new Vector2F(0.55F, 0.2F);
            btnQuit.Button.MaxAnchor   = new Vector2F(1.0F, 0.3F);
            btnQuit.Label.Localization = "#winecrash:ui.mainmenu.quit";
            btnQuit.Button.OnClick    += () => Engine.Stop();
        }
Esempio n. 3
0
        public static void CreateOptions()
        {
            WObject panel = OptionPanel = new WObject("Main Menu Options")
            {
                Parent = MenuWobject
            };

            /*Image bgFullScreen = OptionPanel.AddModule<Image>();
             * bgFullScreen.Color = Color256.DarkGray * new Color256(1.0, 1.0, 1.0, 0.75);*/

            Image mainPanel = panel.AddModule <Image>();

            mainPanel.Color     = Color256.White * 0.0;//new Color256(1.0, 1.0, 1.0, 0.4);
            mainPanel.MinAnchor = new Vector2D(0.2, 0.05D);
            mainPanel.MaxAnchor = new Vector2D(0.8, 0.95D);
            mainPanel.MinSize   = new Vector3D(800.0D, 400.0D, double.NegativeInfinity);


            WObject tabsPanelWobj = new WObject("Options tab panel")
            {
                Parent = panel
            };
            Image tabsPanel = tabsPanelWobj.AddModule <Image>();

            tabsPanel.MinAnchor = new Vector2D(0.0, 0.85);
            tabsPanel.MaxAnchor = new Vector2D(1.0, 1.0);
            tabsPanel.Color     = new Color256(1.0, 1.0, 1.0, .0);

            WObject backOptions = new WObject("Back Options Button")
            {
                Parent = tabsPanelWobj
            };

            GUI.TinyButton btnBack = backOptions.AddModule <GUI.TinyButton>();
            btnBack.Button.MinAnchor  = new Vector2D(0.0, 0.0);
            btnBack.Button.MaxAnchor  = new Vector2D(0.06, 1.0);
            btnBack.Button.Label.Text = "<";
            btnBack.Button.OnClick   += () => ShowMain();

            WObject gameOptions = new WObject("Game Options Panel")
            {
                Parent = panel
            };
            Image gameOptionsPanel = gameOptions.AddModule <Image>();

            gameOptionsPanel.MinAnchor = new Vector2D(0.0, 0.0);
            gameOptionsPanel.MaxAnchor = new Vector2D(1.0, 0.85);
            gameOptionsPanel.Color     = Color256.White;

            WObject gameOptionsTab = new WObject("Game Options Button")
            {
                Parent = tabsPanelWobj
            };

            GUI.SmallButton btnGame = gameOptionsTab.AddModule <GUI.SmallButton>();
            btnGame.Button.MinAnchor  = new Vector2D(WMath.Remap(0.00, 0.0, 1.0, 0.1, 1.0), 0.0);
            btnGame.Button.MaxAnchor  = new Vector2D(WMath.Remap(0.30, 0.0, 1.0, 0.1, 1.0), 1.0);
            btnGame.Button.Label.Text = "#winecrash:ui.settings.game";
            btnGame.Button.OnClick   += () =>
            {
                gameOptions.Enabled = true;
            };



            WObject controlsOptionsTab = new WObject("Controls Options Button")
            {
                Parent = tabsPanelWobj
            };

            GUI.SmallButton btnCtrls = controlsOptionsTab.AddModule <GUI.SmallButton>();
            btnCtrls.Button.MinAnchor  = new Vector2D(WMath.Remap(0.35, 0.0, 1.0, 0.1, 1.0), 0.0);
            btnCtrls.Button.MaxAnchor  = new Vector2D(WMath.Remap(0.65, 0.0, 1.0, 0.1, 1.0), 1.0);
            btnCtrls.Button.Label.Text = "#winecrash:ui.settings.inputs";

            WObject videoOptionsTab = new WObject("Controls Options Button")
            {
                Parent = tabsPanelWobj
            };

            GUI.SmallButton btnVideo = videoOptionsTab.AddModule <GUI.SmallButton>();
            btnVideo.Button.MinAnchor  = new Vector2D(WMath.Remap(0.70, 0.0, 1.0, 0.1, 1.0), 0.0);
            btnVideo.Button.MaxAnchor  = new Vector2D(WMath.Remap(1.00, 0.0, 1.0, 0.1, 1.0), 1.0);
            btnVideo.Button.Label.Text = "#winecrash:ui.settings.video";
        }