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

153 lines
3.8 KiB

  1. GetPicTips = GetPicTips or BaseClass(BaseView)
  2. local GetPicTips = GetPicTips
  3. function GetPicTips:__init()
  4. self.base_file = "common"
  5. self.layout_file = "GetGoodsTips"
  6. self.layer_name = "Activity"
  7. self.open_wnd_anim = 0
  8. self.use_background = true
  9. self.click_bg_toClose = true
  10. self.is_set_zdepth = true
  11. self.item_list = {}
  12. self.load_callback = function ()
  13. self:LoadSuccess()
  14. self:SetPosition()
  15. end
  16. self.open_callback = function ()
  17. self:OpenView()
  18. end
  19. self.close_callback = function ()
  20. end
  21. self.destroy_callback = function ()
  22. self:Remove()
  23. end
  24. end
  25. function GetPicTips:LoadSuccess()
  26. self.layout = self:GetChild("layout")
  27. self.bg = self:GetChild("layout/Window2")
  28. self.closeBtn = self:GetChild("layout/Window2/windowCloseBtn").gameObject
  29. self.name = self:GetChild("layout/name"):GetComponent("Text")
  30. self.content_parent = self:GetChild("layout/itemScrollView/Viewport/Content")
  31. self.icon_tra = self:GetChild("layout/award")
  32. self.icon_go = UiFactory.createChild(self.icon_tra,UIType.Image)
  33. self.icon_img = self.icon_go.transform:GetComponent("Image")
  34. self.icon_item = AwardItem.New(self:GetChild("layout/award"))
  35. self:InitEvent()
  36. end
  37. function GetPicTips:InitEvent()
  38. local function onBtnClickHandler(target)
  39. if target == self.closeBtn then
  40. self:Close()
  41. end
  42. end
  43. AddClickEvent(self.closeBtn, onBtnClickHandler, 1)
  44. end
  45. function GetPicTips:SetPosition()
  46. if self.pos_x and self.pos_y then
  47. local layout_width = self.bg.sizeDelta.x
  48. local layout_height = self.bg.sizeDelta.y
  49. local x,y = ScreenToViewportPoint(self.pos_x,self.pos_y)
  50. x = x - 300
  51. y = y - 100
  52. if x < layout_width - 50 then
  53. x = layout_width - 50
  54. end
  55. if x + layout_width > ScreenWidth then
  56. x = ScreenWidth - layout_width - 80
  57. end
  58. if y < layout_height - 200 then
  59. y = layout_height - 200
  60. end
  61. self.layout.anchoredPosition = Vector2(x,y)
  62. end
  63. end
  64. function GetPicTips:Open(pic_id, x, y)
  65. self.pic_id = pic_id
  66. self.pos_x = x
  67. self.pos_y = y
  68. BaseView.Open(self)
  69. end
  70. --加载可添加的item
  71. function GetPicTips:OpenView()
  72. self.icon_item:SetGoodsIcon(24030002,true)
  73. self.icon_item:SetBgShow(0)
  74. --lua_resM:setOutsideImageSprite(self,self.icon_img,GameResPath.GetGoodsIcon(24030002),true)
  75. for i, v in ipairs(self.item_list) do
  76. v:SetVisible(false)
  77. end
  78. local function callback()
  79. self:Close()
  80. end
  81. local config = Config.Pic[self.pic_id]
  82. if config then
  83. self.name.text = "<color="..ColorUtil:GetColor(0)..">"..config.name.."</color>"
  84. if config.get_way then
  85. local list_1, list_2 = {}, {}
  86. local getway = ErlangParser:GetInstance():Parse(config.get_way)
  87. for i, v in ipairs(getway) do
  88. local main = tonumber(v[1])
  89. local sub = tonumber(v[2])
  90. print(main,sub)
  91. if main == 132 then
  92. table.insert(list_1, v)
  93. elseif main and sub then
  94. local cfg = OpenFun.GetFunCfg(main, sub)
  95. if cfg then
  96. if RoleManager.Instance.mainRoleInfo.level < cfg.openLv then
  97. table.insert(list_2, v)
  98. else
  99. table.insert(list_1, v)
  100. end
  101. else
  102. print("=================== can't find config, fun id is ", main, sub)
  103. end
  104. end
  105. end
  106. for i, v in ipairs(list_1) do
  107. self.item_list[i] = self.item_list[i] or GetPicItem.New(self.content_parent)
  108. self.item_list[i]:SetVisible(true)
  109. self.item_list[i]:SetData(v, self.pic_id, callback)
  110. end
  111. local count = #list_1
  112. for i, v in ipairs(list_2) do
  113. self.item_list[count + i] = self.item_list[count + i] or GetPicItem.New(self.content_parent)
  114. self.item_list[count + i]:SetVisible(true)
  115. self.item_list[count + i]:SetData(v, self.pic_id, callback)
  116. end
  117. end
  118. end
  119. end
  120. function GetPicTips:Remove()
  121. for i, v in ipairs(self.item_list) do
  122. v:DeleteMe()
  123. v = nil
  124. end
  125. self.item_list = {}
  126. if self.icon_item then
  127. self.icon_item:DeleteMe()
  128. self.icon_item = nil
  129. end
  130. if self.icon_go then
  131. destroy(self.icon_go,true)
  132. end
  133. end