Added Screenshots (#656)

* Added ability to take screenshots

Since we have a screenshots folder in the 2006Scape folder in the home path, we might as well make use of it.

* Removed duplicate screenshot warning message

We don't need a warning message for duplicate screenshots, if it takes screenshots that's good enough.

* Added subfolders option for screenshots

This allows for much more flexibility when it comes to screenshots because we can choose any number of levels of subfolders.

* Removed unused code

* Added check for screenshots

* Fixed screenshots NPE when logged out

* Added Local to titlebar when running locally

* Added sendMessage param for screenshots

* Default to send messages for screenshots

* Use the sendMessage variable

Oops lol

* Added ability to take screenshots

Since we have a screenshots folder in the 2006Scape folder in the home path, we might as well make use of it.

* Removed duplicate screenshot warning message

We don't need a warning message for duplicate screenshots, if it takes screenshots that's good enough.

* Added subfolders option for screenshots

This allows for much more flexibility when it comes to screenshots because we can choose any number of levels of subfolders.

* Removed unused code

* Added check for screenshots

* Fixed screenshots NPE when logged out

* Added Local to titlebar when running locally

* Added sendMessage param for screenshots

* Default to send messages for screenshots

* Use the sendMessage variable

Oops lol

* Added screenshots QOL option

* Use server name var for screenshots
This commit is contained in:
ipkpjersi
2024-09-20 21:30:53 -04:00
committed by GitHub
parent 86e7b93b3b
commit fd731242dd
4 changed files with 62 additions and 2 deletions
@@ -117,6 +117,12 @@ public class ClientSettings {
*/
public static boolean CHECK_CRC = true;
/**
* @QoL
* Enables the ability to take screenshots
*/
public static boolean SCREENSHOTS_ENABLED = false;
/**
* The Npc Bits for the Server
*/
+50
View File
@@ -3,12 +3,14 @@
* THIS IS TO ALLOW LOCAL PARABOT TO CONTINUE TO WORK
*/
import javax.imageio.ImageIO;
import javax.swing.*;
import java.applet.AppletContext;
import java.awt.*;
import java.awt.datatransfer.*;
import java.awt.event.KeyEvent;
import java.awt.event.MouseWheelEvent;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.EOFException;
@@ -23,6 +25,7 @@ import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.zip.CRC32;
@@ -5587,7 +5590,51 @@ public class Game extends RSApplet {
}
}
public void screenshot(boolean sendMessage, String... subfolders) {
try {
Window window = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow();
if (window == null) {
return;
}
Point point = window.getLocationOnScreen();
int x = (int) point.getX();
int y = (int) point.getY();
int w = window.getWidth();
int h = window.getHeight();
Robot robot = new Robot(window.getGraphicsConfiguration().getDevice());
Rectangle captureSize = new Rectangle(x, y, w, h);
BufferedImage bufferedimage = robot.createScreenCapture(captureSize);
// Format the current date and time
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy_MM_dd-HH_mm_ss");
String dateTime = dateFormat.format(new Date());
// Update the file path and naming
String fileExtension = myUsername != null && !myUsername.isEmpty() ? myUsername : ClientSettings.SERVER_NAME;
String subfolderPath = String.join(File.separator, subfolders);
if (!subfolderPath.isEmpty()) {
subfolderPath += File.separator;
}
String screenshotDir = System.getProperty("user.home") + File.separatorChar + ClientSettings.SERVER_NAME + File.separatorChar + "screenshots" + File.separatorChar + subfolderPath;
File dir = new File(screenshotDir);
if (!dir.exists()) {
dir.mkdirs(); // Create the directory if it doesn't exist
}
File file = new File(screenshotDir, fileExtension + "_" + dateTime + ".png");
if (!file.exists()) {
ImageIO.write(bufferedimage, "png", file);
if (sendMessage) {
pushMessage("A picture has been saved in your screenshots folder.", 0, "");
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
public void pushMessage(String s, int i, String s1) {
if (i == 0 && dialogID != -1) {
aString844 = s;
@@ -12654,6 +12701,9 @@ public class Game extends RSApplet {
}
}
if (ClientSettings.SCREENSHOTS_ENABLED && keyevent.getKeyCode() == KeyEvent.VK_PRINTSCREEN && keyevent.isControlDown()) {
screenshot(true);
}
}
public long calculateTotalExp() {
+4
View File
@@ -54,6 +54,10 @@ public final class Main {
case"-show-zoom":
ClientSettings.SHOW_ZOOM_LEVEL_MESSAGES = true;
break;
case"-screenshots":
case"-enable-screenshots":
ClientSettings.SCREENSHOTS_ENABLED = true;
break;
}
if (args[i].startsWith("-") && (i + 1) < args.length && !args[i + 1].startsWith("-")) {
switch(args[i]) {
+1 -1
View File
@@ -9,7 +9,7 @@ final class RSFrame extends Frame {
public RSFrame(RSApplet applet) {
rsApplet = applet;
setTitle(ClientSettings.SERVER_NAME + " World: " + ClientSettings.SERVER_WORLD);
setTitle(ClientSettings.SERVER_NAME + " World: " + ClientSettings.SERVER_WORLD + ((ClientSettings.SERVER_IP.equals("localhost") || ClientSettings.SERVER_IP.equals("127.0.0.1")) ? " [Local]" : ""));
this.setResizable(false);
this.setBackground(Color.BLACK);