Skip to content

Commit

Permalink
Merge pull request #399 from Cattlesquat/DeckBandSelectFix
Browse files Browse the repository at this point in the history
3.4.6 - 13505 - Deck band select fix
  • Loading branch information
uckelman committed Oct 11, 2020
2 parents 82c25db + 1000b4b commit 9b2f499
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
30 changes: 19 additions & 11 deletions vassal-app/src/main/java/VASSAL/build/module/map/KeyBufferer.java
Expand Up @@ -104,16 +104,22 @@ public void mousePressed(MouseEvent e) {

final KeyBuffer kbuf = KeyBuffer.getBuffer();

GamePiece p = map.findPiece(e.getPoint(), PieceFinder.PIECE_IN_STACK);
GamePiece p = map.findPiece(e.getPoint(), PieceFinder.DECK_OR_PIECE_IN_STACK);
// Don't clear the buffer until we find the clicked-on piece
// Because selecting a piece affects its visibility
EventFilter filter = null;
BandSelectType bandSelect = BandSelectType.NONE;
boolean isDeck = (p != null) && (p instanceof Deck);
if (p != null) {
filter = (EventFilter) p.getProperty(Properties.SELECT_EVENT_FILTER);
if (SwingUtils.isMainMouseButtonDown(e) && Boolean.TRUE.equals(p.getProperty(Properties.NON_MOVABLE))) {
// Don't "eat" band-selects if unit found is non-movable
bandSelect = BandSelectType.SPECIAL;
if (isDeck) {
p = null;
}
else {
filter = (EventFilter) p.getProperty(Properties.SELECT_EVENT_FILTER);
if (SwingUtils.isMainMouseButtonDown(e) && Boolean.TRUE.equals(p.getProperty(Properties.NON_MOVABLE))) {
// Don't "eat" band-selects if unit found is non-movable
bandSelect = BandSelectType.SPECIAL;
}
}
}

Expand Down Expand Up @@ -175,12 +181,14 @@ else if (!s.isExpanded()) {
bandSelectPiece = p;
}
}
anchor = map.mapToComponent(e.getPoint());
selection = new Rectangle(anchor.x, anchor.y, 0, 0);
if (map.getHighlighter() instanceof ColoredBorder) {
ColoredBorder b = (ColoredBorder) map.getHighlighter();
color = b.getColor();
thickness = b.getThickness();
if (!isDeck) { //BR// If started on a deck, don't do a band select
anchor = map.mapToComponent(e.getPoint());
selection = new Rectangle(anchor.x, anchor.y, 0, 0);
if (map.getHighlighter() instanceof ColoredBorder) {
ColoredBorder b = (ColoredBorder) map.getHighlighter();
color = b.getColor();
thickness = b.getThickness();
}
}
}
}
Expand Down
18 changes: 18 additions & 0 deletions vassal-app/src/main/java/VASSAL/counters/PieceFinder.java
Expand Up @@ -39,6 +39,13 @@ public interface PieceFinder {
* */
PieceFinder PIECE_IN_STACK = new PieceInStack();

/**
* If a Stack overlaps the given point, return the piece containing that point if expanded,
* or the top piece if not expanded.
* If a Deck is found instead, return the deck.
*/
PieceFinder DECK_OR_PIECE_IN_STACK = new DeckOrPieceInStack();

/** Returns a Stack if unexpanded and overlapping the given point,
* or a piece within that stack if expanded and overlapping the given point
*/
Expand All @@ -59,9 +66,20 @@ public Object visitStack(Stack s) {
}
return selected;
}
}


public class DeckOrPieceInStack extends PieceInStack {
@Override
public Object visitDeck(Deck d) {
Shape s = d.getShape();
Point pos = d.getPosition();
Point p = new Point(pt.x - pos.x, pt.y - pos.y);
return (s.contains(p) ? d : null);
}
}


public class PieceInStack extends Movable {
@Override
public Object visitStack(Stack s) {
Expand Down

0 comments on commit 9b2f499

Please sign in to comment.