|
|
|
@ -10,13 +10,13 @@ import mightypork.gamecore.gui.components.painters.TextPainter; |
|
|
|
|
import mightypork.gamecore.gui.screens.ScreenLayer; |
|
|
|
|
import mightypork.gamecore.input.KeyStroke; |
|
|
|
|
import mightypork.gamecore.input.Keys; |
|
|
|
|
import mightypork.gamecore.util.math.color.Color; |
|
|
|
|
import mightypork.gamecore.util.math.color.pal.RGB; |
|
|
|
|
import mightypork.gamecore.util.math.constraints.num.Num; |
|
|
|
|
import mightypork.gamecore.util.math.constraints.rect.Rect; |
|
|
|
|
import mightypork.gamecore.util.strings.StringProvider; |
|
|
|
|
import mightypork.rogue.Res; |
|
|
|
|
import mightypork.rogue.screens.game.ScreenGame.GScrState; |
|
|
|
|
import mightypork.rogue.world.World; |
|
|
|
|
import mightypork.rogue.world.World.PlayerFacade; |
|
|
|
|
import mightypork.rogue.world.WorldProvider; |
|
|
|
|
import mightypork.rogue.world.item.Item; |
|
|
|
@ -25,6 +25,9 @@ import mightypork.rogue.world.item.ItemType; |
|
|
|
|
|
|
|
|
|
public class InvLayer extends ScreenLayer { |
|
|
|
|
|
|
|
|
|
private static final int SLOT_COUNT = 8; |
|
|
|
|
private static final int SLOT_ROW = 4; |
|
|
|
|
|
|
|
|
|
private final StringProvider contextStrProv = new StringProvider() { |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@ -49,15 +52,15 @@ public class InvLayer extends ScreenLayer { |
|
|
|
|
s = "E-equip," + s; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}else { |
|
|
|
|
s = "Click-select,"+s; |
|
|
|
|
} else { |
|
|
|
|
s = "Click-select," + s; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return s; |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
private final InvSlot[] slots = new InvSlot[8]; |
|
|
|
|
private final InvSlot[] slots = new InvSlot[SLOT_COUNT]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private int getSelectedSlot() |
|
|
|
@ -72,8 +75,19 @@ public class InvLayer extends ScreenLayer { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public InvLayer(final ScreenGame screen) |
|
|
|
|
private void selectSlot(int i) |
|
|
|
|
{ |
|
|
|
|
for (final InvSlot sl : slots) { |
|
|
|
|
sl.selected = false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (i >= 0 && i < SLOT_COUNT) { |
|
|
|
|
slots[i].selected = true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public InvLayer(final ScreenGame screen) { |
|
|
|
|
super(screen); |
|
|
|
|
|
|
|
|
|
final Rect fg = root.shrink(root.height().perc(15)); |
|
|
|
@ -106,7 +120,6 @@ public class InvLayer extends ScreenLayer { |
|
|
|
|
row1.add(slots[2] = new InvSlot(2, slots)); |
|
|
|
|
row1.add(slots[3] = new InvSlot(3, slots)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final HorizontalFixedFlowLayout row2 = new HorizontalFixedFlowLayout(root, null, AlignX.LEFT); |
|
|
|
|
row2.setElementWidth(row2.height()); |
|
|
|
|
final ConstraintLayout cl2 = new ConstraintLayout(root); |
|
|
|
@ -124,39 +137,56 @@ public class InvLayer extends ScreenLayer { |
|
|
|
|
gl.put(txp2, pos, 0, 1, 1); |
|
|
|
|
txp2.setPaddingHPerc(0, 25); |
|
|
|
|
|
|
|
|
|
bindKey(new KeyStroke(Keys.ESCAPE), new Runnable() { |
|
|
|
|
final Runnable leaveInv = new Runnable() { |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void run() |
|
|
|
|
{ |
|
|
|
|
if(WorldProvider.get().getPlayer().isDead()) return; |
|
|
|
|
if(!isEnabled()) return; |
|
|
|
|
|
|
|
|
|
screen.setState(GScrState.WORLD); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
bindKey(new KeyStroke(Keys.ESCAPE), leaveInv); |
|
|
|
|
//bindKey(new KeyStroke(Keys.I), leaveInv);
|
|
|
|
|
// TODO needs some rewrite of keys system
|
|
|
|
|
|
|
|
|
|
bindKey(new KeyStroke(Keys.E), new Runnable() { |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void run() |
|
|
|
|
{ |
|
|
|
|
if(WorldProvider.get().getPlayer().isDead()) return; |
|
|
|
|
{ |
|
|
|
|
if(!isEnabled()) return; |
|
|
|
|
|
|
|
|
|
if (WorldProvider.get().getPlayer().isDead()) return; |
|
|
|
|
|
|
|
|
|
final int selected = getSelectedSlot(); |
|
|
|
|
if (selected != -1) { |
|
|
|
|
|
|
|
|
|
final World world = WorldProvider.get().getWorld(); |
|
|
|
|
final PlayerFacade pl = WorldProvider.get().getPlayer(); |
|
|
|
|
final Item itm = pl.getInventory().getItem(selected); |
|
|
|
|
|
|
|
|
|
if (itm != null && !itm.isEmpty()) { |
|
|
|
|
|
|
|
|
|
if (itm.getType() == ItemType.FOOD) { |
|
|
|
|
if (pl.eatFood(itm)) { |
|
|
|
|
final ItemType type = itm.getType(); |
|
|
|
|
|
|
|
|
|
if (type == ItemType.FOOD) { |
|
|
|
|
|
|
|
|
|
if (pl.eatFood(itm)) { |
|
|
|
|
pl.getInventory().clean(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (itm.getType() == ItemType.WEAPON) { |
|
|
|
|
pl.selectWeapon(selected); |
|
|
|
|
WorldProvider.get().getWorld().msgEquipWeapon(itm); |
|
|
|
|
|
|
|
|
|
} else if (type == ItemType.WEAPON) { |
|
|
|
|
|
|
|
|
|
if (pl.getSelectedWeaponIndex() == selected) { |
|
|
|
|
pl.selectWeapon(-1); |
|
|
|
|
} else { |
|
|
|
|
pl.selectWeapon(selected); |
|
|
|
|
} |
|
|
|
|
world.msgEquipWeapon(pl.getSelectedWeapon()); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -168,7 +198,7 @@ public class InvLayer extends ScreenLayer { |
|
|
|
|
@Override |
|
|
|
|
public void run() |
|
|
|
|
{ |
|
|
|
|
if (!isVisible()) return; |
|
|
|
|
if(!isEnabled()) return; |
|
|
|
|
|
|
|
|
|
final int selected = getSelectedSlot(); |
|
|
|
|
if (selected != -1) { |
|
|
|
@ -186,22 +216,88 @@ public class InvLayer extends ScreenLayer { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
setupGridWalkKeys(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public int getZIndex() |
|
|
|
|
private void setupGridWalkKeys() |
|
|
|
|
{ |
|
|
|
|
return 200; |
|
|
|
|
|
|
|
|
|
bindKey(new KeyStroke(Keys.LEFT), new Runnable() { |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void run() |
|
|
|
|
{ |
|
|
|
|
if(!isEnabled()) return; |
|
|
|
|
|
|
|
|
|
int sel = getSelectedSlot(); |
|
|
|
|
if (sel == -1) { |
|
|
|
|
selectSlot(0); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
selectSlot((SLOT_COUNT + (sel - 1)) % SLOT_COUNT); |
|
|
|
|
}; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
bindKey(new KeyStroke(Keys.RIGHT), new Runnable() { |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void run() |
|
|
|
|
{ |
|
|
|
|
if(!isEnabled()) return; |
|
|
|
|
|
|
|
|
|
int sel = getSelectedSlot(); |
|
|
|
|
if (sel == -1) { |
|
|
|
|
selectSlot(0); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
selectSlot((SLOT_COUNT + (sel + 1)) % SLOT_COUNT); |
|
|
|
|
}; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
bindKey(new KeyStroke(Keys.UP), new Runnable() { |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void run() |
|
|
|
|
{ |
|
|
|
|
if(!isEnabled()) return; |
|
|
|
|
|
|
|
|
|
int sel = getSelectedSlot(); |
|
|
|
|
if (sel == -1) { |
|
|
|
|
selectSlot(0); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
selectSlot((SLOT_COUNT + (sel - SLOT_ROW)) % SLOT_COUNT); |
|
|
|
|
}; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
bindKey(new KeyStroke(Keys.DOWN), new Runnable() { |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void run() |
|
|
|
|
{ |
|
|
|
|
if(!isEnabled()) return; |
|
|
|
|
|
|
|
|
|
int sel = getSelectedSlot(); |
|
|
|
|
if (sel == -1) { |
|
|
|
|
selectSlot(0); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
selectSlot((sel + SLOT_ROW) % SLOT_COUNT); |
|
|
|
|
}; |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void onLayoutChanged() |
|
|
|
|
public int getZIndex() |
|
|
|
|
{ |
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
super.onLayoutChanged(); |
|
|
|
|
|
|
|
|
|
System.out.println("LayoutChange @ invlayer"); |
|
|
|
|
return 200; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|