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;
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.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.PositionManager;
import cz.nic.tablexia.game.games.runes.model.RunesDifficultyDefinition;
......@@ -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.ApplicationTextManager;
import cz.nic.tablexia.shared.model.Game;
import cz.nic.tablexia.util.Log;
import cz.nic.tablexia.util.MusicUtil;
import cz.nic.tablexia.util.ui.AnimatedImage;
import cz.nic.tablexia.util.ui.TablexiaLabel;
......@@ -129,7 +129,7 @@ public class RunesGame extends AbstractTablexiaGame<RunesGameState> {
* Init scene elements with certain positions
*/
private void initScene() {
holderManager = new HolderManager(runesDifficultyDefinition, getRandom());
holderManager = TablexiaSettings.getInstance().isRunningOnMobileDevice() ? new MobileHolderManager(runesDifficultyDefinition, getRandom()) : new HolderManager(runesDifficultyDefinition, getRandom());
positionManager = new PositionManager(runesDifficultyDefinition);
content = new Group();
runesGroup = new Group();
......@@ -142,18 +142,17 @@ public class RunesGame extends AbstractTablexiaGame<RunesGameState> {
setActorToFullScene(background);
// click listener to fold all holders on click on background
if(TablexiaSettings.getInstance().getPlatform() != TablexiaSettings.Platform.DESKTOP) {
getStage().addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
if (event.getTarget().equals(background)) {
holderManager.foldAll();
holderManager.resetHoldersState();
}
Log.debug(getClass(),"Clicked x:" + x/getSceneWidth() + ", y:" + y/getSceneInnerHeight());
super.clicked(event, x, y);
}
});
}
}
private void initSidebar() {
......@@ -271,17 +270,10 @@ public class RunesGame extends AbstractTablexiaGame<RunesGameState> {
private void initHolders() {
int maxGroups = PositionDefinition.getGroupsCount(getData().getRound(), getGameDifficulty());
for (int i = 0; i < maxGroups; i++) {
final RunesHolder runesHolder = HolderManager.createHolder(targetPlate.getActiveTargetsDescriptions(),runesDifficultyDefinition);
runesHolder.init();
runesHolder.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
holderManager.switchFolded(runesHolder);
super.clicked(event, x, y);
holderManager.createHolder(targetPlate.getActiveTargetsDescriptions(), runesDifficultyDefinition);
}
});
holderManager.getHolders().add(runesHolder);
runesGroup.addActor(runesHolder);
for (RunesHolder holder: holderManager.getHolders()) {
runesGroup.addActor(holder);
}
updateBoard();
}
......@@ -320,7 +312,10 @@ public class RunesGame extends AbstractTablexiaGame<RunesGameState> {
holderManager.moveHolders(newPositions, getSceneWidth(), getSceneInnerHeight());
holderManager.updateHolders(targetPlate.getActiveTargetsDescriptions(), getData().getRound());
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> {
stopEndingSound();
runesGroup.setVisible(false);
sidebarGroup.setVisible(false);
holderManager.foldAll();
holderManager.resetHoldersState();
getData().stopGame();
gameComplete();
}
......
......@@ -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.RunesGameProperties;
/**
* Created by Vitaliy Vashchenko on 20.4.16.
*/
public class HolderManager {
private List<RunesHolder> holders;
private TablexiaRandom tablexiaRandom;
private RunesDifficultyDefinition runesDifficultyDefinition;
protected List<RunesHolder> holders;
protected TablexiaRandom tablexiaRandom;
protected RunesDifficultyDefinition runesDifficultyDefinition;
public HolderManager(RunesDifficultyDefinition runesDifficultyDefinition, TablexiaRandom tablexiaRandom) {
this.holders = new ArrayList<>();
......@@ -47,14 +44,8 @@ public class HolderManager {
this.runesDifficultyDefinition = runesDifficultyDefinition;
}
public void foldAll() {
public void clearHolders() {
for (RunesHolder rh : holders) {
rh.fold();
}
}
public void clearHolders(){
for (RunesHolder rh : holders){
rh.clearListeners();
}
holders.clear();
......@@ -64,40 +55,23 @@ public class HolderManager {
return holders;
}
public int getTotalRunesCount(){
public int getTotalRunesCount() {
int i = 0;
for (RunesHolder holder : holders){
for (RunesHolder holder : holders) {
i += holder.getAllHolderRunes().size();
}
return i;
}
public Collection<RuneDescription> getAllRunesOnStage(){
Collection<RuneDescription> allRunesOnStage= new ArrayList<>();
for(RunesHolder runesHolder : holders){
allRunesOnStage.addAll(runesHolder.getAllHolderRunes());
public void moveHolders(List<PositionDefinition> positionDefinitionList, float width, float height) {
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)));
}
return allRunesOnStage;
}
public void moveHolders(List<PositionDefinition> positionDefinitionList, float width, float height){
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 resetHoldersState() {
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) {
......@@ -129,12 +103,12 @@ public class HolderManager {
}
}
public void addHoldersActors(GfxLibrary gfxLibrary, ClickListener correctRuneListener){
for(RunesHolder rh : holders){
public void addHoldersActors(GfxLibrary gfxLibrary, ClickListener correctRuneListener) {
for (RunesHolder rh : holders) {
prepareHolder(rh);
Actor holderActor;
rh.clearGroup();
if (runesDifficultyDefinition.getTargetType().equals(RunesDifficultyDefinition.TargetType.CLUSTER)){
if (runesDifficultyDefinition.getTargetType().equals(RunesDifficultyDefinition.TargetType.CLUSTER)) {
for (RuneDescription runeDescription : rh.getAllHolderRunes()) {
holderActor = RunesCluster.createRuneCluster(gfxLibrary, runeDescription, rh.getRoundTargets(), tablexiaRandom);
RunesHolder.addRuneToHolder(rh, holderActor, correctRuneListener, runesDifficultyDefinition.getTargetType().getSpace());
......@@ -142,20 +116,21 @@ public class HolderManager {
} else {
for (RuneDescription runeDescription : rh.getAllHolderRunes()) {
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.randomizeRunesOrder(tablexiaRandom);
}
public static RunesHolder createHolder(Collection<RuneDescription> activeTargets, RunesDifficultyDefinition runesDifficultyDefinition){
final RunesHolder runesHolder = new RunesHolder((List<RuneDescription>) activeTargets, runesDifficultyDefinition);
return runesHolder;
public void createHolder(Collection<RuneDescription> activeTargets, RunesDifficultyDefinition runesDifficultyDefinition) {
RunesHolder runesHolder = new RunesHolder((List<RuneDescription>) activeTargets, runesDifficultyDefinition);
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