public override void Update(GameTime gameTime) { int oldChoice = choice; if ((parentGui?.MouseClicked).HasValue && (parentGui?.MouseClicked).Value) { for (int k = 0; k < buttons.Length; k++) { if (MouseOverButton(parentGui.curMouse.X, parentGui.curMouse.Y, k)) { choice = k; break; } } } if (oldChoice != choice) { parentGui?.RefreshItems(); } }
public override void Update(GameTime gameTime) { cursorTimer++; cursorTimer %= 60; Rectangle dim = GUIHelper.GetFullRectangle(this); MouseState mouse = PlayerInput.MouseInfo; bool mouseOver = mouse.X > dim.X && mouse.X <dim.X + dim.Width && mouse.Y> dim.Y && mouse.Y < dim.Y + dim.Height; bool changed = false; string prev = text; if ((parentGui?.MouseClicked).HasValue && (parentGui?.MouseClicked).Value) { if (!hasFocus && mouseOver) { Main.blockInput = hasFocus = true; } else if (hasFocus && !mouseOver) { Main.blockInput = hasFocus = false; cursorPosition = text.Length; } } else if (parentGui.curMouse.RightButton == ButtonState.Pressed && parentGui.oldMouse.RightButton == ButtonState.Released && Parent != null && hasFocus && !mouseOver) { Main.blockInput = hasFocus = false; cursorPosition = text.Length; } else if (parentGui.curMouse.RightButton == ButtonState.Pressed && parentGui.oldMouse.RightButton == ButtonState.Released && mouseOver) { if (text.Length > 0) { text = string.Empty; cursorPosition = 0; changed = true; } } if (hasFocus) { PlayerInput.WritingText = true; Main.instance.HandleIME(); if (cursorPosition < text.Length && text.Length > 0) { prev = prev.Remove(cursorPosition); } string newString = Main.GetInputText(prev); if (!newString.Equals(prev)) { int newStringLength = newString.Length; if (prev != text) { newString += text.Substring(cursorPosition); } text = newString; cursorPosition = newStringLength; changed = true; } if (KeyTyped(Keys.Delete) && text.Length > 0 && cursorPosition <= text.Length - 1) { text = text.Remove(cursorPosition, 1); changed = true; } if (KeyTyped(Keys.Left) && cursorPosition > 0) { cursorPosition--; } if (KeyTyped(Keys.Right) && cursorPosition < text.Length) { cursorPosition++; } if (KeyTyped(Keys.Home)) { cursorPosition = 0; } if (KeyTyped(Keys.End)) { cursorPosition = text.Length; } if ((Main.keyState.IsKeyDown(Keys.LeftControl) || Main.keyState.IsKeyDown(Keys.RightControl)) && KeyTyped(Keys.Back)) { text = string.Empty; cursorPosition = 0; changed = true; } if ((Main.keyState.IsKeyDown(Keys.LeftControl) || Main.keyState.IsKeyDown(Keys.RightControl)) && KeyTyped(Keys.Delete)) { if (cursorPosition == text.Length) { return; } text = text.Remove(cursorPosition); changed = true; } if (changed) { parentGui.RefreshItems(); } if (KeyTyped(Keys.Enter) || KeyTyped(Keys.Tab) || KeyTyped(Keys.Escape)) { Main.blockInput = hasFocus = false; } } base.Update(gameTime); }