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_NAMES = 812;
|
||||||
public static final int MUSIC_TRACK_IDS = 819;
|
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)
|
@ScriptArguments(integer = 2)
|
||||||
public static final int TOPLEVEL_REDRAW = 907;
|
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 java.util.stream.IntStream;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import net.runelite.api.Client;
|
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 static net.runelite.api.ScriptID.XPDROP_DISABLED;
|
||||||
import net.runelite.api.Skill;
|
import net.runelite.api.Skill;
|
||||||
import net.runelite.api.SpriteID;
|
import net.runelite.api.SpriteID;
|
||||||
import net.runelite.api.Varbits;
|
import net.runelite.api.Varbits;
|
||||||
import net.runelite.api.events.GameTick;
|
import net.runelite.api.events.GameTick;
|
||||||
|
import net.runelite.api.events.ScriptPreFired;
|
||||||
import net.runelite.api.events.StatChanged;
|
import net.runelite.api.events.StatChanged;
|
||||||
import net.runelite.api.events.WidgetHiddenChanged;
|
|
||||||
import net.runelite.api.widgets.Widget;
|
import net.runelite.api.widgets.Widget;
|
||||||
import net.runelite.api.widgets.WidgetID;
|
import static net.runelite.api.widgets.WidgetInfo.TO_CHILD;
|
||||||
import net.runelite.api.widgets.WidgetInfo;
|
import static net.runelite.api.widgets.WidgetInfo.TO_GROUP;
|
||||||
import net.runelite.client.config.ConfigManager;
|
import net.runelite.client.config.ConfigManager;
|
||||||
import net.runelite.client.eventbus.Subscribe;
|
import net.runelite.client.eventbus.Subscribe;
|
||||||
import net.runelite.client.plugins.Plugin;
|
import net.runelite.client.plugins.Plugin;
|
||||||
@@ -49,12 +52,10 @@ import net.runelite.client.plugins.PluginDescriptor;
|
|||||||
@PluginDescriptor(
|
@PluginDescriptor(
|
||||||
name = "XP Drop",
|
name = "XP Drop",
|
||||||
description = "Enable customization of the way XP drops are displayed",
|
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
|
public class XpDropPlugin extends Plugin
|
||||||
{
|
{
|
||||||
private static final int XPDROP_PADDING = 2; // space between xp drop icons
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private Client client;
|
private Client client;
|
||||||
|
|
||||||
@@ -76,116 +77,81 @@ public class XpDropPlugin extends Plugin
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onWidgetHiddenChanged(WidgetHiddenChanged event)
|
public void onScriptPreFired(ScriptPreFired scriptPreFired)
|
||||||
{
|
{
|
||||||
Widget widget = event.getWidget();
|
if (scriptPreFired.getScriptId() == XPDROPS_SETDROPSIZE)
|
||||||
|
|
||||||
int group = WidgetInfo.TO_GROUP(widget.getId());
|
|
||||||
|
|
||||||
if (group != WidgetID.EXPERIENCE_DROP_GROUP_ID)
|
|
||||||
{
|
{
|
||||||
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())
|
private void processXpDrop(int widgetId)
|
||||||
{
|
{
|
||||||
return;
|
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 (config.hideSkillIcons())
|
||||||
{
|
{
|
||||||
if (widget.getSpriteId() > 0)
|
// keep only text
|
||||||
{
|
xpdrop.setChildren(Arrays.copyOf(children, 1));
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PrayerType prayer = currentTickPrayer;
|
PrayerType prayer = currentTickPrayer;
|
||||||
if (prayer == null)
|
if (prayer == null)
|
||||||
{
|
{
|
||||||
resetTextColor(widget);
|
resetTextColor(text);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String text = widget.getText();
|
|
||||||
final IntStream spriteIDs =
|
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();
|
case MELEE:
|
||||||
|
if (correctPrayer || spriteIDs.anyMatch(id ->
|
||||||
switch (prayer)
|
id == SpriteID.SKILL_ATTACK || id == SpriteID.SKILL_STRENGTH || id == SpriteID.SKILL_DEFENCE))
|
||||||
{
|
{
|
||||||
case MELEE:
|
color = config.getMeleePrayerColor().getRGB();
|
||||||
if (spriteIDs.anyMatch(id ->
|
correctPrayer = true;
|
||||||
id == SpriteID.SKILL_ATTACK || id == SpriteID.SKILL_STRENGTH || id == SpriteID.SKILL_DEFENCE
|
}
|
||||||
|| correctPrayer))
|
break;
|
||||||
{
|
case RANGE:
|
||||||
color = config.getMeleePrayerColor().getRGB();
|
if (correctPrayer || spriteIDs.anyMatch(id -> id == SpriteID.SKILL_RANGED))
|
||||||
correctPrayer = true;
|
{
|
||||||
}
|
color = config.getRangePrayerColor().getRGB();
|
||||||
break;
|
correctPrayer = true;
|
||||||
case RANGE:
|
}
|
||||||
if (spriteIDs.anyMatch(id -> id == SpriteID.SKILL_RANGED || correctPrayer))
|
break;
|
||||||
{
|
case MAGIC:
|
||||||
color = config.getRangePrayerColor().getRGB();
|
if (correctPrayer || spriteIDs.anyMatch(id -> id == SpriteID.SKILL_MAGIC))
|
||||||
correctPrayer = true;
|
{
|
||||||
}
|
color = config.getMagePrayerColor().getRGB();
|
||||||
break;
|
correctPrayer = true;
|
||||||
case MAGIC:
|
}
|
||||||
if (spriteIDs.anyMatch(id -> id == SpriteID.SKILL_MAGIC || correctPrayer))
|
break;
|
||||||
{
|
|
||||||
color = config.getMagePrayerColor().getRGB();
|
|
||||||
correctPrayer = true;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
widget.setTextColor(color);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
text.setTextColor(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void resetTextColor(Widget widget)
|
private void resetTextColor(Widget widget)
|
||||||
{
|
{
|
||||||
int defaultColorIdx = client.getVar(Varbits.EXPERIENCE_DROP_COLOR);
|
EnumComposition colorEnum = client.getEnum(EnumID.XPDROP_COLORS);
|
||||||
int defaultColor = DefaultColors.values()[defaultColorIdx].getColor().getRGB();
|
int defaultColorId = client.getVar(Varbits.EXPERIENCE_DROP_COLOR);
|
||||||
widget.setTextColor(defaultColor);
|
int color = colorEnum.getIntValue(defaultColorId);
|
||||||
|
widget.setTextColor(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
private PrayerType getActivePrayerType()
|
private PrayerType getActivePrayerType()
|
||||||
|
|||||||
Reference in New Issue
Block a user