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
|
if engine.ActiveGamemode() ~= "sandbox" then return end
include('shared.lua')
--Don't draw our hull model
function ENT:Draw()
end
local function draw_edit_panel(filename,who)
if not GCompute then error("GCompute not installed!") end
if not GCompute.IDE then error("GCompute was initalized wrong or has changed, update this file!") end
local inst = GCompute.IDE.GetInstance()
inst:SetVisible (true)
print("Opening file browser!")
--Remove donation panel
for k,v in pairs(inst.ViewManager.Views) do
if type(k) == "table" and k.Title == "Donate!" then
k:SetVisible(false)
end
end
local fileuri = "game/data/" .. filename
print("Trying to open","game/data/" .. filename)
--Open up this npc's file
inst:OpenFile(fileuri,function(succ,res,view)
view:Select()
end)
--Set our file browser to the right place
for k,v in pairs(inst.ViewManager.Views) do
if k.Title == "File Browser" then
k.FolderListView:SetPath(string.GetPathFromFilename(fileuri))
end
end
--Detour it's save to let the server know the file was saved.
local doc = inst.DocumentManager.DocumentsByUri[fileuri]
print("Doc was",doc)
doc:AddEventListener("Saved",function()
print("Saved",doc)
net.Start("edit_sendsave")
net.WriteString(doc.Uri)
net.WriteEntity(who)
net.SendToServer()
end)
end
function Reload_Gcompute(what)
print("attempting to refresh instances of ", what)
local inst = GCompute.IDE:GetInstance()
for k,v in pairs(inst.ViewManager.ViewsById) do
if v.Title == what then
v:CreateFileChangeNotificationBar ()
v.FileChangeNotificationBar:DispatchEvent("ReloadRequested")
local oldvisible = v.FileChangeNotificationBar.SetVisible
v.FileChangeNotificationBar.SetVisible = function(self,bool)
if bool then
self.SetVisible = oldvisible
end
end
break
end
end
end
net.Receive("edit_notify_file_changed",function()
local what = net.ReadString()
Reload_Gcompute(what)
end)
net.Receive("edit_confirmremove",function()
local who = net.ReadString()
local frame = vgui.Create( "DFrame" )
frame:SetSize( 300, 250 )
frame:Center()
frame:MakePopup()
local but = vgui.Create( "DButton", frame )
but:SetText( "\nYes, I want to remove\n" .. who .. "\n")
but:Dock(TOP)
but.DoClick = function() // A custom function run when clicked ( note the . instead of : )
net.Start("edit_removeconfirmed")
net.WriteString(who)
net.SendToServer()
frame:Close()
end
local but2 = vgui.Create("DButton",frame)
but2:SetText("\nNo I don't want to remove\n" .. who .. "\n")
but2:Dock(BOTTOM)
but2.DoClick = function() // A custom function run when clicked ( note the . instead of : )
net.Start("edit_removedeny")
net.WriteString(who)
net.SendToServer()
frame:Close()
end
but:SizeToContents()
but2:SizeToContents()
end)
net.Receive("edit_sendopen",function()
print('got request to edit someone')
local file = net.ReadString()
local who = net.ReadEntity()
print(file)
draw_edit_panel(file,who)
end)
hook.Add( "Think", "edit_type_tip", function()
local tr = LocalPlayer():GetEyeTrace()
local e = tr.Entity
if e.Entity then
AddWorldTip( nil, e:GetClass(), nil, tr.HitPos, e )
end
end )
|