v2.0.0: a bit of quickslot refactoring
This commit is contained in:
@@ -33,7 +33,7 @@ public class QuickSlot {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Slots contain objects which are also in a player's inventory. The one exception to this is when quantity is 0,
|
* Slots contain objects which are also in a player's inventory. The one exception to this is when quantity is 0,
|
||||||
* which can happen for a stackable item that has been 'used up', these are refered to a placeholders.
|
* which can happen for a stackable item that has been 'used up', these are referred to as placeholders.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//note that the current max size is coded at 6, due to UI constraints, but it could be much much bigger with no issue.
|
//note that the current max size is coded at 6, due to UI constraints, but it could be much much bigger with no issue.
|
||||||
@@ -59,12 +59,13 @@ public class QuickSlot {
|
|||||||
return slots[slot];
|
return slots[slot];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//utility methods, for easier use of the internal array.
|
//utility methods, for easier use of the internal array.
|
||||||
public int getSlot(Item item) {
|
public int getSlot(Item item) {
|
||||||
for (int i = 0; i < SIZE; i++)
|
for (int i = 0; i < SIZE; i++) {
|
||||||
if (getItem(i) == item)
|
if (getItem(i) == item) {
|
||||||
return i;
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,18 +78,21 @@ public class QuickSlot {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void clearItem(Item item){
|
public void clearItem(Item item){
|
||||||
if (contains(item))
|
if (contains(item)) {
|
||||||
clearSlot(getSlot(item));
|
clearSlot(getSlot(item));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean contains(Item item){
|
public boolean contains(Item item){
|
||||||
return getSlot(item) != -1;
|
return getSlot(item) != -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void replacePlaceholder(Item item){
|
public void replacePlaceholder(Item item) {
|
||||||
for (int i = 0; i < SIZE; i++)
|
for (int i = 0; i < SIZE; i++) {
|
||||||
if (isPlaceholder(i) && item.isSimilar(getItem(i)))
|
if (isPlaceholder(i) && item.isSimilar(getItem(i))) {
|
||||||
setSlot( i , item );
|
setSlot(i, item);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void convertToPlaceholder(Item item){
|
public void convertToPlaceholder(Item item){
|
||||||
@@ -106,10 +110,11 @@ public class QuickSlot {
|
|||||||
public Item randomNonePlaceholder(){
|
public Item randomNonePlaceholder(){
|
||||||
|
|
||||||
ArrayList<Item> result = new ArrayList<>();
|
ArrayList<Item> result = new ArrayList<>();
|
||||||
for (int i = 0; i < SIZE; i ++)
|
for (int i = 0; i < SIZE; i ++) {
|
||||||
if (getItem(i) != null && !isPlaceholder(i))
|
if (getItem(i) != null && !isPlaceholder(i)) {
|
||||||
result.add(getItem(i));
|
result.add(getItem(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
return Random.element(result);
|
return Random.element(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,11 +131,12 @@ public class QuickSlot {
|
|||||||
ArrayList<Item> placeholders = new ArrayList<>(SIZE);
|
ArrayList<Item> placeholders = new ArrayList<>(SIZE);
|
||||||
boolean[] placements = new boolean[SIZE];
|
boolean[] placements = new boolean[SIZE];
|
||||||
|
|
||||||
for (int i = 0; i < SIZE; i++)
|
for (int i = 0; i < SIZE; i++) {
|
||||||
if (isPlaceholder(i)) {
|
if (isPlaceholder(i)) {
|
||||||
placeholders.add(getItem(i));
|
placeholders.add(getItem(i));
|
||||||
placements[i] = true;
|
placements[i] = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
bundle.put( PLACEHOLDERS, placeholders );
|
bundle.put( PLACEHOLDERS, placeholders );
|
||||||
bundle.put( PLACEMENTS, placements );
|
bundle.put( PLACEMENTS, placements );
|
||||||
}
|
}
|
||||||
@@ -141,7 +147,9 @@ public class QuickSlot {
|
|||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (Bundlable item : placeholders){
|
for (Bundlable item : placeholders){
|
||||||
while (!placements[i]) i++;
|
while (!placements[i]){
|
||||||
|
i++;
|
||||||
|
}
|
||||||
setSlot( i, (Item)item );
|
setSlot( i, (Item)item );
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|||||||
+16
-2
@@ -250,12 +250,26 @@ public class QuickSlotButton extends Button {
|
|||||||
@Override
|
@Override
|
||||||
public void onSelect(Item item) {
|
public void onSelect(Item item) {
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
Dungeon.quickslot.setSlot( slotNum , item );
|
set( slotNum , item );
|
||||||
refresh();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public static void set(Item item){
|
||||||
|
for (int i = 0; i < instance.length; i++) {
|
||||||
|
if (select(i) == null || select(i) == item) {
|
||||||
|
set(i, item);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
set(0, item);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void set(int slotNum, Item item){
|
||||||
|
Dungeon.quickslot.setSlot( slotNum , item );
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
|
|
||||||
private static Item select(int slotNum){
|
private static Item select(int slotNum){
|
||||||
return Dungeon.quickslot.getItem( slotNum );
|
return Dungeon.quickslot.getItem( slotNum );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -172,8 +172,7 @@ public class Toolbar extends Component {
|
|||||||
@Override
|
@Override
|
||||||
public void onSelect(Item item) {
|
public void onSelect(Item item) {
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
Dungeon.quickslot.setSlot( idx , item );
|
QuickSlotButton.set(idx, item);
|
||||||
QuickSlotButton.refresh();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -329,8 +329,7 @@ public class WndBag extends WndTabbed {
|
|||||||
protected boolean onLongClick() {
|
protected boolean onLongClick() {
|
||||||
if (selector == null && item.defaultAction != null) {
|
if (selector == null && item.defaultAction != null) {
|
||||||
hide();
|
hide();
|
||||||
Dungeon.quickslot.setSlot( 0 , item );
|
QuickSlotButton.set( item );
|
||||||
QuickSlotButton.refresh();
|
|
||||||
return true;
|
return true;
|
||||||
} else if (selector != null) {
|
} else if (selector != null) {
|
||||||
Game.scene().addToFront(new WndInfoItem(item));
|
Game.scene().addToFront(new WndInfoItem(item));
|
||||||
|
|||||||
Reference in New Issue
Block a user