Skip to content
Snippets Groups Projects
Commit cc9cdffe authored by Luboš Horáček's avatar Luboš Horáček
Browse files

#11 Viewpager start game buttons

parent 3763719b
No related branches found
No related tags found
No related merge requests found
core/assets/cs/screen/gamemenu/potme_startbutton_pressed.png

27.1 KiB

core/assets/cs/screen/gamemenu/strelnice_startbutton_pressed.png

27.1 KiB

......@@ -15,7 +15,7 @@ public final class GameMenuAssets {
public static enum GameMenuLayers {
FORE, MID, BACK, TITLE, STARTBUTTON;
FORE, MID, BACK, TITLE, STARTBUTTON, STARTBUTTON_PRESSED;
}
private static final String GAMEMENU_PATH = "screen/gamemenu/";
......@@ -30,6 +30,7 @@ public final class GameMenuAssets {
public static final String DOOR_PRESSED = GAMEMENU_PATH + "streetdoor_pressed.png";
public static final String PROFILE_PRESSED = GAMEMENU_PATH + "profile_pressed.png";
public static final String DIFF_BAR = GAMEMENU_PATH + "difficultyseekbar_background.png";
public static final String DIFF_THUMB = GAMEMENU_PATH + "difficultyseekbar_thumb.png";
public static final String DIFF_THUMB_EASY = GAMEMENU_PATH + "difficultyseekbar_thumb_easy.png";
public static final String DIFF_THUMB_HARD = GAMEMENU_PATH + "difficultyseekbar_thumb_hard.png";
......@@ -52,6 +53,7 @@ public final class GameMenuAssets {
textures.add(OFFICE_HELP);
textures.add(VIGNETTE);
textures.add(DIFF_BAR);
textures.add(DIFF_THUMB);
textures.add(DIFF_THUMB_EASY);
textures.add(DIFF_THUMB_HARD);
......
......@@ -39,6 +39,7 @@ public class GameMenuScreen extends AbstractTablexiaScreen<Void> {
getStage().addActor(vp);
Image im = new Image(getTexture(GameMenuAssets.VIGNETTE));
im.setTouchable(Touchable.disabled);
im.setSize(getStage().getWidth(), getStage().getHeight());
......
......@@ -2,11 +2,14 @@ package cz.nic.tablexia.screen.gamemenu.pages;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.scenes.scene2d.utils.DragListener;
import cz.nic.tablexia.game.GameDefinition;
import cz.nic.tablexia.screen.AbstractTablexiaScreen;
import cz.nic.tablexia.screen.gamemenu.GameMenuAssets;
import cz.nic.tablexia.util.Log;
import cz.nic.tablexia.util.ui.ViewPager;
/**
......@@ -21,26 +24,72 @@ public class GameMenuPage extends MenuPage implements ViewPager.ScrollListener {
public GameMenuPage(AbstractTablexiaScreen screen, GameDefinition game) {
super(screen);
this.game = game;
// Start button
Texture start = getScreen().getTexture(GameMenuAssets.getResourcePath(game, GameMenuAssets.GameMenuLayers.STARTBUTTON));
Image startButton = new Image(start);
int startY = (int) (screen.getStage().getWidth() * 0.1);
int startHeight = (int) (screen.getStage().getHeight() * 0.25);
int startWidth = (int) (startHeight * ((float) start.getWidth() / (float) start.getHeight()));
int startX = (int) screen.getStage().getWidth() / 2 - startWidth / 2;
startButton.setSize(startWidth, startHeight);
startButton.setPosition(startX, startY);
addActor(startButton);
startButton.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
super.clicked(event, x, y);
GameMenuPage.this.game.performAction();
}
});
// Difficulty button
Texture diff = getScreen().getTexture(GameMenuAssets.DIFF_THUMB_MEDIUM);
final Image diffButton = new Image(diff);
int diffY = 0;
int diffHeight = (int) (screen.getStage().getHeight() * 0.15);
int diffWidth = (int) (diffHeight * ((float) diff.getWidth() / (float) diff.getHeight()));
int diffX = (int) screen.getStage().getWidth() / 2 - diffWidth / 2;
diffButton.setSize(diffWidth, diffHeight);
diffButton.setPosition(diffX, diffY);
addActor(diffButton);
diffButton.addListener(new DragListener() {
@Override
public void drag(InputEvent event, float x, float y, int pointer) {
super.drag(event, x, y, pointer);
diffButton.setX(diffButton.getX() + x);
}
});
}
@Override
public void draw(Batch batch, float parentAlpha) {
// Paralax layers
Texture back = getScreen().getTexture(GameMenuAssets.getResourcePath(game, GameMenuAssets.GameMenuLayers.BACK));
int srcX = (int) (back.getWidth() * Math.max(scrollOffset / 2, 0) / getWidth());
int srcWidth = (int) (back.getWidth() * (getWidth() - (Math.min(scrollOffset, 0) + Math.max(0, (scrollOffset)))) / getWidth());
int srcWidth = (int) (back.getWidth() * (getWidth() - (Math.min(scrollOffset, 0) + Math.max(0, scrollOffset))) / getWidth());
batch.draw(back, getX() - Math.min(scrollOffset, 0), getY(), getWidth() - Math.max(0, scrollOffset), getHeight(), srcX, 0, srcWidth, back.getHeight(), false, false);
Log.info(((Object) this).getClass().getName(), "Draw fro" + srcX + " to " + (srcX + srcWidth) + " of " + back.getWidth());
batch.draw(getScreen().getTexture(GameMenuAssets.getResourcePath(game, GameMenuAssets.GameMenuLayers.MID)), getX(), getY(), getWidth(), getHeight());
batch.draw(getScreen().getTexture(GameMenuAssets.getResourcePath(game, GameMenuAssets.GameMenuLayers.FORE)), getX() + (scrollOffset / 2), getY(), getWidth(), getHeight());
// Title
Texture title = getScreen().getTexture(GameMenuAssets.getResourcePath(game, GameMenuAssets.GameMenuLayers.TITLE));
int titleX = (int) (getStage().getWidth() * 0.2);
int titleY = (int) (getStage().getHeight() - (getStage().getHeight() * 0.05));
int titleX = (int) (getWidth() * 0.2);
int titleY = (int) (getHeight() - (getStage().getHeight() * 0.05));
int titleWidth = (int) (getWidth() * 0.6);
int titleHeight = (int) (titleWidth * (title.getHeight() / getWidth()));
int titleHeight = (int) (titleWidth * ((float) title.getHeight() / (float) title.getWidth()));
batch.draw(title, getX() + titleX, getY() + titleY - titleHeight, titleWidth, titleHeight);
// Difficulty bar
Texture diffBar = getScreen().getTexture(GameMenuAssets.DIFF_BAR);
int diffY = (int) (getHeight() * 0.1);
int diffHeight = (int) (getHeight() * 0.05);
int diffWidth = (int) (diffHeight * ((float) diffBar.getWidth() / (float) diffBar.getHeight()));
int diffX = (int) getWidth() / 2 - diffWidth / 2;
batch.draw(diffBar, getX() + diffX, getY() + diffY - diffHeight, diffWidth, diffHeight);
super.draw(batch, parentAlpha);
}
@Override
......
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