mirror of
https://github.com/correl/mage.git
synced 2024-12-26 03:00:11 +00:00
Merge pull request #4697 from spjspj/master
Add an on-hover over avatar highlight effect.
This commit is contained in:
commit
e2fbe8cee9
2 changed files with 96 additions and 71 deletions
|
@ -8,10 +8,13 @@ import java.awt.Graphics;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.Image;
|
import java.awt.Image;
|
||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.awt.event.MouseListener;
|
import java.awt.event.MouseListener;
|
||||||
import java.awt.font.FontRenderContext;
|
import java.awt.font.FontRenderContext;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.Timer;
|
||||||
import mage.client.util.Command;
|
import mage.client.util.Command;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -43,6 +46,7 @@ public class HoverButton extends JPanel implements MouseListener {
|
||||||
private Image topTextImageRight;
|
private Image topTextImageRight;
|
||||||
private String centerText;
|
private String centerText;
|
||||||
|
|
||||||
|
private boolean wasHovered = false;
|
||||||
private boolean isHovered = false;
|
private boolean isHovered = false;
|
||||||
private boolean isSelected = false;
|
private boolean isSelected = false;
|
||||||
private boolean drawSet = false;
|
private boolean drawSet = false;
|
||||||
|
@ -52,7 +56,8 @@ public class HoverButton extends JPanel implements MouseListener {
|
||||||
private Command onHover = null;
|
private Command onHover = null;
|
||||||
private Color textColor = Color.white;
|
private Color textColor = Color.white;
|
||||||
private final Rectangle centerTextArea = new Rectangle(5, 18, 75, 40);
|
private final Rectangle centerTextArea = new Rectangle(5, 18, 75, 40);
|
||||||
private Color centerTextColor = new Color(200, 190, 0, 180);
|
private Color centerTextColor = new Color(200, 210, 0, 180);
|
||||||
|
private Color origCenterTextColor = new Color(200, 210, 0, 180);
|
||||||
private final Color textBGColor = Color.black;
|
private final Color textBGColor = Color.black;
|
||||||
|
|
||||||
static final Font textFont = new Font("Arial", Font.PLAIN, 12);
|
static final Font textFont = new Font("Arial", Font.PLAIN, 12);
|
||||||
|
@ -64,6 +69,13 @@ public class HoverButton extends JPanel implements MouseListener {
|
||||||
|
|
||||||
private boolean alignTextLeft = false;
|
private boolean alignTextLeft = false;
|
||||||
|
|
||||||
|
Timer faderGainLife = null;
|
||||||
|
Timer faderLoseLife = null;
|
||||||
|
private int loseX = 0;
|
||||||
|
private int gainX = 0;
|
||||||
|
private boolean doLoseFade = true;
|
||||||
|
private boolean doGainFade = true;
|
||||||
|
|
||||||
public HoverButton(String text, Image image, Rectangle size) {
|
public HoverButton(String text, Image image, Rectangle size) {
|
||||||
this(text, image, image, null, image, size);
|
this(text, image, image, null, image, size);
|
||||||
if (image == null) {
|
if (image == null) {
|
||||||
|
@ -95,6 +107,10 @@ public class HoverButton extends JPanel implements MouseListener {
|
||||||
Graphics2D g2d = (Graphics2D) g;
|
Graphics2D g2d = (Graphics2D) g;
|
||||||
if (isEnabled()) {
|
if (isEnabled()) {
|
||||||
if (isHovered || textAlwaysVisible) {
|
if (isHovered || textAlwaysVisible) {
|
||||||
|
if (isHovered) {
|
||||||
|
wasHovered = true;
|
||||||
|
setCenterColor(Color.YELLOW);
|
||||||
|
}
|
||||||
g.drawImage(hoverImage, 0, 0, imageSize.width, imageSize.height, this);
|
g.drawImage(hoverImage, 0, 0, imageSize.width, imageSize.height, this);
|
||||||
if (text != null) {
|
if (text != null) {
|
||||||
if (textColor != null) {
|
if (textColor != null) {
|
||||||
|
@ -109,6 +125,10 @@ public class HoverButton extends JPanel implements MouseListener {
|
||||||
g2d.drawString(text, textOffsetX, textOffsetY);
|
g2d.drawString(text, textOffsetX, textOffsetY);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if (wasHovered) {
|
||||||
|
wasHovered = false;
|
||||||
|
setCenterColor(origCenterTextColor);
|
||||||
|
}
|
||||||
g.drawImage(image, 0, 0, imageSize.width, imageSize.height, this);
|
g.drawImage(image, 0, 0, imageSize.width, imageSize.height, this);
|
||||||
}
|
}
|
||||||
if (isSelected) {
|
if (isSelected) {
|
||||||
|
@ -361,4 +381,75 @@ public class HoverButton extends JPanel implements MouseListener {
|
||||||
// Draw the String
|
// Draw the String
|
||||||
g.drawString(text, x, y);
|
g.drawString(text, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void gainLifeDisplay() {
|
||||||
|
if (faderGainLife == null && doGainFade) {
|
||||||
|
doGainFade = false;
|
||||||
|
faderGainLife = new Timer(50, new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent ae) {
|
||||||
|
gainX++;
|
||||||
|
int alpha = Math.max(250 - gainX, 180);
|
||||||
|
setCenterColor(new Color(2 * gainX, 210, 255, alpha));
|
||||||
|
repaint();
|
||||||
|
if (gainX >= 100) {
|
||||||
|
setCenterColor(new Color(200, 210, 0, 180));
|
||||||
|
gainX = 100;
|
||||||
|
|
||||||
|
if (faderGainLife != null) {
|
||||||
|
faderGainLife.stop();
|
||||||
|
faderGainLife.setRepeats(false);
|
||||||
|
faderGainLife.setDelay(50000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
gainX = 0;
|
||||||
|
faderGainLife.setInitialDelay(25);
|
||||||
|
faderGainLife.setRepeats(true);
|
||||||
|
faderGainLife.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loseLifeDisplay() {
|
||||||
|
if (faderLoseLife == null && doLoseFade) {
|
||||||
|
doLoseFade = false;
|
||||||
|
faderLoseLife = new Timer(50, new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent ae) {
|
||||||
|
loseX++;
|
||||||
|
int alpha = Math.max(250 - loseX, 180);
|
||||||
|
setCenterColor(new Color(250 - loseX / 2, 130 + loseX, 0, alpha));
|
||||||
|
repaint();
|
||||||
|
if (loseX >= 100) {
|
||||||
|
setCenterColor(new Color(200, 210, 0, 180));
|
||||||
|
loseX = 100;
|
||||||
|
stopLifeDisplay();
|
||||||
|
|
||||||
|
if (faderLoseLife != null) {
|
||||||
|
faderLoseLife.stop();
|
||||||
|
faderLoseLife.setRepeats(false);
|
||||||
|
faderLoseLife.setDelay(50000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
loseX = 0;
|
||||||
|
faderLoseLife.setInitialDelay(25);
|
||||||
|
faderLoseLife.setRepeats(true);
|
||||||
|
faderLoseLife.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stopLifeDisplay() {
|
||||||
|
|
||||||
|
if (faderGainLife != null && gainX >= 100) {
|
||||||
|
faderGainLife.stop();
|
||||||
|
faderGainLife = null;
|
||||||
|
}
|
||||||
|
doGainFade = true;
|
||||||
|
if (faderLoseLife != null && loseX >= 100) {
|
||||||
|
faderLoseLife.stop();
|
||||||
|
faderLoseLife = null;
|
||||||
|
}
|
||||||
|
doLoseFade = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,8 +38,6 @@ import java.awt.Dimension;
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
import java.awt.Image;
|
import java.awt.Image;
|
||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
|
@ -55,7 +53,6 @@ import javax.swing.JLabel;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.LayoutStyle.ComponentPlacement;
|
import javax.swing.LayoutStyle.ComponentPlacement;
|
||||||
import javax.swing.SwingConstants;
|
import javax.swing.SwingConstants;
|
||||||
import javax.swing.Timer;
|
|
||||||
import javax.swing.border.Border;
|
import javax.swing.border.Border;
|
||||||
import javax.swing.border.LineBorder;
|
import javax.swing.border.LineBorder;
|
||||||
import mage.cards.decks.importer.DckDeckImporter;
|
import mage.cards.decks.importer.DckDeckImporter;
|
||||||
|
@ -117,12 +114,6 @@ public class PlayerPanelExt extends javax.swing.JPanel {
|
||||||
private String flagName;
|
private String flagName;
|
||||||
private String basicTooltipText;
|
private String basicTooltipText;
|
||||||
private static final Map<UUID, Integer> playerLives = new HashMap<>();
|
private static final Map<UUID, Integer> playerLives = new HashMap<>();
|
||||||
private int loseX;
|
|
||||||
private boolean doLoseFade = true;
|
|
||||||
private int gainX;
|
|
||||||
private boolean doGainFade = true;
|
|
||||||
Timer faderGainLife = null;
|
|
||||||
Timer faderLoseLife = null;
|
|
||||||
|
|
||||||
private PriorityTimer timer;
|
private PriorityTimer timer;
|
||||||
|
|
||||||
|
@ -200,69 +191,12 @@ public class PlayerPanelExt extends javax.swing.JPanel {
|
||||||
if (displayLife) {
|
if (displayLife) {
|
||||||
if (playerLife != pastLife) {
|
if (playerLife != pastLife) {
|
||||||
if (playerLife > pastLife) {
|
if (playerLife > pastLife) {
|
||||||
if (faderGainLife == null && doGainFade) {
|
avatar.gainLifeDisplay();
|
||||||
doGainFade = false;
|
|
||||||
faderGainLife = new Timer(50, new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent ae) {
|
|
||||||
gainX++;
|
|
||||||
int alpha = Math.max(250 - gainX, 180);
|
|
||||||
avatar.setCenterColor(new Color(2 * gainX, 190, 255, alpha));
|
|
||||||
avatar.repaint();
|
|
||||||
if (gainX >= 100) {
|
|
||||||
avatar.setCenterColor(new Color(200, 190, 0, 180));
|
|
||||||
gainX = 100;
|
|
||||||
|
|
||||||
if (faderGainLife != null) {
|
|
||||||
faderGainLife.stop();
|
|
||||||
faderGainLife.setRepeats(false);
|
|
||||||
faderGainLife.setDelay(50000);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
gainX = 0;
|
|
||||||
faderGainLife.setInitialDelay(25);
|
|
||||||
faderGainLife.setRepeats(true);
|
|
||||||
faderGainLife.start();
|
|
||||||
}
|
|
||||||
} else if (playerLife < pastLife) {
|
} else if (playerLife < pastLife) {
|
||||||
if (faderLoseLife == null && doLoseFade) {
|
avatar.loseLifeDisplay();
|
||||||
doLoseFade = false;
|
|
||||||
faderLoseLife = new Timer(50, new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent ae) {
|
|
||||||
loseX++;
|
|
||||||
int alpha = Math.max(250 - loseX, 180);
|
|
||||||
avatar.setCenterColor(new Color(250 - loseX / 2, 140 + loseX / 2, 0, alpha));
|
|
||||||
avatar.repaint();
|
|
||||||
if (loseX >= 100) {
|
|
||||||
avatar.setCenterColor(new Color(200, 190, 0, 180));
|
|
||||||
loseX = 100;
|
|
||||||
|
|
||||||
if (faderLoseLife != null) {
|
|
||||||
faderLoseLife.stop();
|
|
||||||
faderLoseLife.setRepeats(false);
|
|
||||||
faderLoseLife.setDelay(50000);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
loseX = 0;
|
|
||||||
faderLoseLife.setInitialDelay(25);
|
|
||||||
faderLoseLife.setRepeats(true);
|
|
||||||
faderLoseLife.start();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (playerLife == pastLife) {
|
} else if (playerLife == pastLife) {
|
||||||
if (faderGainLife != null && gainX >= 100) {
|
avatar.stopLifeDisplay();
|
||||||
faderGainLife.stop();
|
|
||||||
faderGainLife = null;
|
|
||||||
}
|
|
||||||
doGainFade = true;
|
|
||||||
if (faderLoseLife != null && loseX >= 100) {
|
|
||||||
faderLoseLife.stop();
|
|
||||||
faderLoseLife = null;
|
|
||||||
}
|
|
||||||
doLoseFade = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue