Skip to content

Commit

Permalink
Merge pull request #5466 from SJuliez/clientgui-boardviews-2
Browse files Browse the repository at this point in the history
Move Field of Fire Sprites out of BoardView
  • Loading branch information
HammerGS authored May 19, 2024
2 parents 06698c6 + 637ce46 commit 5d69556
Show file tree
Hide file tree
Showing 38 changed files with 1,298 additions and 757 deletions.
24 changes: 12 additions & 12 deletions megamek/src/megamek/client/AbstractClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ protected void disconnected() {
}

if (!host.equals(MMConstants.LOCALHOST)) {
getIGame().fireGameEvent(new GamePlayerDisconnectedEvent(this, getLocalPlayer()));
getGame().fireGameEvent(new GamePlayerDisconnectedEvent(this, getLocalPlayer()));
}
}
}
Expand Down Expand Up @@ -185,7 +185,7 @@ public void sendNextPlayer() {
* Sends the info associated with the local player.
*/
public void sendPlayerInfo() {
send(new Packet(PacketCommand.PLAYER_UPDATE, getIGame().getPlayer(localPlayerNumber)));
send(new Packet(PacketCommand.PLAYER_UPDATE, getGame().getPlayer(localPlayerNumber)));
}

/**
Expand Down Expand Up @@ -217,9 +217,9 @@ protected void receivePlayerInfo(Packet c) {
int pindex = c.getIntValue(0);
Player newPlayer = (Player) c.getObject(1);
if (!playerExists(newPlayer.getId())) {
getIGame().addPlayer(pindex, newPlayer);
getGame().addPlayer(pindex, newPlayer);
} else {
getIGame().setPlayer(pindex, newPlayer);
getGame().setPlayer(pindex, newPlayer);
}
}

Expand Down Expand Up @@ -301,11 +301,11 @@ protected synchronized void checkDuplicateNamesDuringAdd(Entity entity) {
protected void receiveUnitReplace(Packet packet) {
@SuppressWarnings(value = "unchecked")
List<Force> forces = (List<Force>) packet.getObject(1);
forces.forEach(force -> getIGame().getForces().replace(force.getId(), force));
forces.forEach(force -> getGame().getForces().replace(force.getId(), force));

@SuppressWarnings(value = "unchecked")
List<InGameObject> units = (List<InGameObject>) packet.getObject(0);
getIGame().replaceUnits(units);
getGame().replaceUnits(units);
}

/**
Expand Down Expand Up @@ -441,25 +441,25 @@ protected boolean handleGameIndependentPacket(Packet packet) {
Player player = getPlayer(packet.getIntValue(0));
if (player != null) {
player.setDone(packet.getBooleanValue(1));
getIGame().fireGameEvent(new GamePlayerChangeEvent(player, player));
getGame().fireGameEvent(new GamePlayerChangeEvent(player, player));
}
break;
case PLAYER_REMOVE:
bots.values().removeIf(bot -> bot.localPlayerNumber == packet.getIntValue(0));
getIGame().removePlayer(packet.getIntValue(0));
getGame().removePlayer(packet.getIntValue(0));
break;
case CHAT:
possiblyWriteToLog((String) packet.getObject(0));
getIGame().fireGameEvent(new GamePlayerChatEvent(this, null, (String) packet.getObject(0)));
getGame().fireGameEvent(new GamePlayerChatEvent(this, null, (String) packet.getObject(0)));
break;
case ENTITY_ADD:
receiveUnitReplace(packet);
break;
case SENDING_BOARD:
getIGame().receiveBoards((Map<Integer, Board>) packet.getObject(0));
getGame().receiveBoards((Map<Integer, Board>) packet.getObject(0));
break;
case ROUND_UPDATE:
getIGame().setCurrentRound(packet.getIntValue(0));
getGame().setCurrentRound(packet.getIntValue(0));
break;
case PHASE_CHANGE:
changePhase((GamePhase) packet.getObject(0));
Expand All @@ -485,7 +485,7 @@ protected void possiblyWriteToLog(String message) {
* Changes the game phase, and the displays that go along with it.
*/
public void changePhase(GamePhase phase) {
getIGame().receivePhase(phase);
getGame().receivePhase(phase);
switch (phase) {
case STARTING_SCENARIO:
case EXCHANGE:
Expand Down
16 changes: 4 additions & 12 deletions megamek/src/megamek/client/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,10 @@ public Client(String name, String host, int port) {
}
}

@Override
public IGame getIGame() {
return game;
}

public Game getGame() {
return game;
}


/**
* Get hexes designated for automatic artillery hits.
*/
Expand Down Expand Up @@ -205,9 +199,7 @@ public void changePhase(GamePhase phase) {
}
}

/**
* is it my turn?
*/
@Override
public boolean isMyTurn() {
if (getGame().getPhase().isSimultaneous(getGame())) {
return game.getTurnForPlayer(localPlayerNumber) != null;
Expand Down Expand Up @@ -702,13 +694,13 @@ protected void receiveAttack(Packet c) {


// Should be private?
public String receiveReport(List<Report> v) {
if (v == null) {
public String receiveReport(List<Report> reports) {
if (reports == null) {
return "[null report vector]";
}

StringBuffer report = new StringBuffer();
for (Report r : v) {
for (Report r : reports) {
report.append(r.getText());
}

Expand Down
13 changes: 9 additions & 4 deletions megamek/src/megamek/client/IClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,26 +56,31 @@ public interface IClient {
*
* @return The game of this client
*/
IGame getIGame();
IGame getGame();

/** @return The in-game object associated with the given ID. */
default Optional<InGameObject> getInGameObject(int id) {
return getIGame().getInGameObject(id);
return getGame().getInGameObject(id);
}

/** @return A list of all in-game objects of the game. This list is copied and may be safely modified. */
default List<InGameObject> getInGameObjects() {
return getIGame().getInGameObjects();
return getGame().getInGameObjects();
}

/** @return The player with the given ID, or null if there is no such player. */
default Player getPlayer(int id) {
return getIGame().getPlayer(id);
return getGame().getPlayer(id);
}

/** @return The ID of the player playing at this Client. */
int getLocalPlayerNumber();

/**
* @return True when the currently active turn is a turn for the local player
*/
boolean isMyTurn();

/**
* Sets the ID of the player playing at this Client.
* // TODO : only used by AddBotUtil -> could be included in a bot's constructor and removed here
Expand Down
14 changes: 6 additions & 8 deletions megamek/src/megamek/client/SBFClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,13 @@
*/
package megamek.client;

import megamek.client.ui.swing.tooltip.PilotToolTip;
import megamek.client.ui.swing.util.UIUtil;
import megamek.common.*;
import megamek.common.net.packets.Packet;
import megamek.common.strategicBattleSystems.SBFGame;
import megamek.common.util.ImageUtil;
import org.apache.logging.log4j.LogManager;

import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.*;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/**
Expand Down Expand Up @@ -60,10 +53,15 @@ public SBFClient(String name, String host, int port) {
}

@Override
public IGame getIGame() {
public SBFGame getGame() {
return game;
}

@Override
public boolean isMyTurn() {
return (game.getTurn() != null) && game.getTurn().isValid(localPlayerNumber, game);
}

@Override
@SuppressWarnings("unchecked")
protected boolean handleGameSpecificPacket(Packet packet) {
Expand Down
2 changes: 1 addition & 1 deletion megamek/src/megamek/client/bot/BotClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -1188,7 +1188,7 @@ protected void receiveBuildingCollapse(Packet packet) {
* Let's save ourselves a little processing time and not deal with any of it
*/
@Override
public String receiveReport(List<Report> v) {
public String receiveReport(List<Report> reports) {
return "";
}

Expand Down
5 changes: 0 additions & 5 deletions megamek/src/megamek/client/bot/princess/Princess.java
Original file line number Diff line number Diff line change
Expand Up @@ -1610,11 +1610,6 @@ protected void initMovement() {
}
}

@Override
public Game getGame() {
return game;
}

@Override
public void initialize() {
try {
Expand Down
17 changes: 17 additions & 0 deletions megamek/src/megamek/client/ui/swing/AbstractClientGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
*/
package megamek.client.ui.swing;

import megamek.client.IClient;
import megamek.client.ui.Messages;
import megamek.client.ui.swing.boardview.*;
import megamek.client.ui.swing.util.UIUtil;
import megamek.common.Configuration;
import megamek.common.preference.ClientPreferences;
Expand All @@ -30,7 +32,9 @@
import java.awt.event.WindowEvent;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public abstract class AbstractClientGUI implements IClientGUI {

Expand All @@ -49,6 +53,16 @@ public abstract class AbstractClientGUI implements IClientGUI {
protected static final String FILENAME_ICON_256X256 = "megamek-icon-256x256.png";

protected final JFrame frame = new JFrame(Messages.getString("ClientGUI.title"));
private final IClient iClient;

// BoardViews
protected final Map<Integer, IBoardView> boardViews = new HashMap<>();
protected final BoardViewsContainer boardViewsContainer = new BoardViewsContainer(this);

public AbstractClientGUI(IClient iClient) {
this.iClient = iClient;
initializeFrame();
}

@Override
public JFrame getFrame() {
Expand Down Expand Up @@ -125,4 +139,7 @@ void saveSettings() {

protected abstract boolean saveGame();

public List<IBoardView> boardViews() {
return new ArrayList<>(boardViews.values());
}
}
Loading

0 comments on commit 5d69556

Please sign in to comment.