Correctly show invalid sets
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@471 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
e8549b95df
commit
479384d6bf
13 changed files with 183 additions and 100 deletions
|
@ -92,4 +92,15 @@ public class MockHand implements IHand {
|
||||||
public int getIdenticalStoneCount() {
|
public int getIdenticalStoneCount() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean contains(Stone object) {
|
||||||
|
for (Pair<Stone, Position> stone : stones) {
|
||||||
|
if (stone.getFirst() == object) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,4 +69,15 @@ public class MockTable implements ITable {
|
||||||
return sets.size();
|
return sets.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean contains(StoneSet object) {
|
||||||
|
for (Pair<StoneSet, Position> set : sets) {
|
||||||
|
if (set.getFirst() == object) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import java.io.File;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
import jrummikub.model.Stone;
|
import jrummikub.model.Stone;
|
||||||
|
import jrummikub.model.StoneSet;
|
||||||
import jrummikub.util.IEvent;
|
import jrummikub.util.IEvent;
|
||||||
import jrummikub.util.IEvent1;
|
import jrummikub.util.IEvent1;
|
||||||
import jrummikub.util.MockEvent;
|
import jrummikub.util.MockEvent;
|
||||||
|
@ -237,4 +238,10 @@ public class MockView implements IView {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setInvalidStoneSets(Collection<StoneSet> sets) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,9 +50,9 @@ public class RoundControl {
|
||||||
* Create a new RoundControl using the given gameState and view
|
* Create a new RoundControl using the given gameState and view
|
||||||
*
|
*
|
||||||
* @param roundState
|
* @param roundState
|
||||||
* initial round state
|
* initial round state
|
||||||
* @param view
|
* @param view
|
||||||
* view used for user interaction
|
* view used for user interaction
|
||||||
*/
|
*/
|
||||||
public RoundControl(IRoundState roundState, IView view) {
|
public RoundControl(IRoundState roundState, IView view) {
|
||||||
this.roundState = roundState;
|
this.roundState = roundState;
|
||||||
|
@ -129,12 +129,11 @@ public class RoundControl {
|
||||||
}
|
}
|
||||||
|
|
||||||
view.getTablePanel().setStoneSets(clonedTable.clone());
|
view.getTablePanel().setStoneSets(clonedTable.clone());
|
||||||
view.setCurrentPlayerName(roundState.getActivePlayer()
|
view.setCurrentPlayerName(roundState.getActivePlayer().getPlayerSettings()
|
||||||
.getPlayerSettings().getName());
|
.getName());
|
||||||
view.setCurrentPlayerColor(roundState.getActivePlayer()
|
view.setCurrentPlayerColor(roundState.getActivePlayer().getPlayerSettings()
|
||||||
.getPlayerSettings().getColor());
|
.getColor());
|
||||||
view.setCurrentPlayerHasLaidOut(roundState.getActivePlayer()
|
view.setCurrentPlayerHasLaidOut(roundState.getActivePlayer().getLaidOut());
|
||||||
.getLaidOut());
|
|
||||||
|
|
||||||
if (!isHuman)
|
if (!isHuman)
|
||||||
startTurn();
|
startTurn();
|
||||||
|
@ -160,11 +159,10 @@ public class RoundControl {
|
||||||
view.getPlayerPanel().setEndTurnMode(turnMode);
|
view.getPlayerPanel().setEndTurnMode(turnMode);
|
||||||
}
|
}
|
||||||
turnControl = TurnControlFactory.getFactory(
|
turnControl = TurnControlFactory.getFactory(
|
||||||
roundState.getActivePlayer().getPlayerSettings().getType())
|
roundState.getActivePlayer().getPlayerSettings().getType()).create();
|
||||||
.create();
|
|
||||||
turnControl.setup(new ITurnControl.TurnInfo(clonedTable, clonedHand,
|
turnControl.setup(new ITurnControl.TurnInfo(clonedTable, clonedHand,
|
||||||
roundState.getActivePlayer().getLaidOut(), turnMode),
|
roundState.getActivePlayer().getLaidOut(), turnMode), roundState
|
||||||
roundState.getGameSettings(), view);
|
.getGameSettings(), view);
|
||||||
turnControl.getEndOfTurnEvent().add(new IListener() {
|
turnControl.getEndOfTurnEvent().add(new IListener() {
|
||||||
@Override
|
@Override
|
||||||
public void handle() {
|
public void handle() {
|
||||||
|
@ -184,10 +182,8 @@ public class RoundControl {
|
||||||
void deal() {
|
void deal() {
|
||||||
for (int i = 0; i < roundState.getPlayerCount(); i++) {
|
for (int i = 0; i < roundState.getPlayerCount(); i++) {
|
||||||
IHand hand = roundState.getNthNextPlayer(i).getHand();
|
IHand hand = roundState.getNthNextPlayer(i).getHand();
|
||||||
for (int j = 0; j < roundState.getGameSettings()
|
for (int j = 0; j < roundState.getGameSettings().getNumberOfStonesDealt(); j++) {
|
||||||
.getNumberOfStonesDealt(); j++) {
|
hand.drop(roundState.getGameHeap().drawStone(), new Position(0, 0));
|
||||||
hand.drop(roundState.getGameHeap().drawStone(), new Position(0,
|
|
||||||
0));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -198,13 +194,11 @@ public class RoundControl {
|
||||||
|
|
||||||
int totalValue = 0;
|
int totalValue = 0;
|
||||||
for (StoneSet set : newSets) {
|
for (StoneSet set : newSets) {
|
||||||
totalValue += set.classify(roundState.getGameSettings())
|
totalValue += set.classify(roundState.getGameSettings()).getSecond();
|
||||||
.getSecond();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return totalValue == 0
|
return totalValue == 0
|
||||||
|| totalValue >= roundState.getGameSettings()
|
|| totalValue >= roundState.getGameSettings().getInitialMeldThreshold();
|
||||||
.getInitialMeldThreshold();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void endOfTurn() {
|
private void endOfTurn() {
|
||||||
|
@ -223,26 +217,46 @@ public class RoundControl {
|
||||||
if (lastTurnNotEnoughPoints) {
|
if (lastTurnNotEnoughPoints) {
|
||||||
view.setInitialMeldError(roundState.getGameSettings()
|
view.setInitialMeldError(roundState.getGameSettings()
|
||||||
.getInitialMeldThreshold());
|
.getInitialMeldThreshold());
|
||||||
|
view.setInvalidStoneSets(tableSetDifference(roundState.getTable(),
|
||||||
|
clonedTable));
|
||||||
} else if (lastTurnMeldError) {
|
} else if (lastTurnMeldError) {
|
||||||
view.setInitialMeldFirstError();
|
view.setInitialMeldFirstError();
|
||||||
|
view.setInvalidStoneSets(touchedStoneSets());
|
||||||
} else {
|
} else {
|
||||||
List<Stone> markedStones = new ArrayList<Stone>();
|
|
||||||
for (Pair<StoneSet, Position> set : clonedTable) {
|
|
||||||
if (set.getFirst().isValid(roundState.getGameSettings())) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
for (Stone stone : set.getFirst()) {
|
|
||||||
markedStones.add(stone);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
view.setStoneCollectionHidden(true);
|
view.setStoneCollectionHidden(true);
|
||||||
view.setSelectedStones(markedStones);
|
view.setInvalidStoneSets(invalidStoneSets());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<StoneSet> invalidStoneSets() {
|
||||||
|
List<StoneSet> invalidSets = new ArrayList<StoneSet>();
|
||||||
|
for (Pair<StoneSet, Position> set : clonedTable) {
|
||||||
|
if (set.getFirst().isValid(roundState.getGameSettings())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
invalidSets.add(set.getFirst());
|
||||||
|
}
|
||||||
|
return invalidSets;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<StoneSet> touchedStoneSets() {
|
||||||
|
List<StoneSet> touchedSets = new ArrayList<StoneSet>();
|
||||||
|
for (StoneSet set : tableSetDifference(roundState.getTable(), clonedTable)) {
|
||||||
|
for (Stone stone : set) {
|
||||||
|
if (!roundState.getActivePlayer().getHand().contains(stone)) {
|
||||||
|
touchedSets.add(set);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return touchedSets;
|
||||||
|
}
|
||||||
|
|
||||||
private void nextPlayer() {
|
private void nextPlayer() {
|
||||||
view.setSelectedStones(Collections.<Stone> emptyList());
|
view.setSelectedStones(Collections.<Stone> emptyList());
|
||||||
|
view.setInvalidStoneSets(Collections.<StoneSet> emptyList());
|
||||||
view.setStoneCollectionHidden(false);
|
view.setStoneCollectionHidden(false);
|
||||||
if (roundState.getLastPlayer() == null) {
|
if (roundState.getLastPlayer() == null) {
|
||||||
if (roundState.getGameHeap().getSize() == 0) {
|
if (roundState.getGameHeap().getSize() == 0) {
|
||||||
|
@ -273,8 +287,7 @@ public class RoundControl {
|
||||||
}
|
}
|
||||||
if (!roundState.getActivePlayer().getLaidOut()) {
|
if (!roundState.getActivePlayer().getLaidOut()) {
|
||||||
// Player touched forbidden stones
|
// Player touched forbidden stones
|
||||||
if (!tableSetDifference(clonedTable, roundState.getTable())
|
if (!tableSetDifference(clonedTable, roundState.getTable()).isEmpty()) {
|
||||||
.isEmpty()) {
|
|
||||||
rejectMove();
|
rejectMove();
|
||||||
lastTurnMeldError = true;
|
lastTurnMeldError = true;
|
||||||
return false;
|
return false;
|
||||||
|
@ -285,8 +298,7 @@ public class RoundControl {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Set<Stone> tableDiff = tableDifference(roundState.getTable(),
|
Set<Stone> tableDiff = tableDifference(roundState.getTable(), clonedTable);
|
||||||
clonedTable);
|
|
||||||
|
|
||||||
roundState.setTable(clonedTable);
|
roundState.setTable(clonedTable);
|
||||||
|
|
||||||
|
@ -303,8 +315,7 @@ public class RoundControl {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void rejectMove() {
|
private void rejectMove() {
|
||||||
Set<Stone> tableDiff = tableDifference(roundState.getTable(),
|
Set<Stone> tableDiff = tableDifference(roundState.getTable(), clonedTable);
|
||||||
clonedTable);
|
|
||||||
// deal penalty, reset
|
// deal penalty, reset
|
||||||
roundState.getGameHeap().putBack(tableDiff);
|
roundState.getGameHeap().putBack(tableDiff);
|
||||||
dealPenalty(tableDiff.size());
|
dealPenalty(tableDiff.size());
|
||||||
|
@ -398,12 +409,10 @@ public class RoundControl {
|
||||||
stonePoints = playerHand.isInitialMeldPossible(roundState
|
stonePoints = playerHand.isInitialMeldPossible(roundState
|
||||||
.getGameSettings()) ? 200 : 100;
|
.getGameSettings()) ? 200 : 100;
|
||||||
} else {
|
} else {
|
||||||
stonePoints = playerHand.getStonePoints(roundState
|
stonePoints = playerHand.getStonePoints(roundState.getGameSettings());
|
||||||
.getGameSettings());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bestScore = updateBestScore(bestScore, -stonePoints, playerHand
|
bestScore = updateBestScore(bestScore, -stonePoints, playerHand.getSize());
|
||||||
.getSize());
|
|
||||||
|
|
||||||
points.add(-stonePoints);
|
points.add(-stonePoints);
|
||||||
pointSum += stonePoints;
|
pointSum += stonePoints;
|
||||||
|
@ -425,8 +434,8 @@ public class RoundControl {
|
||||||
private static Pair<Integer, Integer> updateBestScore(
|
private static Pair<Integer, Integer> updateBestScore(
|
||||||
Pair<Integer, Integer> bestScore, int stonePoints, int size) {
|
Pair<Integer, Integer> bestScore, int stonePoints, int size) {
|
||||||
if (bestScore.getFirst() == stonePoints) {
|
if (bestScore.getFirst() == stonePoints) {
|
||||||
return new Pair<Integer, Integer>(stonePoints, Math.min(bestScore
|
return new Pair<Integer, Integer>(stonePoints, Math.min(
|
||||||
.getSecond(), size));
|
bestScore.getSecond(), size));
|
||||||
} else if (bestScore.getFirst() < stonePoints) {
|
} else if (bestScore.getFirst() < stonePoints) {
|
||||||
return new Pair<Integer, Integer>(stonePoints, size);
|
return new Pair<Integer, Integer>(stonePoints, size);
|
||||||
}
|
}
|
||||||
|
|
|
@ -441,7 +441,7 @@ public class HumanTurnControl extends AbstractTurnControl {
|
||||||
|
|
||||||
private void endOfTurn(boolean redeal) {
|
private void endOfTurn(boolean redeal) {
|
||||||
cleanUp();
|
cleanUp();
|
||||||
view.setSelectedStones(new ArrayList<Stone>());
|
view.setSelectedStones(Collections.<Stone> emptyList());
|
||||||
if (redeal) {
|
if (redeal) {
|
||||||
redealEvent.emit();
|
redealEvent.emit();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -55,4 +55,6 @@ public interface IStoneTray<E extends Sizeable> extends
|
||||||
*/
|
*/
|
||||||
public int getSize();
|
public int getSize();
|
||||||
|
|
||||||
|
public boolean contains(E object);
|
||||||
|
|
||||||
}
|
}
|
|
@ -189,7 +189,16 @@ public class StoneTray<E extends Sizeable> implements IStoneTray<E> {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Position getPosition(E object) {
|
public Position getPosition(E object) {
|
||||||
return objects.get(object).getSecond();
|
Pair<E, Position> entry = objects.get(object);
|
||||||
|
if (entry == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return entry.getSecond();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean contains(E object) {
|
||||||
|
return objects.containsKey(objects);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -5,6 +5,7 @@ import java.io.File;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
import jrummikub.model.Stone;
|
import jrummikub.model.Stone;
|
||||||
|
import jrummikub.model.StoneSet;
|
||||||
import jrummikub.util.IEvent;
|
import jrummikub.util.IEvent;
|
||||||
import jrummikub.util.IEvent1;
|
import jrummikub.util.IEvent1;
|
||||||
|
|
||||||
|
@ -236,6 +237,28 @@ public interface IView {
|
||||||
*/
|
*/
|
||||||
public void showGameListPanel(boolean show);
|
public void showGameListPanel(boolean show);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is set if a player tried to lay out less than initial meld threshold
|
||||||
|
*
|
||||||
|
* @param points
|
||||||
|
* initial meld threshold
|
||||||
|
*/
|
||||||
|
public void setInitialMeldError(int points);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show stone collection
|
||||||
|
*
|
||||||
|
* @param enable
|
||||||
|
*/
|
||||||
|
public void setStoneCollectionHidden(boolean enable);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is set if the player tried to modify the table without laying out first
|
||||||
|
*/
|
||||||
|
public void setInitialMeldFirstError();
|
||||||
|
|
||||||
|
public void setInvalidStoneSets(Collection<StoneSet> sets);
|
||||||
/**
|
/**
|
||||||
* Different types of bottom panels
|
* Different types of bottom panels
|
||||||
*/
|
*/
|
||||||
|
@ -253,25 +276,4 @@ public interface IView {
|
||||||
/** */
|
/** */
|
||||||
WIN_PANEL
|
WIN_PANEL
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Is set if a player tried to lay out less than initial meld threshold
|
|
||||||
*
|
|
||||||
* @param points
|
|
||||||
* initial meld threshold
|
|
||||||
*/
|
|
||||||
void setInitialMeldError(int points);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Show stone collection
|
|
||||||
*
|
|
||||||
* @param enable
|
|
||||||
*/
|
|
||||||
void setStoneCollectionHidden(boolean enable);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Is set if the player tried to modify the table without laying out first
|
|
||||||
*/
|
|
||||||
void setInitialMeldFirstError();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ import jrummikub.model.Position;
|
||||||
import jrummikub.model.Stone;
|
import jrummikub.model.Stone;
|
||||||
import jrummikub.util.Pair;
|
import jrummikub.util.Pair;
|
||||||
import jrummikub.view.IHandPanel;
|
import jrummikub.view.IHandPanel;
|
||||||
|
import jrummikub.view.impl.StonePainter.StoneState;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of the board
|
* Implementation of the board
|
||||||
|
@ -118,7 +119,7 @@ class HandPanel extends AbstractStonePanel implements IHandPanel {
|
||||||
|
|
||||||
for (Pair<Stone, Position> entry : getStones()) {
|
for (Pair<Stone, Position> entry : getStones()) {
|
||||||
getStonePainter().paintStone(g, entry.getFirst(), entry.getSecond(),
|
getStonePainter().paintStone(g, entry.getFirst(), entry.getSecond(),
|
||||||
selectedStones.contains(entry.getFirst()),
|
selectedStones.contains(entry.getFirst()) ? StoneState.SELECTED : StoneState.NORMAL,
|
||||||
entry.getFirst() == getHoveredStone());
|
entry.getFirst() == getHoveredStone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ import jrummikub.util.Event1;
|
||||||
import jrummikub.util.IEvent1;
|
import jrummikub.util.IEvent1;
|
||||||
import jrummikub.util.Pair;
|
import jrummikub.util.Pair;
|
||||||
import jrummikub.view.IStoneCollectionPanel;
|
import jrummikub.view.IStoneCollectionPanel;
|
||||||
|
import jrummikub.view.impl.StonePainter.StoneState;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of the stone collection (selection)
|
* Implementation of the stone collection (selection)
|
||||||
|
@ -148,7 +149,7 @@ class StoneCollectionPanel extends AbstractStonePanel implements
|
||||||
float xpos = 0;
|
float xpos = 0;
|
||||||
|
|
||||||
for (Stone stone : selectedStones) {
|
for (Stone stone : selectedStones) {
|
||||||
getStonePainter().paintStone(g, stone, new Position(xpos, 0), false,
|
getStonePainter().paintStone(g, stone, new Position(xpos, 0), StoneState.NORMAL,
|
||||||
stone == getHoveredStone());
|
stone == getHoveredStone());
|
||||||
xpos++;
|
xpos++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,10 @@ import jrummikub.model.StoneColor;
|
||||||
* coordinates
|
* coordinates
|
||||||
*/
|
*/
|
||||||
class StonePainter {
|
class StonePainter {
|
||||||
|
enum StoneState {
|
||||||
|
NORMAL, SELECTED, INVALID
|
||||||
|
}
|
||||||
|
|
||||||
private static final double ASPECT_RATIO = 0.75f;
|
private static final double ASPECT_RATIO = 0.75f;
|
||||||
private static final double DEFAULT_WIDTH = 40;
|
private static final double DEFAULT_WIDTH = 40;
|
||||||
private static final double TEXT_POS = 0.275f;
|
private static final double TEXT_POS = 0.275f;
|
||||||
|
@ -34,11 +38,10 @@ class StonePainter {
|
||||||
|
|
||||||
private static final double BRIGHTER_SCALE = 1.15f;
|
private static final double BRIGHTER_SCALE = 1.15f;
|
||||||
private static final double HOVER_RATIO = 0.7f;
|
private static final double HOVER_RATIO = 0.7f;
|
||||||
|
private static final double REDDEN_RATIO = 0.3f;
|
||||||
|
|
||||||
private Map<StoneColor, Map<Integer, BufferedImage>> defaultStones;
|
private Map<StoneState, Map<StoneColor, Map<Integer, BufferedImage>>> defaultStones;
|
||||||
private Map<StoneColor, Map<Integer, BufferedImage>> selectedStones;
|
private Map<StoneState, Map<StoneColor, Map<Integer, BufferedImage>>> hoveredStones;
|
||||||
private Map<StoneColor, Map<Integer, BufferedImage>> hoveredStones;
|
|
||||||
private Map<StoneColor, Map<Integer, BufferedImage>> hoveredSelectedStones;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The width of one pixel in the scale of 1.0
|
* The width of one pixel in the scale of 1.0
|
||||||
|
@ -71,6 +74,14 @@ class StonePainter {
|
||||||
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 redden(Color color) {
|
||||||
|
int r = (int) (color.getRed() * REDDEN_RATIO + 255 * (1 - REDDEN_RATIO));
|
||||||
|
int g = (int) (color.getGreen() * REDDEN_RATIO + 128 * (1 - REDDEN_RATIO));
|
||||||
|
int b = (int) (color.getBlue() * REDDEN_RATIO + 128 * (1 - REDDEN_RATIO));
|
||||||
|
|
||||||
|
return new Color(r > 255 ? 255 : r, g > 255 ? 255 : g, b > 255 ? 255 : b);
|
||||||
|
}
|
||||||
|
|
||||||
public static Color getColor(StoneColor color) {
|
public static Color getColor(StoneColor color) {
|
||||||
switch (color) {
|
switch (color) {
|
||||||
case BLACK:
|
case BLACK:
|
||||||
|
@ -160,21 +171,13 @@ class StonePainter {
|
||||||
}
|
}
|
||||||
|
|
||||||
private BufferedImage getStoneImage(StoneColor color, int value,
|
private BufferedImage getStoneImage(StoneColor color, int value,
|
||||||
boolean selected, boolean hovered) {
|
StoneState state, boolean hovered) {
|
||||||
Map<StoneColor, Map<Integer, BufferedImage>> stoneMap;
|
Map<StoneColor, Map<Integer, BufferedImage>> stoneMap;
|
||||||
|
|
||||||
if (selected) {
|
if (hovered) {
|
||||||
if (hovered) {
|
stoneMap = hoveredStones.get(state);
|
||||||
stoneMap = hoveredSelectedStones;
|
|
||||||
} else {
|
|
||||||
stoneMap = selectedStones;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (hovered) {
|
stoneMap = defaultStones.get(state);
|
||||||
stoneMap = hoveredStones;
|
|
||||||
} else {
|
|
||||||
stoneMap = defaultStones;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BufferedImage image = stoneMap.get(color).get(value);
|
BufferedImage image = stoneMap.get(color).get(value);
|
||||||
|
@ -182,10 +185,15 @@ class StonePainter {
|
||||||
if (image == null) {
|
if (image == null) {
|
||||||
Color background = BACKGROUND_COLOR;
|
Color background = BACKGROUND_COLOR;
|
||||||
Color foreground = getColor(color);
|
Color foreground = getColor(color);
|
||||||
if (selected) {
|
|
||||||
|
if (state == StoneState.SELECTED) {
|
||||||
background = background.darker();
|
background = background.darker();
|
||||||
foreground = foreground.darker();
|
foreground = foreground.darker();
|
||||||
|
} else if (state == StoneState.INVALID) {
|
||||||
|
background = redden(background);
|
||||||
|
foreground = redden(foreground);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hovered) {
|
if (hovered) {
|
||||||
background = hover(background);
|
background = hover(background);
|
||||||
foreground = hover(foreground);
|
foreground = hover(foreground);
|
||||||
|
@ -200,16 +208,20 @@ class StonePainter {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void resetPrepaint() {
|
private void resetPrepaint() {
|
||||||
defaultStones = new HashMap<StoneColor, Map<Integer, BufferedImage>>();
|
defaultStones = new HashMap<StoneState, Map<StoneColor, Map<Integer, BufferedImage>>>();
|
||||||
selectedStones = new HashMap<StoneColor, Map<Integer, BufferedImage>>();
|
hoveredStones = new HashMap<StoneState, Map<StoneColor, Map<Integer, BufferedImage>>>();
|
||||||
hoveredStones = new HashMap<StoneColor, Map<Integer, BufferedImage>>();
|
|
||||||
hoveredSelectedStones = new HashMap<StoneColor, Map<Integer, BufferedImage>>();
|
|
||||||
|
|
||||||
for (StoneColor color : StoneColor.values()) {
|
for (StoneState state : StoneState.values()) {
|
||||||
defaultStones.put(color, new HashMap<Integer, BufferedImage>());
|
Map<StoneColor, Map<Integer, BufferedImage>> defaultStateStones = new HashMap<StoneColor, Map<Integer, BufferedImage>>();
|
||||||
selectedStones.put(color, new HashMap<Integer, BufferedImage>());
|
Map<StoneColor, Map<Integer, BufferedImage>> hoveredStateStones = new HashMap<StoneColor, Map<Integer, BufferedImage>>();
|
||||||
hoveredStones.put(color, new HashMap<Integer, BufferedImage>());
|
|
||||||
hoveredSelectedStones.put(color, new HashMap<Integer, BufferedImage>());
|
defaultStones.put(state, defaultStateStones);
|
||||||
|
hoveredStones.put(state, hoveredStateStones);
|
||||||
|
|
||||||
|
for (StoneColor color : StoneColor.values()) {
|
||||||
|
defaultStateStones.put(color, new HashMap<Integer, BufferedImage>());
|
||||||
|
hoveredStateStones.put(color, new HashMap<Integer, BufferedImage>());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -348,25 +360,26 @@ class StonePainter {
|
||||||
* the stone to paint
|
* the stone to paint
|
||||||
* @param p
|
* @param p
|
||||||
* the position of the stone
|
* the position of the stone
|
||||||
* @param selected
|
* @param state
|
||||||
* if selected is true the stone will be painted darker
|
* if the stone is selected the stone will be painted darker, if it
|
||||||
|
* is invalid it will be painted in red
|
||||||
* @param hovered
|
* @param hovered
|
||||||
* if hovered is true the stone will be painted brighter
|
* if hovered is true the stone will be painted brighter
|
||||||
*/
|
*/
|
||||||
public void paintStone(Graphics2D g, Stone stone, Position p,
|
public void paintStone(Graphics2D g, Stone stone, Position p,
|
||||||
boolean selected, boolean hovered) {
|
StoneState state, boolean hovered) {
|
||||||
int width = getStoneWidth();
|
int width = getStoneWidth();
|
||||||
int height = getStoneHeight();
|
int height = getStoneHeight();
|
||||||
int x = (int) Math.round(p.getX() * width), y = (int) Math.round(p.getY()
|
int x = (int) Math.round(p.getX() * width), y = (int) Math.round(p.getY()
|
||||||
* height);
|
* height);
|
||||||
|
|
||||||
if (stone.isJoker()) {
|
if (stone.isJoker()) {
|
||||||
g.drawImage(getStoneImage(stone.getColor(), 0, selected, hovered), x, y,
|
g.drawImage(getStoneImage(stone.getColor(), 0, state, hovered), x, y,
|
||||||
null);
|
null);
|
||||||
} else {
|
} else {
|
||||||
g.drawImage(
|
g.drawImage(
|
||||||
getStoneImage(stone.getColor(), stone.getValue(), selected, hovered),
|
getStoneImage(stone.getColor(), stone.getValue(), state, hovered), x,
|
||||||
x, y, null);
|
y, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ import jrummikub.util.IListener1;
|
||||||
import jrummikub.util.Pair;
|
import jrummikub.util.Pair;
|
||||||
import jrummikub.view.IStoneCollectionPanel;
|
import jrummikub.view.IStoneCollectionPanel;
|
||||||
import jrummikub.view.ITablePanel;
|
import jrummikub.view.ITablePanel;
|
||||||
|
import jrummikub.view.impl.StonePainter.StoneState;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The implementation of the table
|
* The implementation of the table
|
||||||
|
@ -54,6 +55,8 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
|
||||||
private Iterable<Pair<StoneSet, Position>> stoneSets = Collections.emptySet();
|
private Iterable<Pair<StoneSet, Position>> stoneSets = Collections.emptySet();
|
||||||
private List<Pair<StoneSet, Position>> pauseStoneSets;
|
private List<Pair<StoneSet, Position>> pauseStoneSets;
|
||||||
|
|
||||||
|
private Collection<StoneSet> invalidStoneSets = Collections.emptyList();
|
||||||
|
|
||||||
private Collection<Stone> selectedStones = Collections.emptyList();
|
private Collection<Stone> selectedStones = Collections.emptyList();
|
||||||
|
|
||||||
private Event1<StoneSet> leftConnectorClickEvent = new Event1<StoneSet>();
|
private Event1<StoneSet> leftConnectorClickEvent = new Event1<StoneSet>();
|
||||||
|
@ -112,6 +115,11 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setInvalidStoneSets(Collection<StoneSet> sets) {
|
||||||
|
invalidStoneSets = sets;
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
|
||||||
void createPauseStoneSets() {
|
void createPauseStoneSets() {
|
||||||
pauseStoneSets = new ArrayList<Pair<StoneSet, Position>>();
|
pauseStoneSets = new ArrayList<Pair<StoneSet, Position>>();
|
||||||
|
|
||||||
|
@ -312,8 +320,12 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
|
||||||
(int) (width * CONNECTOR_WIDTH), height)));
|
(int) (width * CONNECTOR_WIDTH), height)));
|
||||||
|
|
||||||
for (Stone stone : stoneSet) {
|
for (Stone stone : stoneSet) {
|
||||||
|
StoneState state = invalidStoneSets.contains(stoneSet) ? StoneState.INVALID
|
||||||
|
: selectedStones.contains(stone) ? StoneState.SELECTED
|
||||||
|
: StoneState.NORMAL;
|
||||||
|
|
||||||
getStonePainter().paintStone(g, stone, new Position(x, pos.getY()),
|
getStonePainter().paintStone(g, stone, new Position(x, pos.getY()),
|
||||||
selectedStones.contains(stone), stone == getHoveredStone());
|
state, stone == getHoveredStone());
|
||||||
x++;
|
x++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -364,6 +364,11 @@ public class View extends JFrame implements IView {
|
||||||
playerPanel.getHandPanel().setSelectedStones(stones);
|
playerPanel.getHandPanel().setSelectedStones(stones);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setInvalidStoneSets(Collection<StoneSet> sets) {
|
||||||
|
table.setInvalidStoneSets(sets);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void showSettingsPanel(boolean show) {
|
public void showSettingsPanel(boolean show) {
|
||||||
if (show) {
|
if (show) {
|
||||||
|
|
Reference in a new issue