KLPopoverPanel.lua 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  1. ---@class KLPopoverPanel:UIKmlLuaPanelBase
  2. ---@field view KLPopoverPanelView
  3. local KLPopoverPanel = class(UIKmlLuaPanelBase)
  4. local this = KLPopoverPanel
  5. ---创建时调用一次
  6. function this:Init()
  7. self.shownum = 5 ---默认显示前3个预告提示
  8. self.popoverTimetbl = {}
  9. GUI:DataListInitData(self.view.leftdatalist, function()
  10. return self:DataListItemCountFunc()
  11. end, function(realIndex)
  12. return self:DataListItemGetFunc(realIndex)
  13. end, function(realIndex, kmlcontrol)
  14. return self:DataListItemInitFunc(realIndex, kmlcontrol)
  15. end, function(realIndex, kmlcontrol)
  16. return self:DataListItemUpdateFunc(realIndex, kmlcontrol)
  17. end)
  18. self.PopoverHandleFun = {
  19. [PopoverType.Tip_MonthCardQJQuota] = self.Tip_MonthCardQJQuota
  20. }
  21. self.updateTime = SL:Schedule(self.updateTime,0,Time.deltaTime,-1,function()
  22. end)
  23. --摆动气泡
  24. self:DotweenPopover()
  25. end
  26. function this.Tip_MonthCardQJQuota()
  27. SL:CommonTipsMessage({
  28. stringTblID = 461,
  29. })
  30. end
  31. function this:DataListItemCountFunc()
  32. return #self.popoverTimetbl
  33. end
  34. function this:DataListItemGetFunc(realIndex)
  35. end
  36. function this:DataListItemInitFunc(realIndex, kmlcontrol)
  37. --SL:Log('DataListItemInitFunc'..tostring(realIndex))
  38. end
  39. function this:DataListItemUpdateFunc(realIndex, kmlcontrol)
  40. --local iconitem = self.view.leftdatalist:GetChildControl(realIndex, 'iconitem')
  41. local iconitem = GUI:GetChildControl(self.view.leftdatalist, realIndex, 'iconitem')
  42. local idx = realIndex + 1
  43. local info = self.popoverTimetbl[idx]
  44. if info and idx <= self.shownum then
  45. local atlas = "Atlas/KLMainPanelIcon.spriteatlas"
  46. GUI:Image_loadTexture(iconitem, info.icon, atlas)
  47. GUI:AddOnClickEvent(iconitem, self, self.ClickPopoverType, info.id)
  48. GUI:setVisible(iconitem, true)
  49. else
  50. GUI:setVisible(iconitem, false)
  51. end
  52. end
  53. --气泡点击,跳转界面
  54. function this:ClickPopoverType(control, eventData)
  55. if eventData ~= PopoverType.Tip_MonthCard then
  56. --判断是否不是已读消失
  57. local isReadOut = self:GetReadOutPopoverById(eventData)
  58. if isReadOut then
  59. self:DelPopoverById(eventData)--删除气泡显示
  60. end
  61. end
  62. --logError("点击的气泡id = "..eventData)
  63. --暂时缺跳转各界面接口,都先打开加点界面
  64. if (eventData == PopoverType.Tip_attribute) then
  65. SL:OpenKLAttrPanel()
  66. end
  67. if eventData == PopoverType.Tip_efficiency then
  68. end
  69. if eventData == PopoverType.Tip_auction then
  70. end
  71. if eventData == PopoverType.Tip_mail then
  72. GUI:UIPanel_Open("dev/ui/Mail/Panel/KLMail/KLMailPanel")
  73. end
  74. if eventData == PopoverType.Tip_testimonial then
  75. end
  76. if eventData == PopoverType.Tip_brave_trials then
  77. end
  78. if eventData == PopoverType.Tip_partner_incubation then
  79. end
  80. if eventData == PopoverType.Tip_partner_dispatch then
  81. end
  82. if eventData == PopoverType.Tip_task_dispatch then
  83. end
  84. if (eventData == PopoverType.Tip_fashion) then
  85. end
  86. if (eventData == PopoverType.Tip_inventory) then
  87. end
  88. if (eventData == PopoverType.Tip_assist) then
  89. end
  90. if (eventData == PopoverType.Tip_equipment_replacement) then
  91. end
  92. if (eventData == PopoverType.Tip_StrengthMaster) then
  93. end
  94. if (eventData == PopoverType.Tip_AddMaster) then
  95. end
  96. if (eventData == PopoverType.Tip_RefinedMaster) then
  97. end
  98. if (eventData == PopoverType.Tip_StarMaster) then
  99. end
  100. --新增体验翅膀提示
  101. if eventData == PopoverType.Tip_Experiencewings then
  102. end
  103. if (eventData == PopoverType.Tip_AiHook) then
  104. end
  105. if eventData == PopoverType.Tip_team then
  106. GUI:UIPanel_Open("dev/ui/Team/Panel/KLUITeamMain/KLUITeamMainPanel", _, _, { panelType = 4 })
  107. end
  108. if (eventData == PopoverType.Tip_union_trade) then
  109. --[[ local message = {stringTblID=230,
  110. showTips = "战盟拍卖已开启,是否前往竞拍?",
  111. title = "提示",
  112. callback = function()
  113. GUI:UIPanel_Open("dev/outui/Trade/Panel/KLTradeMain/KLTradeMainPanel",nil,nil,"toggle_trade_union")
  114. end
  115. }]]
  116. SL:CommonTipsMessage({ stringTblID = 230,
  117. showTips = "战盟拍卖已开启,是否前往竞拍?",
  118. title = "提示",
  119. callback = function()
  120. GUI:UIPanel_Open("dev/outui/Trade/Panel/KLTradeMain/KLTradeMainPanel", nil, nil, "toggle_trade_union")
  121. end
  122. })
  123. end
  124. if (eventData == PopoverType.Tip_friends) then
  125. GUI:UIPanel_Open("dev/ui/FriendSys/Panel/KLFriendMain/KLFriendMainPanel",nil,nil,{type=EFriendRelation.Friend})
  126. SL.HideMainPanel()
  127. end
  128. if eventData == PopoverType.Tip_MonthCard then
  129. local desc = "您的月卡剩余时间小于24小时,交易行交易税将\n提升至20%,是否购买增加月卡时间?"
  130. GUI:UIPanel_Open("dev/ui/Common/Panel/KLUICommonTips/KLUICommonTipsPanel", nil, nil,
  131. { showTips = desc,
  132. callback = function()
  133. GUI:UIPanel_Open("dev/outui/MonthCard/Panel/KLUIMonthCardMain/KLUIMonthCardMainPanel")
  134. end,
  135. callbackData = nil,
  136. ui = self })
  137. end
  138. if eventData == PopoverType.Tip_GoldPrivilege then
  139. local stringId, stringFormat
  140. local time = PrivilegeCardManager.GetPrivilegeRemainTime(1)
  141. if time > 0 then
  142. stringId = 444
  143. local timeStr = SL:TimeFormatToStr(math.floor(time / 1000))
  144. stringFormat = { tostring(timeStr) }
  145. else
  146. stringId = 446
  147. stringFormat = nil
  148. end
  149. SL:CommonTipsMessage({
  150. stringTblID = stringId,
  151. stringTblFormat = stringFormat,
  152. sureBtnText = "兑换特权",
  153. callback = function()
  154. if InfoManager.monthCardInfo:IsHaveMonthCardRights("privilege") then
  155. GUI:UIPanel_Open("dev/outui/MonthCard/Panel/KLUIMonthCardMain/KLUIMonthCardMainPanel", nil, nil, { type = "privilege" })
  156. else
  157. GUI:UIPanel_Open("dev/outui/MonthCard/Panel/KLUIMonthCardMain/KLUIMonthCardMainPanel")
  158. end
  159. end,
  160. cancelCallBack = function()
  161. PrivilegeCardManager.SetHideGoldPopover(true)
  162. end })
  163. end
  164. if eventData == PopoverType.Tip_DiamondPrivilege then
  165. local stringId, stringFormat
  166. local time = PrivilegeCardManager.GetPrivilegeRemainTime(2) / 1000
  167. if time > 0 then
  168. stringId = 445
  169. local timeStr = SL:TimeFormatToStr(math.floor(time / 1000))
  170. stringFormat = { tostring(timeStr) }
  171. else
  172. stringId = 447
  173. stringFormat = nil
  174. end
  175. SL:CommonTipsMessage({
  176. stringTblID = stringId,
  177. stringTblFormat = stringFormat,
  178. sureBtnText = "兑换特权",
  179. callback = function()
  180. if InfoManager.monthCardInfo:IsHaveMonthCardRights("privilege") then
  181. GUI:UIPanel_Open("dev/outui/MonthCard/Panel/KLUIMonthCardMain/KLUIMonthCardMainPanel", nil, nil, { type = "privilege" })
  182. else
  183. GUI:UIPanel_Open("dev/outui/MonthCard/Panel/KLUIMonthCardMain/KLUIMonthCardMainPanel")
  184. end
  185. end,
  186. cancelCallBack = function()
  187. PrivilegeCardManager.SetHideDiamondPopover(true)
  188. end })
  189. end
  190. local handleFun = self.PopoverHandleFun[eventData]
  191. if handleFun then
  192. handleFun()
  193. end
  194. end
  195. ---创建或者刷新界面数据时调用
  196. function this:Refresh()
  197. GUI:setVisible(self.view.Bg, true)
  198. --刷新显示气泡
  199. self:RefreshUI()
  200. local tbl = SL:GetConfig("cfg_popover", PopoverType.Tip_MonthCard)
  201. local tbl_gold = SL:GetConfig("cfg_popover", PopoverType.Tip_GoldPrivilege)
  202. local tbl_diamond = SL:GetConfig("cfg_popover", PopoverType.Tip_DiamondPrivilege)
  203. self.MonthTime = SL:Schedule(self.MonthTime, 0, 1, -1, function()
  204. if InfoManager.monthCardInfo:IsHaveDayTime() and not self:isInArray(self.popoverTimetbl, tbl.id) then
  205. ---小于1天 大于0时才显示
  206. self:SetPopoverData(PopoverType.Tip_MonthCard)
  207. self:RefreshUI()
  208. else
  209. if not InfoManager.monthCardInfo:IsHaveDayTime() then
  210. self:DelPopoverById(PopoverType.Tip_MonthCard)
  211. end
  212. end
  213. if PrivilegeCardManager.GetDiamondPrivilegePopoverState() then
  214. if not self:isInArray(self.popoverTimetbl, tbl_diamond.id) then
  215. self:SetPopoverData(PopoverType.Tip_DiamondPrivilege)
  216. self:RefreshUI()
  217. end
  218. else
  219. self:DelPopoverById(PopoverType.Tip_DiamondPrivilege)
  220. end
  221. if PrivilegeCardManager.GetGoldPrivilegePopoverState() then
  222. if not self:isInArray(self.popoverTimetbl, tbl_gold.id) then
  223. self:SetPopoverData(PopoverType.Tip_GoldPrivilege)
  224. self:RefreshUI()
  225. end
  226. else
  227. self:DelPopoverById(PopoverType.Tip_GoldPrivilege)
  228. end
  229. end)
  230. end
  231. --刷新面板icon
  232. function this:RefreshUI()
  233. GUI:DataListUpdateData(self.view.leftdatalist)
  234. end
  235. --获取是否已读消失
  236. function this:GetReadOutPopoverById(memberId)
  237. if self.popoverTimetbl == nil then
  238. self.popoverTimetbl = {}
  239. end
  240. for index, popoverInfo in pairs(self.popoverTimetbl) do
  241. if popoverInfo.id == memberId then
  242. if popoverInfo.ReadDisappear then
  243. return popoverInfo.ReadDisappear
  244. end
  245. end
  246. end
  247. end
  248. -- 气泡重复,替换新气泡数据
  249. function this:DelAddPopoverMemberById(tbl, memberId)
  250. if self.popoverTimetbl == nil then
  251. self.popoverTimetbl = {}
  252. end
  253. for index, popoverInfo in pairs(self.popoverTimetbl) do
  254. if popoverInfo.id == memberId then
  255. table.remove(self.popoverTimetbl, index)
  256. local popoverData = self:GetPopovertbl(tbl)
  257. table.insert(self.popoverTimetbl, index, popoverData)
  258. end
  259. end
  260. end
  261. --是否已存在
  262. function this:isInArray(t, val)
  263. for index, v in ipairs(t) do
  264. if v.id then
  265. if v.id == val then
  266. return true, index
  267. end
  268. end
  269. end
  270. return false
  271. end
  272. --获取气泡数据
  273. function this:GetPopovertbl(tbl)
  274. local Popovertbl = {}
  275. local Disappear = false --限时消失目前已取消
  276. local ReadDisappear = true --已读消失
  277. if tbl.disappeartype and tonumber(tbl.disappeartype) == 1 then
  278. --已读不消失
  279. ReadDisappear = false
  280. end
  281. Popovertbl.id = tbl.id
  282. Popovertbl.name = tbl.name
  283. Popovertbl.icon = tbl.icon
  284. Popovertbl.Disappear = Disappear
  285. Popovertbl.ReadDisappear = ReadDisappear
  286. return Popovertbl
  287. end
  288. --添加气泡
  289. function this:SetPopoverData(typeid)
  290. ---@type cfg_popover_column
  291. local tbl = SL:GetConfig("cfg_popover", typeid)
  292. if tbl.switch and tbl.switch == 1 then
  293. --switch=1 不显示
  294. else
  295. if self.popoverTimetbl == nil then
  296. self.popoverTimetbl = {}
  297. end
  298. if #self.popoverTimetbl > 0 then
  299. local isexist, index = self:isInArray(self.popoverTimetbl, tbl.id)
  300. if isexist then
  301. self:DelAddPopoverMemberById(tbl, tbl.id)
  302. else
  303. local popoverData = self:GetPopovertbl(tbl)
  304. table.insert(self.popoverTimetbl, 1, popoverData)
  305. end
  306. else
  307. local popoverData = self:GetPopovertbl(tbl)
  308. table.insert(self.popoverTimetbl, 1, popoverData)
  309. end
  310. end
  311. end
  312. -- 删除气泡
  313. function this:DelPopoverById(memberId)
  314. if self.popoverTimetbl == nil then
  315. self.popoverTimetbl = {}
  316. end
  317. for index, popoverInfo in pairs(self.popoverTimetbl) do
  318. if popoverInfo.id == memberId then
  319. table.remove(self.popoverTimetbl, index)
  320. self:RefreshUI()
  321. end
  322. end
  323. end
  324. --气泡左右摆动
  325. function this:DotweenPopover()
  326. --气泡闪烁动画
  327. self.anim = GUI:DOAlphaCanvasGroup(self.view.Bg, 0, 1)
  328. GUI:TweenSetLoops(self.anim,-1)
  329. GUI:TweenSetEase(self.anim,ELeanTweenType.pingPong)
  330. end
  331. ---注册UI事件和服务器消息
  332. function this:RegistEvents()
  333. SL:RegisterLUAEvent(Event.SetPopoverData, self.OutSetPopoverData, self)
  334. SL:RegisterLUAEvent(Event.ClosePopover, self.ClosePopover, self)
  335. SL:RegisterLUAEvent(LUA_EVENT_BUBBLETIPS_POSY, self.OutSetPosY, self)
  336. SL:RegisterLUAEvent(LUA_EVENT_BUBBLETIPS_ADD, self.OutSetPopoverData, self)
  337. SL:RegisterLUAEvent(LUA_EVENT_BUBBLETIPS_DEL, self.ClosePopover, self)
  338. --SL:RegisterLUAEvent(LUA_EVENT_FIGHTBEGINF,self.LUA_EVENT_FIGHTBEGINF,self)
  339. --SL:RegisterLUAEvent(LUA_EVENT_FIGHTEND,self.LUA_EVENT_FIGHTEND,self)
  340. SL:RegisterLUAEvent(LUA_EVENT_RECEIVE_EMAIL, self.LUA_EVENT_RECEIVE_EMAIL, self)
  341. -------------------------------------------------------------
  342. --属性点分配,
  343. SL:RegisterLUAEvent(LUA_EVENT_ROLE_PROPERTY_CHANGE, self.LUA_EVENT_ROLE_PROPERTY_CHANGE, self)
  344. ---刷新属性点变化
  345. SL:RegisterLUAEvent(LUA_EVENT_OPEN_UI, self.CloseMail, self)
  346. end
  347. function this:LUA_EVENT_RECEIVE_EMAIL()
  348. self:SetPopoverData(PopoverType.Tip_mail)
  349. self:RefreshUI()
  350. end
  351. function this:CloseMail(_, message)
  352. if message.panelName == "KLMailPanel" then
  353. self:DelPopoverById(PopoverType.Tip_mail)
  354. end
  355. end
  356. function this:LUA_EVENT_ROLE_PROPERTY_CHANGE(id, data)
  357. local isshow = SL:CheckIsShowAttributeBoxTip()
  358. if isshow then
  359. ---显示快捷提示
  360. self:SetPopoverData(PopoverType.Tip_attribute)
  361. self:RefreshUI()
  362. else
  363. self:DelPopoverById(PopoverType.Tip_attribute)
  364. end
  365. end
  366. function this:Update()
  367. end
  368. -----设置气泡状态(屏蔽/显示)
  369. --function this:LUA_EVENT_FIGHTBEGINF(id,data)
  370. -- GUI:setVisible(self.view.Bg,false)
  371. --end
  372. -----设置气泡状态(屏蔽/显示)
  373. --function this:LUA_EVENT_FIGHTEND(id,data)
  374. -- GUI:setVisible(self.view.Bg,true)
  375. --end
  376. ---
  377. ---外部设置气泡Y 坐标位置
  378. function this:OutSetPosY(id, data)
  379. local panel = GUI:GetUI("dev/ui/ShopMall/Panel/KLShopMall/KLShopMallPanel")
  380. local npcpanel = GUI:GetUI("dev/ui/NPC/Panel/KLNPCShop/KLNPCShopPanel")
  381. --local popy = self.view.root.rectTransform:GetLocalPositionY()
  382. local popx,popy,popz = GUI:getPosition(self.view.root)
  383. --local tbl = cfg_showHideUI_post.GetSystemInfoByPanelName("KLPopoverPanel")
  384. local tbl = SL:CfgShowHideUIPost_GetSystemInfoByPanelName("KLPopoverPanel")
  385. if tbl then
  386. local showPos = tbl.showPos
  387. local pos = string.split(showPos, "#")
  388. if popy < -500 then
  389. if panel or npcpanel then
  390. GUI:setLocalPosition(self.view.root,popx,tonumber(pos[2])+data.posY,popz)
  391. SL:MainUIManager_SetMovePopoverPos(data.posY > 0)
  392. end
  393. else
  394. GUI:setLocalPosition(self.view.root,popx,tonumber(pos[2])+data.posY,popz)
  395. SL:MainUIManager_SetMovePopoverPos(data.posY > 0)
  396. end
  397. end
  398. end
  399. ---外部设置气泡
  400. function this:OutSetPopoverData(id, data)
  401. self:SetPopoverData(data.id)
  402. self:RefreshUI()
  403. end
  404. ---关闭气泡
  405. function this:ClosePopover(id, type)
  406. self:DelPopoverById(type)
  407. end
  408. function this:Close()
  409. if self.moveX then
  410. self.moveX:Kill()
  411. self.moveX = nil
  412. end
  413. if self.MonthTime then
  414. SL:UnSchedule(self.MonthTime)
  415. self.MonthTime = nil
  416. end
  417. end
  418. return this