local UIEquipmentMain = UIViewClass() local SelectedColor = Color.New(1, 1, 1, 1) local UnSelectedColor = Color.New(174 / 255, 176 / 255, 182 / 255, 1) local SelectedToggleColor = SelectedColor local UnSelectedToggleColor = UnSelectedColor local MAX_NAME_LENGTH = 8 local ChangeItemCountSpeed = 0.15 function UIEquipmentMain:OnCreated() self.isFirstFocus = true UIUtils.SetActive(self.panel_ItemSources, false) UIUtils.SetActive(self.rect_CloseItemSources, false) --配置ids UIUtils.SetLabelText(self.group_toggleTxt[1],MDL.Equipment.EquipTypeNameIDS[MDL.Equipment.EquipTabType.All]) for index, ids in ipairs(MDL.Equipment.EquipTypeNameIDS) do UIUtils.SetLabelText(self.group_toggleTxt[index + 1],ids) end -- 设置标题 UIUtils.SetActive(self.UITemplateTitlePanel.btn_Info, false) UIUtils.SetLabelText(self.UITemplateTitlePanel.lab_Title, Const_IDS["IDS_Equip_Equip"]) end --context[MainTabType,EquipTabType] function UIEquipmentMain:OnOpened(context) self.sortedList = {} MDL.Equipment.UpdateSortedAllTypeList() self.isInit = true self.toggle_LeftGroup = self.group_LeftBtn.toggles_Group UTL.Toggle.InitToggleGroupByIDS(self.toggle_LeftGroup, "txt",{Const_IDS.IDS_Equip_Equip, Const_IDS.IDS_Equip_EquipChip}) self:RegistTriggerEvent(self.event_Plus, UIEventTriggerType.PointerDown) self:RegistTriggerEvent(self.event_Plus, UIEventTriggerType.PointerUp) self:RegistTriggerEvent(self.event_Minus, UIEventTriggerType.PointerDown) self:RegistTriggerEvent(self.event_Minus, UIEventTriggerType.PointerUp) self:RegistSystemEvent(EventID.UI_UpdateEquipmentInfo, self.UpdateInfo) self:RegistSystemEvent(EventID.UI_UpdateDebrisInfo, self.UpdateInfo) local mainTypeIndex = context and context.MainTabType or MDL.Equipment.MainTabType.EquipWhole self.toggle_LeftGroup:SelectIndex(mainTypeIndex) local equipSubIndex = context and context.EquipTabType or MDL.Equipment.EquipTabType.All self.toggle_TopGroup:SelectIndex(equipSubIndex) self.isInit = false if context and context.selectDebrisItemId then local selectIndex for i, info in ipairs(self.sortedList) do if info.ItemData.ID == context.selectDebrisItemId then selectIndex = i - 1 break end end if selectIndex ~= nil then self.ConditionScroll_EquipDebris:SelectIndex(selectIndex, true) end end self:RefreshRedPoint() end function UIEquipmentMain:OnFocusChanged(isFocus) if isFocus then if self.isFirstFocus then self.isFirstFocus = false else self:UpdateInfo() end end end --刷新界面 function UIEquipmentMain:UpdateInfo() --当焦点不在自身,不更新 if UIManager.IsFocus(Const_UI_Lua.UIEnum.UIEquipmentMain) == false then return end MDL.Equipment.UpdateSortedAllTypeList() if self.MainTypeIndex == MDL.Equipment.MainTabType.EquipWhole then self:SwitchWholeEquipType(self.EquipTypeIndex, true) else self:SwitchDebrisEquipType(self.EquipTypeIndex, true) end end function UIEquipmentMain:RefreshRedPoint() local isRed = CTL.Equipment.CheckEquipIfRed() self.toggle_LeftGroup:SetRedPoint(1, isRed) self.toggle_TopGroup:SetRedPoint(1, isRed) if isRed and self.MainTypeIndex == MDL.Equipment.MainTabType.EquipDebris then self.toggle_TopGroup:SetRedPoint(0, isRed) local redTab = CTL.Equipment.GetCombineRedTypeTab() if redTab then for i = 1, 4 do local state = redTab[i] or false self.toggle_TopGroup:SetRedPoint(i,state) end end else self.toggle_TopGroup:SetAllRedPoint(false) end end function UIEquipmentMain:SwitchMainType(mainTypeIndex) if self.MainTypeIndex and self.MainTypeIndex == mainTypeIndex then return end self.MainTypeIndex = mainTypeIndex if mainTypeIndex == MDL.Equipment.MainTabType.EquipWhole then --装备主界面 if self.EquipTypeIndex then self:SwitchWholeEquipType(self.EquipTypeIndex, true) end else --装备碎片 if self.EquipTypeIndex then self:SwitchDebrisEquipType(self.EquipTypeIndex, true) end end end function UIEquipmentMain:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.ConditionScroll_EquipWhole then --装备格子信息 UIUtils.SetLabelText(cellTable.txt_EquipName, Const_IDS[data.ItemData.Name]) CTL.Equipment.SetEquipShow(cellTable.img_Equip, nil, data.ItemData) UTL.Color.SetQualityImageByType(cellTable.img_Frame, data.ItemData.Color, UTL.Color.QualityType.EquipFrame) UTL.Color.SetQualityImageByType(cellTable.bg_Equip, data.ItemData.Color, UTL.Color.QualityType.EquipFrameBase) local heroId = MDL.Equipment.GetEquipHeroId(data.ID) if heroId then UIUtils.SetActive(cellTable.bg_Head, true) UTL.Item.SetHeroIconByHeroId(cellTable.img_PlayerHead, heroId, MDL.HeroAwaken.GetIsHeroAwaken(heroId)) else UIUtils.SetActive(cellTable.bg_Head, false) end UIUtils.SetActive(cellTable.img_Locked, MDL.HeroSelect.GetTeamLevel() < data.EquipData.EquipLevel) CTL.Equipment.SetEquipmentStage(cellTable.txt_EquipStageNum, data.ItemData.ID, false) UIUtils.SetActive(cellTable.txt_EquipStageNum, true) elseif scrollRect == self.ConditionScroll_EquipDebris then --装备碎片 local needNum = data.EquipData.ItemNum local curNum = data.Num cellTable.txt_Num.text = string.format("%s/%d", curNum >= needNum and UTL.Color.FormatGreenColor(curNum) or UTL.Color.FormatRedColor(curNum), needNum) UTL.Item.SetItemCell(cellTable.Item, data.ItemData.ID) UIUtils.SetActive(cellTable.sprite_redpoint.gameObject, CTL.Equipment.CheckDebrisIfRed(data)) cellTable.txt_EquipDebrisName.text = string.format("%s...", UTL.String.CutStrByLength(UIUtils.GetLocalizedTxt(Const_IDS[data.ItemData.Name]), MAX_NAME_LENGTH)) CTL.Equipment.SetEquipmentStage(cellTable.txt_EquipStageNum, data.ItemData.ID, true) UIUtils.SetActive(cellTable.txt_EquipStageNum, true) elseif scrollRect == self.loop_ItemSources then cellTable.txt_ItemSources.text = data.desc cellTable.state_ItemSources:SetState(data.isUnlock) end end function UIEquipmentMain:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.ConditionScroll_EquipWhole then local heroId = MDL.Equipment.GetEquipHeroId(data.ID) --打开信息/强化界面 if heroId then CTL.Equipment.OpenDetailByEquipInfo(data) else CTL.Equipment.OpenDetailByEquipInfo(data, MDL.Equipment.DetailType.Info) end elseif scrollRect == self.loop_ItemSources then if target == cellTable.btn_ItemSources then if data.isUnlock > 0 then if CTL.ItemSources.ExecuteSourceFunctionById(data.sourceId, self.selectDebrisInfo.ItemData.ID) then self:CloseView() end else CTL.Tips.AddTipsMsg(Const_IDS.IDS_Formation_RelationShip_Closed) end end else self:OnSelectDebrisItem(cellTable, data) end end function UIEquipmentMain:OnBackButtonPressed() self:OnButtonClicked(self.UITemplateTitlePanel.btn_close) end function UIEquipmentMain:OnButtonClicked(comp) if comp == self.UITemplateTitlePanel.btn_close then self:CloseView() elseif comp == self.UITemplateTitlePanel.btn_Home then CTL.HomeMain.CloseViewBackHomeMain() elseif comp == self.event_Syn then MDL.Equipment.CombineEquipRequest(self.selectDebrisInfo, self.curCombineNum) elseif comp == self.event_Get then self:OnClickItemSource() elseif comp == self.rect_CloseItemSources then UIUtils.SetActive(self.panel_ItemSources, false) UIUtils.SetActive(self.rect_CloseItemSources, false) elseif comp == self.bg_EquipDebris then if self.selectDebrisInfo then UTL.ItemTips.ShowCommonTipsById(self.selectDebrisInfo.ItemData.ID) end end end function UIEquipmentMain:OnValueChanged(comp, index) if comp == self.toggle_LeftGroup then self:SwitchMainType(index) self:SaveSelectedToggleIndex(index, nil) elseif comp == self.toggle_TopGroup then for i = 1, #self.group_toggleTxt do if i == index + 1 then self.group_toggleTxt[i].color = SelectedToggleColor else self.group_toggleTxt[i].color = UnSelectedToggleColor end end if self.MainTypeIndex == MDL.Equipment.MainTabType.EquipWhole then self:SwitchWholeEquipType(index, false) else self:SwitchDebrisEquipType(index, false) end self:SaveSelectedToggleIndex(nil, index) elseif comp == self.Slider then local minValue = self.enableCombineNum > 0 and 1 or 0 self.curCombineNum = math.max(minValue, index) self:RefreshSelectNum() end end function UIEquipmentMain:SaveSelectedToggleIndex(mainType, subType) if mainType then if self.context then self.context.MainTabType = mainType else self.context = {MainTabType = mainType} end end if subType then if self.context then self.context.EquipTabType = subType else self.context = {EquipTabType = subType} end end end --region 装备主界面 function UIEquipmentMain:SwitchWholeEquipType(equipTypeIndex, force) if self.EquipTypeIndex and self.EquipTypeIndex == equipTypeIndex and not force then return end self.toggle_TopGroup:SetAllRedPoint(false) self.ConditionScroll_EquipWhole:ClearCells() self.ConditionScroll_EquipDebris:ClearCells() local list = MDL.Equipment.GetSortedEquipmentsByType(equipTypeIndex, self.sortedList) if #list > 0 then self.empty_state:SetState(1) for _, info in ipairs(list) do self.ConditionScroll_EquipWhole:AddData(info, 0) end self:RefreshRedPoint() else self.empty_state:SetState(0) UIUtils.SetLabelText(self.lab,Const_IDS.IDS_Equip_NoEquip) end UIUtils.SetActive(self.group_EquipDebris, false) self.EquipTypeIndex = equipTypeIndex end --endregion --region 装备碎片 function UIEquipmentMain:SwitchDebrisEquipType(equipTypeIndex, force) if self.EquipTypeIndex and self.EquipTypeIndex == equipTypeIndex and not force then return end self.ConditionScroll_EquipWhole:ClearCells() self.ConditionScroll_EquipDebris:ClearCells() MDL.Equipment.GetSortedDebrisListByType(equipTypeIndex, self.sortedList) if #self.sortedList > 0 then self.empty_state:SetState(1) UIUtils.SetActive(self.group_EquipInfo.gameObject, true) for _, info in ipairs(self.sortedList) do self.ConditionScroll_EquipDebris:AddData(info, 0) end self.ConditionScroll_EquipDebris:SelectIndex(0) else UIUtils.SetActive(self.group_EquipInfo.gameObject, false) self.empty_state:SetState(0) UIUtils.SetLabelText(self.lab,Const_IDS.IDS_Equip_NoEquipChip) end UIUtils.SetActive(self.group_EquipDebris, true) self.EquipTypeIndex = equipTypeIndex self:RefreshRedPoint() end function UIEquipmentMain:OnSelectDebrisItem(selectItem, debrisInfo) self.selectDebrisInfo = debrisInfo if self.isInit == false then self.context.selectDebrisItemId = self.selectDebrisInfo.ItemData.ID end CTL.Equipment.SetEquipShow(self .img_EquipDebris, self.bg_EquipDebris.gameObject:GetComponent(typeof(Image)), debrisInfo.ItemData) UTL.Color.SetQualityImageByType(self.img_TopBg, debrisInfo.ItemData.Color, UTL.Color.QualityType.EquipFragmentComposeBase) UTL.Color.SetQualityImageByType(self.img_TopBgDec, debrisInfo.ItemData.Color, UTL.Color.QualityType.EquipRefineIcon) UIUtils.SetLabelText(self.txt_EquipDebrisName, Const_IDS[debrisInfo.ItemData.Name]) local needNum = debrisInfo.EquipData.ItemNum local curNum = debrisInfo.Num self.enableCombineNum = math.floor(curNum / needNum) self.txt_Num.text = string.format("%s/%d",curNum >= needNum and UTL.Color.FormatGreenColor(curNum) or UTL.Color.FormatRedColor(curNum), needNum) self.Slider.minValue = 0 self.Slider.maxValue = self.enableCombineNum self.event_Syn:SetGray(self.enableCombineNum == 0,true) self.event_Syn:SetRedPoint(self.enableCombineNum > 0) self.curCombineNum = self.enableCombineNum UIUtils.SetLabelText(self.txt_Info, Const_IDS[debrisInfo.ItemData.Des]) self:RefreshSelectNum() end function UIEquipmentMain:RefreshSelectNum() self.Slider.value = self.curCombineNum self.txt_NumSelect.text = string.format("%d/%d", self.curCombineNum, self.enableCombineNum) end function UIEquipmentMain:OnClickPlus() self.curCombineNum = math.min(self.curCombineNum + 1, self.enableCombineNum) self:RefreshSelectNum() end function UIEquipmentMain:OnClickMinus() self.curCombineNum = math.max(self.curCombineNum - 1, 0) self:RefreshSelectNum() end function UIEquipmentMain:OnPointerDown(comp, eventData) if comp == self.event_Plus then self:OnClickPlus() self:OnPressPlus() elseif comp == self.event_Minus then self:OnClickMinus() self:OnPressMinus() end end function UIEquipmentMain:OnPressPlus() self._pressPlus = true self:StartRepeatFunc(self.OnUpdateFun, ChangeItemCountSpeed) end function UIEquipmentMain:OnPressMinus() self._pressMinus = true self:StartRepeatFunc(self.OnUpdateFun, ChangeItemCountSpeed) end function UIEquipmentMain:OnPointerUp(comp, eventData) if comp == self.event_Plus then self:OnPressPlusStop() elseif comp == self.event_Minus then self:OnPressMinusStop() end end function UIEquipmentMain:OnPressPlusStop() self._pressPlus = false self:StopRepeatFunc(self.OnUpdateFun) end function UIEquipmentMain:OnPressMinusStop() self._pressMinus = false self:StopRepeatFunc(self.OnUpdateFun) end function UIEquipmentMain:OnUpdateFun(deltaTime, timeSineUpdate) if not self._pressPlus and not self._pressMinus then return end if self._pressPlus then self:OnClickPlus() end if self._pressMinus then self:OnClickMinus() end end --点击道具获取途径 function UIEquipmentMain:OnClickItemSource() self.loop_ItemSources:ClearCells() local sourcesList = MDL.ItemSources.GetItemSourcesById(self.selectDebrisInfo.ItemData.ID) if #sourcesList > 0 then UIUtils.SetActive(self.panel_ItemSources, true) for i, v in ipairs(sourcesList) do self.loop_ItemSources:AddData(v, 0) end UIUtils.SetActive(self.rect_CloseItemSources, true) else CTL.Tips.AddTipsMsg(Const_IDS.IDS_Equip_NoGetWay) UIUtils.SetActive(self.rect_CloseItemSources, false) end end function UIEquipmentMain:OnClosed() UIUtils.SetActive(self.UITemplateTitlePanel.btn_Info, true) end --endregion return UIEquipmentMain