Пример #1
0
        public GuiServers(Gui parent)
        {
            this.parent = parent;
            hostTex = new Texture2D(Forgottenvoxels.textureFolder + "gui/mainmenu/gui.png", new Vector2(176, 16), new Vector2(16,16));
            connectTex = new Texture2D(Forgottenvoxels.textureFolder + "gui/mainmenu/gui.png", new Vector2(192, 16), new Vector2(16,16));
            backTex = new Texture2D(Forgottenvoxels.textureFolder + "gui/mainmenu/gui.png", new Vector2(224, 16), new Vector2(16,16));

            const int buttonLabelOffsetX = 75,
                    buttonWidth = 384,
                    buttonHeight = 60;

            host = new Button();
            host.x = -6;
            host.y = 150;
            host.width = buttonWidth;
            host.height = buttonHeight;
            host.label = "Host a game";
            host.labelOffsetX = buttonLabelOffsetX;
            host.ClickChange  += (sender, clicked, hovered) => {
                if(clicked && hovered){
                    server.Begin();
                    host.label = "Hosting";
                }
            };
            LinkComponent(host);

            connect = new Button();
            connect.x = -6;
            connect.y = 225;
            connect.width = buttonWidth;
            connect.height = buttonHeight;
            connect.label = "Join a game";
            connect.labelOffsetX = buttonLabelOffsetX;
            connect.ClickChange += (sender, clicked, hovered) => {
                if(clicked && hovered){
                    Socket s = new Socket (AddressFamily.InterNetwork, SocketType.Dgram,
                    ProtocolType.Udp);

                    IPAddress broadcast;
                    if(IPAddress.TryParse (ipinput.label, out broadcast)){
                        IPEndPoint ep = new IPEndPoint (broadcast, 11000);
                        List<byte> data = new List<byte>();
                        data.Add(1);
                        data.AddRange(System.Text.Encoding.ASCII.GetBytes(input.label));
                        s.SendTo(data.ToArray(), ep);
                    }
                    else
                    {
                        Console.WriteLine("Invalid ip!");
                    }
                }
            };
            LinkComponent(connect);

            back = new Button();
            back.x = -6;
            back.y = 500;
            back.width = buttonWidth;
            back.height = buttonHeight;
            back.label = "Back";
            back.labelOffsetX = buttonLabelOffsetX;
            back.ClickChange += (sender, clicked, hovered) => {
                if (clicked && hovered) {
                    StateMainmenu.instance.gui = parent;
                }
            };
            LinkComponent(back);

            input = new TextInput();
            input.x = 500;
            input.y = 500;
            input.width = buttonWidth;
            input.height = buttonHeight;
            input.label = "Message";
            input.labelOffsetX = buttonLabelOffsetX;
            LinkComponent(input);

            ipinput = new TextInput();
            ipinput.x = 500;
            ipinput.y = connect.y;
            ipinput.width = buttonWidth;
            ipinput.height = buttonHeight;
            ipinput.label = "127.0.0.1";
            ipinput.labelOffsetX = buttonLabelOffsetX;
            LinkComponent(ipinput);

            const int imageTopOffset = 6,
                    imageWidth = 48,
                    imageHeight = 48;
            hostImage = new Image();
            hostImage.x = host.x + 12;
            hostImage.y = host.y + imageTopOffset;
            hostImage.width = imageWidth;
            hostImage.height = imageHeight;
            hostImage.texture = hostTex;
            LinkComponent(hostImage);

            connectImage = new Image();
            connectImage.x = connect.x + 12;
            connectImage.y = connect.y + imageTopOffset;
            connectImage.width = imageWidth;
            connectImage.height = imageHeight;
            connectImage.texture = connectTex;
            LinkComponent(connectImage);

            backImage = new Image();
            backImage.x = back.x + 12;
            backImage.y = back.y + imageTopOffset;
            backImage.width = imageWidth;
            backImage.height = imageHeight;
            backImage.texture = backTex;
            LinkComponent(backImage);
        }
Пример #2
0
        public GuiMainmenu()
        {
            optionsGui = new GuiOptions(this);
            serversGui = new GuiServers(this);

            logo = new Texture2D(Forgottenvoxels.textureFolder + "gui/mainmenu/logo.png");
            bg = new Texture2D(Forgottenvoxels.textureFolder + "gui/mainmenu/gui.png", new Vector2(0, 80), new Vector2(16,16));
            startTex = new Texture2D(Forgottenvoxels.textureFolder + "gui/mainmenu/gui.png", new Vector2(192, 0), new Vector2(16,16));
            serversTex = new Texture2D(Forgottenvoxels.textureFolder + "gui/mainmenu/gui.png", new Vector2(128, 16), new Vector2(16,16));
            optionsTex = new Texture2D(Forgottenvoxels.textureFolder + "gui/mainmenu/gui.png", new Vector2(128, 0), new Vector2(16,16));
            doorOpen = new Texture2D(Forgottenvoxels.textureFolder + "gui/mainmenu/gui.png", new Vector2(224, 0), new Vector2(16,16));
            doorClosed = new Texture2D(Forgottenvoxels.textureFolder + "gui/mainmenu/gui.png", new Vector2(240, 0), new Vector2(16,16));

            logoImage = new Image();
            logoImage.x = 25;
            logoImage.y = 25;
            logoImage.width = 768;
            logoImage.height = 96;
            logoImage.texture = logo;
            LinkComponent(logoImage);

            const int buttonLabelOffsetX = 75,
                    buttonWidth = 384,
                    buttonHeight = 60;

            start = new Button();
            start.x = -6;
            start.y = 150;
            start.width = buttonWidth;
            start.height = buttonHeight;
            start.label = "Start game";
            start.labelOffsetX = buttonLabelOffsetX;
            start.ClickChange += (sender, clicked, hovered) => {
                if (clicked && hovered) {
                    GameStateManager.instance.currentState = StateIngame.instance;
                }
            };
            LinkComponent(start);

            servers = new Button();
            servers.x = -6;
            servers.y = 225;
            servers.width = buttonWidth;
            servers.height = buttonHeight;
            servers.label = "Servers";
            servers.labelOffsetX = buttonLabelOffsetX;
            servers.ClickChange += (sender, clicked, hovered) => {
                if (clicked && hovered) {
                    StateMainmenu.instance.gui = serversGui;
                }
            };
            LinkComponent(servers);

            options = new Button();
            options.x = -6;
            options.y = 300;
            options.width = buttonWidth;
            options.height = buttonHeight;
            options.label = "Options";
            options.labelOffsetX = buttonLabelOffsetX;
            options.ClickChange += (sender, clicked, hovered) => {
                if (clicked && hovered) {
                StateMainmenu.instance.gui = optionsGui;
                }
            };
            LinkComponent(options);

            exit = new Button();
            exit.x = -6;
            exit.y = 425;
            exit.width = buttonWidth;
            exit.height = buttonHeight;
            exit.label = "Exit game";
            exit.labelOffsetX = buttonLabelOffsetX;
            //exit.HoverChange += new ButtonEventHandler(ExitHover);
            //exit.ClickChange += new ButtonEventHandler(ExitPress);
            exit.HoverChange += (sender, hovered) => {
                exitImage.texture = hovered ? doorOpen : doorClosed;
            };
            exit.ClickChange += (sender, clicked, hovered) => {
                if(clicked && hovered) Forgottenvoxels.GetInstance().Close();
            };
            LinkComponent(exit);

            const int imageTopOffset = 6,
                    imageWidth = 48,
                    imageHeight = 48;

            startImage = new Image();
            startImage.x = 6;
            startImage.y = start.y + imageTopOffset;
            startImage.width = imageWidth;
            startImage.height = imageHeight;
            startImage.texture = startTex;
            LinkComponent(startImage);

            serverImage = new Image();
            serverImage.x = 6;
            serverImage.y = servers.y + imageTopOffset;
            serverImage.width = imageWidth;
            serverImage.height = imageHeight;
            serverImage.texture = serversTex;
            LinkComponent(serverImage);

            optionsImage = new Image();
            optionsImage.x = 6;
            optionsImage.y = options.y + imageTopOffset;
            optionsImage.width = imageWidth;
            optionsImage.height = imageHeight;
            optionsImage.texture = optionsTex;
            LinkComponent(optionsImage);

            exitImage = new Image();
            exitImage.x = 6;
            exitImage.y = exit.y + imageTopOffset;
            exitImage.width = imageWidth;
            exitImage.height = imageHeight;
            exitImage.texture = doorClosed;
            LinkComponent(exitImage);

            blur = new Image();
            blur.x = -16;
            blur.y = -16;
            blur.width = Forgottenvoxels.GetInstance().Width + 16;
            blur.height = Forgottenvoxels.GetInstance().Height + 16;
            blur.texture = bg;
        }
Пример #3
0
        public GuiOptions(Gui parent)
        {
            this.parent = parent;
            graphicsTex = new Texture2D(Forgottenvoxels.textureFolder + "gui/mainmenu/gui.png", new Vector2(176, 16), new Vector2(16,16));
            soundTex = new Texture2D(Forgottenvoxels.textureFolder + "gui/mainmenu/gui.png", new Vector2(192, 16), new Vector2(16,16));
            controlsTex = new Texture2D(Forgottenvoxels.textureFolder + "gui/mainmenu/gui.png", new Vector2(144, 16), new Vector2(16,16));
            gameTex = new Texture2D(Forgottenvoxels.textureFolder + "gui/mainmenu/gui.png", new Vector2(208, 16), new Vector2(16,16));
            backTex = new Texture2D(Forgottenvoxels.textureFolder + "gui/mainmenu/gui.png", new Vector2(224, 16), new Vector2(16,16));

            const int buttonLabelOffsetX = 75,
                    buttonWidth = 384,
                    buttonHeight = 60;

            graphics = new Button();
            graphics.x = -6;
            graphics.y = 150;
            graphics.width = buttonWidth;
            graphics.height = buttonHeight;
            graphics.label = "Graphics";
            graphics.labelOffsetX = buttonLabelOffsetX;
            LinkComponent(graphics);

            sound = new Button();
            sound.x = -6;
            sound.y = 225;
            sound.width = buttonWidth;
            sound.height = buttonHeight;
            sound.label = "Sound";
            sound.labelOffsetX = buttonLabelOffsetX;
            LinkComponent(sound);

            controls = new Button();
            controls.x = -6;
            controls.y = 300;
            controls.width = buttonWidth;
            controls.height = buttonHeight;
            controls.label = "Controls";
            controls.labelOffsetX = buttonLabelOffsetX;
            LinkComponent(controls);

            game = new Button();
            game.x = -6;
            game.y = 375;
            game.width = buttonWidth;
            game.height = buttonHeight;
            game.label = "Game";
            game.labelOffsetX = buttonLabelOffsetX;
            LinkComponent(game);

            back = new Button();
            back.x = -6;
            back.y = 500;
            back.width = buttonWidth;
            back.height = buttonHeight;
            back.label = "Back";
            back.labelOffsetX = buttonLabelOffsetX;
            back.ClickChange += (sender, clicked, hovered) => {
                if (clicked && hovered) {
                    StateMainmenu.instance.gui = parent;
                }
            };
            LinkComponent(back);

            const int imageTopOffset = 6,
                    imageWidth = 48,
                    imageHeight = 48;
            graphicsImage = new Image();
            graphicsImage.x = graphics.x + 12;
            graphicsImage.y = graphics.y + imageTopOffset;
            graphicsImage.width = imageWidth;
            graphicsImage.height = imageHeight;
            graphicsImage.texture = graphicsTex;
            LinkComponent(graphicsImage);

            soundImage = new Image();
            soundImage.x = sound.x + 12;
            soundImage.y = sound.y + imageTopOffset;
            soundImage.width = imageWidth;
            soundImage.height = imageHeight;
            soundImage.texture = soundTex;
            LinkComponent(soundImage);

            controlsImage = new Image();
            controlsImage.x = controls.x + 12;
            controlsImage.y = controls.y + imageTopOffset;
            controlsImage.width = imageWidth;
            controlsImage.height = imageHeight;
            controlsImage.texture = controlsTex;
            LinkComponent(controlsImage);

            gameImage = new Image();
            gameImage.x = game.x + 12;
            gameImage.y = game.y + imageTopOffset;
            gameImage.width = imageWidth;
            gameImage.height = imageHeight;
            gameImage.texture = gameTex;
            LinkComponent(gameImage);

            backImage = new Image();
            backImage.x = back.x + 12;
            backImage.y = back.y + imageTopOffset;
            backImage.width = imageWidth;
            backImage.height = imageHeight;
            backImage.texture = backTex;
            LinkComponent(backImage);
        }
Пример #4
0
        public GuiMainmenu()
        {
            logo = new Texture2D(Environment.CurrentDirectory + "/Textures/gui/mainmenu/logo.png");
            bg = new Texture2D(Environment.CurrentDirectory + "/Textures/gui/mainmenu/bg.png");
            startTex = new Texture2D(Environment.CurrentDirectory + "/Textures/gui/mainmenu/gui.png", new Vector2(192, 0), new Vector2(16,16));
            serversTex = new Texture2D(Environment.CurrentDirectory + "/Textures/gui/mainmenu/gui.png", new Vector2(128, 16), new Vector2(16,16));
            optionsTex = new Texture2D(Environment.CurrentDirectory + "/Textures/gui/mainmenu/gui.png", new Vector2(128, 0), new Vector2(16,16));
            doorOpen = new Texture2D(Environment.CurrentDirectory + "/Textures/gui/mainmenu/gui.png", new Vector2(224, 0), new Vector2(16,16));
            doorClosed = new Texture2D(Environment.CurrentDirectory + "/Textures/gui/mainmenu/gui.png", new Vector2(240, 0), new Vector2(16,16));

            logoImage = new Image();
            logoImage.x = 25;
            logoImage.y = 25;
            logoImage.width = 768;
            logoImage.height = 96;
            logoImage.texture = logo;
            LinkComponent(logoImage);

            const int buttonLabelOffsetX = 75,
                    buttonWidth = 384,
                    buttonHeight = 60;

            start = new Button();
            start.x = -6;
            start.y = 150;
            start.width = buttonWidth;
            start.height = buttonHeight;
            start.label = "Start game";
            start.labelOffsetX = buttonLabelOffsetX;
            LinkComponent(start);

            servers = new Button();
            servers.x = -6;
            servers.y = 225;
            servers.width = buttonWidth;
            servers.height = buttonHeight;
            servers.label = "Servers";
            servers.labelOffsetX = buttonLabelOffsetX;
            LinkComponent(servers);

            options = new Button();
            options.x = -6;
            options.y = 300;
            options.width = buttonWidth;
            options.height = buttonHeight;
            options.label = "Options";
            options.labelOffsetX = buttonLabelOffsetX;
            LinkComponent(options);

            exit = new Button();
            exit.x = -6;
            exit.y = 375;
            exit.width = buttonWidth;
            exit.height = buttonHeight;
            exit.label = "Exit game";
            exit.labelOffsetX = buttonLabelOffsetX;
            exit.HoverChange += new ButtonEventHandler(ExitHover);
            exit.ClickChange += new ButtonEventHandler(ExitPress);
            LinkComponent(exit);

            const int imageTopOffset = 6,
                    imageWidth = 48,
                    imageHeight = 48;
            startImage = new Image();
            startImage.x = 6;
            startImage.y = start.y + imageTopOffset;
            startImage.width = imageWidth;
            startImage.height = imageHeight;
            startImage.texture = startTex;
            LinkComponent(startImage);

            serverImage = new Image();
            serverImage.x = 6;
            serverImage.y = servers.y + imageTopOffset;
            serverImage.width = imageWidth;
            serverImage.height = imageHeight;
            serverImage.texture = serversTex;
            LinkComponent(serverImage);

            optionsImage = new Image();
            optionsImage.x = 6;
            optionsImage.y = options.y + imageTopOffset;
            optionsImage.width = imageWidth;
            optionsImage.height = imageHeight;
            optionsImage.texture = optionsTex;
            LinkComponent(optionsImage);

            exitImage = new Image();
            exitImage.x = 6;
            exitImage.y = exit.y + imageTopOffset;
            exitImage.width = imageWidth;
            exitImage.height = imageHeight;
            exitImage.texture = doorClosed;
            LinkComponent(exitImage);

            blur = new Image();
            blur.x = -16;
            blur.y = -16;
            blur.width = Forgottenvoxels.GetInstance().Width + 16;
            blur.height = Forgottenvoxels.GetInstance().Height + 16;
            blur.texture = bg;
        }
Пример #5
0
 public void ExitPress(Button sender, bool state)
 {
     if(state)
         Forgottenvoxels.GetInstance().Exit();
 }
Пример #6
0
 public void ExitHover(Button button, bool state)
 {
     exitImage.texture = state ? doorOpen : doorClosed;
 }