Merge pull request #14019 from superiorser9/notification-screenshot

ScreenshotPlugin: support collection log popup
This commit is contained in:
Jordan
2021-09-21 07:34:24 +00:00
committed by GitHub
5 changed files with 99 additions and 3 deletions

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);
}
}