00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 package com.realtime.crossfire.jxclient.gui.label;
00023
00024 import com.realtime.crossfire.jxclient.gui.gui.GUIElementListener;
00025 import com.realtime.crossfire.jxclient.gui.gui.TooltipManager;
00026 import com.realtime.crossfire.jxclient.stats.Stats;
00027 import com.realtime.crossfire.jxclient.stats.StatsListener;
00028 import java.awt.Color;
00029 import java.awt.Font;
00030 import org.jetbrains.annotations.NotNull;
00031 import org.jetbrains.annotations.Nullable;
00032
00039 public class GUILabelStats2 extends GUIOneLineLabel {
00040
00044 private static final long serialVersionUID = 1;
00045
00049 @NotNull
00050 private final Color colorUpgradable;
00051
00055 @NotNull
00056 private final Color colorDepleted;
00057
00061 @NotNull
00062 private final Color colorBoosted;
00063
00067 @NotNull
00068 private final Color colorBoostedUpgradable;
00069
00073 private final int statCurrent;
00074
00078 private final int statBase;
00079
00083 private final int statRace;
00084
00088 private final int statApplied;
00089
00093 @NotNull
00094 private final Stats stats;
00095
00099 @NotNull
00100 private Color color;
00101
00105 @NotNull
00106 private final StatsListener statsListener = new StatsListener() {
00107
00108 @Override
00109 public void reset() {
00110
00111 }
00112
00113 @Override
00114 public void statChanged(final int statNo, final int value) {
00115 if (statNo == statCurrent || statNo == statBase || statNo == statRace || statNo == statApplied) {
00116 updateStat();
00117 }
00118 }
00119
00120 @Override
00121 public void simpleWeaponSpeedChanged(final boolean simpleWeaponSpeed) {
00122
00123 }
00124
00125 @Override
00126 public void titleChanged(@NotNull final String title) {
00127
00128 }
00129
00130 @Override
00131 public void rangeChanged(@NotNull final String range) {
00132
00133 }
00134
00135 @Override
00136 public void activeSkillChanged(@NotNull final String activeSkill) {
00137
00138 }
00139
00140 @Override
00141 public void experienceChanged(final long exp) {
00142
00143 }
00144
00145 @Override
00146 public void experienceNextLevelChanged(final long expNextLevel) {
00147
00148 }
00149
00150 };
00151
00171 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) {
00172 super(tooltipManager, elementListener, name, null, font, colorNormal, backgroundColor, alignment, "");
00173 this.colorUpgradable = colorUpgradable;
00174 this.colorDepleted = colorDepleted;
00175 this.colorBoosted = colorBoosted;
00176 this.colorBoostedUpgradable = colorBoostedUpgradable;
00177 this.statCurrent = statCurrent;
00178 this.statBase = statBase;
00179 this.statRace = statRace;
00180 this.statApplied = statApplied;
00181 this.stats = stats;
00182 this.stats.addCrossfireStatsListener(statsListener);
00183 color = colorNormal;
00184 updateStat();
00185 }
00186
00190 private void updateStat() {
00191 final int baseValue = stats.getStat(statBase);
00192 final int raceValue = stats.getStat(statRace);
00193 final int appliedValue = stats.getStat(statApplied);
00194 final int currValue = stats.getStat(statCurrent);
00195 final int currValueWithoutGear = currValue-appliedValue;
00196 if (baseValue == 0 && raceValue == 0) {
00197
00198 color = GUILabelStats2.super.getTextColor();
00199 setText(String.valueOf(currValue));
00200 setTooltipText("Current: "+currValue);
00201 return;
00202 }
00203
00204 final Color newColor;
00205 if (currValueWithoutGear < baseValue) {
00206 newColor = colorDepleted;
00207 } else if (currValueWithoutGear == baseValue) {
00208 if (baseValue < raceValue) {
00209 newColor = colorUpgradable;
00210 } else {
00211 newColor = GUILabelStats2.super.getTextColor();
00212 }
00213 } else {
00214 if (baseValue < raceValue) {
00215 newColor = colorBoostedUpgradable;
00216 } else {
00217 newColor = colorBoosted;
00218 }
00219 }
00220 if (color != newColor) {
00221 color = newColor;
00222 setChanged();
00223 }
00224 setText(String.valueOf(currValue));
00225
00226 final StringBuilder sb = new StringBuilder();
00227 sb.append("<html>Current: ").append(currValue);
00228 if (currValueWithoutGear < baseValue) {
00229 sb.append("<br>Depleted by ").append(baseValue-currValueWithoutGear).append(" from ").append(baseValue).append(".");
00230 } else if (currValueWithoutGear > baseValue) {
00231 sb.append("<br>Increased by ").append(currValueWithoutGear-baseValue).append(" from ").append(baseValue).append(".");
00232 }
00233 if (appliedValue > 0) {
00234 sb.append("<br>Boosted by ").append(appliedValue).append(" by gear or skills.");
00235 } else if (appliedValue < 0) {
00236 sb.append("<br>Reduced by ").append(-appliedValue).append(" by gear or skills.");
00237 }
00238 if (baseValue < raceValue) {
00239 sb.append("<br>Upgradable to ").append(raceValue).append(" by drinking stat potions.");
00240 }
00241 setTooltipText(sb.toString());
00242 }
00243
00247 @Override
00248 public void dispose() {
00249 super.dispose();
00250 stats.removeCrossfireStatsListener(statsListener);
00251 }
00252
00256 @NotNull
00257 @Override
00258 protected Color getTextColor() {
00259 return color;
00260 }
00261
00262 }