}
public void mouseReleased(MouseEvent me) {
if ( me.isPopupTrigger() ) {
GameBoard b = Manager.getGame().getBoard();
if(b.getDetectives()!=null) {
int activeDet = Manager.getGame().getActiveDetectiveIndex();
// don't show the menu, if the user clicked anywhere else except the current detective
if(me.getY()<detYOffset-12+pixPerDetective*activeDet || me.getY()>detYOffset+2+pixPerDetective*activeDet) {
return;
}
detectiveMenu.removeAll();
JMenuItem menu1 = new JMenuItem( "Find me");
menu1.setEnabled(false);
detectiveMenu.add( menu1 );
detectiveMenu.addSeparator();
TreeSet<Move> possibleMoves = b.getDetectives()[activeDet].getPossibleMoves();
if(possibleMoves==null) {
AbstractAction action = new AbstractAction("Skip turn")
{
private static final long serialVersionUID = 0L;
public void actionPerformed( ActionEvent e ) {
Manager.getGame().nextDetective();
((MapPanel)PanelRepository.get(PanelRepository.MAP_PANEL)).updatePositions();
PanelRepository.get(PanelRepository.STATUS_PANEL).repaint();
}
};
detectiveMenu.add( action );
}
else {
log.debug("Possible moves: "+possibleMoves.size()+" - "+possibleMoves);
Iterator<Move> i = possibleMoves.iterator();
while(i.hasNext()) {
Move m = (Move) i.next();
StringBuilder linkText = new StringBuilder();
linkText.append(m.getNode()).append(" (");
switch(m.getType()) {
case BoardModel.TAXI: linkText.append("TAXI").append(")"); break;
case BoardModel.BUS: linkText.append("BUS").append(")"); break;
case BoardModel.UG: linkText.append("UG").append(")"); break;
case BoardModel.BLACK: linkText.append("XXX").append(")"); break;
case BoardModel.INF: linkText.append("INF").append(")"); break;
default: linkText.append("???").append(")"); break;
}
// detectiveMenu.add( new JMenuItem(linkText.toString()) );
AbstractAction action = new AbstractAction(linkText.toString())
{
private static final long serialVersionUID = -4379938472159497577L;
public void actionPerformed( ActionEvent e ) {
log.debug("Selected move: "+((Move)this.getValue(e.getActionCommand())));
Manager.getGame().moveDetective((Move)this.getValue(e.getActionCommand()));
// Move selectedMove = (Move)this.getValue(e.getActionCommand());
// Detective d = (Detective)this.getValue("Detective");
// d.changePosition(BoardModel.getInstance().getNode(selectedMove.getNode()), selectedMove.getType());
// Manager.getGame().nextDetective();
// ((MapPanel)PanelRepository.get(PanelRepository.MAP_PANEL)).updatePositions();
PanelRepository.get(PanelRepository.STATUS_PANEL).repaint();
}
};
action.putValue(linkText.toString(), m);
action.putValue("Detective", b.getDetectives()[activeDet]);
detectiveMenu.add( action );
}
detectiveMenu.addSeparator();
JMenuItem options = new JMenuItem( "Help");
options.setEnabled(false);