-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.script
53 lines (43 loc) · 1.29 KB
/
example.script
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
function init(self)
local scale = 2
imgui.scale_all_sizes(scale)
imgui.set_global_font_scale(scale)
self.server_host = "localhost"
self.white_screen = false
end
function update(self, dt)
imgui.begin_window("Example", true, imgui.WINDOWFLAGS_ALWAYSAUTORESIZE)
local connected = netimgui.is_connected()
if connected and imgui.button("Disconnect") then
netimgui.disconnect()
elseif not connected then
imgui.text("Not connected")
end
if connected then
-- trivial example to prove that the connection works
imgui.separator()
imgui.text("Simple demo")
local changed, val = imgui.checkbox("White screen", self.white_screen)
if changed then
self.white_screen = val
if val then
msg.post("@render:", "clear_color", { color = vmath.vector4(1, 1, 1, 0) } )
else
msg.post("@render:", "clear_color", { color = vmath.vector4(0, 0, 0, 0) } )
end
end
end
if not connected then
imgui.separator()
local changed, host = imgui.input_text("Server host", self.server_host)
if changed then self.server_host = host end
if imgui.button("Connect to server") then
netimgui.connect_to_app("Defold", self.server_host)
end
imgui.separator()
if imgui.button("Allow incoming connections") then
netimgui.connect_from_app("Defold")
end
end
imgui.end_window()
end