Color codes in the middle of text parsing when drawing text.
Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com> Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
e8224a4d78
commit
e5185e97e9
Binary file not shown.
@ -1,5 +1,7 @@
|
||||
package sig;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import sig.engine.Alpha;
|
||||
import sig.engine.Font;
|
||||
import sig.engine.PaletteColor;
|
||||
@ -36,13 +38,23 @@ public class DrawLoop {
|
||||
int charCount=0;
|
||||
int yOffset=0;
|
||||
int xOffset=0;
|
||||
PaletteColor currentCol = PaletteColor.NORMAL;
|
||||
for (int i=0;i<finalS.length();i++) {
|
||||
if (finalS.charAt(i)=='%'&&i<finalS.length()-1) {
|
||||
byte nextCol=Byte.parseByte(finalS.substring(i+1, finalS.indexOf(' ',i+1)));
|
||||
if (nextCol>=PaletteColor.values().length||nextCol<0) {
|
||||
throw new ArrayIndexOutOfBoundsException("Chosen color %"+nextCol+" is not in range (Min:0, Max: "+(PaletteColor.values().length-1)+")");
|
||||
} else {
|
||||
currentCol=PaletteColor.values()[nextCol];
|
||||
}
|
||||
finalS=finalS.replaceFirst(Pattern.quote("%"+nextCol+" "),"");
|
||||
} else
|
||||
if (finalS.charAt(i)=='\n') {
|
||||
xOffset+=(charCount+1)*f.getGlyphWidth();
|
||||
yOffset+=f.getGlyphHeight();
|
||||
charCount=0;
|
||||
} else {
|
||||
Draw_Sprite_Partial_Ext(x+i*f.getGlyphWidth()-xOffset, y+yOffset, f.getCharInfo(finalS.charAt(i)).getX(), f.getCharInfo(finalS.charAt(i)).getY(), f.getCharInfo(finalS.charAt(i)).getWidth(), f.getCharInfo(finalS.charAt(i)).getHeight(), f.getSprite(),alpha,col);
|
||||
Draw_Sprite_Partial_Ext(x+i*f.getGlyphWidth()-xOffset, y+yOffset, f.getCharInfo(finalS.charAt(i)).getX(), f.getCharInfo(finalS.charAt(i)).getY(), f.getCharInfo(finalS.charAt(i)).getWidth(), f.getCharInfo(finalS.charAt(i)).getHeight(), f.getSprite(),alpha,currentCol);
|
||||
charCount++;
|
||||
}
|
||||
}
|
||||
|
||||
@ -34,4 +34,11 @@ public enum PaletteColor {
|
||||
GRAPE,
|
||||
MIDNIGHT_BLUE,
|
||||
NORMAL;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "%"+ordinal()+" ";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -24,13 +24,17 @@ public class EditorRenderer extends LevelRenderer{
|
||||
|
||||
public EditorRenderer(Panel panel) {
|
||||
super(panel);
|
||||
AddMessage("Level editing mode started.");
|
||||
AddMessage(PaletteColor.YELLOW_GREEN,"Level editing mode",PaletteColor.NORMAL," started.");
|
||||
}
|
||||
|
||||
private void AddMessage(String...s) {
|
||||
private void AddMessage(Object...s) {
|
||||
messageLog.append('\n');
|
||||
for (int i=0;i<s.length;i++) {
|
||||
messageLog.append(s[i]);
|
||||
if (s[i] instanceof String) {
|
||||
messageLog.append((String)s[i]);
|
||||
} else if (s[i] instanceof PaletteColor) {
|
||||
messageLog.append((PaletteColor)s[i]);
|
||||
}
|
||||
}
|
||||
last_message_log = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user