chat_window.lua 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355
  1. -- 聊天界面
  2. -- author:cloud
  3. -- date:2016.12.27
  4. ChatWindow = ChatWindow or BaseClass(CommonUI)
  5. local ref_controller = RefController:getInstance()
  6. local chat_controller = ChatController:getInstance()
  7. local chat_model = ChatController:getInstance():getModel()
  8. function ChatWindow:__init(ctrl)
  9. self.view_tag = ViewMgrTag.TOP_TAG
  10. self.control_mode = false
  11. self.time = 0
  12. self.is_top = false
  13. self.requestList = {} -- 好友请求列表
  14. self.tab_btn_list = {} --标签页按钮列表
  15. self.cur_selected = nil
  16. self.role_vo = RoleController:getInstance():getRoleVo()
  17. self.item_desc_list = {}
  18. self.item_code_list = {}
  19. self.filt_is_show = false
  20. self.vip_is_show = (self.role_vo.is_show_vip == 1)
  21. self:loadResources()
  22. self:initHandle()
  23. end
  24. function ChatWindow:loadResources( )
  25. local res_path = {
  26. { path = PathTool.getPlistImgForDownLoad("face_icon", "face_icon"), type = ResourcesType.plist }
  27. }
  28. self.resources_load = ResourcesLoad.New(true)
  29. if self.resources_load then self.resources_load:addAllList(res_path) end
  30. end
  31. function ChatWindow:initHandle()
  32. --默认信息
  33. self.default_msg = TI18N("请输入信息...")
  34. self.find_msg = TI18N("点击查找好友")
  35. self:registerNotifier(true)
  36. self:createRootWnd()
  37. self:updateTabBar()
  38. self:initView()
  39. self:initCtrl()
  40. end
  41. function ChatWindow:updateTabBar()
  42. self.stack_tag =
  43. {
  44. [1] = ChatConst.Channel.World,
  45. [2] = ChatConst.Channel.Gang,
  46. [3] = ChatConst.Channel.Friend,
  47. [4] = ChatConst.Channel.Notice,
  48. [5] = ChatConst.Channel.Cross,
  49. [6] = ChatConst.Channel.Province,
  50. }
  51. self.stack_pos =
  52. {
  53. [ChatConst.Channel.World] = 1,
  54. [ChatConst.Channel.Gang] = 2,
  55. [ChatConst.Channel.Friend] = 3,
  56. [ChatConst.Channel.Notice] = 4,
  57. [ChatConst.Channel.Cross] = 5,
  58. [ChatConst.Channel.Province] = 6,
  59. }
  60. end
  61. --主容器
  62. function ChatWindow:createRootWnd()
  63. self.root_wnd = ccui.Layout:create()
  64. self.root_wnd:setTouchEnabled(true)
  65. self.root_wnd:setContentSize(cc.size(SCREEN_WIDTH,SCREEN_HEIGHT))
  66. self.root_wnd:setAnchorPoint(0,0)
  67. --遮罩
  68. self.mask = ccui.Layout:create()
  69. self.mask:setTouchEnabled(true)
  70. self.mask:setContentSize(cc.size(SCREEN_WIDTH,SCREEN_HEIGHT))
  71. self.mask:setAnchorPoint(0.5,0.5)
  72. self.mask:setPosition(self.root_wnd:getContentSize().width/2,self.root_wnd:getContentSize().height/2)
  73. self.root_wnd:addChild(self.mask)
  74. self.mask:setBackGroundColor(cc.c3b(0,0,0))
  75. self.mask:setBackGroundColorOpacity(128)
  76. self.mask:setBackGroundColorType(1)
  77. self.mask:setScale(display.getMaxScale())
  78. ViewManager:getInstance():getLayerByTag(self.view_tag):addChild(self.root_wnd)
  79. local height = display.height
  80. self.design_height = 1280 --美术设计的高度
  81. self.design_width = 720
  82. local rate = height/self.design_height
  83. self.real_height = height --游戏缩放后实际的高度
  84. self.offset_height = self.real_height-height --缩放后增加的高度
  85. self.size = display.size
  86. self.free_height = self.size.height
  87. end
  88. function ChatWindow:initView()
  89. -- 容器,播放动画用的
  90. self.back_bg = ccui.Widget:create()
  91. self.back_bg:setAnchorPoint(cc.p(0,0))
  92. self.back_bg:setPosition(cc.p(0, 0))
  93. self.back_bg:setTouchEnabled(true)
  94. self.back_bg:setContentSize(cc.size(self.size.width, self.size.height))
  95. self.root_wnd:addChild(self.back_bg,1)
  96. -- 计算UI适配
  97. -- 图片的原大小
  98. local bg1_size = cc.size(1400, 640)
  99. -- 计算修改后的大小
  100. if display.width < 1500 then
  101. bg1_size.width = display.width - 100
  102. end
  103. ----------------E
  104. -- 大的背景
  105. local background = createImage(self.back_bg, nil, 0, 0, cc.p(0, 0))
  106. if not self.background_load then self.background_load = loadImageTextureFromCDN(background, PathTool.getTargetRes("bigbg", "bigbg_voyage_01"), ResourcesType.single, self.background_load) end
  107. background:setContentSize(self.size)
  108. -- 小背景
  109. -- self.bg1 = createScale9Sprite(PathTool.getResFrame("common","common_1003"),0,0,LOADTEXT_TYPE_PLIST,self.back_bg)
  110. self.bg1 = createImage(self.back_bg, nil, display.cx, 10, cc.p(0.5, 0), nil, nil, true)
  111. if not self.bg1_load then self.bg1_load = loadImageTextureFromCDN(self.bg1, PathTool.getTargetRes("bigbg", "bigbg_104"), ResourcesType.single, self.bg1_load) end
  112. self.bg1:setCapInsets(cc.rect(30, 30, 30, 30))
  113. self.bg1:setLocalZOrder(1)
  114. self.bg1:setContentSize(bg1_size)
  115. -- res = PathTool.getResFrame("common", "common_1002")
  116. self.bg2 = createScale9Sprite(PathTool.getResFrame("mainui", "mainui_chat_1005"), bg1_size.width * 0.5, 90, LOADTEXT_TYPE_PLIST, self.bg1)
  117. self.bg2:setLocalZOrder(1)
  118. self.bg2:setCapInsets(cc.rect(10, 10, 10, 10))
  119. local size = self.bg1:getContentSize()
  120. self.bg2:setContentSize(cc.size(bg1_size.width - 29, 535))
  121. self.bg2:setAnchorPoint(0.5,0)
  122. --前景遮罩
  123. -- local bg3 = createScale9Sprite(PathTool.getResFrame("common","roundrect_6"),0,0,LOADTEXT_TYPE_PLIST, self.bg2)
  124. -- bg3:setCapInsets(cc.rect(24, 24, 107, 89))
  125. -- bg3:setContentSize(cc.size(bg1_size.width - 29,bg1_size.height - 100))
  126. -- bg3:setAnchorPoint(0,0)
  127. -- bg3:setPosition(cc.p(2,2))
  128. --底部线
  129. -- local line_img = createImage(self.bg2, nil, 0, 0, cc.p(0,0), false, 1)
  130. -- line_img:setCapInsets(cc.rect(24, 24, 107, 89))
  131. -- line_img:setAnchorPoint(0.5,0)
  132. -- line_img:setPosition(cc.p(self.bg2:getContentSize().width/2,6))
  133. -- local bg_res = PathTool.getPlistImgForDownLoad("bigbg/pattern", "pattern_3")
  134. -- self.line_load = loadImageTextureFromCDN(line_img, bg_res, ResourcesType.single, self.line_load)
  135. --关闭按钮
  136. self.shrink_btn = CustomButton.New(self.back_bg,PathTool.getResFrame("common", "close_btn2"),nil,nil,LOADTEXT_TYPE_PLIST)
  137. self.shrink_btn:setAnchorPoint(0.5,0.5)
  138. self.shrink_btn:setPosition(display.width - 50, display.height - 50)
  139. self.shrink_btn:setSize(cc.size(50, 50))
  140. self.shrink_btn:setLocalZOrder(2)
  141. local bg2w = self.bg2:getContentSize().width
  142. --频道背景
  143. local buttomBg = createScale9Sprite(nil, 0, 0,LOADTEXT_TYPE_PLIST,self.bg2)
  144. buttomBg:setContentSize(cc.size(bg2w, 86))
  145. buttomBg:setAnchorPoint(0,1)
  146. buttomBg:setPosition(cc.p(0,0))
  147. self.container_size = cc.size(bg2w - 4, 521)
  148. --提示文字
  149. self.notice_label = createLabel(26, 1,nil,buttomBg:getContentSize().width/2,buttomBg:getContentSize().height/2,TI18N("该频道下无法发言"),buttomBg)
  150. self.notice_label:setAnchorPoint(0.5,0.5)
  151. self.notice_label:setVisible(false)
  152. --发送按钮
  153. self.btn_send = CustomButton.New(buttomBg, PathTool.getResFrame("common", "button_bg_1"), PathTool.getResFrame("common", "button_bg_1"),nil,LOADTEXT_TYPE_PLIST)
  154. self.btn_send:setBtnLableColor(Config.ColorData.data_color4[1])
  155. self.btn_send:setSize(cc.size(150, 50))
  156. self.btn_send:setLabelSize(26)
  157. self.btn_send:setPosition(cc.p(bg2w - 100, buttomBg:getContentSize().height/2))
  158. self.btn_send:setBtnLabel(TI18N("发送"))
  159. self.btn_send:getLabel():enableOutline(cc.c3b(108,43,0),2)
  160. self.btn_send:setLocalZOrder(4)
  161. self:createTabBtnList()
  162. --输入组件
  163. self.chat_input = ChatInput.new("chatWindow")
  164. self.chat_input:setAnchorPoint(cc.p(1, 0))
  165. self.chat_input:setPosition(bg2w - 171, buttomBg:getContentSize().height/2-12) -- 1221
  166. self.chat_input:setInputFunc(function()
  167. self:onEditBoxTouch()
  168. end)
  169. self.chat_input:setVoiceFunc(function(sender, event)
  170. self:beginRecord(sender, event)
  171. end)
  172. buttomBg:addChild(self.chat_input, 5)
  173. --伸缩位置
  174. self.in_x = self.back_bg:getContentSize().width+100
  175. self.out_x = 1
  176. self.back_bg:setPositionX(-self.in_x)
  177. end
  178. function ChatWindow:showAtNotice( status,data )
  179. if self.at_notice == nil then
  180. --self.at_notice = createScale9Sprite(PathTool.getResFrame("common","common_1021"), self.bg2:getContentSize().width-200, 75, LOADTEXT_TYPE_PLIST, self.bg2)
  181. self.at_notice = createImage(self.bg1, PathTool.getResFrame("mainui","mainui_chat_at_bg"), self.bg1:getContentSize().width-262, 130, cc.p(0.5,0.5), true, 0, true)
  182. self.at_notice:setCapInsets(cc.rect(41, 27, 2, 2))
  183. self.at_notice:setContentSize(cc.size(250, 52))
  184. self.at_notice:setAnchorPoint(0,0)
  185. self.at_notice:setTouchEnabled(true)
  186. self.at_notice:setLocalZOrder(99)
  187. self.at_label = createRichLabel(24, 1, cc.p(0,0.5), cc.p(25,self.at_notice:getContentSize().height/2), 0, 0, 150)
  188. self.at_label:setString(TI18N("有人提到了我"))
  189. self.at_notice:addChild(self.at_label)
  190. local line = createScale9Sprite(PathTool.getResFrame("mainui","mainui_chat_at_line"), self.at_label:getPositionX()+self.at_label:getContentSize().width+22, self.at_notice:getContentSize().height/2, LOADTEXT_TYPE_PLIST, self.at_notice)
  191. self.at_close = CustomButton.New(self.at_notice, PathTool.getResFrame("mainui", "mainui_chat_close"), PathTool.getResFrame("mainui", "mainui_chat_close"),nil,LOADTEXT_TYPE_PLIST)
  192. self.at_close:setAnchorPoint(0,0.5)
  193. --self.at_close:setScale(0.7)
  194. self.at_close:setPosition(self.at_notice:getContentSize().width-self.at_close:getContentSize().width-5,self.at_notice:getContentSize().height/2-2)
  195. end
  196. --self.at_notice:setVisible(status)
  197. local function close_callback( )
  198. self.at_notice:setVisible(false)
  199. chat_model:setAtData({})
  200. if data and next(data)~=nil then
  201. chat_controller:sender12768( data.rid,data.srv_id,data.channel,data.msg )
  202. --print("=====sender12768===",data.rid,data.srv_id,data.channel,data.msg )
  203. end
  204. end
  205. handleTouchEnded(self.at_close,function ( )
  206. close_callback()
  207. end)
  208. if data and next(data)~=nil then
  209. local id = chat_controller:getId(self.channel,data.srv_id,data.rid,data.name,data.msg)
  210. if self.channelList then
  211. local scroll = self.channelList[self.channel]
  212. if scroll and scroll.stack_item then
  213. local item = scroll.stack_item[id]
  214. if item then
  215. self.at_notice:setVisible(status)
  216. else
  217. self.at_notice:setVisible(false)
  218. end
  219. else
  220. self.at_notice:setVisible(false)
  221. end
  222. end
  223. else
  224. self.at_notice:setVisible(false)
  225. end
  226. self.at_notice:addTouchEventListener(function ( sender,event_type )
  227. if event_type == ccui.TouchEventType.ended then
  228. if data and next(data)~=nil then
  229. local id = chat_controller:getId(self.channel,data.srv_id,data.rid,data.name,data.msg)
  230. local scroll = self.channelList[self.channel]
  231. if scroll and scroll.stack_item then
  232. local item = scroll.stack_item[id]
  233. if item then
  234. local precent = math.floor(((self.channelList[self.channel].realHeight-item:getPositionY()+item:getContentSize().height)/(self.channelList[self.channel].realHeight))*100)
  235. scroll:jumpToPercentVertical(precent)
  236. close_callback()
  237. end
  238. end
  239. end
  240. end
  241. end)
  242. end
  243. --创建标签按钮
  244. function ChatWindow:createTabBtnList( )
  245. self.tabArray = {
  246. {title = TI18N("同省"), notice = TI18N("等级不足35级"), index = 6, status = true},
  247. {title = TI18N("跨服"), notice = TI18N("等级不足50级"), index = 5, status = true},
  248. {title = TI18N("世界"), index = 1, status = true},
  249. {title = TI18N("公会"), notice = TI18N("您暂时没有加入公会"), index = 2, status = true},
  250. {title = TI18N("私聊"), index = 3, status = true},
  251. {title = TI18N("系统"), index = 4, status = true},
  252. }
  253. -- 服务器数量不足2个时,隐藏跨服频道
  254. --[[local srv_list = LoginController:getInstance():getModel():getServerList()
  255. if tableLen(srv_list) < 2 then
  256. table.remove(self.tabArray, 2)
  257. end--]]
  258. local widget = ccui.Widget:create()
  259. local bg1_size = self.bg1:getContentSize()
  260. widget:setContentSize(cc.size(bg1_size.width - 60,90))
  261. widget:setAnchorPoint(cc.p(0,1))
  262. widget:setPosition(cc.p(15, bg1_size.height + 58))
  263. self.bg1:addChild(widget)
  264. widget:setLocalZOrder(0)
  265. local bgSize = widget:getContentSize()
  266. local scroll_view_size = cc.size(bgSize.width+20, bgSize.height)
  267. local setting = {
  268. item_class = CommonTabBtn, -- 单元类
  269. start_x = 0, -- 第一个单元的X起点
  270. space_x = 0, -- x方向的间隔
  271. start_y = 15, -- 第一个单元的Y起点
  272. space_y = 0, -- y方向的间隔
  273. item_width = 155, -- 单元的尺寸width
  274. item_height = 60, -- 单元的尺寸height
  275. row = 1, -- 行数,作用于水平滚动类型
  276. col = 0, -- 列数,作用于垂直滚动类型
  277. }
  278. self.tab_scrollview = CommonScrollViewLayout.new(widget, cc.p(0, 10) , ScrollViewDir.horizontal, ScrollViewStartPos.top, scroll_view_size, setting)
  279. self.tab_scrollview:setData(self.tabArray, handler(self, self._onClickTabBtn), nil, { default_index = 1, tab_size = cc.size(147, 55)})
  280. self.tab_scrollview:addEndCallBack(function ( )
  281. self.tab_btn_list = self.tab_scrollview:getItemList()
  282. for i,v in ipairs(self.tabArray) do
  283. local is_open = self:checkBtnIsOpen(v.index)
  284. self:setTabBtnTouchStatus(is_open, v.index)
  285. end
  286. self:initChannelRedNum()
  287. if self.temp_cur_index then
  288. self:setSelecteTab(self.temp_cur_index)
  289. self.temp_cur_index = nil
  290. end
  291. end)
  292. end
  293. function ChatWindow:_onClickTabBtn( tab_btn )
  294. if self.cur_selected then
  295. self.cur_selected:setBtnSelectStatus(false)
  296. end
  297. if tab_btn then
  298. self.cur_selected = tab_btn
  299. self.cur_selected:setBtnSelectStatus(true)
  300. self:openTagBtn(self.cur_selected.index)
  301. if self.cur_selected.index == 1 then
  302. PromptController:getInstance():getModel():removePromptDataByTpye(PromptTypeConst.At_notice)
  303. end
  304. end
  305. end
  306. function ChatWindow:setSelecteTab(index)
  307. if self.tab_scrollview then
  308. local tab_btn
  309. for k,btn in pairs(self.tab_btn_list) do
  310. if btn.index == index then
  311. tab_btn = btn
  312. end
  313. end
  314. if tab_btn then
  315. self:_onClickTabBtn(tab_btn)
  316. end
  317. end
  318. end
  319. --[[function ChatWindow:_onClickFiltBtn( )
  320. if not self.filt_layout then
  321. self.filt_layout = ccui.Layout:create()
  322. self.filt_layout:setTouchEnabled(true)
  323. local size = self.bg1:getContentSize()
  324. self.filt_layout:setContentSize(cc.size(size.width, size.height))
  325. self.filt_layout:setAnchorPoint(0.5,1)
  326. self.filt_layout:setPosition(self.back_bg:getContentSize().width/2,self.back_bg:getContentSize().height-65)
  327. self.filt_layout:setLocalZOrder(1)
  328. self.back_bg:addChild(self.filt_layout)
  329. self.filt_layout:addTouchEventListener(function(sender, event)
  330. if event == ccui.TouchEventType.ended then
  331. self:_onClickFiltBtn()
  332. end
  333. end)
  334. local filt_bg_size = cc.size(255, 60)
  335. local filt_bg = createImage(self.filt_layout, PathTool.getResFrame("common", "common_1092"), 0, 0, cc.p(1, 1), true, 1, true)
  336. filt_bg:setTouchEnabled(true)
  337. filt_bg:setContentSize(filt_bg_size)
  338. filt_bg:setAnchorPoint(cc.p(1, 1))
  339. local world_pos = self.filt_btn:getRoot():convertToWorldSpace(cc.p(0, 0))
  340. local node_pos = self.filt_layout:convertToNodeSpace(world_pos)
  341. filt_bg:setPosition(cc.p(node_pos.x+63, node_pos.y))
  342. local box_list = {
  343. [1] = TI18N("隐藏VIP标志"),
  344. }
  345. for i,desc in ipairs(box_list) do
  346. local chose_box = self:createChoseBox(desc, i)
  347. chose_box:setPosition(cc.p(0, filt_bg_size.height - (i-1)*60))
  348. filt_bg:addChild(chose_box)
  349. end
  350. end
  351. self.filt_is_show = not self.filt_is_show
  352. self.filt_layout:setVisible(self.filt_is_show)
  353. end--]]
  354. -- 筛选框
  355. --[[function ChatWindow:createChoseBox( desc, index )
  356. local layout = ccui.Layout:create()
  357. layout:setContentSize(cc.size(255, 60))
  358. layout:setAnchorPoint(0, 1)
  359. local bg, btn = PathTool.getCheckBoxRes_2()
  360. local check_box = RadioButton.new(layout, bg, btn, desc, 100, RadioButtonDir.LEFT, 26)
  361. check_box:setAnchorPoint(cc.p(0, 0.5))
  362. check_box:setTitleColor(cc.c4b(224, 191, 152, 255))
  363. check_box:setPosition(cc.p(20, 30))
  364. check_box:setSelected(self.vip_is_show)
  365. check_box:addTouchEventListener(function(sender, event_type)
  366. if event_type == ccui.TouchEventType.ended then
  367. check_box:setSelected(not check_box:isSelected())
  368. if index == 1 then
  369. self.vip_is_show = not self.vip_is_show
  370. if self.vip_is_show == true then
  371. RoleController:getInstance():sender10348(1)
  372. else
  373. RoleController:getInstance():sender10348(0)
  374. end
  375. end
  376. end
  377. end)
  378. return layout
  379. end--]]
  380. --判断是否开启按钮
  381. function ChatWindow:checkBtnIsOpen( index )
  382. if index == 2 and RoleController:getInstance():getRoleVo():isHasGuild()==false then
  383. return false
  384. elseif index == 5 then
  385. local cross_config = Config.MiscData.data_const["cross_level"]
  386. if self.role_vo.lev >= cross_config.val then
  387. return true
  388. else
  389. return false
  390. end
  391. --[[elseif index == 6 then
  392. local province_config = Config.MiscData.data_const["province_level"]
  393. if province_config and self.role_vo.lev >= province_config.val then
  394. return true
  395. else
  396. return false
  397. end--]]
  398. end
  399. return true
  400. end
  401. --设置按钮是否变灰
  402. function ChatWindow:setTabBtnTouchStatus(status, index)
  403. if self.tab_scrollview then
  404. local tab_btn
  405. for k,btn in pairs(self.tab_btn_list) do
  406. if btn.index == index then
  407. tab_btn = btn
  408. end
  409. end
  410. if tab_btn then
  411. tab_btn:setBtnOpenStatus(status)
  412. end
  413. end
  414. end
  415. --==============================--
  416. --desc:初始化聊天的条目
  417. --time:2018-07-27 04:10:01
  418. --@return
  419. --==============================--
  420. function ChatWindow:initChannelRedNum()
  421. for i,tab_btn in ipairs(self.tab_btn_list) do
  422. if tab_btn.index ~= 4 then
  423. local channel = self.stack_tag[tab_btn.index]
  424. self:setTabTipsII(channel)
  425. end
  426. end
  427. end
  428. --==============================--
  429. --desc:标签页红点,统一处理
  430. --time:2018-07-27 03:51:03
  431. --@channel:
  432. --@return
  433. --==============================--
  434. function ChatWindow:setTabTipsII(channel)
  435. if channel == nil then return end
  436. if not self.tab_scrollview then return end
  437. local index = self.stack_pos[channel]
  438. if index == nil then return end
  439. local tab_btn
  440. for k,btn in pairs(self.tab_btn_list) do
  441. if btn.index == index then
  442. tab_btn = btn
  443. end
  444. end
  445. if tab_btn then
  446. local sum = chat_controller:getChannelMsgSum(channel)
  447. tab_btn:setRedStatus(sum>0, sum)
  448. end
  449. end
  450. -- 打开关/闭界面伸缩处理
  451. function ChatWindow:playMoveAct(is_open)
  452. if self.moving then return end
  453. self.moving = true
  454. self.back_bg:stopAllActions()
  455. local offx = 0
  456. if is_open then
  457. offx = 0--self.in_x
  458. else
  459. offx = -self.in_x
  460. end
  461. local move_action = cc.MoveTo:create(0.2,cc.p(offx + self.out_x, self.back_bg:getPositionY()))
  462. self.back_bg:runAction(cc.Sequence:create(move_action, cc.CallFunc:create(function()
  463. self.moving = nil
  464. if not is_open then
  465. self:close()
  466. else
  467. if self.commend_ui then
  468. self.commend_ui:judgeLead()
  469. end
  470. end
  471. if self.is_top then
  472. self.back_bg:setPositionY(self.back_bg:getPositionY()-275)
  473. self.is_top =false
  474. end
  475. end)))
  476. -- 关闭的时候打开
  477. if not is_open then
  478. if GuideController:getInstance():isInGuide() == false then
  479. MainuiController:getInstance():setMainUIChatBubbleStatus(true)
  480. end
  481. end
  482. --[[if self.filt_is_show then
  483. self:_onClickFiltBtn()
  484. end--]]
  485. end
  486. -- 拖动关闭界面
  487. function ChatWindow:addMoveAndClose()
  488. self.mask:addTouchEventListener(function(sender, event_type)
  489. if event_type == ccui.TouchEventType.ended then
  490. self:playMoveAct()
  491. end
  492. end)
  493. self.back_bg:addTouchEventListener(function(sender, event_type)
  494. local start_pos, end_pos
  495. if event_type == ccui.TouchEventType.ended then
  496. start_pos = cc.p(sender:getTouchBeganPosition())
  497. end_pos = cc.p(sender:getTouchEndPosition())
  498. if start_pos.x - end_pos.x > 300 then
  499. self:playMoveAct()
  500. end
  501. end
  502. end)
  503. end
  504. -- 打开频道
  505. function ChatWindow:openChannel(channel,srv_id,rid)
  506. --[[if channel == ChatConst.Channel.World then
  507. channel = ChatConst.Channel.World
  508. end--]]
  509. local index = self.stack_pos[channel]
  510. self.channel = channel
  511. self.select_srv_id = srv_id
  512. self.select_rid = rid
  513. -- 遍历一下是否激活状态
  514. for i,v in ipairs(self.tabArray) do
  515. local is_open = self:checkBtnIsOpen(v.index)
  516. self:setTabBtnTouchStatus(is_open, v.index)
  517. end
  518. if not self.tab_btn_list or next(self.tab_btn_list) == nil then
  519. self.temp_cur_index = index -- 可能tab按钮还没创建完,那么先缓存一下,创建完再触发选中
  520. else
  521. self:setSelecteTab(index)
  522. end
  523. end
  524. -- 打开频道(只是频道切换)
  525. function ChatWindow:moveToChannel(channel)
  526. local index = self.stack_pos[channel]
  527. self.channel = channel
  528. -- 遍历一下是否激活状态
  529. for i,v in ipairs(self.tabArray) do
  530. local is_open = self:checkBtnIsOpen(v.index)
  531. self:setTabBtnTouchStatus(is_open, v.index)
  532. end
  533. self:setSelecteTab(index)
  534. end
  535. -- 初始化操作
  536. function ChatWindow:initCtrl()
  537. self:registerNotifier(true)
  538. self:addMoveAndClose()
  539. --收起按钮
  540. self.shrink_btn:addTouchEventListener(function(sender, event_type)
  541. if event_type == ccui.TouchEventType.ended then
  542. self:playMoveAct()
  543. end
  544. end)
  545. --发送按钮
  546. handleTouchEnded(self.btn_send, function()
  547. self:onEditBoxTouch()
  548. end)
  549. end
  550. -- 录音
  551. function ChatWindow:beginRecord(sender, event)
  552. local channel = self.channel
  553. if channel == ChatConst.Channel.Multi or channel == ChatConst.Channel.Event then
  554. channel = ChatConst.Channel.World
  555. end
  556. ChatHelp.RecordTouched(sender, event, channel)
  557. end
  558. -- 切换标签按钮
  559. function ChatWindow:openTagBtn(index)
  560. if index == self.select_index or not self.stack_tag or not self.chat_input then return end
  561. self.select_index = index
  562. self.channel = self.stack_tag[index]
  563. chat_controller:setLastChannel(self.channel)
  564. self.chat_input:setChatChannel(self.channel)
  565. --队伍、宗门、综合、事件频道
  566. self:setCoseListDisable()
  567. self:showCoseList(self.channel)
  568. self.chat_input:setVisible(true)
  569. --[[self.filt_btn:setVisible(self:isShowFiltBtn(self.channel))
  570. if self.filt_is_show then
  571. self:_onClickFiltBtn()
  572. end--]]
  573. if self.channel == ChatConst.Channel.Event or self.channel == ChatConst.Channel.Notice then
  574. self.chat_input:setVisible(false)
  575. self.notice_label:setVisible(true)
  576. elseif self.channel == ChatConst.Channel.Province then
  577. local province_config = Config.MiscData.data_const["province_level"]
  578. if not province_config or self.role_vo.lev < province_config.val then
  579. self.chat_input:setVisible(false)
  580. self.notice_label:setVisible(false)
  581. else
  582. self.chat_input:setVisible(true)
  583. self.notice_label:setVisible(false)
  584. end
  585. else
  586. self.notice_label:setVisible(false)
  587. end
  588. -- 同省、跨服、世界、公会可以@人
  589. if index == 1 or index == 2 or index == 5 or index == 6 then
  590. local data = chat_model:getAtData()
  591. if data and next(data)~=nil then
  592. self:showAtNotice(true,data)
  593. end
  594. self.chat_input.edit_box:setPlaceHolder(TI18N("请输入,长按头像可快捷@人"))
  595. else
  596. self.chat_input.edit_box:setPlaceHolder(TI18N("请输入信息"))
  597. end
  598. -- 切到同省频道则清一下输入框数据(同省频道屏蔽了道具等信息发送)
  599. if index == 6 then
  600. self:cleatInputText()
  601. end
  602. self:checkFindInput()
  603. --加入宗门提示
  604. self:analyseGang()
  605. end
  606. -- 查找框UI调整
  607. function ChatWindow:checkFindInput()
  608. if --[[not self.find_scroll and not self.commend_ui and not self.apply_scroll or]] self.channel==ChatConst.Channel.Event or self.channel==ChatConst.Channel.Notice then
  609. self.btn_send:setVisible(false)
  610. if self.find_input then
  611. self.f_edit_box:setPosition(70,0)
  612. end
  613. elseif self.channel == ChatConst.Channel.Province then
  614. local province_config = Config.MiscData.data_const["province_level"]
  615. if not province_config or self.role_vo.lev < province_config.val then
  616. self.btn_send:setVisible(false)
  617. else
  618. self.btn_send:setVisible(true)
  619. end
  620. else
  621. self.btn_send:setVisible(true)
  622. if self.channel==ChatConst.Channel.Mail then
  623. self.btn_send:setBtnLabel(TI18N("返回"))
  624. else
  625. self.btn_send:setBtnLabel(TI18N("发送"))
  626. end
  627. if self.find_input then
  628. self.f_edit_box:setPosition(18,0)
  629. end
  630. end
  631. end
  632. -- 宗门频道显示处理
  633. function ChatWindow:analyseGang()
  634. if self.channel==ChatConst.Channel.Gang and not RoleController:getInstance():getRoleVo():isHasGuild() then
  635. chat_controller:clearChatLog(self.channel)
  636. local scroll = self:getCostList(ChatConst.Channel.Gang)
  637. if scroll then
  638. scroll:reset()
  639. end
  640. self:showJoinGang(true)
  641. else
  642. self:showJoinGang(false)
  643. end
  644. end
  645. -- 添加宗门提示
  646. function ChatWindow:showJoinGang(bool)
  647. if bool then
  648. if self.help_text == nil then
  649. self.help_text =createRichLabel(24, Config.ColorData.data_color4[66], cc.p(0.5,0.5), cc.p(0,0), nil, nil, 300)
  650. local str = TI18N("您暂时没有加入公会")
  651. self.help_text:setString(str)
  652. self.help_text:setAnchorPoint(0.5,0.5)
  653. self.help_text:setPosition(self.bg1:getContentSize().width/2, self.bg1:getContentSize().height/2-90)
  654. self.bg1:addChild(self.help_text)
  655. if self.no_img == nil then
  656. local res = PathTool.getEmptyMark()
  657. self.no_img = createImage(self.bg1, res, self.bg1:getContentSize().width/2, self.bg1:getContentSize().height/2-2, cc.p(0.5,0.5), false, 1, false)
  658. self.no_img:setScale(1.2)
  659. end
  660. end
  661. else
  662. doRemoveFromParent(self.help_text)
  663. self.help_text = nil
  664. if self.no_img then
  665. doRemoveFromParent(self.no_img)
  666. self.no_img = nil
  667. end
  668. end
  669. end
  670. -- 事件处理
  671. function ChatWindow:registerNotifier(bool)
  672. if bool then
  673. --隐藏关闭按钮
  674. if not self.close_btn_event then
  675. self.close_btn_event = GlobalEvent:getInstance():Bind(EventId.CHAT_CLOSEBTN_VISIBLE, function(bool)
  676. self.shrink_btn:setVisible(true)
  677. end)
  678. end
  679. --更新聊天
  680. if not self.world_msg_evt then
  681. self.world_msg_evt = GlobalEvent:getInstance():Bind(EventId.CHAT_UDMSG_WORLD, function(channel, is_self)
  682. if self.is_open then
  683. self:updateCoseList(channel, is_self)
  684. end
  685. end)
  686. end
  687. --更新系统频道聊天
  688. if not self.multi_msg_evt then
  689. self.multi_msg_evt = GlobalEvent:getInstance():Bind(EventId.CHAT_UDMSG_ASSETS, function()
  690. if self.is_open then
  691. self:updateCoseList(ChatConst.Channel.Notice)
  692. end
  693. end)
  694. end
  695. --清除输入文本
  696. if not self.clear_input_event then
  697. self.clear_input_event = GlobalEvent:getInstance():Bind(EventId.CHAT_CLEAR_INPUT, function(is_private)
  698. self:cleatInputText()
  699. end)
  700. end
  701. --删除输入文字
  702. if not self.backspace_evt then
  703. self.backspace_evt = GlobalEvent:getInstance():Bind(EventId.CHAT_BACKSPACE, function(from_name)
  704. if from_name == "chatPanel" then
  705. self:handleBackSpace()
  706. end
  707. end)
  708. end
  709. --添加表情
  710. if not self.add_face_evt then
  711. self.add_face_evt = GlobalEvent:getInstance():Bind(EventId.CHAT_SELECT_FACE, function(face_id, from_name)
  712. if from_name == "chatWindow" then
  713. self:onEditTextAddFace(face_id)
  714. end
  715. end)
  716. end
  717. --添加物品
  718. if not self.add_item_evt then
  719. self.add_item_evt = GlobalEvent:getInstance():Bind(EventId.CHAT_SELECT_ITEM, function(data, from_name)
  720. if from_name == "chatWindow" then
  721. self:onEditTextAddItem(data)
  722. end
  723. end)
  724. end
  725. --更新翻译内容
  726. if not self.adjust_event then
  727. self.adjust_event = GlobalEvent:getInstance():Bind(ChatConst.Voice_Translate_Panel, function()
  728. self:adjustPosAfterTranslate()
  729. end)
  730. end
  731. --点击发送按钮
  732. if not self.touch_send_evt then
  733. self.touch_send_evt = GlobalEvent:getInstance():Bind(EventId.CHAT_QUICK_SEND, function(from_name)
  734. if --[[not chat_controller:isPrivateOpen() and]] from_name == "chatPanel" then
  735. self:onEditBoxTouch()
  736. end
  737. end)
  738. end
  739. --有公会的时候更改下状态
  740. if self.role_vo then
  741. if self.role_update_lev_event == nil then
  742. self.role_update_lev_event = self.role_vo:Bind(RoleEvent.UPDATE_ROLE_ATTRIBUTE,function(key,value)
  743. if key == "gsrv_id" or key == "gid" then
  744. if self.role_vo:isHasGuild() then
  745. self:setTabBtnTouchStatus(true, 2)
  746. end
  747. end
  748. end)
  749. end
  750. end
  751. --私聊的红点更新
  752. -- if not self.update_private_red then
  753. -- self.update_private_red = GlobalEvent:getInstance():Bind(ChatEvent.UpdatePrivateChatRed,function ( )
  754. -- if self.tab_btn_list[3] then
  755. -- self:setTabTipsII(chat_model:getRedCount(), 3)
  756. -- end
  757. -- end)
  758. -- end
  759. if self.new_msg_add_event == nil then
  760. self.new_msg_add_event = GlobalEvent:getInstance():Bind(EventId.CHAT_NEWMSG_FLAG, function(channel)
  761. self:setTabTipsII(channel)
  762. end)
  763. end
  764. --创建完成聊天列表 更新下信息
  765. if not self.update_at then
  766. self.update_at = GlobalEvent:getInstance():Bind(ChatEvent.EndCallBack,function ( )
  767. if self.channel == ChatConst.Channel.Gang or self.channel == ChatConst.Channel.World then
  768. local data = chat_model:getAtData()
  769. if data and next(data)~=nil then
  770. self:showAtNotice(true,data)
  771. end
  772. --self.chat_input.edit_box:setPlaceHolder(TI18N("请输入信息,长按头像可快捷@人"))
  773. else
  774. --self.chat_input.edit_box:setPlaceHolder(TI18N("请输入信息"))
  775. end
  776. end)
  777. end
  778. if not self.enter_fight then
  779. self.enter_fight = GlobalEvent:getInstance():Bind(SceneEvent.ENTER_FIGHT,function ()
  780. self:playMoveAct()
  781. end)
  782. end
  783. else
  784. if self.close_btn_event then
  785. GlobalEvent:getInstance():UnBind(self.close_btn_event)
  786. self.close_btn_event = nil
  787. end
  788. if self.world_msg_evt then
  789. GlobalEvent:getInstance():UnBind(self.world_msg_evt)
  790. self.world_msg_evt = nil
  791. end
  792. if self.multi_msg_evt then
  793. GlobalEvent:getInstance():UnBind(self.multi_msg_evt)
  794. self.multi_msg_evt = nil
  795. end
  796. if self.clear_input_event then
  797. GlobalEvent:getInstance():UnBind(self.clear_input_event)
  798. self.clear_input_event = nil
  799. end
  800. if self.backspace_evt then
  801. GlobalEvent:getInstance():UnBind(self.backspace_evt)
  802. self.backspace_evt = nil
  803. end
  804. if self.add_face_evt then
  805. GlobalEvent:getInstance():UnBind(self.add_face_evt)
  806. self.add_face_evt = nil
  807. end
  808. if self.add_item_evt then
  809. GlobalEvent:getInstance():UnBind(self.add_item_evt)
  810. self.add_item_evt = nil
  811. end
  812. if self.touch_send_evt then
  813. GlobalEvent:getInstance():UnBind(self.touch_send_evt)
  814. self.touch_send_evt = nil
  815. end
  816. if self.adjust_event then
  817. GlobalEvent:getInstance():UnBind(self.adjust_event)
  818. self.adjust_event = nil
  819. end
  820. if self.role_vo then
  821. if self.role_update_lev_event then
  822. self.role_vo:UnBind(self.role_update_lev_event)
  823. self.role_update_lev_event = nil
  824. end
  825. end
  826. -- if self.update_private_red then
  827. -- GlobalEvent:getInstance():UnBind(self.update_private_red)
  828. -- self.update_private_red = nil
  829. -- end
  830. if self.new_msg_add_event then
  831. GlobalEvent:getInstance():UnBind(self.new_msg_add_event)
  832. self.new_msg_add_event = nil
  833. end
  834. if self.update_at then
  835. GlobalEvent:getInstance():UnBind(self.update_at)
  836. self.update_at = nil
  837. end
  838. if self.enter_fight then
  839. GlobalEvent:getInstance():UnBind(self.enter_fight)
  840. self.enter_fight = nil
  841. end
  842. end
  843. end
  844. -- 文本框操作
  845. function ChatWindow:onEditBoxTouch()
  846. local text, srv_id = self.chat_input:getInputText()
  847. srv_id = srv_id or ""
  848. --if self.channel == ChatConst.Channel.Friend then return end
  849. if self.channel == ChatConst.Channel.Event then
  850. message(TI18N("事件频道不能发言"))
  851. return
  852. end
  853. if self.chat_input:isNothing() then
  854. message(TI18N("请输入聊天信息"))
  855. return
  856. end
  857. local data = WordCensor:getInstance():relapceFaceIconTag(text)
  858. if data[1] > 5 then
  859. message(TI18N("发言中不能超过5个表情"))
  860. return
  861. end
  862. local tar_channel
  863. text = WordCensor:getInstance():relpaceChatTag(text)
  864. -- 展示物品替换
  865. if self.item_desc_list and next(self.item_desc_list) then
  866. for k,v in pairs(self.item_desc_list) do
  867. text = string.gsub(text, k, v, 1)
  868. end
  869. end
  870. if self.channel == ChatConst.Channel.World then --世界聊天
  871. tar_channel = 1
  872. text = self:repleaceAtPeopleText(text, srv_id)
  873. elseif self.channel == ChatConst.Channel.Cross then --跨服聊天
  874. tar_channel = 1024
  875. text = self:repleaceAtPeopleText(text, srv_id)
  876. elseif self.channel == ChatConst.Channel.Province then -- 同省聊天
  877. tar_channel = 2048
  878. text = self:repleaceAtPeopleText(text, srv_id)
  879. elseif self.channel == ChatConst.Channel.Scene then --场景聊天
  880. tar_channel = 2
  881. elseif self.channel == ChatConst.Channel.Team then --队伍聊天
  882. tar_channel = 8
  883. elseif self.channel == ChatConst.Channel.Gang then --帮派聊天
  884. if RoleController:getInstance():getRoleVo():isHasGuild() then
  885. tar_channel = 4
  886. text = self:repleaceAtPeopleText(text, srv_id)
  887. else
  888. message(TI18N("加入公会即可在此频道发言"))
  889. end
  890. elseif self.channel == ChatConst.Channel.Friend then --私聊频道
  891. tar_channel = nil
  892. local user_data = self.channelList[self.channel]:getUserData()
  893. if user_data and next(user_data)~=nil then
  894. chat_controller:sender12720(user_data.srv_id, user_data.rid, 0, text)
  895. self:cleatInputText()
  896. else
  897. message(TI18N("当前没人可以聊天~"))
  898. end
  899. end
  900. if tar_channel then
  901. if GameNet:getInstance():getTime() - self.time > 1 then
  902. self.time = GameNet:getInstance():getTime()
  903. local is_success = chat_controller:sendChatMsg(tar_channel, 0, text)
  904. if is_success then
  905. self:cleatInputText()
  906. end
  907. end
  908. end
  909. end
  910. function ChatWindow:repleaceAtPeopleText( text, srv_id )
  911. local num1 = string.find(text,"@")
  912. local num2 = string.find(text," ")
  913. local len = string.len(text)
  914. if num1 and num2 then
  915. local at = string.sub(text,num1,num2)
  916. local rep = string.format("<div href=atpeople srvid=%s>%s</div>",srv_id,at)
  917. text = string.gsub(text,at,rep)
  918. end
  919. return text
  920. end
  921. function ChatWindow:cleatInputText()
  922. self.chat_input:setInputText("")
  923. self.item_desc_list = {}
  924. self.item_code_list = {}
  925. end
  926. -- 删除输入的信息
  927. function ChatWindow:handleBackSpace()
  928. local text = self.chat_input:getInputText()
  929. if text ~= "" then
  930. local str_list, length = StringUtil.splitStr(text)
  931. local words = ""
  932. for i=1, #str_list-1 do
  933. words = words.. tostring(str_list[i].char)
  934. end
  935. self.chat_input:setInputText(words)
  936. end
  937. end
  938. -- 输入框添加表情
  939. function ChatWindow:onEditTextAddFace(face_id)
  940. local text = self.chat_input:getInputText()
  941. if text == self.default_msg then
  942. text = ""
  943. end
  944. self.chat_input:setInputText(text .. face_id)
  945. end
  946. -- 输入框添加表情
  947. function ChatWindow:onEditTextAddItem(data)
  948. if data == nil then return end
  949. local text = self.chat_input:getInputText()
  950. if text == self.default_msg then
  951. text = ""
  952. end
  953. -- 如果没有文字内容,则清一下数据
  954. if text == "" then
  955. self.item_desc_list = {}
  956. self.item_code_list = {}
  957. end
  958. local base_id = data.base_id
  959. local share_id = data.share_id
  960. local count = data.count
  961. local role_vo = RoleController:getInstance():getRoleVo()
  962. local item_config = Config.ItemData.data_get_data(base_id)
  963. local code = data.code
  964. if item_config then
  965. local key = string.format("{%s,%s}", share_id, item_config.name)
  966. local desc = ref_controller:buildItemMsg(base_id, role_vo.srv_id, share_id, count)
  967. if self.item_code_list[code] then
  968. local cur_object = self.item_code_list[code]
  969. local cur_key = cur_object.key
  970. local cur_desc = cur_object.desc
  971. -- 获取原有的
  972. text = string.gsub(text, cur_key, key, 1)
  973. else
  974. text = text..key
  975. end
  976. self.item_code_list[code] = {key=key, desc=desc}
  977. self.item_desc_list[key] = desc
  978. self.chat_input:setInputText(text)
  979. end
  980. end
  981. -- 获取输入文本内容
  982. function ChatWindow:getEditText()
  983. return self.chat_input:getInputText()
  984. end
  985. -- 打开界面
  986. function ChatWindow:open()
  987. if not self.is_open then
  988. self.is_open = true
  989. self:playMoveAct(true)
  990. end
  991. self.root_wnd:setVisible(true)
  992. self:addClock(false)
  993. self:registerNotifier(true)
  994. self:setCommonUIZOrder(self.root_wnd)
  995. self:initChannelRedNum()
  996. chat_controller:openChatUITimer(false)
  997. end
  998. -- 关闭界面
  999. function ChatWindow:close()
  1000. SysEnv:getInstance():save()
  1001. ChatMgr:getInstance():showReportUI(false)
  1002. RefController:getInstance():closeView()
  1003. self.root_wnd:setVisible(false)
  1004. self.is_open = false
  1005. self.select_index = nil
  1006. self:registerNotifier(false)
  1007. self:setCoseListDisable()
  1008. if self.mail_ui then
  1009. self.mail_ui:SetEnabled(false)
  1010. end
  1011. if self.friend_ui then
  1012. self.friend_ui:SetEnabled(false)
  1013. end
  1014. self:addClock(true)
  1015. if GuideController:getInstance():isInGuide() == false then
  1016. MainuiController:getInstance():setMainUIChatBubbleStatus(true)
  1017. end
  1018. if self.background_load then
  1019. self.background_load:DeleteMe()
  1020. self.background_load = nil
  1021. end
  1022. if self.bg1_load then
  1023. self.bg1_load:DeleteMe()
  1024. self.bg1_load = nil
  1025. end
  1026. if self.bg2_load then
  1027. self.bg2_load:DeleteMe()
  1028. self.bg2_load = nil
  1029. end
  1030. if self.resources_load then
  1031. self.resources_load:DeleteMe()
  1032. self.resources_load = nil
  1033. end
  1034. chat_controller:openChatUITimer(true)
  1035. end
  1036. -- 清掉聊天列表数据
  1037. function ChatWindow:clearChatList( )
  1038. if not self.channelList then self.channelList = {} end
  1039. for channel,scroll in pairs(self.channelList) do
  1040. if channel ~= ChatConst.Channel.Friend then
  1041. scroll:reset()
  1042. end
  1043. end
  1044. end
  1045. -- 打开状态
  1046. function ChatWindow:isOpen()
  1047. return self.is_open
  1048. end
  1049. -- 创建聊天列表
  1050. function ChatWindow:showCoseList(channel)
  1051. if not self.channelList then self.channelList = {} end
  1052. if self:isChatChannel(channel) then
  1053. for i,v in pairs(self.channelList) do
  1054. if i ~= ChatConst.Channel.Friend then
  1055. if v then
  1056. v:showNewMessage(false)
  1057. v:setVisible(false)
  1058. end
  1059. else
  1060. if v then
  1061. v:setVisibleStatus(false)
  1062. end
  1063. end
  1064. end
  1065. local scroll = self.channelList[channel]
  1066. local size = self.container_size
  1067. local pos = cc.p(18,97)
  1068. local bg1size = self.bg1:getContentSize()
  1069. if not scroll then
  1070. if channel ~= ChatConst.Channel.Friend then
  1071. scroll = NewCoseList.new(size,self.bg1)
  1072. scroll:setPosition(pos)
  1073. self.bg1:addChild(scroll,22)
  1074. else
  1075. chat_controller:openPrivatePanel(true,nil,self.bg2)
  1076. scroll = chat_controller:getChatPanel()
  1077. end
  1078. self.channelList[channel] = scroll
  1079. else
  1080. if channel ~= ChatConst.Channel.Friend then
  1081. scroll:SetEnabled(true)
  1082. end
  1083. end
  1084. if channel ~= ChatConst.Channel.Friend then
  1085. if chat_controller.stack_list == nil then return end
  1086. delayRun(self.bg1, 1/display.DEFAULT_FPS, function()
  1087. if self.channelList and self.channel and self.channelList[self.channel] and self.channelList[self.channel]["createMsg"] then
  1088. self.channelList[self.channel]:createMsg(chat_controller.stack_list[self.channel], self.channel)
  1089. end
  1090. end)
  1091. else
  1092. self.channelList[self.channel]:setVisibleStatus(true)
  1093. self.channelList[self.channel]:updateData(self.select_srv_id,self.select_rid)
  1094. end
  1095. end
  1096. end
  1097. -- 更新当前频道数据
  1098. function ChatWindow:updateCoseList(channel, is_self)
  1099. if not self.channelList then return end
  1100. if self:isChatChannel(self.channel) and self.channel == channel then
  1101. local scroll = self.channelList[self.channel]
  1102. if self.channel ~= ChatConst.Channel.Friend then
  1103. if scroll and scroll:isSame(self.channel) then
  1104. scroll:SetEnabled(true)
  1105. scroll:initData(chat_controller.stack_list[self.channel])
  1106. scroll:updateMsg(is_self)
  1107. end
  1108. else
  1109. local scroll1 = scroll:getCostList()
  1110. if scroll1 and scroll1:isSame(self.channel) then
  1111. scroll1:SetEnabled(true)
  1112. scroll1:initData(chat_controller.stack_list[self.channel])
  1113. scroll1:updateMsg()
  1114. end
  1115. end
  1116. end
  1117. end
  1118. -- 翻译内容更新
  1119. function ChatWindow:adjustPosAfterTranslate()
  1120. if self.channelList then
  1121. for k, v in pairs(self.channelList) do
  1122. if k~=ChatConst.Channel.Friend then
  1123. v:adjustItemPos()
  1124. else
  1125. local vo = self:getCostList(k)
  1126. if vo and vo["adjustItemPos"] then
  1127. vo:adjustItemPos()
  1128. end
  1129. end
  1130. end
  1131. end
  1132. end
  1133. -- 隐藏所有的聊天内容
  1134. function ChatWindow:setCoseListDisable()
  1135. if self.channelList then
  1136. for k, v in pairs(self.channelList) do
  1137. if k~= ChatConst.Channel.Friend then
  1138. v:SetEnabled(false)
  1139. else
  1140. v:setVisibleStatus(false)
  1141. end
  1142. end
  1143. end
  1144. end
  1145. -- 获取某一个频道滚动组件
  1146. function ChatWindow:getCostList(channel)
  1147. if self.channelList then
  1148. if channel ~= ChatConst.Channel.Friend then
  1149. return self.channelList[channel]
  1150. else
  1151. return self.channelList[channel]
  1152. end
  1153. end
  1154. end
  1155. -- 清掉所有数据
  1156. function ChatWindow:clearAllChatMsg( )
  1157. if self.channelList then
  1158. for k, v in pairs(self.channelList) do
  1159. if k~= ChatConst.Channel.Friend then
  1160. v:reset()
  1161. end
  1162. end
  1163. end
  1164. end
  1165. -- 判断是否是聊天频道#
  1166. function ChatWindow:isChatChannel(channel)
  1167. if channel==ChatConst.Channel.Gang
  1168. or channel==ChatConst.Channel.World
  1169. or channel == ChatConst.Channel.Notice
  1170. or channel == ChatConst.Channel.Friend
  1171. or channel == ChatConst.Channel.Province
  1172. or channel == ChatConst.Channel.Cross then
  1173. -- or channel == ChatConst.Channel.Scene
  1174. -- or channel == ChatConst.Channel.Team then
  1175. return true
  1176. end
  1177. return false
  1178. end
  1179. -- 判断是否要显示下拉筛选按钮
  1180. function ChatWindow:isShowFiltBtn( channel )
  1181. if FILTER_CHARGE then return false end -- 屏蔽充值相关
  1182. if channel==ChatConst.Channel.World
  1183. or channel == ChatConst.Channel.Gang
  1184. or channel == ChatConst.Channel.Cross then
  1185. return true
  1186. end
  1187. return false
  1188. end
  1189. -- 添加定时清理
  1190. function ChatWindow:addClock(bool)
  1191. if self.clock_id then
  1192. GlobalTimeTicket:getInstance():remove(self.clock_id)
  1193. self.clock_id = nil
  1194. end
  1195. if bool then
  1196. local del_key
  1197. local count = 0
  1198. local clean_list = {
  1199. [10] = ChatConst.Channel.Gang,
  1200. [30] = ChatConst.Channel.World,
  1201. [40] = "friend",
  1202. [50] = "mail",
  1203. }
  1204. self.clock_id = GlobalTimeTicket:getInstance():add(function()
  1205. count = count + 1
  1206. del_key = clean_list[count]
  1207. if del_key then
  1208. local scroll = self:getCostList(del_key)
  1209. if scroll then
  1210. -- scroll:stopRunning()
  1211. scroll:reset()
  1212. end
  1213. end
  1214. end, 1, 61)
  1215. end
  1216. end