local UIEquipmentCommon = require "View/Equipment/UIEquipmentCommon" local UIEquipmentGemInfo = UIViewClass(UIEquipmentCommon) local resonance_info = require 'Proto/resonance_info_pb' function UIEquipmentGemInfo:OnCreated() self.RedPoints = { [1] = self.group_Gem1.RedPoint.gameObject, [2] = self.group_Gem2.RedPoint.gameObject, [3] = self.group_Gem3.RedPoint.gameObject, [4] = self.group_Gem4.RedPoint.gameObject, } self.ArrowUps = { [1] = self.group_Gem1.arrowUp.gameObject, [2] = self.group_Gem2.arrowUp.gameObject, [3] = self.group_Gem3.arrowUp.gameObject, [4] = self.group_Gem4.arrowUp.gameObject, } self.AttrGruopItem = { [1] = self.group_1, [2] = self.group_2, [3] = self.group_3, [4] = self.group_4, } self.effect = { [1] = self.group_Gem1.EffectGem1, [2] = self.group_Gem2.EffectGem2, [3] = self.group_Gem3.EffectGem3, [4] = self.group_Gem4.EffectGem4, } self.InlayData = {} self.AttrDatas = {} self.dictAttr = {} self.ColorFormatStr = "%s" self.Color = "D5DEF4" self.CurGroup_Selected = nil self.PlayEffectGem = {} end function UIEquipmentGemInfo:OnGemQuickComposeSuccess() self:RefreshAllGems(self.equipInfo.ItemData.ThirdType) self.effect[self.QuickComposeIndex]:PlayUIEffect(ConstAssetPathConfig.AssetPath127, 2) end function UIEquipmentGemInfo:OnOpened(context) self:RegistSystemEvent(EventID.UI_GemQuickComposeSuccess, self.OnGemQuickComposeSuccess) self:RegistSystemEvent(EventID.UI_RefreshGemBagRedPoint, self.RefreshGemBagRedPoint) self:RegistSystemEvent(EventID.UI_GemInlayOrRemoveSuccess, self.OnGemInlayOrRemoveSuccess) for i=1,#self.RedPoints do UIUtils.SetActive(self.RedPoints[i], false) end for i=1,#self.ArrowUps do UIUtils.SetActive(self.ArrowUps[i], false) end self.btn_GemSyn:SetRedPoint(MDL.GemCompose.BagComposeRedPoint()) end function UIEquipmentGemInfo:OnGemInlayOrRemoveSuccess() for i = 1, 4 do self.PlayEffectGem[i] = self["Gem"..i.."ID"] end self:RefreshAllGems(self.equipInfo.ItemData.ThirdType) for i = 1, 4 do if self["Gem"..i.."ID"] > 0 and self.PlayEffectGem[i] ~= self["Gem"..i.."ID"] then self.effect[i]:PlayUIEffect(ConstAssetPathConfig.Path23, 2) end end end function UIEquipmentGemInfo:RefreshEquipInfo(equipInfo, heroId) if self.equipInfo ~= equipInfo or self.heroId ~= heroId then self.equipInfo = equipInfo self.heroId = heroId MDL.GemCompose.SetHeroID(heroId) self:RefreshAllGems(self.equipInfo.ItemData.ThirdType) end end function UIEquipmentGemInfo:RefreshAllGems(type) self.CurEquipType = type self.isEmpty = true self:RefreshTips() for i = #self.AttrDatas, 1, -1 do self.AttrDatas[i] = nil end for i = 1, 4 do self:InitGemInfo(i, type) end self:InitAttr() UIUtils.SetActive(self.group_NoneGem, self.isEmpty) end function UIEquipmentGemInfo:InitAttr() if #self.AttrDatas > 0 then self.group_BaseAttr:SetState(0) for i = 1, #self.AttrGruopItem do UIUtils.SetActive(self.AttrGruopItem[i].lab_1.transform.parent, false) end for k, v in pairs(self.dictAttr) do self.dictAttr[k] = nil end local fuckSortDict = {} for i = 1, #self.AttrDatas do local AttrCfgData local attrNum local JadeDataCfgData = self.AttrDatas[i] local attrTypeSortKey = 0 for k, v in pairs(JadeDataCfgData.Attr_Table) do AttrCfgData = DataSheetManager.AttrData:GetDataByID(v.AttrType) attrTypeSortKey = v.AttrType fuckSortDict[attrTypeSortKey] = Const_IDS[AttrCfgData.Name] attrNum = v.AttrNum end if self.dictAttr[Const_IDS[AttrCfgData.Name]] ~= nil then self.dictAttr[Const_IDS[AttrCfgData.Name]] = self.dictAttr[Const_IDS[AttrCfgData.Name]] + attrNum else self.dictAttr[Const_IDS[AttrCfgData.Name]] = attrNum end end local index = 0 local fuckKey = {} for k, v in pairs(fuckSortDict) do if v ~= nil then table.insert(fuckKey, k) end end table.sort(fuckKey) for i = 1, #fuckKey do local k = fuckSortDict[fuckKey[i]] local v = self.dictAttr[k] index = index + 1 UTL.Attr.SetAttrIcon(self.AttrGruopItem[index].img_Icon, fuckKey[i]) UIUtils.SetActive(self.AttrGruopItem[index].lab_1.transform.parent, true) UIUtils.SetLabelText(self.AttrGruopItem[index].lab_1, k) self.AttrGruopItem[index].txt_1.text = v end else self.group_BaseAttr:SetState(1) end end function UIEquipmentGemInfo:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.loop_GemInlayScroll then local gemBagData = data local itemId = gemBagData.ID local itemCfgData = DataSheetManager.ItemData:GetDataByID(itemId) local isInlay = gemBagData.IsOwner UIUtils.SetLabel(cellTable.txt_EquipName, UTL.Item.GetItemDataSpliceByType(itemId).Name) local JadeDataCfgData = DataSheetManager.JadeData:GetDataByID(itemId) local AttrDict = UTL.Item.GetAttrDict(JadeDataCfgData.Attr_Table) for k, v in pairs(AttrDict) do local colorValue = string.format( self.ColorFormatStr,self.Color, v) cellTable.txt_Info.text = k..' '..colorValue end UIUtils.SetActive(cellTable.img_Use, isInlay) if isInlay then UIUtils.SetLabelText(cellTable.btn_Get_Text, Const_IDS.IDS_Jade_Inset_4) else UIUtils.SetLabelText(cellTable.btn_Get_Text, self.HasGemInCurGemInlay and Const_IDS.IDS_Jade_Inset_3 or Const_IDS.IDS_Jade_Inset_2) end if self.HasGemInCurGemInlay then if self.CurInlayData ~= nil then local curInlayItemData = DataSheetManager.ItemData:GetDataByID(self.CurInlayData.ID) if curInlayItemData ~= nil then cellTable.btn_Get:SetRedPoint(itemCfgData.ThirdType > curInlayItemData.ThirdType) end end end UTL.Item.ItemSquareIcon(cellTable.img_Gem,cellTable.bg_Gem, itemId) cellTable.lab_Num.text = gemBagData.Count elseif scrollRect == self.loop_UnGemInlayScroll then local gemBagData = data local itemId = gemBagData.ID local isInlay = gemBagData.IsOwner UIUtils.SetLabel(cellTable.txt_EquipName, UTL.Item.GetItemDataSpliceByType(itemId).Name) local JadeDataCfgData = DataSheetManager.JadeData:GetDataByID(itemId) local AttrDict = UTL.Item.GetAttrDict(JadeDataCfgData.Attr_Table) for k, v in pairs(AttrDict) do local colorValue = string.format( self.ColorFormatStr,self.Color, v) cellTable.txt_Info.text = k..' '..colorValue end UIUtils.SetActive(cellTable.img_Use, isInlay) if isInlay then UIUtils.SetLabelText(cellTable.btn_Get_Text, Const_IDS.IDS_Jade_Inset_4) else UIUtils.SetLabelText(cellTable.btn_Get_Text, self.HasGemInCurGemInlay and Const_IDS.IDS_Jade_Inset_3 or Const_IDS.IDS_Jade_Inset_2) end cellTable.btn_Get:SetRedPoint(true) UTL.Item.ItemSquareIcon(cellTable.img_Gem,cellTable.bg_Gem, itemId) cellTable.lab_Num.text = gemBagData.Count end end function UIEquipmentGemInfo:OnCellClicked(scrollRect, index, cellTable, target, data) if target == cellTable.btn_Get then if data.IsOwner then MDL.GemCompose.RemoveJewelryReq(self.CurEquipType, self.CurGemInlayIndex) CTL.Sound.PlayGameSound("UI_equipment_01") else MDL.GemCompose.GemInlayReq(self.heroId, self.CurEquipType, data.ID, self.CurGemInlayIndex) CTL.Sound.PlayGameSound("UI_jeweled_01") end self:DisplayInlayPanel(false) end if scrollRect == self.loop_GemInlayScroll then if target == cellTable.btn_Tips then UTL.ItemTips.ShowCommonTipsById(data.ID) end elseif scrollRect == self.loop_UnGemInlayScroll then if target == cellTable.btn_Tips then UTL.ItemTips.ShowCommonTipsById(data.ID) end end end function UIEquipmentGemInfo:InitGemInfo(index, type) local GemTypeCfgData = MDL.GemCompose.GetGemTypeCfgData(type, index) local gemData = MDL.GemCompose.GetInlayGemInfo(type, index) local isOpen = MDL.Unlock.IsComplete(GemTypeCfgData.UnlockCondition, GemTypeCfgData.UnlockConditionParam) UIUtils.SetActive(self["group_Gem" .. index].group_Locked, not isOpen) self["Gem" .. index .. "ID"] = 0 local group_Gem = self["group_Gem" .. index] local group = self["group_" .. index] if gemData == nil then UIUtils.SetActive(group_Gem.group_UnGem, isOpen) UIUtils.SetActive(group.lab_1.transform.parent, false) UIUtils.SetActive(group_Gem.img_Gem, false) UIUtils.SetActive(group_Gem.btn_Click, false) local GemTypeCfgData = DataSheetManager.JadeType:GetDataByID_ChildID(type, index) UIUtils.SetLabelText(group_Gem.txt_GemName, Const_IDS[GemTypeCfgData.JadeTypeName]) else self.isEmpty = false UIUtils.SetActive(group.lab_1.transform.parent, true) UIUtils.SetActive(group_Gem.group_UnGem, false) UIUtils.SetActive(group_Gem.btn_Click, true) local ItemDataCfgData = DataSheetManager.ItemData:GetDataByID(gemData) self["Gem" .. index .. "ID"] = ItemDataCfgData.ID UIUtils.SetActive(group_Gem.img_Gem, true) UTL.Item.ItemIconWithoutBg(group_Gem.img_Gem, ItemDataCfgData.ID) UIUtils.SetLabel(group_Gem.txt_GemName, UTL.Item.GetItemDataSpliceByType(gemData).Name) local JadeDataCfgData = DataSheetManager.JadeData:GetDataByID(ItemDataCfgData.ID) table.insert(self.AttrDatas, JadeDataCfgData) end UIUtils.SetActive(group_Gem.group_Selected, false) end -- -----#Region---------------红点和箭头逻辑------------------------------------------ function UIEquipmentGemInfo:RefreshRedPoints(isDisplayArray) local inlayRed = false for i=1,#isDisplayArray do UIUtils.SetActive(self.RedPoints[i], isDisplayArray[i]) if inlayRed == false and isDisplayArray[i] then inlayRed = true end end self.btn_Inlay:SetRedPoint(inlayRed) end function UIEquipmentGemInfo:RefreshGemBagRedPoint() self.btn_GemSyn:SetRedPoint(MDL.GemCompose.BagComposeRedPoint()) self:RefreshTips() end function UIEquipmentGemInfo:RefreshTips() local redPointList = MDL.GemCompose.RedpointInfoByHero(self.heroId, self.CurEquipType) self:RefreshRedPoints(redPointList) self.QuickCompose = MDL.GemCompose.QuickComposeInfo(self.heroId, self.CurEquipType) for i = 1, #self.ArrowUps do --这里不能直接用redPointList,因为在计算合成的时候内部调用了计算红点的接口,redPointList已经被改变 if self.QuickCompose[i] and self.RedPoints[i].gameObject.activeSelf == false then UIUtils.SetActive(self.ArrowUps[i], true) else UIUtils.SetActive(self.ArrowUps[i], false) end end end -- -----#end Region---------------红点和箭头逻辑------------------------------------------ function UIEquipmentGemInfo:GoToShopView() UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIPayMallBasePanel, {tabId = CTL.PayMall.ShopTabType.Shop, childTabId = CTL.PayMall.PayMallMainTabId.Jade}) end function UIEquipmentGemInfo:DisplayGemBuyHint() if GameAppInfo.IsVietnamPackage() then CTL.Tips.AddTipsMsg(Const_IDS.IDS_LackOfSPJade) else UTL.MessageBox.ShowOKCancelBox(nil, Const_IDS.IDS_Jade_BuyHint, self.GoToShopView) end end --endregion --镶嵌弹出界面 function UIEquipmentGemInfo:DisplayInlayPanel(isDisplay, gemInlayIndex, CurInlayGemId, hasGem) if isDisplay == false then UIUtils.SetActive(self.panel_Inlay.gameObject, isDisplay) if self.CurGroup_Selected ~= nil then UIUtils.SetActive(self.CurGroup_Selected.gameObject, false) end return false end if hasGem == nil then local datas = MDL.GemCompose.GetInlayGemDatas(self.CurEquipType, gemInlayIndex, CurInlayGemId) if datas == nil or #datas <= 0 then UIUtils.SetActive(self.panel_Inlay.gameObject, false) self:DisplayGemBuyHint() if self.CurGroup_Selected ~= nil then UIUtils.SetActive(self.CurGroup_Selected.gameObject, false) end return false end end self.CurGemInlayIndex = gemInlayIndex self.HasGemInCurGemInlay = hasGem self.loop_GemInlayScroll:ClearCells() UIUtils.SetActive(self.panel_Inlay.gameObject, isDisplay) --load 宝石 self.loop_GemInlayScroll local JadeDataCfgDataName = (CurInlayGemId and CurInlayGemId>0) and DataSheetManager.JadeData:GetDataByID(CurInlayGemId) or nil if JadeDataCfgDataName ~= nil then local curGemTypeCfgData = DataSheetManager.JadeType:GetDataByID_ChildID(self.CurEquipType, gemInlayIndex) UIUtils.SetLabelText(self.txt_InlayTitle, Const_IDS[curGemTypeCfgData.JadeTypeName]) else -- self.CurEquipType gemInlayIndex local curGemTypeCfgData = DataSheetManager.JadeType:GetDataByID_ChildID(self.CurEquipType, gemInlayIndex) UIUtils.SetLabelText(self.txt_InlayTitle, Const_IDS[curGemTypeCfgData.JadeTypeName]) end if self.HasGemInCurGemInlay then UIUtils.SetActive(self.group_GemInlay, true) UIUtils.SetActive(self.group_UnGemIn, false) self.CurInlayGemId = CurInlayGemId self.InlayData.ID = CurInlayGemId self.InlayData.IsOwner = true self.InlayData.Count = 1 self.CurInlayData = self.InlayData local gemBagData = self.InlayData local itemId = gemBagData.ID local isInlay = gemBagData.IsOwner UIUtils.SetLabel(self.cell_GemInlay.txt_EquipName, UTL.Item.GetItemDataSpliceByType(itemId).Name) local JadeDataCfgData = DataSheetManager.JadeData:GetDataByID(itemId) local AttrDict = UTL.Item.GetAttrDict(JadeDataCfgData.Attr_Table) for k,v in pairs(AttrDict) do -- self.cell_GemInlay.txt_Info.text = k .. v local colorValue = string.format( self.ColorFormatStr,self.Color, v) self.cell_GemInlay.txt_Info.text = k..' '..colorValue end UIUtils.SetActive(self.cell_GemInlay.img_Use, isInlay) --IDS_Jade_Inset_3 更换 --IDS_Jade_Inset_2 镶嵌 --IDS_Jade_Inset_4 卸下 if isInlay then UIUtils.SetLabelText(self.cell_GemInlay.btn_Get_Text, Const_IDS.IDS_Jade_Inset_4) else UIUtils.SetLabelText(self.cell_GemInlay.btn_Get_Text, self.HasGemInCurGemInlay and Const_IDS.IDS_Jade_Inset_3 or Const_IDS.IDS_Jade_Inset_2) end UTL.Item.ItemSquareIcon(self.cell_GemInlay.img_Gem,self.cell_GemInlay.bg_Gem, itemId) self.cell_GemInlay.lab_Num.text = nil UIUtils.SetActive(self.cell_GemInlay.bg_Num, false) self.loop_GemInlayScroll:ClearCells() local datas = MDL.GemCompose.GetInlayGemDatas(self.CurEquipType, self.CurGemInlayIndex, CurInlayGemId) for i=1,#datas do self.loop_GemInlayScroll:AddData(datas[i],0) end else UIUtils.SetActive(self.group_GemInlay, false) UIUtils.SetActive(self.group_UnGemIn, true) self.loop_UnGemInlayScroll:ClearCells() local datas = MDL.GemCompose.GetInlayGemDatas(self.CurEquipType, self.CurGemInlayIndex, CurInlayGemId) for i=1,#datas do self.loop_UnGemInlayScroll:AddData(datas[i],0) end end return true end function UIEquipmentGemInfo:SetResonanceLvType() self.resonanceLvType = resonance_info.Jade_Insert end function UIEquipmentGemInfo:OnButtonClicked(comp) if comp == self.btn_Resonance then--共鸣 self:OnResonanceLvClick() elseif comp == self.btn_GemSyn then--合成 UIManager.OpenView(Const_UI_Lua.UIEnum.UIGemCompose) elseif comp == self.btn_Inlay then--一键镶嵌 if MDL.GemCompose.HasGem() then local canInlay = MDL.GemCompose.CanPlayInlayTips() if canInlay then MDL.GemCompose.GemInlayOneKyReq(self.heroId) CTL.Sound.PlayGameSound("UI_jeweled_02") end else CTL.Tips.AddTipsMsg(Const_IDS.IDS_Jade_Inset_9) end elseif comp == self.group_Gem1.add then local isDisplaySelect = self:DisplayInlayPanel(true, 1, self.Gem1ID) if isDisplaySelect then self:Selected(self.group_Gem1.group_Selected) end elseif comp == self.group_Gem2.add then local isDisplaySelect = self:DisplayInlayPanel(true, 2, self.Gem2ID) if isDisplaySelect then self:Selected(self.group_Gem2.group_Selected) end elseif comp == self.group_Gem3.add then local isDisplaySelect = self:DisplayInlayPanel(true, 3, self.Gem3ID) if isDisplaySelect then self:Selected(self.group_Gem3.group_Selected) end elseif comp == self.group_Gem4.add then local isDisplaySelect = self:DisplayInlayPanel(true, 4, self.Gem4ID) if isDisplaySelect then self:Selected(self.group_Gem4.group_Selected) end elseif comp == self.group_Gem1.btn_Click then local isDisplaySelect = self:DisplayInlayPanel(true, 1, self.Gem1ID, true) if isDisplaySelect then self:Selected(self.group_Gem1.group_Selected) end elseif comp == self.group_Gem2.btn_Click then local isDisplaySelect = self:DisplayInlayPanel(true, 2, self.Gem2ID, true) if isDisplaySelect then self:Selected(self.group_Gem2.group_Selected) end elseif comp == self.group_Gem3.btn_Click then local isDisplaySelect = self:DisplayInlayPanel(true, 3, self.Gem3ID, true) if isDisplaySelect then self:Selected(self.group_Gem3.group_Selected) end elseif comp == self.group_Gem4.btn_Click then local isDisplaySelect = self:DisplayInlayPanel(true, 4, self.Gem4ID, true) if isDisplaySelect then self:Selected(self.group_Gem4.group_Selected) end elseif comp == self.btn_Close then self:DisplayInlayPanel(false) elseif comp == self.cell_GemInlay.btn_Get then -- self.InlayData MDL.GemCompose.RemoveJewelryReq(self.CurEquipType, self.CurGemInlayIndex) CTL.Sound.PlayGameSound("UI_equipment_01") self:DisplayInlayPanel(false) elseif comp == self.group_Gem1.arrowUp then self.QuickComposeIndex = 1 UIManager.OpenView(Const_UI_Lua.UIEnum.UIGemUpgradeConfirm, {self.Gem1ID, self.CurEquipType, 1}) elseif comp == self.group_Gem2.arrowUp then self.QuickComposeIndex = 2 UIManager.OpenView(Const_UI_Lua.UIEnum.UIGemUpgradeConfirm, {self.Gem2ID, self.CurEquipType, 2}) elseif comp == self.group_Gem3.arrowUp then self.QuickComposeIndex = 3 UIManager.OpenView(Const_UI_Lua.UIEnum.UIGemUpgradeConfirm, {self.Gem3ID, self.CurEquipType, 3}) elseif comp == self.group_Gem4.arrowUp then self.QuickComposeIndex = 4 UIManager.OpenView(Const_UI_Lua.UIEnum.UIGemUpgradeConfirm, {self.Gem4ID, self.CurEquipType, 4}) elseif comp == self.group_Gem1.group_Locked then local curGemTypeCfgData = DataSheetManager.JadeType:GetDataByID_ChildID(self.CurEquipType, 1) local isUnlock, content = MDL.Unlock.IsComplete(curGemTypeCfgData.UnlockCondition, curGemTypeCfgData.UnlockConditionParam, "IDS_Jade_Inset_1") CTL.Tips.AddTipsMsg(content) elseif comp == self.group_Gem2.group_Locked then local curGemTypeCfgData = DataSheetManager.JadeType:GetDataByID_ChildID(self.CurEquipType, 2) local isUnlock, content = MDL.Unlock.IsComplete(curGemTypeCfgData.UnlockCondition, curGemTypeCfgData.UnlockConditionParam, "IDS_Jade_Inset_1") CTL.Tips.AddTipsMsg(content) elseif comp == self.group_Gem3.group_Locked then local curGemTypeCfgData = DataSheetManager.JadeType:GetDataByID_ChildID(self.CurEquipType, 3) local isUnlock, content = MDL.Unlock.IsComplete(curGemTypeCfgData.UnlockCondition, curGemTypeCfgData.UnlockConditionParam, "IDS_Jade_Inset_1") CTL.Tips.AddTipsMsg(content) elseif comp == self.group_Gem4.group_Locked then local curGemTypeCfgData = DataSheetManager.JadeType:GetDataByID_ChildID(self.CurEquipType, 4) local isUnlock, content = MDL.Unlock.IsComplete(curGemTypeCfgData.UnlockCondition, curGemTypeCfgData.UnlockConditionParam, "IDS_Jade_Inset_1") CTL.Tips.AddTipsMsg(content) elseif comp == self.cell_GemInlay.btn_Tips then UTL.ItemTips.ShowCommonTipsById(self.CurInlayGemId) end end function UIEquipmentGemInfo:Selected( selected ) if self.CurGroup_Selected ~= nil then UIUtils.SetActive(self.CurGroup_Selected.gameObject, false) end self.CurGroup_Selected = selected UIUtils.SetActive(self.CurGroup_Selected.gameObject, true) CTL.Sound.PlayGameSound("UI_click_add") end return UIEquipmentGemInfo