Add infoboxes to item charges plugin

Closes #1318

Co-authored-by: Tomas Slusny <slusnucky@gmail.com>
Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
Hydrox6
2018-12-18 11:24:10 +00:00
parent ac8f728d47
commit 1a38158651
7 changed files with 304 additions and 17 deletions

View File

@@ -203,4 +203,15 @@ public interface ItemChargeConfig extends Config
{
return false;
}
@ConfigItem(
keyName = "showInfoboxes",
name = "Show Infoboxes",
description = "Configures whether to show an infobox equipped charge items",
position = 15
)
default boolean showInfoboxes()
{
return false;
}
}

View File

@@ -0,0 +1,60 @@
/*
* Copyright (c) 2018, Hydrox6 <ikada@protonmail.ch>
* 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.itemcharges;
import java.awt.Color;
import java.awt.image.BufferedImage;
import lombok.Getter;
import net.runelite.api.EquipmentInventorySlot;
import net.runelite.client.ui.overlay.infobox.Counter;
@Getter
class ItemChargeInfobox extends Counter
{
private final ItemChargePlugin plugin;
private final ItemWithSlot item;
private final EquipmentInventorySlot slot;
ItemChargeInfobox(
ItemChargePlugin plugin,
BufferedImage image,
String name,
int charges,
ItemWithSlot item,
EquipmentInventorySlot slot)
{
super(image, plugin, charges);
setTooltip(name);
this.plugin = plugin;
this.item = item;
this.slot = slot;
}
@Override
public Color getTextColor()
{
return getPlugin().getColor(getCount());
}
}

View File

@@ -24,7 +24,6 @@
*/
package net.runelite.client.plugins.itemcharges;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Point;
@@ -112,7 +111,7 @@ class ItemChargeOverlay extends Overlay
final TextComponent textComponent = new TextComponent();
textComponent.setPosition(new Point(bounds.x, bounds.y + 16));
textComponent.setText(charges < 0 ? "?" : String.valueOf(charges));
textComponent.setColor(getColor(charges));
textComponent.setColor(itemChargePlugin.getColor(charges));
textComponent.render(graphics);
}
return null;
@@ -137,20 +136,6 @@ class ItemChargeOverlay extends Overlay
return jewellery;
}
private Color getColor(int charges)
{
Color color = Color.WHITE;
if (charges <= config.veryLowWarning())
{
color = config.veryLowWarningColor();
}
else if (charges <= config.lowWarning())
{
color = config.lowWarningolor();
}
return color;
}
private boolean displayOverlay()
{
return config.showTeleportCharges() || config.showDodgyCount() || config.showFungicideCharges()

View File

@@ -1,5 +1,6 @@
/*
* Copyright (c) 2017, Seth <Sethtroll3@gmail.com>
* Copyright (c) 2018, Hydrox6 <ikada@protonmail.ch>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -25,17 +26,29 @@
package net.runelite.client.plugins.itemcharges;
import com.google.inject.Provides;
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.inject.Inject;
import net.runelite.api.ChatMessageType;
import net.runelite.api.Client;
import net.runelite.api.EquipmentInventorySlot;
import net.runelite.api.InventoryID;
import net.runelite.api.Item;
import net.runelite.api.ItemContainer;
import net.runelite.api.ItemID;
import net.runelite.api.events.ChatMessage;
import net.runelite.api.events.ConfigChanged;
import net.runelite.api.events.ItemContainerChanged;
import net.runelite.client.Notifier;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.game.ItemManager;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.ui.overlay.OverlayManager;
import net.runelite.client.ui.overlay.infobox.InfoBoxManager;
@PluginDescriptor(
name = "Item Charges",
@@ -54,12 +67,21 @@ public class ItemChargePlugin extends Plugin
private static final int MAX_DODGY_CHARGES = 10;
@Inject
private Client client;
@Inject
private OverlayManager overlayManager;
@Inject
private ItemChargeOverlay overlay;
@Inject
private ItemManager itemManager;
@Inject
private InfoBoxManager infoBoxManager;
@Inject
private Notifier notifier;
@@ -82,6 +104,37 @@ public class ItemChargePlugin extends Plugin
protected void shutDown() throws Exception
{
overlayManager.remove(overlay);
infoBoxManager.removeIf(ItemChargeInfobox.class::isInstance);
}
@Subscribe
public void onConfigChanged(ConfigChanged event)
{
if (!event.getGroup().equals("itemCharge"))
{
return;
}
if (!config.showInfoboxes())
{
infoBoxManager.removeIf(ItemChargeInfobox.class::isInstance);
return;
}
if (!config.showTeleportCharges())
{
removeInfobox(ItemWithSlot.TELEPORT);
}
if (!config.showAbyssalBraceletCharges())
{
removeInfobox(ItemWithSlot.ABYSSAL_BRACELET);
}
if (!config.showDodgyCount())
{
removeInfobox(ItemWithSlot.DODGY_NECKLACE);
}
}
@Subscribe
@@ -117,8 +170,128 @@ public class ItemChargePlugin extends Plugin
}
}
@Subscribe
public void onItemContainerChanged(ItemContainerChanged event)
{
if (event.getItemContainer() != client.getItemContainer(InventoryID.EQUIPMENT) || !config.showInfoboxes())
{
return;
}
final Item[] items = event.getItemContainer().getItems();
if (config.showTeleportCharges())
{
updateJewelleryInfobox(ItemWithSlot.TELEPORT, items);
}
if (config.showDodgyCount())
{
updateJewelleryInfobox(ItemWithSlot.DODGY_NECKLACE, items);
}
if (config.showAbyssalBraceletCharges())
{
updateJewelleryInfobox(ItemWithSlot.ABYSSAL_BRACELET, items);
}
}
private void updateDodgyNecklaceCharges(final int value)
{
config.dodgyNecklace(value);
if (config.showInfoboxes() && config.showDodgyCount())
{
final ItemContainer itemContainer = client.getItemContainer(InventoryID.EQUIPMENT);
if (itemContainer == null)
{
return;
}
updateJewelleryInfobox(ItemWithSlot.DODGY_NECKLACE, itemContainer.getItems());
}
}
private void updateJewelleryInfobox(ItemWithSlot item, Item[] items)
{
for (final EquipmentInventorySlot equipmentInventorySlot : item.getSlots())
{
updateJewelleryInfobox(item, items, equipmentInventorySlot);
}
}
private void updateJewelleryInfobox(ItemWithSlot type, Item[] items, EquipmentInventorySlot slot)
{
removeInfobox(type, slot);
if (slot.getSlotIdx() >= items.length)
{
return;
}
final int id = items[slot.getSlotIdx()].getId();
if (id < 0)
{
return;
}
final ItemWithCharge itemWithCharge = ItemWithCharge.findItem(id);
int charges = -1;
if (itemWithCharge == null)
{
if (id == ItemID.DODGY_NECKLACE && type == ItemWithSlot.DODGY_NECKLACE)
{
charges = config.dodgyNecklace();
}
}
else if (itemWithCharge.getType() == type.getType())
{
charges = itemWithCharge.getCharges();
}
if (charges <= 0)
{
return;
}
final String name = itemManager.getItemComposition(id).getName();
final BufferedImage image = itemManager.getImage(id);
final ItemChargeInfobox infobox = new ItemChargeInfobox(this, image, name, charges, type, slot);
infoBoxManager.addInfoBox(infobox);
}
private void removeInfobox(final ItemWithSlot item)
{
infoBoxManager.removeIf(t -> t instanceof ItemChargeInfobox && ((ItemChargeInfobox) t).getItem() == item);
}
private void removeInfobox(final ItemWithSlot item, final EquipmentInventorySlot slot)
{
infoBoxManager.removeIf(t ->
{
if (!(t instanceof ItemChargeInfobox))
{
return false;
}
final ItemChargeInfobox i = (ItemChargeInfobox)t;
return i.getItem() == item && i.getSlot() == slot;
});
}
Color getColor(int charges)
{
Color color = Color.WHITE;
if (charges <= config.veryLowWarning())
{
color = config.veryLowWarningColor();
}
else if (charges <= config.lowWarning())
{
color = config.lowWarningolor();
}
return color;
}
}

View File

@@ -32,5 +32,6 @@ enum ItemChargeType
IMPBOX,
TELEPORT,
WATERCAN,
WATERSKIN
WATERSKIN,
DODGY_NECKLACE
}

View File

@@ -0,0 +1,47 @@
/*
* Copyright (c) 2019, Tomas Slusny <slusnucky@gmail.com>
* 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.itemcharges;
import com.google.common.collect.Sets;
import java.util.Set;
import lombok.Getter;
import net.runelite.api.EquipmentInventorySlot;
@Getter
enum ItemWithSlot
{
ABYSSAL_BRACELET(ItemChargeType.ABYSSAL_BRACELET, EquipmentInventorySlot.GLOVES),
DODGY_NECKLACE(ItemChargeType.DODGY_NECKLACE, EquipmentInventorySlot.AMULET),
TELEPORT(ItemChargeType.TELEPORT, EquipmentInventorySlot.WEAPON, EquipmentInventorySlot.AMULET, EquipmentInventorySlot.GLOVES, EquipmentInventorySlot.RING);
private final ItemChargeType type;
private final Set<EquipmentInventorySlot> slots;
ItemWithSlot(final ItemChargeType type, final EquipmentInventorySlot... slots)
{
this.type = type;
this.slots = Sets.newHashSet(slots);
}
}