RedDotProxy.lua 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. local RemoteProxy = requireProxy("remote/RemoteProxy")
  2. local RedDotProxy = class("RedDotProxy", RemoteProxy)
  3. RedDotProxy.NAME = global.ProxyTable.RedDotProxy
  4. local cjson = require("cjson")
  5. function RedDotProxy:ctor()
  6. RedDotProxy.super.ctor(self)
  7. self:Init()
  8. self._bagReds = {}
  9. end
  10. function RedDotProxy:onRegister()
  11. RedDotProxy.super.onRegister(self)
  12. end
  13. function RedDotProxy:Init()
  14. self.m_data = {}
  15. Schedule(function()
  16. if #self.m_data>0 then
  17. local data = table.remove(self.m_data,1)
  18. global.Facade:sendNotification(global.NoticeTable.Layer_RedDot_refData,data)
  19. end
  20. end,0)
  21. end
  22. function RedDotProxy:GetBagRedDot()
  23. return self._bagReds
  24. end
  25. function RedDotProxy:SetBagRedDotByData(data)
  26. if not data or not next(data) then
  27. return
  28. end
  29. if data.mainId and data.mainId == 1 and data.uiId then --
  30. if data.add and data.add == 1 then
  31. self._bagReds[data.uiId] = data
  32. elseif data.add and data.add == 0 then
  33. self._bagReds[data.uiId] = nil
  34. end
  35. end
  36. end
  37. function RedDotProxy:DeleteBagRedDot(makeIndex)
  38. if not makeIndex then
  39. return
  40. end
  41. self._bagReds[makeIndex] = nil
  42. end
  43. function RedDotProxy:handle_MSG_SC_REDDOT_TIPS(msg)
  44. local msgLen = msg:GetDataLength()
  45. local msgHdr = msg:GetHeader()
  46. local str = ""
  47. -- dump(str,"handle_MSG_SC_REDDOT_TIPS___")
  48. -- dump(msgHdr,"msgHdr_____")
  49. if msgLen ~= 0 then
  50. str = msg:GetData():ReadString(msgLen)
  51. end
  52. local data
  53. local strs = string.split(str,",")
  54. local mainId = tonumber(strs[1])
  55. local uiId = strs[2]
  56. if msgHdr.recog == 0 then--增加
  57. local x = tonumber(strs[3])
  58. local y = tonumber(strs[4])
  59. local mode = tonumber(strs[5])
  60. local res = strs[6]
  61. data = {add = 1, mainId = mainId, uiId = uiId, x = x, y = y, mode = mode, res = res}
  62. if mainId and mainId == 1 and uiId then --
  63. self._bagReds[uiId] = data
  64. end
  65. else--删除
  66. data = {add = 0, mainId = mainId, uiId = uiId}
  67. self._bagReds[uiId] = nil
  68. end
  69. table.insert(self.m_data,data)
  70. end
  71. function RedDotProxy:RegisterMsgHandler()
  72. local msgType = global.MsgType
  73. -- 收到消息
  74. LuaRegisterMsgHandler(msgType.MSG_SC_REDDOT_TIPS, handler(self, self.handle_MSG_SC_REDDOT_TIPS))
  75. end
  76. return RedDotProxy