summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/tankontank/menu/MainMenu.java
blob: ed03d0892276e65a8f9ef006a1598c72ba1db08c (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package ch.asynk.tankontank.menu;

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

import ch.asynk.tankontank.ui.Label;
import ch.asynk.tankontank.ui.Patch;

public class MainMenu extends Patch
{
    public static int PADDING = 40;
    public static int VSPACING = 20;

    private Label options;
    private Label scenarios;
    private Label tutorial;
    private Label exit;

    public enum Menu {
        OPTIONS,
        TUTORIALS,
        SCENARIOS,
        NONE
    };
    private Menu menu;

    public MainMenu(BitmapFont font, TextureAtlas atlas)
    {
        super(atlas.createPatch("typewriter"));
        this.options = new Label(font);
        this.scenarios = new Label(font);
        this.tutorial = new Label(font);
        this.exit = new Label(font);
        this.menu = Menu.NONE;

        options.write("Options");
        scenarios.write("Scenarios");
        tutorial.write("Tutorial");
        exit.write("Quit");
    }

    public Menu getMenu()
    {
        return menu;
    }

    public void setPosition()
    {
        float h = ((4 * tutorial.getHeight()) + (2 * PADDING) + (3 * VSPACING));
        float w = (scenarios.getWidth() + (2 * PADDING));
        float x = position.getX(w);
        float y = position.getY(h);
        setPosition(x, y, w, h);

        y += PADDING;
        x += PADDING;
        float dy = (VSPACING + tutorial.getHeight());

        exit.setPosition(x, y);
        y += dy;
        options.setPosition(x, y);
        y += dy;
        tutorial.setPosition(x, y);
        y += dy;
        scenarios.setPosition(x, y);
    }

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

        if (!visible) return ret;

        if (scenarios.hit(x, y)) {
            menu = Menu.SCENARIOS;
            ret = true;
        } else if (tutorial.hit(x, y)) {
            menu = Menu.TUTORIALS;
            ret = true;
        } else if (options.hit(x, y)) {
            menu = Menu.OPTIONS;
            ret = true;
        } else if (exit.hit(x, y)) {
            Gdx.app.exit();
        }

        return ret;
    }

    @Override
    public void dispose()
    {
        super.dispose();
        scenarios.dispose();
        tutorial.dispose();
        options.dispose();
        exit.dispose();
    }

    @Override
    public void draw(Batch batch)
    {
        if (!visible) return;
        super.draw(batch);
        scenarios.draw(batch);
        tutorial.draw(batch);
        options.draw(batch);
        exit.draw(batch);
    }
}