From 205cf521b1ec7ecc139281ca6ef352995f296aee Mon Sep 17 00:00:00 2001 From: Ethan Chapman Date: Tue, 9 Jan 2024 17:32:07 -0500 Subject: [PATCH] Rename "Return" to "Close", add new CHM controls Some of these might come to other mods in the future, not sure --- .../java/chokistream/ChirunoModClient.java | 100 +++++++++++++----- .../java/chokistream/KeypressHandler.java | 12 ++- src/main/java/chokistream/SwingGUI.java | 12 ++- src/main/java/chokistream/props/Controls.java | 9 +- 4 files changed, 103 insertions(+), 30 deletions(-) diff --git a/src/main/java/chokistream/ChirunoModClient.java b/src/main/java/chokistream/ChirunoModClient.java index c8d12e4..71718ba 100644 --- a/src/main/java/chokistream/ChirunoModClient.java +++ b/src/main/java/chokistream/ChirunoModClient.java @@ -27,13 +27,19 @@ public class ChirunoModClient implements StreamingInterface { private InputStream in = null; private OutputStream out = null; private ColorMode colorMode; - public int quality; private BufferedImage lastTopImage; private BufferedImage lastBottomImage; private int topFrames; private int bottomFrames; + // Remember settings for future use + private int quality; + private int cpuLimit; + private boolean tga; + private boolean interlace; + private DSScreenBoth screen; + private static final int FORMAT_MASK = 0b00000111; private static final int TGA_MASK = 0b00001000; private static final int SCREEN_MASK = 0b00010000; @@ -57,6 +63,12 @@ public class ChirunoModClient implements StreamingInterface { */ public ChirunoModClient(String host, int quality, boolean reqTGA, boolean interlace, int capCPU, ColorMode receivedColorMode, int port, DSScreenBoth reqScreen) throws UnknownHostException, IOException { + this.quality = quality; + this.cpuLimit = capCPU; + this.tga = reqTGA; + this.screen = reqScreen; + this.interlace = interlace; + // Connect to TCP port and set up client client = new Socket(host, port); client.setTcpNoDelay(true); @@ -64,7 +76,6 @@ public ChirunoModClient(String host, int quality, boolean reqTGA, boolean interl out = client.getOutputStream(); this.colorMode = receivedColorMode; - this.quality = quality; lastTopImage = new BufferedImage(400, 240, BufferedImage.TYPE_INT_RGB); lastBottomImage = new BufferedImage(320, 240, BufferedImage.TYPE_INT_RGB); @@ -93,28 +104,6 @@ public void sendQuality(int quality) throws IOException { out.write((new Packet((byte)0x04, (byte)0x01, new byte[] {(byte)quality})).pack); } - // Increase quality by a certain amount, up to 100 - public void increaseQuality(int delta) throws IOException { - if(quality + delta < 100) { - quality = quality + delta; - sendQuality(quality); - } else if(quality < 100) { - quality = 100; - sendQuality(100); - } - } - - // Decrease quality by a certain amount, down to 0 - public void decreaseQuality(int delta) throws IOException { - if(quality - delta > 0) { - quality = quality - delta; - sendQuality(quality); - } else if(quality > 0) { - quality = 0; - sendQuality(0); - } - } - public void sendScreen(DSScreenBoth screen) throws IOException { logger.log("Sending screen packet of "+screen.getLongName(), LogLevel.VERBOSE); byte scr = switch(screen) { @@ -152,6 +141,69 @@ public void sendDebug(byte[] debugData) throws IOException { logger.log("Sending debug packet", LogLevel.VERBOSE); out.write((new Packet((byte)0xFF, (byte)0x00, debugData)).pack); } + + // Increase quality by a certain amount, up to 100 + public void increaseQuality(int delta) throws IOException { + if(quality + delta < 100) { + quality = quality + delta; + sendQuality(quality); + } else if(quality < 100) { + quality = 100; + sendQuality(100); + } + } + + // Decrease quality by a certain amount, down to 1 + public void decreaseQuality(int delta) throws IOException { + if(quality - delta > 1) { + quality = quality - delta; + sendQuality(quality); + } else if(quality > 1) { + quality = 1; + sendQuality(1); + } + } + + // Increase CPU cap by a certain amount, up to 100 + public void increaseCPU(int delta) throws IOException { + if(cpuLimit + delta < 100) { + cpuLimit = cpuLimit + delta; + sendLimitCPU(cpuLimit); + } else if(cpuLimit < 100) { + cpuLimit = 100; + sendLimitCPU(100); + } + } + + // Decrease CPU cap by a certain amount, down to 0 + public void decreaseCPU(int delta) throws IOException { + if(cpuLimit - delta > 0) { + cpuLimit = cpuLimit - delta; + sendLimitCPU(cpuLimit); + } else if(cpuLimit > 0) { + cpuLimit = 0; + sendLimitCPU(0); + } + } + + public void toggleTGA() throws IOException { + tga = !tga; + sendImageType(tga); + } + + public void toggleInterlacing() throws IOException { + interlace = !interlace; + sendInterlace(interlace); + } + + public void switchScreen() throws IOException { + screen = switch(screen) { + case TOP -> DSScreenBoth.BOTTOM; + case BOTTOM -> DSScreenBoth.BOTH; + case BOTH -> DSScreenBoth.TOP; + }; + sendScreen(screen); + } @Override public void close() throws IOException { diff --git a/src/main/java/chokistream/KeypressHandler.java b/src/main/java/chokistream/KeypressHandler.java index 96cd465..c8b5cd2 100644 --- a/src/main/java/chokistream/KeypressHandler.java +++ b/src/main/java/chokistream/KeypressHandler.java @@ -23,7 +23,7 @@ public void keyPressed(KeyEvent e) { // Generic commands if(ck.get(Controls.SCREENSHOT).matches(e)) { output.screenshot(); - } else if(ck.get(Controls.RETURN).matches(e)) { + } else if(ck.get(Controls.CLOSE).matches(e)) { output.kill(); } @@ -44,6 +44,16 @@ public void keyPressed(KeyEvent e) { c.increaseQuality(1); } else if(ck.get(Controls.QUALITY_DOWN).matches(e)) { c.decreaseQuality(1); + } else if(ck.get(Controls.CPU_UP).matches(e)) { + c.increaseCPU(1); + } else if(ck.get(Controls.CPU_DOWN).matches(e)) { + c.decreaseCPU(1); + } else if(ck.get(Controls.TGA).matches(e)) { + c.toggleTGA(); + } else if(ck.get(Controls.REQ_SCREEN).matches(e)) { + c.switchScreen(); + } else if(ck.get(Controls.INTERLACE).matches(e)) { + c.toggleInterlacing(); } } } catch(IOException e1) { diff --git a/src/main/java/chokistream/SwingGUI.java b/src/main/java/chokistream/SwingGUI.java index 56eee20..581ad58 100644 --- a/src/main/java/chokistream/SwingGUI.java +++ b/src/main/java/chokistream/SwingGUI.java @@ -599,18 +599,24 @@ public void createControls() { add(header, p, c, 0, 0, 2, 1); add(new JLabel(Controls.SCREENSHOT.getLongName()), p, c, 0, 1); - add(new JLabel(Controls.RETURN.getLongName()), p, c, 0, 2); + add(new JLabel(Controls.CLOSE.getLongName()), p, c, 0, 2); add(new JLabel(Controls.QUALITY_UP.getLongName()), p, c, 0, 3); add(new JLabel(Controls.QUALITY_DOWN.getLongName()), p, c, 0, 4); + add(new JLabel(Controls.REQ_SCREEN.getLongName()), p, c, 0, 5); + add(new JLabel(Controls.TGA.getLongName()), p, c, 0, 6); + add(new JLabel(Controls.INTERLACE.getLongName()), p, c, 0, 7); // Temporary, for layout controlsFields.put(Controls.SCREENSHOT, add(new JTextField(), p, c, 1, 1)); - controlsFields.put(Controls.RETURN, add(new JTextField(), p, c, 1, 2)); + controlsFields.put(Controls.CLOSE, add(new JTextField(), p, c, 1, 2)); controlsFields.put(Controls.QUALITY_UP, add(new JTextField(), p, c, 1, 3)); controlsFields.put(Controls.QUALITY_DOWN, add(new JTextField(), p, c, 1, 4)); + controlsFields.put(Controls.REQ_SCREEN, add(new JTextField(), p, c, 1, 5)); + controlsFields.put(Controls.TGA, add(new JTextField(), p, c, 1, 6)); + controlsFields.put(Controls.INTERLACE, add(new JTextField(), p, c, 1, 7)); JButton apply = new JButton("Apply"); - add(apply, p, c, 0, 5, 2, 1); + add(apply, p, c, 0, 8, 2, 1); apply.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { diff --git a/src/main/java/chokistream/props/Controls.java b/src/main/java/chokistream/props/Controls.java index 368eacf..b237a6a 100644 --- a/src/main/java/chokistream/props/Controls.java +++ b/src/main/java/chokistream/props/Controls.java @@ -7,9 +7,14 @@ public enum Controls { SCREENSHOT("screenshot", "Screenshot", new Input(KeyEvent.VK_S)), - RETURN("return", "Return", new Input(KeyEvent.VK_BACK_SPACE)), + CLOSE("close", "Close", new Input(KeyEvent.VK_BACK_SPACE)), QUALITY_UP("quality_up", "Increase Quality", new Input(KeyEvent.VK_UP)), - QUALITY_DOWN("quality_down", "Decrease Quality", new Input(KeyEvent.VK_DOWN)); + QUALITY_DOWN("quality_down", "Decrease Quality", new Input(KeyEvent.VK_DOWN)), + CPU_UP("cpu_up", "Increase CPU Cap", new Input(KeyEvent.VK_BRACERIGHT)), + CPU_DOWN("cpu_down", "Decrease CPU Cap", new Input(KeyEvent.VK_BRACELEFT)), + REQ_SCREEN("req_screen","Switch requested screen", new Input(KeyEvent.VK_R)), + INTERLACE("interlace","Toggle interlacing", new Input(KeyEvent.VK_I)), + TGA("tga","Toggle TGA", new Input(KeyEvent.VK_T)); private String shortName; private String longName;