Final changes to text drawing system to make it appear correctly

Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com>
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
main
sigonasr2 3 years ago
parent e5dd00cff8
commit 636aac9bfc
  1. 8
      src/sig/DrawLoop.java
  2. 2
      src/sig/engine/PaletteColor.java

@ -16,7 +16,7 @@ public class DrawLoop {
for (int y=0;y<RabiClone.BASE_HEIGHT;y++) { for (int y=0;y<RabiClone.BASE_HEIGHT;y++) {
for (int x=0;x<RabiClone.BASE_WIDTH;x++) { for (int x=0;x<RabiClone.BASE_WIDTH;x++) {
p[y*RabiClone.BASE_WIDTH+x]=0;//RGB p[y*RabiClone.BASE_WIDTH+x]=(byte)PaletteColor.DARK_ORCHID.ordinal();//RGB
} }
} }
@ -40,14 +40,16 @@ public class DrawLoop {
int xOffset=0; int xOffset=0;
PaletteColor currentCol = col; PaletteColor currentCol = col;
for (int i=0;i<finalS.length();i++) { for (int i=0;i<finalS.length();i++) {
if (finalS.charAt(i)=='\u001a'&&i<finalS.length()-1) { if (finalS.charAt(i)==(char)26&&i<finalS.length()-1) {
byte nextCol=Byte.parseByte(finalS.substring(i+1, finalS.indexOf(' ',i+1))); byte nextCol=Byte.parseByte(finalS.substring(i+1, finalS.indexOf(' ',i+1)));
if (nextCol>=PaletteColor.values().length||nextCol<0) { if (nextCol>=PaletteColor.values().length||nextCol<0) {
throw new ArrayIndexOutOfBoundsException("Chosen color %"+nextCol+" is not in range (Min:0, Max: "+(PaletteColor.values().length-1)+")"); throw new ArrayIndexOutOfBoundsException("Chosen color %"+nextCol+" is not in range (Min:0, Max: "+(PaletteColor.values().length-1)+")");
} else { } else {
currentCol=PaletteColor.values()[nextCol]; currentCol=PaletteColor.values()[nextCol];
} }
finalS=finalS.replaceFirst(Pattern.quote("\u001a"+nextCol+" "),""); int oldLength = finalS.length();
finalS=finalS.replaceFirst(Pattern.quote(Character.valueOf((char)26)+Byte.toString(nextCol)+" "),"");
i--;
} else } else
if (finalS.charAt(i)=='\n') { if (finalS.charAt(i)=='\n') {
xOffset+=(charCount+1)*f.getGlyphWidth(); xOffset+=(charCount+1)*f.getGlyphWidth();

@ -37,7 +37,7 @@ public enum PaletteColor {
@Override @Override
public String toString() { public String toString() {
return "\u001a"+ordinal()+" "; return Character.valueOf((char)26)+Integer.toString(ordinal())+" ";
} }

Loading…
Cancel
Save