mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 04:52:07 -08:00
Timers (In progress)
This commit is contained in:
parent
a373047c58
commit
42dd9d81b4
11 changed files with 302 additions and 58 deletions
|
|
@ -26,8 +26,11 @@ public class HoverButton extends JPanel implements MouseListener {
|
|||
private int textOffsetY = 0;
|
||||
private int textOffsetButtonY = 2;
|
||||
private int textOffsetX = -1;
|
||||
private int topTextOffsetX = -1;
|
||||
private Dimension overlayImageSize;
|
||||
|
||||
private String topText;
|
||||
|
||||
private boolean isHovered = false;
|
||||
private boolean isSelected = false;
|
||||
private boolean drawSet = false;
|
||||
|
|
@ -36,6 +39,7 @@ public class HoverButton extends JPanel implements MouseListener {
|
|||
private Command observer = null;
|
||||
private Command onHover = null;
|
||||
private Color textColor = Color.white;
|
||||
private Color textBGColor = Color.black;
|
||||
|
||||
static final Font textFont = new Font("Arial", Font.PLAIN, 12);
|
||||
static final Font textFontMini = new Font("Arial", Font.PLAIN, 11);
|
||||
|
|
@ -100,6 +104,18 @@ public class HoverButton extends JPanel implements MouseListener {
|
|||
} else {
|
||||
g.drawImage(disabledImage, 0, 0, imageSize.width, imageSize.height, this);
|
||||
}
|
||||
if (topText != null) {
|
||||
if (useMiniFont) {
|
||||
g2d.setFont(textFontMini);
|
||||
} else {
|
||||
g2d.setFont(textFont);
|
||||
}
|
||||
topTextOffsetX = calculateOffsetForTop(g2d, topText);
|
||||
g2d.setColor(textBGColor);
|
||||
g2d.drawString(topText, topTextOffsetX+1, 13);
|
||||
g2d.setColor(textColor);
|
||||
g2d.drawString(topText, topTextOffsetX, 12);
|
||||
}
|
||||
if (overlayImage != null) {
|
||||
g.drawImage(overlayImage, (imageSize.width - overlayImageSize.width) / 2, 10, this);
|
||||
} else if (set != null) {
|
||||
|
|
@ -136,6 +152,15 @@ public class HoverButton extends JPanel implements MouseListener {
|
|||
return textOffsetX;
|
||||
}
|
||||
|
||||
private int calculateOffsetForTop(Graphics2D g2d, String text) {
|
||||
if (topTextOffsetX == -1) { // calculate once
|
||||
FontRenderContext frc = g2d.getFontRenderContext();
|
||||
int textWidth = (int) textFont.getStringBounds(text, frc).getWidth();
|
||||
topTextOffsetX = (imageSize.width - textWidth) / 2;
|
||||
}
|
||||
return topTextOffsetX;
|
||||
}
|
||||
|
||||
public void setTextColor(Color textColor) {
|
||||
this.textColor = textColor;
|
||||
}
|
||||
|
|
@ -242,4 +267,8 @@ public class HoverButton extends JPanel implements MouseListener {
|
|||
observer.execute();
|
||||
}
|
||||
}
|
||||
|
||||
public void setTopText(String topText) {
|
||||
this.topText = topText;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -182,6 +182,8 @@ public class PlayerPanelExt extends javax.swing.JPanel {
|
|||
}
|
||||
}
|
||||
this.avatar.setText(player.getName());
|
||||
String priorityTimeValue = getPriorityTimeLeftString(player);
|
||||
this.avatar.setTopText(priorityTimeValue);
|
||||
this.btnPlayer.setText(player.getName());
|
||||
if (player.isActive()) {
|
||||
this.avatar.setBorder(greenBorder);
|
||||
|
|
@ -216,6 +218,11 @@ public class PlayerPanelExt extends javax.swing.JPanel {
|
|||
update(player.getManaPool());
|
||||
}
|
||||
|
||||
private String getPriorityTimeLeftString(PlayerView player) {
|
||||
int priorityTimeLeft = player.getPriorityTimeLeft();
|
||||
return priorityTimeLeft / 3600 + ":" + (priorityTimeLeft % 3600) / 60 + ":" + priorityTimeLeft % 60;
|
||||
}
|
||||
|
||||
protected void update(ManaPoolView pool) {
|
||||
manaLabels.get("B").setText(Integer.toString(pool.getBlack()));
|
||||
manaLabels.get("R").setText(Integer.toString(pool.getRed()));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue