/
UIMenuCheckboxItem.ts
64 lines (56 loc) · 1.84 KB
/
UIMenuCheckboxItem.ts
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
import { Sprite } from '../../';
import { BadgeStyle } from '../../../enums';
import { Color, LiteEvent, Point, Size } from '../../../utils';
import { UIMenuItem } from './';
export class UIMenuCheckboxItem extends UIMenuItem {
public checked: boolean = false;
private readonly checkedSprite: Sprite;
private readonly oncheckedChanged = new LiteEvent();
public get checkedChanged() {
return this.oncheckedChanged.expose();
}
constructor(text: string, check: boolean = false, description: string = '') {
super(text, description);
const y = 0;
this.checkedSprite = new Sprite(
'commonmenu',
'shop_box_blank',
new Point(410, y + 95),
new Size(50, 50),
);
this.checked = check;
}
public setVerticalPosition(y: number) {
super.setVerticalPosition(y);
this.checkedSprite.pos = new Point(
380 + this.offset.X + this.parent.widthOffset,
y + 138 + this.offset.Y,
);
}
public draw() {
super.draw();
this.checkedSprite.pos = this.checkedSprite.pos = new Point(
380 + this.offset.X + this.parent.widthOffset,
this.checkedSprite.pos.Y,
);
const isDefaultHightlitedForeColor =
this.highlightedForeColor === UIMenuItem.defaultHighlightedForeColor;
if (this.selected && isDefaultHightlitedForeColor) {
this.checkedSprite.textureName = this.checked ? 'shop_box_tickb' : 'shop_box_blankb';
} else {
this.checkedSprite.textureName = this.checked ? 'shop_box_tick' : 'shop_box_blank';
}
this.checkedSprite.color = this.enabled
? this.selected && !isDefaultHightlitedForeColor
? this.highlightedForeColor
: this.foreColor
: new Color(255, 163, 159, 148);
this.checkedSprite.draw();
}
public setRightBadge(badge: BadgeStyle) {
return this;
}
public setRightLabel(text: string) {
return this;
}
}