summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/rustanddust/game/hud/StatisticsPanel.java
blob: 57780af6e7a568ec171e1a1fe434b4479a48b780 (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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package ch.asynk.rustanddust.game.hud;

import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;

import ch.asynk.rustanddust.RustAndDust;
import ch.asynk.rustanddust.game.Player;
import ch.asynk.rustanddust.game.Army;
import ch.asynk.rustanddust.ui.Bg;
import ch.asynk.rustanddust.ui.Label;
import ch.asynk.rustanddust.ui.Patch;
import ch.asynk.rustanddust.ui.Position;

public class StatisticsPanel extends Patch
{
    public static int PADDING = 60;
    public static int VSPACING = 10;
    public static int HSPACING = 10;

    private Label title;
    private Label header;
    private Label stats1;
    private Label stats2;
    private Bg okBtn;
    private Bg flag;
    private Bg geFlag;
    private Bg usFlag;

    public StatisticsPanel(RustAndDust game)
    {
        super(game.bgPatch);
        this.title = new Label(game.font);
        this.header = new Label(game.font);
        this.stats1 = new Label(game.font);
        this.stats2 = new Label(game.font);
        this.okBtn = new Bg(game.factory.getHudRegion(game.factory.ACT_DONE));
        this.usFlag = new Bg(game.factory.getFlag(Army.US));
        this.geFlag = new Bg(game.factory.getFlag(Army.GE));
        this.visible = false;
        this.header.write("\nActions\nUnits Left\nUnits Withrawed\nCasualties\nObjectives");
    }

    public void updatePosition()
    {
        if (!visible) return;
        float dx = (position.getX(rect.width) - rect.x);
        float dy = (position.getY(rect.height) - rect.y);
        translate(dx, dy);
        flag.translate(dx, dy);
        title.translate(dx, dy);
        header.translate(dx, dy);
        stats1.translate(dx, dy);
        stats2.translate(dx, dy);
        okBtn.translate(dx, dy);
    }

    public void show(Player winner, Player loser, Position position)
    {
        flag = ((winner.army == Army.US) ? usFlag : geFlag);
        title.write("is triumphant in " + winner.getTurn() + " turns.");
        stats1.write(winner.getStats());
        stats2.write(loser.getStats());

        float height = (flag.getHeight() + header.getHeight() + (2 * PADDING) + (1 * VSPACING));
        float width = (header.getWidth() + stats1.getWidth() + stats2.getWidth() + (2 * PADDING) + (4 * HSPACING));
        float w2 = (flag.getWidth() + HSPACING + title.getWidth() + (2 * PADDING));
        if (w2 > width) width = w2;
        float x = position.getX(width);
        float y = position.getY(height);
        setPosition(x, y, width, height);

        setBottomRight(okBtn);

        y += PADDING;
        x += PADDING;
        header.setPosition(x, y);
        stats1.setPosition((x + header.getWidth() + (2 * HSPACING)), y);
        stats2.setPosition((stats1.getX() + stats1.getWidth() + (2 * HSPACING)), y);
        y += (header.getHeight() + VSPACING);
        flag.setPosition(x, y);
        title.setPosition(x + flag.getWidth() + VSPACING, y + flag.getHeight() / 3);
        visible = true;
    }

    @Override
    public boolean hit(float x, float y)
    {
        return (rect.contains(x, y) || okBtn.hit(x, y));
    }

    @Override
    public void dispose()
    {
        super.dispose();
        geFlag.dispose();
        usFlag.dispose();
        title.dispose();
        header.dispose();
        stats1.dispose();
        stats2.dispose();
        okBtn.dispose();
    }

    @Override
    public void draw(Batch batch)
    {
        if (!visible) return;
        super.draw(batch);
        flag.draw(batch);
        title.draw(batch);
        header.draw(batch);
        stats1.draw(batch);
        stats2.draw(batch);
        okBtn.draw(batch);
    }

    @Override
    public void drawDebug(ShapeRenderer shapes)
    {
        if (!visible) return;
        super.drawDebug(shapes);
        flag.drawDebug(shapes);
        title.drawDebug(shapes);
        header.drawDebug(shapes);
        stats1.drawDebug(shapes);
        stats2.drawDebug(shapes);
        okBtn.drawDebug(shapes);
    }
}