MatchMaster/assets/coin_madness/script/CoinMadnessSettlement.ts

39 lines
1.8 KiB
TypeScript

import CoinMadnessDigits from './CoinMadnessDigits';
const { ccclass, property } = cc._decorator;
@ccclass
export default class CoinMadnessSettlement extends cc.Component {
@property(cc.Node) card: cc.Node = null;
@property(cc.Node) dim: cc.Node = null;
@property(cc.Node) closeButton: cc.Node = null;
@property(cc.Node) helpButton: cc.Node = null;
@property(CoinMadnessDigits) countdown: CoinMadnessDigits = null;
@property(CoinMadnessDigits) amount: CoinMadnessDigits = null;
@property(cc.Label) message: cc.Label = null;
@property(cc.Node) debugTools: cc.Node = null;
private closing = false;
initialize(data: any, api: any) {
const size = cc.view.getVisibleSize();
this.node.setContentSize(size); this.dim.setContentSize(size);
const scale = .9 * Math.min((size.width - 96) / this.card.width, (size.height - 96) / this.card.height);
this.card.scale = scale * .86;
cc.tween(this.card).to(.2, { scale: scale * 1.035 }, { easing: 'quadOut' })
.to(.12, { scale }, { easing: 'sineOut' }).start();
this.countdown.setText('00:00:00');
this.amount.setText(String(data.state.settlementCoins || 0));
this.amount.node.active = data.state.settlementCoins > 0;
this.closeButton.on(cc.Node.EventType.TOUCH_END, (event: cc.Event.EventTouch) => {
event.stopPropagation();
if (this.closing) return;
this.closing = true;
cc.Tween.stopAllByTarget(this.card);
cc.tween(this.card).to(.15, { scale: scale * .9 }).call(() => api.close()).start();
});
if (this.helpButton) this.helpButton.active = false;
this.debugTools.active = false;
this.message.node.active = false;
}
onDestroy() { cc.Tween.stopAllByTarget(this.card); }
}