From 654fb1f3ea5ad4348dd8a8c36c806748001c81c9 Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Mon, 14 Nov 2011 12:37:55 -0200 Subject: [PATCH] fix uiprogressbar assert --- modules/health_mana/health_mana.lua | 15 +++++++++++---- modules/tooltip/tooltip.lua | 4 +--- src/framework/ui/uiprogressbar.cpp | 5 +++-- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/modules/health_mana/health_mana.lua b/modules/health_mana/health_mana.lua index 388d11dc..a67073f7 100644 --- a/modules/health_mana/health_mana.lua +++ b/modules/health_mana/health_mana.lua @@ -17,7 +17,7 @@ function HealthMana.create() healthLabel:setId('healthLabel') healthLabel:setStyle('HealthLabel') healthLabel:setText('0 / 0') - + local manaBar = UIProgressBar.create() healthManaPanel:addChild(manaBar) manaBar:setId('manaBar') @@ -41,7 +41,7 @@ end function Game.onHealthChange(health, maxHealth) local label = healthManaPanel:getChildById('healthLabel') label:setText(health .. ' / ' .. maxHealth) - + local healthBar = healthManaPanel:getChildById('healthBar') healthBar:setPercent(health / maxHealth * 100) end @@ -49,9 +49,16 @@ end function Game.onManaChange(mana, maxMana) local label = healthManaPanel:getChildById('manaLabel') label:setText(mana .. ' / ' .. maxMana) - + 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 connect(Game, { onLogin = HealthMana.create, diff --git a/modules/tooltip/tooltip.lua b/modules/tooltip/tooltip.lua index feebee61..4f654e61 100644 --- a/modules/tooltip/tooltip.lua +++ b/modules/tooltip/tooltip.lua @@ -50,10 +50,8 @@ local function onWidgetHoverChange(widget, hovered) end local function onWidgetStyleApply(widget, style) - if not style or not style.tooltip then return end - print(style.tooltip) + if not style then return end widget.tooltip = style.tooltip - table.dump(style) end connect(UIWidget, { onStyleApply = onWidgetStyleApply, diff --git a/src/framework/ui/uiprogressbar.cpp b/src/framework/ui/uiprogressbar.cpp index c10c1abd..7e99e794 100644 --- a/src/framework/ui/uiprogressbar.cpp +++ b/src/framework/ui/uiprogressbar.cpp @@ -48,6 +48,7 @@ void UIProgressBar::render() void UIProgressBar::setPercent(double percent) { - assert(percent >= 0 && percent <= 100); - m_percent = percent; + if(percent == NAN) + percent = 0; + m_percent = std::min(std::max(percent, 0.0), 100.0); }