diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/jrummikub/control/TurnControl.java | 86 |
1 files changed, 55 insertions, 31 deletions
diff --git a/src/jrummikub/control/TurnControl.java b/src/jrummikub/control/TurnControl.java index ace201e..d280096 100644 --- a/src/jrummikub/control/TurnControl.java +++ b/src/jrummikub/control/TurnControl.java @@ -77,6 +77,33 @@ public class TurnControl { connections.add(view.getPlayerPanel().getEndTurnEvent() .add(endOfTurnListener)); + addHandPanelHandlers(); + addStoneCollectionHandlers(); + addTablePanelHandlers(); + + connections.add(view.getPlayerPanel().getSortByGroupsEvent() + .add(new IListener() { + @Override + public void handle() { + sortByGroups(); + } + })); + + connections.add(view.getPlayerPanel().getSortByRunsEvent() + .add(new IListener() { + @Override + public void handle() { + sortByRuns(); + } + })); + + view.getPlayerPanel().getHandPanel().setStones(hand.clone()); + view.enableStartTurnPanel(false); + + timer.startTimer(); + } + + private void addHandPanelHandlers() { connections.add(view.getPlayerPanel().getHandPanel().getClickEvent() .add(new IListener1<Position>() { @Override @@ -85,8 +112,8 @@ public class TurnControl { } })); - connections.add(view.getPlayerPanel().getHandPanel() - .getStoneClickEvent().add(new IListener2<Stone, Boolean>() { + connections.add(view.getPlayerPanel().getHandPanel().getStoneClickEvent() + .add(new IListener2<Stone, Boolean>() { @Override public void handle(Stone stone, Boolean collect) { @@ -94,15 +121,17 @@ public class TurnControl { } })); - connections.add(view.getPlayerPanel().getHandPanel() - .getRangeClickEvent().add(new IListener2<Stone, Boolean>() { + connections.add(view.getPlayerPanel().getHandPanel().getRangeClickEvent() + .add(new IListener2<Stone, Boolean>() { @Override public void handle(Stone stone, Boolean collect) { handRangeClick(stone, collect); } })); + } + private void addStoneCollectionHandlers() { connections.add(view.getTablePanel().getStoneCollectionPanel() .getStoneClickEvent().add(new IListener2<Stone, Boolean>() { @@ -111,6 +140,7 @@ public class TurnControl { collectionStoneClick(stone, collect); } })); + connections.add(view.getTablePanel().getStoneCollectionPanel() .getSetClickEvent().add(new IListener2<Stone, Boolean>() { @@ -119,6 +149,9 @@ public class TurnControl { collectionSetClick(stone, collect); } })); + } + + private void addTablePanelHandlers() { connections.add(view.getTablePanel().getStoneClickEvent() .add(new IListener2<Stone, Boolean>() { @@ -127,6 +160,7 @@ public class TurnControl { stoneClick(stone, collect); } })); + connections.add(view.getTablePanel().getSetClickEvent() .add(new IListener2<Stone, Boolean>() { @@ -135,6 +169,7 @@ public class TurnControl { tableSetClick(stone, collect); } })); + connections.add(view.getTablePanel().getRangeClickEvent() .add(new IListener2<Stone, Boolean>() { @@ -151,6 +186,11 @@ public class TurnControl { tableClick(pos); } })); + + addTablePanelConnectorClickHandlers(); + } + + private void addTablePanelConnectorClickHandlers() { connections.add(view.getTablePanel().getLeftConnectorClickEvent() .add(new IListener1<StoneSet>() { @Override @@ -158,6 +198,7 @@ public class TurnControl { connectorClick(set, false); } })); + connections.add(view.getTablePanel().getRightConnectorClickEvent() .add(new IListener1<StoneSet>() { @Override @@ -165,25 +206,6 @@ public class TurnControl { connectorClick(set, true); } })); - connections.add(view.getPlayerPanel().getSortByGroupsEvent() - .add(new IListener() { - @Override - public void handle() { - sortByGroups(); - } - })); - connections.add(view.getPlayerPanel().getSortByRunsEvent() - .add(new IListener() { - @Override - public void handle() { - sortByRuns(); - } - })); - - view.getPlayerPanel().getHandPanel().setStones(hand.clone()); - view.enableStartTurnPanel(false); - - timer.startTimer(); } private void handClick(Position pos) { @@ -226,8 +248,8 @@ public class TurnControl { if (y >= GameControl.HAND_HEIGHT) { throw new ArrayIndexOutOfBoundsException(); // TODO We can't - // handle - // this yet... + // handle + // this yet... } } } @@ -401,12 +423,15 @@ public class TurnControl { table.drop(joinedSet, newPos); } else { StoneSet joinedSet = new StoneSet(selectedStones).join(newSet); - table.drop(joinedSet, new Position(newPos.getX() - - selectedStones.size(), newPos.getY())); + table.drop(joinedSet, + new Position(newPos.getX() - selectedStones.size(), newPos.getY())); } } else { - table.drop(new StoneSet(selectedStones), new Position(pos.getX() - + (set.size() - selectedStones.size()) * 0.5f, pos.getY())); + table.drop( + new StoneSet(selectedStones), + new Position( + pos.getX() + (set.size() - selectedStones.size()) * 0.5f, pos + .getY())); } selectedStones.clear(); @@ -506,8 +531,7 @@ public class TurnControl { static class HandStonePositionComparator implements Comparator<Pair<Stone, Position>> { @Override - public int compare(Pair<Stone, Position> pair1, - Pair<Stone, Position> pair2) { + public int compare(Pair<Stone, Position> pair1, Pair<Stone, Position> pair2) { Position pos1 = pair1.getSecond(), pos2 = pair2.getSecond(); if (pos1.getY() < pos2.getY()) { return -1; |