Commit ea4ea934 authored by Drahomír Karchňák's avatar Drahomír Karchňák

Merge branch 'feature-dekstop-runes-game' into V3.5.1

parents 95a28952 2203bf44
...@@ -44,6 +44,7 @@ import cz.nic.tablexia.game.games.runes.actors.TimeBar; ...@@ -44,6 +44,7 @@ import cz.nic.tablexia.game.games.runes.actors.TimeBar;
import cz.nic.tablexia.game.games.runes.assets.RuneDefinition; import cz.nic.tablexia.game.games.runes.assets.RuneDefinition;
import cz.nic.tablexia.game.games.runes.assets.RunesGameAssets; import cz.nic.tablexia.game.games.runes.assets.RunesGameAssets;
import cz.nic.tablexia.game.games.runes.helper.HolderManager; import cz.nic.tablexia.game.games.runes.helper.HolderManager;
import cz.nic.tablexia.game.games.runes.helper.MobileHolderManager;
import cz.nic.tablexia.game.games.runes.helper.PositionDefinition; import cz.nic.tablexia.game.games.runes.helper.PositionDefinition;
import cz.nic.tablexia.game.games.runes.helper.PositionManager; import cz.nic.tablexia.game.games.runes.helper.PositionManager;
import cz.nic.tablexia.game.games.runes.model.RunesDifficultyDefinition; import cz.nic.tablexia.game.games.runes.model.RunesDifficultyDefinition;
...@@ -52,7 +53,6 @@ import cz.nic.tablexia.game.games.runes.model.RunesGameState; ...@@ -52,7 +53,6 @@ import cz.nic.tablexia.game.games.runes.model.RunesGameState;
import cz.nic.tablexia.loader.application.ApplicationFontManager; import cz.nic.tablexia.loader.application.ApplicationFontManager;
import cz.nic.tablexia.loader.application.ApplicationTextManager; import cz.nic.tablexia.loader.application.ApplicationTextManager;
import cz.nic.tablexia.shared.model.Game; import cz.nic.tablexia.shared.model.Game;
import cz.nic.tablexia.util.Log;
import cz.nic.tablexia.util.MusicUtil; import cz.nic.tablexia.util.MusicUtil;
import cz.nic.tablexia.util.ui.AnimatedImage; import cz.nic.tablexia.util.ui.AnimatedImage;
import cz.nic.tablexia.util.ui.TablexiaLabel; import cz.nic.tablexia.util.ui.TablexiaLabel;
...@@ -129,7 +129,7 @@ public class RunesGame extends AbstractTablexiaGame<RunesGameState> { ...@@ -129,7 +129,7 @@ public class RunesGame extends AbstractTablexiaGame<RunesGameState> {
* Init scene elements with certain positions * Init scene elements with certain positions
*/ */
private void initScene() { private void initScene() {
holderManager = new HolderManager(runesDifficultyDefinition, getRandom()); holderManager = TablexiaSettings.getInstance().isRunningOnMobileDevice() ? new MobileHolderManager(runesDifficultyDefinition, getRandom()) : new HolderManager(runesDifficultyDefinition, getRandom());
positionManager = new PositionManager(runesDifficultyDefinition); positionManager = new PositionManager(runesDifficultyDefinition);
content = new Group(); content = new Group();
runesGroup = new Group(); runesGroup = new Group();
...@@ -142,18 +142,17 @@ public class RunesGame extends AbstractTablexiaGame<RunesGameState> { ...@@ -142,18 +142,17 @@ public class RunesGame extends AbstractTablexiaGame<RunesGameState> {
setActorToFullScene(background); setActorToFullScene(background);
// click listener to fold all holders on click on background // click listener to fold all holders on click on background
getStage().addListener(new ClickListener() { if(TablexiaSettings.getInstance().getPlatform() != TablexiaSettings.Platform.DESKTOP) {
@Override getStage().addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) { @Override
if (event.getTarget().equals(background)) { public void clicked(InputEvent event, float x, float y) {
holderManager.foldAll(); if (event.getTarget().equals(background)) {
holderManager.resetHoldersState();
}
super.clicked(event, x, y);
} }
Log.debug(getClass(),"Clicked x:" + x/getSceneWidth() + ", y:" + y/getSceneInnerHeight()); });
super.clicked(event, x, y); }
}
});
} }
private void initSidebar() { private void initSidebar() {
...@@ -271,17 +270,10 @@ public class RunesGame extends AbstractTablexiaGame<RunesGameState> { ...@@ -271,17 +270,10 @@ public class RunesGame extends AbstractTablexiaGame<RunesGameState> {
private void initHolders() { private void initHolders() {
int maxGroups = PositionDefinition.getGroupsCount(getData().getRound(), getGameDifficulty()); int maxGroups = PositionDefinition.getGroupsCount(getData().getRound(), getGameDifficulty());
for (int i = 0; i < maxGroups; i++) { for (int i = 0; i < maxGroups; i++) {
final RunesHolder runesHolder = HolderManager.createHolder(targetPlate.getActiveTargetsDescriptions(),runesDifficultyDefinition); holderManager.createHolder(targetPlate.getActiveTargetsDescriptions(), runesDifficultyDefinition);
runesHolder.init(); }
runesHolder.addListener(new ClickListener() { for (RunesHolder holder: holderManager.getHolders()) {
@Override runesGroup.addActor(holder);
public void clicked(InputEvent event, float x, float y) {
holderManager.switchFolded(runesHolder);
super.clicked(event, x, y);
}
});
holderManager.getHolders().add(runesHolder);
runesGroup.addActor(runesHolder);
} }
updateBoard(); updateBoard();
} }
...@@ -320,7 +312,10 @@ public class RunesGame extends AbstractTablexiaGame<RunesGameState> { ...@@ -320,7 +312,10 @@ public class RunesGame extends AbstractTablexiaGame<RunesGameState> {
holderManager.moveHolders(newPositions, getSceneWidth(), getSceneInnerHeight()); holderManager.moveHolders(newPositions, getSceneWidth(), getSceneInnerHeight());
holderManager.updateHolders(targetPlate.getActiveTargetsDescriptions(), getData().getRound()); holderManager.updateHolders(targetPlate.getActiveTargetsDescriptions(), getData().getRound());
holderManager.addHoldersActors(runesLibrary, correctRuneListener); holderManager.addHoldersActors(runesLibrary, correctRuneListener);
holderManager.foldAll();
if(TablexiaSettings.getInstance().getPlatform() != TablexiaSettings.Platform.DESKTOP) {
holderManager.resetHoldersState();
}
} }
...@@ -366,7 +361,7 @@ public class RunesGame extends AbstractTablexiaGame<RunesGameState> { ...@@ -366,7 +361,7 @@ public class RunesGame extends AbstractTablexiaGame<RunesGameState> {
stopEndingSound(); stopEndingSound();
runesGroup.setVisible(false); runesGroup.setVisible(false);
sidebarGroup.setVisible(false); sidebarGroup.setVisible(false);
holderManager.foldAll(); holderManager.resetHoldersState();
getData().stopGame(); getData().stopGame();
gameComplete(); gameComplete();
} }
...@@ -449,4 +444,4 @@ public class RunesGame extends AbstractTablexiaGame<RunesGameState> { ...@@ -449,4 +444,4 @@ public class RunesGame extends AbstractTablexiaGame<RunesGameState> {
private String prepareDifficultySuffix() { private String prepareDifficultySuffix() {
return PRELOADER_DIFFICULTY_SUFFIX_SEPARATOR + getGameDifficulty().name().toLowerCase(); return PRELOADER_DIFFICULTY_SUFFIX_SEPARATOR + getGameDifficulty().name().toLowerCase();
} }
} }
\ No newline at end of file
...@@ -33,13 +33,10 @@ import cz.nic.tablexia.game.games.runes.actors.RunesHolder; ...@@ -33,13 +33,10 @@ import cz.nic.tablexia.game.games.runes.actors.RunesHolder;
import cz.nic.tablexia.game.games.runes.model.RunesDifficultyDefinition; import cz.nic.tablexia.game.games.runes.model.RunesDifficultyDefinition;
import cz.nic.tablexia.game.games.runes.model.RunesGameProperties; import cz.nic.tablexia.game.games.runes.model.RunesGameProperties;
/**
* Created by Vitaliy Vashchenko on 20.4.16.
*/
public class HolderManager { public class HolderManager {
private List<RunesHolder> holders; protected List<RunesHolder> holders;
private TablexiaRandom tablexiaRandom; protected TablexiaRandom tablexiaRandom;
private RunesDifficultyDefinition runesDifficultyDefinition; protected RunesDifficultyDefinition runesDifficultyDefinition;
public HolderManager(RunesDifficultyDefinition runesDifficultyDefinition, TablexiaRandom tablexiaRandom) { public HolderManager(RunesDifficultyDefinition runesDifficultyDefinition, TablexiaRandom tablexiaRandom) {
this.holders = new ArrayList<>(); this.holders = new ArrayList<>();
...@@ -47,14 +44,8 @@ public class HolderManager { ...@@ -47,14 +44,8 @@ public class HolderManager {
this.runesDifficultyDefinition = runesDifficultyDefinition; this.runesDifficultyDefinition = runesDifficultyDefinition;
} }
public void foldAll() { public void clearHolders() {
for (RunesHolder rh : holders) { for (RunesHolder rh : holders) {
rh.fold();
}
}
public void clearHolders(){
for (RunesHolder rh : holders){
rh.clearListeners(); rh.clearListeners();
} }
holders.clear(); holders.clear();
...@@ -63,41 +54,24 @@ public class HolderManager { ...@@ -63,41 +54,24 @@ public class HolderManager {
public List<RunesHolder> getHolders() { public List<RunesHolder> getHolders() {
return holders; return holders;
} }
public int getTotalRunesCount(){ public int getTotalRunesCount() {
int i = 0; int i = 0;
for (RunesHolder holder : holders){ for (RunesHolder holder : holders) {
i += holder.getAllHolderRunes().size(); i += holder.getAllHolderRunes().size();
} }
return i; return i;
} }
public Collection<RuneDescription> getAllRunesOnStage(){ public void moveHolders(List<PositionDefinition> positionDefinitionList, float width, float height) {
Collection<RuneDescription> allRunesOnStage= new ArrayList<>(); for (int i = 0; i < holders.size(); i++) {
for(RunesHolder runesHolder : holders){ holders.get(i).updateHolderPosition(positionDefinitionList.get(i), width, height);
allRunesOnStage.addAll(runesHolder.getAllHolderRunes()); holders.get(i).setMaxEntities(PositionDefinition.getMaxChildrenCount(runesDifficultyDefinition, positionDefinitionList.get(i)));
} }
return allRunesOnStage;
} }
public void moveHolders(List<PositionDefinition> positionDefinitionList, float width, float height){ public void resetHoldersState() {
for (int i = 0; i < holders.size(); i++){
holders.get(i).updateHolderPosition(positionDefinitionList.get(i), width,height);
holders.get(i).setMaxEntities(PositionDefinition.getMaxChildrenCount(runesDifficultyDefinition,positionDefinitionList.get(i)));
}
}
public void unfoldHolder(RunesHolder runesHolder){
runesHolder.unfold();
}
public void switchFolded(RunesHolder runesHolder){
if (runesHolder.isFolded()) {
foldAll();
unfoldHolder(runesHolder);
}else {
foldAll();
}
} }
public void updateHolders(List<RuneDescription> roundTargets, int round) { public void updateHolders(List<RuneDescription> roundTargets, int round) {
...@@ -128,13 +102,13 @@ public class HolderManager { ...@@ -128,13 +102,13 @@ public class HolderManager {
i++; i++;
} }
} }
public void addHoldersActors(GfxLibrary gfxLibrary, ClickListener correctRuneListener){ public void addHoldersActors(GfxLibrary gfxLibrary, ClickListener correctRuneListener) {
for(RunesHolder rh : holders){ for (RunesHolder rh : holders) {
prepareHolder(rh); prepareHolder(rh);
Actor holderActor; Actor holderActor;
rh.clearGroup(); rh.clearGroup();
if (runesDifficultyDefinition.getTargetType().equals(RunesDifficultyDefinition.TargetType.CLUSTER)){ if (runesDifficultyDefinition.getTargetType().equals(RunesDifficultyDefinition.TargetType.CLUSTER)) {
for (RuneDescription runeDescription : rh.getAllHolderRunes()) { for (RuneDescription runeDescription : rh.getAllHolderRunes()) {
holderActor = RunesCluster.createRuneCluster(gfxLibrary, runeDescription, rh.getRoundTargets(), tablexiaRandom); holderActor = RunesCluster.createRuneCluster(gfxLibrary, runeDescription, rh.getRoundTargets(), tablexiaRandom);
RunesHolder.addRuneToHolder(rh, holderActor, correctRuneListener, runesDifficultyDefinition.getTargetType().getSpace()); RunesHolder.addRuneToHolder(rh, holderActor, correctRuneListener, runesDifficultyDefinition.getTargetType().getSpace());
...@@ -142,20 +116,21 @@ public class HolderManager { ...@@ -142,20 +116,21 @@ public class HolderManager {
} else { } else {
for (RuneDescription runeDescription : rh.getAllHolderRunes()) { for (RuneDescription runeDescription : rh.getAllHolderRunes()) {
holderActor = Rune.RunesFactory.createInstance(gfxLibrary, runeDescription.getRuneDefinition(), runeDescription.isFlipped()); holderActor = Rune.RunesFactory.createInstance(gfxLibrary, runeDescription.getRuneDefinition(), runeDescription.isFlipped());
RunesHolder.addRuneToHolder(rh,holderActor,correctRuneListener,runesDifficultyDefinition.getTargetType().getSpace()); RunesHolder.addRuneToHolder(rh, holderActor, correctRuneListener, runesDifficultyDefinition.getTargetType().getSpace());
} }
} }
} }
} }
public void prepareHolder(RunesHolder rh){ public void prepareHolder(RunesHolder rh) {
rh.setWrongRunes(RuneInstance.getSimilarRuneInstances(rh.getHolderTargets(), rh.getRoundTargets(), tablexiaRandom, rh.getWrongRunesCount(), runesDifficultyDefinition.isFlipRunes())); rh.setWrongRunes(RuneInstance.getSimilarRuneInstances(rh.getHolderTargets(), rh.getRoundTargets(), tablexiaRandom, rh.getWrongRunesCount(), runesDifficultyDefinition.isFlipRunes()));
rh.randomizeRunesOrder(tablexiaRandom); rh.randomizeRunesOrder(tablexiaRandom);
} }
public static RunesHolder createHolder(Collection<RuneDescription> activeTargets, RunesDifficultyDefinition runesDifficultyDefinition){ public void createHolder(Collection<RuneDescription> activeTargets, RunesDifficultyDefinition runesDifficultyDefinition) {
final RunesHolder runesHolder = new RunesHolder((List<RuneDescription>) activeTargets, runesDifficultyDefinition); RunesHolder runesHolder = new RunesHolder((List<RuneDescription>) activeTargets, runesDifficultyDefinition);
return runesHolder; runesHolder.init();
holders.add(runesHolder);
} }
} }
\ No newline at end of file
/*
* Copyright (C) 2016 CZ.NIC, z.s.p.o. (http://www.nic.cz/)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package cz.nic.tablexia.game.games.runes.helper;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import java.util.Collection;
import java.util.List;
import cz.nic.tablexia.game.common.TablexiaRandom;
import cz.nic.tablexia.game.games.runes.actors.RunesHolder;
import cz.nic.tablexia.game.games.runes.model.RunesDifficultyDefinition;
/**
* Created by Vitaliy Vashchenko on 20.4.16.
*/
public class MobileHolderManager extends HolderManager {
public MobileHolderManager(RunesDifficultyDefinition runesDifficultyDefinition, TablexiaRandom tablexiaRandom) {
super(runesDifficultyDefinition, tablexiaRandom);
}
@Override
public void resetHoldersState() {
for (RunesHolder runesHolder : holders) {
runesHolder.fold();
}
}
@Override
public void createHolder(Collection<RuneDescription> activeTargets, RunesDifficultyDefinition runesDifficultyDefinition) {
RunesHolder runesHolder = new RunesHolder((List<RuneDescription>) activeTargets, runesDifficultyDefinition);
runesHolder.init();
holders.add(runesHolder);
runesHolder.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
switchFolded(runesHolder);
super.clicked(event, x, y);
}
});
}
public void switchFolded(RunesHolder runesHolder) {
if (runesHolder.isFolded()) {
resetHoldersState();
runesHolder.unfold();
} else {
resetHoldersState();
}
}
}
\ No newline at end of file
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