| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- import { _decorator, Component, Node, Label, Sprite, Prefab, instantiate, SpriteFrame, EventHandler } from 'cc';
- import { RewardVideoSystem } from '../../ad/RewardVideoSystem';
- import { DataSystem } from '../../core/data/DataSystem';
- import { Http, HttpResponseCode } from '../../core/net/Http';
- import { HttpSystem } from '../../core/net/HttpSystem';
- import { ResourceLoader } from '../../core/resourceManager/ResourceLoader';
- import { Window } from '../../core/ui/window/Window';
- import { WindowSystem } from '../../core/ui/window/WindowSystem';
- import { ConfigData } from '../../data/ConfigData';
- import { platform } from '../../data/jsb/platform';
- import { UserData } from '../../data/UserData';
- import { NoviceGuideData } from '../../guide/NoviceGuideData';
- import { FormationData } from '../../hero/formation/FormationData';
- import { Hero_Client, UserHeroData } from '../../hero/UserHeroData';
- import { ReportThinking } from '../../ReportThinking';
- import { TurntableUI } from '../../turntable/TurntableUI';
- import { RecruitData } from '../RecruitData';
- import { WishItem } from './WishItem';
- const { ccclass, property } = _decorator;
- /**
- * 心愿武将页
- * @author 郑聂华
- */
- @ccclass('RecruitWishUI')
- export class RecruitWishUI extends Component {
- @property({ type: ResourceLoader, displayName: "资源加载组件", tooltip: "资源加载组件" }) res: ResourceLoader = null;
- @property({ type: Node, displayName: '心愿背景框', tooltip: "心愿背景框" }) wishRect: Node = null;
- @property({ type: Label, displayName: '文本_倍率', tooltip: "文本_倍率" }) txtRate: Label = null;
- @property({ type: Sprite, displayName: '图_心愿武将', tooltip: "图_心愿武将" }) imgWish: Sprite = null;
- @property({ type: Label, displayName: '文本_心愿武将名', tooltip: "文本_心愿武将名" }) txtName: Label = null;
- @property({ type: Sprite, displayName: '图_心愿武将阵营', tooltip: "图_心愿武将阵营" }) imgWishCamp: Sprite = null;
- @property({ type: Node, displayName: "Content", tooltip: "Content" }) content: Node = null;
- @property({ type: Prefab, displayName: "已拥有武将Item", tooltip: "已拥有武将Item" }) wishItemPrefab: Prefab = null;
- @property({ type: Node, displayName: "广告图标_按钮", tooltip: "广告图标_按钮" }) iconAd: Node = null;
- @property({ type: Node, displayName: "广告按钮", tooltip: "广告按钮" }) btnAd: Node = null;
- @property({ type: Node, displayName: "广告按钮置灰", tooltip: "广告按钮置灰" }) btnAdGray: Node = null;
- @property({ type: EventHandler, displayName: "心愿武将回调", tooltip: "心愿武将回调" }) private wishItemBack: EventHandler;
- private selectIndex: number = -1; //选中的index
- private tempWishId: number = -1; //选中的武将id
- private wishItemAry: WishItem[] = []; //武将item
- async start() {
- DataSystem.getData(NoviceGuideData).openRecuitWish = true;
- //请求心愿武将列表 目前没数据
- let quality: any[] = DataSystem.getData(ConfigData).get("serverConfig").needQuality.split(",");
- let heroData = DataSystem.getData(UserHeroData);
- let formationData = DataSystem.getData(FormationData);
- await heroData.pull(this.getComponent(Http));
- let tempGenerals: Hero_Client[] = [];
- for (let i = 0; i < heroData.haveHeros.length; i++) {
- let grl = heroData.get(heroData.haveHeros[i]).client;// .notHavetHeros[i].client;
- if (quality.indexOf(grl.color) != -1)
- tempGenerals.push(grl);
- }
- let self = this;
- tempGenerals.sort(function (a, b) {
- let aFormat = self.isHasFormation(formationData, a.id);// formationData.get(a.id) && formationData.get(a.id) > 0;
- let bFormat = self.isHasFormation(formationData, b.id);//formationData.get(b.id) && formationData.get(b.id) > 0;
- if (aFormat == bFormat == true) {
- if (a.color == b.color) {
- if (a.initStar == b.initStar) {
- if (a.camp == b.camp) {
- return b.id - a.id;
- } else {
- return a.camp - b.camp;//正营 魏蜀吴群 1-4
- }
- } else {
- return b.initStar - a.initStar;
- }
- } else {
- return (Number)(b.color) - (Number)(a.color);
- }
- } else {
- return aFormat ? -1 : 1;
- }
- });
- console.log("WishID: " + DataSystem.getData(RecruitData).curWishId);
- for (let i = 0; i < tempGenerals.length; i++) {
- let grl = tempGenerals[i];
- let tempscr = instantiate(this.wishItemPrefab).getComponent(WishItem);
- tempscr.selectBack = this.wishItemBack;
- let hasFormat = this.isHasFormation(formationData, grl.id);
- tempscr.init(grl, i, hasFormat);
- tempscr.node.active = true;
- this.content.addChild(tempscr.node);
- this.wishItemAry.push(tempscr);
- }
- }
- update() {
- DataSystem.watch(NoviceGuideData, ' isRecuitWish') && this.onClickAd();
- }
- /**阵位上是否有指定武将*/
- private isHasFormation(formationData: FormationData, heroId: number) {
- for (let i = 0; i < 5; i++) {
- if (formationData.get(i + 1) && formationData.get(i + 1) == heroId) return true;
- }
- return false;
- }
- private async seletWishItemBack(wishId: number, index: number, rate: string = "") {
- if (this.tempWishId == wishId) {
- this.tempWishId = this.selectIndex = -1;
- index >= 0 && (this.wishItemAry[index].select.active = false);
- } else {
- wishId > 0 && (this.tempWishId = wishId);
- this.selectIndex >= 0 && (this.wishItemAry[this.selectIndex].select.active = false);
- index >= 0 && (this.wishItemAry[index].select.active = true);
- this.selectIndex = index;
- }
- let heroDataOne: Hero_Client;
- console.log("tempwishid: " + this.tempWishId + " index: " + index);
- if (this.tempWishId > 0) {
- DataSystem.getData(NoviceGuideData).changeHero = true;
- heroDataOne = DataSystem.getData(ConfigData).get("general")[this.tempWishId] as Hero_Client;
- this.imgWish.spriteFrame = await this.res.load<SpriteFrame>("images/general/texture/head_img/" + heroDataOne.hero_res + "/spriteFrame", SpriteFrame);
- this.imgWishCamp.spriteFrame = await this.res.load<SpriteFrame>("images/general/texture/icon_camp_" + heroDataOne.camp + "/spriteFrame", SpriteFrame);
- }
- this.imgWish.node.active = this.tempWishId > 0;
- this.wishRect.active = this.tempWishId < 0;
- this.txtName.string = this.tempWishId > 0 ? heroDataOne.name + "" : "指定武将";
- this.txtRate.string = this.tempWishId > 0 ? rate : "";
- this.iconAd.active = this.tempWishId > 0 && this.tempWishId != DataSystem.getData(RecruitData).curWishId;
- this.btnAdGray.active = this.tempWishId == DataSystem.getData(RecruitData).curWishId;
- this.btnAd.active = this.tempWishId != DataSystem.getData(RecruitData).curWishId;
- }
- private async changeWishAd() {
- let resultAd = await this.getComponent(Http).send("/api/ad/watchVideoAD");
- if (resultAd && resultAd.code == HttpResponseCode.Success) {
- ReportThinking.ad_init('change_wish');
- let adData = await RewardVideoSystem.show();
- if (adData) {
- let result = await this.getComponent(Http).send("/api/recruit/changeWish", { id: this.tempWishId, adData: adData.obj });
- console.log("Change: ", result);
- if (result && result.code == 0) {
- ReportThinking.ad_end('change_wish');
- DataSystem.getData(RecruitData).curWishId = result.data.heroID;// DataSystem.getData(RecruitData).curWishIdTemp;
- DataSystem.getData(RecruitData).wishHeroRate = result.data.up;
- this.txtRate.string = result.data.up + "";
- WindowSystem.close(this.getComponent(Window));
- }
- }
- }
- }
- /**清空心愿武将*/
- private async changeWishClear() {
- let result = await this.getComponent(Http).send("/api/recruit/changeWish", { id: null, adData: null });
- if (result && result.code == 0) {
- DataSystem.getData(RecruitData).curWishId = -1;
- WindowSystem.close(this.getComponent(Window));
- }
- }
- private onClickAd() {
- if (this.tempWishId > 0) {
- this.tempWishId != DataSystem.getData(RecruitData).curWishId
- && this.changeWishAd(); //选中心愿武将
- } else {
- DataSystem.getData(RecruitData).curWishId > 0
- && this.changeWishClear(); //清空心愿武将
- }
- }
- private onClickAdGray() {
- console.log("you click ad gray btn");
- }
- }
|