2014-10-02 08:49:54 +08:00
|
|
|
CreateClientConVar("zs_bossclass", "", true, true)
|
|
|
|
|
|
|
|
local Window
|
|
|
|
local HoveredClassWindow
|
|
|
|
|
|
|
|
local function CreateHoveredClassWindow(classtable)
|
2018-05-02 06:32:59 +08:00
|
|
|
if HoveredClassWindow and HoveredClassWindow:IsValid() then
|
2014-10-02 08:49:54 +08:00
|
|
|
HoveredClassWindow:Remove()
|
|
|
|
end
|
|
|
|
|
|
|
|
HoveredClassWindow = vgui.Create("ClassInfo")
|
|
|
|
HoveredClassWindow:SetSize(ScrW() * 0.5, 128)
|
|
|
|
HoveredClassWindow:CenterHorizontal()
|
|
|
|
HoveredClassWindow:MoveBelow(Window, 32)
|
|
|
|
HoveredClassWindow:SetClassTable(classtable)
|
|
|
|
end
|
|
|
|
|
2018-05-02 06:32:59 +08:00
|
|
|
function GM:OpenClassSelect()
|
|
|
|
if Window and Window:IsValid() then Window:Remove() end
|
2014-10-02 08:49:54 +08:00
|
|
|
|
2018-05-02 06:32:59 +08:00
|
|
|
Window = vgui.Create("ClassSelect")
|
2014-10-02 08:49:54 +08:00
|
|
|
Window:SetAlpha(0)
|
2018-05-02 06:32:59 +08:00
|
|
|
Window:AlphaTo(255, 0.1)
|
2014-10-02 08:49:54 +08:00
|
|
|
|
|
|
|
Window:MakePopup()
|
|
|
|
|
2018-05-02 06:32:59 +08:00
|
|
|
Window:InvalidateLayout()
|
|
|
|
|
2014-10-02 08:49:54 +08:00
|
|
|
PlayMenuOpenSound()
|
|
|
|
end
|
|
|
|
|
|
|
|
local PANEL = {}
|
|
|
|
|
2018-05-02 06:32:59 +08:00
|
|
|
PANEL.Rows = 2
|
|
|
|
|
|
|
|
local bossmode = false
|
2014-10-02 08:49:54 +08:00
|
|
|
local function BossTypeDoClick(self)
|
2018-05-02 06:32:59 +08:00
|
|
|
bossmode = not bossmode
|
|
|
|
GAMEMODE:OpenClassSelect()
|
2014-10-02 08:49:54 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
function PANEL:Init()
|
|
|
|
self.ClassButtons = {}
|
|
|
|
|
2018-05-02 06:32:59 +08:00
|
|
|
self.ClassTypeButton = EasyButton(nil, bossmode and "Open Normal Class Selection" or "Open Boss Class Selection", 8, 4)
|
|
|
|
self.ClassTypeButton:SetFont("ZSHUDFontSmall")
|
|
|
|
self.ClassTypeButton:SizeToContents()
|
|
|
|
self.ClassTypeButton.DoClick = BossTypeDoClick
|
|
|
|
|
|
|
|
self.CloseButton = EasyButton(nil, "Close", 8, 4)
|
|
|
|
self.CloseButton:SetFont("ZSHUDFontSmall")
|
|
|
|
self.CloseButton:SizeToContents()
|
|
|
|
self.CloseButton.DoClick = function() Window:Remove() end
|
|
|
|
|
|
|
|
self.ButtonGrid = vgui.Create("DGrid", self)
|
|
|
|
self.ButtonGrid:SetContentAlignment(5)
|
|
|
|
self.ButtonGrid:Dock(FILL)
|
|
|
|
|
|
|
|
local already_added = {}
|
|
|
|
local use_better_versions = GAMEMODE:ShouldUseBetterVersionSystem()
|
|
|
|
|
|
|
|
for i=1, #GAMEMODE.ZombieClasses do
|
|
|
|
local classtab = GAMEMODE.ZombieClasses[GAMEMODE:GetBestAvailableZombieClass(i)]
|
|
|
|
|
|
|
|
if classtab and not classtab.Disabled and not already_added[classtab.Index] then
|
|
|
|
already_added[classtab.Index] = true
|
|
|
|
|
|
|
|
local ok
|
|
|
|
if bossmode then
|
|
|
|
ok = classtab.Boss
|
|
|
|
else
|
|
|
|
ok = not classtab.Boss and
|
|
|
|
(not classtab.Hidden or classtab.CanUse and classtab:CanUse(MySelf)) and
|
|
|
|
(not GAMEMODE.ObjectiveMap or classtab.Unlocked)
|
|
|
|
end
|
|
|
|
|
|
|
|
if ok then
|
|
|
|
if not use_better_versions or not classtab.BetterVersionOf or GAMEMODE:IsClassUnlocked(classtab.Index) then
|
|
|
|
local button = vgui.Create("ClassButton")
|
|
|
|
button:SetClassTable(classtab)
|
|
|
|
button.Wave = classtab.Wave or 1
|
|
|
|
|
|
|
|
table.insert(self.ClassButtons, button)
|
|
|
|
|
|
|
|
self.ButtonGrid:AddItem(button)
|
|
|
|
end
|
|
|
|
end
|
2014-10-02 08:49:54 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-05-02 06:32:59 +08:00
|
|
|
self.ButtonGrid:SortByMember("Wave")
|
2014-10-02 08:49:54 +08:00
|
|
|
self:InvalidateLayout()
|
|
|
|
end
|
|
|
|
|
|
|
|
function PANEL:PerformLayout()
|
2018-05-02 06:32:59 +08:00
|
|
|
if #self.ClassButtons < 8 then self.Rows = 1 end
|
2014-10-02 08:49:54 +08:00
|
|
|
|
2018-05-02 06:32:59 +08:00
|
|
|
local cols = math.ceil(#self.ClassButtons / self.Rows)
|
|
|
|
local cell_size = ScrW() / cols
|
|
|
|
cell_size = math.min(ScrW() / 7, cell_size)
|
|
|
|
|
|
|
|
self:SetSize(ScrW(), self.Rows * cell_size)
|
|
|
|
self:CenterHorizontal()
|
|
|
|
self:CenterVertical(0.35)
|
|
|
|
|
|
|
|
self.ClassTypeButton:MoveAbove(self, 16)
|
|
|
|
self.ClassTypeButton:CenterHorizontal()
|
|
|
|
|
|
|
|
self.CloseButton:MoveAbove(self, 16)
|
|
|
|
self.CloseButton:CenterHorizontal(0.9)
|
|
|
|
|
|
|
|
self.ButtonGrid:SetCols(cols)
|
|
|
|
self.ButtonGrid:SetColWide(cell_size)
|
|
|
|
self.ButtonGrid:SetRowHeight(cell_size)
|
|
|
|
end
|
2014-10-02 08:49:54 +08:00
|
|
|
|
2018-05-02 06:32:59 +08:00
|
|
|
function PANEL:OnRemove()
|
|
|
|
self.ClassTypeButton:Remove()
|
|
|
|
self.CloseButton:Remove()
|
2014-10-02 08:49:54 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
local texUpEdge = surface.GetTextureID("gui/gradient_up")
|
|
|
|
local texDownEdge = surface.GetTextureID("gui/gradient_down")
|
|
|
|
function PANEL:Paint()
|
|
|
|
local wid, hei = self:GetSize()
|
2018-05-02 06:32:59 +08:00
|
|
|
local edgesize = 16
|
2014-10-02 08:49:54 +08:00
|
|
|
|
|
|
|
DisableClipping(true)
|
2018-05-02 06:32:59 +08:00
|
|
|
surface.SetDrawColor(Color(0, 0, 0, 220))
|
2014-10-02 08:49:54 +08:00
|
|
|
surface.DrawRect(0, 0, wid, hei)
|
|
|
|
surface.SetTexture(texUpEdge)
|
|
|
|
surface.DrawTexturedRect(0, -edgesize, wid, edgesize)
|
|
|
|
surface.SetTexture(texDownEdge)
|
|
|
|
surface.DrawTexturedRect(0, hei, wid, edgesize)
|
|
|
|
DisableClipping(false)
|
|
|
|
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
vgui.Register("ClassSelect", PANEL, "Panel")
|
|
|
|
|
2018-05-02 06:32:59 +08:00
|
|
|
PANEL = {}
|
2014-10-02 08:49:54 +08:00
|
|
|
|
|
|
|
function PANEL:Init()
|
2018-05-02 06:32:59 +08:00
|
|
|
self:SetMouseInputEnabled(true)
|
|
|
|
self:SetContentAlignment(5)
|
2014-10-02 08:49:54 +08:00
|
|
|
|
|
|
|
self.NameLabel = vgui.Create("DLabel", self)
|
|
|
|
self.NameLabel:SetFont("ZSHUDFontSmaller")
|
2018-05-02 06:32:59 +08:00
|
|
|
self.NameLabel:SetAlpha(170)
|
|
|
|
|
2014-10-02 08:49:54 +08:00
|
|
|
self.Image = vgui.Create("DImage", self)
|
|
|
|
|
|
|
|
self:InvalidateLayout()
|
|
|
|
end
|
|
|
|
|
|
|
|
function PANEL:PerformLayout()
|
2018-05-02 06:32:59 +08:00
|
|
|
local cell_size = self:GetParent():GetColWide()
|
|
|
|
|
|
|
|
self:SetSize(cell_size, cell_size)
|
|
|
|
|
|
|
|
self.Image:SetSize(cell_size * 0.75, cell_size * 0.75)
|
|
|
|
self.Image:AlignTop(8)
|
|
|
|
self.Image:CenterHorizontal()
|
2014-10-02 08:49:54 +08:00
|
|
|
|
|
|
|
self.NameLabel:SizeToContents()
|
2018-05-02 06:32:59 +08:00
|
|
|
self.NameLabel:AlignBottom(8)
|
2014-10-02 08:49:54 +08:00
|
|
|
self.NameLabel:CenterHorizontal()
|
|
|
|
end
|
|
|
|
|
|
|
|
function PANEL:SetClassTable(classtable)
|
|
|
|
self.ClassTable = classtable
|
|
|
|
|
2018-05-02 06:32:59 +08:00
|
|
|
local len = #translate.Get(classtable.TranslationName)
|
|
|
|
|
2014-10-02 08:49:54 +08:00
|
|
|
self.NameLabel:SetText(translate.Get(classtable.TranslationName))
|
2018-05-02 06:32:59 +08:00
|
|
|
self.NameLabel:SetFont(len > 15 and "ZSHUDFontTiny" or len > 11 and "ZSHUDFontSmallest" or "ZSHUDFontSmaller")
|
|
|
|
|
2014-10-02 08:49:54 +08:00
|
|
|
self.Image:SetImage(classtable.Icon)
|
2018-05-02 06:32:59 +08:00
|
|
|
self.Image:SetImageColor(classtable.IconColor or color_white)
|
2014-10-02 08:49:54 +08:00
|
|
|
|
|
|
|
self:InvalidateLayout()
|
|
|
|
end
|
|
|
|
|
2018-05-02 06:32:59 +08:00
|
|
|
function PANEL:DoClick()
|
|
|
|
if self.ClassTable then
|
|
|
|
if self.ClassTable.Boss then
|
|
|
|
RunConsoleCommand("zs_bossclass", self.ClassTable.Name)
|
|
|
|
GAMEMODE:CenterNotify(translate.Format("boss_class_select", self.ClassTable.Name))
|
|
|
|
else
|
|
|
|
net.Start("zs_changeclass")
|
|
|
|
net.WriteString(self.ClassTable.Name)
|
|
|
|
net.WriteBool(GAMEMODE.SuicideOnChangeClass)
|
|
|
|
net.SendToServer()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
surface.PlaySound("buttons/button15.wav")
|
|
|
|
|
|
|
|
Window:Remove()
|
|
|
|
bossmode = false
|
|
|
|
end
|
|
|
|
|
2014-10-02 08:49:54 +08:00
|
|
|
function PANEL:Paint()
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function PANEL:OnCursorEntered()
|
2018-05-02 06:32:59 +08:00
|
|
|
self.NameLabel:SetAlpha(230)
|
2014-10-02 08:49:54 +08:00
|
|
|
|
|
|
|
CreateHoveredClassWindow(self.ClassTable)
|
|
|
|
end
|
|
|
|
|
|
|
|
function PANEL:OnCursorExited()
|
2018-05-02 06:32:59 +08:00
|
|
|
self.NameLabel:SetAlpha(170)
|
2014-10-02 08:49:54 +08:00
|
|
|
|
2018-05-02 06:32:59 +08:00
|
|
|
if HoveredClassWindow and HoveredClassWindow:IsValid() and HoveredClassWindow.ClassTable == self.ClassTable then
|
2014-10-02 08:49:54 +08:00
|
|
|
HoveredClassWindow:Remove()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function PANEL:Think()
|
|
|
|
if not self.ClassTable then return end
|
|
|
|
|
2018-05-02 06:32:59 +08:00
|
|
|
local enabled
|
|
|
|
if MySelf:GetZombieClass() == self.ClassTable.Index then
|
|
|
|
enabled = 2
|
|
|
|
elseif self.ClassTable.Boss or gamemode.Call("IsClassUnlocked", self.ClassTable.Index) then
|
|
|
|
enabled = 1
|
|
|
|
else
|
|
|
|
enabled = 0
|
|
|
|
end
|
|
|
|
|
2014-10-02 08:49:54 +08:00
|
|
|
if enabled ~= self.LastEnabledState then
|
|
|
|
self.LastEnabledState = enabled
|
|
|
|
|
|
|
|
if enabled == 2 then
|
|
|
|
self.NameLabel:SetTextColor(COLOR_GREEN)
|
2018-05-02 06:32:59 +08:00
|
|
|
self.Image:SetImageColor(self.ClassTable.IconColor or color_white)
|
|
|
|
self.Image:SetAlpha(245)
|
2014-10-02 08:49:54 +08:00
|
|
|
elseif enabled == 1 then
|
|
|
|
self.NameLabel:SetTextColor(COLOR_GRAY)
|
2018-05-02 06:32:59 +08:00
|
|
|
self.Image:SetImageColor(self.ClassTable.IconColor or color_white)
|
|
|
|
self.Image:SetAlpha(245)
|
2014-10-02 08:49:54 +08:00
|
|
|
else
|
|
|
|
self.NameLabel:SetTextColor(COLOR_DARKRED)
|
2018-05-02 06:32:59 +08:00
|
|
|
self.Image:SetImageColor(COLOR_DARKRED)
|
|
|
|
self.Image:SetAlpha(170)
|
2014-10-02 08:49:54 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
vgui.Register("ClassButton", PANEL, "Button")
|
|
|
|
|
2018-05-02 06:32:59 +08:00
|
|
|
PANEL = {}
|
2014-10-02 08:49:54 +08:00
|
|
|
|
|
|
|
function PANEL:Init()
|
|
|
|
self.NameLabel = vgui.Create("DLabel", self)
|
|
|
|
self.NameLabel:SetFont("ZSHUDFontSmaller")
|
|
|
|
|
|
|
|
self.DescLabels = self.DescLabels or {}
|
|
|
|
|
|
|
|
self:InvalidateLayout()
|
|
|
|
end
|
|
|
|
|
|
|
|
function PANEL:SetClassTable(classtable)
|
|
|
|
self.ClassTable = classtable
|
|
|
|
|
|
|
|
self.NameLabel:SetText(translate.Get(classtable.TranslationName))
|
|
|
|
self.NameLabel:SizeToContents()
|
|
|
|
|
|
|
|
self:CreateDescLabels()
|
|
|
|
|
|
|
|
self:InvalidateLayout()
|
|
|
|
end
|
|
|
|
|
|
|
|
function PANEL:RemoveDescLabels()
|
|
|
|
for _, label in pairs(self.DescLabels) do
|
|
|
|
label:Remove()
|
|
|
|
end
|
|
|
|
|
|
|
|
self.DescLabels = {}
|
|
|
|
end
|
|
|
|
|
|
|
|
function PANEL:CreateDescLabels()
|
|
|
|
self:RemoveDescLabels()
|
|
|
|
|
|
|
|
self.DescLabels = {}
|
|
|
|
|
|
|
|
local classtable = self.ClassTable
|
|
|
|
if not classtable or not classtable.Description then return end
|
|
|
|
|
2018-05-02 06:32:59 +08:00
|
|
|
local lines = {}
|
|
|
|
|
2014-10-02 08:49:54 +08:00
|
|
|
if classtable.Wave and classtable.Wave > 0 then
|
2018-05-02 06:32:59 +08:00
|
|
|
table.insert(lines, translate.Format("unlocked_on_wave_x", classtable.Wave))
|
2014-10-02 08:49:54 +08:00
|
|
|
end
|
|
|
|
|
2018-05-02 06:32:59 +08:00
|
|
|
if classtable.BetterVersion then
|
|
|
|
local betterclasstable = GAMEMODE.ZombieClasses[classtable.BetterVersion]
|
|
|
|
if betterclasstable then
|
|
|
|
table.insert(lines, translate.Format("evolves_in_to_x_on_wave_y", betterclasstable.Name, betterclasstable.Wave))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
table.insert(lines, " ")
|
|
|
|
table.Add(lines, string.Explode("\n", translate.Get(classtable.Description)))
|
|
|
|
|
2014-10-02 08:49:54 +08:00
|
|
|
if classtable.Help then
|
|
|
|
table.insert(lines, " ")
|
|
|
|
table.Add(lines, string.Explode("\n", translate.Get(classtable.Help)))
|
|
|
|
end
|
|
|
|
|
2018-05-02 06:32:59 +08:00
|
|
|
for i, line in ipairs(lines) do
|
2014-10-02 08:49:54 +08:00
|
|
|
local label = vgui.Create("DLabel", self)
|
2018-05-02 06:32:59 +08:00
|
|
|
local notwaveone = classtable.Wave and classtable.Wave > 0
|
|
|
|
|
2014-10-02 08:49:54 +08:00
|
|
|
label:SetText(line)
|
2018-05-02 06:32:59 +08:00
|
|
|
if i == (notwaveone and 2 or 1) and classtable.BetterVersion then
|
|
|
|
label:SetColor(COLOR_RORANGE)
|
|
|
|
end
|
|
|
|
label:SetFont(i == 1 and notwaveone and "ZSBodyTextFontBig" or "ZSBodyTextFont")
|
2014-10-02 08:49:54 +08:00
|
|
|
label:SizeToContents()
|
|
|
|
table.insert(self.DescLabels, label)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function PANEL:PerformLayout()
|
|
|
|
self.NameLabel:SizeToContents()
|
|
|
|
self.NameLabel:CenterHorizontal()
|
|
|
|
|
|
|
|
local maxw = self.NameLabel:GetWide()
|
|
|
|
for _, label in pairs(self.DescLabels) do
|
|
|
|
maxw = math.max(maxw, label:GetWide())
|
|
|
|
end
|
|
|
|
self:SetWide(maxw + 64)
|
|
|
|
self:CenterHorizontal()
|
|
|
|
|
|
|
|
for i, label in ipairs(self.DescLabels) do
|
|
|
|
label:MoveBelow(self.DescLabels[i - 1] or self.NameLabel)
|
|
|
|
label:CenterHorizontal()
|
|
|
|
end
|
|
|
|
|
|
|
|
local lastlabel = self.DescLabels[#self.DescLabels] or self.NameLabel
|
2018-05-02 06:32:59 +08:00
|
|
|
local _, y = lastlabel:GetPos()
|
2014-10-02 08:49:54 +08:00
|
|
|
self:SetTall(y + lastlabel:GetTall())
|
|
|
|
end
|
|
|
|
|
|
|
|
function PANEL:Think()
|
2018-05-02 06:32:59 +08:00
|
|
|
if not Window or not Window:IsValid() or not Window:IsVisible() then
|
2014-10-02 08:49:54 +08:00
|
|
|
self:Remove()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function PANEL:Paint(w, h)
|
|
|
|
derma.SkinHook("Paint", "Frame", self, w, h)
|
|
|
|
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
vgui.Register("ClassInfo", PANEL, "Panel")
|