soc.client
Class SOCBoardPanel.BoardPopupMenu

java.lang.Object
  extended by java.awt.MenuComponent
      extended by java.awt.MenuItem
          extended by java.awt.Menu
              extended by java.awt.PopupMenu
                  extended by soc.client.SOCBoardPanel.BoardPopupMenu
All Implemented Interfaces:
java.awt.event.ActionListener, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible
Enclosing class:
SOCBoardPanel

private class SOCBoardPanel.BoardPopupMenu
extends java.awt.PopupMenu
implements java.awt.event.ActionListener

This class creates a popup menu on the board, to trade or build or cancel building.

actionPerformed(ActionEvent) usually calls SOCBuildingPanel.clickBuildingButton(SOCGame, String, boolean) to send messages to the server.


Nested Class Summary
 
Nested classes/interfaces inherited from class java.awt.PopupMenu
java.awt.PopupMenu.AccessibleAWTPopupMenu
 
Nested classes/interfaces inherited from class java.awt.Menu
java.awt.Menu.AccessibleAWTMenu
 
Nested classes/interfaces inherited from class java.awt.MenuItem
java.awt.MenuItem.AccessibleAWTMenuItem
 
Nested classes/interfaces inherited from class java.awt.MenuComponent
java.awt.MenuComponent.AccessibleAWTMenuComponent
 
Field Summary
(package private)  SOCBoardPanel bp
          our parent boardpanel
(package private)  java.awt.MenuItem buildRoadItem
           
(package private)  java.awt.MenuItem buildSettleItem
           
(package private)  java.awt.MenuItem buildShipItem
          Menu item to build or move a ship if SOCGame.hasSeaBoard, or null.
(package private)  java.awt.MenuItem cancelBuildItem
          Menu item to cancel a build as we're placing it, or to cancel moving a ship.
private  int cancelBuildType
          If allow cancel, type of building piece (SOCPlayingPiece.ROAD, SETTLEMENT, ...) to cancel
private  int hoverCityID
          hover city node ID, or 0, at menu-show time
private  int hoverRoadID
          hover road edge ID, or 0, at menu-show time
private  int hoverSettlementID
          hover settlement node ID, or 0, at menu-show time.
private  int hoverShipID
          hover ship edge ID, or 0, at menu-show time.
protected  boolean isInitialPlacement
          Will this be for initial placement (send putpiece right away), or for placement during game (send build, receive gamestate, send putpiece)?
private  boolean isShipMovable
          True if we can move a ship, at menu-show time.
private  boolean isShipWarship
          True if the ship is a warship, at menu-show time (scenario option _SC_PIRI).
private  boolean menuPlayerIsCurrent
          determined at menu-show time
(package private)  SOCHandPanel.ResourceTradePopupMenu portTradeSubmenu
          determined at menu-show time, only over a useable port.
(package private)  java.awt.MenuItem upgradeCityItem
           
private  boolean wantsCancel
          determined at menu-show time
 
Constructor Summary
SOCBoardPanel.BoardPopupMenu(SOCBoardPanel bpanel)
          create a new BoardPopupMenu on this board
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
          Handling the menu items
 void confirmAttackPirateFortress()
          Confirm with the user that they want to atack the pirate fortress and end their turn, in scenario _SC_PIRI.
 void showAtPirateFortress(int x, int y, SOCFortress ft)
          Custom show method for hovering at a pirate fortress (SOCFortress), giving the options to attack if it's our player's; for scenario option _SC_PIRI.
 void showBuild(int x, int y, int hR, int hSe, int hC, int hSh)
          Custom show method that finds current game status and player status.
 void showCancelBuild(int buildType, int x, int y, int hilightAt)
          Custom 'cancel' show method for when placing a road/settlement/city, giving the build/cancel options for that type of piece.
 void tryAttackPirateFortress()
          Send request to server to attack our player's pirate fortress, in scenario _SC_PIRI.
(package private)  void tryBuild(int ptype)
          Send message to server to request placing this piece, if allowable.
(package private)  void tryCancel()
          Cancel placing a building piece, or cancel moving a ship.
private  void tryMoveShipFromHere()
          Set up the board so the player can click where they want the ship moved.
 
Methods inherited from class java.awt.PopupMenu
addNotify, getAccessibleContext, getParent, show
 
Methods inherited from class java.awt.Menu
add, add, addSeparator, countItems, getItem, getItemCount, insert, insert, insertSeparator, isTearOff, paramString, remove, remove, removeAll, removeNotify
 
Methods inherited from class java.awt.MenuItem
addActionListener, deleteShortcut, disable, disableEvents, enable, enable, enableEvents, getActionCommand, getActionListeners, getLabel, getListeners, getShortcut, isEnabled, processActionEvent, processEvent, removeActionListener, setActionCommand, setEnabled, setLabel, setShortcut
 
Methods inherited from class java.awt.MenuComponent
dispatchEvent, getFont, getName, getPeer, getTreeLock, postEvent, setFont, setName, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.awt.MenuContainer
getFont, postEvent
 

Field Detail

bp

final SOCBoardPanel bp
our parent boardpanel


buildRoadItem

final java.awt.MenuItem buildRoadItem

buildSettleItem

final java.awt.MenuItem buildSettleItem

upgradeCityItem

final java.awt.MenuItem upgradeCityItem

buildShipItem

final java.awt.MenuItem buildShipItem
Menu item to build or move a ship if SOCGame.hasSeaBoard, or null.

Since:
2.0.00

cancelBuildItem

final java.awt.MenuItem cancelBuildItem
Menu item to cancel a build as we're placing it, or to cancel moving a ship. Piece type to cancel is cancelBuildType.


portTradeSubmenu

SOCHandPanel.ResourceTradePopupMenu portTradeSubmenu
determined at menu-show time, only over a useable port. Added then, and removed at next menu-show


menuPlayerIsCurrent

private boolean menuPlayerIsCurrent
determined at menu-show time


wantsCancel

private boolean wantsCancel
determined at menu-show time


cancelBuildType

private int cancelBuildType
If allow cancel, type of building piece (SOCPlayingPiece.ROAD, SETTLEMENT, ...) to cancel


hoverRoadID

private int hoverRoadID
hover road edge ID, or 0, at menu-show time


hoverSettlementID

private int hoverSettlementID
hover settlement node ID, or 0, at menu-show time. As a special case in the _SC_PIRI scenario, hoverSettlementID == -1 indicates any pirate Fortress; buildSettleItem's text will be "Attack Fortress" instead of "Build Settlement"; menu item will be disabled unless it's player's own fortress and SOCGame.canAttackPirateFortress().


hoverCityID

private int hoverCityID
hover city node ID, or 0, at menu-show time


hoverShipID

private int hoverShipID
hover ship edge ID, or 0, at menu-show time.

Since:
2.0.00

isShipMovable

private boolean isShipMovable
True if we can move a ship, at menu-show time. hoverShipID must be != 0.

Since:
2.0.00

isShipWarship

private boolean isShipWarship
True if the ship is a warship, at menu-show time (scenario option _SC_PIRI). hoverShipID must be != 0.

Since:
2.0.00

isInitialPlacement

protected boolean isInitialPlacement
Will this be for initial placement (send putpiece right away), or for placement during game (send build, receive gamestate, send putpiece)?

Constructor Detail

SOCBoardPanel.BoardPopupMenu

public SOCBoardPanel.BoardPopupMenu(SOCBoardPanel bpanel)
create a new BoardPopupMenu on this board

Method Detail

showCancelBuild

public void showCancelBuild(int buildType,
                            int x,
                            int y,
                            int hilightAt)
Custom 'cancel' show method for when placing a road/settlement/city, giving the build/cancel options for that type of piece.

Parameters:
buildType - piece type (SOCPlayingPiece.ROAD, CITY, SETTLEMENT)
x - Mouse x-position
y - Mouse y-position
hilightAt - Current hover/hilight coordinates of piece being cancelled/placed

showBuild

public void showBuild(int x,
                      int y,
                      int hR,
                      int hSe,
                      int hC,
                      int hSh)
Custom show method that finds current game status and player status. Also checks for hovering-over-port for port-trade submenu.

Parameters:
x - Mouse x-position
y - Mouse y-position
hR - Hover road ID, or 0
hSe - Hover settle ID, or 0
hC - Hover city ID, or 0
hSh - Hover ship ID, or 0; use negative if can move this currently placed ship. hSh < 0 is the only time this method trusts the caller's game state checks, instead of doing its own checking.

showAtPirateFortress

public void showAtPirateFortress(int x,
                                 int y,
                                 SOCFortress ft)
Custom show method for hovering at a pirate fortress (SOCFortress), giving the options to attack if it's our player's; for scenario option _SC_PIRI.

Parameters:
x - Mouse x-position
y - Mouse y-position
ft - Fortress being hovered at (our player's or otherwise), or null
Since:
2.0.00

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Handling the menu items

Specified by:
actionPerformed in interface java.awt.event.ActionListener

tryBuild

void tryBuild(int ptype)
Send message to server to request placing this piece, if allowable. If not initial placement or free placement, also sets up a reaction to send the 2nd message (putpiece) when server says it's OK to build, using value of hoverSettlementID, hoverShipID, etc when tryBuild is called.

Assumes player is current, and player is non-null, when called.

Parameters:
ptype - Piece type, like SOCPlayingPiece.ROAD

confirmAttackPirateFortress

public void confirmAttackPirateFortress()
Confirm with the user that they want to atack the pirate fortress and end their turn, in scenario _SC_PIRI. If confirmed, will call tryAttackPirateFortress().

Since:
2.0.00

tryAttackPirateFortress

public void tryAttackPirateFortress()
Send request to server to attack our player's pirate fortress, in scenario _SC_PIRI.

Since:
2.0.00

tryCancel

void tryCancel()
Cancel placing a building piece, or cancel moving a ship. Calls SOCBuildingPanel.clickBuildingButton(SOCGame, String, boolean).


tryMoveShipFromHere

private void tryMoveShipFromHere()
Set up the board so the player can click where they want the ship moved. Change mode to SOCBoardPanel.MOVE_SHIP and set SOCBoardPanel.moveShip_fromEdge. Assumes player is current, and the ship at hoverShipID is movable, when called. Repaints the board.

Since:
2.0.00
See Also:
SOCBoardPanel.tryMoveShipToEdge(), SOCBoardPanel.setModeMoveShip(int)