summaryrefslogtreecommitdiff
path: root/indra/newview/scripts/lua
diff options
context:
space:
mode:
authorMaxim Nikolenko <maximnproductengine@lindenlab.com>2024-03-22 17:15:57 +0200
committerGitHub <noreply@github.com>2024-03-22 17:15:57 +0200
commit7bf84bdcbf13084ff3b94590e4061b4a6708b4dc (patch)
tree7e454bea1e48bf34ccc97e599967944c44a1e644 /indra/newview/scripts/lua
parentc5dec705cf6bb3dce9381c9ec574335356051297 (diff)
parent7b149485e091880269dd9d7941cca47da49e652f (diff)
Merge pull request #967 from secondlife/lua-floater
Initial implementation of LLLuaFloater
Diffstat (limited to 'indra/newview/scripts/lua')
-rw-r--r--indra/newview/scripts/lua/luafloater_demo.xml82
-rw-r--r--indra/newview/scripts/lua/luafloater_gesture_list.xml21
-rw-r--r--indra/newview/scripts/lua/test_luafloater_demo.lua78
-rw-r--r--indra/newview/scripts/lua/test_luafloater_gesture_list.lua74
-rw-r--r--indra/newview/scripts/lua/util.lua10
5 files changed, 265 insertions, 0 deletions
diff --git a/indra/newview/scripts/lua/luafloater_demo.xml b/indra/newview/scripts/lua/luafloater_demo.xml
new file mode 100644
index 0000000000..069f229128
--- /dev/null
+++ b/indra/newview/scripts/lua/luafloater_demo.xml
@@ -0,0 +1,82 @@
+<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
+<floater
+ legacy_header_height="18"
+ height="150"
+ layout="topleft"
+ name="lua_demo"
+ title="LUA"
+ width="320">
+ <check_box
+ height="16"
+ label="Disable button"
+ layout="topleft"
+ top_pad="35"
+ left="5"
+ name="disable_ctrl"
+ width="146" />
+ <line_editor
+ border_style="line"
+ border_thickness="1"
+ follows="left|bottom"
+ font="SansSerif"
+ height="20"
+ layout="topleft"
+ max_length_bytes="50"
+ name="openfloater_cmd"
+ top_delta="25"
+ width="100" />
+ <button
+ follows="left|bottom"
+ height="23"
+ label="Open floater"
+ layout="topleft"
+ name="open_btn"
+ top_delta="25"
+ width="100" >
+ </button>
+ <text
+ type="string"
+ follows="left|top"
+ height="10"
+ layout="topleft"
+ top="30"
+ left_delta="170"
+ name="title_lbl">
+ Select title
+ </text>
+ <combo_box
+ follows="top|left"
+ height="23"
+ name="title_cmb"
+ top_pad="5"
+ width="100">
+ <combo_box.item
+ label="LUA"
+ value="LUA" />
+ <combo_box.item
+ label="LUA floater"
+ value="LUA floater" />
+ <combo_box.item
+ label="LUA-U title"
+ value="LUA-U title" />
+ </combo_box>
+ <text
+ type="string"
+ follows="left|bottom"
+ height="10"
+ layout="topleft"
+ top_delta="50"
+ name="show_time_lbl">
+ Double click me
+ </text>
+ <text
+ type="string"
+ follows="left|top"
+ height="10"
+ layout="topleft"
+ top_pad="15"
+ font="SansSerif"
+ text_color="white"
+ left_delta="15"
+ name="time_lbl"/>
+</floater>
diff --git a/indra/newview/scripts/lua/luafloater_gesture_list.xml b/indra/newview/scripts/lua/luafloater_gesture_list.xml
new file mode 100644
index 0000000000..a38a04eed0
--- /dev/null
+++ b/indra/newview/scripts/lua/luafloater_gesture_list.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
+<floater
+ legacy_header_height="18"
+ height="150"
+ layout="topleft"
+ name="lua_gestures"
+ title="Gestures"
+ width="320">
+ <scroll_list
+ draw_heading="false"
+ left="5"
+ width="310"
+ height="115"
+ top_pad ="25"
+ follows="all"
+ name="gesture_list">
+ <scroll_list.columns
+ name="gesture_name"
+ label="Name"/>
+ </scroll_list>
+</floater>
diff --git a/indra/newview/scripts/lua/test_luafloater_demo.lua b/indra/newview/scripts/lua/test_luafloater_demo.lua
new file mode 100644
index 0000000000..b81259c060
--- /dev/null
+++ b/indra/newview/scripts/lua/test_luafloater_demo.lua
@@ -0,0 +1,78 @@
+XML_FILE_PATH = "luafloater_demo.xml"
+
+leap = require 'leap'
+coro = require 'coro'
+util = require 'util'
+
+--event pump for sending actions to the floater
+COMMAND_PUMP_NAME = ""
+--table of floater UI events
+event_list={}
+coro.launch(function ()
+ event_list = leap.request("LLFloaterReg", {op="getFloaterEvents"})["events"]
+ leap.done()
+end)
+leap.process()
+
+local function _event(event_name)
+ if not util.contains(event_list, event_name) then
+ print_warning("Incorrect event name: " .. event_name)
+ end
+ return event_name
+end
+
+function post(action)
+ leap.send(COMMAND_PUMP_NAME, action)
+end
+
+function getCurrentTime()
+ local currentTime = os.date("*t")
+ return string.format("%02d:%02d:%02d", currentTime.hour, currentTime.min, currentTime.sec)
+end
+
+function handleEvents(event_data)
+ if event_data.event == _event("commit") then
+ if event_data.ctrl_name == "disable_ctrl" then
+ post({action="set_enabled", ctrl_name="open_btn", value = (1 - event_data.value)})
+ elseif event_data.ctrl_name == "title_cmb" then
+ post({action="set_title", value= event_data.value})
+ elseif event_data.ctrl_name == "open_btn" then
+ floater_name = leap.request(COMMAND_PUMP_NAME, {action="get_value", ctrl_name='openfloater_cmd'})['value']
+ leap.send("LLFloaterReg", {name = floater_name, op = "showInstance"})
+ end
+ elseif event_data.event == _event("double_click") then
+ if event_data.ctrl_name == "show_time_lbl" then
+ post({action="set_value", ctrl_name="time_lbl", value= getCurrentTime()})
+ end
+ elseif event_data.event == _event("floater_close") then
+ print_warning("Floater was closed")
+ leap.done()
+ end
+end
+
+local key = {xml_path = XML_FILE_PATH, op = "showLuaFloater"}
+--sign for additional events for defined control {<control_name>= {action1, action2, ...}}
+key.extra_events={show_time_lbl = {_event("right_mouse_down"), _event("double_click")}}
+coro.launch(function ()
+ --script received event pump name, after floater was built
+ COMMAND_PUMP_NAME = leap.request("LLFloaterReg", key)["command_name"]
+ leap.done()
+end)
+leap.process()
+
+catch_events = leap.WaitFor:new(-1, "all_events")
+function catch_events:filter(pump, data)
+ return data
+end
+
+function process_events(waitfor)
+ event_data = waitfor:wait()
+ while event_data do
+ handleEvents(event_data)
+ event_data = waitfor:wait()
+ end
+end
+
+coro.launch(process_events, catch_events)
+leap.process()
+print_warning("End of the script")
diff --git a/indra/newview/scripts/lua/test_luafloater_gesture_list.lua b/indra/newview/scripts/lua/test_luafloater_gesture_list.lua
new file mode 100644
index 0000000000..b46e36b4d9
--- /dev/null
+++ b/indra/newview/scripts/lua/test_luafloater_gesture_list.lua
@@ -0,0 +1,74 @@
+XML_FILE_PATH = "luafloater_gesture_list.xml"
+
+leap = require 'leap'
+coro = require 'coro'
+util = require 'util'
+LLGesture = require 'LLGesture'
+
+--event pump for sending actions to the floater
+COMMAND_PUMP_NAME = ""
+--table of floater UI events
+event_list={}
+coro.launch(function ()
+ event_list = leap.request("LLFloaterReg", {op="getFloaterEvents"})["events"]
+ leap.done()
+end)
+leap.process()
+
+local function _event(event_name)
+ if not util.contains(event_list, event_name) then
+ print_warning("Incorrect event name: " .. event_name)
+ end
+ return event_name
+end
+
+function post(action)
+ leap.send(COMMAND_PUMP_NAME, action)
+end
+
+function handleEvents(event_data)
+ if event_data.event == _event("floater_close") then
+ leap.done()
+ elseif event_data.event == _event("post_build") then
+ COMMAND_PUMP_NAME = event_data.command_name
+ gestures_uuid = LLGesture.getActiveGestures()
+ local action_data = {}
+ action_data.action = "add_list_element"
+ action_data.ctrl_name = "gesture_list"
+ gestures = {}
+ for uuid, info in pairs(gestures_uuid) do
+ table.insert(gestures, {value = uuid, columns ={column = "gesture_name", value = info.name}})
+ end
+ action_data.value = gestures
+ post(action_data)
+ elseif event_data.event == _event("double_click") then
+ if event_data.ctrl_name == "gesture_list" then
+ LLGesture.startGesture(event_data.value)
+ end
+ end
+end
+
+local key = {xml_path = XML_FILE_PATH, op = "showLuaFloater"}
+--receive additional events for defined control {<control_name>= {action1, action2, ...}}
+key.extra_events={gesture_list = {_event("double_click")}}
+coro.launch(function ()
+ handleEvents(leap.request("LLFloaterReg", key))
+ leap.done()
+end)
+leap.process()
+
+catch_events = leap.WaitFor:new(-1, "all_events")
+function catch_events:filter(pump, data)
+ return data
+end
+
+function process_events(waitfor)
+ event_data = waitfor:wait()
+ while event_data do
+ handleEvents(event_data)
+ event_data = waitfor:wait()
+ end
+end
+
+coro.launch(process_events, catch_events)
+leap.process()
diff --git a/indra/newview/scripts/lua/util.lua b/indra/newview/scripts/lua/util.lua
index e3af633ea7..5d6042dfe5 100644
--- a/indra/newview/scripts/lua/util.lua
+++ b/indra/newview/scripts/lua/util.lua
@@ -36,4 +36,14 @@ function util.equal(t1, t2)
return util.empty(temp)
end
+-- check if array-like table contains certain value
+function util.contains(t, v)
+ for _, value in ipairs(t) do
+ if value == v then
+ return true
+ end
+ end
+ return false
+end
+
return util