From 57cc63e3b3d687afc9fae6b88f9cdb732b2b3ed6 Mon Sep 17 00:00:00 2001 From: Zoephix Date: Sun, 14 Feb 2021 14:42:17 +0100 Subject: [PATCH] Update sh_plugin.lua --- plugins/f1menu/sh_plugin.lua | 217 +++++++++++++++++++++++++---------- 1 file changed, 159 insertions(+), 58 deletions(-) diff --git a/plugins/f1menu/sh_plugin.lua b/plugins/f1menu/sh_plugin.lua index 7a401829..e29ca77f 100644 --- a/plugins/f1menu/sh_plugin.lua +++ b/plugins/f1menu/sh_plugin.lua @@ -1,68 +1,169 @@ -PLUGIN.name = "F1 Menu" -PLUGIN.author = "Cheesenut" -PLUGIN.desc = "A menu that shows up upon pressing F1." +local PANEL = {} + function PANEL:Init() + if (IsValid(nut.gui.info)) then + nut.gui.info:Remove() + end + + nut.gui.info = self + + self:SetSize(ScrW() * 0.6, ScrH() * 0.7) + self:Center() + + local suppress = hook.Run("CanCreateCharInfo", self) + + if (!suppress or (suppress and !suppress.all)) then + if (!suppress or !suppress.model) then + self.model = self:Add("nutModelPanel") + self.model:SetWide(ScrW() * 0.25) + self.model:Dock(LEFT) + self.model:SetFOV(50) + self.model.enableHook = true + self.model.copyLocalSequence = true + end + + if (!suppress or !suppress.info) then + self.info = self:Add("DPanel") + self.info:SetWide(ScrW() * 0.4) + self.info:Dock(RIGHT) + self.info:SetPaintBackground(false) + self.info:DockMargin(150, ScrH() * 0.2, 0, 0) + end + + if (!suppress or !suppress.name) then + self.name = self.info:Add("DLabel") + self.name:SetFont("nutHugeFont") + self.name:SetTall(60) + self.name:Dock(TOP) + self.name:SetTextColor(color_white) + self.name:SetExpensiveShadow(1, Color(0, 0, 0, 150)) + end -function PLUGIN:ShowHelp() return false end + if (!suppress or !suppress.desc) then + self.desc = self.info:Add("DTextEntry") + self.desc:Dock(TOP) + self.desc:SetFont("nutMediumLightFont") + self.desc:SetTall(28) + end -if (SERVER) then return end + if (!suppress or !suppress.time) then + self.time = self.info:Add("DLabel") + self.time:SetFont("nutMediumFont") + self.time:SetTall(28) + self.time:Dock(TOP) + self.time:SetTextColor(color_white) + self.time:SetExpensiveShadow(1, Color(0, 0, 0, 150)) + end -function PLUGIN:PlayerBindPress(client, bind, pressed) - if (bind:lower():find("gm_showhelp") and pressed) then - if (IsValid(nut.gui.menu)) then - nut.gui.menu:remove() - elseif (LocalPlayer():getChar()) then - vgui.Create("nutMenu") + if (!suppress or !suppress.money) then + self.money = self.info:Add("DLabel") + self.money:Dock(TOP) + self.money:SetFont("nutMediumFont") + self.money:SetTextColor(color_white) + self.money:SetExpensiveShadow(1, Color(0, 0, 0, 150)) + self.money:DockMargin(0, 10, 0, 0) + end + + if (!suppress or !suppress.faction) then + self.faction = self.info:Add("DLabel") + self.faction:Dock(TOP) + self.faction:SetFont("nutMediumFont") + self.faction:SetTextColor(color_white) + self.faction:SetExpensiveShadow(1, Color(0, 0, 0, 150)) + self.faction:DockMargin(0, 10, 0, 0) + end + + if (!suppress or !suppress.class) then + local class = nut.class.list[LocalPlayer():getChar():getClass()] + + if (class) then + self.class = self.info:Add("DLabel") + self.class:Dock(TOP) + self.class:SetFont("nutMediumFont") + self.class:SetTextColor(color_white) + self.class:SetExpensiveShadow(1, Color(0, 0, 0, 150)) + self.class:DockMargin(0, 10, 0, 0) + end + end + + hook.Run("CreateCharInfoText", self, suppress) end - return true + hook.Run("CreateCharInfo", self) end -end - -function PLUGIN:OnCharInfoSetup(infoPanel) - -- Get the model entity from the F1 menu. - if (not IsValid(infoPanel.model)) then return end - local mdl = infoPanel.model - local ent = mdl.Entity - local client = LocalPlayer() - - -- If the player is alive with a weapon, add a weapon model to the - -- character model in the F1 menu. - if (not IsValid(client) or not client:Alive()) then return end - local weapon = client:GetActiveWeapon() - if (not IsValid(weapon)) then return end - - local weapModel = ClientsideModel(weapon:GetModel(), RENDERGROUP_BOTH) - if (not IsValid(weapModel)) then return end - - weapModel:SetParent(ent) - weapModel:AddEffects(EF_BONEMERGE) - weapModel:SetSkin(weapon:GetSkin()) - weapModel:SetColor(weapon:GetColor()) - weapModel:SetNoDraw(true) - ent.weapon = weapModel - - -- Then, change the animation so the character model holds the weapon. - local act = ACT_MP_STAND_IDLE - local model = ent:GetModel():lower() - local class = nut.anim.getModelClass(model) - local tree = nut.anim[class] - - if (not tree) then return end - - local subClass = weapon.HoldType or weapon:GetHoldType() - subClass = HOLDTYPE_TRANSLATOR[subClass] or subClass - - if (tree[subClass] and tree[subClass][act]) then - local branch = tree[subClass][act] - local act2 = istable(branch) and branch[1] or branch - - if (isstring(act2)) then - act2 = ent:LookupSequence(act2) - else - act2 = ent:SelectWeightedSequence(act2) + + function PANEL:setup() + local char = LocalPlayer():getChar() + if (self.desc) then + self.desc:SetText(char:getDesc():gsub("#", "\226\128\139#")) + self.desc.OnEnter = function(this, w, h) + nut.command.send( + "chardesc", + (this:GetText():gsub("\226\128\139#", "#")) + ) + end + end + + if (self.name) then + self.name:SetText(LocalPlayer():Name():gsub("#", "\226\128\139#")) + hook.Add( + "OnCharVarChanged", + self, + function(panel, character, key, oldValue, value) + if (char ~= character) then return end + if (key ~= "name") then return end + + self.name:SetText(value:gsub("#", "\226\128\139#")) + end + ) end - ent:ResetSequence(act2) + if (self.money) then + self.money:SetText(L("charMoney", nut.currency.get(char:getMoney()))) + end + + if (self.faction) then + self.faction:SetText(L("charFaction", L(team.GetName(LocalPlayer():Team())))) + end + + if (self.time) then + local format = "%A, %d %B "..nut.config.get("year").." %T" + + self.time:SetText(L("curTime", nut.date.getFormatted(format))) + self.time.Think = function(this) + if ((this.nextTime or 0) < CurTime()) then + this:SetText(L("curTime", nut.date.getFormatted(format))) + this.nextTime = CurTime() + 0.5 + end + end + end + + if (self.class) then + local class = nut.class.list[char:getClass()] + if (class) then + self.class:SetText(L("charClass", L(class.name))) + end + end + + if (self.model) then + self.model:SetModel(LocalPlayer():GetModel()) + self.model.Entity:SetSkin(LocalPlayer():GetSkin()) + + for k, v in ipairs(LocalPlayer():GetBodyGroups()) do + self.model.Entity:SetBodygroup(v.id, LocalPlayer():GetBodygroup(v.id)) + end + + local ent = self.model.Entity + if (ent and IsValid(ent)) then + local mats = LocalPlayer():GetMaterials() + for k, v in pairs(mats) do + ent:SetSubMaterial(k - 1, LocalPlayer():GetSubMaterial(k - 1)) + end + end + end + + hook.Run("OnCharInfoSetup", self) end -end + function PANEL:Paint(w, h) + end +vgui.Register("nutCharInfo", PANEL, "EditablePanel")