From 40f032bede826714ad431f912889f6a527fcd0c9 Mon Sep 17 00:00:00 2001 From: LA <14169758+LA@users.noreply.github.com> Date: Wed, 29 Jul 2020 22:39:22 -0700 Subject: [PATCH] screenshot: Capture Barbarian Assault high gamble screenshots (#12071) --- .../plugins/screenshot/ScreenshotConfig.java | 14 +++++- .../plugins/screenshot/ScreenshotPlugin.java | 47 ++++++++++++++++--- .../screenshot/ScreenshotPluginTest.java | 7 +++ 3 files changed, 61 insertions(+), 7 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/screenshot/ScreenshotConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/screenshot/ScreenshotConfig.java index 9753e6da5b..269eb8554a 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/screenshot/ScreenshotConfig.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/screenshot/ScreenshotConfig.java @@ -229,11 +229,23 @@ public interface ScreenshotConfig extends Config return false; } + @ConfigItem( + keyName = "baHighGamble", + name = "Screenshot BA high gambles", + description = "Take a screenshot of your reward from a high gamble at Barbarian Assault.", + position = 16, + section = whatSection + ) + default boolean screenshotHighGamble() + { + return false; + } + @ConfigItem( keyName = "hotkey", name = "Screenshot hotkey", description = "When you press this key a screenshot will be taken", - position = 16 + position = 17 ) default Keybind hotkey() { diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/screenshot/ScreenshotPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/screenshot/ScreenshotPlugin.java index 7d0c3d18a2..ad721b0160 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/screenshot/ScreenshotPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/screenshot/ScreenshotPlugin.java @@ -110,6 +110,7 @@ public class ScreenshotPlugin extends Plugin private static final ImmutableList PET_MESSAGES = ImmutableList.of("You have a funny feeling like you're being followed", "You feel something weird sneaking into your backpack", "You have a funny feeling like you would have been followed"); + private static final Pattern BA_HIGH_GAMBLE_REWARD_PATTERN = Pattern.compile("(?.+)!
High level gamble count: (?.+)"); private String clueType; private Integer clueNumber; @@ -238,8 +239,17 @@ public class ScreenshotPlugin extends Plugin } else if (client.getWidget(WidgetInfo.DIALOG_SPRITE_TEXT) != null) { - fileName = parseLevelUpWidget(WidgetInfo.DIALOG_SPRITE_TEXT); - screenshotSubDir = "Levels"; + String text = client.getWidget(WidgetInfo.DIALOG_SPRITE_TEXT).getText(); + if (Text.removeTags(text).contains("High level gamble")) + { + fileName = parseBAHighGambleWidget(text); + screenshotSubDir = "BA High Gambles"; + } + else + { + fileName = parseLevelUpWidget(WidgetInfo.DIALOG_SPRITE_TEXT); + screenshotSubDir = "Levels"; + } } else if (client.getWidget(WidgetInfo.QUEST_COMPLETED_NAME_TEXT) != null) { @@ -378,7 +388,7 @@ public class ScreenshotPlugin extends Plugin takeScreenshot(fileName, "Pets"); } - if (config.screenshotBossKills() ) + if (config.screenshotBossKills()) { Matcher m = BOSSKILL_MESSAGE_PATTERN.matcher(chatMessage); if (m.matches()) @@ -455,12 +465,17 @@ public class ScreenshotPlugin extends Plugin } break; case LEVEL_UP_GROUP_ID: - case DIALOG_SPRITE_GROUP_ID: if (!config.screenshotLevels()) { return; } break; + case DIALOG_SPRITE_GROUP_ID: + if (!(config.screenshotLevels() || config.screenshotHighGamble())) + { + return; + } + break; case KINGDOM_GROUP_ID: if (!config.screenshotKingdom()) { @@ -626,12 +641,32 @@ public class ScreenshotPlugin extends Plugin return "Quest(" + quest + ')'; } + /** + * Parses the Barbarian Assault high gamble reward dialog text into a shortened string for filename usage. + * + * @param text The {@link Widget#getText() text} of the {@link WidgetInfo#DIALOG_SPRITE_TEXT} widget. + * @return Shortened string in the format "High Gamble(100)" + */ + @VisibleForTesting + static String parseBAHighGambleWidget(final String text) + { + final Matcher highGambleMatch = BA_HIGH_GAMBLE_REWARD_PATTERN.matcher(text); + if (highGambleMatch.find()) + { + String gambleCount = highGambleMatch.group("gambleCount"); + return String.format("High Gamble(%s)", gambleCount); + } + + return "High Gamble(count not found)"; + } + + /** * 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 subDir Subdirectory to store the captured screenshot in. + * @param fileName Filename to use, without file extension. + * @param subDir Subdirectory to store the captured screenshot in. */ private void takeScreenshot(String fileName, String subDir) { diff --git a/runelite-client/src/test/java/net/runelite/client/plugins/screenshot/ScreenshotPluginTest.java b/runelite-client/src/test/java/net/runelite/client/plugins/screenshot/ScreenshotPluginTest.java index 2616db357e..d77ae1d17c 100644 --- a/runelite-client/src/test/java/net/runelite/client/plugins/screenshot/ScreenshotPluginTest.java +++ b/runelite-client/src/test/java/net/runelite/client/plugins/screenshot/ScreenshotPluginTest.java @@ -66,6 +66,7 @@ public class ScreenshotPluginTest private static final String THEATRE_OF_BLOOD_CHEST = "Your completed Theatre of Blood count is: 73."; private static final String VALUABLE_DROP = "Valuable drop: 6 x Bronze arrow (42 coins)"; private static final String UNTRADEABLE_DROP = "Untradeable drop: Rusty sword"; + private static final String BA_HIGH_GAMBLE_REWARD = "Raw shark (x 300)!
High level gamble count: 100"; @Mock @Bind @@ -258,4 +259,10 @@ public class ScreenshotPluginTest assertEquals("Quest(Doric's Quest)", ScreenshotPlugin.parseQuestCompletedWidget("You have completed Doric's Quest!")); assertEquals("Quest(quest not found)", ScreenshotPlugin.parseQuestCompletedWidget("Sins of the Father forgiven!")); } + + @Test + public void testBAHighGambleRewardParsing() + { + assertEquals("High Gamble(100)", ScreenshotPlugin.parseBAHighGambleWidget(BA_HIGH_GAMBLE_REWARD)); + } }