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

146 rivejä
3.4 KiB

1 kuukausi sitten
  1. --[[
  2. @
  3. --]]
  4. OptionalItemTips = OptionalItemTips or BaseClass(BaseView)
  5. local OptionalItemTips = OptionalItemTips
  6. function OptionalItemTips:__init()
  7. self.base_file = "common"
  8. self.layout_file = "OptionalItemTips"
  9. self.layer_name = "Top"
  10. self.destroy_imm = true
  11. self.use_background = true
  12. self.click_bg_toClose = true
  13. self.is_set_zdepth = true
  14. self.wait_for_hide = true
  15. self.item_list = {}
  16. self.load_callback = function()
  17. self:LoadSuccess()
  18. self:AdjustLayoutPos()
  19. end
  20. self.open_callback = function()
  21. self:SetLabel()
  22. self:SetContent()
  23. end
  24. self.destroy_callback = function ()
  25. self:Remove()
  26. end
  27. end
  28. function OptionalItemTips:Remove()
  29. for i, v in ipairs(self.item_list) do
  30. v:DeleteMe()
  31. v = nil
  32. end
  33. self.item_list = {}
  34. end
  35. function OptionalItemTips:LoadSuccess()
  36. self.layout,
  37. self.bg,
  38. self.content_parent
  39. = self:GetChildTransforms(
  40. {
  41. "layout",
  42. "layout/bg",
  43. "layout/itemScrollView/Viewport/Content"
  44. })
  45. self.title,
  46. self.label,
  47. self.tips
  48. = self:GetChildTexts(
  49. {
  50. "layout/title",
  51. "layout/EmptyCon/text",
  52. "layout/tips",
  53. })
  54. self.empty
  55. = self:GetChildGameObjects(
  56. {
  57. "layout/EmptyCon",
  58. })
  59. self.item_mask
  60. = self:GetChildImages(
  61. {
  62. "layout/itemScrollView/Viewport"
  63. })
  64. SetSizeDelta(self.transform, ScreenWidth, ScreenHeight)
  65. end
  66. function OptionalItemTips:SetLabel()
  67. local str = WordManager:GetGoodsTypeStr(self.goods_type)
  68. str = string.len(str) == 0 and "材料" or str
  69. self.title.text = "点击选择"..(self.grade and ((self.grade - 1) .."") or "").. str
  70. self.label.text = "背包中没有可选择的"..str
  71. end
  72. function OptionalItemTips:Open(x, y, goods_type, goods_list, callback, item_type,grade)
  73. self.goods_type = goods_type
  74. self.goods_list = goods_list
  75. self.grade = grade
  76. self.pos_x = x
  77. self.pos_y = y
  78. self.callback = callback
  79. self.item_type = item_type or OptionalItem.Type.EQUIP
  80. BaseView.Open(self)
  81. end
  82. function OptionalItemTips:SetContent()
  83. if self.goods_list and TableSize(self.goods_list) > 0 then
  84. self.empty:SetActive(false)
  85. self:SetItem()
  86. else
  87. local str = WordManager:GetGoodsTypeStr(self.goods_type)
  88. str = string.len(str) == 0 and "材料" or str
  89. self.title.text = "背包中没有可选择的"..(self.grade and ((self.grade - 1) .."") or "")..str
  90. self.empty:SetActive(true)
  91. end
  92. end
  93. function OptionalItemTips:SetItem()
  94. local function onSelectCallback(goods_vo)
  95. if self.callback ~= nil then
  96. self.callback(goods_vo)
  97. end
  98. self:Close()
  99. end
  100. local count = 0
  101. table.sort( self.goods_list, function ( a,b )
  102. return a.color > b.color
  103. end )
  104. for k, v in ipairs(self.goods_list) do
  105. count = count + 1
  106. self.item_list[count] = self.item_list[count] or OptionalItem.New(self.content_parent, nil, self.layer_name, self.item_type)
  107. self.item_list[count]:SetData(v, onSelectCallback)
  108. end
  109. for i = count + 1, #self.item_list do
  110. self.item_list[i]:SetVisible(false)
  111. end
  112. end
  113. function OptionalItemTips:AdjustLayoutPos()
  114. if self.pos_x and self.pos_y then
  115. local layout_width = self.bg.sizeDelta.x
  116. local layout_height = self.bg.sizeDelta.y
  117. local x,y = ScreenToViewportPoint(self.pos_x,self.pos_y)
  118. local iphone_x_offset = math.max(ClientConfig.iphone_x_offset_left,ClientConfig.iphone_x_offset_right)
  119. if x + layout_width + 50 + iphone_x_offset * 2 > SrcScreenWidth then
  120. x = SrcScreenWidth - layout_width - 90 - iphone_x_offset * 2
  121. end
  122. if y < layout_height + 50 then
  123. y = layout_height + 50
  124. end
  125. self.layout.anchoredPosition = Vector2(x,y - ScreenHeight)
  126. end
  127. end