From: Kimmo R. <ki...@us...> - 2012-11-21 20:33:15
|
Update of /cvsroot/arianne/stendhal/src/games/stendhal/client/gui/stats In directory vz-cvs-4.sog:/tmp/cvs-serv11521/src/games/stendhal/client/gui/stats Modified Files: ManaIndicator.java StatsPanel.java Log Message: Changed ManaIndicator to use StatusDisplayBar Index: ManaIndicator.java =================================================================== RCS file: /cvsroot/arianne/stendhal/src/games/stendhal/client/gui/stats/ManaIndicator.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ManaIndicator.java 11 Jun 2012 20:48:17 -0000 1.3 --- ManaIndicator.java 21 Nov 2012 20:33:12 -0000 1.4 *************** *** 12,27 **** package games.stendhal.client.gui.stats; ! import games.stendhal.client.sprite.Sprite; ! import games.stendhal.client.sprite.SpriteStore; import java.awt.Color; - import java.awt.Dimension; - import java.awt.Graphics; - import java.awt.Insets; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.util.Map; - import javax.swing.JComponent; import javax.swing.SwingUtilities; --- 12,23 ---- package games.stendhal.client.gui.stats; ! import games.stendhal.client.gui.LinearScalingModel; ! import games.stendhal.client.gui.StatusDisplayBar; import java.awt.Color; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.util.Map; import javax.swing.SwingUtilities; *************** *** 29,43 **** * A bar indicator component for mana. */ ! public class ManaIndicator extends JComponent implements PropertyChangeListener { private static final long serialVersionUID = 3462088641737184898L; private static ManaIndicator instance; - - private static final String IMAGE_FILE_NAME = "data/gui/mana_scale.png"; ! /** Mana scaled to pixels */ ! private double mana; ! private double base_mana; ! private final Sprite image; /** --- 25,34 ---- * A bar indicator component for mana. */ ! public class ManaIndicator extends StatusDisplayBar implements PropertyChangeListener { private static final long serialVersionUID = 3462088641737184898L; private static ManaIndicator instance; ! private final LinearScalingModel model; /** *************** *** 48,52 **** static synchronized ManaIndicator create() { if (instance == null) { ! instance = new ManaIndicator(); } else { throw new IllegalStateException("Instance already created"); --- 39,44 ---- static synchronized ManaIndicator create() { if (instance == null) { ! LinearScalingModel model = new LinearScalingModel(); ! instance = new ManaIndicator(model); } else { throw new IllegalStateException("Instance already created"); *************** *** 59,69 **** * Create a new mana indicator. */ ! private ManaIndicator() { setVisible(false); ! final SpriteStore store = SpriteStore.get(); ! image = store.getSprite(IMAGE_FILE_NAME); ! ! // We don't draw the background ! setOpaque(false); } --- 51,59 ---- * Create a new mana indicator. */ ! private ManaIndicator(final LinearScalingModel model) { ! super(model); ! this.model = model; setVisible(false); ! setBarColor(new Color(49, 75, 253)); } *************** *** 87,92 **** */ public void setMana(double mana) { ! this.mana = mana; ! repaint(); } --- 77,81 ---- */ public void setMana(double mana) { ! model.setValue(mana); } *************** *** 98,150 **** */ public void setBaseMana(double base_mana) { ! this.base_mana = (int) Math.floor(base_mana); ! repaint(); ! } ! ! @Override ! public Dimension getPreferredSize() { ! Dimension pref = new Dimension(image.getWidth(), image.getHeight()); ! ! Insets insets = getInsets(); ! pref.width += insets.left + insets.right; ! pref.height += insets.top + insets.bottom; ! ! return pref; ! } ! ! @Override ! public Dimension getMinimumSize() { ! // Preferred is also the minimum size where the bar can be drawn properly ! return getPreferredSize(); ! } ! ! /** ! * Scale a mana value to bar length. ! * ! * @param mana player mana ! * @return length of the drawn bar in pixels ! */ ! private int scale(double mana) { ! if(base_mana == 0) { ! return 0; ! } else { ! return (int) (image.getWidth() * mana / base_mana); ! } ! } ! ! @Override ! public void paintComponent(Graphics g) { ! super.paintComponent(g); ! Insets insets = getInsets(); ! // Paint black what is not covered by the colored bar ! g.setColor(Color.BLACK); ! g.fillRect(insets.left, insets.top, image.getWidth(), image.getHeight()); ! // Draw appropriate length of the image ! g.clipRect(insets.left, insets.top, scale(mana), getHeight()); ! image.draw(g, insets.left, insets.top); ! this.setToolTipText("Mana: " + (int) mana + "/" + (int) base_mana); } ! public void propertyChange(PropertyChangeEvent evt) { if (evt == null) { --- 87,94 ---- */ public void setBaseMana(double base_mana) { ! model.setMaxValue(base_mana); } ! @Override public void propertyChange(PropertyChangeEvent evt) { if (evt == null) { *************** *** 157,160 **** --- 101,105 ---- // Feature changes are triggered from outside the EDT. SwingUtilities.invokeLater(new Runnable() { + @Override public void run() { setVisible(false); *************** *** 168,171 **** --- 113,117 ---- // Feature changes are triggered from outside the EDT. SwingUtilities.invokeLater(new Runnable() { + @Override public void run() { setVisible(true); Index: StatsPanel.java =================================================================== RCS file: /cvsroot/arianne/stendhal/src/games/stendhal/client/gui/stats/StatsPanel.java,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** StatsPanel.java 18 Jul 2012 18:40:47 -0000 1.25 --- StatsPanel.java 21 Nov 2012 20:33:12 -0000 1.26 *************** *** 14,17 **** --- 14,18 ---- import games.stendhal.client.gui.layout.SBoxLayout; + import games.stendhal.client.gui.layout.SLayout; import java.awt.Font; *************** *** 46,50 **** karmaIndicator = KarmaIndicator.create(); karmaIndicator.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); - karmaIndicator.setToolTipText("Karma"); add(karmaIndicator); --- 47,50 ---- *************** *** 52,56 **** manaIndicator.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); manaIndicator.setToolTipText("Mana"); ! add(manaIndicator); hpLabel = new StatLabel(); --- 52,56 ---- manaIndicator.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); manaIndicator.setToolTipText("Mana"); ! add(manaIndicator, SBoxLayout.constraint(SLayout.EXPAND_X)); hpLabel = new StatLabel(); |