Crossfire JXClient, Trunk
GUILabelStats2.java
Go to the documentation of this file.
1 /*
2  * This file is part of JXClient, the Fullscreen Java Crossfire Client.
3  *
4  * JXClient is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * JXClient is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with JXClient; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  *
18  * Copyright (C) 2005-2008 Yann Chachkoff
19  * Copyright (C) 2006-2017,2019-2023 Andreas Kirschbaum
20  * Copyright (C) 2010-2012,2014-2018,2020-2023 Nicolas Weeger
21  */
22 
23 package com.realtime.crossfire.jxclient.gui.label;
24 
31 import java.awt.Color;
32 import java.awt.Font;
33 import org.jetbrains.annotations.NotNull;
34 import org.jetbrains.annotations.Nullable;
35 
42 public class GUILabelStats2 extends GUIOneLineLabel {
43 
47  private static final long serialVersionUID = 1;
48 
52  @NotNull
53  private final Color colorUpgradable;
54 
58  @NotNull
59  private final Color colorDepleted;
60 
64  @NotNull
65  private final Color colorBoosted;
66 
70  @NotNull
71  private final Color colorBoostedUpgradable;
72 
76  private final int statCurrent;
77 
81  private final int statBase;
82 
86  private final int statRace;
87 
91  private final int statApplied;
92 
96  @NotNull
97  private final Stats stats;
98 
102  @NotNull
103  private Color color;
104 
108  @NotNull
109  private final StatsListener statsListener = new StatsListener() {
110 
111  @Override
112  public void resetBefore() {
113  // ignore
114  }
115 
116  @Override
117  public void resetAfter() {
118  // ignore
119  }
120 
121  @Override
122  public void statChanged(final int statNo, final int value) {
123  if (statNo == statCurrent || statNo == statBase || statNo == statRace || statNo == statApplied) {
124  updateStat();
125  tooltipChanged();
126  }
127  }
128 
129  @Override
130  public void simpleWeaponSpeedChanged(final boolean simpleWeaponSpeed) {
131  // ignore
132  }
133 
134  @Override
135  public void titleChanged(@NotNull final String title) {
136  // ignore
137  }
138 
139  @Override
140  public void godNameChanged(@NotNull final String godName) {
141  // ignore
142  }
143 
144  @Override
145  public void rangeChanged(@NotNull final String range) {
146  // ignore
147  }
148 
149  @Override
150  public void activeSkillChanged(@NotNull final String activeSkill) {
151  // ignore
152  }
153 
154  @Override
155  public void experienceChanged(final long exp) {
156  // ignore
157  }
158 
159  @Override
160  public void experienceNextLevelChanged(final long expNextLevel) {
161  // ignore
162  }
163 
164  };
165 
186  public GUILabelStats2(@NotNull final TooltipManager tooltipManager, @NotNull final GUIElementListener elementListener, @NotNull final String name, @NotNull final Font font, @NotNull final Color colorNormal, @NotNull final Color colorUpgradable, @NotNull final Color colorDepleted, @NotNull final Color colorBoosted, @NotNull final Color colorBoostedUpgradable, @Nullable final Color backgroundColor, final int statCurrent, final int statBase, final int statRace, final int statApplied, @NotNull final Alignment alignment, @NotNull final Stats stats, @NotNull final GuiFactory guiFactory) {
187  super(tooltipManager, elementListener, name, null, font, colorNormal, colorNormal, backgroundColor, alignment, "", guiFactory);
188  this.colorUpgradable = colorUpgradable;
189  this.colorDepleted = colorDepleted;
190  this.colorBoosted = colorBoosted;
191  this.colorBoostedUpgradable = colorBoostedUpgradable;
192  this.statCurrent = statCurrent;
193  this.statBase = statBase;
194  this.statRace = statRace;
195  this.statApplied = statApplied;
196  this.stats = stats;
198  color = colorNormal;
199  updateStat();
200  }
201 
205  private void updateStat() {
206  final int baseValue = stats.getStat(statBase);
207  final int raceValue = stats.getStat(statRace);
208  final int currValue = stats.getStat(statCurrent);
209  if (baseValue == 0 && raceValue == 0) {
210  // no server support
211  color = super.getTextColor();
212  setText(String.valueOf(currValue));
213  return;
214  }
215 
216  final int appliedValue = stats.getStat(statApplied);
217  final int currValueWithoutGear = currValue-appliedValue;
218  final Color newColor;
219  if (currValueWithoutGear < baseValue) {
220  newColor = colorDepleted;
221  } else if (currValueWithoutGear == baseValue) {
222  newColor = baseValue < raceValue ? colorUpgradable : super.getTextColor();
223  } else {
224  newColor = baseValue < raceValue ? colorBoostedUpgradable : colorBoosted;
225  }
226  if (color != newColor) {
227  color = newColor;
228  setChanged();
229  }
230  setText(String.valueOf(currValue));
231  }
232 
233  @Override
234  public void dispose() {
235  super.dispose();
237  }
238 
239  @NotNull
240  @Override
241  @SuppressWarnings("MethodDoesntCallSuperMethod")
242  protected Color getTextColor() {
243  return color;
244  }
245 
246  @Nullable
247  @Override
248  @SuppressWarnings("MethodDoesntCallSuperMethod")
250  final int baseValue = stats.getStat(statBase);
251  final int raceValue = stats.getStat(statRace);
252  final int currValue = stats.getStat(statCurrent);
253  if (baseValue == 0 && raceValue == 0) {
254  return newTooltipText("Current: "+currValue);
255  }
256 
257  final StringBuilder sb = new StringBuilder();
258  sb.append("<html>Current: ").append(currValue);
259  final int appliedValue = stats.getStat(statApplied);
260  final int currValueWithoutGear = currValue-appliedValue;
261  if (currValueWithoutGear < baseValue) {
262  sb.append("<br>Depleted by ").append(baseValue-currValueWithoutGear).append(" from ").append(baseValue).append(".");
263  } else if (currValueWithoutGear > baseValue) {
264  sb.append("<br>Increased by ").append(currValueWithoutGear-baseValue).append(" from ").append(baseValue).append(".");
265  }
266  if (appliedValue > 0) {
267  sb.append("<br>Boosted by ").append(appliedValue).append(" by gear or skills.");
268  } else if (appliedValue < 0) {
269  sb.append("<br>Reduced by ").append(-appliedValue).append(" by gear or skills.");
270  }
271  if (baseValue < raceValue) {
272  sb.append("<br>Upgradable to ").append(raceValue).append(" by drinking stat potions.");
273  }
274  return newTooltipText(sb.toString());
275  }
276 
277 }
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.newTooltipText
TooltipText newTooltipText(@Nullable final String tooltipText)
Definition: AbstractGUIElement.java:247
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.name
final String name
Definition: AbstractGUIElement.java:77
com.realtime.crossfire.jxclient
com.realtime.crossfire.jxclient.skin.skin
Definition: DefaultJXCSkin.java:23
com.realtime.crossfire.jxclient.skin
com.realtime.crossfire.jxclient.gui.label.GUILabelStats2.getTooltip
TooltipText getTooltip()
Definition: GUILabelStats2.java:249
com.realtime.crossfire.jxclient.gui.label.GUILabelStats2.GUILabelStats2
GUILabelStats2(@NotNull final TooltipManager tooltipManager, @NotNull final GUIElementListener elementListener, @NotNull final String name, @NotNull final Font font, @NotNull final Color colorNormal, @NotNull final Color colorUpgradable, @NotNull final Color colorDepleted, @NotNull final Color colorBoosted, @NotNull final Color colorBoostedUpgradable, @Nullable final Color backgroundColor, final int statCurrent, final int statBase, final int statRace, final int statApplied, @NotNull final Alignment alignment, @NotNull final Stats stats, @NotNull final GuiFactory guiFactory)
Definition: GUILabelStats2.java:186
com.realtime.crossfire.jxclient.skin.skin.GuiFactory
Definition: GuiFactory.java:41
com.realtime.crossfire.jxclient.gui.label.GUILabelStats2.dispose
void dispose()
Definition: GUILabelStats2.java:234
com.realtime.crossfire.jxclient.stats.Stats
Definition: Stats.java:44
com.realtime.crossfire.jxclient.gui.label.Alignment
Definition: Alignment.java:29
com.realtime.crossfire.jxclient.gui.label.GUILabelStats2
Definition: GUILabelStats2.java:42
com.realtime.crossfire.jxclient.gui.label.GUILabelStats2.color
Color color
Definition: GUILabelStats2.java:103
com.realtime.crossfire.jxclient.stats.StatsListener
Definition: StatsListener.java:32
com.realtime.crossfire.jxclient.gui.label.GUILabelStats2.colorBoostedUpgradable
final Color colorBoostedUpgradable
Definition: GUILabelStats2.java:71
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.tooltipChanged
void tooltipChanged()
Definition: AbstractGUIElement.java:265
com.realtime.crossfire.jxclient.gui.label.GUILabelStats2.colorBoosted
final Color colorBoosted
Definition: GUILabelStats2.java:65
com.realtime.crossfire.jxclient.gui.label.GUILabelStats2.colorDepleted
final Color colorDepleted
Definition: GUILabelStats2.java:59
com.realtime.crossfire.jxclient.stats.Stats.getStat
int getStat(final int statNo)
Definition: Stats.java:771
com.realtime.crossfire.jxclient.gui.label.GUILabelStats2.statCurrent
final int statCurrent
Definition: GUILabelStats2.java:76
com.realtime.crossfire.jxclient.gui.label.AbstractLabel.backgroundColor
final Color backgroundColor
Definition: AbstractLabel.java:85
com.realtime.crossfire.jxclient.gui.label.GUILabelStats2.getTextColor
Color getTextColor()
Definition: GUILabelStats2.java:242
com.realtime.crossfire.jxclient.gui
com.realtime.crossfire.jxclient.gui.label.GUILabelStats2.statApplied
final int statApplied
Definition: GUILabelStats2.java:91
com.realtime.crossfire.jxclient.stats.Stats.addCrossfireStatsListener
void addCrossfireStatsListener(@NotNull final StatsListener statsListener)
Definition: Stats.java:963
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.elementListener
final GUIElementListener elementListener
Definition: AbstractGUIElement.java:89
com.realtime.crossfire.jxclient.gui.gui.TooltipManager
Definition: TooltipManager.java:33
com.realtime.crossfire.jxclient.gui.gui
Definition: AbstractGUIElement.java:23
com.realtime.crossfire.jxclient.gui.label.GUILabelStats2.updateStat
void updateStat()
Definition: GUILabelStats2.java:205
com.realtime.crossfire.jxclient.gui.label.AbstractLabel.setText
void setText(@NotNull final String text)
Definition: AbstractLabel.java:120
com.realtime.crossfire.jxclient.gui.gui.TooltipText
Definition: TooltipText.java:31
com.realtime.crossfire
com.realtime
com
com.realtime.crossfire.jxclient.stats.Stats.removeCrossfireStatsListener
void removeCrossfireStatsListener(@NotNull final StatsListener statsListener)
Definition: Stats.java:971
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.setChanged
void setChanged()
Definition: AbstractGUIElement.java:223
com.realtime.crossfire.jxclient.gui.label.GUILabelStats2.statBase
final int statBase
Definition: GUILabelStats2.java:81
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.guiFactory
final GuiFactory guiFactory
Definition: AbstractGUIElement.java:48
com.realtime.crossfire.jxclient.gui.label.GUILabelStats2.statRace
final int statRace
Definition: GUILabelStats2.java:86
com.realtime.crossfire.jxclient.gui.label.GUILabelStats2.stats
final Stats stats
Definition: GUILabelStats2.java:97
com.realtime.crossfire.jxclient.gui.label.GUILabelStats2.colorUpgradable
final Color colorUpgradable
Definition: GUILabelStats2.java:53
com.realtime.crossfire.jxclient.gui.label.GUILabelStats2.serialVersionUID
static final long serialVersionUID
Definition: GUILabelStats2.java:47
com.realtime.crossfire.jxclient.gui.label.GUIOneLineLabel
Definition: GUIOneLineLabel.java:43
com.realtime.crossfire.jxclient.gui.gui.GUIElementListener
Definition: GUIElementListener.java:32
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.tooltipManager
final TooltipManager tooltipManager
Definition: AbstractGUIElement.java:83
com.realtime.crossfire.jxclient.gui.label.GUILabelStats2.statsListener
final StatsListener statsListener
Definition: GUILabelStats2.java:109
com.realtime.crossfire.jxclient.stats
Definition: ActiveSkillWatcher.java:23