Commit 067ff83a authored by Matyáš Latner's avatar Matyáš Latner

#30 Standard text loader from screen and game base assets path

parent c5566c29
package cz.nic.tablexia.game.games.night_watch;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.Action;
import com.badlogic.gdx.scenes.scene2d.Group;
......@@ -53,7 +51,6 @@ public class NightWatchGame extends AbstractTablexiaGame<GameRule> {
private Group windowsGroup;
private Group contentGroup;
private Stack backgroundStack;
public static TextureAtlas buttonAtlas;
private Map<Integer,List<Solution>> gameSolutions;
private Watch watch;
private TablexiaButton button;
......@@ -64,7 +61,6 @@ public class NightWatchGame extends AbstractTablexiaGame<GameRule> {
contentGroup.setSize(SCREEN_WIDTH, SCREEN_MIN_HEIGHT);
getStage().addActor(contentGroup);
buttonAtlas = new TextureAtlas(Gdx.files.internal("atlases/buttons_atlas.pack"));
// difficulty = getGameDifficulty().ordinal();
gameSolutions = GameSolutionGenerator.generateSolutions(difficulty,getRandomAccess().getRandom());
......@@ -315,9 +311,4 @@ public class NightWatchGame extends AbstractTablexiaGame<GameRule> {
int clickY = clickmap.getRegionHeight() - (int) (y / SCREEN_MIN_HEIGHT * clickmap.getRegionHeight());
return new Color(pixmap.getPixel(clickmap.getRegionX() + clickX, clickmap.getRegionY() + clickY));
}
@Override
protected String prepareScreenTextResourcesAssetName() {
return NightWatchAssets.TEXT_PATH;
}
}
......@@ -4,7 +4,6 @@ package cz.nic.tablexia.game.games.night_watch.assets;
* Created by Vendik on 30.4.2015.
*/
public final class NightWatchAssets {
public static final String TEXT_PATH = "text/game/night_watch/night_watch";
public static final String BACKGROUND_FOLDER = "background/";
public static final String WINDOWS_FOLDER = "windows/";
......
......@@ -264,6 +264,13 @@ public class GameScreen extends AbstractTablexiaScreen<Void> {
@Override
protected String prepareScreenAtlasPath(String screenAssetsPath, String screenName) {
// no atlas loading
return null;
}
@Override
protected String prepareScreenTextResourcesAssetName() {
// no text loading
return null;
}
......
......@@ -38,11 +38,6 @@ public class RobberyGame extends AbstractTablexiaGame<GameRule> {
soundsFileNames.add(RobberyAssets.SOUND_ERROR);
soundsFileNames.add(RobberyAssets.SOUND_CHAINS);
}
@Override
protected String prepareScreenTextResourcesAssetName() {
return RobberyAssets.TEXT_PATH;
}
@Override
protected GameRule prepareGameData() {
......
......@@ -45,6 +45,13 @@ public class RuleScreen extends AbstractTablexiaScreen<Void> {
@Override
protected String prepareScreenAtlasPath(String screenAssetsPath, String screenName) {
// no atlas loading
return null;
}
@Override
protected String prepareScreenTextResourcesAssetName() {
// no text loading
return null;
}
......
......@@ -4,8 +4,6 @@ package cz.nic.tablexia.game.games.robbery.assets;
public final class RobberyAssets {
private RobberyAssets() {}
public static final String TEXT_PATH = "text/game/robbery/robbery";
public static final String SOUND_ALARM = "alarm.mp3";
public static final String SOUND_ERROR = "error.mp3";
......
......@@ -150,7 +150,7 @@ public abstract class TablexiaAbstractFileManager extends AssetManager {
return;
}
}
Log.err(getClass(), "Asset file for name: " + assetFileName + " was not found!");
Log.info(getClass(), "Asset file for name: " + assetFileName + " was not found!");
}
public <T> T getAsset(String assetName, Class<T> clazz) {
......
......@@ -20,6 +20,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.MissingResourceException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
......@@ -128,6 +129,8 @@ public abstract class AbstractTablexiaScreen<T> extends ScreenAdapter {
}
}
public static final String TEXT_LOADER_BASE_PATH = "text/";
private String screenName;
private String screenAssetsPath;
private String screenAtlasPath;
......@@ -163,12 +166,17 @@ public abstract class AbstractTablexiaScreen<T> extends ScreenAdapter {
@Override
public I18NBundle call() throws Exception {
FileHandle baseFileHandle = Gdx.files.internal(textResourceFileName);
return I18NBundle.createBundle(baseFileHandle, locale);
try {
return I18NBundle.createBundle(baseFileHandle, locale);
} catch (MissingResourceException e) {
Log.info(getClass(), "No text bundle found: " + baseFileHandle.path());
return null;
}
}
}
public void load(Locale locale, String textFileName) {
if (textFileName != null) {
if (textFileName != null) {
setAsyncTask(new TextLoader(textFileName, locale));
}
}
......@@ -236,9 +244,9 @@ public abstract class AbstractTablexiaScreen<T> extends ScreenAdapter {
notDisposedMusics = new HashMap<String, Music>();
screenName = prepareScreenName();
screenAssetsPath = prepareScreenAssetsPath(screenName);
screenAtlasPath = prepareScreenAtlasPath(screenAssetsPath, screenName);
screenName = prepareScreenName();
screenAssetsPath = prepareScreenAssetsPath(screenName);
screenAtlasPath = prepareScreenAtlasPath(screenAssetsPath, screenName);
}
public boolean hasState() {
......@@ -407,22 +415,38 @@ public abstract class AbstractTablexiaScreen<T> extends ScreenAdapter {
protected void screenDisposed() {};
protected void screenResized(int width, int height) {};
protected void prepareScreenSoundAssetNames(List<String> soundsFileNames) {}
//////////////////////////// TABLEXIA SCREEN CALLBACKS
// SFX
protected void prepareScreenSoundAssetNames(List<String> soundsFileNames) {
// no standard sound file names
}
// GFX
protected void prepareScreenAtlases(List<String> atlasesNames) {
// loads screen standard atlas
if (screenAtlasPath != null) {
atlasesNames.add(screenAtlasPath);
}
}
protected String prepareScreenAtlasPath(String screenAssetsPath, String screenName) {
// prepare standard screen atlas name
return screenAssetsPath + screenName + ".atlas";
}
// TEXT
protected String prepareScreenTextResourcesAssetName() {
return null;
// prepare standard screen text resource file name
return screenName;
}
// DATA
protected T prepareScreenData() {
return null;
}
protected String prepareScreenName() {
String className = getClass().getName().toLowerCase();
Pattern p = Pattern.compile("(\\w+)screen");
......@@ -435,13 +459,11 @@ public abstract class AbstractTablexiaScreen<T> extends ScreenAdapter {
}
protected String prepareScreenAssetsPath(String screenName) {
// standard screen assets path
return "screen/" + screenName + "/";
}
protected String prepareScreenAtlasPath(String screenAssetsPath, String screenName) {
return screenAssetsPath + screenName + ".atlas";
}
protected void printScreenInfo(String infoKey, String infoValue) {
ApplicationBus.getInstance().post(new ScreenInfoEvent(infoKey, infoValue)).asynchronously();
}
......@@ -476,7 +498,10 @@ public abstract class AbstractTablexiaScreen<T> extends ScreenAdapter {
}
private void startTextLoader() {
textManager.load(TablexiaSettings.getInstance().getLocale(), prepareScreenTextResourcesAssetName());
String textResourcesAssetName = prepareScreenTextResourcesAssetName();
if (textResourcesAssetName != null) {
textManager.load(TablexiaSettings.getInstance().getLocale(), TEXT_LOADER_BASE_PATH + screenAssetsPath + textResourcesAssetName);
}
}
protected void startDataLoader() {
......
......@@ -70,6 +70,7 @@ public class FormScreen extends AbstractTablexiaScreen<Void> {
});
this.age = 10;
// TODO load texts from resource file
Label age = new Label("Vek", getLabelStyle());
ageLabel = new Label(String.valueOf(this.age), getLabelStyle());
Label gender = new Label("Pohlavi", getLabelStyle());
......
package cz.nic.tablexia.screen.createuser;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.Color;
......@@ -24,10 +23,8 @@ import java.util.List;
import cz.nic.tablexia.Tablexia;
import cz.nic.tablexia.TablexiaApplication;
import cz.nic.tablexia.bus.ApplicationBus;
import cz.nic.tablexia.loader.TablexiaAbstractFileManager;
import cz.nic.tablexia.screen.AbstractTablexiaScreen;
import cz.nic.tablexia.util.ScaleUtil;
import cz.nic.tablexia.util.Utility;
import cz.nic.tablexia.util.ui.dialog.TablexiaDialog;
import cz.nic.tablexia.util.ui.dialog.TextDialog;
import cz.nic.tablexia.util.ui.dialog.text.DialogTextContent;
......@@ -54,6 +51,12 @@ public class PanoramaScreen extends AbstractTablexiaScreen<Void> {
public static final String MUSIC_3 = MFX_PATH + "newspaper/3.mp3";
public static final String MUSIC_4 = MFX_PATH + "newspaper/4.mp3";
@Override
protected String prepareScreenTextResourcesAssetName() {
// no text loading
return null;
}
@Override
protected void screenLoaded() {
switchSubscreen(prepareBalcony());
......
......@@ -17,6 +17,12 @@ public class GameMenuScreen extends AbstractTablexiaScreen<Void> {
private ViewPager vp;
@Override
protected String prepareScreenTextResourcesAssetName() {
// no text loading
return null;
}
@Override
protected void screenLoaded() {
getStage().setDebugAll(TablexiaSettings.getInstance().isShowBoundingBoxes());
......
......@@ -21,6 +21,13 @@ public class LoaderScreen extends AbstractTablexiaScreen<Void> {
@Override
protected String prepareScreenAtlasPath(String screenAssetsPath, String screenName) {
// no atlas loading
return null;
}
@Override
protected String prepareScreenTextResourcesAssetName() {
// no text loading
return null;
}
......
......@@ -20,14 +20,14 @@ import cz.nic.tablexia.screen.AbstractTablexiaScreen;
public class PreferencesScreen extends AbstractTablexiaScreen<Void> {
public static final String TEXT_RESOURCES_FILE = "text/application/preferences";
public static final String LANGUAGE_LABEL_KEY = "language_label";
private Container<Table> preferencesContainer;
@Override
protected String prepareScreenTextResourcesAssetName() {
return TEXT_RESOURCES_FILE;
protected String prepareScreenAtlasPath(String screenAssetsPath, String screenName) {
// no atlas loading
return null;
}
@Override
......
......@@ -20,6 +20,13 @@ public class FullscreenImageDebugScreen extends AbstractTablexiaScreen<Void> {
@Override
protected String prepareScreenAtlasPath(String screenAssetsPath, String screenName) {
// no atlas loading
return null;
}
@Override
protected String prepareScreenTextResourcesAssetName() {
// no text loading
return null;
}
......
......@@ -14,6 +14,12 @@ import cz.nic.tablexia.util.Log;
*/
public class ViewportDebugScreen extends AbstractTablexiaScreen<Void> {
@Override
protected String prepareScreenAtlasPath(String screenAssetsPath, String screenName) {
// no atlas loading
return null;
}
@Override
protected void screenLoaded() {
getStage().setDebugAll(true);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment