Class ClientGUI

All Implemented Interfaces:
ActionListener, EventListener, BoardViewListener, MekDisplayListener, IClientGUI, IDisconnectSilently, IHasBoardView, IHasCurrentPanel, IHasMenuBar, ILocalBots, IHasUnitDisplay, IClientCommandHandler, IPreferenceChangeListener

  • Field Details

  • Constructor Details

    • ClientGUI

      public ClientGUI(Client client, MegaMekController c)
      Construct a client which will display itself in a new frame. It will not try to connect to a server yet. When the frame closes, this client will clean up after itself as much as possible, but will not call System.exit().
  • Method Details

    • getBoardView

      public BoardView getBoardView()
      Specified by:
      getBoardView in interface IHasBoardView
    • getToastOverlay

      @Deprecated(since="0.51.0", forRemoval=true) public BoardToastOverlay getToastOverlay()
      Deprecated, for removal: This API element is subject to removal in a future version.
    • addToast

      public void addToast(ToastLevel level, String text)
      Shows a toast notification on the board view. Safe to call even when the toast overlay has not been initialized yet (e.g., during the lobby phase).
      Parameters:
      level - the severity level determining color and default duration
      text - the message text to display
    • addToast

      public void addToast(ToastLevel level, String text, @Nullable Entity entity)
      Shows a toast notification with the given entity's sprite icon on the board view.

      This is the single entry point for every toast in the client, server-raised ones included, so the player's GUIPreferences.TOAST_ENABLED setting is enforced here and nowhere else.

      Parameters:
      level - the severity level determining color and default duration
      text - the message text to display
      entity - the entity whose icon to show, or null for text-only
    • getUnitDisplay

      public UnitDisplayPanel getUnitDisplay()
      Specified by:
      getUnitDisplay in interface IHasUnitDisplay
    • getUnitDisplayDialog

      public UnitDisplayDialog getUnitDisplayDialog()
    • setUnitDisplayDialog

      public void setUnitDisplayDialog(UnitDisplayDialog unitDisplayDialog)
    • getForceDisplayPanel

      public ForceDisplayPanel getForceDisplayPanel()
    • setForceDisplayPanel

      public void setForceDisplayPanel(ForceDisplayPanel forceDisplayPanel)
    • getForceDisplayDialog

      public ForceDisplayDialog getForceDisplayDialog()
    • setForceDisplayDialog

      public void setForceDisplayDialog(ForceDisplayDialog forceDisplayDialog)
    • getMiniMapDialog

      public MinimapDialog getMiniMapDialog()
    • getBotCommandsDialog

      public BotCommandsDialog getBotCommandsDialog()
    • setBotCommandsDialog

      public void setBotCommandsDialog(BotCommandsDialog botCommandsDialog)
    • getBotCommandsPanel

      public BotCommandsPanel getBotCommandsPanel()
    • getMiniReportDisplay

      public MiniReportDisplayPanel getMiniReportDisplay()
    • setMiniReportDisplay

      public void setMiniReportDisplay(MiniReportDisplayPanel miniReportDisplayPanel)
    • getMiniReportDisplayDialog

      public MiniReportDisplayDialog getMiniReportDisplayDialog()
    • setMiniReportDisplayDialog

      public void setMiniReportDisplayDialog(MiniReportDisplayDialog miniReportDisplayDialog)
    • getPlayerListDialog

      public PlayerListDialog getPlayerListDialog()
    • setPlayerListDialog

      public void setPlayerListDialog(PlayerListDialog playerListDialog)
    • getRoundsInAirDialog

      public RoundsInAirDialog getRoundsInAirDialog()
    • setRoundsInAirDialog

      public void setRoundsInAirDialog(RoundsInAirDialog roundsInAirDialog)
    • setDisconnectQuietly

      public void setDisconnectQuietly(boolean quietly)
      Description copied from interface: IDisconnectSilently
      Set to true to make the client disconnect without a warning popup.
      Specified by:
      setDisconnectQuietly in interface IDisconnectSilently
      Parameters:
      quietly - When true, the client will disconnect without visible warning
    • systemMessage

      public void systemMessage(String message)
      Display a system message in the chat box.
      Parameters:
      message - the String message to be shown.
    • initializeFrame

      protected void initializeFrame()
      Initializes a number of things about this frame.
      Overrides:
      initializeFrame in class AbstractClientGUI
    • initialize

      public void initialize()
      Description copied from interface: IClientGUI
      Registers this ClientGUI as a listener wherever it's needed. It is generally considered bad practice to do this in the constructor.
      Specified by:
      initialize in interface IClientGUI
      Overrides:
      initialize in class AbstractClientGUI
    • getMenuBar

      public CommonMenuBar getMenuBar()
      Description copied from interface: IHasMenuBar
      Get the menu bar for this client.
      Specified by:
      getMenuBar in interface IHasMenuBar
      Returns:
      the CommonMenuBar of this client.
    • customizePlayer

      public void customizePlayer()
    • showPlayerList

      public void showPlayerList()
      Called when the user selects the "View->Player List" menu item.
    • miniReportDisplayAddReportPages

      public void miniReportDisplayAddReportPages()
    • reportDisplayResetDone

      public void reportDisplayResetDone()
    • reportDisplayResetRerollInitiative

      public void reportDisplayResetRerollInitiative()
    • resetWindowPositions

      public void resetWindowPositions()
    • actionPerformed

      public void actionPerformed(ActionEvent event)
      Implement the ActionListener interface.
      Specified by:
      actionPerformed in interface ActionListener
    • doSaveUnit

      public void doSaveUnit()
      Save all the current in use Entities each grouped by player name

      and a file for salvage

    • die

      public void die()
      Description copied from interface: IClientGUI
      Performs shut down for threads and sockets and other things that can be disposed.
      Specified by:
      die in interface IClientGUI
      Overrides:
      die in class AbstractClientGUI
    • getGameOptionsDialog

      public GameOptionsDialog getGameOptionsDialog()
    • getNetworkInformationDialog

      public NetworkInformationDialog getNetworkInformationDialog()
    • getMekSelectorDialog

      public MegaMekUnitSelectorDialog getMekSelectorDialog()
    • switchPanel

      public void switchPanel(GamePhase phase)
    • updateButtonPanel

      public void updateButtonPanel(GamePhase phase)
    • showBoardPopup

      protected void showBoardPopup(BoardViewEvent event)
    • toggleMMUDDisplays

      public void toggleMMUDDisplays()
      Switches the Minimap and the UnitDisplay an and off together. If the UnitDisplay is active, both will be hidden, else both will be shown.
    • maybeShowUnitDisplay

      public void maybeShowUnitDisplay()
      Shows or hides the Unit Display based on the current menu setting.
    • maybeShowForceDisplay

      public void maybeShowForceDisplay()
      Shows or hides the Unit Display based on the current menu setting.
    • setUnitDisplayVisible

      public void setUnitDisplayVisible(boolean visible)
      Shows or hides the Unit Display based on the given visible. This works independently of the current menu setting, so it should be used only when the Unit Display is to be shown or hidden without regard for the user setting, e.g. hiding it in the lobby or a report phase. Does not change the menu setting.
    • setForceDisplayVisible

      public void setForceDisplayVisible(boolean visible)
    • setUnitDisplayLocation

      public void setUnitDisplayLocation(boolean visible)
    • setMiniReportLocation

      public void setMiniReportLocation(boolean visible)
    • doChoiceDialog

      @Nullable public int[] doChoiceDialog(String title, String question, String... choices)
      Pops up a dialog box giving the player a series of choices that are not mutually exclusive.
      Parameters:
      title - the String title of the dialog box.
      question - the String question that has a "Yes" or "No" answer. The question will be split across multiple line on the '\n' characters.
      choices - the array of String choices that the player can select from.
      Returns:
      The array of the int indexes from the input array that match the selected choices. If no choices were available, if the player did not select a choice, or if the player canceled the choice, a null value is returned.
    • doAlertDialog

      public void doAlertDialog(String title, String message)
      Pops up a dialog box showing an alert
    • doAlertDialog

      public void doAlertDialog(String title, String message, int messageType)
      Brings up a dialog that displays a message using a default icon determined by the messageType parameter.
      Parameters:
      title - the title string for the dialog
      message - the Object to display
      messageType - the type of message to be displayed: ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE, QUESTION_MESSAGE, or PLAIN_MESSAGE
      Throws:
      HeadlessException - if GraphicsEnvironment.isHeadless returns true
      See Also:
    • doInformBotherDialog

      public InformDialog doInformBotherDialog(String title, String message, boolean includeCheckBox)
      Pops up a dialog box giving the player information on a subject. It also includes a checkbox if they don't want to be bothered again by it.
      Parameters:
      title - the String title of the dialog box.
      message - the String message to display.
      includeCheckBox - if true, a checkbox will be included in the dialog box
      Returns:
      InformDialog containing the player's responses. The dialog will already have been shown
    • doYesNoDialog

      public boolean doYesNoDialog(String title, String question)
      Pops up a dialog box asking a yes/no question
      Parameters:
      title - the String title of the dialog box.
      question - the String question that has a "Yes" or "No" answer. The question will be split across multiple line on the '\n' characters.
      Returns:
      true if yes
    • doYesNoBotherDialog

      public ConfirmDialog doYesNoBotherDialog(String title, String question)
      Pops up a dialog box asking a yes/no question

      The player will be given a chance to not show the dialog again.

      Parameters:
      title - the String title of the dialog box.
      question - the String question that has a "Yes" or "No" answer. The question will be split across multiple lines on the '\n' characters.
      Returns:
      the ConfirmDialog containing the player's responses. The dialog will already have been shown to the player, and is only being returned so the calling function can see the answer to the question and the state of the "Show again?" question.
    • doWarnNoBotherDialog

      @Deprecated(since="0.51.0", forRemoval=true) public ConfirmDialog doWarnNoBotherDialog(String title, String question)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Pops up a dialog box asking a yes/no question

      The player will be given a chance to not show the dialog again.

      Parameters:
      title - the String title of the dialog box.
      question - the String question that has a "Yes" or "No" answer. The question will be split across multiple line on the '\n' characters.c tr23ty
      Returns:
      the ConfirmDialog containing the player's responses. The dialog will already have been shown to the player, and is only being returned so the calling function can see the answer to the question and the state of the "Show again?" question.
    • loadListFile

      protected void loadListFile()
      Allow the player to select a MegaMek Unit List file to load. The Entitys in the file will replace any that the player has already selected. As such, this method should only be called in the chat lounge. The file can record damage sustained, non-standard munitions selected, and ammunition expended in a prior engagement.
    • loadListFile

      public void loadListFile(Player player)
      Allow the player to select a MegaMek Unit List file to load. The Entitys in the file will replace any that the player has already selected. As such, this method should only be called in the chat lounge. The file can record damage sustained, non-standard munitions selected, and ammunition expended in a prior engagement.
      Parameters:
      player - The player to add the units to
    • reinforceFromFile

      public void reinforceFromFile(Player player)
      Loads a unit file onto a player as reinforcements, arriving next round.

      Public so that a gamemaster tool which already knows which player it is setting up can send units to them without asking again in a second dialog.

      Parameters:
      player - The player the units are for
    • loadListFile

      protected void loadListFile(Player player, boolean reinforce)
      Allow the player to select a MegaMek Unit List file to load. The Entitys in the file will replace any that the player has already selected. As such, this method should only be called in the chat lounge. The file can record damage sustained, non-standard munitions selected, and ammunition expended in a prior engagement.
      Parameters:
      player - The player to add the units to
    • loadListFile

      protected void loadListFile(Player player, boolean reinforce, boolean requireATeam)
      Loads a unit file onto a player.
      Parameters:
      player - The player to add the units to
      reinforce - Whether the units arrive as reinforcements during a game
      requireATeam - Whether to refuse a player who is on no team. A gamemaster tool that has just assigned one passes false, because the change does not reach the board until the end of the round and the player has no team yet at the moment this is called
    • saveGame

      public boolean saveGame()
      Specified by:
      saveGame in class AbstractClientGUI
    • saveListFile

      public void saveListFile(ArrayList<Entity> unitList, String filename)
      Allow the player to save a list of entities to a MegaMek Unit List file. A "Save As" dialog will be displayed that allows the user to select the file's name and directory. The player can later load this file to quickly select the units for a new game. The file will record damage sustained, non-standard munitions selected, and ammunition expended during the course of the current engagement.
      Parameters:
      unitList - - the Vector of Entitys to be saved to a file. If this value is null or empty, the "Save As" dialog will not be displayed.
      filename - The filename to save to
    • printList

      public void printList(ArrayList<Entity> unitList, JButton button)
      Request MegaMekLab to print out record sheets for the current player's selected units. The method will try to find MML either automatically or based on a configured client setting.
      Parameters:
      unitList - The list of units to print
      button - This should always be ChatLounge#butPrintList, if you need to trigger this method from somewhere else, override it.
    • saveVictoryList

      protected void saveVictoryList()
    • loadPreviewImage

      public void loadPreviewImage(JLabel bp, Entity entity)
      Loads a preview image of the unit into the BufferedPanel.
      Parameters:
      bp - The JLabel to set the image as icon to
      entity - The unit
    • bingChat

      public void bingChat()
      Make a "bing" sound.
    • bingMyTurn

      public void bingMyTurn()
    • bingOthersTurn

      public void bingOthersTurn()
    • getClient

      public Client getClient()
      Specified by:
      getClient in interface IClientGUI
    • turnTimerComponent

      public JComponent turnTimerComponent()
      Specified by:
      turnTimerComponent in interface IClientGUI
    • setChatBoxActive

      public void setChatBoxActive(boolean active)
      Specified by:
      setChatBoxActive in interface IClientGUI
    • clearChatBox

      public void clearChatBox()
      Specified by:
      clearChatBox in interface IClientGUI
    • isChatBoxActive

      public boolean isChatBoxActive()
      Specified by:
      isChatBoxActive in interface IClientGUI
    • getLocalBots

      public Map<String,AbstractClient> getLocalBots()
      Specified by:
      getLocalBots in interface ILocalBots
    • setGenerationContext

      public void setGenerationContext(int playerId, GenerationContext context)
      Records what a player's newly generated units were rolled for, replacing any earlier record. Callers record only what a generator actually asked the player, never a default, so that a later roll on a generator that knows nothing cannot erase a real choice.
      Parameters:
      playerId - the owner of the generated units
      context - what they were generated for
    • getGenerationContext

      @Nullable public GenerationContext getGenerationContext(int playerId)
      Parameters:
      playerId - the player to look up
      Returns:
      what that player's units were generated for, or null when nothing has been recorded for them - they have generated nothing, or only from a generator that asks for no faction, command or rating
    • setSelectedEntityNum

      public void setSelectedEntityNum(int selectedEntityNum)
      Parameters:
      selectedEntityNum - The selectedEntityNum to set.
    • getRandomArmyDialog

      public RandomArmyDialog getRandomArmyDialog()
    • getRandomNameDialog

      public RandomNameDialog getRandomNameDialog()
    • boardSaveAs

      public void boardSaveAs(Game game)
      Opens a file dialog box to select a file to save as; saves the board to the file.
    • hexMoused

      public void hexMoused(BoardViewEvent event)
      Description copied from interface: BoardViewListener
      Sent when user clicks, double clicks or drags hex.
      Specified by:
      hexMoused in interface BoardViewListener
      Parameters:
      event - an event
    • hexCursor

      public void hexCursor(BoardViewEvent b)
      Description copied from interface: BoardViewListener
      Sent when BoardView 'cursor' is set to Hex.
      Specified by:
      hexCursor in interface BoardViewListener
      Parameters:
      b - an event
    • boardHexHighlighted

      public void boardHexHighlighted(BoardViewEvent b)
      Description copied from interface: BoardViewListener
      Sent when Hex is highlighted.
      Specified by:
      boardHexHighlighted in interface BoardViewListener
      Parameters:
      b - an event
    • hexSelected

      public void hexSelected(BoardViewEvent b)
      Description copied from interface: BoardViewListener
      Sent when Hex is selected through a call to the select method (this is not a mouse click event, although many mouse clicks lead to the hex being selected).
      Specified by:
      hexSelected in interface BoardViewListener
      Parameters:
      b - The select event
      See Also:
    • firstLOSHex

      public void firstLOSHex(BoardViewEvent b)
      Description copied from interface: BoardViewListener
      Sent when firstLOS is set.
      Specified by:
      firstLOSHex in interface BoardViewListener
      Parameters:
      b - an event
    • secondLOSHex

      public void secondLOSHex(BoardViewEvent b)
      Description copied from interface: BoardViewListener
      Sent when secondLOS is set.
      Specified by:
      secondLOSHex in interface BoardViewListener
      Parameters:
      b - an event
    • finishedMovingUnits

      public void finishedMovingUnits(BoardViewEvent b)
      Description copied from interface: BoardViewListener
      Sent when moving units is finished.
      Specified by:
      finishedMovingUnits in interface BoardViewListener
      Parameters:
      b - an event
    • unitSelected

      public void unitSelected(BoardViewEvent b)
      Description copied from interface: BoardViewListener
      Sent when Unit is selected.
      Specified by:
      unitSelected in interface BoardViewListener
      Parameters:
      b - an event
    • shouldIgnoreHotKeys

      public boolean shouldIgnoreHotKeys()
      Description copied from interface: IClientGUI
      Returns true if a dialog is visible on top of the ClientGUI. For example, the MegaMekController should ignore hotkeys if there is a dialog, like the CommonSettingsDialog, open.
      Specified by:
      shouldIgnoreHotKeys in interface IClientGUI
      Overrides:
      shouldIgnoreHotKeys in class AbstractClientGUI
      Returns:
      True when hotkey events should not be forwarded to this ClientGUI
    • getCurrentPanel

      public JComponent getCurrentPanel()
      Description copied from interface: IHasCurrentPanel
      The ClientGUI is split into the main panel (view) at the top, which takes up the majority of the view and the "current panel" which has different controls based on the phase.
      Specified by:
      getCurrentPanel in interface IHasCurrentPanel
      Returns:
      the panel for the current phase
    • isProcessingPointblankShot

      public boolean isProcessingPointblankShot()
    • setPointblankEID

      public void setPointblankEID(int eid)
    • getPointblankEID

      public int getPointblankEID()
    • preferenceChange

      public void preferenceChange(PreferenceChangeEvent e)
      Specified by:
      preferenceChange in interface IPreferenceChangeListener
    • showMovementEnvelope

      public void showMovementEnvelope(Entity entity, Map<Coords,Integer> mvEnvData, int gear)
      Shows the movement envelope in the BoardView for the given entity. The movement envelope data is a map of move end Coords to movement points used.
      Parameters:
      entity - The entity for which the movement envelope is
      mvEnvData - The movement envelope data
      gear - The move gear, MovementDisplay.GEAR_LAND or GEAR_JUMP
    • clearMovementEnvelope

      public void clearMovementEnvelope()
      Removes visibility to the Movement Envelope.
    • clearTemporarySprites

      public void clearTemporarySprites()
      Removes all temporary sprites from the board, such as pending actions, movement envelope, collapse warnings etc. Does not remove game-state sprites such as units or flares.
    • showMovementModifiers

      public void showMovementModifiers(Collection<MovePath> movePaths)
      Shows the optimal available movement modifiers in the BoardView.
      Parameters:
      movePaths - The available longest move paths.
    • showSensorRanges

      public void showSensorRanges(Entity entity)
      Shows the sensor/visual ranges for the given entity on its own position in the BoardView
      Parameters:
      entity - The entity that is looking/sensing
    • showSensorRanges

      public void showSensorRanges(Entity entity, Coords assumedPosition)
      Shows the sensor/visual ranges for the given entity in the BoardView. The ranges are centered on the given assumedPosition rather than the entity's own position.
      Parameters:
      entity - The entity that is looking/sensing
      assumedPosition - The position to center all ranges on
    • showCollapseWarning

      public void showCollapseWarning(Collection<BoardLocation> warnList)
      Shows collapse warnings in the given list of Coords in the BoardView
      Parameters:
      warnList - The list of coordinates to show the warning on
    • showSawClearingHexes

      @Deprecated(since="0.51.0", forRemoval=true) public void showSawClearingHexes(Map<BoardLocation,Integer> cutHexes)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Shows saw clearing indicators on the given hexes in the BoardView.
      Parameters:
      cutHexes - a map of board locations to turns remaining for saw clearing
    • showGroundObjects

      public void showGroundObjects(Map<Coords,List<ICarryable>> groundObjectList)
      Shows ground object icons in the given list of Coords in the BoardView
      Parameters:
      groundObjectList - The list of coordinates to show
    • showFiringSolutions

      public void showFiringSolutions(Entity entity)
      Shows firing solutions from the viewpoint of the given entity on targets
      Parameters:
      entity - The attacking entity
    • getMainPanel

      public JPanel getMainPanel()
    • getDisplayedUnit

      @Nullable public Entity getDisplayedUnit()
      Returns:
      The unit currently shown in the Unit Display. Note: This can be a unit than the one that is selected to move or fire.
    • getDisplayedWeapon

      public Optional<WeaponMounted> getDisplayedWeapon()
      Returns the weapon that is currently selected in the Unit Display. The selection can be void for various reasons, therefore this returns it as an Optional. Note: this method does some additional checks to avoid bugs where the weapon of the same ID on the unit is different from the selected weapon or is not even present on the unit. Also, the displayed unit is checked to be an active unit (i.e. can be found in game.getEntity()). It will log an error and return null otherwise. Using the returned weapon should be fairly safe.
      Returns:
      The weapon that is currently selected in the Unit Display, if any
    • getDisplayedAmmo

      public Optional<AmmoMounted> getDisplayedAmmo()
    • weaponSelected

      public void weaponSelected(MekDisplayEvent b)
      Description copied from interface: MekDisplayListener
      Sent when user selects a weapon in the weapon panel.
      Specified by:
      weaponSelected in interface MekDisplayListener
      Parameters:
      b - an event
    • updateFiringArc

      public void updateFiringArc(Entity entity)
      Updates the shown firing arc. The given entity should be the one that has taken an action such as moving or torso twisting or the unit whose selected weapon has changed. This method will check if the given unit is the one displayed in the unit viewer and/or the currently acting unit and update or remove the firing arcs accordingly.
      Parameters:
      entity - The unit that has acted or is otherwise the origin of the update
    • clearFieldOfFire

      public void clearFieldOfFire()
      Removes the field of fire from the BoardView and clears the cached values in the sprite handler.
    • getCurrentHex

      public Coords getCurrentHex()
      Return the Current Hex, used by client commands for the visually impaired
      Returns:
      the current Hex
    • setCurrentHex

      public void setCurrentHex(Hex hex)
      Set the Current Hex, used by client commands for the visually impaired
    • setCurrentHex

      public void setCurrentHex(Coords hex)
    • hideFleeZone

      public void hideFleeZone()
    • isCurrentBoardViewShowingAnimation

      public boolean isCurrentBoardViewShowingAnimation()
      Returns true when the currently shown BoardView is showing some animation and should not be centered on another hex or be hidden right now. An example is showing a unit's move animation.
      Returns:
      True when the currently shown BoardView is in the process of showing some animation
    • centerOnHex

      public void centerOnHex(@Nullable BoardLocation boardLocation)
      Shows the BoardView of the given location, if it exists, and centers on its coords.
      Parameters:
      boardLocation - The location to show and center on
    • centerOnUnit

      public void centerOnUnit(@Nullable Targetable targetable)
      Shows the BoardView of the given targetable, if it exists, and centers on its position, if that exists.
      Parameters:
      targetable - The unit or target to show and center on
    • getBoardView

      public BoardView getBoardView(int boardId)
      Overrides:
      getBoardView in class AbstractClientGUI
    • getBoardView

      public BoardView getBoardView(Targetable entity)
      Overrides:
      getBoardView in class AbstractClientGUI
    • getBoardView

      public BoardView getBoardView(BoardLocation boardLocation)
      Overrides:
      getBoardView in class AbstractClientGUI
    • onAllBoardViews

      public void onAllBoardViews(Consumer<BoardView> consumer)
    • suspendBoardTooltips

      public void suspendBoardTooltips()
    • activateBoardTooltips

      public void activateBoardTooltips()
    • getTilesetManager

      public TilesetManager getTilesetManager()