Esempio n. 1
0
 private void SetDialogue(DialogueUI show, DialogueUI hide, string text)
 {
     show.ShowUI();
     hide.HideUI();
     show.Dialogue(text);
     typingState = TypingState.Typing;
 }
Esempio n. 2
0
        public static void AddChannel(string name, string id, int indexToggle, int indexId)
        {
            GlobalChannel chan = new GlobalChannel(name, id, indexToggle, indexId);

            Channels.Add(chan);

            TypingState state = new TypingState(id, false);

            TypingStates.Add(state);
        }
Esempio n. 3
0
    public static ClientTypingMessage Send(TypingState newState)
    {
        var msg = new ClientTypingMessage()
        {
            state = newState
        };

        msg.Send();
        return(msg);
    }
Esempio n. 4
0
        public static NetMessage Send(TypingState newState)
        {
            var msg = new NetMessage()
            {
                state = newState
            };

            Send(msg);
            return(msg);
        }
Esempio n. 5
0
        public static NetMessage Send(PlayerScript player, TypingState state)
        {
            var msg = new NetMessage()
            {
                state    = state,
                targetID = player.netId
            };

            var playerPos = player.transform.position;

            SendToNearbyPlayers(playerPos, msg);
            return(msg);
        }
Esempio n. 6
0
        public async Task SendTypingState(bool typing, ChatInfo chat = null)
        {
            EnsureChatActive();

            chat ??= ActiveChats.First();

            var typingState = new TypingState(
                chat.Key,
                typing
                );

            var mtypPacket = new EventPacket("_mtyp", typingState);

            await SendEventPacket(mtypPacket);
        }
Esempio n. 7
0
    public void NextLine()
    {
        if (activeLineIndex < dialogue.lines.Length)
        {
            DisplayLine();
        }
        else if (dialogue.inGameDialogue)
        {
            if (dialogue.getFreeRoam())
            {
                UIleft.HideUI();
                UIright.HideUI();

                activeLineIndex = 0;

                onDialogueOver(true, null);
            }
            else if (!dialogue.getFreeRoam())
            {
                UIleft.HideUI();
                UIright.HideUI();

                activeLineIndex = 0;
                eventParty      = dialogue.ghostParty;
                onDialogueOver(false, eventParty);
            }
        }
        else if (!dialogue.inGameDialogue)
        {
            speakerLeft.SetActive(false);
            speakerRight.SetActive(false);
            typingState  = TypingState.Finished;
            audio.volume = 0;
            StartCoroutine(scene.LoadNextScene(dialogue.nextSceneName));
        }
    }
Esempio n. 8
0
    // Update is called once per frame
    void Update()
    {
        if ((player.transform.position - transform.position).magnitude < 2 && Input.GetKeyDown(KeyCode.E))
        {
            if (!startedTalking)
            {
                if (player.currentQuest != null)
                {
                    if (player.currentQuest.type == IType.QuestType.TalkQuest && player.currentQuest.questTalkTarget == this && !player.currentQuest.hasTalkedToNPC)
                    {
                        player.currentQuest.hasTalkedToNPC = true;
                    }

                    bool questGiver    = false;
                    bool questcomplete = player.currentQuest.IsComplete();
                    if (player.currentQuest.npcGiver == this)
                    {
                        questGiver = true;
                    }

                    if ((player.currentQuest.type == IType.QuestType.TalkQuest && questcomplete) ||
                        (player.currentQuest.type == IType.QuestType.KillQuest && questGiver && questcomplete))
                    {
                        if (player.currentQuest.isLastQuest)
                        {
                            SayYouWin();
                        }
                        else
                        {
                            //turn in quest, go to next dialogue
                            TurnInQuest();
                            TalkTo();
                        }
                    }
                    else
                    {
                        SayGoAway();
                    }
                }
                else
                {
                    TalkTo();
                }
            }
        }
        if (startedTalking)
        {
            if (currentState == TypingState.IsTyping && Time.timeSinceLevelLoad - lastCharTime > delay)
            {
                PressEnterUI.SetActive(false);
                lastCharTime       = Time.timeSinceLevelLoad;
                dialogueText.text += convos[conversationIndex][messageIndex][currentCharIndex];
                currentCharIndex++;
                if (currentCharIndex >= convos[conversationIndex][messageIndex].Length)
                {
                    currentState = TypingState.MessageFinished;
                }
            }
            else if (currentState == TypingState.MessageFinished)
            {
                PressEnterUI.SetActive(true);
                if (Input.GetKeyDown(KeyCode.Return))
                {
                    currentCharIndex = 0;
                    messageIndex++;
                    if (messageIndex >= convos[conversationIndex].Count)
                    {
                        if (newQuests.Count > 0)
                        {
                            player.GetComponent <PlayerManager>().currentQuest = newQuests[0];
                            newQuests.RemoveAt(0);
                        }
                        EndDialogue();
                    }
                    dialogueText.text = "";
                    currentState      = TypingState.WaitingForMessage;
                }
            }

            else if (currentState == TypingState.WaitingForMessage)
            {
                if (conversationIndex >= 0 && conversationIndex < convos.Length)
                {
                    if (messageIndex >= 0 && messageIndex < convos[conversationIndex].Count)
                    {
                        currentState = TypingState.IsTyping;
                    }
                }
            }
        }
        else
        {
            if (goAway && Input.GetKeyDown(KeyCode.Return))
            {
                if (player.currentQuest != null)
                {
                    bool questGiver    = false;
                    bool questcomplete = player.currentQuest.IsComplete();
                    if (player.currentQuest.npcGiver == this)
                    {
                        questGiver = true;
                    }
                    if (player.currentQuest.isLastQuest && (player.currentQuest.type == IType.QuestType.TalkQuest && questcomplete) ||
                        (player.currentQuest.type == IType.QuestType.KillQuest && questGiver && questcomplete))
                    {
                        SceneManager.LoadScene("Menu");
                    }
                }
                EndTalkingEarly();
            }
        }

        if (player.inBattle)
        {
            EndTalkingEarly();
        }
    }
Esempio n. 9
0
 public ChatContentTyping(Account account, JID source, string sourceDisplayName, JID destination, TypingState state)
     : base(account, source, sourceDisplayName, destination)
 {
     m_TypingState = state;
 }
Esempio n. 10
0
 public void StopTyping()
 {
     GuiTyping = TypingState.None;
 }
Esempio n. 11
0
 public ChatContentTyping(Account account, JID source, string sourceDisplayName, JID destination, TypingState state)
     : base(account, source, sourceDisplayName, destination)
 {
     m_TypingState = state;
 }
Esempio n. 12
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();
 }
Esempio n. 13
0
        protected void AppendMessage(bool incoming, Message msg)
        {
            string iconPath = null;
            string from     = null;
            JID    fromJid  = null;

            if (msg.From == null)
            {
                from    = m_Account.UserDisplayName;
                fromJid = m_Account.Jid;
            }
            else
            {
                if (this is MucHandler)
                {
                    // FIXME: Abstract this...
                    var participant = ((MucHandler)this).Room.Participants[msg.From];
                    if (participant != null)
                    {
                        fromJid = (!String.IsNullOrEmpty(participant.RealJID)) ? participant.RealJID : participant.NickJID;
                        from    = participant.Nick;
                    }
                    else
                    {
                        fromJid = msg.From;
                        from    = msg.From.Resource;
                    }
                }
                else if (this is ChatHandler && ((ChatHandler)this).IsMucMessage)
                {
                    fromJid = msg.From;
                    from    = msg.From.Resource;
                }
                else
                {
                    fromJid = msg.From;
                    from    = m_Account.GetDisplayName(msg.From);
                }
            }

            foreach (XmlNode child in msg)
            {
                if (child.NamespaceURI == Namespace.ChatStates)
                {
                    TypingState state = TypingState.None;
                    if (child.LocalName == "active")
                    {
                        state = TypingState.Active;
                    }
                    else if (child.LocalName == "composing")
                    {
                        state = TypingState.Composing;
                    }
                    else if (child.LocalName == "paused")
                    {
                        state = TypingState.Paused;
                    }
                    else if (child.LocalName == "inactive")
                    {
                        state = TypingState.Inactive;
                    }
                    else if (child.LocalName == "gone")
                    {
                        state = TypingState.Gone;
                    }
                    else
                    {
                        Console.WriteLine(String.Format("Unknown chatstate from {0}: {1}", from, child.LocalName));
                    }

                    var typingContent = new ChatContentTyping(m_Account, fromJid, from, null, state);
                    OnNewContent(typingContent);
                }
            }

            if (msg.Body != null || msg.Html != null)
            {
                string body = null;

                if (!String.IsNullOrEmpty(msg.Html))
                {
                    body = HtmlSanitizer.Sanitize(msg.Html, true);
                }
                else
                {
                    body = Util.EscapeHtml(msg.Body);
                    body = Util.Linkify(body);
                    body = body.Replace("  ", " &nbsp;");
                    body = body.Replace("\t", " &nbsp;&nbsp;&nbsp;");
                    body = body.Replace("\r\n", "<br/>");
                    body = body.Replace("\n", "<br/>");
                }

                var guiService = ServiceManager.Get <GuiService>();
                foreach (var formatter in guiService.MessageDisplayFormatters)
                {
                    if (formatter.SupportsMessage(body, msg))
                    {
                        body = formatter.FormatMessage(body, msg);
                        if (formatter.StopAfter)
                        {
                            break;
                        }
                    }
                }

                DateTime date = DateTime.Now;

                var nsmgr = new XmlNamespaceManager(msg.OwnerDocument.NameTable);
                nsmgr.AddNamespace("delay", "jabber:x:delay");
                var delay = (XmlElement)msg.SelectSingleNode("delay:x", nsmgr);
                if (delay != null)
                {
                    string stamp = delay.GetAttribute("stamp");
                    // CCYYMMDDThh:mm:ss
                    date = DateTime.ParseExact(stamp, @"yyyyMMdd\THH:mm:ss", null).ToLocalTime();
                }

                var content = new ChatContentMessage(m_Account, fromJid, from, msg.To, date);
                content.IsOutgoing  = !incoming;
                content.MessageHtml = body;

                OnNewContent(content);
            }
        }
Esempio n. 14
0
 void ManicDiggerGameWindow_KeyPress(object sender, OpenTK.KeyPressEventArgs e)
 {
     if ((e.KeyChar == 't' || e.KeyChar == 'T') && GuiTyping == TypingState.None)
     {
         GuiTyping = TypingState.Typing;
         d_HudChat.GuiTypingBuffer = "";
         return;
     }
     if (GuiTyping == TypingState.Typing)
     {
         char c = e.KeyChar;
         if ((char.IsLetterOrDigit(c) || char.IsWhiteSpace(c)
             || char.IsPunctuation(c) || char.IsSeparator(c) || char.IsSymbol(c))
             && c != '\r' && c != '\t')
         {
             d_HudChat.GuiTypingBuffer += e.KeyChar;
         }
         if (c == '\t' && d_HudChat.GuiTypingBuffer.Trim() != "")
         {
             foreach (var k in players)
             {
                 if (k.Value.Type != PlayerType.Player)
                 {
                     continue;
                 }
                 if (k.Value.Name.StartsWith(d_HudChat.GuiTypingBuffer, StringComparison.InvariantCultureIgnoreCase))
                 {
                     d_HudChat.GuiTypingBuffer = k.Value.Name + ": ";
                     break;
                 }
             }
         }
     }
 }
Esempio n. 15
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();
        }
Esempio n. 16
0
 /// <summary>
 /// update the current Typing State.
 /// </summary>
 /// <param name="newState"></param>
 public void setCurrentState(TypingState newState)
 {
     currentTypingState = newState;
     timeOnStateChange  = Time.time;
 }
Esempio n. 17
0
 public void StartTyping()
 {
     GuiTyping = TypingState.Typing;
     IsTyping = true;
     GuiTypingBuffer = "";
     IsTeamchat = false;
 }
Esempio n. 18
0
 void ManicDiggerGameWindow_KeyPress(object sender, OpenTK.KeyPressEventArgs e)
 {
     if ((e.KeyChar == 't' || e.KeyChar=='T') && GuiTyping == TypingState.None)
     {
         GuiTyping = TypingState.Typing;
         GuiTypingBuffer = "";
         return;
     }
     if (GuiTyping == TypingState.Typing)
     {
         char c = e.KeyChar;
         if ((char.IsLetterOrDigit(c) || char.IsWhiteSpace(c)
             || char.IsPunctuation(c) || char.IsSeparator(c) || char.IsSymbol(c))
             && c != '\r')
         {
             GuiTypingBuffer += e.KeyChar;
         }
     }
 }
Esempio n. 19
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();
        }