2011-11-03 13:17:10 +01:00
|
|
|
Skills = {}
|
2011-09-13 23:54:23 +02:00
|
|
|
|
2011-11-03 13:17:10 +01:00
|
|
|
-- private variables
|
2012-01-23 14:47:15 +01:00
|
|
|
local skillsWindow
|
2012-01-14 20:31:20 +01:00
|
|
|
local skillsButton
|
2011-09-13 23:54:23 +02:00
|
|
|
|
2011-12-22 05:06:00 +01:00
|
|
|
-- private functions
|
|
|
|
local function setSkillValue(id, value)
|
2012-01-23 14:47:15 +01:00
|
|
|
local skill = skillsWindow:recursiveGetChildById(id)
|
2012-03-29 21:25:04 +02:00
|
|
|
local widget = skill:getChildById('value')
|
|
|
|
widget:setText(value)
|
2011-12-22 05:06:00 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
local function setSkillPercent(id, percent, tooltip)
|
2012-01-23 14:47:15 +01:00
|
|
|
local skill = skillsWindow:recursiveGetChildById(id)
|
2012-03-29 21:25:04 +02:00
|
|
|
local widget = skill:getChildById('percent')
|
|
|
|
widget:setPercent(percent)
|
2012-01-06 09:48:59 +01:00
|
|
|
|
2012-03-29 21:25:04 +02:00
|
|
|
if tooltip then
|
|
|
|
widget:setTooltip(tooltip)
|
2011-09-13 23:54:23 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-12-22 05:06:00 +01:00
|
|
|
-- public functions
|
2012-03-23 14:48:05 +01:00
|
|
|
function Skills.init()
|
2012-03-28 16:10:21 +02:00
|
|
|
connect(LocalPlayer, {
|
|
|
|
onExperienceChange = Skills.onExperienceChange,
|
|
|
|
onLevelChange = Skills.onLevelChange,
|
|
|
|
onHealthChange = Skills.onHealthChange,
|
|
|
|
onManaChange = Skills.onManaChange,
|
|
|
|
onSoulChange = Skills.onSoulChange,
|
|
|
|
onFreeCapacityChange = Skills.onFreeCapacityChange,
|
|
|
|
onStaminaChange = Skills.onStaminaChange,
|
|
|
|
onMagicLevelChange = Skills.onMagicLevelChange,
|
|
|
|
onSkillChange = Skills.onSkillChange
|
|
|
|
})
|
|
|
|
|
2012-06-26 00:13:30 +02:00
|
|
|
skillsWindow = g_ui.loadUI('skills.otui', GameInterface.getRightPanel())
|
2012-04-26 21:54:16 +02:00
|
|
|
skillsButton = TopMenu.addGameToggleButton('skillsButton', tr('Skills') .. ' (Ctrl+S)', 'skills.png', Skills.toggle)
|
2012-03-28 16:10:21 +02:00
|
|
|
skillsButton:setOn(true)
|
2012-06-26 00:13:30 +02:00
|
|
|
g_keyboard.bindKeyDown('Ctrl+S', Skills.toggle)
|
2012-04-27 08:30:54 +02:00
|
|
|
|
|
|
|
Skills.refresh()
|
2011-12-22 05:06:00 +01:00
|
|
|
end
|
|
|
|
|
2012-03-23 14:48:05 +01:00
|
|
|
function Skills.terminate()
|
2012-03-28 16:10:21 +02:00
|
|
|
disconnect(LocalPlayer, {
|
|
|
|
onExperienceChange = Skills.onExperienceChange,
|
|
|
|
onLevelChange = Skills.onLevelChange,
|
|
|
|
onHealthChange = Skills.onHealthChange,
|
|
|
|
onManaChange = Skills.onManaChange,
|
|
|
|
onSoulChange = Skills.onSoulChange,
|
|
|
|
onFreeCapacityChange = Skills.onFreeCapacityChange,
|
|
|
|
onStaminaChange = Skills.onStaminaChange,
|
|
|
|
onMagicLevelChange = Skills.onMagicLevelChange,
|
|
|
|
onSkillChange = Skills.onSkillChange
|
|
|
|
})
|
|
|
|
|
2012-06-26 00:13:30 +02:00
|
|
|
g_keyboard.unbindKeyDown('Ctrl+S')
|
2012-01-23 14:47:15 +01:00
|
|
|
skillsButton:destroy()
|
|
|
|
skillsButton = nil
|
|
|
|
skillsWindow:destroy()
|
|
|
|
skillsWindow = nil
|
2012-04-27 06:54:14 +02:00
|
|
|
|
|
|
|
Skills = nil
|
2011-11-03 13:17:10 +01:00
|
|
|
end
|
|
|
|
|
2012-04-27 08:30:54 +02:00
|
|
|
function Skills.refresh()
|
|
|
|
local player = g_game.getLocalPlayer()
|
|
|
|
if not player then return end
|
|
|
|
|
|
|
|
Skills.onExperienceChange(player, player:getExperience())
|
|
|
|
Skills.onLevelChange(player, player:getLevel(), player:getLevelPercent())
|
|
|
|
Skills.onHealthChange(player, player:getHealth(), player:getMaxHealth())
|
|
|
|
Skills.onManaChange(player, player:getMana(), player:getMaxMana())
|
|
|
|
Skills.onSoulChange(player, player:getSoul())
|
|
|
|
Skills.onFreeCapacityChange(player, player:getFreeCapacity())
|
|
|
|
Skills.onStaminaChange(player, player:getStamina())
|
|
|
|
Skills.onMagicLevelChange(player, player:getMagicLevel(), player:getMagicLevelPercent())
|
|
|
|
|
|
|
|
for i=0,6 do
|
|
|
|
Skills.onSkillChange(player, i, player:getSkillLevel(i), player:getSkillLevelPercent(i))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-01-14 20:31:20 +01:00
|
|
|
function Skills.toggle()
|
2012-06-21 21:31:22 +02:00
|
|
|
if skillsButton:isOn() then
|
|
|
|
skillsWindow:close()
|
|
|
|
skillsButton:setOn(false)
|
|
|
|
else
|
|
|
|
skillsWindow:open()
|
|
|
|
skillsButton:setOn(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function Skills.onMiniWindowClose()
|
|
|
|
skillsButton:setOn(false)
|
2012-01-14 20:31:20 +01:00
|
|
|
end
|
|
|
|
|
2012-01-06 09:48:59 +01:00
|
|
|
function Skills.onSkillButtonClick(button)
|
|
|
|
local percentBar = button:getChildById('percent')
|
|
|
|
if percentBar then
|
|
|
|
percentBar:setVisible(not percentBar:isVisible())
|
|
|
|
if percentBar:isVisible() then
|
|
|
|
button:setHeight(21)
|
|
|
|
else
|
|
|
|
button:setHeight(21 - 6)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-11-03 13:17:10 +01:00
|
|
|
-- hooked events
|
2012-02-09 04:45:19 +01:00
|
|
|
function Skills.onExperienceChange(localPlayer, value)
|
2012-04-26 18:45:25 +02:00
|
|
|
setSkillValue('experience', tr(value))
|
2011-12-22 05:06:00 +01:00
|
|
|
end
|
2011-11-03 23:14:56 +01:00
|
|
|
|
2012-02-09 04:45:19 +01:00
|
|
|
function Skills.onLevelChange(localPlayer, value, percent)
|
2012-04-26 18:45:25 +02:00
|
|
|
setSkillValue('level', tr(value))
|
2012-04-26 21:54:16 +02:00
|
|
|
setSkillPercent('level', percent, tr('You have %s percent to go', 100 - percent))
|
2011-12-22 05:06:00 +01:00
|
|
|
end
|
|
|
|
|
2012-02-09 04:45:19 +01:00
|
|
|
function Skills.onHealthChange(localPlayer, health, maxHealth)
|
2012-04-26 18:45:25 +02:00
|
|
|
setSkillValue('health', tr(health))
|
2011-12-22 05:06:00 +01:00
|
|
|
end
|
|
|
|
|
2012-02-09 04:45:19 +01:00
|
|
|
function Skills.onManaChange(localPlayer, mana, maxMana)
|
2012-04-26 18:45:25 +02:00
|
|
|
setSkillValue('mana', tr(mana))
|
2011-12-22 05:06:00 +01:00
|
|
|
end
|
|
|
|
|
2012-02-09 04:45:19 +01:00
|
|
|
function Skills.onSoulChange(localPlayer, soul)
|
2011-12-22 05:06:00 +01:00
|
|
|
setSkillValue('soul', soul)
|
|
|
|
end
|
|
|
|
|
2012-02-09 04:45:19 +01:00
|
|
|
function Skills.onFreeCapacityChange(localPlayer, freeCapacity)
|
2011-12-22 05:06:00 +01:00
|
|
|
setSkillValue('capacity', freeCapacity)
|
|
|
|
end
|
|
|
|
|
2012-02-09 04:45:19 +01:00
|
|
|
function Skills.onStaminaChange(localPlayer, stamina)
|
2011-12-22 05:06:00 +01:00
|
|
|
local hours = math.floor(stamina / 60)
|
|
|
|
local minutes = stamina % 60
|
|
|
|
if minutes < 10 then
|
|
|
|
minutes = '0' .. minutes
|
|
|
|
end
|
|
|
|
local percent = 100 * stamina / (42 * 60) -- max is 42 hours
|
2012-01-06 09:48:59 +01:00
|
|
|
|
2011-12-22 05:06:00 +01:00
|
|
|
setSkillValue('stamina', hours .. ":" .. minutes)
|
2012-04-26 21:54:16 +02:00
|
|
|
setSkillPercent('stamina', percent, tr('You have %s percent', percent))
|
2011-12-22 05:06:00 +01:00
|
|
|
end
|
|
|
|
|
2012-02-09 04:45:19 +01:00
|
|
|
function Skills.onMagicLevelChange(localPlayer, value, percent)
|
2011-12-22 05:06:00 +01:00
|
|
|
setSkillValue('magiclevel', value)
|
2012-04-26 21:54:16 +02:00
|
|
|
setSkillPercent('magiclevel', percent, tr('You have %s percent to go', 100 - percent))
|
2011-12-22 05:06:00 +01:00
|
|
|
end
|
2011-11-03 23:14:56 +01:00
|
|
|
|
2012-02-09 04:45:19 +01:00
|
|
|
function Skills.onSkillChange(localPlayer, id, level, percent)
|
2011-12-22 05:06:00 +01:00
|
|
|
setSkillValue('skillId' .. id, level)
|
2012-04-26 21:54:16 +02:00
|
|
|
setSkillPercent('skillId' .. id, percent, tr('You have %s percent to go', 100 - percent))
|
2011-11-03 21:54:53 +01:00
|
|
|
end
|
|
|
|
|