v1.2.0: added listener functionality to inventory pane
This commit is contained in:
parent
c80f89133a
commit
58eb2242f4
|
@ -104,6 +104,7 @@ public class Shopkeeper extends NPC {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static WndBag sell() {
|
public static WndBag sell() {
|
||||||
|
//FIXME currently doesn't allow for repeated sales on new inventory pane
|
||||||
return GameScene.selectItem( itemSelector );
|
return GameScene.selectItem( itemSelector );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -89,6 +89,7 @@ public class Alchemize extends Spell {
|
||||||
@Override
|
@Override
|
||||||
public void onSelect( Item item ) {
|
public void onSelect( Item item ) {
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
|
//FIXME currently doesn't allow for repeated alchemizes on new inventory pane
|
||||||
WndBag parentWnd = GameScene.selectItem( itemSelector );
|
WndBag parentWnd = GameScene.selectItem( itemSelector );
|
||||||
GameScene.show( new WndAlchemizeItem( item, parentWnd ) );
|
GameScene.show( new WndAlchemizeItem( item, parentWnd ) );
|
||||||
}
|
}
|
||||||
|
@ -214,8 +215,10 @@ public class Alchemize extends Spell {
|
||||||
Sample.INSTANCE.play(Assets.Sounds.TELEPORT);
|
Sample.INSTANCE.play(Assets.Sounds.TELEPORT);
|
||||||
if (curItem.quantity() <= 1){
|
if (curItem.quantity() <= 1){
|
||||||
curItem.detachAll(Dungeon.hero.belongings.backpack);
|
curItem.detachAll(Dungeon.hero.belongings.backpack);
|
||||||
owner.hide();
|
if (owner != null) {
|
||||||
owner = null;
|
owner.hide();
|
||||||
|
owner = null;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
curItem.detach(Dungeon.hero.belongings.backpack);
|
curItem.detach(Dungeon.hero.belongings.backpack);
|
||||||
}
|
}
|
||||||
|
|
|
@ -370,21 +370,6 @@ public class GameScene extends PixelScene {
|
||||||
boss.setPos( 6 + (uiCamera.width - boss.width())/2, 20);
|
boss.setPos( 6 + (uiCamera.width - boss.width())/2, 20);
|
||||||
add(boss);
|
add(boss);
|
||||||
|
|
||||||
toolbar = new Toolbar();
|
|
||||||
toolbar.camera = uiCamera;
|
|
||||||
|
|
||||||
if (uiSize == 2) {
|
|
||||||
inventory = new InventoryPane();
|
|
||||||
inventory.camera = uiCamera;
|
|
||||||
inventory.setPos(uiCamera.width - inventory.width(), uiCamera.height - inventory.height());
|
|
||||||
add(inventory);
|
|
||||||
|
|
||||||
toolbar.setRect( 0, uiCamera.height - toolbar.height() - inventory.height(), uiCamera.width, toolbar.height() );
|
|
||||||
} else {
|
|
||||||
toolbar.setRect( 0, uiCamera.height - toolbar.height(), uiCamera.width, toolbar.height() );
|
|
||||||
}
|
|
||||||
add( toolbar );
|
|
||||||
|
|
||||||
attack = new AttackIndicator();
|
attack = new AttackIndicator();
|
||||||
attack.camera = uiCamera;
|
attack.camera = uiCamera;
|
||||||
add( attack );
|
add( attack );
|
||||||
|
@ -406,6 +391,21 @@ public class GameScene extends PixelScene {
|
||||||
log.newLine();
|
log.newLine();
|
||||||
add( log );
|
add( log );
|
||||||
|
|
||||||
|
toolbar = new Toolbar();
|
||||||
|
toolbar.camera = uiCamera;
|
||||||
|
add( toolbar );
|
||||||
|
|
||||||
|
if (uiSize == 2) {
|
||||||
|
inventory = new InventoryPane();
|
||||||
|
inventory.camera = uiCamera;
|
||||||
|
inventory.setPos(uiCamera.width - inventory.width(), uiCamera.height - inventory.height());
|
||||||
|
add(inventory);
|
||||||
|
|
||||||
|
toolbar.setRect( 0, uiCamera.height - toolbar.height() - inventory.height(), uiCamera.width, toolbar.height() );
|
||||||
|
} else {
|
||||||
|
toolbar.setRect( 0, uiCamera.height - toolbar.height(), uiCamera.width, toolbar.height() );
|
||||||
|
}
|
||||||
|
|
||||||
layoutTags();
|
layoutTags();
|
||||||
|
|
||||||
switch (InterlevelScene.mode) {
|
switch (InterlevelScene.mode) {
|
||||||
|
@ -736,7 +736,7 @@ public class GameScene extends PixelScene {
|
||||||
toDestroy.clear();
|
toDestroy.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Point lastOffset = null;
|
public static Point lastOffset = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized Gizmo erase (Gizmo g) {
|
public synchronized Gizmo erase (Gizmo g) {
|
||||||
|
@ -1196,11 +1196,18 @@ public class GameScene extends PixelScene {
|
||||||
public static WndBag selectItem( WndBag.ItemSelector listener ) {
|
public static WndBag selectItem( WndBag.ItemSelector listener ) {
|
||||||
cancelCellSelector();
|
cancelCellSelector();
|
||||||
|
|
||||||
WndBag wnd = WndBag.getBag( listener );
|
if (scene != null) {
|
||||||
|
if (scene.inventory != null && scene.inventory.visible){
|
||||||
|
scene.inventory.setSelector(listener);
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
WndBag wnd = WndBag.getBag( listener );
|
||||||
|
show(wnd);
|
||||||
|
return wnd;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (scene != null) scene.addToFront( wnd );
|
return null;
|
||||||
|
|
||||||
return wnd;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean cancel() {
|
public static boolean cancel() {
|
||||||
|
|
|
@ -30,11 +30,13 @@ import com.shatteredpixel.shatteredpixeldungeon.items.bags.MagicalHolster;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.items.bags.PotionBandolier;
|
import com.shatteredpixel.shatteredpixeldungeon.items.bags.PotionBandolier;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.items.bags.ScrollHolder;
|
import com.shatteredpixel.shatteredpixeldungeon.items.bags.ScrollHolder;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.items.bags.VelvetPouch;
|
import com.shatteredpixel.shatteredpixeldungeon.items.bags.VelvetPouch;
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
|
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
|
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag;
|
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.windows.WndUseItem;
|
import com.shatteredpixel.shatteredpixeldungeon.windows.WndUseItem;
|
||||||
import com.watabou.gltextures.TextureCache;
|
import com.watabou.gltextures.TextureCache;
|
||||||
|
import com.watabou.input.PointerEvent;
|
||||||
import com.watabou.noosa.BitmapText;
|
import com.watabou.noosa.BitmapText;
|
||||||
import com.watabou.noosa.ColorBlock;
|
import com.watabou.noosa.ColorBlock;
|
||||||
import com.watabou.noosa.Game;
|
import com.watabou.noosa.Game;
|
||||||
|
@ -42,6 +44,7 @@ import com.watabou.noosa.Image;
|
||||||
import com.watabou.noosa.NinePatch;
|
import com.watabou.noosa.NinePatch;
|
||||||
import com.watabou.noosa.PointerArea;
|
import com.watabou.noosa.PointerArea;
|
||||||
import com.watabou.noosa.ui.Component;
|
import com.watabou.noosa.ui.Component;
|
||||||
|
import com.watabou.utils.Point;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
@ -50,6 +53,9 @@ public class InventoryPane extends Component {
|
||||||
private NinePatch bg;
|
private NinePatch bg;
|
||||||
private NinePatch bg2; //2 backgrounds to reduce transparency
|
private NinePatch bg2; //2 backgrounds to reduce transparency
|
||||||
|
|
||||||
|
//used to prevent clicks through the BG normally, or to cancel selectors if they're enabled
|
||||||
|
private PointerArea blocker;
|
||||||
|
|
||||||
private static InventoryPane instance;
|
private static InventoryPane instance;
|
||||||
|
|
||||||
private ArrayList<InventorySlot> equipped;
|
private ArrayList<InventorySlot> equipped;
|
||||||
|
@ -59,6 +65,7 @@ public class InventoryPane extends Component {
|
||||||
private BitmapText goldTxt;
|
private BitmapText goldTxt;
|
||||||
private Image energy;
|
private Image energy;
|
||||||
private BitmapText energyTxt;
|
private BitmapText energyTxt;
|
||||||
|
private RenderedTextBlock promptTxt;
|
||||||
|
|
||||||
private ArrayList<BagButton> bags;
|
private ArrayList<BagButton> bags;
|
||||||
|
|
||||||
|
@ -68,6 +75,8 @@ public class InventoryPane extends Component {
|
||||||
private static final int SLOT_WIDTH = 17;
|
private static final int SLOT_WIDTH = 17;
|
||||||
private static final int SLOT_HEIGHT = 24;
|
private static final int SLOT_HEIGHT = 24;
|
||||||
|
|
||||||
|
private WndBag.ItemSelector selector;
|
||||||
|
|
||||||
public static Bag lastBag;
|
public static Bag lastBag;
|
||||||
|
|
||||||
private boolean lastEnabled = true;
|
private boolean lastEnabled = true;
|
||||||
|
@ -92,22 +101,34 @@ public class InventoryPane extends Component {
|
||||||
bg2 = Chrome.get(Chrome.Type.TOAST_TR);
|
bg2 = Chrome.get(Chrome.Type.TOAST_TR);
|
||||||
add(bg2);
|
add(bg2);
|
||||||
|
|
||||||
//blocks touches from going through BG into game scene
|
blocker = new PointerArea(0, 0, PixelScene.uiCamera.width, PixelScene.uiCamera.height){
|
||||||
add (new PointerArea(bg));
|
@Override
|
||||||
|
protected void onClick(PointerEvent event) {
|
||||||
|
if (selector != null){
|
||||||
|
selector = null;
|
||||||
|
updateInventory();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
blocker.target = bg; //targets bg when there is no selector, otherwise targets itself
|
||||||
|
add (blocker);
|
||||||
|
|
||||||
equipped = new ArrayList<>();
|
equipped = new ArrayList<>();
|
||||||
for (int i = 0; i < 5; i++){
|
for (int i = 0; i < 5; i++){
|
||||||
InventorySlot btn = new InventorySlot(null){
|
InventorySlot btn = new InventorySlot(null){
|
||||||
@Override
|
@Override
|
||||||
protected void onClick() {
|
protected void onClick() {
|
||||||
|
//any windows opened as a consequence of this button should be centered on the inventory
|
||||||
|
GameScene.lastOffset = new Point((int)InventoryPane.this.centerX() - camera.width/2,
|
||||||
|
(int)InventoryPane.this.centerY() - camera.height/2);
|
||||||
if (lastBag != item && !lastBag.contains(item) && !item.isEquipped(Dungeon.hero)){
|
if (lastBag != item && !lastBag.contains(item) && !item.isEquipped(Dungeon.hero)){
|
||||||
updateInventory();
|
updateInventory();
|
||||||
|
} else if (selector != null) {
|
||||||
|
selector.onSelect( item );
|
||||||
|
selector = null;
|
||||||
|
updateInventory();
|
||||||
} else {
|
} else {
|
||||||
Window w = new WndUseItem( null, item );
|
GameScene.show(new WndUseItem( null, item ));
|
||||||
w.offset( (int)InventoryPane.this.centerX() - camera.width/2,
|
|
||||||
(int)InventoryPane.this.centerY() - camera.height/2 );
|
|
||||||
w.boundOffsetWithMargin(3);
|
|
||||||
Game.scene().addToFront(w);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -127,28 +148,26 @@ public class InventoryPane extends Component {
|
||||||
energyTxt.hardlight(0x44CCFF);
|
energyTxt.hardlight(0x44CCFF);
|
||||||
add(energyTxt);
|
add(energyTxt);
|
||||||
|
|
||||||
|
promptTxt = PixelScene.renderTextBlock(6);
|
||||||
|
promptTxt.hardlight(Window.TITLE_COLOR);
|
||||||
|
add(promptTxt);
|
||||||
|
|
||||||
bagItems = new ArrayList<>();
|
bagItems = new ArrayList<>();
|
||||||
for (int i = 0; i < 20; i++){
|
for (int i = 0; i < 20; i++){
|
||||||
InventorySlot btn = new InventorySlot(null){
|
InventorySlot btn = new InventorySlot(null){
|
||||||
@Override
|
@Override
|
||||||
protected void onClick() {
|
protected void onClick() {
|
||||||
|
//any windows opened as a consequence of this button should be centered on the inventory
|
||||||
|
GameScene.lastOffset = new Point((int)InventoryPane.this.centerX() - camera.width/2,
|
||||||
|
(int)InventoryPane.this.centerY() - camera.height/2);
|
||||||
if (lastBag != item && !lastBag.contains(item) && !item.isEquipped(Dungeon.hero)){
|
if (lastBag != item && !lastBag.contains(item) && !item.isEquipped(Dungeon.hero)){
|
||||||
updateInventory();
|
updateInventory();
|
||||||
|
} else if (selector != null) {
|
||||||
|
selector.onSelect( item );
|
||||||
|
selector = null;
|
||||||
|
updateInventory();
|
||||||
} else {
|
} else {
|
||||||
Window w = new WndUseItem( null, item );
|
GameScene.show(new WndUseItem( null, item ));
|
||||||
int xOfs, yOfs;
|
|
||||||
if (w.height > InventoryPane.this.height - 15){
|
|
||||||
yOfs = (camera.height - w.height)/2 - 9;
|
|
||||||
} else {
|
|
||||||
yOfs = (int)(InventoryPane.this.y)/2;
|
|
||||||
}
|
|
||||||
if (w.width > InventoryPane.this.width - 15){
|
|
||||||
xOfs = (camera.width - w.width)/2 - 9;
|
|
||||||
} else {
|
|
||||||
xOfs = (int)(InventoryPane.this.x)/2;
|
|
||||||
}
|
|
||||||
w.offset(xOfs, yOfs);
|
|
||||||
Game.scene().addToFront(w);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -186,6 +205,13 @@ public class InventoryPane extends Component {
|
||||||
left = i.right()+1;
|
left = i.right()+1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
promptTxt.maxWidth((int) (width - (left - x) - bg.marginRight()));
|
||||||
|
if (promptTxt.height() > 10){
|
||||||
|
promptTxt.setPos(left, y + 2 + (12 - promptTxt.height()) / 2);
|
||||||
|
} else {
|
||||||
|
promptTxt.setPos(left, y + 4 + (10 - promptTxt.height()) / 2);
|
||||||
|
}
|
||||||
|
|
||||||
goldTxt.x = left;
|
goldTxt.x = left;
|
||||||
goldTxt.y = y+5.5f;
|
goldTxt.y = y+5.5f;
|
||||||
PixelScene.align(goldTxt);
|
PixelScene.align(goldTxt);
|
||||||
|
@ -224,6 +250,12 @@ public class InventoryPane extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateInventory(){
|
public void updateInventory(){
|
||||||
|
if (selector == null){
|
||||||
|
blocker.target = bg;
|
||||||
|
} else {
|
||||||
|
blocker.target = blocker;
|
||||||
|
}
|
||||||
|
|
||||||
Belongings stuff = Dungeon.hero.belongings;
|
Belongings stuff = Dungeon.hero.belongings;
|
||||||
|
|
||||||
if (lastBag == null || !stuff.contains(lastBag)){
|
if (lastBag == null || !stuff.contains(lastBag)){
|
||||||
|
@ -256,12 +288,23 @@ public class InventoryPane extends Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
goldTxt.text(Integer.toString(Dungeon.gold));
|
if (selector == null) {
|
||||||
goldTxt.measure();
|
promptTxt.visible = false;
|
||||||
|
|
||||||
energyTxt.text(Integer.toString(Dungeon.energy));
|
goldTxt.text(Integer.toString(Dungeon.gold));
|
||||||
energyTxt.measure();
|
goldTxt.measure();
|
||||||
energyTxt.visible = energy.visible = Dungeon.energy > 0;
|
goldTxt.visible = gold.visible = true;
|
||||||
|
|
||||||
|
energyTxt.text(Integer.toString(Dungeon.energy));
|
||||||
|
energyTxt.measure();
|
||||||
|
energyTxt.visible = energy.visible = Dungeon.energy > 0;
|
||||||
|
} else {
|
||||||
|
promptTxt.text(selector.textPrompt());
|
||||||
|
promptTxt.visible = true;
|
||||||
|
|
||||||
|
goldTxt.visible = gold.visible = false;
|
||||||
|
energyTxt.visible = energy.visible = false;
|
||||||
|
}
|
||||||
|
|
||||||
ArrayList<Bag> inventBags = stuff.getBags();
|
ArrayList<Bag> inventBags = stuff.getBags();
|
||||||
for (int i = 0; i < bags.size(); i++){
|
for (int i = 0; i < bags.size(); i++){
|
||||||
|
@ -273,10 +316,14 @@ public class InventoryPane extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (InventorySlot b : equipped){
|
for (InventorySlot b : equipped){
|
||||||
b.enable(lastEnabled && !(b.item() instanceof WndBag.Placeholder));
|
b.enable(lastEnabled
|
||||||
|
&& !(b.item() instanceof WndBag.Placeholder)
|
||||||
|
&& (selector == null || selector.itemSelectable(b.item())));
|
||||||
}
|
}
|
||||||
for (InventorySlot b : bagItems){
|
for (InventorySlot b : bagItems){
|
||||||
b.enable(lastEnabled && b.item() != null);
|
b.enable(lastEnabled
|
||||||
|
&& b.item() != null
|
||||||
|
&& (selector == null || selector.itemSelectable(b.item())));
|
||||||
}
|
}
|
||||||
for (BagButton b : bags){
|
for (BagButton b : bags){
|
||||||
b.enable(lastEnabled);
|
b.enable(lastEnabled);
|
||||||
|
@ -290,6 +337,15 @@ public class InventoryPane extends Component {
|
||||||
layout();
|
layout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setSelector(WndBag.ItemSelector selector){
|
||||||
|
this.selector = selector;
|
||||||
|
if (selector.preferredBag() != null) {
|
||||||
|
Bag preferred = Dungeon.hero.belongings.getItem(selector.preferredBag());
|
||||||
|
if (preferred != null) lastBag = preferred;
|
||||||
|
}
|
||||||
|
updateInventory();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void update() {
|
public synchronized void update() {
|
||||||
super.update();
|
super.update();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user