Runepouch plugin

This commit is contained in:
Tyler Hardy
2017-09-24 10:24:41 -05:00
committed by Adam
parent 0374a983da
commit 52d46c1272
25 changed files with 307 additions and 0 deletions

View File

@@ -34,6 +34,16 @@ public enum Varbits
POUCH_LARGE(605, 486, 9, 17),
POUCH_GIANT(606, 486, 18, 29),
/**
* Runepouch
*/
RUNE_POUCH_RUNE1(29, 1139, 0, 5),
RUNE_POUCH_RUNE2(1622, 1139, 6, 11),
RUNE_POUCH_RUNE3(1623, 1139, 12, 17),
RUNE_POUCH_AMOUNT1(1624, 1139, 18, 31),
RUNE_POUCH_AMOUNT2(1625, 1140, 0, 13),
RUNE_POUCH_AMOUNT3(1626, 1140, 14, 27),
/**
* Prayers
*/

View File

@@ -56,6 +56,7 @@ import net.runelite.client.plugins.pestcontrol.PestControl;
import net.runelite.client.plugins.chatcommands.ChatCommands;
import net.runelite.client.plugins.rememberusername.RememberUsername;
import net.runelite.client.plugins.runecraft.Runecraft;
import net.runelite.client.plugins.runepouch.Runepouch;
import net.runelite.client.plugins.timers.Timers;
import net.runelite.client.plugins.woodcutting.WoodcuttingPlugin;
import net.runelite.client.plugins.xpglobes.XpGlobes;
@@ -109,6 +110,7 @@ public class PluginManager
plugins.add(new ChatCommands());
plugins.add(new ClueScrollPlugin());
plugins.add(new Timers());
plugins.add(new Runepouch());
if (RuneLite.getOptions().has("developer-mode"))
{

View File

@@ -0,0 +1,99 @@
/*
* Copyright (c) 2017, Tyler <https://github.com/tylerthardy>
* 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.runepouch;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import java.awt.image.BufferedImage;
import java.io.InputStream;
import java.util.concurrent.ExecutionException;
import javax.imageio.ImageIO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class RuneImageCache
{
private static final Logger logger = LoggerFactory.getLogger(RuneImageCache.class);
// ids from the varbit
private static final String[] RUNE_NAMES =
{
"None",
"Air", //1
"Water", //2
"Earth", //3
"Fire", //4
"Mind", //5
"Chaos", //6
"Death", //7
"Blood", //8
"Cosmic", //9
"Nature", //10
"Law", //11
"Body", //12
"Soul", //13
"Astral", //14
"Mist", //15
"Mud", //16
"Dust", //17
"Lava", //18
"Steam", //19
"Smoke" //20
};
private final LoadingCache<Integer, BufferedImage> cache;
public RuneImageCache()
{
cache = CacheBuilder.newBuilder()
.maximumSize(RUNE_NAMES.length)
.build(
new CacheLoader<Integer, BufferedImage>()
{
@Override
public BufferedImage load(Integer runeId) throws Exception
{
InputStream in = RunepouchOverlay.class.getResourceAsStream(RUNE_NAMES[runeId] + ".png");
return ImageIO.read(in);
}
}
);
}
public BufferedImage getImage(int runeId)
{
try
{
return cache.get(runeId);
}
catch (ExecutionException e)
{
logger.warn("unable to load rune image", e);
return null;
}
}
}

View File

@@ -0,0 +1,49 @@
/*
* Copyright (c) 2017, Tyler <http://github.com/tylerthardy>
* 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.runepouch;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.ui.overlay.Overlay;
public class Runepouch extends Plugin
{
private final RunepouchOverlay overlay = new RunepouchOverlay(this);
@Override
public Overlay getOverlay()
{
return overlay;
}
@Override
protected void startUp() throws Exception
{
}
@Override
protected void shutDown() throws Exception
{
}
}

View File

@@ -0,0 +1,147 @@
/*
* Copyright (c) 2017, Tyler <http://github.com/tylerthardy>
* 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.runepouch;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.font.TextAttribute;
import java.awt.image.BufferedImage;
import java.util.Map;
import net.runelite.api.Client;
import net.runelite.api.GameState;
import net.runelite.api.ItemID;
import net.runelite.api.Point;
import net.runelite.api.Varbits;
import net.runelite.api.widgets.Widget;
import net.runelite.api.widgets.WidgetInfo;
import net.runelite.api.widgets.WidgetItem;
import net.runelite.client.RuneLite;
import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayPosition;
import net.runelite.client.ui.overlay.OverlayUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class RunepouchOverlay extends Overlay
{
private static final Logger logger = LoggerFactory.getLogger(RunepouchOverlay.class);
private static final Varbits[] AMOUNT_VARBITS =
{
Varbits.RUNE_POUCH_AMOUNT1, Varbits.RUNE_POUCH_AMOUNT2, Varbits.RUNE_POUCH_AMOUNT3
};
private static final Varbits[] RUNE_VARBITS =
{
Varbits.RUNE_POUCH_RUNE1, Varbits.RUNE_POUCH_RUNE2, Varbits.RUNE_POUCH_RUNE3
};
private final Client client = RuneLite.getClient();
private final RuneImageCache runeImageCache = new RuneImageCache();
public RunepouchOverlay(Runepouch plugin)
{
super(OverlayPosition.DYNAMIC);
}
@Override
public Dimension render(Graphics2D graphics)
{
if (client.getGameState() != GameState.LOGGED_IN
|| client.getWidget(WidgetInfo.LOGIN_CLICK_TO_PLAY_SCREEN) != null)
{
return null;
}
Widget inventoryWidget = client.getWidget(WidgetInfo.INVENTORY);
if (inventoryWidget == null || inventoryWidget.isHidden())
{
return null;
}
Font font = graphics.getFont();
if (font.getSize() != 10)
{
Map attributes = font.getAttributes();
attributes.put(TextAttribute.SIZE, 10);
font = Font.getFont(attributes);
graphics.setFont(font);
}
for (WidgetItem item : inventoryWidget.getWidgetItems())
{
if (item.getId() != ItemID.RUNE_POUCH)
{
continue;
}
Point location = item.getCanvasLocation();
if (location == null)
{
continue;
}
assert AMOUNT_VARBITS.length == RUNE_VARBITS.length;
for (int i = 0; i < AMOUNT_VARBITS.length; i++)
{
Varbits amountVarbit = AMOUNT_VARBITS[i];
Varbits runeVarbit = RUNE_VARBITS[i];
int amount = client.getSetting(amountVarbit);
if (amount <= 0)
{
continue;
}
int runeId = client.getSetting(runeVarbit);
BufferedImage runeImg = runeImageCache.getImage(runeId);
if (runeImg != null)
{
OverlayUtil.renderImageLocation(graphics,
new Point(location.getX(), location.getY() + 2 + (graphics.getFontMetrics().getHeight() - 2) * i),
runeImg);
}
graphics.setColor(Color.black);
graphics.drawString("" + formatNumber(amount), location.getX() + 13,
location.getY() + (graphics.getFontMetrics().getHeight() - 2) * i + 11);
graphics.setColor(Color.white);
graphics.drawString("" + formatNumber(amount), location.getX() + 12,
location.getY() + (graphics.getFontMetrics().getHeight() - 2) * i + 10);
}
}
return null;
}
private static String formatNumber(int var0)
{
return var0 < 10000 ? String.valueOf(var0) : var0 / 1000 + "K";
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB