v0.7.5b: refactored renderedTextMultiline

It is now much more flexible, and is used in all places.
This commit is contained in:
Evan Debenham 2019-10-11 19:34:22 -04:00
parent b4ae0ee991
commit 03ebdde440
36 changed files with 431 additions and 348 deletions

View File

@ -98,17 +98,15 @@ public class RenderedText extends Image {
width = l.width;
//TODO this is almost the same as old height, but old height was clearly a bit off
height = size*1.375f;
//height = l.height - fonts.get(fontGenerator).get(size).getDescent() + size/5f;
//this is identical to l.height in most cases, but we force this for consistency.
height = Math.round(size*0.75f);
}
@Override
protected void updateMatrix() {
super.updateMatrix();
//the y value is set at the top of the character, not at the top of accents.
//FIXME this doesn't work for .otf fonts on android 6.0
Matrix.translate( matrix, 0, Math.round((baseLine()*0.1f)/scale.y) );
Matrix.translate( matrix, 0, Math.round((baseLine()*Game.platform.getFontHeightOffset(font))/scale.y) );
}
private static TextRenderBatch textRenderer = new TextRenderBatch();

View File

@ -45,5 +45,9 @@ public abstract class PlatformSupport {
public abstract void resetGenerators();
public abstract BitmapFont getFont(int size, String text);
public abstract String[] splitforTextBlock( String text, boolean multiline );
public abstract float getFontHeightOffset( BitmapFont font );
}

View File

@ -162,22 +162,25 @@ public class AndroidPlatformSupport extends PlatformSupport {
private PixmapPacker packer;
private boolean systemfont;
//custom ttf or droid sans, for use with Latin and Cyrillic languages
private static FreeTypeFontGenerator latinAndCryllicFontGenerator;
private static HashMap<Integer, BitmapFont> pixelFonts = new HashMap<>();
//droid sans / roboto, or a custom pixel font, for use with Latin and Cyrillic languages
private static FreeTypeFontGenerator basicFontGenerator;
private static HashMap<Integer, BitmapFont> basicFonts = new HashMap<>();
//droid sans, for use with hangul languages (Korean)
private static FreeTypeFontGenerator hangulFontGenerator;
private static HashMap<Integer, BitmapFont> hangulFonts = new HashMap<>();
//droid sans / nanum gothic / noto sans, for use with Korean
private static FreeTypeFontGenerator KRFontGenerator;
private static HashMap<Integer, BitmapFont> KRFonts = new HashMap<>();
//droid sans, for use with han languages (Chinese, Japanese)
private static FreeTypeFontGenerator hanFontGenerator;
private static HashMap<Integer, BitmapFont> hanFonts = new HashMap<>();
//droid sans / noto sans, for use with Simplified Chinese
private static FreeTypeFontGenerator SCFontGenerator;
private static HashMap<Integer, BitmapFont> SCFonts = new HashMap<>();
//droid sans / noto sans, for use with Japanese
private static FreeTypeFontGenerator JPFontGenerator;
private static HashMap<Integer, BitmapFont> JPFonts = new HashMap<>();
private static HashMap<FreeTypeFontGenerator, HashMap<Integer, BitmapFont>> fonts;
public static Pattern hanMatcher = Pattern.compile("\\p{InHiragana}|\\p{InKatakana}|\\p{InCJK_Unified_Ideographs}|\\p{InCJK_Symbols_and_Punctuation}");
public static Pattern hangulMatcher = Pattern.compile("\\p{InHangul_Syllables}");
private boolean android6OTFPresent = false;
@Override
public void setupFontGenerators(int pageSize, boolean systemfont) {
@ -207,42 +210,53 @@ public class AndroidPlatformSupport extends PlatformSupport {
fonts = new HashMap<>();
if (systemfont){
latinAndCryllicFontGenerator = new FreeTypeFontGenerator(Gdx.files.absolute("/system/fonts/DroidSans.ttf"));
basicFontGenerator = new FreeTypeFontGenerator(Gdx.files.absolute("/system/fonts/DroidSans.ttf"));
} else {
//FIXME need to add currency symbols
latinAndCryllicFontGenerator = new FreeTypeFontGenerator(Gdx.files.internal("pixelfont.ttf"));
basicFontGenerator = new FreeTypeFontGenerator(Gdx.files.internal("pixelfont.ttf"));
}
//android 7.0+. Finally back to normalcy, everything nicely in one .ttc
if (Gdx.files.absolute("/system/fonts/NotoSansCJK-Regular.ttc").exists()) {
//TODO why typeface #2 here? It seems to match DroidSansFallback.ttf the best, but why?
//might be that different languages prefer a different face, see about tweaking this?
hangulFontGenerator = hanFontGenerator = new FreeTypeFontGenerator(Gdx.files.absolute("/system/fonts/NotoSansCJK-Regular.ttc"), 2);
//typefaces are 1-JP, 2-KR, 3-SC, 3-TC.
int typeFace;
switch (SPDSettings.language()){
case JAPANESE:
typeFace = 1;
break;
case KOREAN:
typeFace = 2;
break;
case CHINESE: default:
typeFace = 3;
}
KRFontGenerator = SCFontGenerator = JPFontGenerator = new FreeTypeFontGenerator(Gdx.files.absolute("/system/fonts/NotoSansCJK-Regular.ttc"), typeFace);
//android 6.0. Fonts are split over multiple .otf files, very awkward
} else if (Gdx.files.absolute("/system/fonts/NotoSansKR-Regular.otf").exists()) {
//FIXME all fonts are messed up here currently, need to fix this
hangulFontGenerator = new FreeTypeFontGenerator(Gdx.files.absolute("/system/fonts/NotoSansKR-Regular.otf"));
hanFontGenerator = new FreeTypeFontGenerator(Gdx.files.absolute("/system/fonts/NotoSansSC-Regular.otf"));
KRFontGenerator = new FreeTypeFontGenerator(Gdx.files.absolute("/system/fonts/NotoSansKR-Regular.otf"));
SCFontGenerator = new FreeTypeFontGenerator(Gdx.files.absolute("/system/fonts/NotoSansSC-Regular.otf"));
JPFontGenerator = new FreeTypeFontGenerator(Gdx.files.absolute("/system/fonts/NotoSansJP-Regular.otf"));
android6OTFPresent = true;
//android 4.4-5.1. Korean no longer broken with the addition of NanumGothic.
} else if (Gdx.files.absolute("/system/fonts/NanumGothic.ttf").exists()){
hangulFontGenerator = new FreeTypeFontGenerator(Gdx.files.absolute("/system/fonts/NanumGothic.ttf"));
hanFontGenerator = new FreeTypeFontGenerator(Gdx.files.absolute("/system/fonts/DroidSansFallback.ttf"));
KRFontGenerator = new FreeTypeFontGenerator(Gdx.files.absolute("/system/fonts/NanumGothic.ttf"));
SCFontGenerator = JPFontGenerator = new FreeTypeFontGenerator(Gdx.files.absolute("/system/fonts/DroidSansFallback.ttf"));
//android 4.3-. Note that korean isn't in DroidSandFallback and is therefore unfixably broken on 4.2 and 4.3
} else if (Gdx.files.absolute("/system/fonts/DroidSansFallback.ttf").exists()) {
hangulFontGenerator = hanFontGenerator = new FreeTypeFontGenerator(Gdx.files.absolute("/system/fonts/DroidSansFallback.ttf"));
KRFontGenerator = SCFontGenerator = JPFontGenerator = new FreeTypeFontGenerator(Gdx.files.absolute("/system/fonts/DroidSansFallback.ttf"));
//shouldn't ever trigger, but just incase
//shouldn't ever trigger, but just in case
} else {
hangulFontGenerator = hanFontGenerator = latinAndCryllicFontGenerator;
KRFontGenerator = SCFontGenerator = JPFontGenerator = basicFontGenerator;
}
fonts.put(latinAndCryllicFontGenerator, pixelFonts);
fonts.put(hangulFontGenerator, hangulFonts);
fonts.put(hanFontGenerator, hanFonts);
fonts.put(kataFontGenerator, kataFonts);
fonts.put(basicFontGenerator, basicFonts);
fonts.put(KRFontGenerator, KRFonts);
fonts.put(SCFontGenerator, SCFonts);
fonts.put(JPFontGenerator, JPFonts);
//use RGBA4444 to save memory. Extra precision isn't needed here.
packer = new PixmapPacker(pageSize, pageSize, Pixmap.Format.RGBA4444, 1, false);
@ -268,13 +282,19 @@ public class AndroidPlatformSupport extends PlatformSupport {
setupFontGenerators(pageSize, systemfont);
}
private static Pattern KRMatcher = Pattern.compile("\\p{InHangul_Syllables}");
private static Pattern SCMatcher = Pattern.compile("\\p{InCJK_Unified_Ideographs}|\\p{InCJK_Symbols_and_Punctuation}|\\p{InHalfwidth_and_Fullwidth_Forms}");
private static Pattern JPMatcher = Pattern.compile("\\p{InHiragana}|\\p{InKatakana}");
private static FreeTypeFontGenerator getGeneratorForString( String input ){
if (hanMatcher.matcher(input).find()){
return hanFontGenerator;
} else if (hangulMatcher.matcher(input).find()){
return hangulFontGenerator;
if (KRMatcher.matcher(input).find()){
return KRFontGenerator;
} else if (SCMatcher.matcher(input).find()){
return SCFontGenerator;
} else if (JPMatcher.matcher(input).find()){
return JPFontGenerator;
} else {
return latinAndCryllicFontGenerator;
return basicFontGenerator;
}
}
@ -299,4 +319,43 @@ public class AndroidPlatformSupport extends PlatformSupport {
return fonts.get(generator).get(size);
}
//splits on newlines, underscores, and chinese/japaneses characters
private Pattern regularsplitter = Pattern.compile(
"(?<=\n)|(?=\n)|(?<=_)|(?=_)|" +
"(?<=\\p{InHiragana})|(?=\\p{InHiragana})|" +
"(?<=\\p{InKatakana})|(?=\\p{InKatakana})|" +
"(?<=\\p{InCJK_Unified_Ideographs})|(?=\\p{InCJK_Unified_Ideographs})");
//additionally splits on words, so that each word can be arranged individually
private Pattern regularsplitterMultiline = Pattern.compile(
"(?<= )|(?= )|(?<=\n)|(?=\n)|(?<=_)|(?=_)|" +
"(?<=\\p{InHiragana})|(?=\\p{InHiragana})|" +
"(?<=\\p{InKatakana})|(?=\\p{InKatakana})|" +
"(?<=\\p{InCJK_Unified_Ideographs})|(?=\\p{InCJK_Unified_Ideographs})");
//splits on each group of hangul syllables. Needed for weird android 6.0 font files
private Pattern android6KRSplitter = Pattern.compile(
"(?<= )|(?= )|(?<=\n)|(?=\n)|(?<=_)|(?=_)|" +
"(?!\\p{InHangul_Syllables})");
@Override
public String[] splitforTextBlock(String text, boolean multiline) {
if (android6OTFPresent && getGeneratorForString(text) == KRFontGenerator){
return android6KRSplitter.split(text);
} else if (multiline) {
return regularsplitterMultiline.split(text);
} else {
return regularsplitter.split(text);
}
}
public float getFontHeightOffset( BitmapFont font ){
//more weirdness with android 6 OTF fonts
if (android6OTFPresent && !basicFonts.containsValue(font)){
return -0.2f;
} else {
return 0.0f;
}
}
}

View File

@ -24,7 +24,6 @@ package com.shatteredpixel.shatteredpixeldungeon;
import com.shatteredpixel.shatteredpixeldungeon.messages.Languages;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.watabou.noosa.Game;
import com.watabou.noosa.RenderedText;
import com.watabou.noosa.audio.Music;
import com.watabou.noosa.audio.Sample;
import com.watabou.utils.GameSettings;
@ -251,7 +250,6 @@ public class SPDSettings extends GameSettings {
public static void systemFont(boolean value){
put(KEY_SYSTEMFONT, value);
ShatteredPixelDungeon.seamlessResetScene();
}
public static boolean systemFont(){

View File

@ -24,7 +24,6 @@ package com.shatteredpixel.shatteredpixeldungeon;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.scenes.WelcomeScene;
import com.watabou.noosa.Game;
import com.watabou.noosa.RenderedText;
import com.watabou.noosa.audio.Music;
import com.watabou.noosa.audio.Sample;
import com.watabou.utils.PlatformSupport;

View File

@ -24,6 +24,7 @@ package com.shatteredpixel.shatteredpixeldungeon.effects;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.tiles.DungeonTilemap;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline;
import com.watabou.noosa.Camera;
import com.watabou.noosa.Game;
import com.watabou.noosa.RenderedText;
@ -32,7 +33,7 @@ import com.watabou.utils.SparseArray;
import java.util.ArrayList;
public class FloatingText extends RenderedText {
public class FloatingText extends RenderedTextMultiline {
private static final float LIFESPAN = 1f;
private static final float DISTANCE = DungeonTilemap.SIZE;
@ -44,7 +45,7 @@ public class FloatingText extends RenderedText {
private static final SparseArray<ArrayList<FloatingText>> stacks = new SparseArray<>();
public FloatingText() {
speed.y = - DISTANCE / LIFESPAN;
super(9*PixelScene.defaultZoom);
}
@Override
@ -57,6 +58,12 @@ public class FloatingText extends RenderedText {
} else {
float p = timeLeft / LIFESPAN;
alpha( p > 0.5f ? 1 : p * 2 );
float yMove = (DISTANCE / LIFESPAN) * Game.elapsed;
y -= yMove;
for (RenderedText t : words){
t.y -= yMove;
}
}
}
}
@ -82,14 +89,15 @@ public class FloatingText extends RenderedText {
revive();
size( 9 * PixelScene.defaultZoom);
scale.set( 1 / (float)PixelScene.defaultZoom );
zoom( 1 / (float)PixelScene.defaultZoom );
text( text );
hardlight( color );
this.x = PixelScene.align( Camera.main, x - width() / 2);
this.y = PixelScene.align( Camera.main, y - height());
setPos(
PixelScene.align( Camera.main, x - width() / 2),
PixelScene.align( Camera.main, y - height())
);
timeLeft = LIFESPAN;
}
@ -137,8 +145,8 @@ public class FloatingText extends RenderedText {
int aboveIndex = stack.size() - 1;
while (aboveIndex >= 0) {
FloatingText above = stack.get(aboveIndex);
if (above.y + above.height() > below.y) {
above.y = below.y - above.height();
if (above.bottom() + 4 > below.top()) {
above.setPos(above.left(), below.top() - above.height() - 4);
below = above;
aboveIndex--;

View File

@ -33,7 +33,6 @@ import com.watabou.input.PointerEvent;
import com.watabou.noosa.Camera;
import com.watabou.noosa.Image;
import com.watabou.noosa.PointerArea;
import com.watabou.noosa.RenderedText;
import com.watabou.utils.DeviceCompat;
public class AboutScene extends PixelScene {
@ -69,19 +68,21 @@ public class AboutScene extends PixelScene {
new Flare( 7, 64 ).color( 0x225511, true ).show( shpx, 0 ).angularSpeed = +20;
RenderedText shpxtitle = renderText( TTL_SHPX, 8 );
RenderedTextMultiline shpxtitle = renderMultiline( TTL_SHPX, 8 );
shpxtitle.hardlight( Window.SHPX_COLOR );
add( shpxtitle );
shpxtitle.x = (colWidth - shpxtitle.width()) / 2;
shpxtitle.y = shpx.y + shpx.height + 5;
shpxtitle.setPos(
(colWidth - shpxtitle.width()) / 2,
shpx.y + shpx.height + 5
);
align(shpxtitle);
RenderedTextMultiline shpxtext = renderMultiline( TXT_SHPX, 8 );
shpxtext.maxWidth((int)Math.min(colWidth, 120));
add( shpxtext );
shpxtext.setPos((colWidth - shpxtext.width()) / 2, shpxtitle.y + shpxtitle.height() + 12);
shpxtext.setPos((colWidth - shpxtext.width()) / 2, shpxtitle.bottom() + 12);
align(shpxtext);
RenderedTextMultiline shpxlink = renderMultiline( LNK_SHPX, 8 );
@ -110,19 +111,22 @@ public class AboutScene extends PixelScene {
new Flare( 7, 64 ).color( 0x112233, true ).show( wata, 0 ).angularSpeed = +20;
RenderedText wataTitle = renderText( TTL_WATA, 8 );
RenderedTextMultiline wataTitle = renderMultiline( TTL_WATA, 8 );
wataTitle.hardlight(Window.TITLE_COLOR);
add( wataTitle );
wataTitle.x = wataOffset + (colWidth - wataTitle.width()) / 2;
wataTitle.y = wata.y + wata.height + 11;
wataTitle.setPos(
wataOffset + (colWidth - wataTitle.width()) / 2,
wata.y + wata.height + 11
);
align(wataTitle);
RenderedTextMultiline wataText = renderMultiline( TXT_WATA, 8 );
wataText.maxWidth((int)Math.min(colWidth, 120));
wataText.setHightlighting(false); //underscore in cube_code
add( wataText );
wataText.setPos(wataOffset + (colWidth - wataText.width()) / 2, wataTitle.y + wataTitle.height() + 12);
wataText.setPos(wataOffset + (colWidth - wataText.width()) / 2, wataTitle.bottom() + 12);
align(wataText);
RenderedTextMultiline wataLink = renderMultiline( LNK_WATA, 8 );

View File

@ -56,7 +56,6 @@ import com.watabou.noosa.Image;
import com.watabou.noosa.NinePatch;
import com.watabou.noosa.NoosaScript;
import com.watabou.noosa.NoosaScriptNoLighting;
import com.watabou.noosa.RenderedText;
import com.watabou.noosa.SkinnedBlock;
import com.watabou.noosa.audio.Sample;
import com.watabou.noosa.particles.Emitter;
@ -76,8 +75,8 @@ public class AlchemyScene extends PixelScene {
private Emitter lowerBubbles;
private SkinnedBlock water;
private RenderedText energyLeft;
private RenderedText energyCost;
private RenderedTextMultiline energyLeft;
private RenderedTextMultiline energyCost;
private RedButton btnCombine;
@ -114,10 +113,12 @@ public class AlchemyScene extends PixelScene {
add(im);
RenderedText title = PixelScene.renderText( Messages.get(this, "title"), 9 );
RenderedTextMultiline title = PixelScene.renderMultiline( Messages.get(this, "title"), 9 );
title.hardlight(Window.TITLE_COLOR);
title.x = (Camera.main.width - title.width()) / 2f;
title.y = (20 - title.baseLine()) / 2f;
title.setPos(
(Camera.main.width - title.width()) / 2f,
(20 - title.height()) / 2f
);
align(title);
add(title);
@ -273,12 +274,14 @@ public class AlchemyScene extends PixelScene {
btnGuide.setRect(0, 0, 20, 20);
add(btnGuide);
energyLeft = PixelScene.renderText(Messages.get(AlchemyScene.class, "energy", availableEnergy()), 9);
energyLeft.y = Camera.main.height - 5 - energyLeft.baseLine();
energyLeft.x = (Camera.main.width - energyLeft.width())/2;
energyLeft = PixelScene.renderMultiline(Messages.get(AlchemyScene.class, "energy", availableEnergy()), 9);
energyLeft.setPos(
(Camera.main.width - energyLeft.width())/2,
Camera.main.height - 5 - energyLeft.height()
);
add(energyLeft);
energyCost = PixelScene.renderText(6);
energyCost = PixelScene.renderMultiline(6);
add(energyCost);
fadeIn();
@ -350,8 +353,10 @@ public class AlchemyScene extends PixelScene {
output.visible = true;
energyCost.text( Messages.get(AlchemyScene.class, "cost", cost) );
energyCost.y = btnCombine.top() - energyCost.baseLine();
energyCost.x = btnCombine.left() + (btnCombine.width() - energyCost.width())/2;
energyCost.setPos(
btnCombine.left() + (btnCombine.width() - energyCost.width())/2,
btnCombine.top() - energyCost.height()
);
energyCost.visible = (cost > 0);
@ -360,7 +365,7 @@ public class AlchemyScene extends PixelScene {
energyCost.resetColor();
} else {
btnCombine.enable(false);
energyCost.hardlight(1, 0, 0);
energyCost.hardlight(0xFF0000);
}
} else {
@ -381,8 +386,10 @@ public class AlchemyScene extends PixelScene {
if (recipe != null){
provider.spendEnergy(recipe.cost(ingredients));
energyLeft.text(Messages.get(AlchemyScene.class, "energy", availableEnergy()));
energyLeft.y = Camera.main.height - 5 - energyLeft.baseLine();
energyLeft.x = (Camera.main.width - energyLeft.width())/2;
energyLeft.setPos(
(Camera.main.width - energyLeft.width())/2,
Camera.main.height - 5 - energyLeft.height()
);
result = recipe.brew(ingredients);
}

View File

@ -29,12 +29,12 @@ import com.shatteredpixel.shatteredpixeldungeon.effects.BadgeBanner;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.ui.Archs;
import com.shatteredpixel.shatteredpixeldungeon.ui.ExitButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBadge;
import com.watabou.noosa.Camera;
import com.watabou.noosa.Game;
import com.watabou.noosa.Image;
import com.watabou.noosa.RenderedText;
import com.watabou.noosa.audio.Music;
import com.watabou.noosa.audio.Sample;
import com.watabou.noosa.ui.Button;
@ -63,10 +63,12 @@ public class BadgesScene extends PixelScene {
float left = 5;
float top = 20;
RenderedText title = PixelScene.renderText( Messages.get(this, "title"), 9 );
RenderedTextMultiline title = PixelScene.renderMultiline( Messages.get(this, "title"), 9 );
title.hardlight(Window.TITLE_COLOR);
title.x = (w - title.width()) / 2f;
title.y = (top - title.baseLine()) / 2f;
title.setPos(
(w - title.width()) / 2f,
(top - title.height()) / 2f
);
align(title);
add(title);

View File

@ -27,6 +27,7 @@ import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.ui.Archs;
import com.shatteredpixel.shatteredpixeldungeon.ui.ExitButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline;
import com.shatteredpixel.shatteredpixeldungeon.ui.ScrollPane;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
import com.shatteredpixel.shatteredpixeldungeon.ui.changelist.ChangeInfo;
@ -39,7 +40,6 @@ import com.shatteredpixel.shatteredpixeldungeon.ui.changelist.v0_6_X_Changes;
import com.shatteredpixel.shatteredpixeldungeon.ui.changelist.v0_7_X_Changes;
import com.watabou.noosa.Camera;
import com.watabou.noosa.NinePatch;
import com.watabou.noosa.RenderedText;
import com.watabou.noosa.ui.Component;
import java.util.ArrayList;
@ -55,10 +55,12 @@ public class ChangesScene extends PixelScene {
int w = Camera.main.width;
int h = Camera.main.height;
RenderedText title = PixelScene.renderText( Messages.get(this, "title"), 9 );
RenderedTextMultiline title = PixelScene.renderMultiline( Messages.get(this, "title"), 9 );
title.hardlight(Window.TITLE_COLOR);
title.x = (w - title.width()) / 2f;
title.y = (20 - title.baseLine()) / 2f;
title.setPos(
(w - title.width()) / 2f,
(20 - title.height()) / 2f
);
align(title);
add(title);
@ -73,7 +75,7 @@ public class ChangesScene extends PixelScene {
panel.size( pw, ph );
panel.x = (w - pw) / 2f;
panel.y = title.y + title.height();
panel.y = title.bottom() + 4;
align( panel );
add( panel );

View File

@ -586,9 +586,9 @@ public class GameScene extends PixelScene {
float tagLeft = SPDSettings.flipTags() ? 0 : uiCamera.width - scene.attack.width();
if (SPDSettings.flipTags()) {
scene.log.setRect(scene.attack.width(), scene.toolbar.top(), uiCamera.width - scene.attack.width(), 0);
scene.log.setRect(scene.attack.width(), scene.toolbar.top()-2, uiCamera.width - scene.attack.width(), 0);
} else {
scene.log.setRect(0, scene.toolbar.top(), uiCamera.width - scene.attack.width(), 0 );
scene.log.setRect(0, scene.toolbar.top()-2, uiCamera.width - scene.attack.width(), 0 );
}
float pos = scene.toolbar.top();

View File

@ -34,6 +34,7 @@ import com.shatteredpixel.shatteredpixeldungeon.levels.features.Chasm;
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.SpecialRoom;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.ui.GameLog;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndError;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndStory;
import com.watabou.gltextures.TextureCache;
@ -43,7 +44,6 @@ import com.watabou.noosa.Game;
import com.watabou.noosa.Image;
import com.watabou.noosa.NoosaScript;
import com.watabou.noosa.NoosaScriptNoLighting;
import com.watabou.noosa.RenderedText;
import com.watabou.noosa.SkinnedBlock;
import com.watabou.noosa.audio.Sample;
import com.watabou.utils.DeviceCompat;
@ -80,7 +80,7 @@ public class InterlevelScene extends PixelScene {
private Phase phase;
private float timeLeft;
private RenderedText message;
private RenderedTextMultiline message;
private static Thread thread;
private static Exception error = null;
@ -183,9 +183,11 @@ public class InterlevelScene extends PixelScene {
String text = Messages.get(Mode.class, mode.name());
message = PixelScene.renderText( text, 9 );
message.x = (Camera.main.width - message.width()) / 2;
message.y = (Camera.main.height - message.height()) / 2;
message = PixelScene.renderMultiline( text, 9 );
message.setPos(
(Camera.main.width - message.width()) / 2,
(Camera.main.height - message.height()) / 2
);
align(message);
add( message );

View File

@ -38,7 +38,6 @@ import com.watabou.noosa.Camera;
import com.watabou.noosa.ColorBlock;
import com.watabou.noosa.Game;
import com.watabou.noosa.Gizmo;
import com.watabou.noosa.RenderedText;
import com.watabou.noosa.Scene;
import com.watabou.noosa.Visual;
import com.watabou.noosa.ui.Component;
@ -245,15 +244,15 @@ public class PixelScene extends Scene {
return result;
}
public static RenderedText renderText( int size ) {
return renderText("", size);
}
//public static RenderedText renderText( int size ) {
// return renderText("", size);
//}
public static RenderedText renderText( String text, int size ) {
/*public static RenderedText renderText( String text, int size ) {
RenderedText result = new RenderedText( text, size*defaultZoom);
result.scale.set(1/(float)defaultZoom);
return result;
}
}*/
public static RenderedTextMultiline renderMultiline( int size ){
return renderMultiline("", size);

View File

@ -39,7 +39,6 @@ import com.shatteredpixel.shatteredpixeldungeon.windows.WndRanking;
import com.watabou.noosa.BitmapText;
import com.watabou.noosa.Camera;
import com.watabou.noosa.Image;
import com.watabou.noosa.RenderedText;
import com.watabou.noosa.audio.Music;
import com.watabou.noosa.ui.Button;
import com.watabou.utils.GameMath;
@ -73,10 +72,12 @@ public class RankingsScene extends PixelScene {
Rankings.INSTANCE.load();
RenderedText title = PixelScene.renderText( Messages.get(this, "title"), 9);
RenderedTextMultiline title = PixelScene.renderMultiline( Messages.get(this, "title"), 9);
title.hardlight(Window.TITLE_COLOR);
title.x = (w - title.width()) / 2f;
title.y = (20 - title.baseLine()) / 2f;
title.setPos(
(w - title.width()) / 2f,
(20 - title.height()) / 2f
);
align(title);
add(title);
@ -105,38 +106,29 @@ public class RankingsScene extends PixelScene {
}
if (Rankings.INSTANCE.totalNumber >= Rankings.TABLE_SIZE) {
RenderedText label = PixelScene.renderText( Messages.get(this, "total") + " ", 8 );
RenderedTextMultiline label = PixelScene.renderMultiline( 8 );
label.hardlight( 0xCCCCCC );
label.setHightlighting(true, Window.SHPX_COLOR);
label.text( Messages.get(this, "total") + " _" + Rankings.INSTANCE.wonNumber + "_/" + Rankings.INSTANCE.totalNumber );
add( label );
RenderedText won = PixelScene.renderText( Integer.toString( Rankings.INSTANCE.wonNumber ), 8 );
won.hardlight( Window.SHPX_COLOR );
add( won );
RenderedText total = PixelScene.renderText( "/" + Rankings.INSTANCE.totalNumber, 8 );
total.hardlight( 0xCCCCCC );
total.x = (w - total.width()) / 2;
total.y = top + pos * rowHeight + GAP;
add( total );
float tw = label.width() + won.width() + total.width();
label.x = (w - tw) / 2;
won.x = label.x + label.width();
total.x = won.x + won.width();
label.y = won.y = total.y = h - label.height() - GAP;
label.setPos(
(w - label.width()) / 2,
h - label.height() - 2*GAP
);
align(label);
align(total);
align(won);
}
} else {
RenderedText noRec = PixelScene.renderText(Messages.get(this, "no_games"), 8);
RenderedTextMultiline noRec = PixelScene.renderMultiline(Messages.get(this, "no_games"), 8);
noRec.hardlight( 0xCCCCCC );
noRec.x = (w - noRec.width()) / 2;
noRec.y = (h - noRec.height()) / 2;
noRec.setPos(
(w - noRec.width()) / 2,
(h - noRec.height()) / 2
);
align(noRec);
add(noRec);

View File

@ -32,6 +32,7 @@ import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.ui.Archs;
import com.shatteredpixel.shatteredpixeldungeon.ui.ExitButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.Icons;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndGameInProgress;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndStartGame;
@ -39,7 +40,6 @@ import com.watabou.noosa.BitmapText;
import com.watabou.noosa.Camera;
import com.watabou.noosa.Image;
import com.watabou.noosa.NinePatch;
import com.watabou.noosa.RenderedText;
import com.watabou.noosa.ui.Button;
import java.util.ArrayList;
@ -69,10 +69,12 @@ public class StartScene extends PixelScene {
btnExit.setPos( w - btnExit.width(), 0 );
add( btnExit );
RenderedText title = PixelScene.renderText( Messages.get(this, "title"), 9);
RenderedTextMultiline title = PixelScene.renderMultiline( Messages.get(this, "title"), 9);
title.hardlight(Window.TITLE_COLOR);
title.x = (w - title.width()) / 2f;
title.y = (20 - title.baseLine()) / 2f;
title.setPos(
(w - title.width()) / 2f,
(20 - title.height()) / 2f
);
align(title);
add(title);
@ -120,7 +122,7 @@ public class StartScene extends PixelScene {
private NinePatch bg;
private Image hero;
private RenderedText name;
private RenderedTextMultiline name;
private Image steps;
private BitmapText depth;
@ -137,7 +139,7 @@ public class StartScene extends PixelScene {
bg = Chrome.get(Chrome.Type.GEM);
add( bg);
name = PixelScene.renderText(9);
name = PixelScene.renderMultiline(9);
add(name);
}
@ -221,8 +223,10 @@ public class StartScene extends PixelScene {
hero.y = y + (height - hero.height())/2f;
align(hero);
name.x = hero.x + hero.width() + 6;
name.y = y + (height - name.baseLine())/2f;
name.setPos(
hero.x + hero.width() + 6,
y + (height - name.height())/2f
);
align(name);
classIcon.x = x + width - 24 + (16 - classIcon.width())/2f;
@ -242,8 +246,10 @@ public class StartScene extends PixelScene {
align(depth);
} else {
name.x = x + (width - name.width())/2f;
name.y = y + (height - name.baseLine())/2f;
name.setPos(
x + (width - name.width())/2f,
y + (height - name.height())/2f
);
align(name);
}

View File

@ -28,7 +28,6 @@ import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBadge;
import com.watabou.noosa.Game;
import com.watabou.noosa.Image;
import com.watabou.noosa.RenderedText;
import com.watabou.noosa.audio.Sample;
import com.watabou.noosa.ui.Component;
@ -86,7 +85,7 @@ public class BadgesList extends ScrollPane {
private Badges.Badge badge;
private Image icon;
private RenderedText label;
private RenderedTextMultiline label;
public ListItem( Badges.Badge badge ) {
super();
@ -101,7 +100,7 @@ public class BadgesList extends ScrollPane {
icon = new Image();
add( icon );
label = PixelScene.renderText( 6 );
label = PixelScene.renderMultiline( 6 );
add( label );
}
@ -111,8 +110,10 @@ public class BadgesList extends ScrollPane {
icon.y = y + (height - icon.height) / 2;
PixelScene.align(icon);
label.x = icon.x + icon.width + 2;
label.y = y + (height - label.baseLine()) / 2;
label.setPos(
icon.x + icon.width + 2,
y + (height - label.height()) / 2
);
PixelScene.align(label);
}

View File

@ -37,10 +37,9 @@ public class CheckBox extends RedButton {
protected void layout() {
super.layout();
float margin = (height - text.baseLine()) / 2;
float margin = (height - text.height()) / 2;
text.x = x + margin;
text.y = y + margin;
text.setPos( x + margin, y + margin);
PixelScene.align(text);
margin = (height - icon.height) / 2;

View File

@ -148,7 +148,7 @@ public class GameLog extends Component implements Signal.Listener<String> {
RenderedTextMultiline entry = (RenderedTextMultiline)members.get( i );
entry.maxWidth((int)width);
entry.setPos(x, pos-entry.height());
pos -= entry.height();
pos -= entry.height()+2;
}
}

View File

@ -27,7 +27,6 @@ import com.watabou.input.PointerEvent;
import com.watabou.noosa.ColorBlock;
import com.watabou.noosa.NinePatch;
import com.watabou.noosa.PointerArea;
import com.watabou.noosa.RenderedText;
import com.watabou.noosa.ui.Component;
import com.watabou.utils.GameMath;
import com.watabou.utils.PointF;
@ -36,9 +35,9 @@ public abstract class OptionSlider extends Component {
private PointerArea pointerArea;
private RenderedText title;
private RenderedText minTxt;
private RenderedText maxTxt;
private RenderedTextMultiline title;
private RenderedTextMultiline minTxt;
private RenderedTextMultiline maxTxt;
//values are expressed internally as ints, but they can easily be interpreted as something else externally.
private int minVal;
@ -94,9 +93,9 @@ public abstract class OptionSlider extends Component {
add( BG = Chrome.get(Chrome.Type.RED_BUTTON));
BG.alpha(0.5f);
add(title = PixelScene.renderText(9));
add(this.minTxt = PixelScene.renderText(6));
add(this.maxTxt = PixelScene.renderText(6));
add(title = PixelScene.renderMultiline(9));
add(this.minTxt = PixelScene.renderMultiline(6));
add(this.maxTxt = PixelScene.renderMultiline(6));
add(sliderBG = new ColorBlock(1, 1, 0xFF222222));
sliderNode = Chrome.get(Chrome.Type.RED_BUTTON);
@ -142,8 +141,10 @@ public abstract class OptionSlider extends Component {
@Override
protected void layout() {
title.x = x + (width-title.width())/2;
title.y = y+2;
title.setPos(
x + (width-title.width())/2,
y+2
);
PixelScene.align(title);
sliderBG.y = y + height() - 8;
sliderBG.x = x+2;
@ -154,10 +155,14 @@ public abstract class OptionSlider extends Component {
sliderTicks[i].x = (int)(x + 2 + (tickDist*i));
}
minTxt.y = maxTxt.y = sliderBG.y-6-minTxt.baseLine();
minTxt.x = x+1;
maxTxt.x = x+width()-maxTxt.width()-1;
minTxt.setPos(
x+1,
sliderBG.y-6-minTxt.height()
);
maxTxt.setPos(
x+width()-maxTxt.width()-1,
sliderBG.y-6-minTxt.height()
);
sliderNode.x = (int)(x + tickDist*(selectedVal-minVal));
sliderNode.y = sliderBG.y-4;

View File

@ -22,33 +22,32 @@
package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.watabou.noosa.Game;
import com.watabou.noosa.RenderedText;
import com.watabou.noosa.ui.Component;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
//TODO gdx-freetype can manage multi-line layouts for us, and is more efficient. Should consider migrating to that.
public class RenderedTextMultiline extends Component {
private int maxWidth = Integer.MAX_VALUE;
public int nLines;
private String text;
private String[] tokens;
private ArrayList<RenderedText> words = new ArrayList<>();
private static final RenderedText SPACE = new RenderedText();
private static final RenderedText NEWLINE = new RenderedText();
protected String text;
protected String[] tokens = null;
protected ArrayList<RenderedText> words = new ArrayList<>();
protected boolean multiline = false;
private int size;
private float zoom;
private int color = -1;
private static final String SPACE = " ";
private static final String NEWLINE = "\n";
private static final String UNDERSCORE = "_";
private boolean chinese = false;
private int hightlightColor = Window.TITLE_COLOR;
private boolean highlightingEnabled = true;
public RenderedTextMultiline(int size){
this.size = size;
}
@ -62,21 +61,16 @@ public class RenderedTextMultiline extends Component {
this.text = text;
if (text != null && !text.equals("")) {
//conversion for chinese text
chinese = text.replaceAll("\\p{Han}", "").length() != text.length();
if (chinese){
tokens = text.split("");
} else {
tokens = text.split("(?<= )|(?= )|(?<=\n)|(?=\n)");
}
tokens = Game.platform.splitforTextBlock(text, multiline);
build();
}
}
public void text(String text, int maxWidth){
this.maxWidth = maxWidth;
multiline = true;
text(text);
}
@ -91,7 +85,8 @@ public class RenderedTextMultiline extends Component {
public void maxWidth(int maxWidth){
if (this.maxWidth != maxWidth){
this.maxWidth = maxWidth;
layout();
multiline = true;
text(text);
}
}
@ -100,39 +95,30 @@ public class RenderedTextMultiline extends Component {
}
private synchronized void build(){
if (tokens == null) return;
clear();
words = new ArrayList<>();
boolean highlighting = false;
for (String str : tokens){
if (str.equals(UNDERSCORE)){
if (str.equals("_") && highlightingEnabled){
highlighting = !highlighting;
} else if (str.equals(NEWLINE)){
words.add(null);
} else if (!str.equals(SPACE)){
RenderedText word;
if (str.startsWith(UNDERSCORE) && str.endsWith(UNDERSCORE)){
word = new RenderedText(str.substring(1, str.length()-1), size);
word.hardlight(0xFFFF44);
} else {
if (str.startsWith(UNDERSCORE)){
highlighting = !highlighting;
word = new RenderedText(str.substring(1, str.length()), size);
} else if (str.endsWith(UNDERSCORE)) {
word = new RenderedText(str.substring(0, str.length()-1), size);
} else {
word = new RenderedText(str, size);
}
if (highlighting) word.hardlight(0xFFFF44);
else if (color != -1) word.hardlight(color);
if (str.endsWith(UNDERSCORE)) highlighting = !highlighting;
}
} else if (str.equals("\n")){
words.add(NEWLINE);
} else if (str.equals(" ")){
words.add(SPACE);
} else {
RenderedText word = new RenderedText(str, size);
if (highlighting) word.hardlight(hightlightColor);
else if (color != -1) word.hardlight(color);
word.scale.set(zoom);
words.add(word);
add(word);
if (height < word.baseLine()) height = word.baseLine();
if (height < word.height()) height = word.height();
}
}
layout();
@ -143,6 +129,7 @@ public class RenderedTextMultiline extends Component {
for (RenderedText word : words) {
if (word != null) word.scale.set(zoom);
}
layout();
}
public synchronized void hardlight(int color){
@ -151,6 +138,31 @@ public class RenderedTextMultiline extends Component {
if (word != null) word.hardlight( color );
}
}
public synchronized void resetColor(){
this.color = -1;
for (RenderedText word : words) {
if (word != null) word.resetColor();
}
}
public synchronized void alpha(float value){
for (RenderedText word : words) {
if (word != null) word.alpha( value );
}
}
public synchronized void setHightlighting(boolean enabled){
setHightlighting(enabled, Window.TITLE_COLOR);
}
public synchronized void setHightlighting(boolean enabled, int color){
if (enabled != highlightingEnabled || color != hightlightColor) {
hightlightColor = color;
highlightingEnabled = enabled;
build();
}
}
public synchronized void invert(){
if (words != null) {
@ -175,17 +187,20 @@ public class RenderedTextMultiline extends Component {
float height = 0;
nLines = 1;
width = 0;
for (RenderedText word : words){
if (word == null) {
if (word == SPACE){
x += 1.5f;
} else if (word == NEWLINE) {
//newline
y += height+0.5f;
y += height+2f;
x = this.x;
nLines++;
} else {
if (word.height() > height) height = word.baseLine();
if (word.height() > height) height = word.height();
if ((x - this.x) + word.width() > maxWidth){
y += height+0.5f;
y += height+2f;
x = this.x;
nLines++;
}
@ -194,14 +209,15 @@ public class RenderedTextMultiline extends Component {
word.y = y;
PixelScene.align(word);
x += word.width();
if (!chinese) x ++;
else x -= 0.5f;
if ((x - this.x) > width) width = (x - this.x);
//TODO spacing currently doesn't factor in halfwidth and fullwidth characters
//(e.g. Ideographic full stop)
x -= 0.5f;
}
}
this.height = (y - this.y) + height+0.5f;
this.height = (y - this.y) + height;
}
}

View File

@ -26,7 +26,6 @@ import com.shatteredpixel.shatteredpixeldungeon.Chrome;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.watabou.noosa.Image;
import com.watabou.noosa.NinePatch;
import com.watabou.noosa.RenderedText;
import com.watabou.noosa.audio.Sample;
import com.watabou.noosa.ui.Button;
@ -34,7 +33,7 @@ import com.watabou.noosa.ui.Button;
public class StyledButton extends Button {
protected NinePatch bg;
protected RenderedText text;
protected RenderedTextMultiline text;
protected Image icon;
public StyledButton(Chrome.Type type, String label ) {
@ -47,7 +46,7 @@ public class StyledButton extends Button {
bg = Chrome.get( type );
addToBack( bg );
text = PixelScene.renderText( size );
text = PixelScene.renderMultiline( size );
text.text( label );
add( text );
}
@ -68,8 +67,10 @@ public class StyledButton extends Button {
if (text != null && !text.text().equals("")){
componentWidth += text.width() + 2;
text.x = x + (width() + componentWidth)/2f - text.width() - 1;
text.y = y + (height() - text.baseLine()) / 2f;
text.setPos(
x + (width() + componentWidth)/2f - text.width() - 1,
y + (height() - text.height()) / 2f
);
PixelScene.align(text);
}

View File

@ -24,7 +24,6 @@ package com.shatteredpixel.shatteredpixeldungeon.ui.changelist;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline;
import com.watabou.noosa.ColorBlock;
import com.watabou.noosa.RenderedText;
import com.watabou.noosa.ui.Component;
import java.util.ArrayList;
@ -33,7 +32,7 @@ public class ChangeInfo extends Component {
protected ColorBlock line;
private RenderedText title;
private RenderedTextMultiline title;
public boolean major;
private RenderedTextMultiline text;
@ -44,11 +43,11 @@ public class ChangeInfo extends Component {
super();
if (majorTitle){
this.title = PixelScene.renderText( title, 9 );
this.title = PixelScene.renderMultiline( title, 9 );
line = new ColorBlock( 1, 1, 0xFF222222);
add(line);
} else {
this.title = PixelScene.renderText( title, 6 );
this.title = PixelScene.renderMultiline( title, 6 );
line = new ColorBlock( 1, 1, 0xFF333333);
add(line);
}
@ -87,13 +86,15 @@ public class ChangeInfo extends Component {
@Override
protected void layout() {
float posY = this.y + 2;
float posY = this.y + 3;
if (major) posY += 2;
title.x = x + (width - title.width()) / 2f;
title.y = posY;
title.setPos(
x + (width - title.width()) / 2f,
posY
);
PixelScene.align( title );
posY += title.baseLine() + 2;
posY += title.height() + 2;
if (text != null) {
text.maxWidth((int) width());

View File

@ -95,9 +95,8 @@ public class IconTitle extends Component {
int imHeight = (int)Math.max(imIcon.height(), 16);
tfLabel.maxWidth((int)(width - (imWidth + GAP)));
tfLabel.setPos(x + imWidth + GAP, imHeight > tfLabel.height() ?
y +(imHeight - tfLabel.height()) / 2 :
y);
tfLabel.setPos(x + imWidth + GAP,
imHeight > tfLabel.height() ? y +(imHeight - tfLabel.height()) / 2 : y);
PixelScene.align(tfLabel);
if (health.visible) {

View File

@ -54,12 +54,12 @@ import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
import com.shatteredpixel.shatteredpixeldungeon.ui.Icons;
import com.shatteredpixel.shatteredpixeldungeon.ui.ItemSlot;
import com.shatteredpixel.shatteredpixeldungeon.ui.QuickSlotButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline;
import com.watabou.gltextures.TextureCache;
import com.watabou.noosa.BitmapText;
import com.watabou.noosa.ColorBlock;
import com.watabou.noosa.Game;
import com.watabou.noosa.Image;
import com.watabou.noosa.RenderedText;
import com.watabou.noosa.audio.Sample;
public class WndBag extends WndTabbed {
@ -185,11 +185,13 @@ public class WndBag extends WndTabbed {
protected void placeTitle( Bag bag, int width ){
RenderedText txtTitle = PixelScene.renderText(
RenderedTextMultiline txtTitle = PixelScene.renderMultiline(
title != null ? Messages.titleCase(title) : Messages.titleCase( bag.name() ), 9 );
txtTitle.hardlight( TITLE_COLOR );
txtTitle.x = 1;
txtTitle.y = (int)(TITLE_HEIGHT - txtTitle.baseLine()) / 2f - 1;
txtTitle.setPos(
1,
(TITLE_HEIGHT - txtTitle.height()) / 2f - 1
);
PixelScene.align(txtTitle);
add( txtTitle );

View File

@ -29,15 +29,15 @@ import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.ui.CheckBox;
import com.shatteredpixel.shatteredpixeldungeon.ui.IconButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.Icons;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
import com.watabou.noosa.RenderedText;
import java.util.ArrayList;
public class WndChallenges extends Window {
private static final int WIDTH = 120;
private static final int TTL_HEIGHT = 12;
private static final int TTL_HEIGHT = 18;
private static final int BTN_HEIGHT = 18;
private static final int GAP = 1;
@ -50,10 +50,12 @@ public class WndChallenges extends Window {
this.editable = editable;
RenderedText title = PixelScene.renderText( Messages.get(this, "title"), 9 );
RenderedTextMultiline title = PixelScene.renderMultiline( Messages.get(this, "title"), 12 );
title.hardlight( TITLE_COLOR );
title.x = (WIDTH - title.width()) / 2;
title.y = (TTL_HEIGHT - title.height()) / 2;
title.setPos(
(WIDTH - title.width()) / 2,
(TTL_HEIGHT - title.height()) / 2
);
PixelScene.align(title);
add( title );

View File

@ -28,7 +28,6 @@ import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline;
import com.watabou.noosa.Group;
import com.watabou.noosa.RenderedText;
public class WndClass extends WndTabbed {
@ -113,16 +112,9 @@ public class WndClass extends WndTabbed {
pos += GAP;
}
RenderedText dot = PixelScene.renderText( "-", 6 );
dot.y = pos;
if (dotWidth == 0) {
dotWidth = dot.width();
}
add( dot );
RenderedTextMultiline item = PixelScene.renderMultiline( items[i], 6 );
RenderedTextMultiline item = PixelScene.renderMultiline( "-" + items[i], 6 );
item.maxWidth((int)(WIDTH - MARGIN * 2 - dotWidth));
item.setPos(dot.x + dot.width(), pos);
item.setPos(0, pos);
add( item );
pos += item.height();

View File

@ -33,9 +33,9 @@ import com.shatteredpixel.shatteredpixeldungeon.scenes.StartScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.HeroSprite;
import com.shatteredpixel.shatteredpixeldungeon.ui.ActionIndicator;
import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
import com.watabou.noosa.Game;
import com.watabou.noosa.RenderedText;
import com.watabou.noosa.ui.Button;
import com.watabou.utils.Bundle;
import com.watabou.utils.FileUtils;
@ -48,7 +48,7 @@ public class WndGameInProgress extends Window {
private static final int WIDTH = 120;
private static final int HEIGHT = 120;
private int GAP = 5;
private int GAP = 6;
private float pos;
@ -165,17 +165,16 @@ public class WndGameInProgress extends Window {
private void statSlot( String label, String value ) {
RenderedText txt = PixelScene.renderText( label, 8 );
txt.y = pos;
RenderedTextMultiline txt = PixelScene.renderMultiline( label, 8 );
txt.setPos(0, pos);
add( txt );
txt = PixelScene.renderText( value, 8 );
txt.x = WIDTH * 0.6f;
txt.y = pos;
txt = PixelScene.renderMultiline( value, 8 );
txt.setPos(WIDTH * 0.6f, pos);
PixelScene.align(txt);
add( txt );
pos += GAP + txt.baseLine();
pos += GAP + txt.height();
}
private void statSlot( String label, int value ) {

View File

@ -31,13 +31,13 @@ import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.HeroSprite;
import com.shatteredpixel.shatteredpixeldungeon.ui.BuffIndicator;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline;
import com.shatteredpixel.shatteredpixeldungeon.ui.ScrollPane;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
import com.watabou.gltextures.SmartTexture;
import com.watabou.gltextures.TextureCache;
import com.watabou.noosa.Group;
import com.watabou.noosa.Image;
import com.watabou.noosa.RenderedText;
import com.watabou.noosa.TextureFilm;
import com.watabou.noosa.ui.Component;
@ -92,7 +92,7 @@ public class WndHero extends WndTabbed {
private class StatsTab extends Group {
private static final int GAP = 5;
private static final int GAP = 6;
private float pos;
@ -126,18 +126,17 @@ public class WndHero extends WndTabbed {
}
private void statSlot( String label, String value ) {
RenderedText txt = PixelScene.renderText( label, 8 );
txt.y = pos;
RenderedTextMultiline txt = PixelScene.renderMultiline( label, 8 );
txt.setPos(0, pos);
add( txt );
txt = PixelScene.renderText( value, 8 );
txt.x = WIDTH * 0.6f;
txt.y = pos;
txt = PixelScene.renderMultiline( value, 8 );
txt.setPos(WIDTH * 0.6f, pos);
PixelScene.align(txt);
add( txt );
pos += GAP + txt.baseLine();
pos += GAP + txt.height();
}
private void statSlot( String label, int value ) {
@ -198,7 +197,7 @@ public class WndHero extends WndTabbed {
private Buff buff;
Image icon;
RenderedText txt;
RenderedTextMultiline txt;
public BuffSlot( Buff buff ){
super();
@ -211,9 +210,12 @@ public class WndHero extends WndTabbed {
icon.y = this.y;
add( icon );
txt = PixelScene.renderText( buff.toString(), 8 );
txt.x = icon.width + GAP;
txt.y = this.y + (int)(icon.height - txt.baseLine()) / 2;
txt = PixelScene.renderMultiline( buff.toString(), 8 );
txt.setPos(
icon.width + GAP,
this.y + (icon.height - txt.height()) / 2
);
PixelScene.align(txt);
add( txt );
}
@ -222,8 +224,10 @@ public class WndHero extends WndTabbed {
protected void layout() {
super.layout();
icon.y = this.y;
txt.x = icon.width + GAP;
txt.y = pos + (int)(icon.height - txt.baseLine()) / 2;
txt.setPos(
icon.width + GAP,
this.y + (icon.height - txt.height()) / 2
);
}
protected boolean onClick ( float x, float y ) {

View File

@ -24,9 +24,7 @@ package com.shatteredpixel.shatteredpixeldungeon.windows;
import com.shatteredpixel.shatteredpixeldungeon.SPDSettings;
import com.shatteredpixel.shatteredpixeldungeon.items.Heap;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite;
import com.shatteredpixel.shatteredpixeldungeon.ui.ItemSlot;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;

View File

@ -27,7 +27,7 @@ import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.CharSprite;
import com.shatteredpixel.shatteredpixeldungeon.ui.BuffIndicator;
import com.shatteredpixel.shatteredpixeldungeon.ui.HealthBar;
import com.watabou.noosa.RenderedText;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline;
import com.watabou.noosa.ui.Component;
public class WndInfoMob extends WndTitledMessage {
@ -43,13 +43,13 @@ public class WndInfoMob extends WndTitledMessage {
private static final int GAP = 2;
private CharSprite image;
private RenderedText name;
private RenderedTextMultiline name;
private HealthBar health;
private BuffIndicator buffs;
public MobTitle( Mob mob ) {
name = PixelScene.renderText( Messages.titleCase( mob.name ), 9 );
name = PixelScene.renderMultiline( Messages.titleCase( mob.name ), 9 );
name.hardlight( TITLE_COLOR );
add( name );
@ -70,16 +70,17 @@ public class WndInfoMob extends WndTitledMessage {
image.x = 0;
image.y = Math.max( 0, name.height() + health.height() - image.height );
name.x = image.width + GAP;
name.y = Math.max( 0, image.height - health.height() - name.height());
name.setPos(x + image.width + GAP,
image.height > name.height() ? y +(name.height() - image.height()) / 2 : y);
float w = width - image.width - GAP;
health.setRect(image.width + GAP, name.y + name.height(), w, health.height());
health.setRect(image.width + GAP, name.bottom(), w, health.height());
buffs.setPos(
name.x + name.width() + GAP-1,
name.y + name.baseLine() - BuffIndicator.SIZE-2 );
name.right() + GAP-1,
name.bottom() - BuffIndicator.SIZE-2
);
height = health.bottom();
}

View File

@ -32,7 +32,6 @@ import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
import com.watabou.noosa.ColorBlock;
import com.watabou.noosa.Game;
import com.watabou.noosa.RenderedText;
import java.util.ArrayList;
import java.util.Arrays;
@ -73,6 +72,7 @@ public class WndLangs extends Window {
@Override
public void beforeCreate() {
SPDSettings.language(langs.get(langIndex));
Game.platform.resetGenerators();
}
@Override
public void afterCreate() {
@ -115,9 +115,8 @@ public class WndLangs extends Window {
add(separator);
//language info layout.
RenderedText title = PixelScene.renderText( Messages.titleCase(currLang.nativeName()) , 9 );
title.x = textLeft + (textWidth - title.width())/2f;
title.y = 0;
RenderedTextMultiline title = PixelScene.renderMultiline( Messages.titleCase(currLang.nativeName()) , 9 );
title.setPos( textLeft + (textWidth - title.width())/2f, 0 );
title.hardlight(TITLE_COLOR);
PixelScene.align(title);
add(title);
@ -126,7 +125,7 @@ public class WndLangs extends Window {
RenderedTextMultiline info = PixelScene.renderMultiline(6);
info.text("This is the source language, written by the developer.", width - textLeft);
info.setPos(textLeft, title.height() + 2);
info.setPos(textLeft, title.bottom() + 4);
add(info);
} else {
@ -143,7 +142,7 @@ public class WndLangs extends Window {
info.text(Messages.get(this, "unfinished"), width - textLeft);
break;
}
info.setPos(textLeft, title.height() + 2);
info.setPos(textLeft, title.bottom() + 4);
add(info);
RedButton creditsBtn = new RedButton(Messages.titleCase(Messages.get(this, "credits"))){

View File

@ -22,9 +22,8 @@
package com.shatteredpixel.shatteredpixeldungeon.windows;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
import com.watabou.noosa.BitmapTextMultiline;
import com.watabou.noosa.RenderedText;
public class WndList extends Window {
@ -46,19 +45,9 @@ public class WndList extends Window {
pos += GAP;
}
RenderedText dot = PixelScene.renderText( "-", 6 );
dot.x = MARGIN;
dot.y = pos;
if (dotWidth == 0) {
dotWidth = dot.width();
}
add( dot );
BitmapTextMultiline item = PixelScene.createMultiline( items[i], 6 );
item.x = dot.x + dotWidth;
item.y = pos;
item.maxWidth = (int)(WIDTH - MARGIN * 2 - dotWidth);
item.measure();
RenderedTextMultiline item = PixelScene.renderMultiline( "-" + items[i], 6 );
item.setPos( MARGIN, pos );
item.maxWidth(WIDTH - MARGIN*2);
add( item );
pos += item.height();

View File

@ -35,13 +35,13 @@ import com.shatteredpixel.shatteredpixeldungeon.ui.BadgesList;
import com.shatteredpixel.shatteredpixeldungeon.ui.Icons;
import com.shatteredpixel.shatteredpixeldungeon.ui.ItemSlot;
import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline;
import com.shatteredpixel.shatteredpixeldungeon.ui.ScrollPane;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
import com.watabou.noosa.ColorBlock;
import com.watabou.noosa.Game;
import com.watabou.noosa.Group;
import com.watabou.noosa.Image;
import com.watabou.noosa.RenderedText;
import com.watabou.noosa.audio.Sample;
import com.watabou.noosa.ui.Button;
@ -155,7 +155,7 @@ public class WndRanking extends WndTabbed {
private class StatsTab extends Group {
private int GAP = 4;
private int GAP = 5;
public StatsTab() {
super();
@ -171,7 +171,7 @@ public class WndRanking extends WndTabbed {
title.setRect( 0, 0, WIDTH, 0 );
add( title );
float pos = title.bottom();
float pos = title.bottom() + GAP;
if (Dungeon.challenges > 0) {
RedButton btnChallenges = new RedButton( Messages.get(this, "challenges") ) {
@ -187,7 +187,7 @@ public class WndRanking extends WndTabbed {
pos = btnChallenges.bottom();
}
pos += GAP + GAP;
pos += GAP;
pos = statSlot( this, Messages.get(this, "str"), Integer.toString( Dungeon.hero.STR() ), pos );
pos = statSlot( this, Messages.get(this, "health"), Integer.toString( Dungeon.hero.HT ), pos );
@ -211,17 +211,16 @@ public class WndRanking extends WndTabbed {
private float statSlot( Group parent, String label, String value, float pos ) {
RenderedText txt = PixelScene.renderText( label, 7 );
txt.y = pos;
RenderedTextMultiline txt = PixelScene.renderMultiline( label, 7 );
txt.setPos(0, pos);
parent.add( txt );
txt = PixelScene.renderText( value, 7 );
txt.x = WIDTH * 0.65f;
txt.y = pos;
txt = PixelScene.renderMultiline( value, 7 );
txt.setPos(WIDTH * 0.7f, pos);
PixelScene.align(txt);
parent.add( txt );
return pos + GAP + txt.baseLine();
return pos + GAP + txt.height();
}
}
@ -296,7 +295,7 @@ public class WndRanking extends WndTabbed {
private ItemSlot slot;
private ColorBlock bg;
private RenderedText name;
private RenderedTextMultiline name;
public ItemButton( Item item ) {
@ -323,7 +322,7 @@ public class WndRanking extends WndTabbed {
slot = new ItemSlot();
add( slot );
name = PixelScene.renderText( "?", 7 );
name = PixelScene.renderMultiline( 7 );
add( name );
super.createChildren();
@ -337,19 +336,14 @@ public class WndRanking extends WndTabbed {
slot.setRect( x, y, HEIGHT, HEIGHT );
PixelScene.align(slot);
name.x = slot.right() + 2;
name.y = y + (height - name.baseLine()) / 2;
name.maxWidth((int)(width - slot.width() - 2));
name.text(Messages.titleCase(item.name()));
name.setPos(
slot.right()+2,
y + (height - name.height()) / 2
);
PixelScene.align(name);
String str = Messages.titleCase( item.name() );
name.text( str );
if (name.width() > width - name.x) {
do {
str = str.substring( 0, str.length() - 1 );
name.text( str + "..." );
} while (name.width() > width - name.x);
}
super.layout();
}

View File

@ -30,10 +30,10 @@ import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.ui.CheckBox;
import com.shatteredpixel.shatteredpixeldungeon.ui.OptionSlider;
import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline;
import com.shatteredpixel.shatteredpixeldungeon.ui.Toolbar;
import com.watabou.noosa.Game;
import com.watabou.noosa.Group;
import com.watabou.noosa.RenderedText;
import com.watabou.noosa.audio.Sample;
import com.watabou.utils.DeviceCompat;
@ -197,8 +197,8 @@ public class WndSettings extends WndTabbed {
public UITab(){
super();
RenderedText barDesc = PixelScene.renderText(Messages.get(this, "mode"), 9);
barDesc.x = (WIDTH-barDesc.width())/2;
RenderedTextMultiline barDesc = PixelScene.renderMultiline(Messages.get(this, "mode"), 9);
barDesc.setPos((WIDTH-barDesc.width())/2f, GAP_TINY);
PixelScene.align(barDesc);
add(barDesc);
@ -209,7 +209,7 @@ public class WndSettings extends WndTabbed {
Toolbar.updateLayout();
}
};
btnSplit.setRect( 0, barDesc.y + barDesc.baseLine()+GAP_TINY, 36, 16);
btnSplit.setRect( 0, barDesc.bottom() + GAP_TINY, 36, 16);
add(btnSplit);
RedButton btnGrouped = new RedButton(Messages.get(this, "group")){
@ -219,7 +219,7 @@ public class WndSettings extends WndTabbed {
Toolbar.updateLayout();
}
};
btnGrouped.setRect( btnSplit.right()+GAP_TINY, barDesc.y + barDesc.baseLine()+GAP_TINY, 36, 16);
btnGrouped.setRect( btnSplit.right()+GAP_TINY, btnSplit.top(), 36, 16);
add(btnGrouped);
RedButton btnCentered = new RedButton(Messages.get(this, "center")){
@ -229,7 +229,7 @@ public class WndSettings extends WndTabbed {
Toolbar.updateLayout();
}
};
btnCentered.setRect(btnGrouped.right()+GAP_TINY, barDesc.y + barDesc.baseLine()+GAP_TINY, 36, 16);
btnCentered.setRect(btnGrouped.right()+GAP_TINY, btnSplit.top(), 36, 16);
add(btnCentered);
CheckBox chkFlipToolbar = new CheckBox(Messages.get(this, "flip_toolbar")){

View File

@ -40,11 +40,11 @@ import com.shatteredpixel.shatteredpixeldungeon.ui.ActionIndicator;
import com.shatteredpixel.shatteredpixeldungeon.ui.IconButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.Icons;
import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
import com.watabou.noosa.ColorBlock;
import com.watabou.noosa.Game;
import com.watabou.noosa.Image;
import com.watabou.noosa.RenderedText;
import com.watabou.noosa.ui.Button;
import com.watabou.noosa.ui.Component;
import com.watabou.utils.DeviceCompat;
@ -59,10 +59,10 @@ public class WndStartGame extends Window {
Badges.loadGlobal();
Journal.loadGlobal();
RenderedText title = PixelScene.renderText(Messages.get(this, "title"), 12 );
RenderedTextMultiline title = PixelScene.renderMultiline(Messages.get(this, "title"), 12 );
title.hardlight(Window.TITLE_COLOR);
title.x = (WIDTH - title.width())/2f;
title.y = 2;
title.setPos( (WIDTH - title.width())/2f, 2);
PixelScene.align(title);
add(title);
float heroBtnSpacing = (WIDTH - 4*HeroBtn.WIDTH)/5f;
@ -78,7 +78,7 @@ public class WndStartGame extends Window {
ColorBlock separator = new ColorBlock(1, 1, 0xFF222222);
separator.size(WIDTH, 1);
separator.x = 0;
separator.y = title.baseLine() + 6 + HeroBtn.HEIGHT;
separator.y = title.bottom() + 6 + HeroBtn.HEIGHT;
add(separator);
HeroPane ava = new HeroPane();
@ -227,7 +227,7 @@ public class WndStartGame extends Window {
private IconButton heroMisc;
private IconButton heroSubclass;
private RenderedText name;
private RenderedTextMultiline name;
private static final int BTN_SIZE = 20;
@ -283,7 +283,7 @@ public class WndStartGame extends Window {
heroSubclass.setSize(BTN_SIZE, BTN_SIZE);
add(heroSubclass);
name = PixelScene.renderText(12);
name = PixelScene.renderMultiline(12);
add(name);
visible = false;
@ -297,8 +297,10 @@ public class WndStartGame extends Window {
avatar.y = y + (height - avatar.height() - name.baseLine() - 2)/2f;
PixelScene.align(avatar);
name.x = x + (avatar.width() - name.width())/2f;
name.y = avatar.y + avatar.height() + 2;
name.setPos(
x + (avatar.width() - name.width())/2f,
avatar.y + avatar.height() + 2
);
PixelScene.align(name);
heroItem.setPos(x + width - BTN_SIZE, y);

View File

@ -24,11 +24,11 @@ package com.shatteredpixel.shatteredpixeldungeon.windows;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Chrome;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
import com.watabou.noosa.Game;
import com.watabou.noosa.Image;
import com.watabou.noosa.NinePatch;
import com.watabou.noosa.RenderedText;
import com.watabou.noosa.audio.Sample;
import com.watabou.noosa.ui.Button;
import com.watabou.utils.RectF;
@ -196,7 +196,7 @@ public class WndTabbed extends Window {
protected class LabeledTab extends Tab {
private RenderedText btLabel;
private RenderedTextMultiline btLabel;
public LabeledTab( String label ) {
@ -209,7 +209,7 @@ public class WndTabbed extends Window {
protected void createChildren() {
super.createChildren();
btLabel = PixelScene.renderText( 9 );
btLabel = PixelScene.renderMultiline( 9 );
add( btLabel );
}
@ -217,18 +217,17 @@ public class WndTabbed extends Window {
protected void layout() {
super.layout();
btLabel.x = x + (width - btLabel.width()) / 2;
btLabel.y = y + (height - btLabel.baseLine()) / 2 - 1;
if (!selected) {
btLabel.y -= 2;
}
btLabel.setPos(
x + (width - btLabel.width()) / 2,
y + (height - btLabel.height()) / 2 - (selected ? 1 : 3)
);
PixelScene.align(btLabel);
}
@Override
protected void select( boolean value ) {
super.select( value );
btLabel.am = selected ? 1.0f : 0.6f;
btLabel.alpha( selected ? 1.0f : 0.6f );
}
}