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 <sigonasr2@gmail.com>
main
sigonasr2 3 years ago
parent 148c0ce2a1
commit 7ad3bef8ca
  1. BIN
      maps/world1.map
  2. 11
      src/sig/engine/Panel.java
  3. 24
      src/sig/objects/EditorRenderer.java

Binary file not shown.

@ -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<Integer,Boolean> KEYS = new HashMap<>();
public HashMap<Integer,Boolean> 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

@ -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;
}
}

Loading…
Cancel
Save