Include draw line function and better visuals to indicate deleting a keybind

Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com>
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
main
sigonasr2, Sig, Sigo 3 years ago committed by GitHub
parent 56cef8c828
commit 6c5c2b1c67
  1. BIN
      bin/RabiClone.jar
  2. 52
      src/sig/DrawLoop.java
  3. 8
      src/sig/engine/Object.java
  4. 1
      src/sig/engine/Panel.java
  5. 14
      src/sig/objects/ConfigureControls.java

Binary file not shown.

@ -67,8 +67,58 @@ public class DrawLoop {
} }
} }
} }
public static void Draw_Line(byte[] canvas,int x1,int y1,int x2,int y2,byte col,Alpha alpha) {
int x,y,dx,dy,dx1,dy1,px,py,xe,ye;
dx=x2-x1;dy=y2-y1;
dx1=Math.abs(dx);dy1=Math.abs(dy);
px=2*dy1-dx1;py=2*dx1-dy1;
if (dy1<=dx1) {
if (dx>=0) {
x=x1;y=y1;xe=x2-1;
} else {
x=x2-1;y=y2-1;xe=x1;
}
Draw(canvas,y*RabiClone.BASE_WIDTH+x,col,alpha);
while (x<xe) {
x=x+1;
if (px<0) {
px=px+2*dy1;
} else {
if ((dx<0&&dy<0)||(dx>0&&dy>0)) {
y=y+1;
} else {
y=y-1;
}
px=px+2*(dy1-dx1);
}
Draw(canvas,y*RabiClone.BASE_WIDTH+x,col,alpha);
}
} else {
if (dy>=0) {
x=x1;y=y1;ye=y2-1;
} else {
x=x2-1;y=y2-1;ye=y1;
}
Draw(canvas,y*RabiClone.BASE_WIDTH+x,col,alpha);
while (y<ye) {
y=y+1;
if (py<=0) {
py=py+2*dx1;
} else {
if ((dx<0&&dy<0)||(dx>0&&dy>0)) {
x=x+1;
} else {
x=x-1;
}
py=py+2*(dx1-dy1);
}
Draw(canvas,y*RabiClone.BASE_WIDTH+x,col,alpha);
}
}
}
public static void FillRect(byte[] p,byte col,double x,double y,double w,double h) { public static void Fill_Rect(byte[] p,byte col,double x,double y,double w,double h) {
for (int xx=0;xx<w;xx++) { for (int xx=0;xx<w;xx++) {
for (int yy=0;yy<h;yy++) { for (int yy=0;yy<h;yy++) {
int index = ((int)y+yy)*RabiClone.BASE_WIDTH+(int)x+xx; int index = ((int)y+yy)*RabiClone.BASE_WIDTH+(int)x+xx;

@ -58,8 +58,12 @@ public abstract class Object implements GameEntity{
DrawLoop.Draw(canvas, index, (byte)col.ordinal(), alpha); DrawLoop.Draw(canvas, index, (byte)col.ordinal(), alpha);
} }
protected void Draw_Rect(byte[] p,byte col,double x,double y,double w,double h) { protected void Draw_Rect(byte[] p,PaletteColor col,double x,double y,double w,double h) {
DrawLoop.FillRect(p, col, x, y, w, h); DrawLoop.Fill_Rect(p, (byte)col.ordinal(), x, y, w, h);
}
protected void Draw_Line(byte[] p,double x1,double y1,double x2,double y2,PaletteColor col,Alpha alpha) {
DrawLoop.Draw_Line(p, (int)x1, (int)y1, (int)x2, (int)y2, (byte)col.ordinal(), alpha);
} }
protected void Draw_Sprite(double x, double y, Sprite sprite){ protected void Draw_Sprite(double x, double y, Sprite sprite){

@ -22,7 +22,6 @@ import java.awt.event.KeyListener;
import sig.DrawLoop; import sig.DrawLoop;
import sig.RabiClone; import sig.RabiClone;
import sig.objects.ConfigureControls;
public class Panel extends JPanel implements Runnable,KeyListener { public class Panel extends JPanel implements Runnable,KeyListener {
JFrame window; JFrame window;

@ -23,6 +23,9 @@ public class ConfigureControls extends Object{
KeyBind selectedKeybind = null; KeyBind selectedKeybind = null;
boolean assigningKey = false; boolean assigningKey = false;
List<List<Integer>> actionHighlightSections = new ArrayList<>(); List<List<Integer>> actionHighlightSections = new ArrayList<>();
int storedX=-1;
int storedY=-1;
int storedEndX=-1;
public ConfigureControls(Panel panel) { public ConfigureControls(Panel panel) {
super(panel); super(panel);
@ -87,14 +90,17 @@ public class ConfigureControls extends Object{
for (Action a : Action.values()) { for (Action a : Action.values()) {
if (RabiClone.MOUSE_POS.getY()>=getY()+y&&RabiClone.MOUSE_POS.getY()<getY()+y+Font.PROFONT_12.getGlyphHeight()+4) { if (RabiClone.MOUSE_POS.getY()>=getY()+y&&RabiClone.MOUSE_POS.getY()<getY()+y+Font.PROFONT_12.getGlyphHeight()+4) {
selectedAction=a; selectedAction=a;
Draw_Rect(p,(byte)PaletteColor.PEACH.ordinal(),0,getY()+y,RabiClone.BASE_WIDTH,Font.PROFONT_12.getGlyphHeight()+4); Draw_Rect(p,PaletteColor.PEACH,0,getY()+y,RabiClone.BASE_WIDTH,Font.PROFONT_12.getGlyphHeight()+4);
} }
for (int i=0;i<actionHighlightSections.get(a.ordinal()).size();i+=2) { for (int i=0;i<actionHighlightSections.get(a.ordinal()).size();i+=2) {
List<Integer> sectionList = actionHighlightSections.get(a.ordinal()); List<Integer> sectionList = actionHighlightSections.get(a.ordinal());
int startX=sectionList.get(i)*Font.PROFONT_12.getGlyphWidth()-4; int startX=sectionList.get(i)*Font.PROFONT_12.getGlyphWidth()-4;
int endX=sectionList.get(i+1)*Font.PROFONT_12.getGlyphWidth()+4; int endX=sectionList.get(i+1)*Font.PROFONT_12.getGlyphWidth()+4;
if (selectedKeybind==null&&RabiClone.MOUSE_POS.getY()>=getY()+y&&RabiClone.MOUSE_POS.getY()<getY()+y+Font.PROFONT_12.getGlyphHeight()+4&&RabiClone.MOUSE_POS.getX()>=startX&&RabiClone.MOUSE_POS.getX()<=endX) { if (selectedKeybind==null&&RabiClone.MOUSE_POS.getY()>=getY()+y&&RabiClone.MOUSE_POS.getY()<getY()+y+Font.PROFONT_12.getGlyphHeight()+4&&RabiClone.MOUSE_POS.getX()>=startX&&RabiClone.MOUSE_POS.getX()<=endX) {
Draw_Rect(p,(byte)PaletteColor.AZURE.ordinal(),startX,getY()+y,endX-startX,Font.PROFONT_12.getGlyphHeight()+4); Draw_Rect(p,PaletteColor.RED,startX,getY()+y,endX-startX,Font.PROFONT_12.getGlyphHeight()+4);
storedX=startX;
storedY=y;
storedEndX=endX;
selectedKeybind=KeyBind.KEYBINDS.get(a).get(i/2); selectedKeybind=KeyBind.KEYBINDS.get(a).get(i/2);
break; break;
} }
@ -102,6 +108,10 @@ public class ConfigureControls extends Object{
Draw_Text_Ext(4,getY()+y,DisplayActionKeys(a),Font.PROFONT_12,Alpha.ALPHA0,PaletteColor.MIDNIGHT_BLUE); Draw_Text_Ext(4,getY()+y,DisplayActionKeys(a),Font.PROFONT_12,Alpha.ALPHA0,PaletteColor.MIDNIGHT_BLUE);
y+=Font.PROFONT_12.getGlyphHeight()+4; y+=Font.PROFONT_12.getGlyphHeight()+4;
} }
if (selectedKeybind!=null) {
Draw_Line(p,storedX,getY()+storedY,storedEndX,getY()+storedY+Font.PROFONT_12.getGlyphHeight()+4,PaletteColor.BLACK,Alpha.ALPHA32);
Draw_Line(p,storedX,getY()+storedY+Font.PROFONT_12.getGlyphHeight()+4,storedEndX,getY()+storedY,PaletteColor.BLACK,Alpha.ALPHA32);
}
} else { } else {
Draw_Text_Ext(4, 4, new StringBuilder("Press a key to assign to ").append(selectedAction), Font.PROFONT_12, Alpha.ALPHA0, PaletteColor.MIDNIGHT_BLUE); Draw_Text_Ext(4, 4, new StringBuilder("Press a key to assign to ").append(selectedAction), Font.PROFONT_12, Alpha.ALPHA0, PaletteColor.MIDNIGHT_BLUE);
} }

Loading…
Cancel
Save