summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/rustanddust/menu/MainMenu.java
blob: ff65d50bbe5dfeae69385ce86d42612d92605ee7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package ch.asynk.rustanddust.menu;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;

import ch.asynk.rustanddust.ui.Menu;

public class MainMenu extends Menu
{
    public enum Items implements Menu.MenuItem
    {
        EXIT(0),
        OPTIONS(1),
        TUTORIALS(2),
        PLAY(3),
        NONE(4);
        public int i;
        Items(int i)
        {
            this.i = i;
        }
        public int i() { return i; }
        public int last() { return NONE.i; }
    };

    public MainMenu(BitmapFont font, TextureAtlas atlas)
    {
        super(Items.NONE, font, atlas.createPatch("typewriter"));

        label(Items.PLAY).write("Play");
        label(Items.TUTORIALS).write("Tutorials");
        label(Items.OPTIONS).write("Options");
        label(Items.EXIT).write("Exit");

        this.visible = true;
    }

    public Items getMenu()
    {
        return (Items) menuItem;
    }

    @Override
    public boolean hit(float x, float y)
    {
        boolean ret = false;
        menuItem = Items.NONE;

        if (!visible) return ret;

        if (label(Items.PLAY).hit(x, y)) {
            menuItem = Items.PLAY;
            ret = true;
        } else if (label(Items.TUTORIALS).hit(x, y)) {
            menuItem = Items.TUTORIALS;
            ret = true;
        } else if (label(Items.OPTIONS).hit(x, y)) {
            menuItem = Items.OPTIONS;
            ret = true;
        } else if (label(Items.EXIT).hit(x, y)) {
            Gdx.app.exit();
        }

        return ret;
    }
}