Add ability to automatically screenshot friend and cc deaths (#408)

* Shift always anti-drag when toggled off

* Use better vanguards plugin

* Add ability to automatically screenshot friend and cc deaths

* Fixed Checkstyle

* Revert "Shift always anti-drag when toggled off"

This reverts commit ba40d3a0583a43369eb03925739431dd3ced5dd2.

* Added back shitty vangs cause wrong branch

* fixed checkstyle for a vanguards plugin as you would when editing the screenshot plugin
This commit is contained in:
farhan1666
2019-05-27 10:20:24 +01:00
committed by Kyleeld
parent 2d997068dc
commit 967643309e
4 changed files with 341 additions and 234 deletions

View File

@@ -144,21 +144,31 @@ public interface ScreenshotConfig extends Config
} }
@ConfigItem( @ConfigItem(
keyName = "playerDeath", keyName = "friendDeath",
name = "Screenshot Deaths", name = "Friend Deaths",
description = "Configures whether or not screenshots are automatically taken when you die.", description = "Configures whether or not screenshots are automatically taken when a clanmate or a friend near you dies.",
position = 10 position = 10
) )
default boolean screenshotPlayerDeath() default boolean screenshotFriendDeath()
{ {
return false; return false;
} }
@ConfigItem(
keyName = "playerDeath",
name = "Screenshot Deaths",
description = "Configures whether or not screenshots are automatically taken when you die.",
position = 11
)
default boolean screenshotPlayerDeath()
{
return false;
}
@ConfigItem( @ConfigItem(
keyName = "duels", keyName = "duels",
name = "Screenshot Duels", name = "Screenshot Duels",
description = "Configures whether or not screenshots are automatically taken of the duel end screen.", description = "Configures whether or not screenshots are automatically taken of the duel end screen.",
position = 11 position = 12
) )
default boolean screenshotDuels() default boolean screenshotDuels()
{ {
@@ -169,7 +179,7 @@ public interface ScreenshotConfig extends Config
keyName = "valuableDrop", keyName = "valuableDrop",
name = "Screenshot Valuable drops", name = "Screenshot Valuable drops",
description = "Configures whether or not screenshots are automatically taken when you receive a valuable drop.", description = "Configures whether or not screenshots are automatically taken when you receive a valuable drop.",
position = 12 position = 13
) )
default boolean screenshotValuableDrop() default boolean screenshotValuableDrop()
{ {
@@ -180,7 +190,7 @@ public interface ScreenshotConfig extends Config
keyName = "untradeableDrop", keyName = "untradeableDrop",
name = "Screenshot Untradeable drops", name = "Screenshot Untradeable drops",
description = "Configures whether or not screenshots are automatically taken when you receive an untradeable drop.", description = "Configures whether or not screenshots are automatically taken when you receive an untradeable drop.",
position = 13 position = 14
) )
default boolean screenshotUntradeableDrop() default boolean screenshotUntradeableDrop()
{ {
@@ -191,7 +201,7 @@ public interface ScreenshotConfig extends Config
keyName = "hotkey", keyName = "hotkey",
name = "Screenshot hotkey", name = "Screenshot hotkey",
description = "When you press this key a screenshot will be taken", description = "When you press this key a screenshot will be taken",
position = 14 position = 15
) )
default Keybind hotkey() default Keybind hotkey()
{ {

View File

@@ -1,5 +1,6 @@
/* /*
* Copyright (c) 2018, Lotto <https://github.com/devLotto> * Copyright (c) 2018, Lotto <https://github.com/devLotto>
* Modified by Jason <https://github.com/JasonT20015>
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -46,6 +47,9 @@ import java.text.SimpleDateFormat;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.Date; import java.util.Date;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.regex.Matcher; import java.util.regex.Matcher;
@@ -53,6 +57,7 @@ import java.util.regex.Pattern;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import javax.inject.Inject; import javax.inject.Inject;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import lombok.AccessLevel; import lombok.AccessLevel;
import lombok.Getter; import lombok.Getter;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@@ -62,11 +67,12 @@ import net.runelite.api.GameState;
import net.runelite.api.Player; import net.runelite.api.Player;
import net.runelite.api.Point; import net.runelite.api.Point;
import net.runelite.api.SpriteID; import net.runelite.api.SpriteID;
import net.runelite.api.Varbits;
import net.runelite.api.WorldType; import net.runelite.api.WorldType;
import net.runelite.api.events.AnimationChanged;
import net.runelite.api.events.ChatMessage; import net.runelite.api.events.ChatMessage;
import net.runelite.api.events.GameStateChanged; import net.runelite.api.events.GameStateChanged;
import net.runelite.api.events.GameTick; import net.runelite.api.events.GameTick;
import net.runelite.api.events.LocalPlayerDeath;
import net.runelite.api.events.WidgetLoaded; import net.runelite.api.events.WidgetLoaded;
import net.runelite.api.widgets.Widget; import net.runelite.api.widgets.Widget;
import static net.runelite.api.widgets.WidgetID.BARROWS_REWARD_GROUP_ID; import static net.runelite.api.widgets.WidgetID.BARROWS_REWARD_GROUP_ID;
@@ -105,11 +111,12 @@ import okhttp3.MediaType;
import okhttp3.Request; import okhttp3.Request;
import okhttp3.RequestBody; import okhttp3.RequestBody;
import okhttp3.Response; import okhttp3.Response;
import org.jetbrains.annotations.Nullable;
@PluginDescriptor( @PluginDescriptor(
name = "Screenshot", name = "Screenshot",
description = "Enable the manual and automatic taking of screenshots", description = "Enable the manual and automatic taking of screenshots",
tags = {"external", "images", "imgur", "integration", "notifications"} tags = {"external", "images", "imgur", "integration", "notifications"}
) )
@Slf4j @Slf4j
public class ScreenshotPlugin extends Plugin public class ScreenshotPlugin extends Plugin
@@ -127,8 +134,8 @@ public class ScreenshotPlugin extends Plugin
private static final Pattern UNTRADEABLE_DROP_PATTERN = Pattern.compile(".*Untradeable drop: ([^<>]+)(?:</col>)?"); private static final Pattern UNTRADEABLE_DROP_PATTERN = Pattern.compile(".*Untradeable drop: ([^<>]+)(?:</col>)?");
private static final Pattern DUEL_END_PATTERN = Pattern.compile("You have now (won|lost) ([0-9]+) duels?\\."); private static final Pattern DUEL_END_PATTERN = Pattern.compile("You have now (won|lost) ([0-9]+) duels?\\.");
private static final ImmutableList<String> PET_MESSAGES = ImmutableList.of("You have a funny feeling like you're being followed", private static final ImmutableList<String> PET_MESSAGES = ImmutableList.of("You have a funny feeling like you're being followed",
"You feel something weird sneaking into your backpack", "You feel something weird sneaking into your backpack",
"You have a funny feeling like you would have been followed"); "You have a funny feeling like you would have been followed");
static String format(Date date) static String format(Date date)
{ {
@@ -187,6 +194,8 @@ public class ScreenshotPlugin extends Plugin
@Getter(AccessLevel.PACKAGE) @Getter(AccessLevel.PACKAGE)
private BufferedImage reportButton; private BufferedImage reportButton;
private Map<Player, Integer> dying = new HashMap<Player, Integer>();
private NavigationButton titleBarButton; private NavigationButton titleBarButton;
private final HotkeyListener hotkeyListener = new HotkeyListener(() -> config.hotkey()) private final HotkeyListener hotkeyListener = new HotkeyListener(() -> config.hotkey())
@@ -214,25 +223,25 @@ public class ScreenshotPlugin extends Plugin
final BufferedImage iconImage = ImageUtil.getResourceStreamFromClass(getClass(), "screenshot.png"); final BufferedImage iconImage = ImageUtil.getResourceStreamFromClass(getClass(), "screenshot.png");
titleBarButton = NavigationButton.builder() titleBarButton = NavigationButton.builder()
.tab(false) .tab(false)
.tooltip("Take screenshot") .tooltip("Take screenshot")
.icon(iconImage) .icon(iconImage)
.onClick(() -> takeScreenshot(format(new Date()))) .onClick(() -> takeScreenshot(format(new Date())))
.popup(ImmutableMap .popup(ImmutableMap
.<String, Runnable>builder() .<String, Runnable>builder()
.put("Open screenshot folder...", () -> .put("Open screenshot folder...", () ->
{ {
try try
{ {
Desktop.getDesktop().open(SCREENSHOT_DIR); Desktop.getDesktop().open(SCREENSHOT_DIR);
} }
catch (IOException ex) catch (IOException ex)
{ {
log.warn("Error opening screenshot dir", ex); log.warn("Error opening screenshot dir", ex);
} }
}) })
.build()) .build())
.build(); .build();
clientToolbar.addNavigation(titleBarButton); clientToolbar.addNavigation(titleBarButton);
} }
@@ -249,7 +258,7 @@ public class ScreenshotPlugin extends Plugin
public void onGameStateChanged(GameStateChanged event) public void onGameStateChanged(GameStateChanged event)
{ {
if (event.getGameState() == GameState.LOGGED_IN if (event.getGameState() == GameState.LOGGED_IN
&& reportButton == null) && reportButton == null)
{ {
reportButton = spriteManager.getSprite(SpriteID.CHATBOX_REPORT_BUTTON, 0); reportButton = spriteManager.getSprite(SpriteID.CHATBOX_REPORT_BUTTON, 0);
} }
@@ -258,6 +267,23 @@ public class ScreenshotPlugin extends Plugin
@Subscribe @Subscribe
public void onGameTick(GameTick event) public void onGameTick(GameTick event)
{ {
if (config.screenshotFriendDeath())
{
for (Iterator<Player> it = dying.keySet().iterator(); it.hasNext();)
{
Player key = it.next();
if (key.getAnimation() != 836)
{
it.remove();
}
dying.replace(key, dying.get(key) - 1);
if (dying.get(key) == 0)
{
takeScreenshot(key.getName() + " ded " + format(new Date()), "Deaths");
it.remove();
}
}
}
if (!shouldTakeScreenshot) if (!shouldTakeScreenshot)
{ {
return; return;
@@ -288,11 +314,43 @@ public class ScreenshotPlugin extends Plugin
} }
@Subscribe @Subscribe
public void onLocalPlayerDeath(LocalPlayerDeath death) public void onAnimationChanged(AnimationChanged e)
{ {
if (config.screenshotPlayerDeath()) //this got refactored somewhere, but some things were missing
if (!config.screenshotFriendDeath() || !config.screenshotPlayerDeath())
return;
if (!(e.getActor() instanceof Player))
return;
Player p = (Player) e.getActor();
if (p.getAnimation() != 836)
{ {
takeScreenshot("Death " + format(new Date())); return;
}
if (p.getName().equals(client.getLocalPlayer().getName()))
{
if (config.screenshotPlayerDeath())
{
dying.put(p, 3);
return;
}
else
{
return;
}
}
if (config.screenshotFriendDeath())
{
int tob = client.getVar(Varbits.THEATRE_OF_BLOOD);
if (client.getVar(Varbits.IN_RAID) == 1 || tob == 2 || tob == 3 || p.isFriend())
{
//this is the same as the tick counter had, just want to make ss at right timing
dying.put(p, 3);
}
} }
} }
@@ -375,7 +433,7 @@ public class ScreenshotPlugin extends Plugin
takeScreenshot(fileName); takeScreenshot(fileName);
} }
if (config.screenshotBossKills()) if (config.screenshotBossKills() )
{ {
Matcher m = BOSSKILL_MESSAGE_PATTERN.matcher(chatMessage); Matcher m = BOSSKILL_MESSAGE_PATTERN.matcher(chatMessage);
if (m.matches()) if (m.matches())
@@ -562,7 +620,7 @@ public class ScreenshotPlugin extends Plugin
* Saves a screenshot of the client window to the screenshot folder as a PNG, * Saves a screenshot of the client window to the screenshot folder as a PNG,
* and optionally uploads it to an image-hosting service. * and optionally uploads it to an image-hosting service.
* *
* @param fileName Filename to use, without file extension. * @param fileName Filename to use, without file extension.
*/ */
private void takeScreenshot(String fileName) private void takeScreenshot(String fileName)
{ {
@@ -576,7 +634,7 @@ public class ScreenshotPlugin extends Plugin
Consumer<Image> imageCallback = (img) -> Consumer<Image> imageCallback = (img) ->
{ {
// This callback is on the game thread, move to executor thread // This callback is on the game thread, move to executor thread
executor.submit(() -> takeScreenshot(fileName, img)); executor.submit(() -> takeScreenshot(fileName, img, null));
}; };
if (config.displayDate()) if (config.displayDate())
@@ -589,11 +647,43 @@ public class ScreenshotPlugin extends Plugin
} }
} }
private void takeScreenshot(String fileName, Image image) /**
* Saves a screenshot of the client window to the screenshot folder as a PNG,
* and optionally uploads it to an image-hosting service.
*
* @param fileName Filename to use, without file extension.
* @param subdirectory The subdirectory to save it in
*/
private void takeScreenshot(String fileName, String subdirectory)
{
if (client.getGameState() == GameState.LOGIN_SCREEN)
{
// Prevent the screenshot from being captured
log.info("Login screenshot prevented");
return;
}
Consumer<Image> imageCallback = (img) ->
{
// This callback is on the game thread, move to executor thread
executor.submit(() -> takeScreenshot(fileName, img, subdirectory));
};
if (config.displayDate())
{
screenshotOverlay.queueForTimestamp(imageCallback);
}
else
{
drawManager.requestNextFrameListener(imageCallback);
}
}
private void takeScreenshot(String fileName, Image image, @Nullable String subdirectory)
{ {
BufferedImage screenshot = config.includeFrame() BufferedImage screenshot = config.includeFrame()
? new BufferedImage(clientUi.getWidth(), clientUi.getHeight(), BufferedImage.TYPE_INT_ARGB) ? new BufferedImage(clientUi.getWidth(), clientUi.getHeight(), BufferedImage.TYPE_INT_ARGB)
: new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB); : new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB);
Graphics graphics = screenshot.getGraphics(); Graphics graphics = screenshot.getGraphics();
@@ -644,6 +734,14 @@ public class ScreenshotPlugin extends Plugin
playerFolder.mkdirs(); playerFolder.mkdirs();
if (subdirectory != null)
{
//uhh just tried to do this as workaround, not sure if it's the best idea tho
File actualplayerFolder = new File(playerFolder, subdirectory);
actualplayerFolder.mkdir();
playerFolder = actualplayerFolder;
}
try try
{ {
File screenshotFile = new File(playerFolder, fileName + ".png"); File screenshotFile = new File(playerFolder, fileName + ".png");
@@ -677,10 +775,10 @@ public class ScreenshotPlugin extends Plugin
String json = RuneLiteAPI.GSON.toJson(new ImageUploadRequest(screenshotFile)); String json = RuneLiteAPI.GSON.toJson(new ImageUploadRequest(screenshotFile));
Request request = new Request.Builder() Request request = new Request.Builder()
.url(IMGUR_IMAGE_UPLOAD_URL) .url(IMGUR_IMAGE_UPLOAD_URL)
.addHeader("Authorization", "Client-ID " + IMGUR_CLIENT_ID) .addHeader("Authorization", "Client-ID " + IMGUR_CLIENT_ID)
.post(RequestBody.create(JSON, json)) .post(RequestBody.create(JSON, json))
.build(); .build();
RuneLiteAPI.CLIENT.newCall(request).enqueue(new Callback() RuneLiteAPI.CLIENT.newCall(request).enqueue(new Callback()
{ {
@@ -696,7 +794,7 @@ public class ScreenshotPlugin extends Plugin
try (InputStream in = response.body().byteStream()) try (InputStream in = response.body().byteStream())
{ {
ImageUploadResponse imageUploadResponse = RuneLiteAPI.GSON ImageUploadResponse imageUploadResponse = RuneLiteAPI.GSON
.fromJson(new InputStreamReader(in), ImageUploadResponse.class); .fromJson(new InputStreamReader(in), ImageUploadResponse.class);
if (imageUploadResponse.isSuccess()) if (imageUploadResponse.isSuccess())
{ {
@@ -751,4 +849,4 @@ public class ScreenshotPlugin extends Plugin
{ {
return theatreOfBloodNumber; return theatreOfBloodNumber;
} }
} }

View File

@@ -1,116 +1,116 @@
/* /*
* Copyright (c) 2018, https://runelitepl.us * Copyright (c) 2018, https://runelitepl.us
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, this * 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer. * list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * 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 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * 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 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
package net.runelite.client.plugins.vanguards; package net.runelite.client.plugins.vanguards;
import java.awt.Color; import java.awt.Color;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import javax.inject.Inject; import javax.inject.Inject;
import net.runelite.api.Actor; import net.runelite.api.Actor;
import net.runelite.api.Client; import net.runelite.api.Client;
import net.runelite.api.NPC; import net.runelite.api.NPC;
import net.runelite.api.Player; import net.runelite.api.Player;
import net.runelite.client.ui.overlay.Overlay; import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayPosition; import net.runelite.client.ui.overlay.OverlayPosition;
import net.runelite.client.ui.overlay.components.LineComponent; import net.runelite.client.ui.overlay.components.LineComponent;
import net.runelite.client.ui.overlay.components.PanelComponent; import net.runelite.client.ui.overlay.components.PanelComponent;
import net.runelite.client.ui.overlay.components.TitleComponent; import net.runelite.client.ui.overlay.components.TitleComponent;
import net.runelite.client.util.Text; import net.runelite.client.util.Text;
public class VanguardOverlay extends Overlay public class VanguardOverlay extends Overlay
{ {
private final PanelComponent panelComponent = new PanelComponent(); private final PanelComponent panelComponent = new PanelComponent();
private static final int MAGE_VANGUARD_ID = 7529; private static final int MAGE_VANGUARD_ID = 7529;
private static final int RANGE_VANGUARD_ID = 7528; private static final int RANGE_VANGUARD_ID = 7528;
private static final int MELEE_VANGUARD_ID = 7527; private static final int MELEE_VANGUARD_ID = 7527;
String right_mage_str, right_range_str, right_melee_str = ""; String right_mage_str, right_range_str, right_melee_str = "";
@Inject @Inject
private Client client; private Client client;
@Inject @Inject
public VanguardOverlay(VanguardPlugin plugin) public VanguardOverlay(VanguardPlugin plugin)
{ {
super(plugin);//? super(plugin);//?
setPosition(OverlayPosition.ABOVE_CHATBOX_RIGHT); setPosition(OverlayPosition.ABOVE_CHATBOX_RIGHT);
} }
@Override @Override
public Dimension render(Graphics2D graphics) public Dimension render(Graphics2D graphics)
{ {
Player p = client.getLocalPlayer(); Player p = client.getLocalPlayer();
Actor opponent = p.getInteracting(); Actor opponent = p.getInteracting();
if (opponent instanceof NPC) if (opponent instanceof NPC)
{ {
int id = ((NPC) opponent).getId(); int id = ((NPC) opponent).getId();
if (!Text.standardize(opponent.getName()).contains("vanguard")) if (!Text.standardize(opponent.getName()).contains("vanguard"))
{ {
return null; return null;
} }
if (id == MAGE_VANGUARD_ID) if (id == MAGE_VANGUARD_ID)
{ {
float magePercent = (float) opponent.getHealthRatio() / opponent.getHealth() * 100; float magePercent = (float) opponent.getHealthRatio() / opponent.getHealth() * 100;
int mageHp = (int) magePercent; int mageHp = (int) magePercent;
right_mage_str = Integer.toString(mageHp); right_mage_str = Integer.toString(mageHp);
} }
else if (id == RANGE_VANGUARD_ID) else if (id == RANGE_VANGUARD_ID)
{ {
float rangePercent = (float) opponent.getHealthRatio() / opponent.getHealth() * 100; float rangePercent = (float) opponent.getHealthRatio() / opponent.getHealth() * 100;
int rangeHp = (int) rangePercent; int rangeHp = (int) rangePercent;
right_range_str = Integer.toString(rangeHp); right_range_str = Integer.toString(rangeHp);
} }
else if (id == MELEE_VANGUARD_ID) else if (id == MELEE_VANGUARD_ID)
{ {
float meleePercent = (float) opponent.getHealthRatio() / opponent.getHealth() * 100; float meleePercent = (float) opponent.getHealthRatio() / opponent.getHealth() * 100;
int meleeHp = (int) meleePercent; int meleeHp = (int) meleePercent;
right_melee_str = Integer.toString(meleeHp); right_melee_str = Integer.toString(meleeHp);
} }
} }
panelComponent.getChildren().clear(); panelComponent.getChildren().clear();
String overlayTitle = "Vanguard HP"; String overlayTitle = "Vanguard HP";
panelComponent.getChildren().add(TitleComponent.builder().text(overlayTitle).color(Color.RED).build()); panelComponent.getChildren().add(TitleComponent.builder().text(overlayTitle).color(Color.RED).build());
panelComponent.setPreferredSize(new Dimension(graphics.getFontMetrics().stringWidth(overlayTitle) + 30, 0)); panelComponent.setPreferredSize(new Dimension(graphics.getFontMetrics().stringWidth(overlayTitle) + 30, 0));
panelComponent.getChildren().add(LineComponent.builder().left("Mage:").right(right_mage_str).build()); panelComponent.getChildren().add(LineComponent.builder().left("Mage:").right(right_mage_str).build());
panelComponent.getChildren().add(LineComponent.builder().left("Range:").right(right_range_str).build()); panelComponent.getChildren().add(LineComponent.builder().left("Range:").right(right_range_str).build());
panelComponent.getChildren().add(LineComponent.builder().left("Melee:").right(right_melee_str).build()); panelComponent.getChildren().add(LineComponent.builder().left("Melee:").right(right_melee_str).build());
return panelComponent.render(graphics); return panelComponent.render(graphics);
} }
} }

View File

@@ -1,70 +1,69 @@
/* /*
* Copyright (c) 2018, https://runelitepl.us * Copyright (c) 2018, https://runelitepl.us
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, this * 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer. * list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * 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 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * 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 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
package net.runelite.client.plugins.vanguards; package net.runelite.client.plugins.vanguards;
import javax.inject.Inject; import javax.inject.Inject;
import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor; import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.plugins.PluginType; import net.runelite.client.plugins.PluginType;
import net.runelite.client.ui.overlay.OverlayManager; import net.runelite.client.ui.overlay.OverlayManager;
@PluginDescriptor( @PluginDescriptor(
name = "Vanguard HP Overlay", name = "Vanguard HP Overlay",
description = "tracks HP of all three vanguards", description = "tracks HP of all three vanguards",
tags = {"overlay", "vangs", "cox"}, tags = {"overlay", "vangs", "cox"},
enabledByDefault = false, enabledByDefault = false,
type = PluginType.PVM type = PluginType.PVM
) )
public class VanguardPlugin extends Plugin public class VanguardPlugin extends Plugin
{ {
private static final int MAGE_VANGUARD_ID = 7526; //i think private static final int MAGE_VANGUARD_ID = 7526; //i think
private static final int RANGE_VANGUARD_ID = 7527; private static final int RANGE_VANGUARD_ID = 7527;
private static final int MELEE_VANGUARD_ID = 7528; private static final int MELEE_VANGUARD_ID = 7528;
@Inject @Inject
private OverlayManager overlayManager; private OverlayManager overlayManager;
@Inject @Inject
private VanguardOverlay overlay; private VanguardOverlay overlay;
@Override @Override
protected void startUp() throws Exception protected void startUp() throws Exception
{ {
overlayManager.add(overlay); overlayManager.add(overlay);
} }
@Override @Override
protected void shutDown() throws Exception protected void shutDown() throws Exception
{ {
overlayManager.remove(overlay); overlayManager.remove(overlay);
overlay.right_mage_str = "-"; overlay.right_mage_str = "-";
overlay.right_range_str = "-"; overlay.right_range_str = "-";
overlay.right_melee_str = "-"; overlay.right_melee_str = "-";
} }
} }