Implement pause function
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@390 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
2e376414b9
commit
45d5b3ae10
40 changed files with 642 additions and 425 deletions
|
@ -17,6 +17,8 @@ public class MockPlayerPanel implements IPlayerPanel {
|
|||
/** */
|
||||
public MockEvent sortByRunsEvent = new MockEvent();
|
||||
/** */
|
||||
public MockEvent pauseEvent = new MockEvent();
|
||||
/** */
|
||||
public TurnMode turnMode;
|
||||
|
||||
@Override
|
||||
|
@ -49,5 +51,4 @@ public class MockPlayerPanel implements IPlayerPanel {
|
|||
public void setEndTurnMode(TurnMode turnMode) {
|
||||
this.turnMode = turnMode;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -49,6 +49,10 @@ public class MockView implements IView {
|
|||
public MockEvent1<File> loadEvent = new MockEvent1<File>();
|
||||
/** */
|
||||
public MockEvent1<File> saveEvent = new MockEvent1<File>();
|
||||
/** */
|
||||
public MockEvent pauseEvent = new MockEvent();
|
||||
/** */
|
||||
public MockEvent endPauseEvent = new MockEvent();
|
||||
|
||||
@Override
|
||||
public MockTablePanel getTablePanel() {
|
||||
|
@ -157,4 +161,20 @@ public class MockView implements IView {
|
|||
@Override
|
||||
public void clearView() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enablePauseMode(boolean enable) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEvent getPauseEvent() {
|
||||
return pauseEvent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEvent getEndPauseEvent() {
|
||||
return endPauseEvent;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,14 +51,13 @@ public class ApplicationControl {
|
|||
new IListener3<GameSettings, GameState, IRoundState>() {
|
||||
|
||||
@Override
|
||||
public void handle(GameSettings settings,
|
||||
GameState gameState, IRoundState roundState) {
|
||||
public void handle(GameSettings settings, GameState gameState,
|
||||
IRoundState roundState) {
|
||||
settingsControl.abort();
|
||||
if (gameControl != null){
|
||||
if (gameControl != null) {
|
||||
gameControl.abortGame();
|
||||
}
|
||||
gameControl = new GameControl(settings,
|
||||
saveControl, view);
|
||||
gameControl = new GameControl(settings, saveControl, view);
|
||||
addGameControlListeners(gameControl);
|
||||
gameControl.continueGame(gameState, roundState);
|
||||
|
||||
|
@ -70,8 +69,7 @@ public class ApplicationControl {
|
|||
public void handle(GameSettings settings) {
|
||||
saveControl.setGameSettings(settings);
|
||||
|
||||
gameControl = new GameControl(settings,
|
||||
saveControl, view);
|
||||
gameControl = new GameControl(settings, saveControl, view);
|
||||
addGameControlListeners(gameControl);
|
||||
|
||||
gameControl.startGame();
|
||||
|
|
|
@ -174,8 +174,7 @@ public class GameControl {
|
|||
|
||||
view.getScorePanel().setPlayers(gameSettings.getPlayerList());
|
||||
view.getScorePanel().setScores(gameState.getScores());
|
||||
view.getScorePanel().setAccumulatedScore(
|
||||
gameState.getAccumulatedScore());
|
||||
view.getScorePanel().setAccumulatedScore(gameState.getAccumulatedScore());
|
||||
view.getScorePanel().update();
|
||||
view.showScorePanel(true);
|
||||
}
|
||||
|
|
|
@ -102,12 +102,11 @@ public class RoundControl {
|
|||
: BottomPanelType.COMPUTER_HAND_PANEL);
|
||||
|
||||
view.getTablePanel().setStoneSets(clonedTable.clone());
|
||||
view.setCurrentPlayerName(roundState.getActivePlayer()
|
||||
.getPlayerSettings().getName());
|
||||
view.setCurrentPlayerColor(roundState.getActivePlayer()
|
||||
.getPlayerSettings().getColor());
|
||||
view.setCurrentPlayerHasLaidOut(roundState.getActivePlayer()
|
||||
.getLaidOut());
|
||||
view.setCurrentPlayerName(roundState.getActivePlayer().getPlayerSettings()
|
||||
.getName());
|
||||
view.setCurrentPlayerColor(roundState.getActivePlayer().getPlayerSettings()
|
||||
.getColor());
|
||||
view.setCurrentPlayerHasLaidOut(roundState.getActivePlayer().getLaidOut());
|
||||
|
||||
if (!isHuman)
|
||||
startTurn();
|
||||
|
@ -132,11 +131,11 @@ public class RoundControl {
|
|||
view.getPlayerPanel().setEndTurnMode(turnMode);
|
||||
}
|
||||
turnControl = TurnControlFactory.getFactory(
|
||||
roundState.getActivePlayer().getPlayerSettings()
|
||||
.getTurnControlType()).create();
|
||||
roundState.getActivePlayer().getPlayerSettings().getTurnControlType())
|
||||
.create();
|
||||
turnControl.setup(new ITurnControl.TurnInfo(clonedTable, clonedHand,
|
||||
roundState.getActivePlayer().getLaidOut(), turnMode),
|
||||
roundState.getGameSettings(), view);
|
||||
roundState.getActivePlayer().getLaidOut(), turnMode), roundState
|
||||
.getGameSettings(), view);
|
||||
turnControl.getEndOfTurnEvent().add(new IListener() {
|
||||
@Override
|
||||
public void handle() {
|
||||
|
@ -156,10 +155,8 @@ public class RoundControl {
|
|||
void deal() {
|
||||
for (int i = 0; i < roundState.getPlayerCount(); i++) {
|
||||
IHand hand = roundState.getNthNextPlayer(i).getHand();
|
||||
for (int j = 0; j < roundState.getGameSettings()
|
||||
.getNumberOfStonesDealt(); j++) {
|
||||
hand.drop(roundState.getGameHeap().drawStone(), new Position(0,
|
||||
0));
|
||||
for (int j = 0; j < roundState.getGameSettings().getNumberOfStonesDealt(); j++) {
|
||||
hand.drop(roundState.getGameHeap().drawStone(), new Position(0, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -170,13 +167,11 @@ public class RoundControl {
|
|||
|
||||
int totalValue = 0;
|
||||
for (StoneSet set : newSets) {
|
||||
totalValue += set.classify(roundState.getGameSettings())
|
||||
.getSecond();
|
||||
totalValue += set.classify(roundState.getGameSettings()).getSecond();
|
||||
}
|
||||
|
||||
return totalValue == 0
|
||||
|| totalValue >= roundState.getGameSettings()
|
||||
.getInitialMeldThreshold();
|
||||
|| totalValue >= roundState.getGameSettings().getInitialMeldThreshold();
|
||||
}
|
||||
|
||||
private void endOfTurn() {
|
||||
|
@ -216,8 +211,7 @@ public class RoundControl {
|
|||
}
|
||||
if (!roundState.getActivePlayer().getLaidOut()) {
|
||||
// Player touched forbidden stones
|
||||
if (!tableSetDifference(clonedTable, roundState.getTable())
|
||||
.isEmpty()) {
|
||||
if (!tableSetDifference(clonedTable, roundState.getTable()).isEmpty()) {
|
||||
rejectMove();
|
||||
return;
|
||||
}
|
||||
|
@ -226,8 +220,7 @@ public class RoundControl {
|
|||
return;
|
||||
}
|
||||
}
|
||||
Set<Stone> tableDiff = tableDifference(roundState.getTable(),
|
||||
clonedTable);
|
||||
Set<Stone> tableDiff = tableDifference(roundState.getTable(), clonedTable);
|
||||
|
||||
roundState.setTable(clonedTable);
|
||||
|
||||
|
@ -243,8 +236,7 @@ public class RoundControl {
|
|||
}
|
||||
|
||||
private void rejectMove() {
|
||||
Set<Stone> tableDiff = tableDifference(roundState.getTable(),
|
||||
clonedTable);
|
||||
Set<Stone> tableDiff = tableDifference(roundState.getTable(), clonedTable);
|
||||
// deal penalty, reset
|
||||
roundState.getGameHeap().putBack(tableDiff);
|
||||
dealPenalty(tableDiff.size());
|
||||
|
@ -338,12 +330,10 @@ public class RoundControl {
|
|||
stonePoints = playerHand.isInitialMeldPossible(roundState
|
||||
.getGameSettings()) ? 200 : 100;
|
||||
} else {
|
||||
stonePoints = playerHand.getStonePoints(roundState
|
||||
.getGameSettings());
|
||||
stonePoints = playerHand.getStonePoints(roundState.getGameSettings());
|
||||
}
|
||||
|
||||
bestScore = updateBestScore(bestScore, -stonePoints,
|
||||
playerHand.getSize());
|
||||
bestScore = updateBestScore(bestScore, -stonePoints, playerHand.getSize());
|
||||
|
||||
points.add(-stonePoints);
|
||||
pointSum += stonePoints;
|
||||
|
|
|
@ -110,8 +110,8 @@ public class SaveControl {
|
|||
return;
|
||||
}
|
||||
try {
|
||||
ObjectOutputStream stream = new ObjectOutputStream(
|
||||
new FileOutputStream(file));
|
||||
ObjectOutputStream stream = new ObjectOutputStream(new FileOutputStream(
|
||||
file));
|
||||
|
||||
stream.writeObject(gameSettings);
|
||||
stream.writeObject(gameState);
|
||||
|
|
|
@ -16,7 +16,6 @@ import jrummikub.view.IView;
|
|||
* Abstract base class for TurnControls
|
||||
*/
|
||||
public abstract class AbstractTurnControl implements ITurnControl {
|
||||
|
||||
protected Event endOfTurnEvent = new Event();
|
||||
protected Event redealEvent = new Event();
|
||||
protected TurnInfo turnInfo;
|
||||
|
@ -25,7 +24,6 @@ public abstract class AbstractTurnControl implements ITurnControl {
|
|||
protected ITurnTimer timer;
|
||||
protected List<Connection> connections = new ArrayList<Connection>();
|
||||
|
||||
|
||||
@Override
|
||||
public IEvent getEndOfTurnEvent() {
|
||||
return endOfTurnEvent;
|
||||
|
@ -36,6 +34,16 @@ public abstract class AbstractTurnControl implements ITurnControl {
|
|||
return redealEvent;
|
||||
}
|
||||
|
||||
private void pauseTurn() {
|
||||
timer.stopTimer();
|
||||
view.enablePauseMode(true);
|
||||
}
|
||||
|
||||
private void resumeTurn() {
|
||||
timer.startTimer();
|
||||
view.enablePauseMode(false);
|
||||
}
|
||||
|
||||
protected abstract void timeOut();
|
||||
|
||||
@Override
|
||||
|
@ -52,6 +60,18 @@ public abstract class AbstractTurnControl implements ITurnControl {
|
|||
timeOut();
|
||||
}
|
||||
}));
|
||||
connections.add(view.getPauseEvent().add(new IListener() {
|
||||
@Override
|
||||
public void handle() {
|
||||
pauseTurn();
|
||||
}
|
||||
}));
|
||||
connections.add(view.getEndPauseEvent().add(new IListener() {
|
||||
@Override
|
||||
public void handle() {
|
||||
resumeTurn();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
protected void cleanUp() {
|
||||
|
|
|
@ -111,8 +111,10 @@ public class BaseAIControl extends AbstractTurnControl {
|
|||
for (Stone stone : set) {
|
||||
handStones.add(pickUpMatchingStone(stone));
|
||||
}
|
||||
turnInfo.getTable().drop(new StoneSet(handStones), new Position(
|
||||
(float) Math.random() * 30 - 15, (float) Math.random() * 6 - 3));
|
||||
turnInfo.getTable().drop(
|
||||
new StoneSet(handStones),
|
||||
new Position((float) Math.random() * 30 - 15,
|
||||
(float) Math.random() * 6 - 3));
|
||||
}
|
||||
|
||||
emitEndOfTurn();
|
||||
|
|
|
@ -97,8 +97,7 @@ public class HumanTurnControl extends AbstractTurnControl {
|
|||
}
|
||||
}));
|
||||
|
||||
connections.add(view.getPlayerPanel().getRedealEvent()
|
||||
.add(new IListener() {
|
||||
connections.add(view.getPlayerPanel().getRedealEvent().add(new IListener() {
|
||||
@Override
|
||||
public void handle() {
|
||||
endOfTurn(true);
|
||||
|
@ -304,8 +303,10 @@ public class HumanTurnControl extends AbstractTurnControl {
|
|||
}
|
||||
|
||||
pickUpSelectedStones();
|
||||
turnInfo.getTable().drop(new StoneSet(selectedStones), new Position(position.getX()
|
||||
- selectedStones.size() * 0.5f, position.getY() - 0.5f));
|
||||
turnInfo.getTable().drop(
|
||||
new StoneSet(selectedStones),
|
||||
new Position(position.getX() - selectedStones.size() * 0.5f, position
|
||||
.getY() - 0.5f));
|
||||
selectedStones.clear();
|
||||
|
||||
view.getTablePanel().setStoneSets(turnInfo.getTable());
|
||||
|
@ -421,15 +422,14 @@ public class HumanTurnControl extends AbstractTurnControl {
|
|||
turnInfo.getTable().drop(joinedSet, newPos);
|
||||
} else {
|
||||
StoneSet joinedSet = new StoneSet(selectedStones).join(newSet);
|
||||
turnInfo.getTable().drop(joinedSet, new Position(newPos.getX()
|
||||
- selectedStones.size(), newPos.getY()));
|
||||
turnInfo.getTable().drop(joinedSet,
|
||||
new Position(newPos.getX() - selectedStones.size(), newPos.getY()));
|
||||
}
|
||||
} else {
|
||||
turnInfo.getTable().drop(
|
||||
new StoneSet(selectedStones),
|
||||
new Position(pos.getX()
|
||||
+ (set.getSize() - selectedStones.size()) * 0.5f,
|
||||
pos.getY()));
|
||||
new Position(pos.getX() + (set.getSize() - selectedStones.size())
|
||||
* 0.5f, pos.getY()));
|
||||
}
|
||||
|
||||
selectedStones.clear();
|
||||
|
@ -521,8 +521,7 @@ public class HumanTurnControl extends AbstractTurnControl {
|
|||
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;
|
||||
|
|
|
@ -43,6 +43,11 @@ public interface ITurnControl {
|
|||
*/
|
||||
public void startTurn();
|
||||
|
||||
/**
|
||||
* Abort the turn
|
||||
*/
|
||||
public void abortTurn();
|
||||
|
||||
/**
|
||||
* The TurnInfo class encapsulates all information concerning the current turn
|
||||
*/
|
||||
|
@ -108,9 +113,4 @@ public interface ITurnControl {
|
|||
return turnMode;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Abort the turn
|
||||
*/
|
||||
public void abortTurn();
|
||||
}
|
|
@ -17,7 +17,8 @@ public interface IPlayer extends Serializable {
|
|||
/**
|
||||
* Set the current hand of the player
|
||||
*
|
||||
* @param hand the new hand
|
||||
* @param hand
|
||||
* the new hand
|
||||
*/
|
||||
public void setHand(IHand hand);
|
||||
|
||||
|
|
|
@ -62,8 +62,8 @@ public class StoneSet implements Iterable<Stone>, Sizeable, Serializable {
|
|||
}
|
||||
|
||||
/**
|
||||
* Test for rule conflict within the StoneSet and determine whether the set
|
||||
* is a group or a run
|
||||
* Test for rule conflict within the StoneSet and determine whether the set is
|
||||
* a group or a run
|
||||
*
|
||||
* @param settings
|
||||
* GameSettings
|
||||
|
@ -87,14 +87,10 @@ public class StoneSet implements Iterable<Stone>, Sizeable, Serializable {
|
|||
if (stones.size() > settings.getHighestValue()) {
|
||||
return new Pair<Type, Integer>(INVALID, 0);
|
||||
} else if (stones.size() > settings.getStoneColors().size()) {
|
||||
return new Pair<Type, Integer>(
|
||||
RUN,
|
||||
(settings.getHighestValue() * (settings
|
||||
.getHighestValue() + 1))
|
||||
/ 2
|
||||
return new Pair<Type, Integer>(RUN,
|
||||
(settings.getHighestValue() * (settings.getHighestValue() + 1)) / 2
|
||||
- (stones.size() - settings.getHighestValue())
|
||||
* (stones.size() - settings.getHighestValue() - 1)
|
||||
/ 2);
|
||||
* (stones.size() - settings.getHighestValue() - 1) / 2);
|
||||
} else {
|
||||
return new Pair<Type, Integer>(GROUP, stones.size()
|
||||
* settings.getHighestValue());
|
||||
|
@ -187,8 +183,7 @@ public class StoneSet implements Iterable<Stone>, Sizeable, Serializable {
|
|||
return new Pair<StoneSet, StoneSet>(this, null);
|
||||
}
|
||||
StoneSet firstSet = new StoneSet(stones.subList(0, position));
|
||||
StoneSet secondSet = new StoneSet(stones.subList(position,
|
||||
stones.size()));
|
||||
StoneSet secondSet = new StoneSet(stones.subList(position, stones.size()));
|
||||
return new Pair<StoneSet, StoneSet>(firstSet, secondSet);
|
||||
}
|
||||
|
||||
|
|
|
@ -52,8 +52,7 @@ public class StoneTray<E extends Sizeable> implements IStoneTray<E> {
|
|||
if (currentObject == object)
|
||||
continue;
|
||||
Position currentPosition = getPosition(currentObject);
|
||||
if (!objectsOverlap(object, position, currentObject,
|
||||
currentPosition)) {
|
||||
if (!objectsOverlap(object, position, currentObject, currentPosition)) {
|
||||
continue;
|
||||
}
|
||||
// Object would be placed inside the current object
|
||||
|
@ -64,16 +63,17 @@ public class StoneTray<E extends Sizeable> implements IStoneTray<E> {
|
|||
// Move object to avoid overlap
|
||||
switch (newDirection) {
|
||||
case TOP:
|
||||
newPosition = new Position(currentPosition.getX(),
|
||||
position.getY() - currentObject.getHeight());
|
||||
newPosition = new Position(currentPosition.getX(), position.getY()
|
||||
- currentObject.getHeight());
|
||||
break;
|
||||
case BOTTOM:
|
||||
newPosition = new Position(currentPosition.getX(),
|
||||
position.getY() + object.getHeight());
|
||||
newPosition = new Position(currentPosition.getX(), position.getY()
|
||||
+ object.getHeight());
|
||||
break;
|
||||
case LEFT:
|
||||
newPosition = new Position(position.getX()
|
||||
- currentObject.getWidth(), currentPosition.getY());
|
||||
newPosition = new Position(
|
||||
position.getX() - currentObject.getWidth(),
|
||||
currentPosition.getY());
|
||||
break;
|
||||
case RIGHT:
|
||||
newPosition = new Position(position.getX() + object.getWidth(),
|
||||
|
@ -87,8 +87,8 @@ public class StoneTray<E extends Sizeable> implements IStoneTray<E> {
|
|||
}
|
||||
|
||||
/**
|
||||
* Checks whether the object may be placed on the given position, computes
|
||||
* new position if not
|
||||
* Checks whether the object may be placed on the given position, computes new
|
||||
* position if not
|
||||
*
|
||||
* @param object
|
||||
* to be dropped
|
||||
|
@ -122,15 +122,13 @@ public class StoneTray<E extends Sizeable> implements IStoneTray<E> {
|
|||
if (lessOrEqual(position1.getX() + object1.getWidth(), position2.getX())) {
|
||||
return false;
|
||||
}
|
||||
if (lessOrEqual(position1.getY() + object1.getHeight(),
|
||||
position2.getY())) {
|
||||
if (lessOrEqual(position1.getY() + object1.getHeight(), position2.getY())) {
|
||||
return false;
|
||||
}
|
||||
if (lessOrEqual(position2.getX() + object2.getWidth(), position1.getX())) {
|
||||
return false;
|
||||
}
|
||||
if (lessOrEqual(position2.getY() + object2.getHeight(),
|
||||
position1.getY())) {
|
||||
if (lessOrEqual(position2.getY() + object2.getHeight(), position1.getY())) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -171,15 +169,13 @@ public class StoneTray<E extends Sizeable> implements IStoneTray<E> {
|
|||
double blockingRight = blocking.getSecond().getX()
|
||||
+ blocking.getFirst().getWidth();
|
||||
double overlapRight = Math.min(objectRight, blockingRight);
|
||||
double overlapLeft = Math.max(position.getX(), blocking.getSecond()
|
||||
.getX());
|
||||
double overlapLeft = Math.max(position.getX(), blocking.getSecond().getX());
|
||||
double overlapX = overlapRight - overlapLeft;
|
||||
double objectBottom = position.getY() + object.getHeight();
|
||||
double blockingBottom = blocking.getSecond().getY()
|
||||
+ blocking.getFirst().getHeight();
|
||||
double overlapBottom = Math.min(objectBottom, blockingBottom);
|
||||
double overlapTop = Math.max(position.getY(), blocking.getSecond()
|
||||
.getY());
|
||||
double overlapTop = Math.max(position.getY(), blocking.getSecond().getY());
|
||||
double overlapY = overlapBottom - overlapTop;
|
||||
// vertical or horizontal Shift
|
||||
// TODO magic factor
|
||||
|
|
|
@ -36,8 +36,8 @@ public interface ISettingsPanel {
|
|||
};
|
||||
|
||||
/**
|
||||
* The add player event is emitted when the user wants to add a player to
|
||||
* the player list
|
||||
* The add player event is emitted when the user wants to add a player to the
|
||||
* player list
|
||||
*
|
||||
* @return the event
|
||||
*/
|
||||
|
@ -84,8 +84,8 @@ public interface ISettingsPanel {
|
|||
public IEvent1<Integer> getChangeInitialMeldThresholdEvent();
|
||||
|
||||
/**
|
||||
* The change StoneSet number event is emitted when the user wants to use
|
||||
* more or less than 2 StoneSets per color
|
||||
* The change StoneSet number event is emitted when the user wants to use more
|
||||
* or less than 2 StoneSets per color
|
||||
*
|
||||
* @return number of SoneSets
|
||||
*/
|
||||
|
|
|
@ -108,8 +108,8 @@ public interface IView {
|
|||
public void setCurrentPlayerColor(Color color);
|
||||
|
||||
/**
|
||||
* Is used for the PlayerPanel to display if a player has laid out along
|
||||
* with the name
|
||||
* Is used for the PlayerPanel to display if a player has laid out along with
|
||||
* the name
|
||||
*
|
||||
* @param hasLaidOut
|
||||
* specifies if the current player has laid out or not
|
||||
|
@ -132,24 +132,8 @@ public interface IView {
|
|||
public void setBottomPanel(BottomPanelType type);
|
||||
|
||||
/**
|
||||
* Different types of bottom panels
|
||||
*/
|
||||
public enum BottomPanelType {
|
||||
/** */
|
||||
START_GAME_PANEL,
|
||||
/** */
|
||||
START_TURN_PANEL,
|
||||
/** */
|
||||
HUMAN_HAND_PANEL,
|
||||
/** */
|
||||
COMPUTER_HAND_PANEL,
|
||||
/** */
|
||||
WIN_PANEL
|
||||
}
|
||||
|
||||
/**
|
||||
* The menu new game event is emitted when the user selects the new game
|
||||
* menu entry
|
||||
* The menu new game event is emitted when the user selects the new game menu
|
||||
* entry
|
||||
*
|
||||
* @return the event
|
||||
*/
|
||||
|
@ -178,5 +162,27 @@ public interface IView {
|
|||
*/
|
||||
public IEvent1<File> getSaveEvent();
|
||||
|
||||
public IEvent getPauseEvent();
|
||||
|
||||
public IEvent getEndPauseEvent();
|
||||
|
||||
public void clearView();
|
||||
|
||||
void enablePauseMode(boolean enable);
|
||||
|
||||
/**
|
||||
* Different types of bottom panels
|
||||
*/
|
||||
public enum BottomPanelType {
|
||||
/** */
|
||||
START_GAME_PANEL,
|
||||
/** */
|
||||
START_TURN_PANEL,
|
||||
/** */
|
||||
HUMAN_HAND_PANEL,
|
||||
/** */
|
||||
COMPUTER_HAND_PANEL,
|
||||
/** */
|
||||
WIN_PANEL
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,8 +37,8 @@ class HandPanel extends AbstractStonePanel implements IHandPanel {
|
|||
HandPanel.class.getResource("/jrummikub/resource/dark_wood.png"));
|
||||
BACKGROUND = new BufferedImage(image.getIconWidth(), image.getIconHeight(),
|
||||
BufferedImage.TYPE_INT_RGB);
|
||||
DARK_BACKGROUND = new BufferedImage(darkImage.getIconWidth(), darkImage.getIconHeight(),
|
||||
BufferedImage.TYPE_INT_RGB);
|
||||
DARK_BACKGROUND = new BufferedImage(darkImage.getIconWidth(),
|
||||
darkImage.getIconHeight(), BufferedImage.TYPE_INT_RGB);
|
||||
|
||||
image.paintIcon(null, BACKGROUND.createGraphics(), 0, 0);
|
||||
darkImage.paintIcon(null, DARK_BACKGROUND.createGraphics(), 0, 0);
|
||||
|
@ -54,6 +54,7 @@ class HandPanel extends AbstractStonePanel implements IHandPanel {
|
|||
|
||||
private boolean repaintAll = true;
|
||||
private Collection<Stone> selectedStones = Collections.emptyList();
|
||||
|
||||
/**
|
||||
* Creates a new Board instance
|
||||
*/
|
||||
|
@ -92,8 +93,8 @@ class HandPanel extends AbstractStonePanel implements IHandPanel {
|
|||
|
||||
int size = height / HEIGHT;
|
||||
|
||||
|
||||
BufferedImage background = isEnabled() ? scaledBackground : scaledDarkBackground ;
|
||||
BufferedImage background = isEnabled() ? scaledBackground
|
||||
: scaledDarkBackground;
|
||||
|
||||
if (repaintAll) {
|
||||
if (background.getHeight() != size) {
|
||||
|
|
|
@ -19,7 +19,21 @@ class ImageUtil {
|
|||
g.fillRect(0, 0, size, size);
|
||||
|
||||
g.setColor(c);
|
||||
g.fillRect(border, border, size - 2*border, size - 2*border);
|
||||
g.fillRect(border, border, size - 2 * border, size - 2 * border);
|
||||
|
||||
return new ImageIcon(image);
|
||||
}
|
||||
|
||||
static ImageIcon createPauseIcon(int size) {
|
||||
BufferedImage image = new BufferedImage(size, size,
|
||||
BufferedImage.TYPE_INT_ARGB);
|
||||
|
||||
Graphics2D g = image.createGraphics();
|
||||
|
||||
g.setColor(Color.BLACK);
|
||||
int barWidth = (int) (size * 0.425f);
|
||||
g.fillRect(0, 0, barWidth, size);
|
||||
g.fillRect(size - barWidth, 0, barWidth, size);
|
||||
|
||||
return new ImageIcon(image);
|
||||
}
|
||||
|
|
95
src/jrummikub/view/impl/PausePanel.java
Normal file
95
src/jrummikub/view/impl/PausePanel.java
Normal file
|
@ -0,0 +1,95 @@
|
|||
package jrummikub.view.impl;
|
||||
|
||||
import java.awt.Insets;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
|
||||
import jrummikub.util.Event;
|
||||
import jrummikub.util.IEvent;
|
||||
|
||||
/**
|
||||
* A panel that is displayed before a player's turn
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
class PausePanel extends JPanel {
|
||||
private final static int PANEL_INSET = 15;
|
||||
private final static int PANEL_SEPARATOR = 10;
|
||||
private final static float PANEL_FIRST_LINE_HEIGHT = 0.375f;
|
||||
private final static int PANEL_MAX_WIDTH = 180;
|
||||
private final static float MAX_BUTTON_FONT_SIZE = 12;
|
||||
|
||||
private JLabel pauseLabel;
|
||||
private JButton endPauseButton;
|
||||
|
||||
private Event endPauseEvent = new Event();
|
||||
|
||||
/**
|
||||
* Creates a new StartTurnPanel
|
||||
*/
|
||||
PausePanel() {
|
||||
setLayout(null);
|
||||
setBorder(new EmptyBorder(PANEL_INSET, PANEL_INSET, PANEL_INSET,
|
||||
PANEL_INSET));
|
||||
|
||||
pauseLabel = new JLabel();
|
||||
pauseLabel.setHorizontalAlignment(JLabel.CENTER);
|
||||
pauseLabel.setHorizontalTextPosition(JLabel.CENTER);
|
||||
pauseLabel.setVerticalAlignment(JLabel.CENTER);
|
||||
pauseLabel.setVerticalTextPosition(JLabel.CENTER);
|
||||
add(pauseLabel);
|
||||
|
||||
endPauseButton = new JButton("Spiel fortsetzen");
|
||||
endPauseButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
endPauseEvent.emit();
|
||||
}
|
||||
});
|
||||
add(endPauseButton);
|
||||
|
||||
addComponentListener(new ComponentAdapter() {
|
||||
@Override
|
||||
public void componentResized(ComponentEvent e) {
|
||||
rescale();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void setCurrentPlayerName(String playerName) {
|
||||
pauseLabel.setText("Der Zug von " + playerName + " ist pausiert.");
|
||||
}
|
||||
|
||||
IEvent getEndPauseEvent() {
|
||||
return endPauseEvent;
|
||||
}
|
||||
|
||||
private void rescale() {
|
||||
Insets insets = getInsets();
|
||||
int x = insets.left, y = insets.top, width = getWidth() - insets.left
|
||||
- insets.right, height = getHeight() - insets.top - insets.bottom;
|
||||
|
||||
if (width > PANEL_MAX_WIDTH) {
|
||||
x += (width - PANEL_MAX_WIDTH) / 4;
|
||||
width = width / 2 + PANEL_MAX_WIDTH / 2;
|
||||
}
|
||||
|
||||
int firstLineHeight = (int) ((height - PANEL_SEPARATOR) * PANEL_FIRST_LINE_HEIGHT);
|
||||
int buttonWidth = width;
|
||||
int buttonHeight = height - PANEL_SEPARATOR - firstLineHeight;
|
||||
float fontSize = (float) Math.sqrt(buttonWidth * buttonHeight) / 5;
|
||||
if (fontSize > MAX_BUTTON_FONT_SIZE)
|
||||
fontSize = MAX_BUTTON_FONT_SIZE;
|
||||
|
||||
pauseLabel.setBounds(x, y, width, firstLineHeight);
|
||||
endPauseButton.setBounds(x, y + firstLineHeight + PANEL_SEPARATOR,
|
||||
buttonWidth, buttonHeight);
|
||||
endPauseButton.setFont(endPauseButton.getFont().deriveFont(fontSize));
|
||||
}
|
||||
}
|
|
@ -53,11 +53,13 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
|
|||
private JButton endTurnButton;
|
||||
private JButton keepStonesButton;
|
||||
private JButton redealButton;
|
||||
private JButton pauseButton;
|
||||
|
||||
private Event sortByGroupsEvent = new Event();
|
||||
private Event sortByRunsEvent = new Event();
|
||||
private Event endTurnEvent = new Event();
|
||||
private Event redealEvent = new Event();
|
||||
private Event pauseEvent = new Event();
|
||||
|
||||
HandPanel getHandPanel() {
|
||||
return hand;
|
||||
|
@ -117,6 +119,10 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
|
|||
return redealEvent;
|
||||
}
|
||||
|
||||
IEvent getPauseEvent() {
|
||||
return pauseEvent;
|
||||
}
|
||||
|
||||
private void createLeftPanel() {
|
||||
leftPanel = new JPanel();
|
||||
leftPanel.setLayout(null);
|
||||
|
@ -206,6 +212,13 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
|
|||
redealEvent.emit();
|
||||
}
|
||||
});
|
||||
|
||||
pauseButton = createButton(rightPanel, null, new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
pauseEvent.emit();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private JButton createButton(JPanel panel, String caption,
|
||||
|
@ -271,6 +284,67 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
|
|||
hand.addComponentListener(rescaleListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEndTurnMode(TurnMode turnMode) {
|
||||
|
||||
switch (turnMode) {
|
||||
case MAY_REDEAL:
|
||||
endTurnButton.setVisible(false);
|
||||
keepStonesButton.setVisible(true);
|
||||
redealButton.setVisible(true);
|
||||
break;
|
||||
case INSPECT_ONLY:
|
||||
endTurnButton.setText("N\u00e4chster Spieler");
|
||||
endTurnButton.setVisible(true);
|
||||
keepStonesButton.setVisible(false);
|
||||
redealButton.setVisible(false);
|
||||
break;
|
||||
case NORMAL_TURN:
|
||||
endTurnButton.setText("Zug beenden");
|
||||
endTurnButton.setVisible(true);
|
||||
keepStonesButton.setVisible(false);
|
||||
redealButton.setVisible(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void showButtons(boolean show) {
|
||||
currentPlayerNameLabel.setVisible(show);
|
||||
hasLaidOutLabel.setVisible(show);
|
||||
sortByGroupsButton.setVisible(show);
|
||||
sortByRunsButton.setVisible(show);
|
||||
timeBar.setVisible(show);
|
||||
pauseButton.setVisible(show);
|
||||
|
||||
if (!show) {
|
||||
handRowDownButton.setForeground(Color.GRAY);
|
||||
handRowDownButton.setEnabled(false);
|
||||
handRowUpButton.setForeground(Color.GRAY);
|
||||
handRowUpButton.setEnabled(false);
|
||||
endTurnButton.setVisible(false);
|
||||
redealButton.setVisible(false);
|
||||
keepStonesButton.setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
void enableButtons(boolean enable) {
|
||||
sortByGroupsButton.setEnabled(enable);
|
||||
sortByRunsButton.setEnabled(enable);
|
||||
if (!enable) {
|
||||
setEndTurnMode(TurnMode.NORMAL_TURN);
|
||||
endTurnButton.setText("<html><center>Computer denkt nach");
|
||||
hand.setStones(Collections.<Pair<Stone, Position>> emptyList());
|
||||
handRowDownButton.setForeground(Color.GRAY);
|
||||
handRowDownButton.setEnabled(false);
|
||||
handRowUpButton.setForeground(Color.GRAY);
|
||||
handRowUpButton.setEnabled(false);
|
||||
}
|
||||
endTurnButton.setEnabled(enable);
|
||||
redealButton.setEnabled(enable);
|
||||
keepStonesButton.setEnabled(enable);
|
||||
hand.setEnabled(enable);
|
||||
}
|
||||
|
||||
private class LeftPanelResizeListener extends ComponentAdapter {
|
||||
@Override
|
||||
public void componentResized(ComponentEvent e) {
|
||||
|
@ -341,10 +415,16 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
|
|||
fontSize * 1.5f));
|
||||
handRowDownButton.setBounds(0, getHeight() / 2, handButtonWidth,
|
||||
getHeight() / 2);
|
||||
handRowDownButton.setFont(handRowDownButton.getFont().deriveFont(
|
||||
fontSize * 1.5f));
|
||||
handRowDownButton.setFont(handRowDownButton.getFont()
|
||||
.deriveFont(fontSize));
|
||||
|
||||
timeBar.setBounds(x, y, width - firstLineHeight - SIDE_PANEL_SEPARATOR,
|
||||
firstLineHeight);
|
||||
pauseButton.setBounds(x + width - firstLineHeight, y, firstLineHeight,
|
||||
firstLineHeight);
|
||||
pauseButton.setIcon(ImageUtil
|
||||
.createPauseIcon((int) (firstLineHeight * 0.5f)));
|
||||
|
||||
timeBar.setBounds(x, y, width, firstLineHeight);
|
||||
endTurnButton.setBounds(x, y + firstLineHeight + SIDE_PANEL_SEPARATOR,
|
||||
buttonWidth, buttonHeight);
|
||||
endTurnButton.setFont(endTurnButton.getFont().deriveFont(fontSize));
|
||||
|
@ -360,64 +440,4 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
|
|||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEndTurnMode(TurnMode turnMode) {
|
||||
|
||||
switch (turnMode) {
|
||||
case MAY_REDEAL:
|
||||
endTurnButton.setVisible(false);
|
||||
keepStonesButton.setVisible(true);
|
||||
redealButton.setVisible(true);
|
||||
break;
|
||||
case INSPECT_ONLY:
|
||||
endTurnButton.setText("N\u00e4chster Spieler");
|
||||
endTurnButton.setVisible(true);
|
||||
keepStonesButton.setVisible(false);
|
||||
redealButton.setVisible(false);
|
||||
break;
|
||||
case NORMAL_TURN:
|
||||
endTurnButton.setText("Zug beenden");
|
||||
endTurnButton.setVisible(true);
|
||||
keepStonesButton.setVisible(false);
|
||||
redealButton.setVisible(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void showButtons(boolean show) {
|
||||
currentPlayerNameLabel.setVisible(show);
|
||||
hasLaidOutLabel.setVisible(show);
|
||||
sortByGroupsButton.setVisible(show);
|
||||
sortByRunsButton.setVisible(show);
|
||||
timeBar.setVisible(show);
|
||||
|
||||
if (!show) {
|
||||
handRowDownButton.setForeground(Color.GRAY);
|
||||
handRowDownButton.setEnabled(false);
|
||||
handRowUpButton.setForeground(Color.GRAY);
|
||||
handRowUpButton.setEnabled(false);
|
||||
endTurnButton.setVisible(false);
|
||||
redealButton.setVisible(false);
|
||||
keepStonesButton.setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
void enableButtons(boolean enable) {
|
||||
sortByGroupsButton.setEnabled(enable);
|
||||
sortByRunsButton.setEnabled(enable);
|
||||
if (!enable) {
|
||||
setEndTurnMode(TurnMode.NORMAL_TURN);
|
||||
endTurnButton.setText("<html><center>Computer denkt nach");
|
||||
hand.setStones(Collections.<Pair<Stone, Position>> emptyList());
|
||||
handRowDownButton.setForeground(Color.GRAY);
|
||||
handRowDownButton.setEnabled(false);
|
||||
handRowUpButton.setForeground(Color.GRAY);
|
||||
handRowUpButton.setEnabled(false);
|
||||
}
|
||||
endTurnButton.setEnabled(enable);
|
||||
redealButton.setEnabled(enable);
|
||||
keepStonesButton.setEnabled(enable);
|
||||
hand.setEnabled(enable);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,22 +62,10 @@ class StartTurnPanel extends JPanel {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current player name
|
||||
*
|
||||
* @param playerName
|
||||
* the player name
|
||||
*/
|
||||
void setCurrentPlayerName(String playerName) {
|
||||
startTurnLabel.setText(playerName + " ist jetzt an der Reihe.");
|
||||
}
|
||||
|
||||
/**
|
||||
* The start turn event is emitted when the current player has clicked the
|
||||
* start turn button
|
||||
*
|
||||
* @return the event
|
||||
*/
|
||||
IEvent getStartTurnEvent() {
|
||||
return startTurnEvent;
|
||||
}
|
||||
|
|
|
@ -37,6 +37,8 @@ class StoneCollectionPanel extends AbstractStonePanel implements
|
|||
|
||||
private Event1<Point> otherClickEvent = new Event1<Point>();
|
||||
|
||||
private boolean pauseMode = false;
|
||||
|
||||
/**
|
||||
* Creates a new StoneCollection instance
|
||||
*/
|
||||
|
@ -121,6 +123,10 @@ class StoneCollectionPanel extends AbstractStonePanel implements
|
|||
}
|
||||
}
|
||||
|
||||
if (pauseMode) {
|
||||
return;
|
||||
}
|
||||
|
||||
int inset = (int) (getHeight() * INSET_RATIO);
|
||||
int width = getStonePainter().getStoneWidth() * selectedStones.size() + 2
|
||||
* inset, height = getHeight();
|
||||
|
@ -148,4 +154,9 @@ class StoneCollectionPanel extends AbstractStonePanel implements
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
void enablePauseMode(boolean enable) {
|
||||
pauseMode = enable;
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,8 +60,7 @@ class StonePainter {
|
|||
int g = (int) (color.getGreen() * BRIGHTER_SCALE);
|
||||
int b = (int) (color.getBlue() * BRIGHTER_SCALE);
|
||||
|
||||
return new Color(r > 255 ? 255 : r, g > 255 ? 255 : g, b > 255 ? 255
|
||||
: b);
|
||||
return new Color(r > 255 ? 255 : r, g > 255 ? 255 : g, b > 255 ? 255 : b);
|
||||
}
|
||||
|
||||
private static Color hover(Color color) {
|
||||
|
@ -69,8 +68,7 @@ class StonePainter {
|
|||
int g = (int) (color.getGreen() * HOVER_RATIO + 255 * (1 - HOVER_RATIO));
|
||||
int b = (int) (color.getBlue() * HOVER_RATIO + 255 * (1 - HOVER_RATIO));
|
||||
|
||||
return new Color(r > 255 ? 255 : r, g > 255 ? 255 : g, b > 255 ? 255
|
||||
: b);
|
||||
return new Color(r > 255 ? 255 : r, g > 255 ? 255 : g, b > 255 ? 255 : b);
|
||||
}
|
||||
|
||||
public static Color getColor(StoneColor color) {
|
||||
|
@ -211,8 +209,7 @@ class StonePainter {
|
|||
defaultStones.put(color, new HashMap<Integer, BufferedImage>());
|
||||
selectedStones.put(color, new HashMap<Integer, BufferedImage>());
|
||||
hoveredStones.put(color, new HashMap<Integer, BufferedImage>());
|
||||
hoveredSelectedStones.put(color,
|
||||
new HashMap<Integer, BufferedImage>());
|
||||
hoveredSelectedStones.put(color, new HashMap<Integer, BufferedImage>());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -224,8 +221,7 @@ class StonePainter {
|
|||
setScale(scale);
|
||||
}
|
||||
|
||||
private void paintStoneBackground(Graphics2D g, Rectangle r,
|
||||
Color background) {
|
||||
private void paintStoneBackground(Graphics2D g, Rectangle r, Color background) {
|
||||
// Paint background
|
||||
g.setColor(background);
|
||||
g.fillRect(r.x, r.y, r.width, r.height);
|
||||
|
@ -326,9 +322,8 @@ class StonePainter {
|
|||
pos + (fm.getAscent() - fm.getDescent()) / 2 + 1);
|
||||
}
|
||||
g.setColor(color);
|
||||
g.drawString(value,
|
||||
(int) (r.x + r.width / 2 - stringRect.getWidth() / 2), pos
|
||||
+ (fm.getAscent() - fm.getDescent()) / 2);
|
||||
g.drawString(value, (int) (r.x + r.width / 2 - stringRect.getWidth() / 2),
|
||||
pos + (fm.getAscent() - fm.getDescent()) / 2);
|
||||
}
|
||||
|
||||
private void paintCircle(Graphics2D g, Rectangle r, Color background) {
|
||||
|
@ -337,12 +332,11 @@ class StonePainter {
|
|||
|
||||
// Paint circle
|
||||
g.setColor(background.darker());
|
||||
g.drawArc(r.x + r.width / 2 - size / 2, pos - size / 2, size, size, 50,
|
||||
170);
|
||||
g.drawArc(r.x + r.width / 2 - size / 2, pos - size / 2, size, size, 50, 170);
|
||||
|
||||
g.setColor(brighter(background));
|
||||
g.drawArc((int) (r.x + r.width / 2 - size / 2), pos - size / 2, size,
|
||||
size, -130, 170);
|
||||
g.drawArc((int) (r.x + r.width / 2 - size / 2), pos - size / 2, size, size,
|
||||
-130, 170);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -363,16 +357,16 @@ class StonePainter {
|
|||
boolean selected, boolean hovered) {
|
||||
int width = getStoneWidth();
|
||||
int height = getStoneHeight();
|
||||
int x = (int) Math.round(p.getX() * width), y = (int) Math.round(p
|
||||
.getY() * height);
|
||||
int x = (int) Math.round(p.getX() * width), y = (int) Math.round(p.getY()
|
||||
* height);
|
||||
|
||||
if (stone.isJoker()) {
|
||||
g.drawImage(getStoneImage(stone.getColor(), 0, selected, hovered),
|
||||
x, y, null);
|
||||
g.drawImage(getStoneImage(stone.getColor(), 0, selected, hovered), x, y,
|
||||
null);
|
||||
} else {
|
||||
g.drawImage(
|
||||
getStoneImage(stone.getColor(), stone.getValue(), selected,
|
||||
hovered), x, y, null);
|
||||
getStoneImage(stone.getColor(), stone.getValue(), selected, hovered),
|
||||
x, y, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import java.awt.geom.AffineTransform;
|
|||
import java.awt.geom.Area;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
@ -20,6 +21,7 @@ import javax.swing.SwingUtilities;
|
|||
|
||||
import jrummikub.model.Position;
|
||||
import jrummikub.model.Stone;
|
||||
import jrummikub.model.StoneColor;
|
||||
import jrummikub.model.StoneSet;
|
||||
import jrummikub.util.Event1;
|
||||
import jrummikub.util.IListener1;
|
||||
|
@ -39,8 +41,8 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
|
|||
private final static ImageIcon BRIGHT_BACKGROUND = new ImageIcon(
|
||||
HandPanel.class.getResource("/jrummikub/resource/bright_felt.png"));
|
||||
|
||||
private final static double MIN_VISIBLE_WIDTH = 15;
|
||||
private final static double MIN_VISIBLE_HEIGHT = 7.5f;
|
||||
private final static double MIN_VISIBLE_WIDTH = 10;
|
||||
private final static double MIN_VISIBLE_HEIGHT = 5;
|
||||
private final static double HORIZONTAL_MARGIN = 1;
|
||||
private final static double VERTICAL_MARGIN = 0.7f;
|
||||
private final static double CONNECTOR_WIDTH = 0.25f;
|
||||
|
@ -49,8 +51,9 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
|
|||
|
||||
private StoneCollectionPanel stoneCollection;
|
||||
|
||||
private Iterable<Pair<StoneSet, Position>> stoneSets = Collections
|
||||
.emptySet();
|
||||
private Iterable<Pair<StoneSet, Position>> stoneSets = Collections.emptySet();
|
||||
private List<Pair<StoneSet, Position>> pauseStoneSets;
|
||||
|
||||
private Collection<Stone> selectedStones = Collections.emptyList();
|
||||
|
||||
private Event1<StoneSet> leftConnectorClickEvent = new Event1<StoneSet>();
|
||||
|
@ -59,6 +62,8 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
|
|||
private StoneSet leftHoveredConnector;
|
||||
private StoneSet rightHoveredConnector;
|
||||
|
||||
private boolean pauseMode = false;
|
||||
|
||||
@Override
|
||||
public Event1<StoneSet> getLeftConnectorClickEvent() {
|
||||
return leftConnectorClickEvent;
|
||||
|
@ -107,12 +112,35 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
|
|||
repaint();
|
||||
}
|
||||
|
||||
void createPauseStoneSets() {
|
||||
pauseStoneSets = new ArrayList<Pair<StoneSet, Position>>();
|
||||
|
||||
Stone stoneCoffee1 = new Stone(-'\u2615', StoneColor.BLACK);
|
||||
|
||||
Stone stoneP = new Stone(-'P', StoneColor.BLACK);
|
||||
Stone stonea = new Stone(-'a', StoneColor.ORANGE);
|
||||
Stone stoneu = new Stone(-'u', StoneColor.BLUE);
|
||||
Stone stones = new Stone(-'s', StoneColor.RED);
|
||||
Stone stonee = new Stone(-'e', StoneColor.BLACK);
|
||||
|
||||
Stone stoneCoffee2 = new Stone(-'\u2615', StoneColor.RED);
|
||||
|
||||
pauseStoneSets.add(new Pair<StoneSet, Position>(new StoneSet(stoneCoffee1),
|
||||
new Position(-4, 0)));
|
||||
pauseStoneSets.add(new Pair<StoneSet, Position>(new StoneSet(Arrays.asList(
|
||||
stoneP, stonea, stoneu, stones, stonee)), new Position(-2.5, 0)));
|
||||
pauseStoneSets.add(new Pair<StoneSet, Position>(new StoneSet(stoneCoffee2),
|
||||
new Position(3, 0)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new Table instance
|
||||
*/
|
||||
TablePanel() {
|
||||
setLayout(null);
|
||||
|
||||
createPauseStoneSets();
|
||||
|
||||
stoneCollection = new StoneCollectionPanel();
|
||||
stoneCollection.getOtherClickEvent().add(new IListener1<Point>() {
|
||||
|
||||
|
@ -138,7 +166,8 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
|
|||
double minx = -MIN_VISIBLE_WIDTH / 2, maxx = MIN_VISIBLE_WIDTH / 2;
|
||||
double miny = -MIN_VISIBLE_HEIGHT / 2, maxy = MIN_VISIBLE_HEIGHT / 2;
|
||||
|
||||
for (Pair<StoneSet, Position> entry : stoneSets) {
|
||||
for (Pair<StoneSet, Position> entry : (pauseMode ? pauseStoneSets
|
||||
: stoneSets)) {
|
||||
Position p = entry.getSecond();
|
||||
StoneSet stoneSet = entry.getFirst();
|
||||
|
||||
|
@ -156,19 +185,19 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
|
|||
}
|
||||
|
||||
return new Rectangle2D.Double(minx - HORIZONTAL_MARGIN, miny
|
||||
- VERTICAL_MARGIN, maxx - minx + 2 * HORIZONTAL_MARGIN, maxy
|
||||
- miny + 2 * VERTICAL_MARGIN);
|
||||
- VERTICAL_MARGIN, maxx - minx + 2 * HORIZONTAL_MARGIN, maxy - miny + 2
|
||||
* VERTICAL_MARGIN);
|
||||
}
|
||||
|
||||
private void rescale() {
|
||||
Insets insets = getInsets();
|
||||
int x = insets.left, y = insets.top, width = getWidth() - insets.left
|
||||
- insets.right, height = getHeight() - insets.top
|
||||
- insets.bottom;
|
||||
- insets.right, height = getHeight() - insets.top - insets.bottom;
|
||||
|
||||
int collectionHeight = (int) (height * COLLECTION_RATIO);
|
||||
stoneCollection.setBounds(x, y + height - collectionHeight
|
||||
- COLLECTION_GAP, width, collectionHeight);
|
||||
stoneCollection
|
||||
.setBounds(x, y + height - collectionHeight - COLLECTION_GAP, width,
|
||||
collectionHeight);
|
||||
|
||||
setScale();
|
||||
|
||||
|
@ -205,8 +234,8 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
|
|||
}
|
||||
|
||||
// right connector
|
||||
rect = new Rectangle2D.Double(x + stoneSet.getSize(), y,
|
||||
CONNECTOR_WIDTH, 1);
|
||||
rect = new Rectangle2D.Double(x + stoneSet.getSize(), y, CONNECTOR_WIDTH,
|
||||
1);
|
||||
if (rect.contains(pos.getX(), pos.getY())) {
|
||||
rightConnectorClickEvent.emit(stoneSet);
|
||||
return true;
|
||||
|
@ -237,8 +266,8 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
|
|||
}
|
||||
|
||||
// right connector
|
||||
rect = new Rectangle2D.Double(x + stoneSet.getSize(), y,
|
||||
CONNECTOR_WIDTH, 1);
|
||||
rect = new Rectangle2D.Double(x + stoneSet.getSize(), y, CONNECTOR_WIDTH,
|
||||
1);
|
||||
if (rect.contains(pos.getX(), pos.getY())) {
|
||||
rightHoveredConnector = stoneSet;
|
||||
break;
|
||||
|
@ -260,10 +289,10 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
|
|||
.getStoneHeight();
|
||||
Rectangle2D extent = calculateTableExtent();
|
||||
|
||||
return new Pair<Integer, Integer>(
|
||||
(int) (width / 2 - extent.getCenterX() * stoneWidth),
|
||||
(int) ((height * (1 - COLLECTION_RATIO)) / 2 - extent
|
||||
.getCenterY() * stoneHeight));
|
||||
return new Pair<Integer, Integer>((int) (width / 2 - extent.getCenterX()
|
||||
* stoneWidth),
|
||||
(int) ((height * (1 - COLLECTION_RATIO)) / 2 - extent.getCenterY()
|
||||
* stoneHeight));
|
||||
}
|
||||
|
||||
private void paintStoneSet(Graphics2D g, StoneSet stoneSet, Position pos,
|
||||
|
@ -278,10 +307,9 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
|
|||
|
||||
// Left connector
|
||||
|
||||
leftConnectorArea.add(new Area(new Rectangle2D.Double(Math.round(x
|
||||
* width)
|
||||
- (int) width * CONNECTOR_WIDTH + 1, Math.round(pos.getY()
|
||||
* height), (int) (width * CONNECTOR_WIDTH), height)));
|
||||
leftConnectorArea.add(new Area(new Rectangle2D.Double(Math.round(x * width)
|
||||
- (int) width * CONNECTOR_WIDTH + 1, Math.round(pos.getY() * height),
|
||||
(int) (width * CONNECTOR_WIDTH), height)));
|
||||
|
||||
for (Stone stone : stoneSet) {
|
||||
getStonePainter().paintStone(g, stone, new Position(x, pos.getY()),
|
||||
|
@ -290,8 +318,8 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
|
|||
}
|
||||
|
||||
// Right connector
|
||||
rightConnectorArea.add(new Area(new Rectangle2D.Double(Math.round(x
|
||||
* width), Math.round(pos.getY() * height),
|
||||
rightConnectorArea.add(new Area(new Rectangle2D.Double(Math
|
||||
.round(x * width), Math.round(pos.getY() * height),
|
||||
(int) (width * CONNECTOR_WIDTH), height)));
|
||||
}
|
||||
|
||||
|
@ -314,17 +342,21 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
|
|||
Area connectorArea = new Area();
|
||||
Area hoveredConnectorArea = new Area();
|
||||
|
||||
for (Pair<StoneSet, Position> entry : stoneSets) {
|
||||
paintStoneSet(g, entry.getFirst(), entry.getSecond(),
|
||||
connectorArea, hoveredConnectorArea);
|
||||
for (Pair<StoneSet, Position> entry : (pauseMode ? pauseStoneSets
|
||||
: stoneSets)) {
|
||||
paintStoneSet(g, entry.getFirst(), entry.getSecond(), connectorArea,
|
||||
hoveredConnectorArea);
|
||||
}
|
||||
|
||||
if (pauseMode) {
|
||||
return;
|
||||
}
|
||||
|
||||
g.setClip(connectorArea);
|
||||
g.setTransform(oldTransform);
|
||||
|
||||
for (int x = 0; x < getWidth(); x += DARK_BACKGROUND.getIconWidth()) {
|
||||
for (int y = 0; y < getHeight(); y += DARK_BACKGROUND
|
||||
.getIconHeight()) {
|
||||
for (int y = 0; y < getHeight(); y += DARK_BACKGROUND.getIconHeight()) {
|
||||
DARK_BACKGROUND.paintIcon(this, g, x, y);
|
||||
}
|
||||
}
|
||||
|
@ -340,12 +372,18 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
|
|||
g.setTransform(oldTransform);
|
||||
|
||||
for (int x = 0; x < getWidth(); x += BRIGHT_BACKGROUND.getIconWidth()) {
|
||||
for (int y = 0; y < getHeight(); y += BRIGHT_BACKGROUND
|
||||
.getIconHeight()) {
|
||||
for (int y = 0; y < getHeight(); y += BRIGHT_BACKGROUND.getIconHeight()) {
|
||||
BRIGHT_BACKGROUND.paintIcon(this, g, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
g.setClip(oldClip);
|
||||
}
|
||||
|
||||
void enablePauseMode(boolean enable) {
|
||||
stoneCollection.enablePauseMode(enable);
|
||||
|
||||
pauseMode = enable;
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,10 +53,13 @@ public class View extends JFrame implements IView {
|
|||
private TablePanel table;
|
||||
private PlayerPanel playerPanel;
|
||||
private StartTurnPanel startTurnPanel;
|
||||
private PausePanel pausePanel;
|
||||
private WinPanel winPanel;
|
||||
private SettingsPanel settingsPanel;
|
||||
private ScorePanel scorePanel;
|
||||
|
||||
private BottomPanelType bottomPanelType;
|
||||
|
||||
private JFileChooser chooser;
|
||||
|
||||
private Event menuNewGameEvent = new Event();
|
||||
|
@ -114,12 +117,21 @@ public class View extends JFrame implements IView {
|
|||
return saveEvent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEvent getPauseEvent() {
|
||||
return playerPanel.getPauseEvent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEvent getEndPauseEvent() {
|
||||
return pausePanel.getEndPauseEvent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearView() {
|
||||
showScorePanel(false);
|
||||
showSettingsPanel(false);
|
||||
getHandPanel().setStones(
|
||||
Collections.<Pair<Stone, Position>> emptyList());
|
||||
getHandPanel().setStones(Collections.<Pair<Stone, Position>> emptyList());
|
||||
getTablePanel().setStoneSets(
|
||||
Collections.<Pair<StoneSet, Position>> emptyList());
|
||||
setSelectedStones(Collections.<Stone> emptyList());
|
||||
|
@ -219,14 +231,18 @@ public class View extends JFrame implements IView {
|
|||
mainLayer.add(table);
|
||||
|
||||
playerPanel = new PlayerPanel();
|
||||
playerPanel.setBorder(new MatteBorder(PLAYER_PANEL_BORDER_WIDTH, 0, 0,
|
||||
0, Color.BLACK));
|
||||
playerPanel.setBorder(new MatteBorder(PLAYER_PANEL_BORDER_WIDTH, 0, 0, 0,
|
||||
Color.BLACK));
|
||||
mainLayer.add(playerPanel);
|
||||
|
||||
startTurnPanel = new StartTurnPanel();
|
||||
startTurnPanel.setVisible(false);
|
||||
mainLayer.add(startTurnPanel);
|
||||
|
||||
pausePanel = new PausePanel();
|
||||
pausePanel.setVisible(false);
|
||||
mainLayer.add(pausePanel);
|
||||
|
||||
winPanel = new WinPanel();
|
||||
winPanel.setVisible(false);
|
||||
mainLayer.add(winPanel);
|
||||
|
@ -251,6 +267,14 @@ public class View extends JFrame implements IView {
|
|||
setVisible(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enablePauseMode(boolean enable) {
|
||||
table.enablePauseMode(enable);
|
||||
|
||||
doSetBottomPanel(enable ? null : bottomPanelType);
|
||||
pausePanel.setVisible(enable);
|
||||
}
|
||||
|
||||
private void rescale() {
|
||||
int width = getContentPane().getWidth(), height = getContentPane()
|
||||
.getHeight();
|
||||
|
@ -270,6 +294,7 @@ public class View extends JFrame implements IView {
|
|||
table.validate();
|
||||
playerPanel.setBounds(0, tableHeight, width, playerPanelHeight);
|
||||
startTurnPanel.setBounds(0, tableHeight, width, playerPanelHeight);
|
||||
pausePanel.setBounds(0, tableHeight, width, playerPanelHeight);
|
||||
winPanel.setBounds(0, tableHeight, width, playerPanelHeight);
|
||||
settingsPanel.setBounds(width / 4, height / 4, width / 2, height / 2);
|
||||
scorePanel.setBounds(width / 8, height / 4, width * 3 / 4, height / 2);
|
||||
|
@ -295,6 +320,7 @@ public class View extends JFrame implements IView {
|
|||
public void setCurrentPlayerName(String playerName) {
|
||||
playerPanel.setCurrentPlayerName(playerName);
|
||||
startTurnPanel.setCurrentPlayerName(playerName);
|
||||
pausePanel.setCurrentPlayerName(playerName);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -329,24 +355,24 @@ public class View extends JFrame implements IView {
|
|||
|
||||
@SuppressWarnings("unchecked")
|
||||
private List<Pair<Stone, Position>> createDecorationStones() {
|
||||
Pair<Stone, Position> stoneJ = new Pair<Stone, Position>(new Stone(
|
||||
-'J', StoneColor.BLACK), new Position(2.5f, 0));
|
||||
Pair<Stone, Position> stoneR = new Pair<Stone, Position>(new Stone(
|
||||
-'R', StoneColor.ORANGE), new Position(3.5f, 0));
|
||||
Pair<Stone, Position> stoneu1 = new Pair<Stone, Position>(new Stone(
|
||||
-'u', StoneColor.BLUE), new Position(4.5f, 0));
|
||||
Pair<Stone, Position> stonem1 = new Pair<Stone, Position>(new Stone(
|
||||
-'m', StoneColor.RED), new Position(5.5f, 0));
|
||||
Pair<Stone, Position> stonem2 = new Pair<Stone, Position>(new Stone(
|
||||
-'m', StoneColor.GREEN), new Position(6.5f, 0));
|
||||
Pair<Stone, Position> stonei = new Pair<Stone, Position>(new Stone(
|
||||
-'i', StoneColor.VIOLET), new Position(7.5f, 0));
|
||||
Pair<Stone, Position> stonek = new Pair<Stone, Position>(new Stone(
|
||||
-'k', StoneColor.AQUA), new Position(8.5f, 0));
|
||||
Pair<Stone, Position> stoneu2 = new Pair<Stone, Position>(new Stone(
|
||||
-'u', StoneColor.GRAY), new Position(9.5f, 0));
|
||||
Pair<Stone, Position> stoneb = new Pair<Stone, Position>(new Stone(
|
||||
-'b', StoneColor.BLACK), new Position(10.5f, 0));
|
||||
Pair<Stone, Position> stoneJ = new Pair<Stone, Position>(new Stone(-'J',
|
||||
StoneColor.BLACK), new Position(2.5f, 0));
|
||||
Pair<Stone, Position> stoneR = new Pair<Stone, Position>(new Stone(-'R',
|
||||
StoneColor.ORANGE), new Position(3.5f, 0));
|
||||
Pair<Stone, Position> stoneu1 = new Pair<Stone, Position>(new Stone(-'u',
|
||||
StoneColor.BLUE), new Position(4.5f, 0));
|
||||
Pair<Stone, Position> stonem1 = new Pair<Stone, Position>(new Stone(-'m',
|
||||
StoneColor.RED), new Position(5.5f, 0));
|
||||
Pair<Stone, Position> stonem2 = new Pair<Stone, Position>(new Stone(-'m',
|
||||
StoneColor.GREEN), new Position(6.5f, 0));
|
||||
Pair<Stone, Position> stonei = new Pair<Stone, Position>(new Stone(-'i',
|
||||
StoneColor.VIOLET), new Position(7.5f, 0));
|
||||
Pair<Stone, Position> stonek = new Pair<Stone, Position>(new Stone(-'k',
|
||||
StoneColor.AQUA), new Position(8.5f, 0));
|
||||
Pair<Stone, Position> stoneu2 = new Pair<Stone, Position>(new Stone(-'u',
|
||||
StoneColor.GRAY), new Position(9.5f, 0));
|
||||
Pair<Stone, Position> stoneb = new Pair<Stone, Position>(new Stone(-'b',
|
||||
StoneColor.BLACK), new Position(10.5f, 0));
|
||||
|
||||
Pair<Stone, Position> stone1 = new Pair<Stone, Position>(new Stone(
|
||||
StoneColor.RED), new Position(2, 1));
|
||||
|
@ -361,21 +387,26 @@ public class View extends JFrame implements IView {
|
|||
Pair<Stone, Position> stone6 = new Pair<Stone, Position>(new Stone(
|
||||
StoneColor.BLACK), new Position(11, 1));
|
||||
|
||||
return Arrays.asList(stoneJ, stoneR, stoneu1, stonem1, stonem2, stonei,
|
||||
stonek, stoneu2, stoneb, stone1, stone2, stone3, stone4,
|
||||
stone5, stone6);
|
||||
return Arrays
|
||||
.asList(stoneJ, stoneR, stoneu1, stonem1, stonem2, stonei, stonek,
|
||||
stoneu2, stoneb, stone1, stone2, stone3, stone4, stone5, stone6);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBottomPanel(BottomPanelType type) {
|
||||
bottomPanelType = type;
|
||||
|
||||
doSetBottomPanel(type);
|
||||
}
|
||||
|
||||
private void doSetBottomPanel(BottomPanelType type) {
|
||||
startTurnPanel.setVisible(type == BottomPanelType.START_TURN_PANEL);
|
||||
winPanel.setVisible(type == BottomPanelType.WIN_PANEL);
|
||||
playerPanel.setVisible(type != BottomPanelType.START_TURN_PANEL
|
||||
&& type != BottomPanelType.WIN_PANEL);
|
||||
&& type != BottomPanelType.WIN_PANEL && type != null);
|
||||
|
||||
if (type == BottomPanelType.START_GAME_PANEL) {
|
||||
table.setStoneSets(Collections
|
||||
.<Pair<StoneSet, Position>> emptyList());
|
||||
table.setStoneSets(Collections.<Pair<StoneSet, Position>> emptyList());
|
||||
playerPanel.getHandPanel().setStones(createDecorationStones());
|
||||
}
|
||||
|
||||
|
|
|
@ -101,8 +101,7 @@ class WinPanel extends JPanel {
|
|||
private void rescale() {
|
||||
Insets insets = getInsets();
|
||||
int x = insets.left, y = insets.top, width = getWidth() - insets.left
|
||||
- insets.right, height = getHeight() - insets.top
|
||||
- insets.bottom;
|
||||
- insets.right, height = getHeight() - insets.top - insets.bottom;
|
||||
|
||||
if (width > PANEL_MAX_WIDTH) {
|
||||
x += (width - PANEL_MAX_WIDTH) / 4;
|
||||
|
@ -118,14 +117,13 @@ class WinPanel extends JPanel {
|
|||
newRoundButton.setBounds(x, y, buttonWidth, buttonHeight);
|
||||
newRoundButton.setFont(newRoundButton.getFont().deriveFont(fontSize));
|
||||
|
||||
newGameButton.setBounds(x + buttonWidth + PANEL_SEPARATOR, y,
|
||||
buttonWidth, buttonHeight);
|
||||
newGameButton.setBounds(x + buttonWidth + PANEL_SEPARATOR, y, buttonWidth,
|
||||
buttonHeight);
|
||||
newGameButton.setFont(newGameButton.getFont().deriveFont(fontSize));
|
||||
|
||||
endProgramButton.setBounds(x + 2 * (buttonWidth + PANEL_SEPARATOR), y,
|
||||
buttonWidth, buttonHeight);
|
||||
endProgramButton.setFont(endProgramButton.getFont()
|
||||
.deriveFont(fontSize));
|
||||
endProgramButton.setFont(endProgramButton.getFont().deriveFont(fontSize));
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue