source: 2014/30/MiskaK/The Reclaim/The Reclaim/The Reclaim/The Reclaim/HUD.cs @ 5689

Revision 5689, 2.8 KB checked in by anlakane, 5 years ago (diff)

Esittelyversio

Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using Jypeli;
6
7public class HUD
8{
9    public GameObject IdleIndicator { get; set; }
10    public GameObject MoveIndicator { get; set; }
11    public GameObject ShootIndicator { get; set; }
12
13    public Vector SelectedSize;
14    public Vector UnselectedSize;
15
16    public Vector BottomLeftCorner;
17
18    public double ButtonSpacing = 15.0;
19
20    public delegate void HUDHandler(Behaviour selected);
21    public event HUDHandler Clicked;
22
23    public HUD(Vector bottomLeftCorner, Image idle, Image move, Image shoot, int layer)
24    {
25        IdleIndicator = new GameObject(idle);
26        The_Reclaim.Peli.Add(IdleIndicator, layer);
27
28        MoveIndicator = new GameObject(move);
29        The_Reclaim.Peli.Add(MoveIndicator, layer);
30
31        ShootIndicator = new GameObject(shoot);
32        The_Reclaim.Peli.Add(ShootIndicator, layer);
33
34        SelectedSize = IdleIndicator.Size / 2;
35        UnselectedSize = SelectedSize / 2;
36        BottomLeftCorner = bottomLeftCorner;
37
38        Refresh(Behaviour.Idle);
39
40        The_Reclaim.Peli.Mouse.ListenOn(IdleIndicator, MouseButton.Left, ButtonState.Pressed, Selected, null, Behaviour.Idle);
41        The_Reclaim.Peli.Mouse.ListenOn(MoveIndicator, MouseButton.Left, ButtonState.Pressed, Selected, null, Behaviour.Move);
42        The_Reclaim.Peli.Mouse.ListenOn(ShootIndicator, MouseButton.Left, ButtonState.Pressed, Selected, null, Behaviour.Shoot);
43
44    }
45
46    public void Refresh(Behaviour selected)
47    {
48        switch (selected)
49        {
50            case Behaviour.Idle:
51                IdleIndicator.Size = SelectedSize;
52                MoveIndicator.Size = UnselectedSize;
53                ShootIndicator.Size = UnselectedSize;
54                break;
55            case Behaviour.Move:
56                IdleIndicator.Size = UnselectedSize;
57                MoveIndicator.Size = SelectedSize;
58                ShootIndicator.Size = UnselectedSize;
59                break;
60            case Behaviour.Shoot:
61                IdleIndicator.Size = UnselectedSize;
62                MoveIndicator.Size = UnselectedSize;
63                ShootIndicator.Size = SelectedSize;
64                break;
65            default:
66                break;
67        }
68        IdleIndicator.Left = BottomLeftCorner.X;
69        IdleIndicator.Bottom = BottomLeftCorner.Y;
70
71        MoveIndicator.Left = IdleIndicator.Right + ButtonSpacing;
72        MoveIndicator.Bottom = BottomLeftCorner.Y;
73
74        ShootIndicator.Left = MoveIndicator.Right + ButtonSpacing;
75        ShootIndicator.Bottom = BottomLeftCorner.Y;
76    }
77
78    private void Selected(Behaviour selected)
79    {
80        if (Clicked != null)
81            Clicked(selected);
82        Refresh(selected);
83    }
84}
Note: See TracBrowser for help on using the repository browser.