TTT2 new addon config menu support

This commit is contained in:
TheOnly8Z 2021-10-19 16:11:10 -04:00
parent 525fd17416
commit fc0637c9f4
6 changed files with 191 additions and 59 deletions

View File

@ -360,7 +360,7 @@ local NPCsPanel = {
{ type = "b", text = "NPC Attachments", var = "arccw_npc_atts", sv = true },
}
local function networktheconvar(convar, value, p)
function ArcCW.NetworkConvar(convar, value, p)
if !LocalPlayer():IsAdmin() then return end
if (p.TickCreated or 0) == UnPredictedCurTime() then return end
if value == true or value == false then
@ -435,11 +435,11 @@ function ArcCW.GeneratePanelElements(panel, table)
p.TickCreated = UnPredictedCurTime()
if data.type == "b" then
p.OnChange = function(self, bval)
networktheconvar(data.var, bval, self)
ArcCW.NetworkConvar(data.var, bval, self)
end
elseif data.type == "i" or data.type == "f" or data.type == "m" or data.type == "t" then
p.OnValueChanged = function(self, bval)
networktheconvar(data.var, bval, self)
ArcCW.NetworkConvar(data.var, bval, self)
end
end
end
@ -669,19 +669,19 @@ function ArcCW_Options_Binds(panel)
end
ArcCW.ClientMenus = {
["ArcCW_Options_Client"] = { text = "#arccw.menus.client", func = ArcCW_Options_Client },
["ArcCW_Options_Bullet"] = { text = "#arccw.menus.bullet", func = ArcCW_Options_Bullet },
["ArcCW_Options_Perf"] = { text = "#arccw.menus.perf", func = ArcCW_Options_Perf },
["ArcCW_Options_Viewmodel"] = { text = "#arccw.menus.vmodel", func = ArcCW_Options_Viewmodel },
["ArcCW_Options_HUD"] = { text = "#arccw.menus.hud", func = ArcCW_Options_HUD },
["ArcCW_Options_Crosshair"] = { text = "#arccw.menus.xhair", func = ArcCW_Options_Crosshair },
["ArcCW_Options_Server"] = { text = "#arccw.menus.server", func = ArcCW_Options_Server },
["ArcCW_Options_Ammo"] = { text = "#arccw.menus.ammo", func = ArcCW_Options_Ammo },
["ArcCW_Options_Atts"] = { text = "#arccw.menus.atts", func = ArcCW_Options_Atts },
["ArcCW_Options_Mults"] = { text = "#arccw.menus.mults", func = ArcCW_Options_Mults },
["ArcCW_Options_Dev"] = { text = "#arccw.menus.dev", func = ArcCW_Options_Dev },
["ArcCW_Options_NPC"] = { text = "#arccw.menus.npcs", func = ArcCW_Options_NPC },
["ArcCW_Options_Binds"] = { text = "#arccw.menus.binds", func = ArcCW_Options_Binds },
["ArcCW_Options_Client"] = { text = "#arccw.menus.client", func = ArcCW_Options_Client, tbl = ClientPanel },
["ArcCW_Options_Bullet"] = { text = "#arccw.menus.bullet", func = ArcCW_Options_Bullet, tbl = BulletPanel },
["ArcCW_Options_Perf"] = { text = "#arccw.menus.perf", func = ArcCW_Options_Perf, tbl = PerformancePanel },
["ArcCW_Options_Viewmodel"] = { text = "#arccw.menus.vmodel", func = ArcCW_Options_Viewmodel, tbl = ViewmodelPanel },
["ArcCW_Options_HUD"] = { text = "#arccw.menus.hud", func = ArcCW_Options_HUD, tbl = HudPanel },
["ArcCW_Options_Crosshair"] = { text = "#arccw.menus.xhair", func = ArcCW_Options_Crosshair, tbl = CrosshairPanel },
["ArcCW_Options_Server"] = { text = "#arccw.menus.server", func = ArcCW_Options_Server, tbl = ServerPanel },
["ArcCW_Options_Ammo"] = { text = "#arccw.menus.ammo", func = ArcCW_Options_Ammo, tbl = AmmoPanel },
["ArcCW_Options_Atts"] = { text = "#arccw.menus.atts", func = ArcCW_Options_Atts, tbl = AttsPanel },
["ArcCW_Options_Mults"] = { text = "#arccw.menus.mults", func = ArcCW_Options_Mults, tbl = MultsPanel },
["ArcCW_Options_Dev"] = { text = "#arccw.menus.dev", func = ArcCW_Options_Dev, tbl = DevPanel },
["ArcCW_Options_NPC"] = { text = "#arccw.menus.npcs", func = ArcCW_Options_NPC, tbl = NPCsPanel },
["ArcCW_Options_Binds"] = { text = "#arccw.menus.binds", func = ArcCW_Options_Binds, tbl = BindsPanel },
}
hook.Add("PopulateToolMenu", "ArcCW_Options", function()

View File

@ -1,7 +1,5 @@
if engine.ActiveGamemode() != "terrortown" then return end
CreateClientConVar("arccw_ttt_inforoundstart", "1", true, false, "Whether to show ArcCW config every round.")
CreateClientConVar("arccw_ttt_rolecrosshair", "1", true, false, "Whether to color your crosshair according to your role.")
@ -177,7 +175,8 @@ hook.Add("TTTPrepareRound", "ArcCW_TTT_Info", function()
ArcCW.TTT_AttInfo = {}
end)
hook.Add("TTTSettingsTabs", "ArcCW_TTT", function(dtabs)
if !TTT2 then
hook.Add("TTTSettingsTabs", "ArcCW_TTT", function(dtabs)
local padding = dtabs:GetPadding() * 2
@ -194,15 +193,10 @@ hook.Add("TTTSettingsTabs", "ArcCW_TTT", function(dtabs)
dgui:CheckBox("#arccw.cvar.ttt_rolecrosshair", "arccw_ttt_rolecrosshair")
panellist:AddItem(dgui)
-- Can't rely on LocalPlayer() being valid now
-- TTT2 generates tabs before menu opens
--if LocalPlayer():IsAdmin() then
local dgui2 = vgui.Create("DForm", panellist)
dgui2:SetName("#arccw.menus.ttt_server")
ArcCW.GeneratePanelElements(dgui2, TTTPanel)
panellist:AddItem(dgui2)
--end
for menu, data in SortedPairs(ArcCW.ClientMenus) do
local form = vgui.Create("DForm", panellist)
@ -212,8 +206,13 @@ hook.Add("TTTSettingsTabs", "ArcCW_TTT", function(dtabs)
panellist:AddItem(form)
end
dtabs:AddSheet("ArcCW", panellist, "icon16/gun.png", false, false, "ArcCW Settings")
end)
dtabs:AddSheet("ArcCW", panellist, "icon16/gun.png", false, false, "ArcCW")
end)
end
-----------------------------
-- TTT2-specific support
-----------------------------
hook.Add("TTTRenderEntityInfo", "ArcCW_TTT2_Weapons", function(tData)
local client = LocalPlayer()
@ -272,3 +271,79 @@ hook.Add("TTTRenderEntityInfo", "ArcCW_TTT2_Ammo", function(tData)
tData:SetTitle(ent.PrintName)
tData:SetSubtitle(ArcCW.GetTranslation("ttt.ammo") .. ent:GetNWInt("truecount", ent.AmmoCount))
end)
function ArcCW.TTT2_PopulateSettings(parent, title, tbl)
local form = vgui.CreateTTT2Form(parent, title)
for _, data in pairs(tbl) do
local name = data.text
if string.Left(name, 1) == "#" then name = string.sub(name, 2) end
if data.type == "h" or data.type == "c" then
form:MakeHelp({
label = name
})
end
local cvar = GetConVar(data.var or "")
if !cvar then continue end
local option
if data.type == "b" then
option = form:MakeCheckBox({
label = name,
default = tobool(cvar:GetDefault()),
initial = cvar:GetBool(),
OnChange = function(self, value)
ArcCW.NetworkConvar(data.var, value, self)
end,
})
option.TickCreated = UnPredictedCurTime()
elseif data.type == "i" or data.type == "f" then
option = form:MakeSlider({
label = name,
min = data.min,
max = data.max,
decimal = data.type == "i" and 0 or 2,
default = tonumber(cvar:GetDefault()),
initial = data.type == "i" and cvar:GetInt() or cvar:GetFloat(),
OnChange = function(self, value)
ArcCW.NetworkConvar(data.var, value, self)
end,
})
option.TickCreated = UnPredictedCurTime()
elseif data.type == "o" then
option = form:MakeComboBox({
label = name,
default = tonumber(cvar:GetDefault()),
initial = cvar:GetInt(),
--choices = data.choices,
OnChange = function(self, _, _, value)
ArcCW.NetworkConvar(data.var, value, self)
end,
})
option.TickCreated = UnPredictedCurTime()
for k, v in pairs(data.choices) do
option:AddChoice(v, k)
if k == tonumber(cvar:GetDefault()) then
option:ChooseOptionId(k)
end
end
end
end
end
function ArcCW.TTT2_LoadClientLangs()
local files = file.Find("arccw/client/cl_languages/*", "LUA")
for _, v in pairs(files) do
local exp = string.Explode("_", string.lower(string.Replace(v, ".lua", "")))
include("arccw/client/cl_languages/" .. v)
for phrase, str in pairs(L) do
LANG.AddToLanguage(exp[#exp], phrase, str)
end
print("Loaded ArcCW cl_language file " .. v .. " with " .. table.Count(L) .. " strings.")
end
end
hook.Add("PostGamemodeLoaded", "ArcCW_TTT2_Localization", ArcCW.TTT2_LoadClientLangs)

View File

@ -104,14 +104,23 @@ hook.Add("InitPostEntity", "ArcCW_TTT", function()
local path = "arccw/weaponicons/" .. class
local path2 = "arccw/ttticons/" .. class .. ".png"
local path3 = "vgui/ttt/" .. class
local mat2 = Material(path2)
local path4 = "entities/" .. class .. ".png"
if !mat2:IsError() then
if !Material(path2):IsError() then
-- TTT icon (png)
wep.Icon = path2
elseif !Material(path3):IsError() then
-- TTT icon (vtf)
wep.Icon = path3
elseif !Material(path4):IsError() then
-- Entity spawn icon
wep.Icon = path4
elseif !Material(path):IsError() then
-- Kill icon
wep.Icon = path
else
-- fallback: display _something_
wep.Icon = "arccw/hud/arccw_bird.png"
end
end

View File

@ -154,15 +154,6 @@ if CLIENT then
local lang = ArcCW.GetLanguage()
files = files or file.Find("arccw/client/cl_languages/*", "LUA")
--[[]
-- First make sure there is actually a file in such language; otherwise default to english
local has = false
for _, v in pairs(files) do
local exp = string.Explode("_", string.lower(string.Replace(v, ".lua", "")))
if exp[#exp] == lang then has = true break end
end
if !has then lang = "en" end
]]
local lang_tbl = {}
local lang_tbl_en = {}
@ -229,7 +220,6 @@ function ArcCW.LoadLanguages()
if CLIENT then
ArcCW.LoadClientLanguage()
end
hook.Run("ArcCW_LocalizationLoaded")
@ -249,7 +239,6 @@ hook.Add("PreGamemodeLoaded", "ArcCW_Lang", function()
end
end)
concommand.Add("arccw_reloadlangs", function(ply)
ArcCW.LoadLanguages()
if SERVER and game.SinglePlayer() then

View File

@ -0,0 +1,27 @@
CLGAMEMODESUBMENU.base = "base_gamemodesubmenu"
CLGAMEMODESUBMENU.priority = 0
CLGAMEMODESUBMENU.title = "ArcCW"
local TTTPanel = {
{ type = "h", text = "#arccw.ttt_clienthelp" },
{ type = "b", text = "#arccw.cvar.ttt_inforoundstart", var = "arccw_ttt_rolecrosshair"},
{ type = "b", text = "#arccw.cvar.ttt_rolecrosshair", var = "arccw_ttt_inforoundstart"},
}
local clientpanels = {
"ArcCW_Options_Client",
"ArcCW_Options_Crosshair",
"ArcCW_Options_HUD",
"ArcCW_Options_Viewmodel",
"ArcCW_Options_Perf",
--"ArcCW_Options_Binds",
}
function CLGAMEMODESUBMENU:Populate(parent)
ArcCW.TTT2_PopulateSettings(parent, "arccw.menus.ttt_client", TTTPanel)
for _, pnlname in pairs(clientpanels) do
local pnl = ArcCW.ClientMenus[pnlname]
ArcCW.TTT2_PopulateSettings(parent, pnl.text, pnl.tbl)
end
end

View File

@ -0,0 +1,32 @@
CLGAMEMODESUBMENU.base = "base_gamemodesubmenu"
CLGAMEMODESUBMENU.priority = 0
CLGAMEMODESUBMENU.title = "ArcCW"
local TTTPanel = {
{ type = "h", text = "#arccw.ttt_serverhelp" },
{ type = "b", text = "#arccw.cvar.ttt_replace", var = "arccw_ttt_replace", sv = true },
{ type = "b", text = "#arccw.cvar.ammo_replace", var = "arccw_ttt_ammo", sv = true },
{ type = "b", text = "#arccw.cvar.ttt_atts", var = "arccw_ttt_atts", sv = true },
{ type = "o", text = "#arccw.cvar.ttt_customizemode", var = "arccw_ttt_customizemode", sv = true,
choices = {[0] = "#arccw.cvar.ttt_customizemode.0", [1] = "#arccw.cvar.ttt_customizemode.1", [2] = "#arccw.cvar.ttt_customizemode.2", [3] = "#arccw.cvar.ttt_customizemode.3"}},
{ type = "o", text = "#arccw.cvar.ttt_bodyattinfo", var = "arccw_ttt_bodyattinfo", sv = true,
choices = {[0] = "#arccw.combobox.disabled", [1] = "#arccw.cvar.ttt_bodyattinfo.1", [2] = "#arccw.cvar.ttt_bodyattinfo.2"}},
{ type = "c", text = "#arccw.cvar.ttt_bodyattinfo.help"},
}
local serverpanels = {
"ArcCW_Options_Server",
"ArcCW_Options_Atts",
"ArcCW_Options_Ammo",
"ArcCW_Options_Mults",
"ArcCW_Options_Bullet",
}
function CLGAMEMODESUBMENU:Populate(parent)
ArcCW.TTT2_PopulateSettings(parent, "arccw.menus.ttt_server", TTTPanel)
for _, pnlname in pairs(serverpanels) do
local pnl = ArcCW.ClientMenus[pnlname]
ArcCW.TTT2_PopulateSettings(parent, pnl.text, pnl.tbl)
end
end