Exemplo n.º 1
0
        public void Update()
        {
            #region input
            //check is esc is pressed, if so, toogle main menu
            if (Globals.currentKeyboard.IsKeyDown(Keys.Escape)
                && Globals.oldKeyboard.IsKeyUp(Keys.Escape))
            {
                if (currentGuiState == GuiState.None)
                {
                    currentGuiState = GuiState.MainMenu;
                }
                else if (currentGuiState == GuiState.MainMenu)
                {
                    currentGuiState = GuiState.None;
                }
                else
                {
                    currentGuiState = GuiState.None;
                }
            }

            if (Globals.mouse.RightButton == ButtonState.Pressed
                && Globals.prevMouse.RightButton == ButtonState.Released)
            {
                currentGuiState = GuiState.Context;

                string[] abcd = new string[2];
                abcd[0] = "dupa";
                abcd[1] = "nic";
                contextMenu = new ContextMenu(new Vector2(Globals.mouse.X, Globals.mouse.Y), abcd);
            }
            #endregion

            if (currentGuiState == GuiState.None)
            {
                //pass
            }
            else if (currentGuiState == GuiState.Context)
            {
                contextMenu.Update();
            }
            else if (currentGuiState == GuiState.MainMenu)
            {
                mainMenu.Update(ref currentGuiState, this);
            }
            else if (currentGuiState == GuiState.MessageBox)
            {
                messageBox.Update(ref currentGuiState);
            }
        }
Exemplo n.º 2
0
        public void Update(ref GuiState guiState)
        {
            exitButton.Update();
            if (exitButton.isClicked)
            {
                if (fromMenu)
                {
                    guiState = GuiState.MainMenu;
                }
                else
                {
                    guiState = GuiState.None;
                }

                //if exit button is clicked, swich gui to menu
            }
        }
Exemplo n.º 3
0
        public void Update(ref GuiState gowno, Gui siki)
        {
            foreach (var item in buttons)
            {
                //update buttons
                if (item == null)
                {
                    break;
                }
                item.Update();
            }

            if (buttons[0].isClicked)
            {
                //if button first form top is clicked, swich to message box
                siki.CreateMessageBox("Map Saved", true);
            }
        }
Exemplo n.º 4
0
 public void SetStateAuthInput()
 {
     RootOf3dButtons.SetActive(false);
     guiState = GuiState.AuthInput;
 }
Exemplo n.º 5
0
 public void SetStateAuthHelp()
 {
     RootOf3dButtons.SetActive(false);
     guiState = GuiState.AuthHelp;
 }
Exemplo n.º 6
0
        void Keyboard_KeyDown(object sender, OpenTK.Input.KeyboardKeyEventArgs e)
        {
            if (e.Key == GetKey(OpenTK.Input.Key.F11))
            {
                if (d_MainWindow.WindowState == WindowState.Fullscreen)
                {
                    d_MainWindow.WindowState = WindowState.Normal;
                }
                else
                {
                    d_MainWindow.WindowState = WindowState.Fullscreen;
                }
            }
            if (GuiTyping == TypingState.None)
            {
                keyevent = e;
            }
            if (guistate == GuiState.Normal)
            {
                if (Keyboard[GetKey(OpenTK.Input.Key.Escape)])
                {
                    guistate = GuiState.EscapeMenu;
                    menustate = new MenuState();
                    FreeMouse = true;
                }
                if (e.Key == GetKey(OpenTK.Input.Key.PageUp) && GuiTyping == TypingState.Typing)
                {
                    d_HudChat.ChatPageScroll++;
                }
                if (e.Key == GetKey(OpenTK.Input.Key.PageDown) && GuiTyping == TypingState.Typing)
                {
                    d_HudChat.ChatPageScroll--;
                }
                d_HudChat.ChatPageScroll = MyMath.Clamp(d_HudChat.ChatPageScroll, 0, d_HudChat.ChatLines.Count / d_HudChat.ChatLinesMaxToDraw);
                if (e.Key == GetKey(OpenTK.Input.Key.Enter) || e.Key == GetKey(OpenTK.Input.Key.KeypadEnter))
                {
                    if (GuiTyping == TypingState.Typing)
                    {
                        typinglog.Add(d_HudChat.GuiTypingBuffer);
                        typinglogpos = typinglog.Count;
                        ClientCommand(d_HudChat.GuiTypingBuffer);

                        d_HudChat.GuiTypingBuffer = "";
                        d_HudChat.IsTyping = false;

                        GuiTyping = TypingState.None;
                    }
                    else if (GuiTyping == TypingState.None)
                    {
                        GuiTyping = TypingState.Typing;
                        d_HudChat.IsTyping = true;
                        d_HudChat.GuiTypingBuffer = "";
                    }
                    else if (GuiTyping == TypingState.Ready)
                    {
                        Console.WriteLine("Keyboard_KeyDown ready");
                    }
                    return;
                }
                if (GuiTyping == TypingState.Typing)
                {
                    var key = e.Key;
                    string c = "";
                    if (key == GetKey(OpenTK.Input.Key.BackSpace))
                    {
                        if (d_HudChat.GuiTypingBuffer.Length > 0)
                        {
                            d_HudChat.GuiTypingBuffer = d_HudChat.GuiTypingBuffer.Substring(0, d_HudChat.GuiTypingBuffer.Length - 1);
                        }
                        return;
                    }
                    if (Keyboard[GetKey(OpenTK.Input.Key.ControlLeft)] || Keyboard[GetKey(OpenTK.Input.Key.ControlRight)])
                    {
                        if (key == GetKey(OpenTK.Input.Key.V))
                        {
                            if (Clipboard.ContainsText())
                            {
                                d_HudChat.GuiTypingBuffer += Clipboard.GetText();
                            }
                            return;
                        }
                    }
                    if (key == GetKey(OpenTK.Input.Key.Up))
                    {
                        typinglogpos--;
                        if (typinglogpos < 0) { typinglogpos = 0; }
                        if (typinglogpos >= 0 && typinglogpos < typinglog.Count)
                        {
                            d_HudChat.GuiTypingBuffer = typinglog[typinglogpos];
                        }
                    }
                    if (key == GetKey(OpenTK.Input.Key.Down))
                    {
                        typinglogpos++;
                        if (typinglogpos > typinglog.Count) { typinglogpos = typinglog.Count; }
                        if (typinglogpos >= 0 && typinglogpos < typinglog.Count)
                        {
                            d_HudChat.GuiTypingBuffer = typinglog[typinglogpos];
                        }
                        if (typinglogpos == typinglog.Count)
                        {
                            d_HudChat.GuiTypingBuffer = "";
                        }
                    }
                    return;
                }
                string strFreemoveNotAllowed = "Freemove is not allowed on this server.";
                if (e.Key == GetKey(OpenTK.Input.Key.F1))
                {
                    if (!AllowFreemove)
                    {
                        Log(strFreemoveNotAllowed);
                        return;
                    }
                    movespeed = basemovespeed * 1;
                    Log("Move speed: 1x.");
                }
                if (e.Key == GetKey(OpenTK.Input.Key.F2))
                {
                    if (!AllowFreemove)
                    {
                        Log(strFreemoveNotAllowed);
                        return;
                    }
                    movespeed = basemovespeed * 10;
                    Log("Move speed: 10x.");
                }
                if (e.Key == GetKey(OpenTK.Input.Key.F3))
                {
                    if (!AllowFreemove)
                    {
                        Log(strFreemoveNotAllowed);
                        return;
                    }
                    player.movedz = 0;
                    if (!ENABLE_FREEMOVE)
                    {
                        ENABLE_FREEMOVE = true;
                        Log("Move: Free.");
                    }
                    else if (ENABLE_FREEMOVE && (!ENABLE_NOCLIP))
                    {
                        ENABLE_NOCLIP = true;
                        Log("Move: Free, Noclip.");
                    }
                    else if (ENABLE_FREEMOVE && ENABLE_NOCLIP)
                    {
                        ENABLE_FREEMOVE = false;
                        ENABLE_NOCLIP = false;
                        Log("Move: Normal.");
                    }
                }
                if (e.Key == GetKey(OpenTK.Input.Key.I))
                {
                    drawblockinfo = !drawblockinfo;
                }
                if (e.Key == GetKey(OpenTK.Input.Key.F5))
                {
                    if (cameratype == CameraType.Fpp)
                    {
                        cameratype = CameraType.Tpp;
                        ENABLE_TPP_VIEW = true;
                    }
                    else if (cameratype == CameraType.Tpp)
                    {
                        cameratype = CameraType.Overhead;
                        overheadcamera = true;
                        FreeMouse = true;
                        ENABLE_TPP_VIEW = true;
                        playerdestination = player.playerposition;
                    }
                    else if (cameratype == CameraType.Overhead)
                    {
                        cameratype = CameraType.Fpp;
                        FreeMouse = false;
                        ENABLE_TPP_VIEW = false;
                        overheadcamera = false;
                    }
                    else throw new Exception();
                }
                if (e.Key == GetKey(OpenTK.Input.Key.Plus) || e.Key == GetKey(OpenTK.Input.Key.KeypadPlus))
                {
                    if (cameratype == CameraType.Overhead)
                    {
                        overheadcameradistance -= 1;
                    }
                    else if (cameratype == CameraType.Tpp)
                    {
                        tppcameradistance -= 1;
                    }
                }
                if (e.Key == GetKey(OpenTK.Input.Key.Minus) || e.Key == GetKey(OpenTK.Input.Key.KeypadMinus))
                {
                    if (cameratype == CameraType.Overhead)
                    {
                        overheadcameradistance += 1;
                    }
                    else if (cameratype == CameraType.Tpp)
                    {
                        tppcameradistance += 1;
                    }
                }
                if (overheadcameradistance < TPP_CAMERA_DISTANCE_MIN) { overheadcameradistance = TPP_CAMERA_DISTANCE_MIN; }
                if (overheadcameradistance > TPP_CAMERA_DISTANCE_MAX) { overheadcameradistance = TPP_CAMERA_DISTANCE_MAX; }

                if (tppcameradistance < TPP_CAMERA_DISTANCE_MIN) { tppcameradistance = TPP_CAMERA_DISTANCE_MIN; }
                if (tppcameradistance > TPP_CAMERA_DISTANCE_MAX) { tppcameradistance = TPP_CAMERA_DISTANCE_MAX; }

                if (e.Key == GetKey(OpenTK.Input.Key.F6))
                {
                    RedrawAllBlocks();
                }
                if (e.Key == GetKey(OpenTK.Input.Key.F7))
                {
                    if (ENABLE_DRAWFPSHISTORY)
                    {
                        ENABLE_DRAWFPS = ENABLE_DRAWFPSHISTORY = false;
                    }
                    else
                    {
                        ENABLE_DRAWFPS = ENABLE_DRAWFPSHISTORY = true;
                    }
                }
                if (e.Key == OpenTK.Input.Key.F8)
                {
                    ENABLE_LAG++;
                    ENABLE_LAG = ENABLE_LAG % 3;
                    d_MainWindow.VSync = (ENABLE_LAG == 1) ? VSyncMode.Off : VSyncMode.On;
                    if (ENABLE_LAG == 0) { Log("Frame rate: vsync."); }
                    if (ENABLE_LAG == 1) { Log("Frame rate: unlimited."); }
                    if (ENABLE_LAG == 2) { Log("Frame rate: lag simulation."); }
                }
                if (e.Key == GetKey(OpenTK.Input.Key.F12))
                {
                    d_Screenshot.SaveScreenshot();
                    screenshotflash = 5;
                }
                if (e.Key == GetKey(OpenTK.Input.Key.E))
                {
                    if (currentAttackedBlock != null)
                    {
                        Vector3 pos = new Vector3(currentAttackedBlock.Value.x, currentAttackedBlock.Value.y, currentAttackedBlock.Value.z);
                        int blocktype = d_Map.GetBlock(currentAttackedBlock.Value.x, currentAttackedBlock.Value.y, currentAttackedBlock.Value.z);
                        if (IsUsableBlock(blocktype))
                        {
                            if (GameDataManicDigger.IsRailTile(blocktype))
                            {
                                player.playerposition.X = pos.X + .5f;
                                player.playerposition.Y = pos.Z + 1;
                                player.playerposition.Z = pos.Y + .5f;
                                ENABLE_FREEMOVE = false;
                            }
                            else
                            {
                                SendSetBlock(pos, BlockSetMode.Use, 0, ActiveMaterial);
                            }
                        }
                    }
                }
                if (e.Key == GetKey(OpenTK.Input.Key.R))
                {
                    Respawn();
                    Log("Respawn.");
                }
                if (e.Key == GetKey(OpenTK.Input.Key.P))
                {
                    PlayerPositionSpawn = player.playerposition;
                    player.playerposition = new Vector3((int)player.playerposition.X + 0.5f, player.playerposition.Y, (int)player.playerposition.Z + 0.5f);
                    Log("Spawn position set.");
                }
                if (e.Key == GetKey(OpenTK.Input.Key.F))
                {
                    ToggleFog();
                    Log("Fog distance: " + d_Config3d.viewdistance);
                    OnResize(new EventArgs());
                }
                if (e.Key == GetKey(OpenTK.Input.Key.B))
                {
                    guistate = GuiState.Inventory;
                    menustate = new MenuState();
                    FreeMouse = true;
                }
                HandleMaterialKeys(e);
                if (e.Key == GetKey(OpenTK.Input.Key.Escape))
                {
                    EscapeMenuStart();
                }
            }
            else if (guistate == GuiState.EscapeMenu)
            {
                EscapeMenuKeyDown(e);
                return;
            }
            else if (guistate == GuiState.Inventory)
            {
                if (e.Key == GetKey(OpenTK.Input.Key.B)
                    || e.Key == GetKey(OpenTK.Input.Key.Escape))
                {
                    GuiStateBackToGame();
                }
                return;
            }
            else if (guistate == GuiState.MapLoading)
            {
            }
            else if (guistate == GuiState.CraftingRecipes)
            {
                if (e.Key == GetKey(OpenTK.Input.Key.Escape))
                {
                    GuiStateBackToGame();
                }
            }
            else throw new Exception();
        }
Exemplo n.º 7
0
 public void EscapeMenuStart()
 {
     guistate = GuiState.EscapeMenu;
     menustate = new MenuState();
     platform.ExitMousePointerLock();
     escapeMenuRestart = true;
 }
Exemplo n.º 8
0
 //bool EscapeMenuWasFreemove;
 private void GuiStateBackToGame()
 {
     guistate = GuiState.Normal;
     FreeMouse = false;
     //ENABLE_FREEMOVE = EscapeMenuWasFreemove;
     freemousejustdisabled = true;
 }
Exemplo n.º 9
0
 private void GuiStateSetMapLoading()
 {
     guistate = GuiState.MapLoading;
     freemouse = true;
     maploadingprogress = new MapLoadingProgressEventArgs();
 }
Exemplo n.º 10
0
 public void CreateMessageBox(string text, bool fromMenu)
 {
     messageBox.SetText(text);
     messageBox.fromMenu = fromMenu;
     currentGuiState = GuiState.MessageBox;
 }
Exemplo n.º 11
0
 private void moveClick(Button a_button)
 {
     if (a_button.p_state == Button.State.Toggled) {
         return;
     }
     toggleTiles(m_gameState.getSelectedChampion().getStat("MoveLeft"));
     m_state = GuiState.Move;
 }
Exemplo n.º 12
0
 public void GuiStateBackToGame()
 {
     guistate = GuiState.Normal;
     FreeMouse = false;
     freemousejustdisabled = true;
 }
Exemplo n.º 13
0
    private void SwitchState(GuiState newState)
    {
        if (newState == this.currentState)
        { return; }

        this.currentState = newState;

        this.PlayerInfoContainer.SetActive(this.currentState == GuiState.PlayerInfo);
        this.ShopContainer.SetActive(this.currentState == GuiState.Shop);
        this.TravelContainer.SetActive(this.currentState == GuiState.Travel);
    }
Exemplo n.º 14
0
 private void waitClick(Button a_button)
 {
     toggleTiles(1);
     //m_activeBtnList = null;
     m_state = GuiState.SelectFacing;
 }
Exemplo n.º 15
0
 private void useAbility(Button a_button)
 {
     toggleTiles(m_gameState.getSelectedChampion().getAbility(a_button.p_buttonText.Split(':')[0]).getRange());
     m_state = GuiState.UseAbility;
 }
Exemplo n.º 16
0
 private void restoreStates()
 {
     m_gameState.getTileMap().restoreStates();
     m_state = GuiState.Normal;
 }
Exemplo n.º 17
0
 public void SetStateAuthOrNot()
 {
     RootOf3dButtons.SetActive(true);
     guiState = GuiState.AuthOrNot; 
 }
Exemplo n.º 18
0
 public void GuiStateCraft(List<CraftingRecipe> recipes, List<int> blocks, Action<int?> craftingRecipeSelected)
 {
     this.craftingrecipes = recipes;
     this.craftingblocks = blocks;
     this.craftingrecipeselected = craftingRecipeSelected;
     guistate = GuiState.CraftingRecipes;
     //EscapeMenuWasFreemove = ENABLE_FREEMOVE;
     menustate = new MenuState();
     FreeMouse = true;
 }
Exemplo n.º 19
0
 public void SetStateAuthFailed()
 {
     RootOf3dButtons.SetActive(false);
     guiState = GuiState.AuthFailed; 
 }
Exemplo n.º 20
0
 private void actionClick(Button a_button)
 {
     //m_activeBtnList = m_actionBtnList;
     m_state = GuiState.ActionMenu;
 }
Exemplo n.º 21
0
 public void MapLoadingStart()
 {
     guistate = GuiState.MapLoading;
     SetFreeMouse(true);
     maploadingprogress = new MapLoadingProgressEventArgs();
     fontMapLoading = FontCi.Create("Arial", 14, 0);
 }
Exemplo n.º 22
0
 public void ShowEscapeMenu()
 {
     guistate = GuiState.EscapeMenu;
     menustate = new MenuState();
     SetFreeMouse(true);
 }
Exemplo n.º 23
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            string version = GL.GetString(StringName.Version);
            int major = (int)version[0];
            int minor = (int)version[2];
            if (major <= 1 && minor < 5)
            {
                //System.Windows.Forms.MessageBox.Show("You need at least OpenGL 1.5 to run this example. Aborting.", "VBOs not supported",
                //System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Exclamation);
                this.Exit();
            }
            if (!config3d.ENABLE_VSYNC)
            {
                TargetRenderFrequency = 0;
            }
            GL.ClearColor(System.Drawing.Color.MidnightBlue);
            //GL.Frustum(double.MinValue, double.MaxValue, double.MinValue, double.MaxValue, 1, 1000);
            //clientgame.GeneratePlainMap();
            //clientgame.LoadMapMinecraft();
            if (GameUrl == null)
            {
                if (ENABLE_MAINMENU)
                {
                    guistate = GuiState.MainMenu;
                    FreeMouse = true;
                    mapManipulator.LoadMap(map, getfile.GetFile("menu" + MapManipulator.XmlSaveExtension));
                    ENABLE_FREEMOVE = true;
                    player.playerposition = new Vector3(4.691565f, 45.2253f, 2.52523f);
                    player.playerorientation = new Vector3(3.897586f, 2.385999f, 0f);
                }
                else
                {
                    GuiActionGenerateNewMap();
                    GuiStateBackToGame();
                }
                DrawMap();
                terrain.Start();
            }
            else
            {
                ClientCommand(".server " + GameUrl);
            }
            Mouse.Move += new EventHandler<OpenTK.Input.MouseMoveEventArgs>(Mouse_Move);
            Mouse.WheelChanged += new EventHandler<OpenTK.Input.MouseWheelEventArgs>(Mouse_WheelChanged);
            if (config3d.ENABLE_BACKFACECULLING)
            {
                GL.DepthMask(true);
                GL.Enable(EnableCap.DepthTest);
                GL.CullFace(CullFaceMode.Back);
                GL.Enable(EnableCap.CullFace);
            }
            Keyboard.KeyRepeat = true;
            KeyPress += new EventHandler<OpenTK.KeyPressEventArgs>(ManicDiggerGameWindow_KeyPress);
            Keyboard.KeyDown += new EventHandler<OpenTK.Input.KeyboardKeyEventArgs>(Keyboard_KeyDown);
            Keyboard.KeyUp += new EventHandler<OpenTK.Input.KeyboardKeyEventArgs>(Keyboard_KeyUp);
            materialSlots = data.DefaultMaterialSlots;
            GL.Enable(EnableCap.Lighting);
            SetAmbientLight(terraincolor);
            GL.Enable(EnableCap.ColorMaterial);
            GL.ColorMaterial(MaterialFace.FrontAndBack, ColorMaterialParameter.AmbientAndDiffuse);
            GL.ShadeModel(ShadingModel.Smooth);
            System.Windows.Forms.Cursor.Hide();
        }
Exemplo n.º 24
0
 public void ShowInventory()
 {
     guistate = GuiState.Inventory;
     menustate = new MenuState();
     SetFreeMouse(true);
 }
Exemplo n.º 25
0
 private void GuiStateEscapeMenu()
 {
     guistate = GuiState.EscapeMenu;
     menustate = new MenuState();
     FreeMouse = true;
     //EscapeMenuWasFreemove = ENABLE_FREEMOVE;
 }
Exemplo n.º 26
0
 internal void GuiStateBackToGame()
 {
     guistate = GuiState.Normal;
     SetFreeMouse(false);
 }
Exemplo n.º 27
0
 void Keyboard_KeyDown(object sender, OpenTK.Input.KeyboardKeyEventArgs e)
 {
     if (e.Key == OpenTK.Input.Key.F11)
     {
         if (WindowState == WindowState.Fullscreen)
         {
             WindowState = WindowState.Normal;
         }
         else
         {
             WindowState = WindowState.Fullscreen;
         }
     }
     if (GuiTyping == TypingState.None)
     {
         keyevent = e;
     }
     if (guistate == GuiState.Normal)
     {
         if (Keyboard[OpenTK.Input.Key.Escape])
         {
             guistate = GuiState.EscapeMenu;
             menustate = new MenuState();
             FreeMouse = true;
         }
         if (e.Key == OpenTK.Input.Key.Enter || e.Key == OpenTK.Input.Key.KeypadEnter)
         {
             if (GuiTyping == TypingState.Typing)
             {
                 typinglog.Add(GuiTypingBuffer);
                 typinglogpos = typinglog.Count;
                 ClientCommand(GuiTypingBuffer);
                 GuiTypingBuffer = "";
                 GuiTyping = TypingState.None;
             }
             else if (GuiTyping == TypingState.None)
             {
                 GuiTyping = TypingState.Typing;
                 GuiTypingBuffer = "";
             }
             else if (GuiTyping == TypingState.Ready)
             {
                 Console.WriteLine("Keyboard_KeyDown ready");
             }
             return;
         }
         if (GuiTyping == TypingState.Typing)
         {
             var key = e.Key;
             string c = "";
             if (key == OpenTK.Input.Key.BackSpace)
             {
                 if (GuiTypingBuffer.Length > 0)
                 {
                     GuiTypingBuffer = GuiTypingBuffer.Substring(0, GuiTypingBuffer.Length - 1);
                 }
                 return;
             }
             if (Keyboard[OpenTK.Input.Key.ControlLeft] || Keyboard[OpenTK.Input.Key.ControlRight])
             {
                 if (key == OpenTK.Input.Key.V)
                 {
                     if (Clipboard.ContainsText())
                     {
                         GuiTypingBuffer += Clipboard.GetText();
                     }
                     return;
                 }
             }
             if (key == OpenTK.Input.Key.Up)
             {
                 typinglogpos--;
                 if (typinglogpos < 0) { typinglogpos = 0; }
                 if (typinglogpos >= 0 && typinglogpos < typinglog.Count)
                 {
                     GuiTypingBuffer = typinglog[typinglogpos];
                 }
             }
             if (key == OpenTK.Input.Key.Down)
             {
                 typinglogpos++;
                 if (typinglogpos > typinglog.Count) { typinglogpos = typinglog.Count; }
                 if (typinglogpos >= 0 && typinglogpos < typinglog.Count)
                 {
                     GuiTypingBuffer = typinglog[typinglogpos];
                 }
                 if (typinglogpos == typinglog.Count)
                 {
                     GuiTypingBuffer = "";
                 }
             }
             return;
         }
         if (e.Key == OpenTK.Input.Key.F1)
         {
             movespeed = basemovespeed * 1;
             Log("Move speed: 1x.");
         }
         if (e.Key == OpenTK.Input.Key.F2)
         {
             movespeed = basemovespeed * 10;
             Log("Move speed: 10x.");
         }
         if (e.Key == OpenTK.Input.Key.F9)
         {
             string defaultserverfile = "defaultserver.txt";
             if (File.Exists(defaultserverfile))
             {
                 ConnectToInternetGame(username, pass, File.ReadAllText(defaultserverfile));
                 Log("Connected to default server.");
             }
             else
             {
                 Log(string.Format("File {0} not found.", defaultserverfile));
             }
         }
         if (e.Key == OpenTK.Input.Key.F3)
         {
             ENABLE_FREEMOVE = !ENABLE_FREEMOVE;
             if (ENABLE_FREEMOVE) { Log("Freemove enabled."); }
             else { Log("Freemove disabled."); }
         }
         if (e.Key == OpenTK.Input.Key.F4)
         {
             ENABLE_NOCLIP = !ENABLE_NOCLIP;
             if (ENABLE_NOCLIP) { Log("Noclip enabled."); }
             else { Log("Noclip disabled."); }
         }
         if (e.Key == OpenTK.Input.Key.I)
         {
             drawblockinfo = !drawblockinfo;
         }
         if (e.Key == OpenTK.Input.Key.F5)
         {
             if (cameratype == CameraType.Fpp)
             {
                 cameratype = CameraType.Tpp;
                 ENABLE_TPP_VIEW = true;
             }
             else if (cameratype == CameraType.Tpp)
             {
                 cameratype = CameraType.Overhead;
                 overheadcamera = true;
                 ENABLE_TPP_VIEW = true;
                 playerdestination = player.playerposition;
             }
             else if (cameratype == CameraType.Overhead)
             {
                 cameratype = CameraType.Fpp;
                 ENABLE_TPP_VIEW = false;
                 overheadcamera = false;
             }
             else throw new Exception();
         }
         if (e.Key == OpenTK.Input.Key.F12)
         {
             using (Bitmap bmp = GrabScreenshot())
             {
                 string path = System.Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
                 string time = string.Format("{0:yyyy-MM-dd_HH-mm-ss}", DateTime.Now);
                 string filename = Path.Combine(path, time + ".png");
                 bmp.Save(filename);
                 screenshotflash = 5;
             }
         }
         if (e.Key == OpenTK.Input.Key.R)
         {
             player.playerposition = game.PlayerPositionSpawn;
             player.movedz = 0;
             Log("Respawn.");
         }
         if (e.Key == OpenTK.Input.Key.P)
         {
             game.PlayerPositionSpawn = player.playerposition;
             player.playerposition = new Vector3((int)player.playerposition.X + 0.5f, player.playerposition.Y, (int)player.playerposition.Z + 0.5f);
             Log("Spawn position set.");
         }
         if (e.Key == OpenTK.Input.Key.F)
         {
             if (terrain.DrawDistance == 64) { terrain.DrawDistance = 128; }
             else if (terrain.DrawDistance == 128) { terrain.DrawDistance = 256; }
             else if (terrain.DrawDistance == 256) { terrain.DrawDistance = 512; }
             else if (terrain.DrawDistance == 512) { terrain.DrawDistance = 64; }
             else { terrain.DrawDistance = 64; }
             Log("Fog distance: " + terrain.DrawDistance);
         }
         if (e.Key == OpenTK.Input.Key.B)
         {
             //EscapeMenuWasFreemove = ENABLE_FREEMOVE;
             guistate = GuiState.Inventory;
             menustate = new MenuState();
             FreeMouse = true;
         }
         HandleMaterialKeys(e);
         if (e.Key == OpenTK.Input.Key.Escape)
         {
             GuiStateEscapeMenu();
         }
     }
     else if (guistate == GuiState.EscapeMenu)
     {
         int menuelements = 3;
         if (e.Key == OpenTK.Input.Key.Escape)
         {
             escapemenuOptions = false;
             GuiStateBackToGame();
         }
         if (e.Key == OpenTK.Input.Key.Up)
         {
             menustate.selected--;
             menustate.selected = Math.Max(0, menustate.selected);
         }
         if (e.Key == OpenTK.Input.Key.Down)
         {
             menustate.selected++;
             menustate.selected = Math.Min(menuelements - 1, menustate.selected);
         }
         if (menustate.selected != -1
             && (e.Key == OpenTK.Input.Key.Enter || e.Key == OpenTK.Input.Key.KeypadEnter))
         {
             EscapeMenuAction();
         }
         return;
     }
     else if (guistate == GuiState.MainMenu)
     {
         int menuelements = 3;
         if (e.Key == OpenTK.Input.Key.Escape)
         {
             exit = true;
             Exit();
         }
         if (e.Key == OpenTK.Input.Key.Up)
         {
             menustate.selected--;
             menustate.selected = Math.Max(0, menustate.selected);
         }
         if (e.Key == OpenTK.Input.Key.Down)
         {
             menustate.selected++;
             menustate.selected = Math.Min(menuelements - 1, menustate.selected);
         }
         if (e.Key == OpenTK.Input.Key.Enter || e.Key == OpenTK.Input.Key.KeypadEnter)
         {
             MainMenuAction();
         }
         return;
     }
     else if (guistate == GuiState.Inventory)
     {
         if (e.Key == OpenTK.Input.Key.Escape)
         {
             GuiStateBackToGame();
         }
         Direction4? dir = null;
         if (e.Key == OpenTK.Input.Key.Left) { dir = Direction4.Left; }
         if (e.Key == OpenTK.Input.Key.Right) { dir = Direction4.Right; }
         if (e.Key == OpenTK.Input.Key.Up) { dir = Direction4.Up; }
         if (e.Key == OpenTK.Input.Key.Down) { dir = Direction4.Down; }
         if (dir != null)
         {
             InventorySelectionMove(dir.Value);
         }
         if (e.Key == OpenTK.Input.Key.Enter || e.Key == OpenTK.Input.Key.KeypadEnter)
         {
             var sel = InventoryGetSelected();
             if (sel != null)
             {
                 materialSlots[activematerial] = sel.Value;
                 GuiStateBackToGame();
             }
         }
         HandleMaterialKeys(e);
         return;
     }
     else if (guistate == GuiState.MapLoading)
     {
     }
     else if (guistate == GuiState.CraftingRecipes)
     {
         if (e.Key == OpenTK.Input.Key.Escape)
         {
             GuiStateBackToGame();
         }
     }
     else throw new Exception();
 }
Exemplo n.º 28
0
        void Keyboard_KeyDown(object sender, OpenTK.Input.KeyboardKeyEventArgs e)
        {
            if (e.Key == OpenTK.Input.Key.F10)
            {
                if (!SkySphereNight)
                {
                    SkySphereNight = true;
                    return;
                }
                else
                {
                    SkySphereNight = false;
                    return;
                }
            }
            if (e.Key == OpenTK.Input.Key.F11)
            {
                if (WindowState == WindowState.Fullscreen)
                {
                    WindowState = WindowState.Normal;
                }
                else
                {
                    WindowState = WindowState.Fullscreen;
                }
            }
            if (GuiTyping == TypingState.None)
            {
                keyevent = e;
            }
            if (Keyboard[OpenTK.Input.Key.PageUp] && GuiTyping == TypingState.Typing)
            {
                ChatPageScroll++;
            }
            if (Keyboard[OpenTK.Input.Key.PageDown] && GuiTyping == TypingState.Typing)
            {
                if(ChatPageScroll > 0)
                ChatPageScroll--;
            }
            if (Keyboard[OpenTK.Input.Key.KeypadMinus])
            {
                if (ChatFontSize > 6)
                {
                    ChatFontSize--;
                    fn = new Font(ff, ChatFontSize, FontStyle.Bold);
                }
            }
            if (Keyboard[OpenTK.Input.Key.KeypadPlus])
            {
                if (ChatFontSize < 25)
                {
                    ChatFontSize++;
                    fn = new Font(ff, ChatFontSize, FontStyle.Bold);
                }
            }
            if (guistate == GuiState.Normal)
            {

                if (Keyboard[OpenTK.Input.Key.Escape])
                {
                    if (GuiTyping == TypingState.Typing)
                    {
                        GuiTyping = TypingState.None;
                        GuiStateBackToGame();
                        return;
                    }
                    guistate = GuiState.EscapeMenu;
                    menustate = new MenuState();
                    FreeMouse = true;
                }

                if (e.Key == OpenTK.Input.Key.Enter || e.Key == OpenTK.Input.Key.KeypadEnter)
                {
                    if (GuiTyping == TypingState.Typing)
                    {
                        if (!Disconnected)
                        {
                            typinglog.Add(GuiTypingBuffer);
                            typinglogpos = typinglog.Count;
                            ClientCommand(GuiTypingBuffer);
                            GuiTypingBuffer = "";
                            FreeMouse = false;
                        }
                        GuiTyping = TypingState.None;
                    }
                    else if (GuiTyping == TypingState.None)
                    {
                        GuiTyping = TypingState.Typing;
                    }
                    else if (GuiTyping == TypingState.Ready)
                    {
                        Console.WriteLine("Keyboard_KeyDown ready");
                    }
                    return;
                }
                if (GuiTyping == TypingState.Typing)
                {
                    if (Disconnected) return;
                    var key = e.Key;
                    if (key == OpenTK.Input.Key.BackSpace)
                    {
                        if (GuiTypingBuffer.Length > 0)
                        {
                            GuiTypingBuffer = GuiTypingBuffer.Substring(0, GuiTypingBuffer.Length - 1);
                        }
                        return;
                    }
                    if (Keyboard[OpenTK.Input.Key.ControlLeft] || Keyboard[OpenTK.Input.Key.ControlRight])
                    {
                        if (key == OpenTK.Input.Key.V)
                        {
                            if (Clipboard.ContainsText())
                            {
                                GuiTypingBuffer += Clipboard.GetText();
                            }
                            return;
                        }
                    }
                    if (key == OpenTK.Input.Key.Up)
                    {
                        typinglogpos--;
                        if (typinglogpos < 0) { typinglogpos = 0; }
                        if (typinglogpos >= 0 && typinglogpos < typinglog.Count)
                        {
                            GuiTypingBuffer = typinglog[typinglogpos];
                        }
                    }
                    if (key == OpenTK.Input.Key.Down)
                    {
                        typinglogpos++;
                        if (typinglogpos > typinglog.Count) { typinglogpos = typinglog.Count; }
                        if (typinglogpos >= 0 && typinglogpos < typinglog.Count)
                        {
                            GuiTypingBuffer = typinglog[typinglogpos];
                        }
                        if (typinglogpos == typinglog.Count)
                        {
                            GuiTypingBuffer = "";
                        }
                    }
                    return;
                }
                if (e.Key == OpenTK.Input.Key.F9)
                {
                    string defaultserverfile = "defaultserver.txt";
                    if (File.Exists(defaultserverfile))
                    {
                        string Text = File.ReadAllText(defaultserverfile);
                        if (Text == null || !Text.StartsWith("http://"))
                        {
                            Log("Invalid server url in defaultserver.txt.");
                            return;
                        }
                        LoadPassword();
                        ConnectToInternetGame(username, pass, Text);
                        Log("Connected to default server.");
                    }
                    else
                    {
                        Log(string.Format("File {0} not found.", defaultserverfile));
                        File.Create("defaultserver.txt");
                        Log(string.Format("Created file {0}, you can add your favorite server url in it!", defaultserverfile));
                    }
                }
                if (e.Key == OpenTK.Input.Key.Z)
                {
                    player.movedz = 0;
                    ENABLE_FREEMOVE = !ENABLE_FREEMOVE;
                }

                if (e.Key == OpenTK.Input.Key.F4)
                {
                    ENABLE_NOCLIP = !ENABLE_NOCLIP;
                }
                if (e.Key == OpenTK.Input.Key.F1)
                {
                    drawblockinfo = !drawblockinfo;
                }
                if (e.Key == OpenTK.Input.Key.F5)
                {
                    if (cameratype == CameraType.Fpp)
                    {
                        cameratype = CameraType.Tpp;
                        ENABLE_TPP_VIEW = true;
                    }
                    else if (cameratype == CameraType.Tpp)
                    {
                        cameratype = CameraType.Overhead;
                        overheadcamera = true;
                        ENABLE_TPP_VIEW = true;
                        playerdestination = player.playerposition;
                    }
                    else if (cameratype == CameraType.Overhead)
                    {
                        cameratype = CameraType.Fpp;
                        ENABLE_TPP_VIEW = false;
                        overheadcamera = false;
                    }
                    else throw new Exception();
                }
                if (e.Key == OpenTK.Input.Key.F12)
                {
                    using (Bitmap bmp = GrabScreenshot())
                    {
                        string path = "Screenshots";
                        string time = string.Format("{0:yyyy-MM-dd_HH-mm-ss}", DateTime.Now);
                        string filename = Path.Combine(path, time + ".jpg");
                        bmp.Save(filename, ImageFormat.Jpeg);
                        screenshotflash = 5;
                        Log("Screenshot saved to the Screenshots folder");
                    }
                }
                if (e.Key == OpenTK.Input.Key.R)
                {
                    player.playerposition = game.PlayerPositionSpawn;
                    player.movedz = 0;
                }
                if (e.Key == OpenTK.Input.Key.P)
                {
                    game.PlayerPositionSpawn = player.playerposition;
                    player.playerposition = new Vector3((int)player.playerposition.X + 0.5f, player.playerposition.Y, (int)player.playerposition.Z + 0.5f);
                }
                if (e.Key == OpenTK.Input.Key.F)
                {
                    int[] drawDistances = { 32, 64, 128, 256, 512 };
                    for (int i = 0; i < drawDistances.Length; i++)
                    {
                        if (the3d.config3d.viewdistance == drawDistances[i])
                        {
                            the3d.config3d.viewdistance = drawDistances[(i + 1) % drawDistances.Length];
                            goto done;
                        }
                    }
                    the3d.config3d.viewdistance = drawDistances[0];
                done:
                    OnResize(new EventArgs());
                 }
                if (e.Key == OpenTK.Input.Key.B)
                {
                    //EscapeMenuWasFreemove = ENABLE_FREEMOVE;
                    guistate = GuiState.Inventory;
                    menustate = new MenuState();
                    FreeMouse = true;
                }
                HandleMaterialKeys(e);
                if (e.Key == OpenTK.Input.Key.Escape)
                {
                    GuiStateEscapeMenu();
                }
            }
            else if (guistate == GuiState.EscapeMenu)
            {
                int menuelements = 3;
                if (e.Key == OpenTK.Input.Key.Escape)
                {
                    escapemenuOptions = false;
                    GuiStateBackToGame();
                }
                if (e.Key == OpenTK.Input.Key.Up)
                {
                    menustate.selected--;
                    menustate.selected = Math.Max(0, menustate.selected);
                }
                if (e.Key == OpenTK.Input.Key.Down)
                {
                    menustate.selected++;
                    menustate.selected = Math.Min(menuelements - 1, menustate.selected);
                }
                if (menustate.selected != -1
                    && (e.Key == OpenTK.Input.Key.Enter || e.Key == OpenTK.Input.Key.KeypadEnter))
                {
                    EscapeMenuAction();
                }
                return;
            }
            else if (guistate == GuiState.MainMenu)
            {
                int menuelements = 3;
                if (e.Key == OpenTK.Input.Key.Escape)
                {
                    exit = true;
                    Exit();
                }
                if (e.Key == OpenTK.Input.Key.Up)
                {
                    menustate.selected--;
                    menustate.selected = Math.Max(0, menustate.selected);
                }
                if (e.Key == OpenTK.Input.Key.Down)
                {
                    menustate.selected++;
                    menustate.selected = Math.Min(menuelements - 1, menustate.selected);
                }
                if (e.Key == OpenTK.Input.Key.Enter || e.Key == OpenTK.Input.Key.KeypadEnter)
                {
                    MainMenuAction();
                }
                return;
            }
            else if (guistate == GuiState.Inventory)
            {
                if (e.Key == OpenTK.Input.Key.Escape)
                {
                    GuiStateBackToGame();
                }
                Direction4? dir = null;
                if (e.Key == OpenTK.Input.Key.Left) { dir = Direction4.Left; }
                if (e.Key == OpenTK.Input.Key.Right) { dir = Direction4.Right; }
                if (e.Key == OpenTK.Input.Key.Up) { dir = Direction4.Up; }
                if (e.Key == OpenTK.Input.Key.Down) { dir = Direction4.Down; }
                if (dir != null)
                {
                    InventorySelectionMove(dir.Value);
                }
                if (e.Key == OpenTK.Input.Key.Enter || e.Key == OpenTK.Input.Key.KeypadEnter)
                {
                    var sel = InventoryGetSelected();
                    if (sel != null)
                    {
                        materialSlots[activematerial] = sel.Value;
                        GuiStateBackToGame();
                    }
                }
                HandleMaterialKeys(e);
                return;
            }
            else if (guistate == GuiState.MapLoading)
            {
                DrawMapLoading();
            }
            else if (guistate == GuiState.CraftingRecipes)
            {
                if (e.Key == OpenTK.Input.Key.Escape)
                {
                    GuiStateBackToGame();
                }
            }
            else throw new Exception();
        }