Crossfire JXClient, Trunk
GaugeUpdater.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.gauge;
24 
26 import org.jetbrains.annotations.NotNull;
27 import org.jetbrains.annotations.Nullable;
28 
33 public abstract class GaugeUpdater {
34 
38  @NotNull
40 
44  @Nullable
46 
50  private final boolean hideIfEmpty;
51 
57  protected GaugeUpdater(@NotNull final ExperienceTable experienceTable, final boolean hideIfEmpty) {
58  this.experienceTable = experienceTable;
59  this.hideIfEmpty = hideIfEmpty;
60  }
61 
65  public abstract void dispose();
66 
71  public void setGauge(@NotNull final GUIGaugeListener gauge) {
72  this.gauge = gauge;
73  // hide the gauge initially, so if it's never updated it doesn't appear
74  if (hideIfEmpty) {
75  gauge.setHidden(true);
76  }
77  }
78 
85  protected void setValues(final int curValue, final int minValue, final int maxValue) {
86  if (gauge != null) {
87  final String curValueString = Integer.toString(curValue);
88  final String tooltipText = minValue == 0 ? curValue+"/"+maxValue : curValueString;
89  assert gauge != null;
90  gauge.setValues(curValue, minValue, maxValue, curValueString, tooltipText);
91  if (hideIfEmpty) {
92  assert gauge != null;
93  gauge.setHidden(curValue == 0 && minValue == 0 && maxValue == 0);
94  }
95  }
96  }
97 
106  protected void setValues(final int curValue, final int minValue, final int maxValue, @NotNull final String labelText, @NotNull final String tooltipText) {
107  if (gauge != null) {
108  gauge.setValues(curValue, minValue, maxValue, labelText, tooltipText);
109  }
110  }
111 
118  protected int getPercentsToNextLevel(final int level, final long experience) {
119  return experienceTable.getPercentsToNextLevel(level, experience);
120  }
121 
128  protected long getExperienceToNextLevel(final int level, final long experience) {
129  return experienceTable.getExperienceToNextLevel(level, experience);
130  }
131 
132 }
com.realtime.crossfire.jxclient.gui.gauge.GaugeUpdater.GaugeUpdater
GaugeUpdater(@NotNull final ExperienceTable experienceTable, final boolean hideIfEmpty)
Definition: GaugeUpdater.java:57
com.realtime.crossfire.jxclient
com.realtime.crossfire.jxclient.gui.gauge.GaugeUpdater.gauge
GUIGaugeListener gauge
Definition: GaugeUpdater.java:45
com.realtime.crossfire.jxclient.stats.ExperienceTable.getExperienceToNextLevel
long getExperienceToNextLevel(final int currentLevel, final long currentExp)
Definition: ExperienceTable.java:118
com.realtime.crossfire.jxclient.gui.gauge.GaugeUpdater
Definition: GaugeUpdater.java:33
com.realtime.crossfire.jxclient.gui.gauge.GaugeUpdater.getPercentsToNextLevel
int getPercentsToNextLevel(final int level, final long experience)
Definition: GaugeUpdater.java:118
com.realtime.crossfire.jxclient.gui.gauge.GUIGaugeListener.setValues
void setValues(int curValue, int minValue, int maxValue, @NotNull String labelText, @NotNull String tooltipText)
com.realtime.crossfire.jxclient.gui.gauge.GUIGaugeListener.setHidden
void setHidden(boolean hidden)
com.realtime.crossfire.jxclient.gui.gauge.GaugeUpdater.setValues
void setValues(final int curValue, final int minValue, final int maxValue, @NotNull final String labelText, @NotNull final String tooltipText)
Definition: GaugeUpdater.java:106
com.realtime.crossfire.jxclient.gui.gauge.GaugeUpdater.hideIfEmpty
final boolean hideIfEmpty
Definition: GaugeUpdater.java:50
com.realtime.crossfire.jxclient.stats.ExperienceTable
Definition: ExperienceTable.java:33
com.realtime.crossfire.jxclient.stats.ExperienceTable.getPercentsToNextLevel
int getPercentsToNextLevel(final int currentLevel, final long currentExp)
Definition: ExperienceTable.java:131
com.realtime.crossfire
com.realtime.crossfire.jxclient.gui.gauge.GaugeUpdater.getExperienceToNextLevel
long getExperienceToNextLevel(final int level, final long experience)
Definition: GaugeUpdater.java:128
com.realtime.crossfire.jxclient.gui.gauge.GaugeUpdater.experienceTable
final ExperienceTable experienceTable
Definition: GaugeUpdater.java:39
com.realtime
com
com.realtime.crossfire.jxclient.gui.gauge.GaugeUpdater.setValues
void setValues(final int curValue, final int minValue, final int maxValue)
Definition: GaugeUpdater.java:85
com.realtime.crossfire.jxclient.gui.gauge.GUIGaugeListener
Definition: GUIGaugeListener.java:31
com.realtime.crossfire.jxclient.gui.gauge.GaugeUpdater.setGauge
void setGauge(@NotNull final GUIGaugeListener gauge)
Definition: GaugeUpdater.java:71
com.realtime.crossfire.jxclient.gui.gauge.GaugeUpdater.dispose
abstract void dispose()
com.realtime.crossfire.jxclient.stats
Definition: ActiveSkillWatcher.java:23