UITipsExchangeView.lua 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  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 or itemType == Enum.ItemType.Card or itemType ==
  160. Enum.ItemType.FashionPaper or itemType == Enum.ItemType.HeadFrame
  161. self.baseAttr:SetActive(needBase)
  162. if needBase then
  163. if itemType == Enum.ItemType.Equip then
  164. local baseAttrs = {}
  165. for k, v in pairs(Enum.HeroAttrType) do
  166. if cfgData[k] and cfgData[k] ~= 0 then
  167. table.insert(baseAttrs, {Enum.HeroAttrType[k], cfgData[k]})
  168. end
  169. end
  170. local index = 0
  171. for k, v in pairs(baseAttrs) do
  172. index = index + 1
  173. CommonUtil.BatchCreateItemsLoopWithMould(self, self.attrItem, self.baseAttr.grid.transform, v, index,
  174. Enum.ItemIEnterType.Attr)
  175. end
  176. elseif itemType == Enum.ItemType.Card then
  177. local index = 0
  178. for _, v in pairs(CommonUtil.DeserializeCfgItemList(cfgData.Attribute1)) do
  179. index = index + 1
  180. CommonUtil.BatchCreateItemsLoopWithMould(self, self.attrItem, self.baseAttr.grid.transform, v, index,
  181. 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. if fashionAttrs then
  187. -- 一条属性的时候
  188. if type(fashionAttrs[1]) == 'number' then
  189. fashionAttrs = {fashionAttrs}
  190. end
  191. local index = 0
  192. for _, v in pairs(fashionAttrs) do
  193. index = index + 1
  194. CommonUtil.BatchCreateItemsLoopWithMould(self, self.attrItem, self.baseAttr.grid.transform, v,
  195. index, Enum.ItemIEnterType.Attr)
  196. end
  197. end
  198. elseif itemType == Enum.ItemType.HeadFrame then
  199. local baseAttrs = {}
  200. local _Attrs = cfgData.HeadFrameQuality;
  201. if _Attrs then
  202. for _k, _v in pairs(_Attrs) do
  203. if _v[1] and _v[2] then
  204. table.insert(baseAttrs, {_v[1], _v[2]});
  205. end
  206. end
  207. local index = 0
  208. for k, v in pairs(baseAttrs) do
  209. index = index + 1
  210. CommonUtil.BatchCreateItemsLoopWithMould(self, self.attrItem, self.baseAttr.grid.transform, v,
  211. index, Enum.ItemIEnterType.Attr)
  212. end
  213. end
  214. end
  215. end
  216. end
  217. function UITipsExchangeView:RefreshMakeMaterials(itemType)
  218. local cfgId = self.controller:GetCfgId()
  219. local needCost = itemType == Enum.ItemType.FashionPaper
  220. self.costMaterials:SetActive(needCost)
  221. if needCost then
  222. if itemType == Enum.ItemType.FashionPaper then
  223. local cfgData = ManagerContainer.CfgMgr:GetFashionPaperById(cfgId)
  224. local makeMaterial = clone(cfgData.MakeMaterial)
  225. if type(makeMaterial[1]) == 'number' then
  226. makeMaterial = {makeMaterial}
  227. end
  228. local num = #makeMaterial
  229. local materialCfgId = nil
  230. local materialNum = nil
  231. local moneyCfgId = nil
  232. local moneyNum = nil
  233. for i = num, 1, -1 do
  234. materialCfgId = makeMaterial[i][1]
  235. materialNum = makeMaterial[i][2]
  236. local materialItemCfgData = ManagerContainer.CfgMgr:GetItemById(materialCfgId)
  237. if materialItemCfgData.ResType == Enum.ItemType.Coin
  238. or materialItemCfgData.ResType == Enum.ItemType.Diamond then
  239. moneyCfgId = materialCfgId
  240. moneyNum = materialNum
  241. -- 移除一个货币显示到列表,会单独显示
  242. table.remove(makeMaterial, i)
  243. break
  244. end
  245. end
  246. num = #makeMaterial
  247. if num > 4 then num = 4 end
  248. local index = 0
  249. for _,v in pairs(makeMaterial) do
  250. index = index + 1
  251. CommonUtil.BatchCreateItemsLoopWithMould(self, self.attrItem, self.costMaterials.grid.transform, v, index, Enum.ItemIEnterType.CostMat)
  252. end
  253. return
  254. end
  255. end
  256. end
  257. function UITipsExchangeView:RemoveEventListener()
  258. ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
  259. end
  260. function UITipsExchangeView:AddUIEventListener()
  261. self.uiBase:AddButtonEventListener(self.AnyBtn.button,self, self.OnClickCloseBtn)
  262. self.uiBase:AddButtonEventListener(self.btnClose.button,self, self.OnClickCloseBtn)
  263. self.uiBase:AddButtonEventListener(self.btnExchange.button,self, self.OnExchangeClick)
  264. self.uiBase:AddButtonEventListener(self.btnMinus.button, self, self.MinusFun);
  265. self.uiBase:AddButtonEventListener(self.btnPlus.button, self, self.PlusFun);
  266. self.uiBase:AddSliderUniqueEventListener(self.slider.slider, self, self.OnSliderValueChanged, nil)
  267. end
  268. function UITipsExchangeView:OnClickCloseBtn()
  269. ManagerContainer.LuaUIMgr:ClosePage(self.uiBase.PageId)
  270. if self.uiBase.MSourceUIID > 0 then
  271. ManagerContainer.LuaUIMgr:Open(self.uiBase.MSourceUIID)
  272. end
  273. end
  274. --点击减少按钮
  275. function UITipsExchangeView:MinusFun()
  276. self.controller:RefreshSelectedCount(-1)
  277. self:RefreshSliderBoxNum(true);
  278. end
  279. --点击增加按钮
  280. function UITipsExchangeView:PlusFun()
  281. self.controller:RefreshSelectedCount(1)
  282. self:RefreshSliderBoxNum(true);
  283. end
  284. --滑动条的数值有改变的时候
  285. function UITipsExchangeView:OnSliderValueChanged(slider, value)
  286. if value == 0 then
  287. value = 1
  288. self.slider.slider.value = value;
  289. end
  290. local selectedCount = value
  291. self.controller:SetSelectedCount(selectedCount)
  292. self:RefreshSliderBoxNum(false);
  293. end
  294. function UITipsExchangeView:RefreshSliderBoxNum(needChangeSlider)
  295. local selectedCount = self.controller:GetSelectedCount()
  296. if needChangeSlider then
  297. self.slider.slider.value = selectedCount;
  298. end
  299. local maxCount = self.controller:GetMaxExchangeCount()
  300. if self.controller:GetisExchangeItem() then
  301. if self.controller:GetisSetColor() then
  302. self.box.itemNumber.number.text.text = string.format(Constant.RedColorText, selectedCount * self.controller:GetRadio())
  303. else
  304. self.box.itemNumber.number.text.text = selectedCount * self.controller:GetRadio()
  305. end
  306. self.box.numBox.num.text.text = selectedCount
  307. else
  308. self.box.numBox.num.text.text = selectedCount .."/"..maxCount
  309. end
  310. end
  311. function UITipsExchangeView:OnExchangeClick()
  312. self.controller:OnExchangeClick()
  313. self:OnClickCloseBtn()
  314. end
  315. function UITipsExchangeView:OnHide()
  316. end
  317. function UITipsExchangeView:OnShow(data)
  318. self.controller:SetData(data)
  319. end
  320. function UITipsExchangeView:OnClose()
  321. end
  322. function UITipsExchangeView:OnDispose()
  323. self.controller:OnDispose()
  324. end
  325. return UITipsExchangeView