diff --git a/2006Scape Client/src/main/java/ClientSettings.java b/2006Scape Client/src/main/java/ClientSettings.java index 6f36b636..42a4ee86 100644 --- a/2006Scape Client/src/main/java/ClientSettings.java +++ b/2006Scape Client/src/main/java/ClientSettings.java @@ -116,6 +116,12 @@ public class ClientSettings { * FileServer Must Be Running Before Starting The Client If This Is True */ 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 diff --git a/2006Scape Client/src/main/java/Game.java b/2006Scape Client/src/main/java/Game.java index e565ebad..eff470a9 100644 --- a/2006Scape Client/src/main/java/Game.java +++ b/2006Scape Client/src/main/java/Game.java @@ -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() { diff --git a/2006Scape Client/src/main/java/Main.java b/2006Scape Client/src/main/java/Main.java index d36fbab3..fe9f3d95 100644 --- a/2006Scape Client/src/main/java/Main.java +++ b/2006Scape Client/src/main/java/Main.java @@ -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]) { diff --git a/2006Scape Client/src/main/java/RSFrame.java b/2006Scape Client/src/main/java/RSFrame.java index 1564d08f..05e50420 100644 --- a/2006Scape Client/src/main/java/RSFrame.java +++ b/2006Scape Client/src/main/java/RSFrame.java @@ -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);