From 7ad3bef8ca4503e8c9544756716fcb72601faef0 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Thu, 2 Jun 2022 22:02:59 -0500 Subject: [PATCH] Make tile dragging and placing easier to accomplish. Also refactored old mouse detection code Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com> Co-authored-by: sigonasr2 --- maps/world1.map | Bin 295488 -> 295488 bytes src/sig/engine/Panel.java | 11 +---------- src/sig/objects/EditorRenderer.java | 24 ++++++++++++++---------- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/maps/world1.map b/maps/world1.map index 0798e2e716613f0eeab4a823357a97630dff4742..67eddc0b43e2dd3609eff4611cf7f4b250fd8b2d 100644 GIT binary patch delta 333 zcmX@mB6OfdXal#*M(!WX(u@o^;RbdVM#c%!oB3_-F;C{VQ35l7B8p%JGf>|Ic`%ce zk%0lokp*)m^V_gNwVeZL698hKiHu?}Ngkl2D2&4gGG+5W>-#X35KDksBsk&j+5nan z0tyPi^r3Kg*r7@{*}MgrgKQfc&}~3CK^&$NZUKa$2)6}SH~?*L=J#ml_h1BKCLm_s Q&hNqUh<`g{1B*Qq02wDpKL7v# delta 186 zcmX@mB6OfdXalzlD&WZA5!@D;3< y6QUNVeZyO3cP0j^z|D#U$N3k_7w|O87qrV4Faj|X5HoK!DEMT)ow0$%o(TYxC>qcJ diff --git a/src/sig/engine/Panel.java b/src/sig/engine/Panel.java index 02a9cf1..12df8e9 100644 --- a/src/sig/engine/Panel.java +++ b/src/sig/engine/Panel.java @@ -21,7 +21,6 @@ import java.awt.event.KeyListener; import sig.DrawLoop; import sig.RabiClone; -import sig.map.Tile; public class Panel extends JPanel implements Runnable,KeyListener { JFrame window; @@ -45,7 +44,6 @@ public class Panel extends JPanel implements Runnable,KeyListener { 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 static byte[] generalPalette = new byte[]{ @@ -125,13 +123,12 @@ public class Panel extends JPanel implements Runnable,KeyListener { this.addMouseMotionListener(new MouseMotionListener(){ @Override public void mouseDragged(MouseEvent e) { - + mousePos.set(e.getX()/RabiClone.SIZE_MULTIPLIER,e.getY()/RabiClone.SIZE_MULTIPLIER); } @Override public void mouseMoved(MouseEvent e) { mousePos.set(e.getX()/RabiClone.SIZE_MULTIPLIER,e.getY()/RabiClone.SIZE_MULTIPLIER); - UpdateHighlightedSquare(); } }); this.addMouseWheelListener(new MouseWheelListener(){ @@ -147,12 +144,6 @@ public class Panel extends JPanel implements Runnable,KeyListener { }); } - private static void UpdateHighlightedSquare() { - RabiClone.p.highlightedSquare.setX((int)((RabiClone.level_renderer.getX()+RabiClone.MOUSE_POS.getX())/Tile.TILE_WIDTH)); - RabiClone.p.highlightedSquare.setY((int)((RabiClone.level_renderer.getY()+RabiClone.MOUSE_POS.getY())/Tile.TILE_HEIGHT)); - //System.out.println(RabiClone.p.highlightedSquare); - } - /** * Get Best Color model available for current screen. * @return color model diff --git a/src/sig/objects/EditorRenderer.java b/src/sig/objects/EditorRenderer.java index 2a63fe8..bff1d34 100644 --- a/src/sig/objects/EditorRenderer.java +++ b/src/sig/objects/EditorRenderer.java @@ -65,7 +65,9 @@ public class EditorRenderer extends LevelRenderer{ boolean right_mb = MouseHeld(MouseEvent.BUTTON3); if(left_mb){ - RabiClone.CURRENT_MAP.ModifyTile(RabiClone.p.highlightedSquare.getX(), RabiClone.p.highlightedSquare.getY(), selectedTile); + int tileX = (int)(RabiClone.MOUSE_POS.getX()+getX())/Tile.TILE_WIDTH; + int tileY = (int)(RabiClone.MOUSE_POS.getY()+getY())/Tile.TILE_HEIGHT; + RabiClone.CURRENT_MAP.ModifyTile(tileX, tileY, selectedTile); } if(KeyHeld(KeyEvent.VK_CONTROL)&&KeyHeld(KeyEvent.VK_S)){ AddMessage("Saving map..."); @@ -133,9 +135,9 @@ public class EditorRenderer extends LevelRenderer{ int xpos=(int)(x*Tile.TILE_WIDTH-getX()); int ypos=(int)(y*Tile.TILE_HEIGHT-getY()); Draw_Text(xpos+2,ypos+2, - new StringBuilder("View:").append(PaletteColor.EMERALD).append(RabiClone.CURRENT_MAP.getView(x,y).ordinal()) - .append(PaletteColor.NORMAL).append("\nType:").append(PaletteColor.MIDNIGHT_BLUE).append(RabiClone.CURRENT_MAP.getType(x,y).ordinal()) - .append(PaletteColor.NORMAL).append("\nBackground:").append(PaletteColor.GRAPE).append(RabiClone.CURRENT_MAP.getBackground(x,y).ordinal()) + new StringBuilder("View:").append(PaletteColor.EMERALD).append(RabiClone.CURRENT_MAP.getView(x,y)) + .append(PaletteColor.NORMAL).append("\nType:").append(PaletteColor.MIDNIGHT_BLUE).append(RabiClone.CURRENT_MAP.getType(x,y)) + .append(PaletteColor.NORMAL).append("\nBackground:").append(PaletteColor.GRAPE).append(RabiClone.CURRENT_MAP.getBackground(x,y)) ,Font.PROFONT_12); } if (x%Tile.TILE_SCREEN_COUNT_X==0) { @@ -164,7 +166,9 @@ public class EditorRenderer extends LevelRenderer{ @Override protected void drawMapTileForEditorMode(int x, int y) { - if (x==RabiClone.p.highlightedSquare.getX()&&y==RabiClone.p.highlightedSquare.getY()) { + int tilerX = (int)(RabiClone.MOUSE_POS.getX()+getX())/Tile.TILE_WIDTH; + int tilerY = (int)(RabiClone.MOUSE_POS.getY()+getY())/Tile.TILE_HEIGHT; + if (x==tilerX&&y==tilerY) { double tileX = x*Tile.TILE_WIDTH-this.getX(); double tileY = y*Tile.TILE_HEIGHT-this.getY(); DrawTransparentTile(tileX,tileY,selectedTile,Alpha.ALPHA160); @@ -175,17 +179,17 @@ public class EditorRenderer extends LevelRenderer{ @Override protected void KeyPressed(int key) { - int screenX = (int)(RabiClone.MOUSE_POS.getX()+getX())/Tile.TILE_WIDTH; - int screenY = (int)(RabiClone.MOUSE_POS.getY()+getY())/Tile.TILE_HEIGHT; + int tileX = (int)(RabiClone.MOUSE_POS.getX()+getX())/Tile.TILE_WIDTH; + int tileY = (int)(RabiClone.MOUSE_POS.getY()+getY())/Tile.TILE_HEIGHT; switch (key) { case KeyEvent.VK_F3:{ - RabiClone.CURRENT_MAP.setView(screenX,screenY,View.values()[(RabiClone.CURRENT_MAP.getView(screenX, screenY).ordinal()+1)%View.values().length]); + RabiClone.CURRENT_MAP.setView(tileX,tileY,View.values()[(RabiClone.CURRENT_MAP.getView(tileX, tileY).ordinal()+1)%View.values().length]); }break; case KeyEvent.VK_F4:{ - RabiClone.CURRENT_MAP.setType(screenX,screenY,Type.values()[(RabiClone.CURRENT_MAP.getType(screenX, screenY).ordinal()+1)%Type.values().length]); + RabiClone.CURRENT_MAP.setType(tileX,tileY,Type.values()[(RabiClone.CURRENT_MAP.getType(tileX, tileY).ordinal()+1)%Type.values().length]); }break; case KeyEvent.VK_F5:{ - RabiClone.CURRENT_MAP.setBackground(screenX,screenY,Background.values()[(RabiClone.CURRENT_MAP.getBackground(screenX, screenY).ordinal()+1)%Background.values().length]); + RabiClone.CURRENT_MAP.setBackground(tileX,tileY,Background.values()[(RabiClone.CURRENT_MAP.getBackground(tileX, tileY).ordinal()+1)%Background.values().length]); }break; } }