RedPointProxy.lua 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360
  1. local RemoteProxy = requireProxy("remote/RemoteProxy")
  2. local RedPointProxy = class("RedPointProxy", RemoteProxy)
  3. RedPointProxy.NAME = global.ProxyTable.RedPointProxy
  4. local SUIHelper = require("sui/SUIHelper")
  5. local sgsub = string.gsub
  6. local sformat = string.format
  7. local ssplit = string.split
  8. local sfind = string.find
  9. local smatch = string.match
  10. local cjson = require("cjson")
  11. local values = {
  12. LEVEL = function(isHero)--当前等级
  13. local PropertyProxy
  14. if isHero then
  15. PropertyProxy = global.Facade:retrieveProxy(global.ProxyTable.HeroPropertyProxy)
  16. else
  17. PropertyProxy = global.Facade:retrieveProxy(global.ProxyTable.PlayerProperty)
  18. end
  19. local LEVEL = PropertyProxy:GetRoleLevel()
  20. return LEVEL
  21. end,
  22. HP = function(isHero)--当前hp
  23. local PropertyProxy
  24. if isHero then
  25. PropertyProxy = global.Facade:retrieveProxy(global.ProxyTable.HeroPropertyProxy)
  26. else
  27. PropertyProxy = global.Facade:retrieveProxy(global.ProxyTable.PlayerProperty)
  28. end
  29. local HP = PropertyProxy:GetRoleCurrHP()
  30. return HP
  31. end,
  32. MP = function(isHero)--当前mp
  33. local PropertyProxy
  34. if isHero then
  35. PropertyProxy = global.Facade:retrieveProxy(global.ProxyTable.HeroPropertyProxy)
  36. else
  37. PropertyProxy = global.Facade:retrieveProxy(global.ProxyTable.PlayerProperty)
  38. end
  39. local MP = PropertyProxy:GetRoleCurrMP()
  40. return MP
  41. end,
  42. MAXAC = function(isHero)--最高物防
  43. local PropertyProxy
  44. if isHero then
  45. PropertyProxy = global.Facade:retrieveProxy(global.ProxyTable.HeroPropertyProxy)
  46. else
  47. PropertyProxy = global.Facade:retrieveProxy(global.ProxyTable.PlayerProperty)
  48. end
  49. local MAXAC = PropertyProxy:GetRoleAttByAttType(GUIFunction:PShowAttType().Max_DEF)
  50. return MAXAC
  51. end,
  52. MAXMAC = function(isHero)--最高魔防
  53. local PropertyProxy
  54. if isHero then
  55. PropertyProxy = global.Facade:retrieveProxy(global.ProxyTable.HeroPropertyProxy)
  56. else
  57. PropertyProxy = global.Facade:retrieveProxy(global.ProxyTable.PlayerProperty)
  58. end
  59. local MAXMAC = PropertyProxy:GetRoleAttByAttType(GUIFunction:PShowAttType().Max_MDF)
  60. return MAXMAC
  61. end,
  62. MAXDC = function(isHero)--最高物攻
  63. local PropertyProxy
  64. if isHero then
  65. PropertyProxy = global.Facade:retrieveProxy(global.ProxyTable.HeroPropertyProxy)
  66. else
  67. PropertyProxy = global.Facade:retrieveProxy(global.ProxyTable.PlayerProperty)
  68. end
  69. local MAXDC = PropertyProxy:GetRoleAttByAttType(GUIFunction:PShowAttType().Max_ATK)
  70. return MAXDC
  71. end,
  72. MAXMC = function(isHero)--最高魔攻
  73. local PropertyProxy
  74. if isHero then
  75. PropertyProxy = global.Facade:retrieveProxy(global.ProxyTable.HeroPropertyProxy)
  76. else
  77. PropertyProxy = global.Facade:retrieveProxy(global.ProxyTable.PlayerProperty)
  78. end
  79. local MAXMC = PropertyProxy:GetRoleAttByAttType(GUIFunction:PShowAttType().Max_MAT)
  80. return MAXMC
  81. end,
  82. MAXSC = function(isHero)--最高道术
  83. local PropertyProxy
  84. if isHero then
  85. PropertyProxy = global.Facade:retrieveProxy(global.ProxyTable.HeroPropertyProxy)
  86. else
  87. PropertyProxy = global.Facade:retrieveProxy(global.ProxyTable.PlayerProperty)
  88. end
  89. local MAXMC = PropertyProxy:GetRoleAttByAttType(GUIFunction:PShowAttType().Max_Daoshu)
  90. return MAXMC
  91. end,
  92. MAXHP = function(isHero)--最大hp
  93. local PropertyProxy
  94. if isHero then
  95. PropertyProxy = global.Facade:retrieveProxy(global.ProxyTable.HeroPropertyProxy)
  96. else
  97. PropertyProxy = global.Facade:retrieveProxy(global.ProxyTable.PlayerProperty)
  98. end
  99. local MAXHP = PropertyProxy:GetRoleMaxHP()
  100. return MAXHP
  101. end,
  102. MAXMP = function(isHero)--最大mp
  103. local PropertyProxy
  104. if isHero then
  105. PropertyProxy = global.Facade:retrieveProxy(global.ProxyTable.HeroPropertyProxy)
  106. else
  107. PropertyProxy = global.Facade:retrieveProxy(global.ProxyTable.PlayerProperty)
  108. end
  109. local MAXMP = PropertyProxy:GetRoleMaxMP()
  110. return MAXMP
  111. end,
  112. EXP = function(isHero)--经验
  113. local PropertyProxy
  114. if isHero then
  115. PropertyProxy = global.Facade:retrieveProxy(global.ProxyTable.HeroPropertyProxy)
  116. else
  117. PropertyProxy = global.Facade:retrieveProxy(global.ProxyTable.PlayerProperty)
  118. end
  119. local EXP = PropertyProxy:GetCurrExp()
  120. return EXP
  121. end,
  122. RELEVEL = function(isHero)--转生
  123. local PropertyProxy
  124. if isHero then
  125. PropertyProxy = global.Facade:retrieveProxy(global.ProxyTable.HeroPropertyProxy)
  126. else
  127. PropertyProxy = global.Facade:retrieveProxy(global.ProxyTable.PlayerProperty)
  128. end
  129. local RELEVEL = PropertyProxy:GetRoleReinLv()
  130. return RELEVEL
  131. end,
  132. STARCOUNTALL = function(isHero)--获取全身所有装备星星数量总和
  133. local EquipProxy = global.Facade:retrieveProxy(global.ProxyTable.Equip)
  134. local equipData = EquipProxy:GetEquipData()
  135. local sum = 0
  136. for _, equip in pairs(equipData) do
  137. if equip.Star then
  138. sum = sum + equip.Star
  139. end
  140. end
  141. return sum
  142. end,
  143. JOB = function(isHero)--人物职业
  144. local PropertyProxy
  145. if isHero then
  146. PropertyProxy = global.Facade:retrieveProxy(global.ProxyTable.HeroPropertyProxy)
  147. else
  148. PropertyProxy = global.Facade:retrieveProxy(global.ProxyTable.PlayerProperty)
  149. end
  150. local JOB = PropertyProxy:GetRoleJob()
  151. return JOB
  152. end,
  153. GENDER = function(isHero)--人物性别
  154. local PropertyProxy
  155. if isHero then
  156. PropertyProxy = global.Facade:retrieveProxy(global.ProxyTable.HeroPropertyProxy)
  157. else
  158. PropertyProxy = global.Facade:retrieveProxy(global.ProxyTable.PlayerProperty)
  159. end
  160. local SEX = PropertyProxy:GetRoleSex()
  161. return SEX
  162. end,
  163. USEITEMNAME = function(isHero, pos)--装备名字
  164. if not pos then
  165. return ""
  166. end
  167. local EquipProxy
  168. if isHero then
  169. EquipProxy = global.Facade:retrieveProxy(global.ProxyTable.HeroEquipProxy)
  170. else
  171. EquipProxy = global.Facade:retrieveProxy(global.ProxyTable.Equip)
  172. end
  173. pos = tonumber(pos)
  174. local equipData = EquipProxy:GetEquipDataByPos(pos)
  175. if not equipData then
  176. return ""
  177. end
  178. return equipData.Name
  179. end,
  180. USEITEMID = function(isHero, pos)--装备index
  181. if not pos then
  182. return 0
  183. end
  184. local EquipProxy
  185. if isHero then
  186. EquipProxy = global.Facade:retrieveProxy(global.ProxyTable.HeroEquipProxy)
  187. else
  188. EquipProxy = global.Facade:retrieveProxy(global.ProxyTable.Equip)
  189. end
  190. pos = tonumber(pos)
  191. local equipData = EquipProxy:GetEquipDataByPos(pos)
  192. if not equipData then
  193. return 0
  194. end
  195. return equipData.Index
  196. end,
  197. ITEMINDEX = function(isHero, currencyId, BindCurrency)--道具id
  198. local PayProxy = global.Facade:retrieveProxy(global.ProxyTable.PayProxy)
  199. local binds = ssplit(BindCurrency or "", "#")
  200. local bind = false
  201. for i, v in ipairs(binds) do
  202. if currencyId == (tonumber(v) or 0) then
  203. bind = true
  204. break
  205. end
  206. end
  207. local count = PayProxy:GetItemCount(currencyId, bind)
  208. return count
  209. end,
  210. MONEY = function(isHero, name)
  211. local PayProxy = global.Facade:retrieveProxy(global.ProxyTable.PayProxy)
  212. local MoneyProxy = global.Facade:retrieveProxy(global.ProxyTable.MoneyProxy)
  213. local currencyId = MoneyProxy:GetMoneyIdByName(name)
  214. local count = PayProxy:GetItemCount(currencyId)
  215. return count
  216. end,
  217. }
  218. local function getChildInSubNodes(nodeTable, key)
  219. if not key or key == "" then
  220. return nil
  221. end
  222. if #nodeTable == 0 then
  223. return nil
  224. end
  225. local child = nil
  226. local subNodeTable = {}
  227. for _, v in ipairs(nodeTable) do
  228. if tolua.isnull(v) then
  229. return nil
  230. end
  231. child = v:getChildByName(key)
  232. if (child) then
  233. return child
  234. end
  235. if GUI:getRedID(child) == key then
  236. return child
  237. end
  238. end
  239. for _, v in ipairs(nodeTable) do
  240. local subNodes = v:getChildren()
  241. if #subNodes ~= 0 then
  242. for _, v1 in ipairs(subNodes) do
  243. table.insert(subNodeTable, v1)
  244. end
  245. end
  246. end
  247. return getChildInSubNodes(subNodeTable, key)
  248. end
  249. local function getChildByKey(parent, key)
  250. return getChildInSubNodes({ parent }, key)
  251. end
  252. local getVarNames
  253. getVarNames = function(conditions, vec)
  254. if not conditions then
  255. return
  256. end
  257. if conditions.dType == 2 then
  258. for i, condition in ipairs(conditions.conditions) do
  259. if condition.dType == 2 then
  260. getVarNames(condition, vec)
  261. else
  262. local name = ""
  263. if condition.var.Hero then
  264. name = "H_" .. name
  265. end
  266. name = name .. condition.var.key
  267. if condition.var.value then
  268. name = name .. "_" .. condition.var.value
  269. end
  270. table.insert(vec, name)
  271. end
  272. end
  273. else
  274. local name = ""
  275. if conditions.var.Hero then
  276. name = "H_" .. name
  277. end
  278. name = name .. conditions.var.key
  279. if conditions.var.value then
  280. name = name .. "_" .. conditions.var.value
  281. end
  282. table.insert(vec, name)
  283. end
  284. end
  285. function RedPointProxy:ctor()
  286. RedPointProxy.super.ctor(self)
  287. self:Init()
  288. end
  289. function RedPointProxy:onRegister()
  290. RedPointProxy.super.onRegister(self)
  291. end
  292. -- 获取支持的常量
  293. function RedPointProxy:getValues()
  294. return values
  295. end
  296. function RedPointProxy:Init()
  297. self._configs = {}
  298. self._groups = {} -- 按组分config
  299. self._needCheckItems = {} -- 要检测的项目 {levelConditionVar = {config}}
  300. self._idsWithVarItems = {} -- id里面带有变量的项目
  301. self._GuideWidgetConfig = requireConfig("GuideWidgetConfig.lua")
  302. self._conditionsCache = {}
  303. self._idsCache = {}
  304. self._ServerVars = {} -- 服务器数据解析之后
  305. self._valList = {} -- 触发表
  306. self._TXTServerVars = {}
  307. self._needCheckIDs = {}
  308. self._needCheckIDsVec = {}
  309. self._scheduleId = nil
  310. self._showIDTable = { showIDs = {}, mainIDs = {}, npcLayerIDs = {} }
  311. self._ConstDict = {} -- 常量映射
  312. self:LoadConfig()
  313. self:InitItems()
  314. end
  315. function RedPointProxy:StartSchedule()
  316. if self._scheduleId then
  317. UnSchedule(self._scheduleId)
  318. self._scheduleId = nil
  319. end
  320. self._scheduleId = Schedule(function()
  321. for i = 1, 5 do
  322. if #self._needCheckIDsVec > 0 then
  323. local id = table.remove(self._needCheckIDsVec, 1)
  324. local config = self._configs[id]
  325. if self:CheckStrConditions(config.levelCondition)
  326. and self:CheckStrConditions(config.VarCondition, { BindCurrency = config.BindCurrency })
  327. and self:CheckStrConditions(config.currencyCondition, { BindCurrency = config.BindCurrency }) then --满足条件
  328. self:addShowIds(config.id)
  329. else
  330. self:rmvShowIds(config.id)
  331. end
  332. self._needCheckIDs[id] = false
  333. else
  334. break
  335. end
  336. end
  337. end, 1 / 60)
  338. end
  339. function RedPointProxy:InitItems()
  340. self._needCheckItems["_ALL_"] = {}
  341. for k, v in pairs(self._groups) do
  342. local firstItem = v[1]
  343. if firstItem.levelCondition then
  344. local lConditions = self:stringtoCondition(firstItem.levelCondition)
  345. local namevec = {}
  346. getVarNames(lConditions, namevec)
  347. for i, varname in ipairs(namevec) do
  348. self._needCheckItems[varname] = self._needCheckItems[varname] or {}
  349. table.insert(self._needCheckItems[varname], firstItem)
  350. end
  351. else
  352. for i, v2 in ipairs(v) do
  353. table.insert(self._needCheckItems["_ALL_"], v2)
  354. end
  355. end
  356. end
  357. for k, configs in pairs(self._needCheckItems) do
  358. for i, config in ipairs(configs) do
  359. self:addVarList(config.id)
  360. self:addIdsList(config.id)
  361. end
  362. end
  363. -- dump(self._valList, "self._valList__")
  364. end
  365. ---------------------------------------varlist
  366. function RedPointProxy:rmVarList(id)
  367. for varname, idList in pairs(self._valList) do
  368. idList[id] = nil
  369. end
  370. end
  371. -- 增加触发变量
  372. function RedPointProxy:addVarList(id)
  373. local config = self._configs[id]
  374. local lConditions = self:getConditions(config.levelCondition)
  375. local vConditions = self:getConditions(config.VarCondition, { BindCurrency = config.BindCurrency })
  376. local cConditions = self:getConditions(config.currencyCondition, { BindCurrency = config.BindCurrency })
  377. local namevec = {}
  378. getVarNames(lConditions, namevec)
  379. getVarNames(vConditions, namevec)
  380. getVarNames(cConditions, namevec)
  381. for i, varname in ipairs(namevec) do
  382. self._valList[varname] = self._valList[varname] or {}
  383. self._valList[varname][id] = config
  384. end
  385. end
  386. ----------------------------------------------id {type = 1,value= "101"} {type = 2,var = STR(哈哈),property = haha}
  387. -- str -> ids
  388. function RedPointProxy:getIdsByStr(str)
  389. if not str then
  390. SL:Print("ERROR:红点配置 ids 为空")
  391. return {}
  392. end
  393. if not self._idsCache[str] then
  394. self._idsCache[str] = self:ParseIdsWithStr(str)
  395. end
  396. return self._idsCache[str]
  397. end
  398. --ids -> {101,1,2,3,4}
  399. function RedPointProxy:getIDVecByIds(ids)
  400. local vec = {}
  401. for i, v in ipairs(ids) do
  402. if v.type == 1 then
  403. table.insert(vec, v.value)
  404. else
  405. local key = v.property or "value"
  406. if self._ServerVars[v.var] then
  407. local value = self._ServerVars[v.var][key]
  408. if value then
  409. local idVec = ssplit(value, "#")
  410. for i, v in ipairs(idVec) do
  411. table.insert(vec, v)
  412. end
  413. end
  414. end
  415. end
  416. end
  417. return vec
  418. end
  419. -- str -> ids {id,id}
  420. function RedPointProxy:ParseIdsWithStr(idstrs)
  421. local idVec = ssplit(idstrs, "#")
  422. local res = {}
  423. for i, v in ipairs(idVec) do
  424. local id = {}
  425. if sfind(v, "%b<>") then
  426. id.type = 2
  427. local value = smatch(v, "<(.-)>")
  428. local var, property = self:ParseVar(value)
  429. id.var = var
  430. id.property = property
  431. else
  432. id.type = 1
  433. id.value = v
  434. end
  435. table.insert(res, id)
  436. end
  437. return res
  438. end
  439. function RedPointProxy:addIdsList(id)
  440. local config = self._configs[id]
  441. if config.ids then
  442. local ids = self:getIdsByStr(config.ids)
  443. for i, v in ipairs(ids) do
  444. if v.type == 2 then
  445. local key2 = v.var
  446. self._idsWithVarItems[key2] = self._idsWithVarItems[key2] or {}
  447. table.insert(self._idsWithVarItems[key2], id)
  448. end
  449. end
  450. end
  451. end
  452. function RedPointProxy:rmIdsList(id)
  453. for k, idvec in pairs(self._idsWithVarItems) do
  454. for i = #idvec, 1, -1 do
  455. local id2 = idvec[i]
  456. if id2 == id then
  457. table.remove(idvec, i)
  458. break
  459. end
  460. end
  461. end
  462. end
  463. function RedPointProxy:addRedByIdKey(Idkey)
  464. local vec = self._idsWithVarItems[Idkey]
  465. for i = 1, #vec do
  466. self:addShowIds(vec[i])
  467. end
  468. end
  469. function RedPointProxy:rmvRedByIdKey(Idkey)
  470. local vec = self._idsWithVarItems[Idkey]
  471. for i = 1, #vec do
  472. self:rmvShowIds(vec[i])
  473. end
  474. end
  475. function RedPointProxy:UpdateItems(varkey)
  476. local vec = self._needCheckItems[varkey]
  477. for i, v in ipairs(vec) do
  478. local conf = nil
  479. local group = v.group
  480. local configs = self._groups[group]
  481. for i2, config in ipairs(configs) do
  482. if config.levelCondition and self:CheckStrConditions(config.levelCondition) then
  483. conf = config
  484. break
  485. end
  486. end
  487. if conf then
  488. if vec[i].levelCondition ~= conf.levelCondition then
  489. self:rmVarList(vec[i].id)
  490. self:addVarList(conf.id)
  491. self:rmvShowIds(vec[i].id)
  492. self:rmIdsList(vec[i].id)
  493. self:addIdsList(conf.id)
  494. vec[i] = conf
  495. end
  496. end
  497. end
  498. end
  499. function RedPointProxy:rmvRedDot(widget)
  500. if not widget then
  501. return
  502. end
  503. local reddot = widget:getChildByName("_RedDot_2")
  504. if reddot then
  505. reddot:removeFromParent()
  506. end
  507. end
  508. function RedPointProxy:addRedDot(widget, offset)
  509. if not widget then
  510. return
  511. end
  512. local reddot = widget:getChildByName("_RedDot_2")
  513. if reddot then
  514. reddot:removeFromParent()
  515. end
  516. local offset2, strs, id, x, y,tblr
  517. if offset then
  518. strs = ssplit(offset, "|")
  519. offset2 = strs[global.isWinPlayMode and 2 or 1]
  520. end
  521. if offset2 then --0#-5#5#0
  522. strs = ssplit(offset2, "#")
  523. id = strs[1] or 0
  524. x = strs[2] or 0
  525. y = strs[3] or 0
  526. tblr = strs[4] or 0
  527. end
  528. if not id then
  529. return
  530. end
  531. local redid = tonumber(id)
  532. x = tonumber(x)
  533. y = tonumber(y)
  534. tblr = tonumber(tblr)
  535. local content = widget:getContentSize()
  536. local wid = content.width
  537. local hei = content.height
  538. y = hei - y
  539. --默认左上
  540. if tblr == 1 then--右
  541. x = x + wid
  542. elseif tblr == 2 then--左下
  543. y = y - hei
  544. elseif tblr == 3 then --右下
  545. x = x + wid
  546. y = y - hei
  547. elseif tblr == 4 then--中间
  548. x = x + wid/2
  549. y = y - hei/2
  550. end
  551. if not redid then -- 自定义路径
  552. local path = SUIHelper.fixImageFileName(id)
  553. reddot = cc.Sprite:create(path)
  554. if reddot then
  555. reddot:setName("_RedDot_2")
  556. widget:addChild(reddot)
  557. reddot:setPosition(x, y)
  558. end
  559. elseif redid == 0 then
  560. strs = ssplit(SL:GetMetaValue("GAME_DATA","Redtips") or "", "|")
  561. local path = strs[global.isWinPlayMode and 1 or 2]
  562. path = SUIHelper.fixImageFileName(path)
  563. reddot = cc.Sprite:create(path)
  564. if reddot then
  565. reddot:setName("_RedDot_2")
  566. widget:addChild(reddot)
  567. reddot:setPosition(x, y)
  568. end
  569. else
  570. local sfxID = id
  571. if sfxID then
  572. reddot = global.FrameAnimManager:CreateSFXAnim(sfxID)
  573. if reddot then
  574. reddot:Play(0, 0, true)
  575. reddot:setName("_RedDot_2")
  576. widget:addChild(reddot)
  577. reddot:setPosition(x, y)
  578. end
  579. end
  580. end
  581. end
  582. function RedPointProxy:addShowIds(id)
  583. if self._showIDTable.showIDs[id] then
  584. return false
  585. end
  586. self._showIDTable.showIDs[id] = true
  587. SLBridge:onLUAEvent(LUA_EVENT_RED_POINT_ADD, {id = id})
  588. local config = self._configs[id]
  589. local idvec = self:getIDVecByIds(self:getIdsByStr(config.ids))
  590. --mainIDs = {101 = {count = 1 , btnIDs = {10 = {count = 1}}}}
  591. --npcLayerIDs = {101 = {count = 1 , btnIDs = {10 = {count = 1}}}}
  592. local mainID
  593. local npcLayerID
  594. local activeMainButtonID = 0
  595. local activeNpcLayerID = {}
  596. for i, v in ipairs(idvec) do
  597. if i == 1 then
  598. mainID = v
  599. self._showIDTable.mainIDs[mainID] = self._showIDTable.mainIDs[mainID] or { count = 0, btnIDs = {} }
  600. self._showIDTable.mainIDs[mainID].count = self._showIDTable.mainIDs[mainID].count + 1
  601. elseif i == 2 then
  602. self._showIDTable.mainIDs[mainID].btnIDs[v] = self._showIDTable.mainIDs[mainID].btnIDs[v] or { count = 0, offset = 0 }
  603. if self._showIDTable.mainIDs[mainID].btnIDs[v].count == 0 or self._showIDTable.mainIDs[mainID].btnIDs[v].offset ~= config.offset then--主面板激活红点
  604. activeMainButtonID = v
  605. self._showIDTable.mainIDs[mainID].btnIDs[v].offset = config.offset
  606. end
  607. self._showIDTable.mainIDs[mainID].btnIDs[v].count = self._showIDTable.mainIDs[mainID].btnIDs[v].count + 1
  608. elseif i == 3 then
  609. npcLayerID = v
  610. self._showIDTable.npcLayerIDs[npcLayerID] = self._showIDTable.npcLayerIDs[npcLayerID] or { count = 0, btnIDs = {} }
  611. self._showIDTable.npcLayerIDs[npcLayerID].count = self._showIDTable.npcLayerIDs[npcLayerID].count + 1
  612. else
  613. self._showIDTable.npcLayerIDs[npcLayerID].btnIDs[v] = self._showIDTable.npcLayerIDs[npcLayerID].btnIDs[v] or { count = 0, offset = 0 }
  614. if self._showIDTable.npcLayerIDs[npcLayerID].btnIDs[v].count == 0 or self._showIDTable.npcLayerIDs[npcLayerID].btnIDs[v].offset ~= config.offset then
  615. table.insert(activeNpcLayerID, v)
  616. self._showIDTable.npcLayerIDs[npcLayerID].btnIDs[v].offset = config.offset
  617. end
  618. self._showIDTable.npcLayerIDs[npcLayerID].btnIDs[v].count = self._showIDTable.npcLayerIDs[npcLayerID].btnIDs[v].count + 1
  619. end
  620. end
  621. if activeMainButtonID ~= 0 then
  622. local widgets = self:FindWidget({ { id = mainID, offset = config.offset }, { id = activeMainButtonID, offset = config.offset } }, true)
  623. for i, widget in ipairs(widgets) do
  624. self:addRedDot(widget, config.offset)
  625. end
  626. end
  627. if #activeNpcLayerID > 0 then --npcLayer 在npcLayer打开也要激活红点
  628. local NPCLayerMediator = global.Facade:retrieveMediator("NPCLayerMediator")
  629. if NPCLayerMediator._layer and NPCLayerMediator._layer.background then
  630. local npclayerid = NPCLayerMediator._layer.background.element.attr.layerid
  631. if npclayerid and npclayerid == npcLayerID then
  632. local idVec = { { id = npclayerid, offset = config.offset } }
  633. for i, v in ipairs(activeNpcLayerID) do
  634. table.insert(idVec, { id = v, offset = config.offset })
  635. end
  636. local widgets = self:FindWidget(idVec)
  637. for i, widget in ipairs(widgets) do
  638. self:addRedDot(widget, config.offset)
  639. end
  640. end
  641. end
  642. end
  643. end
  644. function RedPointProxy:rmvShowIds(id)
  645. if not self._showIDTable.showIDs[id] then
  646. return false
  647. end
  648. self._showIDTable.showIDs[id] = nil
  649. SLBridge:onLUAEvent(LUA_EVENT_RED_POINT_DEL, {id = id})
  650. local config = self._configs[id]
  651. local idvec = self:getIDVecByIds(self:getIdsByStr(config.ids))
  652. local otherID = {}
  653. --mainIDs = {101 = {count = 1 , btnIDs = {10 = {count = 1}}}}
  654. --npcLayerIDs = {101 = {count = 1 , btnIDs = {10 = {count = 1}}}}
  655. local mainID
  656. local npcLayerID
  657. local rmvMainButtonID = 0
  658. local rmvNpcLayerID = {}
  659. for i, v in ipairs(idvec) do
  660. if i == 1 then
  661. mainID = v
  662. if self._showIDTable.mainIDs[mainID] and self._showIDTable.mainIDs[mainID].count then
  663. self._showIDTable.mainIDs[mainID].count = math.max(self._showIDTable.mainIDs[mainID].count - 1, 0)
  664. end
  665. elseif i == 2 then
  666. if self._showIDTable.mainIDs[mainID]
  667. and self._showIDTable.mainIDs[mainID].btnIDs
  668. and self._showIDTable.mainIDs[mainID].btnIDs[v]
  669. and self._showIDTable.mainIDs[mainID].btnIDs[v].count then
  670. self._showIDTable.mainIDs[mainID].btnIDs[v].count = math.max(self._showIDTable.mainIDs[mainID].btnIDs[v].count - 1, 0)
  671. if self._showIDTable.mainIDs[mainID].btnIDs[v].count == 0 then
  672. rmvMainButtonID = v
  673. end
  674. end
  675. elseif i == 3 then
  676. npcLayerID = v
  677. if self._showIDTable.npcLayerIDs[npcLayerID] and self._showIDTable.npcLayerIDs[npcLayerID].count then
  678. self._showIDTable.npcLayerIDs[npcLayerID].count = math.max(self._showIDTable.npcLayerIDs[npcLayerID].count - 1, 0)
  679. end
  680. else
  681. if self._showIDTable.npcLayerIDs[npcLayerID]
  682. and self._showIDTable.npcLayerIDs[npcLayerID].btnIDs
  683. and self._showIDTable.npcLayerIDs[npcLayerID].btnIDs[v]
  684. and self._showIDTable.npcLayerIDs[npcLayerID].btnIDs[v].count then
  685. self._showIDTable.npcLayerIDs[npcLayerID].btnIDs[v].count = math.max(self._showIDTable.npcLayerIDs[npcLayerID].btnIDs[v].count - 1, 0)
  686. if self._showIDTable.npcLayerIDs[npcLayerID].btnIDs[v].count == 0 or self._showIDTable.npcLayerIDs[npcLayerID].btnIDs[v].offset ~= config.offset then
  687. table.insert(rmvNpcLayerID, v)
  688. end
  689. end
  690. end
  691. end
  692. if rmvMainButtonID ~= 0 then
  693. local widgets = self:FindWidget({ { id = mainID, offset = config.offset }, { id = rmvMainButtonID, offset = config.offset } }, true)
  694. for i, widget in ipairs(widgets) do
  695. self:rmvRedDot(widget)
  696. end
  697. end
  698. if #rmvNpcLayerID > 0 then --npcLayer 在npcLayer打开也要激活红点
  699. local NPCLayerMediator = global.Facade:retrieveMediator("NPCLayerMediator")
  700. if NPCLayerMediator._layer and NPCLayerMediator._layer.background then
  701. local npclayerid = NPCLayerMediator._layer.background.element.attr.layerid
  702. if npclayerid and npclayerid == npcLayerID then
  703. local idVec = { { id = npcLayerID, offset = config.offset } }
  704. for i, v in ipairs(rmvNpcLayerID) do
  705. table.insert(idVec, { id = v, offset = config.offset })
  706. end
  707. local widgets = self:FindWidget(idVec)
  708. for i, widget in ipairs(widgets) do
  709. self:rmvRedDot(widget)
  710. end
  711. end
  712. end
  713. end
  714. end
  715. function RedPointProxy:FindWidget(idVec, ismain)
  716. -- 主界面ID#按钮ID#面板ID#按钮ID#按钮ID
  717. local mainId, buttonId
  718. local layerId
  719. local buttonIdVec = {}
  720. if ismain then
  721. mainId = idVec[1].id
  722. buttonId = idVec[2].id
  723. mainId = tonumber(mainId)
  724. local getNodesFunc = self._GuideWidgetConfig[mainId]
  725. if not getNodesFunc then
  726. return {}
  727. end
  728. local widget, parent = getNodesFunc({ typeassist = buttonId })
  729. if widget then
  730. widget._Redoffset = idVec[2].offset
  731. return { widget }
  732. end
  733. else
  734. layerId = idVec[1].id
  735. for i = 2, #idVec do
  736. buttonIdVec[#buttonIdVec + 1] = idVec[i]
  737. end
  738. if #buttonIdVec > 0 then
  739. local NPCLayerMediator = global.Facade:retrieveMediator("NPCLayerMediator")
  740. if NPCLayerMediator._layer then
  741. if NPCLayerMediator._layer and NPCLayerMediator._layer.background then
  742. local npclayerid = NPCLayerMediator._layer.background.element.attr.layerid
  743. if npclayerid and npclayerid == layerId then
  744. local widgets = {}
  745. for i, v in ipairs(buttonIdVec) do
  746. local widget = getChildByKey(NPCLayerMediator._layer, tostring(v.id))
  747. if widget then
  748. widget._Redoffset = v.offset
  749. table.insert(widgets, widget)
  750. end
  751. end
  752. return widgets
  753. end
  754. end
  755. end
  756. end
  757. end
  758. return {}
  759. end
  760. ----------------------------------------------------------解析表
  761. -- T10#等级>=10 -> {T10,等级} ,>= ,10
  762. -- T10<=10 -> {T10},<=,10
  763. -- <T10#哈哈>>=10 -> {T10,哈哈},>=,10
  764. function RedPointProxy:ParseExpression(expression)
  765. local elements = {}
  766. local var, element
  767. if sfind(expression, "%b<>") then
  768. elements = { smatch(expression, "<(.-)>([!><=]+)(.*)") }
  769. var, element = self:ParseVar(elements[1])
  770. else
  771. elements = { smatch(expression, "(.-)([!><=]+)(.*)") }
  772. var = self:ParseVar(elements[1])
  773. end
  774. if elements[3] == "null" then
  775. elements[3] = ""
  776. end
  777. return { var, element }, elements[2], elements[3]
  778. end
  779. -- T10 -> T10
  780. -- T10#转生 -> T10,转生
  781. -- $str(T10)#转生 -> T10,转生
  782. -- $custom(T10)#转生 -> custom(T10),转生
  783. -- N$哈哈->N$哈哈
  784. function RedPointProxy:ParseVar(var)
  785. if not var then
  786. return ""
  787. end
  788. local value, attr
  789. if sfind(var, "#") then
  790. local vars = ssplit(var, "#")
  791. value = vars[1]
  792. attr = vars[2]
  793. else
  794. value = var
  795. end
  796. value = string.upper(value)
  797. if value then
  798. if sfind(value, "$STR%(.+%)") then
  799. value = smatch(value, "$STR%((.+)%)")
  800. elseif sfind(value, "%a$.+") then
  801. value = smatch(value, "%a$.+")
  802. elseif sfind(value, "$.+") then
  803. value = smatch(value, "$(.+)")
  804. end
  805. end
  806. return value, attr
  807. end
  808. function RedPointProxy:CheckStrConditions(str, exData)
  809. if not str or str == "" then
  810. return true
  811. end
  812. local conditions = self:getConditions(str, exData)
  813. return self:CheckConditions(conditions)
  814. end
  815. function RedPointProxy:getConditions(str, exData)
  816. if not str or str == "" then
  817. return nil
  818. end
  819. if not self._conditionsCache[str] then
  820. self._conditionsCache[str] = self:ParseConditionStr(str, exData)
  821. end
  822. return self._conditionsCache[str]
  823. end
  824. function RedPointProxy:CheckConditions(conditions)
  825. if not conditions then
  826. return true
  827. end
  828. local ok = true
  829. if conditions.dType == 2 then
  830. local isAnd = true
  831. for i, condition in ipairs(conditions.conditions) do
  832. local conditionres = false
  833. if condition.dType == 2 then
  834. conditionres = self:CheckConditions(condition)
  835. else
  836. conditionres = self:CheckCondition(condition)
  837. end
  838. if isAnd then
  839. ok = (ok and conditionres)
  840. else
  841. ok = (ok or conditionres)
  842. end
  843. if condition.opType == 1 then
  844. isAnd = true
  845. else
  846. isAnd = false
  847. end
  848. end
  849. else
  850. ok = self:CheckCondition(conditions)
  851. end
  852. return ok
  853. end
  854. function RedPointProxy:CheckCondition(condition)
  855. local scount
  856. if values[condition.var.key] then -- 常量 货币道具
  857. scount = values[condition.var.key](condition.var.Hero, condition.var.value, condition.value2)
  858. else
  859. local key = condition.property or "value"
  860. scount = self._ServerVars[condition.var.key] and self._ServerVars[condition.var.key][key]
  861. end
  862. local v = tonumber(scount) or scount
  863. if not v then
  864. v = ""
  865. end
  866. local count = condition.count
  867. local opt = condition.opt
  868. --不等于 可以类型不同
  869. if opt ~= 5 and type(v) ~= type(count) then -- 服务端可能下发""空字符串
  870. return false
  871. end
  872. if opt == 1 then
  873. return v >= count
  874. elseif opt == 2 then
  875. return v <= count
  876. elseif opt == 3 then
  877. return v < count
  878. elseif opt == 4 then
  879. return v > count
  880. elseif opt == 5 then
  881. return v ~= count
  882. else
  883. return v == count
  884. end
  885. end
  886. function RedPointProxy:stringtoCondition(str, exData)
  887. local BindCurrency = exData and exData.BindCurrency
  888. local vars, operator, scount = self:ParseExpression(str)
  889. local condition = {}
  890. local opt = 0
  891. if operator == ">=" then
  892. opt = 1
  893. elseif operator == "<=" then
  894. opt = 2
  895. elseif operator == "<" then
  896. opt = 3
  897. elseif operator == ">" then
  898. opt = 4
  899. elseif operator == "!=" then
  900. opt = 5
  901. end
  902. local count = tonumber(scount)
  903. if not count then
  904. if opt ~= 0 and opt ~= 5 then
  905. opt = 0
  906. end
  907. count = scount
  908. end
  909. -- 操作符
  910. condition.opt = opt
  911. -- 值
  912. condition.count = count
  913. local function getRealVar(var)
  914. local varT = {}
  915. if tonumber(var) then --货币或道具
  916. varT.value = tonumber(var)
  917. varT.key = "ITEMINDEX"
  918. return varT
  919. end
  920. local key, value
  921. if sfind(var, "H%.") then
  922. if sfind(var, "%[(%d+)%]") then
  923. local key, value = smatch(var, "H%.(.+)%[(%d+)%]")
  924. varT.key = key
  925. varT.Hero = true
  926. varT.value = value
  927. else
  928. key = smatch(var, "H%.(.+)")
  929. varT.key = key
  930. varT.Hero = true
  931. end
  932. elseif sfind(var, "MONEY%((.+)%)") then--常量MONEY()特殊处理 服务端的变量 有可能是XXXX(xxx)
  933. value = smatch(var, "MONEY%((.+)%)")
  934. key = "MONEY"
  935. varT.key = key
  936. varT.value = value
  937. else
  938. if sfind(var, "%[(%d+)%]") then
  939. key, value = smatch(var, "(.+)%[(%d+)%]")
  940. varT.key = key
  941. varT.value = value
  942. else
  943. key = var
  944. varT.key = key
  945. end
  946. end
  947. return varT
  948. end
  949. condition.var = getRealVar(vars[1])--{key,Hero,value}
  950. condition.property = vars[2]--键值对
  951. condition.value2 = BindCurrency
  952. condition.dType = 1
  953. return condition
  954. end
  955. function RedPointProxy:_compareBracket(str)
  956. local offset = 1
  957. local strIdx = 2
  958. local len = string.len(str)
  959. local IDX = 1
  960. while 1 do
  961. IDX = IDX + 1
  962. local lIdx = sfind(str, "%[", strIdx) or len
  963. local rIdx = sfind(str, "%]", strIdx) or len
  964. if lIdx < rIdx then
  965. strIdx = lIdx + 1
  966. offset = offset + 1
  967. else
  968. strIdx = rIdx + 1
  969. offset = offset - 1
  970. end
  971. if offset == 0 then
  972. strIdx = strIdx - 1
  973. break
  974. end
  975. if strIdx > string.len(str) then
  976. print(">>>>>>>condition () not compare", str, IDX)
  977. return nil
  978. end
  979. end
  980. return strIdx
  981. end
  982. function RedPointProxy:ParseConditionStr(str, exData)
  983. if not str or str == "" then
  984. return nil
  985. end
  986. local conditions = {}
  987. local idx = 0
  988. while 1 do
  989. idx = idx + 1
  990. if str == "" or idx > 100 then
  991. break
  992. end
  993. local condition = nil
  994. local len = string.len(str)
  995. local andIdx = sfind(str, "&")
  996. local orIdx = sfind(str, "|")
  997. local splitIdx = math.min(andIdx or len + 1, orIdx or len + 1)
  998. local fchar = string.sub(str, 0, 1)
  999. if fchar == "[" then
  1000. local rightBracketIdx = self:_compareBracket(str)
  1001. if not rightBracketIdx then
  1002. rightBracketIdx = string.len(str)
  1003. print(">>Bracket compare error:", str)
  1004. break
  1005. end
  1006. condition = self:ParseConditionStr(string.sub(str, 2, rightBracketIdx - 1), exData)
  1007. conditions[idx] = condition
  1008. local fchar = string.sub(str, rightBracketIdx + 1, rightBracketIdx + 1)
  1009. str = string.sub(str, rightBracketIdx + 2)
  1010. andIdx = sfind(fchar, "&")
  1011. orIdx = sfind(fchar, "|")
  1012. else
  1013. local splitIdx = math.min(andIdx or len + 1, orIdx or len + 1)
  1014. local conditionStr = string.sub(str, 1, splitIdx - 1)
  1015. -- print("idx", andIdx, orIdx, len, str, conditionStr)
  1016. condition = self:stringtoCondition(conditionStr, exData)
  1017. conditions[idx] = condition
  1018. str = string.sub(str, splitIdx + 1)
  1019. end
  1020. if condition then
  1021. if andIdx and (not orIdx or orIdx > andIdx) then
  1022. condition.opType = 1
  1023. end
  1024. if orIdx and (not andIdx or andIdx > orIdx) then
  1025. condition.opType = 2
  1026. end
  1027. end
  1028. end
  1029. if #conditions == 0 then
  1030. return nil
  1031. end
  1032. if #conditions == 1 then
  1033. return conditions[1]
  1034. end
  1035. local data = {}
  1036. data.dType = 2
  1037. data.conditions = conditions
  1038. data.originStr = str
  1039. return data
  1040. end
  1041. function RedPointProxy:LoadConfig()
  1042. local configs = requireGameConfig("cfg_redpoint")
  1043. for k, v in pairs(configs) do
  1044. self._configs[v.id] = v
  1045. if v.group then
  1046. self._groups[v.group] = self._groups[v.group] or {}
  1047. table.insert(self._groups[v.group], v)
  1048. end
  1049. end
  1050. for k, v in pairs(self._groups) do
  1051. table.sort(v, function(a, b)
  1052. return a.level < b.level
  1053. end)
  1054. end
  1055. end
  1056. function RedPointProxy:InstertCheckQue(Var)
  1057. local List = self._valList[Var]
  1058. if List then
  1059. if self._needCheckItems[Var] then--这里需要更新需要检测的条件
  1060. self:UpdateItems(Var)
  1061. end
  1062. for id, val in pairs(List) do
  1063. if not self._needCheckIDs[id] then
  1064. self._needCheckIDs[id] = true
  1065. table.insert(self._needCheckIDsVec, id)
  1066. end
  1067. end
  1068. end
  1069. local BubbleProxy = global.Facade:retrieveProxy(global.ProxyTable.BubbleProxy)
  1070. if BubbleProxy then
  1071. BubbleProxy:InstertCheckQue(Var)
  1072. end
  1073. end
  1074. -- Npc界面打开触发 添加红点
  1075. function RedPointProxy:onNpcLayerOpen()
  1076. local add = function (npcLayerID)
  1077. if not npcLayerID then
  1078. return false
  1079. end
  1080. local idVec = {{id = npcLayerID}}
  1081. local npcButtons = self._showIDTable.npcLayerIDs[npcLayerID]
  1082. local btnIDs = npcButtons and npcButtons.btnIDs
  1083. if not btnIDs then
  1084. return false
  1085. end
  1086. for k, v in pairs(btnIDs) do
  1087. if v.count and v.count > 0 then
  1088. idVec[#idVec+1] = {id = k, offset = v.offset}
  1089. end
  1090. end
  1091. local widgets = self:FindWidget(idVec)
  1092. for i = 1, #widgets do
  1093. local widget = widgets[i]
  1094. self:addRedDot(widget, widget._Redoffset)
  1095. end
  1096. end
  1097. local NPCLayerMediator = global.Facade:retrieveMediator("NPCLayerMediator")
  1098. if NPCLayerMediator._layer and NPCLayerMediator._layer.background then
  1099. add(NPCLayerMediator._layer.background.element.attr.layerid)
  1100. end
  1101. end
  1102. -----------------官方其他界面触发 添加
  1103. function RedPointProxy:onOtherLayer(mainIDs)
  1104. for i, mainID in ipairs(mainIDs) do
  1105. local mainParam = self._showIDTable.mainIDs[tostring(mainID)]
  1106. if mainParam and mainParam.count and mainParam.count > 0 then
  1107. local mianBtns = mainParam.btnIDs
  1108. local widgets
  1109. for id, btn in pairs(mianBtns) do
  1110. if btn.count and btn.count > 0 then
  1111. widgets = self:FindWidget({ { id = mainID }, { id = id, offset = btn.offset } }, true)
  1112. if widgets[1] then
  1113. self:addRedDot(widgets[1], btn.offset)
  1114. end
  1115. end
  1116. end
  1117. end
  1118. end
  1119. end
  1120. -- 背包界面加载成功 添加红点
  1121. function RedPointProxy:onBagLayerLoadSuccess()
  1122. local mainIDs = {1,7}
  1123. self:onOtherLayer(mainIDs)
  1124. end
  1125. -----------------
  1126. ----- 玩家界面加载成功 添加红点
  1127. function RedPointProxy:onPlayerFrameLoadSuccess()
  1128. local mainIDs = {202}
  1129. self:onOtherLayer(mainIDs)
  1130. end
  1131. ----- 玩家装备界面加载成功 添加红点
  1132. function RedPointProxy:onPlayerEquipLoadSuccess()
  1133. local mainIDs = {2}
  1134. self:onOtherLayer(mainIDs)
  1135. end
  1136. -- 英雄背包界面加载成功 添加红点
  1137. function RedPointProxy:onHeroBagLayerLoadSuccess()
  1138. local mainIDs = {3}
  1139. self:onOtherLayer(mainIDs)
  1140. end
  1141. -----------------
  1142. ----- 英雄界面加载成功 添加红点
  1143. function RedPointProxy:onHeroFrameLoadSuccess()
  1144. local mainIDs = {203}
  1145. self:onOtherLayer(mainIDs)
  1146. end
  1147. ----- 英雄装备界面加载成功 添加红点
  1148. function RedPointProxy:onHeroEquipLoadSuccess()
  1149. local mainIDs = {41}
  1150. self:onOtherLayer(mainIDs)
  1151. end
  1152. function RedPointProxy:onSUIComponentUpdate(data)
  1153. local mainID = data.index
  1154. if mainID >= 101 and mainID <= 110 then --暂时只支持101~110
  1155. mainID = tostring(mainID)
  1156. if self._showIDTable.mainIDs[mainID] and self._showIDTable.mainIDs[mainID].count and self._showIDTable.mainIDs[mainID].count > 0 then
  1157. local MainButtons = self._showIDTable.mainIDs[mainID]
  1158. if MainButtons and MainButtons.btnIDs then
  1159. for k, v in pairs(MainButtons.btnIDs) do
  1160. if v.count and v.count > 0 then
  1161. local widgets = self:FindWidget({ { id = mainID, offset = v.offset }, { id = k, offset = v.offset } }, true)
  1162. for i, widget in ipairs(widgets) do
  1163. self:addRedDot(widget, widget._Redoffset)
  1164. end
  1165. end
  1166. end
  1167. end
  1168. end
  1169. end
  1170. end
  1171. -- 触发检测
  1172. function RedPointProxy:doSomeThing(Var)
  1173. self:InstertCheckQue(Var)
  1174. end
  1175. function RedPointProxy:handle_MSG_SC_REDPOINTVARCHANGE(msg)
  1176. local msgHdr = msg:GetHeader()
  1177. local jsonData = ParseRawMsgToJson(msg)
  1178. for i, v in ipairs(jsonData) do
  1179. local key = string.upper(v.Var)
  1180. local txtKey = key
  1181. local txtValue = v.Value
  1182. local IsTable = false
  1183. sgsub(txtValue, "^{(.+)}$", function (s)
  1184. local Tabs = {}
  1185. sgsub(sgsub(s .. ",", ",,", ","), "(.-),", function ( s )
  1186. Tabs[#Tabs+1] = string.trim(s)
  1187. end)
  1188. txtKey = sformat("<V_%s>", sgsub(txtKey, "%$", ""))
  1189. txtValue = Tabs
  1190. IsTable = true
  1191. end)
  1192. if not IsTable then
  1193. sgsub(txtValue, "^%^(.+)%^$", function (s)
  1194. local Tabs = {}
  1195. sgsub(sgsub(s .. ",", ",,", ","), "(.-),", function ( s )
  1196. Tabs[#Tabs+1] = string.trim(s)
  1197. end)
  1198. txtKey = sformat("<T_%s>", sgsub(txtKey, "%$", ""))
  1199. txtValue = Tabs
  1200. end)
  1201. end
  1202. self._TXTServerVars[txtKey] = txtValue
  1203. -- red point
  1204. local var = {
  1205. var = key, _originValue_ = v.Value
  1206. }
  1207. local value = v.Value
  1208. if sfind(value, ",") then
  1209. local exp = ssplit(value, ",")
  1210. for i, v in ipairs(exp) do
  1211. local property, res = smatch(v, "(.+)%s-=%s-(.+)")
  1212. if property and res then
  1213. var[property] = tonumber(res) or res
  1214. end
  1215. end
  1216. else
  1217. var.value = tonumber(value) or value
  1218. if sfind(value, "=") then
  1219. local property, res = smatch(value, "(.+)%s-=%s-(.+)")
  1220. if property and res then
  1221. var[property] = tonumber(res) or res
  1222. end
  1223. end
  1224. end
  1225. -- 解析后的值
  1226. self._ServerVars[key] = var
  1227. if self._idsWithVarItems[key] then
  1228. -- ids更新删除老红点
  1229. self:rmvRedByIdKey(key)
  1230. -- ids更新+新红点
  1231. self:addRedByIdKey(key)
  1232. end
  1233. if self._needCheckItems[key] then
  1234. self:UpdateItems(key)
  1235. end
  1236. SL:onLUAEvent(LUA_EVENT_SERVER_VALUE_CHANGE,{key = key,value = v.Value})
  1237. -- 插入检测队列
  1238. self:InstertCheckQue(key)
  1239. end
  1240. global.Facade:sendNotification(global.NoticeTable.Server_Var_Change)
  1241. end
  1242. function RedPointProxy:TransValueByKey(key)
  1243. local k1, v1 = self:ParseVar(key)
  1244. if self._ServerVars[k1] and v1 and self._ServerVars[k1][v1] then
  1245. return self._ServerVars[k1][v1]
  1246. end
  1247. return self._ServerVars[k1] and self._ServerVars[k1].value or ""
  1248. end
  1249. function RedPointProxy:getOriginValueByKey(key)
  1250. key = string.upper(key)
  1251. return self._ServerVars[key] and self._ServerVars[key]._originValue_ or ""
  1252. end
  1253. function RedPointProxy:getTXTValueByKey(key)
  1254. return self._TXTServerVars[string.upper(key)]
  1255. end
  1256. function RedPointProxy:CheckRedPointID(id)
  1257. if self._showIDTable and self._showIDTable.showIDs and self._showIDTable.showIDs[id] then
  1258. return true
  1259. end
  1260. return false
  1261. end
  1262. function RedPointProxy:RegisterMsgHandler()
  1263. local msgType = global.MsgType
  1264. LuaRegisterMsgHandler(msgType.MSG_SC_REDPOINTVARCHANGE, handler(self, self.handle_MSG_SC_REDPOINTVARCHANGE)) -- 变量变动
  1265. end
  1266. return RedPointProxy