You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
165 lines
6.2 KiB
165 lines
6.2 KiB
// Learn TypeScript:
|
|
// - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
|
|
// Learn Attribute:
|
|
// - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
|
|
// Learn life-cycle callbacks:
|
|
// - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html
|
|
|
|
import { ryw_Event } from "../../FrameWork/Event/EventEnum";
|
|
import EventMgr from "../../FrameWork/Event/EventMgr";
|
|
import User from "../../FrameWork/User/User";
|
|
import Common5 from "../../Platform/th/Common5";
|
|
import TaskManager, { MainTaskIdEnum } from "../JuQingChat/TaskManager";
|
|
import BagManager from "../Manager/BagManager";
|
|
import LevelUpManager from "../Manager/LevelUpManager";
|
|
import ShipuManager from "../Manager/ShipuManager";
|
|
import UserManager from "../Manager/UserManager";
|
|
import PrefabManage, { GameType } from "../PrefabManager/PrefabManage";
|
|
|
|
const { ccclass, property } = cc._decorator;
|
|
|
|
@ccclass
|
|
export default class ZiChanItemNode extends cc.Component {
|
|
|
|
@property(cc.Sprite)
|
|
icon: cc.Sprite = null;
|
|
|
|
@property(cc.Label)
|
|
title_str: cc.Label = null;
|
|
|
|
@property(cc.Label)
|
|
shuliang: cc.Label = null;
|
|
|
|
@property(cc.Label)
|
|
beishu: cc.Label = null;
|
|
|
|
@property(cc.Label)
|
|
money: cc.Label = null;
|
|
|
|
@property(cc.Label)
|
|
str1: cc.Label = null;
|
|
|
|
@property(cc.Label)
|
|
str2: cc.Label = null;
|
|
|
|
@property(cc.Node)
|
|
down: cc.Node = null;
|
|
@property(cc.Node)
|
|
kuang: cc.Node = null;
|
|
@property(cc.Node)
|
|
btn_shop: cc.Node = null;
|
|
@property(cc.Node)
|
|
btn_weijiesuo: cc.Node = null;
|
|
@property(cc.Node)
|
|
yiwancheng: cc.Node = null;
|
|
@property(cc.Node)
|
|
fengyin: cc.Node = null;
|
|
|
|
config: any;
|
|
|
|
// LIFE-CYCLE CALLBACKS:
|
|
|
|
// onLoad () {}
|
|
|
|
start() {
|
|
|
|
}
|
|
|
|
init(data) {
|
|
this.config = data
|
|
// Common5.addUrlSprite_custom(this.config.icon, this.icon)
|
|
Common5.getSpriteFrameFromBundle("ZiChan", this.config.icon, this.icon)
|
|
this.title_str.string = data.descLab
|
|
let ziChanData = User.getZiChanData()
|
|
let level = User.getMyLevel()
|
|
//是否满足解锁条件
|
|
if (ziChanData.unLockNum[this.config.configId] == -1 && ShipuManager.getShipuUnLockNum() >= this.config.unLockNum && level >= this.config.unLockLevel) {
|
|
ziChanData.unLockNum[this.config.configId] = 0
|
|
}
|
|
if (ziChanData.unLockNum[this.config.configId] == -1 && ShipuManager.getShipuUnLockNum() >= this.config.unLockNum) {
|
|
// 变棕色
|
|
this.str1.node.color = cc.color(33, 152, 0)
|
|
}
|
|
if (ziChanData.unLockNum[this.config.configId] == -1 && level >= this.config.unLockLevel) {
|
|
// 变棕色
|
|
this.str2.node.color = cc.color(33, 152, 0)
|
|
}
|
|
let unLockNum = ziChanData.unLockNum[this.config.configId] <= 0 ? 0 : ziChanData.unLockNum[this.config.configId]
|
|
this.shuliang.string = `数量:${unLockNum}/${data.shuliang}`
|
|
if (unLockNum > 0) {
|
|
this.beishu.string = `秒赚倍数:${this.config.miaozhuan[unLockNum - 1]}倍`
|
|
} else {
|
|
this.beishu.string = `秒赚倍数:${0}倍`
|
|
}
|
|
if (unLockNum >= 0) {
|
|
this.money.string = `${Common5.getNumberChangeHanzi(this.config.jiesuoMoney[unLockNum])}` //下一个购买需要的钱
|
|
}
|
|
this.str1.string = `${this.config.str1}`
|
|
this.str2.string = `${this.config.str2}`
|
|
this.refreshState()
|
|
}
|
|
|
|
refreshState() {
|
|
this.down.active = false
|
|
this.kuang.active = false
|
|
this.btn_shop.active = false
|
|
this.btn_weijiesuo.active = false
|
|
this.yiwancheng.active = false
|
|
this.fengyin.active = false
|
|
let ziChanData = User.getZiChanData()
|
|
if (ziChanData.unLockNum[this.config.configId] == -1) {
|
|
this.btn_weijiesuo.active = true
|
|
this.kuang.active = true
|
|
} else if (ziChanData.unLockNum[this.config.configId] < this.config.shuliang) {
|
|
this.btn_shop.active = true
|
|
this.down.active = true
|
|
} else {
|
|
if (this.config.name == '镇中心门店' && TaskManager.getCurUnLockMainTaskId() >= MainTaskIdEnum.MainTask_516_1 && TaskManager.getCurUnLockMainTaskId() <= MainTaskIdEnum.MainTask_517) {
|
|
this.fengyin.active = true
|
|
}else{
|
|
this.yiwancheng.active = true
|
|
}
|
|
}
|
|
}
|
|
|
|
onTouchShop() {
|
|
// //Common5.playEffect("sound/按键点击")
|
|
Common5.playRemoteAudioEffect('sound/diandiandian/升级音效')
|
|
let ziChanData = User.getZiChanData()
|
|
//是否满足解锁条件
|
|
if (ziChanData.unLockNum[this.config.configId] == -1 && ShipuManager.getShipuUnLockNum() >= this.config.unLockNum) {
|
|
ziChanData.unLockNum[this.config.configId] = 0
|
|
}
|
|
UserManager.subMoney(this.config.jiesuoMoney[ziChanData.unLockNum[this.config.configId]])
|
|
|
|
// ziChanData = {curshouyi:0,getnum:0,shouyi:0,unLockNum:[-1,-1,-1,-1]}
|
|
if (ziChanData.unLockNum[this.config.configId] == -1) {
|
|
ziChanData.unLockNum[this.config.configId] = 1
|
|
} else {
|
|
ziChanData.unLockNum[this.config.configId] += 1
|
|
}
|
|
User.setZiChanData(ziChanData)
|
|
this.init(this.config)
|
|
EventMgr.emitEvent_custom(ryw_Event.RefreshZiChan)
|
|
|
|
this.checkTask()
|
|
}
|
|
|
|
checkTask() {
|
|
let ziChanData = User.getZiChanData()
|
|
let mainTaskInfo: any = TaskManager.getCurUnLockMainTaskInfo()
|
|
let mainId = mainTaskInfo.Id
|
|
// if (mainId == MainTaskIdEnum.MainTask_514_2 && ziChanData.unLockNum[0] >= 1) {
|
|
// TaskManager.finishCurMainTask(MainTaskIdEnum.MainTask_514_2)
|
|
// TaskManager.setCurTask(MainTaskIdEnum.MainTask_515)
|
|
// }else if (mainId == MainTaskIdEnum.MainTask_532 && ziChanData.unLockNum[1] >= 1) {
|
|
// TaskManager.finishCurMainTask(MainTaskIdEnum.MainTask_532)
|
|
// TaskManager.setCurTask(MainTaskIdEnum.MainTask_533)
|
|
// }else if (mainId == MainTaskIdEnum.MainTask_542 && ziChanData.unLockNum[2] >= 1) {
|
|
// TaskManager.finishCurMainTask(MainTaskIdEnum.MainTask_542)
|
|
// TaskManager.setCurTask(MainTaskIdEnum.MainTask_543_1)
|
|
// }
|
|
}
|
|
|
|
// update (dt) {}
|
|
}
|
|
|