| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577 |
- local MainPropertyLayout =class("MainPropertyLayout", function()
- return cc.Node:create()
- end)
- local RichTextHelp = requireUtil("RichTextHelp")
- function MainPropertyLayout:ctor()
- self._quickUseCells = {}
- self._miniChatWidth = nil
- self._showLastChatExID = nil -- 固定聊天最后显示的id
- end
- function MainPropertyLayout.create()
- local layout = MainPropertyLayout.new()
- if layout:Init() then
- return layout
- end
- return nil
- end
- function MainPropertyLayout:Init()
- self._quickUI = ui_delegate(self)
- local ChatProxy = global.Facade:retrieveProxy(global.ProxyTable.Chat)
- self._listInterval, self._richVspace = ChatProxy:GetChatParam()
- return true
- end
- function MainPropertyLayout:InitGUI( ... )
- SL:RequireFile(SLDefine.LUAFile.LUA_FILE_MAIN_PROPERTY)
- MainProperty.main()
- self:InitMiniChat()
- self:InitEditMode()
- end
- function MainPropertyLayout:InitEditMode()
- local items =
- {
- "Panel_mini_chat",
- "Image_minichat_bg",
- "ListView_minichat",
- "ListView_chat_ex",
- "Panel_mini_chat_touch",
- "Image_4",
- "Image_14",
- "Image_14_0",
- "Image_14_0_0",
- "Image_17",
- "Image_17_0",
- "Image_19",
- "LoadingBar_exp",
- "Panel_hp",
- "Text_hp",
- "Text_mp",
- "Text_level",
- "Text_time",
- "Text_exp",
- "Image_1",
- "Panel_bubble_tips",
- "Panel_auto_tips",
- "Panel_quick_use_1",
- "Panel_quick_use_2",
- "Panel_quick_use_3",
- "Panel_quick_use_4",
- "Panel_quick_use_5",
- "Panel_quick_use_6",
- "btn_rein_add",
- "Image_divide",
- "LoadingBar_hp",
- "LoadingBar_mp",
- "LoadingBar_fhp",
- "Image_net",
- "Image_battery",
- "LoadingBar_battery",
- "Image_barbg",
- "Image_2",
- "Image_bar",
- "Button_chat_hide",
- "Node_quit_tip",
- "Text_FPS",
- }
- for _, widgetName in ipairs(items) do
- if self._quickUI[widgetName] then
- self._quickUI[widgetName].editMode = 1
- end
- end
- end
- function MainPropertyLayout:InitMiniChat()
- self._layoutMiniChat = self._quickUI["Panel_mini_chat"]
- self._imageMiniChatBG = self._quickUI["Image_minichat_bg"]
- self._listviewMiniChat = self._quickUI["ListView_minichat"]
- self._listviewChatEx = self._quickUI["ListView_chat_ex"]
- if self._listInterval then
- self._listviewMiniChat:setItemsMargin(self._listInterval)
- self._listviewChatEx:setItemsMargin(self._listInterval)
- end
- self:SetMiniChatWidth()
- end
- function MainPropertyLayout:GetMiniChatWidth()
- return self._miniChatWidth
- end
- function MainPropertyLayout:SetMiniChatWidth()
- if self._quickUI.ListView_minichat then
- self._miniChatWidth = self._quickUI.ListView_minichat:getContentSize().width
- end
- end
- function MainPropertyLayout:PushMiniChatCell(cell)
- if not self._listviewMiniChat then
- return
- end
- self._listviewMiniChat:pushBackCustomItem(cell)
- -- 超出限制,移除先放入的
- local limitSize = SL:GetMetaValue("GAME_DATA", "MobileMainMaxChatNum") or 7
- if #self._listviewMiniChat:getItems() > limitSize then
- self._listviewMiniChat:removeItem(0)
- end
- self._listviewMiniChat:jumpToBottom()
- end
- function MainPropertyLayout:OnRemoveItem(uid)
- if not uid then
- return
- end
-
- local items = self._listviewMiniChat:getItems()
- for i, item in ipairs(items) do
- if item and item.tag == uid then
- local index = self._listviewMiniChat:getIndex(item)
- self._listviewMiniChat:removeItem(index)
- self._listviewMiniChat:doLayout()
- end
- end
- local innerSize = self._listviewMiniChat:getInnerContainerSize()
- local contentSize = self._listviewMiniChat:getContentSize()
- self._listviewMiniChat:jumpToBottom()
- end
-
- function MainPropertyLayout:OnShowChatExNotice(data)
- self:CheckChatExNotice()
- end
- function MainPropertyLayout:CheckChatExNotice( showChatExId )
- if not self._listviewChatEx then
- return
- end
- local exList = self._listviewChatEx
- if #exList:getItems() >= 3 then
- return
- end
-
- local proxy = global.Facade:retrieveProxy(global.ProxyTable.Chat)
- local chatExItms = proxy:GetChatExItemsData()
- if #chatExItms == 0 then
- self._showLastChatExID = nil
- return
- end
- local chatExId = self._showLastChatExID and (self._showLastChatExID + 1) or 1
- local data = chatExItms[chatExId]
- if not data then
- return
- end
- self._showLastChatExID = chatExId
- data.Time = data.Time or 5
- if data.Time <= 0 then
- proxy:RemoveChatExItemsData(data, self._showLastChatExID)
- self._showLastChatExID = self._showLastChatExID - 1
- self:CheckChatExNotice()
- return
- end
- data.Label = data.Label or ""
- data.Y = data.Y or 0
- data.Count = data.Count or 1
- data.FColor = data.FColor or 255
- data.BColor = data.BColor or 255
- data.SendNameTemp = data.SendName or ""
- local FColorRGB = GET_COLOR_BYID_C3B(data.FColor)
- local BColorRGB = GET_COLOR_BYID_C3B(data.BColor)
- local BColorEnabel = data.BColor ~= -1
- local cWidth = exList:getContentSize().width
- local capacitySize = cc.size(cWidth, 17)
- local function resetListview()
- local items = exList:getItems()
- local height = 0
- local margin = exList:getItemsMargin()
- for i, v in ipairs(items) do
- local interval = i ~= #items and margin or 0
- height = height + v:getContentSize().height + interval
- end
- exList:setContentSize(cc.size(capacitySize.width, height))
- local contentSize = self._layoutMiniChat:getContentSize()
- local listviewSize = self._listviewMiniChat:getContentSize()
- self._listviewMiniChat:setContentSize(cc.size(listviewSize.width, contentSize.height-height))
- self._listviewMiniChat:jumpToBottom()
- end
- local layout = ccui.Layout:create()
- layout:setContentSize(capacitySize)
- if BColorEnabel then
- layout:setBackGroundColor(BColorRGB)
- layout:setBackGroundColorType(0)
- layout:setBackGroundColorOpacity(255)
- end
-
- exList:pushBackCustomItem(layout)
- resetListview()
- local scrollWidget = ccui.Widget:create()
- layout:addChild(scrollWidget)
- scrollWidget:setContentSize(capacitySize)
- scrollWidget:setAnchorPoint(cc.p(0,0))
- scrollWidget:setPosition(cc.p(0,0))
- local scrollAble = nil
- local scrollSize = cc.size(0,0)
- local remaining = data.Time
- local Msg = Msg_formatPercent(data.Msg)
- local hasFormat = string.find(Msg,"%%")
- local showName = data.SendName and (data.SendName .. ": ") or ""
- local function callback()
- remaining = math.min(remaining, data.Time)
- proxy:SyncChatExItemsTime(self._showLastChatExID, data.chatExId, remaining)
- local name = showName or ""
- local str = name..(hasFormat and string.format(Msg, remaining) or Msg)
- local fontSize = SL:GetMetaValue("GAME_DATA","DEFAULT_FONT_SIZE") or 16
- local richText = RichTextHelp:CreateRichTextWithFCOLOR(str, 1000, fontSize, FColorRGB, {outlineSize = 0}, nil, self._richVspace or 0)
- richText:setTouchEnabled(true)
- richText:addClickEventListener(function()
- if data.SendName and data.SendId then
- global.Facade:sendNotification(global.NoticeTable.PrivateChatWithTarget, {name = data.SendNameTemp, uid = data.SendId})
- end
- end)
- scrollWidget:removeAllChildren()
- scrollWidget:addChild(richText)
- richText:setAnchorPoint({x=0, y=0.5})
- richText:setPosition(cc.p(0, capacitySize.height/2))
- if BColorEnabel then
- richText:setBackgroundColor(BColorRGB)
- richText:setBackgroundColorEnable(true)
- end
-
- if scrollAble == nil then
- richText:formatText()
- scrollSize = richText:getContentSize()
- scrollAble = scrollSize.width > capacitySize.width
- end
- local richSize = richText:getContentSize()
- scrollWidget:setContentSize(capacitySize.width,richSize.height)
- layout:setContentSize(capacitySize.width,richSize.height)
- if remaining < 0 then
- exList:removeItem(exList:getIndex(layout))
- resetListview()
- proxy:RemoveChatExItemsData(data, self._showLastChatExID)
- self._showLastChatExID = self._showLastChatExID - 1
- self:CheckChatExNotice()
- end
- remaining = remaining - 1
- end
- schedule(layout, callback, 1)
- callback()
- -- 滚动
- if scrollAble then
- local actionT = (scrollSize.width - capacitySize.width) / 50
- local action = cc.Sequence:create(
- cc.MoveTo:create(actionT, cc.p(capacitySize.width - scrollSize.width, 0)),
- cc.DelayTime:create(3),
- cc.MoveTo:create(0, cc.p(0, 0))
- )
- scrollWidget:runAction(cc.RepeatForever:create(action))
- end
- end
- ------------
- function MainPropertyLayout:InitQuickUse()
- local showNum = 0
- if self._quickUI.Panel_quick_use and self._quickUI.Panel_quick_use:isVisible() then
- for i = 1, 6 do
- local layout = self._quickUI[string.format("Panel_quick_use_%s", i)]
- if layout and layout:isVisible() then
- showNum = showNum + 1
- local cell = self:CreateQuickUseCell(layout, {index = i})
- self._quickUseCells[i] = cell
- end
- end
- end
- SL:SetMetaValue("QUICK_USE_NUM", showNum)
- self:UpdateQuickUse()
- end
- function MainPropertyLayout:UpdateQuickUse()
- for k, v in pairs(self._quickUseCells) do
- v.nodeItem:removeAllChildren()
- end
- local QuickUseProxy = global.Facade:retrieveProxy(global.ProxyTable.QuickUseProxy)
- local quickUseData = QuickUseProxy:GetQuickUseData()
- for k, v in pairs(quickUseData) do
- self:AddQuickUseItem({index = k, itemData = v})
- end
- end
- function MainPropertyLayout:AddQuickUseItem(data)
- local cell = self._quickUseCells[data.index]
- local function dealSpecialQuickUse()
- local index = data.index
- local QuickUseProxy = global.Facade:retrieveProxy(global.ProxyTable.QuickUseProxy)
- local size = QuickUseProxy:GetQuickUseSize()
- local quickUseData = QuickUseProxy:GetQuickUseData()
- local quickUseList = QuickUseProxy:GetQuickUseLocalList()
- local replaceCell = nil
- for i = 1, size do
- if not quickUseData[i] and self._quickUseCells[i] and i ~= index then
- replaceCell = self._quickUseCells[i]
- cell = replaceCell
- quickUseData[i] = quickUseData[index]
- quickUseData[index] = nil
- quickUseList[i] = quickUseList[index]
- quickUseList[index] = 0
- QuickUseProxy:SetQuickPosMarkData()
- break
- end
- end
- -- 无替代则放回背包
- if not replaceCell then
- local bagProxy = global.Facade:retrieveProxy( global.ProxyTable.Bag )
- local item = data.itemData
- bagProxy:AddItemData(item)
-
- --清数据
- quickUseList[index] = 0
- QuickUseProxy:SetQuickPosMarkData()
- return true
- end
- end
- if not cell then
- if dealSpecialQuickUse() then
- return
- end
- end
-
- cell.nodeItem:removeAllChildren()
- local function getCount(item)
- if item.OverLap > 1 then
- return item.OverLap
- end
- if item.StdMode == 2 and item.Dura > 0 then --使用次数
- return item.Dura < 1000 and 1 or math.floor(item.Dura / 1000) --小于1000都为1;大于1000向下取整
- end
- return 0
- end
- local ItemMoveProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemMoveProxy)
- local info = {}
- info.from = ItemMoveProxy.ItemFrom.QUICK_USE
- info.movable = true
- info.index = data.itemData.Index
- info.itemData = data.itemData
- local item = GoodsItem:create(info)
- cell.nodeItem:addChild(item)
- item:setCount(getCount(data.itemData))
- item:addTouchEventListener(function()
- if cell.nodeItem.touching then
- return
- end
- cell.nodeItem.touching = true
- SL:RequestUseItem(data.itemData)
- performWithDelay(cell.nodeItem, function(sender)
- sender.touching = nil
- end, 0.3)
- end, 2)
- cell.item = item
- end
- function MainPropertyLayout:RmvQuickUseItem(data)
- local cell = self._quickUseCells[data.index]
- if not cell then
- return
- end
- cell.nodeItem:removeAllChildren()
- end
- function MainPropertyLayout:ChangeQuickUseItem(data)
- self:RmvQuickUseItem(data)
- self:AddQuickUseItem(data)
- end
- function MainPropertyLayout:RefreshQuickUseItem(data)
- local cell = self._quickUseCells[data.pos]
- if not cell then
- return
- end
- cell.item:resetMoveState(data.state == 0)
- end
- function MainPropertyLayout:CreateQuickUseCell(parent, data)
- if MainProperty and MainProperty.CreateQuickUseCell then
- MainProperty.CreateQuickUseCell(parent)
- end
- local layout = parent:getChildByName("Panel_cell")
- if not layout then
- return
- end
- local imageBG = layout:getChildByName("Image_bg")
- local nodeItem = layout:getChildByName("Node_item")
- local layoutQuick = layout:getChildByName("Panel_quick")
- layout:addClickEventListener(function()
- local QuickUseProxy = global.Facade:retrieveProxy(global.ProxyTable.QuickUseProxy)
- local quickUseItem = QuickUseProxy:GetQucikUseDataByPos(data.index)
- if not quickUseItem then
- return nil
- end
- SL:RequestUseItem(quickUseItem)
- end)
- local function addItemIntoBag(touchPos)
- local ItemMoveProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemMoveProxy)
- local state = ItemMoveProxy:GetMovingItemState()
- if state then
- local goToName = ItemMoveProxy.ItemGoTo.QUICK_USE
- local ndata = {}
- ndata.target = goToName
- ndata.pos = touchPos
- ndata.posInQuickUse = data.index
- ItemMoveProxy:CheckAndCallBack( ndata )
- else
- return -1
- end
- end
- local function setNoswallowMouse()
- return -1
- end
- global.mouseEventController:registerMouseButtonEvent(
- layoutQuick,
- {
- down_r = setNoswallowMouse,
- special_r = addItemIntoBag
- }
- )
- return {
- layout = layout,
- nodeItem = nodeItem,
- }
- end
- ---------------
- function MainPropertyLayout:OnAddQuitTimeTips( data )
- if not data or not data.time or not data.type then
- return
- end
- local time
- local type = data.type -- 1 小退 2 大退
- if self._quickUI.Node_quit_tip then
- self._quickUI.Node_quit_tip:stopAllActions()
- local function refreshTime()
- if not time then
- time = data.time
- else
- time = time - 1
- end
- local str = string.format(GET_STRING(700000110 + type), time)
- self._quickUI.Node_quit_tip:removeAllChildren()
- local width = global.Director:getVisibleSize().width
- local richText = RichTextHelp:CreateRichTextWithXML(str, width, SL:GetMetaValue("GAME_DATA","DEFAULT_FONT_SIZE") or 16, "#ffffff")
- richText:setAnchorPoint(0.5, 0)
- richText:formatText()
- self._quickUI.Node_quit_tip:addChild(richText)
- end
- schedule(self._quickUI.Node_quit_tip, refreshTime, 1)
- refreshTime()
- end
- end
- function MainPropertyLayout:OnRemoveQuitTimeTips()
- if self._quickUI.Node_quit_tip then
- self._quickUI.Node_quit_tip:stopAllActions()
- self._quickUI.Node_quit_tip:removeAllChildren()
- end
- end
- function MainPropertyLayout:OnMainExChatClean()
- if self._listviewChatEx then
- self._listviewChatEx:stopAllActions()
- self._listviewChatEx:removeAllItems()
- self._showLastChatExID = nil
- end
- end
- function MainPropertyLayout:OnRefreshMobileAutoShout(data)
- if data and data.openChat and self._fristCheckAuto then
- return
- end
- if not self._fristCheckAuto then
- self._fristCheckAuto = true
- end
- local ChatProxy = global.Facade:retrieveProxy(global.ProxyTable.Chat)
- local isOpen = ChatProxy:GetAutoShoutSwitch()
- if not isOpen then
- self._layoutMiniChat:stopActionByTag(888)
- return
- end
- local shoutInput = ChatProxy:getLocalChatDataData(ChatProxy.CHANNEL.Shout)
- if not shoutInput or shoutInput == "" then
- return
- end
- -- 发送
- local function sendChatMsg(input, channel)
- if not channel or not ChatProxy:CheckAbleToSay(channel) then
- return
- end
- local MSG_TYPE = ChatProxy.MSG_TYPE
- local sendData = {mt = MSG_TYPE.Normal, msg = input, channel = channel, risk = 0, oriMsg = input, status = 0}
- global.Facade:sendNotification(global.NoticeTable.SendChatMsg, sendData)
- end
- -- 自动喊话开关
- local autoShoutCallback = nil
- autoShoutCallback = function(shoutInput)
- self._layoutMiniChat:stopActionByTag(888)
- if not shoutInput or shoutInput == "" then
- return
- end
- if not ChatProxy:GetAutoShoutSwitch() then
- return
- end
- local delay = ChatProxy:GetAutoShoutDelay()
- local action = schedule(self._layoutMiniChat, function()
- -- 发送
- sendChatMsg(shoutInput, ChatProxy.CHANNEL.Shout)
- end, delay)
- action:setTag(888)
- --
- sendChatMsg(shoutInput, ChatProxy.CHANNEL.Shout)
- end
- autoShoutCallback(shoutInput)
- end
- function MainPropertyLayout:AfterCUILoadFunc()
- self:SetMiniChatWidth()
- self:InitQuickUse()
- end
- return MainPropertyLayout
|