v5stable
ondra 11 years ago
parent c13a624520
commit 2525eda1bf
  1. 1
      src/mightypork/rogue/screens/game/HeartBar.java
  2. 138
      src/mightypork/rogue/screens/game/InvLayer.java
  3. 2
      src/mightypork/rogue/screens/game/InvSlot.java
  4. 4
      src/mightypork/rogue/screens/game/ScreenGame.java
  5. 1
      src/mightypork/rogue/screens/game/WorldConsoleRenderer.java
  6. 5
      src/mightypork/rogue/world/WorldConsole.java

@ -5,7 +5,6 @@ import mightypork.gamecore.gui.AlignX;
import mightypork.gamecore.gui.components.BaseComponent; import mightypork.gamecore.gui.components.BaseComponent;
import mightypork.gamecore.render.Render; import mightypork.gamecore.render.Render;
import mightypork.gamecore.resources.textures.TxQuad; import mightypork.gamecore.resources.textures.TxQuad;
import mightypork.gamecore.util.math.color.pal.RGB;
import mightypork.gamecore.util.math.constraints.num.Num; import mightypork.gamecore.util.math.constraints.num.Num;
import mightypork.gamecore.util.math.constraints.num.mutable.NumVar; import mightypork.gamecore.util.math.constraints.num.mutable.NumVar;
import mightypork.gamecore.util.math.constraints.rect.Rect; import mightypork.gamecore.util.math.constraints.rect.Rect;

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

@ -8,13 +8,11 @@ import mightypork.gamecore.gui.components.painters.TextPainter;
import mightypork.gamecore.render.Render; import mightypork.gamecore.render.Render;
import mightypork.gamecore.resources.textures.TxQuad; import mightypork.gamecore.resources.textures.TxQuad;
import mightypork.gamecore.util.math.Calc; import mightypork.gamecore.util.math.Calc;
import mightypork.gamecore.util.math.color.Color;
import mightypork.gamecore.util.math.color.pal.RGB; import mightypork.gamecore.util.math.color.pal.RGB;
import mightypork.gamecore.util.math.constraints.num.Num; import mightypork.gamecore.util.math.constraints.num.Num;
import mightypork.gamecore.util.math.constraints.rect.caching.RectCache; import mightypork.gamecore.util.math.constraints.rect.caching.RectCache;
import mightypork.rogue.Res; import mightypork.rogue.Res;
import mightypork.rogue.world.World.PlayerFacade; import mightypork.rogue.world.World.PlayerFacade;
import mightypork.rogue.world.PlayerInfo;
import mightypork.rogue.world.WorldProvider; import mightypork.rogue.world.WorldProvider;
import mightypork.rogue.world.item.Item; import mightypork.rogue.world.item.Item;
import mightypork.rogue.world.item.ItemType; import mightypork.rogue.world.item.ItemType;

@ -92,6 +92,9 @@ public class ScreenGame extends LayeredScreen {
{ {
if (this.state == nstate) return; if (this.state == nstate) return;
System.out.println("Goto: "+nstate);
if (nstate != GScrState.WORLD) { // leaving world. if (nstate != GScrState.WORLD) { // leaving world.
getEventBus().send(new WorldPauseRequest(PauseAction.PAUSE)); getEventBus().send(new WorldPauseRequest(PauseAction.PAUSE));
@ -150,6 +153,7 @@ public class ScreenGame extends LayeredScreen {
//pause key //pause key
bindKey(new KeyStroke(Keys.P), actionTogglePause); bindKey(new KeyStroke(Keys.P), actionTogglePause);
bindKey(new KeyStroke(Keys.PAUSE), actionTogglePause); bindKey(new KeyStroke(Keys.PAUSE), actionTogglePause);
bindKey(new KeyStroke(Keys.SPACE), actionTogglePause);
bindKey(new KeyStroke(Keys.I), actionInv); bindKey(new KeyStroke(Keys.I), actionInv);
bindKey(new KeyStroke(Keys.E), actionEat); bindKey(new KeyStroke(Keys.E), actionEat);

@ -5,7 +5,6 @@ import java.util.Collection;
import mightypork.gamecore.gui.AlignX; import mightypork.gamecore.gui.AlignX;
import mightypork.gamecore.gui.components.BaseComponent; import mightypork.gamecore.gui.components.BaseComponent;
import mightypork.gamecore.gui.components.painters.TextPainter;
import mightypork.gamecore.resources.fonts.FontRenderer; import mightypork.gamecore.resources.fonts.FontRenderer;
import mightypork.gamecore.util.math.color.Color; import mightypork.gamecore.util.math.color.Color;
import mightypork.gamecore.util.math.color.pal.RGB; import mightypork.gamecore.util.math.color.pal.RGB;

@ -1,7 +1,10 @@
package mightypork.rogue.world; package mightypork.rogue.world;
import java.util.*; import java.util.Collection;
import java.util.Deque;
import java.util.Iterator;
import java.util.LinkedList;
import mightypork.gamecore.eventbus.events.Updateable; import mightypork.gamecore.eventbus.events.Updateable;
import mightypork.gamecore.util.math.Easing; import mightypork.gamecore.util.math.Easing;

Loading…
Cancel
Save