UIFuncUnlockMgr.lua 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  1. local UIFuncUnlockMgr = class("UIFuncUnlockMgr")
  2. local ConditionJudge = require("Common/ConditionJudge")
  3. local lockLevels = {}
  4. local funcBtns = {}
  5. local curOpened = {}
  6. local loggedinLevelId = 10001
  7. local dir = Vector3.zero
  8. function UIFuncUnlockMgr:ctor()
  9. ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.UI_FILLCONTENT_COMPELETED, self, self.FillContentCompeleted)
  10. ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.UI_CLOSE_COMPELETED, self, self.UICloseCompeleted)
  11. ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.UI_FUNCLOCK_OPEN_NTF, self, self.UINewLevelFuncOpen)
  12. ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.UI_VIP_FUNCLOCK_OPEN_NTF, self, self.UIFuncOpen)
  13. self:InitLockLevels()
  14. end
  15. function UIFuncUnlockMgr:InitLockLevels()
  16. local cfgs = ManagerContainer.CfgMgr:GetUIFuncUnLockCfgAllDatas()
  17. for _,v in pairs(cfgs) do
  18. if v.PrePose == 0 then
  19. local conds = v.UnlockCond
  20. if conds then
  21. for i = 1, #conds do
  22. local cond = conds[i]
  23. if cond then
  24. if cond[1] == Enum.TaskType.Level_Battle_Count then
  25. if not CommonUtil.EleInTable(cond[2], lockLevels) then
  26. lockLevels[#lockLevels + 1]= cond[2]
  27. end
  28. end
  29. end
  30. end
  31. end
  32. --for _,v1 in pairs(conds) do
  33. -- local conditionData = ManagerContainer.CfgMgr:GetCondDataById(v1)
  34. --
  35. -- local condition = conditionData.Condition
  36. -- if condition[1] == Enum.TaskType.Base_Level then
  37. --
  38. -- elseif condition[1] == Enum.TaskType.Level_Battle_Count then
  39. -- if not CommonUtil.EleInTable(condition[2], lockLevels) then
  40. -- lockLevels[#lockLevels + 1]= condition[2]
  41. -- end
  42. -- end
  43. --end
  44. end
  45. end
  46. end
  47. function UIFuncUnlockMgr:SaveNeedDisplayNewFuncStatus(status)
  48. local uid = ManagerContainer.DataMgr.UserData:GetUserId()
  49. UnityEngine.PlayerPrefs.SetInt(tostring(uid).."NewFunc", status and 1 or 0)
  50. end
  51. function UIFuncUnlockMgr:GetNeedDisplayNewFuncStatus()
  52. local uid = ManagerContainer.DataMgr.UserData:GetUserId()
  53. local result = UnityEngine.PlayerPrefs.GetInt(tostring(uid).."NewFunc", 0)
  54. return result == 1
  55. end
  56. function UIFuncUnlockMgr:SaveLockBubbleStatus(id, status)
  57. local uid = ManagerContainer.DataMgr.UserData:GetUserId()
  58. UnityEngine.PlayerPrefs.SetInt(tostring(uid).."LockBubble"..id, status and 1 or 0)
  59. end
  60. function UIFuncUnlockMgr:GetLockBubbleStatus(id)
  61. local uid = ManagerContainer.DataMgr.UserData:GetUserId()
  62. local result = UnityEngine.PlayerPrefs.GetInt(tostring(uid).."LockBubble"..id, 0)
  63. return result == 1
  64. end
  65. function UIFuncUnlockMgr:NeedOpenFuncCurLevelStart(levelId)
  66. return CommonUtil.EleInTable(levelId, lockLevels) and levelId >= loggedinLevelId
  67. end
  68. function UIFuncUnlockMgr:SetLoggedinLevelId(levelId)
  69. loggedinLevelId = levelId
  70. end
  71. function UIFuncUnlockMgr:FillContentCompeleted(wnd)
  72. local list = ManagerContainer.CfgMgr:GetUIFuncUnLockCfgDataByUIId(wnd.uiData.id)
  73. for _,v in pairs(list) do
  74. self:InsertFuncController(wnd, v)
  75. end
  76. end
  77. function UIFuncUnlockMgr:InsertFuncController(wnd, data)
  78. if data.PrePose > 0 and (not CommonUtil.EleInTable(data.PrePose, curOpened) or CommonUtil.EleInTable(data.Id, curOpened)) then
  79. return
  80. end
  81. local target = CommonUtil.ParseUITargetPath(wnd, data.FuncEnterPath)
  82. if target == nil then return end
  83. if type(target) == "table" then
  84. target = target.gameObject
  85. end
  86. local conds = data.UnlockCond
  87. if not conds then return end
  88. local result = self:CheckConditionPassResult(data)
  89. --LogError("===FuncEnterPath=="..data.FuncEnterPath.."===result==="..Inspect(result))
  90. local isLoggedinLevelId = false
  91. for _,cond in pairs(conds) do
  92. if cond[1] == Enum.TaskType.Level_Battle_Count then
  93. if result and loggedinLevelId == cond[2] and tonumber(cond[2]) ~= 10001 then
  94. isLoggedinLevelId = true
  95. end
  96. if not isLoggedinLevelId and tonumber(cond[2]) <= loggedinLevelId and tonumber(loggedinLevelId) ~= 10001 then
  97. curOpened[#curOpened + 1] = data.Id
  98. end
  99. end
  100. end
  101. --for _,v in pairs(conds) do
  102. -- local result1, condDsc, type = ConditionJudge:ConditionPassResult(v)
  103. -- cond = condDsc
  104. -- if result1 and type == Enum.TaskType.Level_Battle_Count and loggedinLevelId == condDsc then
  105. -- isLoggedinLevelId = true
  106. -- end
  107. -- if not result1 then
  108. -- result = false
  109. -- end
  110. --end
  111. local key ="self."..data.FuncEnterPath
  112. if funcBtns[wnd.uiData.id] == nil then
  113. funcBtns[wnd.uiData.id] = {}
  114. end
  115. local guideState = self:GetLockBubbleStatus(data.Id)
  116. if result == true then
  117. if funcBtns[wnd.uiData.id][key] == nil then
  118. if not guideState then
  119. target:SetActive(true)
  120. return
  121. elseif isLoggedinLevelId and not guideState then
  122. target:SetActive(true)
  123. return
  124. elseif not isLoggedinLevelId and CommonUtil.EleInTable(data.Id, curOpened) and not guideState then
  125. target:SetActive(true)
  126. return
  127. end
  128. else
  129. --if not guideState then
  130. -- target:SetActive(true)
  131. -- local parent = target.transform.parent
  132. -- local lock = target.transform:Find(target.name.."_lock")
  133. -- if lock == nil then
  134. -- lock = parent:Find(target.name.."_lock")
  135. -- end
  136. -- if lock then
  137. -- lock.gameObject:SetActive(false)
  138. -- end
  139. -- return
  140. --end
  141. end
  142. end
  143. if not data.Special then
  144. self:NormalLock(wnd, data, target, result, key, guideState, conds)
  145. else
  146. self:SpecialLock(wnd, data, target, result, key, guideState, conds)
  147. end
  148. end
  149. function UIFuncUnlockMgr:NormalLock(wnd, data, target, result, key, guideState, conds)
  150. local parent = target.transform.parent
  151. local lock = target.transform:Find(target.name.."_lock")
  152. target:SetActive(result or (not result and data.NeedDisplay))
  153. if result and not guideState then
  154. local parent = target.transform.parent
  155. local lock = target.transform:Find(target.name.."_lock")
  156. if lock == nil then
  157. lock = parent:Find(target.name.."_lock")
  158. end
  159. if lock then
  160. lock.gameObject:SetActive(false)
  161. end
  162. return
  163. end
  164. local go
  165. if lock == nil then
  166. lock = parent:Find(target.name.."_lock")
  167. end
  168. if lock == nil then
  169. local targetSize = target:GetComponent(Enum.TypeInfo.RectTransform).sizeDelta
  170. go = UnityEngine.GameObject.New(target.name.."_lock")
  171. go.transform:SetParent(target.transform)
  172. go.transform.localPosition = Vector3.zero
  173. go.transform.localScale = Vector3.one
  174. local rectTrans = go:GetOrAddComponent(Enum.TypeInfo.RectTransform)
  175. rectTrans.sizeDelta = targetSize
  176. end
  177. if lock == nil and go ~= nil then
  178. lock = go.transform
  179. end
  180. if funcBtns[wnd.uiData.id][key] == nil then
  181. funcBtns[wnd.uiData.id][key] = {}
  182. end
  183. funcBtns[wnd.uiData.id][key]["target"] = target
  184. funcBtns[wnd.uiData.id][key]["data"] = data
  185. funcBtns[wnd.uiData.id][key]["lock"] = lock
  186. funcBtns[wnd.uiData.id][key]["needGuide"] = data.NeedGuide
  187. if not result and not guideState then
  188. self:SaveLockBubbleStatus(data.Id, data.NeedGuide)
  189. end
  190. if lock == nil or tolua.isnull(lock) then
  191. --LogError(data.Id.." has no lock target")
  192. return
  193. end
  194. local lockBtn = lock:Find("btn")
  195. local lockBubble = lock:Find("bubble")
  196. if lockBtn == nil then
  197. go = nil
  198. local targetSize = target:GetComponent(Enum.TypeInfo.RectTransform).sizeDelta
  199. go = UnityEngine.GameObject.New("btn")
  200. go.transform:SetParent(lock.transform)
  201. go.transform.localPosition = Vector3.zero
  202. go.transform.localScale = Vector3.one
  203. local rectTrans = go:GetOrAddComponent(Enum.TypeInfo.RectTransform)
  204. rectTrans.sizeDelta = targetSize
  205. go:GetOrAddComponent(Enum.TypeInfo.CanvasRenderer)
  206. go:GetOrAddComponent(Enum.TypeInfo.UIRaycastNoDraw)
  207. go:GetOrAddComponent(Enum.TypeInfo.Button)
  208. end
  209. if lockBtn == nil and go ~= nil then
  210. lockBtn = go.transform
  211. end
  212. lockBtn.gameObject:SetActive(not result and data.NeedMask)
  213. if lockBubble == nil then
  214. go = nil
  215. local targetSize = target:GetComponent(Enum.TypeInfo.RectTransform).sizeDelta
  216. go = UnityEngine.GameObject.New("bubble")
  217. go.transform:SetParent(lock.transform)
  218. go.transform.localPosition = Vector3.zero
  219. go.transform.localScale = Vector3.one
  220. local rectTrans = go:GetOrAddComponent(Enum.TypeInfo.RectTransform)
  221. rectTrans.sizeDelta = targetSize
  222. go:GetOrAddComponent(Enum.TypeInfo.UIRaycastNoDraw)
  223. go:GetOrAddComponent(Enum.TypeInfo.Button)
  224. end
  225. if lockBubble == nil and go ~= nil then
  226. lockBubble = go.transform
  227. end
  228. lockBubble.gameObject:SetActive(result and funcBtns[wnd.uiData.id][key]["needGuide"])
  229. local dscText = lockBubble:Find("Talk/bg/Text")
  230. if dscText ~= nil then
  231. local text = dscText:GetComponent(Enum.TypeInfo.Text)
  232. text.text = I18N.T(data.LockDsc)
  233. end
  234. lock.gameObject:SetActive((not result or (result and funcBtns[wnd.uiData.id][key]["needGuide"])) and data.NeedLock)
  235. if not result then
  236. local button1 = target:GetComponent(Enum.TypeInfo.Button)
  237. if button1 then
  238. local image = target:GetComponent(Enum.TypeInfo.Image)
  239. if image then
  240. image.raycastTarget = false
  241. end
  242. else
  243. button1 = target:GetComponent(Enum.TypeInfo.Toggle)
  244. if button1 then
  245. button1.graphic.raycastTarget = false
  246. end
  247. end
  248. if lockBtn then
  249. local button = lockBtn:GetComponent(Enum.TypeInfo.Button)
  250. if button == nil then
  251. button = lockBtn.gameObject:GetOrAddComponent(Enum.TypeInfo.Button)
  252. end
  253. wnd.uiBase:AddButtonUniqueEventListener(button, wnd, function (button, params)
  254. local result, val, content = self:CheckConditionPassResult(data)
  255. if not result then
  256. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(content..I18N.T(data.FunName)..I18N.T("Fun"))
  257. end
  258. end)
  259. end
  260. if lockBubble and funcBtns[wnd.uiData.id][key]["needGuide"] then
  261. local button = lockBubble:GetComponent(Enum.TypeInfo.Button)
  262. if button == nil then
  263. button = lockBubble.gameObject:GetOrAddComponent(Enum.TypeInfo.Button)
  264. end
  265. wnd.uiBase:AddButtonUniqueEventListener(button, wnd, function (button, params)
  266. if target then
  267. self:SaveLockBubbleStatus(data.Id, false)
  268. funcBtns[wnd.uiData.id][key] = nil
  269. target:SetActive(true)
  270. lock.gameObject:SetActive(false)
  271. curOpened[#curOpened + 1] = data.Id
  272. local button1 = target:GetComponent(Enum.TypeInfo.Button)
  273. if button1 then
  274. button1.onClick:Invoke()
  275. else
  276. button1 = target:GetComponent(Enum.TypeInfo.Toggle)
  277. button1.onValueChanged:Invoke(true)
  278. end
  279. local nextFuncData = ManagerContainer.CfgMgr:GetUIFuncUnLockCfgDataById(data.PostPose)
  280. if nextFuncData and wnd.uiData.id == nextFuncData.UIId then
  281. self:InsertFuncController(wnd, nextFuncData)
  282. end
  283. end
  284. end)
  285. end
  286. else
  287. if lockBubble and funcBtns[wnd.uiData.id][key]["needGuide"] then
  288. local button = lockBubble:GetComponent(Enum.TypeInfo.Button)
  289. if button == nil then
  290. button = lockBubble.gameObject:GetOrAddComponent(Enum.TypeInfo.Button)
  291. end
  292. wnd.uiBase:AddButtonUniqueEventListener(button, wnd, function (button, params)
  293. if target then
  294. self:SaveLockBubbleStatus(data.Id, false)
  295. funcBtns[wnd.uiData.id][key] = nil
  296. local button1 = target:GetComponent(Enum.TypeInfo.Button)
  297. target:SetActive(true)
  298. lock.gameObject:SetActive(false)
  299. curOpened[#curOpened + 1] = data.Id
  300. if button1 then
  301. if button1.onClick then
  302. button1.onClick:Invoke()
  303. elseif button1.onValueChanged then
  304. button1.onValueChanged:Invoke(true)
  305. end
  306. end
  307. local nextFuncData = ManagerContainer.CfgMgr:GetUIFuncUnLockCfgDataById(data.PostPose)
  308. if nextFuncData and wnd.uiData.id == nextFuncData.UIId then
  309. self:InsertFuncController(wnd, nextFuncData)
  310. end
  311. end
  312. end)
  313. end
  314. end
  315. end
  316. --只用于主城的建筑
  317. function UIFuncUnlockMgr:SpecialLock(wnd, data, target, result, key, guideState, conds)
  318. local function InitTitle(lock, targetButtonField, targetTitle, textContent)
  319. local title = lock.transform:Find("Title")
  320. title.transform.position = targetTitle.transform.position
  321. local titleText = title:Find("Text")
  322. titleText:GetComponent(Enum.TypeInfo.TextMeshProUGUI).text = textContent
  323. local rectSize = targetButtonField:GetComponent(Enum.TypeInfo.RectTransform).sizeDelta
  324. local lockButtonField = lock.transform:Find("TargetBox")
  325. lockButtonField.transform.position = targetButtonField.transform.position
  326. lockButtonField:GetComponent(Enum.TypeInfo.RectTransform).sizeDelta = rectSize
  327. end
  328. local targetButtonField = target.transform:Find("TargetBox")
  329. local targetTitle = target.transform:Find("Title")
  330. local textContent = targetTitle:Find("Text"):GetComponent(Enum.TypeInfo.TextMeshProUGUI).text
  331. targetTitle.gameObject:SetActive(result or (not result and data.NeedDisplay))
  332. if result and not guideState then
  333. local lockBtn = target.transform:Find("LockbtnItem")
  334. if lockBtn then
  335. lockBtn.gameObject:SetActive(false)
  336. end
  337. local lockBubble = target.transform:Find("LockBubbleItem")
  338. if lockBubble then
  339. lockBubble.gameObject:SetActive(false)
  340. end
  341. return
  342. end
  343. local lockBtn = target.transform:Find("LockbtnItem")
  344. if not result and data.NeedMask then
  345. if lockBtn == nil then
  346. lockBtn = ManagerContainer.ResMgr:GetGoFromPool(Constants.UICommonPath, "LockbtnItem")
  347. lockBtn.name = "LockbtnItem"
  348. lockBtn.transform:SetParent(target.transform)
  349. lockBtn.transform.localPosition = Vector3.zero
  350. lockBtn.transform.localScale = Vector3.one
  351. InitTitle(lockBtn, targetButtonField, targetTitle, I18N.T(data.FunName))
  352. end
  353. local lockButton = lockBtn.gameObject:GetOrAddComponent(Enum.TypeInfo.Button)
  354. if lockButton then
  355. wnd.uiBase:AddButtonUniqueEventListener(lockButton, wnd, function (button, params)
  356. local result, val, content = self:CheckConditionPassResult(data)
  357. if not result then
  358. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(content..I18N.T(data.FunName)..I18N.T("Fun"))
  359. end
  360. end)
  361. end
  362. lockBtn.gameObject:SetActive(true)
  363. else
  364. if lockBtn then
  365. lockBtn.gameObject:SetActive(false)
  366. end
  367. end
  368. if funcBtns[wnd.uiData.id][key] == nil then
  369. funcBtns[wnd.uiData.id][key] = {}
  370. end
  371. funcBtns[wnd.uiData.id][key]["target"] = target
  372. funcBtns[wnd.uiData.id][key]["data"] = data
  373. funcBtns[wnd.uiData.id][key]["lockBtn"] = lockBtn
  374. funcBtns[wnd.uiData.id][key]["needGuide"] = data.NeedGuide
  375. if not result and not guideState then
  376. self:SaveLockBubbleStatus(data.Id, data.NeedGuide)
  377. end
  378. local lockBubble = target.transform:Find("LockBubbleItem")
  379. if result and funcBtns[wnd.uiData.id][key]["needGuide"] then
  380. if lockBubble == nil then
  381. lockBubble = ManagerContainer.ResMgr:GetGoFromPool(Constants.UICommonPath, "LockBubbleItem")
  382. lockBubble.name = "LockBubbleItem"
  383. lockBubble.transform:SetParent(target.transform)
  384. lockBubble.transform.localPosition = Vector3.zero
  385. lockBubble.transform.localScale = Vector3.one
  386. local canvas = lockBubble:GetComponent(Enum.TypeInfo.Canvas)
  387. if canvas then
  388. canvas.overrideSorting = true
  389. canvas.sortingOrder = Enum.UISibling[Enum.UIType.MAIN + 1] - 1
  390. end
  391. InitTitle(lockBubble, targetButtonField, targetTitle, I18N.T(data.FunName))
  392. local light = lockBubble.transform:Find("BtnLightItem")
  393. light.transform.position = targetTitle.transform.position
  394. local talk = lockBubble.transform:Find("Talk")
  395. local vec2 = data.DscPos and Vector2(data.DscPos[1], data.DscPos[2]) or Vector2.zero
  396. talk:GetComponent(Enum.TypeInfo.RectTransform).anchoredPosition = vec2
  397. local arrowUp = talk.transform:Find("bg/upArrow")
  398. local arrowDown = talk.transform:Find("bg/downArrow")
  399. local arrowLeft = talk.transform:Find("bg/leftArrow")
  400. local arrowRight = talk.transform:Find("bg/rightArrow")
  401. arrowUp.gameObject:SetActive(data.ArrowDir == 1)
  402. arrowDown.gameObject:SetActive(data.ArrowDir == 2)
  403. arrowLeft.gameObject:SetActive(data.ArrowDir == 3)
  404. arrowRight.gameObject:SetActive(data.ArrowDir == 4)
  405. local talkContent = talk.transform:Find("bg/Text")
  406. talkContent:GetComponent(Enum.TypeInfo.Text).text = I18N.T(data.LockDsc)
  407. end
  408. local lockButton = lockBubble.gameObject:GetOrAddComponent(Enum.TypeInfo.Button)
  409. if lockButton then
  410. wnd.uiBase:AddButtonUniqueEventListener(lockButton, wnd, function (button, params)
  411. if target then
  412. self:SaveLockBubbleStatus(data.Id, false)
  413. target:SetActive(true)
  414. local lockBtn = funcBtns[wnd.uiData.id][key]["lockBtn"]
  415. if lockBtn then
  416. lockBtn.gameObject:SetActive(false)
  417. end
  418. local lockBubble = funcBtns[wnd.uiData.id][key]["lockBubble"]
  419. if lockBubble then
  420. lockBubble.gameObject:SetActive(false)
  421. end
  422. targetTitle.gameObject:SetActive(true)
  423. curOpened[#curOpened + 1] = data.Id
  424. local button1 = target:GetComponent(Enum.TypeInfo.Button)
  425. if button1 then
  426. button1.onClick:Invoke()
  427. end
  428. local nextFuncData = ManagerContainer.CfgMgr:GetUIFuncUnLockCfgDataById(data.PostPose)
  429. if nextFuncData and wnd.uiData.id == nextFuncData.UIId then
  430. self:InsertFuncController(wnd, nextFuncData)
  431. end
  432. funcBtns[wnd.uiData.id][key] = nil
  433. end
  434. end)
  435. end
  436. lockBubble.gameObject:SetActive(true)
  437. else
  438. if lockBubble then
  439. lockBubble.gameObject:SetActive(false)
  440. end
  441. end
  442. funcBtns[wnd.uiData.id][key]["lockBubble"] = lockBubble
  443. end
  444. function UIFuncUnlockMgr:UICloseCompeleted(wnd)
  445. if funcBtns[wnd.uiData.id] == nil then return end
  446. for k, v in pairs(funcBtns[wnd.uiData.id]) do
  447. v["target"] = nil
  448. --v["data"] = nil
  449. v["lock"] = nil
  450. v["lockBtn"] = nil
  451. v["lockBubble"] = nil
  452. end
  453. end
  454. ---通关关卡后的解锁通知
  455. function UIFuncUnlockMgr:UINewLevelFuncOpen(type)
  456. self:SaveNeedDisplayNewFuncStatus(true)
  457. self:UIFuncOpen(type)
  458. end
  459. function UIFuncUnlockMgr:UIFuncOpen(type)
  460. for k, v in pairs(funcBtns) do
  461. for k1,v1 in pairs(v) do
  462. if v1.target and not v1.data.IsOperations then
  463. local result = self:CheckConditionPassResult(v1.data)
  464. if result then
  465. v1.target:SetActive(true)
  466. local button1 = v1.target:GetComponent(Enum.TypeInfo.Button)
  467. if button1 then
  468. local image = v1.target:GetComponent(Enum.TypeInfo.Image)
  469. if image then
  470. image.raycastTarget = true
  471. end
  472. else
  473. button1 = v1.target:GetComponent(Enum.TypeInfo.Toggle)
  474. if button1 then
  475. button1.graphic.raycastTarget = true
  476. end
  477. end
  478. if not v1.data.Special then
  479. if v1.lock then
  480. local lockBtn = v1.lock:Find("btn")
  481. local lockBubble = v1.lock:Find("bubble")
  482. if lockBtn then
  483. lockBtn.gameObject:SetActive(false)
  484. end
  485. if lockBubble then
  486. lockBubble.gameObject:SetActive(v1["needGuide"])
  487. end
  488. v1.lock.gameObject:SetActive(v1["needGuide"] and v1.data.NeedLock)
  489. end
  490. else
  491. if v1.lock then
  492. local lockBtn = v1.lockBtn
  493. local lockBubble = v1.lockBubble
  494. if lockBtn then
  495. lockBtn.gameObject:SetActive(false)
  496. end
  497. if lockBubble then
  498. lockBubble.gameObject:SetActive(v1["needGuide"])
  499. end
  500. local targetTitle = v1.target.transform:Find("Title")
  501. targetTitle.gameObject:SetActive(not v1["needGuide"])
  502. end
  503. end
  504. if not v1["needGuide"] then
  505. curOpened[#curOpened + 1] = v1["data"].Id
  506. end
  507. v1["target"] = nil
  508. --v1["data"] = nil
  509. v1["lock"] = nil
  510. v1["lockBtn"] = nil
  511. v1["lockBubble"] = nil
  512. end
  513. end
  514. end
  515. end
  516. end
  517. function UIFuncUnlockMgr:GetTargetFuncLockStatus(wnd, target)
  518. if funcBtns[wnd.uiData.id] == nil then return false end
  519. for k, v in pairs(funcBtns[wnd.uiData.id]) do
  520. if v["target"] == target then
  521. return true
  522. end
  523. end
  524. return false
  525. end
  526. --获得是否已经解锁
  527. function UIFuncUnlockMgr:GetFuncLockStatusById(id, keepSrcContent)
  528. local data = ManagerContainer.CfgMgr:GetUIFuncUnLockCfgDataById(id)
  529. if data == nil then
  530. return true
  531. end
  532. if data.PrePose > 0 and CommonUtil.EleInTable(data.PrePose, curOpened) and CommonUtil.EleInTable(data.Id, curOpened) then
  533. return false
  534. end
  535. local result, val, content = self:CheckConditionPassResult(data)
  536. if not result and content and not keepSrcContent then
  537. content = content..I18N.T(data.FunName)..I18N.T("Fun")
  538. end
  539. return result, val, content
  540. end
  541. function UIFuncUnlockMgr:GetNewFuncAndNearFuncByLevelId(levelId)
  542. self:SaveNeedDisplayNewFuncStatus(false)
  543. local newFuncs, nearFuncs, forceGuideList = ManagerContainer.CfgMgr:GetUIFuncUnLockCfgNewAndNearLevelId(levelId)
  544. return newFuncs, nearFuncs, forceGuideList
  545. end
  546. function UIFuncUnlockMgr:CheckConditionPassResult(data)
  547. local conds = data.UnlockCond
  548. if not conds then
  549. return true, 0, ''
  550. end
  551. local result, val, content
  552. if data.LuaCondition and data.LuaCondition ~= "" then
  553. result = false
  554. local luaCondition = require("FuncUnlockCondition/"..data.LuaCondition)
  555. if luaCondition.CheckCondition then
  556. result, val, content = luaCondition:CheckCondition(data)
  557. end
  558. else
  559. result = true
  560. local result1, val1, content1
  561. for i = 1, #conds do
  562. local cond = conds[i]
  563. if cond then
  564. result1, val1, content1 = ConditionJudge:ConditionPassResult1(cond)
  565. if not result1 then
  566. result = false
  567. if content1 and content1 ~= '' then
  568. val = val1
  569. content = content1
  570. break
  571. end
  572. end
  573. end
  574. end
  575. end
  576. return result, val, content
  577. end
  578. function UIFuncUnlockMgr:Clear()
  579. --self:AutoSaveBubbleLockState()
  580. funcBtns = nil
  581. lockLevels = nil
  582. curOpened = nil
  583. end
  584. function UIFuncUnlockMgr:AutoSaveBubbleLockState()
  585. for _,v in pairs(funcBtns) do
  586. for _,v1 in pairs(v) do
  587. self:SaveLockBubbleStatus(v1.data.Id, false)
  588. end
  589. end
  590. end
  591. function UIFuncUnlockMgr:Destroy()
  592. ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.UI_FILLCONTENT_COMPELETED, self, self.FillContentCompeleted)
  593. ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.UI_CLOSE_COMPELETED, self, self.UICloseCompeleted)
  594. ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.UI_FUNCLOCK_OPEN_NTF, self, self.UIFuncOpen)
  595. self:Clear()
  596. if tolua.getpeer(self) ~= nil then
  597. tolua.setpeer(self, nil)
  598. end
  599. end
  600. return UIFuncUnlockMgr