From bb1f3f08cf93facbf926e57384674441be7e2884 Mon Sep 17 00:00:00 2001 From: Mnikolenko Productengine Date: Mon, 22 Apr 2024 14:56:52 +0300 Subject: Add demo script with idle and notification interactions --- indra/newview/scripts/lua/LLNotification.lua | 15 ++++++++++ .../newview/scripts/lua/luafloater_speedometer.xml | 35 ++++++++++++++++++++++ .../scripts/lua/test_luafloater_speedometer.lua | 26 ++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 indra/newview/scripts/lua/LLNotification.lua create mode 100644 indra/newview/scripts/lua/luafloater_speedometer.xml create mode 100644 indra/newview/scripts/lua/test_luafloater_speedometer.lua (limited to 'indra/newview/scripts') diff --git a/indra/newview/scripts/lua/LLNotification.lua b/indra/newview/scripts/lua/LLNotification.lua new file mode 100644 index 0000000000..f47730d1cc --- /dev/null +++ b/indra/newview/scripts/lua/LLNotification.lua @@ -0,0 +1,15 @@ +-- Engage the LLNotificationsListener LLEventAPI + +leap = require 'leap' + +local LLNotification = {} + +function LLNotification.add(name, substitutions) + leap.send('LLNotifications', {op='requestAdd', name=name, substitutions=substitutions}) +end + +function LLNotification.requestAdd(name, substitutions) + return leap.request('LLNotifications', {op='requestAdd', name=name, substitutions=substitutions})['response'] +end + +return LLNotification diff --git a/indra/newview/scripts/lua/luafloater_speedometer.xml b/indra/newview/scripts/lua/luafloater_speedometer.xml new file mode 100644 index 0000000000..54b99c7d48 --- /dev/null +++ b/indra/newview/scripts/lua/luafloater_speedometer.xml @@ -0,0 +1,35 @@ + + + + + m/s + + diff --git a/indra/newview/scripts/lua/test_luafloater_speedometer.lua b/indra/newview/scripts/lua/test_luafloater_speedometer.lua new file mode 100644 index 0000000000..610401ae44 --- /dev/null +++ b/indra/newview/scripts/lua/test_luafloater_speedometer.lua @@ -0,0 +1,26 @@ +local Floater = require 'Floater' +local startup = require 'startup' +inspect = require 'inspect' +leap = require 'leap' +LLNotification = require 'LLNotification' +local max_speed = 0 +local flt = Floater:new("luafloater_speedometer.xml") +startup.wait('STATE_STARTED') + +function flt:floater_close(event_data) + msg = "Registered max speed: " .. string.format("%.2f", max_speed) .. " m/s"; + LLNotification.add('SystemMessageTip', {MESSAGE = msg}) +end + +function flt:idle(event_data) + local speed = leap.request('LLVOAvatar', {op='getSpeed'})['value'] + flt:post({action="set_value", ctrl_name="speed_lbl", value = string.format("%.2f", speed)}) + max_speed=math.max(max_speed, speed) +end + +msg = 'Are you sure you want to run this "speedometer" script?' +response = LLNotification.requestAdd('GenericAlertYesCancel', {MESSAGE = msg}) + +if response.OK_okcancelbuttons then + flt:show() +end -- cgit v1.2.3 From 3a2018ddda6feb1aaa023106f95de6d8e0a0b507 Mon Sep 17 00:00:00 2001 From: nat-goodspeed Date: Thu, 20 Jun 2024 12:56:35 -0400 Subject: Revert LLLuaFloater "idle" events in favor of Lua timers.Timer(). --- .../newview/scripts/lua/test_luafloater_speedometer.lua | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'indra/newview/scripts') diff --git a/indra/newview/scripts/lua/test_luafloater_speedometer.lua b/indra/newview/scripts/lua/test_luafloater_speedometer.lua index 610401ae44..a9d3a70330 100644 --- a/indra/newview/scripts/lua/test_luafloater_speedometer.lua +++ b/indra/newview/scripts/lua/test_luafloater_speedometer.lua @@ -1,18 +1,23 @@ local Floater = require 'Floater' +local leap = require 'leap' +local LLNotification = require 'LLNotification' local startup = require 'startup' -inspect = require 'inspect' -leap = require 'leap' -LLNotification = require 'LLNotification' +local Timer = (require 'timers').Timer local max_speed = 0 local flt = Floater:new("luafloater_speedometer.xml") startup.wait('STATE_STARTED') +local timer + function flt:floater_close(event_data) + if timer then + timer:cancel() + end msg = "Registered max speed: " .. string.format("%.2f", max_speed) .. " m/s"; LLNotification.add('SystemMessageTip', {MESSAGE = msg}) end -function flt:idle(event_data) +local function idle(event_data) local speed = leap.request('LLVOAvatar', {op='getSpeed'})['value'] flt:post({action="set_value", ctrl_name="speed_lbl", value = string.format("%.2f", speed)}) max_speed=math.max(max_speed, speed) @@ -22,5 +27,6 @@ msg = 'Are you sure you want to run this "speedometer" script?' response = LLNotification.requestAdd('GenericAlertYesCancel', {MESSAGE = msg}) if response.OK_okcancelbuttons then - flt:show() + flt:show() + timer = Timer:new(1, idle, true) -- iterate end -- cgit v1.2.3