fix uiprogressbar assert

This commit is contained in:
Eduardo Bart 2011-11-14 12:37:55 -02:00
parent 5784644701
commit 654fb1f3ea
3 changed files with 15 additions and 9 deletions

View File

@ -17,7 +17,7 @@ function HealthMana.create()
healthLabel:setId('healthLabel') healthLabel:setId('healthLabel')
healthLabel:setStyle('HealthLabel') healthLabel:setStyle('HealthLabel')
healthLabel:setText('0 / 0') healthLabel:setText('0 / 0')
local manaBar = UIProgressBar.create() local manaBar = UIProgressBar.create()
healthManaPanel:addChild(manaBar) healthManaPanel:addChild(manaBar)
manaBar:setId('manaBar') manaBar:setId('manaBar')
@ -41,7 +41,7 @@ end
function Game.onHealthChange(health, maxHealth) function Game.onHealthChange(health, maxHealth)
local label = healthManaPanel:getChildById('healthLabel') local label = healthManaPanel:getChildById('healthLabel')
label:setText(health .. ' / ' .. maxHealth) label:setText(health .. ' / ' .. maxHealth)
local healthBar = healthManaPanel:getChildById('healthBar') local healthBar = healthManaPanel:getChildById('healthBar')
healthBar:setPercent(health / maxHealth * 100) healthBar:setPercent(health / maxHealth * 100)
end end
@ -49,9 +49,16 @@ end
function Game.onManaChange(mana, maxMana) function Game.onManaChange(mana, maxMana)
local label = healthManaPanel:getChildById('manaLabel') local label = healthManaPanel:getChildById('manaLabel')
label:setText(mana .. ' / ' .. maxMana) label:setText(mana .. ' / ' .. maxMana)
local manaBar = healthManaPanel:getChildById('manaBar') local manaBar = healthManaPanel:getChildById('manaBar')
manaBar:setPercent(mana / maxMana * 100)
local percent
if maxMana == 0 then
percent = 100
else
percent = mana / maxMana * 100
end
manaBar:setPercent(percent)
end end
connect(Game, { onLogin = HealthMana.create, connect(Game, { onLogin = HealthMana.create,

View File

@ -50,10 +50,8 @@ local function onWidgetHoverChange(widget, hovered)
end end
local function onWidgetStyleApply(widget, style) local function onWidgetStyleApply(widget, style)
if not style or not style.tooltip then return end if not style then return end
print(style.tooltip)
widget.tooltip = style.tooltip widget.tooltip = style.tooltip
table.dump(style)
end end
connect(UIWidget, { onStyleApply = onWidgetStyleApply, connect(UIWidget, { onStyleApply = onWidgetStyleApply,

View File

@ -48,6 +48,7 @@ void UIProgressBar::render()
void UIProgressBar::setPercent(double percent) void UIProgressBar::setPercent(double percent)
{ {
assert(percent >= 0 && percent <= 100); if(percent == NAN)
m_percent = percent; percent = 0;
m_percent = std::min(std::max(percent, 0.0), 100.0);
} }