aboutsummaryrefslogtreecommitdiff
path: root/gamemode/ents/art_npc/cl_art_npc.lua
blob: 023366614b30475969580583c8e77488cd6edebf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
local ENT = nrequire("sh_art_npc.lua")
local e = nrequire("editor.lua")
local col = nrequire("colortheme.lua")
print("in cl_art_npc, ENT loaded from sh_art_npc is", ENT)

ENT.RenderGroup = RENDERGROUP_BOTH


local function get_settings_info(what)
	-- Settings to display next to an npc
	local settings = {}

	settings["Model"] = what:GetModel()

	-- Classes that this npc inherits from, in the order it inherits
	local sinh = {}
	local sinhc = 1 -- Keep going, even if we encounter nil
	local cursor = what
	sinh[sinhc] = cursor.Name
	while cursor do
		cursor = getmetatable(cursor)
		if type(cursor) == "table" then
			sinh[sinhc] = cursor.Name or "nil"
		else
			sinh[sinhc] = tostring(cursor)
		end
		sinhc = sinhc + 1
	end
	settings["Inherits from"] = string.format("[%s]",table.concat(sinh,", "))

	return settings
end

local settings_info = nil
function ENT:Draw()
	if e.Enabled then --What to draw when "Editor" is enabled
		self:DrawModel()

		if settings_info == nil then
			settings_info = get_settings_info(self)
		end
		local pos,ang = (self:GetRight() * -32) + (self:GetUp() * 72) + self:GetPos() , self:GetAngles()

		cam.Start3D2D( pos, ang + Angle(0, 90, 90), 0.2 )
		local line = 0
		for k,v in pairs(settings_info) do
			draw.DrawText(string.format("%s:%s",k,tostring(v)), "Default", 0, line * 20, col.game.npcsettings )
			line = line + 1
		end

		cam.End3D2D()
	else
		self:DrawModel()
	end
end

function ENT:DrawTranslucent()

	-- This is here just to make it backwards compatible.
	-- You shouldn't really be drawing your model here unless it's translucent

	self:Draw()

end

function ENT:BuildBonePositions( NumBones, NumPhysBones )

	-- You can use this section to position the bones of
	-- any animated model using self:SetBonePosition( BoneNum, Pos, Angle )

	-- This will override any animation data and isn't meant as a
	-- replacement for animations. We're using this to position the limbs
	-- of ragdolls.

end

function ENT:SetRagdollBones( bIn )

	-- If this is set to true then the engine will call
	-- DoRagdollBone (below) for each ragdoll bone.
	-- It will then automatically fill in the rest of the bones

	self.m_bRagdollSetup = bIn

end

function ENT:DoRagdollBone( PhysBoneNum, BoneNum )

	-- self:SetBonePosition( BoneNum, Pos, Angle )

end

local chatframe = nil

net.Receive("art_opennpcdialog",function()
	if chatframe ~= nil and chatframe:IsValid() then
		chatframe:Remove()
		chatframe = nil
	end
	local width, height = ScrW(), ScrH()
	local who = net.ReadEntity()
	local chattbl = net.ReadTable()
	chatframe = vgui.Create( "DFrame" )
	chatframe:SetPos( (width / 2) - (width / 4), height - (height / 4) )
	chatframe:SetSize( width / 2, height / 4 )
	chatframe:SetTitle( chattbl["Name"] )
	chatframe:SetDraggable( true )
	chatframe.OnClose = function()
		net.Start("art_closenpcdialog")
		net.WriteEntity(who)
		net.SendToServer()
	end

	local chattxt = vgui.Create( "DLabel", chatframe )
	--chattxt:SetPos( 40, 40 )
	chattxt:SetText(chattbl["Message"])
	chattxt:Dock(TOP)

	for k,v in pairs(chattbl["Options"]) do
		local chatbutton = vgui.Create( "DButton",chatframe )
		--chatbutton:SetPos( 40, 40 )
		chatbutton:SetText( v )
		--chatbutton:SetSize( 120, 60 )
		chatbutton.DoClick = function()
			net.Start("art_updatenpcdialog")
			net.WriteEntity(who)
			net.WriteString(v)
			net.SendToServer()
		end
		chatbutton:Dock(BOTTOM)
	end
	chattxt:Dock(FILL)



	chatframe:MakePopup()
end)

scripted_ents.Register(ENT, "art_npc")