From 67942698ee1f31bb99f2e5516cbb97a251d070ee Mon Sep 17 00:00:00 2001 From: TovarischPootis <54110479+TovarischPootis@users.noreply.github.com> Date: Sun, 9 May 2021 10:17:00 +0300 Subject: [PATCH 1/4] Add font scaling This allows fonts that are too large for the UI to be adjusted --- gamemode/config/sh_config.lua | 5 +++ gamemode/core/derma/cl_inventory.lua | 16 ++++++--- gamemode/core/hooks/cl_hooks.lua | 54 ++++++++++++++-------------- 3 files changed, 43 insertions(+), 32 deletions(-) diff --git a/gamemode/config/sh_config.lua b/gamemode/config/sh_config.lua index daf3b332..957cd822 100644 --- a/gamemode/config/sh_config.lua +++ b/gamemode/config/sh_config.lua @@ -29,6 +29,11 @@ nut.config.add("genericFont", "Segoe UI", "The font used to display generic text hook.Run("LoadNutFonts", nut.config.get("font"), newValue) end end, {category = "appearance"}) +nut.config.add("fontScale", 1.0, "The scale for the font.", function(oldValue, newValue) + if (CLIENT) then + hook.Run("LoadNutFonts", nut.config.get("font"), nut.config.get("genericFont")) + end +end, { form = "Float", data = {min = 0.1, max = 2.0}, category = "appearance"}) nut.config.add("chatRange", 280, "The maximum distance a person's IC chat message goes to.", nil, { form = "Float", diff --git a/gamemode/core/derma/cl_inventory.lua b/gamemode/core/derma/cl_inventory.lua index 9d1ad015..4abb043e 100644 --- a/gamemode/core/derma/cl_inventory.lua +++ b/gamemode/core/derma/cl_inventory.lua @@ -34,6 +34,8 @@ function PANEL:setItemType(itemTypeOrID) if (isnumber(itemTypeOrID)) then item = nut.item.instances[itemTypeOrID] self.itemID = itemTypeOrID + else + self.itemType = itemTypeOrID end assert(item, "invalid item type or ID "..tostring(item)) @@ -97,9 +99,13 @@ function PANEL:Init() self:SetSize(NS_ICON_SIZE, NS_ICON_SIZE) end +--[[ function PANEL:Think() + self.itemTable = nut.item.instances[self.itemID] + self:updateTooltip() +end ]] + function PANEL:PaintOver(w, h) local itemTable = nut.item.instances[self.itemID] - if (itemTable and itemTable.paintOver) then local w, h = self:GetSize() @@ -308,20 +314,20 @@ hook.Add("CreateMenuButtons", "nutInventory", function(tabs) local childPanels = inventory:show(mainPanel) nut.gui["inv"..inventory:getID()] = childPanels table.insert(sortPanels, childPanels) - + totalSize.x = totalSize.x + childPanels:GetWide() + margin totalSize.y = math.max(totalSize.y, childPanels:GetTall()) end end - + local px, py, pw, ph = mainPanel:GetBounds() - local x, y = px + pw/2 - totalSize.x / 2, py + ph/2 + local x, y = px + pw/2 - totalSize.x / 2, py + ph/2 for _, panel in pairs(sortPanels) do panel:ShowCloseButton(true) panel:SetPos(x, y - panel:GetTall()/2) x = x + panel:GetWide() + margin end - + hook.Add("PostRenderVGUI", mainPanel, function() hook.Run("PostDrawInventory", mainPanel) end) diff --git a/gamemode/core/hooks/cl_hooks.lua b/gamemode/core/hooks/cl_hooks.lua index e4359592..633a900f 100644 --- a/gamemode/core/hooks/cl_hooks.lua +++ b/gamemode/core/hooks/cl_hooks.lua @@ -1,6 +1,7 @@ function GM:LoadNutFonts(font, genericFont) local oldFont, oldGenericFont = font, genericFont - + local scale = math.Round(nut.config.get("fontScale", 1), 2) + print(ScreenScale(14) * scale, ScreenScale(14)) surface.CreateFont("nut3D2DFont", { font = font, size = 2048, @@ -10,28 +11,28 @@ function GM:LoadNutFonts(font, genericFont) surface.CreateFont("nutTitleFont", { font = font, - size = ScreenScale(30), + size = ScreenScale(30) * scale, extended = true, weight = 1000 }) surface.CreateFont("nutSubTitleFont", { font = font, - size = ScreenScale(18), + size = ScreenScale(18) * scale, extended = true, weight = 500 }) surface.CreateFont("nutMenuButtonFont", { font = font, - size = ScreenScale(14), + size = ScreenScale(14) * scale, extended = true, weight = 1000 }) surface.CreateFont("nutMenuButtonLightFont", { font = font, - size = ScreenScale(14), + size = ScreenScale(14) * scale, extended = true, weight = 200 }) @@ -45,21 +46,21 @@ function GM:LoadNutFonts(font, genericFont) surface.CreateFont("nutDynFontSmall", { font = font, - size = ScreenScale(22), + size = ScreenScale(22) * scale, extended = true, weight = 1000 }) surface.CreateFont("nutDynFontMedium", { font = font, - size = ScreenScale(28), + size = ScreenScale(28) * scale, extended = true, weight = 1000 }) surface.CreateFont("nutDynFontBig", { font = font, - size = ScreenScale(48), + size = ScreenScale(48) * scale, extended = true, weight = 1000 }) @@ -69,63 +70,63 @@ function GM:LoadNutFonts(font, genericFont) surface.CreateFont("nutCleanTitleFont", { font = font, - size = 200, + size = 200 * scale, extended = true, weight = 1000 }) surface.CreateFont("nutHugeFont", { font = font, - size = 72, + size = 72 * scale, extended = true, weight = 1000 }) surface.CreateFont("nutBigFont", { font = font, - size = 36, + size = 36 * scale, extended = true, weight = 1000 }) surface.CreateFont("nutMediumFont", { font = font, - size = 25, + size = 25 * scale, extended = true, weight = 1000 }) surface.CreateFont("nutMediumLightFont", { font = font, - size = 25, + size = 25 * scale, extended = true, weight = 200 }) surface.CreateFont("nutGenericFont", { font = font, - size = 20, + size = 20 * scale, extended = true, weight = 1000 }) surface.CreateFont("nutGenericLightFont", { font = font, - size = 20, + size = 20 * scale, extended = true, weight = 500 }) surface.CreateFont("nutChatFont", { font = font, - size = math.max(ScreenScale(7), 17), + size = math.max(ScreenScale(7), 17) * scale, extended = true, weight = 200 }) surface.CreateFont("nutChatFontItalics", { font = font, - size = math.max(ScreenScale(7), 17), + size = math.max(ScreenScale(7), 17) * scale, extended = true, weight = 200, italic = true @@ -133,21 +134,21 @@ function GM:LoadNutFonts(font, genericFont) surface.CreateFont("nutChatFontBold", { font = font, - size = math.max(ScreenScale(7), 17), + size = math.max(ScreenScale(7), 17) * scale, extended = true, weight = 800, }) surface.CreateFont("nutSmallFont", { font = font, - size = math.max(ScreenScale(6), 17), + size = math.max(ScreenScale(6), 17) * scale, extended = true, weight = 500 }) surface.CreateFont("nutItemDescFont", { font = font, - size = math.max(ScreenScale(6), 17), + size = math.max(ScreenScale(6), 17) * scale, extended = true, shadow = true, weight = 500 @@ -155,7 +156,7 @@ function GM:LoadNutFonts(font, genericFont) surface.CreateFont("nutSmallBoldFont", { font = font, - size = math.max(ScreenScale(8), 20), + size = math.max(ScreenScale(8), 20) * scale, extended = true, weight = 800 }) @@ -163,7 +164,7 @@ function GM:LoadNutFonts(font, genericFont) surface.CreateFont("nutItemBoldFont", { font = font, shadow = true, - size = math.max(ScreenScale(8), 20), + size = math.max(ScreenScale(8), 20) * scale, extended = true, weight = 800 }) @@ -286,7 +287,6 @@ end function GM:CharacterListLoaded() local shouldPlayIntro = nut.config.get("alwaysPlayIntro", true) or not nut.localData.intro or nil - print("shouldPlayIntro", shouldPlayIntro) timer.Create("nutWaitUntilPlayerValid", 0.5, 0, function() if (not IsValid(LocalPlayer())) then return end timer.Remove("nutWaitUntilPlayerValid") @@ -345,7 +345,7 @@ function GM:CalcView(client, origin, angles, fov) view.origin = data.Pos view.angles = data.Ang end - + return view end end @@ -387,7 +387,7 @@ end function GM:PlayerBindPress(client, bind, pressed) bind = bind:lower() - + if ((bind:find("use") or bind:find("attack")) and pressed) then local menu, callback = nut.menu.getActiveMenu() @@ -440,7 +440,7 @@ function GM:ItemShowEntityMenu(entity) itemTable.entity = entity if (input.IsShiftDown()) then - callback("take") + callback("take") end for k, v in SortedPairs(itemTable.functions) do @@ -505,7 +505,7 @@ function GM:SetupQuickMenu(menu) local button = menu:addCheck(name, function(panel) panel.checked = true - + if (IsValid(current)) then if (current == panel) then return From 5968937aee0bd6feb9b3ebae5458cb7947fc80bd Mon Sep 17 00:00:00 2001 From: TovarischPootis <54110479+TovarischPootis@users.noreply.github.com> Date: Sun, 9 May 2021 10:17:33 +0300 Subject: [PATCH 2/4] Add GetDefaultCharDesc Much like GetDefaultCharName --- gamemode/core/hooks/sh_hooks.lua | 21 +++++++++++++------ plugins/area/sh_plugin.lua | 14 ++++++------- .../gridinv/plugins/gridinvui/sh_plugin.lua | 2 +- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/gamemode/core/hooks/sh_hooks.lua b/gamemode/core/hooks/sh_hooks.lua index df8dbdad..aa94c1e1 100644 --- a/gamemode/core/hooks/sh_hooks.lua +++ b/gamemode/core/hooks/sh_hooks.lua @@ -214,7 +214,7 @@ end function GM:CalcMainActivity(client, velocity) client.CalcIdeal = ACT_MP_STAND_IDLE - + oldCalcSeqOverride = client.CalcSeqOverride client.CalcSeqOverride = -1 @@ -270,6 +270,15 @@ function GM:GetDefaultCharName(client, faction) end end +function GM:GetDefaultCharDesc(client, faction) + local info = nut.faction.indices[faction] + + if (info and info.onGetDefaultDesc) then + return info:onGetDefaultDesc(client) + end +end + + function GM:CanPlayerUseChar(client, char) local banned = char:getData("banned") @@ -301,7 +310,7 @@ function GM:CheckFactionLimitReached(faction, character, client) -- By default, the limit is the number of players allowed in that faction. local maxPlayers = faction.limit - + -- If some number less than 1, treat it as a percentage of the player count. if (faction.limit < 1) then maxPlayers = math.Round(#player.GetAll() * faction.limit) @@ -326,7 +335,7 @@ function GM:PhysgunPickup(client, entity) if (client:IsSuperAdmin()) then return true end - + if (client:IsAdmin() and !(entity:IsPlayer() and entity:IsSuperAdmin())) then return true end @@ -364,8 +373,8 @@ function GM:Move(client, moveData) ms = ratio end - moveData:SetForwardSpeed(mf * speed) - moveData:SetSideSpeed(ms * speed) + moveData:SetForwardSpeed(mf * speed) + moveData:SetSideSpeed(ms * speed) end end end @@ -373,7 +382,7 @@ end function GM:CanItemBeTransfered(itemObject, curInv, inventory) if (itemObject.onCanBeTransfered) then local itemHook = itemObject:onCanBeTransfered(curInv, inventory) - + return (itemHook ~= false) end end diff --git a/plugins/area/sh_plugin.lua b/plugins/area/sh_plugin.lua index 48403922..00fd0413 100644 --- a/plugins/area/sh_plugin.lua +++ b/plugins/area/sh_plugin.lua @@ -6,7 +6,7 @@ PLUGIN.areaTable = PLUGIN.areaTable or {} nut.area = nut.area or {} ALWAYS_RAISED["nut_areahelper"] = true -nut.config.add("areaFontSize", 26, "The size of the font of Area Display.", +nut.config.add("areaFontSize", 26, "The size of the font of Area Display.", function(oldValue, newValue) if (CLIENT) then hook.Run( @@ -133,7 +133,7 @@ if (SERVER) then table.insert(PLUGIN.areaTable, { name = name, minVector = minVector, - maxVector = maxVector, + maxVector = maxVector, desc = desc or "", }) @@ -222,7 +222,7 @@ else panel:SetTall(30) frame:AddItem(panel) end - + function nut.area.openAreaManager() local frame = vgui.Create("DFrame") frame:SetSize(400, 300) @@ -315,9 +315,9 @@ else function PLUGIN:HUDPaint() -- values if ((hook.Run("CanDisplayArea") == false) or (dieTrigger and dieTimer < RealTime() and dieAlpha <= 1)) then - return + return end - + ft = FrameTime() w, h = ScrW(), ScrH() dsx, dsy = 0 @@ -325,7 +325,7 @@ else local rTime = RealTime() surface.SetFont("nutAreaDisplay") - local sx, sy = surface.GetTextSize(dispString) + local sx, sy = surface.GetTextSize(dispString) -- Number of characters to display. local maxDisplay = math.Round(rTime*speed - powTime) @@ -368,7 +368,7 @@ else (dieTrigger and dieTimer < RealTime()) and dieAlpha or flipTable[i][2]) ) - -- next + -- next dsx = dsx + tx*scale end diff --git a/plugins/gridinv/plugins/gridinvui/sh_plugin.lua b/plugins/gridinv/plugins/gridinvui/sh_plugin.lua index 8d8cbc2e..5082602b 100644 --- a/plugins/gridinv/plugins/gridinvui/sh_plugin.lua +++ b/plugins/gridinv/plugins/gridinvui/sh_plugin.lua @@ -13,7 +13,7 @@ if (CLIENT) then local panel = vgui.Create("nutGridInventory", parent) panel:setInventory(inventory) panel:Center() - + return panel end From 2c6dbad786d0863d4e4104cd4e158966ae275ec2 Mon Sep 17 00:00:00 2001 From: TovarischPootis <54110479+TovarischPootis@users.noreply.github.com> Date: Sun, 9 May 2021 10:17:49 +0300 Subject: [PATCH 3/4] Update nut_hands.lua --- entities/weapons/nut_hands.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/entities/weapons/nut_hands.lua b/entities/weapons/nut_hands.lua index c7b838ed..e3809b48 100644 --- a/entities/weapons/nut_hands.lua +++ b/entities/weapons/nut_hands.lua @@ -77,7 +77,7 @@ PLAYER_PICKUP_RANGE = 200 with prop pushing. CARRY_STRENGTH_GOD: 0 - You can push player with prop on this strength levle. the grabbing never fails. - Try this if you're playing with very trustful community. + Try this if you're playing with very trustful community. ]]-- CARRY_FORCE_LIMIT = CARRY_FORCE_LEVEL[CARRY_STRENGTH_CHAD] -- default strength level is CHAD. @@ -506,7 +506,7 @@ function SWEP:doPickup(throw, entity, trace) -- increase refire to make rags easier to drag --self.Weapon:SetNextSecondaryFire(CurTime() + 0.04) end - + if (IsValid(phys)) then self:dragObject(phys, pdir, 6000, is_ragdoll) return From 48a6c5f6b843029dcbb2586f149fa5a1dd6b4532 Mon Sep 17 00:00:00 2001 From: TovarischPootis <54110479+TovarischPootis@users.noreply.github.com> Date: Sun, 9 May 2021 10:51:39 +0300 Subject: [PATCH 4/4] formatting --- gamemode/config/sh_config.lua | 7 ++++++- gamemode/core/hooks/cl_hooks.lua | 11 ++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/gamemode/config/sh_config.lua b/gamemode/config/sh_config.lua index 957cd822..4a73606e 100644 --- a/gamemode/config/sh_config.lua +++ b/gamemode/config/sh_config.lua @@ -29,11 +29,16 @@ nut.config.add("genericFont", "Segoe UI", "The font used to display generic text hook.Run("LoadNutFonts", nut.config.get("font"), newValue) end end, {category = "appearance"}) + nut.config.add("fontScale", 1.0, "The scale for the font.", function(oldValue, newValue) if (CLIENT) then hook.Run("LoadNutFonts", nut.config.get("font"), nut.config.get("genericFont")) end -end, { form = "Float", data = {min = 0.1, max = 2.0}, category = "appearance"}) +end, { + form = "Float", + data = {min = 0.1, max = 2.0}, + category = "appearance" +}) nut.config.add("chatRange", 280, "The maximum distance a person's IC chat message goes to.", nil, { form = "Float", diff --git a/gamemode/core/hooks/cl_hooks.lua b/gamemode/core/hooks/cl_hooks.lua index 633a900f..ce0d3e0f 100644 --- a/gamemode/core/hooks/cl_hooks.lua +++ b/gamemode/core/hooks/cl_hooks.lua @@ -1,7 +1,6 @@ function GM:LoadNutFonts(font, genericFont) local oldFont, oldGenericFont = font, genericFont local scale = math.Round(nut.config.get("fontScale", 1), 2) - print(ScreenScale(14) * scale, ScreenScale(14)) surface.CreateFont("nut3D2DFont", { font = font, size = 2048, @@ -428,7 +427,7 @@ function GM:ItemShowEntityMenu(entity) local options = {} local itemTable = entity:getItemTable() - if (!itemTable) then return end -- MARK: This is the where error came from. + if (not itemTable) then return end -- MARK: This is the where error came from. local function callback(index) if (IsValid(entity)) then @@ -446,10 +445,8 @@ function GM:ItemShowEntityMenu(entity) for k, v in SortedPairs(itemTable.functions) do if (k == "combine") then continue end -- yeah, noob protection - if (isfunction(v.onCanRun)) then - if (not v.onCanRun(itemTable)) then - continue - end + if (isfunction(v.onCanRun)) and (not v.onCanRun(itemTable)) then + continue end options[L(v.name or k)] = function() @@ -518,7 +515,7 @@ function GM:SetupQuickMenu(menu) RunConsoleCommand("nut_language", k) end, enabled) - if (enabled and !IsValid(current)) then + if (enabled and not IsValid(current)) then current = button end end