blushiemagic / MagicStorage

A tModLoader mod for Terraria
MIT License
178 stars 101 forks source link

Can we support the search from Chinese? #25

Closed sherlockHlb closed 7 years ago

sherlockHlb commented 7 years ago

PLESE。。

JKstring commented 7 years ago

你可以将 MagicStorage\UISearchBar.cs 里的public override void Update(GameTime gameTime) 函数修改为

public override void Update(GameTime gameTime)
{
    cursorTimer++;
    cursorTimer %= 60;

    if (StorageGUI.MouseClicked && Parent != null)
    {
        Rectangle dim = InterfaceHelper.GetFullRectangle(this);
        MouseState mouse = StorageGUI.curMouse;
        bool mouseOver = mouse.X > dim.X && mouse.X < dim.X + dim.Width && mouse.Y > dim.Y && mouse.Y < dim.Y + dim.Height;
        if (!hasFocus && mouseOver)
        {
            hasFocus = true;
            CheckBlockInput();
        }
        else if (hasFocus && !mouseOver)
        {
            hasFocus = false;
            CheckBlockInput();
            cursorPosition = text.Length;
        }
    }
    else if (StorageGUI.curMouse.RightButton == ButtonState.Pressed && StorageGUI.oldMouse.RightButton == ButtonState.Released && Parent != null && hasFocus)
    {
        Rectangle dim = InterfaceHelper.GetFullRectangle(this);
        MouseState mouse = StorageGUI.curMouse;
        bool mouseOver = mouse.X > dim.X && mouse.X < dim.X + dim.Width && mouse.Y > dim.Y && mouse.Y < dim.Y + dim.Height;
        if (!mouseOver)
        {
            hasFocus = false;
            cursorPosition = text.Length;
            CheckBlockInput();
        }
    }

    if (hasFocus)
    {
        Terraria.GameInput.PlayerInput.WritingText = true;
        Main.instance.HandleIME();
        string newString = Main.GetInputText(text);
        if (!newString.Equals(text))
        {
            text = newString;
            cursorPosition = text.Length;
            StorageGUI.RefreshItems();
        }
        if (KeyTyped(Keys.Enter))
        {
            Main.drawingPlayerChat = false;
            hasFocus = false;
            CheckBlockInput();
        }
        cursorTimer = 0;
    }
    base.Update(gameTime);
}

来支持输入法,但是我并不能保证没有BUG,目前我用着还正常