From 2525eda1bfe3790d9431ab3d2f82a2d865ffb1f1 Mon Sep 17 00:00:00 2001 From: ondra Date: Sun, 11 May 2014 19:12:16 +0200 Subject: [PATCH] inv tweaks --- .../rogue/screens/game/HeartBar.java | 1 - .../rogue/screens/game/InvLayer.java | 150 ++++++++++++++---- .../rogue/screens/game/InvSlot.java | 2 - .../rogue/screens/game/ScreenGame.java | 4 + .../screens/game/WorldConsoleRenderer.java | 1 - src/mightypork/rogue/world/WorldConsole.java | 5 +- 6 files changed, 131 insertions(+), 32 deletions(-) diff --git a/src/mightypork/rogue/screens/game/HeartBar.java b/src/mightypork/rogue/screens/game/HeartBar.java index 3bb2533..53f72f9 100644 --- a/src/mightypork/rogue/screens/game/HeartBar.java +++ b/src/mightypork/rogue/screens/game/HeartBar.java @@ -5,7 +5,6 @@ import mightypork.gamecore.gui.AlignX; import mightypork.gamecore.gui.components.BaseComponent; import mightypork.gamecore.render.Render; 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.mutable.NumVar; import mightypork.gamecore.util.math.constraints.rect.Rect; diff --git a/src/mightypork/rogue/screens/game/InvLayer.java b/src/mightypork/rogue/screens/game/InvLayer.java index 750f959..5f953c8 100644 --- a/src/mightypork/rogue/screens/game/InvLayer.java +++ b/src/mightypork/rogue/screens/game/InvLayer.java @@ -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; } } diff --git a/src/mightypork/rogue/screens/game/InvSlot.java b/src/mightypork/rogue/screens/game/InvSlot.java index d6c28f1..499cc90 100644 --- a/src/mightypork/rogue/screens/game/InvSlot.java +++ b/src/mightypork/rogue/screens/game/InvSlot.java @@ -8,13 +8,11 @@ import mightypork.gamecore.gui.components.painters.TextPainter; import mightypork.gamecore.render.Render; import mightypork.gamecore.resources.textures.TxQuad; 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.constraints.num.Num; import mightypork.gamecore.util.math.constraints.rect.caching.RectCache; import mightypork.rogue.Res; import mightypork.rogue.world.World.PlayerFacade; -import mightypork.rogue.world.PlayerInfo; import mightypork.rogue.world.WorldProvider; import mightypork.rogue.world.item.Item; import mightypork.rogue.world.item.ItemType; diff --git a/src/mightypork/rogue/screens/game/ScreenGame.java b/src/mightypork/rogue/screens/game/ScreenGame.java index f3fa98e..cc95994 100644 --- a/src/mightypork/rogue/screens/game/ScreenGame.java +++ b/src/mightypork/rogue/screens/game/ScreenGame.java @@ -92,6 +92,9 @@ public class ScreenGame extends LayeredScreen { { if (this.state == nstate) return; + + System.out.println("Goto: "+nstate); + if (nstate != GScrState.WORLD) { // leaving world. getEventBus().send(new WorldPauseRequest(PauseAction.PAUSE)); @@ -150,6 +153,7 @@ public class ScreenGame extends LayeredScreen { //pause key bindKey(new KeyStroke(Keys.P), actionTogglePause); bindKey(new KeyStroke(Keys.PAUSE), actionTogglePause); + bindKey(new KeyStroke(Keys.SPACE), actionTogglePause); bindKey(new KeyStroke(Keys.I), actionInv); bindKey(new KeyStroke(Keys.E), actionEat); diff --git a/src/mightypork/rogue/screens/game/WorldConsoleRenderer.java b/src/mightypork/rogue/screens/game/WorldConsoleRenderer.java index 0cbb391..d5a0a09 100644 --- a/src/mightypork/rogue/screens/game/WorldConsoleRenderer.java +++ b/src/mightypork/rogue/screens/game/WorldConsoleRenderer.java @@ -5,7 +5,6 @@ import java.util.Collection; import mightypork.gamecore.gui.AlignX; import mightypork.gamecore.gui.components.BaseComponent; -import mightypork.gamecore.gui.components.painters.TextPainter; import mightypork.gamecore.resources.fonts.FontRenderer; import mightypork.gamecore.util.math.color.Color; import mightypork.gamecore.util.math.color.pal.RGB; diff --git a/src/mightypork/rogue/world/WorldConsole.java b/src/mightypork/rogue/world/WorldConsole.java index 0c00fbf..01596c2 100644 --- a/src/mightypork/rogue/world/WorldConsole.java +++ b/src/mightypork/rogue/world/WorldConsole.java @@ -1,7 +1,10 @@ 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.util.math.Easing;