您不能選擇超過 %s 個話題 話題必須以字母或數字為開頭,可包含連接號 ('-') 且最長為 35 個字

165 行
5.1 KiB

  1. local UpdateTipsView = {};
  2. UpdateTipsView.__index = UpdateTipsView;
  3. -- 创建新对象
  4. function UpdateTipsView:new(...)
  5. local instance = {};
  6. setmetatable(instance , UpdateTipsView);
  7. instance:ctor(...);
  8. return instance;
  9. end
  10. -- onOkCallback : funciton(), 点击确定时的处理
  11. -- onCancelCallback : funciton(), 点击确定时的处理
  12. -- closeWhenOk :boolean, 点击确定时是否关闭界面
  13. function UpdateTipsView:ctor(content, onOkCallback, onCancelCallback, closeWhenOk)
  14. self.content = content;
  15. self.onOkCallback = onOkCallback;
  16. self.onCancelCallback = onCancelCallback;
  17. self.closeWhenOk = closeWhenOk;
  18. self:onEnter();
  19. end
  20. function UpdateTipsView:onEnter()
  21. local ui = loadUI("preload/res/preload_update.ui")
  22. self.ui = ui;
  23. local function setTextColor(uiText, color)
  24. local label = uiText:getVirtualRenderer();
  25. local config = label:getTTFConfig()
  26. config.texColor = color;
  27. label:setTTFConfig(config)
  28. end
  29. -- 强更提示内容模板
  30. -- json 工具地址: https://www.bejson.com
  31. --[[
  32. {"title":{"size":24,"color":"30_42_52","content":["发现有新的版本,请点击“确认更新”按钮开始更新。"]},"content":{"size":24,"color":"30_42_52","content":["更新内容:","1、增加绑定及登录的功能。","2、优化已知bug,提升游戏性能。"]},"warnning":{"size":24,"color":"219_56_35","content":["如遇更新失败,请删除老版本再重新下载,或联系客服ddph8800","处理!"]},"team":"悠闲运营团队","date":"2019-11-25"}
  33. --]]
  34. local uiLayout = self.ui.Items.Layout_Text
  35. local uiSpace = self.ui.Items.Layout_Space
  36. local uiTextLeft = self.ui.Items.Text_Left
  37. local uiTextRight = self.ui.Items.Text_Right
  38. uiTextLeft:setVisible(false)
  39. uiTextRight:setVisible(false)
  40. logD("UpdateTipsView:onEnter() self.content = ",self.content)
  41. local jsonData = json.decode(self.content)
  42. if jsonData and type(jsonData) == "table" then
  43. -- title
  44. if jsonData.title and type(jsonData.title) == "table" then
  45. local size = tonumber(jsonData.title.size) or 24
  46. local colors = split(tostring(jsonData.title.color), "_")
  47. local color = { r = colors[1], g = colors[2], b = colors[3], a = 255 }
  48. if jsonData.title.content and type(jsonData.title.content) == "table" then
  49. for k,v in ipairs(jsonData.title.content) do
  50. local uiText = uiTextLeft:getCopied()
  51. uiText:setVisible(true)
  52. uiText:setString(v)
  53. setTextColor(uiText, color)
  54. uiText:setFontSize(size)
  55. uiLayout:addChild(uiText)
  56. end
  57. end
  58. end
  59. -- 空格
  60. uiLayout:addChild(uiSpace:getCopied())
  61. -- content
  62. if jsonData.content and type(jsonData.content) == "table" then
  63. local size = tonumber(jsonData.content.size) or 24
  64. local colors = split(tostring(jsonData.content.color), "_")
  65. local color = { r = colors[1], g = colors[2], b = colors[3], a = 255 }
  66. if jsonData.content.content and type(jsonData.content.content) == "table" then
  67. for k,v in ipairs(jsonData.content.content) do
  68. local uiText = uiTextLeft:getCopied()
  69. uiText:setVisible(true)
  70. uiText:setString(v)
  71. setTextColor(uiText, color)
  72. uiText:setFontSize(size)
  73. uiLayout:addChild(uiText)
  74. end
  75. end
  76. end
  77. -- 空格
  78. uiLayout:addChild(uiSpace:getCopied())
  79. -- warnning
  80. if jsonData.warnning and type(jsonData.warnning) == "table" then
  81. local size = tonumber(jsonData.warnning.size) or 24
  82. local colors = split(tostring(jsonData.warnning.color), "_")
  83. local color = { r = colors[1], g = colors[2], b = colors[3], a = 255 }
  84. if jsonData.warnning.content and type(jsonData.warnning.content) == "table" then
  85. for k,v in ipairs(jsonData.warnning.content) do
  86. local uiText = uiTextLeft:getCopied()
  87. uiText:setVisible(true)
  88. uiText:setString(v)
  89. setTextColor(uiText, color)
  90. uiText:setFontSize(size)
  91. uiLayout:addChild(uiText)
  92. end
  93. end
  94. end
  95. -- 空格
  96. uiLayout:addChild(uiSpace:getCopied())
  97. -- team
  98. if jsonData.team then
  99. local uiText = uiTextRight:getCopied()
  100. uiText:setVisible(true)
  101. uiText:setString(jsonData.team)
  102. uiLayout:addChild(uiText)
  103. end
  104. if jsonData.date then
  105. local uiText = uiTextRight:getCopied()
  106. uiText:setVisible(true)
  107. uiText:setString(jsonData.date)
  108. uiLayout:addChild(uiText)
  109. end
  110. else
  111. local uiText = uiTextLeft:getCopied()
  112. uiText:setVisible(true)
  113. uiText:setString("发现新的更新")
  114. uiLayout:addChild(uiText)
  115. end
  116. local function onClickOK(sender, eventType)
  117. if eventType == 2 then
  118. if self.closeWhenOk then
  119. self.ui:removeFromParent();
  120. end
  121. if self.onOkCallback then
  122. self.onOkCallback()
  123. end
  124. end
  125. return true;
  126. end
  127. ui.Items.Button_Sure:addTouchEventListener(onClickOK)
  128. local function onClickClose(sender, eventType)
  129. if eventType == 2 then
  130. ui.Items.Button_Close:setVisible(false)
  131. self.ui:removeFromParent()
  132. if self.onCancelCallback then
  133. self.onCancelCallback()
  134. end
  135. end
  136. return true;
  137. end
  138. ui.Items.Button_Close:addTouchEventListener(onClickClose)
  139. ui.Items.Button_Close:setVisible(self.onCancelCallback ~= nil)
  140. local scene = cc.Director:getInstance():getRunningScene()
  141. scene:addChild(ui)
  142. end
  143. return UpdateTipsView;