require("Base/BasePanel") local GuildFindPopup = Inherit(BasePanel) local this = GuildFindPopup local _GuildApplyStatusStr = { [GUILD_JOIN_TYPE.NO_LIMIT] = Language[10876], [GUILD_JOIN_TYPE.LIMIT] = Language[10877], [GUILD_JOIN_TYPE.FORBID] = Language[10878], } this._RefreshCD = ConfigManager.GetConfigData(ConfigName.GuildSetting, 1).RefreshCd this._RefreshStamp = 0 --初始化组件(用于子类重写) function GuildFindPopup:InitComponent() this.spLoader = SpriteLoader.New() this.title2 = Util.GetGameObject(self.transform, "bgImage/Title2/text"):GetComponent("Text") this.btnBack = Util.GetGameObject(self.transform, "btnBack") this.mask = Util.GetGameObject(self.transform, "maskImage") this.btnSearch = Util.GetGameObject(self.transform, "bottomImage/searchButton") this.btnRefresh = Util.GetGameObject(self.transform, "bottomImage/refreshButton") this.btnCreate = Util.GetGameObject(self.transform, "bottomImage/createBtn") this.btnAdd = Util.GetGameObject(self.transform, "bottomImage/addBtn") this.input = Util.GetGameObject(self.transform, "bottomImage/InputField"):GetComponent("InputField") this.scrollRoot = Util.GetGameObject(self.transform, "scrollpos") this.item = Util.GetGameObject(self.transform, "scrollpos/item") local height = this.scrollRoot.transform.rect.height local width = this.scrollRoot.transform.rect.width this.ScrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, this.scrollRoot.transform, this.item, nil, Vector2.New(width, height), 1, 1, Vector2.New(0,0)) this.ScrollView.gameObject:GetComponent("RectTransform").anchoredPosition = Vector2.New(0, 0) this.ScrollView.gameObject:GetComponent("RectTransform").anchorMin = Vector2.New(0.5, 0.5) this.ScrollView.gameObject:GetComponent("RectTransform").anchorMax = Vector2.New(0.5, 0.5) this.ScrollView.gameObject:GetComponent("RectTransform").pivot = Vector2.New(0.5, 0.5) this.ScrollView.moveTween.MomentumAmount = 1 this.ScrollView.moveTween.Strength = 2 end --绑定事件(用于子类重写) function GuildFindPopup:BindEvent() -- Util.AddClick(this.btnBack, function() PlaySoundWithoutClick(SoundConfig.Sound_UICancel) this:ClosePanel() end) Util.AddClick(this.mask, function() PlaySoundWithoutClick(SoundConfig.Sound_UICancel) this:ClosePanel() end) -- 搜索 Util.AddClick(this.btnSearch, function() local name = this.input.text if name == "" then this.input.text = "" this.RefreshRecommandList(true,true) PopupTipPanel.ShowTip(Language[10879]) return end GuildManager.RequestSearchGuild(name, function() this.SetListType(2) end) end) -- 刷新 Util.AddClick(this.btnRefresh, function() local curTimeStamp = GetTimeStamp() local cd = this._RefreshCD - (curTimeStamp - this._RefreshStamp) if cd > 0 then PopupTipPanel.ShowTip(string.format(Language[10880], cd)) return end this.input.text = "" this.RefreshRecommandList() this._RefreshStamp = curTimeStamp end) -- 创建 Util.AddClick(this.btnCreate, function() UIManager.OpenPanel(UIName.GuildCreatePopup, function() this:ClosePanel() end) end) -- 一键加入 Util.AddClick(this.btnAdd, function() --local _IsInFight = GuildFightManager.IsInGuildFight() --if _IsInFight then -- PopupTipPanel.ShowTip("公会战期间无法加入公会") -- return --end local list = nil if this._ListType == 1 then list = GuildManager.GetRecommandGuildList() elseif this._ListType == 2 then list = GuildManager.GetSearchGuildList() end if not list or #list == 0 then PopupTipPanel.ShowTip(Language[10881]) return end -- 遍历列表获取符合条件的公会 local operateType = 1 -- 操作类型 1 申请 2 加入 local applyGuildIdList = {} local joinGuild = nil for i = 1, #list do local data = list[i] if data.isApply == GUILD_APPLY_STATUS.NO_APPLY then local guildData = data.familyBaseInfo if guildData.joinType == GUILD_JOIN_TYPE.NO_LIMIT then if guildData.totalNum < guildData.maxNum and PlayerManager.level >= guildData.playerIntoLevel then if not joinGuild or joinGuild.levle < guildData.levle then joinGuild = guildData operateType = 2 end end elseif guildData.joinType == GUILD_JOIN_TYPE.LIMIT then if guildData.totalNum < guildData.maxNum and PlayerManager.level >= guildData.playerIntoLevel then table.insert(applyGuildIdList, guildData.id) end end end end -- 跟据类型执行操作 if operateType == 1 then -- 申请公会 if #applyGuildIdList == 0 then PopupTipPanel.ShowTip(Language[10881]) return end GuildManager.RequestApplyManyGuilds(applyGuildIdList, function() -- 刷新下显示 this.SetListType(this._ListType) PopupTipPanel.ShowTip(Language[10797]) end) elseif operateType == 2 then --加入公会 if not joinGuild then PopupTipPanel.ShowTip(Language[10881]) return end GuildManager.RequestJoinGuild(joinGuild.id, function () this.JoinGuildSuccess() end) end end) end --添加事件监听(用于子类重写) function GuildFindPopup:AddListener() Game.GlobalEvent:AddEvent(GameEvent.Guild.JoinGuildSuccess, this.CloseSelf) end --移除事件监听(用于子类重写) function GuildFindPopup:RemoveListener() Game.GlobalEvent:RemoveEvent(GameEvent.Guild.JoinGuildSuccess, this.CloseSelf) end --界面打开时调用(用于子类重写) function GuildFindPopup:OnOpen(...) this._ListType = nil -- 刷新推荐列表 this.curPage = 1 this.RefreshRecommandList() -- 控制挂机界面伤害文字显示 FightPointPassManager.isBeginFight = true end --界面打开或者重新打开后,界面刷新时调用(用于子类重写) function GuildFindPopup:OnShow() end -- 关闭界面 function this.CloseSelf() this:ClosePanel() end -- 刷新推荐列表 function this.RefreshRecommandList(isTop,isAnim) GuildManager.RecommandGuildList = {} GuildManager.RequestRecommandGuildList(this.curPage,function() this.SetListType(1,isTop,isAnim) end) end -- 公会节点数据匹配 function this.GuildItemAdapter(item, data) local head = Util.GetGameObject(item, "head"):GetComponent("Image") local nameText = Util.GetGameObject(item, "name"):GetComponent("Text") local announceText = Util.GetGameObject(item, "content"):GetComponent("Text") local membersText = Util.GetGameObject(item, "num"):GetComponent("Text") local limitText = Util.GetGameObject(item, "limit"):GetComponent("Text") local btn = Util.GetGameObject(item, "btn") local btnStr = Util.GetGameObject(item, "btn/text"):GetComponent("Text") -- 基础信息 local guildData = data.familyBaseInfo local gName = guildData.name --if string.len(gName) > 15 then -- gName = SubString(gName, 5).."..." --end nameText.text = gName announceText.text = GetLanguageStrById(guildData.annouce) head.sprite = this.spLoader:LoadSprite(GuildManager.GetLogoResName(guildData.icon)) local curGuildLevelInfo = ConfigManager.GetConfigData(ConfigName.GuildLevelConfig, guildData.levle) local maxMemNum = curGuildLevelInfo.Num membersText.text = string.format("%s/%s", guildData.totalNum, maxMemNum) limitText.text = string.format(Language[10882], guildData.playerIntoLevel) -- 按钮显示 local _AddType = guildData.joinType local _IsApply = data.isApply == GUILD_APPLY_STATUS.APPLY local _IsForbid = _AddType == GUILD_JOIN_TYPE.FORBID --local _IsInFight = GuildFightManager.IsInGuildFight() Util.SetGray(btn, _IsForbid or _IsApply)-- or _IsInFight) btnStr.text = _IsApply and Language[10883] or _GuildApplyStatusStr[_AddType] -- 按钮监听事件 Util.AddOnceClick(btn, function() if _IsForbid then PopupTipPanel.ShowTip(Language[10884]) return end if _IsApply then PopupTipPanel.ShowTip(Language[10885]) return end --if _IsInFight then -- PopupTipPanel.ShowTip("公会战期间无法加入公会") -- return --end if guildData.totalNum >= maxMemNum then PopupTipPanel.ShowTip(Language[10886]) return end if PlayerManager.level < guildData.playerIntoLevel then PopupTipPanel.ShowTip(Language[10376]) return end -- 根据加入类型不同执行不同操作 if _AddType == GUILD_JOIN_TYPE.NO_LIMIT then GuildManager.RequestJoinGuild(guildData.id, function () this.JoinGuildSuccess() end) elseif _AddType == GUILD_JOIN_TYPE.LIMIT then GuildManager.RequestApplyManyGuilds({guildData.id}, function() -- 刷新下显示 this.SetListType(this._ListType) PopupTipPanel.ShowTip(Language[10797]) end) end end) end -- 加入公会成功回调 function this.JoinGuildSuccess() -- 关闭当前界面 this:ClosePanel() -- 打开主城 UIManager.OpenPanel(UIName.GuildMainCityPanel) -- PopupTipPanel.ShowTip(Language[10377]) NetManager.RequestRedPacketData() MyGuildManager.ReuqsetRedPackage() end -- 设置数据类型 function this.SetListType(type,isTop,isAnim) this._ListType = type local datalist = {} if this._ListType == 1 then this.title2.text = Language[10887] this.input.text = "" datalist = GuildManager.GetRecommandGuildList() elseif this._ListType == 2 then this.title2.text = Language[10795] datalist = GuildManager.GetSearchGuildList() end -- 刷新列表显示 this.ScrollView:SetData(datalist, function(index, go) this.GuildItemAdapter(go, datalist[index]) if not GuildManager.MaxNumber and index == #datalist then this.curPage = this.curPage + 1 GuildManager.GetNextRecommendFamily(this.curPage,function () this.SetListType(1,true,true) end) end end,isTop,isAnim) end --界面关闭时调用(用于子类重写) function GuildFindPopup:OnClose() -- 控制挂机界面伤害文字显示 GuildManager.RecommandGuildList = {} FightPointPassManager.isBeginFight = false end --界面销毁时调用(用于子类重写) function GuildFindPopup:OnDestroy() this.spLoader:Destroy() this.ScrollView = nil end return GuildFindPopup