2020-01-22 14:25:58 +00:00
|
|
|
-- Copyright (c) 2020 David Vogel
|
|
|
|
--
|
|
|
|
-- This software is released under the MIT License.
|
|
|
|
-- https://opensource.org/licenses/MIT
|
|
|
|
|
2016-10-05 12:30:35 +00:00
|
|
|
local PANEL = {}
|
|
|
|
|
|
|
|
function PANEL:Init()
|
2018-08-03 09:22:18 +00:00
|
|
|
self.Progress = vgui.Create("DProgress", self)
|
|
|
|
self.Progress:SetPos(10, 10)
|
|
|
|
self.Progress:SetSize(200, 20)
|
|
|
|
|
|
|
|
self.Label_XP = vgui.Create("DLabel", self)
|
|
|
|
self.Label_XP:SetTextColor(color_black)
|
|
|
|
self.Label_XP:SetFont(D3stats.Font_Overlay_XP)
|
|
|
|
self.Label_XP:SetSize(200, 20)
|
|
|
|
self.Label_XP:SetPos(10, 10) -- Set the position of the label
|
|
|
|
self.Label_XP:SetContentAlignment(5)
|
|
|
|
|
|
|
|
self.Label_Level = vgui.Create("DLabel", self)
|
|
|
|
self.Label_Level:SetFont(D3stats.Font_Overlay_Level)
|
|
|
|
self.Label_Level:SetPos(10, 35) -- Set the position of the label
|
|
|
|
self.Label_Level:SetSize(200, 20)
|
|
|
|
self.Label_Level:SetContentAlignment(5)
|
|
|
|
|
|
|
|
self:StatsUpdate(0, 1)
|
|
|
|
--self.Label:SetDark(1) -- Set the colour of the text inside the label to a darker one
|
|
|
|
|
|
|
|
--timer.Create("D3statsOverlay_Timer", 0.1, 0, function() self.Progress:SetFraction(math.random()) end)
|
2016-10-05 12:30:35 +00:00
|
|
|
end
|
|
|
|
|
2018-08-03 09:22:18 +00:00
|
|
|
function PANEL:Paint(aWide, aTall)
|
2016-10-05 12:30:35 +00:00
|
|
|
-- Nothing for now
|
|
|
|
end
|
|
|
|
|
2018-08-03 09:22:18 +00:00
|
|
|
function PANEL:StatsUpdate(XP, Level)
|
2016-10-09 16:11:56 +00:00
|
|
|
local Text_XP
|
|
|
|
local Text_Level
|
2016-10-05 12:30:35 +00:00
|
|
|
local Fraction
|
|
|
|
|
2018-08-03 09:22:18 +00:00
|
|
|
if D3stats.Levels[Level+1] then
|
|
|
|
Text_XP = "XP: " .. tostring(XP) .. " / " .. D3stats.Levels[Level+1].XP_needed
|
|
|
|
Fraction = (XP - D3stats.Levels[Level].XP_needed) / (D3stats.Levels[Level+1].XP_needed - D3stats.Levels[Level].XP_needed)
|
2016-10-05 12:30:35 +00:00
|
|
|
else
|
2018-08-03 09:22:18 +00:00
|
|
|
Text_XP = "XP: " .. tostring(XP)
|
2016-10-05 12:30:35 +00:00
|
|
|
Fraction = 1
|
|
|
|
end
|
|
|
|
|
2018-08-03 09:22:18 +00:00
|
|
|
Text_Level = "Level: " .. tostring(Level) .. " \"" .. D3stats.Levels[Level].Name .. "\""
|
2016-10-09 16:11:56 +00:00
|
|
|
|
2018-08-03 09:22:18 +00:00
|
|
|
self.Label_XP:SetText(Text_XP) -- Set the text of the label
|
2016-10-09 16:11:56 +00:00
|
|
|
--self.Label_XP:SizeToContents() -- Size the label to fit the text in it
|
|
|
|
|
2018-08-03 09:22:18 +00:00
|
|
|
self.Label_Level:SetText(Text_Level) -- Set the text of the label
|
2016-10-09 16:11:56 +00:00
|
|
|
--self.Label_Level:SizeToContents() -- Size the label to fit the text in it
|
2016-10-05 12:30:35 +00:00
|
|
|
|
2018-08-03 09:22:18 +00:00
|
|
|
self.Progress:SetFraction(Fraction)
|
2016-10-05 12:30:35 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2018-08-03 09:22:18 +00:00
|
|
|
function PANEL:SetText(aText) self.Text = tostring(aText) end
|
2016-10-05 12:30:35 +00:00
|
|
|
function PANEL:GetText() return self.Text or "" end
|
|
|
|
|
2018-08-03 09:22:18 +00:00
|
|
|
vgui.Register("D3statsOverlay", PANEL, "DPanel")
|