UIRoleNaturePointView.lua 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  1. local UIRoleNaturePointView = require("UIRoleMain/UIRoleNaturePointView_Generate")
  2. local oneAttrAddDic = {}
  3. local twoAttrAddDic = {}
  4. local baseList = {}
  5. local addList = {}
  6. function UIRoleNaturePointView:OnAwake(data)
  7. self.controller = require("UIRoleMain/UIRoleNaturePointCtr")
  8. self.controller:Init(self)
  9. self.controller:SetData(data)
  10. self:InitConfigData()
  11. end
  12. function UIRoleNaturePointView:InitConfigData()
  13. local cfgdata = GlobalConfig.Instance:GetConfigStrValue(312)
  14. self.cfgData = CommonUtil.DeserializeGlobalStrToNumberTable(cfgdata)
  15. end
  16. function UIRoleNaturePointView:AddEventListener()
  17. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.HERO_ATTR_ADD_SUCCESS, function(isReset)
  18. if isReset then
  19. twoAttrAddDic = {}
  20. end
  21. --self:RefreshAttrChangeSuccess()
  22. self:RefreshCurNaturePop()
  23. end)
  24. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.ACTOR_SERVER_CHANGE_ATTRS, function(tbArrtDeffrent)
  25. --LogError(Inspect(tbArrtDeffrent))
  26. twoAttrAddDic = {}
  27. --self:RefreshAttrChangeSuccess()
  28. self:RefreshCurNaturePop()
  29. end)
  30. end
  31. function UIRoleNaturePointView:FillContent(data, uiBase)
  32. self.uiBase = uiBase
  33. local gameObject = self.uiBase:GetRoot()
  34. if gameObject ~= nil then
  35. self.gameObject = gameObject
  36. self.transform = gameObject.transform
  37. end
  38. self:InitGenerate(self.transform, data)
  39. self:Init(true)
  40. end
  41. function UIRoleNaturePointView:OnPageInEnd()
  42. self.super.OnPageInEnd(self)
  43. self:RefreshCurNaturePop()
  44. end
  45. function UIRoleNaturePointView:Init(init)
  46. local logicData = self.controller:GetHeroLogicData()
  47. self.attr_plane.cUIPolygon:InitVertexsCount(6)
  48. self.strStart.transform.localPosition = self:RefreshAttrPlanePercentVec(logicData.attrs[Enum.HeroAttrType.STR], self.strEnd.transform.localPosition)
  49. self.agiStart.transform.localPosition = self:RefreshAttrPlanePercentVec(logicData.attrs[Enum.HeroAttrType.AGI], self.agiEnd.transform.localPosition)
  50. self.intStart.transform.localPosition = self:RefreshAttrPlanePercentVec(logicData.attrs[Enum.HeroAttrType.INT], self.intEnd.transform.localPosition)
  51. self.vitStart.transform.localPosition = self:RefreshAttrPlanePercentVec(logicData.attrs[Enum.HeroAttrType.VIT], self.vitEnd.transform.localPosition)
  52. self.dexStart.transform.localPosition = self:RefreshAttrPlanePercentVec(logicData.attrs[Enum.HeroAttrType.DEX], self.dexEnd.transform.localPosition)
  53. self.lukStart.transform.localPosition = self:RefreshAttrPlanePercentVec(logicData.attrs[Enum.HeroAttrType.LUK], self.lukEnd.transform.localPosition)
  54. self.attr_plane.cUIPolygon:RefreshPolygonVertexs()
  55. --self:RefreshCurNaturePop(init)
  56. self:RefreshRoleTop()
  57. end
  58. function UIRoleNaturePointView:RefreshRoleTop()
  59. local ownedCount = ManagerContainer.DataMgr.PartnerData:GetOwnedPartnerCount()
  60. self.btnLeft:SetActive(ownedCount > 0)
  61. self.btnRight:SetActive(ownedCount > 0)
  62. local id = self.controller:GetData()
  63. local cfgData = CommonUtil.GetHeroCfgDataByUid(id)
  64. CommonUtil.LoadIcon(self, cfgData.BattleCartoonImg, function (sprite)
  65. self.roleImg.role.image.sprite = sprite
  66. end)
  67. local heroData = self.controller:GetHeroLogicData()
  68. local jobName, roleName = CommonUtil.GetHeroSplitJobAndNameByUid(id, heroData.configId)
  69. self.roleImg.textBox.uILocalizeScript:SetContentAndValues("DscRoleTalk", {jobName, roleName})
  70. end
  71. function UIRoleNaturePointView:RefreshCurNaturePop(init)
  72. for i = Enum.HeroAttrType.STR, Enum.HeroAttrType.LUK do
  73. oneAttrAddDic[i] = 0
  74. end
  75. twoAttrAddDic = {}
  76. --self.controller:NilOldSlot()
  77. self.controller:ResetRemainPoints()
  78. self:RefreshPoints()
  79. self:RereshTopAttrs(init)
  80. -- 慧勇需求,在打开过属性界面,主界面的提示分配属性点的按钮就不显示
  81. --ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.MAIN_VIEW_SET_ATTR_BTN)
  82. end
  83. local function PointIncreased()
  84. for _,v in pairs(oneAttrAddDic) do
  85. if v > 0 then
  86. return true
  87. end
  88. end
  89. return false
  90. end
  91. function UIRoleNaturePointView:RefreshAttrPlanePercentVec(val, endPos)
  92. local percent = self.controller:GetAttrPlanePercent(SDataUtil.InvConvert(val))
  93. percent = math.min(100, percent + 10)
  94. local length = endPos - self.center.transform.localPosition
  95. return self.center.transform.localPosition + length * percent /100
  96. --self.attr_plane.meshVerticeMove:SetMeshPosition(GetAttrPlaneIndex(index), curPos)
  97. end
  98. local function GetBaseAttrsByType(baseAttrs, type)
  99. if baseAttrs == nil then return 0 end
  100. if baseAttrs[type] == nil then return 0 end
  101. return SDataUtil.InvConvert(baseAttrs[type] or 0)
  102. end
  103. function UIRoleNaturePointView:RefreshPoints()
  104. --local isLeader = self.controller:IsLeader()
  105. --local userData = self.controller:GetHeroLogicData()
  106. local baseAttrs = self.controller:GetLastBaseAttrs()
  107. --self.leadBox:SetActive(isLeader)
  108. --self.ptBox:SetActive(not isLeader)
  109. for k,v in pairs(oneAttrAddDic) do
  110. if k == Enum.HeroAttrType.STR then
  111. self.strStart.transform.localPosition = self:RefreshAttrPlanePercentVec(GetBaseAttrsByType(baseAttrs, Enum.HeroAttrType.STR)+ v, self.strEnd.transform.localPosition)
  112. elseif k == Enum.HeroAttrType.AGI then
  113. self.agiStart.transform.localPosition = self:RefreshAttrPlanePercentVec(GetBaseAttrsByType(baseAttrs, Enum.HeroAttrType.AGI) + v, self.agiEnd.transform.localPosition)
  114. elseif k == Enum.HeroAttrType.INT then
  115. self.intStart.transform.localPosition = self:RefreshAttrPlanePercentVec(GetBaseAttrsByType(baseAttrs, Enum.HeroAttrType.INT)+ v, self.intEnd.transform.localPosition)
  116. elseif k == Enum.HeroAttrType.VIT then
  117. self.vitStart.transform.localPosition = self:RefreshAttrPlanePercentVec(GetBaseAttrsByType(baseAttrs, Enum.HeroAttrType.VIT)+ v, self.vitEnd.transform.localPosition)
  118. elseif k == Enum.HeroAttrType.DEX then
  119. self.dexStart.transform.localPosition = self:RefreshAttrPlanePercentVec(GetBaseAttrsByType(baseAttrs, Enum.HeroAttrType.DEX)+ v, self.dexEnd.transform.localPosition)
  120. elseif k == Enum.HeroAttrType.LUK then
  121. self.lukStart.transform.localPosition = self:RefreshAttrPlanePercentVec(GetBaseAttrsByType(baseAttrs, Enum.HeroAttrType.LUK)+ v, self.lukEnd.transform.localPosition)
  122. end
  123. end
  124. self.attr_plane.cUIPolygon:RefreshPolygonVertexs()
  125. --if isLeader then
  126. self.leadBox.str.number1.text.text = GetBaseAttrsByType(baseAttrs, Enum.HeroAttrType.STR)
  127. self.leadBox.agi.number1.text.text = GetBaseAttrsByType(baseAttrs, Enum.HeroAttrType.AGI)
  128. self.leadBox.int.number1.text.text = GetBaseAttrsByType(baseAttrs, Enum.HeroAttrType.INT)
  129. self.leadBox.vit.number1.text.text = GetBaseAttrsByType(baseAttrs, Enum.HeroAttrType.VIT)
  130. self.leadBox.dex.number1.text.text = GetBaseAttrsByType(baseAttrs, Enum.HeroAttrType.DEX)
  131. self.leadBox.luk.number1.text.text = GetBaseAttrsByType(baseAttrs, Enum.HeroAttrType.LUK)
  132. local strCost = ManagerContainer.CfgMgr:GetHeroQualityPointByLv(GetBaseAttrsByType(baseAttrs, Enum.HeroAttrType.STR)+ oneAttrAddDic[Enum.HeroAttrType.STR]).cost
  133. local agiCost = ManagerContainer.CfgMgr:GetHeroQualityPointByLv(GetBaseAttrsByType(baseAttrs, Enum.HeroAttrType.AGI)+ oneAttrAddDic[Enum.HeroAttrType.AGI]).cost
  134. local intCost = ManagerContainer.CfgMgr:GetHeroQualityPointByLv(GetBaseAttrsByType(baseAttrs, Enum.HeroAttrType.INT)+ oneAttrAddDic[Enum.HeroAttrType.INT]).cost
  135. local vitCost = ManagerContainer.CfgMgr:GetHeroQualityPointByLv(GetBaseAttrsByType(baseAttrs, Enum.HeroAttrType.VIT)+ oneAttrAddDic[Enum.HeroAttrType.VIT]).cost
  136. local dexCost = ManagerContainer.CfgMgr:GetHeroQualityPointByLv(GetBaseAttrsByType(baseAttrs, Enum.HeroAttrType.DEX)+ oneAttrAddDic[Enum.HeroAttrType.DEX]).cost
  137. local lukCost = ManagerContainer.CfgMgr:GetHeroQualityPointByLv(GetBaseAttrsByType(baseAttrs, Enum.HeroAttrType.LUK)+ oneAttrAddDic[Enum.HeroAttrType.LUK]).cost
  138. self.leadBox.str.number2.text.text = strCost
  139. self.leadBox.agi.number2.text.text = agiCost
  140. self.leadBox.int.number2.text.text = intCost
  141. self.leadBox.vit.number2.text.text = vitCost
  142. self.leadBox.dex.number2.text.text = dexCost
  143. self.leadBox.luk.number2.text.text = lukCost
  144. local totalPoints = self.controller:GetRemainPoint()
  145. self.leadBox.restPoint.number1.text.text = tostring(totalPoints)
  146. -- local strStatus = totalPoints >= strCost and ManagerContainer.CfgMgr:GetHeroQualityPointByLv(GetBaseAttrsByType(baseAttrs, Enum.HeroAttrType.STR)+ 1) ~= nil
  147. local strStatus = SDataUtil.IsGreaterEqual(totalPoints,strCost) and ManagerContainer.CfgMgr:GetHeroQualityPointByLv(GetBaseAttrsByType(baseAttrs, Enum.HeroAttrType.STR)+ 1) ~= nil
  148. self.leadBox.str.btnReduce:SetActive(oneAttrAddDic[Enum.HeroAttrType.STR] > 0 and ManagerContainer.CfgMgr:GetHeroQualityPointByLv(GetBaseAttrsByType(baseAttrs, Enum.HeroAttrType.STR)+ 1) ~= nil )
  149. self.leadBox.str.btnIncrease:SetActive(strStatus)
  150. self.leadBox.str.numberGreen:SetActive(oneAttrAddDic[Enum.HeroAttrType.STR] > 0)
  151. -- local agiStatus = totalPoints >= agiCost and ManagerContainer.CfgMgr:GetHeroQualityPointByLv(baseAttrs[Enum.HeroAttrType.AGI] + 1) ~= nil
  152. local agiStatus = SDataUtil.IsGreaterEqual(totalPoints,agiCost) and ManagerContainer.CfgMgr:GetHeroQualityPointByLv(SDataUtil.InvConvert(baseAttrs[Enum.HeroAttrType.AGI]) + 1) ~= nil
  153. self.leadBox.agi.btnReduce:SetActive(oneAttrAddDic[Enum.HeroAttrType.AGI] > 0 and ManagerContainer.CfgMgr:GetHeroQualityPointByLv(GetBaseAttrsByType(baseAttrs, Enum.HeroAttrType.AGI) + 1) ~= nil )
  154. self.leadBox.agi.btnIncrease:SetActive(agiStatus)
  155. self.leadBox.agi.numberGreen:SetActive(oneAttrAddDic[Enum.HeroAttrType.AGI] > 0)
  156. -- local intStatus = totalPoints >= intCost and ManagerContainer.CfgMgr:GetHeroQualityPointByLv(baseAttrs[Enum.HeroAttrType.INT]+ 1) ~= nil
  157. local intStatus = SDataUtil.IsGreaterEqual(totalPoints,intCost) and ManagerContainer.CfgMgr:GetHeroQualityPointByLv(SDataUtil.InvConvert(baseAttrs[Enum.HeroAttrType.INT])+ 1) ~= nil
  158. self.leadBox.int.btnReduce:SetActive(oneAttrAddDic[Enum.HeroAttrType.INT] > 0 and ManagerContainer.CfgMgr:GetHeroQualityPointByLv(GetBaseAttrsByType(baseAttrs, Enum.HeroAttrType.INT)+ 1) ~= nil )
  159. self.leadBox.int.btnIncrease:SetActive(intStatus)
  160. self.leadBox.int.numberGreen:SetActive(oneAttrAddDic[Enum.HeroAttrType.INT] > 0)
  161. -- local vitStatus = totalPoints >= vitCost and ManagerContainer.CfgMgr:GetHeroQualityPointByLv(baseAttrs[Enum.HeroAttrType.VIT]+ 1) ~= nil
  162. local vitStatus = SDataUtil.IsGreaterEqual(totalPoints,vitCost) and ManagerContainer.CfgMgr:GetHeroQualityPointByLv(SDataUtil.InvConvert(baseAttrs[Enum.HeroAttrType.VIT])+ 1) ~= nil
  163. self.leadBox.vit.btnReduce:SetActive(oneAttrAddDic[Enum.HeroAttrType.VIT] > 0 and ManagerContainer.CfgMgr:GetHeroQualityPointByLv(GetBaseAttrsByType(baseAttrs, Enum.HeroAttrType.VIT)+ 1) ~= nil )
  164. self.leadBox.vit.btnIncrease:SetActive(vitStatus)
  165. self.leadBox.vit.numberGreen:SetActive(oneAttrAddDic[Enum.HeroAttrType.VIT] > 0)
  166. -- local dexStatus = totalPoints >= dexCost and ManagerContainer.CfgMgr:GetHeroQualityPointByLv(baseAttrs[Enum.HeroAttrType.DEX]+ 1) ~= nil
  167. local dexStatus = SDataUtil.IsGreaterEqual(totalPoints,dexCost) and ManagerContainer.CfgMgr:GetHeroQualityPointByLv(SDataUtil.InvConvert(baseAttrs[Enum.HeroAttrType.DEX])+ 1) ~= nil
  168. self.leadBox.dex.btnReduce:SetActive(oneAttrAddDic[Enum.HeroAttrType.DEX] > 0 and ManagerContainer.CfgMgr:GetHeroQualityPointByLv(GetBaseAttrsByType(baseAttrs, Enum.HeroAttrType.DEX)+ 1) ~= nil )
  169. self.leadBox.dex.btnIncrease:SetActive(dexStatus)
  170. self.leadBox.dex.numberGreen:SetActive(oneAttrAddDic[Enum.HeroAttrType.DEX] > 0)
  171. -- local lukStatus = totalPoints >= lukCost and ManagerContainer.CfgMgr:GetHeroQualityPointByLv(baseAttrs[Enum.HeroAttrType.LUK]+ 1) ~= nil
  172. local lukStatus = SDataUtil.IsGreaterEqual(totalPoints,lukCost) and ManagerContainer.CfgMgr:GetHeroQualityPointByLv(SDataUtil.InvConvert(baseAttrs[Enum.HeroAttrType.LUK])+ 1) ~= nil
  173. self.leadBox.luk.btnReduce:SetActive(oneAttrAddDic[Enum.HeroAttrType.LUK] > 0 and ManagerContainer.CfgMgr:GetHeroQualityPointByLv(GetBaseAttrsByType(baseAttrs, Enum.HeroAttrType.LUK)+ 1) ~= nil )
  174. self.leadBox.luk.btnIncrease:SetActive(lukStatus)
  175. self.leadBox.luk.numberGreen:SetActive(oneAttrAddDic[Enum.HeroAttrType.LUK] > 0)
  176. self.btnConfirm:SetActive(PointIncreased())
  177. -- self.btnRecommend:SetActive(totalPoints >= 0)
  178. self.btnRecommend:SetActive(strStatus or agiStatus or intStatus or vitStatus or dexStatus or lukStatus)
  179. --else
  180. -- self.ptBox.str.number1.text.text = tostring(userData.attrs[Enum.HeroAttrType.STR])
  181. -- self.ptBox.agi.number1.text.text = tostring(userData.attrs[Enum.HeroAttrType.AGI])
  182. -- self.ptBox.int.number1.text.text = tostring(userData.attrs[Enum.HeroAttrType.INT])
  183. -- self.ptBox.vit.number1.text.text = tostring(userData.attrs[Enum.HeroAttrType.VIT])
  184. -- self.ptBox.dex.number1.text.text = tostring(userData.attrs[Enum.HeroAttrType.DEX])
  185. -- self.ptBox.luk.number1.text.text = tostring(userData.attrs[Enum.HeroAttrType.LUK])
  186. -- self.btnConfirm:SetActive(false)
  187. -- self.btnRecommend:SetActive(false)
  188. --end
  189. end
  190. function UIRoleNaturePointView:RefreshTableAttrs(v, k, list)
  191. local isIn = false
  192. for _,v1 in pairs(list) do
  193. if v1[1] == k then
  194. isIn = true
  195. v1[2] = v
  196. v1[3] = twoAttrAddDic[k] or 0
  197. end
  198. end
  199. if not isIn then
  200. list[#list + 1] = {k, v, twoAttrAddDic[k] or 0}
  201. end
  202. end
  203. function UIRoleNaturePointView:RereshTopAttrs(init)
  204. -- ManagerContainer.DataMgr.UserData:RefreshAddPointAttr()
  205. local userData = self.controller:GetHeroLogicData()
  206. baseList = {}
  207. addList = {}
  208. for k,v in pairs(userData.attrs) do
  209. if (k >= Enum.HeroAttrType.Life and k <= Enum.HeroAttrType.CastAcceleration) then
  210. baseList[#baseList + 1] = {k, v, twoAttrAddDic[k] or 0}
  211. else
  212. if #userData.attrs > 0 then
  213. if k >= Enum.HeroAttrType.RealHurt then
  214. if SDataUtil.InvConvertDouble(v) > 0 then
  215. addList[#addList + 1] = {k, v, twoAttrAddDic[k] or 0}
  216. end
  217. end
  218. end
  219. end
  220. end
  221. if self.baseSView.loopVerticalScrollRect.totalCount ~= #baseList then
  222. self.baseSView.loopVerticalScrollRect:ClearCells()
  223. CommonUtil.LoopGridViewEleCreateNew(self, self.baseSView.loopVerticalScrollRect, self.baseSView.content.gridLayoutGroup, baseList, 0, nil, function (itemLua, idx)
  224. CommonUtil.UpdateItemPrefab(self, itemLua, baseList[idx + 1])
  225. end)
  226. else
  227. self.baseSView.loopVerticalScrollRect:RefreshCellsData()
  228. end
  229. if self.addSView.loopVerticalScrollRect.totalCount ~= #addList then
  230. self.addSView.loopVerticalScrollRect:ClearCells()
  231. CommonUtil.LoopGridViewEleCreateNew(self, self.addSView.loopVerticalScrollRect, self.addSView.content.gridLayoutGroup, addList, 0, nil, function (itemLua, idx)
  232. CommonUtil.UpdateItemPrefab(self, itemLua, addList[idx + 1])
  233. end)
  234. else
  235. self.addSView.loopVerticalScrollRect:RefreshCellsData()
  236. end
  237. self.addSView:SetActive(#addList > 0)
  238. self.none:SetActive(#addList == 0)
  239. end
  240. function UIRoleNaturePointView:ChangeAttrPreview(attrType, increase)
  241. local baseAttrs = self.controller:GetLastBaseAttrs()
  242. local cost = 0
  243. if attrType == Enum.HeroAttrType.STR then
  244. cost = increase and -ManagerContainer.CfgMgr:GetHeroQualityPointByLv(GetBaseAttrsByType(baseAttrs, Enum.HeroAttrType.STR)+ oneAttrAddDic[attrType]).cost or ManagerContainer.CfgMgr:GetHeroQualityPointByLv(SDataUtil.InvConvert(baseAttrs[Enum.HeroAttrType.STR])+ oneAttrAddDic[attrType] - 1).cost
  245. elseif attrType == Enum.HeroAttrType.AGI then
  246. cost = increase and -ManagerContainer.CfgMgr:GetHeroQualityPointByLv(GetBaseAttrsByType(baseAttrs, Enum.HeroAttrType.AGI) + oneAttrAddDic[attrType]).cost or ManagerContainer.CfgMgr:GetHeroQualityPointByLv(SDataUtil.InvConvert(baseAttrs[Enum.HeroAttrType.AGI]) + oneAttrAddDic[attrType] - 1).cost
  247. elseif attrType == Enum.HeroAttrType.INT then
  248. cost = increase and -ManagerContainer.CfgMgr:GetHeroQualityPointByLv(GetBaseAttrsByType(baseAttrs, Enum.HeroAttrType.INT)+ oneAttrAddDic[attrType]).cost or ManagerContainer.CfgMgr:GetHeroQualityPointByLv(SDataUtil.InvConvert(baseAttrs[Enum.HeroAttrType.INT])+ oneAttrAddDic[attrType] - 1).cost
  249. elseif attrType == Enum.HeroAttrType.VIT then
  250. cost = increase and -ManagerContainer.CfgMgr:GetHeroQualityPointByLv(GetBaseAttrsByType(baseAttrs, Enum.HeroAttrType.VIT)+ oneAttrAddDic[attrType]).cost or ManagerContainer.CfgMgr:GetHeroQualityPointByLv(SDataUtil.InvConvert(baseAttrs[Enum.HeroAttrType.VIT])+ oneAttrAddDic[attrType] - 1).cost
  251. elseif attrType == Enum.HeroAttrType.DEX then
  252. cost = increase and -ManagerContainer.CfgMgr:GetHeroQualityPointByLv(GetBaseAttrsByType(baseAttrs, Enum.HeroAttrType.DEX)+ oneAttrAddDic[attrType]).cost or ManagerContainer.CfgMgr:GetHeroQualityPointByLv(SDataUtil.InvConvert(baseAttrs[Enum.HeroAttrType.DEX])+ oneAttrAddDic[attrType] - 1).cost
  253. elseif attrType == Enum.HeroAttrType.LUK then
  254. cost = increase and -ManagerContainer.CfgMgr:GetHeroQualityPointByLv(GetBaseAttrsByType(baseAttrs, Enum.HeroAttrType.LUK)+ oneAttrAddDic[attrType]).cost or ManagerContainer.CfgMgr:GetHeroQualityPointByLv(SDataUtil.InvConvert(baseAttrs[Enum.HeroAttrType.LUK])+ oneAttrAddDic[attrType] - 1).cost
  255. end
  256. -- if self.controller:GetRemainPoint() + cost < 0 then
  257. -- return
  258. -- end
  259. if SDataUtil.IsLess(SDataUtil.Add(self.controller:GetRemainPoint(),cost),0 ) then
  260. return
  261. end
  262. local totalPoints = self.controller:ChangeRemainPoint(cost)
  263. self.leadBox.restPoint.number1.text.text = tostring(totalPoints)
  264. oneAttrAddDic[attrType] = oneAttrAddDic[attrType] + (increase and 1 or -1)
  265. self:RefreshAllAttr(attrType)
  266. end
  267. function UIRoleNaturePointView:RefreshAllAttr(attrType)
  268. local baseAttrs = self.controller:GetLastBaseAttrs()
  269. for i = Enum.HeroAttrType.STR, Enum.HeroAttrType.LUK do
  270. if oneAttrAddDic[i] == nil then
  271. oneAttrAddDic[i] = 0
  272. end
  273. end
  274. if attrType == Enum.HeroAttrType.STR then
  275. self.leadBox.str.numberGreen.text.text = CommonUtil.StringConcat("+", oneAttrAddDic[attrType])
  276. elseif attrType == Enum.HeroAttrType.AGI then
  277. self.leadBox.agi.numberGreen.text.text = CommonUtil.StringConcat("+", oneAttrAddDic[attrType])
  278. elseif attrType == Enum.HeroAttrType.INT then
  279. self.leadBox.int.numberGreen.text.text = CommonUtil.StringConcat("+", oneAttrAddDic[attrType])
  280. elseif attrType == Enum.HeroAttrType.VIT then
  281. self.leadBox.vit.numberGreen.text.text = CommonUtil.StringConcat("+", oneAttrAddDic[attrType])
  282. elseif attrType == Enum.HeroAttrType.DEX then
  283. self.leadBox.dex.numberGreen.text.text = CommonUtil.StringConcat("+", oneAttrAddDic[attrType])
  284. elseif attrType == Enum.HeroAttrType.LUK then
  285. self.leadBox.luk.numberGreen.text.text = CommonUtil.StringConcat("+", oneAttrAddDic[attrType])
  286. elseif attrType == nil then
  287. self.leadBox.str.numberGreen.text.text = CommonUtil.StringConcat("+", oneAttrAddDic[Enum.HeroAttrType.STR])
  288. self.leadBox.agi.numberGreen.text.text = CommonUtil.StringConcat("+", oneAttrAddDic[Enum.HeroAttrType.AGI])
  289. self.leadBox.int.numberGreen.text.text = CommonUtil.StringConcat("+", oneAttrAddDic[Enum.HeroAttrType.INT])
  290. self.leadBox.vit.numberGreen.text.text = CommonUtil.StringConcat("+", oneAttrAddDic[Enum.HeroAttrType.VIT])
  291. self.leadBox.dex.numberGreen.text.text = CommonUtil.StringConcat("+", oneAttrAddDic[Enum.HeroAttrType.DEX])
  292. self.leadBox.luk.numberGreen.text.text = CommonUtil.StringConcat("+", oneAttrAddDic[Enum.HeroAttrType.LUK])
  293. end
  294. local dic = ManagerContainer.LuaActorDataMgr:GetRoleIncreaseSecondAttrVal(self.controller:GetData(),
  295. oneAttrAddDic[Enum.HeroAttrType.STR] + GetBaseAttrsByType(baseAttrs, Enum.HeroAttrType.STR),
  296. oneAttrAddDic[Enum.HeroAttrType.AGI] + GetBaseAttrsByType(baseAttrs, Enum.HeroAttrType.AGI),
  297. oneAttrAddDic[Enum.HeroAttrType.INT] + GetBaseAttrsByType(baseAttrs, Enum.HeroAttrType.INT),
  298. oneAttrAddDic[Enum.HeroAttrType.VIT] + GetBaseAttrsByType(baseAttrs, Enum.HeroAttrType.VIT),
  299. oneAttrAddDic[Enum.HeroAttrType.DEX] + GetBaseAttrsByType(baseAttrs, Enum.HeroAttrType.DEX),
  300. oneAttrAddDic[Enum.HeroAttrType.LUK] + GetBaseAttrsByType(baseAttrs, Enum.HeroAttrType.LUK)
  301. )
  302. local iter = dic:GetEnumerator()
  303. local userData = self.controller:GetHeroLogicData()
  304. while iter:MoveNext() do
  305. -- LogError("Add "..tostring(iter.Current.Value))
  306. local newAttrs = userData.attrs
  307. -- LogError(Inspect(newAttrs))
  308. --服务器整数增量 = 取下整(当前本地增量 + 服务器当前 )- 取下整(服务器当前)
  309. if newAttrs[iter.Current.Key] ~= nil then
  310. local SfServerAdd = SDataUtil.Add(newAttrs[iter.Current.Key] , iter.Current.Value)
  311. local ServerAdd = SDataUtil.InvConvertDouble(SfServerAdd)
  312. local CurServer = SDataUtil.InvConvertDouble(newAttrs[iter.Current.Key] )
  313. twoAttrAddDic[iter.Current.Key] = math.floor(ServerAdd) - math.floor(CurServer)
  314. else
  315. twoAttrAddDic[iter.Current.Key] = math.floor(iter.Current.Value)
  316. end
  317. end
  318. self:RefreshPoints()
  319. self:RereshTopAttrs()
  320. end
  321. function UIRoleNaturePointView:RemoveEventListener()
  322. ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
  323. end
  324. function UIRoleNaturePointView:AddUIEventListener()
  325. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name)
  326. self.leadBox.str.btnReduce.repeatButton:AddRepeatClickEventListener(function (idx, isOver)
  327. self:ChangeAttrPreview(Enum.HeroAttrType.STR, false)
  328. end)
  329. self.leadBox.str.btnIncrease.repeatButton:AddRepeatClickEventListener(function (idx, isOver)
  330. self:ChangeAttrPreview(Enum.HeroAttrType.STR, true)
  331. end)
  332. self.leadBox.agi.btnReduce.repeatButton:AddRepeatClickEventListener(function (idx, isOver)
  333. self:ChangeAttrPreview(Enum.HeroAttrType.AGI, false)
  334. end)
  335. self.leadBox.agi.btnIncrease.repeatButton:AddRepeatClickEventListener(function (idx, isOver)
  336. self:ChangeAttrPreview(Enum.HeroAttrType.AGI, true)
  337. end)
  338. self.leadBox.int.btnReduce.repeatButton:AddRepeatClickEventListener(function (idx, isOver)
  339. self:ChangeAttrPreview(Enum.HeroAttrType.INT, false)
  340. end)
  341. self.leadBox.int.btnIncrease.repeatButton:AddRepeatClickEventListener(function (idx, isOver)
  342. self:ChangeAttrPreview(Enum.HeroAttrType.INT, true)
  343. end)
  344. self.leadBox.vit.btnReduce.repeatButton:AddRepeatClickEventListener(function (idx, isOver)
  345. self:ChangeAttrPreview(Enum.HeroAttrType.VIT, false)
  346. end)
  347. self.leadBox.vit.btnIncrease.repeatButton:AddRepeatClickEventListener(function (idx, isOver)
  348. self:ChangeAttrPreview(Enum.HeroAttrType.VIT, true)
  349. end)
  350. self.leadBox.dex.btnReduce.repeatButton:AddRepeatClickEventListener(function (idx, isOver)
  351. self:ChangeAttrPreview(Enum.HeroAttrType.DEX, false)
  352. end)
  353. self.leadBox.dex.btnIncrease.repeatButton:AddRepeatClickEventListener(function (idx, isOver)
  354. self:ChangeAttrPreview(Enum.HeroAttrType.DEX, true)
  355. end)
  356. self.leadBox.luk.btnReduce.repeatButton:AddRepeatClickEventListener(function (idx, isOver)
  357. self:ChangeAttrPreview(Enum.HeroAttrType.LUK, false)
  358. end)
  359. self.leadBox.luk.btnIncrease.repeatButton:AddRepeatClickEventListener(function (idx, isOver)
  360. self:ChangeAttrPreview(Enum.HeroAttrType.LUK, true)
  361. end)
  362. self.uiBase:AddButtonEventListener(self.btnBack.button, function ()
  363. --ManagerContainer.LuaUIMgr:OpenSourceUI(self, self.controller:GetData())
  364. self:UIClose()
  365. if self.uiBase.MSourceUIID > 0 then
  366. ManagerContainer.LuaUIMgr:Open(self.uiBase.MSourceUIID, self.controller:GetData())
  367. end
  368. end)
  369. self.uiBase:AddButtonEventListener(self.btnConfirm.button, function ()
  370. self.controller:SendAttrChange(oneAttrAddDic)
  371. end)
  372. self.uiBase:AddButtonEventListener(self.btnPotentialFruit.button, function ()
  373. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIFruitUse)
  374. end)
  375. self.uiBase:AddButtonEventListener(self.btnInfoImage.button, function ()
  376. local herodata = ManagerContainer.DataMgr.UserData:GetHeroData(self.controller:GetData())
  377. local fruitPoint = 0
  378. for i = 1, #self.cfgData do
  379. if herodata.qualityList and herodata.qualityList[self.cfgData[i][1]] ~= nil then
  380. fruitPoint = fruitPoint + herodata.qualityList[self.cfgData[i][1]] * self.cfgData[i][2]
  381. end
  382. end
  383. local basePoint = GlobalConfig.Instance:GetConfigIntValue(30)
  384. local pointCfg = ManagerContainer.CfgMgr.RoleAttributeCfg
  385. for i = 1, herodata.baseLevel - 1 do
  386. basePoint = basePoint + pointCfg[i]['GetPoint']
  387. end
  388. ManagerContainer.LuaUIMgr:ShowMinTips("PointShow",{basePoint,fruitPoint})
  389. end)
  390. self.uiBase:AddButtonEventListener(self.btnReset.button, function ()
  391. self.controller:SendResetPoint()
  392. end)
  393. self.uiBase:AddButtonEventListener(self.btnRecommend.button, function ()
  394. oneAttrAddDic = self.controller:CalcAutoPoints()
  395. local function AttrChanged()
  396. local result = false
  397. for k,v in pairs(oneAttrAddDic) do
  398. if v > 0 then
  399. result = true
  400. end
  401. end
  402. return result
  403. end
  404. self:RefreshAllAttr()
  405. if not AttrChanged() then
  406. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(Enum.ActionNotiveType.AutoAttrPointLack)
  407. return
  408. end
  409. end)
  410. self.uiBase:AddButtonEventListener(self.btnLeft.button, self, self.OnLeftClick)
  411. self.uiBase:AddButtonEventListener(self.btnRight.button, self, self.OnRightClick)
  412. self.uiBase:AddButtonEventListener(self.btnAttrInfo.button, self, self.OnClickInfoBtn)
  413. --LogError("----------AddButtonUniqueEventListener-------"..Inspect(self.btnInfo.button))
  414. end
  415. function UIRoleNaturePointView:OnClickInfoBtn()
  416. --LogError("----------OnClickInfoBtn-------")
  417. -- 计算显示的数据
  418. if not self.infoDatas then
  419. self.infoDatas = {}
  420. self.infoDatas[1] = 'TitleNatureDsc'
  421. local datas = {}
  422. self.infoDatas[2] = datas
  423. for _,v in pairs(Enum.HeroAttrType) do
  424. if v <= Enum.HeroAttrType.Life then
  425. datas[#datas + 1] = {v, 'ShowAttr_'..v, 'ShowAttr_'..v..'_Desc'}
  426. end
  427. end
  428. end
  429. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIRoleInfoPop, self.infoDatas)
  430. end
  431. function UIRoleNaturePointView:OnLeftClick()
  432. self.controller:SwichParterHero(-1)
  433. self:Init()
  434. self:RefreshCurNaturePop()
  435. end
  436. function UIRoleNaturePointView:OnRightClick()
  437. self.controller:SwichParterHero(1)
  438. self:Init()
  439. self:RefreshCurNaturePop()
  440. end
  441. function UIRoleNaturePointView:OnHide()
  442. end
  443. function UIRoleNaturePointView:OnShow(data)
  444. self.controller:SetData(data)
  445. self:Init()
  446. self:RefreshCurNaturePop()
  447. end
  448. function UIRoleNaturePointView:OnClose()
  449. end
  450. function UIRoleNaturePointView:OnDispose()
  451. self.baseSView.loopVerticalScrollRect:ClearCells()
  452. self.addSView.loopVerticalScrollRect:ClearCells()
  453. self.infoDatas = nil
  454. self.cfgData = nil
  455. end
  456. return UIRoleNaturePointView