[UI] Phases new Look and Feel

This commit is contained in:
magenoxx 2012-07-24 19:40:09 +04:00
parent 5c58edced6
commit 0d20e954dc
16 changed files with 113 additions and 21 deletions

View file

@ -42,6 +42,12 @@ public class HoverButton extends JPanel implements MouseListener {
final static Font textSetFontBold = new Font("Arial", Font.BOLD, 14); final static Font textSetFontBold = new Font("Arial", Font.BOLD, 14);
private boolean useMiniFont = false; private boolean useMiniFont = false;
public HoverButton(String text, Image image, Rectangle size) {
this(text, image, image, null, image, size);
if (image == null)
throw new IllegalArgumentException("Image can't be null");
}
public HoverButton(String text, Image image, Image hover, Image disabled, Rectangle size) { public HoverButton(String text, Image image, Image hover, Image disabled, Rectangle size) {
this(text, image, hover, null, disabled, size); this(text, image, hover, null, disabled, size);
} }

View file

@ -35,14 +35,15 @@
package mage.client.game; package mage.client.game;
import mage.Constants; import mage.Constants;
import mage.client.components.layout.RelativeLayout;
import mage.cards.action.ActionCallback; import mage.cards.action.ActionCallback;
import mage.client.MageFrame; import mage.client.MageFrame;
import mage.client.cards.BigCard; import mage.client.cards.BigCard;
import mage.client.chat.ChatPanel; import mage.client.chat.ChatPanel;
import mage.client.combat.CombatManager; import mage.client.combat.CombatManager;
import mage.client.components.HoverButton;
import mage.client.components.MageComponents; import mage.client.components.MageComponents;
import mage.client.components.ext.dlg.DialogManager; import mage.client.components.ext.dlg.DialogManager;
import mage.client.components.layout.RelativeLayout;
import mage.client.dialog.*; import mage.client.dialog.*;
import mage.client.game.FeedbackPanel.FeedbackMode; import mage.client.game.FeedbackPanel.FeedbackMode;
import mage.client.plugins.adapters.MageActionCallback; import mage.client.plugins.adapters.MageActionCallback;
@ -54,6 +55,7 @@ import mage.client.util.PhaseManager;
import mage.remote.Session; import mage.remote.Session;
import mage.view.*; import mage.view.*;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.mage.plugins.card.utils.impl.ImageManagerImpl;
import javax.swing.*; import javax.swing.*;
import javax.swing.GroupLayout.Alignment; import javax.swing.GroupLayout.Alignment;
@ -94,6 +96,8 @@ public class GamePanel extends javax.swing.JPanel {
private HelperPanel helper; private HelperPanel helper;
private Map<String, HoverButton> hoverButtons;
/** Creates new form GamePanel */ /** Creates new form GamePanel */
public GamePanel() { public GamePanel() {
initComponents(); initComponents();
@ -219,7 +223,7 @@ public class GamePanel extends javax.swing.JPanel {
} }
int height = pnlBattlefield.getHeight(); int height = pnlBattlefield.getHeight();
phasesContainer.setPreferredSize(new Dimension(45, height)); phasesContainer.setPreferredSize(new Dimension(75, height));
DialogManager.getManager().setScreenWidth(rect.width); DialogManager.getManager().setScreenWidth(rect.width);
DialogManager.getManager().setScreenHeight(rect.height); DialogManager.getManager().setScreenHeight(rect.height);
@ -491,25 +495,37 @@ public class GamePanel extends javax.swing.JPanel {
prevStep.setForeground(DEFAULT_FOREGROUND_COLOR); prevStep.setForeground(DEFAULT_FOREGROUND_COLOR);
} }
switch (step) { switch (step) {
case UNTAP: updateButton(untap); break; case UNTAP: updateButton("Untap"); break;
case UPKEEP: updateButton(upkeep); break; case UPKEEP: updateButton("Upkeep"); break;
case DRAW: updateButton(draw); break; case DRAW: updateButton("Draw"); break;
case PRECOMBAT_MAIN: updateButton(main1); break; case PRECOMBAT_MAIN: updateButton("Main1"); break;
case BEGIN_COMBAT: case BEGIN_COMBAT: updateButton("Combat_Start"); break;
case DECLARE_ATTACKERS: updateButton(attack); break; case DECLARE_ATTACKERS: updateButton("Combat_Attack"); break;
case DECLARE_BLOCKERS: updateButton(block); break; case DECLARE_BLOCKERS: updateButton("Combat_Block"); break;
case FIRST_COMBAT_DAMAGE: case FIRST_COMBAT_DAMAGE:
case COMBAT_DAMAGE: updateButton(combatButton); break; case COMBAT_DAMAGE: updateButton("Combat_Damage"); break;
case POSTCOMBAT_MAIN: updateButton(main2); break; case POSTCOMBAT_MAIN: updateButton("Main2"); break;
case END_TURN: updateButton(endOfTurn); break; case END_TURN: updateButton("Cleanup"); break;
} }
} }
private void updateButton(JButton button) { private void updateButton(JButton button) {
if (prevBGColor == null) prevBGColor = button.getBackground(); /*if (prevBGColor == null) prevBGColor = button.getBackground();
button.setBackground(new Color(0,0,0,100)); button.setBackground(new Color(0,0,0,100));
button.setForeground(Color.white); button.setForeground(Color.white);
prevStep = button; prevStep = button;
*/
}
private void updateButton(String name) {
if (hoverButtons.containsKey(name)) {
hoverButtons.get(name).setAlignmentX(0.0f);
}
/*if (prevBGColor == null) prevBGColor = button.getBackground();
button.setBackground(new Color(0,0,0,100));
button.setForeground(Color.white);
*/
//prevStep = button;
} }
private void showRevealed(GameView game) { private void showRevealed(GameView game) {
@ -956,12 +972,21 @@ public class GamePanel extends javax.swing.JPanel {
jPhases.setBackground(new Color(0, 0, 0, 100)); jPhases.setBackground(new Color(0, 0, 0, 100));
//jPhases.setLayout(new GridLayout(0, 1)); //jPhases.setLayout(new GridLayout(0, 1));
jPhases.setLayout(new BoxLayout(jPhases, BoxLayout.PAGE_AXIS)); jPhases.setLayout(new BoxLayout(jPhases, BoxLayout.PAGE_AXIS));
jPanel3.setPreferredSize(new Dimension(45, 100)); jPanel3.setPreferredSize(new Dimension(75, 100));
untap = new JButton("Un"); String[] phases = {"Untap", "Upkeep", "Draw", "Main1",
untap.setToolTipText("Untap"); "Combat_Start", "Combat_Attack", "Combat_Block", "Combat_Damage", "Combat_End",
untap.setAlignmentX(RIGHT_ALIGNMENT); "Main2", "Cleanup", "Next_Turn"};
upkeep = new JButton("Up"); for (String name : phases) {
createPhaseButton(name);
}
for (HoverButton hoverButton : hoverButtons.values()) {
//hoverButton.setAlignmentX(RIGHT_ALIGNMENT);
jPhases.add(hoverButton);
}
/*upkeep = new JButton("Up");
upkeep.setToolTipText("Upkeep"); upkeep.setToolTipText("Upkeep");
upkeep.setAlignmentX(RIGHT_ALIGNMENT); upkeep.setAlignmentX(RIGHT_ALIGNMENT);
draw = new JButton("D"); draw = new JButton("D");
@ -994,21 +1019,31 @@ public class GamePanel extends javax.swing.JPanel {
session.sendPlayerInteger(gameId, 0); session.sendPlayerInteger(gameId, 0);
} }
} }
}); });*/
//endButtonTip = new JLabel("<-- Press this button to end the turn"); //endButtonTip = new JLabel("<-- Press this button to end the turn");
//endButtonTip.setForeground(Color.white); //endButtonTip.setForeground(Color.white);
jPhases.add(untap); /*jPhases.add(untap);
untap.setAlignmentX(.0f);
jPhases.add(upkeep); jPhases.add(upkeep);
upkeep.setAlignmentX(.0f);
jPhases.add(draw); jPhases.add(draw);
draw.setAlignmentX(.0f);
jPhases.add(main1); jPhases.add(main1);
main1.setAlignmentX(0.3f);
jPhases.add(attack); jPhases.add(attack);
attack.setAlignmentX(.0f);
jPhases.add(block); jPhases.add(block);
block.setAlignmentX(.0f);
jPhases.add(combatButton); jPhases.add(combatButton);
combatButton.setAlignmentX(.0f);
jPhases.add(main2); jPhases.add(main2);
main2.setAlignmentX(0.5f);
jPhases.add(endOfTurn); jPhases.add(endOfTurn);
endOfTurn.setAlignmentX(.0f);
//jPhases.add(endButtonTip); //jPhases.add(endButtonTip);
*/
pnlReplay.setOpaque(false); pnlReplay.setOpaque(false);
helper = new HelperPanel(); helper = new HelperPanel();
@ -1177,6 +1212,17 @@ public class GamePanel extends javax.swing.JPanel {
abilityPicker.setVisible(false); abilityPicker.setVisible(false);
} }
private void createPhaseButton(String name) {
if (hoverButtons == null) {
hoverButtons = new LinkedHashMap<String, HoverButton>();
}
Rectangle rect = new Rectangle(36, 36);
HoverButton button = new HoverButton("", ImageManagerImpl.getInstance().getPhaseImage(name), rect);
button.setToolTipText(name.replaceAll("_", " "));
button.setPreferredSize(new Dimension(36, 36));
hoverButtons.put(name, button);
}
private mage.client.components.ability.AbilityPicker abilityPicker; private mage.client.components.ability.AbilityPicker abilityPicker;
private mage.client.cards.BigCard bigCard; private mage.client.cards.BigCard bigCard;
private javax.swing.JButton btnConcede; private javax.swing.JButton btnConcede;
@ -1266,5 +1312,4 @@ class ReplayTask extends SwingWorker<Void, Collection<MatchView>> {
logger.fatal("Update Matches Task error", ex); logger.fatal("Update Matches Task error", ex);
} catch (CancellationException ex) {} } catch (CancellationException ex) {}
} }
} }

View file

@ -19,4 +19,6 @@ public interface ImageManager {
public Image getDlgActivePrevButtonImage(); public Image getDlgActivePrevButtonImage();
public Image getDlgNextButtonImage(); public Image getDlgNextButtonImage();
public Image getDlgActiveNextButtonImage(); public Image getDlgActiveNextButtonImage();
public Image getPhaseImage(String phase);
} }

View file

@ -10,6 +10,8 @@ import java.awt.image.BufferedImage;
import java.awt.image.CropImageFilter; import java.awt.image.CropImageFilter;
import java.awt.image.FilteredImageSource; import java.awt.image.FilteredImageSource;
import java.net.URL; import java.net.URL;
import java.util.HashMap;
import java.util.Map;
public class ImageManagerImpl implements ImageManager { public class ImageManagerImpl implements ImageManager {
@ -19,6 +21,26 @@ public class ImageManagerImpl implements ImageManager {
return fInstance; return fInstance;
} }
public ImageManagerImpl() {
init();
}
public void init() {
String[] phases = {"Untap", "Upkeep", "Draw", "Main1",
"Combat_Start", "Combat_Attack", "Combat_Block", "Combat_Damage", "Combat_End",
"Main2", "Cleanup", "Next_Turn"};
phasesImages = new HashMap<String, Image>();
for (String name : phases) {
Image image = getImageFromResource("/phases/phase_" + name.toLowerCase() + ".png", new Rectangle(36, 36));
phasesImages.put(name, image);
}
}
@Override
public Image getPhaseImage(String phase) {
return phasesImages.get(phase);
}
@Override @Override
public Image getAppImage() { public Image getAppImage() {
if (appImage == null) { if (appImage == null) {
@ -158,6 +180,21 @@ public class ImageManagerImpl implements ImageManager {
return resized; return resized;
} }
protected static Image getImageFromResource(String path, Rectangle rec) {
Image resized = null;
URL imageURL = ImageManager.class.getResource(path);
try {
BufferedImage image = ImageIO.read(imageURL);
resized = image.getScaledInstance(rec.width, rec.height, java.awt.Image.SCALE_SMOOTH);
} catch (Exception e) {
e.printStackTrace();
}
return resized;
}
protected static BufferedImage getBufferedImageFromResource(String path) { protected static BufferedImage getBufferedImageFromResource(String path) {
URL imageURL = ImageManager.class.getResource(path); URL imageURL = ImageManager.class.getResource(path);
BufferedImage image = null; BufferedImage image = null;
@ -187,4 +224,6 @@ public class ImageManagerImpl implements ImageManager {
private static BufferedImage imageDlgActivePrevButton; private static BufferedImage imageDlgActivePrevButton;
private static BufferedImage imageDlgNextButton; private static BufferedImage imageDlgNextButton;
private static BufferedImage imageDlgActiveNextButton; private static BufferedImage imageDlgActiveNextButton;
private static Map<String, Image> phasesImages;
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB