Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 64 additions & 13 deletions gamemodes/jazztronauts/entities/weapons/weapon_basehold.lua
Original file line number Diff line number Diff line change
Expand Up @@ -196,18 +196,6 @@ function SWEP:Reload() return false end
function SWEP:CanPrimaryAttack() return true end
function SWEP:CanSecondaryAttack() return false end

function SWEP:DrawWeaponSelection(x, y, w, h, alpha)
surface.SetDrawColor(255, 255, 255, alpha)
if self.WepSelectIcon then
surface.SetMaterial(self.WepSelectIcon)
else
surface.SetTexture("weapons/swep")
end

surface.DrawTexturedRect(x + w / 2 - 128, y + h / 2 - 64, 256, 128)
self:PrintWeaponInfo(x + w + 20, y + h, alpha)
end

hook.Add("KeyRelease", "ReleaseTriggerOnGunsWhatCanBeHeldDown", function(ply, key)
if not IsFirstTimePredicted() then return end
if key != WEAPON_PRIMARY and key != WEAPON_SECONDARY then return end
Expand All @@ -218,4 +206,67 @@ hook.Add("KeyRelease", "ReleaseTriggerOnGunsWhatCanBeHeldDown", function(ply, ke
-- PRIMARY/SECONDARY_WEAPON is an alias for their IN_ATTACK binds
wep:AnyStopAttack(key)
end
end )
end )


-- All clientside from here
if SERVER then return end

local function ScreenScaleH(size)
return size * (ScrH() / 480)
end

local function UpdateFont()
local fontsize = ScreenScaleH(85)

-- Font stored at jazztronauts/resource/fonts/jazzwep.ttf
-- Icon assets in jazztronauts/other/wepicons (git repo only)
surface.CreateFont("JazzWep",{
font = "jazzicons",
size = fontsize,
weight = 500,
antialias = true,
additive = true
})
surface.CreateFont("JazzWepBlur",{
blursize = 8,
scanlines = 3,
font = "jazzicons",
size = fontsize,
weight = 500,
antialias = true,
additive = true
})
end

local oldtall = 0
function SWEP:DrawWeaponSelection(x, y, wide, tall, alpha)
-- This is in case the user changed resolution
if tall != oldtall then UpdateFont() end
oldtall = tall

x2 = x + ScreenScaleH(8)
y2 = y + ScreenScaleH(6)

if self.WepSelectColor then
local color = self.WepSelectColor
color.a = alpha
surface.SetTextColor(color:Unpack())
else
surface.SetTextColor( 179, 83, 177, alpha )
end

surface.SetTextPos( x2, y2 )
surface.SetFont("JazzWepBlur")
surface.DrawText(self.WepSelectIcon)

surface.SetTextPos( x2, y2 )
surface.SetFont("JazzWep")
surface.DrawText(self.WepSelectIcon)

-- Draw weapon info box like standard Gmod
x = x + 10
y = y + 10
wide = wide - 20
self:PrintWeaponInfo( x + wide + 20, y + tall * 0.95, alpha )
end
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ SWEP.Base = "weapon_basehold"
SWEP.PrintName = jazzloc.Localize("jazz.weapon.buscaller")
SWEP.Slot = 5
SWEP.Category = "#jazz.weapon.category"
SWEP.WepSelectIcon = Material( "weapons/weapon_buscaller.png" )
SWEP.Purpose = jazzloc.Localize("jazz.weapon.buscaller.desc")

SWEP.WepSelectIcon = "b"
SWEP.AutoIconAngle = Angle(0, 100, 70)

SWEP.ViewModel = "models/weapons/c_bus_summoner.mdl"
SWEP.WorldModel = "models/weapons/w_bus_summoner.mdl"
Expand Down
21 changes: 6 additions & 15 deletions gamemodes/jazztronauts/entities/weapons/weapon_hacker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ if SERVER then
AddCSLuaFile()
end

SWEP.Base = "weapon_base"
SWEP.Base = "weapon_basehold"
SWEP.PrintName = jazzloc.Localize("jazz.weapon.hacker")
SWEP.Slot = 4
SWEP.Category = "#jazz.weapon.category"
SWEP.Purpose = "#jazz.weapon.hacker.desc"
SWEP.WepSelectIcon = Material( "weapons/weapon_hacker.png" )
SWEP.Purpose = jazzloc.Localize("jazz.weapon.hacker.desc")

SWEP.WepSelectIcon = "h"
SWEP.WepSelectColor = Color(21,204,21)
SWEP.AutoIconAngle = Angle(125, -20, 40)

SWEP.ViewModel = "models/weapons/c_hackergoggles.mdl"
SWEP.WorldModel = "models/weapons/w_hackergoggles.mdl"
Expand Down Expand Up @@ -211,17 +214,5 @@ function SWEP:ShootEffects()

end

function SWEP:DrawWeaponSelection(x, y, w, h, alpha)
surface.SetDrawColor(255, 255, 255, alpha)
if self.WepSelectIcon then
surface.SetMaterial(self.WepSelectIcon)
else
surface.SetTexture("weapons/swep")
end

surface.DrawTexturedRect(x + w / 2 - 128, y + h / 2 - 64, 256, 128)
self:PrintWeaponInfo(x + w + 20, y + h, alpha)
end

function SWEP:Reload() return false end
function SWEP:CanSecondaryAttack() return false end
13 changes: 12 additions & 1 deletion gamemodes/jazztronauts/entities/weapons/weapon_luaphysgun.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
--[[
2023-07-24: For documentation purposes, putting this here. When asked about why this wasn't added to the final game, Zak said:

it just wasn't fun iirc
I originally made it for a fort building gamemode I was working on at the time
and I made the fx purple and it was like... a vibe, so we tried it
]]



-- Variables that are used on both client and server

AddCSLuaFile()
Expand All @@ -12,6 +22,7 @@ SWEP.UseHands = true

SWEP.ViewModel = "models/weapons/c_physcannon.mdl"
SWEP.WorldModel = "models/weapons/w_physics.mdl"
SWEP.IconOverride = "materials/entities/weapon_physcannon.png"

SWEP.Primary.ClipSize = -1
SWEP.Primary.DefaultClip = -1
Expand Down Expand Up @@ -894,4 +905,4 @@ hook.Add("AllowPlayerPickup", "fphysgun_allowpickup", function(ply)
return false
end

end)
end)
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ SWEP.Base = "weapon_basehold"
SWEP.PrintName = jazzloc.Localize("jazz.weapon.snatcher")
SWEP.Slot = 0
SWEP.Category = "#jazz.weapon.category"
SWEP.WepSelectIcon = Material( "weapons/weapon_propsnatcher.png" )
SWEP.Purpose = jazzloc.Localize("jazz.weapon.snatcher.desc")

SWEP.WepSelectIcon = "p"
SWEP.AutoIconAngle = Angle(170, 40, 0)

SWEP.ViewModel = "models/weapons/c_stunstick.mdl"
SWEP.WorldModel = "models/weapons/w_stunbaton.mdl"
Expand Down
9 changes: 6 additions & 3 deletions gamemodes/jazztronauts/entities/weapons/weapon_run.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ SWEP.Base = "weapon_basehold"
SWEP.PrintName = jazzloc.Localize("jazz.weapon.run")
SWEP.Slot = 3
SWEP.Category = "#jazz.weapon.category"
SWEP.Purpose = "#jazz.weapon.run.desc"
SWEP.WepSelectIcon = Material( "weapons/weapon_run.png" )
SWEP.Purpose = jazzloc.Localize("jazz.weapon.run.desc")

SWEP.WepSelectIcon = "r"
SWEP.WepSelectColor = Color(247,92,30)
SWEP.AutoIconAngle = Angle(25, 90, 0)

SWEP.ViewModel = "models/weapons/c_run.mdl"
SWEP.WorldModel = "models/weapons/w_run.mdl"
Expand Down Expand Up @@ -284,7 +287,7 @@ function SWEP:Think()

if self.CrouchTime < 0 or self.JumpMultiplier <= 1 or owner:InVehicle() then
self:StopChargeSound()
end
end
end
owner:SetWalkSpeed( 800 )
owner:SetRunSpeed( 800 )
Expand Down
9 changes: 6 additions & 3 deletions gamemodes/jazztronauts/entities/weapons/weapon_stan.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ SWEP.Base = "weapon_basehold"
SWEP.PrintName = jazzloc.Localize("jazz.weapon.stan")
SWEP.Slot = 2
SWEP.Category = "#jazz.weapon.category"
SWEP.Purpose = "#jazz.weapon.stan.desc"
SWEP.WepSelectIcon = Material( "weapons/weapon_stan.png" )
SWEP.Purpose = jazzloc.Localize("jazz.weapon.stan.desc.short")

SWEP.WepSelectIcon = "s"
SWEP.WepSelectColor = Color(196,0,0)
SWEP.AutoIconAngle = Angle(45, 90, 0)

SWEP.ViewModel = "models/weapons/c_stan.mdl"
SWEP.WorldModel = ""
SWEP.WorldModel = "models/Gibs/HGIBS.mdl"

SWEP.UseHands = true

Expand Down
11 changes: 8 additions & 3 deletions gamemodes/jazztronauts/gamemode/store/jstore.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,13 @@ function Register(unlockName, price, props)
if type(unlockName) == "table" then
local classname = unlockName.ClassName or (unlockName.Folder and string.GetFileFromFilename(unlockName.Folder))
props.name = props.name or unlockName.PrintName or classname
props.desc = props.desc or unlockName.Purpose
props.icon = props.icon or "vgui/entities/" .. classname
props.desc = props.desc or unlockName.Purpose or unlockName.Instructions

local spawnmenuicon
if unlockName.IconOverride then
spawnmenuicon = string.Replace(unlockName.IconOverride, "materials/", "")
end
props.icon = props.icon or spawnmenuicon or "entities/" .. classname .. ".png"

unlockName = classname
end
Expand Down Expand Up @@ -304,4 +309,4 @@ if CLIENT then

runCallbacks(item, success)
end )
end
end
7 changes: 6 additions & 1 deletion gamemodes/jazztronauts/gamemode/ui/spawnmenu/creation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,16 @@ function PANEL:AddUnlockedWeapon( weapon )
local wepinfo = list.Get("Weapon")[weapon]
if not wepinfo then return false end

local spawnmenuicon
if wepinfo.IconOverride then
spawnmenuicon = string.Replace(wepinfo.IconOverride, "materials/", "")
end

local icon = spawnmenu.CreateContentIcon( wepinfo.ScriptedEntityType or "weapon", self.content,
{
nicename = wepinfo.PrintName or wepinfo.ClassName or weapon,
spawnname = wepinfo.ClassName or weapon,
material = "entities/" .. (wepinfo.ClassName or weapon) .. ".png",
material = spawnmenuicon or "entities/" .. (wepinfo.ClassName or weapon) .. ".png",
admin = wepinfo.AdminOnly
} )

Expand Down
Binary file added materials/entities/weapon_buscaller.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added materials/entities/weapon_hacker.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added materials/entities/weapon_propsnatcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added materials/entities/weapon_run.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added materials/entities/weapon_stan.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added materials/ui/gman.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed materials/weapons/weapon_buscaller.png
Binary file not shown.
Binary file removed materials/weapons/weapon_hacker.png
Binary file not shown.
Binary file removed materials/weapons/weapon_propsnatcher.png
Binary file not shown.
Binary file removed materials/weapons/weapon_run.png
Binary file not shown.
Binary file removed materials/weapons/weapon_stan.png
Binary file not shown.
9 changes: 9 additions & 0 deletions other/wepicons/adding-icons.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
If you're trying to add a weapon icon, here's some advice.

1. If it isn't obvious, it needs to be vector art. No, throwing a bitmap into an SVG doesn't count. You need real lines and shapes and stuff. Try to keep in mind it'll be translated into a monochrome font that gets blurred, avoid filters and fancy stuff. Simple paths and shapes. Also keep in mind it will be rendered at both very high and very low resolutions. See how your icon looks when playing the game at not just your native res, but also at 800x600 or even lower. Keep it all the same color, you can set the color in code with SWEP.WepSelectColor.

2. I've included the spacing guide I used. It's not a hard limit or restriction, just a guide. If you compare all of the icons, you'll notice they flirt with the guiding a lot, putting things right against the edges or having things *just* poke into the yellow. You can compare all the icons to the guide and get an idea of how spacing was considered. Essentially, try to stay within the green, but go outside as needed and even for effect. Above all, every icon should look consistent with each other on the default HUD. If yours looks too small, start breaking the rules a bit. The bus is a good example of this.

3. When making the icon font, I used FontForge. You can just import an SVG directly into it, which I made mine in Inkscape. Keep an eye out for things broken upon importing. One issue I had was rounded rectangles becoming unrounded. You can likely fix a lot of issues by converting shapes/objects to paths, which your editor should have an option for. Don't modify the icon in the font itself, re-import it.

4. When exporting the font, you might get some errors about "extremas" or "non integral coordinates" or "self intersecting". Ignore them. Even Valve's official icons say the exact same thing.
18 changes: 18 additions & 0 deletions other/wepicons/implementation-decisions.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Commenter25 from https://commenter.cc here. Consider this one giant code comment, stating the motivation and design decisions that went into these icons, for documentation and future knowledge. Particularly, the considerations around rendering, spacing, positioning, and custom HUDs with custom weapon selectors.

All the icons were designed around safearea.png, which is based off how things looked on GoldSrc HUD. How spacing felt there translated surprisingly well to the default HUD. The green zone is just the size of the prop snatcher, the first icon I made and the one which helped me determine the padding. Anything wider than it seemed off to me, so even though it works sometimes, I just marked it red. Keeping the vertical distance away from the green zone looked cozy to me, but it works a lot better than the red, and I flirted with it a little... or a lot. Orange is actually based off the original bus icon (a material design icon), which happens to fit perfectly to the edges of GoldSrc HUD's selector. Ironically, the current bus icon conforms the least to the sizing guide, since it was made last and after decisions I talk about later, and I just tried to make it feel consistent with the other icons on stock HUD. Anyway, the orange parts are cut off on GoldSrc, which I found useful for replicating the look of stuff like the hivehand. For Run in particular, I made it "the floor" the cat is running on. I'm uncertain if that's obvious, but it feels too high on stock HUD if I raise it, so whatever. All this testing was done with plain PNG textures, and is still accurate if you do that (and change SWEP:DrawWeaponSelection to work like stock Gmod, except the y border is 12 instead of 10). However, this is not accurate in the implementation currently in Jazztronauts.

One major thing I wanted was to have the HL2 scanline effect, making them feel more like stock weapons with polished icons, rather than a crummy sprite plastered in. There were two ways I saw to go about this, one I'll talk about in a minute, and the one I went for, icon fonts. This is how HL2 does it. Every weapon selection icon is actually vector art in a font file, and when internally registering the font, you can activate blur and scanline parameters that just give you the scanline effect for free. I did not want to do this. Fonts are more complicated to scale and position properly in code, and they're a lot harder to create and edit. I was making vector art from the beginning, so that wasn't an issue, but I had to download FontForge and import things into it. I didn't modify anything about the individual icons after importing, but I did have to dig around settings to find how to change the "ascent", cause otherwise the top of Stan's glow would be cut off. Fonts just have weird quirks like that, cause they're made for text, not icons. But this is how Valve did it, so it's what I'm left with. They do have some advantages though. They're seemingly the only way (besides manually drawing with code) to use vectors, so they'll look great at any size, unlike rasters (pngs and jpgs) which blur when upscaled and can artifact when downscaled. And uh... you get the scanline effect for free. Yeah that's all I've got.

My other option was I could attempt to recreate the effect manually on a texture. I experimented with this, referencing Autoicons for how it could possibly be done, but I was encountering multiple issues to where I went back on it. The scanlines looked blurry and strange, I needed to figure out how to make it the correct color, and when using render targets it seems scissor rects don't apply anymore, since testing with GoldSrc HUD no longer cropped the icons and instead rendered them outside the selector. I tried fucking around with color blending and everything just fell apart somehow. It was likely possible to get working just the way I wanted, but it seems to be a lot of additional effort. And I had other issues I needed to deal with.

Regardless of the method I chose, for me to consider my implementation perfect, I would need to find a magical formula which will render it in the perfect position on stock HUD, GoldSrc HUD, and every other HUD in existence. All while keeping the cool scanline effect. Also, everything moves around when resolutions change. So not only am I trying to account for the different sizes, aspect ratios, boundaries, etc of any hypothetical HUD; I've gotta make sure this works at anything from John "GT 610" Doe's 640x480 to some rich kid's 8K monitor. This is really fucking hard. Everything appears to be kinda built around Gmod's stock implementation (which renders a bit high compared to stock icons which annoys me too), so deviating from that kinda makes everything fall apart. There's likely some complex math (or maybe rather simple math my brain can't parse) to perfectly scale just right for every HUD, whether using a font or a texture. But I don't think I'll be the one to figure that out.

So unfortunately, the current icon implementation sucks on anything but stock HUD. The scaling is all fucked up hard. I dislike this, and my original hope from the beginning was to make pretty icons that worked with everything. But I made a short term decision in favor of what would be best for Jazztronauts out of the box for most people who aren't using a custom HUD. For the default HUD, it looks perfect at every resolution (that I can test at least, between 640x480 to 1920x1080), and the scanline effect is a badass extra detail. Custom HUD users currently will have other issues anyway, like things overlapping what Jazztronauts draws. And most of Jazztronauts' HUD elements don't scale for different resolutions well already, which is a bigger issue. So as much as I would like to make this work eventually, it is going to wait for likely a good while. There are more important things to address, and this may not even be possible to do exactly how I want for all I know.

Overall, I dislike how I've added this now. But the state of drawing weapon selection icons for Gmod seems to be a bit of a nightmare. Especially if you want to look uniform with HL2's icons. Ideally there'd be something other than fonts, because I dislike the difficulty and confusion of working with them; but they are likely to stay, since being vector is a major bonus and it's the best way to get the scanline effect. The only issue right now is the scaling is totally fucked on any custom HUD.

If you're a custom HUD creator reading this, and your HUD has a custom weapon selector: I'm sorry. But if you can help me in any way, whether it's helping find that perfect scaling formula, or making a way to pass custom icons that fit the style of your HUD (with documentation somewhere about it please), I'm listening. Help me help you. And if not...

I'll come back to this eventually. Or maybe someone else will find this file one day and work on it. I put this file here not just to document what I tried to do and the reason I've done what I have, but also to let custom HUD creators and users know... hey. I see you. I'm comin back to you later, but I gotta go clockwise around the table first, you're at 10 and I'm only at 2. In the mean time, check out Autoicons, very cool addon!

Binary file added other/wepicons/safearea.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading