util: Add subdirectory option to image captures

This commit adds an optional and nullable `subDir` string to the
`takeScreenshot()` function, allowing screenshots to be filed into a
subdirectory within the player's screenshots folder.
This commit is contained in:
Jordan Atwood
2020-02-22 22:16:52 -08:00
parent e77860ab4c
commit 896b417e66

View File

@@ -25,6 +25,7 @@
*/
package net.runelite.client.util;
import com.google.common.base.Strings;
import java.awt.Toolkit;
import java.awt.TrayIcon;
import java.awt.datatransfer.Clipboard;
@@ -40,6 +41,7 @@ import java.text.SimpleDateFormat;
import java.util.Base64;
import java.util.Date;
import java.util.EnumSet;
import javax.annotation.Nullable;
import javax.imageio.ImageIO;
import javax.inject.Inject;
import javax.inject.Singleton;
@@ -80,10 +82,11 @@ public class ImageCapture
*
* @param screenshot BufferedImage to capture.
* @param fileName Filename to use, without file extension.
* @param subDir Directory within the player screenshots dir to store the captured screenshot to.
* @param notify Send a notification to the system tray when the image is captured.
* @param imageUploadStyle which method to use to upload the screenshot (Imgur or directly to clipboard).
*/
public void takeScreenshot(BufferedImage screenshot, String fileName, boolean notify, ImageUploadStyle imageUploadStyle)
public void takeScreenshot(BufferedImage screenshot, String fileName, @Nullable String subDir, boolean notify, ImageUploadStyle imageUploadStyle)
{
if (client.getGameState() == GameState.LOGIN_SCREEN)
{
@@ -106,6 +109,12 @@ public class ImageCapture
{
playerDir += "-League";
}
if (!Strings.isNullOrEmpty(subDir))
{
playerDir += File.separator + subDir;
}
playerFolder = new File(SCREENSHOT_DIR, playerDir);
}
else
@@ -157,6 +166,20 @@ public class ImageCapture
}
}
/**
* Saves a screenshot of the client window to the screenshot folder as a PNG,
* and optionally uploads it to an image-hosting service.
*
* @param screenshot BufferedImage to capture.
* @param fileName Filename to use, without file extension.
* @param notify Send a notification to the system tray when the image is captured.
* @param imageUploadStyle which method to use to upload the screenshot (Imgur or directly to clipboard).
*/
public void takeScreenshot(BufferedImage screenshot, String fileName, boolean notify, ImageUploadStyle imageUploadStyle)
{
takeScreenshot(screenshot, fileName, null, notify, imageUploadStyle);
}
/**
* Uploads a screenshot to the Imgur image-hosting service,
* and copies the image link to the clipboard.