源战役客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
2.2 KiB

  1. CloudShopOddsView = CloudShopOddsView or BaseClass(BaseView)
  2. function CloudShopOddsView:__init()
  3. self.base_file = "cloudShopping"
  4. self.layout_file = "CloudShopOddsView"
  5. self.layer_name = "Activity"
  6. -- self.use_local_view = true
  7. self.close_mode = CloseMode.CloseDestroy
  8. self.change_scene_close = true
  9. self.destroy_imm = true
  10. self.use_background = true
  11. self.is_set_zdepth = true
  12. self.change_scene_close = true
  13. self.model = CustomActivityModel:getInstance()
  14. self.item_list = {}
  15. self.load_callback = function()
  16. self:LoadSuccess()
  17. self:InitEvent()
  18. end
  19. self.open_callback = function()
  20. self:SetData()
  21. end
  22. self.close_callback = function()
  23. end
  24. self.destroy_callback = function()
  25. self:Remove()
  26. end
  27. end
  28. function CloudShopOddsView:Remove()
  29. for i, item in pairs(self.item_list) do
  30. item:DeleteMe()
  31. end
  32. self.item_list = {}
  33. self.model = nil
  34. end
  35. function CloudShopOddsView:Open(index)
  36. BaseView.Open(self)
  37. end
  38. function CloudShopOddsView:LoadSuccess()
  39. self.content
  40. = GetChildTransforms(self.transform, {
  41. "ScrollView/Viewport/Content"
  42. })
  43. end
  44. function CloudShopOddsView:InitEvent()
  45. end
  46. function CloudShopOddsView:SetData()
  47. local data = self.model:GetCloudShoppingInfo()
  48. if data then
  49. local cfg = Config.Cloudbuy[data.big_reward_id]
  50. if cfg then
  51. local total_weight = 0
  52. local happy_awards = ErlangParser:GetInstance():Parse(cfg.happy_awards)
  53. for _, v in pairs(happy_awards) do
  54. total_weight = total_weight + tonumber(v[1])
  55. end
  56. table.sort(happy_awards, function (a, b)
  57. return tonumber(a[2]) < tonumber(b[2])
  58. end)
  59. self.content.sizeDelta = Vector2(400, 62 * #happy_awards)
  60. for i, v in ipairs(happy_awards) do
  61. local item = self.item_list[i]
  62. if not item then
  63. item = CloudShopOddsItem.New(self.content)
  64. self.item_list[i] = item
  65. end
  66. item:SetData(total_weight, v)
  67. item:SetPosition(0, -62 * (i - 1))
  68. end
  69. end
  70. end
  71. end