Skilltree = {}
skilltreeWindow = nil
selecetedTalent = nil
skilltree = {}
ProtocolGame.registerExtendedOpcode(10, test)
function init()
g_ui.importStyle('modaldialog')
connect(g_game, { onOpenskilltreeWindow = Skilltree.create, onGameEnd = Skilltree.destroy })
end
function terminate()
disconnect(g_game, { onOpenskilltreeWindow = Skilltree.create, onGameEnd = Skilltree.destroy })
Skilltree.destroy()
Skilltree = nil
end
function Skilltree.create(skillList, id, title, message, buttons, enterButton, escapeButton, choices, priority)
print("skillList "..tostring(skillList))
print("id "..tostring(id))
print("title "..tostring(title))
print("message "..tostring(message))
print("buttons "..tostring(buttons))
print("enterButton "..tostring(enterButton))
print("escapeButton "..tostring(escapeButton))
print("choices "..tostring(choices))
print("priority "..tostring(priority))
skilltree = skillList
Skilltree.destroy()
skilltreeWindow = g_ui.displayUI('skilltree.otui')
text = g_ui.createWidget('ModalDialog', rootWidget)
local messageLabel = text:getChildById('messageLabel')
local choiceList = text:getChildById('choiceList')
local choiceScrollbar = text:getChildById('choiceScrollBar')
local buttonsPanel = text:getChildById('buttonsPanel')
local labelHeight
local buttonsWidth = 0
local additionalHeight = 0
text:setText(title)
messageLabel:setText(message)
for i = 1, #choices do
local choiceId = choices[i][1]
local choiceName = choices[i][2]
local label = g_ui.createWidget('ChoiceListLabel', choiceList)
label.choiceId = choiceId
label:setText(choiceName)
label:setPhantom(false)
if not labelHeight then
labelHeight = label:getHeight()
end
end
choiceList:focusNextChild()
for i = 1, #buttons do
local buttonId = buttons[i][1]
local buttonText = buttons[i][2]
local button = g_ui.createWidget('ModalButton', buttonsPanel)
button:setText(buttonText)
button.onClick = function(self)
local focusedChoice = choiceList:getFocusedChild()
local choice = 0xFF
if focusedChoice then
choice = focusedChoice.choiceId
end
g_game.answerModalDialog(id, buttonId, choice)
destroyDialog()
end
buttonsWidth = buttonsWidth + button:getWidth() + button:getMarginLeft() + button:getMarginRight()
end
if #choices > 0 then
choiceList:setVisible(true)
choiceScrollbar:setVisible(true)
additionalHeight = math.min(text.maximumChoices, math.max(text.minimumChoices, #choices)) * labelHeight
additionalHeight = additionalHeight + choiceList:getPaddingTop() + choiceList:getPaddingBottom()
end
local horizontalPadding = text:getPaddingLeft() + text:getPaddingRight()
buttonsWidth = buttonsWidth + horizontalPadding
text:setWidth(math.min(text.maximumWidth, math.max(buttonsWidth, messageLabel:getWidth(), text.minimumWidth)))
messageLabel:setWidth(math.min(text.maximumWidth, math.max(buttonsWidth, messageLabel:getWidth(), text.minimumWidth)) - horizontalPadding)
text:setHeight(text:getHeight() + additionalHeight + messageLabel:getHeight() - 8)
local enterFunc = function()
local focusedChoice = choiceList:getFocusedChild()
local choice = 0xFF
if focusedChoice then
choice = focusedChoice.choiceId
end
g_game.answerModalDialog(id, enterButton, choice)
destroyDialog()
end
local escapeFunc = function()
local focusedChoice = choiceList:getFocusedChild()
local choice = 0xFF
if focusedChoice then
choice = focusedChoice.choiceId
end
g_game.answerModalDialog(id, escapeButton, choice)
destroyDialog()
end
choiceList.onDoubleClick = enterFunc
text.onEnter = enterFunc
text.onEscape = escapeFunc
end
function Skilltree.destroy()
if skilltreeWindow then
skilltreeWindow:destroy()
skilltreeWindow = nil
selecetedTalent = nil
skilltree = {}
end
end
function Skilltree.selectSkill()
if table.empty(skilltree) then
return
end
-- TODO
end