Commit f3247f23 authored by Matyáš Latner's avatar Matyáš Latner

#7 Basic main menu implementation

 * application text loader
 * menu events
 * screen mocks
parent d642cd29
mainmenu_games=Hry
mainmenu_halloffame=Síň slávy
mainmenu_statistics=Statistiky
mainmenu_encyclopedia=Encyklopedie
mainmenu_about=O aplikaci
mainmenu_logout=Odhlásit
......@@ -19,6 +19,7 @@ allprojects {
appName = 'Tablexia-libGDX'
gdxVersion = '1.5.2'
gdxUtilsVersion = '0.9.1'
mbassadorVersion = '1.2.0'
roboVMVersion = '1.0.0-beta-01'
box2DLightsVersion = '1.3'
ashleyVersion = '1.3.1'
......@@ -42,6 +43,7 @@ project(":desktop") {
compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
compile "com.badlogicgames.gdx:gdx-tools:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop"
compile "net.engio:mbassador:$mbassadorVersion"
}
}
......@@ -54,6 +56,7 @@ project(":android") {
compile project(":core")
compile "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
compile "net.engio:mbassador:$mbassadorVersion"
natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi"
natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi-v7a"
natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86"
......@@ -73,6 +76,7 @@ project(":ios") {
compile project(":core")
compile "org.robovm:robovm-rt:${roboVMVersion}"
compile "org.robovm:robovm-cocoatouch:${roboVMVersion}"
compile "net.engio:mbassador:$mbassadorVersion"
compile "com.badlogicgames.gdx:gdx-backend-robovm:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-ios"
......@@ -87,6 +91,7 @@ project(":html") {
dependencies {
compile project(":core")
compile "net.engio:mbassador:$mbassadorVersion"
compile "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion"
compile "com.badlogicgames.gdx:gdx:$gdxVersion:sources"
compile "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion:sources"
......@@ -102,7 +107,7 @@ project(":core") {
dependencies {
compile "com.badlogicgames.gdx:gdx:$gdxVersion"
compile "net.dermetfan.libgdx-utils:libgdx-utils:$gdxUtilsVersion"
compile 'net.engio:mbassador:1.2.0'
compile "net.engio:mbassador:$mbassadorVersion"
compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
testCompile "junit:junit:4.11"
......
package cz.nic.tablexia;
import java.util.Locale;
import net.engio.mbassy.listener.Handler;
import com.badlogic.gdx.Gdx;
......@@ -11,10 +13,13 @@ import com.badlogic.gdx.utils.reflect.ReflectionException;
import cz.nic.tablexia.bus.ApplicationBus;
import cz.nic.tablexia.bus.ApplicationBus.ApplicationEvent;
import cz.nic.tablexia.loader.ApplicationFontManager;
import cz.nic.tablexia.loader.ApplicationTextManager;
import cz.nic.tablexia.loader.ApplicationTextureManager;
import cz.nic.tablexia.menu.MainMenu;
import cz.nic.tablexia.screen.AbstractTablexiaScreen;
import cz.nic.tablexia.screen.GameMenuScreen;
import cz.nic.tablexia.screen.LoaderScreen;
import cz.nic.tablexia.screen.ScreenDefinition;
import cz.nic.tablexia.screen.gamemenu.GameMenuScreen;
import cz.nic.tablexia.util.Log;
import cz.nic.tablexia.util.Log.TablexiaLogLevel;
......@@ -36,6 +41,12 @@ public class Tablexia extends TablexiaApplication {
}
}
private void prepareMainMenu() {
MainMenu menu = new MainMenu(getStage().getWidth() / 4, getStage().getHeight());
menu.initMenuItems();
getStage().addActor(menu);
}
//////////////////////////// LIBGDX LIFECYCLE
......@@ -44,8 +55,11 @@ public class Tablexia extends TablexiaApplication {
super.create();
Log.setLoglevel(TablexiaLogLevel.DEBUG);
// register event bus handler
Gdx.input.setInputProcessor(getStage());
// init event bus handlers
ApplicationBus.getInstance().subscribe(this);
ScreenDefinition.initBus();
// sync loading of first application image (loader background)
AssetManager loaderGraphicManager = new AssetManager();
......@@ -56,6 +70,7 @@ public class Tablexia extends TablexiaApplication {
// async loading of remaining application assets
ApplicationTextureManager.getInstance().load();
ApplicationFontManager.getInstance().load();
ApplicationTextManager.getInstance().load(new Locale("cs", "CZ"));
}
@Override
......@@ -67,7 +82,9 @@ public class Tablexia extends TablexiaApplication {
if (!loadingComplete) {
if (!ApplicationTextureManager.getInstance().update()) return;
if (!ApplicationFontManager.getInstance().update()) return;
if (!ApplicationTextManager.getInstance().update()) return;
prepareMainMenu();
loadingComplete();
}
}
......
......@@ -35,11 +35,16 @@ public abstract class TablexiaApplication implements ApplicationListener {
private AbstractTablexiaScreen screen;
private Stage stage;
public Stage getStage() {
return stage;
}
//////////////////////////// LIBGDX LIFECYCLE
@Override
public void dispose () {
stage.dispose();
if (lastScreen != null) lastScreen.hide();
if (screen != null) screen.hide();
}
......@@ -135,7 +140,7 @@ public abstract class TablexiaApplication implements ApplicationListener {
screen = newScreen;
screenTransaction.processTransaction(stage, lastScreen, newScreen,
new Runnable() {
new Runnable() {
@Override
public void run() {
......@@ -171,6 +176,7 @@ public abstract class TablexiaApplication implements ApplicationListener {
private void processLastScreen(Screen lastScreen) {
if (lastScreen != null) {
lastScreen.hide();
lastScreen.dispose();
lastScreen = null;
}
}
......
package cz.nic.tablexia;
public class TablexiaSettings {
private static final boolean DEBUG = true;
private static final boolean DEBUG_SHOW_BOUNDING_BOXES = true;
public static boolean isDebug() {
return DEBUG;
}
public static boolean isShowBoudingBoxes() {
return DEBUG && DEBUG_SHOW_BOUNDING_BOXES;
}
}
package cz.nic.tablexia.graphics;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Pixmap.Format;
import com.badlogic.gdx.graphics.Texture;
/**
* Texture filled with color.
*
* @author Matyáš Latner
*
*/
public class ColorTexture extends Texture {
public ColorTexture(int width, int height, final Color color) {
super(new Pixmap(width, height, Format.RGB565) {
@Override
public void setColor (float r, float g, float b, float a) {
super.setColor(color);
}
});
}
}
......@@ -9,14 +9,19 @@ import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGeneratorLoader;
import com.badlogic.gdx.graphics.g2d.freetype.FreetypeFontLoader;
import com.badlogic.gdx.graphics.g2d.freetype.FreetypeFontLoader.FreeTypeFontLoaderParameter;
/**
* Font loader and manager class for application context
*
* @author Matyáš Latner
*
*/
public class ApplicationFontManager extends AssetManager implements IApplicationLoader {
public static final String APPLICATION_FONT_PATH = "application/font/";
public static final String FONT_ROBOTO_REGULAR = APPLICATION_FONT_PATH + "Roboto-Regular.ttf";
public static final String FONT_ROBOTO_BOLD = APPLICATION_FONT_PATH + "Roboto-Bold.ttf";
public static final String CZECH_CHARACTERS = "ěřťůšďžčň";
public static final int FONT_SIZE = 20;
private static final int FONT_SIZE = 20;
private static final String CZECH_CHARACTERS = "ěřťůšďžčň";
private static final String APPLICATION_FONT_PATH = "application/font/";
public static final String FONT_ROBOTO_REGULAR = APPLICATION_FONT_PATH + "Roboto-Regular.ttf";
public static final String FONT_ROBOTO_BOLD = APPLICATION_FONT_PATH + "Roboto-Bold.ttf";
private static ApplicationFontManager instance;
......
package cz.nic.tablexia.loader;
import java.util.Locale;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.utils.I18NBundle;
import com.badlogic.gdx.utils.async.AsyncTask;
import cz.nic.tablexia.game.loader.AbstractDataManager;
import cz.nic.tablexia.loader.IApplicationLoader;
/**
* Texture loader and manager for application context.
*
* @author Matyáš Latner
*
*/
public class ApplicationTextManager extends AbstractDataManager<I18NBundle> implements IApplicationLoader {
private static final String ROBBERY_TEXT = "application/text/application";
private static class RobberyTextLoader implements AsyncTask<I18NBundle> {
private String textResourceFileName;
private Locale locale;
public RobberyTextLoader(String textResourceFileName, Locale locale) {
this.textResourceFileName = textResourceFileName;
this.locale = locale;
}
@Override
public I18NBundle call() throws Exception {
FileHandle baseFileHandle = Gdx.files.internal(textResourceFileName);
return I18NBundle.createBundle(baseFileHandle, locale);
}
}
private static ApplicationTextManager instance;
private ApplicationTextManager() {}
public static ApplicationTextManager getInstance() {
if (instance == null) {
instance = new ApplicationTextManager();
}
return instance;
}
public void load(Locale locale) {
setAsyncTask(new RobberyTextLoader(ROBBERY_TEXT, locale));
}
public void dispose() {
instance = null;
}
}
\ No newline at end of file
package cz.nic.tablexia.menu;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.ui.Container;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle;
import com.badlogic.gdx.scenes.scene2d.utils.Align;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import cz.nic.tablexia.TablexiaSettings;
import cz.nic.tablexia.graphics.ColorTexture;
import cz.nic.tablexia.loader.ApplicationFontManager;
/**
* MainMenu container
*
* @author Matyáš Latner
*
*/
public class MainMenu extends Container<Table> {
private static final Color MENU_BACKGROUND_COLOR = Color.valueOf("f2deb7");
private static final Color MENU_TEXT_COLOR = Color.BLACK;
private Table menuTableLayout;
private TextButtonStyle menuButtonStyle;
public MainMenu(float width, float height) {
setBounds(0, 0, width, height);
setDebug(TablexiaSettings.isShowBoudingBoxes());
align(Align.bottomLeft);
setBackground(new TextureRegionDrawable(new TextureRegion(new ColorTexture(1, 1, MENU_BACKGROUND_COLOR))));
menuTableLayout = new Table();
menuTableLayout.setFillParent(true);
setActor(menuTableLayout);
menuButtonStyle = new TextButtonStyle();
menuButtonStyle.font = ApplicationFontManager.getInstance().<BitmapFont>get(ApplicationFontManager.FONT_ROBOTO_REGULAR);
menuButtonStyle.fontColor = MENU_TEXT_COLOR;
menuButtonStyle.up = new TextureRegionDrawable(new TextureRegion(new ColorTexture(50, 50, Color.BLUE)));
}
public void initMenuItems() {
menuTableLayout.reset();
menuTableLayout.setDebug(TablexiaSettings.isShowBoudingBoxes());
for (final MainMenuDefinition mainMenuDefinition : MainMenuDefinition.values()) {
TextButton menuButton = new TextButton(mainMenuDefinition.getMenuTitle(), menuButtonStyle);
menuButton.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
mainMenuDefinition.performMenuAction();
}
});
menuTableLayout.add(menuButton).expandX();
menuTableLayout.row();
}
}
}
package cz.nic.tablexia.menu;
import cz.nic.tablexia.bus.ApplicationBus;
import cz.nic.tablexia.bus.ApplicationBus.ApplicationEvent;
import cz.nic.tablexia.loader.ApplicationTextManager;
public enum MainMenuDefinition implements ApplicationEvent {
GAMES ("mainmenu_games"),
HALL_OF_FAME ("mainmenu_halloffame"),
STATISTICS ("mainmenu_statistics"),
ENCYCLOPEDIA ("mainmenu_encyclopedia"),
ABOUT_APPLICATION ("mainmenu_about"),
LOGOUT ("mainmenu_logout");
private String menuTextKey;
private MainMenuDefinition(String nameResource) {
this.menuTextKey = nameResource;
}
public String getMenuTitle() {
return ApplicationTextManager.getInstance().getResult().get(menuTextKey);
}
public void performMenuAction() {
ApplicationBus.getInstance().publishAsync(this);
}
}
......@@ -47,7 +47,7 @@ public abstract class AbstractTablexiaScreen extends ScreenAdapter {
@Override
public void dispose() {
stage = null;
stage.dispose();
}
}
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.statistics.StatisticsScreen;
public enum ScreenDefinition {
GAME_MENU (GameMenuScreen.class, null),
HALL_OF_FAME (HallOfFameScreen.class, MainMenuDefinition.HALL_OF_FAME),
STATISTICS (StatisticsScreen.class, MainMenuDefinition.STATISTICS),
ENCYCLOPEDIA (EncyclopediaScreen.class, MainMenuDefinition.ENCYCLOPEDIA),
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 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);
}
}
package cz.nic.tablexia.screen.about;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import cz.nic.tablexia.loader.ApplicationFontManager;
import cz.nic.tablexia.screen.AbstractTablexiaScreen;
public class AboutScreen extends AbstractTablexiaScreen {
@Override
public void show() {
super.show();
Label label = new Label(getClass().getSimpleName(), new LabelStyle(ApplicationFontManager.getInstance().get(ApplicationFontManager.FONT_ROBOTO_REGULAR, BitmapFont.class), Color.WHITE));
Table table = new Table();
table.add(label);
label.setPosition(getStage().getWidth() / 2, getStage().getHeight() / 2);
getStage().addActor(label);
}
}
package cz.nic.tablexia.screen.encyclopedia;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import cz.nic.tablexia.loader.ApplicationFontManager;
import cz.nic.tablexia.screen.AbstractTablexiaScreen;
public class EncyclopediaScreen extends AbstractTablexiaScreen {
@Override
public void show() {
super.show();
Label label = new Label(getClass().getSimpleName(), new LabelStyle(ApplicationFontManager.getInstance().get(ApplicationFontManager.FONT_ROBOTO_REGULAR, BitmapFont.class), Color.WHITE));
Table table = new Table();
table.add(label);
label.setPosition(getStage().getWidth() / 2, getStage().getHeight() / 2);
getStage().addActor(label);
}
}
package cz.nic.tablexia.screen;
package cz.nic.tablexia.screen.gamemenu;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.graphics.g2d.Batch;
......@@ -8,11 +7,8 @@ import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener;
import cz.nic.tablexia.Tablexia.ChangeScreenEvent;
import cz.nic.tablexia.TablexiaApplication.ScreenTransaction;
import cz.nic.tablexia.bus.ApplicationBus;
import cz.nic.tablexia.game.games.robbery.RuleScreen;
import cz.nic.tablexia.loader.ApplicationTextureManager;
import cz.nic.tablexia.screen.AbstractTablexiaScreen;
public class GameMenuScreen extends AbstractTablexiaScreen {
......@@ -39,14 +35,14 @@ public class GameMenuScreen extends AbstractTablexiaScreen {
@Override
public void show() {
super.show();
Gdx.input.setInputProcessor(getStage());
// Gdx.input.setInputProcessor(getStage());
background = new GameMenuBackground();
background.addListener(new InputListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
ApplicationBus.getInstance().publishAsync(new ChangeScreenEvent(RuleScreen.class, ScreenTransaction.FADE));
// ApplicationBus.getInstance().publishAsync(new ChangeScreenEvent(RuleScreen.class, ScreenTransaction.FADE));
return super.touchDown(event, x, y, pointer, button);
}
......
package cz.nic.tablexia.screen.halloffame;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import cz.nic.tablexia.loader.ApplicationFontManager;
import cz.nic.tablexia.screen.AbstractTablexiaScreen;
public class HallOfFameScreen extends AbstractTablexiaScreen {
@Override
public void show() {
super.show();
Label label = new Label(getClass().getSimpleName(), new LabelStyle(ApplicationFontManager.getInstance().get(ApplicationFontManager.FONT_ROBOTO_REGULAR, BitmapFont.class), Color.WHITE));
Table table = new Table();
table.add(label);
label.setPosition(getStage().getWidth() / 2, getStage().getHeight() / 2);
getStage().addActor(label);
}
}
package cz.nic.tablexia.screen.statistics;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import cz.nic.tablexia.loader.ApplicationFontManager;
import cz.nic.tablexia.screen.AbstractTablexiaScreen;
public class StatisticsScreen extends AbstractTablexiaScreen {
@Override
public void show() {
super.show();
Label label = new Label(getClass().getSimpleName(), new LabelStyle(ApplicationFontManager.getInstance().get(ApplicationFontManager.FONT_ROBOTO_REGULAR, BitmapFont.class), Color.WHITE));
Table table = new Table();
table.add(label);
label.setPosition(getStage().getWidth() / 2, getStage().getHeight() / 2);
getStage().addActor(label);
}
}
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