screenshot: Capture collection log popup notifications

This commit is contained in:
superiorser9
2021-08-11 14:58:44 +01:00
committed by Jordan Atwood
parent 4bfd020b2a
commit 8345f6c7bd
5 changed files with 99 additions and 3 deletions

View File

@@ -367,4 +367,18 @@ public final class ScriptID
@ScriptArguments(integer = 6)
public static final int COLLECTION_DRAW_LIST = 2730;
/**
* Draws the active notification in increasing sizes (increasing horizontally first, then vertically) to show a
* starting animation.
*/
@ScriptArguments(integer = 3)
public static final int NOTIFICATION_START = 3346;
/**
* Draws the active notification in full size for a specified number of client ticks. In essence, delayed between
* the open and close animations.
*/
@ScriptArguments(integer = 1)
public static final int NOTIFICATION_DELAY = 3347;
}

View File

@@ -41,7 +41,9 @@ public enum VarClientStr
CHATBOX_TYPED_TEXT(335),
INPUT_TEXT(359),
PRIVATE_MESSAGE_TARGET(360),
RECENT_FRIENDS_CHAT(362);
RECENT_FRIENDS_CHAT(362),
NOTIFICATION_TOP_TEXT(387),
NOTIFICATION_BOTTOM_TEXT(388);
private final int index;
}

View File

@@ -607,7 +607,17 @@ public enum Varbits
*
* @see <a href="https://oldschool.runescape.wiki/w/Minimap#Special_attack_orb">The OSRS Wiki's Minimap page</a>
*/
PVP_SPEC_ORB(8121);
PVP_SPEC_ORB(8121),
/**
* Collection Log notification settings whenever a new item is added
*
* 0 = no notification
* 1 = chat notification only
* 2 = popup notification only
* 3 = chat and popup
*/
COLLECTION_LOG_NOTIFICATION(11959);
/**
* The raw varbit ID.

View File

@@ -51,11 +51,15 @@ import net.runelite.api.Client;
import net.runelite.api.GameState;
import net.runelite.api.Player;
import net.runelite.api.Point;
import net.runelite.api.ScriptID;
import net.runelite.api.SpriteID;
import net.runelite.api.VarClientStr;
import net.runelite.api.Varbits;
import net.runelite.api.events.ActorDeath;
import net.runelite.api.events.ChatMessage;
import net.runelite.api.events.GameTick;
import net.runelite.api.events.ScriptCallbackEvent;
import net.runelite.api.events.ScriptPreFired;
import net.runelite.api.events.WidgetLoaded;
import net.runelite.api.widgets.Widget;
import net.runelite.api.widgets.WidgetID;
@@ -148,6 +152,7 @@ public class ScreenshotPlugin extends Plugin
private Integer killCountNumber;
private boolean shouldTakeScreenshot;
private boolean notificationStarted;
@Inject
private ScreenshotConfig config;
@@ -239,6 +244,7 @@ public class ScreenshotPlugin extends Plugin
clientToolbar.removeNavigation(titleBarButton);
keyManager.unregisterKeyListener(hotkeyListener);
kickPlayerName = null;
notificationStarted = false;
}
@Subscribe
@@ -479,7 +485,7 @@ public class ScreenshotPlugin extends Plugin
}
}
if (config.screenshotCollectionLogEntries() && chatMessage.startsWith(COLLECTION_LOG_TEXT))
if (config.screenshotCollectionLogEntries() && chatMessage.startsWith(COLLECTION_LOG_TEXT) && client.getVar(Varbits.COLLECTION_LOG_NOTIFICATION) == 1)
{
String entry = Text.removeTags(chatMessage).substring(COLLECTION_LOG_TEXT.length());
String fileName = "Collection log (" + entry + ")";
@@ -622,6 +628,32 @@ public class ScreenshotPlugin extends Plugin
takeScreenshot(fileName, screenshotSubDir);
}
@Subscribe
public void onScriptPreFired(ScriptPreFired scriptPreFired)
{
switch (scriptPreFired.getScriptId())
{
case ScriptID.NOTIFICATION_START:
notificationStarted = true;
break;
case ScriptID.NOTIFICATION_DELAY:
if (!notificationStarted)
{
return;
}
String topText = client.getVar(VarClientStr.NOTIFICATION_TOP_TEXT);
String bottomText = client.getVar(VarClientStr.NOTIFICATION_BOTTOM_TEXT);
if (topText.equalsIgnoreCase("Collection log") && config.screenshotCollectionLogEntries())
{
String entry = Text.removeTags(bottomText).substring("New item:".length());
String fileName = "Collection log (" + entry + ")";
takeScreenshot(fileName, SD_COLLECTION_LOG);
}
notificationStarted = false;
break;
}
}
private void manualScreenshot()
{
takeScreenshot("", null);

View File

@@ -32,8 +32,12 @@ import java.util.function.Consumer;
import javax.inject.Inject;
import static net.runelite.api.ChatMessageType.GAMEMESSAGE;
import net.runelite.api.Client;
import net.runelite.api.ScriptID;
import net.runelite.api.VarClientStr;
import net.runelite.api.Varbits;
import net.runelite.api.events.ChatMessage;
import net.runelite.api.events.GameTick;
import net.runelite.api.events.ScriptPreFired;
import net.runelite.api.events.WidgetLoaded;
import net.runelite.api.widgets.Widget;
import net.runelite.api.widgets.WidgetID;
@@ -59,6 +63,7 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import org.mockito.junit.MockitoJUnitRunner;
@@ -76,6 +81,7 @@ public class ScreenshotPluginTest
private static final String UNTRADEABLE_DROP = "<col=ef1020>Untradeable drop: Rusty sword";
private static final String BA_HIGH_GAMBLE_REWARD = "Raw shark (x 300)!<br>High level gamble count: <col=7f0000>100</col>";
private static final String HUNTER_LEVEL_2_TEXT = "<col=000080>Congratulations, you've just advanced a Hunter level.<col=000000><br><br>Your Hunter level is now 2.";
private static final String COLLECTION_LOG_CHAT = "New item added to your collection log: <col=ef1020>Chompy bird hat</col>";
@Mock
@Bind
@@ -128,6 +134,7 @@ public class ScreenshotPluginTest
when(screenshotConfig.screenshotValuableDrop()).thenReturn(true);
when(screenshotConfig.valuableDropThreshold()).thenReturn(1000);
when(screenshotConfig.screenshotUntradeableDrop()).thenReturn(true);
when(screenshotConfig.screenshotCollectionLogEntries()).thenReturn(true);
}
@Test
@@ -386,4 +393,35 @@ public class ScreenshotPluginTest
verify(drawManager, times(0)).requestNextFrameListener(any(Consumer.class));
}
@Test
public void testCollectionLogPopup()
{
ScriptPreFired notificationStart = new ScriptPreFired(ScriptID.NOTIFICATION_START);
screenshotPlugin.onScriptPreFired(notificationStart);
when(client.getVar(VarClientStr.NOTIFICATION_TOP_TEXT)).thenReturn("Collection log");
when(client.getVar(VarClientStr.NOTIFICATION_BOTTOM_TEXT)).thenReturn("New item:<br><br><col=ffffff>Chompy bird hat</col>");
ScriptPreFired notificationDelay = new ScriptPreFired(ScriptID.NOTIFICATION_DELAY);
screenshotPlugin.onScriptPreFired(notificationDelay);
verify(drawManager).requestNextFrameListener(any(Consumer.class));
}
@Test
public void testCollectionLogChat()
{
ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", COLLECTION_LOG_CHAT, null, 0);
when(client.getVar(Varbits.COLLECTION_LOG_NOTIFICATION)).thenReturn(1);
screenshotPlugin.onChatMessage(chatMessageEvent);
verify(drawManager).requestNextFrameListener(any(Consumer.class));
when(client.getVar(Varbits.COLLECTION_LOG_NOTIFICATION)).thenReturn(3);
screenshotPlugin.onChatMessage(chatMessageEvent);
verifyNoMoreInteractions(drawManager);
}
}