Skip to content
Merged
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
2 changes: 1 addition & 1 deletion lua/precision_align/classes/base_toolmodes/line.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ end

local PA = PrecisionAlign.PA
function PrecisionAlign.SelectNextLine()
if PrecisionAlign.SelectedLine < 9 and PrecisionAlign.Functions.construct_exists( PrecisionAlign.CONSTRUCT_LINE, PrecisionAlign.SelectedLine ) then
if PrecisionAlign.SelectedLine < PrecisionAlign.MAX_CONSTRUCTS and PrecisionAlign.Functions.construct_exists( PrecisionAlign.CONSTRUCT_LINE, PrecisionAlign.SelectedLine ) then
PrecisionAlign.SelectedLine = PrecisionAlign.SelectedLine + 1
local dlist_lines = controlpanel.Get( PA ).line_window.list_line
dlist_lines:ClearSelection()
Expand Down
2 changes: 1 addition & 1 deletion lua/precision_align/classes/base_toolmodes/plane.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ end

local PA = PrecisionAlign.PA
function PrecisionAlign.SelectNextPlane()
if PrecisionAlign.SelectedPlane < 9 and PrecisionAlign.Functions.construct_exists( PrecisionAlign.CONSTRUCT_PLANE, PrecisionAlign.SelectedPlane ) then
if PrecisionAlign.SelectedPlane < PrecisionAlign.MAX_CONSTRUCTS and PrecisionAlign.Functions.construct_exists( PrecisionAlign.CONSTRUCT_PLANE, PrecisionAlign.SelectedPlane ) then
PrecisionAlign.SelectedPlane = PrecisionAlign.SelectedPlane + 1
local dlist_planes = controlpanel.Get( PA ).plane_window.list_plane
dlist_planes:ClearSelection()
Expand Down
2 changes: 1 addition & 1 deletion lua/precision_align/classes/base_toolmodes/point.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ end

local PA = PrecisionAlign.PA
function PrecisionAlign.SelectNextPoint()
if PrecisionAlign.SelectedPoint < 9 and PrecisionAlign.Functions.construct_exists( PrecisionAlign.CONSTRUCT_POINT, PrecisionAlign.SelectedPoint ) then
if PrecisionAlign.SelectedPoint < PrecisionAlign.MAX_CONSTRUCTS and PrecisionAlign.Functions.construct_exists( PrecisionAlign.CONSTRUCT_POINT, PrecisionAlign.SelectedPoint ) then
PrecisionAlign.SelectedPoint = PrecisionAlign.SelectedPoint + 1
local dlist_points = controlpanel.Get( PA ).point_window.list_primarypoint
dlist_points:ClearSelection()
Expand Down
6 changes: 6 additions & 0 deletions lua/precision_align/core/consts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ PrecisionAlign.CONSTRUCT_POINT = 0
PrecisionAlign.CONSTRUCT_LINE = 1
PrecisionAlign.CONSTRUCT_PLANE = 2

-- Number of point/line/plane slots in the construct stack.
PrecisionAlign.MAX_CONSTRUCTS = 10

-- Per-player cooldown, in seconds, between primitive_convex_hull spawns from the Primitives tab.
PrecisionAlign.PRIMITIVE_SPAWN_COOLDOWN = 0.1

PrecisionAlign.TOOLMODE_BACKGROUND_COLOR = Color(50, 50, 50, 50)
PrecisionAlign.TOOLMODE_BACKGROUND_COLOR_BACKGROUND = Color(103, 100, 110, 255)
PrecisionAlign.TOOLMODE_BACKGROUND_COLOR_DISABLED = Color(160, 160, 160, 255)
Expand Down
78 changes: 78 additions & 0 deletions lua/precision_align/core/utils/primitives_sv.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
-- Serverside handler for the "Primitives" manipulation panel tab: takes a list of
-- world-space points the client picked from its PA point stack and spawns a
-- primitive_convex_hull entity (from the separate "primitive" addon) using them
-- as vertices. Soft dependency: if that addon isn't loaded, the net message
-- just gets dropped, since the primitive_convex_hull class won't exist to check for.

local PA_ = PrecisionAlign.PA_

util.AddNetworkString( PA_ .. "primitive" )

local MIN_POINTS = 4
local MAX_POINTS = 10

local nextSpawn = {}

net.Receive( PA_ .. "primitive", function( _, ply )
local count = net.ReadUInt( 8 )
if count < MIN_POINTS or count > MAX_POINTS then return end

if ( nextSpawn[ply] or 0 ) > SysTime() then return end
nextSpawn[ply] = SysTime() + PrecisionAlign.PRIMITIVE_SPAWN_COOLDOWN

local points = {}
for i = 1, count do
points[i] = net.ReadVector()
end

if not scripted_ents.GetStored( "primitive_convex_hull" ) then
Warning( "Precision Alignment: primitive_convex_hull entity is not registered, is the \"primitive\" addon installed?\n" )
return
end

if scripted_ents.GetMember( "primitive_convex_hull", "AdminOnly" ) and not ply:IsAdmin() then return end
if not gamemode.Call( "PlayerSpawnProp", ply, "models/combine_helicopter/helicopter_bomb01.mdl" ) then return end
if not ply:CheckLimit( "props" ) then return end

-- centroid becomes the entity's own position; vertices are stored relative to it
local centroid = Vector( 0, 0, 0 )
for i = 1, count do
centroid = centroid + points[i]
end
centroid = centroid / count

local ent = ents.Create( "primitive_convex_hull" )
if not IsValid( ent ) then return end

ent:SetPos( centroid )
ent:SetAngles( Angle( 0, 0, 0 ) )
ent:Spawn()
ent:Activate()

if isfunction( ent.PrimitiveSetup ) then
ent:PrimitiveSetup( true )
end

ent:SetPrimPOINTS( count )
for i = 1, count do
local local_point = points[i] - centroid

ent[ "SetPrimPX" .. i ]( ent, local_point.x )
ent[ "SetPrimPY" .. i ]( ent, local_point.y )
ent[ "SetPrimPZ" .. i ]( ent, local_point.z )
end

ent:SetVar( "Player", ply )
ply:AddCount( "props", ent )
ply:AddCleanup( "primitive", ent )

undo.Create( "primitive" )
undo.SetPlayer( ply )
undo.AddEntity( ent )
undo.SetCustomUndoText( "Undone primitive ( primitive_convex_hull )" )
undo.Finish( "primitive ( primitive_convex_hull )" )

DoPropSpawnedEffect( ent )

gamemode.Call( "PlayerSpawnedProp", ply, "models/combine_helicopter/helicopter_bomb01.mdl", ent )
end )
2 changes: 1 addition & 1 deletion lua/precision_align/core/utils/utils_cl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ do -- Backwards compatibility for Prop Mover
end

-- Initialize tables, set defaults
for i = 1, 9 do
for i = 1, PrecisionAlign.MAX_CONSTRUCTS do
PrecisionAlign.Points[i] = {visible = true}
PrecisionAlign.Lines[i] = {visible = true}
PrecisionAlign.Planes[i] = {visible = true}
Expand Down
6 changes: 3 additions & 3 deletions lua/vgui/pa_construct_listview.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ end
function CONSTRUCT_LISTVIEW:Text( title, construct )
self.construct_type = construct
self:AddColumn( "" .. title)
for i = 1, 9 do
for i = 1, PrecisionAlign.MAX_CONSTRUCTS do
local line = self:AddLine(PrecisionAlign.GetConstructName(construct) .. " " .. tostring(i))
line.indicator = vgui.Create( "PA_Indicator", line )
end
Expand All @@ -18,14 +18,14 @@ function CONSTRUCT_LISTVIEW:Text( title, construct )
end

function CONSTRUCT_LISTVIEW:SetIndicators()
for i = 1, 9 do
for i = 1, PrecisionAlign.MAX_CONSTRUCTS do
local line = self:GetLine(i)
line.indicator = vgui.Create( "PA_Indicator", line )
end
end

function CONSTRUCT_LISTVIEW:SetIndicatorOffset( offset )
for i = 1, 9 do
for i = 1, PrecisionAlign.MAX_CONSTRUCTS do
local indicator = self:GetLine(i).indicator
indicator.offset = offset
end
Expand Down
2 changes: 1 addition & 1 deletion lua/vgui/pa_construct_multiselect.lua
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ end

function CONSTRUCT_MULTISELECT:SelectAll( value )
local function SelectLines( panel, construct_table )
for id = 1, 9 do
for id = 1, PrecisionAlign.MAX_CONSTRUCTS do
local line = panel.Sorted[ id ]
line:SetSelected( value )
if self.visibility then
Expand Down
5 changes: 3 additions & 2 deletions lua/weapons/gmod_tool/stools/precision_align.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ local PA_ = PA .. "_"
AddCSLuaFile( PA .. "/ui.lua" )
AddCSLuaFile( PA .. "/draw_hud.lua" )
AddCSLuaFile( PA .. "/manipulation_panel.lua" )
AddCSLuaFile( PA .. "/primitives_panel.lua" )

-- local typeCvar = GetConVar("precision_align_tooltype")

Expand Down Expand Up @@ -501,7 +502,7 @@ end
local function DrawIndicators( x, y, w, curToolType )
local radius = 8
local diameter = radius * 2 + 1
local separation = (w - 4) / 9
local separation = (w - 4) / PrecisionAlign.MAX_CONSTRUCTS

-- Background
draw.RoundedBox( 10, x, y, w, diameter + 15, Color(50, 50, 50, 100) )
Expand All @@ -512,7 +513,7 @@ local function DrawIndicators( x, y, w, curToolType )
-- Indicators
local IndicatorColour
local ConstructNum = GetConstructNum( curToolType )
for i = 1, 9 do
for i = 1, PrecisionAlign.MAX_CONSTRUCTS do
-- Draw construct selection ring
if i == ConstructNum then
draw.RoundedBox( radius + 4, xpos - 4, ypos - 4, diameter + 8, diameter + 8, Color(255, 255, 255, 255) )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ local BGColor_Rotation = PrecisionAlign.TOOLMODE_BACKGROUND_COLOR_ROTATION

local MANIPULATION_FRAME = {}
function MANIPULATION_FRAME:Init()
self:SetSize(900, 500)
self:SetSize(980, 500)
self:Center()
self:SetTitle( "Precision Alignment Manipulation Panel" )
self:SetVisible( true )
Expand Down Expand Up @@ -83,6 +83,7 @@ function MANIPULATION_FRAME:Init()
self.rotation_tab = vgui.Create( "PA_Rotation_Tab", self.body )
self.rotation_functions_tab = vgui.Create( "PA_Rotation_Functions_Tab", self.body )
self.constraints_tab = vgui.Create( "PA_Constraints_Tab", self.body )
self.primitives_tab = vgui.Create( "PA_Primitives_Tab", self.body )

self.panel:AddSheet( "Display Options", self.displays_tab, "icon16/picture_edit.png", false, false )
self.panel:AddSheet( "Points", self.points_tab, "icon16/add.png", false, false )
Expand All @@ -96,10 +97,11 @@ function MANIPULATION_FRAME:Init()
self.panel:AddSheet( "Rotation", self.rotation_tab, "icon16/arrow_refresh.png", false, false )
self.panel:AddSheet( "Rotation Functions", self.rotation_functions_tab, "icon16/arrow_refresh.png", false, false )
self.panel:AddSheet( "Constraints", self.constraints_tab, "icon16/anchor.png", false, false )
self.panel:AddSheet( "Primitives", self.primitives_tab, "icon16/shape_square.png", false, false )

-- Help button
self.button_help = vgui.Create( "PA_Function_Button", self )
self.button_help:SetPos( 810, 30 )
self.button_help:SetPos( 890, 30 )
self.button_help:SetSize( 60, 20 )
self.button_help:SetText( "Help" )
self.button_help:SetTooltip( "Open online help using the Steam in-game browser." )
Expand Down Expand Up @@ -142,7 +144,7 @@ vgui.Register("PA_Manipulation_Body", MANIPULATION_BODY, "DPanel")
local MANIPULATION_PANEL = {}
function MANIPULATION_PANEL:Init()
self:SetPos(0, 5)
self:SetSize(900, 470)
self:SetSize(980, 470)
end

function MANIPULATION_PANEL:Paint()
Expand All @@ -168,7 +170,7 @@ function DISPLAYS_TAB:Init()
keytable[ selection[k]:GetID() ] = true
end

for I = 1, 9 do
for I = 1, PrecisionAlign.MAX_CONSTRUCTS do
if keytable[I] then
construct_table[I].visible = true
else
Expand Down
94 changes: 94 additions & 0 deletions lua/weapons/gmod_tool/stools/precision_align/primitives_panel.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
-- Primitives Tab. Lets the user pick 4-10 PA points and spawn a
-- primitive_convex_hull entity (from the "primitive" addon) whose vertices are
-- those points. Soft dependency: if the primitive addon isn't loaded, the tab
-- still shows but the create button just warns instead of doing anything.
--********************************************************************************************************************

if SERVER then return end

local PA = "precision_align"
local PA_ = PA .. "_"

local BGColor_Point = PrecisionAlign.TOOLMODE_BACKGROUND_COLOR_POINT

local function AddMenuText( text, x, y, parent )
local Text = vgui.Create( "DLabel", parent )
Text:SetFont( "Default" )
Text:SetText( text )
Text:SizeToContents()
Text:SetPos( x, y )
return Text
end

local MIN_POINTS = 4
local MAX_POINTS = 10

local PRIMITIVES_TAB = {}
function PRIMITIVES_TAB:Init()
self:CopyBounds( self:GetParent() )

AddMenuText( "Points", 32, 9, self )

self.colour_panel = vgui.Create( "PA_Colour_Panel", self )
self.colour_panel:SetPos( 5, 31 )
self.colour_panel:SetSize( 300, 404 )
self.colour_panel:SetColour( BGColor_Point )

self.list_points = vgui.Create( "PA_Construct_ListView", self.colour_panel )
self.list_points:Text( "Points", PrecisionAlign.CONSTRUCT_POINT, self.colour_panel )
self.list_points:SetTooltip( "Select 4-10 points to use as the convex hull's vertices" )
self.list_points:SetPos( 20, 30 )
self.list_points:SetMultiSelect( true )

AddMenuText( "Primitive: Convex Hull", 330, 9, self )

self.text_description = vgui.Create( "DLabel", self )
self.text_description:SetPos( 330, 36 )
self.text_description:SetSize( 400, 300 )
self.text_description:SetWrap( true )
self.text_description:SetContentAlignment( 7 )
self.text_description:SetTextColor( self:GetSkin().Colours.Label.Dark )
self.text_description:SetText(
"Select 4 to 10 points, then hit Create.\n\n" ..
"The physics engine builds the hull, so point order doesn't matter.\n\n" ..
"Requires the \"primitive\" addon."
)

self.button_create = vgui.Create( "PA_Function_Button", self )
self.button_create:SetPos( 330, 378 )
self.button_create:SetSize( 191, 50 )
self.button_create:SetText( "Create Primitive" )
self.button_create:SetTooltip( "Spawn a convex hull from the selected points" )
self.button_create:SetFunction( function()
local selected = self.list_points:GetSelected()

local points = {}
for _, v in pairs( selected ) do
local ID = v:GetID()
if PrecisionAlign.Functions.construct_exists( PrecisionAlign.CONSTRUCT_POINT, ID ) then
points[#points + 1] = PrecisionAlign.Functions.point_global( ID ).origin
end
end

if #points < MIN_POINTS then
Warning( "Select at least " .. MIN_POINTS .. " defined points" )
return false
end

if #points > MAX_POINTS then
Warning( "Select at most " .. MAX_POINTS .. " points" )
return false
end

net.Start( PA_ .. "primitive" )
net.WriteUInt( #points, 8 )
for i = 1, #points do
net.WriteVector( points[i] )
end
net.SendToServer()

return true
end )
end

vgui.Register( "PA_Primitives_Tab", PRIMITIVES_TAB, "DPanel" )
3 changes: 2 additions & 1 deletion lua/weapons/gmod_tool/stools/precision_align/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ PrecisionAlign.SelectedPlane = 1

PrecisionAlign.ActiveEnt = nil

include("weapons/gmod_tool/stools/" .. PA .. "/primitives_panel.lua")
include("weapons/gmod_tool/stools/" .. PA .. "/manipulation_panel.lua")

local tooltypeCvar = GetConVar( PA_ .. "toolname" )
Expand Down Expand Up @@ -177,7 +178,7 @@ do
function PA_ConstructList:Setup(Construct, Click, DbClick)
self.construct_type = Construct
local Name = PrecisionAlign.GetConstructName(Construct)
for I = 1, 9 do
for I = 1, PrecisionAlign.MAX_CONSTRUCTS do
local Line = self:AddLine(Name .. " " .. I)
Line.Indicator = Line:Add "PA_Indicator"
end
Expand Down
Loading