Esempio n. 1
0
        ////////////////

        private void UpdateInteractivity()
        {
            if (this.HasFocus)
            {
                // Hackish:
                if (Main.drawingPlayerChat)
                {
                    Main.drawingPlayerChat = false;
                    Main.chatText          = "";
                    Main.chatRelease       = false;
                }
                if (!this.IsInteractive || !UILibraries.IsUIAvailable(keyboardNotInVanillaUI: true))
                {
                    this.Unfocus();
                    return;
                }
                if (UILibraries.JustPressedKey(Keys.Escape) || UILibraries.JustPressedKey(Keys.Enter))
                {
                    this.Unfocus();
                    return;
                }
            }

            CalculatedStyle dim = this.GetDimensions();

            // Detect if user selects this element
            if (Main.mouseLeft)
            {
                bool isNowSelected = false;

                if (Main.mouseX >= dim.X && Main.mouseX < (dim.X + dim.Width))
                {
                    if (Main.mouseY >= dim.Y && Main.mouseY < (dim.Y + dim.Height))
                    {
                        isNowSelected = true;
                        Main.keyCount = 0;
                    }
                }

                if (this.HasFocus && !isNowSelected)
                {
                    // Delay Unfocus (lets Update (Draw?) code finish, first)
                    Timers.RunNow(() => { this.Unfocus(); });
                    return;
                }

                this.HasFocus = isNowSelected;
            }

            if (this.HasFocus)
            {
                this.UpdateInput();
            }
        }
        ////////////////

        internal static void UpdateDisplay()
        {
            if (!ReadableBookItem.IsDisplayingNote)
            {
                return;
            }

            bool uiAvailable = UILibraries.IsUIAvailable(
                //mouseNotInUse: true,
                playerAvailable: true,
                playerNotTalkingToNPC: true,
                noFullscreenMap: true
                );

            if (Main.gameMenu || Main.playerInventory || !uiAvailable)
            {
                ReadableBookItem.IsDisplayingNote = false;
                ReadableBookItem.ClearDisplay();
            }
        }
Esempio n. 3
0
        ////////////////

        private void UpdateFocus()
        {
            if (this.HasFocus)
            {
                if (!this.IsInteractive || !UILibraries.IsUIAvailable(keyboardNotInVanillaUI: true))
                {
                    this.Unfocus();
                    return;
                }
                if (UILibraries.JustPressedKey(Keys.Escape) || UILibraries.JustPressedKey(Keys.Enter))
                {
                    this.Unfocus();
                    return;
                }

                Main.blockInput = true;                 // Force the point!

                this.CursorAnimation++;

                PlayerInput.WritingText = true;
                Main.instance.HandleIME();

                string newText = Main.GetInputText(this.Text);

                if (!newText.Equals(this.Text))
                {
                    this.SetTextWithValidation(newText);
                }
            }

            if (this.HasFocus)
            {
                var mouse = new Vector2(Main.mouseX, Main.mouseY);
                if (!this.ContainsPoint(mouse) && Main.mouseLeft)
                {
                    this.Unfocus();
                }
            }
        }