Skip to content

Commit

Permalink
Fix the second issue in #772 (right-click to undo in panel UI)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiraoka committed Oct 10, 2020
1 parent 6136470 commit 29507eb
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/main/java/featurecat/lizzie/gui/BoardPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void mousePressed(MouseEvent e) {
// if (Lizzie.frame.isMouseOver) {
// Lizzie.frame.addSuggestionAsBranch();
// } else {
if (!Lizzie.frame.openRightClickMenu(e.getX(), e.getY())) Input.undo();
Lizzie.frame.onRightClicked(e.getX(), e.getY());
// }
}
}
Expand All @@ -144,6 +144,10 @@ public void mouseDragged(MouseEvent e) {}
});
}

protected void checkRightClick(MouseEvent e) {
// cancel default behavior of LizziePane
}

/** Clears related status from empty board. */
public void clear() {
if (LizzieMain.winratePane != null) {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/featurecat/lizzie/gui/CommentPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public CommentPane(LizzieMain owner) {
@Override
public void mouseClicked(MouseEvent e) {
Lizzie.frame.getFocus();
Lizzie.frame.checkRightClick(e);
}
});
scrollPane = new JScrollPane();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/featurecat/lizzie/gui/Input.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void mousePressed(MouseEvent e) {
}
} else if (e.getButton() == MouseEvent.BUTTON3) // right click
{
if (!Lizzie.frame.openRightClickMenu(e.getX(), e.getY())) undo(1);
Lizzie.frame.onRightClicked(e.getX(), e.getY());
}
}

Expand Down
1 change: 1 addition & 0 deletions src/main/java/featurecat/lizzie/gui/LizzieMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ protected void paintComponent(Graphics g) {
@Override
public void mouseClicked(MouseEvent e) {
Lizzie.frame.getFocus();
Lizzie.frame.checkRightClick(e);
}
});

Expand Down
5 changes: 5 additions & 0 deletions src/main/java/featurecat/lizzie/gui/LizziePane.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,15 @@ public LizziePane(LizzieMain owner) {
@Override
public void mouseClicked(MouseEvent e) {
Lizzie.frame.getFocus();
checkRightClick(e); // actual behavior may be modified in subclasses
}
});
}

protected void checkRightClick(MouseEvent e) {
Lizzie.frame.checkRightClick(e);
}

@Override
public LizziePaneUI getUI() {
return (LizziePaneUI) ui;
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/featurecat/lizzie/gui/MainFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,20 @@ public boolean processCommentMouseWheelMoved(MouseWheelEvent e) {

public abstract void onDoubleClicked(int x, int y);

public void checkRightClick(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON3) {
onRightClickedOutsideBoard();
}
}

public void onRightClicked(int x, int y) {
if (!openRightClickMenu(x, y)) onRightClickedOutsideBoard();
}

private void onRightClickedOutsideBoard() {
Input.undo();
}

public abstract boolean subBoardOnClick(MouseEvent e);

public abstract void onMouseDragged(int x, int y);
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/featurecat/lizzie/gui/SubBoardPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ public void mouseWheelMoved(MouseWheelEvent e) {
});
}

protected void checkRightClick(MouseEvent e) {
// cancel default behavior of LizziePane
}

/**
* Draws the game board and interface
*
Expand Down

0 comments on commit 29507eb

Please sign in to comment.