public override void Update(GameTime gameTime) { hoverSlot = -1; Vector2 origin = InterfaceHelper.GetFullRectangle(this).TopLeft(); MouseState curMouse = StorageGUI.curMouse; if (curMouse.X <= origin.X || curMouse.Y <= origin.Y) { return; } var inventoryBackTexture = TextureAssets.InventoryBack.Value; int slotWidth = (int)(inventoryBackTexture.Width * inventoryScale * Main.UIScale); int slotHeight = (int)(inventoryBackTexture.Height * inventoryScale * Main.UIScale); int slotX = (curMouse.X - (int)origin.X) / (slotWidth + padding); int slotY = (curMouse.Y - (int)origin.Y) / (slotHeight + padding); if (slotX < 0 || slotX >= numColumns || slotY < 0 || slotY >= numRows) { return; } Vector2 slotPos = origin + new Vector2(slotX * (slotWidth + padding * Main.UIScale), slotY * (slotHeight + padding * Main.UIScale)); if (curMouse.X > slotPos.X && curMouse.X < slotPos.X + slotWidth && curMouse.Y > slotPos.Y && curMouse.Y < slotPos.Y + slotHeight) { onHover(slotX + numColumns * slotY, ref hoverSlot); } }
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(); } else if (StorageGUI.curMouse.RightButton == ButtonState.Pressed && StorageGUI.oldMouse.RightButton == ButtonState.Released && mouseOver) { text = string.Empty; cursorPosition = 0; StorageGUI.RefreshItems(); } } if (hasFocus) { 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) || KeyTyped(Keys.Tab) || KeyTyped(Keys.Escape)) { hasFocus = false; CheckBlockInput(); } } base.Update(gameTime); }
private bool MouseOverButton(int mouseX, int mouseY, int button) { Rectangle dim = InterfaceHelper.GetFullRectangle(this); float left = dim.X + button * (buttonSize + buttonPadding) * Main.UIScale; float right = left + buttonSize * Main.UIScale; float top = dim.Y; float bottom = top + buttonSize * Main.UIScale; return(mouseX > left && mouseX < right && mouseY > top && mouseY < bottom); }
public override void Load() { if (ModLoader.version < requiredVersion) { throw new Exception("Magic storage requires a tModLoader version of at least " + requiredVersion); } Instance = this; InterfaceHelper.Initialize(); legendMod = ModLoader.GetMod("LegendOfTerraria3"); }
public static void Draw(TEStorageHeart heart) { Player player = Main.player[Main.myPlayer]; StoragePlayer modPlayer = player.GetModPlayer <StoragePlayer>(); Initialize(); if (Main.mouseX > panelLeft && Main.mouseX < panelLeft + panelWidth && Main.mouseY > panelTop && Main.mouseY < panelTop + panelHeight) { player.mouseInterface = true; player.showItemIcon = false; InterfaceHelper.HideItemIconCache(); } basePanel.Draw(Main.spriteBatch); slotZone.DrawText(); sortButtons.DrawText(); filterButtons.DrawText(); }
public static void Draw(TEStorageHeart heart) { Player player = Main.player[Main.myPlayer]; StoragePlayer modPlayer = player.GetModPlayer <StoragePlayer>(MagicStorage.Instance); Initialize(); if (Main.mouseX > panelLeft && Main.mouseX < panelLeft + panelWidth && Main.mouseY > panelTop && Main.mouseY < panelTop + panelHeight) { player.mouseInterface = true; player.showItemIcon = false; InterfaceHelper.HideItemIconCache(); } basePanel.Draw(Main.spriteBatch); float itemSlotWidth = Main.inventoryBackTexture.Width * inventoryScale; float itemSlotHeight = Main.inventoryBackTexture.Height * inventoryScale; Vector2 slotZonePos = slotZone.GetDimensions().Position(); float oldScale = Main.inventoryScale; Main.inventoryScale = inventoryScale; Item[] temp = new Item[11]; for (int k = 0; k < numColumns * displayRows; k++) { int index = k + numColumns * (int)Math.Round(scrollBar.ViewPosition); Item item = index < items.Count ? items[index] : new Item(); if (!item.IsAir && !didMatCheck[index]) { item.checkMat(); didMatCheck[index] = true; } Vector2 drawPos = slotZonePos + new Vector2((itemSlotWidth + padding) * (k % 10), (itemSlotHeight + padding) * (k / 10)); temp[10] = item; ItemSlot.Draw(Main.spriteBatch, temp, 0, 10, drawPos); } if (hoverSlot >= 0 && hoverSlot < items.Count) { Main.HoverItem = items[hoverSlot].Clone(); Main.instance.MouseText(string.Empty); } sortButtons.DrawText(); filterButtons.DrawText(); Main.inventoryScale = oldScale; }
private static void UpdateDepositButton() { Rectangle dim = InterfaceHelper.GetFullRectangle(depositButton); if (curMouse.X > dim.X && curMouse.X < dim.X + dim.Width && curMouse.Y > dim.Y && curMouse.Y < dim.Y + dim.Height) { depositButton.BackgroundColor = new Color(73, 94, 171); if (MouseClicked) { if (TryDepositAll()) { RefreshItems(); Main.PlaySound(7, -1, -1, 1); } } } else { depositButton.BackgroundColor = new Color(63, 82, 151) * 0.7f; } }
public static void Draw(TEStorageHeart heart) { Player player = Main.player[Main.myPlayer]; StoragePlayer modPlayer = player.GetModPlayer <StoragePlayer>(MagicStorage.Instance); Initialize(); if (Main.mouseX > panelLeft && Main.mouseX < panelLeft + panelWidth && Main.mouseY > panelTop && Main.mouseY < panelTop + panelHeight) { player.mouseInterface = true; player.showItemIcon = false; InterfaceHelper.HideItemIconCache(); } basePanel.Draw(Main.spriteBatch); float itemSlotWidth = Main.inventoryBackTexture.Width * inventoryScale; float itemSlotHeight = Main.inventoryBackTexture.Height * inventoryScale; Vector2 slotZonePos = slotZone.GetDimensions().Position(); float oldScale = Main.inventoryScale; Main.inventoryScale = inventoryScale; Item[] temp = new Item[11]; Item[] craftingStations = GetCraftingStations(); for (int k = 0; k < numColumns; k++) { temp[10] = craftingStations[k]; Vector2 drawPos = GetSlotPosition(k); ItemSlot.Draw(Main.spriteBatch, temp, 0, 10, drawPos); } if (hoverSlot >= 0 && hoverSlot < items.Count) { Main.HoverItem = items[hoverSlot].Clone(); Main.instance.MouseText(string.Empty); } sortButtons.DrawText(); filterButtons.DrawText(); Main.inventoryScale = oldScale; }
public override void ModifyInterfaceLayers(List <GameInterfaceLayer> layers) { InterfaceHelper.ModifyInterfaceLayers(layers); }
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); }