| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- import { _decorator, Component, Node, Prefab, instantiate, ProgressBar, Label, Animation, Button } from 'cc';
- import { Http } from '../../core/net/Http';
- import { ResourcesUtils } from '../../core/resourceManager/ResourcesUtils';
- import { WindowManager } from '../../core/ui/window/WindowManager';
- import { WindowOpenMode } from '../../core/ui/window/WindowOpenMode';
- import { g } from '../../Data/g';
- import { platform } from '../../Data/platform';
- import { FriendChallengeItem } from '../../Item/FriendChallengeItem';
- const { ccclass, property } = _decorator;
- /**好友约战 */
- @ccclass('FriendBattleWindow')
- export class FriendBattleWindow extends Component {
- @property({ tooltip: "宝箱节点", type: Button })
- boxButton: Button;
- @property({ tooltip: "list节点", type: Node })
- listNode: Node;
- @property({ tooltip: "item预制体路径" })
- itemPrefabUrl = "";
- @property({ tooltip: "宝箱进度条", type: ProgressBar })
- boxProgress: ProgressBar;
- @property({ type: Label, tooltip: "进度文本" })
- progressLabel: Label;
- @property({ type: Animation, tooltip: "宝箱特效" })
- animation: Animation;
- @property({ type: Http, tooltip: "Http服务" })
- http: Http;
- start() {
- this.animation.node.active = false;
- this.boxButton.enabled = false;
- }
- update() {
- if (g.gameData.hasBattleLogUpdate) {
- g.gameData.hasBattleLogUpdate = false;
- this.listNode.removeAllChildren();
- this.onOpenhandler(true);//刷新数据
- }
- }
- //窗口打开回调
- private async onOpenhandler(isUpdate: boolean = false) {
- if (g.battleData.friendBattleUpdate || isUpdate) {
- g.battleData.friendBattleUpdate = false;
- let result = await this.http.send("/api/battle/GetChallenges");//查询挑战信息 20
- if (!result.code) {
- g.battleData.battleLogs = result.data.logs;
- g.battleData.winTimes = result.data.winTimes;
- g.battleData.getChallengePrize = result.data.getChallengePrize;
- } else {
- WindowManager.showTips(g.CodeMsg[result.code]);
- }
- }
- this.progressLabel.string = g.battleData.winTimes + '/5';
- this.boxProgress.progress = g.battleData.winTimes / 5;
- if (g.battleData.winTimes == 5 && g.battleData.getChallengePrize == 0) {
- this.animation.node.active = true;
- this.boxButton.enabled = true;
- this.animation.play();
- } else {
- this.animation.node.active = false;
- this.boxButton.enabled = false;
- }
- for (let i = 0; i < g.gameData.myFriendDatas.length; i++) {
- let prefabData = await ResourcesUtils.load<Prefab>(this.itemPrefabUrl, null, this.node);
- var itemNode = instantiate(prefabData);
- itemNode.parent = this.listNode;
- let itemData = g.gameData.myFriendDatas[i];
- await itemNode.getComponent(FriendChallengeItem).setData(itemData, g.battleData.battleLogs);
- }
- }
- /**打开战斗日志 */
- private openBattleLogWindow() {
- WindowManager.open("Prefabs/Battle/FriendBattleLogWindow", WindowOpenMode.NotCloseAndAdd, g.battleData.battleLogs);
- }
- /**领取挑战奖励 */
- private async onGetBox() {
- if (this.animation.node.active) {//可领取
- let result = await this.http.send("/api/battle/GetChallengePrize");//领取挑战奖励21
- if (!result.code) {
- WindowManager.open("Prefabs/Windows/DialogWindow", WindowOpenMode.NotCloseAndAdd, { num: result.data.addMoney, content: "领取成功,恭喜获得", type: 1 });
- g.userData.money += result.data.addMoney;
- this.animation.node.active = false;
- this.boxButton.enabled = false;
- } else {
- WindowManager.showTips(g.CodeMsg[result.code]);
- }
- }
- }
- /**点击发起挑战 */
- public async onInvite() {
- let result = await this.http.send("/api/app/share", {});
- if (result.code == 0) {
- platform.wxShare(result.data.url, result.data.title, result.data.descroption);
- } else {
- WindowManager.showTips("分享信息获取失败,请稍后再试");
- }
- }
- }
|