BeltGrid will no longer allow non poti item types

BeltGrid will no longer allow non poti item types
Added support for ItemGrid to reject an item type
This commit is contained in:
Collin Smith 2019-04-01 02:57:49 -07:00
parent 8010dd9c4e
commit df40ff5acd
2 changed files with 38 additions and 21 deletions

View File

@ -6,6 +6,8 @@ import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Touchable; import com.badlogic.gdx.scenes.scene2d.Touchable;
import com.badlogic.gdx.utils.SnapshotArray; import com.badlogic.gdx.utils.SnapshotArray;
import com.riiablo.item.Item;
import com.riiablo.item.Type;
import com.riiablo.screen.GameScreen; import com.riiablo.screen.GameScreen;
public class BeltGrid extends ItemGrid { public class BeltGrid extends ItemGrid {
@ -28,6 +30,11 @@ public class BeltGrid extends ItemGrid {
this.background = background; this.background = background;
} }
@Override
protected boolean accept(Item item) {
return item != null && item.type.is(Type.POTI);
}
public void setRows(int rows) { public void setRows(int rows) {
if (this.rows != rows) { if (this.rows != rows) {
this.rows = rows; this.rows = rows;

View File

@ -120,6 +120,10 @@ public class ItemGrid extends Group {
return store; return store;
} }
protected boolean accept(Item item) {
return true;
}
private void mouseMoved() { private void mouseMoved() {
swap = null; swap = null;
blocked = true; blocked = true;
@ -188,12 +192,12 @@ public class ItemGrid extends Group {
switch (hits.size) { switch (hits.size) {
case 0: case 0:
blocked = false; blocked = !accept(cursor);
swap = null; swap = null;
break; break;
case 1: case 1:
blocked = false; blocked = !accept(cursor);
swap = (StoredItem) hits.first(); swap = (StoredItem) hits.first();
break; break;
@ -207,8 +211,13 @@ public class ItemGrid extends Group {
protected void drawChildren(Batch batch, float parentAlpha) { protected void drawChildren(Batch batch, float parentAlpha) {
super.drawChildren(batch, parentAlpha); super.drawChildren(batch, parentAlpha);
mouseMoved(); mouseMoved();
if (Riiablo.cursor.getItem() != null && clickListener.isOver()) { Item cursor = Riiablo.cursor.getItem();
if (cursor != null && clickListener.isOver()) {
PaletteIndexedBatch b = (PaletteIndexedBatch) batch; PaletteIndexedBatch b = (PaletteIndexedBatch) batch;
if (!accept(cursor)) {
b.setBlendMode(BlendMode.SOLID, backgroundColorR);
b.draw(fill, coords.x, coords.y, itemSize.x, itemSize.y);
} else {
switch (hits.size) { switch (hits.size) {
case 0: case 0:
b.setBlendMode(BlendMode.SOLID, backgroundColorG); b.setBlendMode(BlendMode.SOLID, backgroundColorG);
@ -230,6 +239,7 @@ public class ItemGrid extends Group {
b.flush(); b.flush();
clipEnd(); clipEnd();
} }
}
b.resetBlendMode(); b.resetBlendMode();
} }
} }