-
Notifications
You must be signed in to change notification settings - Fork 1
Player Inventory Display
The Player Inventory Display class is an extension of the Inventory Display class, specifically designed to add extra functionality such as a hotbar and drag-and-drop features. It manages the display of items in a player's inventory and provides enhanced functionality for potion usage and combat-specific inventory management.
- Hotbar Management: Integrates a hotbar system for easy access to items.
- Drag-and-Drop Functionality: Adds support for drag-and-drop operations between inventory slots.
- Timed Potion Effects: Manages the usage of potions over time, especially during combat.
- Contextual Item Descriptions: Displays detailed information about items when hovered over.
- Combat Item Restrictions: Prevents the use of combat-restricted items outside of combat.
-
ArrayList<TimedUseItem> potions
: Stores active potions with timed effects. These items are updated or removed based on the player's context (combat or non-combat).
-
Parameters:
-
inventory
: The player's inventory. -
numCols
: Number of columns to display in the inventory UI. -
hotBarCapacity
: The maximum number of items allowed in the hotbar.
-
-
Description: Initializes the
PlayerInventoryDisplay
with an inventory, setting up the hotbar and basic inventory display configuration.
-
Description: Updates the status of all active potions, applying their effects or removing them when necessary.
-
Parameters:
-
context
: Provides the current context of item usage, such as whether the player is in combat or not.
-
-
Notes:
- Removes potions that are no longer active or are restricted to combat.
- Ensures potion effects are updated every time the inventory display is regenerated.
-
Description: Attempts to use an item and trigger its effects. If the item is a
TimedUseItem
, it is added to the list of active potions. -
Parameters:
-
item
: The item to be used. -
index
: The index of the item in the inventory.
-
-
Notes: This method is triggered whenever an item is used, and it ensures that the item's effects are applied and the necessary events are fired.
-
Description: Displays the description or warning of an item when the user hovers over it.
-
Parameters:
-
item
: The item being hovered over.
-
-
Notes:
- Handles special cases for specific items like
DefensePotion
andAttackPotion
by displaying their warnings. - Uses the
DialogueBoxService
to update the item description overlay.
- Handles special cases for specific items like
- Description: Hides the item description when the cursor leaves the inventory slot.
-
Parameters:
-
item
: The item that was being hovered over.
-
- Description: Regenerates the entire inventory display. Also updates the status of active potions.
- Notes: This method is useful when a refresh of the UI is required (e.g., when new items are added to the inventory).
-
Description: Attempts to use a combat-specific item. If the player is not in combat, the item usage is prevented.
-
Parameters:
-
item
: The item to be used. -
context
: The context of item usage (combat or non-combat). -
index
: The index of the item in the inventory.
-
-
Notes: If the item is flagged as a "combat-only" item, it will log a warning and prevent usage outside of combat.
- itemUsed: Triggered whenever an item is used by the player.
Class: PlayerFactory
Function: createPlayer
// Add inventory from player
InventoryComponent inventoryComponent = new InventoryComponent(50);
player.addComponent(inventoryComponent)
.addComponent(new PlayerInventoryDisplay(inventoryComponent.getInventory(), 9, 5))
.addComponent(new LootBoxOverlayComponent());
player.addComponent(new AchievementPopup());