源战役客户端
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.

143 lines
4.1 KiB

  1. GetWayTipsView = GetWayTipsView or BaseClass(BaseView)
  2. function GetWayTipsView:__init()
  3. self.base_file = "common"
  4. self.layout_file = "GetWayTipsView"
  5. self.layer_name = "Top"
  6. self.destroy_imm = true
  7. self.use_background = false
  8. self.background_alpha = 0
  9. self.pos_x = nil
  10. self.pos_y = nil
  11. self.type_id = nil
  12. self.item_list = {} --item列表
  13. self.show_animation = false
  14. self.hide_background = false
  15. self:AddPreLoadList("common",{"GetWayTipsItem"})
  16. self.load_callback = function()
  17. self:LoadSuccess()
  18. self:InitEvent()
  19. end
  20. self.open_callback = function()
  21. self:SetPosAndAnimation()
  22. self:InitViewInfo()
  23. end
  24. self.close_callback = function ()
  25. end
  26. self.destroy_callback = function()
  27. self:Remove()
  28. end
  29. end
  30. function GetWayTipsView:SetPosAndAnimation()
  31. if self.transform and self.pos_x and self.pos_y then
  32. local pos = self.transform.localPosition
  33. if self.show_animation then
  34. self.transform.localPosition = Vector3(self.transform.localPosition.x, self.pos_y, self.transform.localPosition.z)
  35. self.canvasGroup.alpha = 0
  36. local end_fun = function ()
  37. end
  38. TweenLite.to(self, self.transform, TweenLite.UiAnimationType.POS, Vector3(self.pos_x, self.pos_y, pos.z), 0.3, end_fun)
  39. TweenLite.to(self, self.canvasGroup,TweenLite.UiAnimationType.ALPHA, 1, 0.5)
  40. self.clickBg.transform.localPosition = Vector3(-self.pos_x, -self.pos_y, -pos.z)
  41. else
  42. self.transform.localPosition = Vector3(self.pos_x, self.pos_y, pos.z)
  43. self.clickBg.transform.localPosition = Vector3(-self.pos_x, -self.pos_y, -pos.z)
  44. end
  45. if self.hide_background and self.clickBg then
  46. self.clickBg:SetActive(false)
  47. end
  48. end
  49. end
  50. function GetWayTipsView:Open(type_id, x, y, show_animation, hide_background)
  51. self.type_id = type_id
  52. self.pos_x = x
  53. self.pos_y = y
  54. self.show_animation = show_animation
  55. self.hide_background = hide_background
  56. BaseView.Open(self)
  57. end
  58. function GetWayTipsView:Remove()
  59. for i,v in ipairs(self.item_list) do
  60. v:DeleteMe()
  61. v = nil
  62. end
  63. self.item_list = {}
  64. if self.event_id then
  65. GlobalEventSystem:UnBind(self.event_id)
  66. self.event_id = nil
  67. end
  68. if self.event_id2 then
  69. GlobalEventSystem:UnBind(self.event_id2)
  70. self.event_id2 = nil
  71. end
  72. if self.event_id3 then
  73. GlobalEventSystem:UnBind(self.event_id3)
  74. self.event_id3 = nil
  75. end
  76. end
  77. function GetWayTipsView:LoadSuccess()
  78. self.canvasGroup = self.transform:GetComponent("CanvasGroup")
  79. self.bg = self:GetChild("bg")
  80. self.ScrollView = self:GetChild("ScrollView/Viewport/Content")
  81. self.clickBg = self:GetChild("clickBg").gameObject
  82. self.desc_bg_img = self:GetChild("layout/desc_bg"):GetComponent("Image")
  83. lua_resM:setOutsideImageSprite(self,self.desc_bg_img,GameResPath.GetViewBigBg("goods_tool_tip_bg"),false)
  84. SetSizeDelta(self.bg, ScreenWidth, ScreenHeight)
  85. end
  86. function GetWayTipsView:InitEvent()
  87. local call_fun = function ()
  88. if self then
  89. self:Close()
  90. GlobalEventSystem:Fire(EventName.CLICK_GET_WAY_CLOSE)
  91. end
  92. end
  93. self.event_id = GlobalEventSystem:Bind(EventName.CLICK_GET_WAY_ITEM, call_fun)
  94. self.event_id2 = GlobalEventSystem:Bind(EventName.GOODS_TOOLTIP_CLOSE, call_fun)
  95. self.event_id3 = GlobalEventSystem:Bind(CultureEvent.CLOSE_EQUIP_CULTURE_TIPS_VIEW, call_fun)
  96. AddClickEvent(self.clickBg,call_fun)
  97. end
  98. function GetWayTipsView:InitViewInfo()
  99. local goodsVo = GoodsModel:getInstance():GetGoodsBasicByTypeId(self.type_id)
  100. if goodsVo == nil then
  101. -- print("没有找到对应的物品vo----------:", self.type_id)
  102. return
  103. end
  104. self:ShowGainWay(goodsVo)
  105. end
  106. function GetWayTipsView:ShowGainWay(goodsVo)
  107. -- local list = ErlangParser:GetInstance():Parse(goodsVo.getway)
  108. -- goodsVo.getway = "1,2,3,4"
  109. local arr = Split(goodsVo.getway,",")
  110. -- print("--------------goodsVo.getway---:", goodsVo.getway)
  111. -- PrintTable(arr)
  112. for i,v in ipairs(self.item_list) do
  113. v:DeleteMe()
  114. v = nil
  115. end
  116. self.item_list = {}
  117. if not IsTableEmpty(arr) then
  118. for k,v in ipairs(arr) do
  119. local item = self.item_list[k]
  120. if item == nil then
  121. item = GetWayTipsItem.New(self.ScrollView)
  122. self.item_list[k] = item
  123. end
  124. item:SetPosition(0,-85*(k - 1))
  125. item:SetData(v)
  126. end
  127. self.ScrollView.sizeDelta = Vector2(290,#arr*85)
  128. end
  129. end