forked from Guad/NativeUI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUIMenuCheckboxItem.cs
More file actions
90 lines (77 loc) · 2.78 KB
/
UIMenuCheckboxItem.cs
File metadata and controls
90 lines (77 loc) · 2.78 KB
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
using System;
using System.Drawing;
namespace NativeUI
{
public class UIMenuCheckboxItem : UIMenuItem
{
protected Sprite _checkedSprite;
/// <summary>
/// Triggered when the checkbox state is changed.
/// </summary>
public event ItemCheckboxEvent CheckboxEvent;
/// <summary>
/// Checkbox item with a toggleable checkbox.
/// </summary>
/// <param name="text">Item label.</param>
/// <param name="check">Boolean value whether the checkbox is checked.</param>
public UIMenuCheckboxItem(string text, bool check)
: this(text, check, "")
{
}
/// <summary>
/// Checkbox item with a toggleable checkbox.
/// </summary>
/// <param name="text">Item label.</param>
/// <param name="check">Boolean value whether the checkbox is checked.</param>
/// <param name="description">Description for this item.</param>
public UIMenuCheckboxItem(string text, bool check, string description)
: base(text, description)
{
const int y = 0;
_checkedSprite = new Sprite("commonmenu", "shop_box_blank", new Point(410, y + 95), new Size(50, 50));
Checked = check;
}
/// <summary>
/// Change or get whether the checkbox is checked.
/// </summary>
public bool Checked { get; set; }
/// <summary>
/// Change item's position.
/// </summary>
/// <param name="y">New Y value.</param>
public override void Position(int y)
{
base.Position(y);
_checkedSprite.Position = new Point(380 + Offset.X + Parent.WidthOffset, y + 138 + Offset.Y);
}
/// <summary>
/// Draw item.
/// </summary>
public override void Draw()
{
base.Draw();
_checkedSprite.Position = _checkedSprite.Position = new Point(380 + Offset.X + Parent.WidthOffset, _checkedSprite.Position.Y);
if (Selected)
{
_checkedSprite.TextureName = Checked ? "shop_box_tickb" : "shop_box_blankb";
}
else
{
_checkedSprite.TextureName = Checked ? "shop_box_tick" : "shop_box_blank";
}
_checkedSprite.Draw();
}
public void CheckboxEventTrigger()
{
CheckboxEvent?.Invoke(this, Checked);
}
public override void SetRightBadge(BadgeStyle badge)
{
throw new Exception("UIMenuCheckboxItem cannot have a right badge.");
}
public override void SetRightLabel(string text)
{
throw new Exception("UIMenuListItem cannot have a right label.");
}
}
}