Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Screenshots #656

Merged
merged 23 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
863ffde
Added ability to take screenshots
ipkpjersi Dec 27, 2023
4c65665
Removed duplicate screenshot warning message
ipkpjersi Dec 27, 2023
9dc9625
Added subfolders option for screenshots
ipkpjersi Dec 29, 2023
02a1707
Removed unused code
ipkpjersi Jan 6, 2024
4858e16
Added check for screenshots
ipkpjersi Jan 6, 2024
0b694a2
Fixed screenshots NPE when logged out
ipkpjersi Jan 9, 2024
edfb4ec
Added Local to titlebar when running locally
ipkpjersi Jan 9, 2024
1d15c2c
Added sendMessage param for screenshots
ipkpjersi Apr 13, 2024
a315467
Default to send messages for screenshots
ipkpjersi Apr 13, 2024
db5f9d2
Use the sendMessage variable
ipkpjersi Apr 13, 2024
38a22a3
Added ability to take screenshots
ipkpjersi Dec 27, 2023
a6b3718
Removed duplicate screenshot warning message
ipkpjersi Dec 27, 2023
cab34b6
Added subfolders option for screenshots
ipkpjersi Dec 29, 2023
930756b
Removed unused code
ipkpjersi Jan 6, 2024
50b6dc0
Added check for screenshots
ipkpjersi Jan 6, 2024
df2f1fc
Fixed screenshots NPE when logged out
ipkpjersi Jan 9, 2024
9625128
Added Local to titlebar when running locally
ipkpjersi Jan 9, 2024
fb0bfdb
Added sendMessage param for screenshots
ipkpjersi Apr 13, 2024
dc5a790
Default to send messages for screenshots
ipkpjersi Apr 13, 2024
97eddef
Use the sendMessage variable
ipkpjersi Apr 13, 2024
dc8dc30
Merge branch 'screenshots' of https://github.com/ipkpjersi/2006Scape …
ipkpjersi Sep 21, 2024
6037672
Added screenshots QOL option
ipkpjersi Sep 21, 2024
0792bc8
Use server name var for screenshots
ipkpjersi Sep 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions 2006Scape Client/src/main/java/ClientSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
52 changes: 51 additions & 1 deletion 2006Scape Client/src/main/java/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,6 +25,7 @@
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;
Expand Down Expand Up @@ -5587,7 +5590,51 @@ public void drawSplitpublicChat() {
}

}

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 : "2006Scape";

String subfolderPath = String.join(File.separator, subfolders);
if (!subfolderPath.isEmpty()) {
subfolderPath += File.separator;
}

String screenshotDir = System.getProperty("user.home") + File.separatorChar + "2006Scape" + File.separatorChar + "screenshots" + File.separatorChar + subfolderPath;
ipkpjersi marked this conversation as resolved.
Show resolved Hide resolved
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;
Expand Down Expand Up @@ -12654,6 +12701,9 @@ public void keyPressed(KeyEvent keyevent)
}

}
if (ClientSettings.SCREENSHOTS_ENABLED && keyevent.getKeyCode() == KeyEvent.VK_PRINTSCREEN && keyevent.isControlDown()) {
screenshot(true);
}
}

public long calculateTotalExp() {
Expand Down
4 changes: 4 additions & 0 deletions 2006Scape Client/src/main/java/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ public static void main(String[] args) {
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]) {
Expand Down
2 changes: 1 addition & 1 deletion 2006Scape Client/src/main/java/RSFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Loading