1-- @docclass
2UIHealthBar = extends(UIWidget, "UIHealthBar")
3
4function UIHealthBar.create()
5 local bar = UIHealthBar.internalCreate()
6 bar:setPhantom(false)
7 bar:setAutoFocusPolicy(AutoFocusFirst)
8 bar.hasBorder = true
9 return bar
10end
11
12function UIHealthBar.setHealthBorder(self, value)
13 self.hasBorder = value
14end
15
16-- used for healthbars, manabars and resourcebars (check game_healthinfo module for examples)
17function UIHealthBar.setPercentage(self, value, maxValue)
18 -- the extra resize code is implemented to work in junction with uiwidget.lua:resizeElements
19 local percentage = math.min(100, math.floor((value/maxValue)*100))
20 local widget = self:recursiveGetChildById('bar')
21 local icon = self:recursiveGetChildById('icon')
22
23 widget:setImageWidth(math.ceil((widget:getWidth() - icon:getWidth() + 13) * percentage / 100))
24
25 widget:setVisible(widget:getImageWidth() > 0)
26
27 local text = self:recursiveGetChildById('text')
28 if text then
29 --text:setText(getFormattedShortNumber(value) .. '/' .. getFormattedShortNumber(maxValue))
30 text:setText(value .. '/' .. maxValue)
31 end
32
33 local resourceText = self:recursiveGetChildById('resourceText')
34 if resourceText then
35 resourceText:setText(value)
36 end
37
38--[[
39 local indicator = self:recursiveGetChildById('indicator')
40 if indicator then
41 indicator:setMarginRight(-2*resizeFactor + (size.width - size.newWidth))
42 end
43
44
45 local anim = self:recursiveGetChildById('orb')
46 local backGlow = self:recursiveGetChildById('background-glow')
47 if anim and backGlow then
48 if percentage == 100 then
49 -- anim:play()
50 backGlow:setOpacity(0)
51 backGlow:show()
52 g_effects.startFadeInOut(backGlow, 0, 50, 0.05)
53 else
54 -- anim:stop()
55 g_effects.stopFadeInOut(backGlow)
56 backGlow:hide()
57 end
58 end
59]]
60end