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

#7 Submenus in main menu

parent f3247f23
......@@ -4,3 +4,5 @@ mainmenu_statistics=Statistiky
mainmenu_encyclopedia=Encyklopedie
mainmenu_about=O aplikaci
mainmenu_logout=Odhlásit
game_robbery_title=Lupiči
......@@ -93,6 +93,7 @@ public class Tablexia extends TablexiaApplication {
public void dispose() {
ApplicationTextureManager.getInstance().dispose();
ApplicationFontManager.getInstance().dispose();
ApplicationTextManager.getInstance().dispose();
}
......
package cz.nic.tablexia.game;
import cz.nic.tablexia.Tablexia.ChangeScreenEvent;
import cz.nic.tablexia.TablexiaApplication.ScreenTransaction;
import cz.nic.tablexia.bus.ApplicationBus;
import cz.nic.tablexia.bus.ApplicationBus.ApplicationEvent;
import cz.nic.tablexia.game.games.robbery.RuleScreen;
import cz.nic.tablexia.loader.ApplicationTextManager;
import cz.nic.tablexia.menu.IMenuItem;
import cz.nic.tablexia.screen.AbstractTablexiaScreen;
public enum GameDefinition implements ApplicationEvent, IMenuItem {
ROBBERY ("game_robbery_title", RuleScreen.class);
private String menuTextKey;
private Class<? extends AbstractTablexiaScreen> screenClass;
private GameDefinition(String nameResource, Class<? extends AbstractTablexiaScreen> screenClass) {
this.menuTextKey = nameResource;
this.screenClass = screenClass;
}
@Override
public String getTitle() {
return ApplicationTextManager.getInstance().getResult().get(menuTextKey);
}
@Override
public void performAction() {
ApplicationBus.getInstance().publishAsync(this);
ApplicationBus.getInstance().publishAsync(new ChangeScreenEvent(screenClass, ScreenTransaction.FADE));
}
}
......@@ -36,8 +36,8 @@ public class MPantsAttribute extends BottomAttribute {
add(new AttributeDescription(AttributeColor.BROWN, AttributeGender.MALE, RobberyTextureManager.ATTRIBUTE_M_PANTS_BROWN, MPantsAttribute.class));
add(new AttributeDescription(AttributeColor.GREEN, AttributeGender.MALE, RobberyTextureManager.ATTRIBUTE_M_PANTS_GREEN, MPantsAttribute.class));
add(new AttributeDescription(AttributeColor.GREY, AttributeGender.MALE, RobberyTextureManager.ATTRIBUTE_M_PANTS_GREY, MPantsAttribute.class));
add(new AttributeDescription(AttributeColor.RED, AttributeGender.MALE, RobberyTextureManager.ATTRIBUTE_M_PANTS_RED, MPantsAttribute.class));
add(new AttributeDescription(AttributeColor.YELLOW, AttributeGender.MALE, RobberyTextureManager.ATTRIBUTE_M_PANTS_YELLOW, MPantsAttribute.class));
add(new AttributeDescription(AttributeColor.RED, AttributeGender.MALE, RobberyTextureManager.ATTRIBUTE_M_PANTS_RED, MPantsAttribute.class));
add(new AttributeDescription(AttributeColor.YELLOW, AttributeGender.MALE, RobberyTextureManager.ATTRIBUTE_M_PANTS_YELLOW, MPantsAttribute.class));
}
};
......
......@@ -20,8 +20,8 @@ public class RobberyTextureManager extends AssetManager implements IApplicationL
@Override
public synchronized void dispose() {
super.dispose();
instance = null;
// super.dispose();
// instance = null;
}
public static final String GAME_ROBBERY_GFX_PATH = "game/robbery/gfx/";
......
package cz.nic.tablexia.menu;
public interface IMenuItem {
public String getTitle();
public void performAction();
}
......@@ -49,19 +49,29 @@ public class MainMenu extends Container<Table> {
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();
for (final MainMenuDefinition menuItem : MainMenuDefinition.values()) {
addMenuItem(menuItem);
IMenuItem[] subMenu = menuItem.getSubmenu();
if (subMenu != null) {
for (IMenuItem submenuItem : subMenu) {
addMenuItem(submenuItem);
}
});
menuTableLayout.add(menuButton).expandX();
menuTableLayout.row();
}
}
}
private void addMenuItem(final IMenuItem menuItem) {
TextButton subMenuButton = new TextButton(menuItem.getTitle(), menuButtonStyle);
subMenuButton.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
menuItem.performAction();
}
});
menuTableLayout.add(subMenuButton).expandX();
menuTableLayout.row();
}
}
......@@ -2,30 +2,38 @@ package cz.nic.tablexia.menu;
import cz.nic.tablexia.bus.ApplicationBus;
import cz.nic.tablexia.bus.ApplicationBus.ApplicationEvent;
import cz.nic.tablexia.game.GameDefinition;
import cz.nic.tablexia.loader.ApplicationTextManager;
public enum MainMenuDefinition implements ApplicationEvent {
public enum MainMenuDefinition implements ApplicationEvent, IMenuItem {
GAMES ("mainmenu_games"),
HALL_OF_FAME ("mainmenu_halloffame"),
STATISTICS ("mainmenu_statistics"),
ENCYCLOPEDIA ("mainmenu_encyclopedia"),
ABOUT_APPLICATION ("mainmenu_about"),
LOGOUT ("mainmenu_logout");
GAMES ("mainmenu_games", GameDefinition.values()),
HALL_OF_FAME ("mainmenu_halloffame", null),
STATISTICS ("mainmenu_statistics", null),
ENCYCLOPEDIA ("mainmenu_encyclopedia", null),
ABOUT_APPLICATION ("mainmenu_about", null),
LOGOUT ("mainmenu_logout", null);
private String menuTextKey;
private IMenuItem[] submenu;
private MainMenuDefinition(String nameResource) {
private MainMenuDefinition(String nameResource, IMenuItem[] submenu) {
this.menuTextKey = nameResource;
this.submenu = submenu;
}
public String getMenuTitle() {
@Override
public String getTitle() {
return ApplicationTextManager.getInstance().getResult().get(menuTextKey);
}
}
public void performMenuAction() {
@Override
public void performAction() {
ApplicationBus.getInstance().publishAsync(this);
}
public IMenuItem[] getSubmenu() {
return submenu;
}
}
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