local UIGuildAlliesMapView = UIViewClass() local HeroPicPath = ConstAssetPathConfig.HeroPicPath local HeroIconPath = ConstAssetPathConfig.ItemIconPath ------------------------- 系统函数 -------------------------------- function UIGuildAlliesMapView:OnCreated() UIUtils.SetLabelText(self.UITemplateTitlePanel.lab_Title, Const_IDS["IDS_GuildAllies_FunctionName"]) self:RegistSystemEvent(EventID.UI_GuildAlliesMapView_Refresh, self.RefreshPanel) self.idMapToGuildAlly = LuaExt.CreateTable(DataSheetManager.GuildAlliesData:GetDataCount(), 0) for i = 1, DataSheetManager.GuildAlliesData:GetDataCount() do table.insert(self.idMapToGuildAlly, self.group_GuildFrames[i]) UIUtils.SetActive(self.group_GuildFrames[i].gameObject, false) end self.curGuildAllies = nil self.paramGuildAllies = nil self:RegistSystemEvent(EventID.UI_CloseAndRecoverView, self.OnCloseAndRecoverView) end function UIGuildAlliesMapView:OnOpened(context) self.paramGuildAllies = context MDL.GuildAllies.RequestEnterGuildAllies() end function UIGuildAlliesMapView:OnBackButtonPressed() self:OnButtonClicked(self.UITemplateTitlePanel.btn_close) end function UIGuildAlliesMapView:OnButtonClicked(comp) if comp == self.btn_Visit then self:CloseView(true) UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIGuildAlliesMainPanelNew, self.curGuildAllies) elseif comp == self.UITemplateTitlePanel.btn_Info then CTL.GuildAllies.OpenGuildAlliesDesc() elseif comp == self.btn_MyAllies then UIManager.OpenView(Const_UI_Lua.UIEnum.UIGuildAlliesMyAllies) elseif comp == self.btn_QuestionMark then UIManager.OpenView(Const_UI_Lua.UIEnum.UIDescriptionPanel,{target = self.btn_QuestionMark, posType = LuaConst.DescriptionPanelType.RightUpper, text = UIUtils.GetLocalizedTxt(Const_IDS["IDS_GuildAllies_VisitIntroTips"])}) elseif comp == self.UITemplateTitlePanel.btn_close then self:CloseView(true) elseif comp == self.UITemplateTitlePanel.btn_Home then CTL.HomeMain.CloseViewBackHomeMain() else for id, v in ipairs (self.idMapToGuildAlly) do if comp == v.btn_select then local newGuildAllies = MDL.GuildAllies.GetGuildAlliesAndPosByID(id) self:RefreshSelected(newGuildAllies, true) break end end end end function UIGuildAlliesMapView:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.loop_GuildInfo then UIUtils.SetImageByAssetBundle(cellTable.img_HeroHead, string.format(HeroIconPath, data.HeroHead)) UIUtils.SetActive(cellTable.group_Allies, MDL.GuildAllies.IsMyAllyByPowerId(data.ID)) UIUtils.SetActive(cellTable.group_Selected, self.curGuildAllies and self.curGuildAllies.ID == data.ID or false) UIUtils.SetActive(cellTable.group_Visit, data.isTarget) UIUtils.SetLabelText(cellTable.txt_Name, Const_IDS[data.AlliesName]) UIUtils.SetLabelText(cellTable.txt_Area, Const_IDS[data.CityName]) cellTable.Gradient:SetState(data.BigAllies == 1 and 1 or 0) end end function UIGuildAlliesMapView:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.loop_GuildInfo then -- 切换选中状态 CTL.Sound.PlayGameSound("UI_sound_Qieye01") self:RefreshSelected(data) end end ------------------------------------------------------------------- function UIGuildAlliesMapView:RefreshPanel() local showGuildList = MDL.GuildAllies.GetGuildAlliesShowList() if self.loop_GuildInfo.Count ~= 0 then self.loop_GuildInfo:ClearCells() end for i, v in ipairs (showGuildList) do if self.idMapToGuildAlly[v.ID] then local group_ally = self.idMapToGuildAlly[v.ID] UIUtils.SetActive(group_ally.gameObject, true) UIUtils.SetImageByAssetBundle(group_ally.img_HeroHead, string.format(HeroIconPath, v.HeroHead)) UIUtils.SetLabelText(group_ally.txt_GuildName, Const_IDS[v.AlliesName]) UIUtils.SetLabel(group_ally.txt_Number, v.friendliness) UIUtils.SetActive(group_ally.group_Allies, v.isTarget) UIUtils.SetActive(group_ally.group_selected, false) group_ally.UIStateSwitch:SetState(v.BigAllies == 1 and 1 or 0) end self.loop_GuildInfo:AddData(v, 0) end self:RefreshSelected(self.paramGuildAllies and self.paramGuildAllies or showGuildList[1], true) self.paramGuildAllies = nil end function UIGuildAlliesMapView:RefreshSelected(newGuildAllies, isMove) if newGuildAllies and (not self.curGuildAllies or self.curGuildAllies.ID ~= newGuildAllies.ID) then local oldGuildAllies = self.curGuildAllies self.curGuildAllies = newGuildAllies if oldGuildAllies then local _, pos = MDL.GuildAllies.GetGuildAlliesAndPosByID(oldGuildAllies.ID) self.loop_GuildInfo:UpdateIndex(pos - 1) local guild_ally_old = self.idMapToGuildAlly[oldGuildAllies.ID] UIUtils.SetActive(guild_ally_old.group_selected, false) end local _, newPos = MDL.GuildAllies.GetGuildAlliesAndPosByID(self.curGuildAllies.ID) self.loop_GuildInfo:UpdateIndex(newPos - 1) if isMove then self.loop_GuildInfo:MoveIndex(newPos - 1) end local guild_ally_new = self.idMapToGuildAlly[self.curGuildAllies.ID] UIUtils.SetActive(guild_ally_new.group_selected, true) self.img_HeroPic.transform:SetLocalPosition(0, 5, 0) UIUtils.SetSpritePivotPos(self.img_HeroPic, string.format(HeroPicPath, self.curGuildAllies.HeroPic), 0.8) UIUtils.SetLabelText(self.txt_HeroName, Const_IDS[self.curGuildAllies.AlliesName]) UIUtils.SetLabelText(self.txt_AreaName, Const_IDS[self.curGuildAllies.CityName]) CTL.GuildAllies.SetTextBuff(self.curGuildAllies.State_Table[1].StateAttr, self.group_AllianceAttribute.group_Attr1.img_AttrIcon, self.group_AllianceAttribute.group_Attr1.txt_AttrName, self.group_AllianceAttribute.group_Attr1.txt_AttrNum, self.group_AllianceAttribute.group_Attr2.img_AttrIcon, self.group_AllianceAttribute.group_Attr2.txt_AttrName, self.group_AllianceAttribute.group_Attr2.txt_AttrNum) UIUtils.SetLabelText(self.txt_InfoText, Const_IDS[self.curGuildAllies.AlliesIntro]) end end return UIGuildAlliesMapView