Merging 1.9.1 source: ui changes (plus wndchooseway)
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
*/
|
||||
package com.shatteredpixel.shatteredpixeldungeon.ui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.watabou.noosa.BitmapTextMultiline;
|
||||
@@ -32,20 +33,30 @@ import com.watabou.utils.Signal;
|
||||
|
||||
public class GameLog extends Component implements Signal.Listener<String> {
|
||||
|
||||
private static final int MAX_MESSAGES = 3;
|
||||
|
||||
private static final int MAX_LINES = 3;
|
||||
|
||||
private static final Pattern PUNCTUATION = Pattern.compile( ".*[.,;?! ]$" );
|
||||
|
||||
|
||||
private BitmapTextMultiline lastEntry;
|
||||
private int lastColor;
|
||||
|
||||
|
||||
private static ArrayList<Entry> entries = new ArrayList<Entry>();
|
||||
|
||||
public GameLog() {
|
||||
super();
|
||||
GLog.update.add( this );
|
||||
|
||||
newLine();
|
||||
|
||||
recreateLines();
|
||||
}
|
||||
|
||||
|
||||
private void recreateLines() {
|
||||
for (Entry entry : entries) {
|
||||
lastEntry = PixelScene.createMultiline( entry.text, 6 );
|
||||
lastEntry.hardlight( lastColor = entry.color );
|
||||
add( lastEntry );
|
||||
}
|
||||
}
|
||||
|
||||
public void newLine() {
|
||||
lastEntry = null;
|
||||
}
|
||||
@@ -70,48 +81,80 @@ public class GameLog extends Component implements Signal.Listener<String> {
|
||||
text = text.substring( GLog.HIGHLIGHT.length() );
|
||||
color = CharSprite.NEUTRAL;
|
||||
}
|
||||
|
||||
|
||||
text = Utils.capitalize( text ) +
|
||||
(PUNCTUATION.matcher( text ).matches() ? "" : ".");
|
||||
|
||||
if (lastEntry != null && color == lastColor) {
|
||||
|
||||
(PUNCTUATION.matcher( text ).matches() ? "" : ".");
|
||||
|
||||
if (lastEntry != null && color == lastColor && lastEntry.nLines < MAX_LINES) {
|
||||
|
||||
String lastMessage = lastEntry.text();
|
||||
lastEntry.text( lastMessage.length() == 0 ? text : lastMessage + " " + text );
|
||||
lastEntry.measure();
|
||||
|
||||
|
||||
entries.get( entries.size() - 1 ).text = lastEntry.text();
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
lastEntry = PixelScene.createMultiline( text, 6 );
|
||||
lastEntry.maxWidth = (int)width;
|
||||
lastEntry.measure();
|
||||
lastEntry.hardlight( color );
|
||||
lastColor = color;
|
||||
add( lastEntry );
|
||||
|
||||
|
||||
entries.add( new Entry( text, color ) );
|
||||
|
||||
}
|
||||
|
||||
if (length > MAX_MESSAGES) {
|
||||
remove( members.get( 0 ) );
|
||||
|
||||
if (length > 0) {
|
||||
int nLines;
|
||||
do {
|
||||
nLines = 0;
|
||||
for (int i = 0; i < length; i++) {
|
||||
nLines += ((BitmapTextMultiline) members.get(i)).nLines;
|
||||
}
|
||||
|
||||
if (nLines > MAX_LINES) {
|
||||
remove(members.get(0));
|
||||
|
||||
entries.remove( 0 );
|
||||
}
|
||||
} while (nLines > MAX_LINES);
|
||||
if (entries.isEmpty()) {
|
||||
lastEntry = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
layout();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void layout() {
|
||||
float pos = y;
|
||||
for (int i=length-1; i >= 0; i--) {
|
||||
BitmapTextMultiline entry = (BitmapTextMultiline)members.get( i );
|
||||
entry.maxWidth = (int)width;
|
||||
entry.measure();
|
||||
entry.x = x;
|
||||
entry.y = pos - entry.height();
|
||||
pos -= entry.height();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
GLog.update.remove( this );
|
||||
super.destroy();
|
||||
}
|
||||
|
||||
private static class Entry {
|
||||
public String text;
|
||||
public int color;
|
||||
public Entry( String text, int color ) {
|
||||
this.text = text;
|
||||
this.color = color;
|
||||
}
|
||||
}
|
||||
|
||||
public static void wipe() {
|
||||
entries.clear();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user