Enable ProgressBarComponents and the opponentinfo plugin to show both value and percentage in label (#144)
This commit is contained in:
@@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public enum HitpointsDisplayStyle
|
||||||
|
{
|
||||||
|
HITPOINTS("Hitpoints"),
|
||||||
|
PERCENTAGE("Percentage"),
|
||||||
|
BOTH("Both");
|
||||||
|
|
||||||
|
private final String name;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -43,14 +43,14 @@ public interface OpponentInfoConfig extends Config
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ConfigItem(
|
@ConfigItem(
|
||||||
keyName = "showPercent",
|
keyName = "hitpointsDisplayStyle",
|
||||||
name = "Show percent",
|
name = "Hitpoints display style",
|
||||||
description = "Shows hitpoints as a percentage even if hitpoints are known",
|
description = "Show opponent's hitpoints as a value (if known), percentage, or both",
|
||||||
position = 1
|
position = 1
|
||||||
)
|
)
|
||||||
default boolean showPercent()
|
default HitpointsDisplayStyle hitpointsDisplayStyle()
|
||||||
{
|
{
|
||||||
return false;
|
return HitpointsDisplayStyle.HITPOINTS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ConfigItem(
|
@ConfigItem(
|
||||||
|
|||||||
@@ -164,7 +164,10 @@ class OpponentInfoOverlay extends Overlay
|
|||||||
progressBarComponent.setBackgroundColor(HP_RED);
|
progressBarComponent.setBackgroundColor(HP_RED);
|
||||||
progressBarComponent.setForegroundColor(HP_GREEN);
|
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
|
// 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)
|
// 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
|
// so we know nothing about the upper limit except that it can't be higher than maxHealth
|
||||||
maxHealth = lastMaxHealth;
|
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;
|
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.setMaximum(lastMaxHealth);
|
||||||
progressBarComponent.setValue(health);
|
progressBarComponent.setValue(health);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,8 @@ public class ProgressBarComponent implements LayoutableRenderableEntity
|
|||||||
public enum LabelDisplayMode
|
public enum LabelDisplayMode
|
||||||
{
|
{
|
||||||
PERCENTAGE,
|
PERCENTAGE,
|
||||||
FULL
|
FULL,
|
||||||
|
BOTH
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("0.0");
|
private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("0.0");
|
||||||
@@ -77,6 +78,10 @@ public class ProgressBarComponent implements LayoutableRenderableEntity
|
|||||||
case PERCENTAGE:
|
case PERCENTAGE:
|
||||||
textToWrite = DECIMAL_FORMAT.format(pc * 100d) + "%";
|
textToWrite = DECIMAL_FORMAT.format(pc * 100d) + "%";
|
||||||
break;
|
break;
|
||||||
|
case BOTH:
|
||||||
|
textToWrite = DECIMAL_FORMAT_ABS.format(Math.floor(currentValue)) + "/" + maximum
|
||||||
|
+ " (" + DECIMAL_FORMAT.format(pc * 100d) + "%)";
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
textToWrite = DECIMAL_FORMAT_ABS.format(Math.floor(currentValue)) + "/" + maximum;
|
textToWrite = DECIMAL_FORMAT_ABS.format(Math.floor(currentValue)) + "/" + maximum;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user