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; width = l.width;
//TODO this is almost the same as old height, but old height was clearly a bit off //this is identical to l.height in most cases, but we force this for consistency.
height = size*1.375f; height = Math.round(size*0.75f);
//height = l.height - fonts.get(fontGenerator).get(size).getDescent() + size/5f;
} }
@Override @Override
protected void updateMatrix() { protected void updateMatrix() {
super.updateMatrix(); super.updateMatrix();
//the y value is set at the top of the character, not at the top of accents. //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()*Game.platform.getFontHeightOffset(font))/scale.y) );
Matrix.translate( matrix, 0, Math.round((baseLine()*0.1f)/scale.y) );
} }
private static TextRenderBatch textRenderer = new TextRenderBatch(); private static TextRenderBatch textRenderer = new TextRenderBatch();

View File

@ -46,4 +46,8 @@ public abstract class PlatformSupport {
public abstract BitmapFont getFont(int size, String text); 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 PixmapPacker packer;
private boolean systemfont; private boolean systemfont;
//custom ttf or droid sans, for use with Latin and Cyrillic languages //droid sans / roboto, or a custom pixel font, for use with Latin and Cyrillic languages
private static FreeTypeFontGenerator latinAndCryllicFontGenerator; private static FreeTypeFontGenerator basicFontGenerator;
private static HashMap<Integer, BitmapFont> pixelFonts = new HashMap<>(); private static HashMap<Integer, BitmapFont> basicFonts = new HashMap<>();
//droid sans, for use with hangul languages (Korean) //droid sans / nanum gothic / noto sans, for use with Korean
private static FreeTypeFontGenerator hangulFontGenerator; private static FreeTypeFontGenerator KRFontGenerator;
private static HashMap<Integer, BitmapFont> hangulFonts = new HashMap<>(); private static HashMap<Integer, BitmapFont> KRFonts = new HashMap<>();
//droid sans, for use with han languages (Chinese, Japanese) //droid sans / noto sans, for use with Simplified Chinese
private static FreeTypeFontGenerator hanFontGenerator; private static FreeTypeFontGenerator SCFontGenerator;
private static HashMap<Integer, BitmapFont> hanFonts = new HashMap<>(); 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; 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}"); private boolean android6OTFPresent = false;
public static Pattern hangulMatcher = Pattern.compile("\\p{InHangul_Syllables}");
@Override @Override
public void setupFontGenerators(int pageSize, boolean systemfont) { public void setupFontGenerators(int pageSize, boolean systemfont) {
@ -207,42 +210,53 @@ public class AndroidPlatformSupport extends PlatformSupport {
fonts = new HashMap<>(); fonts = new HashMap<>();
if (systemfont){ if (systemfont){
latinAndCryllicFontGenerator = new FreeTypeFontGenerator(Gdx.files.absolute("/system/fonts/DroidSans.ttf")); basicFontGenerator = new FreeTypeFontGenerator(Gdx.files.absolute("/system/fonts/DroidSans.ttf"));
} else { } else {
//FIXME need to add currency symbols //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 //android 7.0+. Finally back to normalcy, everything nicely in one .ttc
if (Gdx.files.absolute("/system/fonts/NotoSansCJK-Regular.ttc").exists()) { 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? //typefaces are 1-JP, 2-KR, 3-SC, 3-TC.
//might be that different languages prefer a different face, see about tweaking this? int typeFace;
hangulFontGenerator = hanFontGenerator = new FreeTypeFontGenerator(Gdx.files.absolute("/system/fonts/NotoSansCJK-Regular.ttc"), 2); 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 //android 6.0. Fonts are split over multiple .otf files, very awkward
} else if (Gdx.files.absolute("/system/fonts/NotoSansKR-Regular.otf").exists()) { } else if (Gdx.files.absolute("/system/fonts/NotoSansKR-Regular.otf").exists()) {
//FIXME all fonts are messed up here currently, need to fix this KRFontGenerator = new FreeTypeFontGenerator(Gdx.files.absolute("/system/fonts/NotoSansKR-Regular.otf"));
hangulFontGenerator = new FreeTypeFontGenerator(Gdx.files.absolute("/system/fonts/NotoSansKR-Regular.otf")); SCFontGenerator = new FreeTypeFontGenerator(Gdx.files.absolute("/system/fonts/NotoSansSC-Regular.otf"));
hanFontGenerator = 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. //android 4.4-5.1. Korean no longer broken with the addition of NanumGothic.
} else if (Gdx.files.absolute("/system/fonts/NanumGothic.ttf").exists()){ } else if (Gdx.files.absolute("/system/fonts/NanumGothic.ttf").exists()){
hangulFontGenerator = new FreeTypeFontGenerator(Gdx.files.absolute("/system/fonts/NanumGothic.ttf")); KRFontGenerator = new FreeTypeFontGenerator(Gdx.files.absolute("/system/fonts/NanumGothic.ttf"));
hanFontGenerator = new FreeTypeFontGenerator(Gdx.files.absolute("/system/fonts/DroidSansFallback.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 //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()) { } 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 in case //shouldn't ever trigger, but just in case
} else { } else {
hangulFontGenerator = hanFontGenerator = latinAndCryllicFontGenerator; KRFontGenerator = SCFontGenerator = JPFontGenerator = basicFontGenerator;
} }
fonts.put(latinAndCryllicFontGenerator, pixelFonts); fonts.put(basicFontGenerator, basicFonts);
fonts.put(hangulFontGenerator, hangulFonts); fonts.put(KRFontGenerator, KRFonts);
fonts.put(hanFontGenerator, hanFonts); fonts.put(SCFontGenerator, SCFonts);
fonts.put(kataFontGenerator, kataFonts); fonts.put(JPFontGenerator, JPFonts);
//use RGBA4444 to save memory. Extra precision isn't needed here. //use RGBA4444 to save memory. Extra precision isn't needed here.
packer = new PixmapPacker(pageSize, pageSize, Pixmap.Format.RGBA4444, 1, false); packer = new PixmapPacker(pageSize, pageSize, Pixmap.Format.RGBA4444, 1, false);
@ -268,13 +282,19 @@ public class AndroidPlatformSupport extends PlatformSupport {
setupFontGenerators(pageSize, systemfont); 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 ){ private static FreeTypeFontGenerator getGeneratorForString( String input ){
if (hanMatcher.matcher(input).find()){ if (KRMatcher.matcher(input).find()){
return hanFontGenerator; return KRFontGenerator;
} else if (hangulMatcher.matcher(input).find()){ } else if (SCMatcher.matcher(input).find()){
return hangulFontGenerator; return SCFontGenerator;
} else if (JPMatcher.matcher(input).find()){
return JPFontGenerator;
} else { } else {
return latinAndCryllicFontGenerator; return basicFontGenerator;
} }
} }
@ -299,4 +319,43 @@ public class AndroidPlatformSupport extends PlatformSupport {
return fonts.get(generator).get(size); 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.messages.Languages;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.watabou.noosa.Game; import com.watabou.noosa.Game;
import com.watabou.noosa.RenderedText;
import com.watabou.noosa.audio.Music; import com.watabou.noosa.audio.Music;
import com.watabou.noosa.audio.Sample; import com.watabou.noosa.audio.Sample;
import com.watabou.utils.GameSettings; import com.watabou.utils.GameSettings;
@ -251,7 +250,6 @@ public class SPDSettings extends GameSettings {
public static void systemFont(boolean value){ public static void systemFont(boolean value){
put(KEY_SYSTEMFONT, value); put(KEY_SYSTEMFONT, value);
ShatteredPixelDungeon.seamlessResetScene();
} }
public static boolean systemFont(){ 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.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.scenes.WelcomeScene; import com.shatteredpixel.shatteredpixeldungeon.scenes.WelcomeScene;
import com.watabou.noosa.Game; import com.watabou.noosa.Game;
import com.watabou.noosa.RenderedText;
import com.watabou.noosa.audio.Music; import com.watabou.noosa.audio.Music;
import com.watabou.noosa.audio.Sample; import com.watabou.noosa.audio.Sample;
import com.watabou.utils.PlatformSupport; 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.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene; import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.tiles.DungeonTilemap; import com.shatteredpixel.shatteredpixeldungeon.tiles.DungeonTilemap;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline;
import com.watabou.noosa.Camera; import com.watabou.noosa.Camera;
import com.watabou.noosa.Game; import com.watabou.noosa.Game;
import com.watabou.noosa.RenderedText; import com.watabou.noosa.RenderedText;
@ -32,7 +33,7 @@ import com.watabou.utils.SparseArray;
import java.util.ArrayList; import java.util.ArrayList;
public class FloatingText extends RenderedText { public class FloatingText extends RenderedTextMultiline {
private static final float LIFESPAN = 1f; private static final float LIFESPAN = 1f;
private static final float DISTANCE = DungeonTilemap.SIZE; 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<>(); private static final SparseArray<ArrayList<FloatingText>> stacks = new SparseArray<>();
public FloatingText() { public FloatingText() {
speed.y = - DISTANCE / LIFESPAN; super(9*PixelScene.defaultZoom);
} }
@Override @Override
@ -57,6 +58,12 @@ public class FloatingText extends RenderedText {
} else { } else {
float p = timeLeft / LIFESPAN; float p = timeLeft / LIFESPAN;
alpha( p > 0.5f ? 1 : p * 2 ); 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(); revive();
size( 9 * PixelScene.defaultZoom); zoom( 1 / (float)PixelScene.defaultZoom );
scale.set( 1 / (float)PixelScene.defaultZoom );
text( text ); text( text );
hardlight( color ); hardlight( color );
this.x = PixelScene.align( Camera.main, x - width() / 2); setPos(
this.y = PixelScene.align( Camera.main, y - height()); PixelScene.align( Camera.main, x - width() / 2),
PixelScene.align( Camera.main, y - height())
);
timeLeft = LIFESPAN; timeLeft = LIFESPAN;
} }
@ -137,8 +145,8 @@ public class FloatingText extends RenderedText {
int aboveIndex = stack.size() - 1; int aboveIndex = stack.size() - 1;
while (aboveIndex >= 0) { while (aboveIndex >= 0) {
FloatingText above = stack.get(aboveIndex); FloatingText above = stack.get(aboveIndex);
if (above.y + above.height() > below.y) { if (above.bottom() + 4 > below.top()) {
above.y = below.y - above.height(); above.setPos(above.left(), below.top() - above.height() - 4);
below = above; below = above;
aboveIndex--; aboveIndex--;

View File

@ -33,7 +33,6 @@ import com.watabou.input.PointerEvent;
import com.watabou.noosa.Camera; import com.watabou.noosa.Camera;
import com.watabou.noosa.Image; import com.watabou.noosa.Image;
import com.watabou.noosa.PointerArea; import com.watabou.noosa.PointerArea;
import com.watabou.noosa.RenderedText;
import com.watabou.utils.DeviceCompat; import com.watabou.utils.DeviceCompat;
public class AboutScene extends PixelScene { 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; 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 ); shpxtitle.hardlight( Window.SHPX_COLOR );
add( shpxtitle ); add( shpxtitle );
shpxtitle.x = (colWidth - shpxtitle.width()) / 2; shpxtitle.setPos(
shpxtitle.y = shpx.y + shpx.height + 5; (colWidth - shpxtitle.width()) / 2,
shpx.y + shpx.height + 5
);
align(shpxtitle); align(shpxtitle);
RenderedTextMultiline shpxtext = renderMultiline( TXT_SHPX, 8 ); RenderedTextMultiline shpxtext = renderMultiline( TXT_SHPX, 8 );
shpxtext.maxWidth((int)Math.min(colWidth, 120)); shpxtext.maxWidth((int)Math.min(colWidth, 120));
add( shpxtext ); add( shpxtext );
shpxtext.setPos((colWidth - shpxtext.width()) / 2, shpxtitle.y + shpxtitle.height() + 12); shpxtext.setPos((colWidth - shpxtext.width()) / 2, shpxtitle.bottom() + 12);
align(shpxtext); align(shpxtext);
RenderedTextMultiline shpxlink = renderMultiline( LNK_SHPX, 8 ); 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; 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); wataTitle.hardlight(Window.TITLE_COLOR);
add( wataTitle ); add( wataTitle );
wataTitle.x = wataOffset + (colWidth - wataTitle.width()) / 2; wataTitle.setPos(
wataTitle.y = wata.y + wata.height + 11; wataOffset + (colWidth - wataTitle.width()) / 2,
wata.y + wata.height + 11
);
align(wataTitle); align(wataTitle);
RenderedTextMultiline wataText = renderMultiline( TXT_WATA, 8 ); RenderedTextMultiline wataText = renderMultiline( TXT_WATA, 8 );
wataText.maxWidth((int)Math.min(colWidth, 120)); wataText.maxWidth((int)Math.min(colWidth, 120));
wataText.setHightlighting(false); //underscore in cube_code
add( wataText ); 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); align(wataText);
RenderedTextMultiline wataLink = renderMultiline( LNK_WATA, 8 ); 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.NinePatch;
import com.watabou.noosa.NoosaScript; import com.watabou.noosa.NoosaScript;
import com.watabou.noosa.NoosaScriptNoLighting; import com.watabou.noosa.NoosaScriptNoLighting;
import com.watabou.noosa.RenderedText;
import com.watabou.noosa.SkinnedBlock; import com.watabou.noosa.SkinnedBlock;
import com.watabou.noosa.audio.Sample; import com.watabou.noosa.audio.Sample;
import com.watabou.noosa.particles.Emitter; import com.watabou.noosa.particles.Emitter;
@ -76,8 +75,8 @@ public class AlchemyScene extends PixelScene {
private Emitter lowerBubbles; private Emitter lowerBubbles;
private SkinnedBlock water; private SkinnedBlock water;
private RenderedText energyLeft; private RenderedTextMultiline energyLeft;
private RenderedText energyCost; private RenderedTextMultiline energyCost;
private RedButton btnCombine; private RedButton btnCombine;
@ -114,10 +113,12 @@ public class AlchemyScene extends PixelScene {
add(im); 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.hardlight(Window.TITLE_COLOR);
title.x = (Camera.main.width - title.width()) / 2f; title.setPos(
title.y = (20 - title.baseLine()) / 2f; (Camera.main.width - title.width()) / 2f,
(20 - title.height()) / 2f
);
align(title); align(title);
add(title); add(title);
@ -273,12 +274,14 @@ public class AlchemyScene extends PixelScene {
btnGuide.setRect(0, 0, 20, 20); btnGuide.setRect(0, 0, 20, 20);
add(btnGuide); add(btnGuide);
energyLeft = PixelScene.renderText(Messages.get(AlchemyScene.class, "energy", availableEnergy()), 9); energyLeft = PixelScene.renderMultiline(Messages.get(AlchemyScene.class, "energy", availableEnergy()), 9);
energyLeft.y = Camera.main.height - 5 - energyLeft.baseLine(); energyLeft.setPos(
energyLeft.x = (Camera.main.width - energyLeft.width())/2; (Camera.main.width - energyLeft.width())/2,
Camera.main.height - 5 - energyLeft.height()
);
add(energyLeft); add(energyLeft);
energyCost = PixelScene.renderText(6); energyCost = PixelScene.renderMultiline(6);
add(energyCost); add(energyCost);
fadeIn(); fadeIn();
@ -350,8 +353,10 @@ public class AlchemyScene extends PixelScene {
output.visible = true; output.visible = true;
energyCost.text( Messages.get(AlchemyScene.class, "cost", cost) ); energyCost.text( Messages.get(AlchemyScene.class, "cost", cost) );
energyCost.y = btnCombine.top() - energyCost.baseLine(); energyCost.setPos(
energyCost.x = btnCombine.left() + (btnCombine.width() - energyCost.width())/2; btnCombine.left() + (btnCombine.width() - energyCost.width())/2,
btnCombine.top() - energyCost.height()
);
energyCost.visible = (cost > 0); energyCost.visible = (cost > 0);
@ -360,7 +365,7 @@ public class AlchemyScene extends PixelScene {
energyCost.resetColor(); energyCost.resetColor();
} else { } else {
btnCombine.enable(false); btnCombine.enable(false);
energyCost.hardlight(1, 0, 0); energyCost.hardlight(0xFF0000);
} }
} else { } else {
@ -381,8 +386,10 @@ public class AlchemyScene extends PixelScene {
if (recipe != null){ if (recipe != null){
provider.spendEnergy(recipe.cost(ingredients)); provider.spendEnergy(recipe.cost(ingredients));
energyLeft.text(Messages.get(AlchemyScene.class, "energy", availableEnergy())); energyLeft.text(Messages.get(AlchemyScene.class, "energy", availableEnergy()));
energyLeft.y = Camera.main.height - 5 - energyLeft.baseLine(); energyLeft.setPos(
energyLeft.x = (Camera.main.width - energyLeft.width())/2; (Camera.main.width - energyLeft.width())/2,
Camera.main.height - 5 - energyLeft.height()
);
result = recipe.brew(ingredients); 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.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.ui.Archs; import com.shatteredpixel.shatteredpixeldungeon.ui.Archs;
import com.shatteredpixel.shatteredpixeldungeon.ui.ExitButton; import com.shatteredpixel.shatteredpixeldungeon.ui.ExitButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window; import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBadge; import com.shatteredpixel.shatteredpixeldungeon.windows.WndBadge;
import com.watabou.noosa.Camera; import com.watabou.noosa.Camera;
import com.watabou.noosa.Game; import com.watabou.noosa.Game;
import com.watabou.noosa.Image; import com.watabou.noosa.Image;
import com.watabou.noosa.RenderedText;
import com.watabou.noosa.audio.Music; import com.watabou.noosa.audio.Music;
import com.watabou.noosa.audio.Sample; import com.watabou.noosa.audio.Sample;
import com.watabou.noosa.ui.Button; import com.watabou.noosa.ui.Button;
@ -63,10 +63,12 @@ public class BadgesScene extends PixelScene {
float left = 5; float left = 5;
float top = 20; 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.hardlight(Window.TITLE_COLOR);
title.x = (w - title.width()) / 2f; title.setPos(
title.y = (top - title.baseLine()) / 2f; (w - title.width()) / 2f,
(top - title.height()) / 2f
);
align(title); align(title);
add(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.Archs;
import com.shatteredpixel.shatteredpixeldungeon.ui.ExitButton; import com.shatteredpixel.shatteredpixeldungeon.ui.ExitButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton; import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline;
import com.shatteredpixel.shatteredpixeldungeon.ui.ScrollPane; import com.shatteredpixel.shatteredpixeldungeon.ui.ScrollPane;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window; import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
import com.shatteredpixel.shatteredpixeldungeon.ui.changelist.ChangeInfo; 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.shatteredpixel.shatteredpixeldungeon.ui.changelist.v0_7_X_Changes;
import com.watabou.noosa.Camera; import com.watabou.noosa.Camera;
import com.watabou.noosa.NinePatch; import com.watabou.noosa.NinePatch;
import com.watabou.noosa.RenderedText;
import com.watabou.noosa.ui.Component; import com.watabou.noosa.ui.Component;
import java.util.ArrayList; import java.util.ArrayList;
@ -55,10 +55,12 @@ public class ChangesScene extends PixelScene {
int w = Camera.main.width; int w = Camera.main.width;
int h = Camera.main.height; 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.hardlight(Window.TITLE_COLOR);
title.x = (w - title.width()) / 2f; title.setPos(
title.y = (20 - title.baseLine()) / 2f; (w - title.width()) / 2f,
(20 - title.height()) / 2f
);
align(title); align(title);
add(title); add(title);
@ -73,7 +75,7 @@ public class ChangesScene extends PixelScene {
panel.size( pw, ph ); panel.size( pw, ph );
panel.x = (w - pw) / 2f; panel.x = (w - pw) / 2f;
panel.y = title.y + title.height(); panel.y = title.bottom() + 4;
align( panel ); align( panel );
add( panel ); add( panel );

View File

@ -586,9 +586,9 @@ public class GameScene extends PixelScene {
float tagLeft = SPDSettings.flipTags() ? 0 : uiCamera.width - scene.attack.width(); float tagLeft = SPDSettings.flipTags() ? 0 : uiCamera.width - scene.attack.width();
if (SPDSettings.flipTags()) { 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 { } 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(); 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.levels.rooms.special.SpecialRoom;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.ui.GameLog; import com.shatteredpixel.shatteredpixeldungeon.ui.GameLog;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndError; import com.shatteredpixel.shatteredpixeldungeon.windows.WndError;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndStory; import com.shatteredpixel.shatteredpixeldungeon.windows.WndStory;
import com.watabou.gltextures.TextureCache; import com.watabou.gltextures.TextureCache;
@ -43,7 +44,6 @@ import com.watabou.noosa.Game;
import com.watabou.noosa.Image; import com.watabou.noosa.Image;
import com.watabou.noosa.NoosaScript; import com.watabou.noosa.NoosaScript;
import com.watabou.noosa.NoosaScriptNoLighting; import com.watabou.noosa.NoosaScriptNoLighting;
import com.watabou.noosa.RenderedText;
import com.watabou.noosa.SkinnedBlock; import com.watabou.noosa.SkinnedBlock;
import com.watabou.noosa.audio.Sample; import com.watabou.noosa.audio.Sample;
import com.watabou.utils.DeviceCompat; import com.watabou.utils.DeviceCompat;
@ -80,7 +80,7 @@ public class InterlevelScene extends PixelScene {
private Phase phase; private Phase phase;
private float timeLeft; private float timeLeft;
private RenderedText message; private RenderedTextMultiline message;
private static Thread thread; private static Thread thread;
private static Exception error = null; private static Exception error = null;
@ -183,9 +183,11 @@ public class InterlevelScene extends PixelScene {
String text = Messages.get(Mode.class, mode.name()); String text = Messages.get(Mode.class, mode.name());
message = PixelScene.renderText( text, 9 ); message = PixelScene.renderMultiline( text, 9 );
message.x = (Camera.main.width - message.width()) / 2; message.setPos(
message.y = (Camera.main.height - message.height()) / 2; (Camera.main.width - message.width()) / 2,
(Camera.main.height - message.height()) / 2
);
align(message); align(message);
add( message ); add( message );

View File

@ -38,7 +38,6 @@ import com.watabou.noosa.Camera;
import com.watabou.noosa.ColorBlock; import com.watabou.noosa.ColorBlock;
import com.watabou.noosa.Game; import com.watabou.noosa.Game;
import com.watabou.noosa.Gizmo; import com.watabou.noosa.Gizmo;
import com.watabou.noosa.RenderedText;
import com.watabou.noosa.Scene; import com.watabou.noosa.Scene;
import com.watabou.noosa.Visual; import com.watabou.noosa.Visual;
import com.watabou.noosa.ui.Component; import com.watabou.noosa.ui.Component;
@ -245,15 +244,15 @@ public class PixelScene extends Scene {
return result; return result;
} }
public static RenderedText renderText( int size ) { //public static RenderedText renderText( int size ) {
return renderText("", 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); RenderedText result = new RenderedText( text, size*defaultZoom);
result.scale.set(1/(float)defaultZoom); result.scale.set(1/(float)defaultZoom);
return result; return result;
} }*/
public static RenderedTextMultiline renderMultiline( int size ){ public static RenderedTextMultiline renderMultiline( int size ){
return renderMultiline("", 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.BitmapText;
import com.watabou.noosa.Camera; import com.watabou.noosa.Camera;
import com.watabou.noosa.Image; import com.watabou.noosa.Image;
import com.watabou.noosa.RenderedText;
import com.watabou.noosa.audio.Music; import com.watabou.noosa.audio.Music;
import com.watabou.noosa.ui.Button; import com.watabou.noosa.ui.Button;
import com.watabou.utils.GameMath; import com.watabou.utils.GameMath;
@ -73,10 +72,12 @@ public class RankingsScene extends PixelScene {
Rankings.INSTANCE.load(); 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.hardlight(Window.TITLE_COLOR);
title.x = (w - title.width()) / 2f; title.setPos(
title.y = (20 - title.baseLine()) / 2f; (w - title.width()) / 2f,
(20 - title.height()) / 2f
);
align(title); align(title);
add(title); add(title);
@ -105,38 +106,29 @@ public class RankingsScene extends PixelScene {
} }
if (Rankings.INSTANCE.totalNumber >= Rankings.TABLE_SIZE) { 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.hardlight( 0xCCCCCC );
label.setHightlighting(true, Window.SHPX_COLOR);
label.text( Messages.get(this, "total") + " _" + Rankings.INSTANCE.wonNumber + "_/" + Rankings.INSTANCE.totalNumber );
add( label ); add( label );
RenderedText won = PixelScene.renderText( Integer.toString( Rankings.INSTANCE.wonNumber ), 8 ); label.setPos(
won.hardlight( Window.SHPX_COLOR ); (w - label.width()) / 2,
add( won ); h - label.height() - 2*GAP
);
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;
align(label); align(label);
align(total);
align(won);
} }
} else { } 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.hardlight( 0xCCCCCC );
noRec.x = (w - noRec.width()) / 2; noRec.setPos(
noRec.y = (h - noRec.height()) / 2; (w - noRec.width()) / 2,
(h - noRec.height()) / 2
);
align(noRec); align(noRec);
add(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.Archs;
import com.shatteredpixel.shatteredpixeldungeon.ui.ExitButton; import com.shatteredpixel.shatteredpixeldungeon.ui.ExitButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.Icons; import com.shatteredpixel.shatteredpixeldungeon.ui.Icons;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window; import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndGameInProgress; import com.shatteredpixel.shatteredpixeldungeon.windows.WndGameInProgress;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndStartGame; import com.shatteredpixel.shatteredpixeldungeon.windows.WndStartGame;
@ -39,7 +40,6 @@ import com.watabou.noosa.BitmapText;
import com.watabou.noosa.Camera; import com.watabou.noosa.Camera;
import com.watabou.noosa.Image; import com.watabou.noosa.Image;
import com.watabou.noosa.NinePatch; import com.watabou.noosa.NinePatch;
import com.watabou.noosa.RenderedText;
import com.watabou.noosa.ui.Button; import com.watabou.noosa.ui.Button;
import java.util.ArrayList; import java.util.ArrayList;
@ -69,10 +69,12 @@ public class StartScene extends PixelScene {
btnExit.setPos( w - btnExit.width(), 0 ); btnExit.setPos( w - btnExit.width(), 0 );
add( btnExit ); 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.hardlight(Window.TITLE_COLOR);
title.x = (w - title.width()) / 2f; title.setPos(
title.y = (20 - title.baseLine()) / 2f; (w - title.width()) / 2f,
(20 - title.height()) / 2f
);
align(title); align(title);
add(title); add(title);
@ -120,7 +122,7 @@ public class StartScene extends PixelScene {
private NinePatch bg; private NinePatch bg;
private Image hero; private Image hero;
private RenderedText name; private RenderedTextMultiline name;
private Image steps; private Image steps;
private BitmapText depth; private BitmapText depth;
@ -137,7 +139,7 @@ public class StartScene extends PixelScene {
bg = Chrome.get(Chrome.Type.GEM); bg = Chrome.get(Chrome.Type.GEM);
add( bg); add( bg);
name = PixelScene.renderText(9); name = PixelScene.renderMultiline(9);
add(name); add(name);
} }
@ -221,8 +223,10 @@ public class StartScene extends PixelScene {
hero.y = y + (height - hero.height())/2f; hero.y = y + (height - hero.height())/2f;
align(hero); align(hero);
name.x = hero.x + hero.width() + 6; name.setPos(
name.y = y + (height - name.baseLine())/2f; hero.x + hero.width() + 6,
y + (height - name.height())/2f
);
align(name); align(name);
classIcon.x = x + width - 24 + (16 - classIcon.width())/2f; classIcon.x = x + width - 24 + (16 - classIcon.width())/2f;
@ -242,8 +246,10 @@ public class StartScene extends PixelScene {
align(depth); align(depth);
} else { } else {
name.x = x + (width - name.width())/2f; name.setPos(
name.y = y + (height - name.baseLine())/2f; x + (width - name.width())/2f,
y + (height - name.height())/2f
);
align(name); align(name);
} }

View File

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

View File

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

View File

@ -22,32 +22,31 @@
package com.shatteredpixel.shatteredpixeldungeon.ui; package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene; import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.watabou.noosa.Game;
import com.watabou.noosa.RenderedText; import com.watabou.noosa.RenderedText;
import com.watabou.noosa.ui.Component; import com.watabou.noosa.ui.Component;
import java.util.ArrayList; 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 { public class RenderedTextMultiline extends Component {
private int maxWidth = Integer.MAX_VALUE; private int maxWidth = Integer.MAX_VALUE;
public int nLines; public int nLines;
private String text; private static final RenderedText SPACE = new RenderedText();
private String[] tokens; private static final RenderedText NEWLINE = new RenderedText();
private ArrayList<RenderedText> words = new ArrayList<>();
protected String text;
protected String[] tokens = null;
protected ArrayList<RenderedText> words = new ArrayList<>();
protected boolean multiline = false;
private int size; private int size;
private float zoom; private float zoom;
private int color = -1; private int color = -1;
private static final String SPACE = " "; private int hightlightColor = Window.TITLE_COLOR;
private static final String NEWLINE = "\n"; private boolean highlightingEnabled = true;
private static final String UNDERSCORE = "_";
private boolean chinese = false;
public RenderedTextMultiline(int size){ public RenderedTextMultiline(int size){
this.size = size; this.size = size;
@ -62,21 +61,16 @@ public class RenderedTextMultiline extends Component {
this.text = text; this.text = text;
if (text != null && !text.equals("")) { if (text != null && !text.equals("")) {
//conversion for chinese text
chinese = text.replaceAll("\\p{Han}", "").length() != text.length(); tokens = Game.platform.splitforTextBlock(text, multiline);
if (chinese){
tokens = text.split("");
} else {
tokens = text.split("(?<= )|(?= )|(?<=\n)|(?=\n)");
}
build(); build();
} }
} }
public void text(String text, int maxWidth){ public void text(String text, int maxWidth){
this.maxWidth = maxWidth; this.maxWidth = maxWidth;
multiline = true;
text(text); text(text);
} }
@ -91,7 +85,8 @@ public class RenderedTextMultiline extends Component {
public void maxWidth(int maxWidth){ public void maxWidth(int maxWidth){
if (this.maxWidth != maxWidth){ if (this.maxWidth != maxWidth){
this.maxWidth = maxWidth; this.maxWidth = maxWidth;
layout(); multiline = true;
text(text);
} }
} }
@ -100,39 +95,30 @@ public class RenderedTextMultiline extends Component {
} }
private synchronized void build(){ private synchronized void build(){
if (tokens == null) return;
clear(); clear();
words = new ArrayList<>(); words = new ArrayList<>();
boolean highlighting = false; boolean highlighting = false;
for (String str : tokens){ for (String str : tokens){
if (str.equals(UNDERSCORE)){
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; if (str.equals("_") && highlightingEnabled){
} 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); word.scale.set(zoom);
words.add(word); words.add(word);
add(word); add(word);
if (height < word.baseLine()) height = word.baseLine(); if (height < word.height()) height = word.height();
} }
} }
layout(); layout();
@ -143,6 +129,7 @@ public class RenderedTextMultiline extends Component {
for (RenderedText word : words) { for (RenderedText word : words) {
if (word != null) word.scale.set(zoom); if (word != null) word.scale.set(zoom);
} }
layout();
} }
public synchronized void hardlight(int color){ public synchronized void hardlight(int color){
@ -152,6 +139,31 @@ public class RenderedTextMultiline extends Component {
} }
} }
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(){ public synchronized void invert(){
if (words != null) { if (words != null) {
for (RenderedText word : words) { for (RenderedText word : words) {
@ -175,17 +187,20 @@ public class RenderedTextMultiline extends Component {
float height = 0; float height = 0;
nLines = 1; nLines = 1;
width = 0;
for (RenderedText word : words){ for (RenderedText word : words){
if (word == null) { if (word == SPACE){
x += 1.5f;
} else if (word == NEWLINE) {
//newline //newline
y += height+0.5f; y += height+2f;
x = this.x; x = this.x;
nLines++; nLines++;
} else { } else {
if (word.height() > height) height = word.baseLine(); if (word.height() > height) height = word.height();
if ((x - this.x) + word.width() > maxWidth){ if ((x - this.x) + word.width() > maxWidth){
y += height+0.5f; y += height+2f;
x = this.x; x = this.x;
nLines++; nLines++;
} }
@ -195,13 +210,14 @@ public class RenderedTextMultiline extends Component {
PixelScene.align(word); PixelScene.align(word);
x += word.width(); x += word.width();
if (!chinese) x ++;
else x -= 0.5f;
if ((x - this.x) > width) width = (x - this.x); 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.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.watabou.noosa.Image; import com.watabou.noosa.Image;
import com.watabou.noosa.NinePatch; import com.watabou.noosa.NinePatch;
import com.watabou.noosa.RenderedText;
import com.watabou.noosa.audio.Sample; import com.watabou.noosa.audio.Sample;
import com.watabou.noosa.ui.Button; import com.watabou.noosa.ui.Button;
@ -34,7 +33,7 @@ import com.watabou.noosa.ui.Button;
public class StyledButton extends Button { public class StyledButton extends Button {
protected NinePatch bg; protected NinePatch bg;
protected RenderedText text; protected RenderedTextMultiline text;
protected Image icon; protected Image icon;
public StyledButton(Chrome.Type type, String label ) { public StyledButton(Chrome.Type type, String label ) {
@ -47,7 +46,7 @@ public class StyledButton extends Button {
bg = Chrome.get( type ); bg = Chrome.get( type );
addToBack( bg ); addToBack( bg );
text = PixelScene.renderText( size ); text = PixelScene.renderMultiline( size );
text.text( label ); text.text( label );
add( text ); add( text );
} }
@ -68,8 +67,10 @@ public class StyledButton extends Button {
if (text != null && !text.text().equals("")){ if (text != null && !text.text().equals("")){
componentWidth += text.width() + 2; componentWidth += text.width() + 2;
text.x = x + (width() + componentWidth)/2f - text.width() - 1; text.setPos(
text.y = y + (height() - text.baseLine()) / 2f; x + (width() + componentWidth)/2f - text.width() - 1,
y + (height() - text.height()) / 2f
);
PixelScene.align(text); 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.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline; import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline;
import com.watabou.noosa.ColorBlock; import com.watabou.noosa.ColorBlock;
import com.watabou.noosa.RenderedText;
import com.watabou.noosa.ui.Component; import com.watabou.noosa.ui.Component;
import java.util.ArrayList; import java.util.ArrayList;
@ -33,7 +32,7 @@ public class ChangeInfo extends Component {
protected ColorBlock line; protected ColorBlock line;
private RenderedText title; private RenderedTextMultiline title;
public boolean major; public boolean major;
private RenderedTextMultiline text; private RenderedTextMultiline text;
@ -44,11 +43,11 @@ public class ChangeInfo extends Component {
super(); super();
if (majorTitle){ if (majorTitle){
this.title = PixelScene.renderText( title, 9 ); this.title = PixelScene.renderMultiline( title, 9 );
line = new ColorBlock( 1, 1, 0xFF222222); line = new ColorBlock( 1, 1, 0xFF222222);
add(line); add(line);
} else { } else {
this.title = PixelScene.renderText( title, 6 ); this.title = PixelScene.renderMultiline( title, 6 );
line = new ColorBlock( 1, 1, 0xFF333333); line = new ColorBlock( 1, 1, 0xFF333333);
add(line); add(line);
} }
@ -87,13 +86,15 @@ public class ChangeInfo extends Component {
@Override @Override
protected void layout() { protected void layout() {
float posY = this.y + 2; float posY = this.y + 3;
if (major) posY += 2; if (major) posY += 2;
title.x = x + (width - title.width()) / 2f; title.setPos(
title.y = posY; x + (width - title.width()) / 2f,
posY
);
PixelScene.align( title ); PixelScene.align( title );
posY += title.baseLine() + 2; posY += title.height() + 2;
if (text != null) { if (text != null) {
text.maxWidth((int) width()); text.maxWidth((int) width());

View File

@ -95,9 +95,8 @@ public class IconTitle extends Component {
int imHeight = (int)Math.max(imIcon.height(), 16); int imHeight = (int)Math.max(imIcon.height(), 16);
tfLabel.maxWidth((int)(width - (imWidth + GAP))); tfLabel.maxWidth((int)(width - (imWidth + GAP)));
tfLabel.setPos(x + imWidth + GAP, imHeight > tfLabel.height() ? tfLabel.setPos(x + imWidth + GAP,
y +(imHeight - tfLabel.height()) / 2 : imHeight > tfLabel.height() ? y +(imHeight - tfLabel.height()) / 2 : y);
y);
PixelScene.align(tfLabel); PixelScene.align(tfLabel);
if (health.visible) { 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.Icons;
import com.shatteredpixel.shatteredpixeldungeon.ui.ItemSlot; import com.shatteredpixel.shatteredpixeldungeon.ui.ItemSlot;
import com.shatteredpixel.shatteredpixeldungeon.ui.QuickSlotButton; import com.shatteredpixel.shatteredpixeldungeon.ui.QuickSlotButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline;
import com.watabou.gltextures.TextureCache; import com.watabou.gltextures.TextureCache;
import com.watabou.noosa.BitmapText; import com.watabou.noosa.BitmapText;
import com.watabou.noosa.ColorBlock; import com.watabou.noosa.ColorBlock;
import com.watabou.noosa.Game; import com.watabou.noosa.Game;
import com.watabou.noosa.Image; import com.watabou.noosa.Image;
import com.watabou.noosa.RenderedText;
import com.watabou.noosa.audio.Sample; import com.watabou.noosa.audio.Sample;
public class WndBag extends WndTabbed { public class WndBag extends WndTabbed {
@ -185,11 +185,13 @@ public class WndBag extends WndTabbed {
protected void placeTitle( Bag bag, int width ){ 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 ); title != null ? Messages.titleCase(title) : Messages.titleCase( bag.name() ), 9 );
txtTitle.hardlight( TITLE_COLOR ); txtTitle.hardlight( TITLE_COLOR );
txtTitle.x = 1; txtTitle.setPos(
txtTitle.y = (int)(TITLE_HEIGHT - txtTitle.baseLine()) / 2f - 1; 1,
(TITLE_HEIGHT - txtTitle.height()) / 2f - 1
);
PixelScene.align(txtTitle); PixelScene.align(txtTitle);
add( 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.CheckBox;
import com.shatteredpixel.shatteredpixeldungeon.ui.IconButton; import com.shatteredpixel.shatteredpixeldungeon.ui.IconButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.Icons; import com.shatteredpixel.shatteredpixeldungeon.ui.Icons;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window; import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
import com.watabou.noosa.RenderedText;
import java.util.ArrayList; import java.util.ArrayList;
public class WndChallenges extends Window { public class WndChallenges extends Window {
private static final int WIDTH = 120; 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 BTN_HEIGHT = 18;
private static final int GAP = 1; private static final int GAP = 1;
@ -50,10 +50,12 @@ public class WndChallenges extends Window {
this.editable = editable; 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.hardlight( TITLE_COLOR );
title.x = (WIDTH - title.width()) / 2; title.setPos(
title.y = (TTL_HEIGHT - title.height()) / 2; (WIDTH - title.width()) / 2,
(TTL_HEIGHT - title.height()) / 2
);
PixelScene.align(title); PixelScene.align(title);
add( 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.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline; import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline;
import com.watabou.noosa.Group; import com.watabou.noosa.Group;
import com.watabou.noosa.RenderedText;
public class WndClass extends WndTabbed { public class WndClass extends WndTabbed {
@ -113,16 +112,9 @@ public class WndClass extends WndTabbed {
pos += GAP; pos += GAP;
} }
RenderedText dot = PixelScene.renderText( "-", 6 ); RenderedTextMultiline item = PixelScene.renderMultiline( "-" + items[i], 6 );
dot.y = pos;
if (dotWidth == 0) {
dotWidth = dot.width();
}
add( dot );
RenderedTextMultiline item = PixelScene.renderMultiline( items[i], 6 );
item.maxWidth((int)(WIDTH - MARGIN * 2 - dotWidth)); item.maxWidth((int)(WIDTH - MARGIN * 2 - dotWidth));
item.setPos(dot.x + dot.width(), pos); item.setPos(0, pos);
add( item ); add( item );
pos += item.height(); 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.sprites.HeroSprite;
import com.shatteredpixel.shatteredpixeldungeon.ui.ActionIndicator; import com.shatteredpixel.shatteredpixeldungeon.ui.ActionIndicator;
import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton; import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window; import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
import com.watabou.noosa.Game; import com.watabou.noosa.Game;
import com.watabou.noosa.RenderedText;
import com.watabou.noosa.ui.Button; import com.watabou.noosa.ui.Button;
import com.watabou.utils.Bundle; import com.watabou.utils.Bundle;
import com.watabou.utils.FileUtils; import com.watabou.utils.FileUtils;
@ -48,7 +48,7 @@ public class WndGameInProgress extends Window {
private static final int WIDTH = 120; private static final int WIDTH = 120;
private static final int HEIGHT = 120; private static final int HEIGHT = 120;
private int GAP = 5; private int GAP = 6;
private float pos; private float pos;
@ -165,17 +165,16 @@ public class WndGameInProgress extends Window {
private void statSlot( String label, String value ) { private void statSlot( String label, String value ) {
RenderedText txt = PixelScene.renderText( label, 8 ); RenderedTextMultiline txt = PixelScene.renderMultiline( label, 8 );
txt.y = pos; txt.setPos(0, pos);
add( txt ); add( txt );
txt = PixelScene.renderText( value, 8 ); txt = PixelScene.renderMultiline( value, 8 );
txt.x = WIDTH * 0.6f; txt.setPos(WIDTH * 0.6f, pos);
txt.y = pos;
PixelScene.align(txt); PixelScene.align(txt);
add( txt ); add( txt );
pos += GAP + txt.baseLine(); pos += GAP + txt.height();
} }
private void statSlot( String label, int value ) { 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.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.HeroSprite; import com.shatteredpixel.shatteredpixeldungeon.sprites.HeroSprite;
import com.shatteredpixel.shatteredpixeldungeon.ui.BuffIndicator; import com.shatteredpixel.shatteredpixeldungeon.ui.BuffIndicator;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline;
import com.shatteredpixel.shatteredpixeldungeon.ui.ScrollPane; import com.shatteredpixel.shatteredpixeldungeon.ui.ScrollPane;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window; import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
import com.watabou.gltextures.SmartTexture; import com.watabou.gltextures.SmartTexture;
import com.watabou.gltextures.TextureCache; import com.watabou.gltextures.TextureCache;
import com.watabou.noosa.Group; import com.watabou.noosa.Group;
import com.watabou.noosa.Image; import com.watabou.noosa.Image;
import com.watabou.noosa.RenderedText;
import com.watabou.noosa.TextureFilm; import com.watabou.noosa.TextureFilm;
import com.watabou.noosa.ui.Component; import com.watabou.noosa.ui.Component;
@ -92,7 +92,7 @@ public class WndHero extends WndTabbed {
private class StatsTab extends Group { private class StatsTab extends Group {
private static final int GAP = 5; private static final int GAP = 6;
private float pos; private float pos;
@ -127,17 +127,16 @@ public class WndHero extends WndTabbed {
private void statSlot( String label, String value ) { private void statSlot( String label, String value ) {
RenderedText txt = PixelScene.renderText( label, 8 ); RenderedTextMultiline txt = PixelScene.renderMultiline( label, 8 );
txt.y = pos; txt.setPos(0, pos);
add( txt ); add( txt );
txt = PixelScene.renderText( value, 8 ); txt = PixelScene.renderMultiline( value, 8 );
txt.x = WIDTH * 0.6f; txt.setPos(WIDTH * 0.6f, pos);
txt.y = pos;
PixelScene.align(txt); PixelScene.align(txt);
add( txt ); add( txt );
pos += GAP + txt.baseLine(); pos += GAP + txt.height();
} }
private void statSlot( String label, int value ) { private void statSlot( String label, int value ) {
@ -198,7 +197,7 @@ public class WndHero extends WndTabbed {
private Buff buff; private Buff buff;
Image icon; Image icon;
RenderedText txt; RenderedTextMultiline txt;
public BuffSlot( Buff buff ){ public BuffSlot( Buff buff ){
super(); super();
@ -211,9 +210,12 @@ public class WndHero extends WndTabbed {
icon.y = this.y; icon.y = this.y;
add( icon ); add( icon );
txt = PixelScene.renderText( buff.toString(), 8 ); txt = PixelScene.renderMultiline( buff.toString(), 8 );
txt.x = icon.width + GAP; txt.setPos(
txt.y = this.y + (int)(icon.height - txt.baseLine()) / 2; icon.width + GAP,
this.y + (icon.height - txt.height()) / 2
);
PixelScene.align(txt);
add( txt ); add( txt );
} }
@ -222,8 +224,10 @@ public class WndHero extends WndTabbed {
protected void layout() { protected void layout() {
super.layout(); super.layout();
icon.y = this.y; icon.y = this.y;
txt.x = icon.width + GAP; txt.setPos(
txt.y = pos + (int)(icon.height - txt.baseLine()) / 2; icon.width + GAP,
this.y + (icon.height - txt.height()) / 2
);
} }
protected boolean onClick ( float x, float y ) { 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.SPDSettings;
import com.shatteredpixel.shatteredpixeldungeon.items.Heap; import com.shatteredpixel.shatteredpixeldungeon.items.Heap;
import com.shatteredpixel.shatteredpixeldungeon.items.Item; import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene; import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite;
import com.shatteredpixel.shatteredpixeldungeon.ui.ItemSlot; import com.shatteredpixel.shatteredpixeldungeon.ui.ItemSlot;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline; import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window; 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.sprites.CharSprite;
import com.shatteredpixel.shatteredpixeldungeon.ui.BuffIndicator; import com.shatteredpixel.shatteredpixeldungeon.ui.BuffIndicator;
import com.shatteredpixel.shatteredpixeldungeon.ui.HealthBar; import com.shatteredpixel.shatteredpixeldungeon.ui.HealthBar;
import com.watabou.noosa.RenderedText; import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline;
import com.watabou.noosa.ui.Component; import com.watabou.noosa.ui.Component;
public class WndInfoMob extends WndTitledMessage { public class WndInfoMob extends WndTitledMessage {
@ -43,13 +43,13 @@ public class WndInfoMob extends WndTitledMessage {
private static final int GAP = 2; private static final int GAP = 2;
private CharSprite image; private CharSprite image;
private RenderedText name; private RenderedTextMultiline name;
private HealthBar health; private HealthBar health;
private BuffIndicator buffs; private BuffIndicator buffs;
public MobTitle( Mob mob ) { public MobTitle( Mob mob ) {
name = PixelScene.renderText( Messages.titleCase( mob.name ), 9 ); name = PixelScene.renderMultiline( Messages.titleCase( mob.name ), 9 );
name.hardlight( TITLE_COLOR ); name.hardlight( TITLE_COLOR );
add( name ); add( name );
@ -70,16 +70,17 @@ public class WndInfoMob extends WndTitledMessage {
image.x = 0; image.x = 0;
image.y = Math.max( 0, name.height() + health.height() - image.height ); image.y = Math.max( 0, name.height() + health.height() - image.height );
name.x = image.width + GAP; name.setPos(x + image.width + GAP,
name.y = Math.max( 0, image.height - health.height() - name.height()); image.height > name.height() ? y +(name.height() - image.height()) / 2 : y);
float w = width - image.width - GAP; 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( buffs.setPos(
name.x + name.width() + GAP-1, name.right() + GAP-1,
name.y + name.baseLine() - BuffIndicator.SIZE-2 ); name.bottom() - BuffIndicator.SIZE-2
);
height = health.bottom(); height = health.bottom();
} }

View File

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

View File

@ -22,9 +22,8 @@
package com.shatteredpixel.shatteredpixeldungeon.windows; package com.shatteredpixel.shatteredpixeldungeon.windows;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene; import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window; import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
import com.watabou.noosa.BitmapTextMultiline;
import com.watabou.noosa.RenderedText;
public class WndList extends Window { public class WndList extends Window {
@ -46,19 +45,9 @@ public class WndList extends Window {
pos += GAP; pos += GAP;
} }
RenderedText dot = PixelScene.renderText( "-", 6 ); RenderedTextMultiline item = PixelScene.renderMultiline( "-" + items[i], 6 );
dot.x = MARGIN; item.setPos( MARGIN, pos );
dot.y = pos; item.maxWidth(WIDTH - MARGIN*2);
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();
add( item ); add( item );
pos += item.height(); 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.Icons;
import com.shatteredpixel.shatteredpixeldungeon.ui.ItemSlot; import com.shatteredpixel.shatteredpixeldungeon.ui.ItemSlot;
import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton; import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline;
import com.shatteredpixel.shatteredpixeldungeon.ui.ScrollPane; import com.shatteredpixel.shatteredpixeldungeon.ui.ScrollPane;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window; import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
import com.watabou.noosa.ColorBlock; import com.watabou.noosa.ColorBlock;
import com.watabou.noosa.Game; import com.watabou.noosa.Game;
import com.watabou.noosa.Group; import com.watabou.noosa.Group;
import com.watabou.noosa.Image; import com.watabou.noosa.Image;
import com.watabou.noosa.RenderedText;
import com.watabou.noosa.audio.Sample; import com.watabou.noosa.audio.Sample;
import com.watabou.noosa.ui.Button; import com.watabou.noosa.ui.Button;
@ -155,7 +155,7 @@ public class WndRanking extends WndTabbed {
private class StatsTab extends Group { private class StatsTab extends Group {
private int GAP = 4; private int GAP = 5;
public StatsTab() { public StatsTab() {
super(); super();
@ -171,7 +171,7 @@ public class WndRanking extends WndTabbed {
title.setRect( 0, 0, WIDTH, 0 ); title.setRect( 0, 0, WIDTH, 0 );
add( title ); add( title );
float pos = title.bottom(); float pos = title.bottom() + GAP;
if (Dungeon.challenges > 0) { if (Dungeon.challenges > 0) {
RedButton btnChallenges = new RedButton( Messages.get(this, "challenges") ) { RedButton btnChallenges = new RedButton( Messages.get(this, "challenges") ) {
@ -187,7 +187,7 @@ public class WndRanking extends WndTabbed {
pos = btnChallenges.bottom(); 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, "str"), Integer.toString( Dungeon.hero.STR() ), pos );
pos = statSlot( this, Messages.get(this, "health"), Integer.toString( Dungeon.hero.HT ), 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 ) { private float statSlot( Group parent, String label, String value, float pos ) {
RenderedText txt = PixelScene.renderText( label, 7 ); RenderedTextMultiline txt = PixelScene.renderMultiline( label, 7 );
txt.y = pos; txt.setPos(0, pos);
parent.add( txt ); parent.add( txt );
txt = PixelScene.renderText( value, 7 ); txt = PixelScene.renderMultiline( value, 7 );
txt.x = WIDTH * 0.65f; txt.setPos(WIDTH * 0.7f, pos);
txt.y = pos;
PixelScene.align(txt); PixelScene.align(txt);
parent.add( 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 ItemSlot slot;
private ColorBlock bg; private ColorBlock bg;
private RenderedText name; private RenderedTextMultiline name;
public ItemButton( Item item ) { public ItemButton( Item item ) {
@ -323,7 +322,7 @@ public class WndRanking extends WndTabbed {
slot = new ItemSlot(); slot = new ItemSlot();
add( slot ); add( slot );
name = PixelScene.renderText( "?", 7 ); name = PixelScene.renderMultiline( 7 );
add( name ); add( name );
super.createChildren(); super.createChildren();
@ -337,19 +336,14 @@ public class WndRanking extends WndTabbed {
slot.setRect( x, y, HEIGHT, HEIGHT ); slot.setRect( x, y, HEIGHT, HEIGHT );
PixelScene.align(slot); PixelScene.align(slot);
name.x = slot.right() + 2; name.maxWidth((int)(width - slot.width() - 2));
name.y = y + (height - name.baseLine()) / 2; name.text(Messages.titleCase(item.name()));
name.setPos(
slot.right()+2,
y + (height - name.height()) / 2
);
PixelScene.align(name); 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(); 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.CheckBox;
import com.shatteredpixel.shatteredpixeldungeon.ui.OptionSlider; import com.shatteredpixel.shatteredpixeldungeon.ui.OptionSlider;
import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton; import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline;
import com.shatteredpixel.shatteredpixeldungeon.ui.Toolbar; import com.shatteredpixel.shatteredpixeldungeon.ui.Toolbar;
import com.watabou.noosa.Game; import com.watabou.noosa.Game;
import com.watabou.noosa.Group; import com.watabou.noosa.Group;
import com.watabou.noosa.RenderedText;
import com.watabou.noosa.audio.Sample; import com.watabou.noosa.audio.Sample;
import com.watabou.utils.DeviceCompat; import com.watabou.utils.DeviceCompat;
@ -197,8 +197,8 @@ public class WndSettings extends WndTabbed {
public UITab(){ public UITab(){
super(); super();
RenderedText barDesc = PixelScene.renderText(Messages.get(this, "mode"), 9); RenderedTextMultiline barDesc = PixelScene.renderMultiline(Messages.get(this, "mode"), 9);
barDesc.x = (WIDTH-barDesc.width())/2; barDesc.setPos((WIDTH-barDesc.width())/2f, GAP_TINY);
PixelScene.align(barDesc); PixelScene.align(barDesc);
add(barDesc); add(barDesc);
@ -209,7 +209,7 @@ public class WndSettings extends WndTabbed {
Toolbar.updateLayout(); Toolbar.updateLayout();
} }
}; };
btnSplit.setRect( 0, barDesc.y + barDesc.baseLine()+GAP_TINY, 36, 16); btnSplit.setRect( 0, barDesc.bottom() + GAP_TINY, 36, 16);
add(btnSplit); add(btnSplit);
RedButton btnGrouped = new RedButton(Messages.get(this, "group")){ RedButton btnGrouped = new RedButton(Messages.get(this, "group")){
@ -219,7 +219,7 @@ public class WndSettings extends WndTabbed {
Toolbar.updateLayout(); 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); add(btnGrouped);
RedButton btnCentered = new RedButton(Messages.get(this, "center")){ RedButton btnCentered = new RedButton(Messages.get(this, "center")){
@ -229,7 +229,7 @@ public class WndSettings extends WndTabbed {
Toolbar.updateLayout(); 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); add(btnCentered);
CheckBox chkFlipToolbar = new CheckBox(Messages.get(this, "flip_toolbar")){ 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.IconButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.Icons; import com.shatteredpixel.shatteredpixeldungeon.ui.Icons;
import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton; import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window; import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
import com.watabou.noosa.ColorBlock; import com.watabou.noosa.ColorBlock;
import com.watabou.noosa.Game; import com.watabou.noosa.Game;
import com.watabou.noosa.Image; import com.watabou.noosa.Image;
import com.watabou.noosa.RenderedText;
import com.watabou.noosa.ui.Button; import com.watabou.noosa.ui.Button;
import com.watabou.noosa.ui.Component; import com.watabou.noosa.ui.Component;
import com.watabou.utils.DeviceCompat; import com.watabou.utils.DeviceCompat;
@ -59,10 +59,10 @@ public class WndStartGame extends Window {
Badges.loadGlobal(); Badges.loadGlobal();
Journal.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.hardlight(Window.TITLE_COLOR);
title.x = (WIDTH - title.width())/2f; title.setPos( (WIDTH - title.width())/2f, 2);
title.y = 2; PixelScene.align(title);
add(title); add(title);
float heroBtnSpacing = (WIDTH - 4*HeroBtn.WIDTH)/5f; float heroBtnSpacing = (WIDTH - 4*HeroBtn.WIDTH)/5f;
@ -78,7 +78,7 @@ public class WndStartGame extends Window {
ColorBlock separator = new ColorBlock(1, 1, 0xFF222222); ColorBlock separator = new ColorBlock(1, 1, 0xFF222222);
separator.size(WIDTH, 1); separator.size(WIDTH, 1);
separator.x = 0; separator.x = 0;
separator.y = title.baseLine() + 6 + HeroBtn.HEIGHT; separator.y = title.bottom() + 6 + HeroBtn.HEIGHT;
add(separator); add(separator);
HeroPane ava = new HeroPane(); HeroPane ava = new HeroPane();
@ -227,7 +227,7 @@ public class WndStartGame extends Window {
private IconButton heroMisc; private IconButton heroMisc;
private IconButton heroSubclass; private IconButton heroSubclass;
private RenderedText name; private RenderedTextMultiline name;
private static final int BTN_SIZE = 20; private static final int BTN_SIZE = 20;
@ -283,7 +283,7 @@ public class WndStartGame extends Window {
heroSubclass.setSize(BTN_SIZE, BTN_SIZE); heroSubclass.setSize(BTN_SIZE, BTN_SIZE);
add(heroSubclass); add(heroSubclass);
name = PixelScene.renderText(12); name = PixelScene.renderMultiline(12);
add(name); add(name);
visible = false; visible = false;
@ -297,8 +297,10 @@ public class WndStartGame extends Window {
avatar.y = y + (height - avatar.height() - name.baseLine() - 2)/2f; avatar.y = y + (height - avatar.height() - name.baseLine() - 2)/2f;
PixelScene.align(avatar); PixelScene.align(avatar);
name.x = x + (avatar.width() - name.width())/2f; name.setPos(
name.y = avatar.y + avatar.height() + 2; x + (avatar.width() - name.width())/2f,
avatar.y + avatar.height() + 2
);
PixelScene.align(name); PixelScene.align(name);
heroItem.setPos(x + width - BTN_SIZE, y); 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.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Chrome; import com.shatteredpixel.shatteredpixeldungeon.Chrome;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene; import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window; import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
import com.watabou.noosa.Game; import com.watabou.noosa.Game;
import com.watabou.noosa.Image; import com.watabou.noosa.Image;
import com.watabou.noosa.NinePatch; import com.watabou.noosa.NinePatch;
import com.watabou.noosa.RenderedText;
import com.watabou.noosa.audio.Sample; import com.watabou.noosa.audio.Sample;
import com.watabou.noosa.ui.Button; import com.watabou.noosa.ui.Button;
import com.watabou.utils.RectF; import com.watabou.utils.RectF;
@ -196,7 +196,7 @@ public class WndTabbed extends Window {
protected class LabeledTab extends Tab { protected class LabeledTab extends Tab {
private RenderedText btLabel; private RenderedTextMultiline btLabel;
public LabeledTab( String label ) { public LabeledTab( String label ) {
@ -209,7 +209,7 @@ public class WndTabbed extends Window {
protected void createChildren() { protected void createChildren() {
super.createChildren(); super.createChildren();
btLabel = PixelScene.renderText( 9 ); btLabel = PixelScene.renderMultiline( 9 );
add( btLabel ); add( btLabel );
} }
@ -217,18 +217,17 @@ public class WndTabbed extends Window {
protected void layout() { protected void layout() {
super.layout(); super.layout();
btLabel.x = x + (width - btLabel.width()) / 2; btLabel.setPos(
btLabel.y = y + (height - btLabel.baseLine()) / 2 - 1; x + (width - btLabel.width()) / 2,
if (!selected) { y + (height - btLabel.height()) / 2 - (selected ? 1 : 3)
btLabel.y -= 2; );
}
PixelScene.align(btLabel); PixelScene.align(btLabel);
} }
@Override @Override
protected void select( boolean value ) { protected void select( boolean value ) {
super.select( value ); super.select( value );
btLabel.am = selected ? 1.0f : 0.6f; btLabel.alpha( selected ? 1.0f : 0.6f );
} }
} }