Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.4.6 - 13505 - Deck band select fix #399

Merged
merged 3 commits into from Oct 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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