1 package ru
.deadsoftware
.cavedroid
.menu
;
3 import com
.badlogic
.gdx
.Gdx
;
4 import com
.badlogic
.gdx
.utils
.Array
;
5 import ru
.deadsoftware
.cavedroid
.CaveGame
;
6 import ru
.deadsoftware
.cavedroid
.GameScreen
;
7 import ru
.deadsoftware
.cavedroid
.game
.GameItems
;
8 import ru
.deadsoftware
.cavedroid
.game
.GameSaver
;
9 import ru
.deadsoftware
.cavedroid
.menu
.objects
.Button
;
10 import ru
.deadsoftware
.cavedroid
.misc
.AppState
;
11 import ru
.deadsoftware
.cavedroid
.misc
.Assets
;
12 import ru
.deadsoftware
.cavedroid
.misc
.Renderer
;
14 public class MenuRenderer
extends Renderer
{
16 public Array
<Button
> menuMainBtns
;
17 public Array
<Button
> menuNGBtns
;
19 public MenuRenderer(int width
) {
20 super(width
, width
* ((float) GameScreen
.getHeight() / GameScreen
.getWidth()));
22 menuMainBtns
= new Array
<Button
>();
23 menuMainBtns
.add(new Button("New game", getWidth() / 2 - 100, getHeight() / 4));
24 menuMainBtns
.add(new Button("Load game", getWidth() / 2 - 100, getHeight() / 4 + 30, GameSaver
.exists() ?
1 : 0));
25 menuMainBtns
.add(new Button("Quit", getWidth() / 2 - 100, getHeight() / 4 + 60));
27 menuNGBtns
= new Array
<Button
>();
28 menuNGBtns
.add(new Button("Survival", getWidth() / 2 - 100, getHeight() / 4, 0));
29 menuNGBtns
.add(new Button("Creative", getWidth() / 2 - 100, getHeight() / 4 + 30));
30 menuNGBtns
.add(new Button("Back", getWidth() / 2 - 100, getHeight() / 4 + 60));
34 public void buttonClicked(Button button
) {
35 if (button
.getLabel().toLowerCase().equals("new game")) {
36 CaveGame
.STATE
= AppState
.MENU_NEW_GAME
;
37 } else if (button
.getLabel().toLowerCase().equals("load game")) {
38 CaveGame
.STATE
= AppState
.GOTO_LOAD_GAME
;
39 } else if (button
.getLabel().toLowerCase().equals("quit")) {
41 } else if (button
.getLabel().toLowerCase().equals("survival")) {
42 GameScreen
.NEW_GAME_MODE
= 0;
43 CaveGame
.STATE
= AppState
.GOTO_NEW_GAME
;
44 } else if (button
.getLabel().toLowerCase().equals("creative")) {
45 GameScreen
.NEW_GAME_MODE
= 1;
46 CaveGame
.STATE
= AppState
.GOTO_NEW_GAME
;
47 } else if (button
.getLabel().toLowerCase().equals("back")) {
48 CaveGame
.STATE
= AppState
.MENU_MAIN
;
52 private void drawButton(Button button
) {
53 spriter
.draw(Assets
.menuBtn
[button
.getType()], button
.getX(), button
.getY());
54 setFontColor(255, 255, 255);
55 drawString(button
.getLabel(),
56 (button
.getX() + button
.getWidth() / 2) - (float) Assets
.getStringWidth(button
.getLabel()) / 2,
57 (button
.getY() + button
.getHeight() / 2) - (float) Assets
.getStringHeight(button
.getLabel()) / 2);
60 private void drawButtons(Array
<Button
> buttons
) {
61 for (Button button
: buttons
) {
62 if (button
.getType() > 0) {
63 if (button
.getRect().contains(Gdx
.input
.getX() * getWidth() / GameScreen
.getWidth(),
64 Gdx
.input
.getY() * getHeight() / GameScreen
.getHeight()) &&
65 (!CaveGame
.TOUCH
|| Gdx
.input
.isTouched()))
67 else button
.setType(1);
73 private void drawLabel(String str
) {
78 public void render() {
80 for (int x
= 0; x
<= getWidth() / 16; x
++) {
81 for (int y
= 0; y
<= getHeight() / 16; y
++) {
82 spriter
.draw(GameItems
.getBlock(3).getTex(), x
* 16, y
* 16);
83 spriter
.draw(Assets
.shade
, x
* 16, y
* 16);
86 spriter
.draw(Assets
.gameLogo
, getWidth() / 2 - (float) Assets
.gameLogo
.getWidth() / 2, 8);
88 switch (CaveGame
.STATE
) {
90 drawButtons(menuMainBtns
);
93 drawButtons(menuNGBtns
);
97 drawLabel("Generating World...");
100 drawLabel("Saving Game...");
104 drawString("CaveDroid " + CaveGame
.VERSION
, 0,
105 getHeight() - Assets
.getStringHeight("CaveDroid " + CaveGame
.VERSION
) * 1.5f);
108 switch (CaveGame
.STATE
) {
110 CaveGame
.STATE
= AppState
.NEW_GAME
;
113 CaveGame
.STATE
= AppState
.LOAD_GAME
;
116 CaveGame
.STATE
= AppState
.SAVE_GAME
;