-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5571 from SJuliez/code-clean-towards-SBF-statusba…
…rphasedisplays3 PhaseDisplay Code Cleanup
- Loading branch information
Showing
21 changed files
with
253 additions
and
375 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,21 @@ | ||
/* | ||
* MegaMek - Copyright (C) 2000-2003 Ben Mazur ([email protected]) | ||
* Copyright (c) 2000-2003 Ben Mazur ([email protected]) | ||
* Copyright (c) 2024 - The MegaMek Team. All Rights Reserved. | ||
* | ||
* This program is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License as published by the Free | ||
* Software Foundation; either version 2 of the License, or (at your option) | ||
* any later version. | ||
* This file is part of MegaMek. | ||
* | ||
* This program is distributed in the hope that it will be useful, but | ||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* for more details. | ||
* MegaMek is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* MegaMek is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with MegaMek. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package megamek.client.ui.swing; | ||
|
||
|
@@ -20,53 +26,74 @@ | |
import megamek.client.ui.swing.widget.*; | ||
import megamek.common.event.*; | ||
import megamek.common.util.Distractable; | ||
import megamek.common.util.DistractableAdapter; | ||
import megamek.common.util.DistractableDelegate; | ||
|
||
import java.util.Objects; | ||
|
||
import static megamek.client.ui.swing.util.UIUtil.guiScaledFontHTML; | ||
|
||
/** | ||
* This is the base class for all the "displays" which take control during the local player's turn. | ||
* Only one display is shown at each time; the ChatLounge is also a display. The ChatLounge doesn't | ||
* show the boardview but most other displays do. Typically the display itself is the button bar | ||
* at the bottom of the GUI. | ||
* | ||
* Note that a display being active does not mean that it is also the player's turn. The display | ||
* should allow inspecting units and other actions even when it's another player's turn. Also, | ||
* even when it's the local player's turn, a unit is not necessarily selected. The unit that is | ||
* selected to act (if there is one) is not necessarily the same as the one open in the unit display. | ||
*/ | ||
public abstract class AbstractPhaseDisplay extends SkinnedJPanel implements | ||
BoardViewListener, GameListener, Distractable { | ||
|
||
public static final int DONE_BUTTON_WIDTH = 160; | ||
|
||
protected DistractableAdapter distracted = new DistractableAdapter(); | ||
protected MegamekButton butDone; | ||
protected final MegamekButton butDone; | ||
|
||
private final DistractableDelegate distractableDelegate = new DistractableDelegate(); | ||
|
||
/** The IClientgui that this display is a part of. Cannot be null. */ | ||
private final IClientGUI clientgui; | ||
|
||
/** | ||
* Creates a phase display using the standard skin settings for phase displays. | ||
* | ||
* @param cg The IClientGUI parent of this display | ||
*/ | ||
protected AbstractPhaseDisplay(IClientGUI cg) { | ||
this(cg, SkinSpecification.UIComponents.PhaseDisplay.getComp(), | ||
SkinSpecification.UIComponents.PhaseDisplayDoneButton.getComp()); | ||
} | ||
|
||
protected AbstractPhaseDisplay(IClientGUI cg, String borderSkinComp, String buttonSkinComp) { | ||
super(borderSkinComp, 0); | ||
/** | ||
* Creates a phase display using the given skin settings for the button panel and the buttons. | ||
* | ||
* @param cg The IClientGUI parent of this display | ||
* @see SkinSpecification.UIComponents#getComp() | ||
*/ | ||
protected AbstractPhaseDisplay(IClientGUI cg, String panelSkin, String buttonSkin) { | ||
super(panelSkin, 0); | ||
clientgui = Objects.requireNonNull(cg); | ||
setBorder(new MegamekBorder(borderSkinComp)); | ||
butDone = new MegamekButton("DONE", buttonSkinComp); | ||
setBorder(new MegamekBorder(panelSkin)); | ||
|
||
butDone = new MegamekButton("DONE", buttonSkin); | ||
String f = guiScaledFontHTML(UIUtil.uiLightViolet()) + KeyCommandBind.getDesc(KeyCommandBind.DONE)+ "</FONT>"; | ||
butDone.setToolTipText("<html><body>" + f + "</body></html>"); | ||
butDone.setActionCommand("doneButton"); | ||
butDone.addActionListener(e -> { | ||
if (shouldPerformKeyCommands()) { | ||
done(); | ||
} | ||
}); | ||
|
||
MegaMekGUI.getKeyDispatcher().registerCommandAction(KeyCommandBind.DONE, this::shouldPerformKeyCommands, this::done); | ||
butDone.addActionListener(e -> done()); | ||
|
||
MegaMekGUI.getKeyDispatcher().registerCommandAction(KeyCommandBind.DONE, this::shouldperformDone, this::done); | ||
} | ||
|
||
private void done() { | ||
// When the turn is ended, we could miss a key release event | ||
// This will ensure no repeating keys are stuck down | ||
MegaMekGUI.getKeyDispatcher().stopAllRepeating(); | ||
ready(); | ||
if (shouldperformDone()) { | ||
// When the turn is ended, we could miss a key release event | ||
// This will ensure no repeating keys are stuck down | ||
MegaMekGUI.getKeyDispatcher().stopAllRepeating(); | ||
ready(); | ||
} | ||
} | ||
|
||
private boolean shouldPerformKeyCommands() { | ||
private boolean shouldperformDone() { | ||
return ((clientgui.getClient().isMyTurn() | ||
|| (clientgui.getClient().getGame().getTurn() == null) | ||
|| (clientgui.getClient().getGame().getPhase().isReport()))) | ||
|
@@ -78,21 +105,26 @@ && isVisible() | |
|
||
@Override | ||
public final boolean isIgnoringEvents() { | ||
return distracted.isIgnoringEvents(); | ||
return distractableDelegate.isIgnoringEvents(); | ||
} | ||
|
||
@Override | ||
public final void setIgnoringEvents(boolean distracted) { | ||
this.distracted.setIgnoringEvents(distracted); | ||
public final void setIgnoringEvents(boolean isDistracted) { | ||
distractableDelegate.setIgnoringEvents(isDistracted); | ||
} | ||
|
||
public void ready() { } | ||
/** | ||
* Tells the display to finish the current player turn and send all planned actions to the server. | ||
* Planned actions are e.g. movement, attacks or deployment. Usually, the planned actions are all | ||
* actions that, together, make up a single unit's turn, e.g. all weapon attacks of one unit. | ||
*/ | ||
public abstract void ready(); | ||
|
||
public IClientGUI getClientgui() { | ||
return clientgui; | ||
} | ||
|
||
// BoardListener | ||
//region Empty BoardListener | ||
|
||
@Override | ||
public void hexMoused(BoardViewEvent b) { } | ||
|
@@ -118,7 +150,9 @@ public void finishedMovingUnits(BoardViewEvent b) { } | |
@Override | ||
public void unitSelected(BoardViewEvent b) { } | ||
|
||
// GameListener | ||
//endregion | ||
|
||
//region Empty GameListener | ||
|
||
@Override | ||
public void gamePlayerConnected(GamePlayerConnectedEvent e) { } | ||
|
@@ -176,4 +210,6 @@ public void gameClientFeedbackRequest(GameCFREvent evt) { } | |
|
||
@Override | ||
public void gameVictory(GameVictoryEvent e) { } | ||
|
||
//endregion | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.