spjspj - Modifications to shrink size of players who have left.

This commit is contained in:
spjspj 2016-06-24 19:20:46 +10:00
parent 48ae863459
commit 157d94360c
2 changed files with 81 additions and 6 deletions

View file

@ -30,6 +30,7 @@ package mage.client.game;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
@ -156,6 +157,7 @@ public final class GamePanel extends javax.swing.JPanel {
private static final String CMD_AUTO_ORDER_RESET_ALL = "cmdAutoOrderResetAll";
private final Map<UUID, PlayAreaPanel> players = new HashMap<>();
private final Map<UUID, Boolean> playersWhoLeft = new HashMap<>();
// non modal frames
private final Map<UUID, CardInfoWindowDialog> exiles = new HashMap<>();
@ -309,6 +311,7 @@ public final class GamePanel extends javax.swing.JPanel {
playAreaPanelEntry.getValue().CleanUp();
}
this.players.clear();
this.playersWhoLeft.clear();
jLayeredPane.remove(abilityPicker);
this.abilityPicker.cleanUp();
@ -594,6 +597,7 @@ public final class GamePanel extends javax.swing.JPanel {
private void addPlayers(GameView game) {
this.players.clear();
this.playersWhoLeft.clear();
this.pnlBattlefield.removeAll();
//arrange players in a circle with the session player at the bottom left
int numSeats = game.getPlayers().size();
@ -614,6 +618,7 @@ public final class GamePanel extends javax.swing.JPanel {
PlayAreaPanel playAreaPanel = new PlayAreaPanel(player, bigCard, gameId, game.getPriorityTime(), this,
new PlayAreaPanelOptions(game.isPlayer(), game.isPlayer(), game.isRollbackTurnsAllowed()));
players.put(player.getPlayerId(), playAreaPanel);
playersWhoLeft.put(player.getPlayerId(), false);
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.BOTH;
c.weightx = 0.5;
@ -622,8 +627,19 @@ public final class GamePanel extends javax.swing.JPanel {
c.gridwidth = 2;
}
c.gridx = col;
c.gridy = row;
this.pnlBattlefield.add(playAreaPanel, c);
c.gridy = 0;
// Top panel (row=0)
JPanel topPanel = new JPanel();
topPanel.setOpaque(false);
// Bottom panel (row=1)
JPanel bottomPanel = new JPanel();
bottomPanel.setOpaque(false);
topPanel.setLayout(new GridBagLayout());
bottomPanel.setLayout(new GridBagLayout());
bottomPanel.add(playAreaPanel, c);
playAreaPanel.setVisible(true);
if (oddNumber) {
col++;
@ -646,13 +662,20 @@ public final class GamePanel extends javax.swing.JPanel {
PlayAreaPanel playerPanel = new PlayAreaPanel(player, bigCard, gameId, game.getPriorityTime(), this,
new PlayAreaPanelOptions(game.isPlayer(), false, game.isRollbackTurnsAllowed()));
players.put(player.getPlayerId(), playerPanel);
playersWhoLeft.put(player.getPlayerId(), false);
c = new GridBagConstraints();
c.fill = GridBagConstraints.BOTH;
c.weightx = 0.5;
c.weighty = 0.5;
c.gridx = col;
c.gridy = row;
this.pnlBattlefield.add(playerPanel, c);
c.gridy = 0;
if (row == 0) {
topPanel.add(playerPanel, c);
} else {
bottomPanel.add(playerPanel, c);
}
playerPanel.setVisible(true);
playerNum++;
if (playerNum >= numSeats) {
@ -665,6 +688,16 @@ public final class GamePanel extends javax.swing.JPanel {
for (PlayAreaPanel p : players.values()) {
p.sizePlayer(smallMode);
}
GridBagConstraints panelC = new GridBagConstraints();
panelC.fill = GridBagConstraints.BOTH;
panelC.weightx = 0.5;
panelC.weighty = 0.5;
panelC.gridwidth = 1;
panelC.gridy = 0;
this.pnlBattlefield.add(topPanel, panelC);
panelC.gridy = 1;
this.pnlBattlefield.add(bottomPanel, panelC);
}
public synchronized void updateGame(GameView game) {
@ -838,6 +871,42 @@ public final class GamePanel extends javax.swing.JPanel {
CombatManager.getInstance().hideCombat(gameId);
}
for (PlayerView player : game.getPlayers()) {
if (player.hasLeft() && !playersWhoLeft.get(player.getPlayerId())) {
PlayAreaPanel playerLeftPanel = players.get(player.getPlayerId());
playersWhoLeft.put(player.getPlayerId(), true);
Container parent = playerLeftPanel.getParent();
GridBagLayout layout = (GridBagLayout) parent.getLayout();
for (Component otherPanel : parent.getComponents()) {
if (otherPanel instanceof PlayAreaPanel) {
GridBagConstraints gbc = layout.getConstraints(otherPanel);
if (gbc.weightx > 0.1) {
gbc.weightx = 0.99;
}
gbc.fill = GridBagConstraints.BOTH;
gbc.anchor = GridBagConstraints.WEST;
if (gbc.gridx > 0) {
gbc.anchor = GridBagConstraints.EAST;
}
if (otherPanel == playerLeftPanel) {
gbc.weightx = 0.01;
Dimension d = playerLeftPanel.getPreferredSize();
d.width = 95;
otherPanel.setPreferredSize(d);
}
parent.remove(otherPanel);
parent.add(otherPanel, gbc);
}
}
parent.validate();
parent.repaint();
}
}
feedbackPanel.disableUndo();
this.revalidate();

View file

@ -112,6 +112,7 @@ public class PlayerPanelExt extends javax.swing.JPanel {
private static final Border RED_BORDER = new LineBorder(Color.red, 2);
private static final Border EMPTY_BORDER = BorderFactory.createEmptyBorder(0, 0, 0, 0);
private final Color greenBackgroundColor = new Color(180, 255, 180, 200);
private final Color deadBackgroundColor = new Color(200, 180, 180, 200);
private int avatarId = -1;
private String flagName;
@ -222,7 +223,7 @@ public class PlayerPanelExt extends javax.swing.JPanel {
}
graveLabel.setText(Integer.toString(graveCards));
graveLabel.setToolTipText("Card Types: " + qtyCardTypes(player.getGraveyard()));
int exileCards = player.getExile().size();
if (exileCards > 99) {
if (!changedFontExile) {
@ -282,6 +283,7 @@ public class PlayerPanelExt extends javax.swing.JPanel {
if (player.hasLeft()) {
this.avatar.setBorder(RED_BORDER);
this.btnPlayer.setBorder(RED_BORDER);
setDeadBackgroundColor();
} else {
this.avatar.setBorder(EMPTY_BORDER);
this.btnPlayer.setBorder(EMPTY_BORDER);
@ -299,6 +301,10 @@ public class PlayerPanelExt extends javax.swing.JPanel {
panelBackground.setBackgroundColor(greenBackgroundColor);
}
private void setDeadBackgroundColor() {
panelBackground.setBackgroundColor(deadBackgroundColor);
}
/**
* Updates the avatar image and tooltip text
*/
@ -878,7 +884,7 @@ public class PlayerPanelExt extends javax.swing.JPanel {
if (cardTypesPresent.isEmpty()) return 0;
else return cardTypesPresent.size();
}
private HoverButton avatar;
private JLabel avatarFlag;
private JButton btnPlayer;