MainPropertyLayout.lua 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. local MainPropertyLayout =class("MainPropertyLayout", function()
  2. return cc.Node:create()
  3. end)
  4. local RichTextHelp = requireUtil("RichTextHelp")
  5. function MainPropertyLayout:ctor()
  6. self._quickUseCells = {}
  7. self._miniChatWidth = nil
  8. self._showLastChatExID = nil -- 固定聊天最后显示的id
  9. end
  10. function MainPropertyLayout.create()
  11. local layout = MainPropertyLayout.new()
  12. if layout:Init() then
  13. return layout
  14. end
  15. return nil
  16. end
  17. function MainPropertyLayout:Init()
  18. self._quickUI = ui_delegate(self)
  19. local ChatProxy = global.Facade:retrieveProxy(global.ProxyTable.Chat)
  20. self._listInterval, self._richVspace = ChatProxy:GetChatParam()
  21. return true
  22. end
  23. function MainPropertyLayout:InitGUI( ... )
  24. SL:RequireFile(SLDefine.LUAFile.LUA_FILE_MAIN_PROPERTY)
  25. MainProperty.main()
  26. self:InitMiniChat()
  27. self:InitEditMode()
  28. end
  29. function MainPropertyLayout:InitEditMode()
  30. local items =
  31. {
  32. "Panel_mini_chat",
  33. "Image_minichat_bg",
  34. "ListView_minichat",
  35. "ListView_chat_ex",
  36. "Panel_mini_chat_touch",
  37. "Image_4",
  38. "Image_14",
  39. "Image_14_0",
  40. "Image_14_0_0",
  41. "Image_17",
  42. "Image_17_0",
  43. "Image_19",
  44. "LoadingBar_exp",
  45. "Panel_hp",
  46. "Text_hp",
  47. "Text_mp",
  48. "Text_level",
  49. "Text_time",
  50. "Text_exp",
  51. "Image_1",
  52. "Panel_bubble_tips",
  53. "Panel_auto_tips",
  54. "Panel_quick_use_1",
  55. "Panel_quick_use_2",
  56. "Panel_quick_use_3",
  57. "Panel_quick_use_4",
  58. "Panel_quick_use_5",
  59. "Panel_quick_use_6",
  60. "btn_rein_add",
  61. "Image_divide",
  62. "LoadingBar_hp",
  63. "LoadingBar_mp",
  64. "LoadingBar_fhp",
  65. "Image_net",
  66. "Image_battery",
  67. "LoadingBar_battery",
  68. "Image_barbg",
  69. "Image_2",
  70. "Image_bar",
  71. "Button_chat_hide",
  72. "Node_quit_tip",
  73. "Text_FPS",
  74. }
  75. for _, widgetName in ipairs(items) do
  76. if self._quickUI[widgetName] then
  77. self._quickUI[widgetName].editMode = 1
  78. end
  79. end
  80. end
  81. function MainPropertyLayout:InitMiniChat()
  82. self._layoutMiniChat = self._quickUI["Panel_mini_chat"]
  83. self._imageMiniChatBG = self._quickUI["Image_minichat_bg"]
  84. self._listviewMiniChat = self._quickUI["ListView_minichat"]
  85. self._listviewChatEx = self._quickUI["ListView_chat_ex"]
  86. if self._listInterval then
  87. self._listviewMiniChat:setItemsMargin(self._listInterval)
  88. self._listviewChatEx:setItemsMargin(self._listInterval)
  89. end
  90. self:SetMiniChatWidth()
  91. end
  92. function MainPropertyLayout:GetMiniChatWidth()
  93. return self._miniChatWidth
  94. end
  95. function MainPropertyLayout:SetMiniChatWidth()
  96. if self._quickUI.ListView_minichat then
  97. self._miniChatWidth = self._quickUI.ListView_minichat:getContentSize().width
  98. end
  99. end
  100. function MainPropertyLayout:PushMiniChatCell(cell)
  101. if not self._listviewMiniChat then
  102. return
  103. end
  104. self._listviewMiniChat:pushBackCustomItem(cell)
  105. -- 超出限制,移除先放入的
  106. local limitSize = SL:GetMetaValue("GAME_DATA", "MobileMainMaxChatNum") or 7
  107. if #self._listviewMiniChat:getItems() > limitSize then
  108. self._listviewMiniChat:removeItem(0)
  109. end
  110. self._listviewMiniChat:jumpToBottom()
  111. end
  112. function MainPropertyLayout:OnRemoveItem(uid)
  113. if not uid then
  114. return
  115. end
  116. local items = self._listviewMiniChat:getItems()
  117. for i, item in ipairs(items) do
  118. if item and item.tag == uid then
  119. local index = self._listviewMiniChat:getIndex(item)
  120. self._listviewMiniChat:removeItem(index)
  121. self._listviewMiniChat:doLayout()
  122. end
  123. end
  124. local innerSize = self._listviewMiniChat:getInnerContainerSize()
  125. local contentSize = self._listviewMiniChat:getContentSize()
  126. self._listviewMiniChat:jumpToBottom()
  127. end
  128. function MainPropertyLayout:OnShowChatExNotice(data)
  129. self:CheckChatExNotice()
  130. end
  131. function MainPropertyLayout:CheckChatExNotice( showChatExId )
  132. if not self._listviewChatEx then
  133. return
  134. end
  135. local exList = self._listviewChatEx
  136. if #exList:getItems() >= 3 then
  137. return
  138. end
  139. local proxy = global.Facade:retrieveProxy(global.ProxyTable.Chat)
  140. local chatExItms = proxy:GetChatExItemsData()
  141. if #chatExItms == 0 then
  142. self._showLastChatExID = nil
  143. return
  144. end
  145. local chatExId = self._showLastChatExID and (self._showLastChatExID + 1) or 1
  146. local data = chatExItms[chatExId]
  147. if not data then
  148. return
  149. end
  150. self._showLastChatExID = chatExId
  151. data.Time = data.Time or 5
  152. if data.Time <= 0 then
  153. proxy:RemoveChatExItemsData(data, self._showLastChatExID)
  154. self._showLastChatExID = self._showLastChatExID - 1
  155. self:CheckChatExNotice()
  156. return
  157. end
  158. data.Label = data.Label or ""
  159. data.Y = data.Y or 0
  160. data.Count = data.Count or 1
  161. data.FColor = data.FColor or 255
  162. data.BColor = data.BColor or 255
  163. data.SendNameTemp = data.SendName or ""
  164. local FColorRGB = GET_COLOR_BYID_C3B(data.FColor)
  165. local BColorRGB = GET_COLOR_BYID_C3B(data.BColor)
  166. local BColorEnabel = data.BColor ~= -1
  167. local cWidth = exList:getContentSize().width
  168. local capacitySize = cc.size(cWidth, 17)
  169. local function resetListview()
  170. local items = exList:getItems()
  171. local height = 0
  172. local margin = exList:getItemsMargin()
  173. for i, v in ipairs(items) do
  174. local interval = i ~= #items and margin or 0
  175. height = height + v:getContentSize().height + interval
  176. end
  177. exList:setContentSize(cc.size(capacitySize.width, height))
  178. local contentSize = self._layoutMiniChat:getContentSize()
  179. local listviewSize = self._listviewMiniChat:getContentSize()
  180. self._listviewMiniChat:setContentSize(cc.size(listviewSize.width, contentSize.height-height))
  181. self._listviewMiniChat:jumpToBottom()
  182. end
  183. local layout = ccui.Layout:create()
  184. layout:setContentSize(capacitySize)
  185. if BColorEnabel then
  186. layout:setBackGroundColor(BColorRGB)
  187. layout:setBackGroundColorType(0)
  188. layout:setBackGroundColorOpacity(255)
  189. end
  190. exList:pushBackCustomItem(layout)
  191. resetListview()
  192. local scrollWidget = ccui.Widget:create()
  193. layout:addChild(scrollWidget)
  194. scrollWidget:setContentSize(capacitySize)
  195. scrollWidget:setAnchorPoint(cc.p(0,0))
  196. scrollWidget:setPosition(cc.p(0,0))
  197. local scrollAble = nil
  198. local scrollSize = cc.size(0,0)
  199. local remaining = data.Time
  200. local Msg = Msg_formatPercent(data.Msg)
  201. local hasFormat = string.find(Msg,"%%")
  202. local showName = data.SendName and (data.SendName .. ": ") or ""
  203. local function callback()
  204. remaining = math.min(remaining, data.Time)
  205. proxy:SyncChatExItemsTime(self._showLastChatExID, data.chatExId, remaining)
  206. local name = showName or ""
  207. local str = name..(hasFormat and string.format(Msg, remaining) or Msg)
  208. local fontSize = SL:GetMetaValue("GAME_DATA","DEFAULT_FONT_SIZE") or 16
  209. local richText = RichTextHelp:CreateRichTextWithFCOLOR(str, 1000, fontSize, FColorRGB, {outlineSize = 0}, nil, self._richVspace or 0)
  210. richText:setTouchEnabled(true)
  211. richText:addClickEventListener(function()
  212. if data.SendName and data.SendId then
  213. global.Facade:sendNotification(global.NoticeTable.PrivateChatWithTarget, {name = data.SendNameTemp, uid = data.SendId})
  214. end
  215. end)
  216. scrollWidget:removeAllChildren()
  217. scrollWidget:addChild(richText)
  218. richText:setAnchorPoint({x=0, y=0.5})
  219. richText:setPosition(cc.p(0, capacitySize.height/2))
  220. if BColorEnabel then
  221. richText:setBackgroundColor(BColorRGB)
  222. richText:setBackgroundColorEnable(true)
  223. end
  224. if scrollAble == nil then
  225. richText:formatText()
  226. scrollSize = richText:getContentSize()
  227. scrollAble = scrollSize.width > capacitySize.width
  228. end
  229. local richSize = richText:getContentSize()
  230. scrollWidget:setContentSize(capacitySize.width,richSize.height)
  231. layout:setContentSize(capacitySize.width,richSize.height)
  232. if remaining < 0 then
  233. exList:removeItem(exList:getIndex(layout))
  234. resetListview()
  235. proxy:RemoveChatExItemsData(data, self._showLastChatExID)
  236. self._showLastChatExID = self._showLastChatExID - 1
  237. self:CheckChatExNotice()
  238. end
  239. remaining = remaining - 1
  240. end
  241. schedule(layout, callback, 1)
  242. callback()
  243. -- 滚动
  244. if scrollAble then
  245. local actionT = (scrollSize.width - capacitySize.width) / 50
  246. local action = cc.Sequence:create(
  247. cc.MoveTo:create(actionT, cc.p(capacitySize.width - scrollSize.width, 0)),
  248. cc.DelayTime:create(3),
  249. cc.MoveTo:create(0, cc.p(0, 0))
  250. )
  251. scrollWidget:runAction(cc.RepeatForever:create(action))
  252. end
  253. end
  254. ------------
  255. function MainPropertyLayout:InitQuickUse()
  256. local showNum = 0
  257. if self._quickUI.Panel_quick_use and self._quickUI.Panel_quick_use:isVisible() then
  258. for i = 1, 6 do
  259. local layout = self._quickUI[string.format("Panel_quick_use_%s", i)]
  260. if layout and layout:isVisible() then
  261. showNum = showNum + 1
  262. local cell = self:CreateQuickUseCell(layout, {index = i})
  263. self._quickUseCells[i] = cell
  264. end
  265. end
  266. end
  267. SL:SetMetaValue("QUICK_USE_NUM", showNum)
  268. self:UpdateQuickUse()
  269. end
  270. function MainPropertyLayout:UpdateQuickUse()
  271. for k, v in pairs(self._quickUseCells) do
  272. v.nodeItem:removeAllChildren()
  273. end
  274. local QuickUseProxy = global.Facade:retrieveProxy(global.ProxyTable.QuickUseProxy)
  275. local quickUseData = QuickUseProxy:GetQuickUseData()
  276. for k, v in pairs(quickUseData) do
  277. self:AddQuickUseItem({index = k, itemData = v})
  278. end
  279. end
  280. function MainPropertyLayout:AddQuickUseItem(data)
  281. local cell = self._quickUseCells[data.index]
  282. local function dealSpecialQuickUse()
  283. local index = data.index
  284. local QuickUseProxy = global.Facade:retrieveProxy(global.ProxyTable.QuickUseProxy)
  285. local size = QuickUseProxy:GetQuickUseSize()
  286. local quickUseData = QuickUseProxy:GetQuickUseData()
  287. local quickUseList = QuickUseProxy:GetQuickUseLocalList()
  288. local replaceCell = nil
  289. for i = 1, size do
  290. if not quickUseData[i] and self._quickUseCells[i] and i ~= index then
  291. replaceCell = self._quickUseCells[i]
  292. cell = replaceCell
  293. quickUseData[i] = quickUseData[index]
  294. quickUseData[index] = nil
  295. quickUseList[i] = quickUseList[index]
  296. quickUseList[index] = 0
  297. QuickUseProxy:SetQuickPosMarkData()
  298. break
  299. end
  300. end
  301. -- 无替代则放回背包
  302. if not replaceCell then
  303. local bagProxy = global.Facade:retrieveProxy( global.ProxyTable.Bag )
  304. local item = data.itemData
  305. bagProxy:AddItemData(item)
  306. --清数据
  307. quickUseList[index] = 0
  308. QuickUseProxy:SetQuickPosMarkData()
  309. return true
  310. end
  311. end
  312. if not cell then
  313. if dealSpecialQuickUse() then
  314. return
  315. end
  316. end
  317. cell.nodeItem:removeAllChildren()
  318. local function getCount(item)
  319. if item.OverLap > 1 then
  320. return item.OverLap
  321. end
  322. if item.StdMode == 2 and item.Dura > 0 then --使用次数
  323. return item.Dura < 1000 and 1 or math.floor(item.Dura / 1000) --小于1000都为1;大于1000向下取整
  324. end
  325. return 0
  326. end
  327. local ItemMoveProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemMoveProxy)
  328. local info = {}
  329. info.from = ItemMoveProxy.ItemFrom.QUICK_USE
  330. info.movable = true
  331. info.index = data.itemData.Index
  332. info.itemData = data.itemData
  333. local item = GoodsItem:create(info)
  334. cell.nodeItem:addChild(item)
  335. item:setCount(getCount(data.itemData))
  336. item:addTouchEventListener(function()
  337. if cell.nodeItem.touching then
  338. return
  339. end
  340. cell.nodeItem.touching = true
  341. SL:RequestUseItem(data.itemData)
  342. performWithDelay(cell.nodeItem, function(sender)
  343. sender.touching = nil
  344. end, 0.3)
  345. end, 2)
  346. cell.item = item
  347. end
  348. function MainPropertyLayout:RmvQuickUseItem(data)
  349. local cell = self._quickUseCells[data.index]
  350. if not cell then
  351. return
  352. end
  353. cell.nodeItem:removeAllChildren()
  354. end
  355. function MainPropertyLayout:ChangeQuickUseItem(data)
  356. self:RmvQuickUseItem(data)
  357. self:AddQuickUseItem(data)
  358. end
  359. function MainPropertyLayout:RefreshQuickUseItem(data)
  360. local cell = self._quickUseCells[data.pos]
  361. if not cell then
  362. return
  363. end
  364. cell.item:resetMoveState(data.state == 0)
  365. end
  366. function MainPropertyLayout:CreateQuickUseCell(parent, data)
  367. if MainProperty and MainProperty.CreateQuickUseCell then
  368. MainProperty.CreateQuickUseCell(parent)
  369. end
  370. local layout = parent:getChildByName("Panel_cell")
  371. if not layout then
  372. return
  373. end
  374. local imageBG = layout:getChildByName("Image_bg")
  375. local nodeItem = layout:getChildByName("Node_item")
  376. local layoutQuick = layout:getChildByName("Panel_quick")
  377. layout:addClickEventListener(function()
  378. local QuickUseProxy = global.Facade:retrieveProxy(global.ProxyTable.QuickUseProxy)
  379. local quickUseItem = QuickUseProxy:GetQucikUseDataByPos(data.index)
  380. if not quickUseItem then
  381. return nil
  382. end
  383. SL:RequestUseItem(quickUseItem)
  384. end)
  385. local function addItemIntoBag(touchPos)
  386. local ItemMoveProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemMoveProxy)
  387. local state = ItemMoveProxy:GetMovingItemState()
  388. if state then
  389. local goToName = ItemMoveProxy.ItemGoTo.QUICK_USE
  390. local ndata = {}
  391. ndata.target = goToName
  392. ndata.pos = touchPos
  393. ndata.posInQuickUse = data.index
  394. ItemMoveProxy:CheckAndCallBack( ndata )
  395. else
  396. return -1
  397. end
  398. end
  399. local function setNoswallowMouse()
  400. return -1
  401. end
  402. global.mouseEventController:registerMouseButtonEvent(
  403. layoutQuick,
  404. {
  405. down_r = setNoswallowMouse,
  406. special_r = addItemIntoBag
  407. }
  408. )
  409. return {
  410. layout = layout,
  411. nodeItem = nodeItem,
  412. }
  413. end
  414. ---------------
  415. function MainPropertyLayout:OnAddQuitTimeTips( data )
  416. if not data or not data.time or not data.type then
  417. return
  418. end
  419. local time
  420. local type = data.type -- 1 小退 2 大退
  421. if self._quickUI.Node_quit_tip then
  422. self._quickUI.Node_quit_tip:stopAllActions()
  423. local function refreshTime()
  424. if not time then
  425. time = data.time
  426. else
  427. time = time - 1
  428. end
  429. local str = string.format(GET_STRING(700000110 + type), time)
  430. self._quickUI.Node_quit_tip:removeAllChildren()
  431. local width = global.Director:getVisibleSize().width
  432. local richText = RichTextHelp:CreateRichTextWithXML(str, width, SL:GetMetaValue("GAME_DATA","DEFAULT_FONT_SIZE") or 16, "#ffffff")
  433. richText:setAnchorPoint(0.5, 0)
  434. richText:formatText()
  435. self._quickUI.Node_quit_tip:addChild(richText)
  436. end
  437. schedule(self._quickUI.Node_quit_tip, refreshTime, 1)
  438. refreshTime()
  439. end
  440. end
  441. function MainPropertyLayout:OnRemoveQuitTimeTips()
  442. if self._quickUI.Node_quit_tip then
  443. self._quickUI.Node_quit_tip:stopAllActions()
  444. self._quickUI.Node_quit_tip:removeAllChildren()
  445. end
  446. end
  447. function MainPropertyLayout:OnMainExChatClean()
  448. if self._listviewChatEx then
  449. self._listviewChatEx:stopAllActions()
  450. self._listviewChatEx:removeAllItems()
  451. self._showLastChatExID = nil
  452. end
  453. end
  454. function MainPropertyLayout:OnRefreshMobileAutoShout(data)
  455. if data and data.openChat and self._fristCheckAuto then
  456. return
  457. end
  458. if not self._fristCheckAuto then
  459. self._fristCheckAuto = true
  460. end
  461. local ChatProxy = global.Facade:retrieveProxy(global.ProxyTable.Chat)
  462. local isOpen = ChatProxy:GetAutoShoutSwitch()
  463. if not isOpen then
  464. self._layoutMiniChat:stopActionByTag(888)
  465. return
  466. end
  467. local shoutInput = ChatProxy:getLocalChatDataData(ChatProxy.CHANNEL.Shout)
  468. if not shoutInput or shoutInput == "" then
  469. return
  470. end
  471. -- 发送
  472. local function sendChatMsg(input, channel)
  473. if not channel or not ChatProxy:CheckAbleToSay(channel) then
  474. return
  475. end
  476. local MSG_TYPE = ChatProxy.MSG_TYPE
  477. local sendData = {mt = MSG_TYPE.Normal, msg = input, channel = channel, risk = 0, oriMsg = input, status = 0}
  478. global.Facade:sendNotification(global.NoticeTable.SendChatMsg, sendData)
  479. end
  480. -- 自动喊话开关
  481. local autoShoutCallback = nil
  482. autoShoutCallback = function(shoutInput)
  483. self._layoutMiniChat:stopActionByTag(888)
  484. if not shoutInput or shoutInput == "" then
  485. return
  486. end
  487. if not ChatProxy:GetAutoShoutSwitch() then
  488. return
  489. end
  490. local delay = ChatProxy:GetAutoShoutDelay()
  491. local action = schedule(self._layoutMiniChat, function()
  492. -- 发送
  493. sendChatMsg(shoutInput, ChatProxy.CHANNEL.Shout)
  494. end, delay)
  495. action:setTag(888)
  496. --
  497. sendChatMsg(shoutInput, ChatProxy.CHANNEL.Shout)
  498. end
  499. autoShoutCallback(shoutInput)
  500. end
  501. function MainPropertyLayout:AfterCUILoadFunc()
  502. self:SetMiniChatWidth()
  503. self:InitQuickUse()
  504. end
  505. return MainPropertyLayout