源战役客户端
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

574 行
20 KiB

  1. --[[@------------------------------------------------------------------
  2. @description:
  3. @author:wyb
  4. ----------------------------------------------------------------------]]
  5. CloudShoppingView = CloudShoppingView or BaseClass(BaseView)
  6. function CloudShoppingView:__init()
  7. self.base_file = "cloudShopping"
  8. self.layout_file = "CloudShoppingView"
  9. self.layer_name = "UI"
  10. -- self.use_local_view = true
  11. self.use_background = true
  12. self.close_mode = CloseMode.CloseDestroy
  13. self.destroy_imm = true
  14. self.append_to_ctl_queue = true
  15. self.model = CustomActivityModel:getInstance()
  16. self.item_list = {}
  17. self.event_list = {}
  18. self.first_open_view = false
  19. self.base_type = CustomActivityModel.CustomActBaseType.CLOUD_SHOPPING
  20. self.load_callback = function ()
  21. self:LoadSuccess()
  22. self:InitEvent()
  23. end
  24. self.open_callback = function ()
  25. if self.sub_type then
  26. self.model:Fire(CustomActivityModel.PROTO_CCMD_EVENT, 33112, self.sub_type)
  27. end
  28. end
  29. self.close_callback = function ()
  30. self:Remove()
  31. end
  32. end
  33. function CloudShoppingView:Open(sub_type, open_type)
  34. self.sub_type = sub_type
  35. self.open_type = open_type
  36. BaseView.Open(self)
  37. end
  38. function CloudShoppingView:Remove()
  39. self:CancelLeftTimer()
  40. for _, v in pairs(self.event_list) do
  41. self.model:UnBind(v)
  42. v = nil
  43. end
  44. for _, v in pairs(self.item_list) do
  45. v:DeleteMe()
  46. v = nil
  47. end
  48. self.item_list = {}
  49. self.first_open_view = false
  50. self:CancelTimer()
  51. end
  52. function CloudShoppingView:LoadSuccess()
  53. self.bg2,
  54. self.iconOne,
  55. self.iconTen
  56. = GetChildImages(self.transform, {
  57. "bg2",
  58. "rightCon/poolCon/btnOne/icon",
  59. "rightCon/poolCon/btnTen/icon"
  60. })
  61. -- lua_resM:setOutsideImageSprite(self, self.bg2, GameResPath.GetJpgImage("cloud_shopping_bg.jpg"), false)
  62. self.txtProgress,
  63. self.txtPrice,
  64. self.txtTime,
  65. self.txtBuy,
  66. self.txtLimit,
  67. self.txtOne,
  68. self.txtTen,
  69. self.txtName
  70. = GetChildTexts(self.transform, {
  71. "leftCon/txtProgress",
  72. "leftCon/priceCon/txtPrice",
  73. "rightCon/timeCon/txtTime",
  74. "rightCon/poolCon/txtBuy",
  75. "rightCon/poolCon/txtLimit",
  76. "rightCon/poolCon/btnOne/text",
  77. "rightCon/poolCon/btnTen/text",
  78. "leftCon/nameCon/txtName",
  79. })
  80. self.imgGoods,
  81. self.effect
  82. = GetChildTransforms(self.transform, {
  83. "leftCon/imgGoods",
  84. "leftCon/effect",
  85. })
  86. self.timeCon,
  87. self.imgOver,
  88. self.btnHelp,
  89. self.btnReward,
  90. self.btnOne,
  91. self.btnTen,
  92. self.probBtn,
  93. self.btnGL,
  94. self.clickGo
  95. = GetChildGameObjects(self.transform, {
  96. "rightCon/timeCon",
  97. "rightCon/imgOver",
  98. "rightCon/btnHelp",
  99. "rightCon/btnReward",
  100. "rightCon/poolCon/btnOne",
  101. "rightCon/poolCon/btnTen",
  102. "Window/probBtn",
  103. "rightCon/btnGL",
  104. "clickGo"
  105. })
  106. self.box_list = {}
  107. for i = 1, 14 do
  108. self.box_list[i] = self:GetChild("rightCon/poolCon/BoxCon/Box" .. i)
  109. end
  110. self:AddUIEffect("effect_xunbao_001_3", self.effect, self.layer_name, nil, 0.7, true)
  111. end
  112. function CloudShoppingView:InitEvent()
  113. local onClickHandler = function (target, x, y)
  114. if not self.goods_basic then
  115. return
  116. end
  117. local onGotoBag = function ()
  118. local ok_callback = function ()
  119. GlobalEventSystem:Fire(EventName.OPEN_BAG_VIEW)
  120. end
  121. Alert.show("您的背包已满,无法购买,是否前往整理背包!", Alert.Type.Two, ok_callback, nil, "确定", "取消")
  122. end
  123. local empty = GoodsModel:getInstance():GetEmptyGrid()
  124. local goodsNum = GoodsModel:getInstance():GetTypeGoodsNum(self.type_id)
  125. if self.btnOne == target then
  126. if empty <= 0 then
  127. onGotoBag()
  128. return
  129. end
  130. if goodsNum >= self.cost then
  131. self.model:Fire(CustomActivityModel.PROTO_CCMD_EVENT, 33113, self.sub_type, 1, 0)
  132. else
  133. if TreasureHuntModel:getInstance().not_show["cloud_shopping"] then
  134. self.model:Fire(CustomActivityModel.PROTO_CCMD_EVENT, 33113, self.sub_type, 1, 1)
  135. else
  136. self:TipsFunc(self.cost, 1)
  137. end
  138. end
  139. elseif self.btnTen == target then
  140. if empty < 10 then
  141. onGotoBag()
  142. return
  143. end
  144. if goodsNum >= (self.cost * 10) then
  145. self.model:Fire(CustomActivityModel.PROTO_CCMD_EVENT, 33113, self.sub_type, 10, 0)
  146. else
  147. if TreasureHuntModel:getInstance().not_show["cloud_shopping"] then
  148. self.model:Fire(CustomActivityModel.PROTO_CCMD_EVENT, 33113, self.sub_type, 10, 1)
  149. else
  150. self:TipsFunc(self.cost * 10, 10)
  151. end
  152. end
  153. elseif self.btnReward == target then
  154. self.model:Fire(CustomActivityModel.OPEN_CLOUD_REWARD_VIEW, self.sub_type)
  155. elseif self.btnHelp == target then
  156. if not self.open_type then return end
  157. if self.open_type == CustomActivityModel.CloudShoppingType.BenFu then
  158. UIToolTipMgr:getInstance():AppendSimpleTips(Config.ConfigActStatic.CloudShoppingDescBenFu, x, y)
  159. elseif self.open_type == CustomActivityModel.CloudShoppingType.KuaFu then
  160. UIToolTipMgr:getInstance():AppendSimpleTips(Config.ConfigActStatic.CloudShoppingDescKuaFu, x, y)
  161. end
  162. elseif self.probBtn == target then
  163. elseif self.clickGo == target then
  164. self:ClickBigRewardFunc(x, y)
  165. elseif target == self.btnGL then
  166. self.model:Fire(CustomActivityModel.OPEN_CLOUD_SHOP_ODDS_VIEW)
  167. end
  168. end
  169. AddClickEvent(self.btnOne, onClickHandler)
  170. AddClickEvent(self.btnTen, onClickHandler)
  171. AddClickEvent(self.btnReward, onClickHandler)
  172. AddClickEvent(self.btnHelp, onClickHandler)
  173. AddClickEvent(self.probBtn, onClickHandler)
  174. AddClickEvent(self.btnGL, onClickHandler)
  175. AddClickEvent(self.clickGo, onClickHandler)
  176. local onUpdate = function ()
  177. self:SetData()
  178. if self.first_open_view == false then
  179. -- self:UpdateItems()
  180. self.first_open_view = true
  181. end
  182. end
  183. self.event_list[1] = self.model:Bind(CustomActivityModel.UPDATE_CLOUD_SHOPPING_VIEW, onUpdate)
  184. local onUpateItem = function ()
  185. --购买成功之后的处理
  186. self:UpdateItems()
  187. end
  188. self.event_list[2] = self.model:Bind(CustomActivityModel.UPDATE_CLOUD_BUY_LIST, onUpateItem)
  189. end
  190. function CloudShoppingView:TipsFunc(costNum, buyNum)
  191. local goodsNum = GoodsModel:getInstance():GetTypeGoodsNum(self.type_id)
  192. local goodsPrice, _ = GoodsModel:getInstance():GetGoodsPrice(self.goods_basic.type_id)
  193. local str_color = WordManager.GetGoodsColor(self.goods_basic.color)
  194. local need_price = (costNum - goodsNum) * goodsPrice
  195. local content = string.format("当前材料<color=%s>%s</color>不足\n",
  196. str_color, Trim(self.goods_basic.goods_name))
  197. local per_str = "是否使用"..need_price
  198. local cur_str = "立即补充<color=#4eae1a>" .. (costNum - goodsNum) .. "</color>个"
  199. local jin = RoleManager.Instance.mainRoleInfo:GetRealJin()
  200. local function ok_callback()
  201. if jin >= need_price then
  202. self.model:Fire(CustomActivityModel.PROTO_CCMD_EVENT, 33113, self.sub_type, buyNum, 1)
  203. else
  204. Message.show("您的彩钻不足")
  205. end
  206. end
  207. TreasureHuntModel:getInstance():Fire(TreasureHuntModel.OPEN_HINT_VIEW, "cloud_shopping", content, ok_callback, per_str, cur_str)
  208. end
  209. function CloudShoppingView:SetData()
  210. self.act_data = self.model:getActList(self.base_type)
  211. self.data = self.model:GetCloudShoppingInfo()
  212. if not self.act_data or not self.data then
  213. return
  214. end
  215. self:SetLeftTime()
  216. self:CreateItems()
  217. end
  218. function CloudShoppingView:SetLeftTime()
  219. local time = self.data.next_reward_time - TimeUtil:getServerTime()
  220. local function timer_func()
  221. self:CancelLeftTimer()
  222. local timeStr = TimeUtil:timeConvert9(time)
  223. self.txtTime.text = time > 0 and timeStr or ""
  224. if time <= 0 then
  225. self:CancelLeftTimer()
  226. end
  227. if time - 3600 > 0 then --大于1小时的
  228. local duration = 60
  229. local first_time = time % 60 --先计算秒数的
  230. if first_time ~= 0 then
  231. duration = first_time
  232. end
  233. local function delayFunc( )
  234. time = time - duration
  235. timer_func()
  236. end
  237. self.left_time_id = GlobalTimerQuest:AddPeriodQuest(delayFunc, duration)
  238. else
  239. local function delayFunc( )
  240. time = time - 1
  241. timer_func()
  242. end
  243. self.left_time_id = GlobalTimerQuest:AddPeriodQuest(delayFunc, 1)
  244. end
  245. end
  246. timer_func()
  247. self.imgOver:SetActive(time <= 0)
  248. self.timeCon:SetActive(time > 0)
  249. end
  250. function CloudShoppingView:CancelLeftTimer()
  251. if self.left_time_id then
  252. GlobalTimerQuest:CancelQuest(self.left_time_id)
  253. self.left_time_id = nil
  254. end
  255. end
  256. function CloudShoppingView:CreateItems()
  257. local cfg = Config.Cloudbuy[self.data.big_reward_id]
  258. if cfg then
  259. local boxList = ErlangParser:GetInstance():Parse(cfg.happy_awards)
  260. if TableSize(boxList) > 0 then
  261. local onSortFunc = function (a, b)
  262. return tonumber(a[2]) < tonumber(b[2])
  263. end
  264. table.sort(boxList, onSortFunc)
  265. local item = nil
  266. for i, v in ipairs(boxList) do
  267. if self.box_list[i] then
  268. local reward_id = tonumber(v[2])
  269. item = self.item_list[reward_id]
  270. if item == nil then
  271. item = CloudShoppingItem.New(self.box_list[i])
  272. self.item_list[reward_id] = item
  273. end
  274. item:SetData(reward_id)
  275. end
  276. end
  277. end
  278. local total_count = tonumber(cfg.total_count)
  279. local buyNumStr = "<color="..ColorUtil.GREEN..">" .. self.data.all_buy_num .. "</color>"
  280. self.txtProgress.text = string.format("开奖进度:%s/%d", buyNumStr, total_count)
  281. self.txtPrice.text = cfg.worth
  282. buyNumStr = "<color="..ColorUtil.GREEN..">" .. self.data.self_buy_num .. "</color>"
  283. local leftStr = total_count - self.data.all_buy_num > 0 and "<color="..ColorUtil.GREEN..">" .. (total_count - self.data.all_buy_num) .. "</color>" or "<color="..ColorUtil.RED..">0</color>"
  284. self.txtBuy.text = string.format("您已购买%s份(剩余%s份)", buyNumStr, leftStr)
  285. local unlimited_time, award_time = self:GetActCondition()
  286. if unlimited_time and award_time then
  287. local cur_hour = os.date("%H", TimeUtil:getServerTime())
  288. cur_hour = tonumber(cur_hour)
  289. local str = ""
  290. local buy_time_str = self.data.less_buy_num > 0 and self.data.less_buy_num or "<color="..ColorUtil.RED..">0</color>"
  291. if cur_hour < unlimited_time or cur_hour > award_time then
  292. str = string.format("(还可购买%s份,开奖前%d小时不限制)", buy_time_str, award_time - unlimited_time)
  293. else
  294. str = string.format("(还可购买%s份)", buy_time_str)
  295. end
  296. self.txtLimit.text = str
  297. end
  298. self:SetGiftName(cfg)
  299. self:SetGiftModel(cfg)
  300. self:SetCost(cfg.cost)
  301. end
  302. end
  303. function CloudShoppingView:SetGiftName(cfg)
  304. local reward = ErlangParser:GetInstance():Parse(cfg.rewards)
  305. if TableSize(reward) > 0 then
  306. local type_id = 0
  307. if cfg.reward_type == 2 then --按职业区分
  308. local career = RoleManager.Instance:GetMainRoleVo().career
  309. for _,v in pairs(reward) do
  310. if career == tonumber(v[1]) then
  311. type_id = tonumber(v[2][1][2])
  312. break
  313. end
  314. end
  315. else
  316. type_id = tonumber(reward[1][2])
  317. end
  318. local goods_basic = GoodsModel:getInstance():GetGoodsBasicByTypeId(type_id)
  319. if goods_basic then
  320. local goodsName = "<color="..WordManager.GetGoodsColor(goods_basic.color) .. "><a@><u>"..Trim(goods_basic.goods_name) .. "</u></a></color>"
  321. local numStr = "<color="..ColorUtil.GREEN..">(" .. cfg.award_count .. "份)</color>"
  322. self.txtName.text = goodsName .. numStr
  323. local call_back = function(param, x, y)
  324. self:ClickBigRewardFunc(x, y)
  325. end
  326. AddUnderLineAndClick(self, self.txtName.transform, call_back, false, true)
  327. end
  328. end
  329. end
  330. function CloudShoppingView:ClickBigRewardFunc(x, y)
  331. local cfg = Config.Cloudbuy[self.data.big_reward_id]
  332. if not cfg then
  333. return
  334. end
  335. local reward = ErlangParser:GetInstance():Parse(cfg.rewards)
  336. if TableSize(reward) > 0 then
  337. local type_id = 0
  338. if cfg.reward_type == 2 then --按职业区分
  339. local career = RoleManager.Instance:GetMainRoleVo().career
  340. for _,v in pairs(reward) do
  341. if career == tonumber(v[1]) then
  342. type_id = tonumber(v[2][1][2])
  343. break
  344. end
  345. end
  346. else
  347. type_id = tonumber(reward[1][2])
  348. end
  349. local goods_basic = GoodsModel:getInstance():GetGoodsBasicByTypeId(type_id)
  350. if goods_basic then
  351. if goods_basic.type == GoodsModel.TYPE.EQUIP then
  352. local target_config = Config.Equipattr[type_id]
  353. if target_config then
  354. local dynamic = {}
  355. dynamic.type_id = type_id
  356. dynamic.rating = target_config.base_rating
  357. dynamic.equip_extra_attr = {}
  358. dynamic.equip_type = goods_basic.equip_type
  359. local target_pro = ErlangParser:GetInstance():Parse(target_config.recommend_attr)
  360. for i, v in ipairs(target_pro) do
  361. local attr = {}
  362. attr.color = tonumber(v[2][1])
  363. attr.attr_id = tonumber(v[2][2])
  364. if #v[2] == 5 then
  365. attr.type_id = 1
  366. attr.plus_interval = tonumber(v[2][4])
  367. attr.plus_unit = tonumber(v[2][5])
  368. else
  369. attr.type_id = 2
  370. attr.attr_val = tonumber(v[2][3])
  371. end
  372. table.insert(dynamic.equip_extra_attr, attr)
  373. end
  374. UIToolTipMgr:getInstance():AppendEquipShowTips(dynamic, x, y, EquipShowTips.EQUIP_RECOMMAND_TARGET)
  375. end
  376. else
  377. UIToolTipMgr:getInstance():AppendGoodsTips(type_id, x, y)
  378. end
  379. end
  380. end
  381. end
  382. function CloudShoppingView:SetGiftModel(cfg)
  383. local resouce_id_list = ErlangParser:GetInstance():Parse(cfg.resouce_id)
  384. local res_id = 0
  385. local career = RoleManager.Instance.mainRoleInfo.career
  386. for _,v in pairs(resouce_id_list) do
  387. if tonumber(v[1]) == career then
  388. res_id = tonumber(v[2])
  389. break
  390. end
  391. end
  392. local scale = tonumber(cfg.resouce_size)
  393. if scale and scale > 0 then
  394. scale = scale
  395. else
  396. scale = nil
  397. end
  398. local posList = ErlangParser:GetInstance():Parse(cfg.resouce_height)
  399. local x, y = 0, 0
  400. if TableSize(posList) > 0 then
  401. x = tonumber(posList[1][1])
  402. y = tonumber(posList[1][2])
  403. end
  404. local data = {
  405. clothe_res_id = res_id,
  406. type = SceneBaseType.Role,
  407. layer_name = self.layer_name,
  408. action_name_list = {"show", "idle"},
  409. can_rotate = true,
  410. layout_file = self.layout_file
  411. -- position = Vector3(x, y, 0),
  412. }
  413. lua_resM:SetRoleModel(self, self.imgGoods, data)
  414. --lua_resM:SetRoleModel(self,self.imgGoods,nil,nil,res_id,nil,nil,SceneBaseType.Role,self.layer_name,nil,{"show","idle"},false,scale,Vector3(x, y, 0))
  415. self.imgGoods:GetComponent("RawImage").raycastTarget = true
  416. end
  417. function CloudShoppingView:SetCost(costList)
  418. local cost_list = ErlangParser:GetInstance():Parse(costList)
  419. if TableSize(cost_list) > 0 then
  420. self.cost_type = tonumber(cost_list[1][1])
  421. self.cost = tonumber(cost_list[1][3])
  422. self.type_id = tonumber(cost_list[1][2])
  423. self.txtOne.text = self.cost
  424. self.txtTen.text = self.cost * 10
  425. self.goods_basic = GoodsModel:getInstance():GetGoodsBasicByTypeId(self.type_id)
  426. if self.goods_basic then
  427. lua_resM:setOutsideImageSprite(self, self.iconOne, GameResPath.GetGoodsIcon(self.goods_basic.goods_icon))
  428. lua_resM:setOutsideImageSprite(self, self.iconTen, GameResPath.GetGoodsIcon(self.goods_basic.goods_icon))
  429. end
  430. end
  431. end
  432. function CloudShoppingView:UpdateItems()
  433. local buy_list = self.model:GetCloudBuyList()
  434. for _, item in pairs(self.item_list) do
  435. item:ResetItem()
  436. end
  437. self:CancelTimer()
  438. local last_item = nil
  439. local len = TableSize(buy_list)
  440. if len > 0 then
  441. local index = 1
  442. local sub_index = 1
  443. function go_next()
  444. local data = buy_list[index]
  445. self:CancelTimer()
  446. if data then
  447. sub_index = sub_index % 14
  448. if sub_index == 0 then
  449. sub_index = 14
  450. end
  451. local function show_anim()
  452. local item = self.item_list[sub_index]
  453. if item then
  454. local find = false
  455. if not item.stop_change then
  456. local bool, num = self:ShowItemLightBg(buy_list, sub_index)
  457. if bool then
  458. item:ShowLightBg(bool, num)
  459. find = true
  460. else
  461. item:ShowLightBg(true, 0, true)
  462. end
  463. end
  464. if last_item then
  465. if not last_item.stop_change then
  466. last_item:ShowLightBg(false, 0, true)
  467. end
  468. end
  469. last_item = item
  470. if find then
  471. go_next()
  472. return
  473. end
  474. end
  475. sub_index = sub_index + 1
  476. end
  477. self.timer_id_1 = GlobalTimerQuest:AddPeriodQuest(show_anim, 0.1, -1)
  478. show_anim()
  479. end
  480. index = index + 1
  481. end
  482. go_next()
  483. end
  484. end
  485. function CloudShoppingView:ShowItemLightBg(buy_list, reward_id)
  486. local bool = false
  487. local num = 0
  488. for _, v in pairs(buy_list) do
  489. if v.reward_id == reward_id then
  490. bool = true
  491. num = v.reward_num
  492. break
  493. end
  494. end
  495. return bool, num
  496. end
  497. --获得活动条件
  498. function CloudShoppingView:GetActCondition()
  499. local act_data = self.model:getActList(self.base_type)
  500. --不限购时间和开奖时间
  501. local unlimited_time, award_time
  502. if act_data and act_data.condition_list then
  503. local condList = act_data.condition_list
  504. if TableSize(condList) > 0 then
  505. for _, v in ipairs(condList) do
  506. if Trim(v[1]) == "unlimited_time" then
  507. unlimited_time = tonumber(v[2][1])
  508. end
  509. if Trim(v[1]) == "award_time" then
  510. award_time = tonumber(v[2][1])
  511. end
  512. end
  513. end
  514. end
  515. return unlimited_time, award_time
  516. end
  517. function CloudShoppingView:CancelTimer()
  518. if self.timer_id_1 then
  519. GlobalTimerQuest:CancelQuest(self.timer_id_1)
  520. self.timer_id_1 = nil
  521. end
  522. if self.timer_id_2 then
  523. GlobalTimerQuest:CancelQuest(self.timer_id_2)
  524. self.timer_id_2 = nil
  525. end
  526. end