| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- // 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 PropIntroduceNode from "../ui/PropIntroduceNode";
- import { Utils } from "../utils/Utils";
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default class TurntableItem extends cc.Component {
- @property(cc.Sprite)
- icon: cc.Sprite = null;
- @property(cc.Label)
- labNum: cc.Label = null;
- @property(cc.Label)
- labDes: cc.Label = null;
- @property(cc.Node)
- scaleNode: cc.Node = null;
- /** 数据 */
- data = null
- num = 0
- animNum = 0
- rewardPrefab: cc.Prefab = null
- start() {
- }
- async init(data) {
- this.data = data
- this.num = data.num
- this.node.angle = (data.index - 1) * 60
- let self = this
- let path = 'gift/turn_' + data.reward
- if (data.reward == 2) {
- if (data.moneyLevel > 0) {
- path = path + "_" + data.moneyLevel
- }
- }
- this.rewardPrefab = await Utils.loadResPromise('prefabs/TurntableRewardTip')
- // else if(data.reward == 1){
- // self.icon.node.scale = 0.8
- // }else if(data.reward == 3){
- // self.icon.node.scale = 0.6
- // }
- cc.loader.loadRes(path, cc.SpriteFrame, (err, assets) => {
- if (err) {
- cc.error(err);
- return;
- }
- self.icon.spriteFrame = assets;
- })
- //惊喜宝箱
- if (data.reward == 1) {
- this.labNum.string = '' + data.num
- }
- //挂机收益
- else if (data.reward == 2) {
- this.labNum.string = '' + data.num + '分钟'
- }
- //元宝
- else if (data.reward == 3) {
- this.labNum.string = '' + data.num
- }
- else if (data.reward == 4) {
- this.labNum.string = '' + data.num
- }
- // if ((data.index - 1) % 2 == 0) {
- // this.labDes.node.color = cc.color(42, 81, 190)
- // this.labNum.node.color = cc.color(42, 81, 190)
- // }
- // else {
- this.labDes.node.color = cc.color(162, 93, 93);
- this.labNum.node.color = cc.color(162, 93, 93);
- // }
- this.labDes.string = data.txt
- let str = ""
- if (data.reward == 2) {
- str = "用于购买怪物"
- } else if (data.reward == 3) {
- str = "用于提现消耗"
- } else if (data.reward == 4) {
- str = "用于升级伙伴天赋"
- } else {
- str = data.txt
- }
- this.icon.node.on(cc.Node.EventType.TOUCH_START, (touch) => {
- this.showPropIntroduce(str, "", cc.v3(touch.getLocation()))
- }, this)
- }
- updateNum(num: number) {
- if (num != this.num) {
- this.animNum = this.num
- this.num = num
- // this.labNum.string = 'x' + this.num
- this.unschedule(this.showAction)
- this.showRewardNode()
- // this.node.runAction(cc.sequence(cc.scaleTo(1,1.5),cc.scaleTo(1,1)))
- }
- }
- showRewardNode() {
- let rewardNode = cc.instantiate(this.rewardPrefab)
- rewardNode.parent = cc.find("Canvas")
- rewardNode.scale = 0.001
- let worldPos = this.icon.node.parent.convertToWorldSpaceAR(this.icon.node.position)
- let localPos = rewardNode.parent.convertToNodeSpaceAR(worldPos)
- rewardNode.position = localPos
- rewardNode.runAction(cc.sequence(cc.scaleTo(0.2, 1.6), cc.delayTime(0.5), cc.spawn(cc.moveTo(0.4, cc.v2(localPos.x, localPos.y + 100)), cc.fadeOut(0.4)), cc.callFunc(() => {
- if (cc.isValid(rewardNode)) {
- rewardNode.destroy()
- }
- let color = this.labNum.node.color
- this.scaleNode.runAction(cc.sequence(cc.callFunc(() => {
- this.node.parent = this.node.parent.parent.getChildByName("turntable_in")
- this.labNum.node.color = cc.color(250, 245, 69)// cc.Color.RED
- let outline = this.labNum.node.addComponent(cc.LabelOutline)
- outline.color = cc.Color.BLACK
- outline.width = 1
- }), cc.scaleTo(0.3, 1.6), cc.callFunc(() => {
- this.schedule(this.showAction, 0.015)
- }), cc.delayTime((this.num - this.animNum) * 0.016), cc.scaleTo(0.3, 1), cc.callFunc(() => {
- this.node.parent = this.node.parent.parent.getChildByName("turntable_in")
- this.labNum.node.color = color
- this.labNum.node.removeComponent(cc.LabelOutline)
- })))
- })))
- }
- showAction() {
- if (this.animNum < this.num) {
- this.animNum++
- } else {
- if (cc.isValid(this.labNum)) {
- // this.labNum.node.stopAllActions()
- // this.labNum.node.runAction(cc.scaleTo(0.3,1))
- // this.labNum.node.scale = 1
- }
- }
- if (cc.isValid(this.labNum)) {
- this.labNum.string = "" + this.animNum.toString() + "分钟"
- }
- // this.node.runAction(cc.repeat(cc.callFunc(()=>{
- // this.animNum += dur/repeats
- // this.labNum.string =
- // }),repeats))
- }
- async showPropIntroduce(name: string, desc: string, worldPos: cc.Vec3) {
- let canvas = cc.find("Canvas")
- if (cc.isValid(canvas.getChildByName("propIntroduceNode"))) {
- canvas.getChildByName("propIntroduceNode").destroy()
- }
- let propIntroducePrefab = await Utils.loadResPromise("prefabs/propIntroduceNode")
- let propIntroduceNode: cc.Node = cc.instantiate(propIntroducePrefab)
- propIntroduceNode.parent = cc.find("Canvas")
- propIntroduceNode.name = "propIntroduceNode"
- propIntroduceNode.position = cc.find("Canvas").convertToNodeSpaceAR(worldPos)
- propIntroduceNode.y += 60
- propIntroduceNode.x -= 60
- propIntroduceNode.getComponent(PropIntroduceNode).initView(name, desc)
- }
- // update (dt) {}
- }
|