Class MasterBoard

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public final class MasterBoard extends JPanel
Class MasterBoard implements the GUI for a Titan masterboard.
Author:
David Ripton, Romain Dolbeau
See Also:
  • Field Details

    • LOGGER

      private static final Logger LOGGER
    • offScreenBuffer

      private Image offScreenBuffer
    • overlayChanged

      private boolean overlayChanged
    • guiHexArray

      private GUIMasterHex[][] guiHexArray
    • client

      private Client client
    • gui

      private final ClientGUI gui
    • masterFrame

      private KFrame masterFrame
    • showReadme

      private ShowReadme showReadme
    • showHelpDoc

      private ShowHelpDoc showHelpDoc
    • editMenu

      private JMenu editMenu
    • phaseMenu

      private JMenu phaseMenu
    • popupMenu

      private JPopupMenu popupMenu
    • popupMenuWithLegions

      private JPopupMenu popupMenuWithLegions
    • checkboxes

      private Map<String,JCheckBoxMenuItem> checkboxes
    • legionFlyouts

      private JPanel[] legionFlyouts
    • mbwh

    • iph

    • lastPoint

      private Point lastPoint
      Last point clicked is needed for popup menus.
    • engagingPendingHex

      private MasterHex engagingPendingHex
      engage() has been sent to server but answer (tellEngagement()) not received yet; mostly we have this, to be able to react properly when user clicks on an engagement while there is still the server response missing for the last one
    • defenderFleePhase

      private boolean defenderFleePhase
      In that time while we got tellEngagement but nothing else (bottom bar just tells engaged, but no other visible notice of what's going on), we might be waiting for the opponent to think about whether to flee or not. So if user is impatient and clicks a hex with any (same, or other) engagement, inform him we are already engaged right now and probably opponent is currently thinking about whether to flee or not. Once we receive showConcede or showNegotiate messages, this time window is over, after that we don't say this about the "perhaps opponent is currently thinking whether to flee" any more.
    • saveDuringEngagementDialogMessageShown

      private boolean saveDuringEngagementDialogMessageShown
      Show the message that "saving during engagement/battle will store the last commit point" only once each game - flag that it has been shown
    • legionToMarkerMap

      private final LinkedHashMap<Legion,Marker> legionToMarkerMap
      List of markers which are currently on the board, for painting in z-order => the end of the list is on top. Now synchronized access to prevent NPEs when EDT wants to paint a marker and asks for the legion for it, and legion has just been removed. I don't use a synchronizedList, because then I get into trouble in the recreateMarkers method.
    • recruitedChits

      private final Map<Legion,Chit> recruitedChits
    • possibleRecruitChits

      private final Map<MasterHex,List<Chit>> possibleRecruitChits
    • scrollPane

      private JScrollPane scrollPane
      The scrollbarspanel, needed to correct lastPoint.
    • contentPane

      private final Container contentPane
    • bottomBar

      private MasterBoard.BottomBar bottomBar
      our own little bar implementation
    • gameOverStateReached

      private boolean gameOverStateReached
    • saveGameAs

      private static final String saveGameAs
      See Also:
    • clearRecruitChits

      private static final String clearRecruitChits
      See Also:
    • skipLegion

      private static final String skipLegion
      See Also:
    • nextLegion

      private static final String nextLegion
      See Also:
    • undoLast

      private static final String undoLast
      See Also:
    • undoAll

      private static final String undoAll
      See Also:
    • doneWithPhase

      private static final String doneWithPhase
      See Also:
    • forcedDoneWithPhase

      private static final String forcedDoneWithPhase
      See Also:
    • kickPhase

      private static final String kickPhase
      See Also:
    • takeMulligan

      private static final String takeMulligan
      See Also:
    • withdrawFromGame

      private static final String withdrawFromGame
      See Also:
    • viewWebClient

      private static final String viewWebClient
      See Also:
    • viewFullRecruitTree

      private static final String viewFullRecruitTree
      See Also:
    • viewHexRecruitTree

      private static final String viewHexRecruitTree
      See Also:
    • viewBattleMap

      private static final String viewBattleMap
      See Also:
    • viewLegions

      private static final String viewLegions
      See Also:
    • chooseScreen

      private static final String chooseScreen
      See Also:
    • preferences

      private static final String preferences
      See Also:
    • about

      private static final String about
      See Also:
    • viewReadme

      private static final String viewReadme
      See Also:
    • viewHelpDoc

      private static final String viewHelpDoc
      See Also:
    • viewWelcome

      private static final String viewWelcome
      See Also:
    • newGameAction

      private AbstractAction newGameAction
    • loadGameAction

      private AbstractAction loadGameAction
    • saveGameAction

      private AbstractAction saveGameAction
    • saveGameAsAction

      private AbstractAction saveGameAsAction
    • closeBoardAction

      private AbstractAction closeBoardAction
    • quitGameAction

      private AbstractAction quitGameAction
    • cleanDisconnectAction

      private AbstractAction cleanDisconnectAction
    • enforcedDisconnectByServerAction

      private AbstractAction enforcedDisconnectByServerAction
    • tryReconnectAction

      private AbstractAction tryReconnectAction
    • checkConnectionAction

      private AbstractAction checkConnectionAction
    • clearRecruitChitsAction

      private AbstractAction clearRecruitChitsAction
    • skipLegionAction

      private AbstractAction skipLegionAction
    • nextLegionAction

      private AbstractAction nextLegionAction
    • undoLastAction

      private AbstractAction undoLastAction
    • undoAllAction

      private AbstractAction undoAllAction
    • doneWithPhaseAction

      private AbstractAction doneWithPhaseAction
    • forcedDoneWithPhaseAction

      private AbstractAction forcedDoneWithPhaseAction
    • kickPhaseAction

      private AbstractAction kickPhaseAction
    • takeMulliganAction

      private AbstractAction takeMulliganAction
    • withdrawFromGameAction

      private AbstractAction withdrawFromGameAction
    • viewWebClientAction

      private AbstractAction viewWebClientAction
    • viewFullRecruitTreeAction

      private AbstractAction viewFullRecruitTreeAction
    • viewHexRecruitTreeAction

      private AbstractAction viewHexRecruitTreeAction
    • viewBattleMapAction

      private AbstractAction viewBattleMapAction
    • viewLegionsAction

      private AbstractAction viewLegionsAction
    • chooseScreenAction

      private AbstractAction chooseScreenAction
    • preferencesAction

      private AbstractAction preferencesAction
    • aboutAction

      private AbstractAction aboutAction
    • viewReadmeAction

      private AbstractAction viewReadmeAction
    • viewHelpDocAction

      private AbstractAction viewHelpDocAction
    • viewWelcomeAction

      private AbstractAction viewWelcomeAction
    • playerLabelDone

      private boolean playerLabelDone
    • saveWindow

      private SaveWindow saveWindow
    • cachedPlayerName

      private String cachedPlayerName
    • editLegionOngoing

      EditLegion editLegionOngoing
    • relocateOngoing

      EditLegion relocateOngoing
    • itemHandler

      private ItemListener itemHandler
  • Constructor Details

  • Method Details

    • setBoardActive

      public void setBoardActive(boolean val)
    • enableSaveActions

      public void enableSaveActions()
    • saveDuringEngagementDialog

      private boolean saveDuringEngagementDialog()
      Inform the user that saving during an engagement will save the last commit point, so loading it will re-set game to just before the engagement was started. Only if user closes the dialog, no save will be done.
      Returns:
      True if saving shall be done anyway
    • confirmDialog

      private Constants.ConfirmVals confirmDialog(String text, int count)
    • setupActions

      private void setupActions()
    • getLogDirectory

      private String getLogDirectory()
    • doQuitGameAction

      public void doQuitGameAction()
    • showBattleMap

      public void showBattleMap(GUIMasterHex hex)
    • setupPopupMenus

      private void setupPopupMenus()
    • viewLegions

      public void viewLegions(Point point)
    • addCheckBox

      private JCheckBoxMenuItem addCheckBox(JMenu menu, String name, int mnemonic)
    • cleanCBListeners

      private void cleanCBListeners()
    • setupTopMenu

      private void setupTopMenu()
    • adjustCheckboxIfNeeded

      void adjustCheckboxIfNeeded(String name, boolean enable)
      Find the checkbox for the given (boolean) option name; set it to the new given value (only if different that previous value).
      Parameters:
      name - The option name to adjust the checkbox for
      enable - The should-be state of the checkbox
    • setupPlayerLabel

      void setupPlayerLabel()
      Show which player owns this board.
    • setupGUIHexes

      private void setupGUIHexes()
    • getMasterBoard

      private MasterBoard getMasterBoard()
      TODO this should probably be stored as member, possibly instead of the client class.
    • cleanGUIHexes

      private void cleanGUIHexes()
    • doneWithPhase

      private void doneWithPhase()
      Finishes the current phase. Depending on the current phase this method dispatches to the different done methods.
      See Also:
    • setupPhasePreparations

      private void setupPhasePreparations(String titleText)
    • setupAsInactivePlayer

      private void setupAsInactivePlayer(String text)
      Do the setup needed for an inactive player: set the actions which are allowed only for active player to inactive, and update the bottomBar info why "Done" is disabled accordingly
      Parameters:
      text - What the active player is doing right now
    • setupSplitMenu

      void setupSplitMenu()
    • setupMoveMenu

      void setupMoveMenu()
    • setMovementPhase

      public void setMovementPhase()
    • setupTitleForMovementRoll

      void setupTitleForMovementRoll(int roll)
    • setupFightMenu

      void setupFightMenu()
    • updateEngagementsLeftText

      public void updateEngagementsLeftText()
    • setupMusterMenu

      void setupMusterMenu()
    • highlightPossibleRecruitLegionHexes

      void highlightPossibleRecruitLegionHexes()
      Highlight all hexes with legions that (still) can do recruiting
    • getFrame

      KFrame getFrame()
    • alignAllLegions

      void alignAllLegions()
      This is incredibly inefficient.
    • alignLegions

      void alignLegions(MasterHex masterHex)
    • alignLegions

      private void alignLegions(Set<MasterHex> hexes)
    • highlightTallLegions

      void highlightTallLegions()
    • highlightUnmovedLegions

      void highlightUnmovedLegions()
    • setPendingText

      void setPendingText(String text)
    • highlightMoves

      private void highlightMoves(LegionClientSide legion)
      Select hexes where this legion can move.
    • highlightEngagements

      void highlightEngagements()
    • setupIcon

      private void setupIcon()
    • getGUIHexByMasterHex

      GUIMasterHex getGUIHexByMasterHex(MasterHex masterHex)
      Do a brute-force search through the hex array, looking for a match. Return the hex, or null if none is found.
    • getHexContainingPoint

      private GUIMasterHex getHexContainingPoint(Point point)
      Return the MasterHex that contains the given point, or null if none does.
    • setMarkerForLegion

      void setMarkerForLegion(Legion legion, Marker marker)
    • removeMarkerForLegion

      void removeMarkerForLegion(Legion legion)
    • recreateMarkers

      public void recreateMarkers()
      Create new markers in response to a rescale.
    • getMarkerAtPoint

      private Marker getMarkerAtPoint(Point point)
      Return the topmost Marker that contains the given point, or null if none does.
    • unselectAllHexes

      void unselectAllHexes()
    • selectHex

      void selectHex(MasterHex modelHex)
    • selectHexes

      private void selectHexes(Set<MasterHex> hexes)
    • selectHexes

      private void selectHexes(Set<MasterHex> hexes, Color color)
    • focusBackToMasterboard

      public void focusBackToMasterboard()
    • actOnMisclick

      void actOnMisclick()
    • isPopupButton

      private static boolean isPopupButton(MouseEvent e)
      Return true if the MouseEvent e came from button 2 or 3. In theory, isPopupTrigger() is the right way to check for this. In practice, the poor design choice of only having isPopupTrigger() fire on mouse release on Windows makes it useless here.
    • actOnLegion

      private void actOnLegion(LegionClientSide legion, MasterHex hex)
    • actOnHex

      private void actOnHex(MasterHex hex)
    • actOnEditLegionMaybe

      public void actOnEditLegionMaybe(Legion legion)
    • setEditOngoing

      public void setEditOngoing(EditLegion editLegion)
    • setRelocateOngoing

      public void setRelocateOngoing(EditLegion editLegion)
    • viewEditLegion

      public void viewEditLegion(LegionClientSide legion)
      Parameters:
      legion - the legion which shall be edited
    • clearEngagingPending

      public void clearEngagingPending()
      tellEngagement calls this, now "engaging" is not pending, instead there is a real engagement to be resolved.
    • clearDefenderFlee

      public void clearDefenderFlee()
      We got showConcede or showNegotiate messages, i.e. the phase in which defender might flee is over, thus the message dialog should not tell that any more. This client here should now have some dialog or even the actual battle map anyway.
    • attemptEngage

      private void attemptEngage(MasterHex hex)
    • repaintAfterOverlayChanged

      void repaintAfterOverlayChanged()
    • paintComponent

      public void paintComponent(Graphics g)
      Overrides:
      paintComponent in class JComponent
    • paintHexes

      private void paintHexes(Graphics g)
    • paintHighlights

      private void paintHighlights(Graphics2D g)
    • paintMarkers

      private void paintMarkers(Graphics g)
      Paint markers in z-order.
    • paintRecruitedChits

      private void paintRecruitedChits(Graphics g)
    • addPossibleRecruitChits

      public void addPossibleRecruitChits(LegionClientSide legion, Set<MasterHex> hexes)
    • addRecruitedChit

      void addRecruitedChit(Legion legion)
    • cleanRecruitedChit

      void cleanRecruitedChit(LegionClientSide legion)
    • addPossibleRecruitChits

      private void addPossibleRecruitChits(List<CreatureType> imageNameList, MasterHex masterHex)
    • clearRecruitedChits

      public void clearRecruitedChits()
    • clearPossibleRecruitChits

      public void clearPossibleRecruitChits()
    • paintPossibleRecruitChits

      private void paintPossibleRecruitChits(Graphics g)
    • paintMovementDie

      private void paintMovementDie(Graphics g)
    • markLegionSkip

      public void markLegionSkip()
    • jumpToNextUnhandledLegion

      private void jumpToNextUnhandledLegion()
      user pressed "N". Find the next legion that "deserves" handling, activate (as if user had clicked it), and position the mouse cursor over it.
    • activateNextLegionAndPlaceMouse

      private void activateNextLegionAndPlaceMouse(Legion nextLegion)
      Parameters:
      nextLegion -
    • getMinimumSize

      public Dimension getMinimumSize()
      Overrides:
      getMinimumSize in class JComponent
    • getPreferredSize

      public Dimension getPreferredSize()
      Overrides:
      getPreferredSize in class JComponent
    • rescale

      void rescale()
    • deiconify

      void deiconify()
    • dispose

      public void dispose()
    • pack

      void pack()
    • updateComponentTreeUI

      void updateComponentTreeUI()
    • fullRepaint

      void fullRepaint()
    • maybeRequestFocusAndToFront

      void maybeRequestFocusAndToFront()
      If and only if stealFocus option is enabled, this does both requestFocus and getFrame().toFront().
    • myTurnStartsActions

      void myTurnStartsActions()
    • updateLegionsLeftToMusterText

      public void updateLegionsLeftToMusterText()
    • updateLegionsLeftToMoveText

      public void updateLegionsLeftToMoveText(boolean have_roll)
    • enableDoneAction

      public void enableDoneAction()
    • disableDoneAction

      public void disableDoneAction(String reason)
      Disable the Done action, and update the reason text in bottomBar
      Parameters:
      reason - Information why one is not ready to be Done
    • disableDoneActionActivePlayerDoes

      private void disableDoneActionActivePlayerDoes(String doesWhat)
      Clear bottomBar phase text and call disableDoneAction, as reason the standard text "<active player> doesWhat"
      Parameters:
      doesWhat - Information what the active player currently does
    • makeDoneCloseWindow

      private void makeDoneCloseWindow()
    • setServerClosedMessage

      public void setServerClosedMessage(boolean gameOver)
    • setReconnectedMessage

      public void setReconnectedMessage()
    • setReplayMode

      public void setReplayMode()
    • updateReplayText

      public void updateReplayText(int currTurn, int maxTurn)
    • setTitleInfoText

      private void setTitleInfoText(String text)
    • setTempDisconnectedState

      public void setTempDisconnectedState(String message)
    • setGameOverState

      public void setGameOverState(String message)
    • setPhaseInfo

      public void setPhaseInfo(String message)