| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- import { _decorator, Component, Node, SystemEventType, Label, SpriteFrame, Sprite, ProgressBar, EventTouch, Vec2 } from 'cc';
- import { DataSystem } from '../../core/data/DataSystem';
- import { Http } from '../../core/net/Http';
- import { HttpSystem } from '../../core/net/HttpSystem';
- import { ResourceLoader } from '../../core/resourceManager/ResourceLoader';
- import { BitmapFont } from '../../core/ui/BitmapFont';
- import { OpenWindow } from '../../core/ui/window/OpenWindow';
- import { WindowOpenMode } from '../../core/ui/window/WindowOpenMode';
- import { WindowSystem } from '../../core/ui/window/WindowSystem';
- import { ConfigData } from '../../data/ConfigData';
- import { HttpErrorCode } from '../../data/HttpErrorCode';
- import { platform } from '../../data/jsb/platform';
- import { UserData } from '../../data/UserData';
- import { RedPoint } from '../../main/RedPoint';
- import { ReportThinking } from '../../ReportThinking';
- import { FormationData } from '../formation/FormationData';
- import { UserHero, UserHeroData } from '../UserHeroData'
- const { ccclass, property, requireComponent } = _decorator;
- /**
- * 图鉴英雄项
- * @author 袁浩
- */
- @ccclass('BookHeroItem')
- @requireComponent(ResourceLoader)
- export class BookHeroItem extends Component {
- @property({ tooltip: "即将解锁", type: Node })
- public lockChipNode: Node;
- @property({ tooltip: "已解锁并只有碎片", type: Node })
- public unlockNode: Node;
- @property({ tooltip: "已上阵显示的节点", type: Node })
- public haveNode: Node;
- @property({ tooltip: "名字", type: Label })
- public nameLabel: Label;
- @property({ tooltip: "名字背景", type: Sprite })
- public nameBg: Sprite;
- @property({ tooltip: "所有名字背景", type: [SpriteFrame] })
- public nameBgList: SpriteFrame[] = [];
- @property({ tooltip: "品质背景", type: Sprite })
- public campBg: Sprite;
- @property({ tooltip: "所有品质背景", type: [SpriteFrame] })
- public campBgList: SpriteFrame[] = [];
- @property({ tooltip: "阵营图标", type: Sprite })
- public campIcon: Sprite;
- @property({ tooltip: "所有阵营图标", type: [SpriteFrame] })
- public campIconList: SpriteFrame[] = [];
- @property({ tooltip: "品质框", type: Sprite })
- public qualityBorder: Sprite;
- @property({ tooltip: "所有品质框", type: [SpriteFrame] })
- public qualityBorderList: SpriteFrame[] = [];
- @property({ tooltip: "解锁文本提示", type: Label })
- public unlockLabel: Label;
- @property({ tooltip: "武将原画", type: Sprite })
- public body: Sprite;
- @property({ tooltip: "星级", type: BitmapFont })
- public starBitmapLabel: BitmapFont;
- @property({ tooltip: "操作文本", type: Label })
- public operateLabel: Label;
- @property({ tooltip: "碎片进度", type: Sprite })
- public chipProgress: Sprite;
- @property({ tooltip: "碎片进度文本", type: Label })
- public chipLabel: Label;
- @property({ tooltip: "用于打开武将信息的组件", type: OpenWindow })
- public openHeroInfo: OpenWindow;
- @property({ tooltip: "红点提示", type: Sprite })
- public redPoint: Sprite;
- public data: UserHero;
- public heroList: UserHero[];
- public index: number;
- start() {
- this.node.on(SystemEventType.TOUCH_END, this.onItemTouch, this);
- }
- update() {
- if (this.data && DataSystem.watch(UserHeroData, this.data.client.id + "")) {//如果英雄数据发生变化
- this.heroList[this.index].server = DataSystem.getData(UserHeroData).get(this.data.client.id).server;
- this.onDataChange(this.heroList, this.index);
- }
- }
- public async onDataChange(heroList: UserHero[], index: number) {
- this.data = heroList[index];
- this.heroList = heroList;
- this.index = index;
- this.lockChipNode.active = !this.data.client.isunlock;
- this.campIcon.enabled = !this.lockChipNode.active;
- this.unlockNode.active = !!this.data.client.isunlock && (!this.data.server || !this.data.server.active);
- this.haveNode.active = !!this.data.server && !!DataSystem.getData(FormationData).getIDByHero(this.data.client.id);
- this.nameLabel.string = this.data.client.name;
- this.campBg.spriteFrame = this.campBgList[this.data.client.color - 1];
- this.nameBg.spriteFrame = this.nameBgList[this.data.client.color - 1];
- this.campIcon.spriteFrame = this.campIconList[this.data.client.camp - 1];
- this.qualityBorder.spriteFrame = this.qualityBorderList[this.data.client.color - 1];
- this.unlockLabel.string = !!this.data.client.unlockLv ? `兵营${this.data.client.unlockLv}级解锁` : '';
- let starString = "";
- let star = !!this.data.server ? this.data.server.star : this.data.client.initStar;
- for (let i = 0; i < star; i++) {
- starString += "0";
- }
- this.starBitmapLabel.string = starString;
- let chip = !!this.data.server ? this.data.server.chip : 0;
- this.chipProgress.fillRange = Math.min(1, chip / this.data.client.needChip);
- this.chipLabel.string = `${chip}/${this.data.client.needChip}`;
- this.operateLabel.string = `${chip >= this.data.client.needChip ? '合成>' : '获取>'}`;
- if (this.data.server && !this.data.server.active && chip >= this.data.client.needChip) {
- this.redPoint.node.active = true;
- }
- else {
- if (this.data && this.data.server && this.data.server.active) {
- let starConfig = DataSystem.getData(ConfigData).get("star");
- if (starConfig[this.data.server.star] && this.data.server.chip >= starConfig[this.data.server.star].nextReq) {
- this.redPoint.node.active = true;
- }
- else {
- this.redPoint.node.active = false;
- }
- }
- else {
- this.redPoint.node.active = false;
- }
- }
- this.body.spriteFrame = await this.getComponent(ResourceLoader).load(`images/general/texture/hero_img/${this.data.client.hero_res}/spriteFrame`, SpriteFrame);
- }
- private async onItemTouch(event: EventTouch) {
- if (Vec2.distance(event.getUILocation(), event.getUIStartLocation()) > 20) {
- return;
- }
- if (this.lockChipNode.active) {//未解锁的不做处理
- return;
- }
- if (!!this.data.server && this.data.server.active) {//已经解锁且已经获得
- //打开武将信息界面
- this.openHeroInfo.open(this.data);
- }
- else if (this.unlockNode.active) {//已解锁且只有碎片
- let chip = !!this.data.server ? this.data.server.chip : 0;
- if (chip >= this.data.client.needChip) {//合成
- let result = await this.getComponent(Http).send("/api/hero/compose", { id: this.data.client.id });
- let userHeroData = DataSystem.getData(UserHeroData);
- if (result.data) {
- let heroID = parseInt(result.data.id);
- let chip = result.data.chip;
- let hero = userHeroData.get(heroID);
- //更新碎片
- hero.server.chip = chip;
- //等级为兵营等级
- hero.server.lv = DataSystem.getData(UserData).campLv;
- //设置为已拥有
- hero.server.active = true;
- //更新英雄数据
- userHeroData.set(heroID, hero);
- userHeroData.haveHeros.push(heroID);
- let index = userHeroData.notHavetHeros.indexOf(heroID);
- index != -1 && userHeroData.notHavetHeros.splice(index, 1);
- ReportThinking.hero_activate(this.data.client.name, 'hero_compose');
- //打开升星界面
- WindowSystem.open("prefabs/ui/hero/compose", WindowOpenMode.NotCloseAndCover, [this.data]);
- }
- else if (result.code == HttpErrorCode.SendDataError) {
- userHeroData.pull(this.getComponent(Http));
- }
- }
- else {//打开招募界面
- WindowSystem.open("prefabs/ui/recruit/recruit", WindowOpenMode.NotCloseAndAdd);
- }
- }
- }
- }
|