From 7192ed111a2efdc51ee37d403ee8c3608925213a Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Sun, 18 May 2014 09:52:56 +1000 Subject: llDialog() implementation almost complete. --- lib/LSLGuiMess.lua | 83 +++++++++++++++++++++++++++++++++++++++++++----------- 1 file 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 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') - -- This has to be global so that the action below works. - purkle = require 'purkle' + local purkle = require 'purkle' --[[ TODO - @@ -27,12 +26,8 @@ llSetTouchText(string text) ]] - --[[ llDialog(key id, string message, list buttons, integer chat_channel) http://lslwiki.net/lslwiki/wakka.php?wakka=llDialog - -TODO - Like the files window, just reuse a single window, hiding and showing it when needed. - The switch button shows the buttons from the next one. ]] local dialogs = {count = 0, current = 0} @@ -41,37 +36,93 @@ TODO - Like the files window, just reuse a single window, hiding and showing it local h = 20 local x = 2 + (((1 - 1) % 3) * w) local y = h * math.floor((1 - 1) / 3) - local dialog = skang.window(4 + w * 3, h * math.ceil((buttCount + 1) / 3), message, 'llDialogWindow') + local dialog = skang.window(4 + w * 3, (h * 3) + (h * math.ceil((buttCount + 1) / 3)), message, 'llDialogWindow') + skang.thingasm{dialog, 'message', 'Dialog message', types = 'widget', widget='"textbox", "", ' .. 2 .. ', ' .. 2 .. ', ' .. (w * 3) .. ', ' .. (h * 3)} for i = 1, buttCount do x = 2 + (((i - 1) % 3) * w) - y = h * math.floor((i - 1) / 3) + y = (h * 3) + (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 = h * math.floor((buttCount + 1) / 3) + y = (h * 3) + (h * math.floor((buttCount + 1) / 3)) 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 - -- Hide the last set of 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 - skang.hide(dialog.W['button' .. i].Cwidget) + 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 - dialogs.current = dialogs.count - for i, v in ipairs(buttons) do - dialog.W['button' .. i].action = 'purkle.say(' .. channel .. ', "onefang Rejected", "' .. id .. '", "' .. v .. '")' - dialog.W['button' .. i].text = v - skang.show(dialog.W['button' .. i].Cwidget) + -- 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. 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. -- cgit v1.1