MainInfoSubviewImpl.ts
2.21 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
import { DummyLabel, DummySprite } from "../../../../common/CCDummyObjects";
import { CCPureSubview } from "../../../../common/classbase/CCViewBase";
import { RegSubview } from "../../PresenterCCViewFactory";
import { MainInfoSubviewProps, MainInfoSubviewType } from "../type/MainInfoSubviewiew";
const { ccclass, property } = cc._decorator;
@ccclass
@RegSubview(MainInfoSubviewType)
export class MainInfoViewImpl extends CCPureSubview<MainInfoSubviewProps> {
//#region editor bindings
@property(cc.Label)
private timeLabel: cc.Label = DummyLabel;
@property(cc.Sprite)
private energySprite: cc.Sprite = DummySprite;
@property(cc.Label)
private energyLabel: cc.Label = DummyLabel;
@property(cc.SpriteFrame)
private energySprites: cc.SpriteFrame[] = [];
@property(cc.Label)
private coolddown: cc.Label = DummyLabel;
//#endregion
onLoad() {
this.updateTime();
this.energySprite.type = cc.Sprite.Type.FILLED;
this.energySprite.fillType = cc.Sprite.FillType.VERTICAL;
this.bindProp("energycontent", (value) => {
this.energyLabel.string = value;
});
this.bindProp("timecontent", (value) => {
if (value === "") {
this.coolddown.node.active = false;
} else {
this.coolddown.node.active = true;
this.coolddown.string = value;
}
});
this.bindProp("energybackindex", (value) => {
this.energySprite.spriteFrame = this.energySprites[value];
});
this.bindProp("energy", (value) => {
this.energySprite.fillRange = value;
});
this.energySprite.node.on(cc.Node.EventType.TOUCH_END, this.onEnergyClickCallback, this);
this.energyLabel.node.on(cc.Node.EventType.TOUCH_END, this.onEnergyClickCallback, this);
}
onEnergyClickCallback = () => {
this._props.onClick();
}
private updateTime = () => {
let now = new Date;
this.timeLabel.string = `${now.getHours()}:${(now.getMinutes() < 10 ? '0' : '') + now.getMinutes()}`;
this.scheduleOnce(() => {
this.scheduleOnce(this.updateTime, 60 - now.getSeconds());
});
}
}