Commit ac81c9b6 authored by Luboš Horáček's avatar Luboš Horáček

#317 & #318 Chyby při volbě položky nového uživatele

parent aa80ade5
......@@ -661,7 +661,7 @@ public class Tablexia extends com.activeandroid.app.Application {
@Override
public void onAnimationEnd(Animator animation) {
((Activity) getCurrentMenuActivity()).startActivityForResult(intent, 0);
((Activity) getCurrentMenuActivity()).startActivityForResult(intent, MainActivity.REQUEST_CODE_NEW_USER);
// TODO remove TestFlight.log("Create user button");
}
});
......
......@@ -82,6 +82,7 @@ public class MapGenerator implements IMapProvider {
this.randomAccess = randomAccess;
}
@Override
public TileMap prepareMap(Tile lastFinishTile, int mapXSize, int mapYSize, MapObjectType finishMapObject, boolean hasKey) {
Log.d(MapGenerator.class.getCanonicalName(), "Start generating with random seed: " + randomAccess.getRandomSeed());
TileMap tileMap = new TileMap(mapXSize, mapYSize);
......@@ -134,8 +135,8 @@ public class MapGenerator implements IMapProvider {
startTile = new Tile(TileType.getRandomTileTypeForAvailableDoors(null, true, null, null, true, randomAccess));
} else {
startPosition = lastEndTile.getTileMapPosition();
if (Arrays.asList(new TileType[] {TileType.TILE_1B, TileType.TILE_1D}).contains(lastEndTile.getTileType()) && (startPosition.getPositionX() == 0 || startPosition.getPositionX() == tileMap.getMapXSize() - 1) ||
Arrays.asList(new TileType[] {TileType.TILE_1A, TileType.TILE_1C}).contains(lastEndTile.getTileType()) && (startPosition.getPositionY() == 0 || startPosition.getPositionY() == tileMap.getMapYSize() - 1)) {
if ((Arrays.asList(new TileType[] {TileType.TILE_1B, TileType.TILE_1D}).contains(lastEndTile.getTileType()) && ((startPosition.getPositionX() == 0) || (startPosition.getPositionX() == (tileMap.getMapXSize() - 1)))) ||
(Arrays.asList(new TileType[] {TileType.TILE_1A, TileType.TILE_1C}).contains(lastEndTile.getTileType()) && ((startPosition.getPositionY() == 0) || (startPosition.getPositionY() == (tileMap.getMapYSize() - 1))))) {
// create same tile as last tile
startTile = new Tile(lastEndTile.getTileType());
......@@ -167,7 +168,7 @@ public class MapGenerator implements IMapProvider {
TileGroupsDistanceContainer minimalDistance = null;
for (List<Tile> tileGroup : tileGroups) {
TileGroupsDistanceContainer distance = getGroupsMinimalDistance(biggestGroup, tileGroup, bannedPositions);
if (minimalDistance == null || distance.getDistance() < minimalDistance.getDistance()) {
if ((minimalDistance == null) || (distance.getDistance() < minimalDistance.getDistance())) {
minimalDistance = distance;
}
}
......@@ -194,7 +195,7 @@ public class MapGenerator implements IMapProvider {
private List<Tile> getBiggestTileGroup(List<List<Tile>> tileGroups) {
List<Tile> biggestGroup = null;
for (List<Tile> tileGroup : tileGroups) {
if (biggestGroup == null || tileGroup.size() > biggestGroup.size()) {
if ((biggestGroup == null) || (tileGroup.size() > biggestGroup.size())) {
biggestGroup = tileGroup;
}
}
......@@ -214,7 +215,7 @@ public class MapGenerator implements IMapProvider {
for (int i = 0; i < tileMap.getMapXSize(); i++) {
for (int j = 0; j < tileMap.getMapYSize(); j++) {
Tile tile = tileMap.getTileAtPosition(i, j);
if (tile != null && !checkedTiles.contains(tile)) {
if ((tile != null) && !checkedTiles.contains(tile)) {
List<Tile> group = getTileGroup(checkedTiles, tile);
if (group.size() > 0) {
result.add(group);
......@@ -249,11 +250,11 @@ public class MapGenerator implements IMapProvider {
protected TileGroupsDistanceContainer getGroupsMinimalDistance(List<Tile> group1, List<Tile> group2, List<TileMapPosition> bannedPositions) {
TileGroupsDistanceContainer minimalDistance = null;
for (Tile tile1 : group1) {
if (bannedPositions == null || !bannedPositions.contains(tile1.getTileMapPosition())) {
if ((bannedPositions == null) || !bannedPositions.contains(tile1.getTileMapPosition())) {
for (Tile tile2 : group2) {
if (bannedPositions == null || !bannedPositions.contains(tile2.getTileMapPosition())) {
if ((bannedPositions == null) || !bannedPositions.contains(tile2.getTileMapPosition())) {
int distance = Math.abs(tile1.getMapPositionX() - tile2.getMapPositionX()) + Math.abs(tile1.getMapPositionY() - tile2.getMapPositionY());
if (minimalDistance == null || distance < minimalDistance.getDistance()) {
if ((minimalDistance == null) || (distance < minimalDistance.getDistance())) {
minimalDistance = new TileGroupsDistanceContainer(tile1, tile2, distance);
}
}
......@@ -287,12 +288,12 @@ public class MapGenerator implements IMapProvider {
protected List<Tile> getTileGroup(List<Tile> checkedTiles, Tile startTile) {
List<Tile> result = new ArrayList<Tile>();
if (startTile != null && !startTile.getTileType().isWall()) {
if ((startTile != null) && !startTile.getTileType().isWall()) {
checkedTiles.add(startTile);
result.add(startTile);
for (Tile tile : startTile.getNeighbors()) {
if (tile != null && !checkedTiles.contains(tile)) {
if ((tile != null) && !checkedTiles.contains(tile)) {
result.addAll(getTileGroup(checkedTiles, tile));
}
}
......@@ -315,7 +316,7 @@ public class MapGenerator implements IMapProvider {
int lastXPosition = startPosition.getPositionX();
int lastYPosition = startPosition.getPositionY();
while (lastXPosition != finishPosition.getPositionX() || lastYPosition != finishPosition.getPositionY()) {
while ((lastXPosition != finishPosition.getPositionX()) || (lastYPosition != finishPosition.getPositionY())) {
List<TileMapPosition> freeBorders = tileMap.getTileFreeBorders(lastXPosition, lastYPosition, useOnlyFreeTiles, true);
......@@ -516,7 +517,7 @@ public class MapGenerator implements IMapProvider {
for (int i = 0; i < tileMap.getMapXSize(); i++) {
for (int j = 0; j < tileMap.getMapYSize(); j++) {
Tile tile = tileMap.getTileAtPosition(i, j);
if (tile != null && (tileTypes == null || tileTypes.contains(tile.getTileType()))) {
if ((tile != null) && ((tileTypes == null) || tileTypes.contains(tile.getTileType()))) {
if (tile.getDistance() > maxDistance) {
result = tile;
maxDistance = tile.getDistance();
......
......@@ -49,8 +49,8 @@ import cz.nic.tablexia.menu.mainmenu.screen.AbstractMenuFragment.MenuFragmentVis
import cz.nic.tablexia.menu.mainmenu.screen.LoaderFragment;
import cz.nic.tablexia.menu.usermenu.User;
import cz.nic.tablexia.newusers.fragment.AnimationContainerFragment;
import cz.nic.tablexia.util.MintHelper;
import cz.nic.tablexia.util.MediaPlayerHelper;
import cz.nic.tablexia.util.MintHelper;
import cz.nic.tablexia.widget.TablexiaDrawerLayout;
/**
......@@ -63,6 +63,10 @@ public class MainActivity extends FragmentActivity implements MenuActivity {
private static final String TAG = MainActivity.class.getSimpleName();
public static final int REQUEST_CODE_NEW_USER = 1000;
public static final int REQUEST_CODE_GAME = 2000;
public static final int RESULT_CODE_NEW_USER = 1000;
private static final int START_PRELOADER_ANIM_DURATION = 2000;
private static final int MAIN_SCREEN_CONTAINER_ID = R.id.main_screen_container;
private static final int MAIN_SCREEN_PRELOADER_ID = R.id.main_screen_preloader;
......@@ -178,7 +182,7 @@ public class MainActivity extends FragmentActivity implements MenuActivity {
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if ((requestCode == 0) && (data != null) && (resultCode == Activity.RESULT_OK)) {
if ((requestCode == REQUEST_CODE_NEW_USER) && (data != null) && (resultCode == Activity.RESULT_OK)) {
hideLoadingScreen(false);
LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent("cz.nic.tablexia.action.NEW_USER_CREATED"));
......@@ -190,6 +194,10 @@ public class MainActivity extends FragmentActivity implements MenuActivity {
closeMenuDrawer();
}
}
if ((requestCode == REQUEST_CODE_GAME) && (data != null) && (resultCode == RESULT_CODE_NEW_USER)) {
// TODO show new user dialog
Log.d(TAG, "Start new user sequence");
}
getTablexiaContext().initMenu();
}
......
......@@ -45,9 +45,11 @@ import cz.nic.tablexia.R;
import cz.nic.tablexia.Tablexia;
import cz.nic.tablexia.audio.SoundControl;
import cz.nic.tablexia.audio.resources.PermanentSounds;
import cz.nic.tablexia.game.GameActivity;
import cz.nic.tablexia.game.games.GamesDefinition;
import cz.nic.tablexia.main.MainActivity;
import cz.nic.tablexia.menu.AbstractMenu;
import cz.nic.tablexia.menu.MenuActivity;
import cz.nic.tablexia.menu.MenuEnum;
import cz.nic.tablexia.util.Utility;
import cz.nic.tablexia.widget.TablexiaDrawerLayout.DrawerListenerAdapter;
......@@ -336,17 +338,37 @@ public class MainMenu extends AbstractMenu implements OnGroupClickListener, OnCh
@Override
public void positiveAction() {
// tablexiaContext.showNewUserScreen();
// TODO add code for starting animation on new user click from game menu while user logged in
// TODO add code for starting animation on new user click from game menu while user logged in/home/lhoracek/Downloads/Prago Union - Vážná Hudba (2013)
Bundle args = new Bundle();
args.putString("NEWUSER_GAMEMENU", "NEWUSER_GAMEMENU");
// HACK to create new user from game
MenuActivity activity = tablexiaContext.getCurrentMenuActivity();
if (activity instanceof MainActivity) {
((MainActivity) tablexiaContext.getCurrentMenuActivity()).showLoadingScreen(true, args);
((MainActivity) tablexiaContext.getCurrentMenuActivity()).lockCloseMenuDrawer();
}
tablexiaContext.changeMenu(AbstractMenu.USER_MENU);
userSpinner.setSelection(userSpinnerAdapter.getUserPositionInList(tablexiaContext.getCurrentMenuActivity().getTablexiaContext().getSelectedUser().getNickName()));
tablexiaContext.getTablexiaState().setAndSaveActiveUser(null);
if (activity instanceof GameActivity) {
tablexiaContext.hardResetUser();
// changeMenuItem(MainMenuDefinition.LOGOUT, false, false);
((GameActivity) activity).setResult(MainActivity.RESULT_CODE_NEW_USER);
// ((GameActivity) activity).finish();
}
super.positiveAction();
}
@Override
public void negativeAction() {
userSpinner.setSelection(userSpinnerAdapter.getUserPositionInList(tablexiaContext.getCurrentMenuActivity().getTablexiaContext().getSelectedUser().getNickName()));
super.negativeAction();
};
}.show(((Activity) tablexiaContext.getCurrentMenuActivity()).getFragmentManager(), null);
} else {
......
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