Skip to content

Commit

Permalink
GUI: enhance visibility of timer (resolves #11236)
Browse files Browse the repository at this point in the history
  • Loading branch information
xenohedron committed Sep 30, 2023
1 parent 0753f82 commit 4883679
Showing 1 changed file with 32 additions and 24 deletions.
56 changes: 32 additions & 24 deletions Mage.Client/src/main/java/mage/client/game/PlayerPanelExt.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,20 @@ public void init(UUID gameId, UUID playerId, boolean controlled, BigCard bigCard
timer.setTaskOnTick(() -> {
int priorityTimeValue = pt.getCount() + pt.getBufferCount();
String text = getPriorityTimeLeftString(priorityTimeValue);

// Set timer text colors (note, if you change it here, change it in update() as well)
Color textColor = null; // use default in HoverButton
Color foregroundColor = Color.BLACK;
if (pt.getBufferCount() > 0) {
textColor = Color.GREEN;
foregroundColor = Color.GREEN.darker().darker();
} else if (pt.getCount() < 300) { // visual indication for under 5 minutes
textColor = Color.RED;
foregroundColor = Color.RED.darker().darker();
}
PlayerPanelExt.this.avatar.setTopText(text);
PlayerPanelExt.this.avatar.setTopTextColor(pt.getBufferCount() > 0 ? Color.GREEN : null);
PlayerPanelExt.this.avatar.setTopTextColor(textColor);
PlayerPanelExt.this.timerLabel.setText(text);
PlayerPanelExt.this.timerLabel
.setForeground(pt.getBufferCount() > 0 ? Color.GREEN.darker().darker() : Color.BLACK);
PlayerPanelExt.this.timerLabel.setForeground(foregroundColor);
PlayerPanelExt.this.avatar.repaint();
});
timer.init(gameId);
Expand Down Expand Up @@ -195,10 +203,10 @@ public void update(GameView game, PlayerView player, Set<UUID> possibleTargets)
if (playerLife != pastLife) {
if (playerLife > pastLife) {
avatar.gainLifeDisplay();
} else if (playerLife < pastLife) {
} else {
avatar.loseLifeDisplay();
}
} else if (playerLife == pastLife) {
} else {
avatar.stopLifeDisplay();
}
}
Expand Down Expand Up @@ -311,10 +319,18 @@ public void update(GameView game, PlayerView player, Set<UUID> possibleTargets)
this.timer.setBufferCount(player.getBufferTimeLeft());
this.avatar.setTopText(priorityTimeValue);
this.timerLabel.setText(priorityTimeValue);

this.avatar.setTopTextColor(player.getBufferTimeLeft() > 0 ? Color.GREEN : null);
this.timerLabel
.setForeground(player.getBufferTimeLeft() > 0 ? Color.GREEN.darker().darker() : Color.BLACK);
// Set timer text colors (note, if you change it here, change it in init()::timer.setTaskOnTick() as well)
Color textColor = null; // use default in HoverButton
Color foregroundColor = Color.BLACK;
if (player.getBufferTimeLeft() > 0) {
textColor = Color.GREEN;
foregroundColor = Color.GREEN.darker().darker();
} else if (player.getPriorityTimeLeft() < 300) { // visual indication for under 5 minutes
textColor = Color.RED;
foregroundColor = Color.RED.darker().darker();
}
this.avatar.setTopTextColor(textColor);
this.timerLabel.setForeground(foregroundColor);
}
if (player.isTimerActive()) {
this.timer.resume();
Expand Down Expand Up @@ -360,25 +376,17 @@ private void setDeadBackgroundColor() {
private void updateAvatar() {
if (flagName == null) { // do only once
avatar.setText(this.player.getName());
if (!player.getUserData().getFlagName().equals(flagName)) {
flagName = player.getUserData().getFlagName();
this.avatar.setTopTextImage(CountryUtil.getCountryFlagIconSize(flagName, 11).getImage());
}
// TODO: Add the wins to the tooltiptext of the avatar
String countryname = CountryUtil.getCountryName(flagName);
if (countryname == null) {
countryname = "Unknown";
}
flagName = player.getUserData().getFlagName();
this.avatar.setTopTextImage(CountryUtil.getCountryFlagIconSize(flagName, 11).getImage());
String countryName = CountryUtil.getCountryName(flagName);
basicTooltipText = "<HTML>Name: " + player.getName()
+ "<br/>Flag: " + countryname
+ "<br/>Constructed rating: " + player.getUserData().getConstructedRating()
+ "<br/>Limited rating: " + player.getUserData().getLimitedRating()
+ "<br/>Flag: " + (countryName == null ? "Unknown" : countryName)
+ "<br/>Deck hash code: " + player.getDeckHashCode()
+ "<br/>This match wins: " + player.getWins() + " of " + player.getWinsNeeded() + " (to win the match)"
+ (player.getUserData() == null ? "" : "<br/>History: " + player.getUserData().getHistory());
+ "<br/>This match wins: " + player.getWins() + " of " + player.getWinsNeeded() + " (to win the match)";
}
// Extend tooltip
StringBuilder tooltipText = new StringBuilder(basicTooltipText);
tooltipText.append("<br/>Match time remaining: ").append(getPriorityTimeLeftString(player));
this.avatar.setTopTextImageRight(null);
for (String name : player.getDesignationNames()) {
tooltipText.append("<br/>").append(name);
Expand Down

0 comments on commit 4883679

Please sign in to comment.