From 194f82e374c25e293879e7e3811046aea4dc2daf Mon Sep 17 00:00:00 2001 From: unknown <45179536+r3cp3ct@users.noreply.github.com> Date: Sun, 29 May 2022 20:13:45 +0300 Subject: [PATCH] Mouse buttons and scrolling Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com> Co-authored-by: sigonasr2 --- Java/scripts/md5 | 8 ++++---- src/sig/engine/Object.java | 9 +++++++++ src/sig/engine/Panel.java | 21 +++++++++++++++++---- src/sig/objects/LevelRenderer.java | 27 +++++++++++++++++++-------- utils/filelist | 2 +- utils/md5 | 8 ++++---- 6 files changed, 54 insertions(+), 21 deletions(-) diff --git a/Java/scripts/md5 b/Java/scripts/md5 index d4665a7..22a476c 100644 --- a/Java/scripts/md5 +++ b/Java/scripts/md5 @@ -1,4 +1,4 @@ -build.sh:55f0208b07ba384f45009d6f92fe88fe - -clean.sh:96ce35f2d2dcb555421e00a6afda23ca - -commit.sh:5e4448db9ad48e72ec3a1ff4f5763b41 - -jar.sh:56f9b7c6dc8e85f28ffefe9ce82b1f07 - +build.sh:55f0208b07ba384f45009d6f92fe88fe *- +clean.sh:96ce35f2d2dcb555421e00a6afda23ca *- +commit.sh:5e4448db9ad48e72ec3a1ff4f5763b41 *- +jar.sh:56f9b7c6dc8e85f28ffefe9ce82b1f07 *- diff --git a/src/sig/engine/Object.java b/src/sig/engine/Object.java index ec6b286..3903176 100644 --- a/src/sig/engine/Object.java +++ b/src/sig/engine/Object.java @@ -61,4 +61,13 @@ public abstract class Object implements GameEntity{ protected boolean KeyHeld(int key) { return panel.KEYS.getOrDefault(key,false); } + + protected boolean MouseHeld(int mb) { + return panel.MOUSE.getOrDefault(mb,false); + } + + protected boolean MouseScrolled(int scrolled) { + //-1 is UP, 1 is DOWN + return true; + } } diff --git a/src/sig/engine/Panel.java b/src/sig/engine/Panel.java index dc12d18..d693a17 100644 --- a/src/sig/engine/Panel.java +++ b/src/sig/engine/Panel.java @@ -12,6 +12,8 @@ import java.util.List; import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; import java.awt.event.MouseMotionListener; +import java.awt.event.MouseWheelEvent; +import java.awt.event.MouseWheelListener; import javax.swing.JFrame; import javax.swing.JPanel; @@ -40,12 +42,13 @@ public class Panel extends JPanel implements Runnable,KeyListener { boolean resizing=false; long lastUpdate=System.nanoTime(); final long TARGET_FRAMETIME = 8333333l; - boolean mouseHeld=false; public double nanaX = 0; public double nanaY = 0; public Point mousePos=new Point(0,0); + public int button = 0; public Point highlightedSquare = new Point(0,0); public HashMap KEYS = new HashMap<>(); + public HashMap MOUSE = new HashMap<>(); public Panel(JFrame f) { super(true); @@ -59,13 +62,14 @@ public class Panel extends JPanel implements Runnable,KeyListener { @Override public void mousePressed(MouseEvent e) { - mouseHeld=true; + MOUSE.put(e.getButton(),true); mousePos.set(e.getX()/RabiClone.SIZE_MULTIPLIER,e.getY()/RabiClone.SIZE_MULTIPLIER); + //System.out.println("Mouse List: "+MOUSE); } @Override public void mouseReleased(MouseEvent e) { - mouseHeld=false; + MOUSE.put(e.getButton(),false); mousePos.set(e.getX()/RabiClone.SIZE_MULTIPLIER,e.getY()/RabiClone.SIZE_MULTIPLIER); } @@ -86,7 +90,6 @@ public class Panel extends JPanel implements Runnable,KeyListener { } }); this.addMouseMotionListener(new MouseMotionListener(){ - @Override public void mouseDragged(MouseEvent e) { @@ -98,6 +101,16 @@ public class Panel extends JPanel implements Runnable,KeyListener { UpdateHighlightedSquare(); } }); + this.addMouseWheelListener(new MouseWheelListener(){ + //-1 is UP, 1 is DOWN + @Override + public void mouseWheelMoved(MouseWheelEvent e) { + for(int i=0; i