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

87 lines
2.3 KiB

  1. --[[@------------------------------------------------------------------
  2. @description:
  3. @author:wyb
  4. ----------------------------------------------------------------------]]
  5. UISimpleToolTips = UISimpleToolTips or BaseClass(BaseView)
  6. function UISimpleToolTips:__init()
  7. self.base_file = "common"
  8. self.layout_file = "UISimpleToolTips"
  9. self.layer_name = "Top"
  10. self.use_background = true
  11. self.click_bg_toClose = true
  12. self.background_alpha = 0
  13. self.hide_maincancas = false
  14. self.close_mode = CloseMode.CloseDestroy
  15. self.destroy_imm = true
  16. self.load_callback = function ()
  17. self:LoadSuccess()
  18. self:addEvents()
  19. end
  20. self.open_callback = function ()
  21. self:SetText()
  22. end
  23. self.close_callback = function ()
  24. end
  25. self.destroy_callback = function ()
  26. self:Remove()
  27. end
  28. end
  29. function UISimpleToolTips:Remove()
  30. end
  31. function UISimpleToolTips:Open(desc, x, y, sx, sy)
  32. self.desc = desc
  33. self.pos_x = x
  34. self.pos_y = y
  35. self.size_x = sx
  36. self.size_y = sy
  37. BaseView.Open(self)
  38. end
  39. function UISimpleToolTips:LoadSuccess()
  40. self.panel = self:GetChild("panel")
  41. self.bg = self:GetChild("panel/bg")
  42. self.scroll = self:GetChild("panel/ScrollView/Viewport/Content")
  43. self.scroll_view = self:GetChild("panel/ScrollView")
  44. self.contentTxt = self:GetChild("panel/ScrollView/Viewport/Content/contentTxt"):GetComponent("Text")
  45. self.txt = self:GetChild("panel/ScrollView/Viewport/Content/contentTxt")
  46. end
  47. function UISimpleToolTips:addEvents()
  48. end
  49. function UISimpleToolTips:SetText()
  50. local s_x = self.size_x or self.scroll_view.transform.sizeDelta.x
  51. local s_y = self.size_y or self.scroll_view.transform.sizeDelta.y
  52. self.panel.transform.sizeDelta= Vector2(s_x+40, s_y+35)
  53. self.scroll_view.transform.sizeDelta = Vector2(s_x, s_y)
  54. self.txt.transform.sizeDelta = Vector2(s_x, s_y)
  55. self.contentTxt.text = self.desc
  56. self.scroll.sizeDelta = Vector2(s_x, self.contentTxt.preferredHeight)
  57. local con_width = self.panel.transform.sizeDelta.x
  58. local con_height = self.panel.transform.sizeDelta.y
  59. local x, y = ScreenToViewportPoint(self.pos_x, self.pos_y)
  60. if x + con_width > SrcScreenWidth then
  61. x = SrcScreenWidth - con_width - 20
  62. end
  63. if y - con_height <= 0 then
  64. y = con_height + 80
  65. end
  66. if y + con_height > ScreenHeight then
  67. y = ScreenHeight - con_height - 20
  68. end
  69. self.panel.transform.anchoredPosition = Vector3(x, y, 0)
  70. end