TxtTranslator.lua 112 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527
  1. --------------------------------------------------------
  2. --------------------------------------------------------
  3. --------------------------------------------------------
  4. local TxtTranslator = class("TxtTranslator")
  5. local Element = require("sui/Element")
  6. local SWidget = require("sui/SWidget")
  7. local SUIHelper = require("sui/SUIHelper")
  8. local LexicalHelper = require("sui/LexicalHelper")
  9. local RichTextHelp = require("util/RichTextHelp")
  10. local QuickCell = requireUtil("QuickCell")
  11. local TWidget = require("sui/TWidget")
  12. local cjson = require("cjson")
  13. local tinsert = table.insert
  14. local tremove = table.remove
  15. local ssplit = string.split
  16. local sfind = string.find
  17. local sformat = string.format
  18. local mfloor = math.floor
  19. local lineS = sformat("%s%s","\n", "\t")
  20. local tabS = "\t"
  21. local noParentCode = -1
  22. ------------------------------------------ util
  23. TxtTranslator.isBackground = function(swidget)
  24. if not swidget then
  25. return false
  26. end
  27. return tonumber(swidget.element.attr.bg) == 1
  28. end
  29. ------------------------------------------
  30. ------------------------------------------
  31. --
  32. local defaultOutline = 0
  33. local defaultOutlineC = 0
  34. local defaultColorID = 255
  35. local defaultFontSize = global.isWinPlayMode and 12 or 18
  36. local anchorPoints = {[0] = {x = 0, y = 1}, [1] = {x = 1, y = 1}, [2] = {x = 0, y = 0}, [3] = {x = 1, y = 0}, [4] = {x = 0.5, y = 0.5}}
  37. local defaultTextX = 25
  38. local defaultTextY = 20
  39. local interval = 0.167
  40. local function transToTable(jsonStr)
  41. local resultStr = jsonStr
  42. for v in string.gmatch(resultStr, "\"(.-)\":") do
  43. resultStr = string.gsub(resultStr, "\"" .. v .. "\"", v)
  44. break
  45. end
  46. for v in string.gmatch(resultStr, ",\"(.-)\":") do
  47. resultStr = string.gsub(resultStr, "\"" .. v .. "\"" , v)
  48. end
  49. for v in string.gmatch(resultStr, "{\"(.-)\":") do
  50. resultStr = string.gsub(resultStr, "\"" .. v .. "\"" , v)
  51. end
  52. resultStr = string.gsub(resultStr, "%[", "{")
  53. resultStr = string.gsub(resultStr, "%]", "}")
  54. resultStr = string.gsub(resultStr, "\\/", "/")
  55. resultStr = string.gsub(resultStr, ",", ", ")
  56. return string.gsub(resultStr, ":", " = ")
  57. end
  58. local function replace(str, valueList)
  59. local result = ""
  60. local function getValueBySrc(source, valueList)
  61. if valueList and next(valueList) then
  62. source = string.gsub(source, "^[${]+", "")
  63. source = string.gsub(source, "[}]+$", "")
  64. if source and string.len(source) > 0 and valueList[source] then
  65. if type(valueList[source]) == "table" then
  66. local jsonStr = cjson.encode(valueList[source])
  67. return transToTable(jsonStr)
  68. end
  69. return tostring(valueList[source])
  70. elseif source and string.len(source) > 0 and type(valueList[source]) == "boolean" then
  71. return tostring(valueList[source])
  72. end
  73. end
  74. return "ERROR"
  75. end
  76. while string.find(str, "${.-}") do
  77. local info = {string.find(str, "(${.-})")}
  78. if info[3] then
  79. result = result..string.sub(str, 1, info[1] - 1)
  80. local needRe = string.sub(str, info[1], info[2])
  81. result = string.format("%s%s", result, getValueBySrc(needRe, valueList))
  82. str = string.sub(str, info[2] + 1)
  83. end
  84. end
  85. return string.format("%s%s", result, str)
  86. end
  87. local function tranNegNum(num)
  88. if num < 0 then
  89. return sformat("(%s)", num)
  90. end
  91. return num
  92. end
  93. function TxtTranslator:loadTalkContent(str, filename)
  94. local NPCProxy = global.Facade:retrieveProxy(global.ProxyTable.NPC)
  95. local talkData = NPCProxy:GetCurrentNPCTalkData()
  96. local backgroundData = NPCProxy:GetCurrentBackground()
  97. local function callback(cdata)
  98. end
  99. local function closeCB()
  100. end
  101. local function loadCompleteCB()
  102. print("load complete T")
  103. end
  104. local needAdd = (self.trunk == nil)
  105. local ext = {background = backgroundData, lastTrunk = self.trunk, lastBackground = self.background, loadCompleteCB = loadCompleteCB }
  106. self._content = self:load(str, callback, closeCB, ext)
  107. -- 保存
  108. self:SaveToFile(filename, self._content)
  109. end
  110. function TxtTranslator:SaveToFile(fileName, content)
  111. if not fileName or string.len(fileName) == 0 then
  112. fileName = "export_file_" .. Random(0, 9999)
  113. end
  114. local exportPath = global.FileUtilCtl:getDefaultResourceRootPath() .. "dev/ssrExportFile"
  115. if not global.FileUtilCtl:isDirectoryExist(exportPath) then
  116. global.FileUtilCtl:createDirectory(exportPath)
  117. end
  118. local filePath = string.format("%s/%s.lua", exportPath, fileName)
  119. global.FileUtilCtl:writeStringToFile(content, filePath)
  120. ShowSystemTips("转化成功 ".. exportPath .. " ".. fileName .. ".lua")
  121. end
  122. TxtTranslator.getAnchorByIndex = function(index)
  123. return anchorPoints[index or 0]
  124. end
  125. TxtTranslator.modifySizeAble = function(swidget)
  126. local element = swidget.element
  127. if element.type == "Effect" then
  128. return false
  129. end
  130. if element.type == "Text" then
  131. return false
  132. end
  133. if element.type == "ItemShow" then
  134. return false
  135. end
  136. if element.type == "CostItem" then
  137. return false
  138. end
  139. if element.type == "COUNTDOWN" then
  140. return false
  141. end
  142. if element.type == "EquipShow" or element.type == "HEROEquipShow" or element.type == "PETEQUIPSHOW" then
  143. return false
  144. end
  145. if element.type == "TIMETIPS" then
  146. return false
  147. end
  148. if element.type == "TextAtlas" then
  149. return false
  150. end
  151. if element.type == "UIModel" then
  152. return false
  153. end
  154. if element.type == "ScrapePic" then
  155. return false
  156. end
  157. if element.type == "BmpText" then
  158. return false
  159. end
  160. return true
  161. end
  162. TxtTranslator.modifyAnchorAble = function(swidget)
  163. local element = swidget.element
  164. if element.type == "Effect" then
  165. return false
  166. end
  167. if element.type == "UIModel" then
  168. return false
  169. end
  170. return true
  171. end
  172. TxtTranslator.modifyRotateAble = function(swidget)
  173. return true
  174. end
  175. TxtTranslator.modifyVisible = function(swidget)
  176. return true
  177. end
  178. TxtTranslator.fixAnchor = function(swidget)
  179. local content = ""
  180. local name = swidget.realname or swidget.name
  181. if tonumber(swidget.element.attr.bg) == 1 and tonumber(swidget.element.attr.show) == 5 or tonumber(swidget.element.attr.show) == 6 then
  182. local ax = tonumber(swidget.element.attr.tax)
  183. local ay = tonumber(swidget.element.attr.tay)
  184. ax = ax or 0
  185. ay = ay or 1
  186. content = string.format("GUI:setAnchorPoint(%s, %.2f, %.2f)", name, ax, ay)
  187. return content
  188. end
  189. if swidget.element.attr.ax or swidget.element.attr.ay then
  190. local ax = tonumber(swidget.element.attr.ax)
  191. local ay = tonumber(swidget.element.attr.ay)
  192. ax = ax or 0
  193. ay = ay or 1
  194. content = string.format("GUI:setAnchorPoint(%s, %.2f, %.2f)", name, ax, ay)
  195. return content
  196. end
  197. local a = tonumber(swidget.element.attr.a) or 0
  198. local anchorPoint = TxtTranslator.getAnchorByIndex(a)
  199. content = string.format("GUI:setAnchorPoint(%s, %.2f, %.2f)", name, anchorPoint.x, anchorPoint.y)
  200. return content
  201. end
  202. TxtTranslator.fixPosition = function(swidget)
  203. local defaultX = (swidget.element.type == "Text" or swidget.element.type == "RText") and defaultTextX or 0
  204. local defaultY = (swidget.element.type == "Text" or swidget.element.type == "RText") and defaultTextY or 0
  205. local x = tonumber(swidget.element.attr.x) or defaultX
  206. local y = tonumber(swidget.element.attr.y) or defaultY
  207. local percentx = nil
  208. local percenty = nil
  209. if tonumber(swidget.element.attr.bg) == 1 and tonumber(swidget.element.attr.show) == 5 or tonumber(swidget.element.attr.show) == 6 then
  210. percentx = tonumber(swidget.element.attr.tpercentx)
  211. percenty = tonumber(swidget.element.attr.tpercenty)
  212. else
  213. percentx = tonumber(swidget.element.attr.percentx)
  214. percenty = tonumber(swidget.element.attr.percenty)
  215. end
  216. local name = swidget.realname or swidget.name
  217. local content = string.format("%s%s%s",
  218. sformat("local parent = GUI:getParent(%s)", name),
  219. lineS,
  220. "local parentSize = GUI:getContentSize(parent)"
  221. )
  222. if percentx then
  223. content = sformat("%s%s%s", content, lineS,
  224. sformat("local x = parentSize.width * (%s / 100)", percentx))
  225. else
  226. content = sformat("%s%s%s", content, lineS, sformat("local x = %s", x))
  227. end
  228. if percenty then
  229. content = sformat("%s%s%s", content, lineS,
  230. sformat("local y = parentSize.height - parentSize.height * (%s / 100)", percenty))
  231. else
  232. content = sformat("%s%s%s", content, lineS, sformat("local y = parentSize.height - %s", tranNegNum(y)))
  233. end
  234. content = sformat("%s%s%s", content, lineS, sformat("GUI:setPosition(%s, x, y)", name))
  235. return content
  236. end
  237. TxtTranslator.fixSize = function(swidget)
  238. local width = tonumber(swidget.element.attr.width)
  239. local height = tonumber(swidget.element.attr.height)
  240. local percentwidth = tonumber(swidget.element.attr.percentwidth)
  241. local percentheight = tonumber(swidget.element.attr.percentheight)
  242. local name = swidget.realname or swidget.name
  243. local content = ""
  244. if width or height or percentwidth or percentheight then
  245. content = sformat("local contentSize = GUI:getContentSize(%s)", name)
  246. if percentwidth or percentheight then
  247. content = string.format("%s%s%s%s%s",
  248. content,
  249. lineS,
  250. sformat("local parent = GUI:getParent(%s)", name),
  251. lineS,
  252. "local parentSize = GUI:getContentSize(parent)"
  253. )
  254. end
  255. if percentwidth then
  256. content = string.format("%s%s%s",
  257. content,
  258. lineS,
  259. sformat("local width = parentSize.width * (%s / 100)", percentwidth)
  260. )
  261. elseif width then
  262. content = string.format("%s%s%s", content, lineS, sformat("local width = %s", width))
  263. else
  264. content = string.format("%s%s%s", content, lineS, "local width = contentSize.width")
  265. end
  266. if percentheight then
  267. content = string.format("%s%s%s",
  268. content,
  269. lineS,
  270. sformat("local height = parentSize.height * (%s / 100)", percentheight)
  271. )
  272. elseif height then
  273. content = string.format("%s%s%s", content, lineS, sformat("local height = %s", height))
  274. else
  275. content = string.format("%s%s%s", content, lineS, "local height = contentSize.height")
  276. end
  277. content = string.format("%s%s%s", content, lineS, sformat("GUI:setContentSize(%s, width, height)", name))
  278. end
  279. return content
  280. end
  281. TxtTranslator.fixRotate = function(swidget)
  282. local rotate = tonumber(swidget.element.attr.rotate) or 0
  283. return rotate
  284. end
  285. TxtTranslator.fixVisible = function(swidget)
  286. -- 默认0可见 1不可见
  287. local visible = tonumber(swidget.element.attr.visible) or 0
  288. return visible == 0
  289. end
  290. -- load attr
  291. TxtTranslator.loadSWidgetAttr = function(swidget)
  292. local render = swidget.render
  293. local element = swidget.element
  294. local name = swidget.realname or swidget.name
  295. -- size
  296. local content = ""
  297. local function checkNeedLineS(content)
  298. if content and string.len(content) > 0 then
  299. return lineS
  300. end
  301. return ""
  302. end
  303. if TxtTranslator.modifySizeAble(swidget) and not swidget._setSized then
  304. local sizeStr = TxtTranslator.fixSize(swidget)
  305. content = string.format("%s%s%s", content, checkNeedLineS(content), sizeStr)
  306. end
  307. -- anchor
  308. if TxtTranslator.modifyAnchorAble(swidget) then
  309. local anchorStr = TxtTranslator.fixAnchor(swidget)
  310. content = string.format("%s%s%s", content, checkNeedLineS(content), anchorStr)
  311. end
  312. -- rotate
  313. if TxtTranslator.modifyRotateAble(swidget) then
  314. local rotate = TxtTranslator.fixRotate(swidget)
  315. content = string.format("%s%s%s", content, checkNeedLineS(content), sformat("GUI:setRotation(%s, %s)", name, rotate))
  316. end
  317. -- x y
  318. content = string.format("%s%s%s", content, checkNeedLineS(content), TxtTranslator.fixPosition(swidget))
  319. if TxtTranslator.modifyVisible(swidget) then
  320. local visible = TxtTranslator.fixVisible(swidget)
  321. content = string.format("%s%s%s", content, checkNeedLineS(content), sformat("GUI:setVisible(%s, %s)", name, tostring(visible)))
  322. end
  323. return content
  324. end
  325. ------------------------------------------
  326. --- init
  327. function TxtTranslator:ctor()
  328. defaultOutline = SL:GetMetaValue("GAME_DATA", "defaultOutlineSize") or 0
  329. defaultOutlineC = SL:GetMetaValue("GAME_DATA", "defaultOutlineColor") or 0
  330. end
  331. ------------------------------------------------------------------
  332. -- load
  333. function TxtTranslator:load(source, callback, closeCB, ext)
  334. local clock = os.clock()
  335. -- parse
  336. local elements = LexicalHelper:Parse(source)
  337. -- fix background
  338. self:fixBackground(elements, ext)
  339. -- content
  340. local visibleSize = global.Director:getVisibleSize()
  341. local _, rootRect = checkNotchPhone()
  342. rootRect.width = visibleSize.width
  343. rootRect.height = visibleSize.height
  344. local content = self:loadContent(elements, callback, closeCB, rootRect, ext)
  345. --
  346. print("load cost", os.clock() - clock)
  347. return content
  348. end
  349. function TxtTranslator:fixBackground(elements, ext)
  350. -- 优先级 脚本中设置过bg字段 -> GM指定大背景框 -> 默认背景框
  351. -- find background
  352. local background = nil
  353. for k, v in ipairs(elements) do
  354. if v.attr["bg"] == "1" then
  355. if not background then
  356. background = v
  357. else
  358. v.attr["bg"] = nil
  359. end
  360. end
  361. end
  362. if nil == background then
  363. if ext and ext.background then
  364. -- GM指定大背景框
  365. -- OPENMERCHANTBIGDLG 路径 显示位置 X坐标 Y坐标 高度 宽度 是否显示关闭按钮 关闭按钮X坐标 关闭按钮Y坐标 固定NPC对话框
  366. if ext.background.Param7 and tonumber(ext.background.Param7) == 1 then
  367. local element = {}
  368. element.type = "Button"
  369. element.attr = {}
  370. element.attr.nimg = "public/1900000510.png"
  371. element.attr.pimg = "public/1900000511.png"
  372. element.attr.link = "@exit"
  373. element.attr.x = tonumber(ext.background.Param8)
  374. element.attr.y = tonumber(ext.background.Param9)
  375. table.insert(elements, 1, element)
  376. end
  377. local element = {}
  378. element.type = "Img"
  379. element.attr = {}
  380. element.attr.img = ext.background.Param1
  381. element.attr.bg = 1
  382. element.attr.move = tonumber(ext.background.Param10) and 1 or 0
  383. element.attr.reset = 1
  384. element.attr.show = tonumber(ext.background.Param2)
  385. element.attr.x = tonumber(ext.background.Param3)
  386. element.attr.y = tonumber(ext.background.Param4)
  387. element.attr.height = tonumber(ext.background.Param5) ~= 0 and tonumber(ext.background.Param5) or nil
  388. element.attr.width = tonumber(ext.background.Param6) ~= 0 and tonumber(ext.background.Param6) or nil
  389. element.attr.loadDelay = 1
  390. table.insert(elements, 1, element)
  391. else
  392. -- 默认背景框
  393. local element = {}
  394. element.type = "Button"
  395. element.attr = {}
  396. element.attr.nimg = "public/1900000510.png"
  397. element.attr.pimg = "public/1900000511.png"
  398. element.attr.link = "@exit"
  399. element.attr.x = 546
  400. element.attr.y = 0
  401. table.insert(elements, 1, element)
  402. local element = {}
  403. element.type = "Layout"
  404. element.attr = {}
  405. element.attr.width = 80
  406. element.attr.height = 80
  407. element.attr.x = 545
  408. element.attr.y = 0
  409. element.attr.link = "@exit"
  410. table.insert(elements, 1, element)
  411. local element = {}
  412. element.type = "Img"
  413. element.attr = {}
  414. element.attr.img = "public/bg_npc_01.png"
  415. element.attr.bg = 1
  416. element.attr.move = 0
  417. element.attr.reset = 1
  418. element.attr.show = 0
  419. element.attr.loadDelay = 1
  420. table.insert(elements, 1, element)
  421. end
  422. end
  423. return background
  424. end
  425. function TxtTranslator:loadContent(elements, callback, closeCB, rootRect, ext)
  426. self._loaders =
  427. {
  428. ["Img"] = handler(self, self.load_render_Img),
  429. ["Text"] = handler(self, self.load_render_Text),
  430. ["RText"] = handler(self, self.load_render_RText),
  431. ["Input"] = handler(self, self.load_render_Input),
  432. ["Button"] = handler(self, self.load_render_Button),
  433. ["Effect"] = handler(self, self.load_render_Effect),
  434. ["Frames"] = handler(self, self.load_render_Frames),
  435. ["Layout"] = handler(self, self.load_render_Layout),
  436. ["CheckBox"] = handler(self, self.load_render_CheckBox),
  437. ["ListView"] = handler(self, self.load_render_ListView),
  438. ["ItemShow"] = handler(self, self.load_render_ItemShow),
  439. ["COUNTDOWN"] = handler(self, self.load_render_COUNTDOWN),
  440. ["ITEMBOX"] = handler(self, self.load_render_ITEMBOX),
  441. ["EquipShow"] = handler(self, self.load_render_EquipShow),
  442. -- ["BAGITEMS"] = handler(self, self.load_render_BAGITEMS),
  443. -- ["EQUIPITEMS"] = handler(self, self.load_render_EQUIPITEMS),
  444. ["DBItemShow"] = handler(self, self.load_render_DBItemShow),
  445. ["TIMETIPS"] = handler(self, self.load_render_TIMETIPS),
  446. ["TextAtlas"] = handler(self, self.load_render_TextAtlas),
  447. ["LoadingBar"] = handler(self, self.load_render_LoadingBar),
  448. ["CircleBar"] = handler(self, self.load_render_CircleBar),
  449. ["PercentImg"] = handler(self, self.load_render_PercentImg),
  450. ["UIModel"] = handler(self, self.load_render_UIModel),
  451. ["HEROEquipShow"] = handler(self, self.load_render_HEROEquipShow),
  452. -- ["HEROEQUIPITEMS"] = handler(self, self.load_render_HEROEQUIPITEMS),
  453. ["HERODBItemShow"] = handler(self, self.load_render_HERODBItemShow),
  454. -- ["HEROBAGITEMS"] = handler(self, self.load_render_HEROBAGITEMS),
  455. ["RTextX"] = handler(self, self.load_render_RTextX),
  456. ["PageView"] = handler(self, self.load_render_PageView),
  457. ["Slider"] = handler(self, self.load_render_Slider),
  458. ["ScrapePic"] = handler(self, self.load_render_ScrapePic),
  459. ["BmpText"] = handler(self, self.load_render_BmpText),
  460. }
  461. --
  462. self._inputWidgets = {}
  463. self._checkboxWidgets = {}
  464. -- 对比上次,差异化更改
  465. local lastTrunk = ext and ext.lastTrunk or nil
  466. local lastBackground = ext and ext.lastBackground or nil
  467. local loadCompleteCB = ext and ext.loadCompleteCB or nil
  468. local isImmediate = ext and ext.isImmediate or false
  469. local parentNode = ext and ext.parentNode or nil
  470. -- load swidgets
  471. local background = nil
  472. local swidgets = {}
  473. for i, element in ipairs(elements) do
  474. -- exist loader
  475. if self._loaders[element.type] then
  476. element.attr.id = element.attr.id or string.format("default_%s", i)
  477. element.attr.x = (element.type == "Text" or element.type == "RText" or element.type == "RTextX" or element.type == "BmpText") and (element.attr.x or defaultTextX) or element.attr.x
  478. element.attr.y = (element.type == "Text" or element.type == "RText" or element.type == "RTextX" or element.type == "BmpText") and (element.attr.y or defaultTextY) or element.attr.y
  479. -- swidget
  480. local swidget = TWidget.new()
  481. swidget.element = element
  482. swidget.render = nil
  483. swidget.name = string.format("%s_%s", element.type, element.attr.id or i)
  484. swidget.id = element.attr.id
  485. swidgets[element.attr.id] = swidget
  486. -- 记录背景图
  487. local isBG = tonumber(element.attr.bg) == 1
  488. if isBG and not background then
  489. background = swidget
  490. end
  491. end
  492. end
  493. -- tree mode
  494. for _, element in ipairs(elements) do
  495. if swidgets[element.attr.id] and swidgets[element.attr.id].element.attr.children then
  496. local swidget = swidgets[element.attr.id]
  497. local branches = swidget.element.attr.children
  498. local find_info = {sfind(branches, "{(.-)}")}
  499. local slices = ssplit(find_info[3] or branches, ",")
  500. if #slices > 0 then
  501. for _, branchID in ipairs(slices) do
  502. local branch = swidgets[branchID]
  503. if branch and not branch.render and branch.element.attr.id ~= swidget.element.attr.id then
  504. if branch.trunk then
  505. print("ERROR TxtTranslator: swidget can't be add aegin. swidgetID=" .. element.attr.id .. " branchID=" .. branchID)
  506. else
  507. swidget:addBranch(branch)
  508. end
  509. end
  510. end
  511. end
  512. end
  513. end
  514. -- trunk
  515. local trunk = TWidget.new()
  516. trunk.element = Element.new("Layout")
  517. trunk.depth = 0
  518. trunk.name = "Layout_1"
  519. trunk.id = "Layout_1"
  520. for _, element in ipairs(elements) do
  521. local swidget = swidgets[element.attr.id]
  522. if swidget and swidget.trunk == nil then
  523. trunk:addBranch(swidget)
  524. end
  525. end
  526. self._content = ""
  527. local winPositions = {[0] = {x = rootRect.x, y = rootRect.height}, [1] = {x = rootRect.width, y = rootRect.height},
  528. [2] = {x = rootRect.x, y = 0}, [3] = {x = rootRect.width, y = 0}, [4] = {x = rootRect.width / 2, y = rootRect.height / 2}}
  529. -- load trunk render
  530. if trunk and not trunk.render then
  531. local root_show = background and tonumber(background.element.attr.show) or 0
  532. local extParam = {pos = winPositions[root_show]}
  533. self._content = tabS .. self:load_render(trunk, callback, closeCB, extParam)
  534. end
  535. ---
  536. -- load background render
  537. local backRender = nil
  538. if background and not background.render then
  539. local extParam = {parent = trunk and trunk.name}
  540. self._content = sformat("%s%s%s", self._content, "\n" .. lineS, self:load_render(background, callback, closeCB, extParam))
  541. backRender = true
  542. end
  543. -- size
  544. if background and backRender and TxtTranslator.modifySizeAble(background) then
  545. local content = TxtTranslator.fixSize(background)
  546. if content and string.len(content) > 0 then
  547. self._content = sformat("%s%s%s", self._content, lineS, content)
  548. end
  549. background._setSized = true
  550. end
  551. local root_anchor = cc.p(0, 0)
  552. local root_position = cc.p(rootRect.x, 0)
  553. local root_size = cc.size(rootRect.width, rootRect.height)
  554. if background then
  555. local name = background.name
  556. local root_show = tonumber(background.element.attr.show) or 0
  557. if root_show == 0 then
  558. -- 左上
  559. root_anchor = cc.p(0, 1)
  560. root_position = cc.p(rootRect.x, rootRect.height)
  561. self._content = sformat("%s%s%s", self._content, lineS, sformat("local root_size = GUI:getContentSize(%s)", name))
  562. elseif root_show == 1 then
  563. -- 右上
  564. root_anchor = cc.p(1, 1)
  565. root_position = cc.p(rootRect.width, rootRect.height)
  566. self._content = sformat("%s%s%s", self._content, lineS, sformat("local root_size = GUI:getContentSize(%s)", name))
  567. elseif root_show == 2 then
  568. -- 左下
  569. root_anchor = cc.p(0, 0)
  570. root_position = cc.p(rootRect.x, 0)
  571. self._content = sformat("%s%s%s", self._content, lineS, sformat("local root_size = GUI:getContentSize(%s)", name))
  572. elseif root_show == 3 then
  573. -- 右下
  574. root_anchor = cc.p(1, 0)
  575. root_position = cc.p(rootRect.width, 0)
  576. self._content = sformat("%s%s%s", self._content, lineS, sformat("local root_size = GUI:getContentSize(%s)", name))
  577. elseif root_show == 4 then
  578. -- 中间
  579. root_anchor = cc.p(0.5, 0.5)
  580. root_position = cc.p(mfloor(rootRect.width / 2), mfloor(rootRect.height / 2))
  581. self._content = sformat("%s%s%s", self._content, lineS, sformat("local root_size = GUI:getContentSize(%s)", name))
  582. elseif root_show == 5 or root_show == 6 then
  583. -- 中间铺满
  584. local attr = background.element.attr
  585. if attr.width or attr.height then
  586. self._content = sformat("%s%s%s", self._content, lineS, sformat("local root_size = GUI:getContentSize(%s)", name))
  587. else
  588. self._content = sformat("%s%s%s", self._content, lineS, sformat("local root_size = {width = %s, height = %s}", root_size.width. root_size.height))
  589. end
  590. root_anchor = cc.p(0.5, 0.5)
  591. root_position = cc.p(mfloor(rootRect.width / 2), mfloor(rootRect.height / 2))
  592. background.element.attr.tax = 0.5
  593. background.element.attr.tay = 0.5
  594. background.element.attr.tpercentx = 50
  595. background.element.attr.tpercenty = 50
  596. elseif root_show == 7 then
  597. -- 上下居中
  598. root_anchor.y = 0.5
  599. root_position.y = mfloor(rootRect.height / 2)
  600. self._content = sformat("%s%s%s", self._content, lineS, sformat("local root_size = GUI:getContentSize(%s)", name))
  601. elseif root_show == 8 then
  602. -- 左右居中
  603. root_anchor.x = 0.5
  604. root_position.x = mfloor(rootRect.width / 2)
  605. self._content = sformat("%s%s%s", self._content, lineS, sformat("local root_size = GUI:getContentSize(%s)", name))
  606. end
  607. end
  608. local show = background and tonumber(background.element.attr.show) or 0
  609. if show == 5 or show == 6 then
  610. show = 4
  611. end
  612. local anchorPoint = anchorPoints[show] or anchorPoints[4]
  613. local position = winPositions[show] or cc.p(0, 0)
  614. if trunk.name then
  615. self._content = sformat("%s%s%s%s%s%s%s%s%s",
  616. self._content,
  617. lineS,
  618. sformat("GUI:setContentSize(%s, root_size)", trunk.name),
  619. lineS,
  620. sformat("GUI:setAnchorPoint(%s, %.2f, %.2f)", trunk.name, anchorPoint.x, anchorPoint.y),
  621. lineS,
  622. sformat("GUI:setPosition(%s, %s, %s)", trunk.name, position.x, position.y),
  623. lineS,
  624. sformat("GUI:stopAllActions(%s)", trunk.name)
  625. )
  626. end
  627. -- load background attr
  628. if background and background.name then
  629. self._content = sformat("%s%s%s", self._content, lineS, TxtTranslator.loadSWidgetAttr(background))
  630. end
  631. ---------------------------------------
  632. -- load renders
  633. local function loadBranchRenders(loadTrunk)
  634. if #loadTrunk.branches == 0 then
  635. return nil
  636. end
  637. for _, branch in ipairs(loadTrunk.branches) do
  638. if not branch.content then
  639. local extParam = {parent = loadTrunk.name}
  640. local content = self:load_render(branch, callback, closeCB, extParam)
  641. if content then
  642. branch.content = content
  643. -- load show attr
  644. content = sformat("%s%s%s", content, lineS, TxtTranslator.loadSWidgetAttr(branch))
  645. if loadTrunk.element.type == "ListView" then
  646. if loadTrunk.element.attr.default and tonumber(loadTrunk.element.attr.default) then
  647. local default = tonumber(loadTrunk.element.attr.default) - 1
  648. local index = math.max(default, 0)
  649. end
  650. end
  651. self._content = sformat("%s%s%s", self._content, "\n" .. lineS, content)
  652. end
  653. end
  654. end
  655. end
  656. -- load immediate flag, edit form background
  657. local loadCount = 1
  658. local loadStep = 50
  659. isImmediate = true
  660. if isImmediate then
  661. local function loadBranch(loadTrunk)
  662. if #loadTrunk.branches > 0 then
  663. loadBranchRenders(loadTrunk)
  664. for _, branch in ipairs(loadTrunk.branches) do
  665. loadBranch(branch)
  666. end
  667. end
  668. end
  669. loadBranch(trunk)
  670. -- 装载完成
  671. if loadCompleteCB then
  672. loadCompleteCB()
  673. end
  674. end
  675. return self._content
  676. end
  677. function TxtTranslator:load_action(source)
  678. if not source then
  679. return nil
  680. end
  681. local find_info = {sfind(source, "{(.+)}")}
  682. if not (find_info[1] and find_info[2] and string.len(find_info[3]) > 0) then
  683. return nil
  684. end
  685. local actions = {}
  686. local slices = ssplit(find_info[3], ";")
  687. for _, slice in ipairs(slices) do
  688. local slice_info = {sfind(slice, "(.+):(.+)")}
  689. local action_type = tonumber(slice_info[3])
  690. local params = ssplit(slice_info[4], "#")
  691. if action_type == 1 then
  692. table.insert(actions, cc.ScaleTo:create(tonumber(params[1]), tonumber(params[2]), tonumber(params[2])))
  693. elseif action_type == 2 then
  694. table.insert(actions, cc.FadeTo:create(tonumber(params[1]), tonumber(params[2])))
  695. end
  696. end
  697. if not next(actions) then
  698. return nil
  699. end
  700. return cc.Sequence:create(actions)
  701. end
  702. function TxtTranslator:reload_render(swidget)
  703. local element = swidget.element
  704. if element.type == "ListView" then
  705. local default = tonumber(element.attr.default)
  706. if default and swidget.render then
  707. -- default
  708. local function callback()
  709. local index = math.max(default - 1, 0)
  710. swidget.render:jumpToItem(index, cc.p(0, 0), cc.p(0, 0))
  711. swidget.render:doLayout()
  712. end
  713. performWithDelay(swidget.render, callback, 1/60)
  714. end
  715. end
  716. end
  717. function TxtTranslator:load_render(swidget, callback, closeCB, ext)
  718. local element = swidget.element
  719. local loader = self._loaders[element.type]
  720. if nil == loader then
  721. print("load render error")
  722. return nil
  723. end
  724. local content = loader(swidget, callback, closeCB, ext)
  725. local prefix = sformat("-- Create SUI %s", element.type)
  726. swidget.content = sformat("%s%s%s", prefix, lineS, content)
  727. return swidget.content
  728. end
  729. function TxtTranslator:load_render_Layout(swidget, callback, closeCB, ext)
  730. local element = swidget.element
  731. local width = tonumber(element.attr.width) or 1
  732. local height = tonumber(element.attr.height) or 1
  733. local color = tonumber(element.attr.color)
  734. local link = element.attr.link
  735. local submitInput = element.attr.submitInput
  736. local submitCheckBox = element.attr.submitCheckBox
  737. local x = tonumber(element.attr.x) or 0
  738. local y = tonumber(element.attr.y) or 0
  739. local name = swidget.name
  740. local id = swidget.id
  741. local parent = ext and ext.parent
  742. local content = ""
  743. if not parent then
  744. content = sformat([[local win = GUI:Win_Create("win")]])
  745. content = sformat("%s%s%s", content, lineS,
  746. sformat([[local %s = GUI:Layout_Create(win, "%s", %s, %s, %s, %s)]], name, id, x, y, width, height))
  747. else
  748. content = sformat([[local %s = GUI:Layout_Create(%s, "%s", %s, %s, %s, %s)]], name, parent, id, x, y, width, height)
  749. end
  750. -- color
  751. if color then
  752. content = sformat("%s%s%s%s%s%s%s", content, lineS,
  753. sformat("GUI:Layout_setBackGroundColor(%s, \"%s\")", name, GET_COLOR_BYID(color)),
  754. lineS,
  755. sformat("GUI:Layout_setBackGroundColorType(%s, 1)", name),
  756. lineS,
  757. sformat("GUI:Layout_setBackGroundColorOpacity(%s, 255)", name))
  758. end
  759. -- link
  760. if link and string.len(link) > 0 then
  761. content = sformat("%s%s%s%s%s", content, lineS,
  762. sformat("GUI:setTouchEnabled(%s, true)", name),
  763. lineS,
  764. sformat("GUI:addOnClickEvent(%s, function()%s-- %s%send)", name, lineS, link, lineS)
  765. )
  766. end
  767. return content
  768. end
  769. function TxtTranslator:load_render_Text(swidget, callback, closeCB, ext)
  770. local element = swidget.element
  771. local text = element.attr.text or ""
  772. local size = tonumber(element.attr.size) or defaultFontSize
  773. local color = element.attr.color or defaultColorID
  774. local link = element.attr.link
  775. local width = tonumber(element.attr.width)
  776. local outline = tonumber(element.attr.outline) or defaultOutline
  777. local outlinecolor = tonumber(element.attr.outlinecolor) or defaultOutlineC
  778. local scrollWidth = tonumber(element.attr.scrollWidth)
  779. local submitInput = element.attr.submitInput
  780. local submitCheckBox = element.attr.submitCheckBox
  781. local auto = tonumber(element.attr.auto)
  782. local platform = tonumber(element.attr.platform)
  783. local clickInterval = (tonumber(element.attr.clickInterval) or 0) * 0.001
  784. local tips = element.attr.tips
  785. local tipsx = tonumber(element.attr.tipsx) or 0
  786. local tipsy = tonumber(element.attr.tipsy) or 0
  787. local tipWidth = tonumber(element.attr.tipWidth) or 1136
  788. local simplenum = tonumber(element.attr.simplenum) or 0
  789. local scrollWay = tonumber(element.attr.scrollWay) or 0 -- 0 从右到左 1 从下到上
  790. local scrollTime = tonumber(element.attr.scrollTime) or 4
  791. local scrollHeight = tonumber(element.attr.scrollHeight)
  792. local thouFormat = tonumber(element.attr.thouFormat) or 0
  793. local x = tonumber(element.attr.x) or 0
  794. local y = tonumber(element.attr.y) or 0
  795. local hexColor = element.attr.hexcolor
  796. local needLine = false
  797. if string.find(text, "\\") then
  798. needLine = true
  799. end
  800. text = string.gsub(text, "\\", "\r\n")
  801. text = string.trim(text)
  802. local showText = needLine and ("[[" .. text .. "]]") or sformat("\"%s\"", text)
  803. --
  804. local colorTable = {}
  805. if tonumber(color) then
  806. table.insert(colorTable, tonumber(color))
  807. else
  808. local slices = ssplit(color, ",")
  809. for _, v in ipairs(slices) do
  810. table.insert(colorTable, tonumber(v))
  811. end
  812. end
  813. --
  814. local useHex = false
  815. local hexColorTable = {}
  816. if hexColor then
  817. local slices = ssplit(hexColor, ",")
  818. for _, v in ipairs(slices) do
  819. if string.len(v) > 0 and string.find(v, "#") then
  820. table.insert(hexColorTable, v)
  821. end
  822. end
  823. if #hexColorTable > 0 then
  824. useHex = true
  825. end
  826. end
  827. local colorHex = useHex and hexColorTable[1] or GET_COLOR_BYID(colorTable[1])
  828. local name = swidget.name
  829. local id = swidget.id
  830. local parent = ext and ext.parent or noParentCode
  831. local content = ""
  832. if scrollWidth then
  833. swidget.realname = "scrollLayout_" .. id
  834. content = sformat("%s%s%s", sformat("local %s = GUI:Layout_Create(%s, \"%s\", %s, %s, %s, 0, true)", swidget.realname, parent, id, x, y, scrollWidth),
  835. lineS,
  836. sformat("local %s = GUI:Text_Create(%s, \"%s\", 0, 0, %s, \"%s\", %s)",
  837. name, swidget.realname, id, size, colorHex, showText)
  838. )
  839. -- size
  840. content = sformat("%s%s%s", content, lineS, sformat("local widgetSize = GUI:getContentSize(%s)", name))
  841. if scrollHeight then
  842. content = sformat("%s%s%s", content, lineS, sformat("local scrollH = %s", scrollHeight))
  843. else
  844. content = sformat("%s%s%s", content, lineS, "local scrollH = widgetSize.height")
  845. end
  846. content = sformat("%s%s%s", content, lineS, sformat("GUI:setContentSize(%s, %s, scrollH)", swidget.realname, scrollWidth))
  847. content = sformat("%s%s%s", content, lineS, sformat("GUI:setAnchorPoint(%s, 0.00, 0.00)", name))
  848. else
  849. content = sformat("local %s = GUI:Text_Create(%s, \"%s\", %s, %s, %s, \"%s\", %s)", name, parent, id, x, y, size, colorHex, showText)
  850. end
  851. if outline > 0 then
  852. content = sformat("%s%s%s", content, lineS, sformat("GUI:Text_enableOutline(%s, \"%s\", %s)", name, GET_COLOR_BYID(outlinecolor), outline))
  853. end
  854. -- width
  855. if width then
  856. content = sformat("%s%s%s", content, lineS, sformat("GUI:Text_setMaxLineWidth(%s, %s)", name, width))
  857. end
  858. -- link
  859. if link and string.len(link) > 0 or (tips and string.len(tips) > 0) then
  860. -- 下划线
  861. content = sformat("%s%s%s", content, lineS, sformat("GUI:Text_enableUnderline(%s)", name))
  862. if link then
  863. content = sformat("%s%s%s%s%s", content, lineS,
  864. sformat("GUI:setTouchEnabled(%s, true)", name),
  865. lineS,
  866. sformat("GUI:addOnClickEvent(%s, function()%s-- %s%send)", name, lineS, link, lineS)
  867. )
  868. end
  869. end
  870. -- auto color
  871. local tbl = useHex and hexColorTable or colorTable
  872. if #tbl > 1 then
  873. content = sformat("%s%s%s", content, lineS, replace([[local index = 1
  874. ${t}local colorTable = ${colorTable}
  875. ${t}local function callback()
  876. ${t}${t}index = index + 1
  877. ${t}${t}if index > #colorTable then
  878. ${t}${t}${t}index = 1
  879. ${t}${t}end
  880. ${t}${t}local color = colorTable[index]
  881. ${t}${t}if tonumber(colorTable[index]) then
  882. ${t}${t}${t}color = SL:GetHexColorByStyleId(tonumber(colorTable[index]))
  883. ${t}${t}end
  884. ${t}${t}GUI:Text_setTextColor(${name}, color)
  885. ${t}end
  886. ${t}SL:schedule(${name}, callback, 1)]], {colorTable = tbl, name = name, t = tabS})
  887. )
  888. end
  889. -- auto scroll
  890. if scrollWidth then
  891. if scrollWay == 0 then
  892. content = sformat("%s%s%s", content, lineS,
  893. [[GUI:setAnchorPoint(${name}, 0.00, 0.00)
  894. ${t}GUI:setPosition(${name}, 0, 0)
  895. ${t}GUI:runAction(${name}, GUI:ActionRepeatForever(GUI:ActionSequence(
  896. ${t}${t}GUI:ActionMoveBy(${scrollTime}, - widgetSize.width, 0),
  897. ${t}${t}GUI:ActionMoveBy(0, widgetSize.width, 0))))]])
  898. elseif scrollWay == 1 then
  899. content = sformat("%s%s%s", content, lineS,
  900. [[GUI:setAnchorPoint(${name}, 0.00, 1.00)
  901. ${t}GUI:setPosition(${name}, 0, scrollH)
  902. ${t}GUI:runAction(${name}, GUI:ActionRepeatForever(GUI:ActionSequence(
  903. ${t}${t}GUI:ActionMoveBy(${scrollTime}, 0, widgetSize.height),
  904. ${t}${t}GUI:ActionMoveBy(0, 0, - widgetSize.height))))]])
  905. end
  906. content = replace(content, {
  907. name = name, scrollTime = scrollTime, t = tabS
  908. })
  909. return content
  910. end
  911. if simplenum == 1 or thouFormat == 1 then
  912. content = sformat("%s%s%s", content, lineS, sformat("local str = GUI:Text_getString(%s)", name))
  913. if simplenum == 1 then
  914. content = sformat("%s%s%s", content, lineS, replace([[if str and tonumber(str) then
  915. ${t}${t}str = SL:GetSimpleNumber(tonumber(str))
  916. ${t}${t}GUI:Text_getString(${name}, str)
  917. ${t}end]], {name = name, t = tabS}))
  918. end
  919. if thouFormat == 1 then
  920. content = sformat("%s%s%s", content, lineS, replace([[if str and tonumber(str) then
  921. ${t}${t}str = SL:GetThousandSepString(tonumber(str))
  922. ${t}${t}GUI:Text_getString(${name}, str)
  923. ${t}end]], {name = name, t = tabS}))
  924. end
  925. end
  926. return content
  927. end
  928. function TxtTranslator:load_render_TextAtlas(swidget, callback, closeCB, ext)
  929. local element = swidget.element
  930. local img = element.attr.img or "public/word_tywz_01.png"
  931. local iwidth = tonumber(element.attr.iwidth) or 18
  932. local iheight = tonumber(element.attr.iheight) or 28
  933. local schar = element.attr.schar or "0"
  934. local text = element.attr.text or ""
  935. local x = tonumber(element.attr.x) or 0
  936. local y = tonumber(element.attr.y) or 0
  937. local img = SUIHelper.fixImageFileName(img)
  938. local fullPath = (img and img ~= "") and string.format(getResFullPath("res/%s"), img) or ""
  939. if not fullPath or fullPath == "" or not global.FileUtilCtl:isFileExist(fullPath) then
  940. img = SUIHelper.fixImageFileName("public/word_tywz_01.png")
  941. fullPath = string.format(getResFullPath("res/%s"), img)
  942. end
  943. local name = swidget.name
  944. local id = swidget.id
  945. local parent = ext and ext.parent or noParentCode
  946. local content = sformat("local %s = GUI:TextAtlas_Create(%s, \"%s\", %s, %s, \"%s\", \"%s\", %s, %s, \"%s\")",
  947. name, parent, id, x, y, text, fullPath, iwidth, iheight, schar)
  948. return content
  949. end
  950. function TxtTranslator:load_render_RText(swidget, callback, closeCB, ext)
  951. local element = swidget.element
  952. local text = element.attr.text or ""
  953. local size = tonumber(element.attr.size) or defaultFontSize
  954. local color = tonumber(element.attr.color) or defaultColorID
  955. local width = tonumber(element.attr.width) or 1136
  956. local link = element.attr.link
  957. local submitInput = element.attr.submitInput
  958. local submitCheckBox = element.attr.submitCheckBox
  959. local outline = tonumber(element.attr.outline) or defaultOutline
  960. local outlinecolor = tonumber(element.attr.outlinecolor) or defaultOutlineC
  961. local scrollWidth = tonumber(element.attr.scrollWidth)
  962. local scrollWay = tonumber(element.attr.scrollWay) or 0 -- 0 从右到左 1 从下到上
  963. local scrollTime = tonumber(element.attr.scrollTime) or 4
  964. local scrollHeight = tonumber(element.attr.scrollHeight)
  965. local x = tonumber(element.attr.x) or 0
  966. local y = tonumber(element.attr.y) or 0
  967. local colorHex = GET_COLOR_BYID(color)
  968. local vspace = SL:GetMetaValue("GAME_DATA", "DEFAULT_VSPACE")
  969. local outlineParam = {
  970. outlineSize = outline,
  971. outlineColor = GET_COLOR_BYID_C3B(outlinecolor)
  972. }
  973. -- text = string.gsub(text, "\\", "<br></br>")
  974. local needLine = false
  975. if string.find(text, "\\") then
  976. needLine = true
  977. end
  978. local showText = needLine and ("[[" .. text .. "]]") or sformat("\"%s\"", text)
  979. local name = swidget.name
  980. local id = swidget.id
  981. local parent = ext and ext.parent or noParentCode
  982. local content = ""
  983. if scrollWidth then
  984. swidget.realname = "scrollLayout_" .. id
  985. content = sformat("%s%s%s",
  986. sformat("local %s = GUI:Layout_Create(%s, \"%s\", %s, %s, %s, 0, true)", swidget.realname, parent, id, x, y, scrollWidth),
  987. lineS,
  988. replace(sformat("local %s = GUI:RichTextFCOLOR_Create(%s, \"%s\", 0, 0, %s, %s, %s, \"%s\", %s, nil, nil, ${outlineParam})",
  989. name, swidget.realname, id, showText, width, size, colorHex, vspace)
  990. , {outlineParam = outlineParam})
  991. )
  992. -- size
  993. content = sformat("%s%s%s", content, lineS, sformat("local widgetSize = GUI:getContentSize(%s)", name))
  994. if scrollHeight then
  995. content = sformat("%s%s%s", content, lineS, sformat("local scrollH = %s", scrollHeight))
  996. else
  997. content = sformat("%s%s%s", content, lineS, "local scrollH = widgetSize.height")
  998. end
  999. content = sformat("%s%s%s", content, lineS, sformat("GUI:setContentSize(%s, %s, scrollH)", swidget.realname, scrollWidth))
  1000. else
  1001. content = replace(sformat("local %s = GUI:RichTextFCOLOR_Create(%s, \"%s\", 0, 0, %s, %s, %s, \"%s\", %s, nil, nil, ${outlineParam})",
  1002. name, parent, id, showText, width, size, colorHex, vspace), {outlineParam = outlineParam})
  1003. end
  1004. -- auto scroll
  1005. if scrollWidth then
  1006. if scrollWay == 0 then
  1007. content = sformat("%s%s%s", content, lineS, [[GUI:setAnchorPoint(${name}, 0.00, 0.00)
  1008. ${t}GUI:setPosition(${name}, 0, 0)
  1009. ${t}GUI:runAction(${name}, GUI:ActionRepeatForever(GUI:ActionSequence(
  1010. ${t}${t}GUI:ActionMoveBy(${scrollTime}, - widgetSize.width, 0),
  1011. ${t}${t}GUI:ActionMoveBy(0, widgetSize.width, 0))))]])
  1012. elseif scrollWay == 1 then
  1013. content = sformat("%s%s%s", content, lineS, [[GUI:setAnchorPoint(${name}, 0.00, 1.00)
  1014. ${t}GUI:setPosition(${name}, 0, scrollH)
  1015. ${t}GUI:runAction(${name}, GUI:ActionRepeatForever(GUI:ActionSequence(
  1016. ${t}${t}GUI:ActionMoveBy(${scrollTime}, 0, widgetSize.height),
  1017. ${t}${t}GUI:ActionMoveBy(0, 0, - widgetSize.height))))]])
  1018. end
  1019. content = replace(content, {
  1020. name = name, scrollTime = scrollTime, t = tabS
  1021. })
  1022. return content
  1023. end
  1024. return content
  1025. end
  1026. function TxtTranslator:load_render_Img(swidget, callback, closeCB, ext)
  1027. local element = swidget.element
  1028. local bg = tonumber(element.attr.bg)
  1029. local img = element.attr.img or ""
  1030. local link = element.attr.link
  1031. local width = tonumber(element.attr.width)
  1032. local height = tonumber(element.attr.height)
  1033. local scale9l = tonumber(element.attr.scale9l)
  1034. local scale9r = tonumber(element.attr.scale9r)
  1035. local scale9t = tonumber(element.attr.scale9t)
  1036. local scale9b = tonumber(element.attr.scale9b)
  1037. local submitInput = element.attr.submitInput
  1038. local submitCheckBox = element.attr.submitCheckBox
  1039. local grey = tonumber(element.attr.grey) or 0
  1040. local flip = tonumber(element.attr.flip) or 0
  1041. local x = tonumber(element.attr.x) or 0
  1042. local y = tonumber(element.attr.y) or 0
  1043. local img = SUIHelper.fixImageFileName(img)
  1044. local fullPath = (img and img ~= "") and string.format(getResFullPath("res/%s"), img) or ""
  1045. local name = swidget.name
  1046. local id = swidget.id
  1047. local parent = ext and ext.parent or noParentCode
  1048. local content = sformat("local %s = GUI:Image_Create(%s, \"%s\", %s, %s, \"%s\")", name, parent, id, x, y, fullPath)
  1049. if scale9l and scale9r and scale9t and scale9b then
  1050. content = sformat("%s%s%s", content, lineS, sformat("GUI:Image_setScale9Slice(%s, %s, %s, %s, %s)", name, scale9l, scale9r, scale9t, scale9b))
  1051. end
  1052. if bg == 1 then
  1053. content = sformat("%s%s%s", content, lineS, "GUI:setTouchEnabled(${name}, true)")
  1054. if global.isWinPlayMode then
  1055. content = sformat("%s%s%s%s%s", content, lineS, "GUI:setMouseEnabled(${name}, true)", lineS, "GUI:addMouseMoveEvent(${name}, {})")
  1056. end
  1057. end
  1058. -- grey
  1059. if grey == 1 then
  1060. content = sformat("%s%s%s", content, lineS, "GUI:Img_SetGrey(${name}, true)")
  1061. end
  1062. if flip == 1 then
  1063. content = sformat("%s%s%s", content, lineS, "GUI:setFlippedX(${name}, true)")
  1064. elseif flip == 2 then
  1065. content = sformat("%s%s%s", content, lineS, "GUI:setFlippedY(${name}, true)")
  1066. end
  1067. return replace(content, {name = name})
  1068. end
  1069. function TxtTranslator:load_render_Button(swidget, callback, closeCB, ext)
  1070. local element = swidget.element
  1071. local nimg = element.attr.nimg
  1072. local pimg = element.attr.pimg
  1073. local mimg = element.attr.mimg
  1074. local text = element.attr.text or ""
  1075. local color = tonumber(element.attr.color) or defaultColorID
  1076. local size = tonumber(element.attr.size) or defaultFontSize
  1077. local width = tonumber(element.attr.width)
  1078. local height = tonumber(element.attr.height)
  1079. local link = element.attr.link
  1080. local submitInput = element.attr.submitInput
  1081. local submitCheckBox = element.attr.submitCheckBox
  1082. local tips = element.attr.tips
  1083. local tipsx = tonumber(element.attr.tipsx) or 0
  1084. local tipsy = tonumber(element.attr.tipsy) or 0
  1085. local textWidth = tonumber(element.attr.textwidth)
  1086. local grey = tonumber(element.attr.grey) or 0
  1087. local clickInterval = (tonumber(element.attr.clickInterval) or 0) * 0.001
  1088. local outline = tonumber(element.attr.outline) or defaultOutline
  1089. local outlinecolor = tonumber(element.attr.outlinecolor) or defaultOutlineC
  1090. local tipWidth = tonumber(element.attr.tipWidth) or 1136
  1091. local x = tonumber(element.attr.x) or 0
  1092. local y = tonumber(element.attr.y) or 0
  1093. text = string.gsub(text, "\\", "\r\n")
  1094. text = string.trim(text)
  1095. local nimg = SUIHelper.fixImageFileName(nimg)
  1096. local pimg = SUIHelper.fixImageFileName(pimg)
  1097. local mimg = SUIHelper.fixImageFileName(mimg)
  1098. local fullPathN = (nimg and string.len(nimg) > 0 and string.format(getResFullPath( "res/%s" ), nimg) or "")
  1099. local fullPathP = (pimg and string.len(pimg) > 0 and string.format(getResFullPath( "res/%s" ), pimg) or "")
  1100. local fullPathM = (mimg and string.len(mimg) > 0 and string.format(getResFullPath( "res/%s" ), mimg) or "")
  1101. local name = swidget.name
  1102. local id = swidget.id
  1103. local parent = ext and ext.parent or noParentCode
  1104. local content = replace([[local ${name} = GUI:Button_Create(${parent}, "${ID}", ${x}, ${y}, "${nimg}")
  1105. ${t}GUI:Button_setTitleText(${name}, "${text}")
  1106. ${t}GUI:Button_setTitleColor(${name}, "${color}")
  1107. ${t}GUI:Button_setTitleFontSize(${name}, ${size})]],
  1108. {name = name, text = text, color = GET_COLOR_BYID(color), size = size, parent = parent, ID = id, x = x, y = y, nimg = fullPathN, t = tabS})
  1109. if fullPathP ~= "" and global.FileUtilCtl:isFileExist(fullPathP) then
  1110. content = sformat("%s%s%s", content, lineS,
  1111. sformat("GUI:Button_loadTexturePressed(%s, \"%s\")", name, fullPathP))
  1112. end
  1113. if textWidth then
  1114. content = sformat("%s%s%s", content, lineS, replace([[GUI:Button_setMaxLineWidth(${name}, ${textWidth})]], {name = name, textWidth = textWidth}))
  1115. end
  1116. if outline > 0 then
  1117. content = sformat("%s%s%s", content, lineS,
  1118. sformat("GUI:Button_titleEnableOutline(%s, \"%s\", %s)", name, GET_COLOR_BYID(outlinecolor), outline))
  1119. end
  1120. -- grey
  1121. if grey == 1 then
  1122. content = sformat("%s%s%s", content, lineS, sformat("GUI:Button_SetGrey(%s, true)", name))
  1123. end
  1124. return content
  1125. end
  1126. function TxtTranslator:load_render_CheckBox(swidget, callback, closeCB, ext)
  1127. local element = swidget.element
  1128. local checkboxid = element.attr.checkboxid
  1129. local nimg = element.attr.nimg
  1130. local pimg = element.attr.pimg
  1131. local default = tonumber(element.attr.default) or 0
  1132. local submit = tonumber(element.attr.submit) or 0
  1133. local delay = math.max(tonumber(element.attr.delay) or 0, 1 / 60)
  1134. local count = tonumber(element.attr.count) or 0
  1135. local link = element.attr.link
  1136. local x = tonumber(element.attr.x) or 0
  1137. local y = tonumber(element.attr.y) or 0
  1138. local nimg = SUIHelper.fixImageFileName(nimg)
  1139. local pimg = SUIHelper.fixImageFileName(pimg)
  1140. local nimgPath = nimg and string.format(getResFullPath("res/%s"), nimg)
  1141. local pimgPath = pimg and string.format(getResFullPath("res/%s"), pimg)
  1142. local isSelected = default == 1
  1143. local name = swidget.name
  1144. local id = swidget.id
  1145. local parent = ext and ext.parent or noParentCode
  1146. local content = replace([[local ${name} = GUI:CheckBox_Create(${parent}, "${ID}", ${x}, ${y}, "${nimgPath}", "${pimgPath}")
  1147. ${t}GUI:CheckBox_setSelected(${name}, ${isSelected})
  1148. ${t}GUI:setTouchEnabled(${name}, true)]],
  1149. {name = name, parent = parent, ID = id, x = x, y = y, nimgPath = nimgPath, pimgPath = pimgPath, isSelected = isSelected, t = tabS})
  1150. return content
  1151. end
  1152. function TxtTranslator:load_render_ListView(swidget, callback, closeCB, ext)
  1153. local element = swidget.element
  1154. local width = element.attr.width or 200
  1155. local height = element.attr.height or 200
  1156. local color = tonumber(element.attr.color)
  1157. local direction = tonumber(element.attr.direction) or 1
  1158. local bounce = tonumber(element.attr.bounce) or 1
  1159. local margin = tonumber(element.attr.margin) or 0
  1160. local default = tonumber(element.attr.default)
  1161. local x = tonumber(element.attr.x) or 0
  1162. local y = tonumber(element.attr.y) or 0
  1163. local name = swidget.name
  1164. local id = swidget.id
  1165. local parent = ext and ext.parent or noParentCode
  1166. local content = sformat("local %s = GUI:ListView_Create(%s, \"%s\", %s, %s, %s, %s, %s)",
  1167. name, parent, id, x, y, width, height, direction)
  1168. content = sformat("%s%s%s", content, lineS, replace("GUI:ListView_setBounceEnabled(${name}, ${bounce})", {bounce = bounce == 1, name = name}))
  1169. if margin > 0 then
  1170. content = sformat("%s%s%s", content, lineS, sformat("GUI:ListView_setItemsMargin(%s, %s)", name, margin))
  1171. end
  1172. -- color
  1173. if color then
  1174. content = sformat("%s%s%s", content, lineS, replace([[GUI:ListView_setBackGroundColor(${name}, "${color}")
  1175. ${t}GUI:ListView_setBackGroundColorType(${name}, 1)
  1176. ${t}GUI:ListView_setBackGroundColorOpacity(${name}, 255)]], {name = name, color = GET_COLOR_BYID(color), t = tabS}))
  1177. end
  1178. -- default
  1179. if default then
  1180. content = sformat("%s%s%s", content, lineS, replace(
  1181. [[${t}local default = ${default}
  1182. ${t}local function callback()
  1183. ${t}${t}default = default - 1
  1184. ${t}${t}local index = math.max(default, 0)
  1185. ${t}${t}GUI:ListView_JumpToItem(${name}, index)
  1186. ${t}${t}GUI:ListView_doLayout(${name})
  1187. ${t}end
  1188. ${t}SL:scheduleOnce(${name}, callback, 1 / 60)]], {default = default, name = name, t = tabS}))
  1189. end
  1190. return content
  1191. end
  1192. function TxtTranslator:load_render_Effect(swidget, callback, closeCB, ext)
  1193. local element = swidget.element
  1194. local effecttype = tonumber(element.attr.effecttype) or 0
  1195. local effectid = tonumber(element.attr.effectid) or 9999
  1196. local sex = tonumber(element.attr.sex) or 0
  1197. local act = tonumber(element.attr.act) or 0
  1198. local dir = tonumber(element.attr.dir) or 5
  1199. local speed = tonumber(element.attr.speed) or 1
  1200. local scale = tonumber(element.attr.scale) or 1
  1201. local count = tonumber(element.attr.count) or 0
  1202. local link = element.attr.link
  1203. local x = tonumber(element.attr.x) or 0
  1204. local y = tonumber(element.attr.y) or 0
  1205. -- 0.普通特效 1.npc模型 2.怪物模型 3.技能特效 4.人物 5.武器 6.翅膀 7.发型
  1206. local name = swidget.name
  1207. local id = swidget.id
  1208. local parent = ext and ext.parent or noParentCode
  1209. local needScale = scale ~= 1
  1210. local needCount = count ~= 0
  1211. local content = [[local ${name} = GUI:Effect_Create(${parent}, "${ID}", ${x}, ${y}, ${effecttype}, ${effectid}, ${sex}, ${act}, ${dir}, ${speed})]]
  1212. if needScale or needCount then
  1213. content = sformat("%s%s%s", content, lineS, "if ${name} then")
  1214. if needScale then
  1215. content = sformat("%s%s%s", content, lineS, "${t}${name}:setScale(${scale})")
  1216. end
  1217. if needCount then
  1218. content = sformat("%s%s%s", content, lineS,
  1219. [[${t}local counting = 0
  1220. ${t}${t}GUI:Effect_addOnCompleteEvent(${name}, function()
  1221. ${t}${t}${t}counting = counting + 1
  1222. ${t}${t}${t}if counting == ${count} then
  1223. ${t}${t}${t}${t}GUI:Effect_Stop(${name})
  1224. ${t}${t}${t}${t}GUI:setVisible(${name}, false)
  1225. ${t}${t}${t}end
  1226. ${t}${t}end]])
  1227. end
  1228. content = sformat("%s%s%s", content, lineS, "end")
  1229. end
  1230. content = replace(content, {parent = parent, ID = id, x = x, y = y, name = name, effecttype = effecttype,
  1231. effectid = effectid, act = act, sex = sex, dir = dir, speed = speed, scale = scale, count = count})
  1232. return content
  1233. end
  1234. function TxtTranslator:load_render_Frames(swidget, callback, closeCB, ext)
  1235. local element = swidget.element
  1236. local prefix = element.attr.prefix or ""
  1237. local suffix = element.attr.suffix or ""
  1238. local speed = tonumber(element.attr.speed) or 100
  1239. local count = tonumber(element.attr.count) or 1
  1240. local loop = tonumber(element.attr.loop) or -1
  1241. local finishframe = tonumber(element.attr.finishframe) or "nil"
  1242. local finishhide = tonumber(element.attr.finishhide)
  1243. local link = element.attr.link
  1244. local submitInput = element.attr.submitInput
  1245. local submitCheckBox = element.attr.submitCheckBox
  1246. local x = tonumber(element.attr.x) or 0
  1247. local y = tonumber(element.attr.y) or 0
  1248. -- 逻辑差别
  1249. prefix = string.format(getResFullPath("res/%s"), prefix)
  1250. speed = speed * 10
  1251. count = count > 0 and count - 1 or count
  1252. local name = swidget.name
  1253. local id = swidget.id
  1254. local parent = ext and ext.parent or noParentCode
  1255. local content = replace([[local ${name} = GUI:Frames_Create(${parent}, "${ID}", ${x}, ${y}, "${prefix}", "${suffix}", 1, ${finishframe}, ${ext})]],
  1256. {name = name, parent = parent, ID = id, x = x, y = y, prefix = prefix, suffix = suffix, finishframe = finishframe,
  1257. ext = {speed = speed, count = count, loop = loop, finishhide = finishhide}})
  1258. return content
  1259. end
  1260. function TxtTranslator:load_render_Input(swidget, callback, closeCB, ext)
  1261. local element = swidget.element
  1262. local inputid = element.attr.inputid
  1263. local inputtype = tonumber(element.attr.type) or 0
  1264. local text = element.attr.text or ""
  1265. local place = element.attr.place
  1266. local placecolor = element.attr.placecolor or defaultColorID
  1267. local width = element.attr.width
  1268. local height = element.attr.height
  1269. local color = element.attr.color or defaultColorID
  1270. local size = element.attr.size or defaultFontSize
  1271. local mincount = element.attr.mincount
  1272. local maxcount = tonumber(element.attr.maxcount) or 10000
  1273. local errortips = element.attr.errortips
  1274. local submitInput = element.attr.submitInput
  1275. local submitCheckBox = element.attr.submitCheckBox
  1276. local linkType = tonumber(element.attr.linkType) or 1
  1277. local link = element.attr.link
  1278. local x = tonumber(element.attr.x) or 0
  1279. local y = tonumber(element.attr.y) or 0
  1280. local fontPath = global.MMO.PATH_FONT2
  1281. local name = swidget.name
  1282. local id = swidget.id
  1283. local parent = ext and ext.parent or noParentCode
  1284. local content = [[local ${name} = GUI:TextInput_Create(${parent}, "${ID}", ${x}, ${y}, ${width}, ${height}, ${size})
  1285. ${t}GUI:TextInput_setFontColor(${name}, "${fontColor}")
  1286. ${t}GUI:TextInput_setFont(${name}, "${fontPath}", ${size})
  1287. ${t}GUI:TextInput_setString(${name}, "${text}")]]
  1288. if place then
  1289. content = sformat("%s%s%s", content, lineS, [[GUI:TextInput_setPlaceHolder(${name}, "${place}")
  1290. ${t}GUI:TextInput_setPlaceholderFontColor(${name}, "${placeColor}")
  1291. ${t}GUI:TextInput_setPlaceholderFontSize(${name}, ${size})]])
  1292. end
  1293. content = sformat("%s%s%s", content, lineS, [[GUI:TextInput_setTextHorizontalAlignment(${name}, 0)
  1294. ${t}GUI:TextInput_setMaxLength(${name}, ${maxcount})]])
  1295. -- 输入类型
  1296. if inputtype == 1 then
  1297. content = sformat("%s%s%s", content, lineS, [[GUI:TextInput_setInputMode(${name}, 2)]])
  1298. elseif inputtype == 2 then
  1299. content = sformat("%s%s%s", content, lineS, [[GUI:TextInput_setInputMode(${name}, 0)]])
  1300. end
  1301. content = replace(content, {name = name, width = width, height = height, fontColor = GET_COLOR_BYID(tonumber(color)), fontPath = fontPath,
  1302. parent = parent, ID = id, x = x, y = y, size = tonumber(size), text = text, place = place or "",
  1303. placeColor = GET_COLOR_BYID(tonumber(placecolor)), maxcount = maxcount, t = tabS})
  1304. return content
  1305. end
  1306. function TxtTranslator:load_render_COUNTDOWN(swidget, callback, closeCB, ext)
  1307. local element = swidget.element
  1308. local time = tonumber(element.attr.time) or 10
  1309. local count = tonumber(element.attr.count) or 1
  1310. local color = tonumber(element.attr.color) or defaultColorID
  1311. local size = tonumber(element.attr.size) or defaultFontSize
  1312. local showWay = tonumber(element.attr.showWay) or 0
  1313. local link = element.attr.link
  1314. local x = tonumber(element.attr.x) or 0
  1315. local y = tonumber(element.attr.y) or 0
  1316. local showStr = showWay == 1 and TimeFormatToString(time) or sformat("%s秒", time)
  1317. local name = swidget.name
  1318. local id = swidget.id
  1319. local parent = ext and ext.parent or noParentCode
  1320. local content = replace([[local ${name} = GUI:Text_Create(${parent}, "${ID}", ${x}, ${y}, ${size}, "${color}", "${str}")]],
  1321. {name = name, size = size, color = GET_COLOR_BYID(color), str = showStr, parent = parent, ID = id, x = x, y = y})
  1322. content = sformat("%s%s%s", content, lineS, replace([[local counting = 0
  1323. ${t}local remaining = ${time}
  1324. ${t}local function callback()]], {t = tabS, time = time}))
  1325. if showWay == 1 then
  1326. content = sformat("%s%s%s", content, lineS, sformat("%sGUI:Text_setString(%s, SL:TimeFormatToStr(remaining))", tabS, name))
  1327. else
  1328. content = sformat("%s%s%s", content, lineS, sformat("%sGUI:Text_setString(%s, remaining .. \"秒\")", tabS, name))
  1329. end
  1330. content = sformat("%s%s%s", content, lineS, replace([[${t}remaining = remaining - 1
  1331. ${t}${t}if remaining < 0 then
  1332. ${t}${t}${t}counting = counting + 1
  1333. ${t}${t}${t}if counting >= ${count} then
  1334. ${t}${t}${t}${t}GUI:stopAllActions(${name})
  1335. ${t}${t}${t}end
  1336. ${t}${t}end
  1337. ${t}end
  1338. ${t}SL:schedule(${name}, callback, 1)
  1339. ${t}callback()]], {name = name, count = count, t = tabS}))
  1340. return content
  1341. end
  1342. function TxtTranslator:load_render_ItemShow(swidget, callback, closeCB, ext)
  1343. local element = swidget.element
  1344. local itemid = tonumber(element.attr.itemid) or 1
  1345. local itemcount = tonumber(element.attr.itemcount) or 1
  1346. local showtips = tonumber(element.attr.showtips) or 1
  1347. local bgtype = tonumber(element.attr.bgtype)
  1348. local scale = tonumber(element.attr.scale) or 1
  1349. local grey = tonumber(element.attr.grey) or 0
  1350. local lock = tonumber(element.attr.lock) or 0
  1351. local link = element.attr.link
  1352. local submitInput = element.attr.submitInput
  1353. local submitCheckBox = element.attr.submitCheckBox
  1354. local countColor = tonumber(element.attr.color) or defaultColorID
  1355. local effectshow = tonumber(element.attr.effectshow) or 1
  1356. local x = tonumber(element.attr.x) or 0
  1357. local y = tonumber(element.attr.y) or 0
  1358. local contentSize = cc.size(66, 66)
  1359. local name = swidget.name
  1360. local id = swidget.id
  1361. local parent = ext and ext.parent or noParentCode
  1362. local content = replace([[local ${name} = GUI:Widget_Create(${parent}, "${ID}", ${x}, ${y}, ${width}, ${height})]], {name = name, parent = parent, ID = id, x = x, y = y,
  1363. width = contentSize.width, height = contentSize.height})
  1364. local infoStr = [[local info = {}
  1365. ${t}info.index = ${itemid}
  1366. ${t}info.look = ${isShowtips}]]
  1367. if not (showtips == 1) and global.isWinPlayMode then
  1368. infoStr = sformat("%s%s%s", infoStr, lineS, "info.noMouseTips = true")
  1369. end
  1370. if effectshow == 2 then
  1371. infoStr = sformat("%s%s%s", infoStr, lineS, "info.showModelEffect = true")
  1372. elseif effectshow == 0 then
  1373. infoStr = sformat("%s%s%s", infoStr, lineS, "info.isShowEff = false")
  1374. end
  1375. infoStr = sformat("%s%s%s", infoStr, lineS, [[info.count = ${itemcount}
  1376. ${t}info.bgVisible = ${bgVisible}
  1377. ${t}info.color = ${countColor}
  1378. ${t}local item = GUI:ItemShow_Create(${name}, "${ID}", ${posX}, ${posY}, info)
  1379. ${t}GUI:setAnchorPoint(item, 0.50, 0.50)
  1380. ${t}GUI:setScale(item, ${scale})
  1381. ${t}GUI:ItemShow_setIconGrey(item, ${isGrey})]])
  1382. content = sformat("%s%s%s", content, lineS, replace(infoStr, {name = name, itemid = itemid, isShowtips = showtips == 1, itemcount = itemcount,
  1383. bgVisible = bgtype == 1, countColor = countColor, posX = contentSize.width / 2, posY = contentSize.height / 2,
  1384. scale = scale, isGrey = grey == 1, ID = id, t = tabS}))
  1385. if lock == 1 then
  1386. content = sformat("%s%s%s", content, lineS, replace([[local imageLock = GUI:Image_Create(${name}, "${ID}", 0, GUI:getContentSize(${name}).height, "${lockPath}")]], {name = name, lockPath = global.MMO.PATH_RES_PUBLIC .. "lock.png", ID = "lock_" .. id}))
  1387. content = sformat("%s%s%s", content, lineS, "GUI:setAnchorPoint(imageLock, 0.00, 1.00)")
  1388. if global.isWinPlayMode then
  1389. content = sformat("%s%s%s", content, lineS, "GUI:setScale(imageLock, 0.7)")
  1390. end
  1391. end
  1392. return content
  1393. end
  1394. function TxtTranslator:load_render_DBItemShow(swidget, callback, closeCB, ext)
  1395. local element = swidget.element
  1396. local makeindex = tonumber(element.attr.makeindex) or 1
  1397. local showtips = tonumber(element.attr.showtips) or 1
  1398. local showtips = tonumber(element.attr.showtips) or 1
  1399. local bgtype = tonumber(element.attr.bgtype)
  1400. local scale = tonumber(element.attr.scale) or 1
  1401. local grey = tonumber(element.attr.grey) or 0
  1402. local showstar = tonumber(element.attr.showstar) == 1
  1403. local count = tonumber(element.attr.count)
  1404. local link = element.attr.link
  1405. local effectshow = tonumber(element.attr.effectshow) or 1 -- 1只显示背包 2只显示内观 0不显示
  1406. local x = tonumber(element.attr.x) or 0
  1407. local y = tonumber(element.attr.y) or 0
  1408. local contentSize = cc.size(66, 66)
  1409. local name = swidget.name
  1410. local id = swidget.id
  1411. local parent = ext and ext.parent or noParentCode
  1412. local content = replace([[local ${name} = GUI:Widget_Create(${parent}, "${ID}", ${x}, ${y}, ${width}, ${height})]], {name = name, parent = parent, ID = id, x = x, y = y,
  1413. width = contentSize.width, height = contentSize.height})
  1414. local infoStr = [[local itemData = SL:GetMetaValue("EQUIP_DATA_BY_MAKEINDEX", ${makeindex})
  1415. ${t}if not itemData then
  1416. ${t}${t}itemData = SL:GetMetaValue("ITEM_DATA_BY_MAKEINDEX", ${makeindex})
  1417. ${t}end
  1418. ${t}if not itemData then
  1419. ${t}${t}itemData = SL:GetMetaValue("QUICKUSE_DATA_BY_MAKEINDEX", ${makeindex})
  1420. ${t}end
  1421. ${t}if not itemData then
  1422. ${t}${t}itemData = SL:GetMetaValue("LOOKPLAYER_DATA_BY_MAKEINDEX", ${makeindex})
  1423. ${t}end
  1424. ${t}if itemData then
  1425. ${t}${t}local info = {}
  1426. ${t}${t}info.index = itemData.Index
  1427. ${t}${t}info.itemData = itemData
  1428. ${t}${t}info.look = ${isShowtips}]]
  1429. if not (showtips == 1) and global.isWinPlayMode then
  1430. infoStr = sformat("%s%s%s", infoStr, lineS .. tabS, "info.noMouseTips = true")
  1431. end
  1432. if effectshow == 2 then
  1433. infoStr = sformat("%s%s%s", infoStr, lineS .. tabS, "info.showModelEffect = true")
  1434. elseif effectshow == 0 then
  1435. infoStr = sformat("%s%s%s", infoStr, lineS .. tabS, "info.isShowEff = false")
  1436. end
  1437. infoStr = sformat("%s%s%s", infoStr, lineS .. tabS, [[info.bgVisible = ${bgVisible}
  1438. ${t}${t}info.starLv = ${showstar}
  1439. ${t}${t}local item = GUI:ItemShow_Create(${name}, "${ID}", ${posX}, ${posY}, info)
  1440. ${t}${t}GUI:setAnchorPoint(item, 0.50, 0.50)
  1441. ${t}${t}GUI:setScale(item, ${scale})
  1442. ${t}${t}GUI:ItemShow_setIconGrey(item, ${isGrey})]])
  1443. if count then
  1444. infoStr = sformat("%s%s%s", infoStr, lineS .. tabS, sformat("GUI:ItemShow_OnRunFunc(item, \"SetCount\", %s)", count))
  1445. end
  1446. infoStr = sformat("%s%s%s", infoStr, lineS, "end")
  1447. content = sformat("%s%s%s", content, lineS, replace(infoStr, {name = name, makeindex = makeindex, isShowtips = showtips == 1,
  1448. bgVisible = bgtype == 1, showstar = showstar, posX = contentSize.width / 2, posY = contentSize.height / 2,
  1449. scale = scale, isGrey = grey == 1, ID = id, t = tabS}))
  1450. return content
  1451. end
  1452. function TxtTranslator:load_render_ITEMBOX(swidget, callback, closeCB, ext)
  1453. local element = swidget.element
  1454. local width = tonumber(element.attr.width) or 1
  1455. local height = tonumber(element.attr.height) or 1
  1456. local boxindex = tonumber(element.attr.boxindex)
  1457. local img = element.attr.img
  1458. local stdmode = element.attr.stdmode
  1459. local x = tonumber(element.attr.x) or 0
  1460. local y = tonumber(element.attr.y) or 0
  1461. local img = SUIHelper.fixImageFileName(img)
  1462. local fullPath = string.format(getResFullPath("res/%s"), img)
  1463. local name = swidget.name
  1464. local id = swidget.id
  1465. local parent = ext and ext.parent or noParentCode
  1466. local stdmodeStr = stdmode
  1467. if string.find(stdmode, ",") then
  1468. local slices = string.split(stdmode, ",")
  1469. stdmodeStr = slices
  1470. elseif stdmode == "*" then
  1471. stdmodeStr = "\"*\""
  1472. end
  1473. local content = replace([[local ${name} = GUI:ItemBox_Create(${parent}, "${ID}", ${x}, ${y}, "${fullPath}", ${boxindex}, ${stdmode})]],
  1474. {name = name, parent = parent, ID = id, x = x, y = y, fullPath = fullPath, boxindex = boxindex, stdmode = stdmodeStr})
  1475. return content
  1476. end
  1477. function TxtTranslator:load_render_EquipShow(swidget, callback, closeCB, ext)
  1478. local element = swidget.element
  1479. local index = tonumber(element.attr.index) or 0
  1480. local showtips = tonumber(element.attr.showtips) or 1
  1481. local bgtype = tonumber(element.attr.bgtype)
  1482. local scale = tonumber(element.attr.scale) or 1
  1483. local grey = tonumber(element.attr.grey) or 0
  1484. local showstar = tonumber(element.attr.showstar) == 1
  1485. local link = element.attr.link
  1486. local x = tonumber(element.attr.x) or 0
  1487. local y = tonumber(element.attr.y) or 0
  1488. local effectshow = tonumber(element.attr.effectshow) or 1
  1489. local contentSize = cc.size(66, 66)
  1490. local name = swidget.name
  1491. local id = swidget.id
  1492. local parent = ext and ext.parent or noParentCode
  1493. local content = replace([[local ${name} = GUI:Widget_Create(${parent}, "${ID}", ${x}, ${y}, ${width}, ${height})]], {name = name, parent = parent, ID = id, x = x, y = y,
  1494. width = contentSize.width, height = contentSize.height})
  1495. local infoStr = [[local equipData = SL:GetMetaValue("EQUIP_DATA", ${index})
  1496. ${t}if equipData then
  1497. ${t}${t}local info = {}
  1498. ${t}${t}info.index = equipData.Index
  1499. ${t}${t}info.itemData = equipData
  1500. ${t}${t}info.look = ${isShowtips}]]
  1501. if not (showtips == 1) and global.isWinPlayMode then
  1502. infoStr = sformat("%s%s%s", infoStr, lineS .. tabS, "info.noMouseTips = true")
  1503. end
  1504. if effectshow == 2 then
  1505. infoStr = sformat("%s%s%s", infoStr, lineS .. tabS, "info.showModelEffect = true")
  1506. elseif effectshow == 0 then
  1507. infoStr = sformat("%s%s%s", infoStr, lineS .. tabS, "info.isShowEff = false")
  1508. end
  1509. infoStr = sformat("%s%s%s", infoStr, lineS .. tabS, [[info.bgVisible = ${bgVisible}
  1510. ${t}${t}info.starLv = ${showstar}
  1511. ${t}${t}local item = GUI:ItemShow_Create(${name}, "${ID}", ${posX}, ${posY}, info)
  1512. ${t}${t}GUI:setAnchorPoint(item, 0.50, 0.50)
  1513. ${t}${t}GUI:setScale(item, ${scale})
  1514. ${t}${t}GUI:ItemShow_setIconGrey(item, ${isGrey})
  1515. ${t}end]])
  1516. content = sformat("%s%s%s", content, lineS, replace(infoStr, {name = name, index = index, isShowtips = showtips == 1,
  1517. bgVisible = bgtype == 1, showstar = showstar, posX = contentSize.width / 2, posY = contentSize.height / 2,
  1518. scale = scale, isGrey = grey == 1, ID = id, t = tabS}))
  1519. return content
  1520. end
  1521. function TxtTranslator:load_render_BAGITEMS(swidget, callback, closeCB, ext)
  1522. local element = swidget.element
  1523. local condition = element.attr.condition or ""
  1524. local exclude = element.attr.exclude or ""
  1525. local select = element.attr.select or ""
  1526. local count = tonumber(element.attr.count) or 12
  1527. local row = tonumber(element.attr.row) or 2
  1528. local selecttype = tonumber(element.attr.selecttype) or 0
  1529. local showstar = tonumber(element.attr.showstar) == 1
  1530. local iwidth = tonumber(element.attr.iwidth) or 70
  1531. local iheight = tonumber(element.attr.iheight) or 70
  1532. local iimg = element.attr.iimg
  1533. local filter1 = element.attr.fliter1 or element.attr.filter1 or ""
  1534. local filter2 = element.attr.fliter2 or element.attr.filter2 or ""
  1535. local filter3 = element.attr.fliter3 or element.attr.filter3 or ""
  1536. local link = element.attr.link
  1537. local conditionEx = element.attr.conditionEx
  1538. local conditionParam = element.attr.conditionParam
  1539. local conditionOnOff = tonumber(element.attr.conditionOnOff) or 0
  1540. local condition2 = element.attr.condition2
  1541. local x = tonumber(element.attr.x) or 0
  1542. local y = tonumber(element.attr.y) or 0
  1543. local effectshow = tonumber(element.attr.effectshow) or 1
  1544. local exBind = tonumber(element.attr.exbind) == 1
  1545. local showtips = (tonumber(element.attr.showtips) or 0) == 1
  1546. -- 是否满足显示条件
  1547. local conditionT = {}
  1548. local slices1 = ssplit(condition, ",")
  1549. local slices2 = {}
  1550. for _, v in pairs(slices1) do
  1551. slices2 = ssplit(v, "#")
  1552. tinsert(conditionT, {StdMode = tonumber(slices2[1]), Shape = tonumber(slices2[2])})
  1553. end
  1554. -- 唯一ID过滤
  1555. local excludeT = {}
  1556. local slices = ssplit(exclude, ",")
  1557. for _, v in pairs(slices) do
  1558. tinsert(excludeT, tonumber(v))
  1559. end
  1560. -- 道具ID过滤,存在不显示
  1561. local filter1T = {}
  1562. local slices = ssplit(filter1, ",")
  1563. for _, v in pairs(slices) do
  1564. tinsert(filter1T, tonumber(v))
  1565. end
  1566. -- 道具名过滤,存在不显示
  1567. local filter2T = {}
  1568. local slices = ssplit(filter2, ",")
  1569. for _, v in pairs(slices) do
  1570. if v ~= "" then
  1571. tinsert(filter2T, v)
  1572. end
  1573. end
  1574. -- 道具ID过滤,存在才显示
  1575. local filter3T = {}
  1576. local slices = ssplit(filter3, ",")
  1577. for _, v in pairs(slices) do
  1578. if v ~= "" then
  1579. tinsert(filter3T, v)
  1580. end
  1581. end
  1582. local name = swidget.name
  1583. local id = swidget.id
  1584. local parent = ext and ext.parent or noParentCode
  1585. iimg = (iimg and iimg ~= "") and SUIHelper.fixImageFileName(iimg) or "public/1900000664.png"
  1586. local itemParam = {
  1587. width = iwidth,
  1588. height = iheight,
  1589. imgBg = string.format(getResFullPath("res/%s"), iimg),
  1590. showtips = showtips,
  1591. effectshow = effectshow
  1592. }
  1593. local conditionList = {
  1594. conditionEx = conditionEx,
  1595. conditionOnOff = conditionOnOff,
  1596. conditionParam = conditionParam,
  1597. condition = condition == "*" and condition or conditionT,
  1598. condition2 = condition2,
  1599. exclude = excludeT,
  1600. filter1 = filter1T,
  1601. filter2 = filter2T,
  1602. filter3 = filter3T,
  1603. exBind = exBind,
  1604. }
  1605. local content = replace([[local ${name} = GUI:BAGITEMS_Create(${parent}, "${ID}", ${x}, ${y}, ${conditionList}, ${count}, ${row}, ${showstar}, ${itemParam})]],
  1606. {name = name, parent = parent, ID = id, x = x, y = y, conditionList = conditionList, count = count, row = row, showstar = showstar, itemParam = itemParam})
  1607. return content
  1608. end
  1609. function TxtTranslator:load_render_EQUIPITEMS(swidget, callback, closeCB, ext)
  1610. local element = swidget.element
  1611. local positions = element.attr.positions or "*"
  1612. local select = element.attr.select or ""
  1613. local count = tonumber(element.attr.count) or 12
  1614. local row = tonumber(element.attr.row) or 2
  1615. local selecttype = tonumber(element.attr.selecttype) or 0
  1616. local showstar = tonumber(element.attr.showstar) == 1
  1617. local iwidth = tonumber(element.attr.iwidth) or 70
  1618. local iheight = tonumber(element.attr.iheight) or 70
  1619. local iimg = element.attr.iimg
  1620. local link = element.attr.link
  1621. local x = tonumber(element.attr.x) or 0
  1622. local y = tonumber(element.attr.y) or 0
  1623. local effectshow = tonumber(element.attr.effectshow) or 1
  1624. -- 装备位
  1625. local equipPositions = {}
  1626. local slices = ssplit(positions, ",")
  1627. for _, v in ipairs(slices) do
  1628. tinsert(equipPositions, tonumber(v))
  1629. end
  1630. positions = positions == "*" and "\"*\"" or equipPositions
  1631. local name = swidget.name
  1632. local id = swidget.id
  1633. local parent = ext and ext.parent or noParentCode
  1634. iimg = (iimg and iimg ~= "") and SUIHelper.fixImageFileName(iimg) or "public/1900000664.png"
  1635. local itemParam = {
  1636. width = iwidth,
  1637. height = iheight,
  1638. imgBg = string.format(getResFullPath("res/%s"), iimg),
  1639. effectshow = effectshow
  1640. }
  1641. local content = replace([[local ${name} = GUI:EQUIPITEMS_Create(${parent}, "${ID}", ${x}, ${y}, ${positions}, ${count}, ${row}, ${showstar}, ${itemParam})]],
  1642. {name = name, parent = parent, ID = id, x = x, y = y, positions = positions, count = count, row = row,
  1643. itemParam = itemParam, showstar = showstar})
  1644. return content
  1645. end
  1646. function TxtTranslator:load_render_TIMETIPS(swidget, callback, closeCB, ext)
  1647. local element = swidget.element
  1648. local size = tonumber(element.attr.size) or defaultFontSize
  1649. local color = tonumber(element.attr.color) or defaultColorID
  1650. local time = tonumber(element.attr.time) or 0
  1651. local outline = tonumber(element.attr.outline) or defaultOutline
  1652. local outlinecolor = tonumber(element.attr.outlinecolor) or defaultOutlineC
  1653. local link = element.attr.link
  1654. local x = tonumber(element.attr.x) or 0
  1655. local y = tonumber(element.attr.y) or 0
  1656. local name = swidget.name
  1657. local id = swidget.id
  1658. local parent = ext and ext.parent or noParentCode
  1659. local content = replace([[local ${name} = GUI:Text_Create(${parent}, "${ID}", ${x}, ${y}, ${size}, ${color}, "")]],
  1660. {name = name, size = size, color = GET_COLOR_BYID(color), parent = parent, ID = id, x = x, y = y})
  1661. if outline > 0 then
  1662. content = sformat("%s%s%s", content, lineS, sformat("GUI:Text_enableOutline(%s, \"%s\", %s)", name, GET_COLOR_BYID(outlinecolor), outline))
  1663. end
  1664. content = sformat("%s%s%s", content, lineS, sformat([[local endTime = time + SL:GetMetaValue("SERVER_TIME")
  1665. ${t}local function callback()
  1666. ${t}${t}local remaining = math.max(endTime - SL:GetMetaValue("SERVER_TIME"), 0)
  1667. ${t}${t}GUI:Text_setString(${name}, SL:SecondToHMS(remaining, true))
  1668. ${t}${t}if remaining <= 0 then
  1669. ${t}${t}${t}-- link
  1670. ${t}${t}${t}GUI:stopAllAction(${name})
  1671. ${t}${t}end
  1672. ${t}end
  1673. ${t}SL:schedule((${name}, callback, 1)
  1674. ${t}callback()]], {name = name, time = time, t = tabS}))
  1675. return content
  1676. end
  1677. function TxtTranslator:load_render_LoadingBar(swidget, callback, closeCB, ext)
  1678. local element = swidget.element
  1679. local size = tonumber(element.attr.size) or defaultFontSize
  1680. local color = tonumber(element.attr.color) or defaultColorID
  1681. local outline = tonumber(element.attr.outline) or defaultOutline
  1682. local outlinecolor = tonumber(element.attr.outlinecolor) or defaultOutlineC
  1683. local direction = tonumber(element.attr.direction) or 0 -- 0从左至右 1从右到左
  1684. local loadBgImg = element.attr.loadingbg or "public/bg_szjm_03_1.png"
  1685. local loadBarImg = element.attr.loadingbar or "public/bg_szjm_03_2.png"
  1686. local startPercent = tonumber(element.attr.startper) or 0
  1687. local interval = tonumber(element.attr.interval) or 0.05
  1688. local loadValue = tonumber(element.attr.loadvalue) or 10
  1689. local link = element.attr.link
  1690. local submitInput = element.attr.submitInput
  1691. local submitCheckBox = element.attr.submitCheckBox
  1692. local offsetX = tonumber(element.attr.offsetX) or 0
  1693. local offsetY = tonumber(element.attr.offsetY) or 0
  1694. local x = tonumber(element.attr.x) or 0
  1695. local y = tonumber(element.attr.y) or 0
  1696. local imgBg = SUIHelper.fixImageFileName(loadBgImg)
  1697. local imgBar = SUIHelper.fixImageFileName(loadBarImg)
  1698. local fullPathBG = (imgBg and imgBg ~= "") and string.format(getResFullPath("res/%s"), imgBg) or ""
  1699. local fullPathBAR = (imgBar and imgBar ~= "") and string.format(getResFullPath("res/%s"), imgBar) or ""
  1700. local name = swidget.name
  1701. local id = swidget.id
  1702. local parent = ext and ext.parent or noParentCode
  1703. local content = replace([[local ${name} = GUI:Image_Create(${parent}, "${ID}", ${x}, ${y}, "${fullPathBG}")]],
  1704. {name = name, ID = id, x = x, y = y, fullPathBG = fullPathBG, parent = parent})
  1705. content = sformat("%s%s%s", content, lineS, sformat("local bgSize = GUI:getContentSize(%s)", name))
  1706. local barId = id .. "_Bar"
  1707. if fullPathBAR and fullPathBAR ~= "" and global.FileUtilCtl:isFileExist(fullPathBAR) then
  1708. content = sformat("%s%s%s", content, lineS, replace([[local ${ID} = GUI:LoadingBar_Create(${name}, "${ID}", bgSize.width / 2 + ${offsetX}, bgSize.height / 2 + ${offsetY}, "${fullPathBAR}", ${direction})
  1709. ${t}GUI:setAnchorPoint(${ID}, 0.50, 0.50)
  1710. ${t}GUI:LoadingBar_setPercent(${ID}, ${startPercent})]],
  1711. {name = name, ID = barId, offsetX = tranNegNum(offsetX), offsetY = tranNegNum(offsetY), startPercent = startPercent, fullPathBAR = fullPathBAR, direction = direction, t = tabS})
  1712. )
  1713. local textId = id .. "_Text"
  1714. content = sformat("%s%s%s", content, lineS, replace([[local ${ID} = GUI:Text_Create(${name}, "${ID}", bgSize.width / 2, bgSize.height / 2, ${size}, "${textColor}", "${perStr}")
  1715. ${t}GUI:setAnchorPoint(${ID}, 0.50, 0.50)
  1716. ${t}GUI:Text_enableOutline(${ID}, "${outlinecolor}", ${outline})]],
  1717. {perStr = string.format("%s/%s", startPercent, 100), size = size, textColor = GET_COLOR_BYID(color),
  1718. outlinecolor = GET_COLOR_BYID(outlinecolor), outline = outline, name = name, ID = textId, t = tabS})
  1719. )
  1720. content = sformat("%s%s%s", content, lineS, replace([[GUI:stopAllActions(${barId})
  1721. ${t}local percent = ${startPercent}
  1722. ${t}local function scheduleCB()
  1723. ${t}${t}percent = percent + ${loadValue}
  1724. ${t}${t}GUI:LoadingBar_setPercent(${barId}, percent)
  1725. ${t}${t}local curPercent = math.floor(percent / 100 * 100)
  1726. ${t}${t}GUI:Text_setString(${textId}, string.format("%s/%s", curPercent, 100))
  1727. ${t}${t}if percent >= 100 then
  1728. ${t}${t}${t}GUI:stopAllActions(${barId})
  1729. ${t}${t}${t}-- link
  1730. ${t}${t}end
  1731. ${t}end
  1732. ${t}SL:schedule(${barId}, scheduleCB, ${interval})
  1733. ${t}scheduleCB()]], {startPercent = startPercent, loadValue = loadValue, interval = interval, barId = barId, textId = textId, t = tabS})
  1734. )
  1735. end
  1736. return content
  1737. end
  1738. function TxtTranslator:load_render_CircleBar(swidget, callback, closeCB, ext)
  1739. local element = swidget.element
  1740. local loadBgImg = element.attr.loadingbg or "private/sui/bg_xbzy_02.png"
  1741. local loadBarImg = element.attr.loadingbar or "private/sui/bg_xbzy_03.png"
  1742. local startPercent = tonumber(element.attr.startper) or 0
  1743. local endPercent = tonumber(element.attr.endper) or 100
  1744. local time = tonumber(element.attr.time) or 1
  1745. local link = element.attr.link
  1746. local submitInput = element.attr.submitInput
  1747. local submitCheckBox = element.attr.submitCheckBox
  1748. local offsetX = element.attr.offsetX or 0
  1749. local offsetY = element.attr.offsetY or 0
  1750. local imgBg = SUIHelper.fixImageFileName(loadBgImg)
  1751. local imgBar = SUIHelper.fixImageFileName(loadBarImg)
  1752. local fullPathBG = (imgBg and imgBg ~= "") and string.format(getResFullPath("res/%s"), imgBg) or ""
  1753. local fullPathBAR = (imgBar and imgBar ~= "") and string.format(getResFullPath("res/%s"), imgBar) or ""
  1754. local x = tonumber(element.attr.x) or 0
  1755. local y = tonumber(element.attr.y) or 0
  1756. local name = swidget.name
  1757. local id = swidget.id
  1758. local parent = ext and ext.parent or noParentCode
  1759. local content = replace([[local ${name} = GUI:CircleBar_Create(${parent}, "${ID}", ${x}, ${y}, "${fullPathBG}", "${fullPathBAR}", ${startPercent}, ${endPercent}, ${time})
  1760. ${t}GUI:CircleBar_setBarOffSet(${name}, ${offsetX}, ${offsetY})]], {name = name, fullPathBG = fullPathBG, fullPathBAR = fullPathBAR, offsetX = offsetX, offsetY = offsetY,
  1761. startPercent = startPercent, time = time, endPercent = endPercent, parent = parent, ID = id, x = x, y = y})
  1762. return content
  1763. end
  1764. function TxtTranslator:load_render_PercentImg(swidget, callback, closeCB, ext)
  1765. local element = swidget.element
  1766. local direction = tonumber(element.attr.direction) or 0 -- 0 从左到右 1从右到左 2从上往下 3从下往上
  1767. local loadImg = element.attr.img or "public/bg_szjm_03_2.png"
  1768. local minValue = tonumber(element.attr.minValue) or 100
  1769. local maxValue = tonumber(element.attr.maxValue) or 100
  1770. local percent = math.floor(minValue / maxValue * 100) or 100
  1771. local x = tonumber(element.attr.x) or 0
  1772. local y = tonumber(element.attr.y) or 0
  1773. local img = SUIHelper.fixImageFileName(loadImg)
  1774. local fullPath = (img and img ~= "") and string.format(getResFullPath("res/%s"), img) or ""
  1775. local name = swidget.name
  1776. local id = swidget.id
  1777. local parent = ext and ext.parent or noParentCode
  1778. local content = replace([[local ${name} = GUI:PercentImg_Create(${parent}, "${ID}", ${x}, ${y}, "${fullPath}", ${direction}, "${minValue}", "${maxValue}")]],
  1779. {name = name, parent = parent, fullPath = fullPath, ID = id, x = x, y = y,
  1780. direction = direction, minValue = element.attr.minValue or 100, maxValue = element.attr.maxValue or 100})
  1781. return content
  1782. end
  1783. function TxtTranslator:load_render_UIModel(swidget,callback, closeCB, ext)
  1784. local element = swidget.element
  1785. local sex = tonumber(element.attr.sex) or 0
  1786. local scale = tonumber(element.attr.scale) or 1
  1787. local x = tonumber(element.attr.x) or 0
  1788. local y = tonumber(element.attr.y) or 0
  1789. local function parseEffectStr(str)
  1790. if not str then
  1791. return nil
  1792. end
  1793. return string.gsub(str, "&", "|")
  1794. end
  1795. local feature = {}
  1796. feature.clothID = tonumber(element.attr.clothID)
  1797. feature.weaponID = tonumber(element.attr.weaponID)
  1798. feature.headID = tonumber(element.attr.headID)
  1799. feature.headEffectID = parseEffectStr(element.attr.headEffectID)
  1800. feature.weaponEffectID = parseEffectStr(element.attr.weaponEffectID)
  1801. feature.clothEffectID = parseEffectStr(element.attr.clothEffectID)
  1802. feature.capID = tonumber(element.attr.capID)
  1803. feature.shieldID = tonumber(element.attr.shieldID)
  1804. feature.shieldEffectID = parseEffectStr(element.attr.shieldEffectID)
  1805. feature.tDressID = tonumber(element.attr.tDressID)
  1806. feature.tDressEffectID = parseEffectStr(element.attr.tDressEffectID)
  1807. feature.tWeaponID = tonumber(element.attr.tWeaponID)
  1808. feature.tWeaponEffectID = parseEffectStr(element.attr.tWeaponEffectID)
  1809. feature.capEffectID = parseEffectStr(element.attr.capEffectID)
  1810. feature.veilID = tonumber(element.attr.veilID)
  1811. feature.veilEffectID = parseEffectStr(element.attr.veilEffectID)
  1812. feature.hairID = tonumber(element.attr.hairID)
  1813. feature.notShowMold = element.attr.notShowMold
  1814. feature.notShowHair = element.attr.notShowHair
  1815. local name = swidget.name
  1816. local id = swidget.id
  1817. local parent = ext and ext.parent or noParentCode
  1818. local content = replace([[local ${name} = GUI:UIModel_Create(${parent}, "${ID}", ${x}, ${y}, ${sex}, ${feature}, ${scale})]],
  1819. {name = name, parent = parent, ID = id, x = x, y = y, sex = sex, feature = feature, scale = scale})
  1820. return content
  1821. end
  1822. ---- 英雄相关
  1823. function TxtTranslator:load_render_HEROEquipShow(swidget, callback, closeCB, ext)
  1824. local element = swidget.element
  1825. local index = tonumber(element.attr.index) or 0
  1826. local showtips = tonumber(element.attr.showtips) or 1
  1827. local bgtype = tonumber(element.attr.bgtype)
  1828. local scale = tonumber(element.attr.scale) or 1
  1829. local grey = tonumber(element.attr.grey) or 0
  1830. local showstar = tonumber(element.attr.showstar) == 1
  1831. local link = element.attr.link
  1832. local x = tonumber(element.attr.x) or 0
  1833. local y = tonumber(element.attr.y) or 0
  1834. local effectshow = tonumber(element.attr.effectshow) or 1
  1835. local contentSize = cc.size(66,66)
  1836. local name = swidget.name
  1837. local id = swidget.id
  1838. local parent = ext and ext.parent or noParentCode
  1839. local content = replace([[local ${name} = GUI:Widget_Create(${parent}, "${ID}", ${x}, ${y}, ${width}, ${height})]], {name = name, parent = parent, ID = id, x = x, y = y,
  1840. width = contentSize.width, height = contentSize.height})
  1841. local infoStr = [[local equipData = SL:GetMetaValue("H.EQUIP_DATA", ${index})
  1842. ${t}if equipData then
  1843. ${t}${t}local info = {}
  1844. ${t}${t}info.index = equipData.Index
  1845. ${t}${t}info.itemData = equipData
  1846. ${t}${t}info.look = ${isShowtips}]]
  1847. if not (showtips == 1) and global.isWinPlayMode then
  1848. infoStr = sformat("%s%s%s", infoStr, lineS .. tabS, "info.noMouseTips = true")
  1849. end
  1850. if effectshow == 2 then
  1851. infoStr = sformat("%s%s%s", infoStr, lineS .. tabS, "info.showModelEffect = true")
  1852. elseif effectshow == 0 then
  1853. infoStr = sformat("%s%s%s", infoStr, lineS .. tabS, "info.isShowEff = false")
  1854. end
  1855. infoStr = sformat("%s%s%s", infoStr, lineS .. tabS, [[info.bgVisible = ${bgVisible}
  1856. ${t}${t}info.starLv = ${showstar}
  1857. ${t}${t}local item = GUI:ItemShow_Create(${name}, "${ID}", ${posX}, ${posY}, info)
  1858. ${t}${t}GUI:setAnchorPoint(item, 0.50, 0.50)
  1859. ${t}${t}GUI:setScale(item, ${scale})
  1860. ${t}${t}GUI:ItemShow_setIconGrey(item, ${isGrey})
  1861. ${t}end]])
  1862. content = sformat("%s%s%s", content, lineS, replace(infoStr, {name = name, index = index, isShowtips = showtips == 1,
  1863. bgVisible = bgtype == 1, showstar = showstar, posX = contentSize.width / 2, posY = contentSize.height / 2,
  1864. scale = scale, isGrey = grey == 1, ID = id, t = tabS}))
  1865. return content
  1866. end
  1867. function TxtTranslator:load_render_HEROEQUIPITEMS(swidget, callback, closeCB, ext)
  1868. local element = swidget.element
  1869. local positions = element.attr.positions or "*"
  1870. local select = element.attr.select or ""
  1871. local count = tonumber(element.attr.count) or 12
  1872. local row = tonumber(element.attr.row) or 2
  1873. local selecttype = tonumber(element.attr.selecttype) or 0
  1874. local showstar = tonumber(element.attr.showstar) == 1
  1875. local iwidth = tonumber(element.attr.iwidth) or 70
  1876. local iheight = tonumber(element.attr.iheight) or 70
  1877. local iimg = element.attr.iimg
  1878. local link = element.attr.link
  1879. local x = tonumber(element.attr.x) or 0
  1880. local y = tonumber(element.attr.y) or 0
  1881. local effectshow = tonumber(element.attr.effectshow) or 1
  1882. -- 装备位
  1883. local equipPositions = {}
  1884. local slices = ssplit(positions, ",")
  1885. for _, v in ipairs(slices) do
  1886. tinsert(equipPositions, tonumber(v))
  1887. end
  1888. positions = positions == "*" and "\"*\"" or equipPositions
  1889. local name = swidget.name
  1890. local id = swidget.id
  1891. local parent = ext and ext.parent or noParentCode
  1892. iimg = (iimg and iimg ~= "") and SUIHelper.fixImageFileName(iimg) or "public/1900000664.png"
  1893. local itemParam = {
  1894. width = iwidth,
  1895. height = iheight,
  1896. imgBg = string.format(getResFullPath("res/%s"), iimg),
  1897. effectshow = effectshow
  1898. }
  1899. local content = replace([[local ${name} = GUI:EQUIPITEMS_Create(${parent}, "${ID}", ${x}, ${y}, ${positions}, ${count}, ${row}, ${showstar}, ${itemParam}, true)]],
  1900. {name = name, parent = parent, ID = id, x = x, y = y, positions = positions, count = count, row = row,
  1901. itemParam = itemParam, showstar = showstar})
  1902. return content
  1903. end
  1904. function TxtTranslator:load_render_HERODBItemShow(swidget, callback, closeCB, ext)
  1905. local element = swidget.element
  1906. local makeindex = tonumber(element.attr.makeindex) or 1
  1907. local showtips = tonumber(element.attr.showtips) or 1
  1908. local showtips = tonumber(element.attr.showtips) or 1
  1909. local bgtype = tonumber(element.attr.bgtype)
  1910. local scale = tonumber(element.attr.scale) or 1
  1911. local grey = tonumber(element.attr.grey) or 0
  1912. local showstar = tonumber(element.attr.showstar) == 1
  1913. local count = tonumber(element.attr.count)
  1914. local link = element.attr.link
  1915. local x = tonumber(element.attr.x) or 0
  1916. local y = tonumber(element.attr.y) or 0
  1917. local effectshow = tonumber(element.attr.effectshow) or 1
  1918. local contentSize = cc.size(66, 66)
  1919. local name = swidget.name
  1920. local id = swidget.id
  1921. local parent = ext and ext.parent or noParentCode
  1922. local content = replace([[local ${name} = GUI:Widget_Create(${parent}, "${ID}", ${x}, ${y}, ${width}, ${height})]], {name = name, parent = parent, ID = id, x = x, y = y,
  1923. width = contentSize.width, height = contentSize.height})
  1924. local infoStr = [[local itemData = SL:GetMetaValue("EQUIP_DATA_BY_MAKEINDEX", ${makeindex}, true)
  1925. ${t}if not itemData then
  1926. ${t}${t}itemData = SL:GetMetaValue("ITEM_DATA_BY_MAKEINDEX", ${makeindex}, true)
  1927. ${t}end
  1928. ${t}if not itemData then
  1929. ${t}${t}itemData = SL:GetMetaValue("LOOKPLAYER_DATA_BY_MAKEINDEX", ${makeindex})
  1930. ${t}end
  1931. ${t}if itemData then
  1932. ${t}${t}local info = {}
  1933. ${t}${t}info.index = itemData.Index
  1934. ${t}${t}info.itemData = itemData
  1935. ${t}${t}info.look = ${isShowtips}]]
  1936. if not (showtips == 1) and global.isWinPlayMode then
  1937. infoStr = sformat("%s%s%s", infoStr, lineS .. tabS, "info.noMouseTips = true")
  1938. end
  1939. if effectshow == 2 then
  1940. infoStr = sformat("%s%s%s", infoStr, lineS .. tabS, "info.showModelEffect = true")
  1941. elseif effectshow == 0 then
  1942. infoStr = sformat("%s%s%s", infoStr, lineS .. tabS, "info.isShowEff = false")
  1943. end
  1944. infoStr = sformat("%s%s%s", infoStr, lineS .. tabS, [[info.bgVisible = ${bgVisible}
  1945. ${t}${t}info.starLv = ${showstar}
  1946. ${t}${t}local item = GUI:ItemShow_Create(${name}, "${ID}", ${posX}, ${posY}, info)
  1947. ${t}${t}GUI:setAnchorPoint(item, 0.50, 0.50)
  1948. ${t}${t}GUI:setScale(item, ${scale})
  1949. ${t}${t}GUI:ItemShow_setIconGrey(item, ${isGrey})]])
  1950. if count then
  1951. infoStr = sformat("%s%s%s", infoStr, lineS .. tabS, sformat("GUI:ItemShow_OnRunFunc(item, \"SetCount\", %s)", count))
  1952. end
  1953. infoStr = sformat("%s%s%s", infoStr, lineS, "end")
  1954. content = sformat("%s%s%s", content, lineS, replace(infoStr, {name = name, makeindex = makeindex, isShowtips = showtips == 1,
  1955. bgVisible = bgtype == 1, showstar = showstar, posX = contentSize.width / 2, posY = contentSize.height / 2,
  1956. scale = scale, isGrey = grey == 1, ID = id, t = tabS}))
  1957. return content
  1958. end
  1959. function TxtTranslator:load_render_HEROBAGITEMS(swidget, callback, closeCB, ext)
  1960. local element = swidget.element
  1961. local condition = element.attr.condition or ""
  1962. local exclude = element.attr.exclude or ""
  1963. local select = element.attr.select or ""
  1964. local count = tonumber(element.attr.count) or 12
  1965. local row = tonumber(element.attr.row) or 2
  1966. local selecttype = tonumber(element.attr.selecttype) or 0
  1967. local showstar = tonumber(element.attr.showstar) == 1
  1968. local iwidth = tonumber(element.attr.iwidth) or 70
  1969. local iheight = tonumber(element.attr.iheight) or 70
  1970. local iimg = element.attr.iimg
  1971. local filter1 = element.attr.fliter1 or element.attr.filter1 or ""
  1972. local filter2 = element.attr.fliter2 or element.attr.filter2 or ""
  1973. local filter3 = element.attr.fliter3 or element.attr.filter3 or ""
  1974. local link = element.attr.link
  1975. local conditionEx = element.attr.conditionEx
  1976. local conditionParam = element.attr.conditionParam
  1977. local conditionOnOff = tonumber(element.attr.conditionOnOff) or 0
  1978. local x = tonumber(element.attr.x) or 0
  1979. local y = tonumber(element.attr.y) or 0
  1980. local effectshow = tonumber(element.attr.effectshow) or 1
  1981. -- 是否满足显示条件
  1982. local conditionT = {}
  1983. local slices1 = ssplit(condition, ",")
  1984. local slices2 = {}
  1985. for _, v in pairs(slices1) do
  1986. slices2 = ssplit(v, "#")
  1987. tinsert(conditionT, {StdMode = tonumber(slices2[1]), Shape = tonumber(slices2[2])})
  1988. end
  1989. -- 唯一ID过滤
  1990. local excludeT = {}
  1991. local slices = ssplit(exclude, ",")
  1992. for _, v in pairs(slices) do
  1993. tinsert(excludeT, tonumber(v))
  1994. end
  1995. -- 道具ID过滤,存在不显示
  1996. local filter1T = {}
  1997. local slices = ssplit(filter1, ",")
  1998. for _, v in pairs(slices) do
  1999. tinsert(filter1T, tonumber(v))
  2000. end
  2001. -- 道具名过滤,存在不显示
  2002. local filter2T = {}
  2003. local slices = ssplit(filter2, ",")
  2004. for _, v in pairs(slices) do
  2005. if v ~= "" then
  2006. tinsert(filter2T, v)
  2007. end
  2008. end
  2009. -- 道具ID过滤,存在才显示
  2010. local filter3T = {}
  2011. local slices = ssplit(filter3, ",")
  2012. for _, v in pairs(slices) do
  2013. if v ~= "" then
  2014. tinsert(filter3T, v)
  2015. end
  2016. end
  2017. local name = swidget.name
  2018. local name = swidget.name
  2019. local id = swidget.id
  2020. local parent = ext and ext.parent or noParentCode
  2021. iimg = (iimg and iimg ~= "") and SUIHelper.fixImageFileName(iimg) or "public/1900000664.png"
  2022. local itemParam = {
  2023. width = iwidth,
  2024. height = iheight,
  2025. imgBg = string.format(getResFullPath("res/%s"), iimg),
  2026. effectshow = effectshow
  2027. }
  2028. local conditionList = {
  2029. conditionEx = conditionEx,
  2030. conditionOnOff = conditionOnOff,
  2031. conditionParam = conditionParam,
  2032. condition = condition == "*" and "\"*\"" or conditionT,
  2033. exclude = excludeT,
  2034. filter1 = filter1T,
  2035. filter2 = filter2T,
  2036. filter3 = filter3T,
  2037. }
  2038. local content = replace([[local ${name} = GUI:BAGITEMS_Create(${parent}, "${ID}", ${x}, ${y}, ${conditionList}, ${count}, ${row}, ${showstar}, ${itemParam}, true)]],
  2039. {name = name, parent = parent, ID = id, x = x, y = y, conditionList = conditionList, count = count, row = row, showstar = showstar, itemParam = itemParam})
  2040. return content
  2041. end
  2042. function TxtTranslator:load_render_RTextX(swidget, callback, closeCB, ext)
  2043. local element = swidget.element
  2044. local text = element.attr.text or ""
  2045. local size = tonumber(element.attr.size) or defaultFontSize
  2046. local color = tonumber(element.attr.color) or defaultColorID
  2047. local width = tonumber(element.attr.width) or 1136
  2048. local link = element.attr.link
  2049. local outline = tonumber(element.attr.outline) or defaultOutline
  2050. local outlinecolor = tonumber(element.attr.outlinecolor) or defaultOutlineC
  2051. local scrollWidth = tonumber(element.attr.scrollWidth)
  2052. local scrollWay = tonumber(element.attr.scrollWay) or 0 -- 0 从右到左 1 从下到上
  2053. local scrollTime = tonumber(element.attr.scrollTime) or 4
  2054. local scrollHeight = tonumber(element.attr.scrollHeight)
  2055. local x = tonumber(element.attr.x) or 0
  2056. local y = tonumber(element.attr.y) or 0
  2057. local colorHex = GET_COLOR_BYID(color)
  2058. local vspace = SL:GetMetaValue("GAME_DATA", "DEFAULT_VSPACE")
  2059. local outlineParam = {
  2060. outlineSize = outline,
  2061. outlineColor = GET_COLOR_BYID_C3B(outlinecolor)
  2062. }
  2063. local name = swidget.name
  2064. local id = swidget.id
  2065. local parent = ext and ext.parent or noParentCode
  2066. local content = ""
  2067. if scrollWidth then
  2068. swidget.realname = "scrollLayout_" .. id
  2069. content = sformat("%s%s%s",
  2070. sformat("local %s = GUI:Layout_Create(%s, \"%s\", %s, %s, %s, 0, true)", swidget.realname, parent, id, x, y, scrollWidth),
  2071. lineS,
  2072. sformat("local %s = GUI:RichText_Create(%s, \"%s\", 0, 0, \"%s\", %s, %s, \"%s\", %s)",
  2073. name, swidget.realname, id, text, width, size, colorHex, vspace)
  2074. )
  2075. -- size
  2076. content = sformat("%s%s%s", content, lineS, sformat("local widgetSize = GUI:getContentSize(%s)", name))
  2077. if scrollHeight then
  2078. content = sformat("%s%s%s", content, lineS, sformat("local scrollH = %s", scrollHeight))
  2079. else
  2080. content = sformat("%s%s%s", content, lineS, "local scrollH = widgetSize.height")
  2081. end
  2082. content = sformat("%s%s%s", content, lineS, sformat("GUI:setContentSize(%s, %s, scrollH)", swidget.realname, scrollWidth))
  2083. else
  2084. content = sformat("local %s = GUI:RichText_Create(%s, \"%s\", 0, 0, \"%s\", %s, %s, \"%s\", %s)", name, parent, id, text, width, size, colorHex, vspace)
  2085. end
  2086. -- auto scroll
  2087. if scrollWidth then
  2088. if scrollWay == 0 then
  2089. content = sformat("%s%s%s", content, lineS, [[GUI:setAnchorPoint(${name}, 0.00, 0.00)
  2090. ${t}GUI:setPosition(${name}, 0, 0)
  2091. ${t}GUI:runAction(${name}, GUI:ActionRepeatForever(GUI:ActionSequence(
  2092. ${t}${t}GUI:ActionMoveBy(${scrollTime}, - widgetSize.width, 0),
  2093. ${t}${t}GUI:ActionMoveBy(0, widgetSize.width, 0))))]])
  2094. elseif scrollWay == 1 then
  2095. content = sformat("%s%s%s", content, lineS, [[GUI:setAnchorPoint(${name}, 0.00, 1.00)
  2096. ${t}GUI:setPosition(${name}, 0, scrollH)
  2097. ${t}GUI:runAction(${name}, GUI:ActionRepeatForever(GUI:ActionSequence(
  2098. ${t}${t}GUI:ActionMoveBy(${scrollTime}, 0, widgetSize.height),
  2099. ${t}${t}GUI:ActionMoveBy(0, 0, - widgetSize.height))))]])
  2100. end
  2101. content = replace(content, {
  2102. name = name, scrollTime = scrollTime, t = tabS
  2103. })
  2104. return content
  2105. end
  2106. return content
  2107. end
  2108. function TxtTranslator:load_render_PageView(swidget, callback, closeCB, ext)
  2109. local element = swidget.element
  2110. local width = element.attr.width or 200
  2111. local height = element.attr.height or 200
  2112. local color = tonumber(element.attr.color)
  2113. local default = tonumber(element.attr.default)
  2114. local cantouch = tonumber(element.attr.cantouch) or 1
  2115. local x = tonumber(element.attr.x) or 0
  2116. local y = tonumber(element.attr.y) or 0
  2117. local name = swidget.name
  2118. local id = swidget.id
  2119. local parent = ext and ext.parent or noParentCode
  2120. local content = sformat("local %s = GUI:PageView_Create(%s, \"%s\", %s, %s, %s, %s)", name, parent, id, x, y, width, height)
  2121. -- color
  2122. if color then
  2123. content = sformat("%s%s%s", content, lineS, replace([[GUI:PageView_setBackGroundColorType(${name}, 1)
  2124. ${t}GUI:PageView_setBackGroundColor(${name}, "${colorHex}")
  2125. ${t}GUI:PageView_setBackGroundColorOpacity(${name}, 255)]], {colorHex = GET_COLOR_BYID(color), name = name, t = tabS}))
  2126. end
  2127. if cantouch == 0 then
  2128. content = sformat("%s%s%s", content, lineS, sformat("GUI:setTouchEnabled(%s, false)", name))
  2129. end
  2130. return content
  2131. end
  2132. function TxtTranslator:load_render_Slider(swidget, callback, closeCB, ext)
  2133. local element = swidget.element
  2134. local sliderid = element.attr.sliderid
  2135. local ballPath = element.attr.ballimg or "public/bg_szjm_02_1.png"
  2136. local barPath = element.attr.barimg or "public/bg_szjm_02.png"
  2137. local bgPath = element.attr.bgimg or "public/bg_szjm_01.png"
  2138. local default = tonumber(element.attr.defvalue) or 0
  2139. local maxValue = tonumber(element.attr.maxvalue) or 100
  2140. local link = element.attr.link
  2141. local x = tonumber(element.attr.x) or 0
  2142. local y = tonumber(element.attr.y) or 0
  2143. local defaultPer = mfloor(default)
  2144. ballPath = string.format(getResFullPath("res/%s"), SUIHelper.fixImageFileName(ballPath))
  2145. barPath = string.format(getResFullPath("res/%s"), SUIHelper.fixImageFileName(barPath))
  2146. bgPath = string.format(getResFullPath("res/%s"), SUIHelper.fixImageFileName(bgPath))
  2147. local name = swidget.name
  2148. local id = swidget.id
  2149. local parent = ext and ext.parent or noParentCode
  2150. local content = sformat("local %s = GUI:Slider_Create(%s, \"%s\", %s, %s, \"%s\", \"%s\", \"%s\")",
  2151. name, parent, id, x, y, bgPath, barPath, ballPath)
  2152. content = sformat("%s%s%s", content, lineS, sformat("GUI:Slider_setMaxPercent(%s, %s)", name, maxValue))
  2153. content = sformat("%s%s%s", content, lineS, sformat("GUI:Slider_setPercent(%s, %s)", name, defaultPer))
  2154. return content
  2155. end
  2156. function TxtTranslator:load_render_ScrapePic(swidget, callback, closeCB, ext)
  2157. local element = swidget.element
  2158. local showImg = element.attr.showimg -- 展示图片
  2159. local maskImg = element.attr.maskimg or "public/mask_1.png" -- 遮罩图片
  2160. local clearHei = tonumber(element.attr.clearhei) or 16 -- 刮除高度
  2161. local moveTime = tonumber(element.attr.movetime) or 5 -- 移动时间
  2162. local beginTime = tonumber(element.attr.begintime) -- 开始按下时间
  2163. local link = element.attr.link
  2164. local x = tonumber(element.attr.x) or 0
  2165. local y = tonumber(element.attr.y) or 0
  2166. local path = SUIHelper.fixImageFileName(showImg)
  2167. local showPath = (path and path ~= "") and string.format(getResFullPath("res/%s"), path) or ""
  2168. local path = SUIHelper.fixImageFileName(maskImg)
  2169. local maskPath = (path and path ~= "") and string.format(getResFullPath("res/%s"), path)
  2170. local name = swidget.name
  2171. local id = swidget.id
  2172. local parent = ext and ext.parent or noParentCode
  2173. local content = sformat("local %s = GUI:ScrapePic_Create(%s, \"%s\", %s, %s, \"%s\", \"%s\", %s, %s%s)",
  2174. name, parent, id, x, y, showPath, maskPath, clearHei, moveTime, beginTime and sformat(", %s", beginTime) or "")
  2175. return content
  2176. end
  2177. function TxtTranslator:load_render_BmpText(swidget, callback, closeCB, ext)
  2178. local element = swidget.element
  2179. local text = element.attr.text or ""
  2180. local size = tonumber(element.attr.size) or defaultFontSize
  2181. local color = tonumber(element.attr.color) or defaultColorID
  2182. local link = element.attr.link
  2183. local clickInterval = (tonumber(element.attr.clickInterval) or 0) * 0.001
  2184. local tips = element.attr.tips
  2185. local tipsx = tonumber(element.attr.tipsx) or 0
  2186. local tipsy = tonumber(element.attr.tipsy) or 0
  2187. local tipWidth = tonumber(element.attr.tipWidth) or 1136
  2188. local x = tonumber(element.attr.x) or 0
  2189. local y = tonumber(element.attr.y) or 0
  2190. text = string.gsub(text, "\\", "\r\n")
  2191. text = string.trim(text)
  2192. local name = swidget.name
  2193. local id = swidget.id
  2194. local parent = ext and ext.parent or noParentCode
  2195. local content = sformat("local %s = GUI:BmpText_Create(%s, \"%s\", %s, %s, \"%s\", \"%s\")", name, parent, id, x, y, GET_COLOR_BYID(color), text)
  2196. content = sformat("%s%s%s", content, lineS, sformat("GUI:Text_setFontSize(%s, %s)", name, size))
  2197. return content
  2198. end
  2199. return TxtTranslator