UIEquipTipsView.lua 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. local UIEquipTipsView = require("UIEquipTips/UIEquipTipsView_Generate")
  2. local IconItemCtr = require("Common/IconItemCtr")
  3. local ConditionJudge = require("Common/ConditionJudge")
  4. local EquipSlotItemNewCtr = require("Common/EquipSlotItemNewCtr")
  5. function UIEquipTipsView:OnAwake(data)
  6. self.controller = require("UIEquipTips/UIEquipTipsCtr"):new()
  7. self.controller:Init(self)
  8. self.controller:SetData(data)
  9. end
  10. function UIEquipTipsView:AddEventListener()
  11. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name)
  12. self.uiBase:AddUIEventHandlerClickListener(self.uIEventHandler, function (go)
  13. if go and go.transform:IsChildOf(self.transform) then
  14. return
  15. end
  16. ManagerContainer.LuaUIMgr:Hide(self.uiData.id)
  17. end)
  18. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.HERO_EQUIP_REFRESH, function()
  19. local cfgId = self.controller:GetCfgId()
  20. local slotIndex = self.controller:GetSlotIndex()
  21. local equipCfgData = ManagerContainer.CfgMgr:GetEquipById(cfgId)
  22. -- 道具图标
  23. local slots = self.controller:GetSlot();
  24. local _cardIdList = self.controller:GetCardIdList();
  25. local data = {false, nil, nil, slots, slotIndex, equipCfgData.Type, nil, _cardIdList}
  26. EquipSlotItemNewCtr:SetData(self, self.equipSlotItemNew, data)
  27. self:RefreshCards()
  28. self:RefreshCardBtns()
  29. local slotIndex = self.controller:GetSlotIndex()
  30. ManagerContainer.LuaUIMgr:AttrNoticeDisplay(slotIndex)
  31. end)
  32. end
  33. function UIEquipTipsView:FillContent(data, uiBase)
  34. self.uiBase = uiBase
  35. local gameObject = self.uiBase:GetRoot()
  36. if gameObject ~= nil then
  37. self.gameObject = gameObject
  38. self.transform = gameObject.transform
  39. end
  40. self:InitGenerate(self.transform, data)
  41. self:Init()
  42. end
  43. function UIEquipTipsView:Init()
  44. local id = self.controller:GetHeroId()
  45. local heroConfigId = self.controller:GetHeroConfigId()
  46. local cfgId = self.controller:GetCfgId()
  47. local slotIndex = self.controller:GetSlotIndex()
  48. local enterType = self.controller:GetEnterType()
  49. local nickName = self.controller:GetNickName()
  50. local itemCfgData = ManagerContainer.CfgMgr:GetItemById(cfgId)
  51. if itemCfgData == nil then
  52. LogError(cfgId.." isnt exist in itemCfg")
  53. return
  54. end
  55. local equipCfgData = ManagerContainer.CfgMgr:GetEquipById(cfgId)
  56. if equipCfgData == nil then
  57. LogError(cfgId.." isnt exist in equipCfg")
  58. return
  59. end
  60. if id == 0 then
  61. return
  62. end
  63. local jobIcon
  64. if id == 1 then
  65. local jobData = ManagerContainer.CfgMgr:GetJobDataById(heroConfigId)
  66. jobIcon = jobData.JobIcon
  67. else
  68. local heroCfgData = ManagerContainer.CfgMgr:GetPartnerDataById(heroConfigId)
  69. jobIcon = heroCfgData.JobIcon
  70. end
  71. CommonUtil.LoadIcon(self, jobIcon, function (sprite)
  72. self.jobIcon.image.sprite = sprite
  73. end)
  74. local name
  75. if id == 1 then
  76. local cfgData = ManagerContainer.CfgMgr:GetJobDataById(heroConfigId)
  77. if nickName == nil then
  78. name = CommonUtil.GetHeroJobAndNameByUid(id, heroConfigId)
  79. else
  80. if cfgData == nil then
  81. name = nickName
  82. else
  83. name = I18N.T(cfgData.JobName) .. nickName
  84. end
  85. end
  86. else
  87. name = CommonUtil.GetHeroJobAndNameByUid(id, heroConfigId)
  88. end
  89. self.heroName.text.text = name
  90. -- 道具图标
  91. local slots = self.controller:GetSlot();
  92. local _cardIdList = self.controller:GetCardIdList();
  93. local data = {false, nil, nil, slots, slotIndex, equipCfgData.Type, nil, _cardIdList}
  94. EquipSlotItemNewCtr:SetData(self, self.equipSlotItemNew, data)
  95. -- 道具名称
  96. local name = I18N.T(itemCfgData.Name)
  97. self.textName.text.text = name
  98. -- 道具描述
  99. self.desTxt.text.text = itemCfgData.Describe
  100. -- 道具类型
  101. self.type1.text2.text.text = I18N.T("ItemTypeDes_" .. itemCfgData.ResType)
  102. self.type2.text2.text.text = I18N.T(Enum.EquipTypeName[equipCfgData.Type])
  103. --基础属性
  104. self:RefreshEquipInfo(name)
  105. --设置一些按钮的显示状态,这个目前是给头像交互界面用的,只有头像交互界面打开tip的时候,按钮需要隐藏,应为不能对这些按钮做操作
  106. self:SetButtonsState();
  107. ManagerContainer.RedPointMgr.HeroRPCtr:RefreshRoleCardSlotRP(slotIndex)
  108. end
  109. --设置一些按钮的显示状态,有些界面打开这个tip仅仅是为了查看,所有一些按钮是不能用的
  110. function UIEquipTipsView:SetButtonsState()
  111. local _isView = self.controller:GetIsView();
  112. self.btnChange.gameObject:SetActive(not _isView);
  113. self.btnBox.gameObject:SetActive(not _isView);
  114. end
  115. function UIEquipTipsView:RefreshEquipInfo(name)
  116. local cfgId = self.controller:GetCfgId()
  117. local slotIndex = self.controller:GetSlotIndex()
  118. local slotType = self.controller:GetSlotType()
  119. local slots = self.controller:GetSlot();
  120. local jobType = 1
  121. local slot = ManagerContainer.DataMgr.UserData:GetSlotBySlotIndex(slotIndex)
  122. if slot then
  123. local heroId = slot.hero_id
  124. if heroId == 1 then
  125. jobType = ManagerContainer.DataMgr.UserData:GetJobType()
  126. else
  127. local logicData = CommonUtil.GetHeroLogicDataByUid(heroId)
  128. local configId = logicData.configId
  129. local partnerData = ManagerContainer.CfgMgr:GetPartnerDataById(configId)
  130. jobType = partnerData.JobType
  131. end
  132. end
  133. local refineLv = 0
  134. if slots ~= nil then
  135. refineLv = slots[slotType].level
  136. --self.contentItem.textLv:SetActive(refineLv > 0)
  137. --if refineLv > 0 then
  138. -- self.contentItem.textLv.text.text = "+"..refineLv
  139. --end
  140. end
  141. -- 装备基本属性
  142. local equipCfgData = ManagerContainer.CfgMgr:GetEquipById(cfgId)
  143. local baseAttrs = {}
  144. for k,v in pairs(Enum.HeroAttrType) do
  145. if equipCfgData[k] and equipCfgData[k] ~= 0 then
  146. table.insert(baseAttrs, {Enum.HeroAttrType[k], equipCfgData[k], refineLv})
  147. end
  148. end
  149. table.sort(baseAttrs, function (a,b)
  150. return a[1] < b[1]
  151. end)
  152. local idx = 0
  153. for k, v in pairs(baseAttrs) do
  154. idx = idx + 1
  155. CommonUtil.BatchCreateItemsLoopWithMould(self, self.attrItem, self.baseAttr.grid.transform, v, idx, Enum.ItemIEnterType.Attr)
  156. end
  157. self.suit:SetActive(equipCfgData.Suit > 0)
  158. -- 装备套装属性
  159. if equipCfgData.Suit > 0 then
  160. local suitNum, suits = ManagerContainer.DataMgr.UserData:GetSuitNum(slots, slotType)
  161. local index = math.floor(suitNum/2)
  162. local equipSuitCfgData = ManagerContainer.CfgMgr:GetEquipSuitById(equipCfgData.Suit)
  163. local equipSuits = ManagerContainer.CfgMgr:GetSameSuitEquipsBySuitId(equipCfgData.Suit, jobType)
  164. self.suitTxt.text.text = equipSuitCfgData.Name
  165. self.suitActiveTxt.text.text = string.format("(%s/6)", suitNum)
  166. for i = 1, 6 do
  167. self["suitText"..i]:SetActive(equipSuits[i] ~= nil)
  168. if equipSuits[i] then
  169. self["suitText"..i].text.text = I18N.T(suits[i] and suits[i] or (equipSuits and equipSuits[i].Name) or "")
  170. self["suitText"..i].check:SetActive(suits[i] ~= nil)
  171. if suits[i] then
  172. CommonUtil.SetTextColor(self["suitText"..i].text, Constant.GreenColorText)
  173. end
  174. end
  175. end
  176. local i = 1
  177. local keyName = ("Suit" .. i)
  178. local suitAttrs = {}
  179. while (equipSuitCfgData[keyName] ~= nil) do
  180. if equipSuitCfgData[keyName] ~= "" then
  181. table.insert(suitAttrs, {i, equipSuitCfgData[keyName], i <= index, i})
  182. end
  183. i = i + 1
  184. keyName = ("Suit" .. i)
  185. end
  186. for k,v in pairs(suitAttrs) do
  187. local addAttr = CommonUtil.DeserializeCfgItemList(v[2])
  188. if #addAttr > 0 then
  189. addAttr = addAttr[1]
  190. local id = addAttr[1]
  191. local name = I18N.T("Attr_"..id)
  192. if id == Enum.HeroAttrType.Attack_Percent or id == Enum.HeroAttrType.MagicAttack_Percent then
  193. name = I18N.T("Attack")
  194. elseif id == Enum.HeroAttrType.Defense_Percent or id == Enum.HeroAttrType.MagicDefense_Percent then
  195. name = I18N.T("show_def")
  196. end
  197. self["additionText"..v[1]].text.text = I18N.SetLanguageValue("SuitAddAttr", v[1]*2, name, (addAttr[2]/100).."%")
  198. if v[3] then
  199. CommonUtil.SetTextColor(self["additionText"..v[1]].text, Constant.GreenColorText)
  200. end
  201. end
  202. end
  203. end
  204. self:RefreshCards()
  205. self:RefreshCardBtns()
  206. self.redPointItem:SetActive(self.controller:GetCanRefine())
  207. end
  208. function UIEquipTipsView:RefreshCards()
  209. local slotIndex = self.controller:GetSlotIndex()
  210. local slotType = self.controller:GetSlotType()
  211. local slots = self.controller:GetSlot();
  212. --卡片信息
  213. if slots ~= nil then
  214. local cardList = slots[slotType].card_id_list
  215. local list = {}
  216. for i = 1, Constant.CARD_SLOT_LIMIT do
  217. local condition = ManagerContainer.CfgMgr:GetCardUnlockConditionById(slotType * 100 + i)
  218. if condition ~= nil then
  219. list[#list + 1] = {cfgId = cardList[i] ~= nil and cardList[i] or 0, condition = condition.UnlockingCondition[1], idx = i}
  220. end
  221. end
  222. for k,v in pairs(list) do
  223. local cardIcon = self["cardIcon"..k]
  224. cardIcon.owned:SetActive(v.cfgId > 0)
  225. cardIcon.gameObject:SetActive(true)
  226. local result, val,content = ConditionJudge:ConditionPassResult1(v.condition)
  227. if v.cfgId > 0 then
  228. IconItemCtr:SetData(self, cardIcon.iconItem, v, nil, self, self.OnCardClick)
  229. end
  230. local _isView = self.controller:GetIsView();
  231. local _showLock = not result;
  232. if _isView then
  233. _showLock = false
  234. cardIcon.unowned:SetActive(v.cfgId == 0)
  235. else
  236. cardIcon.unowned:SetActive(v.cfgId == 0 and result)
  237. end
  238. cardIcon.locked:SetActive(_showLock)
  239. cardIcon.lvLocked.text.text = content
  240. if result then
  241. if self.rpGos == nil then
  242. self.rpGos = {}
  243. end
  244. local rpState = ManagerContainer.RedPointMgr.HeroRPCtr:GetRoleCardSlotRP(slotIndex, slotType, k - 1)
  245. if rpState == Enum.RedPointEnum.CardSlotRP then
  246. if self.rpGos[k] then
  247. self.rpGos[k]:SetActive(true)
  248. else
  249. local redPointGo = ManagerContainer.ResMgr:GetGoFromPool(Constants.UICommonPath, Enum.RPPrefab[Enum.RPType.CardOpen])
  250. self.rpGos[k] = redPointGo
  251. self.rpGos[k].transform:SetParent(cardIcon.rpPoint.transform)
  252. self.rpGos[k].transform.localPosition = Vector3.zero
  253. self.rpGos[k].transform.localScale = Vector3.one
  254. self.rpGos[k]:SetActive(true)
  255. end
  256. end
  257. end
  258. end
  259. end
  260. end
  261. function UIEquipTipsView:RefreshCardBtns()
  262. local id = self.controller:GetHeroId()
  263. local slotType = self.controller:GetSlotType()
  264. local cardState = self.controller:InsertedCards(slotType)
  265. local emptyRP = ManagerContainer.RedPointMgr.HeroRPCtr:GetRoleCardSlotEmptyRP(id, slotType)
  266. self.btnCard:SetActive(not cardState or emptyRP)
  267. self.btnRemoveCard:SetActive(cardState and not emptyRP)
  268. end
  269. function UIEquipTipsView:RemoveEventListener()
  270. ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
  271. end
  272. function UIEquipTipsView:AddUIEventListener()
  273. self.uiBase:AddButtonEventListener(self.btnChange.button, function ()
  274. self:UIClose()
  275. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIEquipList, self.controller:GetData())
  276. end)
  277. self.uiBase:AddButtonEventListener(self.btnClose.button, function ()
  278. self:UIClose()
  279. end)
  280. self.uiBase:AddButtonEventListener(self.AnyBtn.button, function ()
  281. self:UIClose()
  282. end)
  283. self.uiBase:AddButtonEventListener(self.btnRefine.button, function ()
  284. self:UIClose()
  285. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIEquipRefineTips, self.controller:GetData()[1])
  286. end)
  287. self.uiBase:AddButtonEventListener(self.btnCard.button, self, self.OnOneKeyCardClick)
  288. self.uiBase:AddButtonEventListener(self.btnRemoveCard.button, self, self.OnOneKeyCardDownClick)
  289. self.uiBase:AddButtonEventListener(self.cardIcon1.unowned.icon.button, self, self.OnCardClick, 1)
  290. self.uiBase:AddButtonEventListener(self.cardIcon2.unowned.icon.button, self, self.OnCardClick, 2)
  291. self.uiBase:AddButtonEventListener(self.cardIcon3.unowned.icon.button, self, self.OnCardClick, 3)
  292. self.uiBase:AddButtonEventListener(self.cardIcon4.unowned.icon.button, self, self.OnCardClick, 4)
  293. end
  294. function UIEquipTipsView:OnOneKeyCardClick()
  295. --一键上卡
  296. self.controller:OnOneKeyCardUp()
  297. end
  298. function UIEquipTipsView:OnOneKeyCardDownClick()
  299. --一键卸卡
  300. self.controller:OnOneKeyCardDown()
  301. end
  302. function UIEquipTipsView:OnCardClick(button, params)
  303. local _isView = self.controller:GetIsView()
  304. if _isView then
  305. return;
  306. end
  307. self:UIClose()
  308. local data
  309. if type(params[0]) ~= "table" then
  310. data = {cfgId = 0, idx = params[0]}
  311. else
  312. data = params[0]
  313. end
  314. data.equipTipsData = self.controller:GetData()
  315. --ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UICardTips, self.controller:GetData()[1])
  316. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UICardListTips, data)
  317. end
  318. function UIEquipTipsView:OnHide()
  319. end
  320. function UIEquipTipsView:OnShow(data)
  321. self.controller:SetData(data)
  322. self:Init()
  323. end
  324. function UIEquipTipsView:OnClose()
  325. end
  326. function UIEquipTipsView:OnDispose()
  327. self.uIEventHandler:RemoveListener()
  328. if self.rpGos then
  329. for k,v in pairs(self.rpGos) do
  330. ManagerContainer.ResMgr:RecycleGO(Constants.UICommonPath, Enum.RPPrefab[Enum.RPType.CardSlot], v)
  331. end
  332. self.rpGos = nil
  333. end
  334. end
  335. return UIEquipTipsView