From f641b76bcac15871458e649cdde02331c2cef882 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sun, 19 Jun 2011 01:40:14 +0200 Subject: Added table update event to turn control and round control git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@477 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/control/RoundControl.java | 13 +++++++++++++ src/jrummikub/control/turn/AbstractTurnControl.java | 9 +++++++++ src/jrummikub/control/turn/HumanTurnControl.java | 16 ++++++++++------ src/jrummikub/control/turn/ITurnControl.java | 3 +++ 4 files changed, 35 insertions(+), 6 deletions(-) (limited to 'src/jrummikub') diff --git a/src/jrummikub/control/RoundControl.java b/src/jrummikub/control/RoundControl.java index 174cc9a..d8435af 100644 --- a/src/jrummikub/control/RoundControl.java +++ b/src/jrummikub/control/RoundControl.java @@ -26,6 +26,7 @@ import jrummikub.util.Event1; import jrummikub.util.IEvent; import jrummikub.util.IEvent1; import jrummikub.util.IListener; +import jrummikub.util.IListener1; import jrummikub.util.Pair; import jrummikub.view.IView; import jrummikub.view.IView.BottomPanelType; @@ -40,6 +41,7 @@ public class RoundControl { IHand clonedHand; private Event restartRoundEvent = new Event(); private Event1 endOfRoundEvent = new Event1(); + private Event1 tableUpdateEvent = new Event1(); private List connections = new ArrayList(); private ITurnControl turnControl; private boolean roundFinished; @@ -68,6 +70,10 @@ public class RoundControl { return endOfRoundEvent; } + public IEvent1 getTableUpdateEvent() { + return tableUpdateEvent; + } + /** * Begin the round */ @@ -170,6 +176,13 @@ public class RoundControl { } }); + turnControl.getTableUpdateEvent().add(new IListener1() { + @Override + public void handle(ITable table) { + tableUpdateEvent.emit(table); + } + }); + turnControl.getRedealEvent().add(new IListener() { @Override public void handle() { diff --git a/src/jrummikub/control/turn/AbstractTurnControl.java b/src/jrummikub/control/turn/AbstractTurnControl.java index d6d0271..fd88370 100644 --- a/src/jrummikub/control/turn/AbstractTurnControl.java +++ b/src/jrummikub/control/turn/AbstractTurnControl.java @@ -6,9 +6,12 @@ import java.util.List; import jrummikub.control.ITurnTimer; import jrummikub.control.TurnTimer; import jrummikub.model.GameSettings; +import jrummikub.model.ITable; import jrummikub.util.Connection; import jrummikub.util.Event; +import jrummikub.util.Event1; import jrummikub.util.IEvent; +import jrummikub.util.IEvent1; import jrummikub.util.IListener; import jrummikub.view.IView; @@ -18,6 +21,7 @@ import jrummikub.view.IView; public abstract class AbstractTurnControl implements ITurnControl { protected Event endOfTurnEvent = new Event(); protected Event redealEvent = new Event(); + protected Event1 tableUpdateEvent = new Event1(); protected TurnInfo turnInfo; protected GameSettings settings; protected IView view; @@ -33,6 +37,11 @@ public abstract class AbstractTurnControl implements ITurnControl { public IEvent getRedealEvent() { return redealEvent; } + + @Override + public IEvent1 getTableUpdateEvent() { + return tableUpdateEvent; + } protected void pauseTurn() { timer.stopTimer(); diff --git a/src/jrummikub/control/turn/HumanTurnControl.java b/src/jrummikub/control/turn/HumanTurnControl.java index a9a73d7..3efad2f 100644 --- a/src/jrummikub/control/turn/HumanTurnControl.java +++ b/src/jrummikub/control/turn/HumanTurnControl.java @@ -297,6 +297,14 @@ public class HumanTurnControl extends AbstractTurnControl { } } + private void updateTable() { + view.getTablePanel().setStoneSets(turnInfo.getTable()); + view.getHandPanel().setStones(turnInfo.getHand()); + view.setSelectedStones(selectedStones); + + tableUpdateEvent.emit(turnInfo.getTable()); + } + private void tableClick(Position position) { if (selectedStones.isEmpty()) { return; @@ -309,9 +317,7 @@ public class HumanTurnControl extends AbstractTurnControl { .getY() - 0.5f)); selectedStones.clear(); - view.getTablePanel().setStoneSets(turnInfo.getTable()); - view.getHandPanel().setStones(turnInfo.getHand()); - view.setSelectedStones(selectedStones); + updateTable(); } private void tableSetClick(Stone stone, boolean collect) { @@ -434,9 +440,7 @@ public class HumanTurnControl extends AbstractTurnControl { selectedStones.clear(); - view.getTablePanel().setStoneSets(turnInfo.getTable()); - view.getHandPanel().setStones(turnInfo.getHand()); - view.setSelectedStones(selectedStones); + updateTable(); } private void endOfTurn(boolean redeal) { diff --git a/src/jrummikub/control/turn/ITurnControl.java b/src/jrummikub/control/turn/ITurnControl.java index 63290d5..0039a42 100644 --- a/src/jrummikub/control/turn/ITurnControl.java +++ b/src/jrummikub/control/turn/ITurnControl.java @@ -4,6 +4,7 @@ import jrummikub.model.GameSettings; import jrummikub.model.IHand; import jrummikub.model.ITable; import jrummikub.util.IEvent; +import jrummikub.util.IEvent1; import jrummikub.view.IView; /** @@ -48,6 +49,8 @@ public interface ITurnControl { */ public void abortTurn(); + public IEvent1 getTableUpdateEvent(); + /** * The TurnInfo class encapsulates all information concerning the current turn */ -- cgit v1.2.3