From af296cbe79b13a2825e977beabd15b74cecd60e6 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Sat, 17 Mar 2018 00:47:09 +0100 Subject: [PATCH] * Added display of live on player avatar image, --- .../mage/client/components/HoverButton.java | 46 ++++++++++++++- .../mage/client/dialog/PreferencesDialog.form | 48 +++++++++++----- .../mage/client/dialog/PreferencesDialog.java | 56 +++++++++++++------ .../java/mage/client/game/PlayerPanelExt.java | 18 ++---- 4 files changed, 122 insertions(+), 46 deletions(-) diff --git a/Mage.Client/src/main/java/mage/client/components/HoverButton.java b/Mage.Client/src/main/java/mage/client/components/HoverButton.java index bd288506cf8..7dbf3891525 100644 --- a/Mage.Client/src/main/java/mage/client/components/HoverButton.java +++ b/Mage.Client/src/main/java/mage/client/components/HoverButton.java @@ -3,6 +3,7 @@ package mage.client.components; import java.awt.Color; import java.awt.Dimension; import java.awt.Font; +import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Image; @@ -40,6 +41,7 @@ public class HoverButton extends JPanel implements MouseListener { private String topText; private Image topTextImage; private Image topTextImageRight; + private String centerText; private boolean isHovered = false; private boolean isSelected = false; @@ -49,12 +51,15 @@ public class HoverButton extends JPanel implements MouseListener { private Command observer = null; private Command onHover = null; private Color textColor = Color.white; + private final Rectangle centerTextArea = new Rectangle(5, 18, 75, 40); + private final Color centerTextColor = Color.YELLOW; private final Color textBGColor = Color.black; static final Font textFont = new Font("Arial", Font.PLAIN, 12); static final Font textFontMini = new Font("Arial", Font.PLAIN, 11); static final Font textSetFontBoldMini = new Font("Arial", Font.BOLD, 12); static final Font textSetFontBold = new Font("Arial", Font.BOLD, 14); + private boolean useMiniFont = false; private boolean alignTextLeft = false; @@ -134,6 +139,21 @@ public class HoverButton extends JPanel implements MouseListener { if (topTextImageRight != null) { g.drawImage(topTextImageRight, this.getWidth() - 20, 3, this); } + + if (centerText != null) { + g2d.setColor(centerTextColor); + int fontSize = 40; + int val = Integer.parseInt(centerText); + if (val > 9999) { + fontSize = 24; + } else if (val > 999) { + fontSize = 28; + } else if (val > 99) { + fontSize = 34; + } + drawCenteredString(g2d, centerText, centerTextArea, new Font("Arial", Font.BOLD, fontSize)); + } + g2d.setColor(textColor); if (overlayImage != null) { g.drawImage(overlayImage, (imageSize.width - overlayImageSize.width) / 2, 10, this); } else if (set != null) { @@ -298,13 +318,17 @@ public class HoverButton extends JPanel implements MouseListener { public void setTopTextImage(Image topTextImage) { this.topTextImage = topTextImage; - this.textOffsetX = -1; // rest for new clculation + this.textOffsetX = -1; // rest for new calculation } public void setTopTextImageRight(Image topTextImage) { this.topTextImageRight = topTextImage; } + public void setCenterText(String centerText) { + this.centerText = centerText; + } + public void setTextAlwaysVisible(boolean textAlwaysVisible) { this.textAlwaysVisible = textAlwaysVisible; } @@ -313,4 +337,24 @@ public class HoverButton extends JPanel implements MouseListener { this.alignTextLeft = alignTextLeft; } + /** + * Draw a String centered in the middle of a Rectangle. + * + * @param g The Graphics instance. + * @param text The String to draw. + * @param rect The Rectangle to center the text in. + * @param font + */ + public void drawCenteredString(Graphics g, String text, Rectangle rect, Font font) { + // Get the FontMetrics + FontMetrics metrics = g.getFontMetrics(font); + // Determine the X coordinate for the text + int x = rect.x + (rect.width - metrics.stringWidth(text)) / 2; + // Determine the Y coordinate for the text (note we add the ascent, as in java 2d 0 is top of the screen) + int y = rect.y + ((rect.height - metrics.getHeight()) / 2) + metrics.getAscent(); + // Set the font + g.setFont(font); + // Draw the String + g.drawString(text, x, y); + } } diff --git a/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.form b/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.form index fc3c45de371..f122cdc1c44 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.form +++ b/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.form @@ -95,10 +95,10 @@ - + - + @@ -200,7 +200,7 @@ - + @@ -295,16 +295,22 @@ - - - - - - - - + + + + + + + + + + + + + + - + @@ -315,6 +321,8 @@ + + @@ -324,7 +332,6 @@ - @@ -354,6 +361,17 @@ + + + + + + + + + + + @@ -4274,7 +4292,7 @@ - + @@ -4847,7 +4865,7 @@ - + diff --git a/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.java b/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.java index ba94fc5d2f9..76aeb4619e4 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.java @@ -96,6 +96,7 @@ public class PreferencesDialog extends javax.swing.JDialog { public static final String KEY_SHOW_FULL_IMAGE_PATH = "showFullImagePath"; public static final String KEY_PERMANENTS_IN_ONE_PILE = "nonLandPermanentsInOnePile"; public static final String KEY_SHOW_PLAYER_NAMES_PERMANENTLY = "showPlayerNamesPermanently"; + public static final String KEY_DISPLAY_LIVE_ON_AVATAR = "displayLiveOnAvatar"; public static final String KEY_SHOW_ABILITY_PICKER_FORCED = "showAbilityPicker"; public static final String KEY_GAME_ALLOW_REQUEST_SHOW_HAND_CARDS = "gameAllowRequestShowHandCards"; public static final String KEY_GAME_SHOW_STORM_COUNTER = "gameShowStormCounter"; @@ -421,6 +422,7 @@ public class PreferencesDialog extends javax.swing.JDialog { main_game = new javax.swing.JPanel(); nonLandPermanentsInOnePile = new javax.swing.JCheckBox(); showPlayerNamesPermanently = new javax.swing.JCheckBox(); + displayLifeOnAvatar = new javax.swing.JCheckBox(); showAbilityPickerForced = new javax.swing.JCheckBox(); cbAllowRequestToShowHandCards = new javax.swing.JCheckBox(); cbShowStormCounter = new javax.swing.JCheckBox(); @@ -700,7 +702,7 @@ public class PreferencesDialog extends javax.swing.JDialog { .add(6, 6, 6) .add(main_cardLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(main_cardLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false) - .add(tooltipDelayLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 308, Short.MAX_VALUE) + .add(tooltipDelayLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .add(tooltipDelay, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .add(main_cardLayout.createSequentialGroup() .add(showCardName) @@ -741,6 +743,16 @@ public class PreferencesDialog extends javax.swing.JDialog { } }); + displayLifeOnAvatar.setSelected(true); + displayLifeOnAvatar.setText("Display life on avatar image"); + displayLifeOnAvatar.setToolTipText("Display the player's life over its avatar image."); + displayLifeOnAvatar.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); + displayLifeOnAvatar.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + displayLifeOnAvatarActionPerformed(evt); + } + }); + showAbilityPickerForced.setSelected(true); showAbilityPickerForced.setText("Show ability picker for abilities or spells without costs"); showAbilityPickerForced.setToolTipText("This prevents you from accidently activating abilities without other costs than tapping or casting spells with 0 mana costs."); @@ -797,15 +809,19 @@ public class PreferencesDialog extends javax.swing.JDialog { main_gameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(main_gameLayout.createSequentialGroup() .addContainerGap() - .add(main_gameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false) - .add(showPlayerNamesPermanently, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .add(nonLandPermanentsInOnePile, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .add(cbConfirmEmptyManaPool, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .add(cbAllowRequestToShowHandCards, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .add(cbShowStormCounter, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .add(cbAskMoveToGraveOrder, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .add(showAbilityPickerForced, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addContainerGap(177, Short.MAX_VALUE)) + .add(main_gameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(main_gameLayout.createSequentialGroup() + .add(main_gameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false) + .add(showPlayerNamesPermanently, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .add(nonLandPermanentsInOnePile, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .add(cbConfirmEmptyManaPool, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .add(cbAllowRequestToShowHandCards, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .add(cbShowStormCounter, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .add(cbAskMoveToGraveOrder, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .add(showAbilityPickerForced, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .add(0, 0, Short.MAX_VALUE)) + .add(displayLifeOnAvatar, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addContainerGap()) ); main_gameLayout.setVerticalGroup( main_gameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) @@ -814,6 +830,8 @@ public class PreferencesDialog extends javax.swing.JDialog { .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(showPlayerNamesPermanently) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(displayLifeOnAvatar) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(showAbilityPickerForced) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(cbAllowRequestToShowHandCards) @@ -822,8 +840,7 @@ public class PreferencesDialog extends javax.swing.JDialog { .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(cbConfirmEmptyManaPool) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) - .add(cbAskMoveToGraveOrder) - .addContainerGap()) + .add(cbAskMoveToGraveOrder)) ); nonLandPermanentsInOnePile.getAccessibleContext().setAccessibleName("nonLandPermanentsInOnePile"); @@ -880,10 +897,10 @@ public class PreferencesDialog extends javax.swing.JDialog { .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(main_game, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) - .add(main_gamelog, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 107, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(main_gamelog, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(main_battlefield, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) - .addContainerGap(121, Short.MAX_VALUE)) + .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); main_card.getAccessibleContext().setAccessibleName("Game panel"); @@ -1797,7 +1814,7 @@ public class PreferencesDialog extends javax.swing.JDialog { .add(panelCardImages, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(panelBackgroundImages, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) - .addContainerGap(125, Short.MAX_VALUE)) + .addContainerGap(133, Short.MAX_VALUE)) ); tabsPanel.addTab("Images", tabImages); @@ -2372,7 +2389,7 @@ public class PreferencesDialog extends javax.swing.JDialog { tabAvatarsLayout.setVerticalGroup( tabAvatarsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(tabAvatarsLayout.createSequentialGroup() - .add(avatarPane, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 584, Short.MAX_VALUE) + .add(avatarPane, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 620, Short.MAX_VALUE) .addContainerGap()) ); @@ -2762,6 +2779,7 @@ public class PreferencesDialog extends javax.swing.JDialog { save(prefs, dialog.showFullImagePath, KEY_SHOW_FULL_IMAGE_PATH, "true", "false", UPDATE_CACHE_POLICY); save(prefs, dialog.nonLandPermanentsInOnePile, KEY_PERMANENTS_IN_ONE_PILE, "true", "false", UPDATE_CACHE_POLICY); save(prefs, dialog.showPlayerNamesPermanently, KEY_SHOW_PLAYER_NAMES_PERMANENTLY, "true", "false", UPDATE_CACHE_POLICY); + save(prefs, dialog.displayLifeOnAvatar, KEY_DISPLAY_LIVE_ON_AVATAR, "true", "false", UPDATE_CACHE_POLICY); save(prefs, dialog.showAbilityPickerForced, KEY_SHOW_ABILITY_PICKER_FORCED, "true", "false", UPDATE_CACHE_POLICY); save(prefs, dialog.cbAllowRequestToShowHandCards, KEY_GAME_ALLOW_REQUEST_SHOW_HAND_CARDS, "true", "false", UPDATE_CACHE_POLICY); save(prefs, dialog.cbShowStormCounter, KEY_GAME_SHOW_STORM_COUNTER, "true", "false", UPDATE_CACHE_POLICY); @@ -3225,6 +3243,10 @@ public class PreferencesDialog extends javax.swing.JDialog { } }//GEN-LAST:event_cbGameJsonLogAutoSaveActionPerformed + private void displayLifeOnAvatarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_displayLifeOnAvatarActionPerformed + // TODO add your handling code here: + }//GEN-LAST:event_displayLifeOnAvatarActionPerformed + private void showProxySettings() { Connection.ProxyType proxyType = (Connection.ProxyType) cbProxyType.getSelectedItem(); switch (proxyType) { @@ -3331,6 +3353,7 @@ public class PreferencesDialog extends javax.swing.JDialog { load(prefs, dialog.showFullImagePath, KEY_SHOW_FULL_IMAGE_PATH, "true"); load(prefs, dialog.nonLandPermanentsInOnePile, KEY_PERMANENTS_IN_ONE_PILE, "true"); load(prefs, dialog.showPlayerNamesPermanently, KEY_SHOW_PLAYER_NAMES_PERMANENTLY, "true"); + load(prefs, dialog.displayLifeOnAvatar, KEY_DISPLAY_LIVE_ON_AVATAR, "true"); load(prefs, dialog.showAbilityPickerForced, KEY_SHOW_ABILITY_PICKER_FORCED, "true"); load(prefs, dialog.cbAllowRequestToShowHandCards, KEY_GAME_ALLOW_REQUEST_SHOW_HAND_CARDS, "true"); load(prefs, dialog.cbShowStormCounter, KEY_GAME_SHOW_STORM_COUNTER, "true"); @@ -3928,6 +3951,7 @@ public class PreferencesDialog extends javax.swing.JDialog { private javax.swing.JCheckBox checkBoxUpkeepYou; private javax.swing.JPanel connection_servers; private javax.swing.JLabel controlsDescriptionLabel; + private javax.swing.JCheckBox displayLifeOnAvatar; private javax.swing.JButton exitButton; private javax.swing.JLabel fontSizeLabel; private javax.swing.JPanel guiSizeBasic; diff --git a/Mage.Client/src/main/java/mage/client/game/PlayerPanelExt.java b/Mage.Client/src/main/java/mage/client/game/PlayerPanelExt.java index 5722b74785d..cf7b843556e 100644 --- a/Mage.Client/src/main/java/mage/client/game/PlayerPanelExt.java +++ b/Mage.Client/src/main/java/mage/client/game/PlayerPanelExt.java @@ -77,7 +77,6 @@ import mage.constants.ManaType; import mage.counters.Counter; import mage.counters.CounterType; import mage.designations.DesignationType; -import mage.remote.Session; import mage.utils.timer.PriorityTimer; import mage.view.CardView; import mage.view.ManaPoolView; @@ -93,13 +92,10 @@ public class PlayerPanelExt extends javax.swing.JPanel { private UUID playerId; private UUID gameId; - private Session session; private PlayerView player; private BigCard bigCard; - private static final int AVATAR_COUNT = 77; - private static final String DEFAULT_AVATAR_PATH = "/avatars/" + DEFAULT_AVATAR_ID + ".jpg"; private static final int PANEL_WIDTH = 94; @@ -179,8 +175,11 @@ public class PlayerPanelExt extends javax.swing.JPanel { public void update(PlayerView player) { this.player = player; - updateAvatar(); int playerLife = player.getLife(); + avatar.setCenterText("true".equals(MageFrame.getPreferences().get(PreferencesDialog.KEY_DISPLAY_LIVE_ON_AVATAR, "true")) + ? String.valueOf(playerLife) : null); + updateAvatar(); + if (playerLife > 99) { Font font = lifeLabel.getFont(); font = font.deriveFont(9f); @@ -701,8 +700,6 @@ public class PlayerPanelExt extends javax.swing.JPanel { .addComponent(btnPlayer, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(timerLabel, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(avatar, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE)) - // .addGroup(gl_panelBackground.createSequentialGroup() - // .addComponent(avatarFlag, GroupLayout.PREFERRED_SIZE, 16, GroupLayout.PREFERRED_SIZE)) .addGap(8)) .addGroup(gl_panelBackground.createSequentialGroup() .addGap(6) @@ -824,16 +821,12 @@ public class PlayerPanelExt extends javax.swing.JPanel { protected void sizePlayerPanel(boolean smallMode) { if (smallMode) { avatar.setVisible(false); -// avatarFlag.setVisible(false); -// monarchIcon.setVisible(false); btnPlayer.setVisible(true); timerLabel.setVisible(true); panelBackground.setPreferredSize(new Dimension(PANEL_WIDTH - 2, PANEL_HEIGHT_SMALL)); panelBackground.setBounds(0, 0, PANEL_WIDTH - 2, PANEL_HEIGHT_SMALL); } else { avatar.setVisible(true); -// avatarFlag.setVisible(true); -// monarchIcon.setVisible(true); btnPlayer.setVisible(false); timerLabel.setVisible(false); panelBackground.setPreferredSize(new Dimension(PANEL_WIDTH - 2, PANEL_HEIGHT)); @@ -887,8 +880,6 @@ public class PlayerPanelExt extends javax.swing.JPanel { } private HoverButton avatar; -// private JLabel avatarFlag; -// private JLabel monarchIcon; private JButton btnPlayer; private ImagePanel life; private ImagePanel poison; @@ -918,7 +909,6 @@ public class PlayerPanelExt extends javax.swing.JPanel { private JPanel energyExperiencePanel; private HoverButton exileZone; private HoverButton commandZone; - private HoverButton enchantPlayerViewZone; private final Map manaLabels = new HashMap<>(); }