Skip to content
Snippets Groups Projects
Commit 6f14608b authored by Matyáš Latner's avatar Matyáš Latner
Browse files

#5 Robbery game debug screen rule text and select box for rule selection

parent ca83785d
No related branches found
No related tags found
No related merge requests found
package cz.nic.tablexia.game.games.robbery;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
import com.badlogic.gdx.scenes.scene2d.ui.SelectBox;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import com.badlogic.gdx.utils.Align;
import java.util.List;
import java.util.Map;
import cz.nic.tablexia.game.games.robbery.assets.RobberyAssets;
import cz.nic.tablexia.game.games.robbery.creature.CreatureRoot;
import cz.nic.tablexia.game.games.robbery.rules.GameRulesDefinition;
import cz.nic.tablexia.screen.AbstractTablexiaScreen;
import cz.nic.tablexia.util.Log;
public class DebugScreen extends AbstractTablexiaScreen<Void> {
private enum DebugGroupColors {
private static final float SELECTBOX_WIDTH_RATIO = 1f/5;
private static final float SELECTBOX_HEIGHT_RATIO = 1f/20;
private static final float SELECTBOX_X_HEIGHT_RATIO = 17f/20;
private static final float RULE_WIDTH_RATIO = 2f/3;
private static final float RULE_HEIGHT_RATIO = 2f/10;
private static final float RULE_X_RATIO = 1f/2;
private static final float RULE_Y_RATIO = 1f/50;
private enum DebugGroupColors {
RED(Color.RED),
GREEN(Color.GREEN),
BLUE(Color.BLUE),
......@@ -30,7 +46,7 @@ public class DebugScreen extends AbstractTablexiaScreen<Void> {
Color color;
private DebugGroupColors(Color color) {
DebugGroupColors(Color color) {
this.color = color;
}
......@@ -47,40 +63,88 @@ public class DebugScreen extends AbstractTablexiaScreen<Void> {
@Override
protected void screenLoaded(Map<String, String> screenState) {
displayAllCreatures(RobberyGame.getRobberyData().getCreatures(), getStage());
displayRule();
displayRuleSelectBox();
}
private void displayAllCreatures(List<CreatureRoot> creatures, Stage stage) {
private void displayRuleSelectBox() {
BitmapFont font = getDefaultRegularFont();
ScrollPane.ScrollPaneStyle scrollPaneStyle = new ScrollPane.ScrollPaneStyle();
scrollPaneStyle.background = new TextureRegionDrawable(getColorTextureRegion(Color.GRAY));
scrollPaneStyle.background.setMinWidth(50); // temporary size
scrollPaneStyle.background.setMinHeight(50);
com.badlogic.gdx.scenes.scene2d.ui.List.ListStyle listStyle = new com.badlogic.gdx.scenes.scene2d.ui.List.ListStyle();
listStyle.selection = new TextureRegionDrawable(getColorTextureRegion(Color.GRAY));
listStyle.font = font;
SelectBox.SelectBoxStyle selectBoxStyle = new SelectBox.SelectBoxStyle();
selectBoxStyle.font = font;
selectBoxStyle.scrollStyle = scrollPaneStyle;
selectBoxStyle.listStyle = listStyle;
selectBoxStyle.background = new TextureRegionDrawable(getColorTextureRegion(Color.GRAY));
selectBoxStyle.background.setMinWidth(50); // temporary size
selectBoxStyle.background.setMinHeight(50);
SelectBox<GameRulesDefinition> ruleSelectBox = new SelectBox<GameRulesDefinition>(selectBoxStyle);
ruleSelectBox.setItems(GameRulesDefinition.values());
ruleSelectBox.setSelected(RobberyGame.getRobberyRuleDefinition());
ruleSelectBox.addCaptureListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
}
});
getStage().addActor(ruleSelectBox);
float selectBoxWidth = getStage().getWidth() * SELECTBOX_WIDTH_RATIO;
float selectBoxHeight = getStage().getHeight() * SELECTBOX_HEIGHT_RATIO;
ruleSelectBox.setBounds((getStage().getWidth() / 2) - (selectBoxWidth / 2), getStage().getHeight() * SELECTBOX_X_HEIGHT_RATIO, selectBoxWidth, selectBoxHeight);
}
private void displayRule() {
Label label = new Label(RobberyGame.getRobberyData().getRuleMessageText(), new Label.LabelStyle(RobberyGame.getRobberyRegularFont(), Color.WHITE));
label.setWrap(true);
float labelWidth = getStage().getWidth() * RULE_WIDTH_RATIO;
float labelHeight = getStage().getHeight() * RULE_HEIGHT_RATIO;
label.setBounds((getStage().getWidth() * RULE_X_RATIO) - (labelWidth / 2), getStage().getHeight() * RULE_Y_RATIO, labelWidth, labelHeight);
label.setAlignment(Align.center);
getStage().addActor(label);
}
private void displayAllCreatures(List<CreatureRoot> creatures, Stage stage) {
if (creatures != null && creatures.size() > 0) {
float creatureScale = 0.5f;
float creatureScale = 0.4f;
TextureRegion sizeTextureRegion = RobberyGame.getRobberyTextureRegion(RobberyAssets.CREATURE_BACKGROUND_TEXTURE);
float creatureWidth = sizeTextureRegion.getRegionWidth() * creatureScale;
float creatureHeight = sizeTextureRegion.getRegionHeight() * creatureScale;
float borderX = (Gdx.graphics.getWidth() / 40);
float borderY = Gdx.graphics.getHeight() / 7;
float borderX = getStage().getWidth() / 40;
float borderY = getStage().getHeight() / 5;
int creaturesInLine = (int)Math.ceil(Double.valueOf(creatures.size()) / 2);
float xStep = (Gdx.graphics.getWidth() - (2 * borderX) - (creatureWidth / 2)) / creaturesInLine;
float xStep = (getStage().getWidth() - (2 * borderX) - (creatureWidth / 2)) / creaturesInLine;
float positionX = borderX;
float positionY = Gdx.graphics.getHeight() - (creatureHeight) - borderY;
float positionY = getStage().getHeight() - (creatureHeight) - borderY;
for (int i = 0; i < creatures.size(); i++) {
CreatureRoot creatureRoot = creatures.get(i);
creatureRoot.setScale(creatureScale);
creatureRoot.setPosition(positionX, positionY);
int groupNumber = creatureRoot.getGroupNumber();
if (groupNumber >= 0) {
if (groupNumber >= 0) {
creatureRoot.highliteWithColor(DebugGroupColors.values()[groupNumber].getColor());
}
positionX = positionX + xStep;
if ((i + 1) % creaturesInLine == 0) {
positionX = borderX;
positionY = borderY;
}
stage.addActor(creatureRoot);
}
} else {
......
......@@ -28,13 +28,14 @@ public class RobberyGame extends AbstractTablexiaGame<GameRule> {
private InputMultiplexer inputMultiplexer;
private AbstractTablexiaScreen<Void> actualScreen;
private GameRulesDefinition rulesDefinition;
private boolean isRootScreenVisible;
private boolean isComponentScreenVisible;
private boolean isComponentScreenVisible;
private static int actualCreatureNumber;
//////////////////////////// SCREEN LOADERS
@Override
......@@ -46,8 +47,8 @@ public class RobberyGame extends AbstractTablexiaGame<GameRule> {
@Override
protected GameRule prepareGameData(Map<String, String> gameState) {
GameRulesDefinition rule = GameRulesDefinition.getRandomGameRuleForDifficulty(getGameDifficulty(), getRandom());
GameRule gameRule = rule.getGameRuleInstance(getRandom(), CREATURES_COUNT, THIEVES_COUNT);
rulesDefinition = GameRulesDefinition.getRandomGameRuleForDifficulty(getGameDifficulty(), getRandom());
GameRule gameRule = rulesDefinition.getGameRuleInstance(getRandom(), CREATURES_COUNT, THIEVES_COUNT);
gameRule.generateCreatures();
if (gameState != null && gameState.containsKey(ACTUAL_CREATURE_NUMBER)) {
......@@ -255,6 +256,17 @@ public class RobberyGame extends AbstractTablexiaGame<GameRule> {
}
return null;
}
public GameRulesDefinition getRulesDefinition() {
return rulesDefinition;
}
public static GameRulesDefinition getRobberyRuleDefinition() {
if (instance != null) {
return instance.getRulesDefinition();
}
return null;
}
static void showRobberyRuleScreen() {
instance.showRuleScreen(true);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment