public void Update(GameTime gameTime) { if (base.Count == 0) { return; } foreach (Control control in this) { if (control.Enabled) { control.Update(gameTime); } if (control.HasFocus) { control.HandleInput(); } if (control is ItemHolder) { ItemHolder holder = control as ItemHolder; holder.UpdateMouse(); /* * if (holder.isMouseInside()) * { * holder.HasFocus = true; * } * else * { * holder.HasFocus = false; * } */ } } if (InputHandler.LeftButtonPressed()) { if (ClickItem != null) { ClickItem(this, null); } } }
public void OnSizeChange(Vector2 position, Vector2 size) { Vector2 holderPosition = position; Vector2 holderSize = new Vector2(size.X / COLUMNS, size.Y / ROWS); for (int y = 0; y < ROWS; y++) { holderPosition.X = position.X; for (int x = 0; x < COLUMNS; x++) { ItemHolder itemHolder = itemSlots[x, y]; itemHolder.Position = holderPosition; itemHolder.Size = holderSize; holderPosition.X += holderSize.X; } holderPosition.Y += holderSize.Y; } }
private void InitializeInventory(Vector2 position, Vector2 size, InventoryManager inventoryManager, ItemManager itemManager) { Vector2 holderPosition = position; Vector2 holderSize = new Vector2(size.X / COLUMNS, size.Y / ROWS); for (int y = 0; y < ROWS; y++) { holderPosition.X = position.X; for (int x = 0; x < COLUMNS; x++) { ItemHolder itemHolder = new ItemHolder(holderPosition, holderSize, itemManager); itemHolder.AcceptedItems.Add(ItemKind.ANY); itemHolder.Enabled = false; inventoryManager.Add(itemHolder); inventoryManager.ClickItem += itemHolder.OnClickItem; inventoryManager.RightClick += itemHolder.OnRightClick; inventoryManager.RightClickEquip += itemHolder.OnRightClickEquip; itemHolder.Changed += inventoryManager.OnChangedItemHolder; itemSlots[x, y] = itemHolder; holderPosition.X += holderSize.X; } holderPosition.Y += holderSize.Y; } }
public void Update(GameTime gameTime) { if (enabled) { if (base.Count == 0) { return; } foreach (Control control in this) { if (control.Enabled) { control.Update(gameTime); } if (control.HasFocus) { control.HandleInput(); } if (control is ItemHolder) { ItemHolder holder = control as ItemHolder; holder.UpdateMouse(); /* * if (holder.isMouseInside()) * { * holder.HasFocus = true; * } * else * { * holder.HasFocus = false; * } */ } } if (InputHandler.LeftButtonPressed()) { if (ClickItem != null) { changedHolders = 0; ClickItem(this, null); //If no ItemHolder was modified, fire an event //that checks whether draggedItem should be dropped/disposed of if ((changedHolders == 0) && (DisposeItem != null)) { DisposeItem(this, null); } } } if (InputHandler.RightButtonPressed()) { if (draggedItem != null) { if (draggedItemLastSpot != null && RightClick != null) { RightClick(this, null); } else if (RightClickNull != null) { RightClickNull(this, null); } } else { if (RightClickEquip != null) { RightClickEquip(this, null); } } } if (draggedItem != null) { draggedItem.Update(gameTime); if (draggedItem.IsBeingDragged) { Vector2 newPosition = new Vector2(InputHandler.MouseState.X - draggedItem.Size.X / 2, InputHandler.MouseState.Y - draggedItem.Size.Y / 2); draggedItem.SetPosition(newPosition); } } } }