UITipsExchangeView.lua 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. local UITipsExchangeView = require("UITips/UITipsExchangeView_Generate")
  2. local IconItemCtr = require("Common/IconItemCtr")
  3. local ColorExtension = require("ColorExtension")
  4. function UITipsExchangeView:OnAwake(data)
  5. self.controller = require("UITips/UITipsExchangeCtr"):new()
  6. self.controller:Init(self)
  7. self.controller:SetData(data)
  8. end
  9. function UITipsExchangeView:AddEventListener()
  10. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name)
  11. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.ACTIVITY_PAGECLOSE,self,self.OnClickCloseBtn)
  12. end
  13. function UITipsExchangeView:FillContent(data, uiBase)
  14. self.uiBase = uiBase
  15. local gameObject = self.uiBase:GetRoot()
  16. if gameObject ~= nil then
  17. self.gameObject = gameObject
  18. self.transform = gameObject.transform
  19. end
  20. self:InitGenerate(self.transform, data)
  21. self:Init()
  22. end
  23. function UITipsExchangeView:Init()
  24. local cfgId = self.controller:GetCfgId()
  25. local itemCfgData = ManagerContainer.CfgMgr:GetItemById(cfgId)
  26. if not itemCfgData then return end
  27. local cfgData = self:GetCfgDataAndType(cfgId,itemCfgData.ResType,itemCfgData.ComposeItem)
  28. if cfgData == nil then
  29. cfgData = itemCfgData
  30. end
  31. local itemType = itemCfgData.ResType
  32. local data1 = {cfgId = cfgId, num = 0}
  33. IconItemCtr:SetData(self, self.iconItem, data1, Enum.ItemIEnterType.Bag)
  34. self.textName.text.text = I18N.T(itemCfgData.Name)
  35. self.type1.text1.uILocalizeScript:SetContent('Type')
  36. self.type1.text2.text.text = I18N.T("ItemTypeDes_"..itemType)
  37. local dsc = cfgData.Desc or itemCfgData.Describe
  38. local count
  39. if self.controller:GetisExchangeItem() or self.controller:GetEnterType() == Enum.UIPageName.UIActivityChipRewardCom then
  40. self.desTxt.text.text = self.controller:GetisExchangeDesc() and I18N.T(self.controller:GetisExchangeRadioDesc()) or I18N.T(dsc)
  41. count = CommonUtil.GetOwnResCountByItemId(cfgId) or 0
  42. else
  43. self.desTxt.text.text = I18N.T(dsc)
  44. count = self.controller:GetCfgCount()
  45. end
  46. if itemCfgData.ResType < 100 then
  47. count = CommonUtil.FormatNumber(count)
  48. else
  49. count = CommonUtil.GetPreciseDecimalFloor(count/10000, 1) .. "萬"--w
  50. end
  51. self.owned.text2.text.text = count
  52. local _type2State = itemType == Enum.ItemType.Equip or itemType == Enum.ItemType.Card or itemType == Enum.ItemType.FashionPaper;
  53. self.type2:SetActive(_type2State)
  54. self.type2.text1.uILocalizeScript:SetContent('Position')
  55. local _type3State = (itemType == Enum.ItemType.Gift or itemType == Enum.ItemType.Income or itemType == Enum.ItemType.OptionalGift)
  56. self.type3:SetActive(_type3State)
  57. local _type4State = itemType == Enum.ItemType.FashionPaper
  58. self.type4:SetActive(_type4State)
  59. local _type5State = itemType == Enum.ItemType.HeadFrame;
  60. self.type5:SetActive(_type5State);
  61. if itemType == Enum.ItemType.Equip then
  62. self.type2.text2.text.text = I18N.T(Enum.EquipTypeName[cfgData.Type])
  63. elseif itemType == Enum.ItemType.Card then
  64. self.type2.text2.text.text = I18N.T(Enum.EquipTypeName[cfgData.CardLocation])
  65. elseif itemType == Enum.ItemType.FashionPaper then
  66. local fashionData = ManagerContainer.CfgMgr:GetFashionById(cfgData.FashionId)
  67. self:RefreshJobOnly(fashionData.FashionUseJob)
  68. self.type2.text2.text.text = I18N.T('FashionSlot_' .. fashionData.FashionLocation)
  69. elseif itemType == Enum.ItemType.Gift or itemType == Enum.ItemType.Compose or itemType == Enum.ItemType.Income or itemType == Enum.ItemType.OptionalGift then
  70. local _enough, _needLevel, _level = self:JudgeItemNeedLevel(itemCfgData)
  71. if _needLevel <= 0 then
  72. self.type3:SetActive(false)
  73. else
  74. self.type3.text2.text.text = tostring(_needLevel);
  75. if not _enough then
  76. CommonUtil.SetTextColor(self.type3.text2.text, Constant.RedColorText)
  77. end
  78. end
  79. elseif itemType == Enum.ItemType.HeadFrame then
  80. local _timeStamp = itemCfgData.ComposeItem
  81. if _timeStamp then
  82. if _timeStamp[1][2] == nil or _timeStamp[1][2] <= 0 then
  83. self.type5.text2.text.text = I18N.T("Forever");
  84. else
  85. local _timeStr = "";
  86. local _timeSecond = _timeStamp[1][2] * 3600;
  87. if _timeSecond >= 60 and _timeSecond < Constant.OneDaySeconds then
  88. _timeStr = DateTimeUtil.convertSeconds2TimeStr1(_timeSecond, true, false, false);
  89. else
  90. _timeStr = DateTimeUtil.convertSeconds2TimeStr1(_timeSecond, false, false, false);
  91. end
  92. self.type5.text2.text.text = _timeStr;
  93. end
  94. end
  95. end
  96. self.skillTag:SetActive(false)
  97. self.box.itemNumber:SetActive(self.controller:GetisExchangeItem())
  98. if self.controller:GetisExchangeItem() then
  99. local itemcfg = ManagerContainer.CfgMgr:GetItemById(self.controller:GetTargetCfgId())
  100. if itemcfg then
  101. CommonUtil.LoadIcon(self, itemcfg.Icon , function (sprite)
  102. self.box.itemNumber.icon.image.sprite = sprite
  103. end)
  104. end
  105. end
  106. self:RefreshBaseAttrs(itemType, cfgData)
  107. self:RefreshMakeMaterials()
  108. self.slider.slider.maxValue = self.controller:GetMaxExchangeCount();
  109. self.slider.slider.value = 1
  110. self:RefreshSliderBoxNum()
  111. self.txtdsc.uILocalizeScript:SetContentAndValues("DscExchangeNum", {self.controller:GetMaxExchangeCount()})
  112. end
  113. function UITipsExchangeView:JudgeItemNeedLevel(_itemCfg)
  114. local _needLevel = _itemCfg.NeedLevel or 0;
  115. local _level = ManagerContainer.DataMgr.UserData:GetRoleLv();
  116. return _needLevel <= _level, _needLevel, _level;
  117. end
  118. function UITipsExchangeView:GetCfgDataAndType(cfgId,resType,composeItem)
  119. local cfgData = nil
  120. if resType == Enum.ItemType.Equip then
  121. cfgData = ManagerContainer.CfgMgr:GetEquipById(cfgId)
  122. if cfgData ~= nil then
  123. return cfgData
  124. end
  125. end
  126. if resType == Enum.ItemType.Card then
  127. cfgData = ManagerContainer.CfgMgr:GetCardDataById(cfgId)
  128. if cfgData ~= nil then
  129. return cfgData
  130. end
  131. end
  132. if resType == Enum.ItemType.Parter then
  133. cfgData = ManagerContainer.CfgMgr:GetPartnerDataById(cfgId)
  134. if cfgData ~= nil then
  135. return cfgData
  136. end
  137. end
  138. if resType == Enum.ItemType.FashionPaper then
  139. cfgData = ManagerContainer.CfgMgr:GetFashionPaperById(cfgId)
  140. if cfgData ~= nil then
  141. return cfgData
  142. end
  143. end
  144. if resType == Enum.ItemType.Pet then
  145. cfgData = ManagerContainer.CfgMgr:GetPetDataById(cfgId)
  146. if cfgData ~= nil then
  147. return cfgData
  148. end
  149. end
  150. if resType == Enum.ItemType.HeadFrame then
  151. if composeItem ~= nil and #composeItem > 0 and #composeItem[1] > 0 then
  152. cfgData = ManagerContainer.CfgMgr:GetHeadFrameById(composeItem[1][1])
  153. return cfgData
  154. end
  155. end
  156. return nil
  157. end
  158. function UITipsExchangeView:RefreshBaseAttrs(itemType, cfgData)
  159. local needBase = itemType == Enum.ItemType.Equip
  160. or itemType == Enum.ItemType.Card
  161. or itemType == Enum.ItemType.FashionPaper
  162. or itemType == Enum.ItemType.HeadFrame
  163. self.baseAttr:SetActive(needBase)
  164. if needBase then
  165. if itemType == Enum.ItemType.Equip then
  166. local baseAttrs = {}
  167. for k,v in pairs(Enum.HeroAttrType) do
  168. if cfgData[k] and cfgData[k] ~= 0 then
  169. table.insert(baseAttrs, {Enum.HeroAttrType[k], cfgData[k]})
  170. end
  171. end
  172. local index = 0
  173. for k, v in pairs(baseAttrs) do
  174. index = index + 1
  175. CommonUtil.BatchCreateItemsLoopWithMould(self, self.attrItem, self.baseAttr.grid.transform, v, index, Enum.ItemIEnterType.Attr)
  176. end
  177. elseif itemType == Enum.ItemType.Card then
  178. local index = 0
  179. for _,v in pairs(CommonUtil.DeserializeCfgItemList(cfgData.Attribute1)) do
  180. index = index + 1
  181. CommonUtil.BatchCreateItemsLoopWithMould(self, self.attrItem, self.baseAttr.grid.transform, v, index, Enum.ItemIEnterType.Attr)
  182. end
  183. elseif itemType == Enum.ItemType.FashionPaper then
  184. local fashionData = ManagerContainer.CfgMgr:GetFashionById(cfgData.FashionId)
  185. local fashionAttrs = fashionData.FashionAttr
  186. -- 一条属性的时候
  187. if type(fashionAttrs[1]) == 'number' then
  188. fashionAttrs = {fashionAttrs}
  189. end
  190. local index = 0
  191. for _,v in pairs(fashionAttrs) do
  192. index = index + 1
  193. CommonUtil.BatchCreateItemsLoopWithMould(self, self.attrItem, self.baseAttr.grid.transform, v, index, Enum.ItemIEnterType.Attr)
  194. end
  195. elseif itemType == Enum.ItemType.HeadFrame then
  196. local baseAttrs = {}
  197. local _Attrs = cfgData.HeadFrameQuality;
  198. if _Attrs then
  199. for _k, _v in pairs(_Attrs) do
  200. if _v[1] and _v[2] then
  201. table.insert(baseAttrs, {_v[1],_v[2]});
  202. end
  203. end
  204. local index = 0
  205. for k, v in pairs(baseAttrs) do
  206. index = index + 1
  207. CommonUtil.BatchCreateItemsLoopWithMould(self, self.attrItem, self.baseAttr.grid.transform, v, index, Enum.ItemIEnterType.Attr)
  208. end
  209. end
  210. end
  211. end
  212. end
  213. function UITipsExchangeView:RefreshMakeMaterials(itemType)
  214. local cfgId = self.controller:GetCfgId()
  215. local needCost = itemType == Enum.ItemType.FashionPaper
  216. self.costMaterials:SetActive(needCost)
  217. if needCost then
  218. if itemType == Enum.ItemType.FashionPaper then
  219. local cfgData = ManagerContainer.CfgMgr:GetFashionPaperById(cfgId)
  220. local makeMaterial = clone(cfgData.MakeMaterial)
  221. if type(makeMaterial[1]) == 'number' then
  222. makeMaterial = {makeMaterial}
  223. end
  224. local num = #makeMaterial
  225. local materialCfgId = nil
  226. local materialNum = nil
  227. local moneyCfgId = nil
  228. local moneyNum = nil
  229. for i = num, 1, -1 do
  230. materialCfgId = makeMaterial[i][1]
  231. materialNum = makeMaterial[i][2]
  232. local materialItemCfgData = ManagerContainer.CfgMgr:GetItemById(materialCfgId)
  233. if materialItemCfgData.ResType == Enum.ItemType.Coin
  234. or materialItemCfgData.ResType == Enum.ItemType.Diamond then
  235. moneyCfgId = materialCfgId
  236. moneyNum = materialNum
  237. -- 移除一个货币显示到列表,会单独显示
  238. table.remove(makeMaterial, i)
  239. break
  240. end
  241. end
  242. num = #makeMaterial
  243. if num > 4 then num = 4 end
  244. local index = 0
  245. for _,v in pairs(makeMaterial) do
  246. index = index + 1
  247. CommonUtil.BatchCreateItemsLoopWithMould(self, self.attrItem, self.costMaterials.grid.transform, v, index, Enum.ItemIEnterType.CostMat)
  248. end
  249. return
  250. end
  251. end
  252. end
  253. function UITipsExchangeView:RemoveEventListener()
  254. ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
  255. end
  256. function UITipsExchangeView:AddUIEventListener()
  257. self.uiBase:AddButtonEventListener(self.AnyBtn.button,self, self.OnClickCloseBtn)
  258. self.uiBase:AddButtonEventListener(self.btnClose.button,self, self.OnClickCloseBtn)
  259. self.uiBase:AddButtonEventListener(self.btnExchange.button,self, self.OnExchangeClick)
  260. self.uiBase:AddButtonEventListener(self.btnMinus.button, self, self.MinusFun);
  261. self.uiBase:AddButtonEventListener(self.btnPlus.button, self, self.PlusFun);
  262. self.uiBase:AddSliderUniqueEventListener(self.slider.slider, self, self.OnSliderValueChanged, nil)
  263. end
  264. function UITipsExchangeView:OnClickCloseBtn()
  265. ManagerContainer.LuaUIMgr:ClosePage(self.uiBase.PageId)
  266. if self.uiBase.MSourceUIID > 0 then
  267. ManagerContainer.LuaUIMgr:Open(self.uiBase.MSourceUIID)
  268. end
  269. end
  270. --点击减少按钮
  271. function UITipsExchangeView:MinusFun()
  272. self.controller:RefreshSelectedCount(-1)
  273. self:RefreshSliderBoxNum(true);
  274. end
  275. --点击增加按钮
  276. function UITipsExchangeView:PlusFun()
  277. self.controller:RefreshSelectedCount(1)
  278. self:RefreshSliderBoxNum(true);
  279. end
  280. --滑动条的数值有改变的时候
  281. function UITipsExchangeView:OnSliderValueChanged(slider, value)
  282. if value == 0 then
  283. value = 1
  284. self.slider.slider.value = value;
  285. end
  286. local selectedCount = value
  287. self.controller:SetSelectedCount(selectedCount)
  288. self:RefreshSliderBoxNum(false);
  289. end
  290. function UITipsExchangeView:RefreshSliderBoxNum(needChangeSlider)
  291. local selectedCount = self.controller:GetSelectedCount()
  292. if needChangeSlider then
  293. self.slider.slider.value = selectedCount;
  294. end
  295. local maxCount = self.controller:GetMaxExchangeCount()
  296. if self.controller:GetisExchangeItem() then
  297. if self.controller:GetisSetColor() then
  298. self.box.itemNumber.number.text.text = string.format(Constant.RedColorText, selectedCount * self.controller:GetRadio())
  299. else
  300. self.box.itemNumber.number.text.text = selectedCount * self.controller:GetRadio()
  301. end
  302. self.box.numBox.num.text.text = selectedCount
  303. else
  304. self.box.numBox.num.text.text = selectedCount .."/"..maxCount
  305. end
  306. end
  307. function UITipsExchangeView:OnExchangeClick()
  308. self.controller:OnExchangeClick()
  309. self:OnClickCloseBtn()
  310. end
  311. function UITipsExchangeView:OnHide()
  312. end
  313. function UITipsExchangeView:OnShow(data)
  314. self.controller:SetData(data)
  315. end
  316. function UITipsExchangeView:OnClose()
  317. end
  318. function UITipsExchangeView:OnDispose()
  319. self.controller:OnDispose()
  320. end
  321. return UITipsExchangeView