xpdrop plugin: use script events instead of widget hidden
This also uses the default color enum to assign default xpdrop colors instead of using our hardcoded enum.
This commit is contained in:
@@ -33,4 +33,5 @@ public final class EnumID
|
||||
{
|
||||
public static final int MUSIC_TRACK_NAMES = 812;
|
||||
public static final int MUSIC_TRACK_IDS = 819;
|
||||
public static final int XPDROP_COLORS = 1169;
|
||||
}
|
||||
|
||||
@@ -275,4 +275,13 @@ public final class ScriptID
|
||||
*/
|
||||
@ScriptArguments(integer = 2)
|
||||
public static final int TOPLEVEL_REDRAW = 907;
|
||||
|
||||
/**
|
||||
* Called to set position of an xpdrop text and sprite(s)
|
||||
* <ul>
|
||||
* <li> XP drop parent component </li>
|
||||
* </ul>
|
||||
*/
|
||||
@ScriptArguments(integer = 4, string = 1)
|
||||
public static final int XPDROPS_SETDROPSIZE = 996;
|
||||
}
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Cameron <https://github.com/noremac201>
|
||||
* 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.experiencedrop;
|
||||
|
||||
import java.awt.Color;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@AllArgsConstructor
|
||||
enum DefaultColors
|
||||
{
|
||||
WHITE(new Color(0xFF, 0xFF, 0xFF)),
|
||||
LILAC(new Color(0xC8, 0xC8, 0xFF)),
|
||||
CYAN(new Color(0x00, 0xFF, 0xFF)),
|
||||
JADE(new Color(0xC8, 0xFF, 0xC8)),
|
||||
LIME(new Color(0x64, 0xFF, 0x64)),
|
||||
YELLOW(new Color(0xFF, 0xFF, 0x40)),
|
||||
ORANGE(new Color(0xFF, 0x98, 0x1F)),
|
||||
PINK(new Color(0xFF, 0xC8, 0xC8));
|
||||
|
||||
@Getter
|
||||
private final Color color;
|
||||
}
|
||||
@@ -31,16 +31,19 @@ import java.util.Map;
|
||||
import java.util.stream.IntStream;
|
||||
import javax.inject.Inject;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.EnumComposition;
|
||||
import net.runelite.api.EnumID;
|
||||
import static net.runelite.api.ScriptID.XPDROPS_SETDROPSIZE;
|
||||
import static net.runelite.api.ScriptID.XPDROP_DISABLED;
|
||||
import net.runelite.api.Skill;
|
||||
import net.runelite.api.SpriteID;
|
||||
import net.runelite.api.Varbits;
|
||||
import net.runelite.api.events.GameTick;
|
||||
import net.runelite.api.events.ScriptPreFired;
|
||||
import net.runelite.api.events.StatChanged;
|
||||
import net.runelite.api.events.WidgetHiddenChanged;
|
||||
import net.runelite.api.widgets.Widget;
|
||||
import net.runelite.api.widgets.WidgetID;
|
||||
import net.runelite.api.widgets.WidgetInfo;
|
||||
import static net.runelite.api.widgets.WidgetInfo.TO_CHILD;
|
||||
import static net.runelite.api.widgets.WidgetInfo.TO_GROUP;
|
||||
import net.runelite.client.config.ConfigManager;
|
||||
import net.runelite.client.eventbus.Subscribe;
|
||||
import net.runelite.client.plugins.Plugin;
|
||||
@@ -49,12 +52,10 @@ import net.runelite.client.plugins.PluginDescriptor;
|
||||
@PluginDescriptor(
|
||||
name = "XP Drop",
|
||||
description = "Enable customization of the way XP drops are displayed",
|
||||
tags = {"experience", "levels", "tick", "prayer"}
|
||||
tags = {"experience", "levels", "tick", "prayer", "xpdrop"}
|
||||
)
|
||||
public class XpDropPlugin extends Plugin
|
||||
{
|
||||
private static final int XPDROP_PADDING = 2; // space between xp drop icons
|
||||
|
||||
@Inject
|
||||
private Client client;
|
||||
|
||||
@@ -76,116 +77,81 @@ public class XpDropPlugin extends Plugin
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onWidgetHiddenChanged(WidgetHiddenChanged event)
|
||||
public void onScriptPreFired(ScriptPreFired scriptPreFired)
|
||||
{
|
||||
Widget widget = event.getWidget();
|
||||
|
||||
int group = WidgetInfo.TO_GROUP(widget.getId());
|
||||
|
||||
if (group != WidgetID.EXPERIENCE_DROP_GROUP_ID)
|
||||
if (scriptPreFired.getScriptId() == XPDROPS_SETDROPSIZE)
|
||||
{
|
||||
return;
|
||||
final int[] intStack = client.getIntStack();
|
||||
final int intStackSize = client.getIntStackSize();
|
||||
// This runs prior to the proc being invoked, so the arguments are still on the stack.
|
||||
// Grab the first argument to the script.
|
||||
final int widgetId = intStack[intStackSize - 4];
|
||||
processXpDrop(widgetId);
|
||||
}
|
||||
}
|
||||
|
||||
if (widget.isHidden())
|
||||
{
|
||||
return;
|
||||
}
|
||||
private void processXpDrop(int widgetId)
|
||||
{
|
||||
final Widget xpdrop = client.getWidget(TO_GROUP(widgetId), TO_CHILD(widgetId));
|
||||
final Widget[] children = xpdrop.getDynamicChildren();
|
||||
// child 0 is the xpdrop text, everything else are sprite ids for skills
|
||||
final Widget text = children[0];
|
||||
|
||||
if (config.hideSkillIcons())
|
||||
{
|
||||
if (widget.getSpriteId() > 0)
|
||||
{
|
||||
widget.setHidden(true);
|
||||
return;
|
||||
}
|
||||
else if (!widget.getText().isEmpty())
|
||||
{
|
||||
// Align text accordingly to take up hidden skill icon space
|
||||
int width = 0;
|
||||
for (Widget w : widget.getParent().getDynamicChildren())
|
||||
{
|
||||
if (w.getSpriteId() != -1)
|
||||
{
|
||||
if (width > 0)
|
||||
{
|
||||
// Add in space between sprites
|
||||
width += XPDROP_PADDING;
|
||||
}
|
||||
width += w.getWidth(); // width of sprite
|
||||
}
|
||||
}
|
||||
|
||||
final int xpDropPosition = client.getVar(Varbits.EXPERIENCE_TRACKER_POSITION);
|
||||
switch (xpDropPosition)
|
||||
{
|
||||
case 2: // left
|
||||
int cur = widget.getRelativeX();
|
||||
cur -= width;
|
||||
widget.setRelativeX(cur);
|
||||
break;
|
||||
case 0: // right
|
||||
break;
|
||||
case 1: // center
|
||||
cur = widget.getRelativeX();
|
||||
cur -= width / 2;
|
||||
widget.setRelativeX(cur);
|
||||
break;
|
||||
}
|
||||
}
|
||||
// keep only text
|
||||
xpdrop.setChildren(Arrays.copyOf(children, 1));
|
||||
}
|
||||
|
||||
PrayerType prayer = currentTickPrayer;
|
||||
if (prayer == null)
|
||||
{
|
||||
resetTextColor(widget);
|
||||
resetTextColor(text);
|
||||
return;
|
||||
}
|
||||
|
||||
String text = widget.getText();
|
||||
final IntStream spriteIDs =
|
||||
Arrays.stream(widget.getParent().getDynamicChildren()).mapToInt(Widget::getSpriteId);
|
||||
Arrays.stream(children)
|
||||
.skip(1) // skip text
|
||||
.mapToInt(Widget::getSpriteId);
|
||||
|
||||
if (text != null)
|
||||
int color = text.getTextColor();
|
||||
|
||||
switch (prayer)
|
||||
{
|
||||
int color = widget.getTextColor();
|
||||
|
||||
switch (prayer)
|
||||
{
|
||||
case MELEE:
|
||||
if (spriteIDs.anyMatch(id ->
|
||||
id == SpriteID.SKILL_ATTACK || id == SpriteID.SKILL_STRENGTH || id == SpriteID.SKILL_DEFENCE
|
||||
|| correctPrayer))
|
||||
{
|
||||
color = config.getMeleePrayerColor().getRGB();
|
||||
correctPrayer = true;
|
||||
}
|
||||
break;
|
||||
case RANGE:
|
||||
if (spriteIDs.anyMatch(id -> id == SpriteID.SKILL_RANGED || correctPrayer))
|
||||
{
|
||||
color = config.getRangePrayerColor().getRGB();
|
||||
correctPrayer = true;
|
||||
}
|
||||
break;
|
||||
case MAGIC:
|
||||
if (spriteIDs.anyMatch(id -> id == SpriteID.SKILL_MAGIC || correctPrayer))
|
||||
{
|
||||
color = config.getMagePrayerColor().getRGB();
|
||||
correctPrayer = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
widget.setTextColor(color);
|
||||
case MELEE:
|
||||
if (correctPrayer || spriteIDs.anyMatch(id ->
|
||||
id == SpriteID.SKILL_ATTACK || id == SpriteID.SKILL_STRENGTH || id == SpriteID.SKILL_DEFENCE))
|
||||
{
|
||||
color = config.getMeleePrayerColor().getRGB();
|
||||
correctPrayer = true;
|
||||
}
|
||||
break;
|
||||
case RANGE:
|
||||
if (correctPrayer || spriteIDs.anyMatch(id -> id == SpriteID.SKILL_RANGED))
|
||||
{
|
||||
color = config.getRangePrayerColor().getRGB();
|
||||
correctPrayer = true;
|
||||
}
|
||||
break;
|
||||
case MAGIC:
|
||||
if (correctPrayer || spriteIDs.anyMatch(id -> id == SpriteID.SKILL_MAGIC))
|
||||
{
|
||||
color = config.getMagePrayerColor().getRGB();
|
||||
correctPrayer = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
text.setTextColor(color);
|
||||
}
|
||||
|
||||
private void resetTextColor(Widget widget)
|
||||
{
|
||||
int defaultColorIdx = client.getVar(Varbits.EXPERIENCE_DROP_COLOR);
|
||||
int defaultColor = DefaultColors.values()[defaultColorIdx].getColor().getRGB();
|
||||
widget.setTextColor(defaultColor);
|
||||
EnumComposition colorEnum = client.getEnum(EnumID.XPDROP_COLORS);
|
||||
int defaultColorId = client.getVar(Varbits.EXPERIENCE_DROP_COLOR);
|
||||
int color = colorEnum.getIntValue(defaultColorId);
|
||||
widget.setTextColor(color);
|
||||
}
|
||||
|
||||
private PrayerType getActivePrayerType()
|
||||
|
||||
Reference in New Issue
Block a user