Skip to content
Snippets Groups Projects
Commit 83da9d76 authored by Anton Danilov's avatar Anton Danilov
Browse files

#123 Change language is performed through LoaderScreen, fixed loading of fonts in StatisticsScreen

parent 8ab11421
No related branches found
No related tags found
No related merge requests found
......@@ -39,6 +39,7 @@ import cz.nic.tablexia.loader.application.ApplicationTextManager;
import cz.nic.tablexia.menu.MenuController;
import cz.nic.tablexia.screen.AbstractTablexiaScreen;
import cz.nic.tablexia.screen.AbstractTablexiaScreen.ScreenLoadingListener;
import cz.nic.tablexia.screen.loader.LoaderScreen;
import cz.nic.tablexia.util.Log;
import cz.nic.tablexia.util.ui.TablexiaButton;
import cz.nic.tablexia.util.ui.dialog.TablexiaDialog;
......@@ -475,6 +476,7 @@ public abstract class TablexiaApplication implements ApplicationListener {
/**
* Change current screen to new screen with screen transaction.
* If new screen is same as current screen no change is performed.
* Unless it's LoaderScreen. That means, that language was changed.
* If {@link ScreenTransaction} is <code>null</code> screen is changed without transaction.
*
* @param newScreen new screen to change for
......@@ -482,7 +484,7 @@ public abstract class TablexiaApplication implements ApplicationListener {
*/
public void setScreenIfIsDifferent(AbstractTablexiaScreen<?> newScreen, ScreenTransaction screenTransaction) {
if (newScreen != null) {
if (getScreen() == null || getScreen().getClass() != newScreen.getClass()) {
if (getScreen() == null || getScreen().getClass() != newScreen.getClass() || LoaderScreen.class.equals(newScreen.getClass())) {
setScreen(newScreen, screenTransaction);
}
}
......
......@@ -358,6 +358,7 @@ public class TablexiaSettings {
preferences.flush();
if (!lastLocale.getLocale().getLanguage().equals(localeDefinition.getLocale().getLanguage())) {
ApplicationBus.getInstance().post(new LocaleChangedEvent(localeDefinition)).asynchronously();
ApplicationBus.getInstance().post(new Tablexia.ChangeScreenEvent(LOADER_SCREEN, null)).asynchronously();
}
}
......
......@@ -67,8 +67,6 @@ public class StatisticsScreen extends AbstractTablexiaScreen<Void> {
private static final String[] BOOKMARKS_TEXTURES = {"1", "2", "3", "2", "1", "3"};
private static final String SELECTED_SWITCH_KEY = "selected_switch", SELECTED_GAME_KEY = "selected_game", DIFFICULTY_EASY_KEY = "diff_easy", DIFFICULTY_MEDIUM_KEY = "diff_medium", DIFFICULTY_HARD_KEY = "diff_hard";
private static final GameDefinition DEFAULT_GAME = GameDefinition.ROBBERY;
private static final BitmapFont DEFAULT_FONT = ApplicationFontManager.getInstance().getFont(ApplicationFontManager.FontType.ROBOTO_REGULAR_20);
private static final BitmapFont DEFAULT_BOLD_FONT = ApplicationFontManager.getInstance().getFont(ApplicationFontManager.FontType.ROBOTO_BOLD_20);
private Group content;
private Image background;
......@@ -91,6 +89,7 @@ public class StatisticsScreen extends AbstractTablexiaScreen<Void> {
private Table graphPaneHolder;
private GraphPane graphPane;
private Map<GameDifficulty, Button> difficultyButtons;
private BitmapFont defaultFont, defaultBoldFont;
public StatisticsScreen() {
}
......@@ -107,11 +106,13 @@ public class StatisticsScreen extends AbstractTablexiaScreen<Void> {
@Override
protected void screenLoaded(Map<String, String> screenState) {
loadFonts();
getStage().setDebugAll(TablexiaSettings.getInstance().isShowBoundingBoxes());
content = new Group();
content.addActor(background = new TablexiaNoBlendingImage(getApplicationTextureRegion(ApplicationAtlasManager.BACKGROUND_WOODEN)));
content.addActor(titleLabel = new Label(getText("statistics_label"), new Label.LabelStyle(DEFAULT_FONT, Color.BLACK)));
content.addActor(titleLabel = new Label(getText("statistics_label"), new Label.LabelStyle(defaultFont, Color.BLACK)));
content.addActor(buttonClose = new Button(new TextureRegionDrawable(getApplicationTextureRegion(BUTTON_PATH + "closebutton_unpressed")), new TextureRegionDrawable(getApplicationTextureRegion(BUTTON_PATH + "closebutton_pressed"))));
content.addListener(onScreenTouchListener);
buttonClose.addListener(closeClickListener);
......@@ -129,8 +130,8 @@ public class StatisticsScreen extends AbstractTablexiaScreen<Void> {
switchGraph.setSwitchSelectedListener(switchListener);
switchGraph.setDisabledStep(1);
switchGraphType = new WidgetGroup();
Label left = setSmallFont(new Label(getText("statistics_games"), new Label.LabelStyle(DEFAULT_FONT, Color.BLACK)));
Label right = setSmallFont(new Label(getText("statistics_average"), new Label.LabelStyle(DEFAULT_FONT, Color.BLACK)));
Label left = setSmallFont(new Label(getText("statistics_games"), new Label.LabelStyle(defaultFont, Color.BLACK)));
Label right = setSmallFont(new Label(getText("statistics_average"), new Label.LabelStyle(defaultFont, Color.BLACK)));
left.addListener(leftButtonListener);
right.addListener(rightButtonListener);
switchGraphType.addActor(left);
......@@ -148,7 +149,7 @@ public class StatisticsScreen extends AbstractTablexiaScreen<Void> {
for (GameDifficulty gameDifficulty : GameDifficulty.getVisibleGameDifficultyList()) {
String diffString = gameDifficulty.name().toLowerCase();
Button diffButton = new Button(new TextureRegionDrawable(getScreenTextureRegion(GFX_PATH + "difficultyradio_" + diffString + "_unpressed", false)), new TextureRegionDrawable(getScreenTextureRegion(GFX_PATH + "difficultyradio_" + diffString + "_pressed", false)), new TextureRegionDrawable(getScreenTextureRegion(GFX_PATH + "difficultyradio_" + diffString + "_pressed", false)));
Label diffLabel = setSmallFont(new Label(ApplicationTextManager.getInstance().getText("gamedifficulty_" + diffString), new Label.LabelStyle(DEFAULT_FONT, Color.BLACK)));
Label diffLabel = setSmallFont(new Label(ApplicationTextManager.getInstance().getText("gamedifficulty_" + diffString), new Label.LabelStyle(defaultFont, Color.BLACK)));
difficulties.addActor(diffButton);
difficulties.addActor(diffLabel);
diffButton.setUserObject(gameDifficulty);
......@@ -171,7 +172,7 @@ public class StatisticsScreen extends AbstractTablexiaScreen<Void> {
boolean gameFromDBLoaded = false;
for (int i = 0; i < GameMenuDefinition.values().length; i++) {
GameMenuDefinition gameMenuDefinition = GameMenuDefinition.values()[i];
Button button = new BookmarkButton(gameMenuDefinition.getTitle(), getScreenTextureRegion(GFX_PATH + "gamelist_listitem_background" + BOOKMARKS_TEXTURES[i] + "_inactive", false), getScreenTextureRegion(GFX_PATH + "gamelist_listitem_background" + BOOKMARKS_TEXTURES[i] + "_active", false), DEFAULT_FONT);
Button button = new BookmarkButton(gameMenuDefinition.getTitle(), getScreenTextureRegion(GFX_PATH + "gamelist_listitem_background" + BOOKMARKS_TEXTURES[i] + "_inactive", false), getScreenTextureRegion(GFX_PATH + "gamelist_listitem_background" + BOOKMARKS_TEXTURES[i] + "_active", false), defaultFont);
button.setUserObject(gameMenuDefinition);
button.addListener(bookmarkClickListener);
bookmarks.addActor(button);
......@@ -194,6 +195,11 @@ public class StatisticsScreen extends AbstractTablexiaScreen<Void> {
}
private void loadFonts() {
defaultFont = ApplicationFontManager.getInstance().getFont(ApplicationFontManager.FontType.ROBOTO_REGULAR_20);
defaultBoldFont = ApplicationFontManager.getInstance().getFont(ApplicationFontManager.FontType.ROBOTO_BOLD_20);
}
private void selectFirstGameAndDifficultyAvailable() {
List<Game> games = null;
......@@ -369,7 +375,7 @@ public class StatisticsScreen extends AbstractTablexiaScreen<Void> {
};
private Label getLabel(DialogTextContent dialogTextContent) {
Label.LabelStyle labelStyle = new Label.LabelStyle(DEFAULT_BOLD_FONT, Color.BLACK);
Label.LabelStyle labelStyle = new Label.LabelStyle(defaultBoldFont, Color.BLACK);
Label label = new Label(dialogTextContent.getContent(), labelStyle);
label.setWrap(true);
label.setAlignment(Align.center);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment