/****************************************************************** * * 联盟主窗体 * ******************************************************************/ const BridgeWindow = require( "bridge.window" ); const GuildConst = require( "guild_const" ); const GuildEvent = require( "guild_event" ); const GuildController = require( "guild_controller" ); const RoleController = require( "role_controller" ); const TipController = require( "tips_controller" ); // 工会职位 const GPT = GuildConst.PositionType; cc.Class( { extends: BridgeWindow, properties: { nodBase: { default: null, type: cc.Node }, nodSign: { default: null, type: cc.Node }, nodOps: { default: null, type: cc.Node }, nodBtns: { default: null, type: cc.Node }, }, // 显示 onEnable: function() { this.ctrl = GuildController.getInstance(); this.model = this.ctrl.getModel(); // 事件监听 this.bindGEvent( GuildEvent.UpdateMyInfoEvent, this.onUpdateInfo.bind( this ) ); this.ctrl.reqBase( ( _ret, _data ) => { if( !_ret ) { nx.tbox( _data ); this.scheduleOnce( () => { this.close(); }, 0.01 ); return; } this.freshDetail( _data ); this.freshSign( _data ); this.freshOps( _data ); } ); }, // 关闭 onDisable: function() { this.unbindGEvents(); }, // 刷新成员人数 updateMember: function( _data ) { let info = _data || this.model.getMyGuildInfo(); let txt = info ? ( info.members_num + "/" + info.members_max ) : "0/0"; nx.gui.setString( this.nodBase, "member/txt", txt ); }, // 刷新联盟等级 updateLevel: function( _data ) { let info = _data || this.model.getMyGuildInfo(); let lev = info ? info.lev : 1; nx.gui.setString( this.nodBase, "level/txt", nx.text.format( "LvNumber", lev ) ); }, // 刷新联盟经验 updateExp: function( _data ) { let info = _data || this.model.getMyGuildInfo(); let DATA = game.configs.guild_data.data_guild_lev; let limit = DATA[ info.lev ].exp; nx.gui.setString( this.nodBase, "exp/txt", info.exp + "/" + limit ); let prog = nx.gui.getComponent( this.nodBase, "prog", cc.ProgressBar ); prog.progress = info.exp / limit; }, // 更新推送 onUpdateInfo: function( _key, _value ) { // 成员人数 if( _key == "members_num" ) { this.updateMember(); return; } // 联盟等级 if( _key == "lev" ) { this.updateLevel(); return; } // 联盟经验 if( _key == "exp" ) { this.updateExp(); return; } }, // 刷新详情 freshDetail: function( _data ) { nx.gui.setString( this.nodBase, "name/txt", _data.name ); nx.gui.setString( this.nodBase, "leader/txt", _data.leader_name ); this.updateMember( _data ); this.updateLevel( _data ); this.updateExp( _data ); }, // 刷新口号 freshSign: function( _data ) { nx.gui.setString( this.nodSign, "txt", _data.sign || "" ); }, // 刷新操作 freshOps: function( _data ) { let role = RoleController.getInstance().getRoleVo(); if( !role || role.position == GPT.Member ) { nx.gui.setActive( this.nodSign, "modify", false ); nx.gui.setActive( this.nodBase, "rename", false ); for (let i = 0; i < this.nodOps.children.length; i++) { const op = this.nodOps.children[i]; if( i == 1 || i == this.nodOps.children.length - 1 ){ nx.gui.setActive( op, "", true ); continue; } nx.gui.setActive( op, "", false ); } } else { nx.gui.setActive( this.nodSign, "modify", true ); nx.gui.setActive( this.nodBase, "rename", true ); this.nodOps.children.forEach(op => { nx.gui.setActive( op, "", true ); }); } }, // 联盟改名 onTouchRename: function() { let self = this; let modify = function( _name ) { self.ctrl.reqRename( _name, ( _ret, _data ) => { if( !_ret ) { nx.tbox( _data ); return; } nx.gui.setString( self.nodBase, "name/txt", _name ); } ) }; let TC = TipController.getInstance(); TC.showInputString( { txt: this.model.getMyGuildInfo().name, tip: "GuildInputNameEmpty", limit: [ 4, 12 ], cb: ( _box, _str ) => { _box.close(); modify( _str ); } } ); }, // 口号修改 onTouchModifySign: function() { let self = this; let modify = function( _sign ) { self.ctrl.reqModifySign( _sign, ( _ret, _data ) => { if( !_ret ) { nx.tbox( _data ); return; } nx.gui.setString( self.nodSign, "txt", _sign ); } ) }; let TC = TipController.getInstance(); TC.showInputWords( { txt: this.model.getMyGuildInfo().sign, tip: "GuildInputSignEmpty", limit: [ 4, 100 ], cb: ( _box, _str ) => { _box.close(); modify( _str ); } } ); }, // 一键招募 onTouchRecruit: function() { // 判空 let info = this.model.getMyGuildInfo(); if( !info ) { return; } // 免费 if( info.recruit_num < 1 ) { nx.mbox( "GuildRecruitFree", [ 'cancel', 'confirm' ], ( _key, _box ) => { _box.close(); if( _key == 'confirm' ) { this.ctrl.reqBroadcast( ( _ret, _data ) => { if( !_ret ) { nx.tbox( _data ); return; } } ); } } ); return; } // 付费 let cost = gdata( "guild_data", "data_const", "recruit_cost" ); let role = RoleController.getInstance().getRoleVo(); if( !cost || !role ) { return; } let txt = nx.text.format( "GuildRecruitPay", cost.val ); nx.mbox( txt, [ 'cancel', 'confirm' ], ( _key, _box ) => { _box.close(); if( _key == 'confirm' ) { this.ctrl.reqBroadcast( ( _ret, _data ) => { if( !_ret ) { nx.tbox( _data ); return; } } ); } } ); }, // 点击成员管理 onTouchMemebers: function() { // 普通成员浏览 let role = RoleController.getInstance().getRoleVo(); if( role.position == GPT.Member ) { nx.bridge.createPanel( "WndGuildMemberList" ); return; } // 特殊的管理 nx.bridge.createPanel( "WndGuildMemberManager" ); }, // 点击每日獎勵 onTouchDailyReward: function() { this.ctrl.reqGetDailyReward( ( _ret, _data ) => { if( !_ret ) { nx.tbox( _data ); return; } _data.mod = this.ctrl; nx.bridge.createPanel( "WndGuildReward", _data ); }); }, } );