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

137 lines
4.4 KiB

  1. GoodsUseToolTips = GoodsUseToolTips or BaseClass(BaseView)
  2. function GoodsUseToolTips:__init()
  3. self.base_file = "common"
  4. self.layout_file = "GoodsUseToolTips"
  5. self.layer_name = "Top"
  6. -- self.use_local_view = true
  7. self.use_background = true
  8. self.is_set_zdepth = true
  9. self.click_bg_toClose = true
  10. self.pos_x = 0
  11. self.pos_y = 0
  12. self.model = GoodsModel:getInstance()
  13. self.curr_height = 0
  14. self.load_callback = function ()
  15. self:LoadSuccess()
  16. self:InitData()
  17. end
  18. self.open_callback = function ()
  19. self:SetData()
  20. end
  21. self.close_callback = function ()
  22. end
  23. self.destroy_callback = function ()
  24. end
  25. end
  26. function GoodsUseToolTips:LoadSuccess()
  27. self.bg = self:GetChild("layout/bg")
  28. self.layout = self:GetChild("layout")
  29. self.icon_img = self:GetChild("layout/icon_con/img"):GetComponent("Image")
  30. self.icon = self:GetChild("layout/icon_con"):GetComponent("Image")
  31. self.name_text = self:GetChild("layout/nameText"):GetComponent("Text")
  32. self.use_text = self:GetChild("layout/useText"):GetComponent("Text")
  33. self.content_text = self:GetChild("layout/contentText")
  34. self.getway = self:GetChild("layout/getway")
  35. self.getway_text = self:GetChild("layout/getway/getwayText"):GetComponent("Text")
  36. self.close_btn = self:GetChild("layout/close_btn").gameObject
  37. self:InitEvent()
  38. end
  39. function GoodsUseToolTips:InitEvent()
  40. function OnClickEvent(target)
  41. if target == self.close_btn then
  42. self:Close()
  43. end
  44. end
  45. AddClickEvent(self.close_btn,OnClickEvent)
  46. end
  47. -- goods_id:物品id、max_times:最大使用数、attr:属性加成表 use_times:物品当前使用次数
  48. function GoodsUseToolTips:Open(goods_id,max_times,attr,use_times,x,y,module_id, combat)
  49. self.goods_id = goods_id
  50. self.max_times = max_times
  51. self.attr = attr
  52. self.use_times = use_times
  53. self.pos_x = x
  54. self.pos_y = y
  55. self.module_id = module_id
  56. self.combat = combat
  57. self.cfg = ConfigItemMgr.Instance:GetGoodItem(self.goods_id)
  58. BaseView.Open(self)
  59. end
  60. function GoodsUseToolTips:InitData() --在load完设置位置就不会出现闪屏的现象了
  61. if not self.is_loaded then return end
  62. if self.pos_x and self.pos_y then
  63. local x,y = ScreenToViewportPoint(self.pos_x,self.pos_y)
  64. if x+400 > ScreenWidth then
  65. x = ScreenWidth-400-20
  66. elseif x<20 then
  67. x = 20
  68. end
  69. if y < 20 then
  70. y = 20
  71. elseif y+self.bg.sizeDelta.y > ScreenHeight then
  72. y = ScreenHeight-self.bg.sizeDelta.y -20
  73. end
  74. self.layout.anchoredPosition = Vector3(x + 10,y +self.bg.sizeDelta.y,0)
  75. end
  76. end
  77. function GoodsUseToolTips:SetData()
  78. if self.cfg == nil then return end
  79. local id = self.goods_id
  80. local max_times = self.max_times
  81. local attr_list = self.attr
  82. if type(self.attr) ~= "table" then
  83. attr_list = ErlangParser:GetInstance():Parse(self.attr)
  84. end
  85. if self.cfg.color then
  86. lua_resM:setImageSprite(self, self.icon, "common_asset", "tyui_pz_"..self.cfg.color)
  87. end
  88. lua_resM:setOutsideImageSprite(self,self.icon_img,GameResPath.GetGoodsIcon(id))
  89. self.name_text.text = "<color="..ColorUtil.RED..">"..self.cfg.goods_name.."</color>"
  90. self.use_text.text = "当前使用: "..self.use_times.."/"..max_times..""
  91. self.curr_height = 161
  92. self.content_text.localPosition = co.TableXYZ(43,-self.curr_height,0)
  93. local str = ""
  94. if #attr_list >0 then
  95. local attr_name = ""
  96. local attr_value = ""
  97. for i = 1,#attr_list do
  98. local attr_id = attr_list[i].attr_id or tonumber(attr_list[i][1])
  99. local attr_num = attr_list[i].attr_num or tonumber(attr_list[i][2])
  100. attr_name = WordManager:GetProperties(attr_id,self.module_id)
  101. attr_value = WordManager:GetPropertyValue(attr_id,attr_num)
  102. --str = str .. WordManager:GetProperties(tonumber(attr_list[i][1])).."+"..attr_list[i][2].."\n"
  103. str = str .. attr_name.." + "..attr_value.."\n"
  104. end
  105. end
  106. if self.combat then
  107. str = str.."战力 + "..self.combat.."\n"
  108. end
  109. local good_type = WordManager:GetGoodsTypeStr(self.cfg.type, self.cfg.subtype)
  110. self.content_text:GetComponent("Text").text = "使用后"..good_type.."属性变化:\n".."<color="..ColorUtil.GREEN..">"..str.."</color>"
  111. self.curr_height = self.curr_height + self.content_text:GetComponent("Text").preferredHeight + 10
  112. self.getway.localPosition = co.TableXYZ(18,-self.curr_height,0)
  113. self.getway_text.text = "<color="..ColorUtil.BLUE..">"..Trim(self.cfg.getway).."</color>"
  114. self.bg.sizeDelta = Vector2(394,self.curr_height + 80)
  115. -- local x,y = ScreenToViewportPoint(self.pos_x,self.pos_y)
  116. -- self.layout.anchoredPosition = Vector3(x + 10,y +self.bg.sizeDelta.y,0)
  117. end