ModuleChooseLayer_launcher.lua 133 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593
  1. local ModuleChooseLayer = class("ModuleChooseLayer", function ()
  2. return cc.Layer:create()
  3. end)
  4. local cjson = require("cjson")
  5. local tinsert = table.insert
  6. local tremove = table.remove
  7. local fixBtnPos = cc.p(950, 310)
  8. local hasRoleGroup = -99
  9. ModuleChooseLayer.CountOfPage = 200
  10. ModuleChooseLayer.path = "res_launcher/private/server/"
  11. ModuleChooseLayer.publicPath = "res_launcher/public/"
  12. ModuleChooseLayer.DownloadFlag =
  13. {
  14. Logo = 1,
  15. AgeTips = 2,
  16. LogoMini = 3,
  17. LogoMini2 = 4,
  18. }
  19. local function TextCreateRichText(parent, str)
  20. parent:setString("")
  21. parent:removeAllChildren()
  22. local visibleSize = global.Director:getVisibleSize()
  23. local RichTextHelp = requireLauncher( "init/RichTextHelp" )
  24. local colorRGB = parent:getTextColor()
  25. local color = string.format("#%02x%02x%02x", colorRGB.r, colorRGB.g, colorRGB.b)
  26. local maxWidth = global.IS_PORTRAIT and visibleSize.width or 2000
  27. local richText = RichTextHelp:CreateRichTextWithXML(str, maxWidth, parent:getFontSize() or 18, color)
  28. richText:setName("RICH_TEXT_")
  29. richText:formatText()
  30. richText:setAnchorPoint({x=0.5, y=0})
  31. parent:addChild(richText)
  32. if global.IS_PORTRAIT then
  33. local pSize = parent:getContentSize()
  34. richText:setPosition(pSize.width / 2, 0)
  35. end
  36. richText:setOpenUrlHandler( function(sender, url)
  37. cc.Application:getInstance():openURL(url)
  38. end )
  39. end
  40. local function drawButtonColorStyle(sender, config)
  41. local labelRenderer = sender:getTitleRenderer()
  42. -- button
  43. sender:setTitleFontSize(config.fontSize)
  44. -- 字体大小
  45. local lastTTFConfig = labelRenderer:getTTFConfig()
  46. lastTTFConfig.fontSize = config.fontSize
  47. labelRenderer:setTTFConfig( lastTTFConfig )
  48. -- 字体颜色
  49. labelRenderer:setTextColor(config.color)
  50. -- 描边颜色和大小
  51. if config.outlineColor and config.outlineSize then
  52. labelRenderer:enableOutline(config.outlineColor, config.outlineSize)
  53. end
  54. end
  55. local function drawTextColorStyle(sender, config)
  56. local labelRenderer = sender:getVirtualRenderer()
  57. sender:setFontSize(config.fontSize)
  58. -- 字体大小
  59. local lastTTFConfig = labelRenderer:getTTFConfig()
  60. lastTTFConfig.fontSize = config.fontSize
  61. labelRenderer:setTTFConfig( lastTTFConfig )
  62. -- 字体颜色
  63. labelRenderer:setTextColor(config.color)
  64. -- 描边颜色和大小
  65. if config.outlineColor and config.outlineSize then
  66. labelRenderer:enableOutline(config.outlineColor, config.outlineSize)
  67. end
  68. end
  69. --哈希表转成按数组
  70. local function HashToSortArray(hashTab, sortFunc)
  71. if hashTab == nil or type(hashTab) ~= "table" then
  72. return nil
  73. end
  74. local sortTable = {}
  75. for _, v in pairs(hashTab) do
  76. tinsert(sortTable, v)
  77. end
  78. if sortFunc then
  79. table.sort(sortTable, sortFunc)
  80. end
  81. return sortTable
  82. end
  83. local function createQuickCell(data)
  84. local wid = data.wid
  85. local hei = data.hei
  86. local callback = data.callback
  87. local widget = ccui.Widget:create()
  88. widget:setContentSize({width=wid, height=hei})
  89. widget:setAnchorPoint({x=0, y=0})
  90. local quickCell = {}
  91. quickCell.widget = widget
  92. quickCell.callback = callback
  93. quickCell.actived = false
  94. local visibleSize = cc.Director:getInstance():getVisibleSize()
  95. local function refresh()
  96. local worldPos = widget:getWorldPosition()
  97. local active = (worldPos.y <= visibleSize.height + hei and worldPos.y >= -hei )
  98. if active then
  99. if not quickCell.actived then
  100. quickCell.actived= active
  101. local cell = quickCell.callback()
  102. cell:setAnchorPoint({x=0.5, y=0.5})
  103. cell:setPosition({x=wid/2, y=hei/2})
  104. widget:removeAllChildren()
  105. widget:addChild(cell)
  106. end
  107. else
  108. if quickCell.actived then
  109. quickCell.actived= active
  110. widget:removeAllChildren()
  111. end
  112. end
  113. end
  114. quickCell.exit = function()
  115. quickCell.actived = false
  116. refresh()
  117. end
  118. local delay = cc.DelayTime:create(0.02)
  119. local sequence = cc.Sequence:create(delay, cc.CallFunc:create(refresh))
  120. local action = cc.RepeatForever:create(sequence)
  121. widget:runAction(action)
  122. return quickCell
  123. end
  124. local function getAgreementState()
  125. local launcherModID = global.L_ModuleManager:GetLauncherModuleID()
  126. local channelID = tostring(global.L_GameEnvManager:GetChannelID())
  127. local userData = UserData:new(launcherModID .. channelID .. "_data")
  128. local agreement = userData:getIntegerForKey("agreement", 0)
  129. return tonumber(agreement) or 0
  130. end
  131. local function isAutoLaunchEnable()
  132. -- windows平台生效
  133. if cc.Application:getInstance():getTargetPlatform() ~= cc.PLATFORM_OS_WINDOWS then
  134. return false
  135. end
  136. -- 是否有字段启动的字段
  137. -- 给qq大厅自动启动
  138. local autoBoot = global.L_GameEnvManager:GetEnvDataByKey("isAutoBoot")
  139. if not autoBoot then
  140. return false
  141. end
  142. return true
  143. end
  144. function ModuleChooseLayer:ctor()
  145. self._subModCells = {} -- module
  146. self._currentModule = nil -- 当前module
  147. self._currentSubMod = nil -- 当前subMod
  148. self._group = -1 -- 当前选择组
  149. self._gservers = {} -- 服务器,根据组分开的
  150. self._groupCells = {} -- 组条目
  151. self._serverCells = {} -- 服务器条目
  152. self._loginedCells = {} -- 已登录条目
  153. self._serverCache = {} -- 缓存池
  154. self._announceUI = nil
  155. self._agreementUI = nil
  156. self._existLastMod = false -- 是否有上次选择模块,用以区分新老用户
  157. self._releaseFlag = false
  158. self._srvlistCount = 0
  159. self._customCount = 0
  160. self._launchTimerID = nil
  161. self._srvlistTimerID = nil
  162. self._srvlistTime = 10*60
  163. end
  164. function ModuleChooseLayer.create()
  165. local layer = ModuleChooseLayer.new()
  166. if layer:Init() then
  167. return layer
  168. end
  169. return nil
  170. end
  171. function ModuleChooseLayer:Init()
  172. local visibleSize = cc.Director:getInstance():getVisibleSize()
  173. if global.IS_PORTRAIT then
  174. self._isPortrait = true
  175. self._root = CreateExport_launcher("server/all_modules_portrait")
  176. else
  177. self._root = CreateExport_launcher("server/all_modules")
  178. end
  179. if not self._root then
  180. return false
  181. end
  182. self:addChild(self._root)
  183. self.ui = ui_delegate(self._root)
  184. self.ui.Image_login_bg:setContentSize(visibleSize)
  185. self.ui.Panel_bg:setVisible(false)
  186. self:InitCustomUI()
  187. self:InitCode()
  188. self:InitLaunch()
  189. self:InitServers()
  190. self:InitAllModules()
  191. self:InitLauncherVersion()
  192. self:SelectDefaultModule()
  193. self:ShowLaunch()
  194. self:HideServers()
  195. self:UpdateSelected()
  196. self.ui.Image_icon:setVisible(false)
  197. self.ui.Panel_agreement:setVisible(false)
  198. self.ui.Image_age_tips:setVisible(false)
  199. self.ui.Text_auth_tips:setVisible(false)
  200. self.ui.Panel_launch:setSwallowTouches(false)
  201. -- logo mini
  202. self._imageLogoMini = ccui.ImageView:create()
  203. self.ui.Panel_launch:addChild(self._imageLogoMini)
  204. self._imageLogoMini:setAnchorPoint(0.5, 0)
  205. local logoPos = cc.p(330, 460)
  206. if self._isPortrait then
  207. logoPos = cc.p(296,650)
  208. end
  209. self._imageLogoMini:setPosition(logoPos)
  210. self._imageLogoMini:setVisible(false)
  211. -- logo mini2
  212. local posx, posy = self.ui.Button_logout:getPosition()
  213. self._imageLogoMini2 = ccui.ImageView:create()
  214. self._imageLogoMini2:loadTexture( imgPath )
  215. self._imageLogoMini2:setAnchorPoint( 0.5, 0.5 )
  216. self._imageLogoMini2:setPosition( posx + 50, posy + 60 )
  217. self.ui.Panel_bg:addChild( self._imageLogoMini2,-1 )
  218. self._imageLogoMini2:setVisible(false)
  219. if self._isPortrait then
  220. fixBtnPos = cc.p(554,710)
  221. end
  222. local showResolution = global.L_GameEnvManager:GetEnvDataByKey("showResolution")
  223. local otherResolution = global.L_GameEnvManager:GetEnvDataByKey("otherResolution")
  224. if global.isDebugMode or global.isGMMode or showResolution then
  225. local buttonPlatform = ccui.Button:create()
  226. self.ui.Panel_launch:addChild(buttonPlatform)
  227. local platformOffsetY = 140
  228. if self._isPortrait then
  229. platformOffsetY = 350
  230. end
  231. buttonPlatform:setPosition(cc.p(fixBtnPos.x, fixBtnPos.y - platformOffsetY))
  232. buttonPlatform:loadTextureNormal(self.path .. "btn_jryx_02.png",0)
  233. buttonPlatform:loadTexturePressed(self.path .. "btn_jryx_02_1.png",0)
  234. buttonPlatform:setTitleFontName("fonts/font.ttf")
  235. buttonPlatform:setTitleFontSize(18)
  236. local btnTextStr = global.CURRENT_OPERMODE == global.OPERMODE_WINDOWS and "电脑端" or "手机端"
  237. btnTextStr = fixNewLanguageString( btnTextStr )
  238. buttonPlatform:setTitleText(btnTextStr)
  239. buttonPlatform:setTouchEnabled(true)
  240. buttonPlatform:addClickEventListener(function()
  241. global.CURRENT_OPERMODE = (global.CURRENT_OPERMODE == global.OPERMODE_WINDOWS and global.OPERMODE_MOBILE or global.OPERMODE_WINDOWS)
  242. buttonPlatform:setTitleText(btnTextStr)
  243. --
  244. local resolution = (global.CURRENT_OPERMODE == global.OPERMODE_WINDOWS) and "1024x768" or "1136x640"
  245. global.L_GameEnvManager:SetGameEnvDataByKey("resolution", resolution)
  246. global.L_GameEnvManager:SetGameEnvDataByKey("oper_mode", global.CURRENT_OPERMODE)
  247. global.L_GameEnvManager:RestartGame()
  248. end)
  249. drawButtonColorStyle(buttonPlatform, {fontSize=18, color=cc.c3b(0xf8, 0xe6, 0xc6), outlineSize=3, outlineColor=cc.c3b(0x11,0x11,0x11)})
  250. if showResolution then
  251. buttonPlatform:setVisible(false)
  252. end
  253. --
  254. if global.CURRENT_OPERMODE == global.OPERMODE_WINDOWS then
  255. local buttonResolution = ccui.Button:create()
  256. self.ui.Panel_launch:addChild(buttonResolution)
  257. buttonResolution:setPosition(cc.p(fixBtnPos.x-100, fixBtnPos.y - platformOffsetY))
  258. buttonResolution:loadTextureNormal(self.path .. "btn_jryx_02.png",0)
  259. buttonResolution:loadTexturePressed(self.path .. "btn_jryx_02_1.png",0)
  260. buttonResolution:setTitleFontName("fonts/font.ttf")
  261. buttonResolution:setTitleFontSize(18)
  262. buttonResolution:setTitleText(string.format("%s x %s", global.DesignSize_Win.width, global.DesignSize_Win.height))
  263. buttonResolution:setTouchEnabled(true)
  264. buttonResolution:addClickEventListener(function()
  265. local resolutions =
  266. {
  267. {width = 1136, height = 640},
  268. }
  269. if otherResolution and string.len( otherResolution ) > 0 then
  270. local data = string.split( otherResolution, "|" )
  271. for _, v in ipairs(data) do
  272. if v and v ~= "" then
  273. local size = string.split( v, "x" )
  274. if size and tonumber(size[1]) and tonumber(size[2]) then
  275. table.insert( resolutions,{width = tonumber(size[1]), height = tonumber(size[2]) } )
  276. end
  277. end
  278. end
  279. end
  280. local newresolution = resolutions[1]
  281. for k, v in pairs(resolutions) do
  282. if v.width == global.DesignSize_Win.width and v.height == global.DesignSize_Win.height then
  283. local index = (k == #resolutions and 1 or k+1)
  284. newresolution = resolutions[index]
  285. break
  286. end
  287. end
  288. global.L_GameEnvManager:SetGameEnvDataByKey("resolution", string.format("%sx%s", newresolution.width, newresolution.height))
  289. global.L_GameEnvManager:SetGamePreEnvDataByKey("resolution", string.format("%sx%s", newresolution.width, newresolution.height))
  290. global.L_GameEnvManager:RestartGame()
  291. end)
  292. drawButtonColorStyle(buttonResolution, {fontSize=18, color=cc.c3b(0xf8, 0xe6, 0xc6), outlineSize=3, outlineColor=cc.c3b(0x11,0x11,0x11)})
  293. end
  294. end
  295. -- 监听window size change
  296. if global.isWindows and not global.isBoxLogin then
  297. self._windowResizedListener = cc.EventListenerCustom:create("glview_window_resized", handler( self, self.onWindowResized ))
  298. global.Director:getEventDispatcher():addEventListenerWithFixedPriority(self._windowResizedListener, 1)
  299. end
  300. -- 10min,执行退出SDK/返回盒子
  301. self.ui.Panel_launch:runAction(cc.Sequence:create(cc.DelayTime:create(10*60), cc.CallFunc:create(function()
  302. if global.isBoxLogin and global.L_NativeBridgeManager.GN_finishGame and not global.isWindows then
  303. global.L_NativeBridgeManager:GN_finishGame()
  304. return
  305. end
  306. if tonumber(global.L_GameEnvManager:GetEnvDataByKey("isBoxLogin")) == 1 and global.L_GameEnvManager:GetEnvDataByKey("isCloudLogin") then
  307. return
  308. end
  309. global.L_NativeBridgeManager:GN_accountLogout()
  310. global.L_GameEnvManager:RestartGame()
  311. end)))
  312. self:InitGameList()
  313. return true
  314. end
  315. function ModuleChooseLayer:InitGameList()
  316. self.ui.Panel_webview:setVisible(false)
  317. local winSize = global.Director:getWinSize()
  318. self.ui.Panel_webview:setContentSize(winSize.width, winSize.height)
  319. self.ui.Panel_webview_tips:setPosition(winSize.width / 2 , winSize.height / 2)
  320. self.ui.Panel_webview_tips:setVisible(false)
  321. self.ui.Panel_webview:addClickEventListener(function ()
  322. -- self:HideGameList()
  323. end)
  324. self.ui.Button_exit_wait:addClickEventListener(function ()
  325. self:HideGameList()
  326. end)
  327. self.ui.Image_web_wait:runAction(cc.RepeatForever:create(cc.RotateBy:create(1.5, 360)))
  328. end
  329. function ModuleChooseLayer:HideGameList()
  330. self.ui.Panel_webview:setVisible(false)
  331. self.ui.Panel_webview_tips:setVisible(false)
  332. if self._webView then
  333. self._webView:removeFromParent()
  334. self._webView = nil
  335. end
  336. end
  337. function ModuleChooseLayer:onWindowResized( eventCustom )
  338. global.L_GameEnvManager:RestartGame()
  339. end
  340. function ModuleChooseLayer:InitCustomUI()
  341. local lastBtnPosX,lastBtnPosY = nil,nil
  342. if self.ui.Button_fix then
  343. lastBtnPosX,lastBtnPosY = self.ui.Button_fix:getPosition()
  344. end
  345. local Button_delete_account = ccui.Button:create()
  346. self.ui.Panel_launch:addChild(Button_delete_account)
  347. Button_delete_account:setPosition(cc.p(lastBtnPosX or fixBtnPos.x, lastBtnPosY and (lastBtnPosY-70) or fixBtnPos.y))
  348. Button_delete_account:loadTextureNormal(self.path .. "btn_jryx_02.png",0)
  349. Button_delete_account:loadTexturePressed(self.path .. "btn_jryx_02_1.png",0)
  350. Button_delete_account:setTitleFontName("fonts/font.ttf")
  351. Button_delete_account:setTitleFontSize(18)
  352. local btnTextStr = fixNewLanguageString( "注销账号" )
  353. Button_delete_account:setTitleText(btnTextStr)
  354. Button_delete_account:setTouchEnabled(true)
  355. Button_delete_account:setVisible(false)
  356. self.ui.Button_delete_account = Button_delete_account
  357. end
  358. function ModuleChooseLayer:LaunchModule()
  359. releasePrint("++++++++++++++++++++++++++++launch module")
  360. --
  361. ShowLoadingBar(1)
  362. self.ui.Button_launch:setTouchEnabled(false)
  363. self.ui.Button_launch:runAction(cc.Sequence:create(
  364. cc.DelayTime:create(3),
  365. cc.CallFunc:create(function() self.ui.Button_launch:setTouchEnabled(true) end))
  366. )
  367. -- 未勾选用户协议
  368. if not self.BoxAutoEnterGame and self.ui.CheckBox_agreement and not self.ui.CheckBox_agreement:isSelected() then
  369. global.L_SystemTipsManager:ShowTips("请仔细阅读下方协议并勾选")
  370. -- 弹出用户协议提示 上报自定义事件
  371. local dataParam = {
  372. event={time=os.time(),name = "openNotice_agreement",type = "track"}
  373. }
  374. local userId = global.L_GameEnvManager:GetEnvDataByKey("user_id") or global.L_GameEnvManager:GetEnvDataByKey("uid")
  375. if userId and userId ~= "" then
  376. dataParam.user = {id = userId}
  377. end
  378. global.L_DataRePort:SendRePortData( dataParam )
  379. return
  380. end
  381. -- 未曾登录
  382. if not self.BoxAutoEnterGame and global.isMobile and (1 ~= global.L_NativeBridgeManager:GetLoginState()) then
  383. global.L_NativeBridgeManager:GN_accountLogin()
  384. return
  385. end
  386. if not self._currentModule or not self._currentSubMod then
  387. global.L_SystemTipsManager:ShowTips("未选择游戏模块!")
  388. return
  389. end
  390. local modGameEnv = self._currentSubMod:GetGameEnv()
  391. local serverData = modGameEnv:GetServerData()
  392. local selectedServer = modGameEnv:GetSelectedServer()
  393. if modGameEnv:IsNewServerlist() and not modGameEnv:GetCustomIsLoaded() then
  394. releasePrint("custom还未获取!")
  395. return
  396. end
  397. -- 未选择服务器
  398. if not selectedServer then
  399. global.L_SystemTipsManager:ShowTips("请选择服务器!")
  400. return nil
  401. end
  402. -- 维护且不是白名单
  403. if selectedServer.state == 4 and (not modGameEnv:IsWhitelist()) then
  404. global.L_SystemTipsManager:ShowTips("服务器正在维护中,请选择其它服务器!")
  405. return
  406. end
  407. -- 登录数据
  408. local username = global.L_NativeBridgeManager:GetUsername()
  409. local password = global.L_NativeBridgeManager:GetPassword()
  410. modGameEnv:SetLoginData({username = username, password = password})
  411. -- 选择的服务器存储到本地
  412. modGameEnv:SaveLastServers()
  413. -- 上次选择模块存储本地
  414. local launcherModID = global.L_ModuleManager:GetLauncherModuleID()
  415. local channelID = tostring(global.L_GameEnvManager:GetChannelID())
  416. local userData = UserData:new(launcherModID .. channelID .. "_data")
  417. userData:setStringForKey("last_module", self._currentModule:GetID())
  418. userData:setStringForKey("last_submod", self._currentSubMod:GetID())
  419. userData:writeMapDataToFile()
  420. -- 发起一个请求, 请求启动游戏
  421. local modGameEnv = self._currentSubMod:GetGameEnv()
  422. local serverData = modGameEnv:GetServerData()
  423. local selectedServer = modGameEnv:GetSelectedServer()
  424. local server_id = selectedServer.serverId
  425. local server_name = selectedServer.serverName
  426. -- 进入游戏, 上报自定义事件
  427. local dataParam = {
  428. event = {
  429. time = os.time(), name = "clickButton_enter", type = "track"
  430. },
  431. properities = {
  432. servid = tostring(server_id), server_name = tostring(server_name)
  433. }
  434. }
  435. local main_servid = selectedServer and selectedServer.mainServerId
  436. local main_server_name = selectedServer and selectedServer.mainServerName
  437. dataParam.properities.main_servid = main_servid and tostring(main_servid) or tostring(server_id)
  438. dataParam.properities.main_server_name = main_server_name and tostring(main_server_name) or tostring(server_name)
  439. local userId = global.L_GameEnvManager:GetEnvDataByKey("user_id") or global.L_GameEnvManager:GetEnvDataByKey("uid")
  440. if userId and userId ~= "" then
  441. dataParam.user = {id = userId}
  442. end
  443. global.L_DataRePort:SendRePortData( dataParam )
  444. local jData = {}
  445. jData.gameid = self._currentSubMod:GetOperID()
  446. jData.id = self._currentSubMod:GetID()
  447. jData.name = self._currentSubMod:GetName()
  448. jData.channelID = tostring(global.L_GameEnvManager:GetChannelID())
  449. jData.server_id = server_id
  450. jData.server_name = server_name
  451. jData.userId = global.L_GameEnvManager:GetEnvDataByKey("user_id") or ""
  452. global.L_NativeBridgeManager:GN_requestAllowLaunch(jData)
  453. -- run game
  454. if self._launchTimerID then
  455. UnSchedule(self._launchTimerID)
  456. self._launchTimerID = nil
  457. end
  458. local function scheduleCB()
  459. -- 不允许进入
  460. if not global.L_NativeBridgeManager:CheckAllowLaunch() then
  461. return false
  462. end
  463. -- 未选择模块
  464. if not self._currentModule or not self._currentSubMod then
  465. return false
  466. end
  467. -- 停止定时器
  468. if self._launchTimerID then
  469. UnSchedule(self._launchTimerID)
  470. self._launchTimerID = nil
  471. end
  472. -- 停止srvlist自动刷新定时器
  473. if self._srvlistTimerID then
  474. UnSchedule(self._srvlistTimerID)
  475. self._srvlistTimerID = nil
  476. end
  477. -- 数据上报
  478. local jData = {}
  479. jData.gameid = self._currentSubMod:GetOperID()
  480. jData.id = self._currentSubMod:GetID()
  481. jData.name = self._currentSubMod:GetName()
  482. jData.subModID = self._currentSubMod:GetID()
  483. jData.moduleID = self._currentModule:GetID()
  484. jData.version = self._currentModule:GetVersion()
  485. jData.originVersion = self._currentModule:GetOriginVersion()
  486. jData.cacheVersion = self._currentModule:GetCacheVersion()
  487. jData.channelID = tostring(global.L_GameEnvManager:GetChannelID())
  488. jData.server_id = selectedServer.serverId
  489. jData.server_name = selectedServer.serverName
  490. global.L_NativeBridgeManager:GN_selectGameMod(jData)
  491. if self._windowResizedListener then
  492. global.Director:getEventDispatcher():removeEventListener( self._windowResizedListener )
  493. self._windowResizedListener = nil
  494. end
  495. -- 进入了
  496. self._currentModule:RegisterSubMod(self._currentSubMod:GetID())
  497. global.L_ModuleManager:RegisterModuleByID(self._currentModule:GetID())
  498. global.L_ModuleManager:CheckModuleLocalStorage()
  499. end
  500. self._launchTimerID = Schedule(scheduleCB, 0.1)
  501. -- 停止定时器,目的是为了停止自动执行退出游戏操作
  502. self.ui.Panel_launch:stopAllActions()
  503. end
  504. function ModuleChooseLayer:checkAutoLaunchGameMod()
  505. if not isAutoLaunchEnable() then
  506. return
  507. end
  508. if tonumber(global.L_GameEnvManager:GetEnvDataByKey("auto_agreement_select")) == 1 then
  509. self.ui.CheckBox_agreement:setSelected(true)
  510. end
  511. -- 倒计时3s自动登录 新玩家1s 老玩家6s
  512. local newPlayerDelay = tonumber(global.L_GameEnvManager:GetEnvDataByKey("auto_new_player_delay")) or 1
  513. local oldPlayerDelay = tonumber(global.L_GameEnvManager:GetEnvDataByKey("auto_old_player_delay")) or 6
  514. local isNewPlayer = self._existLastMod == false
  515. local delay = isNewPlayer and newPlayerDelay or oldPlayerDelay
  516. local function callback()
  517. self.ui.Button_launch:setTitleText(string.format("进入游戏(%s)", delay))
  518. delay = delay - 1
  519. if delay == 0 then
  520. self:LaunchModule()
  521. end
  522. end
  523. local action = self.ui.Button_launch.ctdownAction
  524. self.ui.Button_launch:stopAction( action )
  525. local sequence = cc.Sequence:create(cc.DelayTime:create(1), cc.CallFunc:create(callback))
  526. action = cc.RepeatForever:create(sequence)
  527. self.ui.Button_launch:runAction(action)
  528. self.ui.Button_launch.ctdownAction = action
  529. callback()
  530. self:touchTerminateAutoButton()
  531. end
  532. function ModuleChooseLayer:terminateAutoLaunchGameMod()
  533. if not isAutoLaunchEnable() then
  534. return
  535. end
  536. local action = self.ui.Button_launch.ctdownAction
  537. if action then
  538. self.ui.Button_launch:stopAction( action )
  539. action = nil
  540. end
  541. self.ui.Button_launch:setTitleText("进入游戏")
  542. end
  543. -- 创建触摸层 用来停止自动按钮
  544. function ModuleChooseLayer:touchTerminateAutoButton()
  545. if self._tochAutoPanel then
  546. return
  547. end
  548. local panel = ccui.Layout:create()
  549. panel:setContentSize( global.Director:getVisibleSize() )
  550. panel:setTouchEnabled( true )
  551. panel:setSwallowTouches( false )
  552. self:addChild( panel,999 )
  553. self._tochAutoPanel = panel
  554. panel:addClickEventListener( function()
  555. self:terminateAutoLaunchGameMod()
  556. end)
  557. end
  558. function ModuleChooseLayer:InitCode()
  559. local items = {
  560. ["1212"] = function()
  561. -- 开启帧率
  562. global.Director:setDisplayStats(true)
  563. end,
  564. ["333333333"] = function()
  565. -- 开启远程测试
  566. local console = global.Director:getConsole()
  567. console:listenOnTCP( 9999 )
  568. end,
  569. ["222222"] = function()
  570. local ipurl = "https://sdkv2.dhsf.xqhuyu.com/api/data/client_ip"
  571. if self._currentSubMod then
  572. local modGameEnv = self._currentSubMod:GetGameEnv()
  573. local customData = modGameEnv:GetCustomDataByKey("clientIPUrl")
  574. if customData and string.len(customData) > 0 then
  575. ipurl = customData
  576. end
  577. end
  578. if ipurl and string.len(ipurl) > 0 then
  579. HTTPRequest(ipurl, function(success, response)
  580. if success then
  581. HideLoadingBar()
  582. local modGameEnv = self._currentSubMod:GetGameEnv()
  583. modGameEnv:SetSelfip(response)
  584. global.L_SystemTipsManager:ShowTips(response)
  585. end
  586. end)
  587. end
  588. ShowLoadingBar()
  589. end,
  590. ["4444"] = function()
  591. global.L_GameEnvManager:RestartGame()
  592. end
  593. }
  594. local input = ""
  595. local viewSize = global.Director:getVisibleSize()
  596. local width = viewSize.width
  597. local height = viewSize.height
  598. local pos = {cc.p(25, height - 25), cc.p(width - 25, height - 25), cc.p(25, 25), cc.p(width - 25, 25)}
  599. for index = 1, 4 do
  600. local layout = ccui.Layout:create()
  601. self:addChild(layout)
  602. layout:setTouchEnabled(true)
  603. layout:setContentSize(50, 50)
  604. layout:setAnchorPoint(cc.p(0.5, 0.5))
  605. layout:setPosition(pos[index])
  606. layout:addClickEventListener(
  607. function()
  608. input = input .. tostring(index)
  609. for k, callback in pairs(items) do
  610. if string.find(input, k) then
  611. global.L_SystemTipsManager:ShowTips(k)
  612. input = ""
  613. callback()
  614. break
  615. end
  616. end
  617. end
  618. )
  619. end
  620. end
  621. function ModuleChooseLayer:InitLaunch()
  622. -------------------------------------------------------------
  623. local isBoxLogin = global.L_GameEnvManager:GetEnvDataByKey("isBoxLogin")
  624. global.isBoxLogin = isBoxLogin == 1
  625. local isUgc = global.L_GameEnvManager:GetEnvDataByKey("isUgc")
  626. global.isUgc = isUgc == 1
  627. self:updateBoxUI()
  628. -- 切换账号按钮文本可替换
  629. local buttonName = global.L_GameEnvManager:GetEnvDataByKey("logoutName")
  630. if buttonName and buttonName ~= "" then
  631. local btnTextStr = fixNewLanguageString( buttonName )
  632. self.ui.Button_logout:setTitleText(btnTextStr)
  633. end
  634. ----------------------------------------------------------------
  635. -- 进入游戏
  636. self.ui.Button_launch:addClickEventListener(function()
  637. -- 迅雷检测游戏实名
  638. if global.L_NativeBridgeManager:PCCheckMedthodName("GN_checkRealName") then
  639. local envMgr = global.L_GameEnvManager
  640. local env_uid = envMgr:GetEnvDataByKey("user_id") or ""
  641. local data = {
  642. userId = tostring( env_uid )
  643. }
  644. global.L_NativeBridgeManager:PCNoticeRequest("GN_checkRealName",data)
  645. return
  646. end
  647. self:LaunchModule()
  648. end)
  649. local shiwan = global.L_GameEnvManager:GetEnvDataByKey("shiwan")
  650. if shiwan and tonumber(shiwan) == 1 then
  651. self.ui.Button_select:setTouchEnabled(false)
  652. end
  653. -- 上次区服
  654. self.ui.Button_select:addClickEventListener(function()
  655. self:HideLaunch()
  656. self:ShowServers()
  657. self:UpdateServers()
  658. end)
  659. -- 切换账号/返回盒子
  660. if not global.isBoxLogin then
  661. self.ui.Button_logout:setVisible(false)
  662. end
  663. self.ui.Button_logout:addClickEventListener(function()
  664. if (global.isBoxLogin or global.isUgc) and global.L_NativeBridgeManager.GN_finishGame and not global.isWindows then
  665. global.L_NativeBridgeManager:GN_finishGame()
  666. return
  667. end
  668. global.L_NativeBridgeManager:GN_accountLogout()
  669. global.L_GameEnvManager:RestartGame()
  670. end)
  671. -- 游戏大厅(盒子)
  672. self.ui.Button_game_list:addClickEventListener(function()
  673. if global.isBoxLogin and self._supportGameList then
  674. --游戏大厅
  675. self:ShowGameList()
  676. end
  677. end)
  678. -- 游戏公告
  679. self.ui.Button_announce:addClickEventListener(function()
  680. self:ShowModuleAnnounce()
  681. end)
  682. -- 注销账号
  683. if self.ui.Button_delete_account then
  684. self.ui.Button_delete_account:setVisible(false)
  685. self.ui.Button_delete_account:addClickEventListener(function()
  686. if global.L_NativeBridgeManager.GN_deleteAccount then
  687. global.L_NativeBridgeManager:GN_deleteAccount()
  688. end
  689. end)
  690. end
  691. -- 游戏修复
  692. self.ui.Button_fix:addClickEventListener(function()
  693. local function callback( aType, custom )
  694. if aType == 1 then
  695. -- cleanup
  696. local fileUtil = cc.FileUtils:getInstance()
  697. local writePath = fileUtil:getWritablePath()
  698. fileUtil:removeDirectory( writePath )
  699. fileUtil:purgeCachedEntries()
  700. releasePrint("+++++++++++++++++++++++++++++isBoxLogin, isCloudLogin ", global.L_GameEnvManager:GetEnvDataByKey("isBoxLogin"), global.L_GameEnvManager:GetEnvDataByKey("isCloudLogin"))
  701. local mode = nil
  702. if global.L_GameEnvManager:GetEnvDataByKey("isBoxLogin") and global.L_GameEnvManager:GetEnvDataByKey("isCloudLogin") then
  703. mode = "cold"
  704. end
  705. global.L_NativeBridgeManager:GN_accountLogout()
  706. global.L_GameEnvManager:RestartGame(mode)
  707. end
  708. end
  709. local tipsData = {}
  710. tipsData.str = "当补丁缺失或其他显示异常问题,可尝试在此进行\n修复。(此操作会清理本地补丁并重新下载,请在\n良好的网络环境下进行)"
  711. tipsData.btnType = 2
  712. tipsData.callback = callback
  713. global.L_CommonTipsManager:OpenLayer(tipsData)
  714. end)
  715. -- 分享游戏
  716. self.ui.Button_share:setVisible(false)
  717. self.ui.Button_share:addClickEventListener(function()
  718. if not self._currentModule or not self._currentSubMod then
  719. return nil
  720. end
  721. local modGameEnv = self._currentSubMod:GetGameEnv()
  722. if not modGameEnv then
  723. return nil
  724. end
  725. local shareUrl = modGameEnv:GetCustomDataByKey("shareUrl")
  726. local isShowShare = shareUrl and shareUrl ~= ""
  727. if not isShowShare then
  728. return nil
  729. end
  730. cc.Application:getInstance():openURL(shareUrl)
  731. end)
  732. -- 用户协议
  733. self.ui.Button_agreement:setVisible(false)
  734. self.ui.Button_agreement:addClickEventListener(function()
  735. self:ShowAgreement()
  736. end)
  737. -- 用户协议复选框
  738. self.ui.CheckBox_agreement:addEventListener(function(sender)
  739. local isSelected = sender:isSelected()
  740. local userData = UserData:new("agreement_data")
  741. userData:setIntegerForKey("select", isSelected and 1 or 0)
  742. userData:writeMapDataToFile()
  743. -- 用户协议复选框点击 上报自定义事件
  744. local dataParam = {
  745. event={time=os.time(),name = "tickNotice_agreement",type = "track"}
  746. }
  747. local userId = global.L_GameEnvManager:GetEnvDataByKey("user_id") or global.L_GameEnvManager:GetEnvDataByKey("uid")
  748. if userId and userId ~= "" then
  749. dataParam.user = {id = userId}
  750. end
  751. global.L_DataRePort:SendRePortData( dataParam )
  752. end)
  753. -- 版号
  754. local copyright1 = ""
  755. local copyright2 = ""
  756. self.ui.Text_copyright:setString(copyright1 .. "\n" .. copyright2)
  757. self.ui.Text_copyright:setVisible(false)
  758. -- 健康游戏
  759. self.ui.Text_health:setVisible(false)
  760. self.ui.Text_health_tips:setVisible(false)
  761. -- logo
  762. self.ui.Image_icon:setVisible(false)
  763. -- 版本号
  764. local visibleSize = global.Director:getVisibleSize()
  765. if self._isPortrait then
  766. local y = self.ui.ListView_modules:getPositionY()
  767. self.ui.Text_ver_launcher:setPositionY(y + 30)
  768. else
  769. self.ui.Text_ver_launcher:setPositionY(640-5)
  770. end
  771. self.ui.Text_ver_launcher:setFontSize(16)
  772. self.ui.Text_ver_launcher:setVisible(false)
  773. self.ui.Text_ver_module:setVisible(false)
  774. drawButtonColorStyle(self.ui.Button_launch, {fontSize=18, color=cc.c3b(0xf8, 0xe6, 0xc6), outlineSize=3, outlineColor=cc.c3b(0x11,0x11,0x11)})
  775. drawButtonColorStyle(self.ui.Button_logout, {fontSize=18, color=cc.c3b(0xf8, 0xe6, 0xc6), outlineSize=3, outlineColor=cc.c3b(0x11,0x11,0x11)})
  776. drawButtonColorStyle(self.ui.Button_announce, {fontSize=18, color=cc.c3b(0xf8, 0xe6, 0xc6), outlineSize=3, outlineColor=cc.c3b(0x11,0x11,0x11)})
  777. drawButtonColorStyle(self.ui.Button_fix, {fontSize=18, color=cc.c3b(0xf8, 0xe6, 0xc6), outlineSize=3, outlineColor=cc.c3b(0x11,0x11,0x11)})
  778. drawButtonColorStyle(self.ui.Button_share, {fontSize=18, color=cc.c3b(0xf8, 0xe6, 0xc6), outlineSize=3, outlineColor=cc.c3b(0x11,0x11,0x11)})
  779. drawButtonColorStyle(self.ui.Button_agreement, {fontSize=18, color=cc.c3b(0xf8, 0xe6, 0xc6), outlineSize=3, outlineColor=cc.c3b(0x11,0x11,0x11)})
  780. drawButtonColorStyle(self.ui.Button_game_list, {fontSize=18, color=cc.c3b(0xf8, 0xe6, 0xc6), outlineSize=3, outlineColor=cc.c3b(0x11,0x11,0x11)})
  781. drawButtonColorStyle(self.ui.Button_select, {fontSize=18, color=cc.c3b(0xf8, 0xe6, 0xc6), outlineSize=3, outlineColor=cc.c3b(0x11,0x11,0x11)})
  782. drawButtonColorStyle(self.ui.Button_game, {fontSize=18, color=cc.c3b(0xf8, 0xe6, 0xc6), outlineSize=3, outlineColor=cc.c3b(0x11,0x11,0x11)})
  783. if self.ui.Button_delete_account then
  784. drawButtonColorStyle(self.ui.Button_delete_account, {fontSize=18, color=cc.c3b(0xf8, 0xe6, 0xc6), outlineSize=3, outlineColor=cc.c3b(0x11,0x11,0x11)})
  785. end
  786. end
  787. function ModuleChooseLayer:ShowLaunch()
  788. self.ui.Panel_launch:setVisible(true)
  789. end
  790. function ModuleChooseLayer:HideLaunch()
  791. self.ui.Panel_launch:setVisible(false)
  792. end
  793. function ModuleChooseLayer:InitAllModules()
  794. self.ui.ListView_modules:removeAllItems()
  795. local allSubMods = {}
  796. local allModules = global.L_ModuleManager:GetAllModules()
  797. for _, module in ipairs(allModules) do
  798. for _, subMod in ipairs(module:GetSubMods()) do
  799. table.insert(allSubMods, {module = module, subMod = subMod})
  800. end
  801. end
  802. for k, v in ipairs(allSubMods) do
  803. local key = string.format("%s_%s", v.module:GetID(), v.subMod:GetID())
  804. local cell = self:CreateModuleCell(v)
  805. self._subModCells[key] = cell
  806. self.ui.ListView_modules:pushBackCustomItem(cell.nativeUI)
  807. end
  808. self.ui.ListView_modules:setVisible(#allSubMods > 1)
  809. -- 审核服,隐藏多版本
  810. if global.L_GameEnvManager:IsReview() then
  811. self.ui.ListView_modules:setVisible(false)
  812. end
  813. end
  814. function ModuleChooseLayer:CreateModuleCell(data)
  815. local root = CreateExport_launcher("server/module_cell")
  816. local layout = root:getChildByName("Panel_1")
  817. layout:removeFromParent()
  818. local module = data.module
  819. local subMod = data.subMod
  820. local cell = ui_delegate(layout)
  821. cell.Button_1:setTitleText(subMod.name)
  822. cell.Button_1:addClickEventListener(function()
  823. self:OnSelectModule(module, subMod)
  824. end)
  825. drawButtonColorStyle(cell.Button_1, {fontSize=18, color=cc.c3b(0xf8, 0xe6, 0xc6), outlineSize=3, outlineColor=cc.c3b(0x11,0x11,0x11)})
  826. return cell
  827. end
  828. function ModuleChooseLayer:SelectDefaultModule()
  829. local defaultModule = nil
  830. -- 存储文件
  831. local launcherModID = global.L_ModuleManager:GetLauncherModuleID()
  832. local channelID = tostring(global.L_GameEnvManager:GetChannelID())
  833. local userData = UserData:new(launcherModID .. channelID .. "_data")
  834. -- env 传入
  835. if not defaultModule then
  836. local envModID = global.L_GameEnvManager:GetEnvDataByKey("modID")
  837. if envModID and string.len(envModID) > 0 then
  838. defaultModule = global.L_ModuleManager:GetModuleByID(envModID)
  839. end
  840. end
  841. -- 上次
  842. if not defaultModule then
  843. local lastModuleID = userData:getStringForKey("last_module", nil)
  844. if lastModuleID and string.len(lastModuleID) > 0 then
  845. defaultModule = global.L_ModuleManager:GetModuleByID(lastModuleID)
  846. self._existLastMod = true
  847. end
  848. end
  849. -- 推荐
  850. if not defaultModule then
  851. local referModuleID = global.L_ModuleManager:GetReferModuleID()
  852. if referModuleID and string.len(referModuleID) > 0 then
  853. defaultModule = global.L_ModuleManager:GetModuleByID(referModuleID)
  854. end
  855. end
  856. -- 第一个
  857. if not defaultModule then
  858. local allModule = global.L_ModuleManager:GetAllModules()
  859. defaultModule = allModule[1]
  860. end
  861. -- 子模块
  862. local defaultSubMod = nil
  863. -- env 传入
  864. if defaultModule and not defaultSubMod then
  865. local subModID = global.L_GameEnvManager:GetEnvDataByKey("subModID", nil)
  866. if subModID and string.len(subModID) > 0 then
  867. defaultSubMod = defaultModule:GetSubModByID(subModID)
  868. end
  869. end
  870. -- 盒子启动的
  871. local boxConfig = global.L_GameEnvManager:GetEnvDataByKey("boxConfig")
  872. if not defaultSubMod and boxConfig and boxConfig ~= "" then
  873. local isJson = false
  874. local findS, findE = string.find(boxConfig, "^{(.-)}$")
  875. if findS and findE and findE > findS then
  876. isJson = true
  877. end
  878. local jsonData = isJson and cjson.decode(boxConfig)
  879. if jsonData and jsonData.gameId then
  880. local allModules = global.L_ModuleManager:GetAllModules()
  881. for _, module in ipairs(allModules) do
  882. for _, subMod in ipairs(module:GetSubMods()) do
  883. if subMod:GetOperID() == jsonData.gameId then
  884. defaultSubMod = subMod
  885. break
  886. end
  887. end
  888. if defaultSubMod then
  889. break
  890. end
  891. end
  892. end
  893. end
  894. -- 上次
  895. if defaultModule and not defaultSubMod then
  896. local lastSubModID = userData:getStringForKey("last_submod", nil)
  897. if lastSubModID and string.len(lastSubModID) > 0 then
  898. defaultSubMod = defaultModule:GetSubModByID(lastSubModID)
  899. end
  900. end
  901. -- 推荐
  902. if defaultModule and not defaultSubMod then
  903. local referModuleID = defaultModule:GetRefer()
  904. if referModuleID and string.len(referModuleID) > 0 then
  905. defaultSubMod = defaultModule:GetSubModByID(referModuleID)
  906. end
  907. end
  908. -- 第一个
  909. if defaultModule and not defaultSubMod then
  910. local subMods = defaultModule:GetSubMods()
  911. defaultSubMod = subMods[1]
  912. end
  913. -- 选择
  914. if defaultModule and defaultSubMod then
  915. self:OnSelectModule(defaultModule, defaultSubMod)
  916. end
  917. end
  918. function ModuleChooseLayer:GetServerTime()
  919. GetModListServerTime(true, self._currentSubMod)
  920. end
  921. function ModuleChooseLayer:OnSelectModule(module, subMod)
  922. self._currentModule = module
  923. self._currentSubMod = subMod
  924. self:GetServerTime()
  925. -- 检测modeInfoURL合法性
  926. global.L_DataRePort:RequestModeInfoCheck(subMod)
  927. self:UpdateCurrentModule()
  928. self:checkAutoLaunchGameMod()
  929. for k, v in pairs(self._subModCells) do
  930. local moduleCell = self._subModCells[k]
  931. local key = string.format("%s_%s", module:GetID(), subMod:GetID())
  932. local able = (k == key)
  933. local path = string.format(self.path .. "%s.png", able and "btn_jryx_03" or "btn_jryx_03_1")
  934. moduleCell.Button_1:loadTextureNormal(path)
  935. moduleCell.Button_1:setTouchEnabled(not able)
  936. end
  937. -- request server data
  938. local modGameEnv = subMod:GetGameEnv()
  939. if not modGameEnv:GetServerData() then
  940. self:RequestModSrvlist(true)
  941. else
  942. self:UpdateServers()
  943. self:UpdateSelected()
  944. if modGameEnv:GetCustomIsLoaded() then
  945. self:OnCustomData(false)
  946. end
  947. end
  948. -- 通知native,当前选择的模块发生改变(注意!!进游戏第一次选择也会通知,比accountLogin更早)
  949. local jsonData = {}
  950. jsonData.channelId = tostring(global.L_GameEnvManager:GetChannelID())
  951. jsonData.gameid = self._currentSubMod:GetOperID()
  952. jsonData.id = self._currentSubMod:GetID()
  953. jsonData.name = self._currentSubMod:GetName()
  954. jsonData.subModID = self._currentSubMod:GetID()
  955. jsonData.moduleID = self._currentModule:GetID()
  956. jsonData.gameidlist = global.L_ModuleManager:GetAllGameID()
  957. global.L_NativeBridgeManager:GN_SendGameInfo(jsonData)
  958. -- 获取新app数据通知native
  959. global.L_MultiVersionData:GetNewAppData( subMod )
  960. -- 设备登录 上报自定义事件
  961. global.L_DataRePort:UpDeviceLogin(self._currentSubMod)
  962. end
  963. function ModuleChooseLayer:UpdateCurrentModule()
  964. if not self._currentModule or not self._currentSubMod then
  965. return nil
  966. end
  967. local channelID = tostring(global.L_GameEnvManager:GetChannelID())
  968. local launcherMod = global.L_ModuleManager:GetLauncherModule()
  969. local lOringinVersion = launcherMod:GetOriginVersion()
  970. local lRemoteVersion = launcherMod:GetRemoteVersion()
  971. local originVersion = self._currentModule:GetOriginVersion()
  972. local cacheVersion = self._currentModule:GetCacheVersion()
  973. local versionStr = string.format("%s (%s/%s) (%s/%s)", channelID, lOringinVersion, lRemoteVersion, originVersion, cacheVersion)
  974. self.ui.Text_ver_launcher:setString(versionStr)
  975. -- logo
  976. self:UpdateLogo()
  977. local subModInfo = self._currentSubMod:GetSubModInfo()
  978. local logoInfo = subModInfo.logo
  979. local downloadFlag = self.DownloadFlag.Logo
  980. if logoInfo and logoInfo.name and logoInfo.name ~= "" and logoInfo.url and logoInfo.url ~= "" then
  981. global.L_GameEnvManager:downloadResEasy(logoInfo.url, logoInfo.name, function(isOK, filename)
  982. if global.L_GameLayerManager._uiNode then
  983. global.L_ModuleChooseManager:OnDownloadResCB(isOK, filename, downloadFlag)
  984. end
  985. end)
  986. end
  987. -- logo mini
  988. local logoInfoMini = subModInfo.logo_mini
  989. -- local isBoxLogin = global.L_GameEnvManager:GetEnvDataByKey("isBoxLogin")
  990. -- if isBoxLogin == 1 then --盒子登录 取对应平台的版号logo
  991. -- if global.isWindows then
  992. -- logoInfoMini = subModInfo.logo_mini_box_pc
  993. -- else
  994. -- logoInfoMini = subModInfo.logo_mini_box
  995. -- end
  996. -- end
  997. local downloadFlag = self.DownloadFlag.LogoMini
  998. if logoInfoMini and logoInfoMini.name and logoInfoMini.name ~= "" and logoInfoMini.url and logoInfoMini.url ~= "" then
  999. global.L_GameEnvManager:downloadResEasy(logoInfoMini.url, logoInfoMini.name, function(isOK, filename)
  1000. if global.L_GameLayerManager._uiNode then
  1001. global.L_ModuleChooseManager:OnDownloadResCB(isOK, filename, downloadFlag)
  1002. end
  1003. end)
  1004. end
  1005. -- logo mini2
  1006. local logoInfoMini2 = subModInfo.logo_mini2
  1007. local downloadFlag = self.DownloadFlag.LogoMini2
  1008. if logoInfoMini2 and logoInfoMini2.name and logoInfoMini2.name ~= "" and logoInfoMini2.url and logoInfoMini2.url ~= "" then
  1009. global.L_GameEnvManager:downloadResEasy(logoInfoMini2.url, logoInfoMini2.name, function(isOK, filename)
  1010. if global.L_GameLayerManager._uiNode then
  1011. global.L_ModuleChooseManager:OnDownloadResCB(isOK, filename, downloadFlag)
  1012. end
  1013. end)
  1014. end
  1015. --current module
  1016. -- self.ui.Panel_game:setVisible(false)
  1017. if global.isBoxLogin or global.isUgc then
  1018. self.ui.Button_game:setTitleText(subModInfo.name or "")
  1019. else
  1020. local modName = ""
  1021. if global.isWindows then
  1022. modName = global.L_GameEnvManager:GetEnvDataByKey("subModName") or ""
  1023. else
  1024. modName = global.L_GameEnvManager:GetAPKPackageShowName() or ""
  1025. end
  1026. if string.len(modName) == 0 then
  1027. self.ui.Panel_game:setVisible(false)
  1028. else
  1029. self.ui.Button_game:setTitleText(modName)
  1030. end
  1031. end
  1032. end
  1033. function ModuleChooseLayer:decodeBase64(response)
  1034. local Base64 = require("lockbox.util.base64")
  1035. response = Base64.toString(response)
  1036. return response
  1037. end
  1038. function ModuleChooseLayer:decodeSrvlistXXTEA(response)
  1039. local fileUtil = cc.FileUtils:getInstance()
  1040. local filePath = fileUtil:getWritablePath() .. "temp_decode"
  1041. if fileUtil:isFileExist(filePath) then
  1042. fileUtil:removeFile(filePath)
  1043. end
  1044. fileUtil:writeStringToFile(response, filePath)
  1045. response = fileUtil:getDataFromFileEx(filePath)
  1046. return response
  1047. end
  1048. function ModuleChooseLayer:decodeSrvlist(response)
  1049. local needDecode = self._currentSubMod:GetIsSign()
  1050. if needDecode then
  1051. response = self:DecodeServerList(response)
  1052. end
  1053. local jsonData = cjson.decode(response)
  1054. return jsonData
  1055. end
  1056. function ModuleChooseLayer:AddSrvlistCacheNamePrefix(cacheName)
  1057. if not self._currentModule or not self._currentSubMod then
  1058. return string.format("%s_%s", cacheName, global.L_GameEnvManager:GetChannelID())
  1059. end
  1060. return string.format("%s_%s", cacheName, self._currentSubMod:GetOperID())
  1061. end
  1062. function ModuleChooseLayer:GetSrvlistCachePath()
  1063. local fileUtil = cc.FileUtils:getInstance()
  1064. local filename = self:AddSrvlistCacheNamePrefix("ResServerlist.txt")
  1065. local filePath = fileUtil:getWritablePath() .. filename
  1066. return filePath
  1067. end
  1068. function ModuleChooseLayer:CleanupLocalSrvlist()
  1069. local fileUtil = cc.FileUtils:getInstance()
  1070. local filePath = self:GetSrvlistCachePath()
  1071. if fileUtil:isFileExist(filePath) then
  1072. fileUtil:removeFile(filePath)
  1073. end
  1074. end
  1075. function ModuleChooseLayer:GetLocalRuntime()
  1076. local fileUtil = cc.FileUtils:getInstance()
  1077. local filePath = self:GetSrvlistCachePath()
  1078. if not fileUtil:isFileExist(filePath) then
  1079. return ""
  1080. end
  1081. local response = fileUtil:getDataFromFileEx(filePath)
  1082. local jsonData = self:decodeSrvlist(response)
  1083. if not jsonData then
  1084. return ""
  1085. end
  1086. if not jsonData.runtime then
  1087. return ""
  1088. end
  1089. return "runtime=" .. jsonData.runtime
  1090. end
  1091. function ModuleChooseLayer:RequestModSrvlist(showAnnounce)
  1092. if not self._currentModule or not self._currentSubMod then
  1093. return nil
  1094. end
  1095. local modGameEnv = self._currentSubMod:GetGameEnv()
  1096. local mmin = math.min
  1097. local mmax = math.max
  1098. ----------------------------------------
  1099. local function reportError(str, callback)
  1100. local tipsData = {
  1101. btnType = 1,
  1102. str = str,
  1103. callback = callback
  1104. }
  1105. global.L_CommonTipsManager:OpenLayer( tipsData )
  1106. end
  1107. ----------------------------------------
  1108. local function httpCB(success, response, url, code)
  1109. HideLoadingBar()
  1110. self._srvlistCount = self._srvlistCount + 1
  1111. local function callback()
  1112. self:RequestModSrvlist(showAnnounce)
  1113. end
  1114. -- 拉取失败,网络原因
  1115. if not success then
  1116. if self._srvlistCount >= 3 then
  1117. reportError("[srvlist][0]网络不给力哦!点“确认”重试。", callback)
  1118. -- 上报至服务器
  1119. global.L_DataRePort:ReportErrorModlistURL("SRVLIST_INFO_REQUEST_FAILED", "-3000", "Request srvlist INFO ERROR, CODE ERROR", url, code)
  1120. else
  1121. callback()
  1122. end
  1123. return nil
  1124. end
  1125. -- 拉取失败,内容空
  1126. if not response then
  1127. if self._srvlistCount >= 3 then
  1128. reportError("[srvlist][1]网络不给力哦!点“确认”重试。", callback)
  1129. -- 上报至服务器
  1130. global.L_DataRePort:ReportErrorModlistURL("SRVLIST_INFO_REQUEST_FAILED", "-3001", "Request srvlist INFO ERROR, RESPONSE ERROR", url, code)
  1131. else
  1132. callback()
  1133. end
  1134. return nil
  1135. end
  1136. local isXXTEAEncrypt = global.L_GameEnvManager:GetModlistCustomDataByKey("isEncrypt")
  1137. if not string.find(response, "latestData") and isXXTEAEncrypt and isXXTEAEncrypt == 1 then
  1138. response = self:decodeBase64(response)
  1139. end
  1140. -- xxtea 解密
  1141. response = self:decodeSrvlistXXTEA(response)
  1142. -- json解析,检测是否解析成功
  1143. local jsonData = self:decodeSrvlist(response)
  1144. if not jsonData then
  1145. self:CleanupLocalSrvlist()
  1146. reportError("[srvlist][2]远端服务器配置格式异常", callback)
  1147. -- 上报至服务器
  1148. global.L_DataRePort:ReportErrorModlistURL("SRVLIST_INFO_REQUEST_FAILED", "-3002", "Request srvlist INFO ERROR, JSON ERROR", url, code)
  1149. return nil
  1150. end
  1151. local fileUtil = cc.FileUtils:getInstance()
  1152. local filePath = ""
  1153. if jsonData.latestData then
  1154. -- 本地是否是最新的
  1155. -- 读取本地
  1156. filePath = self:GetSrvlistCachePath()
  1157. response = fileUtil:getDataFromFileEx(filePath)
  1158. jsonData = self:decodeSrvlist(response)
  1159. else
  1160. -- 不是最新,保存内容至本地,无需再次解析json
  1161. filePath = self:GetSrvlistCachePath()
  1162. if fileUtil:isFileExist(filePath) then
  1163. fileUtil:removeFile(filePath)
  1164. end
  1165. fileUtil:writeStringToFile(response, filePath)
  1166. end
  1167. -- json解析,检测是否解析成功
  1168. if not jsonData then
  1169. self:CleanupLocalSrvlist()
  1170. reportError("[srvlist][3]远端服务器配置格式异常", callback)
  1171. -- 上报至服务器
  1172. global.L_DataRePort:ReportErrorModlistURL("SRVLIST_INFO_REQUEST_FAILED", "-3003", "Request srvlist INFO ERROR, JSON ERROR", url, code)
  1173. return nil
  1174. end
  1175. self._srvlistCount = 0
  1176. global.L_ModuleChooseManager:RespModSrvlist(jsonData, showAnnounce)
  1177. end
  1178. local signKey = global.L_GameEnvManager:GetModlistSignKey()
  1179. local modInfo = self._currentSubMod:GetSubModInfo()
  1180. local srvlist = modInfo.srvlist
  1181. if global.L_GameEnvManager:IsReview() and modInfo.srvlistReview and string.len(modInfo.srvlistReview) > 0 then
  1182. srvlist = modInfo.srvlistReview
  1183. end
  1184. local srvlistURL = string.format(srvlist, global.L_GameEnvManager:GetChannelID())
  1185. local srvlistData = srvlistURL
  1186. srvlistData = string.gsub(srvlistData, "http://", "")
  1187. srvlistData = string.gsub(srvlistData, "https://", "")
  1188. srvlistData = string.gsub(srvlistData, "/gsl/auth/server_list_auth", "")
  1189. srvlistData = string.gsub(srvlistData, "/gsl/main", "")
  1190. local s = string.find(srvlistData, "/")
  1191. srvlistData = string.sub(srvlistData, s+1, string.len(srvlistData))
  1192. local timestamp = os.time()
  1193. local sign = get_str_MD5("data=" .. srvlistData .. "&key=" .. signKey .. "&time="..timestamp)
  1194. srvlistURL = srvlistURL .. "?" .. self:GetLocalRuntime()
  1195. srvlistURL = srvlistURL .. string.format("&time=%s&sign=%s", timestamp, sign)
  1196. -- debug
  1197. releasePrint( "mod srvlist URL:", srvlistURL )
  1198. if srvlistURL and string.len(srvlistURL) > 0 then
  1199. ShowLoadingBar()
  1200. HTTPRequest(srvlistURL, httpCB)
  1201. end
  1202. end
  1203. function ModuleChooseLayer:RespModSrvlist(jsonData, showAnnounce)
  1204. if not self._currentModule or not self._currentSubMod then
  1205. return nil
  1206. end
  1207. local modGameEnv = self._currentSubMod:GetGameEnv()
  1208. local mmin = math.min
  1209. local mmax = math.max
  1210. -- clean
  1211. modGameEnv:Cleanup()
  1212. ------------------------------------------
  1213. local serverData = {}
  1214. serverData.source = jsonData
  1215. -- 推荐服
  1216. local referArrAble = false
  1217. local refer = jsonData.refer
  1218. local referArr = jsonData.referArr
  1219. local referOnlyOne = jsonData.referOnlyOne
  1220. if referArr and next(referArr) then
  1221. referArrAble = true
  1222. local randIndex = math.random(1, #referArr)
  1223. refer = referArr[randIndex]
  1224. end
  1225. modGameEnv:SetRefer(refer)
  1226. -- 服务器组
  1227. serverData.srvgroup = jsonData.serverGroup
  1228. ------------------------------------------
  1229. local function parseSrvitem(data, srvRoot)
  1230. if not data then
  1231. return nil
  1232. end
  1233. local function fixSrvip(srvid, srvRoot)
  1234. if srvRoot then
  1235. return string.format("s%s-%s", srvid, srvRoot)
  1236. end
  1237. return ""
  1238. end
  1239. -- 拼接服务器ip
  1240. local srvid = data.srvid
  1241. local srvip = fixSrvip(srvid, srvRoot)
  1242. local mainsrvid = data.mainsrvid
  1243. if mainsrvid and string.len(mainsrvid) > 0 and tonumber(mainsrvid) then
  1244. srvip = fixSrvip(mainsrvid, srvRoot)
  1245. end
  1246. srvip = data.srvip or srvip
  1247. -- srvitem
  1248. local srvitem = {}
  1249. srvitem.serverId = srvid -- 服务器id
  1250. srvitem.ip = srvip -- 服务器ip
  1251. srvitem.port = tonumber(data.port) -- 端口
  1252. srvitem.stab = data.beta == "1" and "beta" or "stab" -- 先行服
  1253. srvitem.state = mmax(mmin(tonumber(data.state), 5), 1) -- 状态 1新服,2畅通,3爆满,4维护,5隐藏
  1254. srvitem.serverName = data.srvname or srvid -- 服务器名
  1255. srvitem.urlSuffix = data.urlsuffix -- 资源URL 后缀
  1256. srvitem.mainServerId = mainsrvid -- 主服id,拼接ip
  1257. srvitem.tag = data.tag -- 所属服务器组tag
  1258. srvitem.gmurlsuffix = data.gmurlsuffix -- 先行服版本号
  1259. srvitem.proxyport = data.proxyport -- 代理端口
  1260. srvitem.oriState = srvitem.state
  1261. srvitem.bg = data.bg -- 冠名
  1262. return srvitem
  1263. end
  1264. ------------------------------------------
  1265. -- 服务器列表
  1266. local function isValid(v)
  1267. if v.srvid == 0 or v.port == nil then
  1268. return false
  1269. end
  1270. return true
  1271. end
  1272. local isReview = global.L_GameEnvManager:IsReview()
  1273. local srvData = isReview and jsonData.serverDataReview or jsonData.serverData or {}
  1274. local srvRoot = isReview and jsonData.srvRootReview or jsonData.srvRoot
  1275. serverData.srvlist = {}
  1276. local mainServerNameData = {}
  1277. for _, v in ipairs(srvData) do
  1278. --精简
  1279. v.srvid = v.d or v.srvid
  1280. v.port = v.p or v.port
  1281. v.state = v.s or v.state
  1282. v.urlsuffix = v.u or v.urlsuffix
  1283. v.mainsrvid = v.m or v.mainsrvid
  1284. v.tag = v.t or v.tag
  1285. v.srvname = v.n or v.srvname
  1286. v.gmurlsuffix = v.g or v.gmurlsuffix
  1287. v.srvip = v.i or v.srvip
  1288. v.proxyport = v.x or v.proxyport
  1289. v.beta = v.b or v.beta
  1290. if isValid(v) then
  1291. local srvitem = parseSrvitem(v, srvRoot)
  1292. tinsert(serverData.srvlist, srvitem)
  1293. mainServerNameData[srvitem.serverId] = srvitem.serverName
  1294. end
  1295. end
  1296. -- 加载主服名字 区服列表那精简不好再加字段了
  1297. for i,v in ipairs(serverData.srvlist) do
  1298. v.mainServerName = mainServerNameData[v.mainServerId] --主服名
  1299. end
  1300. --
  1301. -- 安卓/ios 分平台读取
  1302. local resURL = jsonData.resURL
  1303. local resURL_win = jsonData.resURL_win
  1304. local resURL_ios = jsonData.resURL_ios
  1305. local resURL_ad = jsonData.resURL_ad
  1306. local gmResURL = jsonData.gmResURL
  1307. local gmResURL_win = jsonData.gmResURL_win
  1308. local gmResURL_ad = jsonData.gmResURL_ad
  1309. local gmResURL_ios = jsonData.gmResURL_ios
  1310. resURL_ios = (resURL_ios and resURL_ios ~= "") and resURL_ios or resURL
  1311. resURL_ad = (resURL_ad and resURL_ad ~= "") and resURL_ad or resURL
  1312. resURL_win = (resURL_win and resURL_win ~= "") and resURL_win or resURL_ad
  1313. gmResURL_ad = (gmResURL_ad and gmResURL_ad ~= "") and gmResURL_ad or gmResURL
  1314. gmResURL_ios = (gmResURL_ios and gmResURL_ios ~= "") and gmResURL_ios or gmResURL
  1315. gmResURL_win = (gmResURL_win and gmResURL_win ~= "") and gmResURL_win or gmResURL_ad
  1316. --备份cdn
  1317. local resURL2 = jsonData.resURL2
  1318. local resURL_win2 = jsonData.resURL_win2
  1319. local resURL_ios2 = jsonData.resURL_ios2
  1320. local resURL_ad2 = jsonData.resURL_ad2
  1321. local gmResURL2 = jsonData.gmResURL2
  1322. local gmResURL_win2 = jsonData.gmResURL_win2
  1323. local gmResURL_ad2 = jsonData.gmResURL_ad2
  1324. local gmResURL_ios2 = jsonData.gmResURL_ios2
  1325. resURL_ios2 = (resURL_ios2 and resURL_ios2 ~= "") and resURL_ios2 or resURL2
  1326. resURL_ad2 = (resURL_ad2 and resURL_ad2 ~= "") and resURL_ad2 or resURL2
  1327. resURL_win2 = (resURL_win2 and resURL_win2 ~= "") and resURL_win2 or resURL_ad2
  1328. gmResURL_ad2 = (gmResURL_ad2 and gmResURL_ad2 ~= "") and gmResURL_ad2 or gmResURL2
  1329. gmResURL_ios2 = (gmResURL_ios2 and gmResURL_ios2 ~= "") and gmResURL_ios2 or gmResURL2
  1330. gmResURL_win2 = (gmResURL_win2 and gmResURL_win2 ~= "") and gmResURL_win2 or gmResURL_ad2
  1331. if global.isWindows then
  1332. resURL = resURL_win
  1333. resURL2 = resURL_win2
  1334. gmResURL = gmResURL_win
  1335. gmResURL2 = gmResURL_win2
  1336. elseif global.isAndroid or global.isOHOS then
  1337. resURL = resURL_ad
  1338. resURL2 = resURL_ad2
  1339. gmResURL = gmResURL_ad
  1340. gmResURL2 = gmResURL_ad2
  1341. elseif global.isIOS then
  1342. resURL = resURL_ios
  1343. resURL2 = resURL_ios2
  1344. gmResURL = gmResURL_ios
  1345. gmResURL2 = gmResURL_ios2
  1346. end
  1347. serverData.resURL = resURL
  1348. serverData.resURL2 = resURL2
  1349. serverData.whitelist = jsonData.whitelist
  1350. serverData.resVer = jsonData.resVer
  1351. serverData.sceneURL = jsonData.sceneURL
  1352. serverData.sceneResVer = jsonData.sceneResVer
  1353. serverData.gmResVer = jsonData.gmResVer
  1354. serverData.gmResURL = gmResURL
  1355. serverData.gmResURL2 = gmResURL2
  1356. serverData.gmInitResVer = jsonData.gmInitResVer
  1357. serverData.gmInitResURL = jsonData.gmInitResURL
  1358. serverData.gmInitResURL2 = jsonData.gmInitResURL2
  1359. serverData.gmWebResURL = jsonData.gmWebResURL
  1360. serverData.gmWebResURL2 = jsonData.gmWebResURL2
  1361. serverData.gmWebResVer = jsonData.gmWebResVer
  1362. serverData.uidWhiteList = jsonData.uidWhiteList
  1363. -- custom
  1364. local customURL = jsonData.custom and jsonData.custom.custom_url
  1365. local newServerList = false
  1366. modGameEnv:SetCustomData(jsonData.custom or {})
  1367. if customURL and string.len(customURL) > 0 then
  1368. newServerList = true
  1369. modGameEnv:SetCustomUrl(customURL)
  1370. modGameEnv:SetIsNewServerlist(true)
  1371. self:RequestCustomURL(customURL)
  1372. end
  1373. modGameEnv:SetServerData(serverData)
  1374. --新用户 推荐服等设置
  1375. self:ParseShowHideSrvitem()
  1376. modGameEnv:ReadLastServers()
  1377. --------------------
  1378. -- 自动弹出用户协议
  1379. local agreement = modGameEnv:GetCustomDataByKey("agreement")
  1380. local autoAgreement = getAgreementState() == 0 and agreement and string.len(agreement) > 0
  1381. -- 请求公告
  1382. -- 非审核服状态生效
  1383. if not isReview then
  1384. local announceURL = jsonData.custom and jsonData.custom.announceUrl
  1385. if announceURL and string.len(announceURL) > 0 then
  1386. releasePrint("announceURL", announceURL)
  1387. HTTPRequest(announceURL, function(success, response)
  1388. if success then
  1389. local jsonData = cjson.decode(response)
  1390. if jsonData and next(jsonData) then
  1391. serverData.announce = jsonData
  1392. -- find announce
  1393. if showAnnounce and not autoAgreement then
  1394. global.L_ModuleChooseManager:ShowAnnounce()
  1395. end
  1396. end
  1397. end
  1398. end)
  1399. end
  1400. end
  1401. self:UpdateServers()
  1402. self:UpdateSelected()
  1403. -- 显示用户协议
  1404. if not isReview then
  1405. if autoAgreement then
  1406. self:ShowAgreement()
  1407. end
  1408. end
  1409. if not newServerList then
  1410. self:OnCustomData(true)
  1411. end
  1412. end
  1413. function ModuleChooseLayer:OnCustomData(isCheckAutoEnterGame)
  1414. self:CheckLoadRoleinfo()
  1415. self:UpdateShareBtn()
  1416. self:UpdateCopyright()
  1417. self:UpdateHealthGame()
  1418. self:UpdateLicense()
  1419. self:UpdateLogo()
  1420. self:UpdateAgreementBtn()
  1421. self:UpdateAgreementTips()
  1422. self:UpdateVersion()
  1423. self:UpdateAgeTipsImage()
  1424. self:UpdateAuthTips()
  1425. self:UpdateDeleteAccountBtn()
  1426. self:UpdateChangeAccountBtn()
  1427. if isCheckAutoEnterGame then
  1428. self:checkAutoLaunchGameMod()
  1429. self:CheckAutoEnterGame()
  1430. self:CheckShiWanAutoEnterGame()
  1431. end
  1432. end
  1433. function ModuleChooseLayer:InitLauncherVersion()
  1434. local channelID = tostring(global.L_GameEnvManager:GetChannelID())
  1435. local module = global.L_ModuleManager:GetLauncherModule()
  1436. local originVersion = module:GetOriginVersion()
  1437. local remoteVersion = module:GetRemoteVersion()
  1438. self.ui.Text_ver_launcher:setString(string.format("%s (%s/%s)", channelID, originVersion, remoteVersion))
  1439. end
  1440. function ModuleChooseLayer:UpdateSelected()
  1441. local btnTextStr = fixNewLanguageString("未选择线路")
  1442. if not self._currentModule or not self._currentSubMod then
  1443. self.ui.Button_select:setTitleText(btnTextStr)
  1444. self.ui.Image_select_state:setVisible(false)
  1445. self.ui.Image_select_new:setVisible(false)
  1446. return nil
  1447. end
  1448. local modGameEnv = self._currentSubMod:GetGameEnv()
  1449. local serverData = modGameEnv:GetServerData()
  1450. if not serverData then
  1451. self.ui.Button_select:setTitleText(btnTextStr)
  1452. self.ui.Image_select_state:setVisible(false)
  1453. self.ui.Image_select_new:setVisible(false)
  1454. return nil
  1455. end
  1456. local selectedServer = modGameEnv:GetSelectedServer()
  1457. if not selectedServer then
  1458. self.ui.Button_select:setTitleText(btnTextStr)
  1459. self.ui.Image_select_state:setVisible(false)
  1460. self.ui.Image_select_new:setVisible(false)
  1461. return nil
  1462. end
  1463. -- 服务器名
  1464. local statePath = self.path .. "fuguchuanqi.apk_000870.png"
  1465. if selectedServer.state == 1 then
  1466. -- 新服 绿色
  1467. statePath = self.path .. "fuguchuanqi.apk_000870.png"
  1468. elseif selectedServer.state == 2 then
  1469. -- 普通 绿色
  1470. statePath = self.path .. "fuguchuanqi.apk_000870.png"
  1471. elseif selectedServer.state == 3 then
  1472. -- 爆满
  1473. statePath = self.path .. "fuguchuanqi.apk_000872.png"
  1474. elseif selectedServer.state == 4 then
  1475. -- 维护
  1476. statePath = self.path .. "fuguchuanqi.apk_000873.png"
  1477. elseif selectedServer.state == 5 then
  1478. -- 隐藏服 隐藏字
  1479. statePath = self.path .. "fuguchuanqi.apk_000873.png"
  1480. end
  1481. -- 任务活动
  1482. -- 是否开启活动
  1483. local boxScene = tonumber(global.L_GameEnvManager:GetEnvDataByKey("scene"))
  1484. if boxScene == 9 then
  1485. local isShowActivityIcon = false
  1486. local activitySevId = global.L_GameEnvManager:GetEnvDataByKey("serverId")
  1487. activitySevId = activitySevId and tostring(activitySevId)
  1488. if activitySevId and tostring(selectedServer.serverId) == activitySevId then
  1489. isShowActivityIcon = true
  1490. if not self.ui.activityIcon then
  1491. -- 显示活动icon
  1492. local bttonSizeW = self.ui.Button_select:getContentSize().width
  1493. local activityIcon = ccui.ImageView:create()
  1494. activityIcon:loadTexture(self.path .. "box_activity_icon.png")
  1495. activityIcon:setAnchorPoint(1, 0.5)
  1496. activityIcon:setPosition(bttonSizeW-18, 37)
  1497. self.ui.Button_select:addChild(activityIcon)
  1498. self.ui.activityIcon = activityIcon
  1499. end
  1500. end
  1501. if self.ui.activityIcon then
  1502. self.ui.activityIcon:setVisible(isShowActivityIcon)
  1503. end
  1504. end
  1505. local suffix = ""
  1506. if selectedServer.state == 1 then
  1507. suffix = ""
  1508. elseif selectedServer.state == 3 then
  1509. suffix = ""
  1510. elseif selectedServer.state == 5 then
  1511. suffix = "(隐)"
  1512. end
  1513. self.ui.Button_select:setTitleText(selectedServer.serverName .. suffix)
  1514. self.ui.Image_select_new:setVisible(selectedServer.state == 1)
  1515. self.ui.Image_select_state:setVisible(true)
  1516. self.ui.Image_select_state:loadTexture(statePath)
  1517. end
  1518. function ModuleChooseLayer:CheckShiWanAutoEnterGame()
  1519. --试玩直接启动游戏
  1520. local shiwan = global.L_GameEnvManager:GetEnvDataByKey("shiwan")
  1521. if shiwan and tonumber(shiwan) == 1 then
  1522. if global.L_NativeBridgeManager:PCCheckMedthodName("GN_checkRealName") then
  1523. local envMgr = global.L_GameEnvManager
  1524. local env_uid = envMgr:GetEnvDataByKey("user_id") or ""
  1525. local data = {
  1526. userId = tostring( env_uid )
  1527. }
  1528. global.L_NativeBridgeManager:PCNoticeRequest("GN_checkRealName",data)
  1529. return
  1530. end
  1531. self:LaunchModule()
  1532. end
  1533. end
  1534. function ModuleChooseLayer:UpdateLogo()
  1535. if not self._currentModule or not self._currentSubMod then
  1536. return nil
  1537. end
  1538. local directoryPath = global.FileUtilCtl:getWritablePath()
  1539. local modInfo = self._currentSubMod:GetSubModInfo()
  1540. local logoInfo = modInfo.logo
  1541. local showlogo = modInfo.showlogo
  1542. local logoInfoMini = modInfo.logo_mini
  1543. local logoInfoMini2 = modInfo.logo_mini2
  1544. if logoInfo and logoInfo.name and logoInfo.name ~= "" and logoInfo.url and logoInfo.url ~= "" then
  1545. local filePath = directoryPath .. logoInfo.name
  1546. if cc.FileUtils:getInstance():isFileExist(filePath) then
  1547. self.ui.Image_icon:setVisible(true)
  1548. self.ui.Image_icon:loadTexture(filePath)
  1549. self.ui.Image_icon:ignoreContentAdaptWithSize(true)
  1550. else
  1551. self.ui.Image_icon:setVisible(false)
  1552. end
  1553. elseif showlogo and tonumber(showlogo) == 1 then
  1554. self.ui.Image_icon:setVisible(true)
  1555. self.ui.Image_icon:loadTexture(self.path .. "logo_1.png")
  1556. self.ui.Image_icon:ignoreContentAdaptWithSize(true)
  1557. else
  1558. self.ui.Image_icon:setVisible(false)
  1559. end
  1560. -- local isBoxLogin = global.L_GameEnvManager:GetEnvDataByKey("isBoxLogin")
  1561. -- if isBoxLogin == 1 then --盒子登录 取对应平台的版号logo
  1562. -- if global.isWindows then
  1563. -- logoInfoMini = modInfo.logo_mini_box_pc
  1564. -- else
  1565. -- logoInfoMini = modInfo.logo_mini_box
  1566. -- end
  1567. -- end
  1568. -- logo mini
  1569. if logoInfoMini and logoInfoMini.name and logoInfoMini.name ~= "" and logoInfoMini.url and logoInfoMini.url ~= "" then
  1570. local filePath = directoryPath .. logoInfoMini.name
  1571. if cc.FileUtils:getInstance():isFileExist(filePath) then
  1572. self._imageLogoMini:setVisible(true)
  1573. self._imageLogoMini:loadTexture(filePath)
  1574. self._imageLogoMini:ignoreContentAdaptWithSize(true)
  1575. else
  1576. self._imageLogoMini:setVisible(false)
  1577. end
  1578. else
  1579. self._imageLogoMini:setVisible(false)
  1580. end
  1581. if logoInfoMini2 and logoInfoMini2.name and logoInfoMini2.name ~= "" and logoInfoMini2.url and logoInfoMini2.url ~= "" then
  1582. local filePath = directoryPath .. logoInfoMini2.name
  1583. if cc.FileUtils:getInstance():isFileExist(filePath) then
  1584. self._imageLogoMini2:setVisible(true)
  1585. self._imageLogoMini2:loadTexture(filePath)
  1586. self._imageLogoMini2:ignoreContentAdaptWithSize(true)
  1587. else
  1588. self._imageLogoMini2:setVisible(false)
  1589. end
  1590. else
  1591. self._imageLogoMini2:setVisible(false)
  1592. end
  1593. end
  1594. function ModuleChooseLayer:UpdateShareBtn()
  1595. if not self._currentModule or not self._currentSubMod then
  1596. return nil
  1597. end
  1598. local modGameEnv = self._currentSubMod:GetGameEnv()
  1599. if not modGameEnv then
  1600. return nil
  1601. end
  1602. -- 分享游戏
  1603. local shareUrl = modGameEnv:GetCustomDataByKey("shareUrl")
  1604. local isShowShare = shareUrl and shareUrl ~= ""
  1605. self.ui.Button_share:setVisible(isShowShare)
  1606. end
  1607. function ModuleChooseLayer:UpdateCopyright()
  1608. if not self._currentModule or not self._currentSubMod then
  1609. return nil
  1610. end
  1611. local modGameEnv = self._currentSubMod:GetGameEnv()
  1612. if not modGameEnv then
  1613. return nil
  1614. end
  1615. -- 版号
  1616. local hideCopyright = (tonumber(modGameEnv:GetCustomDataByKey("hideCopyright")) == 1)
  1617. self.ui.Text_copyright:setVisible(hideCopyright == false)
  1618. local copyright1 = modGameEnv:GetCustomDataByKey("copyright1")
  1619. local copyright2 = modGameEnv:GetCustomDataByKey("copyright2")
  1620. local copyrightStr = nil
  1621. if copyright1 and copyright2 and string.len(copyright1) > 0 and string.len(copyright2) > 0 then
  1622. TextCreateRichText(self.ui.Text_copyright, copyright1 .. "\n" .. copyright2)
  1623. end
  1624. -- 特殊处理PC端的版号问题
  1625. if global.isWindows then
  1626. local copyright1_pc = modGameEnv:GetCustomDataByKey("copyright1_pc")
  1627. local copyright2_pc = modGameEnv:GetCustomDataByKey("copyright2_pc")
  1628. if copyright1_pc and copyright2_pc and string.len(copyright1_pc) > 0 and string.len(copyright2_pc) > 0 then
  1629. TextCreateRichText(self.ui.Text_copyright, copyright1_pc .. "\n" .. copyright2_pc)
  1630. end
  1631. end
  1632. self:UpdateCopyright360()
  1633. end
  1634. -- 360过白版号
  1635. function ModuleChooseLayer:UpdateCopyright360()
  1636. local modGameEnv = self._currentSubMod:GetGameEnv()
  1637. if not modGameEnv then
  1638. return nil
  1639. end
  1640. local isSwithch = tonumber(modGameEnv:GetCustomDataByKey("cprh")) == 1
  1641. local whiteFileName = "CHxAY7FThcchFK2dmR2j.txt"
  1642. local fileUtil = cc.FileUtils:getInstance()
  1643. if fileUtil:isFileExist(whiteFileName) or isSwithch then
  1644. local filename = "cright.txt"
  1645. local isExist = fileUtil:isFileExist(filename)
  1646. if not fileUtil:isFileExist(filename) then
  1647. return nil
  1648. end
  1649. local fileData = fileUtil:getDataFromFileEx(filename)
  1650. local dataArray = string.split(fileData or "", "\n")
  1651. local copyright1_pc = dataArray[1]
  1652. local copyright2_pc = dataArray[2]
  1653. if copyright1_pc and copyright2_pc and string.len(copyright1_pc) > 0 and string.len(copyright2_pc) > 0 then
  1654. TextCreateRichText(self.ui.Text_copyright, copyright1_pc .. "\n" .. copyright2_pc)
  1655. end
  1656. end
  1657. end
  1658. function ModuleChooseLayer:UpdateHealthGame()
  1659. if not self._currentModule or not self._currentSubMod then
  1660. return nil
  1661. end
  1662. local modGameEnv = self._currentSubMod:GetGameEnv()
  1663. if not modGameEnv then
  1664. return nil
  1665. end
  1666. self.ui.Text_health:setVisible(true)
  1667. self.ui.Text_health_tips:setVisible(true)
  1668. -- 健康游戏内容
  1669. local customData = modGameEnv:GetCustomDataByKey("healthtips")
  1670. if customData then
  1671. TextCreateRichText(self.ui.Text_health, customData)
  1672. end
  1673. -- 适龄提醒
  1674. local customData = modGameEnv:GetCustomDataByKey("agetips")
  1675. if customData then
  1676. TextCreateRichText(self.ui.Text_health_tips, customData)
  1677. end
  1678. end
  1679. function ModuleChooseLayer:UpdateAgeTipsImage()
  1680. if not self._currentModule or not self._currentSubMod then
  1681. return nil
  1682. end
  1683. local modGameEnv = self._currentSubMod:GetGameEnv()
  1684. if not modGameEnv then
  1685. return nil
  1686. end
  1687. self.ui.Image_age_tips:setVisible(false)
  1688. self.ui.Image_age_tips:setTouchEnabled(false)
  1689. -- 适龄提醒
  1690. local customData = modGameEnv:GetCustomDataByKey("agetipsImage")
  1691. if customData then
  1692. -- 显示
  1693. if tostring(customData.visible) == "1" then
  1694. self.ui.Image_age_tips:setVisible(true)
  1695. end
  1696. -- 图标
  1697. if customData.name and customData.url then
  1698. self.ui.Image_age_tips:setVisible(false)
  1699. local directoryPath = global.FileUtilCtl:getWritablePath()
  1700. local filePath = directoryPath .. string.format("%s", customData.name)
  1701. if cc.FileUtils:getInstance():isFileExist(filePath) then
  1702. self.ui.Image_age_tips:setVisible(true)
  1703. self.ui.Image_age_tips:loadTexture(filePath)
  1704. self.ui.Image_age_tips:ignoreContentAdaptWithSize(true)
  1705. else
  1706. local downloadFlag = self.DownloadFlag.AgeTips
  1707. global.L_GameEnvManager:downloadResEasy(customData.url, customData.name, function(isOK, filename)
  1708. if global.L_GameLayerManager._uiNode then
  1709. global.L_ModuleChooseManager:OnDownloadResCB(isOK, filename, downloadFlag)
  1710. end
  1711. end)
  1712. end
  1713. end
  1714. if customData.hyperlink and customData.hyperlink ~= "" then
  1715. -- 跳转链接
  1716. self.ui.Image_age_tips:setTouchEnabled(true)
  1717. self.ui.Image_age_tips:addClickEventListener(function()
  1718. cc.Application:getInstance():openURL(customData.hyperlink)
  1719. end)
  1720. elseif customData.clickTips and customData.clickTips ~= "" then
  1721. -- 跳转提醒框
  1722. self.ui.Image_age_tips:setTouchEnabled(true)
  1723. self.ui.Image_age_tips:addClickEventListener(function()
  1724. local visibleSize = global.Director:getVisibleSize()
  1725. local layout = ccui.Layout:create()
  1726. self._root:addChild(layout)
  1727. layout:setContentSize(visibleSize)
  1728. layout:setTouchEnabled(true)
  1729. layout:setBackGroundColor(cc.c3b(0, 0, 0))
  1730. layout:setBackGroundColorType(1)
  1731. layout:setBackGroundColorOpacity(80)
  1732. local csize = {width=600, height=400}
  1733. -- 背景图
  1734. local imageBG = ccui.ImageView:create()
  1735. layout:addChild(imageBG)
  1736. imageBG:setPosition({x=visibleSize.width/2, y=visibleSize.height/2})
  1737. imageBG:loadTexture(self.publicPath .. "1900000600.png")
  1738. local x = 30
  1739. local y = 30
  1740. local width = 452-60
  1741. local height = 179-60
  1742. imageBG:setScale9Enabled(true)
  1743. imageBG:setCapInsets({x = x, y = y, width = width, height = height})
  1744. imageBG:setContentSize(csize)
  1745. -- 确认按钮
  1746. local buttonConfirm = ccui.Button:create()
  1747. imageBG:addChild(buttonConfirm)
  1748. buttonConfirm:setPosition({x=csize.width/2, y=40})
  1749. buttonConfirm:loadTextureNormal(self.publicPath .. "1900001022.png")
  1750. buttonConfirm:loadTexturePressed(self.publicPath .. "1900001022.png")
  1751. buttonConfirm:setTouchEnabled(true)
  1752. buttonConfirm:setTitleFontName("fonts/font.ttf")
  1753. buttonConfirm:setTitleFontSize(18)
  1754. buttonConfirm:setTitleText("确 认")
  1755. buttonConfirm:addClickEventListener(function()
  1756. layout:removeFromParent()
  1757. end)
  1758. -- 内容
  1759. local scrollview = ccui.ScrollView:create()
  1760. imageBG:addChild(scrollview)
  1761. scrollview:setContentSize({width=550, height=300})
  1762. scrollview:setInnerContainerSize({width = 500, height = 300})
  1763. scrollview:ignoreContentAdaptWithSize(false)
  1764. scrollview:setClippingEnabled(true)
  1765. scrollview:setAnchorPoint({x=0.5, y=1})
  1766. scrollview:setPosition({x=csize.width/2, y=380})
  1767. scrollview:setTouchEnabled(true)
  1768. local RichTextHelp = requireLauncher( "init/RichTextHelp" )
  1769. local innerSize = scrollview:getInnerContainerSize()
  1770. local richText = RichTextHelp:CreateRichTextWithXML(customData.clickTips, innerSize.width, 18, "#c9b39c")
  1771. scrollview:addChild( richText )
  1772. richText:formatText()
  1773. richText:setAnchorPoint({x=0.5, y=1})
  1774. richText:setPosition({x=innerSize.width/2, y=300})
  1775. richText:setOpenUrlHandler( function(sender, str)
  1776. cc.Application:getInstance():openURL(str)
  1777. end )
  1778. local textContentSize = richText:getContentSize()
  1779. local scrollContentSize = scrollview:getContentSize()
  1780. local newContentSize = {width=textContentSize.width, height=math.min(scrollContentSize.height, textContentSize.height)}
  1781. local newInnerSize = {width=textContentSize.width, height=math.max(newContentSize.height, textContentSize.height)}
  1782. newInnerSize.width = math.max(550, newInnerSize.width)
  1783. newInnerSize.height = math.max(300, newInnerSize.height)
  1784. scrollview:setInnerContainerSize( newInnerSize )
  1785. richText:setPosition({x=newInnerSize.width/2, y=newInnerSize.height})
  1786. end)
  1787. end
  1788. end
  1789. end
  1790. function ModuleChooseLayer:UpdateAuthTips()
  1791. if not self._currentModule or not self._currentSubMod then
  1792. return nil
  1793. end
  1794. local modGameEnv = self._currentSubMod:GetGameEnv()
  1795. if not modGameEnv then
  1796. return nil
  1797. end
  1798. self.ui.Text_auth_tips:setVisible(true)
  1799. -- 账号安全提醒
  1800. local customData = modGameEnv:GetCustomDataByKey("authtips")
  1801. if customData then
  1802. TextCreateRichText(self.ui.Text_auth_tips, customData)
  1803. end
  1804. end
  1805. function ModuleChooseLayer:UpdateLicense()
  1806. if not self._currentModule or not self._currentSubMod then
  1807. return nil
  1808. end
  1809. local modGameEnv = self._currentSubMod:GetGameEnv()
  1810. if not modGameEnv then
  1811. return nil
  1812. end
  1813. -- 正版
  1814. local hideLicense = (tonumber(modGameEnv:GetCustomDataByKey("hideLicense")) == 1)
  1815. end
  1816. function ModuleChooseLayer:UpdateAgreementBtn()
  1817. if not self._currentModule or not self._currentSubMod then
  1818. return nil
  1819. end
  1820. local modGameEnv = self._currentSubMod:GetGameEnv()
  1821. if not modGameEnv then
  1822. return nil
  1823. end
  1824. -- 用户协议
  1825. local isShowBtn = (modGameEnv:GetCustomDataByKey("agreement") and string.len(modGameEnv:GetCustomDataByKey("agreement")) > 0)
  1826. self.ui.Button_agreement:setVisible(isShowBtn)
  1827. end
  1828. function ModuleChooseLayer:UpdateChangeAccountBtn()
  1829. if not self._currentModule or not self._currentSubMod then
  1830. return nil
  1831. end
  1832. local modGameEnv = self._currentSubMod:GetGameEnv()
  1833. if not modGameEnv then
  1834. return nil
  1835. end
  1836. --盒子登录显示的是返回盒子不要隐藏
  1837. if global.isBoxLogin then
  1838. return
  1839. end
  1840. -- 切换账号
  1841. local isHideBtn = tonumber(modGameEnv:GetCustomDataByKey("hideChangeAccountBtn")) == 1
  1842. self.ui.Button_logout:setVisible(not isHideBtn)
  1843. end
  1844. function ModuleChooseLayer:UpdateDeleteAccountBtn()
  1845. local module = self._currentSubMod
  1846. if not module then
  1847. return nil
  1848. end
  1849. local modGameEnv = self._currentSubMod:GetGameEnv()
  1850. if not modGameEnv then
  1851. return nil
  1852. end
  1853. if not self.ui.Button_delete_account then
  1854. return nil
  1855. end
  1856. -- 注销账号
  1857. local isShowBtn = tonumber(modGameEnv:GetCustomDataByKey("showDeleteAccount")) == 1
  1858. self.ui.Button_delete_account:setVisible(isShowBtn)
  1859. end
  1860. function ModuleChooseLayer:UpdateAgreementTips()
  1861. if not self._currentModule or not self._currentSubMod then
  1862. return nil
  1863. end
  1864. local modGameEnv = self._currentSubMod:GetGameEnv()
  1865. if not modGameEnv then
  1866. return nil
  1867. end
  1868. if not self.ui.Panel_agreement then
  1869. return nil
  1870. end
  1871. local discardAgreementBSwitch = modGameEnv:GetCustomDataByKey("discardAgreementBSwitch") == 1
  1872. -- 用户协议
  1873. local agreementB = (modGameEnv:GetCustomDataByKey("agreementB"))
  1874. if not agreementB or agreementB == "" then
  1875. self.ui.Panel_agreement:setVisible(false)
  1876. self.ui.CheckBox_agreement:setSelected(true)
  1877. return nil
  1878. end
  1879. self.ui.Panel_agreement:setVisible(true)
  1880. self.ui.CheckBox_agreement:setSelected(true)
  1881. -- 默认状态
  1882. local userData = UserData:new("agreement_data")
  1883. local localData = discardAgreementBSwitch and 0 or userData:getIntegerForKey("select", 0)
  1884. local selectStatus = localData == 1
  1885. self.ui.CheckBox_agreement:setSelected(selectStatus)
  1886. local isInsideShow = tonumber(modGameEnv:GetCustomDataByKey("showInside")) == 1
  1887. local RichTextHelp = requireLauncher( "init/RichTextHelp" )
  1888. local richText = RichTextHelp:CreateRichTextWithXML( agreementB, 2000, 18, "#ffffff" )
  1889. self.ui.Node_agreement:removeAllChildren()
  1890. self.ui.Node_agreement:addChild( richText )
  1891. richText:formatText()
  1892. richText:setOpenUrlHandler( function(sender, str)
  1893. if isInsideShow then
  1894. local httpRequest = cc.XMLHttpRequest:new()
  1895. httpRequest.responseType = cc.XMLHTTPREQUEST_RESPONSE_JSON
  1896. httpRequest.timeout = 100000 -- 10 s
  1897. httpRequest:open("GET", str)
  1898. httpRequest:registerScriptHandler(function()
  1899. local code = httpRequest.status
  1900. local success = code >= 200 and code < 300
  1901. local response = httpRequest.response
  1902. self:InsideShowNoticeContent( response )
  1903. end)
  1904. httpRequest:send()
  1905. return
  1906. end
  1907. cc.Application:getInstance():openURL(str)
  1908. end )
  1909. local contentSize = richText:getContentSize()
  1910. local width = contentSize.width + 50
  1911. self.ui.Panel_agreement:setContentSize({width=width, height=35})
  1912. self.ui.Node_agreement:setPositionX(width / 2 + 15)
  1913. self.ui.CheckBox_agreement:setPositionX(20)
  1914. end
  1915. function ModuleChooseLayer:UpdateVersion()
  1916. local modGameEnv = self._currentSubMod:GetGameEnv()
  1917. if not modGameEnv then
  1918. return nil
  1919. end
  1920. -- 自定义版本号显示
  1921. self.ui.Text_ver_launcher:setVisible(true)
  1922. local launcherVer = modGameEnv:GetCustomDataByKey("launcherVer")
  1923. local moduleVer = modGameEnv:GetCustomDataByKey("moduleVer")
  1924. if launcherVer and moduleVer then
  1925. self.ui.Text_ver_launcher:setString(launcherVer)
  1926. end
  1927. end
  1928. function ModuleChooseLayer:InitServers()
  1929. local visibleSize = cc.Director:getInstance():getVisibleSize()
  1930. self.ui.Panel_hide:setContentSize(visibleSize)
  1931. self.ui.Panel_hide:addClickEventListener(function()
  1932. self:ShowLaunch()
  1933. self:HideServers()
  1934. end)
  1935. self.ui.ListView_groups:setBounceEnabled(true)
  1936. self.ui.ListView_servers:setBounceEnabled(true)
  1937. self.ui.Button_more:addClickEventListener(function()
  1938. self:SelectSGroup(hasRoleGroup)
  1939. end)
  1940. end
  1941. function ModuleChooseLayer:ShowServers()
  1942. self.ui.Panel_servers:setVisible(true)
  1943. end
  1944. function ModuleChooseLayer:HideServers()
  1945. self.ui.Panel_servers:setVisible(false)
  1946. end
  1947. function ModuleChooseLayer:UpdateServers()
  1948. if not self._currentModule or not self._currentSubMod then
  1949. return nil
  1950. end
  1951. local modGameEnv = self._currentSubMod:GetGameEnv()
  1952. local srvData = modGameEnv:GetServerData()
  1953. if not srvData then
  1954. return false
  1955. end
  1956. if not self.ui.Panel_servers:isVisible() then
  1957. return false
  1958. end
  1959. self.ui.ListView_groups:removeAllItems()
  1960. self.ui.ListView_servers:removeAllItems()
  1961. self.ui.ListView_logined:removeAllItems()
  1962. self._group = -1
  1963. self._gservers = {}
  1964. self._groupCells = {}
  1965. self._serverCells = {}
  1966. self._loginedCells = {}
  1967. -- 筛选服务器
  1968. local function filterServers()
  1969. local tservers = {}
  1970. local srvlist = clone(modGameEnv:GetSrvlist())
  1971. -- 组
  1972. -- 先tag为key,方便快速存储,再使用table.sort
  1973. -- 服务器列表倒序遍历
  1974. -- 问题1,没配置tag
  1975. -- 问题2,配置tag但是不存在该tag组
  1976. -- normalsrvlist 剩余正常列表
  1977. -- hash
  1978. local groupSrvlist = {}
  1979. if srvData.srvgroup and type(srvData.srvgroup) == "table" then
  1980. for i, v in ipairs(srvData.srvgroup) do
  1981. groupSrvlist[v.tag] = {index = i, name = v.name, tag = v.tag, items = {}}
  1982. end
  1983. end
  1984. -- 筛选出组列表和普通列表
  1985. local normalsrvlist = {}
  1986. for i, v in ipairs(srvlist) do
  1987. local srvitem = v
  1988. if srvitem.tag and groupSrvlist[srvitem.tag] then
  1989. tinsert(groupSrvlist[srvitem.tag].items, srvitem)
  1990. else
  1991. tinsert(normalsrvlist, srvitem)
  1992. end
  1993. end
  1994. -- 排序
  1995. groupSrvlist = HashToSortArray(groupSrvlist, function(a, b)
  1996. return a.index < b.index
  1997. end)
  1998. for i, v in ipairs(groupSrvlist) do
  1999. if #v.items > 0 then
  2000. local item = {}
  2001. item.index = #tservers+1
  2002. item.name = v.name
  2003. item.items = v.items
  2004. tinsert(tservers, item)
  2005. end
  2006. end
  2007. -- 正常区服
  2008. local pageCount = math.ceil(#normalsrvlist / self.CountOfPage)
  2009. local function calcServersByPage(page)
  2010. local begin = (page - 1) * self.CountOfPage + 1
  2011. local ended = begin + self.CountOfPage - 1
  2012. local servers = {}
  2013. for i = begin, ended do
  2014. tinsert(servers, normalsrvlist[i])
  2015. end
  2016. return servers
  2017. end
  2018. for page = pageCount, 1, -1 do
  2019. local items = calcServersByPage(page)
  2020. local item = {}
  2021. item.index = #tservers+1
  2022. item.name = string.format("%s-%s区", (page - 1) * self.CountOfPage + 1, (page - 1) * self.CountOfPage + #items)
  2023. item.items = items
  2024. tinsert(tservers, item)
  2025. end
  2026. return tservers
  2027. end
  2028. -- 组
  2029. self._gservers = filterServers()
  2030. for _, v in ipairs(self._gservers) do
  2031. local cell = self:CreateSGroupCell(v)
  2032. self._groupCells[v.index] = cell
  2033. self.ui.ListView_groups:pushBackCustomItem(cell.nativeUI)
  2034. end
  2035. -- 已经登录的
  2036. local lastervers = modGameEnv:GetLastservers()
  2037. for i, v in ipairs(lastervers) do
  2038. local server = modGameEnv:GetServerByID(v)
  2039. if server then
  2040. local cell = self:CreateServerCell(server)
  2041. self.ui.ListView_logined:pushBackCustomItem(cell.nativeUI)
  2042. self._loginedCells[server.serverId] = cell
  2043. end
  2044. end
  2045. self:SelectSGroup(1)
  2046. end
  2047. function ModuleChooseLayer:SelectSGroup(g)
  2048. self._group = g
  2049. for k, cell in pairs(self._groupCells) do
  2050. if self._group == k then
  2051. cell.Button_group:loadTextureNormal(self.path .. "fuguchuanqi.apk_000858.png")
  2052. else
  2053. cell.Button_group:loadTextureNormal(self.path .. "fuguchuanqi.apk_000857.png")
  2054. end
  2055. end
  2056. self._serverCells = {}
  2057. self.ui.ListView_servers:removeAllItems()
  2058. self.ui.ListView_servers:jumpToTop()
  2059. local servers = {}
  2060. if self._group == hasRoleGroup then --玩过的区服
  2061. servers = self:GetHasRoleSrvItems()
  2062. else
  2063. local gservers = self._gservers[self._group]
  2064. if not gservers then
  2065. return nil
  2066. end
  2067. servers = clone(gservers.items)
  2068. end
  2069. if not servers then
  2070. return nil
  2071. end
  2072. print("count ", #servers)
  2073. while next(servers) do
  2074. local batchServers = {}
  2075. tinsert(batchServers, servers[#servers])
  2076. tremove(servers, #servers)
  2077. if next(servers) then
  2078. tinsert(batchServers, servers[#servers])
  2079. tremove(servers, #servers)
  2080. end
  2081. local cell = self:CreateBatchServerCell(batchServers)
  2082. self.ui.ListView_servers:pushBackCustomItem(cell)
  2083. end
  2084. end
  2085. function ModuleChooseLayer:GetHasRoleSrvItems()
  2086. if not self._currentModule or not self._currentSubMod then
  2087. return nil
  2088. end
  2089. local modGameEnv = self._currentSubMod:GetGameEnv()
  2090. if not modGameEnv then
  2091. return nil
  2092. end
  2093. local items = modGameEnv:GetHasRoleSrvItems()
  2094. return items
  2095. end
  2096. function ModuleChooseLayer:CreateSGroupCell(data)
  2097. local root = CreateExport_launcher("server/group_cell")
  2098. local layout = root:getChildByName("Panel_bg")
  2099. layout:removeFromParent()
  2100. local cell = ui_delegate(layout)
  2101. cell.Button_group:setTitleText(data.name)
  2102. drawButtonColorStyle(cell.Button_group, {fontSize=20, color=cc.c3b(0xf8, 0xe6, 0xc6), outlineSize=3, outlineColor=cc.c3b(0x11,0x11,0x11)})
  2103. -- 选择
  2104. local function callback()
  2105. self:SelectSGroup(data.index)
  2106. end
  2107. cell.Button_group:addClickEventListener(callback)
  2108. cell.nativeUI:addClickEventListener(callback)
  2109. return cell
  2110. end
  2111. function ModuleChooseLayer:CreateBatchServerCell(data)
  2112. local widget = ccui.Widget:create()
  2113. widget:setContentSize({width = 264*2, height = 49})
  2114. if data[1] then
  2115. local cell_data = {}
  2116. cell_data.wid = 264
  2117. cell_data.hei = 49
  2118. cell_data.callback = function()
  2119. local cell = self:CreateServerCell(data[1])
  2120. return cell.nativeUI
  2121. end
  2122. local quickCell = createQuickCell(cell_data)
  2123. widget:addChild(quickCell.widget)
  2124. quickCell.widget:setPositionX(0)
  2125. self._serverCells[data[1].serverId] = quickCell
  2126. end
  2127. if data[2] then
  2128. local cell_data = {}
  2129. cell_data.wid = 264
  2130. cell_data.hei = 49
  2131. cell_data.callback = function()
  2132. local cell = self:CreateServerCell(data[2])
  2133. return cell.nativeUI
  2134. end
  2135. local quickCell = createQuickCell(cell_data)
  2136. widget:addChild(quickCell.widget)
  2137. quickCell.widget:setPositionX(264)
  2138. self._serverCells[data[2].serverId] = quickCell
  2139. end
  2140. return widget
  2141. end
  2142. function ModuleChooseLayer:CreateServerCell(data)
  2143. local cell = self:GetServerCache()
  2144. -- 选服
  2145. local function callback()
  2146. if not self._currentModule or not self._currentSubMod then
  2147. return nil
  2148. end
  2149. local modGameEnv = self._currentSubMod:GetGameEnv()
  2150. local serverData = modGameEnv:GetServerData()
  2151. -- 维护,且不是白名单
  2152. if data.state == 4 and (not modGameEnv:IsWhitelist()) then
  2153. global.L_SystemTipsManager:ShowTips("服务器正在维护中,请选择其它服务器!")
  2154. return nil
  2155. end
  2156. -- 隐藏服给提醒
  2157. if data.state == 5 then
  2158. global.L_SystemTipsManager:ShowTips("正在进入隐藏服!")
  2159. end
  2160. modGameEnv:SetSelectedServer(data)
  2161. -- 选择的服务器存储到本地
  2162. modGameEnv:SaveLastServers()
  2163. self:ShowLaunch()
  2164. self:HideServers()
  2165. self:UpdateSelected()
  2166. end
  2167. cell.nativeUI:addClickEventListener(callback)
  2168. cell.Button_server:addClickEventListener(callback)
  2169. cell.Button_server:setZoomScale(0.05)
  2170. -- 服务器名
  2171. local suffix = ""
  2172. if data.state == 1 then
  2173. suffix = ""
  2174. elseif data.state == 3 then
  2175. suffix = ""
  2176. elseif data.state == 5 then
  2177. suffix = "(隐)"
  2178. end
  2179. -- 白名单显示服务器id
  2180. local modGameEnv = self._currentSubMod:GetGameEnv()
  2181. if modGameEnv:IsWhitelist() then
  2182. suffix = suffix .. string.format("(%s)", data.serverId)
  2183. end
  2184. cell.Button_server:setTitleText(data.serverName .. suffix)
  2185. cell.Image_new:setVisible(data.state == 1)
  2186. drawButtonColorStyle(cell.Button_server, {fontSize=18, color=cc.c3b(0xf8, 0xe6, 0xc6), outlineSize=3, outlineColor=cc.c3b(0x11,0x11,0x11)})
  2187. -- 服务器状态
  2188. if data.state == 1 then
  2189. -- 新服 绿色
  2190. cell.Image_state:loadTexture(self.path .. "fuguchuanqi.apk_000870.png")
  2191. elseif data.state == 2 then
  2192. -- 普通 绿色
  2193. cell.Image_state:loadTexture(self.path .. "fuguchuanqi.apk_000870.png")
  2194. elseif data.state == 3 then
  2195. -- 爆满
  2196. cell.Image_state:loadTexture(self.path .. "fuguchuanqi.apk_000872.png")
  2197. elseif data.state == 4 then
  2198. -- 维护
  2199. cell.Image_state:loadTexture(self.path .. "fuguchuanqi.apk_000873.png")
  2200. cell.Button_server:setTitleColor(cc.c3b(0xbf, 0xbf, 0xbf))
  2201. elseif data.state == 5 then
  2202. -- 隐藏服 隐藏字
  2203. cell.Image_state:loadTexture(self.path .. "fuguchuanqi.apk_000873.png")
  2204. end
  2205. -- 冠名
  2206. local titleBgPath = self.path .. "fuguchuanqi.apk_000853.png"
  2207. if data.bg and tonumber(data.bg) then
  2208. local bgPath = self.path .. "title/" .. data.bg .. ".png"
  2209. if cc.FileUtils:getInstance():isFileExist(bgPath) then
  2210. titleBgPath = bgPath
  2211. end
  2212. end
  2213. cell.Button_server:loadTextureNormal(titleBgPath)
  2214. -- 服务器是否有角色
  2215. local module = self._currentSubMod
  2216. local modGameEnv = module:GetGameEnv()
  2217. local roleCount = modGameEnv:GetRoleInfoByServerID(data.serverId)
  2218. cell.Image_role:setVisible(roleCount and roleCount > 0)
  2219. -- 任务活动
  2220. -- 是否开启活动
  2221. local boxScene = tonumber(global.L_GameEnvManager:GetEnvDataByKey("scene"))
  2222. if boxScene == 9 then
  2223. local isShowActivityIcon = false
  2224. local activitySevId = global.L_GameEnvManager:GetEnvDataByKey("serverId")
  2225. activitySevId = activitySevId and tostring(activitySevId)
  2226. if activitySevId and tostring(data.serverId) == activitySevId then
  2227. isShowActivityIcon = true
  2228. if not cell.activityIcon then
  2229. -- 显示活动icon
  2230. local offX = -24
  2231. if roleCount and roleCount > 0 then
  2232. offX = -40
  2233. end
  2234. local bttonSizeW = cell.Button_server:getContentSize().width
  2235. local activityIcon = ccui.ImageView:create()
  2236. activityIcon:loadTexture(self.path .. "box_activity_icon.png")
  2237. activityIcon:setAnchorPoint(1, 0.5)
  2238. activityIcon:setPosition(bttonSizeW+offX, 26)
  2239. cell.Button_server:addChild(activityIcon)
  2240. cell.activityIcon = activityIcon
  2241. end
  2242. end
  2243. if cell.activityIcon then
  2244. cell.activityIcon:setVisible(isShowActivityIcon)
  2245. end
  2246. end
  2247. return cell
  2248. end
  2249. function ModuleChooseLayer:GetServerCache()
  2250. if #self._serverCache > 0 then
  2251. local cache = tremove(self._serverCache)
  2252. cache.nativeUI:autorelease()
  2253. return cache
  2254. end
  2255. local root = CreateExport_launcher("server/server_cell")
  2256. local layout = root:getChildByName("Panel_bg")
  2257. layout:removeFromParent()
  2258. local cell = ui_delegate(layout)
  2259. layout:registerScriptHandler( function(state)
  2260. if state == "exit" then
  2261. if false == self._releaseFlag then
  2262. self:AddServerCache(cell)
  2263. end
  2264. end
  2265. end )
  2266. return cell
  2267. end
  2268. function ModuleChooseLayer:AddServerCache(cache)
  2269. cache.nativeUI:retain()
  2270. tinsert(self._serverCache, cache)
  2271. end
  2272. function ModuleChooseLayer:ReleaseServerCache()
  2273. for k, v in pairs(self._serverCache) do
  2274. v.nativeUI:autorelease()
  2275. end
  2276. if self._windowResizedListener then
  2277. global.Director:getEventDispatcher():removeEventListener( self._windowResizedListener )
  2278. self._windowResizedListener = nil
  2279. end
  2280. self._serverCache = {}
  2281. self._releaseFlag = true
  2282. end
  2283. function ModuleChooseLayer:OnLoginSuccessResp()
  2284. self:CheckLoadRoleinfo()
  2285. --强更
  2286. self:CheckApkUpdate()
  2287. end
  2288. --强更 因为996sdk 有一部分包去掉权限了 得通过登录之后的NG_SDKLoginCB sdkver和 NG_recvData code_java来判断是不是没权限的包
  2289. --存在sdkver和code_java 并且code_java<=10000的为没权限的包
  2290. function ModuleChooseLayer:CheckApkUpdate()
  2291. if not global.isAndroid then
  2292. return
  2293. end
  2294. if global.isBoxLogin then
  2295. return
  2296. end
  2297. if global.L_GameEnvManager:GetEnvDataByKey("isCloudLogin") then
  2298. return
  2299. end
  2300. local hasPermission = true
  2301. local sdkInfo = global.L_NativeBridgeManager:GetLoginDataByKey("sdkInfo")
  2302. local sdkver = nil
  2303. if sdkInfo then
  2304. local sdkInfoT = cjson.decode(sdkInfo)
  2305. if sdkInfoT and sdkInfoT.sdkver then
  2306. sdkver = sdkInfoT.sdkver
  2307. end
  2308. end
  2309. local javaVersion = global.L_GameEnvManager:GetJavaVersionCode()
  2310. javaVersion = tonumber(javaVersion)
  2311. if sdkver and javaVersion and javaVersion <=10000 then
  2312. hasPermission = false
  2313. end
  2314. global.L_GameEnvManager:SetHasInstallPermission(hasPermission)
  2315. local apkUpdateInfoUrl = global.L_GameEnvManager:GetAPKUpdateInfoUrl()
  2316. if not apkUpdateInfoUrl then
  2317. releasePrint("not apkUpdateUrl")
  2318. return
  2319. end
  2320. HTTPRequest(apkUpdateInfoUrl, function (success, response)
  2321. if not success then
  2322. releasePrint("get apkInfo fail!")
  2323. return
  2324. end
  2325. if not response then
  2326. releasePrint("get apkInfo empty fail!")
  2327. end
  2328. local jsonData = cjson.decode(response)
  2329. local versionCode = jsonData.update_ver_code
  2330. global.L_GameEnvManager:SetAPKUpdateInfo(jsonData)
  2331. local userData = UserData:new("update_ver_code")
  2332. local lastCode = userData:getStringForKey("lastCode", "-1")
  2333. if versionCode and lastCode ~= tostring(versionCode) then
  2334. if hasPermission then
  2335. userData:setStringForKey("lastCode", tostring(versionCode))
  2336. userData:writeMapDataToFile()
  2337. local urlInfo = {}
  2338. urlInfo.apkVerUrl = apkUpdateInfoUrl
  2339. global.L_NativeBridgeManager:GN_checkApkUpdate(urlInfo)
  2340. end
  2341. end
  2342. end)
  2343. end
  2344. function ModuleChooseLayer:CheckLoadRoleinfo()
  2345. if nil == self._currentModule or not self._currentSubMod then
  2346. return false
  2347. end
  2348. local modGameEnv = self._currentSubMod:GetGameEnv()
  2349. local exist = modGameEnv:GetRoleinfo()
  2350. if not exist then
  2351. modGameEnv:RequestRoleInfo(function(jsonData)
  2352. if not (global.L_ModuleChooseManager and global.L_ModuleChooseManager._layer) then
  2353. return
  2354. end
  2355. if jsonData then
  2356. modGameEnv:SetRoleinfo(jsonData)
  2357. -- 保存至本地
  2358. modGameEnv:savelocalRoleinfo()
  2359. modGameEnv:SetSelectedServer(nil)
  2360. global.L_ModuleChooseManager:UpdateServersWhenRoleInfoGet()
  2361. global.L_ModuleChooseManager:OnServerRoleInfoResp()
  2362. else
  2363. -- 本地读取
  2364. modGameEnv:readLocalRoleinfo()
  2365. end
  2366. end)
  2367. end
  2368. end
  2369. function ModuleChooseLayer:UpdateServerRoleInfo()
  2370. if not self._currentModule or not self._currentSubMod then
  2371. return false
  2372. end
  2373. local modGameEnv = self._currentSubMod:GetGameEnv()
  2374. for serverId, cell in pairs(self._serverCells) do
  2375. cell.exit()
  2376. end
  2377. for serverId, cell in pairs(self._loginedCells) do
  2378. local roleCount = modGameEnv:GetRoleInfoByServerID(serverId)
  2379. cell.Image_role:setVisible(roleCount and roleCount > 0)
  2380. end
  2381. modGameEnv:ReadLastServers()
  2382. self:UpdateSelected()
  2383. end
  2384. function ModuleChooseLayer:OnAlreadyUpToDate()
  2385. self.ui.Panel_bg:setVisible(true)
  2386. self:InitAllModules()
  2387. self:InitLauncherVersion()
  2388. self:SelectDefaultModule()
  2389. self:ShowLaunch()
  2390. self:HideServers()
  2391. self:UpdateSelected()
  2392. -- 为防止界面等太久导致的服务器列表有问题,30分钟刷一次
  2393. if self._srvlistTimerID then
  2394. UnSchedule(self._srvlistTimerID)
  2395. self._srvlistTimerID = nil
  2396. end
  2397. self._srvlistTimerID = Schedule(function()
  2398. self:RequestModSrvlist(false)
  2399. end, self._srvlistTime)
  2400. end
  2401. function ModuleChooseLayer:ShowModuleAnnounce()
  2402. if self.BoxAutoEnterGame then
  2403. return
  2404. end
  2405. if self._announceUI then
  2406. self._announceUI.nativeUI:removeFromParent()
  2407. self._announceUI = nil
  2408. end
  2409. self._announceGroupCells = {}
  2410. if nil == self._currentModule or not self._currentSubMod then
  2411. return
  2412. end
  2413. local root = nil
  2414. if self._isPortrait then
  2415. root = CreateExport_launcher("server/module_announce_portrait")
  2416. else
  2417. root = CreateExport_launcher("server/module_announce")
  2418. end
  2419. self:addChild(root)
  2420. self._announceUI = ui_delegate(root)
  2421. -- close
  2422. local function closeCB()
  2423. self._announceUI.nativeUI:removeFromParent()
  2424. self._announceUI = nil
  2425. -- 公告关闭 上报自定义事件
  2426. local dataParam = {
  2427. event={time=os.time(),name = "closeNotice",type = "track"}
  2428. }
  2429. local userId = global.L_GameEnvManager:GetEnvDataByKey("user_id") or global.L_GameEnvManager:GetEnvDataByKey("uid")
  2430. if userId and userId ~= "" then
  2431. dataParam.user = {id = userId}
  2432. end
  2433. global.L_DataRePort:SendRePortData( dataParam )
  2434. end
  2435. self._announceUI.Panel_1:addClickEventListener(closeCB)
  2436. self._announceUI.Button_sure:addClickEventListener(closeCB)
  2437. self._announceUI.Button_close:addClickEventListener(closeCB)
  2438. drawButtonColorStyle(self._announceUI.Button_sure, {fontSize=18, color=cc.c3b(0xf8, 0xe6, 0xc6), outlineSize=2, outlineColor=cc.c3b(0x11,0x11,0x11)})
  2439. -- desc
  2440. local function showDesc(data)
  2441. for k, v in pairs(self._announceGroupCells) do
  2442. if k == data.index then
  2443. v.Button_group:loadTextureNormal(self.path .. "announce/1900000662.png")
  2444. v.Button_group:loadTexturePressed(self.path .. "announce/1900000662.png")
  2445. v.Button_group:setTouchEnabled(false)
  2446. drawButtonColorStyle(v.Button_group, {fontSize=18, color=cc.c3b(0xf8, 0xe6, 0xc6), outlineSize=2, outlineColor=cc.c3b(0x11,0x11,0x11)})
  2447. else
  2448. v.Button_group:loadTextureNormal(self.path .. "announce/1900000663.png")
  2449. v.Button_group:loadTexturePressed(self.path .. "announce/1900000662.png")
  2450. v.Button_group:setTouchEnabled(true)
  2451. drawButtonColorStyle(v.Button_group, {fontSize=18, color=cc.c3b(0x80, 0x72, 0x56), outlineSize=2, outlineColor=cc.c3b(0x11,0x11,0x11)})
  2452. end
  2453. end
  2454. local RichTextHelp = requireLauncher( "init/RichTextHelp" )
  2455. -- 公告标题
  2456. local textTitle = RichTextHelp:CreateRichTextWithXML(data.title, 500, 18, "#43d849" )
  2457. self._announceUI.Node_title:removeAllChildren()
  2458. self._announceUI.Node_title:addChild(textTitle)
  2459. -- 公告内容
  2460. local scrollview = self._announceUI.ScrollView_content
  2461. scrollview:setContentSize({width=500, height=220})
  2462. scrollview:setInnerContainerSize({width=500, height=220})
  2463. scrollview:removeAllChildren()
  2464. local textAnnounce = RichTextHelp:CreateRichTextWithXML( data.desc, scrollview:getContentSize().width, 18, "#c9b39c" )
  2465. scrollview:addChild( textAnnounce )
  2466. textAnnounce:formatText()
  2467. textAnnounce:setAnchorPoint({x=0.5, y=1})
  2468. local textContentSize = textAnnounce:getContentSize()
  2469. local scrollContentSize = scrollview:getContentSize()
  2470. local newContentSize = {width=textContentSize.width, height=math.min(scrollContentSize.height, textContentSize.height)}
  2471. local newInnerSize = {width=textContentSize.width, height=math.max(newContentSize.height, textContentSize.height)}
  2472. scrollview:setContentSize( newContentSize )
  2473. scrollview:setInnerContainerSize( newInnerSize )
  2474. textAnnounce:setPosition({x=newContentSize.width/2, y=textContentSize.height})
  2475. end
  2476. -- group cell
  2477. local function createGroup(data)
  2478. local root = CreateExport_launcher("server/module_announce_cell")
  2479. local layout = root:getChildByName("Panel_1")
  2480. layout:removeFromParent()
  2481. local ui = ui_delegate(layout)
  2482. -- 特性
  2483. local trait = tonumber(data.typename) or 1
  2484. ui.Image_trait:loadTexture(string.format(self.path .. "announce/word_hefubq_0%s.png", trait))
  2485. -- 查看
  2486. ui.Button_group:setTitleText(data.name)
  2487. ui.Button_group:addClickEventListener( function()
  2488. showDesc(data)
  2489. end )
  2490. return ui
  2491. end
  2492. local modGameEnv = self._currentSubMod:GetGameEnv()
  2493. local serverData = modGameEnv:GetServerData()
  2494. if nil == serverData then
  2495. return
  2496. end
  2497. local announce = serverData.announce
  2498. if nil == announce then
  2499. return
  2500. end
  2501. -- filter
  2502. local items = {}
  2503. for i, v in ipairs(announce) do
  2504. if v.type and tonumber(v.type) == 1 then
  2505. tinsert(items, 1, v)
  2506. else
  2507. tinsert(items, v)
  2508. end
  2509. end
  2510. for i, v in ipairs(items) do
  2511. v.index = i
  2512. local cell = createGroup(v)
  2513. self._announceUI.ListView_group:pushBackCustomItem(cell.nativeUI)
  2514. self._announceGroupCells[v.index] = cell
  2515. end
  2516. if #items > 0 then
  2517. showDesc(items[1])
  2518. end
  2519. end
  2520. function ModuleChooseLayer:OnClose()
  2521. self:ReleaseServerCache()
  2522. end
  2523. function ModuleChooseLayer:OnDownloadResCB(isOK, filename, downloadFlag)
  2524. if not isOK then
  2525. return nil
  2526. end
  2527. if downloadFlag == self.DownloadFlag.Logo then
  2528. self:UpdateLogo()
  2529. elseif downloadFlag == self.DownloadFlag.AgeTips then
  2530. self:UpdateAgeTipsImage()
  2531. elseif downloadFlag == self.DownloadFlag.LogoMini then
  2532. self:UpdateLogo()
  2533. elseif downloadFlag == self.DownloadFlag.LogoMini2 then
  2534. self:UpdateLogo()
  2535. end
  2536. end
  2537. function ModuleChooseLayer:ShowAgreement()
  2538. if self._agreementUI then
  2539. self._agreementUI.nativeUI:removeFromParent()
  2540. self._agreementUI = nil
  2541. end
  2542. if nil == self._currentModule or not self._currentSubMod then
  2543. return
  2544. end
  2545. local modGameEnv = self._currentSubMod:GetGameEnv()
  2546. if not modGameEnv then
  2547. return nil
  2548. end
  2549. local content = modGameEnv:GetCustomDataByKey("agreement")
  2550. if not content or string.len(content) == 0 then
  2551. return nil
  2552. end
  2553. content = string.gsub(content, "<%s-br%s->", "<br></br>")
  2554. content = string.gsub(content, "<%s-br%s-/>", "<br></br>")
  2555. local root = CreateExport_launcher("server/agreement")
  2556. self:addChild(root)
  2557. self._agreementUI = ui_delegate(root)
  2558. drawButtonColorStyle(self._agreementUI.Button_refuse, {fontSize=18, color=cc.c3b(0xf8, 0xe6, 0xc6), outlineSize=3, outlineColor=cc.c3b(0x11,0x11,0x11)})
  2559. drawButtonColorStyle(self._agreementUI.Button_agree, {fontSize=18, color=cc.c3b(0xf8, 0xe6, 0xc6), outlineSize=3, outlineColor=cc.c3b(0x11,0x11,0x11)})
  2560. -- agree
  2561. local function agreeCB()
  2562. self._agreementUI.nativeUI:removeFromParent()
  2563. self._agreementUI = nil
  2564. local launcherModID = global.L_ModuleManager:GetLauncherModuleID()
  2565. local channelID = tostring(global.L_GameEnvManager:GetChannelID())
  2566. local userData = UserData:new(launcherModID .. channelID .. "_data")
  2567. userData:setIntegerForKey("agreement", 1)
  2568. userData:writeMapDataToFile()
  2569. end
  2570. self._agreementUI.Button_agree:addClickEventListener(agreeCB)
  2571. -- refuse
  2572. local function refuseCB()
  2573. local launcherModID = global.L_ModuleManager:GetLauncherModuleID()
  2574. local channelID = tostring(global.L_GameEnvManager:GetChannelID())
  2575. local userData = UserData:new(launcherModID .. channelID .. "_data")
  2576. userData:setIntegerForKey("agreement", 0)
  2577. userData:writeMapDataToFile()
  2578. if global.isIOS then
  2579. global.L_NativeBridgeManager:GN_accountLogout()
  2580. global.L_GameEnvManager:RestartGame()
  2581. else
  2582. global.Director:endToLua()
  2583. end
  2584. end
  2585. self._agreementUI.Button_refuse:addClickEventListener(refuseCB)
  2586. -- 公告内容
  2587. local RichTextHelp = requireLauncher( "init/RichTextHelp" )
  2588. local scrollview = self._agreementUI.ScrollView_content
  2589. local innerSize = scrollview:getInnerContainerSize()
  2590. local richText = RichTextHelp:CreateRichTextWithXML(content, innerSize.width, 18, "#c9b39c")
  2591. scrollview:addChild( richText )
  2592. richText:formatText()
  2593. richText:setAnchorPoint({x=0.5, y=1})
  2594. richText:setOpenUrlHandler( function(sender, str)
  2595. cc.Application:getInstance():openURL(str)
  2596. end )
  2597. local textContentSize = richText:getContentSize()
  2598. local scrollContentSize = scrollview:getContentSize()
  2599. local newContentSize = {width=textContentSize.width, height=math.min(scrollContentSize.height, textContentSize.height)}
  2600. local newInnerSize = {width=textContentSize.width, height=math.max(newContentSize.height, textContentSize.height)}
  2601. scrollview:setContentSize( newContentSize )
  2602. scrollview:setInnerContainerSize( newInnerSize )
  2603. richText:setPosition({x=newContentSize.width/2, y=textContentSize.height})
  2604. end
  2605. -- 内部显示隐私内容
  2606. function ModuleChooseLayer:InsideShowNoticeContent( content )
  2607. content = tostring(content) or ""
  2608. -- root
  2609. local visibleSize = cc.Director:getInstance():getVisibleSize()
  2610. local Panel_1 = ccui.Layout:create()
  2611. Panel_1:setName( "NOTICE_CONTENT" )
  2612. Panel_1:setContentSize(visibleSize)
  2613. Panel_1:setTouchEnabled( true )
  2614. Panel_1:setSwallowTouches( true )
  2615. self:addChild( Panel_1 )
  2616. local clickCount = 0 --点击的内容url数量
  2617. local clickUrl = false --是否是点击超链接进入的内容
  2618. local clickCountUrls = {} --记录点击的内容的超链
  2619. -- 背景图
  2620. local csize = {width=600, height=400}
  2621. local innerSize = {width=500,height=300}
  2622. local Image_bg = ccui.ImageView:create()
  2623. Image_bg:loadTexture(self.publicPath .. "1900000600.png",0)
  2624. Image_bg:setPosition( visibleSize.width/2, visibleSize.height/2 )
  2625. Image_bg:setTouchEnabled( true )
  2626. Image_bg:setSwallowTouches( true )
  2627. local x = 30
  2628. local y = 30
  2629. local width = 452-60
  2630. local height = 179-60
  2631. Image_bg:setScale9Enabled(true)
  2632. Image_bg:setCapInsets({x = x, y = y, width = width, height = height})
  2633. Image_bg:setContentSize(csize)
  2634. Panel_1:addChild( Image_bg )
  2635. local RichTextHelp = requireLauncher( "init/RichTextHelp" )
  2636. local function UpdateContent( newContent )
  2637. local listview = Image_bg:getChildByName("LISTVIEW_CONTENT")
  2638. if listview then
  2639. listview:removeAllChildren()
  2640. -- 内容RichText
  2641. local richText = RichTextHelp:CreateRichTextWithXML(newContent, innerSize.width, 18, "#FFFFFF")
  2642. richText:formatText()
  2643. listview:pushBackCustomItem( richText )
  2644. richText:setOpenUrlHandler(function(sender,str)
  2645. HTTPRequest(str, function(success,response)
  2646. if success and response and string.len(response) > 0 then
  2647. if success and response and string.len(response) > 0 then
  2648. table.insert( clickCountUrls,str )
  2649. clickCount = #clickCountUrls
  2650. clickUrl = true
  2651. UpdateContent( response )
  2652. end
  2653. end
  2654. end)
  2655. end)
  2656. end
  2657. end
  2658. -- 确认按钮
  2659. local Button_confirm = ccui.Button:create()
  2660. Button_confirm:setPosition({x=csize.width/2, y=40})
  2661. Button_confirm:loadTextureNormal(self.publicPath .. "1900001022.png")
  2662. Button_confirm:loadTexturePressed(self.publicPath .. "1900001022.png")
  2663. Button_confirm:setTouchEnabled(true)
  2664. Button_confirm:setTitleFontName("fonts/font.ttf")
  2665. Button_confirm:setTitleFontSize(18)
  2666. Button_confirm:setTitleText("确 认")
  2667. Button_confirm:addClickEventListener(function()
  2668. if clickCount == #clickCountUrls then
  2669. table.remove(clickCountUrls)
  2670. end
  2671. local url = table.remove(clickCountUrls)
  2672. if url then
  2673. HTTPRequest(url, function(success,response)
  2674. if success and response and string.len(response) > 0 then
  2675. UpdateContent( response )
  2676. end
  2677. end)
  2678. return
  2679. end
  2680. if clickUrl then
  2681. clickUrl = false
  2682. UpdateContent( content )
  2683. return
  2684. end
  2685. Panel_1:removeFromParent()
  2686. Panel_1 = nil
  2687. end)
  2688. Image_bg:addChild(Button_confirm)
  2689. -- 内容List
  2690. local ListView_content = ccui.ListView:create()
  2691. ListView_content:setName("LISTVIEW_CONTENT")
  2692. ListView_content:ignoreContentAdaptWithSize(false)
  2693. ListView_content:setClippingEnabled(true)
  2694. ListView_content:setTouchEnabled(true)
  2695. ListView_content:setAnchorPoint(0.5,1)
  2696. ListView_content:setPosition( csize.width/2, 380)
  2697. ListView_content:setContentSize( {width=550, height=300} )
  2698. ListView_content:setInnerContainerSize( innerSize )
  2699. Image_bg:addChild( ListView_content )
  2700. -- 内容RichText
  2701. local RichTextHelp = requireLauncher( "init/RichTextHelp" )
  2702. local richText = RichTextHelp:CreateRichTextWithXML(content, innerSize.width, 18, "#FFFFFF")
  2703. richText:formatText()
  2704. ListView_content:pushBackCustomItem( richText )
  2705. UpdateContent( content )
  2706. end
  2707. function ModuleChooseLayer:CheckAutoEnterGame()
  2708. local envMgr = global.L_GameEnvManager
  2709. local env_uid = envMgr:GetEnvDataByKey("uid")
  2710. local env_token = envMgr:GetEnvDataByKey("token")
  2711. local env_visitkey = envMgr:GetEnvDataByKey("visitkey")
  2712. local env_isAutoEnterGame = envMgr:GetEnvDataByKey("isAutoEnterGame")
  2713. local BoxAutoEnterGame = envMgr:GetEnvDataByKey("BoxAutoEnterGame")
  2714. if env_uid and env_token and (env_visitkey or env_isAutoEnterGame or BoxAutoEnterGame) then
  2715. if BoxAutoEnterGame then
  2716. self.BoxAutoEnterGame = true
  2717. self:UpdateEnvByKey("BoxAutoEnterGame",nil)
  2718. end
  2719. self:LaunchModule()
  2720. return
  2721. end
  2722. local env_userId = envMgr:GetEnvDataByKey("user_id")
  2723. local env_qqFirst = envMgr:GetEnvDataByKey("firstopen")
  2724. if env_userId and env_token and tonumber(env_qqFirst) and tonumber(env_qqFirst) == 1 then
  2725. if self.ui.CheckBox_agreement then
  2726. self.ui.CheckBox_agreement:setSelected(true)
  2727. end
  2728. self:LaunchModule()
  2729. end
  2730. end
  2731. function ModuleChooseLayer:updateBoxUI()
  2732. -- 切换账号/返回盒子
  2733. -- 区服大厅
  2734. local HideGameList = function ()
  2735. self.ui.Button_game_list:setVisible(false)
  2736. local gameListY = self.ui.Button_game_list:getPositionY()
  2737. local fixY = self.ui.Button_fix:getPositionY()
  2738. self.ui.Button_fix:setPositionY(gameListY)
  2739. self.ui.Button_share:setPositionY(fixY)
  2740. end
  2741. self.ui.Button_game:setTouchEnabled(false)
  2742. if global.isBoxLogin or global.isUgc then
  2743. if not global.isWindows then
  2744. local btnTextStr = fixNewLanguageString( "返回盒子" )
  2745. if global.isUgc then
  2746. btnTextStr = fixNewLanguageString( "退出游戏" )
  2747. end
  2748. self.ui.Button_logout:setTitleText(btnTextStr)
  2749. if global.L_GameEnvManager:GetEnvDataByKey("hideBackBox") == 1 then
  2750. self.ui.Button_logout:setVisible(false)
  2751. end
  2752. if global.L_GameEnvManager:GetEnvDataByKey("platform") ~= "mac" then
  2753. self.ui.Button_fix:setVisible(false)
  2754. local fixY = self.ui.Button_fix:getPositionY()
  2755. self.ui.Button_share:setPositionY(fixY)
  2756. end
  2757. end
  2758. local boxConfig = global.L_GameEnvManager:GetEnvDataByKey("boxConfig")
  2759. local hideServerList = global.L_GameEnvManager:GetEnvDataByKey("hideServerList")
  2760. local showServer = hideServerList == 0 or hideServerList == nil
  2761. if boxConfig and boxConfig ~= "" and showServer then
  2762. self.ui.Button_game_list:setVisible(true)
  2763. self._supportGameList = true
  2764. else
  2765. HideGameList()
  2766. end
  2767. else
  2768. -- self.ui.Panel_game:setVisible(false)
  2769. HideGameList()
  2770. end
  2771. end
  2772. function ModuleChooseLayer:DecodeServerList(data) -- base64 -> des --ebc zeropadding
  2773. local Array = require("lockbox.util.array");
  2774. local Stream = require("lockbox.util.stream");
  2775. local Base64 = require("lockbox.util.base64");
  2776. local ECBMode = require("lockbox.cipher.mode.ecb");
  2777. local ZeroPadding = require("lockbox.padding.zero");
  2778. local DESCipher = require("lockbox.cipher.des");
  2779. local decodeinfo = {
  2780. mode = ECBMode,
  2781. key = Array.fromString("v@K#KlYkLlH3BN&3%wM!BM99"),
  2782. iv = Array.fromString(""),
  2783. ciphertext=Base64.toStream(data),
  2784. padding = ZeroPadding
  2785. }
  2786. local decipher = decodeinfo.mode.Decipher()
  2787. .setKey(decodeinfo.key)
  2788. .setBlockCipher(DESCipher)
  2789. .setPadding(decodeinfo.padding);
  2790. local res = decipher
  2791. .init()
  2792. .update(Stream.fromArray(decodeinfo.iv))
  2793. .update(decodeinfo.ciphertext)
  2794. .finish()
  2795. .asBytes();
  2796. return Array.toString(res)
  2797. end
  2798. function ModuleChooseLayer:OnLastSelectServerResp()
  2799. if not self._currentModule or not self._currentSubMod then
  2800. return nil
  2801. end
  2802. local modGameEnv = self._currentSubMod:GetGameEnv()
  2803. if not modGameEnv then
  2804. return nil
  2805. end
  2806. modGameEnv:ReadLastServers()
  2807. self:UpdateSelected()
  2808. end
  2809. --showGameList
  2810. function ModuleChooseLayer:ShowGameList()
  2811. if global.isWindows then
  2812. if getWindowsVersion then
  2813. local versionStr = getWindowsVersion()
  2814. local MajorVer = 10
  2815. local MinorVer = 0
  2816. local BuildNumber = 19045
  2817. if versionStr and #versionStr > 0 then
  2818. local verList = string.split(versionStr,"_")
  2819. MajorVer = tonumber(verList[1]) or 10
  2820. MinorVer = tonumber(verList[2]) or 0
  2821. end
  2822. --win7 6 1 win8 6 2
  2823. if MajorVer <= 6 then
  2824. if MinorVer <= 1 then
  2825. global.L_SystemTipsManager:ShowTips("本功能暂不支持win7及以下版本")
  2826. return
  2827. end
  2828. end
  2829. end
  2830. self.ui.Panel_webview:setVisible(true)
  2831. self.ui.Panel_webview_tips:setVisible(true)
  2832. local winSize = global.Director:getWinSize()
  2833. local defaultSize = {width = winSize.width, height = winSize.height}--{width = 1050, height = 600}
  2834. local showSize = defaultSize
  2835. local minScale = 1
  2836. -- if defaultSize.width > winSize.width or defaultSize.height > winSize.height then
  2837. -- minScale = math.min(winSize.width / defaultSize.width , winSize.height / defaultSize.height)
  2838. -- showSize.width = minScale * defaultSize.width
  2839. -- showSize.height = minScale * defaultSize.height
  2840. -- else
  2841. -- showSize = defaultSize
  2842. -- end
  2843. if not ccexp.CustomView then --老版本可能没有
  2844. return
  2845. end
  2846. local webview = ccexp.CustomView:create()
  2847. if not webview.setWebToGameFunc then --老ie版本 打不开
  2848. return
  2849. end
  2850. self._webView = webview
  2851. local boxConfig = global.L_GameEnvManager:GetEnvDataByKey("boxConfig")
  2852. local webUrl = global.L_GameEnvManager:GetEnvDataByKey("gameListUrl") or ""
  2853. webview:setWebToGameFunc(function (param)
  2854. -- releasePrint("setWebToGameFunc param is ", param)
  2855. local jsonData = cjson.decode(param)
  2856. local action = jsonData.action
  2857. if action == "close" then
  2858. self:HideGameList()
  2859. return ""
  2860. elseif action == "restart" then
  2861. local envStr = jsonData.env
  2862. local env = cjson.decode(envStr)
  2863. env.gameListUrl = webUrl--游戏内启动需要保存一下地址
  2864. -- 盒子 游戏大厅切换游戏 写入上报配置(PC盒子都一样)
  2865. local appid = global.L_GameEnvManager:GetEnvDataByKey("sdkAppid")
  2866. if appid then
  2867. env.sdkAppid = appid
  2868. end
  2869. local secretKey = global.L_GameEnvManager:GetEnvDataByKey("sdkAppkey")
  2870. if secretKey then
  2871. env.sdkAppkey = secretKey
  2872. end
  2873. local channelid = global.L_GameEnvManager:GetEnvDataByKey("sdkChannel")
  2874. if channelid then
  2875. env.sdkChannel = channelid
  2876. end
  2877. envStr = cjson.encode(env)
  2878. self:WriteEnvAndRestart(envStr)
  2879. return ""
  2880. elseif action == "getConfig" then
  2881. return cjson.encode({
  2882. boxConfig = boxConfig,
  2883. viewScale = minScale,
  2884. gameName = "cq"
  2885. })
  2886. end
  2887. end)
  2888. webview:setOnDidFinishLoading(function(sender, url)
  2889. -- releasePrint("onWebViewDidFinishLoading, url is ", url)
  2890. if url == webUrl or url == (webUrl .. "/") or url == ("http://" .. webUrl .. "/") or url == ("http://" .. webUrl) then
  2891. self.ui.Panel_webview_tips:setVisible(false)
  2892. end
  2893. end)
  2894. webview:setOnDidFailLoading(function(sender, url)
  2895. releasePrint("setOnDidFailLoading, url is ", url)
  2896. if url == webUrl or url == (webUrl .. "/") or url == ("http://" .. webUrl .. "/") or url == ("http://" .. webUrl) then
  2897. global.L_SystemTipsManager:ShowTips("加载失败,请稍后再试~")
  2898. self:HideGameList()
  2899. end
  2900. end)
  2901. webview:setAnchorPoint(cc.p(0.5,0.5))
  2902. webview:setContentSize(showSize.width,showSize.height)
  2903. webview:setPosition(winSize.width/2 ,winSize.height/2)
  2904. webview:loadURL(webUrl)
  2905. self.ui.Panel_webview:addChild(webview)
  2906. else
  2907. --游戏大厅
  2908. if global.L_NativeBridgeManager.GN_GameList then
  2909. global.L_NativeBridgeManager:GN_GameList()
  2910. end
  2911. end
  2912. -- 弹出用户协议提示 上报自定义事件
  2913. local dataParam = {
  2914. event={time=os.time(),name = "click_serverhall",type = "track"}
  2915. }
  2916. local userId = global.L_GameEnvManager:GetEnvDataByKey("user_id") or global.L_GameEnvManager:GetEnvDataByKey("uid")
  2917. if userId and userId ~= "" then
  2918. dataParam.user = {id = userId}
  2919. end
  2920. global.L_DataRePort:SendRePortData( dataParam )
  2921. end
  2922. function ModuleChooseLayer:WriteEnv(envStr)
  2923. local fileutil = cc.FileUtils:getInstance()
  2924. local envPath = ""
  2925. if global.isWindows then
  2926. local rootPath = fileutil:getDefaultResourceRootPath()
  2927. envPath = rootPath .. "env.json"
  2928. else
  2929. local writePath = global.FileUtilCtl:getWritablePath()
  2930. local launchDir = getNewFoldername("mod_launcher")
  2931. envPath = writePath.. launchDir .. "/env.json"
  2932. if not fileutil:isDirectoryExist(launchDir) then
  2933. fileutil:createDirectory(launchDir)
  2934. end
  2935. end
  2936. if fileutil:isFileExist(envPath) then
  2937. fileutil:removeFile(envPath)
  2938. end
  2939. fileutil:writeStringToFile(envStr, envPath)
  2940. end
  2941. function ModuleChooseLayer:UpdateEnvByKey(key, value)
  2942. local fileutil = cc.FileUtils:getInstance()
  2943. local envPath = ""
  2944. if global.isWindows then
  2945. local rootPath = fileutil:getDefaultResourceRootPath()
  2946. envPath = rootPath .. "env.json"
  2947. else
  2948. local writePath = global.FileUtilCtl:getWritablePath()
  2949. local launchDir = getNewFoldername("mod_launcher")
  2950. envPath = writePath.. launchDir .. "/env.json"
  2951. end
  2952. local jsonData = global.L_GameEnvManager:GetEnvData("new_boxtoken")
  2953. jsonData[key] = value
  2954. local jsonStr = cjson.encode(jsonData)
  2955. fileutil:writeStringToFile(jsonStr, envPath)
  2956. end
  2957. function ModuleChooseLayer:WriteEnvAndRestart(envStr)
  2958. self:WriteEnv(envStr)
  2959. global.L_GameEnvManager:RestartGame()
  2960. end
  2961. --新用户 推荐服等设置
  2962. function ModuleChooseLayer:ParseShowHideSrvitem()
  2963. if not self._currentModule or not self._currentSubMod then
  2964. return
  2965. end
  2966. local modGameEnv = self._currentSubMod:GetGameEnv()
  2967. local serverData = modGameEnv:GetServerData()
  2968. local jsonData = serverData.source
  2969. local referArrAble = false
  2970. local stateHide = {}
  2971. local refer = modGameEnv:GetRefer()
  2972. local referArr = jsonData.referArr
  2973. local referOnlyOne = jsonData.referOnlyOne --只展示一个 推荐
  2974. if referArr and next(referArr) then
  2975. referArrAble = true
  2976. -- 推荐服组除了随到的其他服全隐藏
  2977. for i, v in ipairs(referArr) do
  2978. if refer and v ~= refer then
  2979. stateHide[v] = 1
  2980. end
  2981. end
  2982. end
  2983. local hidesrvGroup = {}
  2984. if self._existLastMod == false then
  2985. -- 服务器组tag为key,新用户隐藏组功能
  2986. if serverData.srvgroup and type(serverData.srvgroup) == "table" then
  2987. for i, v in ipairs(serverData.srvgroup) do
  2988. hidesrvGroup[v.tag] = (1 == tonumber(v.hide))
  2989. end
  2990. end
  2991. end
  2992. for i, srvitem in ipairs(serverData.srvlist) do
  2993. local srvid = srvitem.serverId
  2994. srvitem.state = srvitem.oriState
  2995. --新用户
  2996. if self._existLastMod == false then
  2997. if referArrAble and refer then
  2998. --推荐服没随到的都隐藏
  2999. if stateHide[srvid] then
  3000. --隐藏
  3001. srvitem.state = 5-- 状态 1新服,2畅通,3爆满,4维护,5隐藏
  3002. end
  3003. --非审核状态
  3004. if not global.L_GameEnvManager:IsReview() then
  3005. local srvid = tonumber(srvid)
  3006. local refer = tonumber(refer)
  3007. local referOnlyOne = tonumber(referOnlyOne)
  3008. if srvid and refer then
  3009. --
  3010. if (srvitem.state <= 3 and srvid > refer) or (referOnlyOne == 1 and srvid ~= refer) then
  3011. srvitem.state = 5
  3012. end
  3013. end
  3014. if hidesrvGroup[srvitem.tag] then
  3015. srvitem.state = 5
  3016. end
  3017. end
  3018. end
  3019. else
  3020. --老用户
  3021. if referArrAble and refer then
  3022. if stateHide[srvid] then
  3023. --爆满
  3024. srvitem.state = 3
  3025. end
  3026. end
  3027. end
  3028. end
  3029. end
  3030. function ModuleChooseLayer:UpdateServersWhenRoleInfoGet()
  3031. --获取到角色数据了。。。。
  3032. self._existLastMod = true
  3033. self:ParseShowHideSrvitem()
  3034. self:UpdateServers()
  3035. end
  3036. function ModuleChooseLayer:RequestCustomURL(customURL)
  3037. if not customURL then
  3038. return nil
  3039. end
  3040. self._customCount = self._customCount + 1
  3041. local function reportError(str, callback)
  3042. local tipsData = {
  3043. btnType = 1,
  3044. str = str,
  3045. callback = callback
  3046. }
  3047. global.L_CommonTipsManager:OpenLayer( tipsData )
  3048. end
  3049. local function callback()
  3050. self:RequestCustomURL(customURL)
  3051. end
  3052. ----------------------------------------
  3053. local function httpCB(success, response, url, code)
  3054. HideLoadingBar()
  3055. -- 拉取失败,网络原因
  3056. if not success then
  3057. if self._customCount >= 3 then
  3058. reportError("[customURL][0]远端数据获取异常,点击“确认”重试\n多次失败请联系客服", callback)
  3059. -- 上报至服务器
  3060. global.L_DataRePort:ReportErrorModlistURL("CUSTOMURL_REQUEST_FAILED", "-3010", "Request customURL ERROR, CODE ERROR", url, code)
  3061. else
  3062. callback()
  3063. end
  3064. return nil
  3065. end
  3066. -- 拉取失败,内容空
  3067. if not response then
  3068. if self._customCount >= 3 then
  3069. reportError("[customURL][1]远端数据获取异常,点击“确认”重试\n多次失败请联系客服", callback)
  3070. -- 上报至服务器
  3071. global.L_DataRePort:ReportErrorModlistURL("CUSTOMURL_REQUEST_FAILED", "-3011", "Request customURL ERROR, RESPONSE ERROR", url, code)
  3072. else
  3073. callback()
  3074. end
  3075. return nil
  3076. end
  3077. local isOk, jsonData = pcall(function ()
  3078. -- body
  3079. return cjson.decode(response)
  3080. end)
  3081. -- json解析,检测是否解析成功
  3082. if not isOk then
  3083. reportError("[customURL][2]远端服务器配置格式异常,点击“确认”重试\n多次失败请联系客服", callback)
  3084. -- 上报至服务器
  3085. global.L_DataRePort:ReportErrorModlistURL("CUSTOMURL_REQUEST_FAILED", "-3013", "Request customURL ERROR, JSON ERROR"..response, url, code)
  3086. return nil
  3087. end
  3088. self._customCount = 0
  3089. if not self._currentModule or not self._currentSubMod then
  3090. return nil
  3091. end
  3092. local modGameEnv = self._currentSubMod:GetGameEnv()
  3093. if modGameEnv:GetCustomUrl() ~= customURL then
  3094. return nil
  3095. end
  3096. for k, v in pairs(jsonData) do
  3097. modGameEnv:SetCustomDataByKey(k, v)
  3098. end
  3099. modGameEnv:SetCustomIsLoaded(true)
  3100. self:OnCustomData(true)
  3101. end
  3102. local str = string.match(customURL, "/(custom/.*/.*)")
  3103. local srvlistData = str and str or ""
  3104. local timestamp = os.time()
  3105. local signKey = global.L_GameEnvManager:GetModlistSignKey()
  3106. local sign = get_str_MD5("data=" .. srvlistData .. "&key=" .. signKey .. "&time="..timestamp)
  3107. local customURL2 = customURL .. string.format("?time=%s&sign=%s", timestamp, sign)
  3108. releasePrint("customURL:", customURL2)
  3109. if customURL2 and string.len(customURL2) > 0 then
  3110. ShowLoadingBar()
  3111. HTTPRequest(customURL2, httpCB)
  3112. end
  3113. end
  3114. return ModuleChooseLayer