blob: e81fe07bba2ed725da515776feb22982ef750eb7 (
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
  | 
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.ui.Label;
import ch.asynk.rustanddust.ui.Patch;
import ch.asynk.rustanddust.ui.Position;
import ch.asynk.rustanddust.game.Battle;
public class ObjectivesPanel extends Patch
{
    public static int PADDING = 60;
    public static int TITLE_PADDING = 5;
    public static int LABEL_PADDING = 10;
    private Label title;
    private Label content;
    public ObjectivesPanel(RustAndDust game)
    {
        super(game.bgPatch);
        this.title = new Label(game.font, LABEL_PADDING);
        this.content = new Label(game.font, LABEL_PADDING);
        this.visible = false;
    }
    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);
    }
    public void show(Battle battle)
    {
        this.title.write(String.format(" - %s -", battle.getName()));
        this.content.write(battle.getDescription());
        show(Position.MIDDLE_CENTER);
    }
    public void show(Position position)
    {
        float h = (title.getHeight() + TITLE_PADDING);
        h += content.getHeight();
        h += (2 * PADDING);
        float w = (content.getWidth());
        w += (2 * PADDING);
        float x = position.getX(w);
        float y = position.getY(h);
        setPosition(x, y, w, h);
        y += PADDING;
        x += PADDING;
        content.setPosition(x, y);
        y += content.getHeight();
        y += TITLE_PADDING;
        title.setPosition(x, y);
        visible = true;
    }
    @Override
    public boolean hit(float x, float y)
    {
        if (!visible) return false;
        // if (super.hit(x,y)) return true;
        return true;
    }
    @Override
    public void dispose()
    {
        super.dispose();
        title.dispose();
        content.dispose();
    }
    @Override
    public void draw(Batch batch)
    {
        if (!visible) return;
        super.draw(batch);
        title.draw(batch);
        content.draw(batch);
    }
    @Override
    public void drawDebug(ShapeRenderer shapes)
    {
        if (!visible) return;
        super.drawDebug(shapes);
        title.drawDebug(shapes);
        content.drawDebug(shapes);
    }
}
  |