Allow adjustments for all screen properties at each screen location through the editor

Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com>
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
main
sigonasr2 3 years ago
parent 82f9016255
commit 148c0ce2a1
  1. BIN
      maps/world1.map
  2. 6
      src/sig/engine/Object.java
  3. 6
      src/sig/engine/Panel.java
  4. 30
      src/sig/map/Maps.java
  5. 35
      src/sig/objects/EditorRenderer.java

Binary file not shown.

@ -82,6 +82,12 @@ public abstract class Object implements GameEntity{
return panel.KEYS.getOrDefault(key,false); return panel.KEYS.getOrDefault(key,false);
} }
protected void KeyPressed(int key) {
}
protected void KeyReleased(int key) {
}
protected boolean MouseHeld(int mb) { protected boolean MouseHeld(int mb) {
return panel.MOUSE.getOrDefault(mb,false); return panel.MOUSE.getOrDefault(mb,false);
} }

@ -421,12 +421,18 @@ public class Panel extends JPanel implements Runnable,KeyListener {
@Override @Override
public void keyPressed(KeyEvent e) { public void keyPressed(KeyEvent e) {
KEYS.put(e.getKeyCode(),true); KEYS.put(e.getKeyCode(),true);
for (int i=0;i<RabiClone.OBJ.size();i++) {
RabiClone.OBJ.get(i).KeyPressed(e.getKeyCode());
}
//System.out.println("Key List: "+KEYS); //System.out.println("Key List: "+KEYS);
} }
@Override @Override
public void keyReleased(KeyEvent e) { public void keyReleased(KeyEvent e) {
KEYS.put(e.getKeyCode(),false); KEYS.put(e.getKeyCode(),false);
for (int i=0;i<RabiClone.OBJ.size();i++) {
RabiClone.OBJ.get(i).KeyReleased(e.getKeyCode());
}
//System.out.println("Key List: "+KEYS); //System.out.println("Key List: "+KEYS);
} }
} }

@ -55,4 +55,34 @@ public enum Maps {
return Type.values()[this.map.types[index]]; return Type.values()[this.map.types[index]];
} }
} }
public void setView(int x,int y,View view) {
int index = (y/Tile.TILE_SCREEN_COUNT_Y)*(Map.MAP_WIDTH/Tile.TILE_WIDTH)+x/Tile.TILE_SCREEN_COUNT_X;
if (index>=0&&index<this.map.views.length) {
this.map.views[index]=(byte)view.ordinal();
}
}
public void setType(int x,int y,Type type) {
int index = (y/Tile.TILE_SCREEN_COUNT_Y)*(Map.MAP_WIDTH/Tile.TILE_WIDTH)+x/Tile.TILE_SCREEN_COUNT_X;
if (index>=0&&index<this.map.types.length) {
this.map.types[index]=(byte)type.ordinal();
}
}
public Background getBackground(int x,int y) {
int index = (y/Tile.TILE_SCREEN_COUNT_Y)*(Map.MAP_WIDTH/Tile.TILE_WIDTH)+x/Tile.TILE_SCREEN_COUNT_X;
if (index<0||index>=this.map.backgrounds.length) {
return Background.DEFAULT;
} else {
return Background.values()[this.map.backgrounds[index]];
}
}
public void setBackground(int x,int y,Background background) {
int index = (y/Tile.TILE_SCREEN_COUNT_Y)*(Map.MAP_WIDTH/Tile.TILE_WIDTH)+x/Tile.TILE_SCREEN_COUNT_X;
if (index>=0&&index<this.map.backgrounds.length) {
this.map.backgrounds[index]=(byte)background.ordinal();
}
}
} }

@ -11,8 +11,11 @@ import sig.engine.MouseScrollValue;
import sig.engine.PaletteColor; import sig.engine.PaletteColor;
import sig.engine.Panel; import sig.engine.Panel;
import sig.engine.Sprite; import sig.engine.Sprite;
import sig.map.Background;
import sig.map.Map; import sig.map.Map;
import sig.map.Tile; import sig.map.Tile;
import sig.map.View;
import sig.map.Type;
public class EditorRenderer extends LevelRenderer{ public class EditorRenderer extends LevelRenderer{
@ -22,6 +25,10 @@ public class EditorRenderer extends LevelRenderer{
final static long MESSAGE_TIME = 5000; final static long MESSAGE_TIME = 5000;
long last_message_log = System.currentTimeMillis(); long last_message_log = System.currentTimeMillis();
final static StringBuilder HELP_TEXT = new StringBuilder("(F3) Toggle Camera (F4) Toggle Map Type (F5) Toggle Background");
final static char CAMERA_SPD = 512;
public EditorRenderer(Panel panel) { public EditorRenderer(Panel panel) {
super(panel); super(panel);
setX(3.5*Tile.TILE_WIDTH); setX(3.5*Tile.TILE_WIDTH);
@ -47,12 +54,12 @@ public class EditorRenderer extends LevelRenderer{
int left = KeyHeld(KeyEvent.VK_LEFT)||KeyHeld(KeyEvent.VK_A)?1:0; int left = KeyHeld(KeyEvent.VK_LEFT)||KeyHeld(KeyEvent.VK_A)?1:0;
int up = KeyHeld(KeyEvent.VK_UP)||KeyHeld(KeyEvent.VK_W)?1:0; int up = KeyHeld(KeyEvent.VK_UP)||KeyHeld(KeyEvent.VK_W)?1:0;
int down = KeyHeld(KeyEvent.VK_DOWN)||KeyHeld(KeyEvent.VK_S)?1:0; int down = KeyHeld(KeyEvent.VK_DOWN)||KeyHeld(KeyEvent.VK_S)?1:0;
/*if (right-left!=0) { if (right-left!=0) {
setX(getX()+(right-left)*512*updateMult); setX(getX()+(right-left)*CAMERA_SPD*updateMult);
} }
if (up-down!=0) { if (up-down!=0) {
setY(getY()+(down-up)*512*updateMult); setY(getY()+(down-up)*CAMERA_SPD*updateMult);
}*/ }
boolean left_mb = MouseHeld(MouseEvent.BUTTON1); boolean left_mb = MouseHeld(MouseEvent.BUTTON1);
boolean middle_mb = MouseHeld(MouseEvent.BUTTON2); boolean middle_mb = MouseHeld(MouseEvent.BUTTON2);
boolean right_mb = MouseHeld(MouseEvent.BUTTON3); boolean right_mb = MouseHeld(MouseEvent.BUTTON3);
@ -118,16 +125,17 @@ public class EditorRenderer extends LevelRenderer{
} }
} }
Draw_Text(4,0,messageLog,Font.PROFONT_12); Draw_Text(4,0,messageLog,Font.PROFONT_12);
Draw_Text(4,RabiClone.BASE_HEIGHT-Font.PROFONT_12.getGlyphHeight()-4,HELP_TEXT,Font.PROFONT_12);
} }
private void drawTileGrid(byte[] p, int x, int y) { private void drawTileGrid(byte[] p, int x, int y) {
if (x%Tile.TILE_SCREEN_COUNT_X==0&&y%Tile.TILE_SCREEN_COUNT_Y==0) { if (x%Tile.TILE_SCREEN_COUNT_X==0&&y%Tile.TILE_SCREEN_COUNT_Y==0) {
int xpos=(int)(x*Tile.TILE_WIDTH-getX()); int xpos=(int)(x*Tile.TILE_WIDTH-getX());
int ypos=(int)(y*Tile.TILE_HEIGHT-getY()); int ypos=(int)(y*Tile.TILE_HEIGHT-getY());
int index=ypos*Map.MAP_WIDTH+xpos;
Draw_Text(xpos+2,ypos+2, Draw_Text(xpos+2,ypos+2,
new StringBuilder("View:").append(PaletteColor.EMERALD).append(RabiClone.CURRENT_MAP.getView(x,y).ordinal()) 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("\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())
,Font.PROFONT_12); ,Font.PROFONT_12);
} }
if (x%Tile.TILE_SCREEN_COUNT_X==0) { if (x%Tile.TILE_SCREEN_COUNT_X==0) {
@ -163,5 +171,22 @@ public class EditorRenderer extends LevelRenderer{
Draw_Text(tileX+2,tileY-Font.PROFONT_12.getGlyphHeight()-2,new StringBuilder(selectedTile.toString()),Font.PROFONT_12); Draw_Text(tileX+2,tileY-Font.PROFONT_12.getGlyphHeight()-2,new StringBuilder(selectedTile.toString()),Font.PROFONT_12);
Draw_Text_Ext(tileX+2,tileY+Tile.TILE_HEIGHT+2,new StringBuilder(RabiClone.CURRENT_MAP.getTile(x,y).toString()),Font.PROFONT_12,Alpha.ALPHA0,PaletteColor.CRIMSON); Draw_Text_Ext(tileX+2,tileY+Tile.TILE_HEIGHT+2,new StringBuilder(RabiClone.CURRENT_MAP.getTile(x,y).toString()),Font.PROFONT_12,Alpha.ALPHA0,PaletteColor.CRIMSON);
} }
}
@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;
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]);
}break;
case KeyEvent.VK_F4:{
RabiClone.CURRENT_MAP.setType(screenX,screenY,Type.values()[(RabiClone.CURRENT_MAP.getType(screenX, screenY).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]);
}break;
}
} }
} }

Loading…
Cancel
Save