opponentinfo: add option to show both hp value and percent
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) 2019, Sean Dewar <https://github.com/seandewar>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.runelite.client.plugins.opponentinfo;
|
||||
|
||||
public enum HitpointsDisplayStyle
|
||||
{
|
||||
HITPOINTS,
|
||||
PERCENTAGE,
|
||||
BOTH;
|
||||
}
|
||||
@@ -43,14 +43,14 @@ public interface OpponentInfoConfig extends Config
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
keyName = "showPercent",
|
||||
name = "Show percent",
|
||||
description = "Shows hitpoints as a percentage even if hitpoints are known",
|
||||
keyName = "hitpointsDisplayStyle",
|
||||
name = "Hitpoints display style",
|
||||
description = "Show opponent's hitpoints as a value (if known), percentage, or both",
|
||||
position = 1
|
||||
)
|
||||
default boolean showPercent()
|
||||
default HitpointsDisplayStyle hitpointsDisplayStyle()
|
||||
{
|
||||
return false;
|
||||
return HitpointsDisplayStyle.HITPOINTS;
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
|
||||
@@ -164,7 +164,10 @@ class OpponentInfoOverlay extends Overlay
|
||||
progressBarComponent.setBackgroundColor(HP_RED);
|
||||
progressBarComponent.setForegroundColor(HP_GREEN);
|
||||
|
||||
if (lastMaxHealth != null && !opponentInfoConfig.showPercent())
|
||||
final HitpointsDisplayStyle displayStyle = opponentInfoConfig.hitpointsDisplayStyle();
|
||||
|
||||
if ((displayStyle == HitpointsDisplayStyle.HITPOINTS || displayStyle == HitpointsDisplayStyle.BOTH)
|
||||
&& lastMaxHealth != null)
|
||||
{
|
||||
// This is the reverse of the calculation of healthRatio done by the server
|
||||
// which is: healthRatio = 1 + (healthScale - 1) * health / maxHealth (if health > 0, 0 otherwise)
|
||||
@@ -194,11 +197,15 @@ class OpponentInfoOverlay extends Overlay
|
||||
// so we know nothing about the upper limit except that it can't be higher than maxHealth
|
||||
maxHealth = lastMaxHealth;
|
||||
}
|
||||
// Take the average of min and max possible healts
|
||||
// Take the average of min and max possible healths
|
||||
health = (minHealth + maxHealth + 1) / 2;
|
||||
}
|
||||
|
||||
progressBarComponent.setLabelDisplayMode(ProgressBarComponent.LabelDisplayMode.FULL);
|
||||
// Show both the hitpoint and percentage values if enabled in the config
|
||||
final ProgressBarComponent.LabelDisplayMode progressBarDisplayMode = displayStyle == HitpointsDisplayStyle.BOTH ?
|
||||
ProgressBarComponent.LabelDisplayMode.BOTH : ProgressBarComponent.LabelDisplayMode.FULL;
|
||||
|
||||
progressBarComponent.setLabelDisplayMode(progressBarDisplayMode);
|
||||
progressBarComponent.setMaximum(lastMaxHealth);
|
||||
progressBarComponent.setValue(health);
|
||||
}
|
||||
|
||||
@@ -40,7 +40,8 @@ public class ProgressBarComponent implements LayoutableRenderableEntity
|
||||
public enum LabelDisplayMode
|
||||
{
|
||||
PERCENTAGE,
|
||||
FULL
|
||||
FULL,
|
||||
BOTH
|
||||
}
|
||||
|
||||
private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("0.0");
|
||||
@@ -79,10 +80,13 @@ public class ProgressBarComponent implements LayoutableRenderableEntity
|
||||
switch (labelDisplayMode)
|
||||
{
|
||||
case PERCENTAGE:
|
||||
textToWrite = DECIMAL_FORMAT.format(pc * 100d) + "%";
|
||||
textToWrite = formatPercentageProgress(pc);
|
||||
break;
|
||||
case BOTH:
|
||||
textToWrite = formatFullProgress(currentValue, maximum) + " (" + formatPercentageProgress(pc) + ")";
|
||||
break;
|
||||
default:
|
||||
textToWrite = DECIMAL_FORMAT_ABS.format(Math.floor(currentValue)) + "/" + maximum;
|
||||
textToWrite = formatFullProgress(currentValue, maximum);
|
||||
}
|
||||
|
||||
final int width = preferredSize.width;
|
||||
@@ -126,4 +130,14 @@ public class ProgressBarComponent implements LayoutableRenderableEntity
|
||||
bounds.setSize(dimension);
|
||||
return dimension;
|
||||
}
|
||||
|
||||
private static String formatFullProgress(double current, long maximum)
|
||||
{
|
||||
return DECIMAL_FORMAT_ABS.format(Math.floor(current)) + "/" + maximum;
|
||||
}
|
||||
|
||||
private static String formatPercentageProgress(double ratio)
|
||||
{
|
||||
return DECIMAL_FORMAT.format(ratio * 100d) + "%";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user