PetRelationItemCtr.lua 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. local PetRelationItemCtr = {}
  2. local IconPetItemCtr = require("Common/IconPetItemCtr")
  3. function PetRelationItemCtr:SetData(wnd, item, logicData, enterType, onClickOwner, onClickCB, params)
  4. local cfgData = logicData
  5. local selected = params
  6. item.textName.text.text = I18N.T(cfgData.Name)
  7. local relationData = ManagerContainer.DataMgr.PetDataMgr:GetPetRelationDataByCfgId(cfgData.Id)
  8. local count = 0
  9. local cfgIds = {}
  10. for j = 3, 1, -1 do
  11. local condition = cfgData['Condition'..j]
  12. local state
  13. local relationAttr = item['relationAttr'..j]
  14. relationAttr:SetActive(condition ~= nil)
  15. if condition then
  16. count = count + 1
  17. local advance = 0
  18. for k,v in pairs(condition) do
  19. cfgIds[#cfgIds + 1] = v[1]
  20. advance = v[2]
  21. end
  22. if selected then
  23. local curCount = 0
  24. if relationData and relationData.relationPets then
  25. for k,v1 in pairs(relationData.relationPets) do
  26. local cfgId = condition[k][1]
  27. local num = condition[k][2]
  28. if v1.cfgId == cfgId and v1.advanceLevel >= num and v1.petId > 0 then
  29. curCount = curCount + 1
  30. end
  31. end
  32. end
  33. if item.grid.activeSelf and relationData and relationData.newActived == j then
  34. if relationAttr.uIEffectCfg and not relationAttr.uIEffectCfg.Ready then
  35. relationAttr.uIEffectCfg:LoadEffect()
  36. end
  37. if relationAttr.uIEffectCfg then
  38. relationAttr.uIEffectCfg:ShowEffect("FX_UI_TuPo_New",relationAttr.fx.transform)
  39. end
  40. relationData.newActived = 0
  41. end
  42. relationAttr.count.text.text = curCount .."/3"
  43. state = curCount >= 3
  44. relationAttr.activedState:SetActive(state)
  45. relationAttr.unactivatedState:SetActive(not state)
  46. local color = Constant.GrayColor
  47. if j == 1 then
  48. color = state and Constant.BlueColor or color
  49. elseif j == 2 then
  50. color = state and Constant.PurpleColor or color
  51. elseif j == 3 then
  52. color = state and Constant.GoldColor or color
  53. end
  54. relationAttr.bgActivedState.image.color = Color(color[1], color[2], color[3], color[4])
  55. relationAttr.attrDsc.text.text = I18N.SetLanguageValue("Petadfetter_001", advance)
  56. end
  57. end
  58. if condition and selected then
  59. local attribute = cfgData['attribute'..j]
  60. for i = 1, 3 do
  61. relationAttr["attr"..i]:SetActive(false)
  62. end
  63. if attribute then
  64. for i = 1,#attribute do
  65. local attr = relationAttr["attr"..i]
  66. if attr then
  67. attr:SetActive(attribute[i] ~= nil)
  68. if attribute[i] then
  69. local key = attribute[i][1]
  70. local val = key > 21 and CommonUtil.GetPreciseDecimal(attribute[i][2]*0.0001, 3) or math.floor(attribute[i][2])
  71. attr.text.text = I18N.T("Attr_"..attribute[i][1]).." "..CommonUtil.HeroAttrFormatValue(key, val, true)
  72. local color = state and Constant.GreenColor or Constant.GrayColor
  73. attr.text.color = Color(color[1], color[2], color[3], color[4])
  74. attr:SetActive(true)
  75. end
  76. end
  77. end
  78. end
  79. end
  80. end
  81. if relationData then
  82. for k,v in pairs(relationData.relationPets) do
  83. local cfgId = cfgIds[k]
  84. local advanceLv = v.advanceLevel
  85. if v.petId == 0 then
  86. advanceLv = 0
  87. end
  88. local itemlua = item['item'..k]
  89. local data = {cfgId = cfgId, advanceLevel = advanceLv}
  90. IconPetItemCtr:SetData(wnd,itemlua.iconPetItem, data, Enum.ItemIEnterType.PetRelation, onClickOwner, onClickCB, {cfgData.Id, k})
  91. CommonUtil.SetTotalChildrenGray(itemlua.iconPetItem.gameObject, v.petId == 0)
  92. itemlua.iconPetItem.nameBg:SetActive(v.petId > 0)
  93. itemlua.iconPetItem.qualityFX:SetActive(v.petId > 0)
  94. if v.petId > 0 then
  95. local uid = v.uid
  96. local nickname = uid == 0 and ManagerContainer.DataMgr.UserData:GetUserNickname() or ManagerContainer.DataMgr.PetDataMgr:GetRelationPlayerNameByUid(uid)
  97. itemlua.iconPetItem.petName.text.text = CommonUtil.GetShortVaildNickName(nickname)
  98. end
  99. end
  100. else
  101. for i = 1, 3 do
  102. local cfgId = cfgIds[i]
  103. local itemlua = item['item'..i]
  104. local data = {cfgId = cfgId, advanceLevel = 0}
  105. IconPetItemCtr:SetData(wnd,itemlua.iconPetItem, data, Enum.ItemIEnterType.PetRelation, onClickOwner, onClickCB, {cfgData.Id, i})
  106. CommonUtil.SetTotalChildrenGray(itemlua.iconPetItem.gameObject, true)
  107. itemlua.iconPetItem.nameBg:SetActive(false)
  108. itemlua.iconPetItem.qualityFX:SetActive(false)
  109. end
  110. end
  111. -- local rpIdxList = ManagerContainer.RedPointMgr.PetRPCtr:RefresgPetRelationState(cfgData.Id)
  112. -- for i = 1, 3 do
  113. -- local parent = item['item'..i].transform
  114. -- local redPoint = parent:Find("redPoint")
  115. -- local isIn = CommonUtil.EleInTable(i, rpIdxList)
  116. -- if redPoint then
  117. -- redPoint.gameObject:SetActive(isIn)
  118. -- else
  119. -- if isIn and rpIdxList and next(rpIdxList) then
  120. -- local go = ManagerContainer.ResMgr:GetGoFromPool(Constants.UIPath, "Common/UIRedPointRP")
  121. -- if go then
  122. -- redPoint = go.transform
  123. -- redPoint:SetParent(parent)
  124. -- redPoint.localRotation = Quaternion.identity
  125. -- redPoint.localScale = Vector3.one
  126. -- local rectTransform = redPoint:GetComponent(Enum.TypeInfo.RectTransform)
  127. -- rectTransform.anchoredPosition3D = Vector3(60, 60, 0)
  128. -- go.name = "redPoint"
  129. -- end
  130. -- end
  131. -- end
  132. -- end
  133. --item.grid:SetActive(false)
  134. --item.down:SetActive(true)
  135. --item.up:SetActive(false)
  136. return count
  137. end
  138. return PetRelationItemCtr