GUIUtil.lua 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. ---
  2. --- Generated by EmmyLua(https://github.com/EmmyLua)
  3. --- Created by PZM.
  4. --- DateTime: 2024/7/23 9:13
  5. ---外部自定义Lua的入口,编写同名文件GUIUtil.lua进行二进制覆盖。工程内的GUIUtil里面不要添加其他任何逻辑
  6. require "dev/CustomMsgDef"
  7. require "dev/OutEnum"
  8. require "dev/info/InfoManager"
  9. require "dev/manager/GlobalLuaEventManager"
  10. require "dev/manager/PrivilegeCardManager"
  11. require "dev/manager/MainUiStateManager"
  12. require "dev/Logic/Common/shortcutOutMgr"
  13. require "dev/Logic/Common/SL_Out"
  14. require "dev/Logic/Common/EquipFunc"
  15. require "dev/CfgPost/CfgPostRequire"
  16. require "dev/OutEvent"
  17. require "dev/manager/KLGuideManager"
  18. require "dev/Condition/ConditionManager"
  19. require "dev/Logic/BT/BTMgr"
  20. GUIUtil = {}
  21. local this = GUIUtil
  22. function this.Init()
  23. InfoManager:Init()
  24. GlobalLuaEventManager.Init()
  25. this.updtSch = SL:Schedule(this.updtSch, 0, 0.02, math.maxinteger, this.UpdateTest)
  26. PrivilegeCardManager.Init()
  27. KLGuideManager.Init()
  28. MainUiStateManager.Init()
  29. EquipFunc.Init()
  30. --SL:Schedule(0,0.02,math.maxinteger,this.UpdateTest)
  31. end
  32. function this.PreLoad()
  33. --GUI:SetUICacheTime("dev/ui/Equip/Panel/KLEquipUI/KLEquipUIPanel",-1)
  34. --GUI:SetUICacheTime("dev/ui/Bag/Panel/KLUIBag/KLUIBagPanel",-1)
  35. GUI:PreLoadUI("dev/ui/Equip/Panel/KLEquipUI/KLEquipUIPanel", 1)
  36. --GUI:PreLoadUI("dev/ui/Bag/Panel/KLUIBag/KLUIBagPanel",1)
  37. end
  38. function this.Reset()
  39. InfoManager:Reset()
  40. GlobalLuaEventManager.Reset()
  41. PrivilegeCardManager.Reset()
  42. EquipFunc.Reset()
  43. end
  44. function this.Update()
  45. PrivilegeCardManager.Update()
  46. end
  47. function this.UpdateTest()
  48. if Input.GetKeyDown(KeyCode.U) then
  49. logError("当前开服天数:" .. SL:GetOpenServerDay())
  50. end
  51. if Input.GetKeyDown(KeyCode.K) then
  52. --GUI:UIPanel_Open("dev/outui/Activity/Panel/KLRedFort/KLRedFortPanel")
  53. --GUI:UIPanel_Open("dev/outui/Activity/Panel/KLGoldChallenge/KLGoldChallengePanel")
  54. end
  55. end
  56. function this.GetColorText(msg, color)
  57. return string.format("<color=%s>%s</color>", color, msg)
  58. end
  59. --艺术字 时分
  60. function this.FormatTimeHMAndDW(time)
  61. time = math.modf(time)
  62. local hour = math.modf(time / 3600)
  63. local minute = math.modf(time % 3600 / 60)
  64. local fmtTime = string.format("%02sh%02sm", hour, minute)
  65. return fmtTime
  66. end
  67. --时分
  68. function this.FormatTimeHM(time)
  69. time = math.modf(time)
  70. local hour = math.modf(time / 3600)
  71. local minute = math.modf(time % 3600 / 60)
  72. local fmtTime = string.format("%02s小时%02s分钟", hour, minute)
  73. return fmtTime
  74. end
  75. --时分秒
  76. function this.FormatTimeHMS(time)
  77. time = math.modf(time)
  78. local hour = math.modf(time / 3600)
  79. local minute = math.modf(time % 3600 / 60)
  80. local second = time % 60
  81. local fmtTime = string.format("%02s:%02s:%02s", hour, minute, second)
  82. return fmtTime
  83. end
  84. --时分秒
  85. function this.FormatTimeHMSD(time)
  86. time = math.modf(time)
  87. local minute = time // 60 % 60
  88. local hour = time // 3600 % 24
  89. local second = time % 60
  90. local day = time // 86400
  91. if day >= 1 then
  92. return string.format("%s天:%02s时:%02s分", day, hour, minute)
  93. else
  94. return string.format("%02s:%02s:%02s", hour, minute, second)
  95. end
  96. end
  97. --时分秒
  98. function this.FormatTimeHMSD_S(time)
  99. time = math.modf(time)
  100. local minute = time // 60 % 60
  101. local hour = time // 3600 % 24
  102. local second = time % 60
  103. local day = time // 86400
  104. if day >= 1 then
  105. return string.format("%s天:%02s时:%02s分", day, hour, minute)
  106. else
  107. return string.format("%02s时:%02s分:%02s秒", hour, minute, second)
  108. end
  109. end
  110. --分秒
  111. function this.FormatTimeMS(time)
  112. time = math.modf(time)
  113. local minute = math.modf(time / 60)
  114. local second = time % 60
  115. local fmtTime = string.format("%02s:%02s", minute, second)
  116. return fmtTime
  117. end
  118. --秒(剩余秒数倒计时)
  119. function this.FormatTimeDHM(time)
  120. local m = time // 60 % 60
  121. local h = time // 3600 % 24
  122. local d = time // 86400
  123. if tonumber(d) < 10 then
  124. return string.format("%s天%02s小时%02s分钟", d, h, m);
  125. else
  126. return string.format("%02s天%02s小时%02s分钟", d, h, m);
  127. end
  128. end
  129. --秒(剩余秒数倒计时)
  130. function this.FormatTimeDHMN(time)
  131. local m = time // 60 % 60
  132. local h = time // 3600 % 24
  133. local d = time // 86400
  134. return string.format("%02s:%02s:%02s", d, h, m);
  135. end
  136. --秒(剩余秒数倒计时)
  137. function this.FormatTimeD(time)
  138. local d = math.modf(time // 86400)
  139. return string.format("%s天", d);
  140. end
  141. --将数字转为中文数字
  142. function this.ToNumberString(num)
  143. if num == 1 then
  144. return "一"
  145. elseif num == 2 then
  146. return "二"
  147. elseif num == 3 then
  148. return "三"
  149. elseif num == 4 then
  150. return "四"
  151. elseif num == 5 then
  152. return "五"
  153. elseif num == 6 then
  154. return "六"
  155. elseif num == 7 then
  156. return "七"
  157. elseif num == 8 then
  158. return "八"
  159. elseif num == 9 then
  160. return "九"
  161. elseif num == 10 then
  162. return "十"
  163. end
  164. return ""
  165. end
  166. function this.GetSampleNumberString(numArg)
  167. local num = tonumber(numArg)
  168. if not num then
  169. return numArg
  170. end
  171. if num < 10000 then
  172. --5位
  173. return num
  174. elseif num < 100000000 then
  175. --9位
  176. return math.floor(num / 1000 + 0.5) / 10 .. "万"
  177. elseif num < 1000000000000 then
  178. --13位
  179. return math.floor(num / 10000000 + 0.5) / 10 .. "亿"
  180. elseif num < 10000000000000000 then
  181. --17位
  182. return math.floor(num / 100000000000 + 0.5) / 10 .. "兆"
  183. else
  184. return math.floor(num / 100000000000 + 0.5) / 10 .. "兆"
  185. end
  186. return ""
  187. end
  188. --秒(剩余秒数倒计时)
  189. function this.FormatTimeDHM_S(time)
  190. local m = time // 60 % 60
  191. local h = time // 3600 % 24
  192. local d = time // 86400
  193. if tonumber(d) < 10 then
  194. return string.format("%s天%02s时%02s分", d, h, m);
  195. else
  196. return string.format("%02s天%02s时%02s分", d, h, m);
  197. end
  198. end
  199. ---格式化数据
  200. function this.FormatNumber(count, integer_bit_notZero, isReplace_chinese_character)
  201. if not integer_bit_notZero then
  202. local str = count
  203. count = tonumber(count)
  204. if count >= 100000 and count < 10000000 then
  205. local num = string.format("%0.1f", count / 10000)
  206. str = num .. (isReplace_chinese_character and "w" or "万")
  207. elseif count > 10000000 then
  208. local num = string.format("%0.1f", count / 100000000)
  209. str = num .. (isReplace_chinese_character and "y" or "亿")
  210. end
  211. return str
  212. else
  213. local str = count
  214. if count >= 10000 and count < 100000000 then
  215. local num = string.format("%0.1f", count / 10000)
  216. if tonumber(num) == math.floor(num) then
  217. num = math.floor(num)
  218. end
  219. str = num .. (isReplace_chinese_character and "w" or "万")
  220. elseif count >= 100000000 then
  221. local num = tonumber(string.format("%0.1f", count / 100000000))
  222. if num < 10000 then
  223. str = (isReplace_chinese_character and "y" or "亿")
  224. elseif num >= 10000 and num < 100000000 then
  225. num = string.format("%0.1f", num / 10000)
  226. str = (isReplace_chinese_character and "z" or "兆")
  227. elseif num >= 100000000 then
  228. num = string.format("%0.1f", num / 100000000)
  229. str = (isReplace_chinese_character and "j" or "京")
  230. end
  231. if tonumber(num) == math.floor(num) then
  232. num = math.floor(num)
  233. end
  234. str = num .. str
  235. end
  236. return str
  237. end
  238. end
  239. --代币id
  240. local coinId
  241. --获得代币id
  242. local function GetCoinId()
  243. if coinId then
  244. return coinId
  245. end
  246. ---默认代币id
  247. coinId = 30510308
  248. local tbl = SL:GetConfigTable("cfg_item")
  249. for _, v in pairs(tbl) do
  250. if v.type == 3 and v.subType == 51 then
  251. coinId = v.id
  252. return coinId
  253. end
  254. end
  255. return coinId
  256. end
  257. ---@充值通用接口(需要使用代币调用这个)
  258. ---@param rechargeTbl cfg_recharge_column @充值表
  259. ---@param count number @充值数量
  260. ---@param extraParams table @透传参数(可选参数
  261. function this.SDKPay(rechargeTbl, count, extraParams)
  262. if not rechargeTbl then
  263. logError("Not found rechargeTbl")
  264. return
  265. end
  266. local haveCount = SL:GetBagItemCount(GetCoinId())
  267. local needCount = rechargeTbl.amount
  268. if haveCount >= needCount then
  269. ---有代币
  270. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_RECHARGE, { rechargeId = rechargeTbl.id, count = count, extraParams = extraParams })
  271. return
  272. end
  273. SL:SDKPay(rechargeTbl, count, extraParams)
  274. end