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
140
141
142
143
144
|
--[[ LSLGuiMess - replicates the horrid and barely usable LSL user interface crap.
]]
do
local skang = require 'skang'
-- This module has no default skin, it creates windows as needed.
local _M = skang.moduleBegin('LSLGuiMess', nil, 'Copyright 2014 David Seikel', '0.1', '2014-05-16 11:07:00')
local purkle = require 'purkle'
--[[ TODO -
llTextBox()
http://wiki.secondlife.com/wiki/LlTextBox
llSetText(string text, vector color, float alpha)
http://lslwiki.net/lslwiki/wakka.php?wakka=llSetText
llSetSitText(string text)
http://lslwiki.net/lslwiki/wakka.php?wakka=llSetSitText
llSetTouchText(string text)
http://lslwiki.net/lslwiki/wakka.php?wakka=llSetTouchText
]]
--[[ llDialog(key id, string message, list buttons, integer chat_channel)
http://lslwiki.net/lslwiki/wakka.php?wakka=llDialog
]]
local dialogs = {count = 0, current = 0}
local buttCount = 12 * 8
local w = 80
local h = 20
local l = 4
local x = 2 + (((1 - 1) % 3) * w)
local y = h * math.floor((1 - 1) / 3)
local dialog = skang.window(4 + w * 3, (h * l) + (h * math.ceil((buttCount + 1) / 3)), message, 'llDialogWindow')
skang.thingasm{dialog, 'message', 'Dialog message', types = 'widget', widget='"textbox", "", ' .. 2 .. ', ' .. 2 .. ', ' .. (w * 3) .. ', ' .. (h * l)}
for i = 1, buttCount do
x = 2 + (((i - 1) % 3) * w)
y = 2 + (h * l) + (h * math.floor((i - 1) / 3))
skang.thingasm{dialog, 'button' .. i, 'Selects button ' .. i, types = 'widget', widget='"button", "' .. i .. '", ' .. x .. ', ' .. y .. ', ' .. w .. ', ' .. h}
skang.hide(dialog.W['button' .. i].Cwidget)
end
x = 2 + (((3 - 1) % 3) * w)
y = 2 + (h * l) + (h * math.floor((buttCount + 1) / 3))
-- TODO - LL's V3 has a block button to. Dunno how I'll deal with blocking stuff, think about that later.
skang.thingasm{dialog, 'ignore', 'Ignore this dialog', types = 'widget', widget='"button", "ignore", ' .. x .. ', ' .. y .. ', ' .. w - 20 .. ', ' .. h}
dialog.W['ignore'].action = 'dialogIgnore()'
skang.thingasm{dialog, 'switch', 'Switch to next dialog', types = 'widget', widget='"button", ">", ' .. (x + w - 20) .. ', ' .. y .. ', ' .. 20 .. ', ' .. h}
dialog.W['switch'].action = 'dialogSwitch()'
skang.vanish(dialog.window)
llDialog = function (id, message, buttons, channel)
buttons.channel = channel
-- TODO - Should do a llKey2Name(id) here, and let the dialogChoose function catch it so we are not waiting for it.
-- On the other hand, this should only be used by the viewer, so only one user ever, could stash that somewhere else.
-- On the gripping hand, does llDialog() send back as the user? I think it does, but should check.
buttons.name = 'onefang rejected'
buttons.id = id
buttons.message = message
dialogs.count = dialogs.count + 1
dialogs[dialogs.count] = buttons
dialogs.current = dialogs.count
dialogUpdate()
end
-- Update the current dialog.
dialogUpdate = function ()
local last = 1
dialog.W['message'].text = dialogs[dialogs.current].message
if 0 ~= dialogs.current then
for i, v in ipairs(dialogs[dialogs.current]) do
dialog.W['button' .. i].action = 'dialogChoose(' .. i .. ')'
dialog.W['button' .. i].text = v
skang.show(dialog.W['button' .. i].Cwidget)
last = i + 1
end
end
-- Hide the excess buttons
for i = last, buttCount do
skang.hide(dialog.W['button' .. i].Cwidget)
end
if dialogs.count > 1 then
skang.show(dialog.W['switch'].Cwidget)
else
skang.hide(dialog.W['switch'].Cwidget)
end
skang.appear(dialog.window)
end
dialogChoose = function (i)
local c = dialogs[dialogs.current].channel
local n = dialogs[dialogs.current].name
local id = dialogs[dialogs.current].id
local t = dialogs[dialogs.current][i]
dialogIgnore()
purkle.say(c, n, id, t)
end
-- Ignore button.
dialogIgnore = function ()
table.remove(dialogs, dialogs.current)
dialogs.count = dialogs.count - 1
if dialogs.current > dialogs.count then dialogs.current = dialogs.count end
if 0 == dialogs.current then
skang.vanish(dialog.window)
else
dialogUpdate()
end
end
-- Switch button.
dialogSwitch = function ()
dialogs.current = dialogs.current + 1
if dialogs.current > dialogs.count then dialogs.current = 1 end
dialogUpdate()
end
-- TODO - This should be generalised and moved elsewhere.
-- Likely as a Lua counterpart to doLuaString() in Runnr.c
-- Or just combine them.
local doLua = function (command)
-- Yes I know, it hurt my brain just writing this. lol
-- It just swaps square brackets for curly ones, coz LSL uses [] to surround lists, and Lua uses {} to surround tables.
local c, err = loadstring(string.gsub(command, '[%[%]]', {['['] = '{', [']'] = '}'}))
if c then
setfenv(c, _M)
c()
else
print("ERROR - " .. err)
end
end
skang.thingasm('doLua', 'Run a Lua command.', doLua, 'string')
skang.moduleEnd(_M)
end
|