Пример #1
0
 public override void PostUpdateInput()
 {
     if (!Main.instance.IsActive)
     {
         return;
     }
     StorageGUI.Update(null);
     CraftingGUI.Update(null);
 }
Пример #2
0
        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);
        }
Пример #3
0
        public override void Load()
        {
            Instance = this;

            if (!Main.dedServ)
            {
                UI = new UserInterface();

                StorageUI  = new StorageGUI();
                CraftingUI = new CraftingGUI();
            }
        }
Пример #4
0
        public override bool ShiftClickSlot(Item[] inventory, int context, int slot)
        {
            if (context != ItemSlot.Context.InventoryItem && context != ItemSlot.Context.InventoryCoin && context != ItemSlot.Context.InventoryAmmo)
            {
                return(false);
            }
            if (storageAccess.X < 0 || storageAccess.Y < 0)
            {
                return(false);
            }
            Item item = inventory[slot];

            if (item.favorited || item.IsAir)
            {
                return(false);
            }
            int oldType  = item.type;
            int oldStack = item.stack;

            if (StorageCrafting())
            {
                if (Main.netMode == 0)
                {
                    GetCraftingAccess().TryDepositStation(item);
                }
                else
                {
                    NetHelper.SendDepositStation(GetCraftingAccess().ID, item);
                    item.SetDefaults(0, true);
                }
            }
            else
            {
                if (Main.netMode == 0)
                {
                    GetStorageHeart().DepositItem(item);
                }
                else
                {
                    NetHelper.SendDeposit(GetStorageHeart().ID, item);
                    item.SetDefaults(0, true);
                }
            }
            if (item.type != oldType || item.stack != oldStack)
            {
                Main.PlaySound(7, -1, -1, 1, 1f, 0f);
                StorageGUI.RefreshItems();
            }
            return(true);
        }
Пример #5
0
        private static void ReceiveRefreshNetworkItems(BinaryReader reader)
        {
            int ent = reader.ReadInt32();

            if (Main.netMode == 2)
            {
                return;
            }

            if (!TileEntity.ByID.TryGetValue(ent, out _))
            {
                //Nothing would've happened anyway
                return;
            }

            StorageGUI.RefreshItems();
        }
Пример #6
0
        public static void HandlePacket(BinaryReader reader, int sender)
        {
            MessageType type = (MessageType)reader.ReadByte();

            if (type == MessageType.SearchAndRefreshNetwork)
            {
                ReceiveSearchAndRefresh(reader);
            }
            else if (type == MessageType.TryStorageOperation)
            {
                ReceiveStorageOperation(reader, sender);
            }
            else if (type == MessageType.StorageOperationResult)
            {
                ReceiveOperationResult(reader);
            }
            else if (type == MessageType.RefreshNetworkItems)
            {
                StorageGUI.RefreshItems();
            }
            else if (type == MessageType.ClientSendTEUpdate)
            {
                ReceiveClientSendTEUpdate(reader, sender);
            }
            else if (type == MessageType.TryStationOperation)
            {
                ReceiveStationOperation(reader, sender);
            }
            else if (type == MessageType.StationOperationResult)
            {
                ReceiveStationResult(reader);
            }
            else if (type == MessageType.ResetCompactStage)
            {
                ReceiveResetCompactStage(reader);
            }
            else if (type == MessageType.CraftRequest)
            {
                ReceiveCraftRequest(reader, sender);
            }
            else if (type == MessageType.CraftResult)
            {
                ReceiveCraftResult(reader);
            }
        }
Пример #7
0
        public override void Update(GameTime gameTime)
        {
            int oldChoice = choice;

            if (StorageGUI.MouseClicked && Parent != null)
            {
                for (int k = 0; k < buttons.Length; k++)
                {
                    if (MouseOverButton(StorageGUI.curMouse.X, StorageGUI.curMouse.Y, k))
                    {
                        choice = k;
                        break;
                    }
                }
            }
            if (oldChoice != choice)
            {
                StorageGUI.RefreshItems();
            }
        }
Пример #8
0
        public override void ModifyTooltips(Item item, List <TooltipLine> tooltips)
        {
            var modLoaderMod = ModLoader.GetMod("ModLoader");

            if (item.modItem != null && !item.Name.Contains("[" + item.modItem.mod.Name + "]") && !item.Name.Contains("[" + item.modItem.mod.DisplayName + "]"))
            {
                string text  = (item.modItem.mod.Name + ":" + item.modItem.Name);
                var    line1 = new TooltipLine(mod, mod.Name, "[" + text + "]");
                line1.overrideColor = Colors.RarityBlue;
                tooltips.Add(line1);
            }
            int itemCount = StorageGUI.ItemCount(item.type);

            if (itemCount >= 0)
            {
                var itemCountTip = new TooltipLine(mod, mod.Name, "In storage:" + itemCount);
                itemCountTip.overrideColor = Color.Yellow;
                tooltips.Add(itemCountTip);
            }
        }
Пример #9
0
 public void OpenStorage(Point16 point, bool remote = false)
 {
     storageAccess = point;
     remoteAccess  = remote;
     StorageGUI.RefreshItems();
 }
Пример #10
0
        public override void Update(GameTime gameTime)
        {
            cursorTimer++;
            cursorTimer %= 60;

            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 (StorageGUI.MouseClicked && Parent != null)
            {
                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 && !mouseOver)
            {
                hasFocus       = false;
                cursorPosition = text.Length;
                CheckBlockInput();
            }
            else if (StorageGUI.curMouse.RightButton == ButtonState.Pressed && StorageGUI.oldMouse.RightButton == ButtonState.Released && mouseOver)
            {
                if (text.Length > 0)
                {
                    text           = string.Empty;
                    cursorPosition = 0;
                }
            }

            if (hasFocus)
            {
                PlayerInput.WritingText = true;
                Main.instance.HandleIME();
                string prev = text;

                if (cursorPosition < text.Length && text.Length > 0)
                {
                    prev = prev.Remove(cursorPosition);
                }

                string newString = Main.GetInputText(prev);
                bool   changed   = false;

                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 (changed)
                {
                    StorageGUI.RefreshItems();
                }

                if (KeyTyped(Keys.Enter) || KeyTyped(Keys.Tab) || KeyTyped(Keys.Escape))
                {
                    hasFocus = false;
                    CheckBlockInput();
                }
            }
            base.Update(gameTime);
        }
Пример #11
0
 public void OpenStorage(Point16 point)
 {
     storageAccess = point;
     StorageGUI.RefreshItems();
 }
Пример #12
0
 public override void PostUpdateInput()
 {
     StorageGUI.Update(null);
     CraftingGUI.Update(null);
 }
Пример #13
0
        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)
            {
                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 && Parent != null && hasFocus)
                {
                    hasFocus       = false;
                    cursorPosition = text.Length;
                    CheckBlockInput();
                }
                if (mouseOver)
                {
                    Reset();
                    StorageGUI.RefreshItems();
                    hasFocus = true;
                }
            }

            if (hasFocus)
            {
                PlayerInput.WritingText = true;
                Main.instance.HandleIME();
                string newString = Main.GetInputText(text);
                if ((Main.keyState.IsKeyDown(Keys.LeftControl) || Main.keyState.IsKeyDown(Keys.RightControl)) && KeyTyped(Keys.Back))
                {
                    newString = string.Empty;
                }
                if (!newString.Equals(text))
                {
                    text           = newString;
                    cursorPosition = text.Length;
                    StorageGUI.RefreshItems();
                }
                if (KeyTyped(Keys.Enter) || KeyTyped(Keys.Tab) || KeyTyped(Keys.Escape))
                {
                    hasFocus = false;
                    CheckBlockInput();
                }
            }
            base.Update(gameTime);
        }