local UIAnim = require "widgets/uianim"
local Widget = require "widgets/widget"
local Text = require "widgets/text"
local Image = require "widgets/image"
local ImageButton = require "widgets/imagebutton"
local AnimButton = require "widgets/animbutton"
local HoverText = require "widgets/hoverer"

local lingli = Class(Widget, function(self, owner)
	Widget._ctor(self, "lingli")
	self.owner = owner

    self:SetPosition(0,0,0)


    self.point = 0
    

    self.anim = self:AddChild(UIAnim())
	self.anim:GetAnimState():SetBank("hunger")
	self.anim:GetAnimState():SetBuild("lingli")
	--self.anim:SetScale(0.14,0.14,0.14)	
	
    self.num = self:AddChild(Text(BODYTEXTFONT, 26))
    self.num:SetHAlign(ANCHOR_MIDDLE)
    self.num:SetPosition(4, 0, 0)

    self.num.t1 = self:AddChild(Text(BODYTEXTFONT, 26))
    self.num.t1:SetHAlign(ANCHOR_MIDDLE)
    self.num.t1:SetPosition(4, -50, 0)
	
	    self.num.t1:SetString( tostring(
		"\n技能消耗基于等级减少"..
		"\n灵力高于150克制煞气"))
		self.num.t1:SetColour(0, 0.5, 0, 1)
		self.num.t1:Hide()	
	
	

	
	self:StartUpdating()
end)

function lingli:OnUpdate(dt)
	local newnum = self.owner.components.lingli.currentlingli
	--local oldnum = self.point
	self.lingleipercent = (250 - newnum) / 250
	self.point = newnum
	--if newnum ~= oldnum then
		self.anim:GetAnimState():SetPercent("anim", self.lingleipercent)
	--end

	self.num:SetString( tostring( math.ceil(newnum) ).."\0" )
		--设置鼠标移动到上面时的状态
		self.anim.OnGainFocus = function()
			self:OnGainFocus(self)
			self.num.t1:Show()
		end
		self.anim.OnLoseFocus = function()
			self:OnLoseFocus(self)
			self.num.t1:Hide()	
		end
		
end

function lingli:OnGainFocus()
    lingli._base.OnGainFocus(self)
end

function lingli:OnLoseFocus()
    lingli._base.OnLoseFocus(self)
end


return lingli