Advertisement
Guest User

Untitled

a guest
Mar 18th, 2024
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 37.06 KB | None | 0 0
  1. local window = nil
  2.  
  3. local appearanceGroup = nil
  4. local colorModeGroup = nil
  5. local colorBoxGroup = nil
  6.  
  7. local floor = nil
  8. local movementCheck = nil
  9. local showFloorCheck = nil
  10. local showOutfitCheck = nil
  11. local showMountCheck = nil
  12. local showWingsCheck = nil
  13. local showAuraCheck = nil
  14. local showShaderCheck = nil
  15. local showBarsCheck = nil
  16.  
  17. local colorBoxes = {}
  18. local currentColorBox = nil
  19.  
  20. ignoreNextOutfitWindow = 0
  21. local floorTiles = 7
  22. local settingsFile = "/settings/outfit.json"
  23. local settings = {}
  24.  
  25. local tempOutfit = {}
  26. local ServerData = {
  27. currentOutfit = {},
  28. outfits = {},
  29. mounts = {},
  30. wings = {},
  31. auras = {},
  32. shaders = {},
  33. healthBars = {},
  34. manaBars = {}
  35. }
  36.  
  37. local AppearanceData = {
  38. "preset",
  39. "outfit",
  40. "mount",
  41. "wings",
  42. "aura",
  43. "shader",
  44. "healthBar",
  45. "manaBar"
  46. }
  47.  
  48. function init()
  49. connect(
  50. g_game,
  51. {
  52. onOpenOutfitWindow = create,
  53. onGameEnd = destroy
  54. }
  55. )
  56. end
  57.  
  58. function terminate()
  59. disconnect(
  60. g_game,
  61. {
  62. onOpenOutfitWindow = create,
  63. onGameEnd = destroy
  64. }
  65. )
  66. destroy()
  67. end
  68.  
  69. function onMovementChange(checkBox, checked)
  70. previewCreature:setAnimate(checked)
  71. settings.movement = checked
  72. end
  73.  
  74. function onShowFloorChange(checkBox, checked)
  75. if checked then
  76. floor:show()
  77.  
  78. -- Magic!
  79. local delay = 50
  80. periodicalEvent(
  81. function()
  82. if movementCheck:isChecked() then
  83. local direction = previewCreature:getDirection()
  84. if direction == Directions.North then
  85. local newMargin = floor:getMarginTop() + 8
  86. floor:setMarginTop(newMargin)
  87. if newMargin >= 96 then
  88. for i = 1, floorTiles do
  89. floor:moveChildToIndex(floor:getChildByIndex(floorTiles * floorTiles), 1)
  90. end
  91. floor:setMarginTop(32)
  92. end
  93. elseif direction == Directions.South then
  94. local newMargin = floor:getMarginBottom() + 8
  95. floor:setMarginBottom(newMargin)
  96. if newMargin >= 64 then
  97. for i = 1, floorTiles do
  98. floor:moveChildToIndex(floor:getChildByIndex(1), floorTiles * floorTiles)
  99. end
  100. floor:setMarginBottom(0)
  101. end
  102. elseif direction == Directions.East then
  103. local newMargin = floor:getMarginRight() + 8
  104. floor:setMarginRight(newMargin)
  105. if newMargin >= 64 then
  106. floor:setMarginRight(0)
  107. end
  108. elseif direction == Directions.West then
  109. local newMargin = floor:getMarginLeft() + 8
  110. floor:setMarginLeft(newMargin)
  111. if newMargin >= 64 then
  112. floor:setMarginLeft(0)
  113. end
  114. end
  115. else
  116. floor:setMargin(0)
  117. end
  118. end,
  119. function()
  120. return window and floor and showFloorCheck:isChecked()
  121. end,
  122. delay,
  123. delay
  124. )
  125. else
  126. floor:hide()
  127. end
  128.  
  129. settings.showFloor = checked
  130. end
  131.  
  132. function onShowMountChange(checkBox, checked)
  133. settings.showMount = checked
  134. updatePreview()
  135. end
  136.  
  137. function onShowOutfitChange(checkBox, checked)
  138. settings.showOutfit = checked
  139. showMountCheck:setEnabled(settings.showOutfit)
  140. showWingsCheck:setEnabled(settings.showOutfit)
  141. showAuraCheck:setEnabled(settings.showOutfit)
  142. showShaderCheck:setEnabled(settings.showOutfit)
  143. showBarsCheck:setEnabled(settings.showOutfit)
  144. updatePreview()
  145. end
  146.  
  147. function onShowAuraChange(checkBox, checked)
  148. settings.showAura = checked
  149. updatePreview()
  150. end
  151.  
  152. function onShowWingsChange(checkBox, checked)
  153. settings.showWings = checked
  154. updatePreview()
  155. end
  156.  
  157. function onShowShaderChange(checkBox, checked)
  158. settings.showShader = checked
  159. updatePreview()
  160. end
  161.  
  162. function onShowBarsChange(checkBox, checked)
  163. settings.showBars = checked
  164. updatePreview()
  165. end
  166.  
  167. local PreviewOptions = {
  168. ["showFloor"] = onShowFloorChange,
  169. ["showOutfit"] = onShowOutfitChange,
  170. ["showMount"] = onShowMountChange,
  171. ["showWings"] = onShowWingsChange,
  172. ["showAura"] = onShowAuraChange,
  173. ["showShader"] = onShowShaderChange,
  174. ["showBars"] = onShowBarsChange
  175. }
  176.  
  177. function create(currentOutfit, outfitList, mountList, wingList, auraList, shaderList, healthBarList, manaBarList)
  178. if ignoreNextOutfitWindow and g_clock.millis() < ignoreNextOutfitWindow + 1000 then
  179. return
  180. end
  181.  
  182. if window then
  183. destroy()
  184. end
  185.  
  186. if currentOutfit.shader == "" then
  187. currentOutfit.shader = "outfit_default"
  188. end
  189.  
  190. loadSettings()
  191.  
  192. ServerData = {
  193. currentOutfit = currentOutfit,
  194. outfits = outfitList,
  195. mounts = mountList,
  196. wings = wingList,
  197. auras = auraList,
  198. shaders = shaderList,
  199. healthBars = healthBarList,
  200. manaBars = manaBarList
  201. }
  202.  
  203. window = g_ui.displayUI("outfitwindow")
  204.  
  205. floor = window.preview.panel.floor
  206. for i = 1, floorTiles * floorTiles do
  207. g_ui.createWidget("FloorTile", floor)
  208. end
  209. floor:hide()
  210.  
  211. for _, appKey in ipairs(AppearanceData) do
  212. updateAppearanceText(appKey, "None")
  213. end
  214.  
  215. previewCreature = window.preview.panel.creature
  216.  
  217. if settings.currentPreset > 0 then
  218. local preset = settings.presets[settings.currentPreset]
  219. tempOutfit = table.copy(preset.outfit)
  220.  
  221. updateAppearanceText("preset", preset.title)
  222. else
  223. tempOutfit = currentOutfit
  224. end
  225.  
  226. updatePreview()
  227.  
  228. updateAppearanceTexts(currentOutfit)
  229.  
  230. if g_game.getFeature(GamePlayerMounts) then
  231. local isMount = g_game.getLocalPlayer():isMounted()
  232. if isMount then
  233. window.configure.mount.check:setEnabled(true)
  234. window.configure.mount.check:setChecked(true)
  235. else
  236. window.configure.mount.check:setEnabled(currentOutfit.mount > 0)
  237. window.configure.mount.check:setChecked(isMount and currentOutfit.mount > 0)
  238. end
  239. end
  240.  
  241. if currentOutfit.addons == 3 then
  242. window.configure.addon1.check:setChecked(true)
  243. window.configure.addon2.check:setChecked(true)
  244. elseif currentOutfit.addons == 2 then
  245. window.configure.addon1.check:setChecked(false)
  246. window.configure.addon2.check:setChecked(true)
  247. elseif currentOutfit.addons == 1 then
  248. window.configure.addon1.check:setChecked(true)
  249. window.configure.addon2.check:setChecked(false)
  250. end
  251. window.configure.addon1.check.onCheckChange = onAddonChange
  252. window.configure.addon2.check.onCheckChange = onAddonChange
  253.  
  254. configureAddons(currentOutfit.addons)
  255.  
  256. movementCheck = window.preview.panel.movement
  257. showFloorCheck = window.preview.options.showFloor.check
  258. showOutfitCheck = window.preview.options.showOutfit.check
  259. showMountCheck = window.preview.options.showMount.check
  260. showWingsCheck = window.preview.options.showWings.check
  261. showAuraCheck = window.preview.options.showAura.check
  262. showShaderCheck = window.preview.options.showShader.check
  263. showBarsCheck = window.preview.options.showBars.check
  264.  
  265. movementCheck.onCheckChange = onMovementChange
  266. for _, option in ipairs(window.preview.options:getChildren()) do
  267. option.check.onCheckChange = PreviewOptions[option:getId()]
  268. end
  269.  
  270. movementCheck:setChecked(settings.movement)
  271. showFloorCheck:setChecked(settings.showFloor)
  272.  
  273. if not settings.showOutfit then
  274. showMountCheck:setEnabled(false)
  275. showWingsCheck:setEnabled(false)
  276. showAuraCheck:setEnabled(false)
  277. showShaderCheck:setEnabled(false)
  278. showBarsCheck:setEnabled(false)
  279. end
  280.  
  281. showOutfitCheck:setChecked(settings.showOutfit)
  282. showMountCheck:setChecked(settings.showMount)
  283. showWingsCheck:setChecked(settings.showWings)
  284. showAuraCheck:setChecked(settings.showAura)
  285. showShaderCheck:setChecked(settings.showShader)
  286. showBarsCheck:setChecked(settings.showBars)
  287.  
  288. colorBoxGroup = UIRadioGroup.create()
  289. for j = 0, 6 do
  290. for i = 0, 18 do
  291. local colorBox = g_ui.createWidget("ColorBox", window.appearance.colorBoxPanel)
  292. local outfitColor = getOutfitColor(j * 19 + i)
  293. colorBox:setImageColor(outfitColor)
  294. colorBox:setId("colorBox" .. j * 19 + i)
  295. colorBox.colorId = j * 19 + i
  296.  
  297. if colorBox.colorId == currentOutfit.head then
  298. currentColorBox = colorBox
  299. colorBox:setChecked(true)
  300. end
  301. colorBoxGroup:addWidget(colorBox)
  302. end
  303. end
  304.  
  305. colorBoxGroup.onSelectionChange = onColorCheckChange
  306.  
  307. appearanceGroup = UIRadioGroup.create()
  308. appearanceGroup:addWidget(window.appearance.settings.preset.check)
  309. appearanceGroup:addWidget(window.appearance.settings.outfit.check)
  310. appearanceGroup:addWidget(window.appearance.settings.mount.check)
  311. appearanceGroup:addWidget(window.appearance.settings.aura.check)
  312. appearanceGroup:addWidget(window.appearance.settings.wings.check)
  313. appearanceGroup:addWidget(window.appearance.settings.shader.check)
  314. appearanceGroup:addWidget(window.appearance.settings.healthBar.check)
  315. appearanceGroup:addWidget(window.appearance.settings.manaBar.check)
  316.  
  317. appearanceGroup.onSelectionChange = onAppearanceChange
  318. appearanceGroup:selectWidget(window.appearance.settings.preset.check)
  319.  
  320. colorModeGroup = UIRadioGroup.create()
  321. colorModeGroup:addWidget(window.appearance.colorMode.head)
  322. colorModeGroup:addWidget(window.appearance.colorMode.primary)
  323. colorModeGroup:addWidget(window.appearance.colorMode.secondary)
  324. colorModeGroup:addWidget(window.appearance.colorMode.detail)
  325.  
  326. colorModeGroup.onSelectionChange = onColorModeChange
  327. colorModeGroup:selectWidget(window.appearance.colorMode.head)
  328.  
  329. window.preview.options.showMount:setVisible(g_game.getFeature(GamePlayerMounts))
  330. window.preview.options.showWings:setVisible(g_game.getFeature(GameWingsAndAura))
  331. window.preview.options.showAura:setVisible(g_game.getFeature(GameWingsAndAura))
  332. window.preview.options.showShader:setVisible(g_game.getFeature(GameOutfitShaders))
  333.  
  334. window.appearance.settings.mount:setVisible(g_game.getFeature(GamePlayerMounts))
  335. window.appearance.settings.wings:setVisible(g_game.getFeature(GameWingsAndAura))
  336. window.appearance.settings.aura:setVisible(g_game.getFeature(GameWingsAndAura))
  337. window.appearance.settings.shader:setVisible(g_game.getFeature(GameOutfitShaders))
  338. window.appearance.settings.healthBar:setVisible(g_game.getFeature(GameHealthInfoBackground))
  339. window.appearance.settings.manaBar:setVisible(g_game.getFeature(GameHealthInfoBackground))
  340.  
  341. window.configure.mount:setVisible(g_game.getFeature(GamePlayerMounts))
  342.  
  343. window.listSearch.search.onKeyPress = onFilterSearch
  344. end
  345.  
  346. function destroy()
  347. if window then
  348. window:destroy()
  349. window = nil
  350.  
  351. floor = nil
  352. movementCheck = nil
  353. showFloorCheck = nil
  354. showOutfitCheck = nil
  355. showMountCheck = nil
  356. showWingsCheck = nil
  357. showAuraCheck = nil
  358. showShaderCheck = nil
  359. showBarsCheck = nil
  360.  
  361. colorBoxes = {}
  362. currentColorBox = nil
  363.  
  364. appearanceGroup:destroy()
  365. appearanceGroup = nil
  366. colorModeGroup:destroy()
  367. colorModeGroup = nil
  368. colorBoxGroup:destroy()
  369. colorBoxGroup = nil
  370.  
  371. ServerData = {
  372. currentOutfit = {},
  373. outfits = {},
  374. mounts = {},
  375. wings = {},
  376. auras = {},
  377. shaders = {},
  378. healthBars = {},
  379. manaBars = {}
  380. }
  381.  
  382. saveSettings()
  383. settings = {}
  384. end
  385. end
  386.  
  387. function configureAddons(addons)
  388. local hasAddon1 = addons == 1 or addons == 3
  389. local hasAddon2 = addons == 2 or addons == 3
  390. window.configure.addon1.check:setEnabled(hasAddon1)
  391. window.configure.addon2.check:setEnabled(hasAddon2)
  392.  
  393. window.configure.addon1.check.onCheckChange = nil
  394. window.configure.addon2.check.onCheckChange = nil
  395. window.configure.addon1.check:setChecked(false)
  396. window.configure.addon2.check:setChecked(false)
  397. if tempOutfit.addons == 3 then
  398. window.configure.addon1.check:setChecked(true)
  399. window.configure.addon2.check:setChecked(true)
  400. elseif tempOutfit.addons == 2 then
  401. window.configure.addon1.check:setChecked(false)
  402. window.configure.addon2.check:setChecked(true)
  403. elseif tempOutfit.addons == 1 then
  404. window.configure.addon1.check:setChecked(true)
  405. window.configure.addon2.check:setChecked(false)
  406. end
  407. window.configure.addon1.check.onCheckChange = onAddonChange
  408. window.configure.addon2.check.onCheckChange = onAddonChange
  409. end
  410.  
  411. function newPreset()
  412. if not settings.presets then
  413. settings.presets = {}
  414. end
  415.  
  416. local presetWidget = g_ui.createWidget("PresetButton", window.presetsList)
  417. local presetId = #settings.presets + 1
  418. presetWidget:setId(presetId)
  419. presetWidget.title:setText("New Preset")
  420. local outfitCopy = table.copy(tempOutfit)
  421. presetWidget.creature:setOutfit(outfitCopy)
  422. presetWidget.creature:setCenter(true)
  423.  
  424. settings.presets[presetId] = {
  425. title = "New Preset",
  426. outfit = outfitCopy,
  427. mounted = window.configure.mount.check:isChecked()
  428. }
  429.  
  430. presetWidget:focus()
  431. window.presetsList:ensureChildVisible(presetWidget, {x = 0, y = 196})
  432. end
  433.  
  434. function deletePreset()
  435. local presetId = settings.currentPreset
  436. if presetId == 0 then
  437. local focused = window.presetsList:getFocusedChild()
  438. if focused then
  439. presetId = tonumber(focused:getId())
  440. end
  441. end
  442.  
  443. if not presetId or presetId == 0 then
  444. return
  445. end
  446.  
  447. table.remove(settings.presets, presetId)
  448. window.presetsList[presetId]:destroy()
  449. settings.currentPreset = 0
  450. local newId = 1
  451. for _, child in ipairs(window.presetsList:getChildren()) do
  452. child:setId(newId)
  453. newId = newId + 1
  454. end
  455. updateAppearanceText("preset", "None")
  456. end
  457.  
  458. function savePreset()
  459. local presetId = settings.currentPreset
  460. if presetId == 0 then
  461. local focused = window.presetsList:getFocusedChild()
  462. if focused then
  463. presetId = tonumber(focused:getId())
  464. end
  465. end
  466.  
  467. if not presetId or presetId == 0 then
  468. return
  469. end
  470.  
  471. local outfitCopy = table.copy(tempOutfit)
  472. window.presetsList[presetId].creature:setOutfit(outfitCopy)
  473. window.presetsList[presetId].creature:setCenter(true)
  474. settings.presets[presetId].outfit = outfitCopy
  475. settings.presets[presetId].mounted = window.configure.mount.check:isChecked()
  476. settings.currentPreset = presetId
  477. end
  478.  
  479. function renamePreset()
  480. local presetId = settings.currentPreset
  481. if presetId == 0 then
  482. local focused = window.presetsList:getFocusedChild()
  483. if focused then
  484. presetId = tonumber(focused:getId())
  485. end
  486. end
  487.  
  488. if not presetId or presetId == 0 then
  489. return
  490. end
  491.  
  492. local presetWidget = window.presetsList[presetId]
  493. presetWidget.title:hide()
  494. presetWidget.rename.input:setText("")
  495. presetWidget.rename.save.onClick = function()
  496. saveRename(presetId)
  497. end
  498. presetWidget.rename:show()
  499. end
  500.  
  501. function saveRename(presetId)
  502. local presetWidget = window.presetsList[presetId]
  503. if not presetWidget then
  504. return
  505. end
  506.  
  507. local newTitle = presetWidget.rename.input:getText():trim()
  508. presetWidget.rename.input:setText("")
  509. presetWidget.rename:hide()
  510. presetWidget.title:setText(newTitle)
  511. presetWidget.title:show()
  512. settings.presets[presetId].title = newTitle
  513.  
  514. if presetId == settings.currentPreset then
  515. updateAppearanceText("preset", newTitle)
  516. end
  517. end
  518.  
  519. function onAppearanceChange(widget, selectedWidget)
  520. local id = selectedWidget:getParent():getId()
  521. if id == "preset" then
  522. showPresets()
  523. elseif id == "outfit" then
  524. showOutfits()
  525. elseif id == "mount" then
  526. showMounts()
  527. elseif id == "aura" then
  528. showAuras()
  529. elseif id == "wings" then
  530. showWings()
  531. elseif id == "shader" then
  532. showShaders()
  533. elseif id == "healthBar" then
  534. showHealthBars()
  535. elseif id == "manaBar" then
  536. showManaBars()
  537. end
  538. end
  539.  
  540. function showPresets()
  541. window.listSearch:hide()
  542. window.selectionList:hide()
  543. window.selectionScroll:hide()
  544.  
  545. local focused = nil
  546. if window.presetsList:getChildCount() == 0 and settings.presets then
  547. for presetId, preset in ipairs(settings.presets) do
  548. local presetWidget = g_ui.createWidget("PresetButton", window.presetsList)
  549. presetWidget:setId(presetId)
  550. presetWidget.title:setText(preset.title)
  551. presetWidget.creature:setOutfit(preset.outfit)
  552. presetWidget.creature:setCenter(true)
  553. if presetId == settings.currentPreset then
  554. focused = presetId
  555. end
  556. end
  557. end
  558.  
  559. if focused then
  560. local w = window.presetsList[focused]
  561. w:focus()
  562. window.presetsList:ensureChildVisible(w, {x = 0, y = 196})
  563. end
  564.  
  565. window.presetsList.onChildFocusChange = onPresetSelect
  566. window.presetsList:show()
  567. window.presetsScroll:show()
  568. window.presetButtons:show()
  569. end
  570.  
  571. function showOutfits()
  572. window.presetsList:hide()
  573. window.presetsScroll:hide()
  574. window.presetButtons:hide()
  575.  
  576. window.selectionList.onChildFocusChange = nil
  577. window.selectionList:destroyChildren()
  578.  
  579. local focused = nil
  580. for _, outfitData in ipairs(ServerData.outfits) do
  581. local button = g_ui.createWidget("SelectionButton", window.selectionList)
  582. button:setId(outfitData[1])
  583.  
  584. local outfit = table.copy(previewCreature:getOutfit())
  585. outfit.type = outfitData[1]
  586. outfit.addons = outfitData[3]
  587. outfit.mount = 0
  588. outfit.aura = 0
  589. outfit.wings = 0
  590. outfit.shader = "outfit_default"
  591. outfit.healthBar = 0
  592. outfit.manaBar = 0
  593. button.outfit:setOutfit(outfit)
  594. button.outfit:setCenter(true)
  595. button.name:setText(outfitData[2])
  596. if tempOutfit.type == outfitData[1] then
  597. focused = outfitData[1]
  598. configureAddons(outfitData[3])
  599. end
  600. end
  601.  
  602. if focused then
  603. local w = window.selectionList[focused]
  604. w:focus()
  605. window.selectionList:ensureChildVisible(w, {x = 0, y = 196})
  606. end
  607.  
  608. window.selectionList.onChildFocusChange = onOutfitSelect
  609. window.selectionList:show()
  610. window.selectionScroll:show()
  611. window.listSearch:show()
  612. end
  613.  
  614. function showMounts()
  615. window.presetsList:hide()
  616. window.presetsScroll:hide()
  617. window.presetButtons:hide()
  618.  
  619. window.selectionList.onChildFocusChange = nil
  620. window.selectionList:destroyChildren()
  621.  
  622. local focused = nil
  623. for _, mountData in ipairs(ServerData.mounts) do
  624. local button = g_ui.createWidget("SelectionButton", window.selectionList)
  625. button:setId(mountData[1])
  626.  
  627. button.outfit:setOutfit({type = mountData[1]})
  628. button.outfit:setCenter(true)
  629. button.name:setText(mountData[2])
  630. if tempOutfit.mount == mountData[1] then
  631. focused = mountData[1]
  632. end
  633. end
  634.  
  635. if #ServerData.mounts == 1 then
  636. window.selectionList:focusChild(nil)
  637. end
  638.  
  639. window.configure.mount.check:setEnabled(focused)
  640. window.configure.mount.check:setChecked(g_game.getLocalPlayer():isMounted() and focused)
  641.  
  642. if focused ~= nil then
  643. local w = window.selectionList[focused]
  644. w:focus()
  645. window.selectionList:ensureChildVisible(w, {x = 0, y = 196})
  646. end
  647.  
  648. window.selectionList.onChildFocusChange = onMountSelect
  649. window.selectionList:show()
  650. window.selectionScroll:show()
  651. window.listSearch:show()
  652. end
  653.  
  654. function showAuras()
  655. window.presetsList:hide()
  656. window.presetsScroll:hide()
  657. window.presetButtons:hide()
  658.  
  659. window.selectionList.onChildFocusChange = nil
  660. window.selectionList:destroyChildren()
  661.  
  662. local focused = nil
  663. do
  664. local button = g_ui.createWidget("SelectionButton", window.selectionList)
  665. button:setId("0")
  666.  
  667. button.outfit:setOutfit({type = 0})
  668. button.name:setText("None")
  669. if tempOutfit.aura == 0 then
  670. focused = 0
  671. end
  672. end
  673.  
  674. for _, auraData in ipairs(ServerData.auras) do
  675. local button = g_ui.createWidget("SelectionButton", window.selectionList)
  676. button:setId(auraData[1])
  677.  
  678. button.outfit:setOutfit({type = auraData[1]})
  679. button.outfit:setAnimate(true)
  680. button.name:setText(auraData[2])
  681. if tempOutfit.aura == auraData[1] then
  682. focused = auraData[1]
  683. end
  684. end
  685.  
  686. if focused ~= nil then
  687. local w = window.selectionList[focused]
  688. w:focus()
  689. window.selectionList:ensureChildVisible(w, {x = 0, y = 196})
  690. end
  691.  
  692. window.selectionList.onChildFocusChange = onAuraSelect
  693. window.selectionList:show()
  694. window.selectionScroll:show()
  695. window.listSearch:show()
  696. end
  697.  
  698. function showWings()
  699. window.presetsList:hide()
  700. window.presetsScroll:hide()
  701. window.presetButtons:hide()
  702.  
  703. window.selectionList.onChildFocusChange = nil
  704. window.selectionList:destroyChildren()
  705.  
  706. local focused = nil
  707. do
  708. local button = g_ui.createWidget("SelectionButton", window.selectionList)
  709. button:setId("0")
  710.  
  711. button.outfit:setOutfit({type = 0})
  712. button.name:setText("None")
  713. if tempOutfit.wings == 0 then
  714. focused = 0
  715. end
  716. end
  717.  
  718. for _, wingsData in ipairs(ServerData.wings) do
  719. local button = g_ui.createWidget("SelectionButton", window.selectionList)
  720. button:setId(wingsData[1])
  721.  
  722. button.outfit:setOutfit({type = wingsData[1]})
  723. button.outfit:setAnimate(true)
  724. button.name:setText(wingsData[2])
  725. if tempOutfit.wings == wingsData[1] then
  726. focused = wingsData[1]
  727. end
  728. end
  729.  
  730. if focused ~= nil then
  731. local w = window.selectionList[focused]
  732. w:focus()
  733. window.selectionList:ensureChildVisible(w, {x = 0, y = 196})
  734. end
  735.  
  736. window.selectionList.onChildFocusChange = onWingsSelect
  737. window.selectionList:show()
  738. window.selectionScroll:show()
  739. window.listSearch:show()
  740. end
  741.  
  742. function showShaders()
  743. window.presetsList:hide()
  744. window.presetsScroll:hide()
  745. window.presetButtons:hide()
  746.  
  747. window.selectionList.onChildFocusChange = nil
  748. window.selectionList:destroyChildren()
  749.  
  750. local focused = nil
  751. do
  752. local button = g_ui.createWidget("SelectionButton", window.selectionList)
  753. button:setId("outfit_default")
  754.  
  755. button.outfit:setOutfit({type = tempOutfit.type, addons = tempOutfit.addons, shader = "outfit_default"})
  756. button.name:setText("None")
  757. if tempOutfit.shader == "outfit_default" then
  758. focused = "outfit_default"
  759. end
  760. end
  761.  
  762. for _, shaderData in ipairs(ServerData.shaders) do
  763. local button = g_ui.createWidget("SelectionButton", window.selectionList)
  764. button:setId(shaderData[2])
  765.  
  766. button.outfit:setOutfit({type = tempOutfit.type, addons = tempOutfit.addons, shader = shaderData[2]})
  767. button.outfit:setCenter(true)
  768. button.name:setText(shaderData[2])
  769. if tempOutfit.shader == shaderData[2] then
  770. focused = shaderData[2]
  771. end
  772. end
  773.  
  774. if focused ~= nil then
  775. local w = window.selectionList[focused]
  776. w:focus()
  777. window.selectionList:ensureChildVisible(w, {x = 0, y = 196})
  778. end
  779.  
  780. window.selectionList.onChildFocusChange = onShaderSelect
  781. window.selectionList:show()
  782. window.selectionScroll:show()
  783. window.listSearch:show()
  784. end
  785.  
  786. function showHealthBars()
  787. window.presetsList:hide()
  788. window.presetsScroll:hide()
  789. window.presetButtons:hide()
  790.  
  791. window.selectionList.onChildFocusChange = nil
  792. window.selectionList:destroyChildren()
  793.  
  794. local focused = nil
  795. do
  796. local button = g_ui.createWidget("SelectionButton", window.selectionList)
  797. button:setId("0")
  798.  
  799. button.outfit:hide()
  800. button.name:setText("None")
  801. if tempOutfit.healthBar == 0 then
  802. focused = 0
  803. end
  804. end
  805.  
  806. for _, barData in ipairs(ServerData.healthBars) do
  807. local button = g_ui.createWidget("SelectionButton", window.selectionList)
  808. button:setId(barData[1])
  809.  
  810. button.outfit:hide()
  811.  
  812. button.bar:setImageSource(g_healthBars.getHealthBarPath(barData[1]))
  813. button.bar:show()
  814.  
  815. button.name:setText(barData[2])
  816. if tempOutfit.healthBar == barData[1] then
  817. focused = barData[1]
  818. end
  819. end
  820.  
  821. if focused ~= nil then
  822. local w = window.selectionList[focused]
  823. w:focus()
  824. window.selectionList:ensureChildVisible(w, {x = 0, y = 196})
  825. end
  826.  
  827. window.selectionList.onChildFocusChange = onHealthBarSelect
  828. window.selectionList:show()
  829. window.selectionScroll:show()
  830. window.listSearch:show()
  831. end
  832.  
  833. function showManaBars()
  834. window.presetsList:hide()
  835. window.presetsScroll:hide()
  836. window.presetButtons:hide()
  837.  
  838. window.selectionList.onChildFocusChange = nil
  839. window.selectionList:destroyChildren()
  840.  
  841. local focused = nil
  842. do
  843. local button = g_ui.createWidget("SelectionButton", window.selectionList)
  844. button:setId("0")
  845.  
  846. button.outfit:hide()
  847. button.name:setText("None")
  848. if tempOutfit.manaBar == 0 then
  849. focused = 0
  850. end
  851. end
  852.  
  853. for _, barData in ipairs(ServerData.manaBars) do
  854. local button = g_ui.createWidget("SelectionButton", window.selectionList)
  855. button:setId(barData[1])
  856.  
  857. button.outfit:hide()
  858.  
  859. button.bar:setImageSource(g_healthBars.getManaBarPath(barData[1]))
  860. button.bar:show()
  861.  
  862. button.name:setText(barData[2])
  863. if tempOutfit.manaBar == barData[1] then
  864. focused = barData[1]
  865. end
  866. end
  867.  
  868. if focused ~= nil then
  869. local w = window.selectionList[focused]
  870. w:focus()
  871. window.selectionList:ensureChildVisible(w, {x = 0, y = 196})
  872. end
  873.  
  874. window.selectionList.onChildFocusChange = onManaBarSelect
  875. window.selectionList:show()
  876. window.selectionScroll:show()
  877. window.listSearch:show()
  878. end
  879.  
  880. function onPresetSelect(list, focusedChild, unfocusedChild, reason)
  881. if focusedChild then
  882. local presetId = tonumber(focusedChild:getId())
  883. local preset = settings.presets[presetId]
  884. tempOutfit = table.copy(preset.outfit)
  885.  
  886. for _, outfitData in ipairs(ServerData.outfits) do
  887. if tempOutfit.type == outfitData[1] then
  888. configureAddons(outfitData[3])
  889. break
  890. end
  891. end
  892.  
  893. if g_game.getFeature(GamePlayerMounts) then
  894. window.configure.mount.check:setChecked(preset.mounted and tempOutfit.mount > 0)
  895. end
  896.  
  897. settings.currentPreset = presetId
  898.  
  899. updatePreview()
  900.  
  901. updateAppearanceTexts(tempOutfit)
  902. updateAppearanceText("preset", preset.title)
  903. end
  904. end
  905.  
  906. function onOutfitSelect(list, focusedChild, unfocusedChild, reason)
  907. if focusedChild then
  908. local outfitType = tonumber(focusedChild:getId())
  909. local outfit = focusedChild.outfit:getOutfit()
  910. tempOutfit.type = outfit.type
  911. tempOutfit.addons = outfit.addons
  912.  
  913. deselectPreset()
  914.  
  915. configureAddons(outfit.addons)
  916.  
  917. if showOutfitCheck:isChecked() then
  918. updatePreview()
  919. end
  920. updateAppearanceText("outfit", focusedChild.name:getText())
  921. end
  922. end
  923.  
  924. function onMountSelect(list, focusedChild, unfocusedChild, reason)
  925. if focusedChild then
  926. local mountType = tonumber(focusedChild:getId())
  927. tempOutfit.mount = mountType
  928.  
  929. deselectPreset()
  930.  
  931. if showMountCheck:isChecked() then
  932. updatePreview()
  933. end
  934.  
  935. window.configure.mount.check:setEnabled(tempOutfit.mount > 0)
  936. window.configure.mount.check:setChecked(g_game.getLocalPlayer():isMounted() and tempOutfit.mount > 0)
  937.  
  938. updateAppearanceText("mount", focusedChild.name:getText())
  939. end
  940. end
  941.  
  942. function onAuraSelect(list, focusedChild, unfocusedChild, reason)
  943. if focusedChild then
  944. local auraType = tonumber(focusedChild:getId())
  945. tempOutfit.aura = auraType
  946. updatePreview()
  947.  
  948. deselectPreset()
  949.  
  950. updateAppearanceText("aura", focusedChild.name:getText())
  951. end
  952. end
  953.  
  954. function onWingsSelect(list, focusedChild, unfocusedChild, reason)
  955. if focusedChild then
  956. local wingsType = tonumber(focusedChild:getId())
  957. tempOutfit.wings = wingsType
  958. updatePreview()
  959.  
  960. deselectPreset()
  961.  
  962. updateAppearanceText("wings", focusedChild.name:getText())
  963. end
  964. end
  965.  
  966. function onShaderSelect(list, focusedChild, unfocusedChild, reason)
  967. if focusedChild then
  968. local shaderType = focusedChild:getId()
  969. tempOutfit.shader = shaderType
  970. updatePreview()
  971.  
  972. deselectPreset()
  973.  
  974. updateAppearanceText("shader", focusedChild.name:getText())
  975. end
  976. end
  977.  
  978. function onHealthBarSelect(list, focusedChild, unfocusedChild, reason)
  979. if focusedChild then
  980. local barType = tonumber(focusedChild:getId())
  981. tempOutfit.healthBar = barType
  982. updatePreview()
  983.  
  984. deselectPreset()
  985.  
  986. updateAppearanceText("healthBar", focusedChild.name:getText())
  987. end
  988. end
  989.  
  990. function onManaBarSelect(list, focusedChild, unfocusedChild, reason)
  991. if focusedChild then
  992. local barType = tonumber(focusedChild:getId())
  993. tempOutfit.manaBar = barType
  994. updatePreview()
  995.  
  996. deselectPreset()
  997.  
  998. updateAppearanceText("manaBar", focusedChild.name:getText())
  999. end
  1000. end
  1001.  
  1002. function updateAppearanceText(widget, text)
  1003. window.appearance.settings[widget].name:setText(text)
  1004. end
  1005.  
  1006. function updateAppearanceTexts(outfit)
  1007. for _, appKey in ipairs(AppearanceData) do
  1008. updateAppearanceText(appKey, "None")
  1009. end
  1010.  
  1011. for key, value in pairs(outfit) do
  1012. local newKey = key
  1013. local appKey = key
  1014. if key == "type" then
  1015. newKey = "outfits"
  1016. appKey = "outfit"
  1017. elseif key == "wings" then
  1018. newKey = "wings"
  1019. appKey = "wings"
  1020. else
  1021. newKey = key .. "s"
  1022. appKey = key
  1023. end
  1024. local dataTable = ServerData[newKey]
  1025. if dataTable then
  1026. for _, data in ipairs(dataTable) do
  1027. if outfit[key] == data[1] or outfit[key] == data[2] then
  1028. updateAppearanceText(appKey, data[2])
  1029. end
  1030. end
  1031. end
  1032. end
  1033. end
  1034.  
  1035. function deselectPreset()
  1036. settings.currentPreset = 0
  1037. end
  1038.  
  1039. function onAddonChange(widget, checked)
  1040. local addonId = widget:getParent():getId()
  1041.  
  1042. local addons = tempOutfit.addons
  1043. if addonId == "addon1" then
  1044. addons = checked and addons + 1 or addons - 1
  1045. elseif addonId == "addon2" then
  1046. addons = checked and addons + 2 or addons - 2
  1047. end
  1048.  
  1049. settings.currentPreset = 0
  1050.  
  1051. tempOutfit.addons = addons
  1052. updatePreview()
  1053. if appearanceGroup:getSelectedWidget() == window.appearance.settings.outfit.check then
  1054. showOutfits()
  1055. end
  1056. end
  1057.  
  1058. function onColorModeChange(widget, selectedWidget)
  1059. local colorMode = selectedWidget:getId()
  1060. if colorMode == "head" then
  1061. colorBoxGroup:selectWidget(window.appearance.colorBoxPanel["colorBox" .. tempOutfit.head])
  1062. elseif colorMode == "primary" then
  1063. colorBoxGroup:selectWidget(window.appearance.colorBoxPanel["colorBox" .. tempOutfit.body])
  1064. elseif colorMode == "secondary" then
  1065. colorBoxGroup:selectWidget(window.appearance.colorBoxPanel["colorBox" .. tempOutfit.legs])
  1066. elseif colorMode == "detail" then
  1067. colorBoxGroup:selectWidget(window.appearance.colorBoxPanel["colorBox" .. tempOutfit.feet])
  1068. end
  1069. end
  1070.  
  1071. function onColorCheckChange(widget, selectedWidget)
  1072. local colorId = selectedWidget.colorId
  1073. local colorMode = colorModeGroup:getSelectedWidget():getId()
  1074. if colorMode == "head" then
  1075. tempOutfit.head = colorId
  1076. elseif colorMode == "primary" then
  1077. tempOutfit.body = colorId
  1078. elseif colorMode == "secondary" then
  1079. tempOutfit.legs = colorId
  1080. elseif colorMode == "detail" then
  1081. tempOutfit.feet = colorId
  1082. end
  1083.  
  1084. updatePreview()
  1085.  
  1086. if appearanceGroup:getSelectedWidget() == window.appearance.settings.outfit.check then
  1087. showOutfits()
  1088. end
  1089. end
  1090.  
  1091. function updatePreview()
  1092. local direction = previewCreature:getDirection()
  1093. local previewOutfit = table.copy(tempOutfit)
  1094.  
  1095. if not settings.showOutfit then
  1096. previewCreature:hide()
  1097. else
  1098. previewCreature:show()
  1099. end
  1100.  
  1101. if not settings.showMount then
  1102. previewOutfit.mount = 0
  1103. end
  1104.  
  1105. if not settings.showAura then
  1106. previewOutfit.aura = 0
  1107. end
  1108.  
  1109. if not settings.showWings then
  1110. previewOutfit.wings = 0
  1111. end
  1112.  
  1113. if not settings.showShader then
  1114. previewOutfit.shader = "outfit_default"
  1115. end
  1116.  
  1117. if not settings.showBars then
  1118. previewOutfit.healthBar = 0
  1119. previewOutfit.manaBar = 0
  1120. window.preview.panel.bars:hide()
  1121. else
  1122. if g_game.getFeature(GamePlayerMounts) and settings.showMount and previewOutfit.mount > 0 then
  1123. window.preview.panel.bars:setMarginTop(45)
  1124. window.preview.panel.bars:setMarginLeft(25)
  1125. else
  1126. window.preview.panel.bars:setMarginTop(30)
  1127. window.preview.panel.bars:setMarginLeft(15)
  1128. end
  1129. local name = g_game.getCharacterName()
  1130. window.preview.panel.bars.name:setText(name)
  1131. if name:find("g") or name:find("j") or name:find("p") or name:find("q") or name:find("y") then
  1132. window.preview.panel.bars.name:setHeight(14)
  1133. else
  1134. window.preview.panel.bars.name:setHeight(11)
  1135. end
  1136.  
  1137. local healthBar = window.preview.panel.bars.healthBar
  1138. local manaBar = window.preview.panel.bars.manaBar
  1139. if not g_game.getFeature(GameHealthInfoBackground) then
  1140. manaBar:setMarginTop(0)
  1141. healthBar:setMarginTop(1)
  1142. healthBar.image:setMargin(0)
  1143. healthBar.image:hide()
  1144. manaBar.image:setMargin(0)
  1145. manaBar.image:hide(0)
  1146. else
  1147. local healthOffset = g_healthBars.getHealthBarOffset(previewOutfit.healthBar)
  1148. local healthBarOffset = g_healthBars.getHealthBarOffsetBar(previewOutfit.healthBar)
  1149. local manaOffset = g_healthBars.getHealthBarOffset(previewOutfit.manaBar)
  1150.  
  1151. if previewOutfit.healthBar > 0 then
  1152. healthBar.image:setImageSource(g_healthBars.getHealthBarPath(previewOutfit.healthBar))
  1153.  
  1154. healthBar:setMarginTop(-healthOffset.y + 1)
  1155. healthBar.image:setMarginTop(-healthOffset.y)
  1156. healthBar.image:setMarginBottom(-healthOffset.y)
  1157. healthBar.image:setMarginLeft(-healthOffset.x)
  1158. healthBar.image:setMarginRight(-healthOffset.x)
  1159. healthBar.image:show()
  1160. manaBar:setMarginTop(healthBarOffset.y + 1 - manaOffset.y)
  1161. else
  1162. manaBar:setMarginTop(0)
  1163. healthBar:setMarginTop(1)
  1164. healthBar.image:setMargin(0)
  1165. healthBar.image:hide()
  1166. end
  1167.  
  1168. if previewOutfit.manaBar > 0 then
  1169. manaBar.image:setImageSource(g_healthBars.getManaBarPath(previewOutfit.manaBar))
  1170.  
  1171. manaBar:setMarginTop(healthBarOffset.y + 1 - manaOffset.y)
  1172.  
  1173. manaBar.image:setMarginTop(-manaOffset.y)
  1174. manaBar.image:setMarginBottom(-manaOffset.y)
  1175. manaBar.image:setMarginLeft(-manaOffset.x)
  1176. manaBar.image:setMarginRight(-manaOffset.x)
  1177. manaBar.image:show()
  1178. else
  1179. manaBar.image:setMargin(0)
  1180. manaBar.image:hide(0)
  1181. end
  1182. end
  1183. window.preview.panel.bars:show()
  1184. end
  1185.  
  1186. previewCreature:setOutfit(previewOutfit)
  1187. previewCreature:setDirection(direction)
  1188. end
  1189.  
  1190. function rotate(value)
  1191. local direction = previewCreature:getDirection()
  1192. direction = direction + value
  1193. if direction < Directions.North then
  1194. direction = Directions.West
  1195. elseif direction > Directions.West then
  1196. direction = Directions.North
  1197. end
  1198. previewCreature:setDirection(direction)
  1199. floor:setMargin(0)
  1200. end
  1201.  
  1202. function onFilterSearch()
  1203. addEvent(
  1204. function()
  1205. local searchText = window.listSearch.search:getText():lower():trim()
  1206. local children = window.selectionList:getChildren()
  1207. if searchText:len() >= 1 then
  1208. for _, child in ipairs(children) do
  1209. local text = child.name:getText():lower()
  1210. if text:find(searchText) then
  1211. child:show()
  1212. else
  1213. child:hide()
  1214. end
  1215. end
  1216. else
  1217. for _, child in ipairs(children) do
  1218. child:show()
  1219. end
  1220. end
  1221. end
  1222. )
  1223. end
  1224.  
  1225. function saveSettings()
  1226. if not g_resources.fileExists(settingsFile) then
  1227. g_resources.makeDir("/settings")
  1228. g_resources.writeFileContents(settingsFile, "[]")
  1229. end
  1230.  
  1231. local fullSettings = {}
  1232. do
  1233. local json_status, json_data =
  1234. pcall(
  1235. function()
  1236. return json.decode(g_resources.readFileContents(settingsFile))
  1237. end
  1238. )
  1239.  
  1240. if not json_status then
  1241. g_logger.error("[saveSettings] Couldn't load JSON: " .. json_data)
  1242. return
  1243. end
  1244. fullSettings = json_data
  1245. end
  1246.  
  1247. fullSettings[g_game.getCharacterName()] = settings
  1248.  
  1249. local json_status, json_data =
  1250. pcall(
  1251. function()
  1252. return json.encode(fullSettings)
  1253. end
  1254. )
  1255.  
  1256. if not json_status then
  1257. g_logger.error("[saveSettings] Couldn't save JSON: " .. json_data)
  1258. return
  1259. end
  1260.  
  1261. g_resources.writeFileContents(settingsFile, json.encode(fullSettings))
  1262. end
  1263.  
  1264. function loadSettings()
  1265. if not g_resources.fileExists(settingsFile) then
  1266. g_resources.makeDir("/settings")
  1267. end
  1268.  
  1269. if g_resources.fileExists(settingsFile) then
  1270. local json_status, json_data =
  1271. pcall(
  1272. function()
  1273. return json.decode(g_resources.readFileContents(settingsFile))
  1274. end
  1275. )
  1276.  
  1277. if not json_status then
  1278. g_logger.error("[loadSettings] Couldn't load JSON: " .. json_data)
  1279. return
  1280. end
  1281.  
  1282. settings = json_data[g_game.getCharacterName()]
  1283. if not settings then
  1284. loadDefaultSettings()
  1285. end
  1286. else
  1287. loadDefaultSettings()
  1288. end
  1289. end
  1290.  
  1291. function loadDefaultSettings()
  1292. settings = {
  1293. movement = false,
  1294. showFloor = false,
  1295. showOutfit = true,
  1296. showMount = false,
  1297. showWings = false,
  1298. showAura = false,
  1299. showShader = false,
  1300. showBars = false,
  1301. presets = {},
  1302. currentPreset = 0
  1303. }
  1304. settings.currentPreset = 0
  1305. end
  1306.  
  1307. function accept()
  1308. if g_game.getFeature(GamePlayerMounts) then
  1309. local player = g_game.getLocalPlayer()
  1310. local isMountedChecked = window.configure.mount.check:isChecked()
  1311. if not player:isMounted() and isMountedChecked then
  1312. player:mount()
  1313. elseif player:isMounted() and not isMountedChecked then
  1314. player:dismount()
  1315. end
  1316. if settings.currentPreset > 0 then
  1317. settings.presets[settings.currentPreset].mounted = isMountedChecked
  1318. end
  1319. end
  1320.  
  1321. g_game.changeOutfit(tempOutfit)
  1322. destroy()
  1323. end
  1324.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement