Skip to content
Snippets Groups Projects
Commit 50f51514 authored by Matyáš Latner's avatar Matyáš Latner
Browse files

Merge branch 'devel' into feature-abstractgame

parents 21046069 858abb57
No related branches found
No related tags found
No related merge requests found
Showing
with 509 additions and 255 deletions
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
<activity <activity
android:name="cz.nic.tablexia.android.AndroidLauncher" android:name="cz.nic.tablexia.android.AndroidLauncher"
android:label="@string/app_name" android:label="@string/app_name"
android:screenOrientation="landscape" android:screenOrientation="sensorLandscape"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"> android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
......
android/assets/gfx/screen_loader_bighand.png

985 B

android/assets/gfx/screen_loader_smallhand.png

751 B

...@@ -10,6 +10,10 @@ mainmenu_preferences=Nastavení ...@@ -10,6 +10,10 @@ mainmenu_preferences=Nastavení
mainmenu_about=O aplikaci mainmenu_about=O aplikaci
mainmenu_logout=Odhlásit mainmenu_logout=Odhlásit
gamedifficulty_easy=Lehká
gamedifficulty_medium=Střední
gamedifficulty_hard=Těžká
game_robbery_title=Lupiči game_robbery_title=Lupiči
game_kidnapping_title=Únos game_kidnapping_title=Únos
game_pursuit_title=Pronásledování game_pursuit_title=Pronásledování
......
...@@ -10,6 +10,10 @@ mainmenu_preferences=Nastavenie ...@@ -10,6 +10,10 @@ mainmenu_preferences=Nastavenie
mainmenu_about=O aplikácií mainmenu_about=O aplikácií
mainmenu_logout=Odhlásiť mainmenu_logout=Odhlásiť
gamedifficulty_easy=Ľahká
gamedifficulty_medium=Stredná
gamedifficulty_hard=Ťažká
game_robbery_title=Lupiči game_robbery_title=Lupiči
game_kidnapping_title=Únos game_kidnapping_title=Únos
game_pursuit_title=Prenasledovanie game_pursuit_title=Prenasledovanie
......
...@@ -36,9 +36,11 @@ android { ...@@ -36,9 +36,11 @@ android {
} }
applicationVariants.all { variant -> applicationVariants.all { variant ->
variant.outputs.each { output -> if (!variant.buildType.name.equals("debug")) {
def file = output.outputFile variant.outputs.each { output ->
output.outputFile = new File(file.parent, file.name.replace(".apk", "-" + tablexiaVersionName + ".apk").replace("android", appName)) def file = output.outputFile
output.outputFile = new File(file.parent, file.name.replace(".apk", "-" + tablexiaVersionName + ".apk").replace("android", appName))
}
} }
} }
......
core/assets/common/screen/gamemenu/overlay.png

86 B

core/assets/cs/screen/gamemenu/helplayer.png

35.4 KiB | W: | H:

core/assets/cs/screen/gamemenu/helplayer.png

35.4 KiB | W: | H:

core/assets/cs/screen/gamemenu/helplayer.png
core/assets/cs/screen/gamemenu/helplayer.png
core/assets/cs/screen/gamemenu/helplayer.png
core/assets/cs/screen/gamemenu/helplayer.png
  • 2-up
  • Swipe
  • Onion skin
core/assets/cs/screen/gamemenu/potme_startbutton_pressed.png

27.1 KiB | W: | H:

core/assets/cs/screen/gamemenu/potme_startbutton_pressed.png

44.9 KiB | W: | H:

core/assets/cs/screen/gamemenu/potme_startbutton_pressed.png
core/assets/cs/screen/gamemenu/potme_startbutton_pressed.png
core/assets/cs/screen/gamemenu/potme_startbutton_pressed.png
core/assets/cs/screen/gamemenu/potme_startbutton_pressed.png
  • 2-up
  • Swipe
  • Onion skin
core/assets/cs/screen/gamemenu/strelnice_startbutton_pressed.png

27.1 KiB | W: | H:

core/assets/cs/screen/gamemenu/strelnice_startbutton_pressed.png

42.3 KiB | W: | H:

core/assets/cs/screen/gamemenu/strelnice_startbutton_pressed.png
core/assets/cs/screen/gamemenu/strelnice_startbutton_pressed.png
core/assets/cs/screen/gamemenu/strelnice_startbutton_pressed.png
core/assets/cs/screen/gamemenu/strelnice_startbutton_pressed.png
  • 2-up
  • Swipe
  • Onion skin
...@@ -22,11 +22,11 @@ import cz.nic.tablexia.util.Log; ...@@ -22,11 +22,11 @@ import cz.nic.tablexia.util.Log;
import cz.nic.tablexia.util.Utility; import cz.nic.tablexia.util.Utility;
public class Tablexia extends TablexiaApplication { public class Tablexia extends TablexiaApplication {
private boolean loadingComplete = false; private boolean loadingComplete = false;
private MainMenuContainer mainMenuContainer; private MainMenuContainer mainMenuContainer;
private ZipAssetLoader zipAssetLoader; private ZipAssetLoader zipAssetLoader;
private boolean resetState; private boolean resetState;
public Tablexia(boolean debug, Locale systemLocale, String versionName, String applicationId, boolean resetState) { public Tablexia(boolean debug, Locale systemLocale, String versionName, String applicationId, boolean resetState) {
TablexiaSettings.init(debug, systemLocale, versionName, applicationId); TablexiaSettings.init(debug, systemLocale, versionName, applicationId);
...@@ -37,14 +37,14 @@ public class Tablexia extends TablexiaApplication { ...@@ -37,14 +37,14 @@ public class Tablexia extends TablexiaApplication {
TablexiaSettings.init(buildTypeKey, systemLocale, versionName, applicationId); TablexiaSettings.init(buildTypeKey, systemLocale, versionName, applicationId);
this.resetState = resetState; this.resetState = resetState;
} }
private void loadingComplete() { private void loadingComplete() {
if (!loadingComplete) { if (!loadingComplete) {
loadingComplete = true; loadingComplete = true;
showLastOrInitialScreen(); showLastOrInitialScreen();
ApplicationBus.getInstance().publishAsync(new ApplicationLoadingCompleteEvent()); ApplicationBus.getInstance().publishAsync(new ApplicationLoadingCompleteEvent());
} }
} }
private void showLastOrInitialScreen() { private void showLastOrInitialScreen() {
AbstractTablexiaScreen<?> lastScreen = TablexiaSettings.getInstance().getCurrentScreen(); AbstractTablexiaScreen<?> lastScreen = TablexiaSettings.getInstance().getCurrentScreen();
...@@ -58,7 +58,7 @@ public class Tablexia extends TablexiaApplication { ...@@ -58,7 +58,7 @@ public class Tablexia extends TablexiaApplication {
private void prepareMainMenu() { private void prepareMainMenu() {
mainMenuContainer = new MainMenuContainer(getStage().getWidth(), getStage().getHeight()); mainMenuContainer = new MainMenuContainer(getStage().getWidth(), getStage().getHeight());
getStage().addActor(mainMenuContainer); getStage().addActor(mainMenuContainer);
} }
private void startLoading(Locale locale) { private void startLoading(Locale locale) {
// sync loaded screen with loader image // sync loaded screen with loader image
...@@ -106,13 +106,13 @@ public class Tablexia extends TablexiaApplication { ...@@ -106,13 +106,13 @@ public class Tablexia extends TablexiaApplication {
} }
}); });
} }
//////////////////////////// LIBGDX LIFECYCLE //////////////////////////// LIBGDX LIFECYCLE
@Override @Override
public void create () { public void create() {
super.create(); super.create();
TablexiaSettings.getInstance().loadPreferences(resetState); TablexiaSettings.getInstance().loadPreferences(resetState);
Log.setLoglevel(TablexiaSettings.getInstance().getLogLevel()); Log.setLoglevel(TablexiaSettings.getInstance().getLogLevel());
...@@ -122,7 +122,7 @@ public class Tablexia extends TablexiaApplication { ...@@ -122,7 +122,7 @@ public class Tablexia extends TablexiaApplication {
// start loading application scope data // start loading application scope data
startLoading(TablexiaSettings.getInstance().getLocale()); startLoading(TablexiaSettings.getInstance().getLocale());
} }
@Override @Override
public void pause() { public void pause() {
...@@ -134,76 +134,77 @@ public class Tablexia extends TablexiaApplication { ...@@ -134,76 +134,77 @@ public class Tablexia extends TablexiaApplication {
} }
@Override @Override
public void render () { public void render() {
// render other screens // render other screens
super.render(); super.render();
// process loading // process loading
if (!loadingComplete) { if (!loadingComplete) {
// load internal assets // load internal assets
if (!ApplicationFontManager.getInstance().update()) return; if (!ApplicationFontManager.getInstance().update()) return;
if (!ApplicationTextManager.getInstance().update()) return; if (!ApplicationTextManager.getInstance().update()) return;
// load external assets // load external assets
if (!zipAssetLoader.update()) return; if (!zipAssetLoader.update()) return;
if (!ApplicationTextureManager.getInstance().update()) return; if (!ApplicationTextureManager.getInstance().update()) return;
if (!ApplicationSoundManager.getInstance().update()) return; if (!ApplicationSoundManager.getInstance().update()) return;
prepareMainMenu(); prepareMainMenu();
loadingComplete(); loadingComplete();
} }
} }
@Override @Override
public void dispose() { public void dispose() {
super.dispose(); super.dispose();
clearLoadedData(); clearLoadedData();
} }
//////////////////////////// APPLICATION LOADING COMPLETE EVENT //////////////////////////// APPLICATION LOADING COMPLETE EVENT
public static class ApplicationLoadingCompleteEvent implements ApplicationEvent {} public static class ApplicationLoadingCompleteEvent implements ApplicationEvent {
}
//////////////////////////// CHANGE SCREEN EVENT //////////////////////////// CHANGE SCREEN EVENT
public static class ChangeScreenEvent implements ApplicationEvent {
private Class<? extends AbstractTablexiaScreen<?>> screen;
private ScreenTransaction screenTransaction;
public ChangeScreenEvent(Class<? extends AbstractTablexiaScreen<?>> screen, ScreenTransaction screenTransaction) { public static class ChangeScreenEvent implements ApplicationEvent {
this.screen = screen;
this.screenTransaction = screenTransaction; private Class<? extends AbstractTablexiaScreen<?>> screen;
} private ScreenTransaction screenTransaction;
public Class<? extends AbstractTablexiaScreen<?>> getScreen() { public ChangeScreenEvent(Class<? extends AbstractTablexiaScreen<?>> screen, ScreenTransaction screenTransaction) {
return screen; this.screen = screen;
} this.screenTransaction = screenTransaction;
}
public ScreenTransaction getScreenTransaction() {
return screenTransaction; public Class<? extends AbstractTablexiaScreen<?>> getScreen() {
} return screen;
} }
@Handler public ScreenTransaction getScreenTransaction() {
public void handleChangeScreenEvent(final ChangeScreenEvent changeScreenEvent) { return screenTransaction;
final Class<? extends AbstractTablexiaScreen<?>> screenClass = changeScreenEvent.getScreen(); }
if (!loadingComplete) { }
Log.err(getClass(), "Cannot change screen -> Application loading not complete!");
return; @Handler
} public void handleChangeScreenEvent(final ChangeScreenEvent changeScreenEvent) {
if (screenClass == null) { final Class<? extends AbstractTablexiaScreen<?>> screenClass = changeScreenEvent.getScreen();
Log.err(getClass(), "Cannot change screen -> Received empty screen class!"); if (!loadingComplete) {
return; Log.err(((Object)this).getClass(), "Cannot change screen -> Application loading not complete!");
} return;
// create new screen on GL thread }
Gdx.app.postRunnable(new Runnable() { if (screenClass == null) {
Log.err(((Object)this).getClass(), "Cannot change screen -> Received empty screen class!");
@Override return;
public void run() { }
// create new screen on GL thread
Gdx.app.postRunnable(new Runnable() {
@Override
public void run() {
setScreenIfIsDifferent(Utility.getScreenForScreenClass(screenClass), changeScreenEvent.getScreenTransaction()); setScreenIfIsDifferent(Utility.getScreenForScreenClass(screenClass), changeScreenEvent.getScreenTransaction());
} }
}); });
} }
} }
...@@ -19,38 +19,38 @@ import cz.nic.tablexia.util.Utility; ...@@ -19,38 +19,38 @@ import cz.nic.tablexia.util.Utility;
public class TablexiaSettings { public class TablexiaSettings {
private static final int DEFAULT_SCREEN_WIDTH = 1000; private static final int DEFAULT_SCREEN_WIDTH = 1000;
private static final double MAXIMUM_RATIO = 9.0 / 16.0; private static final double MAXIMUM_RATIO = 9.0 / 16.0;
private static final int MIN_SCREEN_HEIGHT = (int) (DEFAULT_SCREEN_WIDTH * MAXIMUM_RATIO); private static final int MIN_SCREEN_HEIGHT = (int) (DEFAULT_SCREEN_WIDTH * MAXIMUM_RATIO);
private static final boolean DEBUG_SHOW_BOUNDING_BOXES = true; private static final boolean DEBUG_SHOW_BOUNDING_BOXES = true;
public static final Class<? extends AbstractTablexiaScreen<?>> INITIAL_SCREEN = GameMenuScreen.class; public static final Class<? extends AbstractTablexiaScreen<?>> INITIAL_SCREEN = GameMenuScreen.class;
public static final String LOCALE_KEY = "locale"; public static final String LOCALE_KEY = "locale";
public static final String CURRENT_SCREEN_KEY = "current_screen"; public static final String CURRENT_SCREEN_KEY = "current_screen";
private static final String IDE_BUILD_APPLICATION_ID = "cz.nic.tablexia.debug"; private static final String IDE_BUILD_APPLICATION_ID = "cz.nic.tablexia.debug";
private static final String IDE_BUILD_VERSION_NAME = "IDE-BUILD"; private static final String IDE_BUILD_VERSION_NAME = "IDE-BUILD";
private final BuildType BUILD_TYPE; private final BuildType BUILD_TYPE;
private final String VERSION_NAME; private final String VERSION_NAME;
private final String APPLICATION_ID; private final String APPLICATION_ID;
private Preferences preferences; private Preferences preferences;
private LocaleDefinition systemLocale; private LocaleDefinition systemLocale;
private LocaleDefinition selectedLocale; private LocaleDefinition selectedLocale;
public static enum BuildType { public static enum BuildType {
RELEASE ("release", false, Log.TablexiaLogLevel.ERROR), RELEASE("release", false, Log.TablexiaLogLevel.ERROR),
DEBUG ("debug", true, Log.TablexiaLogLevel.DEBUG); DEBUG("debug", true, Log.TablexiaLogLevel.DEBUG);
private final static BuildType FALLBACK_VARIANT = BuildType.DEBUG; private final static BuildType FALLBACK_VARIANT = BuildType.DEBUG;
private final String key; private final String key;
private final boolean isDebug; private final boolean isDebug;
private Log.TablexiaLogLevel logLevel; private Log.TablexiaLogLevel logLevel;
private BuildType(String key, boolean isDebug, Log.TablexiaLogLevel logLevel) { private BuildType(String key, boolean isDebug, Log.TablexiaLogLevel logLevel) {
this.key = key; this.key = key;
...@@ -67,7 +67,7 @@ public class TablexiaSettings { ...@@ -67,7 +67,7 @@ public class TablexiaSettings {
} }
public static BuildType getBuildTypeForKey(String key) { public static BuildType getBuildTypeForKey(String key) {
for(BuildType buildType : BuildType.values()) { for (BuildType buildType : BuildType.values()) {
if (buildType.key.equals(key)) { if (buildType.key.equals(key)) {
return buildType; return buildType;
} }
...@@ -78,12 +78,12 @@ public class TablexiaSettings { ...@@ -78,12 +78,12 @@ public class TablexiaSettings {
public enum LocaleDefinition { public enum LocaleDefinition {
SYSTEM (null, "system", ApplicationTextManager.LANGUAGE_SYSTEM), SYSTEM(null, "system", ApplicationTextManager.LANGUAGE_SYSTEM),
cs_CZ (new Locale("cs", "CZ"), "cs_CZ", ApplicationTextManager.LANGUAGE_CZECH), cs_CZ(new Locale("cs", "CZ"), "cs_CZ", ApplicationTextManager.LANGUAGE_CZECH),
sk_SK (new Locale("sk", "SK"), "sk_SK", ApplicationTextManager.LANGUAGE_SLOVAK); sk_SK(new Locale("sk", "SK"), "sk_SK", ApplicationTextManager.LANGUAGE_SLOVAK);
public final static LocaleDefinition DEFAULT_LOCALE = LocaleDefinition.cs_CZ; public final static LocaleDefinition DEFAULT_LOCALE = LocaleDefinition.cs_CZ;
private final static LocaleDefinition FALLBACK_VARIANT = LocaleDefinition.SYSTEM; private final static LocaleDefinition FALLBACK_VARIANT = LocaleDefinition.SYSTEM;
private final Locale locale; private final Locale locale;
private final String localeKey; private final String localeKey;
...@@ -113,7 +113,7 @@ public class TablexiaSettings { ...@@ -113,7 +113,7 @@ public class TablexiaSettings {
} }
public static LocaleDefinition getLocaleDefinitionForKey(String key) { public static LocaleDefinition getLocaleDefinitionForKey(String key) {
for(LocaleDefinition localeDefinition: LocaleDefinition.values()) { for (LocaleDefinition localeDefinition : LocaleDefinition.values()) {
if (localeDefinition.localeKey.equals(key)) { if (localeDefinition.localeKey.equals(key)) {
return localeDefinition; return localeDefinition;
} }
...@@ -122,7 +122,7 @@ public class TablexiaSettings { ...@@ -122,7 +122,7 @@ public class TablexiaSettings {
} }
public static LocaleDefinition getLocaleDefinitionForLocale(Locale locale) { public static LocaleDefinition getLocaleDefinitionForLocale(Locale locale) {
for(LocaleDefinition localeDefinition: LocaleDefinition.values()) { for (LocaleDefinition localeDefinition : LocaleDefinition.values()) {
if (localeDefinition.locale != null && localeDefinition.locale.equals(locale)) { if (localeDefinition.locale != null && localeDefinition.locale.equals(locale)) {
return localeDefinition; return localeDefinition;
} }
...@@ -137,10 +137,10 @@ public class TablexiaSettings { ...@@ -137,10 +137,10 @@ public class TablexiaSettings {
private static TablexiaSettings instance; private static TablexiaSettings instance;
private TablexiaSettings(BuildType buildType, Locale systemLocale, String versionName, String applicationId) { private TablexiaSettings(BuildType buildType, Locale systemLocale, String versionName, String applicationId) {
BUILD_TYPE = buildType; BUILD_TYPE = buildType;
VERSION_NAME = versionName == null ? IDE_BUILD_VERSION_NAME : versionName; VERSION_NAME = versionName == null ? IDE_BUILD_VERSION_NAME : versionName;
APPLICATION_ID = applicationId == null ? IDE_BUILD_APPLICATION_ID : applicationId; APPLICATION_ID = applicationId == null ? IDE_BUILD_APPLICATION_ID : applicationId;
this.systemLocale = LocaleDefinition.getLocaleDefinitionForLocale(systemLocale); this.systemLocale = LocaleDefinition.getLocaleDefinitionForLocale(systemLocale);
} }
public static TablexiaSettings getInstance() { public static TablexiaSettings getInstance() {
...@@ -174,8 +174,8 @@ public class TablexiaSettings { ...@@ -174,8 +174,8 @@ public class TablexiaSettings {
//////////////////////////// LIBGDX PREFERENCES //////////////////////////// LIBGDX PREFERENCES
public void loadPreferences(boolean resetState) { public void loadPreferences(boolean resetState) {
preferences = Gdx.app.getPreferences(getApplicationId()); preferences = Gdx.app.getPreferences(getApplicationId());
selectedLocale = LocaleDefinition.getLocaleDefinitionForKey(preferences.getString(LOCALE_KEY)); selectedLocale = LocaleDefinition.getLocaleDefinitionForKey(preferences.getString(LOCALE_KEY));
if (resetState) { if (resetState) {
preferences.remove(CURRENT_SCREEN_KEY); preferences.remove(CURRENT_SCREEN_KEY);
preferences.flush(); preferences.flush();
......
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
package cz.nic.tablexia.game.difficulty; package cz.nic.tablexia.game.difficulty;
import cz.nic.tablexia.loader.application.ApplicationTextManager;
/** /**
* Game difficulty types * Game difficulty types
* *
...@@ -26,35 +28,29 @@ package cz.nic.tablexia.game.difficulty; ...@@ -26,35 +28,29 @@ package cz.nic.tablexia.game.difficulty;
*/ */
public enum GameDifficulty { public enum GameDifficulty {
// TODO use string resources EASY ("gamedifficulty_easy"),
EASY(1), MEDIUM ("gamedifficulty_medium"),
MEDIUM(2), HARD ("gamedifficulty_hard");
HARD(3);
public static final GameDifficulty DEFAULT_DIFFICULTY = EASY; public static final GameDifficulty DEFAULT_DIFFICULTY = EASY;
private int descriptionResourceId; private String descriptionResourceKey;
private GameDifficulty(int descriptionResourceId) { private GameDifficulty(String descriptionResourceKey) {
this.descriptionResourceId = descriptionResourceId; this.descriptionResourceKey = descriptionResourceKey;
} }
/** public String getTextDescription() {
* Returns id of description for current difficulty return ApplicationTextManager.getInstance().getText(getDescriptionResourceKey());
*
* @return id of description string resource
*/
public int getDescriptionResourceId() {
return descriptionResourceId;
} }
/** /**
* Returns string key for intent extra * Returns key of description for current difficulty
* *
* @return string key for intent extra * @return key of description string resource
*/ */
public static String getIntentKey() { public String getDescriptionResourceKey() {
return GameDifficulty.class.getName(); return descriptionResourceKey;
} }
/** /**
......
package cz.nic.tablexia.screen;
import net.engio.mbassy.listener.Handler;
import cz.nic.tablexia.Tablexia.ChangeScreenEvent;
import cz.nic.tablexia.TablexiaApplication.ScreenTransaction;
import cz.nic.tablexia.bus.ApplicationBus;
import cz.nic.tablexia.menu.MainMenuDefinition;
import cz.nic.tablexia.screen.about.AboutScreen;
import cz.nic.tablexia.screen.encyclopedia.EncyclopediaScreen;
import cz.nic.tablexia.screen.gamemenu.GameMenuScreen;
import cz.nic.tablexia.screen.halloffame.HallOfFameScreen;
import cz.nic.tablexia.screen.loader.LoaderScreen;
import cz.nic.tablexia.screen.preferences.PreferencesScreen;
import cz.nic.tablexia.screen.statistics.StatisticsScreen;
public enum ScreenDefinition {
LOADER(LoaderScreen.class, null),
GAME_MENU(GameMenuScreen.class, null),
HALL_OF_FAME(HallOfFameScreen.class, MainMenuDefinition.HALL_OF_FAME),
STATISTICS(StatisticsScreen.class, MainMenuDefinition.STATISTICS),
ENCYCLOPEDIA(EncyclopediaScreen.class, MainMenuDefinition.ENCYCLOPEDIA),
PREFERENCES(PreferencesScreen.class, MainMenuDefinition.PREFERENCES),
ABOUT_APPLICATION(AboutScreen.class, MainMenuDefinition.ABOUT_APPLICATION);
private Class<? extends AbstractTablexiaScreen<?>> screenClass;
private MainMenuDefinition mainMenuDefinition;
private static Object messageHandler;
private ScreenDefinition(Class<? extends AbstractTablexiaScreen<?>> screenClass, MainMenuDefinition mainMenuDefinition) {
this.screenClass = screenClass;
this.mainMenuDefinition = mainMenuDefinition;
}
public MainMenuDefinition getMainMenuDefinition() {
return mainMenuDefinition;
}
public Class<? extends AbstractTablexiaScreen<?>> getScreenClass() {
return screenClass;
}
public void performMenuAction() {
ApplicationBus.getInstance().publishAsync(new ChangeScreenEvent(screenClass, ScreenTransaction.FADE));
}
public static ScreenDefinition getScreenDefinitionForMainMenuDefinition(MainMenuDefinition mainMenuDefinition) {
for (ScreenDefinition screenDefinition : ScreenDefinition.values()) {
if (screenDefinition.getMainMenuDefinition() == mainMenuDefinition) {
return screenDefinition;
}
}
return null;
}
public static void initBus() {
messageHandler = new Object() {
@Handler
public void handleChangeScreenEvent(MainMenuDefinition mainMenuDefinition) {
ScreenDefinition.getScreenDefinitionForMainMenuDefinition(mainMenuDefinition).performMenuAction();
}
};
ApplicationBus.getInstance().subscribe(messageHandler);
}
}
...@@ -23,6 +23,7 @@ public final class GameMenuAssets { ...@@ -23,6 +23,7 @@ public final class GameMenuAssets {
public static final String OFFICE = GAMEMENU_PATH + "office.jpg"; public static final String OFFICE = GAMEMENU_PATH + "office.jpg";
public static final String OFFICE_CLICKMAP = GAMEMENU_PATH + "clickablemap.png"; public static final String OFFICE_CLICKMAP = GAMEMENU_PATH + "clickablemap.png";
public static final String OFFICE_HELP = GAMEMENU_PATH + "helplayer.png"; public static final String OFFICE_HELP = GAMEMENU_PATH + "helplayer.png";
public static final String OVERLAY = GAMEMENU_PATH + "overlay.png";
public static final String VIGNETTE = GAMEMENU_PATH + "vignetting.png"; public static final String VIGNETTE = GAMEMENU_PATH + "vignetting.png";
public static final String DESK = GAMEMENU_PATH + "desk.png"; public static final String DESK = GAMEMENU_PATH + "desk.png";
public static final String ENCYCLOPEDIA_PRESSED = GAMEMENU_PATH + "encyclopedia_pressed.png"; public static final String ENCYCLOPEDIA_PRESSED = GAMEMENU_PATH + "encyclopedia_pressed.png";
...@@ -54,6 +55,7 @@ public final class GameMenuAssets { ...@@ -54,6 +55,7 @@ public final class GameMenuAssets {
textures.add(DESK); textures.add(DESK);
textures.add(OFFICE_HELP); textures.add(OFFICE_HELP);
textures.add(VIGNETTE); textures.add(VIGNETTE);
textures.add(OVERLAY);
textures.add(DIFF_BAR); textures.add(DIFF_BAR);
textures.add(DIFF_THUMB); textures.add(DIFF_THUMB);
......
package cz.nic.tablexia.screen.gamemenu; package cz.nic.tablexia.screen.gamemenu;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.scenes.scene2d.Touchable; import com.badlogic.gdx.scenes.scene2d.Touchable;
import com.badlogic.gdx.scenes.scene2d.ui.Image; import com.badlogic.gdx.scenes.scene2d.ui.Image;
import net.engio.mbassy.listener.Handler;
import java.util.List; import java.util.List;
import cz.nic.tablexia.bus.ApplicationBus;
import cz.nic.tablexia.game.GameDefinition; import cz.nic.tablexia.game.GameDefinition;
import cz.nic.tablexia.screen.AbstractTablexiaScreen; import cz.nic.tablexia.screen.AbstractTablexiaScreen;
import cz.nic.tablexia.screen.gamemenu.pages.GameMenuPage; import cz.nic.tablexia.screen.gamemenu.pages.GameMenuPage;
import cz.nic.tablexia.screen.gamemenu.pages.OfficeMenuPage; import cz.nic.tablexia.screen.gamemenu.pages.OfficeMenuPage;
import cz.nic.tablexia.util.Log;
import cz.nic.tablexia.util.ui.ViewPager; import cz.nic.tablexia.util.ui.ViewPager;
public class GameMenuScreen extends AbstractTablexiaScreen<Void> { public class GameMenuScreen extends AbstractTablexiaScreen<Void> {
private ViewPager vp; private ViewPager vp;
@Override @Override
protected void prepareScreenTextureAssetNames(List<String> textureFileNames) { protected void prepareScreenTextureAssetNames(List<String> textureFileNames) {
super.prepareScreenTextureAssetNames(textureFileNames); super.prepareScreenTextureAssetNames(textureFileNames);
...@@ -26,7 +28,6 @@ public class GameMenuScreen extends AbstractTablexiaScreen<Void> { ...@@ -26,7 +28,6 @@ public class GameMenuScreen extends AbstractTablexiaScreen<Void> {
@Override @Override
protected void screenLoaded() { protected void screenLoaded() {
vp = new ViewPager(); vp = new ViewPager();
vp.addPage(new OfficeMenuPage(this)); vp.addPage(new OfficeMenuPage(this));
for (GameDefinition gd : GameDefinition.getActiveGames()) { for (GameDefinition gd : GameDefinition.getActiveGames()) {
...@@ -34,15 +35,25 @@ public class GameMenuScreen extends AbstractTablexiaScreen<Void> { ...@@ -34,15 +35,25 @@ public class GameMenuScreen extends AbstractTablexiaScreen<Void> {
} }
vp.setSize(getStage().getWidth(), getStage().getHeight()); vp.setSize(getStage().getWidth(), getStage().getHeight());
Log.info(getClass().getName(), "ViewPager size: " + getStage().getWidth() + "x" + getStage().getHeight());
getStage().addActor(vp); getStage().addActor(vp);
Image im = new Image(getTexture(GameMenuAssets.VIGNETTE)); Image im = new Image(getTexture(GameMenuAssets.VIGNETTE));
im.setTouchable(Touchable.disabled); im.setTouchable(Touchable.disabled);
im.setSize(getStage().getWidth(), getStage().getHeight()); im.setSize(getStage().getWidth(), getStage().getHeight());
getStage().addActor(im); getStage().addActor(im);
ApplicationBus.getInstance().subscribe(this);
}
@Handler
public void handleShowStreet(OfficeMenuPage.ShowStreetEvent message) {
vp.scrollToPage(1);
}
@Override
public Texture getTexture(String textureName) {
Texture texture = super.getTexture(textureName);
texture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
return texture;
} }
} }
...@@ -3,6 +3,7 @@ package cz.nic.tablexia.screen.gamemenu.pages; ...@@ -3,6 +3,7 @@ package cz.nic.tablexia.screen.gamemenu.pages;
import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.InputEvent; import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener; import com.badlogic.gdx.scenes.scene2d.InputListener;
...@@ -10,10 +11,13 @@ import com.badlogic.gdx.scenes.scene2d.actions.AlphaAction; ...@@ -10,10 +11,13 @@ import com.badlogic.gdx.scenes.scene2d.actions.AlphaAction;
import com.badlogic.gdx.scenes.scene2d.actions.MoveToAction; import com.badlogic.gdx.scenes.scene2d.actions.MoveToAction;
import com.badlogic.gdx.scenes.scene2d.ui.Image; import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Label; import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Stack;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import cz.nic.tablexia.TablexiaSettings; import cz.nic.tablexia.TablexiaSettings;
import cz.nic.tablexia.game.GameDefinition; import cz.nic.tablexia.game.GameDefinition;
import cz.nic.tablexia.game.difficulty.GameDifficulty;
import cz.nic.tablexia.loader.application.ApplicationTextManager;
import cz.nic.tablexia.screen.AbstractTablexiaScreen; import cz.nic.tablexia.screen.AbstractTablexiaScreen;
import cz.nic.tablexia.screen.gamemenu.GameMenuAssets; import cz.nic.tablexia.screen.gamemenu.GameMenuAssets;
import cz.nic.tablexia.util.ui.ViewPager; import cz.nic.tablexia.util.ui.ViewPager;
...@@ -26,6 +30,9 @@ public class GameMenuPage extends MenuPage implements ViewPager.ScrollListener { ...@@ -26,6 +30,9 @@ public class GameMenuPage extends MenuPage implements ViewPager.ScrollListener {
private GameDefinition game; private GameDefinition game;
private float diffEasyX, diffMediumX, diffHardX; private float diffEasyX, diffMediumX, diffHardX;
private Actor diffEasy, diffMedium, diffHard;
private Stack diffStack;
private GameDifficulty gameDifficulty = GameDifficulty.EASY;
private float scrollOffset = TablexiaSettings.getDefaultScreenWidth(); // hack to keep paralax layers out of picture before scrolled for first time private float scrollOffset = TablexiaSettings.getDefaultScreenWidth(); // hack to keep paralax layers out of picture before scrolled for first time
...@@ -33,7 +40,6 @@ public class GameMenuPage extends MenuPage implements ViewPager.ScrollListener { ...@@ -33,7 +40,6 @@ public class GameMenuPage extends MenuPage implements ViewPager.ScrollListener {
super(screen); super(screen);
this.game = game; this.game = game;
// Title // Title
Texture title = getScreen().getTexture(GameMenuAssets.getResourcePath(game, GameMenuAssets.GameMenuLayers.TITLE)); Texture title = getScreen().getTexture(GameMenuAssets.getResourcePath(game, GameMenuAssets.GameMenuLayers.TITLE));
Image titleImage = new Image(title); Image titleImage = new Image(title);
...@@ -68,7 +74,6 @@ public class GameMenuPage extends MenuPage implements ViewPager.ScrollListener { ...@@ -68,7 +74,6 @@ public class GameMenuPage extends MenuPage implements ViewPager.ScrollListener {
addActor(startDownButton); addActor(startDownButton);
addActor(startButton); addActor(startButton);
startButton.addListener(new ClickListener() { startButton.addListener(new ClickListener() {
@Override @Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
...@@ -93,53 +98,59 @@ public class GameMenuPage extends MenuPage implements ViewPager.ScrollListener { ...@@ -93,53 +98,59 @@ public class GameMenuPage extends MenuPage implements ViewPager.ScrollListener {
} }
}); });
// Labels for diffuculty slider final Texture diff = getScreen().getTexture(GameMenuAssets.DIFF_THUMB_EASY);
Label.LabelStyle labelStyle = new Label.LabelStyle(screen.getDefaultRegularFont(), Color.BLACK); float diffY = screen.getStage().getHeight() * 0.06f;
// TODO load texts from GameDifficulty enum float diffHeight = screen.getStage().getHeight() * 0.12f;
Label easy = new Label("Easy", labelStyle); float diffWidth = diffHeight * ((float) diff.getWidth() / (float) diff.getHeight());
Label medium = new Label("Medium", labelStyle);
Label hard = new Label("Hard", labelStyle);
easy.setPosition((screen.getStage().getWidth() / 2) - (screen.getStage().getWidth() * 0.1f) - easy.getWidth() / 2, screen.getStage().getHeight() * 0.0f);
medium.setPosition((screen.getStage().getWidth() / 2) - medium.getWidth() / 2, screen.getStage().getHeight() * 0.0f);
hard.setPosition((screen.getStage().getWidth() / 2) + (screen.getStage().getWidth() * 0.1f) - hard.getWidth() / 2, screen.getStage().getHeight() * 0.0f);
addActor(easy);
addActor(medium);
addActor(hard);
// Difficulty bar // Difficulty bar
Texture diffBar = getScreen().getTexture(GameMenuAssets.DIFF_BAR); Texture diffBar = getScreen().getTexture(GameMenuAssets.DIFF_BAR);
Image diffBarImage = new Image(diffBar); Image diffBarImage = new Image(diffBar);
int diffBarHeight = (int) (screen.getStage().getHeight() * 0.05); int diffBarHeight = (int) (screen.getStage().getHeight() * 0.04f);
int diffBarWidth = (int) (diffBarHeight * ((float) diffBar.getWidth() / (float) diffBar.getHeight())); int diffBarWidth = (int) (diffBarHeight * ((float) diffBar.getWidth() / (float) diffBar.getHeight()));
int diffBarX = (int) screen.getStage().getWidth() / 2 - diffBarWidth / 2; int diffBarX = (int) screen.getStage().getWidth() / 2 - diffBarWidth / 2;
int diffBarY = (int) (screen.getStage().getHeight() * 0.1 - diffBarHeight); int diffBarY = (int) (screen.getStage().getHeight() * 0.1);
diffBarImage.setPosition(diffBarX, diffBarY); diffBarImage.setPosition(diffBarX, diffBarY);
diffBarImage.setSize(diffBarWidth, diffBarHeight); diffBarImage.setSize(diffBarWidth, diffBarHeight);
addActor(diffBarImage); addActor(diffBarImage);
// Difficulty button diffMediumX = (screen.getStage().getWidth() / 2) - (diffWidth / 2);
diffEasyX = diffMediumX - (diffBarWidth / 2) + (diffWidth * 0.1f);
diffHardX = diffMediumX + (diffBarWidth / 2) - (diffWidth * 0.1f);
// Labels for diffuculty slider
BitmapFont font = screen.getDefaultBoldFont();
font.setScale(0.5f);
Label.LabelStyle labelStyle = new Label.LabelStyle(font, Color.BLACK);
final Texture diff = getScreen().getTexture(GameMenuAssets.DIFF_THUMB_MEDIUM); Label easy = new Label(GameDifficulty.EASY.getTextDescription(), labelStyle);
final Image diffButton = new Image(diff); Label medium = new Label(GameDifficulty.MEDIUM.getTextDescription(), labelStyle);
float diffY = 0; Label hard = new Label(GameDifficulty.HARD.getTextDescription(), labelStyle);
float diffHeight = screen.getStage().getHeight() * 0.15f;
float diffWidth = diffHeight * ((float) diff.getWidth() / (float) diff.getHeight());
diffEasyX = (screen.getStage().getWidth() / 2 - diffWidth / 2 + (int) (diffWidth * 0.1f)) - diffBarWidth / 2; float labelY = screen.getStage().getHeight() * 0.06f;
diffMediumX = screen.getStage().getWidth() / 2 - diffWidth / 2 + (int) (diffWidth * 0.1f); float labelAddX = diffWidth / 2;
diffHardX = (screen.getStage().getWidth() / 2 - diffWidth / 2 + (int) (diffWidth * 0.1f)) + diffBarWidth / 2; easy.setPosition(diffEasyX + labelAddX - easy.getWidth() / 2, labelY);
medium.setPosition(diffMediumX + labelAddX - medium.getWidth() / 2, labelY);
hard.setPosition(diffHardX + labelAddX - hard.getWidth() / 2, labelY);
float diffX = diffEasyX; addActor(easy);
diffButton.setSize(diffWidth, diffHeight); addActor(medium);
diffButton.setPosition(diffX, diffY); addActor(hard);
addActor(diffButton);
// Difficulty button
diffStack = new Stack();
diffStack.addActor(diffEasy = new Image(diff));
diffStack.addActor(diffMedium = new Image(getScreen().getTexture(GameMenuAssets.DIFF_THUMB_MEDIUM)));
diffStack.addActor(diffHard = new Image(getScreen().getTexture(GameMenuAssets.DIFF_THUMB_HARD)));
float diffX = diffEasyX;
diffStack.setSize(diffWidth, diffHeight);
diffStack.setPosition(diffX, diffY);
addActor(diffStack);
setDifficulty(gameDifficulty);
diffButton.addListener(new InputListener() { diffStack.addListener(new InputListener() {
float lastX; float lastX;
@Override @Override
...@@ -153,41 +164,117 @@ public class GameMenuPage extends MenuPage implements ViewPager.ScrollListener { ...@@ -153,41 +164,117 @@ public class GameMenuPage extends MenuPage implements ViewPager.ScrollListener {
@Override @Override
public void touchDragged(InputEvent event, float x, float y, int pointer) { public void touchDragged(InputEvent event, float x, float y, int pointer) {
super.touchDragged(event, x, y, pointer); super.touchDragged(event, x, y, pointer);
float bx = diffButton.getX() + (x - lastX); float bx = diffStack.getX() + (x - lastX);
if (bx >= diffEasyX && bx <= diffHardX) { if (bx >= diffEasyX && bx <= diffHardX) {
diffButton.setPosition(bx, diffButton.getY()); diffStack.setPosition(bx, diffStack.getY());
} }
showDifficulty(getDifficulty());
event.stop(); event.stop();
} }
@Override @Override
public void touchUp(InputEvent event, float x, float y, int pointer, int button) { public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
super.touchUp(event, x, y, pointer, button); super.touchUp(event, x, y, pointer, button);
float bx = diffButton.getX() + (x - lastX); float bx = diffStack.getX() + (x - lastX);
MoveToAction ma = new MoveToAction();
if (bx < diffMediumX) { GameDifficulty newDiff = getDifficulty();
if ((diffEasyX + ((diffMediumX - diffEasyX) / 2)) > bx) { setDifficulty(newDiff);
ma.setPosition(diffEasyX, diffButton.getY()); if (gameDifficulty != newDiff) {
} else { difficultyChanged(newDiff);
ma.setPosition(diffMediumX, diffButton.getY());
}
} else {
if ((diffMediumX + ((diffHardX - diffMediumX) / 2)) > bx) {
ma.setPosition(diffMediumX, diffButton.getY());
} else {
ma.setPosition(diffHardX, diffButton.getY());
}
} }
diffButton.addAction(ma);
event.stop(); event.stop();
} }
}); });
} }
/**
* Change selector to custom difficulty
*
* @param difficulty
*/
public void setDifficulty(GameDifficulty difficulty) {
showDifficulty(difficulty);
MoveToAction ma = new MoveToAction();
switch (difficulty) {
case EASY:
ma.setPosition(diffEasyX, diffStack.getY());
break;
case MEDIUM:
ma.setPosition(diffMediumX, diffStack.getY());
break;
case HARD:
ma.setPosition(diffHardX, diffStack.getY());
break;
}
diffStack.addAction(ma);
if (gameDifficulty != difficulty) {
difficultyChanged(difficulty);
}
}
/**
* Called when difficulty is changed
*
* @param difficulty
*/
public void difficultyChanged(GameDifficulty difficulty) {
gameDifficulty = difficulty;
// TODO
}
/**
* Get nearest difficulty from current slider position
*
* @return
*/
private GameDifficulty getDifficulty() {
float bx = diffStack.getX();
if (bx < diffMediumX) {
if ((diffEasyX + ((diffMediumX - diffEasyX) / 2)) > bx) {
return GameDifficulty.EASY;
} else {
return GameDifficulty.MEDIUM;
}
} else {
if ((diffMediumX + ((diffHardX - diffMediumX) / 2)) > bx) {
return GameDifficulty.MEDIUM;
} else {
return GameDifficulty.HARD;
}
}
}
/**
* Check difficulty image and display corresponding image
*
* @param diff
*/
private void showDifficulty(GameDifficulty diff) {
diffEasy.setVisible(false);
diffMedium.setVisible(false);
diffHard.setVisible(false);
switch (diff) {
case EASY:
diffEasy.setVisible(true);
break;
case MEDIUM:
diffMedium.setVisible(true);
break;
case HARD:
diffHard.setVisible(true);
break;
}
}
@Override @Override
public void draw(Batch batch, float parentAlpha) { public void draw(Batch batch, float parentAlpha) {
// Paralax layers // Paralax layers
// Back layer travels half the speed of scroll // Back layer travels half the speed of scroll
// needed to make fade work
Color color = new Color(this.getColor().r, this.getColor().g, this.getColor().b, this.getColor().a * parentAlpha);
batch.setColor(color);
Texture back = getScreen().getTexture(GameMenuAssets.getResourcePath(game, GameMenuAssets.GameMenuLayers.BACK)); Texture back = getScreen().getTexture(GameMenuAssets.getResourcePath(game, GameMenuAssets.GameMenuLayers.BACK));
float scrollHalf = (Math.abs(scrollOffset / 2) / getWidth()) * back.getWidth(); float scrollHalf = (Math.abs(scrollOffset / 2) / getWidth()) * back.getWidth();
int srcX = (int) scrollHalf; int srcX = (int) scrollHalf;
...@@ -200,7 +287,6 @@ public class GameMenuPage extends MenuPage implements ViewPager.ScrollListener { ...@@ -200,7 +287,6 @@ public class GameMenuPage extends MenuPage implements ViewPager.ScrollListener {
batch.draw(getScreen().getTexture(GameMenuAssets.getResourcePath(game, GameMenuAssets.GameMenuLayers.MID)), getX(), getY(), getWidth(), getHeight()); batch.draw(getScreen().getTexture(GameMenuAssets.getResourcePath(game, GameMenuAssets.GameMenuLayers.MID)), getX(), getY(), getWidth(), getHeight());
// Foreground layer travels faster and could be wider than screen. Needs to be clipped // Foreground layer travels faster and could be wider than screen. Needs to be clipped
Texture fore = getScreen().getTexture(GameMenuAssets.getResourcePath(game, GameMenuAssets.GameMenuLayers.FORE)); Texture fore = getScreen().getTexture(GameMenuAssets.getResourcePath(game, GameMenuAssets.GameMenuLayers.FORE));
float foreWidth = (getHeight() / fore.getHeight()) * fore.getWidth(); float foreWidth = (getHeight() / fore.getHeight()) * fore.getWidth();
batch.draw(fore, getX() - ((foreWidth - getWidth()) / 2) + (scrollOffset / 2), getY(), foreWidth, getHeight()); batch.draw(fore, getX() - ((foreWidth - getWidth()) / 2) + (scrollOffset / 2), getY(), foreWidth, getHeight());
......
package cz.nic.tablexia.screen.gamemenu.pages; package cz.nic.tablexia.screen.gamemenu.pages;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Group; import com.badlogic.gdx.scenes.scene2d.Group;
import cz.nic.tablexia.screen.AbstractTablexiaScreen; import cz.nic.tablexia.screen.AbstractTablexiaScreen;
...@@ -17,4 +18,12 @@ public abstract class MenuPage extends Group { ...@@ -17,4 +18,12 @@ public abstract class MenuPage extends Group {
protected AbstractTablexiaScreen getScreen() { protected AbstractTablexiaScreen getScreen() {
return screen; return screen;
} }
@Override
public void setDebug(boolean enabled) {
super.setDebug(enabled);
for (Actor a : getChildren()) {
a.setDebug(enabled);
}
}
} }
...@@ -3,13 +3,24 @@ package cz.nic.tablexia.screen.gamemenu.pages; ...@@ -3,13 +3,24 @@ package cz.nic.tablexia.screen.gamemenu.pages;
import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Pixmap; import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.scenes.scene2d.Group;
import com.badlogic.gdx.scenes.scene2d.InputEvent; import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Stack;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import cz.nic.tablexia.Tablexia;
import cz.nic.tablexia.TablexiaApplication;
import cz.nic.tablexia.bus.ApplicationBus;
import cz.nic.tablexia.menu.MainMenuDefinition; import cz.nic.tablexia.menu.MainMenuDefinition;
import cz.nic.tablexia.screen.AbstractTablexiaScreen; import cz.nic.tablexia.screen.AbstractTablexiaScreen;
import cz.nic.tablexia.screen.encyclopedia.EncyclopediaScreen;
import cz.nic.tablexia.screen.gamemenu.GameMenuAssets; import cz.nic.tablexia.screen.gamemenu.GameMenuAssets;
import cz.nic.tablexia.screen.halloffame.HallOfFameScreen;
import cz.nic.tablexia.screen.profile.ProfileScreen;
import cz.nic.tablexia.screen.statistics.StatisticsScreen;
import cz.nic.tablexia.util.Log; import cz.nic.tablexia.util.Log;
/** /**
...@@ -23,34 +34,120 @@ public class OfficeMenuPage extends MenuPage { ...@@ -23,34 +34,120 @@ public class OfficeMenuPage extends MenuPage {
public static final Color ENCYCLOPEDIA_COLOR = Color.BLACK; public static final Color ENCYCLOPEDIA_COLOR = Color.BLACK;
public static final Color PROFILE_COLOR = Color.BLUE; public static final Color PROFILE_COLOR = Color.BLUE;
private Group help;
private Image hallOfFame;
private Image statistics;
private Image encyclopedia;
private Image street;
private Image profile;
public OfficeMenuPage(AbstractTablexiaScreen screen) { public OfficeMenuPage(AbstractTablexiaScreen screen) {
super(screen); super(screen);
createImageStack();
// TODO show help layer button
addListener(new InputListener() {
private Color downColor;
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
super.touchDown(event, x, y, pointer, button);
Color color = getTouchedColor(x, y);
downColor = color;
help.addAction(Actions.fadeOut(0.5f));
if (color.equals(ENCYCLOPEDIA_COLOR)) {
encyclopedia.setVisible(true);
} else if (color.equals(STATISTICS_COLOR)) {
statistics.setVisible(true);
} else if (color.equals(HALLOFFAME_COLOR)) {
hallOfFame.setVisible(true);
} else if (color.equals(STREET_COLOR)) {
street.setVisible(true);
} else if (color.equals(PROFILE_COLOR)) {
profile.setVisible(true);
} else {
return false;
}
return true;
}
@Override
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
super.touchUp(event, x, y, pointer, button);
Log.info(((Object) this).getClass().getName(), "Touch up ");
hideAllActions();
}
});
addListener(new ClickListener() { addListener(new ClickListener() {
@Override @Override
public void clicked(InputEvent event, float x, float y) { public void clicked(InputEvent event, float x, float y) {
super.clicked(event, x, y); super.clicked(event, x, y);
Color color = getTouchedColor(x, y); Color color = getTouchedColor(x, y);
if (color.equals(ENCYCLOPEDIA_COLOR)) { if (color.equals(ENCYCLOPEDIA_COLOR)) {
MainMenuDefinition.ENCYCLOPEDIA.performAction(); ApplicationBus.getInstance().publishAsync(new Tablexia.ChangeScreenEvent(EncyclopediaScreen.class, TablexiaApplication.ScreenTransaction.FADE));
} else if (color.equals(STATISTICS_COLOR)) { } else if (color.equals(STATISTICS_COLOR)) {
MainMenuDefinition.STATISTICS.performAction(); ApplicationBus.getInstance().publishAsync(new Tablexia.ChangeScreenEvent(StatisticsScreen.class, TablexiaApplication.ScreenTransaction.FADE));
} else if (color.equals(HALLOFFAME_COLOR)) { } else if (color.equals(HALLOFFAME_COLOR)) {
MainMenuDefinition.HALL_OF_FAME.performAction(); ApplicationBus.getInstance().publishAsync(new Tablexia.ChangeScreenEvent(HallOfFameScreen.class, TablexiaApplication.ScreenTransaction.FADE));
} else if (color.equals(STREET_COLOR)) { } else if (color.equals(STREET_COLOR)) {
Log.info(((Object) this).getClass().getName(), "Clicked STREET_COLOR"); ApplicationBus.getInstance().publishAsync(new ShowStreetEvent());
// TODO go to street
} else if (color.equals(PROFILE_COLOR)) { } else if (color.equals(PROFILE_COLOR)) {
// TODO show profile ApplicationBus.getInstance().publishAsync(new Tablexia.ChangeScreenEvent(ProfileScreen.class, TablexiaApplication.ScreenTransaction.FADE));
} else {
// TODO hide help layer
} }
hideAllActions();
} }
}); });
} }
private void createImageStack() {
Stack stack = new Stack();
stack.setSize(getScreen().getStage().getWidth(), getScreen().getStage().getHeight());
stack.setPosition(0, 0);
addActor(stack);
stack.addActor(createImage(GameMenuAssets.OFFICE));
stack.addActor(street = createImage(GameMenuAssets.DOOR_PRESSED));
stack.addActor(encyclopedia = createImage(GameMenuAssets.ENCYCLOPEDIA_PRESSED));
stack.addActor(statistics = createImage(GameMenuAssets.STATISTICS_PRESSED));
stack.addActor(hallOfFame = createImage(GameMenuAssets.HALLOFFAME_PRESSED));
stack.addActor(createImage(GameMenuAssets.DESK));
stack.addActor(profile = createImage(GameMenuAssets.PROFILE_PRESSED));
hideAllActions();
help = new Stack();
help.setSize(getScreen().getStage().getWidth(), getScreen().getStage().getHeight());
help.setPosition(0, 0);
stack.addActor(help);
Image overlay = createImage(GameMenuAssets.OVERLAY);
overlay.getColor().a = 0.5f;
help.addActor(overlay);
help.addActor(createImage(GameMenuAssets.OFFICE_HELP));
}
private void hideAllActions() {
profile.setVisible(false);
street.setVisible(false);
encyclopedia.setVisible(false);
statistics.setVisible(false);
hallOfFame.setVisible(false);
}
/**
* Helper method for creating image instances
*
* @param texture
* @return
*/
private Image createImage(String texture) {
Image image = new Image(getScreen().getTexture(texture));
return image;
}
private Color getTouchedColor(float x, float y) { private Color getTouchedColor(float x, float y) {
Texture clickmap = getScreen().getTexture(GameMenuAssets.OFFICE_CLICKMAP); Texture clickmap = getScreen().getTexture(GameMenuAssets.OFFICE_CLICKMAP);
...@@ -61,28 +158,12 @@ public class OfficeMenuPage extends MenuPage { ...@@ -61,28 +158,12 @@ public class OfficeMenuPage extends MenuPage {
Pixmap pixmap = clickmap.getTextureData().consumePixmap(); Pixmap pixmap = clickmap.getTextureData().consumePixmap();
int clickX = (int) (x / getWidth() * clickmap.getWidth()); int clickX = (int) (x / getWidth() * clickmap.getWidth());
int clickY = clickmap.getHeight() - (int) (y / getHeight() * clickmap.getHeight()); int clickY = clickmap.getHeight() - (int) (y / getHeight() * clickmap.getHeight());
Log.info(((Object) this).getClass().getName(), "Color map " + clickmap.getWidth() + ":" + clickmap.getHeight() + " at " + clickX + ": " + clickY);
return new Color(pixmap.getPixel(clickX, clickY)); return new Color(pixmap.getPixel(clickX, clickY));
} }
/**
@Override * Event fired by clicking on door telling viewpager to page to first game
public void draw(Batch batch, float parentAlpha) { */
batch.disableBlending(); public static class ShowStreetEvent implements ApplicationBus.ApplicationEvent {
batch.draw(getScreen().getTexture(GameMenuAssets.OFFICE), getX(), getY(), getWidth(), getHeight());
batch.enableBlending();
batch.draw(getScreen().getTexture(GameMenuAssets.OFFICE_HELP), getX(), getY(), getWidth(), getHeight());
batch.draw(getScreen().getTexture(GameMenuAssets.PROFILE_PRESSED), getX(), getY(), getWidth(), getHeight());
batch.draw(getScreen().getTexture(GameMenuAssets.DOOR_PRESSED), getX(), getY(), getWidth(), getHeight());
batch.draw(getScreen().getTexture(GameMenuAssets.ENCYCLOPEDIA_PRESSED), getX(), getY(), getWidth(), getHeight());
batch.draw(getScreen().getTexture(GameMenuAssets.STATISTICS_PRESSED), getX(), getY(), getWidth(), getHeight());
batch.draw(getScreen().getTexture(GameMenuAssets.HALLOFFAME_PRESSED), getX(), getY(), getWidth(), getHeight());
batch.draw(getScreen().getTexture(GameMenuAssets.DESK), getX(), getY(), getWidth(), getHeight());
batch.draw(getScreen().getTexture(GameMenuAssets.OFFICE_HELP), getX(), getY(), getWidth(), getHeight());
} }
} }
package cz.nic.tablexia.screen.loader; package cz.nic.tablexia.screen.loader;
import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.graphics.Texture.TextureFilter; import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.scenes.scene2d.Actor;
import java.util.List; import java.util.List;
...@@ -13,26 +11,8 @@ import cz.nic.tablexia.screen.AbstractTablexiaScreen; ...@@ -13,26 +11,8 @@ import cz.nic.tablexia.screen.AbstractTablexiaScreen;
public class LoaderScreen extends AbstractTablexiaScreen<Void> { public class LoaderScreen extends AbstractTablexiaScreen<Void> {
private static final String LOADER_BACKGROUND = "gfx/screen_loader_background.jpg"; private static final String LOADER_BACKGROUND = "gfx/screen_loader_background.jpg";
private static final String LOADER_SMALL_HAND = "gfx/screen_loader_smallhand.png";
private LoaderBackground background; private static final String LOADER_BIG_HAND = "gfx/screen_loader_bighand.png";
private Texture backgroundTexture;
private class LoaderBackground extends Actor {
public LoaderBackground() {
backgroundTexture = getTexture(LOADER_BACKGROUND);
backgroundTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
}
@Override
public void draw(Batch batch, float parentAlpha) {
batch.disableBlending();
batch.draw(backgroundTexture, 0, 0, getWidth(), getHeight());
batch.enableBlending();
}
}
public LoaderScreen() { public LoaderScreen() {
super(false, false, TablexiaAssetManager.StorageType.INTERNAL); super(false, false, TablexiaAssetManager.StorageType.INTERNAL);
...@@ -41,17 +21,29 @@ public class LoaderScreen extends AbstractTablexiaScreen<Void> { ...@@ -41,17 +21,29 @@ public class LoaderScreen extends AbstractTablexiaScreen<Void> {
@Override @Override
protected void prepareScreenTextureAssetNames(List<String> textureFileNames) { protected void prepareScreenTextureAssetNames(List<String> textureFileNames) {
textureFileNames.add(LOADER_BACKGROUND); textureFileNames.add(LOADER_BACKGROUND);
textureFileNames.add(LOADER_SMALL_HAND);
textureFileNames.add(LOADER_BIG_HAND);
} }
@Override @Override
protected void screenLoaded() { protected void screenLoaded() {
background = new LoaderBackground(); Image background = new Image(getTexture(LOADER_BACKGROUND));
background.setPosition(0, 0);
background.setSize(getStage().getWidth(), getStage().getHeight()); background.setSize(getStage().getWidth(), getStage().getHeight());
getStage().addActor(background); getStage().addActor(background);
}
@Override Image smallhand = new Image(getTexture(LOADER_SMALL_HAND));
public void screenResized(int width, int height) { smallhand.setPosition(getStage().getWidth()*0.22f, getStage().getHeight() * 0.64f);
background.setSize(width, height); smallhand.setSize(getStage().getWidth()*0.01f, getStage().getHeight()*0.06f);
getStage().addActor(smallhand);
smallhand.setOrigin(smallhand.getWidth()/2,0);
smallhand.addAction(Actions.forever(Actions.rotateBy(-360, 6)));
Image bighand = new Image(getTexture(LOADER_BIG_HAND));
bighand.setPosition(getStage().getWidth()*0.22f, getStage().getHeight() * 0.64f);
bighand.setSize(getStage().getWidth()*0.01f, getStage().getHeight()*0.06f);
getStage().addActor(bighand);
bighand.setOrigin(bighand.getWidth()/2,0);
bighand.addAction(Actions.forever(Actions.rotateBy(-360, 0.5f)));
} }
} }
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