local UIHorseSoulStar = UIViewClass() function UIHorseSoulStar:OnOpened(context) self:RegistSystemEvent(EventID.BagItem_Update, self.RefreshBreakItem) self:RegistSystemEvent(EventID.UI_HorseSoul_Upgrade, self.StarUpgrade) self.selectMaterialDict = {} --key为id,用来判断该物品是否被选为材料 self.selectMaterialList = {} --value为id,被选为材料的数组,用于展示并且查找删除 end function UIHorseSoulStar:OnButtonClicked(comp) if comp == self.btn_Bottom then self:ActiveMaterialGroup(false) elseif comp == self.btn_Star then if #self.selectMaterialList == self.starLevelUpCount then local isHasLevelUp, isHasStarUp = false, false for i, v in ipairs(self.selectMaterialList) do local soulInfo = MDL.HorseSoul.GetSoulInfoById(v) if soulInfo.star > 0 then isHasStarUp = soulInfo.star > 0 break end if soulInfo.levelInfo.level > 1 then isHasLevelUp = soulInfo.levelInfo.level > 1 break end end if isHasStarUp or isHasLevelUp then UTL.MessageBox.ShowOKCancelBox(nil, Const_IDS.IDS_HorseSoul_StarHint5, function() self:ExecuteStarLevelUp() end, function() CTL.Reborn.OpenRebornView(MDL.Reborn.RebornToggleIndex.Recast, {RecastType = MDL.Reborn.RebornType.HorseSoul}) end, nil, Const_IDS.IDS_HorseSoul_StarHint6) else self:ExecuteStarLevelUp() end else CTL.Tips.AddTipsMsg(Const_IDS.IDS_HorseSoul_StarHint4) end end end function UIHorseSoulStar:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.loop_ItemMaterial then if type(data) ~= "number" and (data.isEmpty or data.isGet) then cellTable.state:SetState(1) UIUtils.SetActive(cellTable.img_Add, data.isGet or false) else local soulInfo = MDL.HorseSoul.GetSoulInfoById(data) if soulInfo then cellTable.state:SetState(0) UTL.Item.SetItemCell(cellTable.item, soulInfo.cfgId) cellTable.item.txt_Level.text = string.FormatByIdsKey("IDS_HorseSoul_Button3", soulInfo.levelInfo.level) CTL.HorseSoul.SetPositionImage(cellTable.item.img_Pos, soulInfo.soulData.HorseSoulPositionID) if soulInfo.itemData.Color >= LuaConst.QualityColor.Gold then CTL.HorseSoul.SetStarLevel(cellTable.item.group_Star, soulInfo.star) end else cellTable.state:SetState(1) UIUtils.SetActive(cellTable.img_Add, true) end end elseif scrollRect == self.loop_Material then local soulInfo = MDL.HorseSoul.GetSoulInfoById(data) if soulInfo then UTL.Item.SetItemCell(cellTable.item, soulInfo.cfgId) cellTable.item.txt_Level.text = string.FormatByIdsKey("IDS_HorseSoul_Button3", soulInfo.levelInfo.level) CTL.HorseSoul.SetPositionImage(cellTable.item.img_Pos, soulInfo.soulData.HorseSoulPositionID) if soulInfo.itemData.Color >= LuaConst.QualityColor.Gold then CTL.HorseSoul.SetStarLevel(cellTable.item.group_Star, soulInfo.star) cellTable.state_Mask:SetState(self.selectMaterialDict[data] and 4 or 0) else cellTable.state_Mask:SetState(self.selectMaterialDict[data] and 1 or 0) end end end end function UIHorseSoulStar:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.loop_ItemMaterial then if target == cellTable.btn_Get or target == cellTable.item.event_Click then self:ActiveMaterialGroup(true) end elseif scrollRect == self.loop_Material then local isChange = false if target == cellTable.item.event_Click then if not self.selectMaterialDict[data] then if #self.selectMaterialList < self.starLevelUpCount then self.selectMaterialDict[data] = 1 table.insert(self.selectMaterialList, data) isChange = true end end elseif target == cellTable.btn_Reduce then self.selectMaterialDict[data] = nil table.remove(self.selectMaterialList, self:GetIndexById(data)) isChange = true end if isChange then local soulInfo = MDL.HorseSoul.GetSoulInfoById(data) local itemID = soulInfo.cfgId UTL.Item.SetItemCell(cellTable.item, itemID) if self.selectMaterialDict[data] then if soulInfo.itemData.Color >= LuaConst.QualityColor.Gold then cellTable.state_Mask:SetState(4) else cellTable.state_Mask:SetState(1) end else cellTable.state_Mask:SetState(0) end self:SetStarUpMaterial() end end end function UIHorseSoulStar:RefreshSoulItem(soulId) self.soulInfo = MDL.HorseSoul.GetSoulInfoById(soulId) UTL.Item.OnlyItemIconWithoutBg(self.img_Item, self.soulInfo.cfgId) self.txt_Name.text = UTL.Color.FormatQualityText(UIUtils.GetLocalizedTxt(Const_IDS[self.soulInfo.itemData.Name]), self.soulInfo.itemData.Color) CTL.HorseSoul.SetPositionImage(self.img_Pos, self.soulInfo.soulData.HorseSoulPositionID) self.selectMaterialDict = {} self.selectMaterialList = {} if self.soulInfo.itemData.Color < LuaConst.QualityColor.Gold then self.state_Info:SetState(2) UIUtils.SetActive(self.group_Star.gameObject, false) self.effect_Bg:StopUIEffect() else UIUtils.SetActive(self.group_Star.gameObject, true) self.effect_Bg:PlayUIEffect() self:RefreshStarUpgradeInfo() end self:ActiveMaterialGroup(false) end function UIHorseSoulStar:RefreshStarUpgradeInfo() for k,v in ipairs(self.group_Star) do UIUtils.SetActive(v.img_Star, k <= self.soulInfo.star) if k <= self.soulInfo.star then v.effect_Light:PlayUIEffect() else v.effect_Light:StopUIEffect() end end if self.soulInfo.star == 3 then self.state_Info:SetState(1) UIUtils.SetLabel(self.group_Before.txt_LvBefore, string.FormatByIdsId(Const_IDS.IDS_HorseSoul_StarHint2, UIUtils.GetLocalizedTxt(Const_IDS["IDS_Number_Written_"..self.soulInfo.star]))) CTL.HorseSoul.SetStarLevel(self.group_Before.group_Star, self.soulInfo.star) local attrTable = CTL.HorseSoul.GetSoulAwakeAttrTable(self.soulInfo.soulData.HorseSoulStarAttrID, self.soulInfo.star) self:SetAttr(attrTable) else UIUtils.SetLabel(self.group_Before.txt_LvBefore, string.FormatByIdsId(Const_IDS.IDS_HorseSoul_StarHint2, UIUtils.GetLocalizedTxt(Const_IDS["IDS_Number_Written_"..self.soulInfo.star]))) for k,v in ipairs(self.group_Before.group_Star) do UIUtils.SetActive(v, k <= self.soulInfo.star) end UIUtils.SetLabel(self.group_After.txt_LvAfter, string.FormatByIdsId(Const_IDS.IDS_HorseSoul_StarHint2, UIUtils.GetLocalizedTxt(Const_IDS["IDS_Number_Written_"..(self.soulInfo.star + 1)]))) CTL.HorseSoul.SetStarLevel(self.group_After.group_Star, self.soulInfo.star + 1) self.state_Info:SetState(0) if self.soulInfo.star == 0 then local attrTable = CTL.HorseSoul.GetSoulAwakeAttrTable(self.soulInfo.soulData.HorseSoulStarAttrID, 1) self:SetAttr(nil, attrTable) else local attrTable = CTL.HorseSoul.GetSoulAwakeAttrTable(self.soulInfo.soulData.HorseSoulStarAttrID, self.soulInfo.star) local nextAttrTable = CTL.HorseSoul.GetSoulAwakeAttrTable(self.soulInfo.soulData.HorseSoulStarAttrID, self.soulInfo.star + 1) self:SetAttr(attrTable, nextAttrTable) end self:SetStarUpMaterial() end end function UIHorseSoulStar:SetAttr(nowAttrTable, nextAttrTable) local isInitStar = nowAttrTable == nil for i, v in ipairs(self.group_Attr) do local attrData = nowAttrTable and nowAttrTable[i] or nil local nextAttrData = nextAttrTable and nextAttrTable[i] or nil if attrData then UIUtils.SetActive(v.gameObject, true) UTL.Attr.SetAttrItemByCompName(v, attrData.AttrType, nil, true) if nextAttrData then v.txt_Attr.text = attrData.AttrNum v.txt_Next.text = nextAttrData.AttrNum else v.txt_Attr.text = attrData.AttrNum end elseif isInitStar then UIUtils.SetActive(v.gameObject, true) UTL.Attr.SetAttrItemByCompName(v, nextAttrData.AttrType, nil, true) v.txt_Attr.text = 0 v.txt_Next.text = nextAttrData.AttrNum else UIUtils.SetActive(v.gameObject, false) end end end function UIHorseSoulStar:SetStarUpMaterial() if self.loop_ItemMaterial.Count > 0 then self.loop_ItemMaterial:ClearCells() end self.starLevelUpCount = DataSheetManager.HorseSoulStarData:GetDataByHorseSoulStarAttrID_Star(self.soulInfo.soulData.HorseSoulStarAttrID, self.soulInfo.star + 1).NeedSoulNum for i = 1, self.starLevelUpCount do self.loop_ItemMaterial:AddData(self.selectMaterialList[i] or i, 0) end end function UIHorseSoulStar:ActiveMaterialGroup(active) UIUtils.SetActive(self.group_Material, active) UIUtils.SetActive(self.btn_Bottom, active) if active then self:RefreshMaterialLoop() end end function UIHorseSoulStar:RefreshMaterialLoop() if self.loop_Material.Count > 0 then self.loop_Material:ClearCells() end for i, v in ipairs(MDL.HorseSoul.GetSoulMaterialList()) do local soulInfo = MDL.HorseSoul.GetSoulInfoById(v) if self.soulInfo.id ~= soulInfo.id and not MDL.HorseSoul.JudgeIfEquip(v) and soulInfo.itemData.Color >= LuaConst.QualityColor.Gold and soulInfo.cfgId == self.soulInfo.cfgId then self.loop_Material:AddData(v, 0) end end UIUtils.SetActive(self.img_MaterialEmpty, self.loop_Material.Count == 0) end function UIHorseSoulStar:GetIndexById(soulId) for i, v in ipairs(self.selectMaterialList) do if v == soulId then return i end end end function UIHorseSoulStar:ExecuteStarLevelUp() self:ActiveMaterialGroup(false) for i, v in ipairs(self.selectMaterialList) do self.selectMaterialList[i] = {id = v, count = self.selectMaterialDict[v], bagTyp = MDL.HorseSoul.GetSoulInfoById(v).itemData.BagType} end MDL.HorseSoul.HorseSoulOptReq(MDL.HorseSoul.HorseSoulOptType.Star, self.soulInfo.id, self.selectMaterialList) self.selectMaterialList = {} end function UIHorseSoulStar:StarUpgrade(tempLevelData) local soulInfo = MDL.HorseSoul.GetSoulInfoById(tempLevelData.soulId) for k,v in ipairs(self.group_Star) do if k == soulInfo.star then v.effect_Twinkle:PlayUIEffect() end end self:StartRepeatFunc(function() for k,v in ipairs(self.group_Star) do if k == soulInfo.star then UIUtils.SetActive(v.img_Star, true) end end end, 0.1, 1) self:StartRepeatFunc(function() UIManager.OpenView(Const_UI_Lua.UIEnum.UIHorseSoulStarSuccess, {soulInfo = soulInfo}) self:RefreshStarUpgradeInfo() end, 0.5, 1) end return UIHorseSoulStar