Beispiel #1
0
        private bool Validate()
        {
            try
            {
                System.Net.IPAddress.Parse(Result);
            }
            catch
            {
                Disable();

                if (myMsg != null)
                {
                    Parent.RemoveChild(myMsg);
                }

                myMsg = new UIMessageBox("Not a valid IP Address", "Error", true)
                {
                    Size = new Vector2(192, 48)
                };
                Parent.AddChild(myMsg);
                myMsg.Centre();

                myMsg.Closed += delegate(object sender, EventArgs e2)
                {
                    myMsg = null;
                    Enable();
                };
                return(false);
            }

            return(true);
        }
Beispiel #2
0
        public LewtWindow(int width, int height)
            : base(width, height, GraphicsMode.Default, Res.Get <String>("game_window_title", "Lewt RPG"))
        {
            VSync = VSyncMode.Off;

            Res.MountArchive(Res.LoadArchive("Data" + System.IO.Path.DirectorySeparatorChar + "cl_lewtui.rsa"));

            SpriteRenderer.SetUp(width, height);

            Font font = Font.Large;

            myUIRoot = new UIObject(new Vector2(width, height));
#if DEBUG
            myFPSDisplay          = new UILabel(font, 1.0f);
            myFPSDisplay.Position = new Vector2(4, 4);
            myFPSDisplay.Colour   = Color4.White;
            AddChild(myFPSDisplay);

            myTimeDisplay          = new UILabel(font, 1.0f);
            myTimeDisplay.Position = new Vector2(4, 4 + font.CharHeight * 3);
            myTimeDisplay.Colour   = Color4.White;
            AddChild(myTimeDisplay);
#endif

            myChatBox = new UIChatBox(Width, new Vector2(0, Height - 28));
            AddChild(myChatBox);

            myMsgBox = new UIMessageBox("", "Loading", false)
            {
                Height     = 256,
                CentreText = false,
                IsVisible  = false
            };
            AddChild(myMsgBox);

            GameServer.ServerMessage += delegate(object sender3, ServerMessageEventArgs e3)
            {
                myMsgBox.Text += e3.Message.TrimEnd() + "\n";
            };
            GameClient.ClientMessageReceived += delegate(object sender3, ClientMessageEventArgs e3)
            {
                myMsgBox.Text += e3.Message.TrimEnd() + "\n";
            };

            myMainMenu = new UIMenu(new Vector2(256, 256))
            {
                Title    = "Lewt RPG " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version,
                CanClose = false
            };

            mySinglePlayerButton = myMainMenu.CreateButton("Single Player", delegate(object sender, MouseButtonEventArgs e)
            {
                myHostingLocal = true;

                myMainMenu.Hide();

                myMsgBox.Text = "Starting single player game, please wait...\n";
                myMsgBox.Show();
                myMsgBox.Focus();
                myMsgBox.Centre();

                GameClient.Nickname = "Local Player";

                Lewt.Shared.Networking.LocalClientServer.Reset();
                GameServer.SinglePlayerStart();
            });
            myMultiPlayerButton = myMainMenu.CreateButton("Multi Player", delegate(object sender, MouseButtonEventArgs e)
            {
                UIMenu multiMenu = new UIMenu(new Vector2(192, 256))
                {
                    Title    = "Multi Player Menu",
                    CanClose = false
                };
                AddChild(multiMenu);

                myMainMenu.Disable();

                multiMenu.CreateButton("Join", delegate(object sender2, MouseButtonEventArgs e2)
                {
                    multiMenu.Disable();

                    IPPrompt ipPrompt = new IPPrompt(delegate(String address, int port)
                    {
                        multiMenu.Close();
                        myMainMenu.Hide();

                        myMsgBox.Text = "Joining game, please wait...\n";
                        myMsgBox.Show();
                        myMsgBox.Focus();
                        myMsgBox.Centre();

                        GameClient.Nickname = "Player";
                        GameClient.Connect(address, port);
                    });
                    AddChild(ipPrompt);
                    ipPrompt.Centre();

                    ipPrompt.Closed += delegate(object sender3, EventArgs e3)
                    {
                        multiMenu.Enable();
                    };

                    ipPrompt.FocusOnInput();
                });
                multiMenu.CreateButton("Host LAN", delegate(object sender2, MouseButtonEventArgs e2)
                {
                    multiMenu.Disable();

                    HostPrompt hostPrompt = new HostPrompt(delegate(int maxPlayers, int port)
                    {
                        multiMenu.Close();
                        myMainMenu.Hide();

                        myHostingLocal = true;

                        myMsgBox.Text = "Hosting and joining game, please wait...\n";
                        myMsgBox.Show();
                        myMsgBox.Focus();
                        myMsgBox.Centre();

                        GameClient.Nickname = "Player";
                        Lewt.Shared.Networking.LocalClientServer.Reset();
                        GameServer.Start(maxPlayers, port, true);
                    })
                    {
                        Title = "Host LAN Game"
                    };
                    AddChild(hostPrompt);
                    hostPrompt.Centre();

                    hostPrompt.Closed += delegate(object sender3, EventArgs e3)
                    {
                        multiMenu.Enable();
                    };
                });
                multiMenu.CreateButton("Host Internet", delegate(object sender2, MouseButtonEventArgs e2)
                {
                    multiMenu.Disable();

                    HostPrompt hostPrompt = new HostPrompt(delegate(int maxPlayers, int port)
                    {
                        multiMenu.Close();
                        myMainMenu.Hide();

                        myHostingLocal = true;

                        myMsgBox.Text = "Hosting and joining game, please wait...\n";
                        myMsgBox.Show();
                        myMsgBox.Focus();
                        myMsgBox.Centre();

                        GameClient.Nickname = "Player";
                        Lewt.Shared.Networking.LocalClientServer.Reset();
                        GameServer.Start(maxPlayers, port, false);
                    })
                    {
                        Title = "Host Internet Game"
                    };
                    AddChild(hostPrompt);
                    hostPrompt.Centre();

                    hostPrompt.Closed += delegate(object sender3, EventArgs e3)
                    {
                        multiMenu.Enable();
                    };
                });
                multiMenu.CreateButton("Cancel", delegate(object sender2, MouseButtonEventArgs e2)
                {
                    multiMenu.Close();
                });

                multiMenu.Closed += delegate(object sender2, EventArgs e2)
                {
                    myMainMenu.Enable();
                };

                multiMenu.AutoSize();
                multiMenu.Centre();
            });
            myMainMenu.CreateButton("Settings");
            myMainMenu.CreateButton("Quit", delegate(object sender, MouseButtonEventArgs e)
            {
                Close();
            });

            AddChild(myMainMenu);
            myMainMenu.AutoSize();
            myMainMenu.Centre();

            Mouse.ButtonDown += delegate(object sender, MouseButtonEventArgs e)
            {
                myUIRoot.SendMouseButtonEvent(new Vector2(e.X, e.Y), e);
            };

            Mouse.ButtonUp += delegate(object sender, MouseButtonEventArgs e)
            {
                myUIRoot.SendMouseButtonEvent(new Vector2(e.X, e.Y), e);
            };

            Mouse.Move += delegate(object sender, MouseMoveEventArgs e)
            {
                myUIRoot.SendMouseMoveEvent(new Vector2(e.X, e.Y), e);
            };

#if DEBUG
            myLastFPSShow = DateTime.Now;
#endif

            GameClient.ClientMessageReceived += new ClientMessageEventHandler(ClientMessageHandler);

            myKeyBinds = new Dictionary <LewtKey, Key[]>
            {
                { LewtKey.WalkUp, new Key[] { Key.W, Key.Up } },
                { LewtKey.WalkDown, new Key[] { Key.S, Key.Down } },
                { LewtKey.WalkLeft, new Key[] { Key.A, Key.Left } },
                { LewtKey.WalkRight, new Key[] { Key.D, Key.Right } },
                { LewtKey.Attack, new Key[] { Key.X } },
                { LewtKey.Block, new Key[] { Key.Z } },
                { LewtKey.Cast, new Key[] { Key.C } },
                { LewtKey.Use, new Key[] { Key.E } },
                { LewtKey.Chat, new Key[] { Key.T } },
                { LewtKey.Inventory, new Key[] { Key.I } },
                { LewtKey.Menu, new Key[] { Key.Escape } }
            };
        }