No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

outfit.lua 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. Outfit = {}
  2. -- private variables
  3. local window = nil
  4. local m_creature = nil
  5. local m_outfit = nil
  6. local m_outfits = nil
  7. local m_currentOutfit = 1
  8. local m_currentColor = nil
  9. local m_currentClothe = nil
  10. -- private functions
  11. local function onAddonCheckChange(addon, value)
  12. if addon:isChecked() then
  13. m_outfit.addons = m_outfit.addons + value
  14. else
  15. m_outfit.addons = m_outfit.addons - value
  16. end
  17. m_creature:setOutfit(m_outfit)
  18. end
  19. local function onColorCheckChange(color)
  20. if color == m_currentColor then
  21. color.onCheckChange = nil
  22. color:setChecked(true)
  23. color.onCheckChange = onColorCheckChange
  24. else
  25. m_currentColor.onCheckChange = nil
  26. m_currentColor:setChecked(false)
  27. m_currentColor.onCheckChange = onColorCheckChange
  28. m_currentColor = color
  29. if m_currentClothe:getId() == 'head' then
  30. m_outfit.head = m_currentColor.colorId
  31. elseif m_currentClothe:getId() == 'primary' then
  32. m_outfit.body = m_currentColor.colorId
  33. elseif m_currentClothe:getId() == 'secondary' then
  34. m_outfit.legs = m_currentColor.colorId
  35. elseif m_currentClothe:getId() == 'detail' then
  36. m_outfit.feet = m_currentColor.colorId
  37. end
  38. m_creature:setOutfit(m_outfit)
  39. end
  40. end
  41. local function onClotheCheckChange(clothe)
  42. if clothe == m_currentClothe then
  43. clothe.onCheckChange = nil
  44. clothe:setChecked(true)
  45. clothe.onCheckChange = onClotheCheckChange
  46. else
  47. m_currentClothe.onCheckChange = nil
  48. m_currentClothe:setChecked(false)
  49. m_currentClothe.onCheckChange = onClotheCheckChange
  50. m_currentClothe = clothe
  51. local color = 0
  52. if m_currentClothe:getId() == 'head' then
  53. color = m_outfit.head
  54. elseif m_currentClothe:getId() == 'primary' then
  55. color = m_outfit.body
  56. elseif m_currentClothe:getId() == 'secondary' then
  57. color = m_outfit.legs
  58. elseif m_currentClothe:getId() == 'detail' then
  59. color = m_outfit.feet
  60. end
  61. window:getChildById('color' .. color):setChecked(true)
  62. end
  63. end
  64. local function update()
  65. local nameWidget = window:getChildById('name')
  66. nameWidget:setText(m_outfits[m_currentOutfit][2])
  67. local availableAddons = m_outfits[m_currentOutfit][3]
  68. local addon1 = window:getChildById('addon1')
  69. local addon2 = window:getChildById('addon2')
  70. local addon3 = window:getChildById('addon3')
  71. addon1:setChecked(false)
  72. addon2:setChecked(false)
  73. addon3:setChecked(false)
  74. addon1.onCheckChange = function(self) onAddonCheckChange(self, 1) end
  75. addon2.onCheckChange = function(self) onAddonCheckChange(self, 2) end
  76. addon3.onCheckChange = function(self) onAddonCheckChange(self, 4) end
  77. addon1:setEnabled(false)
  78. addon2:setEnabled(false)
  79. addon3:setEnabled(false)
  80. -- Maybe rework this someday
  81. if availableAddons == 1 then
  82. addon1:setEnabled(true)
  83. elseif availableAddons == 2 then
  84. addon2:setEnabled(true)
  85. elseif availableAddons == 3 then
  86. addon1:setEnabled(true)
  87. addon2:setEnabled(true)
  88. elseif availableAddons == 4 then
  89. addon3:setEnabled(true)
  90. elseif availableAddons == 5 then
  91. addon1:setEnabled(true)
  92. addon3:setEnabled(true)
  93. elseif availableAddons == 6 then
  94. addon2:setEnabled(true)
  95. addon3:setEnabled(true)
  96. elseif availableAddons == 7 then
  97. addon1:setEnabled(true)
  98. addon2:setEnabled(true)
  99. addon3:setEnabled(true)
  100. end
  101. m_outfit.type = m_outfits[m_currentOutfit][1]
  102. m_outfit.addons = 0
  103. m_creature:setOutfit(m_outfit)
  104. end
  105. -- public functions
  106. function Outfit.create(creature, outfitList)
  107. Outfit.destroy()
  108. window = displayUI('outfit.otui', { parent = rootWidget })
  109. window:lock()
  110. m_outfit = creature:getOutfit()
  111. m_currentClothe = window:getChildById('head')
  112. window:getChildById('head').onCheckChange = onClotheCheckChange
  113. window:getChildById('primary').onCheckChange = onClotheCheckChange
  114. window:getChildById('secondary').onCheckChange = onClotheCheckChange
  115. window:getChildById('detail').onCheckChange = onClotheCheckChange
  116. local creatureWidget = window:getChildById('creature')
  117. creatureWidget:setCreature(creature)
  118. for i=0,18 do
  119. for j=0,6 do
  120. local color = createWidget('Color', window)
  121. local outfitColor = getOufitColor(j*19 + i)
  122. color:setId('color' .. j*19+i)
  123. color.colorId = j*19 + i
  124. color:setImageColor(outfitColor)
  125. color:setMarginTop(j * 3 + j * 14)
  126. color:setMarginLeft(10 + i * 3 + i * 14)
  127. if j*19 + i == m_outfit.head then
  128. m_currentColor = color
  129. color:setChecked(true)
  130. end
  131. color.onCheckChange = onColorCheckChange
  132. end
  133. end
  134. m_creature = creature
  135. m_outfits = outfitList
  136. m_currentOutfit = 1
  137. for i=1,#outfitList do
  138. if outfitList[i][1] == m_outfit.type then
  139. m_currentOutfit = i
  140. break
  141. end
  142. end
  143. update()
  144. end
  145. function Outfit.destroy()
  146. if window ~= nil then
  147. window:destroy()
  148. window = nil
  149. end
  150. end
  151. function Outfit.accept()
  152. Game.setOutfit(m_outfit)
  153. Outfit.destroy()
  154. end
  155. function Outfit.nextType()
  156. m_currentOutfit = m_currentOutfit + 1
  157. if m_currentOutfit > #m_outfits then
  158. m_currentOutfit = 1
  159. end
  160. update()
  161. end
  162. function Outfit.previousType()
  163. m_currentOutfit = m_currentOutfit - 1
  164. if m_currentOutfit <= 0 then
  165. m_currentOutfit = #m_outfits
  166. end
  167. update()
  168. end
  169. -- hooked events
  170. connect(Game, { onOpenOutfitWindow = Outfit.create,
  171. onGameEnd = Outfit.destroy })