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 getNumberString(number)
|
|
|
|
local out = ''
|
|
|
|
number = tostring(number):reverse()
|
|
|
|
for i=1,#number do
|
|
|
|
out = out .. number:sub(i, i)
|
|
|
|
if i % 3 == 0 and i ~= #number then
|
|
|
|
out = out .. ','
|
|
|
|
end
|
|
|
|
end
|
|
|
|
out = out:reverse()
|
|
|
|
return out
|
|
|
|
end
|
2011-11-03 10:59:11 +01:00
|
|
|
|
2011-12-22 05:06:00 +01:00
|
|
|
local function setSkillValue(id, value)
|
2012-01-23 14:47:15 +01:00
|
|
|
local skill = skillsWindow:recursiveGetChildById(id)
|
2012-01-06 09:48:59 +01:00
|
|
|
|
2011-12-22 05:06:00 +01:00
|
|
|
if skill then
|
|
|
|
local widget = skill:getChildById('value')
|
|
|
|
widget:setText(value)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function setSkillPercent(id, percent, tooltip)
|
2012-01-23 14:47:15 +01:00
|
|
|
local skill = skillsWindow:recursiveGetChildById(id)
|
2012-01-06 09:48:59 +01:00
|
|
|
|
2011-12-22 05:06:00 +01:00
|
|
|
if skill then
|
|
|
|
local widget = skill:getChildById('percent')
|
|
|
|
widget:setPercent(percent)
|
2012-01-06 09:48:59 +01:00
|
|
|
|
2011-12-22 05:06:00 +01:00
|
|
|
if tooltip then
|
|
|
|
widget:setTooltip(tooltip)
|
2011-11-14 09:46:27 +01:00
|
|
|
end
|
2011-09-13 23:54:23 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-12-22 05:06:00 +01:00
|
|
|
-- public functions
|
|
|
|
function Skills.create()
|
2012-02-08 22:23:15 +01:00
|
|
|
skillsWindow = displayUI('skills.otui', { parent = g_game.gameRightPanel })
|
2012-01-23 14:47:15 +01:00
|
|
|
skillsWindow:hide()
|
2012-01-15 16:13:22 +01:00
|
|
|
skillsButton = TopMenu.addGameButton('skillsButton', 'Skills (Ctrl+S)', '/core_styles/icons/skills.png', Skills.toggle)
|
2012-02-06 05:39:52 +01:00
|
|
|
Keyboard.bindKeyDown('Ctrl+S', Skills.toggle)
|
2011-12-22 05:06:00 +01:00
|
|
|
end
|
|
|
|
|
2011-11-03 13:17:10 +01:00
|
|
|
function Skills.destroy()
|
2012-02-06 05:39:52 +01:00
|
|
|
Keyboard.unbindKeyDown('Ctrl+S')
|
2012-01-23 14:47:15 +01:00
|
|
|
skillsButton:destroy()
|
|
|
|
skillsButton = nil
|
|
|
|
skillsWindow:destroy()
|
|
|
|
skillsWindow = nil
|
2011-11-03 13:17:10 +01:00
|
|
|
end
|
|
|
|
|
2012-01-14 20:31:20 +01:00
|
|
|
function Skills.toggle()
|
2012-01-23 14:47:15 +01:00
|
|
|
local visible = not skillsWindow:isExplicitlyVisible()
|
|
|
|
skillsWindow:setVisible(visible)
|
|
|
|
skillsButton:setOn(visible)
|
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)
|
2011-12-22 05:06:00 +01:00
|
|
|
setSkillValue('experience', getNumberString(value))
|
|
|
|
end
|
2011-11-03 23:14:56 +01:00
|
|
|
|
2012-02-09 04:45:19 +01:00
|
|
|
function Skills.onLevelChange(localPlayer, value, percent)
|
2011-12-22 05:06:00 +01:00
|
|
|
setSkillValue('level', getNumberString(value))
|
|
|
|
setSkillPercent('level', percent, 'You have ' .. (100 - percent) .. ' percent to go')
|
|
|
|
end
|
|
|
|
|
2012-02-09 04:45:19 +01:00
|
|
|
function Skills.onHealthChange(localPlayer, health, maxHealth)
|
2011-12-22 05:06:00 +01:00
|
|
|
setSkillValue('health', getNumberString(health))
|
|
|
|
end
|
|
|
|
|
2012-02-09 04:45:19 +01:00
|
|
|
function Skills.onManaChange(localPlayer, mana, maxMana)
|
2011-12-22 05:06:00 +01:00
|
|
|
setSkillValue('mana', getNumberString(mana))
|
|
|
|
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)
|
|
|
|
setSkillPercent('stamina', percent, 'You have ' .. percent .. ' percent')
|
|
|
|
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)
|
|
|
|
setSkillPercent('magiclevel', percent, 'You have ' .. (100 - percent) .. ' percent to go')
|
|
|
|
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)
|
|
|
|
setSkillPercent('skillId' .. id, percent, 'You have ' .. (100 - percent) .. ' percent to go')
|
2011-11-03 21:54:53 +01:00
|
|
|
end
|
|
|
|
|
2012-02-08 22:23:15 +01:00
|
|
|
connect(g_game, { onGameStart = Skills.create,
|
2012-02-09 04:45:19 +01:00
|
|
|
onGameEnd = Skills.destroy })
|
|
|
|
|
|
|
|
connect(LocalPlayer, {
|
2011-12-22 05:06:00 +01:00
|
|
|
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 })
|