Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernizing Team #4106

Merged
merged 3 commits into from
Jan 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion megamek/src/megamek/client/ui/swing/MovementDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ private ArrayList<MegamekButton> getButtonList(int flag) {
Game game = clientgui.getClient().getGame();
Player localPlayer = clientgui.getClient().getLocalPlayer();
forwardIni = (game.getTeamForPlayer(localPlayer) != null)
&& (game.getTeamForPlayer(localPlayer).getSize() > 1);
&& (game.getTeamForPlayer(localPlayer).size() > 1);
opts = game.getOptions();
}

Expand Down
24 changes: 12 additions & 12 deletions megamek/src/megamek/client/ui/swing/lobby/TeamOverviewPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import java.awt.event.MouseListener;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Vector;
import java.util.List;

import static megamek.client.ui.swing.util.UIUtil.*;

Expand Down Expand Up @@ -190,7 +190,7 @@ public int getColumnCount() {
/** Updates the stored data from the provided game. */
public void updateTable(Game game) {
clearData();
for (Team team: game.getTeams()) {
for (Team team : game.getTeams()) {
teams.add(team);
teamID.add(team.getId());
teamNames.add(team.toString());
Expand All @@ -202,11 +202,11 @@ public void updateTable(Game game) {
int hiddenBv = 0;
boolean[] unitCritical = { false, false, false, false, false };
boolean[] unitWarnings = { false, false, false, false, false };
for (Player teamMember: team.getPlayersVector()) {
for (Player teamMember : team.players()) {
// Get the "real" player object, as the team's may be wrong
Player player = game.getPlayer(teamMember.getId());
bv += player.getBV();
for (Entity entity: game.getPlayerEntities(player, false)) {
for (Entity entity : game.getPlayerEntities(player, false)) {
// Avoid counting fighters in squadrons twice
if (entity instanceof FighterSquadron) {
continue;
Expand Down Expand Up @@ -260,8 +260,8 @@ private String unitSummary(int[] counts, boolean[] criticals, boolean[] warnings
String result = "";
for (int i = 0; i < counts.length; i++) {
if (counts[i] > 0) {
result += criticals[i] ? criticalSign() + " ": "";
result += warnings[i] ? warningSign() + " ": "";
result += criticals[i] ? criticalSign() + " " : "";
result += warnings[i] ? warningSign() + " " : "";
result += Messages.getString("ChatLounge.teamOverview.unitSum" + i) + " " + counts[i];
result += "<BR>";
}
Expand Down Expand Up @@ -307,7 +307,7 @@ public Object getValueAt(int row, int col) {
TOMCOLS column = TOMCOLS.values()[col];
switch (column) {
case TEAM:
boolean isEnemy = !teams.get(row).getPlayersVector().contains(clientGui.getClient().getLocalPlayer());
boolean isEnemy = !teams.get(row).players().contains(clientGui.getClient().getLocalPlayer());
Color color = isEnemy ? GUIPreferences.getInstance().getEnemyUnitColor() : GUIPreferences.getInstance().getMyUnitColor();
result.append(guiScaledFontHTML(color, textSizeDelta) + "&nbsp;");
result.append(teamNames.get(row) + "</FONT>");
Expand Down Expand Up @@ -335,7 +335,7 @@ public Object getValueAt(int row, int col) {
break;

case MEMBERS:
return teams.get(row).getPlayersVector();
return teams.get(row).players();

case BV:
result.append(guiScaledFontHTML(textSizeDelta) + "<CENTER>");
Expand All @@ -354,7 +354,7 @@ public Object getValueAt(int row, int col) {
case HIDDEN:
result.append(guiScaledFontHTML(textSizeDelta) + "<CENTER>");
var percentage = hidden.get(row);
result.append(percentage == 0 ? "--": NumberFormat.getPercentInstance().format(percentage));
result.append(percentage == 0 ? "--" : NumberFormat.getPercentInstance().format(percentage));

default:
break;
Expand Down Expand Up @@ -408,16 +408,16 @@ private class MemberListRenderer extends JPanel implements TableCellRenderer {
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
boolean hasFocus, int row, int column) {

if (!(value instanceof Vector<?>)) {
if (!(value instanceof List<?>)) {
return null;
}
removeAll();
add(Box.createVerticalGlue());
Vector<?> playerList = (Vector<?>) value;
List<?> playerList = (List<?>) value;
int baseSize = FONT_SCALE1 - (isDetached ? 2 : 0);
int size = scaleForGUI(2 * baseSize);
Font font = new Font(MMConstants.FONT_DIALOG, Font.PLAIN, scaleForGUI(baseSize));
for (Object obj: playerList) {
for (Object obj : playerList) {
if (!(obj instanceof Player)) {
continue;
}
Expand Down
5 changes: 2 additions & 3 deletions megamek/src/megamek/common/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,8 @@ public void setOptions(final @Nullable GameOptions options) {
*/
public @Nullable Team getTeamForPlayer(Player p) {
for (Team team : teams) {
for (Enumeration<Player> j = team.getPlayers(); j.hasMoreElements(); ) {
final Player player = j.nextElement();
if (p.equals(player)) {
for (Player player : team.players()) {
if (player.equals(p)) {
return team;
}
}
Expand Down
6 changes: 0 additions & 6 deletions megamek/src/megamek/common/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,6 @@ public boolean getGameMaster() {
*/
public void setGameMaster(boolean gameMaster) {
this.gameMaster = gameMaster;
if (game != null && game.getTeamForPlayer(this) != null) {
game.getTeamForPlayer(this).cacheObserverStatus();
}
}

/** @return true if {@link #observer} flag is true and not in VICTORY phase*/
Expand Down Expand Up @@ -312,9 +309,6 @@ public boolean isSeeAllPermitted() {
/** set the {@link #observer} flag. Observers have no units ad no team */
public void setObserver(boolean observer) {
this.observer = observer;
if (game != null && game.getTeamForPlayer(this) != null) {
game.getTeamForPlayer(this).cacheObserverStatus();
}
}

/**
Expand Down
Loading