Skip to content

Commit

Permalink
added back link functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin-771 committed Nov 21, 2023
1 parent 9eb5075 commit 2790c45
Showing 1 changed file with 76 additions and 76 deletions.
152 changes: 76 additions & 76 deletions src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentController.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,83 +29,83 @@ public TreeTentController() {
this.lastCellPressed = null;
}

// @Override
// public void mousePressed(MouseEvent e) {
// if (e.getButton() != MouseEvent.BUTTON2) {
// BoardView boardView = getInstance().getLegupUI().getBoardView();
// dragStart = boardView.getElement(e.getPoint());
// lastCellPressed = boardView.getElement(e.getPoint());
// }
// }
@Override
public void mousePressed(MouseEvent e) {
if (e.getButton() != MouseEvent.BUTTON2) {
BoardView boardView = getInstance().getLegupUI().getBoardView();
dragStart = boardView.getElement(e.getPoint());
lastCellPressed = boardView.getElement(e.getPoint());
}
}

@Override
public void mouseReleased(MouseEvent e) {
if (GameBoardFacade.getInstance().getLegupUI().getTreePanel() != null && e.getButton() != MouseEvent.BUTTON2) {
TreePanel treePanel = GameBoardFacade.getInstance().getLegupUI().getTreePanel();
TreeView treeView = GameBoardFacade.getInstance().getLegupUI().getTreePanel().getTreeView();
BoardView boardView = getInstance().getLegupUI().getBoardView();
lastCellPressed = boardView.getElement(e.getPoint());
Board board = boardView.getBoard();
TreeViewSelection selection = treeView.getSelection();

// @Override
// public void mouseReleased(MouseEvent e) {
// if (GameBoardFacade.getInstance().getLegupUI().getTreePanel() != null && e.getButton() != MouseEvent.BUTTON2) {
// TreePanel treePanel = GameBoardFacade.getInstance().getLegupUI().getTreePanel();
// TreeView treeView = GameBoardFacade.getInstance().getLegupUI().getTreePanel().getTreeView();
// BoardView boardView = getInstance().getLegupUI().getBoardView();
// lastCellPressed = boardView.getElement(e.getPoint());
// Board board = boardView.getBoard();
// TreeViewSelection selection = treeView.getSelection();
//
// if (dragStart != null) {
// if (board instanceof CaseBoard) {
// CaseBoard caseBoard = (CaseBoard) board;
// AutoCaseRuleCommand autoCaseRuleCommand = new AutoCaseRuleCommand(dragStart, selection, caseBoard.getCaseRule(), caseBoard, e);
// if (autoCaseRuleCommand.canExecute()) {
// autoCaseRuleCommand.execute();
// getInstance().getHistory().pushChange(autoCaseRuleCommand);
// treePanel.updateError("");
// }
// else {
// treePanel.updateError(autoCaseRuleCommand.getError());
// }
// }
// else {
// if (dragStart == lastCellPressed) {
// if (dragStart.getPuzzleElement().getIndex() >= 0) {
// ICommand edit = new EditDataCommand(lastCellPressed, selection, e);
// if (edit.canExecute()) {
// edit.execute();
// getInstance().getHistory().pushChange(edit);
// treePanel.updateError("");
// }
// else {
// treePanel.updateError(edit.getError());
// }
// }
// else {
// ClueCommand edit = new ClueCommand(selection, (TreeTentClueView) dragStart);
// if (edit.canExecute()) {
// edit.execute();
// getInstance().getHistory().pushChange(edit);
// treePanel.updateError("");
// }
// else {
// treePanel.updateError(edit.getError());
// }
// }
// }
// else {
// if (lastCellPressed != null) {
// if (dragStart instanceof TreeTentElementView) {
// ICommand editLine = new EditLineCommand(selection, (TreeTentElementView) dragStart, lastCellPressed);
// if (editLine.canExecute()) {
// editLine.execute();
// getInstance().getHistory().pushChange(editLine);
// }
// else {
// treePanel.updateError(editLine.getError());
// }
// }
// }
// }
// }
// }
// dragStart = null;
// lastCellPressed = null;
// }
// }
if (dragStart != null) {
if (board instanceof CaseBoard) {
CaseBoard caseBoard = (CaseBoard) board;
AutoCaseRuleCommand autoCaseRuleCommand = new AutoCaseRuleCommand(dragStart, selection, caseBoard.getCaseRule(), caseBoard, e);
if (autoCaseRuleCommand.canExecute()) {
autoCaseRuleCommand.execute();
getInstance().getHistory().pushChange(autoCaseRuleCommand);
treePanel.updateError("");
}
else {
treePanel.updateError(autoCaseRuleCommand.getError());
}
}
else {
if (dragStart == lastCellPressed) {
if (dragStart.getPuzzleElement().getIndex() >= 0) {
ICommand edit = new EditDataCommand(lastCellPressed, selection, e);
if (edit.canExecute()) {
edit.execute();
getInstance().getHistory().pushChange(edit);
treePanel.updateError("");
}
else {
treePanel.updateError(edit.getError());
}
}
else {
ClueCommand edit = new ClueCommand(selection, (TreeTentClueView) dragStart);
if (edit.canExecute()) {
edit.execute();
getInstance().getHistory().pushChange(edit);
treePanel.updateError("");
}
else {
treePanel.updateError(edit.getError());
}
}
}
else {
if (lastCellPressed != null) {
if (dragStart instanceof TreeTentElementView) {
ICommand editLine = new EditLineCommand(selection, (TreeTentElementView) dragStart, lastCellPressed);
if (editLine.canExecute()) {
editLine.execute();
getInstance().getHistory().pushChange(editLine);
}
else {
treePanel.updateError(editLine.getError());
}
}
}
}
}
}
dragStart = null;
lastCellPressed = null;
}
}

@Override
public void changeCell(MouseEvent e, PuzzleElement element) {
Expand Down

0 comments on commit 2790c45

Please sign in to comment.