aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/lib
diff options
context:
space:
mode:
authorDavid Walter Seikel2014-05-18 09:52:56 +1000
committerDavid Walter Seikel2014-05-18 09:52:56 +1000
commit7192ed111a2efdc51ee37d403ee8c3608925213a (patch)
treea405948a7765eba9f9c2e300a3b5f541df700435 /lib
parentImplement hiding and showing window Lua functions. (diff)
downloadSledjHamr-7192ed111a2efdc51ee37d403ee8c3608925213a.zip
SledjHamr-7192ed111a2efdc51ee37d403ee8c3608925213a.tar.gz
SledjHamr-7192ed111a2efdc51ee37d403ee8c3608925213a.tar.bz2
SledjHamr-7192ed111a2efdc51ee37d403ee8c3608925213a.tar.xz
llDialog() implementation almost complete.
Diffstat (limited to '')
-rw-r--r--lib/LSLGuiMess.lua83
1 files changed, 67 insertions, 16 deletions
diff --git a/lib/LSLGuiMess.lua b/lib/LSLGuiMess.lua
index 101f28e..44eae67 100644
--- a/lib/LSLGuiMess.lua
+++ b/lib/LSLGuiMess.lua
@@ -6,8 +6,7 @@ do
6 local skang = require 'skang' 6 local skang = require 'skang'
7 -- This module has no default skin, it creates windows as needed. 7 -- This module has no default skin, it creates windows as needed.
8 local _M = skang.moduleBegin('LSLGuiMess', nil, 'Copyright 2014 David Seikel', '0.1', '2014-05-16 11:07:00') 8 local _M = skang.moduleBegin('LSLGuiMess', nil, 'Copyright 2014 David Seikel', '0.1', '2014-05-16 11:07:00')
9 -- This has to be global so that the action below works. 9 local purkle = require 'purkle'
10 purkle = require 'purkle'
11 10
12 11
13--[[ TODO - 12--[[ TODO -
@@ -27,12 +26,8 @@ llSetTouchText(string text)
27]] 26]]
28 27
29 28
30
31--[[ llDialog(key id, string message, list buttons, integer chat_channel) 29--[[ llDialog(key id, string message, list buttons, integer chat_channel)
32 http://lslwiki.net/lslwiki/wakka.php?wakka=llDialog 30 http://lslwiki.net/lslwiki/wakka.php?wakka=llDialog
33
34TODO - Like the files window, just reuse a single window, hiding and showing it when needed.
35 The switch button shows the buttons from the next one.
36]] 31]]
37 32
38 local dialogs = {count = 0, current = 0} 33 local dialogs = {count = 0, current = 0}
@@ -41,37 +36,93 @@ TODO - Like the files window, just reuse a single window, hiding and showing it
41 local h = 20 36 local h = 20
42 local x = 2 + (((1 - 1) % 3) * w) 37 local x = 2 + (((1 - 1) % 3) * w)
43 local y = h * math.floor((1 - 1) / 3) 38 local y = h * math.floor((1 - 1) / 3)
44 local dialog = skang.window(4 + w * 3, h * math.ceil((buttCount + 1) / 3), message, 'llDialogWindow') 39 local dialog = skang.window(4 + w * 3, (h * 3) + (h * math.ceil((buttCount + 1) / 3)), message, 'llDialogWindow')
45 40
41 skang.thingasm{dialog, 'message', 'Dialog message', types = 'widget', widget='"textbox", "", ' .. 2 .. ', ' .. 2 .. ', ' .. (w * 3) .. ', ' .. (h * 3)}
46 for i = 1, buttCount do 42 for i = 1, buttCount do
47 x = 2 + (((i - 1) % 3) * w) 43 x = 2 + (((i - 1) % 3) * w)
48 y = h * math.floor((i - 1) / 3) 44 y = (h * 3) + (h * math.floor((i - 1) / 3))
49 skang.thingasm{dialog, 'button' .. i, 'Selects button ' .. i, types = 'widget', widget='"button", "' .. i .. '", ' .. x .. ', ' .. y .. ', ' .. w .. ', ' .. h} 45 skang.thingasm{dialog, 'button' .. i, 'Selects button ' .. i, types = 'widget', widget='"button", "' .. i .. '", ' .. x .. ', ' .. y .. ', ' .. w .. ', ' .. h}
50 skang.hide(dialog.W['button' .. i].Cwidget) 46 skang.hide(dialog.W['button' .. i].Cwidget)
51 end 47 end
52 x = 2 + (((3 - 1) % 3) * w) 48 x = 2 + (((3 - 1) % 3) * w)
53 y = h * math.floor((buttCount + 1) / 3) 49 y = (h * 3) + (h * math.floor((buttCount + 1) / 3))
54 skang.thingasm{dialog, 'ignore', 'Ignore this dialog', types = 'widget', widget='"button", "ignore", ' .. x .. ', ' .. y .. ', ' .. w - 20 .. ', ' .. h} 50 skang.thingasm{dialog, 'ignore', 'Ignore this dialog', types = 'widget', widget='"button", "ignore", ' .. x .. ', ' .. y .. ', ' .. w - 20 .. ', ' .. h}
51 dialog.W['ignore'].action = 'dialogIgnore()'
55 skang.thingasm{dialog, 'switch', 'Switch to next dialog', types = 'widget', widget='"button", ">", ' .. (x + w - 20) .. ', ' .. y .. ', ' .. 20 .. ', ' .. h} 52 skang.thingasm{dialog, 'switch', 'Switch to next dialog', types = 'widget', widget='"button", ">", ' .. (x + w - 20) .. ', ' .. y .. ', ' .. 20 .. ', ' .. h}
53 dialog.W['switch'].action = 'dialogSwitch()'
54 skang.vanish(dialog.window)
56 55
57 llDialog = function (id, message, buttons, channel) 56 llDialog = function (id, message, buttons, channel)
57 buttons.channel = channel
58 -- TODO - Should do a llKey2Name(id) here, and let the dialogChoose function catch it so we are not waiting for it.
59 -- On the other hand, this should only be used by the viewer, so only one user ever, could stash that somewhere else.
60 -- On the gripping hand, does llDialog() send back as the user? I think it does, but should check.
61 buttons.name = 'onefang rejected'
62 buttons.id = id
63 buttons.message = message
58 dialogs.count = dialogs.count + 1 64 dialogs.count = dialogs.count + 1
59 dialogs[dialogs.count] = buttons 65 dialogs[dialogs.count] = buttons
60 -- Hide the last set of buttons 66 dialogs.current = dialogs.count
67 dialogUpdate()
68 end
69
70 -- Update the current dialog.
71 dialogUpdate = function ()
72 local last = 1
73
74 dialog.W['message'].text = dialogs[dialogs.current].message
61 if 0 ~= dialogs.current then 75 if 0 ~= dialogs.current then
62 for i, v in ipairs(dialogs[dialogs.current]) do 76 for i, v in ipairs(dialogs[dialogs.current]) do
63 skang.hide(dialog.W['button' .. i].Cwidget) 77 dialog.W['button' .. i].action = 'dialogChoose(' .. i .. ')'
78 dialog.W['button' .. i].text = v
79 skang.show(dialog.W['button' .. i].Cwidget)
80 last = i + 1
64 end 81 end
65 end 82 end
66 dialogs.current = dialogs.count
67 83
68 for i, v in ipairs(buttons) do 84 -- Hide the excess buttons
69 dialog.W['button' .. i].action = 'purkle.say(' .. channel .. ', "onefang Rejected", "' .. id .. '", "' .. v .. '")' 85 for i = last, buttCount do
70 dialog.W['button' .. i].text = v 86 skang.hide(dialog.W['button' .. i].Cwidget)
71 skang.show(dialog.W['button' .. i].Cwidget) 87 end
88 if dialogs.count > 1 then
89 skang.show(dialog.W['switch'].Cwidget)
90 else
91 skang.hide(dialog.W['switch'].Cwidget)
92 end
93 skang.appear(dialog.window)
94 end
95
96 dialogChoose = function (i)
97 local c = dialogs[dialogs.current].channel
98 local n = dialogs[dialogs.current].name
99 local id = dialogs[dialogs.current].id
100 local t = dialogs[dialogs.current][i]
101 dialogIgnore()
102 purkle.say(c, n, id, t)
103 end
104
105 -- Ignore button.
106 dialogIgnore = function ()
107 table.remove(dialogs, dialogs.current)
108 dialogs.count = dialogs.count - 1
109 if dialogs.current > dialogs.count then dialogs.current = dialogs.count end
110 if 0 == dialogs.current then
111 skang.vanish(dialog.window)
112 else
113 dialogUpdate()
72 end 114 end
73 end 115 end
74 116
117 -- Switch button.
118 dialogSwitch = function ()
119 dialogs.current = dialogs.current + 1
120 if dialogs.current > dialogs.count then dialogs.current = 1 end
121 dialogUpdate()
122 end
123
124
125 -- TODO - This should be generalised and moved elsewhere.
75 local doLua = function (command) 126 local doLua = function (command)
76 -- Yes I know, it hurt my brain just writing this. lol 127 -- Yes I know, it hurt my brain just writing this. lol
77 -- It just swaps square brackets for curly ones, coz LSL uses [] to surround lists, and Lua uses {} to surround tables. 128 -- It just swaps square brackets for curly ones, coz LSL uses [] to surround lists, and Lua uses {} to surround tables.