import AudioUtil from "../ts/core/AudioUtil"; import GameModel from "../ts/core/GameModel"; import MsgAlert from "../ts/game/msg/MsgAlert"; let roleTitleUtil = require('../utils/RoleTitlesUtil'); let GameDefine = require('./GameDefine'); var SetRoleTitleUIMgr = require('./SetRoleTitleUIMgr'); cc.Class({ extends: cc.Component, properties: { scrollViewContent: cc.Node, roleTitleItem: cc.Prefab, titleName: cc.Label, titleDesc: cc.Label, btnUnload: cc.Node, btnLoad: cc.Node, }, onLoad() { SetRoleTitleUIMgr.showTitleList(); this.selectRoleTitleId = -1; this.selectRoleTitleType = -1; this.selectRoleTitleName = ''; this.titles = []; }, //初始化用戶稱謂列表數據 initScrollViewTitle(data) { let roleTitleIdList = data; this.titles = JSON.parse(roleTitleIdList.titles); this.titles.forEach((titleItem, index) => { let pkgTitltItem = roleTitleUtil.pkgRoleTitle(titleItem, GameModel.player.bangname); if (pkgTitltItem != null) { let pre_roleTitle = cc.instantiate(this.roleTitleItem); var toggle = pre_roleTitle.getComponent(cc.Toggle); let toggleName = pre_roleTitle.getChildByName('LblTitleName').getComponent(cc.Label); toggleName.string = pkgTitltItem.name; toggleName = pre_roleTitle.getChildByName('LblTitleType').getComponent(cc.Label); toggleName.string = pkgTitltItem.type; var checkEventHandler = new cc.Component.EventHandler(); checkEventHandler.target = this; checkEventHandler.component = "SetRoleTitleUI"; checkEventHandler.handler = "onSelectRoleTitle"; checkEventHandler.customEventData = pkgTitltItem.id; if (index == 0) { toggle.isChecked = true; this.titleName.string = pkgTitltItem.name; this.titleDesc.string = pkgTitltItem.desc; this.selectRoleTitleId = pkgTitltItem.id; this.selectRoleTitleName = pkgTitltItem.name; this.selectRoleTitleType = pkgTitltItem.type; if (!pkgTitltItem.onLoad) { this.btnLoad.active = true; this.btnUnload.active = false; } else { this.btnLoad.active = false; this.btnUnload.active = true; } } else { toggle.isChecked = false; } toggle.checkEvents.push(checkEventHandler); pre_roleTitle.parent = this.scrollViewContent; } }); }, onClickedBtnLoad() { if (this.selectRoleTitleId != -1) { if (this.selectRoleTitleId == GameModel.player.titleid && this.selectRoleTitleType == GameModel.player.titletype) { //特殊稱謂 if (this.selectRoleTitleType == GameDefine.TitleType.BroTitle || this.selectRoleTitleType == GameDefine.TitleType.CoupleTitle) { if (this.selectRoleTitleName == GameModel.player.titleval) { GameModel.send('c2s_title_change', { type: -1, titleid: 0, value: '', operatetype: 1 }); //卸下當前稱謂 } else { GameModel.send('c2s_title_change', { type: this.selectRoleTitleType, titleid: this.selectRoleTitleId, value: this.selectRoleTitleName, operatetype: 2 }); //裝備新稱謂 } } else { GameModel.send('c2s_title_change', { type: -1, titleid: 0, value: '', operatetype: 1 }); //卸下當前稱謂 } } else { //圖片或者普通稱謂 GameModel.send('c2s_title_change', { type: this.selectRoleTitleType, titleid: this.selectRoleTitleId, value: this.selectRoleTitleName, operatetype: 2 }); //裝備新稱謂 } } else { MsgAlert.addMsg('請先選擇一個稱謂'); } }, //接收服務端傳來的操作稱謂結果 changeBtnLoadStatus(data) { if (data.ecode == 0) { if (data.operatetype == 2) { this.btnUnload.active = true; this.btnLoad.active = false; } else { let childrens = this.scrollViewContent.getChildren(); for (const child of childrens) { var toggle = child.getComponent(cc.Toggle); toggle.isChecked = false; } this.btnUnload.active = false; this.btnLoad.active = true; } GameModel.player.titleid = data.titleid; GameModel.player.titletype = data.type; GameModel.player.titleval = data.value; let logic = cc.find('Canvas').getComponent('GameLogic'); if (logic) { logic.resetSelfPlayerTitle(); } } else { cc.log('稱謂操作失敗'); } }, onSelectRoleTitle(toggle, roleTitleId) { roleTitleId = Number(roleTitleId); let titleName = toggle.node.getChildByName('LblTitleName').getComponent(cc.Label).string; var roleTitle = roleTitleUtil.getRoleTitle(roleTitleId, titleName, GameModel.player.bangname); this.titleName.string = roleTitle.name; this.titleDesc.string = roleTitle.desc; this.selectRoleTitleId = roleTitleId; this.selectRoleTitleName = roleTitle.name; this.selectRoleTitleType = roleTitle.type; /* let titleList = this.titles.filter(e => { if(e.titleid == roleTitleId) return true; }); if(titleList.length > 0){ let titleItem = titleList[0]; this.selectRoleTitleType = titleItem.type; } */ if (this.selectRoleTitleId != GameModel.player.titleid) { this.btnUnload.active = false; this.btnLoad.active = true; } else { this.btnUnload.active = true; this.btnLoad.active = false; } }, onCloseBtnClicked(e, d) { //zfy --關閉音效 AudioUtil.playAudio('ui/ui_guanbi'); this.node.destroy(); }, });