22 package com.realtime.crossfire.jxclient.items;
25 import java.util.ArrayList;
26 import java.util.Comparator;
27 import java.util.List;
28 import org.jetbrains.annotations.NotNull;
29 import org.jetbrains.annotations.Nullable;
60 private final List<CfItem>
items =
new ArrayList<>();
73 @SuppressWarnings(
"FieldCanBeLocal")
77 public void itemAdded(@NotNull
final CfItem item) {
82 public void itemMoved(@NotNull
final CfItem item) {
87 public void itemChanged(@NotNull
final CfItem item) {
92 public void itemRemoved(@NotNull
final CfItem item) {
97 public void playerChanged(@Nullable
final CfItem player) {
102 public void openContainerChanged(
final int tag) {
115 public void itemChanged(
final int tag) {
120 public void itemRemoved(
final int tag) {
125 public void inventoryAdded(
final int tag,
final int index, @NotNull
final CfItem item) {
129 mapping.
insert(index2, index);
130 items.add(index2, item);
135 public void inventoryRemoved(
final int tag,
final int index) {
138 final int index2 = mapping.
getSrc(index);
140 items.remove(index2);
155 final CfItem player = itemSet.getPlayer();
156 currentPlayerTag = player == null ? -1 : player.
getTag();
165 if (this.currentPlayerTag == -1) {
173 if (this.currentPlayerTag == -1) {
182 if (currentPlayerTag != -1) {
183 for (
int i = 0; i < nextSize; i++) {
186 playerInventoryListener.
inventoryAdded(currentPlayerTag, i, item);
211 return items.get(index);
212 }
catch (
final IndexOutOfBoundsException ignored) {
224 for (i = 0; i < items.size(); i++) {
225 if (comparator.compare(items.get(i), item) >= 0) {
int findInsertionIndex(@NotNull final CfItem item)
Returns the insertion index of a CfItem.
CfItem getItem(final int index)
Returns the CfItem in a given slot.the slot index the item ornull if the slot is empty ...
CfItem getInventoryItem(final int tag, final int index)
Returns a CfItem from the inventory of an item.
Provides a view of all items in the current player's inventory.
int currentPlayerTag
The tag of the current player object or.
void clear()
Removes all mappings.
int getNumberOfItemsByLocation(final int location)
Returns the number of items in a given location.
final ItemListener playerInventoryListener
The ItemListener attached to the current player object.
Interface for listeners for changes of item locations.
final ItemSetListener itemSetListener
The ItemSetListener attached to itemSet to track the current player object.
final List< CfItem > items
The items in the inventory ordered by comparator.
int getSrc(final int dst)
Returns a mapping.
final Comparator< CfItem > comparator
The Comparator for sorting.
void removeInventoryListener(final int tag, @NotNull final ItemListener listener)
Removes an ItemListener to be notified about changes.
InventoryView(@NotNull final ItemSet itemSet, @NotNull final Comparator< CfItem > comparator)
Creates a new instance.
Interface for listeners in ItemSet related events.
void inventoryAdded(int tag, int index, @NotNull CfItem item)
An inventory CfItem has been added to the watched item.
void addModifiedRange(final int firstIndex, final int lastIndex)
Marks a range of slots as modified.
void addInventoryListener(final int tag, @NotNull final ItemListener listener)
Adds an ItemListener to be notified about changes.
final DoubleMapping mapping
Maps external index to original index.
int getTag()
Returns the tag.
void insert(final int src, final int dst)
Adds a mapping.
final ItemSet itemSet
The ItemSet to monitor.
Maintains a bidirectional mapping from a set of integers to the same range of integers.
int getSize()
Returns the number of items.the number of items
Abstract base class for ItemView implementing classes.
Model class maintaining the CfItems known to the player.
void setCurrentPlayerTag(final int currentPlayerTag)
Updates the current player object.
void remove(final int src)
Removes a mapping.
The representation of a Crossfire Item, client-side.