| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214 |
- import { AudioManager } from "../configData/AudioManager";
- import DataObj from "../configData/DataObj";
- import GameConfig from "../configData/GameConfig";
- import viewComtent from "../game/UIFace/viewComtent";
- import mainManager from "./mainManager";
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default class talantNode extends cc.Component {
- /**背景 */
- @property(cc.Prefab)
- private zhehzao: cc.Prefab = null;
- /**背景 */
- @property(cc.Sprite)
- private mainbg: cc.Sprite = null;
- /**名字 */
- @property(cc.Sprite)
- private title: cc.Sprite = null;
- /**滚轮 */
- @property(cc.ScrollView)
- private scroll: cc.ScrollView = null;
- /**可视图 */
- @property(cc.Node)
- private view: cc.Node = null;
- /**容器 */
- @property(cc.Node)
- private content: cc.Node = null;
- /**升级按钮 */
- @property(cc.Button)
- private upbtn: cc.Button = null;
- // /**关闭按钮 */
- // @property(cc.Button)
- // private closebtn: cc.Button = null;
- /**天赋名字 */
- @property(cc.Label)
- private skillname: cc.Label = null;
- /**描述 */
- @property(cc.Label)
- private skillword: cc.Label = null;
- /**星星总数 */
- @property(cc.Label)
- private total: cc.Label = null;
- /**单个天赋价格 */
- @property(cc.Label)
- private saleNum: cc.Label = null;
- /**天赋图标 */
- @property(cc.Sprite)
- private talantIcon: cc.Sprite = null;
- /**天赋icon数组 */
- private skillIcon: cc.SpriteFrame[] = [];
- /**选择ID */
- private seleId = 1;
- /**icon */
- private iconSpr:cc.Sprite[] = [];
- private norMaterial:cc.Material = cc.Material.getBuiltinMaterial('2d-sprite');
- private grayMaterial:cc.Material = cc.Material.getBuiltinMaterial('2d-gray-sprite');
- public myDataObj: DataObj = null;
- public static instance: talantNode = null;
- protected onLoad() {
- talantNode.instance = this;
- this.node.opacity = 255;
- this.mainbg.node.on(cc.Node.EventType.TOUCH_START, this.onTouchStart, this);
- this.myDataObj = new DataObj();
- this.initPos();
- this.loadSprite();
- this.scroll.scrollToOffset(cc.v2());
- }
- /**初始化坐标 */
- private initPos() {
- let hetgt = viewComtent.instance.getWinsize().y;
- // let closepos = this.closebtn.node.getPosition();
- // this.closebtn.node.setPosition(closepos.x, hetgt/2 - 62);
- this.title.node.setPosition(0, hetgt/2 - 72);
- this.total.string = '' + GameConfig.instance().storageData.starNum;
- }
- /**加载图片 */
- private loadSprite() {
- let self = this;
- self.skillIcon = [];
- cc.resources.load("talant/itembg", cc.SpriteFrame, function (err, myspriteFrame: cc.SpriteFrame) {
- for (let i = 0; i < 6; i++) {
- let mynode = new cc.Node();
- let spr = mynode.addComponent(cc.Sprite);
- spr.spriteFrame = myspriteFrame;
- mynode.setPosition(0, self.content.getContentSize().height / 2 - 300 - 207 * i);
- self.content.addChild(mynode);
- }
- });
- let strArr = ["sele_tower_build_4","sele_tower_build_1","sele_tower_build_2","sele_tower_build_3","yunshiicon","yuanbinicon"];
- for (let i = 0; i < 6; i++) {
- cc.resources.load("game/"+strArr[i], cc.SpriteFrame, function (err, myspriteFrame: cc.SpriteFrame) {
- let mynode = new cc.Node();
- let spr = mynode.addComponent(cc.Sprite);
- spr.spriteFrame = myspriteFrame;
- mynode.setPosition(-500, self.content.getContentSize().height / 2 - 300 - 207 * i);
- self.content.addChild(mynode);
- });
- }
- for (let i = 0; i < 30; i++) {
- self.skillIcon.push(null);
- }
- let coint = 0;
- for (let i = 0; i < 30; i++) {
- this.myDataObj.writeTalent_Config(i+1);
- cc.resources.load("talant/" + this.myDataObj.talentData.talent_icon, cc.SpriteFrame, function (err, myspriteFrame: cc.SpriteFrame) {
- let mynode = new cc.Node();
- let spr = mynode.addComponent(cc.Sprite);
- spr.spriteFrame = myspriteFrame;
- self.skillIcon[i] = myspriteFrame;
- mynode.setPosition(-322 + (i % 5) * 200, self.content.getContentSize().height / 2 - 300 - 207 * Math.floor((i / 5)));
- self.content.addChild(mynode);
- mynode.on(cc.Node.EventType.TOUCH_START, function () {
- self.tapSkillId(i + 1);
- }, self);
- coint++;
- if (coint == 30) {
- self.tapSkillId(self.seleId);
- }
- let isKaiqi = GameConfig.instance().storageData.myTalant[i];
- if (isKaiqi == 0) {
- spr.setMaterial(0, self.grayMaterial);
- }
- self.iconSpr.push(spr);
- });
- }
- }
- private loadTowerPic()
- {
- }
- /**点击各个天赋标志 */
- private tapSkillId(ID: number) {
- // console.log('-----------:' + ID);
- this.seleId = ID;
- this.myDataObj.writeTalent_Config(ID);
- this.skillname.string = this.myDataObj.talentData.name;
- this.skillword.string = this.myDataObj.talentData.talent_text;
- this.talantIcon.spriteFrame = this.skillIcon[ID - 1];
- this.saleNum.string = '' + this.myDataObj.talentData.star_required;
- this.saleNum.node.color = cc.color(142,105,52);
- this.setIsShowUpBtn(ID);
- }
- /**判断升级按钮是否能显示 */
- private setIsShowUpBtn(ID: number) {
- let isKaiqi = GameConfig.instance().storageData.myTalant[ID - 1];
- this.upbtn.node.active = false;
- if (isKaiqi == 0) {
- if ((ID - 1) % 5 == 0) {
- this.upbtn.node.active = true;
- }
- else {
- if (GameConfig.instance().storageData.myTalant[ID - 2] == 1) {
- this.upbtn.node.active = true;
- }
- }
-
- let starNum = GameConfig.instance().storageData.starNum;
- if (starNum < this.myDataObj.talentData.star_required) {
- this.upbtn.node.active = false;
- this.saleNum.node.color = cc.color(255,0,0);
- }
- }
- }
- private onTouchStart(e: cc.Event.EventTouch): void {
- }
- /**升级天赋 */
- private upTalant() {
- AudioManager.palyAudio(6);
- let starNum = GameConfig.instance().storageData.starNum;
- if (starNum >= this.myDataObj.talentData.star_required) {
- GameConfig.instance().storageData.starNum -= this.myDataObj.talentData.star_required;
- GameConfig.instance().storageData.myTalant[this.seleId - 1] = 1;
- GameConfig.instance().setStorage();
- this.total.string = '' + GameConfig.instance().storageData.starNum;
- this.iconSpr[this.seleId - 1].setMaterial(0, this.norMaterial);
- this.upbtn.node.active = false;
- }
- }
- /**关闭界面 */
- private closed() {
- AudioManager.palyAudio(6);
- mainManager.instance.initData();
- this.node.destroy();
- }
- }
|