Skip to content

Commit

Permalink
#43: AmuletScene is now localized, and a base tr() method has been ad…
Browse files Browse the repository at this point in the history
…ded to scenes
  • Loading branch information
Arcnor committed Oct 12, 2014
1 parent e385814 commit 3748f89
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 23 deletions.
8 changes: 8 additions & 0 deletions android/assets/i18n/l10n.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ about_txt = Original code & graphics: {0}\n\
Try it on Windows, Mac OS or Linux - it's awesome! ;)\n\n\
Please visit the official website for additional info:

# AmuletScene
amulet_txt = You finally hold it in your hands, the Amulet of Yendor. Using its power \
you can take over the world or bring peace and prosperity to people or whatever. \
Anyway, your life will change forever and this game will end here. \
Or you can stay a mere mortal a little longer.
amulet_exit = Let's call it a day
amulet_stay = I'm not done yet

# TitleScreen
title_play = Play
title_rankings = Rankings
Expand Down
4 changes: 1 addition & 3 deletions core/src/com/watabou/pixeldungeon/scenes/AboutScene.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package com.watabou.pixeldungeon.scenes;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.utils.I18NBundle;
import com.watabou.input.NoosaInputProcessor;
import com.watabou.noosa.BitmapTextMultiline;
import com.watabou.noosa.Camera;
Expand All @@ -40,8 +39,7 @@ public class AboutScene extends PixelScene {
public void create() {
super.create();

final I18NBundle i18nBundle = Game.instance.getI18nBundle();
BitmapTextMultiline text = createMultiline(i18nBundle.format(TXT, "Watabou", "Arcnor", "Cubic_Code", "Brian Walker", "Brogue"), 8);
BitmapTextMultiline text = createMultiline(tr(TXT, "Watabou", "Arcnor", "Cubic_Code", "Brian Walker", "Brogue"), 8);
text.maxWidth = Math.min( Camera.main.width, 120 );
text.measure();
add( text );
Expand Down
18 changes: 7 additions & 11 deletions core/src/com/watabou/pixeldungeon/scenes/AmuletScene.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,16 @@

public class AmuletScene extends PixelScene {

private static final String TXT_EXIT = "Let's call it a day";
private static final String TXT_STAY = "I'm not done yet";
private static final String TXT_EXIT = "amulet_exit";
private static final String TXT_STAY = "amulet_stay";

private static final int WIDTH = 120;
private static final int BTN_HEIGHT = 18;
private static final float SMALL_GAP = 2;
private static final float LARGE_GAP = 8;

private static final String TXT =
"You finally hold it in your hands, the Amulet of Yendor. Using its power " +
"you can take over the world or bring peace and prosperity to people or whatever. " +
"Anyway, your life will change forever and this game will end here. " +
"Or you can stay a mere mortal a little longer.";

private static final String TXT = "amulet_txt";

public static boolean noText = false;

private Image amulet;
Expand All @@ -54,7 +50,7 @@ public void create() {

BitmapTextMultiline text = null;
if (!noText) {
text = createMultiline( TXT, 8 );
text = createMultiline(tr(TXT), 8);
text.maxWidth = WIDTH;
text.measure();
add( text );
Expand All @@ -63,7 +59,7 @@ public void create() {
amulet = new Image( Assets.AMULET );
add( amulet );

RedButton btnExit = new RedButton( TXT_EXIT ) {
RedButton btnExit = new RedButton(tr(TXT_EXIT)) {
@Override
protected void onClick() {
Dungeon.deleteGame( Dungeon.hero.heroClass, true );
Expand All @@ -73,7 +69,7 @@ protected void onClick() {
btnExit.setSize( WIDTH, BTN_HEIGHT );
add( btnExit );

RedButton btnStay = new RedButton( TXT_STAY ) {
RedButton btnStay = new RedButton(tr(TXT_STAY)) {
@Override
protected void onClick() {
onBackPressed();
Expand Down
19 changes: 16 additions & 3 deletions core/src/com/watabou/pixeldungeon/scenes/PixelScene.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.watabou.input.NoosaInputProcessor;
import com.watabou.noosa.*;
import com.watabou.noosa.BitmapText;
import com.watabou.noosa.BitmapText.Font;
import com.watabou.noosa.BitmapTextMultiline;
import com.watabou.noosa.Camera;
import com.watabou.noosa.ColorBlock;
import com.watabou.noosa.Game;
import com.watabou.noosa.Scene;
import com.watabou.noosa.Visual;
import com.watabou.noosa.audio.Sample;
import com.watabou.pixeldungeon.Assets;
import com.watabou.pixeldungeon.Badges;
Expand Down Expand Up @@ -220,7 +225,15 @@ public static BitmapTextMultiline createMultiline( String text, float size ) {

return result;
}


protected String tr(final String key) {
return Game.instance.getI18nBundle().get(key);
}

protected String tr(final String key, final Object... args) {
return Game.instance.getI18nBundle().format(key, args);
}

public static float align( Camera camera, float pos ) {
return ((int)(pos * camera.zoom)) / camera.zoom;
}
Expand Down
10 changes: 4 additions & 6 deletions core/src/com/watabou/pixeldungeon/scenes/TitleScene.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/
package com.watabou.pixeldungeon.scenes;

import com.badlogic.gdx.utils.I18NBundle;
import com.watabou.noosa.BitmapText;
import com.watabou.noosa.Camera;
import com.watabou.noosa.Game;
Expand Down Expand Up @@ -67,8 +66,7 @@ public void create() {
placeTorch( title.x + 18, title.y + 20 );
placeTorch( title.x + title.width - 18, title.y + 20 );

final I18NBundle i18nBundle = Game.instance.getI18nBundle();
DashboardItem btnBadges = new DashboardItem(i18nBundle.get(TXT_BADGES), 3) {
DashboardItem btnBadges = new DashboardItem(tr(TXT_BADGES), 3) {
@Override
protected void onClick() {
Game.switchScene( BadgesScene.class );
Expand All @@ -77,7 +75,7 @@ protected void onClick() {
btnBadges.setPos( w / 2 - btnBadges.width(), (h + height) / 2 - DashboardItem.SIZE );
add( btnBadges );

DashboardItem btnAbout = new DashboardItem(i18nBundle.get(TXT_ABOUT), 1) {
DashboardItem btnAbout = new DashboardItem(tr(TXT_ABOUT), 1) {
@Override
protected void onClick() {
Game.switchScene( AboutScene.class );
Expand All @@ -86,7 +84,7 @@ protected void onClick() {
btnAbout.setPos( w / 2, (h + height) / 2 - DashboardItem.SIZE );
add( btnAbout );

DashboardItem btnPlay = new DashboardItem(i18nBundle.get(TXT_PLAY), 0) {
DashboardItem btnPlay = new DashboardItem(tr(TXT_PLAY), 0) {
@Override
protected void onClick() {
Game.switchScene( StartScene.class );
Expand All @@ -95,7 +93,7 @@ protected void onClick() {
btnPlay.setPos( w / 2 - btnPlay.width(), btnAbout.top() - DashboardItem.SIZE );
add( btnPlay );

DashboardItem btnHighscores = new DashboardItem(i18nBundle.get(TXT_HIGHSCORES), 2) {
DashboardItem btnHighscores = new DashboardItem(tr(TXT_HIGHSCORES), 2) {
@Override
protected void onClick() {
Game.switchScene( RankingsScene.class );
Expand Down

0 comments on commit 3748f89

Please sign in to comment.