zombiesurvival-evolved/gamemodes/zombiesurvival/gamemode/vgui/pclassselect.lua

362 lines
8.9 KiB
Lua
Raw Permalink Normal View History

2014-10-02 08:49:54 +08:00
CreateClientConVar("zs_bossclass", "", true, true)
local Window
local HoveredClassWindow
local function CreateHoveredClassWindow(classtable)
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
function GM:OpenClassSelect()
if Window and Window:IsValid() then Window:Remove() end
2014-10-02 08:49:54 +08:00
Window = vgui.Create("ClassSelect")
2014-10-02 08:49:54 +08:00
Window:SetAlpha(0)
Window:AlphaTo(255, 0.1)
2014-10-02 08:49:54 +08:00
Window:MakePopup()
Window:InvalidateLayout()
2014-10-02 08:49:54 +08:00
PlayMenuOpenSound()
end
local PANEL = {}
PANEL.Rows = 2
local bossmode = false
2014-10-02 08:49:54 +08:00
local function BossTypeDoClick(self)
bossmode = not bossmode
GAMEMODE:OpenClassSelect()
2014-10-02 08:49:54 +08:00
end
function PANEL:Init()
self.ClassButtons = {}
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
self.ButtonGrid:SortByMember("Wave")
2014-10-02 08:49:54 +08:00
self:InvalidateLayout()
end
function PANEL:PerformLayout()
if #self.ClassButtons < 8 then self.Rows = 1 end
2014-10-02 08:49:54 +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
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()
local edgesize = 16
2014-10-02 08:49:54 +08:00
DisableClipping(true)
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")
PANEL = {}
2014-10-02 08:49:54 +08:00
function PANEL:Init()
self:SetMouseInputEnabled(true)
self:SetContentAlignment(5)
2014-10-02 08:49:54 +08:00
self.NameLabel = vgui.Create("DLabel", self)
self.NameLabel:SetFont("ZSHUDFontSmaller")
self.NameLabel:SetAlpha(170)
2014-10-02 08:49:54 +08:00
self.Image = vgui.Create("DImage", self)
self:InvalidateLayout()
end
function PANEL:PerformLayout()
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()
self.NameLabel:AlignBottom(8)
2014-10-02 08:49:54 +08:00
self.NameLabel:CenterHorizontal()
end
function PANEL:SetClassTable(classtable)
self.ClassTable = classtable
local len = #translate.Get(classtable.TranslationName)
2014-10-02 08:49:54 +08:00
self.NameLabel:SetText(translate.Get(classtable.TranslationName))
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)
self.Image:SetImageColor(classtable.IconColor or color_white)
2014-10-02 08:49:54 +08:00
self:InvalidateLayout()
end
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()
self.NameLabel:SetAlpha(230)
2014-10-02 08:49:54 +08:00
CreateHoveredClassWindow(self.ClassTable)
end
function PANEL:OnCursorExited()
self.NameLabel:SetAlpha(170)
2014-10-02 08:49:54 +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
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)
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)
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)
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")
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
local lines = {}
2014-10-02 08:49:54 +08:00
if classtable.Wave and classtable.Wave > 0 then
table.insert(lines, translate.Format("unlocked_on_wave_x", classtable.Wave))
2014-10-02 08:49:54 +08:00
end
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
for i, line in ipairs(lines) do
2014-10-02 08:49:54 +08:00
local label = vgui.Create("DLabel", self)
local notwaveone = classtable.Wave and classtable.Wave > 0
2014-10-02 08:49:54 +08:00
label:SetText(line)
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
local _, y = lastlabel:GetPos()
2014-10-02 08:49:54 +08:00
self:SetTall(y + lastlabel:GetTall())
end
function PANEL:Think()
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")