import { HttpStateType, ReveData } from "../../../util/CHttp"; import PetIcon from "../../common/PetIcon"; import Equip from "./Equip"; /** * 设置队长 */ const {ccclass, property} = cc._decorator; @ccclass export default class SetLeader extends cc.Component { @property(cc.Node) mSetButton: cc.Node = null;//设置的按钮 private equip:Equip = null public onLoad(){ this.equip = this.node.getComponent(Equip) } public start(){ this.flushLeader() } public flushLeader(){ let main = this.equip.main let player = main.player let petListNode = this.equip.mPetList let nodes = petListNode.children for (let i = 0; i < nodes.length; i++) { let node = nodes[i]; let petIcon = node.getComponent(PetIcon) if(petIcon.id == player.role.leader){ petIcon.mLeaderIcon.active = true }else{ petIcon.mLeaderIcon.active = false } } } /** * 设置队长 */ public onclickSetLeader(){ let main = this.equip.main let msg = { leader:this.equip.curPi.id } main.gameHttp.sendJson('set/v1/leader',msg,(state,reve:ReveData)=>{ main.stopLoad(); if(state == HttpStateType.SUCCESS){ if(reve.retCode == 0){ main.player.role.leader = msg.leader this.flushLeader() main.showTips('设置成功'); }else{ main.showTips(reve.message); } }else{ main.showTips('网络异常'); } }); } }