GameSceneUnlockTip.ts
1.99 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
// Learn TypeScript:
// - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
// - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
import { SaveDataManager } from "../../component/SaveDataManager";
import { GameSceneObjTable } from "../../kernel/table/TableDefine";
import { MainSceneData } from "../../scenes/MainSceneData";
const { ccclass, property } = cc._decorator;
@ccclass
export default class GameSceneUnlockTip extends cc.Component {
private _obj: GameSceneObjTable;
private _txtNum: cc.Label;
private _txtName: cc.Label;
private _btn: cc.Node;
//#region LIFE-CYCLE CALLBACKS:
onLoad() {
this._txtNum = this.node.getChildByName('btnUnlock').getComponentInChildren(cc.Label);
this._txtName = this.node.getChildByName('txtName').getComponent(cc.Label);
this._btn = this.node.getChildByName('btnUnlock');
}
// update (dt) {}
//#endregion
//#region public method
setObj(obj: GameSceneObjTable) {
this._obj = obj;
this.refresh();
}
//#endregion
//#region event
onClick() {
if (this._obj && !MainSceneData.isUnlockAni) {
this.node.active = false;
if (SaveDataManager.ins.runtimeData.star >= this._obj.Star) {
let wpos = this._btn.convertToWorldSpaceAR(cc.v3(0, 0, 0));
if (SaveDataManager.ins.adjustStar(-this._obj.Star, true, wpos)) {
SaveDataManager.ins.unlockGameSceneObj(this._obj.ID);
}
}
}
}
//#endregion
//#region private method
private refresh() {
this._txtName.string = this._obj.Name;
this._txtNum.string = this._obj.Star.toString();
this._btn.getComponent(cc.Button).interactable = SaveDataManager.ins.runtimeData.star >= this._obj.Star;
}
//#endregion
}