modules changes

* speedup widget destruction checks
* rework outfit module using grid layout and the new design
* fixes in console, terminal, textmessage modules
This commit is contained in:
Eduardo Bart
2012-03-22 18:47:52 -03:00
parent 159eb98df2
commit 33458a3e39
41 changed files with 335 additions and 234 deletions

View File

@@ -1,84 +1,84 @@
Outfit = {}
-- private variables
local window = nil
local m_creature = nil
local m_outfit = nil
local m_outfits = nil
local m_currentOutfit = 1
local m_currentColor = nil
local m_currentClothe = nil
local outfitWindow
local outfitCreature
local outfit
local outfits
local currentOutfit = 1
local currentColorBox
local currentClotheButtonBox
-- private functions
local function onAddonCheckChange(addon, value)
if addon:isChecked() then
m_outfit.addons = m_outfit.addons + value
outfit.addons = outfit.addons + value
else
m_outfit.addons = m_outfit.addons - value
outfit.addons = outfit.addons - value
end
m_creature:setOutfit(m_outfit)
outfitCreature:setOutfit(outfit)
end
local function onColorCheckChange(color)
if color == m_currentColor then
color.onCheckChange = nil
color:setChecked(true)
color.onCheckChange = onColorCheckChange
local function onColorCheckChange(colorBox)
if colorBox == currentColorBox then
colorBox.onCheckChange = nil
colorBox:setChecked(true)
colorBox.onCheckChange = onColorCheckChange
else
m_currentColor.onCheckChange = nil
m_currentColor:setChecked(false)
m_currentColor.onCheckChange = onColorCheckChange
currentColorBox.onCheckChange = nil
currentColorBox:setChecked(false)
currentColorBox.onCheckChange = onColorCheckChange
m_currentColor = color
currentColorBox = colorBox
if m_currentClothe:getId() == 'head' then
m_outfit.head = m_currentColor.colorId
elseif m_currentClothe:getId() == 'primary' then
m_outfit.body = m_currentColor.colorId
elseif m_currentClothe:getId() == 'secondary' then
m_outfit.legs = m_currentColor.colorId
elseif m_currentClothe:getId() == 'detail' then
m_outfit.feet = m_currentColor.colorId
if currentClotheButtonBox:getId() == 'head' then
outfit.head = currentColorBox.colorId
elseif currentClotheButtonBox:getId() == 'primary' then
outfit.body = currentColorBox.colorId
elseif currentClotheButtonBox:getId() == 'secondary' then
outfit.legs = currentColorBox.colorId
elseif currentClotheButtonBox:getId() == 'detail' then
outfit.feet = currentColorBox.colorId
end
m_creature:setOutfit(m_outfit)
outfitCreature:setOutfit(outfit)
end
end
local function onClotheCheckChange(clothe)
if clothe == m_currentClothe then
clothe.onCheckChange = nil
clothe:setChecked(true)
clothe.onCheckChange = onClotheCheckChange
local function onClotheCheckChange(clotheButtonBox)
if clotheButtonBox == currentClotheButtonBox then
clotheButtonBox.onCheckChange = nil
clotheButtonBox:setChecked(true)
clotheButtonBox.onCheckChange = onClotheCheckChange
else
m_currentClothe.onCheckChange = nil
m_currentClothe:setChecked(false)
m_currentClothe.onCheckChange = onClotheCheckChange
currentClotheButtonBox.onCheckChange = nil
currentClotheButtonBox:setChecked(false)
currentClotheButtonBox.onCheckChange = onClotheCheckChange
m_currentClothe = clothe
currentClotheButtonBox = clotheButtonBox
local color = 0
if m_currentClothe:getId() == 'head' then
color = m_outfit.head
elseif m_currentClothe:getId() == 'primary' then
color = m_outfit.body
elseif m_currentClothe:getId() == 'secondary' then
color = m_outfit.legs
elseif m_currentClothe:getId() == 'detail' then
color = m_outfit.feet
local colorId = 0
if currentClotheButtonBox:getId() == 'head' then
colorId = outfit.head
elseif currentClotheButtonBox:getId() == 'primary' then
colorId = outfit.body
elseif currentClotheButtonBox:getId() == 'secondary' then
colorId = outfit.legs
elseif currentClotheButtonBox:getId() == 'detail' then
colorId = outfit.feet
end
window:getChildById('color' .. color):setChecked(true)
outfitWindow:recursiveGetChildById('colorBox' .. colorId):setChecked(true)
end
end
local function update()
local nameWidget = window:getChildById('name')
nameWidget:setText(m_outfits[m_currentOutfit][2])
local nameWidget = outfitWindow:getChildById('outfitName')
nameWidget:setText(outfits[currentOutfit][2])
local availableAddons = m_outfits[m_currentOutfit][3]
local addon1 = window:getChildById('addon1')
local addon2 = window:getChildById('addon2')
local addon3 = window:getChildById('addon3')
local availableAddons = outfits[currentOutfit][3]
local addon1 = outfitWindow:getChildById('addon1')
local addon2 = outfitWindow:getChildById('addon2')
local addon3 = outfitWindow:getChildById('addon3')
addon1:setChecked(false)
addon2:setChecked(false)
addon3:setChecked(false)
@@ -111,55 +111,63 @@ local function update()
addon3:setEnabled(true)
end
m_outfit.type = m_outfits[m_currentOutfit][1]
m_outfit.addons = 0
m_creature:setOutfit(m_outfit)
outfit.type = outfits[currentOutfit][1]
outfit.addons = 0
outfitCreature:setOutfit(outfit)
end
-- public functions
function Outfit.create(creature, outfitList)
function Outfit.init()
connect(g_game, { onOpenOutfitWindow = Outfit.create,
onGameEnd = Outfit.destroy })
end
function Outfit.terminate()
disconnect(g_game, { onOpenOutfitWindow = Outfit.create,
onGameEnd = Outfit.destroy })
Outfit.destroy()
window = displayUI('outfit.otui')
window:lock()
end
m_outfit = creature:getOutfit()
function Outfit.create(creature, outfitList)
outfitCreature = creature
outfits = outfitList
Outfit.destroy()
m_currentClothe = window:getChildById('head')
window:getChildById('head').onCheckChange = onClotheCheckChange
window:getChildById('primary').onCheckChange = onClotheCheckChange
window:getChildById('secondary').onCheckChange = onClotheCheckChange
window:getChildById('detail').onCheckChange = onClotheCheckChange
outfitWindow = displayUI('outfit.otui')
--outfitWindow:lock()
local creatureWidget = window:getChildById('creature')
creatureWidget:setCreature(creature)
outfit = outfitCreature:getOutfit()
for i=0,18 do
for j=0,6 do
local color = createWidget('Color', window)
currentClotheButtonBox = outfitWindow:getChildById('head')
outfitWindow:getChildById('head').onCheckChange = onClotheCheckChange
outfitWindow:getChildById('primary').onCheckChange = onClotheCheckChange
outfitWindow:getChildById('secondary').onCheckChange = onClotheCheckChange
outfitWindow:getChildById('detail').onCheckChange = onClotheCheckChange
local outfitCreatureBox = outfitWindow:getChildById('outfitCreatureBox')
local colorBoxPanel = outfitWindow:getChildById('colorBoxPanel')
outfitCreatureBox:setCreature(outfitCreature)
for j=0,6 do
for i=0,18 do
local colorBox = createWidget('ColorBox', colorBoxPanel)
local outfitColor = getOufitColor(j*19 + i)
color:setId('color' .. j*19+i)
color.colorId = j*19 + i
color:setImageColor(outfitColor)
color:setMarginTop(j * 3 + j * 14)
color:setMarginLeft(10 + i * 3 + i * 14)
colorBox:setImageColor(outfitColor)
colorBox:setId('colorBox' .. j*19+i)
colorBox.colorId = j*19 + i
if j*19 + i == m_outfit.head then
m_currentColor = color
color:setChecked(true)
if j*19 + i == outfit.head then
currentColorBox = colorBox
colorBox:setChecked(true)
end
color.onCheckChange = onColorCheckChange
colorBox.onCheckChange = onColorCheckChange
end
end
m_creature = creature
m_outfits = outfitList
m_currentOutfit = 1
currentOutfit = 1
for i=1,#outfitList do
if outfitList[i][1] == m_outfit.type then
m_currentOutfit = i
if outfitList[i][1] == outfit.type then
currentOutfit = i
break
end
end
@@ -168,35 +176,33 @@ function Outfit.create(creature, outfitList)
end
function Outfit.destroy()
if window ~= nil then
window:destroy()
window = nil
if outfitWindow then
outfitWindow:destroy()
outfitWindow = nil
outfitCreature = nil
currentColorBox = nil
currentClotheButtonBox = nil
end
end
function Outfit.accept()
g_game.changeOutfit(m_outfit)
g_game.changeOutfit(outfit)
Outfit.destroy()
end
function Outfit.nextType()
m_currentOutfit = m_currentOutfit + 1
if m_currentOutfit > #m_outfits then
m_currentOutfit = 1
currentOutfit = currentOutfit + 1
if currentOutfit > #outfits then
currentOutfit = 1
end
update()
end
function Outfit.previousType()
m_currentOutfit = m_currentOutfit - 1
if m_currentOutfit <= 0 then
m_currentOutfit = #m_outfits
currentOutfit = currentOutfit - 1
if currentOutfit <= 0 then
currentOutfit = #outfits
end
update()
end
-- hooked events
connect(g_game, { onOpenOutfitWindow = Outfit.create,
onGameEnd = Outfit.destroy })

View File

@@ -3,5 +3,11 @@ Module
description: Change local player outfit
author: OTClient team
website: https://github.com/edubart/otclient
onLoad: |
reloadable: true
@onLoad: |
dofile 'outfit'
Outfit.init()
@onUnload: |
Outfit.terminate()

View File

@@ -1,7 +1,3 @@
Color < ColorBox
anchors.top: head.top
anchors.left: head.right
Window
text: Select Outfit
size: 550 280
@@ -14,7 +10,7 @@ Window
@onEscape: Outfit.destroy()
Label
id: name
id: outfitName
text: Outfit Name
width: 100
anchors.top: parent.top
@@ -23,60 +19,81 @@ Window
margin-left: 20
Creature
id: creature
anchors.top: name.bottom
anchors.left: name.left
id: outfitCreatureBox
anchors.top: outfitName.bottom
anchors.left: outfitName.left
margin-top: 5
padding: 16 4 4 16
fixed-creature-size: true
Panel
id: colorBoxPanel
anchors.top: parent.top
anchors.right: parent.right
margin-top: 54
margin-right: 20
width: 323
height: 119
layout:
type: grid
cell-size: 16 16
cell-spacing: 2
num-columns: 19
num-lines: 7
ButtonBox
id: head
text: Head
anchors.top: creature.top
anchors.left: creature.right
anchors.top: outfitCreatureBox.top
anchors.left: outfitCreatureBox.right
margin-left: 10
checked: true
width: 90
ButtonBox
id: primary
text: Primary
anchors.top: prev.bottom
anchors.left: prev.left
width: 90
ButtonBox
id: secondary
text: Secondary
anchors.top: prev.bottom
anchors.left: prev.left
width: 90
ButtonBox
id: detail
text: Detail
anchors.top: prev.bottom
anchors.left: prev.left
width: 90
Button
id: outfitNextButton
@onClick: Outfit.nextType()
text: >>
width: 32
margin-top: 4
anchors.top: creature.bottom
anchors.right: creature.right
anchors.top: outfitCreatureBox.bottom
anchors.right: outfitCreatureBox.right
Button
id: outfitPreviousButton
@onClick: Outfit.previousType()
text: <<
width: 32
margin-top: 4
anchors.top: creature.bottom
anchors.left: creature.left
anchors.top: outfitCreatureBox.bottom
anchors.left: outfitCreatureBox.left
CheckBox
id: addon1
text: Addon 1
enabled: false
margin-top: 10
margin-top: 6
width: 100
anchors.top: prev.bottom
anchors.left: prev.left
@@ -85,7 +102,7 @@ Window
id: addon2
text: Addon 2
enabled: false
margin-top: 10
margin-top: 2
width: 100
anchors.top: prev.bottom
anchors.left: prev.left
@@ -94,7 +111,7 @@ Window
id: addon3
text: Addon 3
enabled: false
margin-top: 10
margin-top: 2
width: 100
anchors.top: prev.bottom
anchors.left: prev.left
@@ -108,7 +125,7 @@ Window
margin-bottom: 10
Button
id: buttonOk
id: outfitOkButton
text: Ok
width: 64
anchors.right: next.left
@@ -118,7 +135,7 @@ Window
@onClick: Outfit.accept()
Button
id: buttonCancel
id: outfitCancelButton
text: Cancel
width: 64
anchors.right: parent.right