-- @docclass UIHealthBar = extends(UIWidget, "UIHealthBar") function UIHealthBar.create() local bar = UIHealthBar.internalCreate() bar:setPhantom(false) bar:setAutoFocusPolicy(AutoFocusFirst) bar.hasBorder = true return bar end function UIHealthBar.setHealthBorder(self, value) self.hasBorder = value end -- used for healthbars, manabars and resourcebars (check game_healthinfo module for examples) function UIHealthBar.setPercentage(self, value, maxValue) -- the extra resize code is implemented to work in junction with uiwidget.lua:resizeElements local percentage = math.min(100, math.floor((value/maxValue)*100)) local widget = self:recursiveGetChildById('bar') local icon = self:recursiveGetChildById('icon') widget:setImageWidth(math.ceil((widget:getWidth() - icon:getWidth() + 13) * percentage / 100)) widget:setVisible(widget:getImageWidth() > 0) local text = self:recursiveGetChildById('text') if text then --text:setText(getFormattedShortNumber(value) .. '/' .. getFormattedShortNumber(maxValue)) text:setText(value .. '/' .. maxValue) end local resourceText = self:recursiveGetChildById('resourceText') if resourceText then resourceText:setText(value) end --[[ local indicator = self:recursiveGetChildById('indicator') if indicator then indicator:setMarginRight(-2*resizeFactor + (size.width - size.newWidth)) end local anim = self:recursiveGetChildById('orb') local backGlow = self:recursiveGetChildById('background-glow') if anim and backGlow then if percentage == 100 then -- anim:play() backGlow:setOpacity(0) backGlow:show() g_effects.startFadeInOut(backGlow, 0, 50, 0.05) else -- anim:stop() g_effects.stopFadeInOut(backGlow) backGlow:hide() end end ]] end