New String class system that wraps a builder and keeps track of text bounds. Added background to editor message logs

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 6c5c2b1c67
commit 9c207e2f2a
  1. 28
      README.md
  2. BIN
      bin/RabiClone.jar
  3. 7
      src/sig/DrawLoop.java
  4. 2
      src/sig/engine/Edge.java
  5. 2
      src/sig/engine/Key.java
  6. 2
      src/sig/engine/KeyBind.java
  7. 4
      src/sig/engine/Object.java
  8. 2
      src/sig/engine/PaletteColor.java
  9. 2
      src/sig/engine/Point.java
  10. 2
      src/sig/engine/Rectangle.java
  11. 125
      src/sig/engine/String.java
  12. 7
      src/sig/objects/ConfigureControls.java
  13. 22
      src/sig/objects/EditorRenderer.java

@ -43,3 +43,31 @@ Movement Systems
Collectibles
Combat Systems
Storyboarding / Event Systems
`all` to suppress all warnings
`boxing` to suppress warnings relative to boxing/unboxing operations
`cast` to suppress warnings relative to cast operations
`dep`-ann to suppress warnings relative to deprecated annotation
`deprecation` to suppress warnings relative to deprecation
`fallthrough` to suppress warnings relative to missing breaks in switch statements
`finally` to suppress warnings relative to finally block that don’t return
`hiding` to suppress warnings relative to locals that hide variable
`incomplete`-switch to suppress warnings relative to missing entries in a switch statement (enum case)
`nls` to suppress warnings relative to non-nls string literals
`null` to suppress warnings relative to null analysis
`restriction` to suppress warnings relative to usage of discouraged or forbidden references
`serial` to suppress warnings relative to missing serialVersionUID field for a serializable class
`static`-access to suppress warnings relative to incorrect static access
`synthetic`-access to suppress warnings relative to unoptimized access from inner classes
`unchecked` to suppress warnings relative to unchecked operations
`unqualified`-field-access to suppress warnings relative to field access unqualified
`unused` to suppress warnings relative to unused code
`javadoc` to suppress warnings relative to javadoc warnings
`rawtypes` to suppress warnings relative to usage of raw types
`static`-method to suppress warnings relative to methods that could be declared as static
`super` to suppress warnings relative to overriding a method without super invocations
`resource` to suppress warnings relative to usage of resources of type Closeable
`sync-override` to suppress warnings because of missing synchronize when overriding a synchronized method

Binary file not shown.

@ -9,6 +9,7 @@ import sig.engine.PaletteColor;
import sig.engine.Panel;
import sig.engine.Rectangle;
import sig.engine.Sprite;
import sig.engine.String;
import sig.engine.Transform;
public class DrawLoop {
@ -36,12 +37,12 @@ public class DrawLoop {
}
}
public static void Draw_Text(double x, double y, StringBuilder s, Font f) {
public static void Draw_Text(double x, double y, String s, Font f) {
Draw_Text_Ext(x,y,s,f,Alpha.ALPHA0,PaletteColor.NORMAL);
}
public static void Draw_Text_Ext(double x, double y, StringBuilder s, Font f, Alpha alpha, PaletteColor col) {
String finalS = s.toString();
public static void Draw_Text_Ext(double x, double y, String s, Font f, Alpha alpha, PaletteColor col) {
java.lang.String finalS = s.toString();
int charCount=0;
int yOffset=0;
int xOffset=0;

@ -25,7 +25,7 @@ public class Edge {
inverse_slope=(double)(a.x-b.x)/(a.y-b.y);
}
@Override
public String toString() {
public java.lang.String toString() {
return "Edge [a=" + a + ", b=" + b + ", min_y=" + min_y + ", max_y=" + max_y + ", min_x=" + min_x + ", max_x="
+ max_x + ", x_of_min_y=" + x_of_min_y + ", inverse_slope=" + inverse_slope + "]";
}

@ -7,7 +7,7 @@ import net.java.games.input.Component.Identifier;
public class Key extends Identifier{
protected Key(String name) {
protected Key(java.lang.String name) {
super(name);
}

@ -123,7 +123,7 @@ public class KeyBind {
}
}
public String getName() {
public java.lang.String getName() {
if (RabiClone.CONTROLLERS.length>port&&port!=-1) {
return RabiClone.CONTROLLERS[port].getComponent(id).getName();
} else

@ -78,11 +78,11 @@ public abstract class Object implements GameEntity{
DrawLoop.Draw_Animated_Sprite(x,y,sprite,frameIndex,transform);
}
protected void Draw_Text(double x, double y, StringBuilder string, Font font){
protected void Draw_Text(double x, double y, String string, Font font){
DrawLoop.Draw_Text(x,y,string,font);
}
protected void Draw_Text_Ext(double x, double y, StringBuilder string, Font font, Alpha alpha, PaletteColor col){
protected void Draw_Text_Ext(double x, double y, String string, Font font, Alpha alpha, PaletteColor col){
DrawLoop.Draw_Text_Ext(x,y,string,font,alpha,col);
}

@ -36,7 +36,7 @@ public enum PaletteColor {
NORMAL;
@Override
public String toString() {
public java.lang.String toString() {
return Character.valueOf((char)26)+Integer.toString(ordinal())+" ";
}

@ -34,7 +34,7 @@ public class Point {
}
@Override
public String toString() {
public java.lang.String toString() {
return "Point(" + x + "," + y + ")";
}
}

@ -43,7 +43,7 @@ public class Rectangle {
}
@Override
public String toString() {
public java.lang.String toString() {
return new StringBuilder("Rectangle(x=").append(x).append(",")
.append("y=").append(y).append(",")
.append("w=").append(w).append(",")

@ -0,0 +1,125 @@
package sig.engine;
import java.util.regex.Pattern;
@SuppressWarnings("unused")
public class String{
private StringBuilder sb;
private Point bounds = new Point(0,1);
private int currentLineWidth;
public String() {
this.sb=new StringBuilder();
}
public String(java.lang.String str) {
this.sb=new StringBuilder(str);
updateBounds(str);
}
public String(Object obj) {
this.sb=new StringBuilder(obj.toString());
updateBounds(obj.toString());
}
public String append(char c) {
this.sb.append(c);
updateBounds(Character.toString(c));
return this;
}
public String append(java.lang.Object...obj) {
for (java.lang.Object o : obj) {
this.sb.append(o.toString());
updateBounds(o.toString());
}
return this;
}
public StringBuilder getBuilder() {
return this.sb;
}
/**
* Returns the index within this string of the first occurrence of the
* specified substring.
*
* <p>The returned index is the smallest value {@code k} for which:
* <pre>{@code
* this.toString().startsWith(str, k)
* }</pre>
* If no such value of {@code k} exists, then {@code -1} is returned.
*
* @param str the substring to search for.
* @return the index of the first occurrence of the specified substring,
* or {@code -1} if there is no such occurrence.
*/
public int indexOf(java.lang.String str) {
return this.sb.indexOf(str);
}
/**
* Returns the index within this string of the first occurrence of the
* specified substring, starting at the specified index.
*
* <p>The returned index is the smallest value {@code k} for which:
* <pre>{@code
* k >= Math.min(fromIndex, this.length()) &&
* this.toString().startsWith(str, k)
* }</pre>
* If no such value of {@code k} exists, then {@code -1} is returned.
*
* @param str the substring to search for.
* @param fromIndex the index from which to start the search.
* @return the index of the first occurrence of the specified substring,
* starting at the specified index,
* or {@code -1} if there is no such occurrence.
*/
public int indexOf(java.lang.String str,int fromIndex) {
return this.sb.indexOf(str,fromIndex);
}
/**
* Replaces the characters in a substring of this sequence
* with characters in the specified {@code String}. The substring
* begins at the specified {@code start} and extends to the character
* at index {@code end - 1} or to the end of the
* sequence if no such character exists. First the
* characters in the substring are removed and then the specified
* {@code String} is inserted at {@code start}. (This
* sequence will be lengthened to accommodate the
* specified String if necessary.)
*
* @param start The beginning index, inclusive.
* @param end The ending index, exclusive.
* @param str String that will replace previous contents.
* @return This object.
* @throws StringIndexOutOfBoundsException if {@code start}
* is negative, greater than {@code length()}, or
* greater than {@code end}.
*/
public String replace(int start,int end,java.lang.String str) {
this.sb.replace(start,end,str);
return this;
}
public int length() {
return this.sb.length();
}
public java.lang.String toString() {
return this.sb.toString();
}
public Point getBounds(Font f) {
return new Point(bounds.x*f.getGlyphWidth(),length()>0?Math.max(bounds.y*f.getGlyphHeight(),f.getGlyphHeight()):0);
}
private void updateBounds(java.lang.String string) {
for (int i=0;i<string.length();i++) {
if (string.charAt(i)=='\n') {
bounds.x=i+1>bounds.x?i+1:bounds.x;
bounds.y++;
currentLineWidth=0;
} else
if (string.charAt(i)==(char)26&&i<string.length()-1) {
byte nextCol=Byte.parseByte(string.substring(i+1, string.indexOf(' ',i+1)));
string=string.replaceFirst(Pattern.quote(Character.valueOf((char)26)+Byte.toString(nextCol)+" "),"");
i--;
} else {
currentLineWidth++;
bounds.x=currentLineWidth>bounds.x?currentLineWidth:bounds.x;
}
}
}
}

@ -16,6 +16,7 @@ import sig.engine.KeyBind;
import sig.engine.Object;
import sig.engine.PaletteColor;
import sig.engine.Panel;
import sig.engine.String;
public class ConfigureControls extends Object{
@ -113,7 +114,7 @@ public class ConfigureControls extends Object{
Draw_Line(p,storedX,getY()+storedY+Font.PROFONT_12.getGlyphHeight()+4,storedEndX,getY()+storedY,PaletteColor.BLACK,Alpha.ALPHA32);
}
} 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 String("Press a key to assign to ").append(selectedAction), Font.PROFONT_12, Alpha.ALPHA0, PaletteColor.MIDNIGHT_BLUE);
}
}
@ -132,8 +133,8 @@ public class ConfigureControls extends Object{
}
}
private StringBuilder DisplayActionKeys(Action a) {
StringBuilder sb = new StringBuilder(a.toString()).append(": ");
private String DisplayActionKeys(Action a) {
String sb = new String(a.toString()).append(": ");
for (int i=0;i<KeyBind.KEYBINDS.get(a).size();i++) {
KeyBind c = KeyBind.KEYBINDS.get(a).get(i);
sb.append(c.isKeyHeld()?PaletteColor.YELLOW_GREEN:"").append(c.getName()).append(PaletteColor.MIDNIGHT_BLUE).append(i!=KeyBind.KEYBINDS.get(a).size()-1?",":"");

@ -10,6 +10,7 @@ import sig.engine.Font;
import sig.engine.MouseScrollValue;
import sig.engine.PaletteColor;
import sig.engine.Panel;
import sig.engine.String;
import sig.map.Background;
import sig.map.Map;
import sig.map.Tile;
@ -20,11 +21,11 @@ public class EditorRenderer extends LevelRenderer{
Tile selectedTile = Tile.WALL;
StringBuilder messageLog = new StringBuilder();
String messageLog = new String();
final static long MESSAGE_TIME = 5000;
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 String HELP_TEXT = new String("(F3) Toggle Camera (F4) Toggle Map Type (F5) Toggle Background");
final static char CAMERA_SPD = 512;
@ -37,13 +38,7 @@ public class EditorRenderer extends LevelRenderer{
private void AddMessage(Object...s) {
messageLog.append('\n');
for (int i=0;i<s.length;i++) {
if (s[i] instanceof String) {
messageLog.append((String)s[i]);
} else if (s[i] instanceof PaletteColor) {
messageLog.append((PaletteColor)s[i]);
}
}
messageLog.append(s);
last_message_log = System.currentTimeMillis();
}
@ -68,7 +63,7 @@ public class EditorRenderer extends LevelRenderer{
int tileY = (int)(RabiClone.MOUSE_POS.getY()+getY())/Tile.TILE_HEIGHT;
RabiClone.CURRENT_MAP.ModifyTile(tileX, tileY, selectedTile);
}
if(KeyHeld(Action.SLIDE)||KeyHeld(Action.FALL)){
if(KeyHeld(Action.SLIDE)&&KeyHeld(Action.FALL)){
AddMessage("Saving map...");
try {
Map.SaveMap(RabiClone.CURRENT_MAP);
@ -125,6 +120,7 @@ public class EditorRenderer extends LevelRenderer{
drawTileGrid(p,x,y);
}
}
Draw_Rect(p,PaletteColor.YELLOW,2,0,messageLog.getBounds(Font.PROFONT_12).getX(),messageLog.getBounds(Font.PROFONT_12).getY());
Draw_Text(4,0,messageLog,Font.PROFONT_12);
Draw_Text(4,RabiClone.BASE_HEIGHT-Font.PROFONT_12.getGlyphHeight()-4,HELP_TEXT,Font.PROFONT_12);
}
@ -134,7 +130,7 @@ 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))
new String("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);
@ -171,8 +167,8 @@ public class EditorRenderer extends LevelRenderer{
double tileX = x*Tile.TILE_WIDTH-this.getX();
double tileY = y*Tile.TILE_HEIGHT-this.getY();
DrawTransparentTile(tileX,tileY,selectedTile,Alpha.ALPHA160);
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(tileX+2,tileY-Font.PROFONT_12.getGlyphHeight()-2,new String(selectedTile.toString()),Font.PROFONT_12);
Draw_Text_Ext(tileX+2,tileY+Tile.TILE_HEIGHT+2,new String(RabiClone.CURRENT_MAP.getTile(x,y).toString()),Font.PROFONT_12,Alpha.ALPHA0,PaletteColor.CRIMSON);
}
}

Loading…
Cancel
Save