KLUICommonTipsPanel.lua 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. ---@class KLUICommonTipsPanel:UIKmlLuaPanelBase
  2. ---@field view KLUICommonTipsPanelView
  3. ---@field args KLUICommonTipsData
  4. local KLUICommonTipsPanel = class(UIKmlLuaPanelBase)
  5. local this = KLUICommonTipsPanel
  6. ---@class KLUICommonTipsData
  7. ---@field showTips string @中心文本
  8. ---@field tipsPos table @中心文本位置
  9. ---@field title string @标题文本
  10. ---@field titlePos table @标题位置
  11. ---@field isShowSureBtn boolean @确认按钮是否显示(默认显示)
  12. ---@field isShowCancelBtn boolean @确认按钮是否显示(默认显示)
  13. ---@field callback function @确认回调
  14. ---@field sureBtnPos table @确认按钮位置
  15. ---@field sureBtnText string @确认按钮文本
  16. ---@field sureBtnImageData KLUICommonTipsImageData @确认按钮图片数据
  17. ---@field cancelCallBack function @取消回调
  18. ---@field cancelBtnPos table @确认按钮位置
  19. ---@field cancelBtnText string @取消按钮文本
  20. ---@field cancelBtnImageData KLUICommonTipsImageData @确认按钮图片数据
  21. ---@field ui UIKmlLuaPanelBase @打开通用面板的ui
  22. ---@field callbackData table @回调数据
  23. ---@field closeTime number @如果有关闭时间,关闭整个面板
  24. ---@field showInput boolean @显示输入框
  25. ---@field inputPos table @输入框位置
  26. ---@field showToggle boolean @显示复选框
  27. ---@field togglePos table @复选框位置
  28. ---@field showSlider boolean @显示拖动条
  29. ---@field sliderPos table @拖动条位置
  30. ---@field littleTipsTextTable KLUICommonTipsTextControl @提示文本
  31. ---@field closeCallBack KLUICommonTipsTextControl @关闭回调
  32. ---@field stringTblID number @string表id
  33. ---@field stringTblFormat table @字符串参数
  34. ---@class KLUICommonTipsTextControl
  35. ---@field id string @控件名字
  36. ---@field x number @水平偏移
  37. ---@field y number @垂直偏移
  38. ---@field text string @文本内容
  39. ---@class KLUICommonTipsImageData
  40. ---@field atlas string @图集名
  41. ---@field src string @图片名
  42. ---创建时调用一次
  43. function this:Init()
  44. end
  45. ---创建或者刷新界面数据时调用
  46. function this:Refresh()
  47. self.returnData = {}
  48. ---@type KLUICommonTipsData
  49. self.args = self.args
  50. if self.args then
  51. if self.args.stringTblID then
  52. ---@type cfg_string_column
  53. local stringTbl = SL:GetConfig("cfg_string", self.args.stringTblID)
  54. local ColorTbl = SL:GetConfig("cfg_color", tonumber(stringTbl.textColor))
  55. local textColor = ColorTbl.color
  56. textColor = string.sub(textColor, 1, 7)
  57. local alpha = string.format("%x", math.floor(255 - stringTbl.transparencyT * 2.55))
  58. self.args.showTips = "<color=" .. textColor .. alpha .. ">" .. stringTbl.text .. "</color>"
  59. GUI:setPosition(self.view.root, stringTbl.offsetX, stringTbl.offsetY)
  60. GUI:Text_setFontSize(self.view.tipsContent, stringTbl.textSize)
  61. if self.args.stringTblFormat then
  62. self.args.showTips = string.format(self.args.showTips, table.unpack(self.args.stringTblFormat))
  63. end
  64. end
  65. if self.args.cfgId and self.args.needCount then
  66. GUI:Item_Create(self.view.tipsContent, {
  67. width = "80",
  68. height = "80",
  69. itemid = self.args.cfgId,
  70. tips = "1",
  71. noclip = "1",
  72. mfixsize = "80,80",
  73. bgtype = "0",
  74. y="-50",
  75. x="-20"
  76. })
  77. local haveCount = SL:GetBagItemCount(self.args.cfgId)
  78. local needCount = self.args.needCount
  79. if haveCount < needCount then
  80. GUI:Text_setString(self.view.tipsItemCount, string.format('<color="#9b1818">%d</color>/%d', haveCount, needCount))
  81. else
  82. GUI:Text_setString(self.view.tipsItemCount, string.format('<color="#5CE366FF">%d</color>/%d', haveCount, needCount))
  83. end
  84. GUI:setVisible(self.view.tipsItemCount, true)
  85. GUI:setPosition(self.view.tipsItemCount, 20, -25)
  86. GUI:setPosition(self.view.tipsContent,0,25)
  87. end
  88. ---内容
  89. if self.args.showTips then
  90. GUI:Text_setString(self.view.tipsContent, self.args.showTips)
  91. GUI:setVisible(self.view.tipsContent, true)
  92. if self.args.tipsPos then
  93. GUI:setPosition(self.view.tipsContent, self.args.tipsPos.x, self.args.tipsPos.y)
  94. end
  95. end
  96. if self.args.littleTipsTextTable then
  97. local defaultPos = { x = 0, y = -40 }
  98. if not self.args.littleTipsTextTable.x or not self.args.littleTipsTextTable.y then
  99. self.args.littleTipsTextTable.x = defaultPos.x
  100. self.args.littleTipsTextTable.y = defaultPos.y
  101. end
  102. local textControl = GUI:Text_Create(self.view.bg, {
  103. id = "tipsText",
  104. text = self.args.littleTipsTextTable.text,
  105. x = self.args.littleTipsTextTable.x,
  106. y = self.args.littleTipsTextTable.y + 10
  107. --fontType = "MSYH"
  108. })
  109. end
  110. ---标题
  111. if self.args.title then
  112. GUI:Text_setString(self.view.txt_title, self.args.title)
  113. GUI:setVisible(self.view.img_title, false)
  114. GUI:setVisible(self.view.txt_title, true)
  115. if self.args.titlePos then
  116. GUI:setPosition(self.view.txt_title, self.args.titlePos.x, self.args.titlePos.y)
  117. end
  118. end
  119. ---按钮
  120. if self.args.isShowSureBtn == nil then
  121. self.args.isShowSureBtn = true
  122. end
  123. if self.args.isShowCancelBtn == nil then
  124. self.args.isShowCancelBtn = true
  125. end
  126. if self.args.isShowCloseBtn == nil then
  127. self.args.isShowCloseBtn = true
  128. end
  129. if not self.args.isShowSureBtn then
  130. GUI:setVisible(self.view.btn_sure, false)
  131. end
  132. if not self.args.isShowCancelBtn then
  133. GUI:setVisible(self.view.btn_cancel, false)
  134. if self.args.isShowSureBtn then
  135. GUI:setPosition(self.view.btn_sure, 0, GUI:getPositionY(self.view.btn_sure))
  136. end
  137. end
  138. if not self.args.isShowCloseBtn then
  139. GUI:setVisible(self.view.closeBtn, false)
  140. end
  141. if self.args.sureBtnText then
  142. GUI:Text_setString(self.view.btn_sure, self.args.sureBtnText)
  143. end
  144. if self.args.cancelBtnText then
  145. GUI:Text_setString(self.view.btn_cancel, self.args.cancelBtnText)
  146. end
  147. if self.args.sureBtnImageData then
  148. GUI:Image_loadTexture(self.view.btn_sure, self.args.sureBtnImageData.src, self.args.sureBtnImageData.atlas)
  149. end
  150. if self.args.cancelBtnImageData then
  151. GUI:Image_loadTexture(self.view.btn_cancel, self.args.cancelBtnImageData.src, self.args.cancelBtnImageData.atlas)
  152. end
  153. if self.args.cancelBtnColor then
  154. GUI:Button_setTitleColor(self.view.btn_cancel, self.args.cancelBtnColor)
  155. end
  156. ---输入框
  157. if self.args.showInput then
  158. GUI:setVisible(self.view.input, true)
  159. if self.args.inputPos then
  160. GUI:setPosition(self.view.input, self.args.inputPos.x, self.args.inputPos.y)
  161. end
  162. end
  163. ---复选框
  164. if self.args.showToggle then
  165. GUI:setVisible(self.view.toggle, true)
  166. if self.args.togglePos then
  167. GUI:setPosition(self.view.toggle, self.args.togglePos.x, self.args.togglePos.y)
  168. end
  169. end
  170. ---滑动条
  171. if self.args.showSlider then
  172. GUI:setVisible(self.view.slider, true)
  173. if self.args.sliderPos then
  174. GUI:setPosition(self.view.slider, self.args.sliderPos.x, self.args.sliderPos.y)
  175. end
  176. else
  177. GUI:setVisible(self.view.slider, false)
  178. end
  179. ---延迟关闭
  180. if self.args.closeTime and type(self.args.closeTime) == "number" then
  181. SL:ScheduleOnce(self.args.closeTime, function()
  182. self:CloseSelf()
  183. end)
  184. end
  185. end
  186. GUI:setPositionZ(self.view.root,-5000)
  187. end
  188. ---注册UI事件和服务器消息
  189. function this:RegistEvents()
  190. GUI:AddOnClickEvent(self.view.btn_sure, self, self.OnClickSureButton)
  191. GUI:AddOnClickEvent(self.view.btn_cancel, self, self.OnClickCancel)
  192. GUI:AddOnClickEvent(self.view.closeBtn, self, self.CloseSelf)
  193. end
  194. function this:OnClickCancel()
  195. if self.args.cancelCallBack then
  196. self.args.cancelCallBack(self.args.ui, self.returnData)
  197. end
  198. GUI:UIPanel_Close('dev/ui/Common/Panel/KLUICommonTips/KLUICommonTipsPanel')
  199. end
  200. function this:CloseSelf()
  201. if self.args.closeCallBack then
  202. self.args.closeCallBack(self.args.ui, self.returnData)
  203. end
  204. GUI:UIPanel_Close('dev/ui/Common/Panel/KLUICommonTips/KLUICommonTipsPanel')
  205. end
  206. function this:OnClickSureButton()
  207. if self.args.showInput then
  208. self.returnData["inputText"] = GUI:Text_getString(self.view.input)
  209. end
  210. if self.args.showToggle then
  211. self.returnData["toggleIsOn"] = GUI:Toggle_getIsOn(self.view.toggle)
  212. end
  213. if self.args.showSlider then
  214. self.returnData["toggleIsOn"] = GUI:Toggle_getIsOn(self.view.slider)
  215. end
  216. self.returnData["callbackData"] = self.args.callbackData
  217. self.returnData["ui"] = self.args.ui
  218. if self.args and self.args.callback then
  219. self.args.callback(self.returnData)
  220. end
  221. self:CloseSelf()
  222. end
  223. function this:Close()
  224. end
  225. return this