Commit 844c2dab authored by Matyáš Latner's avatar Matyáš Latner

#7 New user button with transaction to PanoramaScreen

parent c9c0b75f
......@@ -18,6 +18,8 @@ mainmenu_logout=Odhlásit
mainmenu_screendebug=Debug Screen
mainmenu_panorama=Panorama
usermenu_newuser=+ Nový detektiv
gamedifficulty_easy=Lehká
gamedifficulty_medium=Střední
gamedifficulty_hard=Těžká
......
......@@ -18,6 +18,8 @@ mainmenu_logout=Abmelden
mainmenu_screendebug=Debug Screen
mainmenu_panorama=Panorama
usermenu_newuser=+ Neuer Detektiv
gamedifficulty_easy=Leicht
gamedifficulty_medium=Mittel
gamedifficulty_hard=Schwierig
......
......@@ -18,6 +18,8 @@ mainmenu_logout=Odhlásiť
mainmenu_screendebug=Debug Screen
mainmenu_panorama=Panorama
usermenu_newuser=+ Nový detektív
gamedifficulty_easy=Ľahká
gamedifficulty_medium=Stredná
gamedifficulty_hard=Ťažká
......
......@@ -264,6 +264,7 @@ public abstract class TablexiaApplication implements ApplicationListener {
MOVE_RIGHT(new MoveRightAnimation()),
MOVE_LEFT(new MoveLeftAnimation()),
MOVE_UP(new MoveUpAnimation()),
FADE(new FadeAnimation());
private interface ScreenTransactionImplementation {
......@@ -283,9 +284,13 @@ public abstract class TablexiaApplication implements ApplicationListener {
private static class MoveRightAnimation implements cz.nic.tablexia.TablexiaApplication.ScreenTransaction.ScreenTransactionImplementation {
protected float newScreenMoveFrom = -Gdx.graphics.getWidth();
protected float newScreenMoveTo = 0;
protected float lastScreenMoveTo = Gdx.graphics.getWidth();
protected float newScreenMoveFromX = -Gdx.graphics.getWidth();
protected float newScreenMoveToX = 0;
protected float lastScreenMoveToX = Gdx.graphics.getWidth();
protected float newScreenMoveFromY = 0;
protected float newScreenMoveToY = 0;
protected float lastScreenMoveToY = 0;
@Override
public void processTransaction(Stage stage, final AbstractTablexiaScreen<?> lastScreen, final AbstractTablexiaScreen<?> newScreen, Runnable newScreenHandler, final Runnable lastScreenHandler, final Runnable finishHandler) {
......@@ -296,11 +301,11 @@ public abstract class TablexiaApplication implements ApplicationListener {
public void loadingComplete() {
newScreen.resetLoadingListener();
if (lastScreen != null) {
lastScreen.addAction(sequence(moveTo(lastScreenMoveTo, 0, transactionSpeed, Interpolation.pow4Out), run(lastScreenHandler)));
lastScreen.addAction(sequence(moveTo(lastScreenMoveToX, lastScreenMoveToY, transactionSpeed, Interpolation.pow4Out), run(lastScreenHandler)));
}
if (newScreen != null) {
newScreen.setPosition(newScreenMoveFrom, 0);
newScreen.addAction(sequence(moveTo(newScreenMoveTo, 0, transactionSpeed, Interpolation.pow4Out), run(finishHandler)));
newScreen.setPosition(newScreenMoveFromX, newScreenMoveFromY);
newScreen.addAction(sequence(moveTo(newScreenMoveToX, newScreenMoveToY, transactionSpeed, Interpolation.pow4Out), run(finishHandler)));
}
}
});
......@@ -312,9 +317,25 @@ public abstract class TablexiaApplication implements ApplicationListener {
@Override
public void processTransaction(Stage stage, final AbstractTablexiaScreen<?> lastScreen, AbstractTablexiaScreen<?> newScreen, Runnable newScreenHandler, final Runnable lastScreenHandler, final Runnable finishHandler) {
newScreenMoveFrom = Gdx.graphics.getWidth();
newScreenMoveTo = 0;
lastScreenMoveTo = -Gdx.graphics.getWidth();
newScreenMoveFromX = Gdx.graphics.getWidth();
newScreenMoveToX = 0;
lastScreenMoveToX = -Gdx.graphics.getWidth();
super.processTransaction(stage, lastScreen, newScreen, newScreenHandler, lastScreenHandler, finishHandler);
}
}
private static class MoveUpAnimation extends MoveRightAnimation {
@Override
public void processTransaction(Stage stage, final AbstractTablexiaScreen<?> lastScreen, AbstractTablexiaScreen<?> newScreen, Runnable newScreenHandler, final Runnable lastScreenHandler, final Runnable finishHandler) {
newScreenMoveFromX = 0;
newScreenMoveToX = 0;
lastScreenMoveToX = 0;
newScreenMoveFromY = -Gdx.graphics.getHeight();
newScreenMoveToY = 0;
lastScreenMoveToY = Gdx.graphics.getHeight();
super.processTransaction(stage, lastScreen, newScreen, newScreenHandler, lastScreenHandler, finishHandler);
}
}
......
......@@ -11,31 +11,30 @@ import cz.nic.tablexia.game.games.pursuit.PursuitGame;
import cz.nic.tablexia.game.games.robbery.RobberyGame;
import cz.nic.tablexia.game.games.shooting_range.ShootingRangeGame;
import cz.nic.tablexia.loader.application.ApplicationTextManager;
import cz.nic.tablexia.menu.AbstractMenu;
import cz.nic.tablexia.menu.IMenuItem;
public enum GameDefinition implements ApplicationEvent, IMenuItem {
ROBBERY ("game_robbery_title", RobberyGame.class, true),
PURSUIT ("game_pursuit_title", PursuitGame.class, true),
KIDNAPPING ("game_kidnapping_title", KidnappingGame.class, true),
NIGHT_WATCH ("game_night_watch_title", NightWatchGame.class, true),
SHOOTING_RANGE ("game_shooting_range_title", ShootingRangeGame.class, true),
IN_THE_DARKNESS ("game_in_the_darkness_title", InTheDarknessGame.class, true);
ROBBERY ("game_robbery_title", RobberyGame.class),
PURSUIT ("game_pursuit_title", PursuitGame.class),
KIDNAPPING ("game_kidnapping_title", KidnappingGame.class),
NIGHT_WATCH ("game_night_watch_title", NightWatchGame.class),
SHOOTING_RANGE ("game_shooting_range_title", ShootingRangeGame.class),
IN_THE_DARKNESS ("game_in_the_darkness_title", InTheDarknessGame.class);
private String menuTextKey;
private Class<? extends AbstractTablexiaGame<?>> screenClass;
private boolean isCloseMenu;
public static GameDefinition[] getActiveGames(){
return new GameDefinition[]{ROBBERY, PURSUIT, KIDNAPPING, NIGHT_WATCH, SHOOTING_RANGE, IN_THE_DARKNESS};
}
GameDefinition(String nameResource, Class<? extends AbstractTablexiaGame<?>> screenClass, boolean isCloseMenu) {
GameDefinition(String nameResource, Class<? extends AbstractTablexiaGame<?>> screenClass) {
this.menuTextKey = nameResource;
this.screenClass = screenClass;
this.isCloseMenu = isCloseMenu;
}
@Override
......@@ -50,8 +49,8 @@ public enum GameDefinition implements ApplicationEvent, IMenuItem {
}
@Override
public boolean isCloseMenu() {
return isCloseMenu;
public AbstractMenu.MenuAction getMenuAction() {
return AbstractMenu.MenuAction.CLOSE;
}
@Override
......
......@@ -21,6 +21,7 @@ public class ApplicationTextManager extends TablexiaDataManager<I18NBundle> impl
public static final class ApplicationTextsAssets {
public static final String VICTORYSCREEN_BUTTON_REPLAY = "victoryscreen_button_replay";
public static final String VICTORYSCREEN_BUTTON_CHANGEGAME = "victoryscreen_button_changegame";
public static final String USERMENU_NEWUSER = "usermenu_newuser";
}
private static final String APPLICATION_TEXT_RESOURCE_FILE = "text/application/application";
......
......@@ -217,9 +217,7 @@ public abstract class AbstractMenu extends Stack {
@Override
public void clicked(InputEvent event, float x, float y) {
if (menuItem.isCloseMenu()) {
closeMenu(true, false);
}
doMenuAction(menuItem.getMenuAction(), true, true);
performMenuAction(menuItem);
}
......@@ -354,7 +352,9 @@ public abstract class AbstractMenu extends Stack {
}
void doMenuAction(MenuAction menuAction, boolean animated, boolean force) {
menuAction.doAction(this, animated, force);
if (menuAction != null) {
menuAction.doAction(this, animated, force);
}
}
......
......@@ -4,7 +4,7 @@ public interface IMenuItem {
String getTitle();
void performAction();
boolean isCloseMenu();
AbstractMenu.MenuAction getMenuAction();
IMenuItem[] getSubmenu();
}
......@@ -156,10 +156,8 @@ public class MenuController extends Group implements Disposable {
@Handler
public void handleSelectedUserEvent(SelectedUserEvent selectedUserEvent) {
if (selectedUserEvent.isUserSelected()) {
doMenuAction(UserMenu.class, AbstractMenu.MenuAction.HIDE, true, true);
showMainMenuOnNextScreen();
} else {
doMenuAction(MainMenu.class, AbstractMenu.MenuAction.HIDE, true, true);
openUserMenuOnNextScreen();
}
}
......
......@@ -10,6 +10,7 @@ import cz.nic.tablexia.bus.ApplicationBus;
import cz.nic.tablexia.bus.ApplicationBus.ApplicationEvent;
import cz.nic.tablexia.game.GameDefinition;
import cz.nic.tablexia.loader.application.ApplicationTextManager;
import cz.nic.tablexia.menu.AbstractMenu;
import cz.nic.tablexia.menu.IMenuItem;
import cz.nic.tablexia.screen.about.AboutScreen;
import cz.nic.tablexia.screen.encyclopedia.EncyclopediaScreen;
......@@ -21,32 +22,32 @@ import cz.nic.tablexia.screen.viewport.ViewportDebugScreen;
public enum MainMenuDefinition implements IMenuItem {
GAMES (false, "mainmenu_games", GameDefinition.values(), false, null), // TODO open menu event
HALL_OF_FAME (false, "mainmenu_halloffame", null, true, new Tablexia.ChangeScreenEvent(HallOfFameScreen.class, TablexiaApplication.ScreenTransaction.FADE)),
STATISTICS (false, "mainmenu_statistics", null, true, new Tablexia.ChangeScreenEvent(StatisticsScreen.class, TablexiaApplication.ScreenTransaction.FADE)),
ENCYCLOPEDIA (false, "mainmenu_encyclopedia", null, true, new Tablexia.ChangeScreenEvent(EncyclopediaScreen.class, TablexiaApplication.ScreenTransaction.FADE)),
PREFERENCES (false, "mainmenu_preferences", null, true, new Tablexia.ChangeScreenEvent(PreferencesScreen.class, TablexiaApplication.ScreenTransaction.FADE)),
ABOUT_APPLICATION (false, "mainmenu_about", null, true, new Tablexia.ChangeScreenEvent(AboutScreen.class, TablexiaApplication.ScreenTransaction.FADE)),
LOGOUT (false, "mainmenu_logout", null, true, null) {
GAMES (false, "mainmenu_games", GameDefinition.values(), null, null), // TODO open menu event
HALL_OF_FAME (false, "mainmenu_halloffame", null, AbstractMenu.MenuAction.CLOSE, new Tablexia.ChangeScreenEvent(HallOfFameScreen.class, TablexiaApplication.ScreenTransaction.FADE)),
STATISTICS (false, "mainmenu_statistics", null, AbstractMenu.MenuAction.CLOSE, new Tablexia.ChangeScreenEvent(StatisticsScreen.class, TablexiaApplication.ScreenTransaction.FADE)),
ENCYCLOPEDIA (false, "mainmenu_encyclopedia", null, AbstractMenu.MenuAction.CLOSE, new Tablexia.ChangeScreenEvent(EncyclopediaScreen.class, TablexiaApplication.ScreenTransaction.FADE)),
PREFERENCES (false, "mainmenu_preferences", null, AbstractMenu.MenuAction.CLOSE, new Tablexia.ChangeScreenEvent(PreferencesScreen.class, TablexiaApplication.ScreenTransaction.FADE)),
ABOUT_APPLICATION (false, "mainmenu_about", null, AbstractMenu.MenuAction.CLOSE, new Tablexia.ChangeScreenEvent(AboutScreen.class, TablexiaApplication.ScreenTransaction.FADE)),
LOGOUT (false, "mainmenu_logout", null, AbstractMenu.MenuAction.HIDE, null) {
@Override
public void performAction() {
TablexiaSettings.getInstance().setSelectedUser(null);
}
},
SCREEN_DEBUG (true, "mainmenu_screendebug", null, true, new Tablexia.ChangeScreenEvent(ViewportDebugScreen.class, TablexiaApplication.ScreenTransaction.FADE));
SCREEN_DEBUG (true, "mainmenu_screendebug", null, AbstractMenu.MenuAction.CLOSE, new Tablexia.ChangeScreenEvent(ViewportDebugScreen.class, TablexiaApplication.ScreenTransaction.FADE));
private boolean debug;
private String menuTextKey;
private IMenuItem[] submenu;
private boolean isCloseMenu;
private AbstractMenu.MenuAction menuAction;
private ApplicationEvent action;
MainMenuDefinition(boolean debug, String nameResource, IMenuItem[] submenu, boolean isCloseMenu, ApplicationEvent action) {
MainMenuDefinition(boolean debug, String nameResource, IMenuItem[] submenu, AbstractMenu.MenuAction menuAction, ApplicationEvent action) {
this.debug = debug;
this.menuTextKey = nameResource;
this.submenu = submenu;
this.isCloseMenu = isCloseMenu;
this.menuAction = menuAction;
this.action = action;
}
......@@ -69,8 +70,8 @@ public enum MainMenuDefinition implements IMenuItem {
}
@Override
public boolean isCloseMenu() {
return isCloseMenu;
public AbstractMenu.MenuAction getMenuAction() {
return menuAction;
}
public static List<IMenuItem> getItemsForMenu() {
......
package cz.nic.tablexia.menu.user;
import java.util.ArrayList;
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.application.ApplicationTextManager;
import cz.nic.tablexia.menu.AbstractMenu;
import cz.nic.tablexia.menu.IMenuItem;
import cz.nic.tablexia.model.User;
import cz.nic.tablexia.screen.createuser.PanoramaScreen;
/**
* UserMenu container
......@@ -13,6 +19,19 @@ import cz.nic.tablexia.model.User;
*/
public class UserMenu extends AbstractMenu {
public static abstract class UserMenuItem implements IMenuItem {
@Override
public MenuAction getMenuAction() {
return MenuAction.HIDE;
}
@Override
public IMenuItem[] getSubmenu() {
return null;
}
}
public UserMenu(Float width, Float height) {
super(width, height);
}
......@@ -29,7 +48,21 @@ public class UserMenu extends AbstractMenu {
@Override
protected List<? extends IMenuItem> getMenuItems() {
return User.selectAllAvailableUsers();
List<IMenuItem> userMenuItems = new ArrayList<IMenuItem>();
userMenuItems.add(new UserMenuItem() {
@Override
public String getTitle() {
return ApplicationTextManager.getInstance().getText(ApplicationTextManager.ApplicationTextsAssets.USERMENU_NEWUSER);
}
@Override
public void performAction() {
ApplicationBus.getInstance().post(new Tablexia.ChangeScreenEvent(PanoramaScreen.class, TablexiaApplication.ScreenTransaction.MOVE_UP)).asynchronously();
}
});
userMenuItems.addAll(User.selectAllAvailableUsers());
return userMenuItems;
}
}
......@@ -4,12 +4,12 @@ import java.util.ArrayList;
import java.util.List;
import cz.nic.tablexia.TablexiaSettings;
import cz.nic.tablexia.menu.IMenuItem;
import cz.nic.tablexia.menu.user.UserMenu;
/**
* Created by lhoracek on 4/16/15.
* Created by lhoracek, Matyáš Latner
*/
public class User implements IMenuItem {
public class User extends UserMenu.UserMenuItem {
private Long id;
private String name;
......@@ -40,13 +40,14 @@ public class User implements IMenuItem {
this.gender = gender;
}
public static enum Gender {
MALE,FEMALE;
public enum Gender {
MALE,
FEMALE;
}
//TODO wrap to class
//////////////////////////// IMENUITEM
//////////////////////////// USER MENU ITEM
@Override
public String getTitle() {
......@@ -58,16 +59,6 @@ public class User implements IMenuItem {
TablexiaSettings.getInstance().setSelectedUser(this);
}
@Override
public boolean isCloseMenu() {
return true;
}
@Override
public IMenuItem[] getSubmenu() {
return null;
}
//////////////////////////// DB ACCESS
......
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