From ad1f5ac8906316f8e90355a4ebdbf33400758080 Mon Sep 17 00:00:00 2001 From: Mnikolenko Productengine Date: Tue, 19 Mar 2024 15:32:47 +0200 Subject: search xml file in the lib, if path is not full; add test lua floater scripts --- indra/newview/scripts/lua/luafloater_demo.xml | 82 ++++++++++++++++++++++ .../scripts/lua/luafloater_gesture_list.xml | 21 ++++++ indra/newview/scripts/lua/test_luafloater_demo.lua | 69 ++++++++++++++++++ .../scripts/lua/test_luafloater_gesture_list.lua | 62 ++++++++++++++++ 4 files changed, 234 insertions(+) create mode 100644 indra/newview/scripts/lua/luafloater_demo.xml create mode 100644 indra/newview/scripts/lua/luafloater_gesture_list.xml create mode 100644 indra/newview/scripts/lua/test_luafloater_demo.lua create mode 100644 indra/newview/scripts/lua/test_luafloater_gesture_list.lua (limited to 'indra/newview/scripts') 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 @@ + + + + + + + Select title + + + + + + + + Double click me + + + 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 @@ + + + + + + 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..a7bbdccb30 --- /dev/null +++ b/indra/newview/scripts/lua/test_luafloater_demo.lua @@ -0,0 +1,69 @@ +XML_FILE_PATH = "luafloater_demo.xml" + +leap = require 'leap' +coro = require 'coro' + +--event pump for sending actions to the floater +COMMAND_PUMP_NAME = "" +--table of floater UI events +e={} +coro.launch(function () + e = leap.request("LLFloaterReg", {op="getFloaterEvents"})["events"] + leap.done() +end) +leap.process() + +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 == e.COMMIT_EVENT 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 == e.DOUBLE_CLICK_EVENT 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 == e.CLOSE_EVENT then + print_warning("Floater was closed") + leap.done() + --script received event pump name, after floater was built + elseif event_data.event == e.POST_BUILD_EVENT then + COMMAND_PUMP_NAME = event_data.command_name + end +end + +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 + +local key = {xml_path = XML_FILE_PATH, op = "showLuaFloater"} + +--sign for additional events for defined control {= {action1, action2, ...}} +key.extra_events={show_time_lbl = {e.RIGHT_MOUSE_DOWN_EVENT, e.DOUBLE_CLICK_EVENT}} +leap.send("LLFloaterReg", key) + +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..070ff8415a --- /dev/null +++ b/indra/newview/scripts/lua/test_luafloater_gesture_list.lua @@ -0,0 +1,62 @@ +XML_FILE_PATH = "luafloater_gesture_list.xml" + +leap = require 'leap' +coro = require 'coro' +LLGesture = require 'LLGesture' + +--event pump for sending actions to the floater +COMMAND_PUMP_NAME = "" +--table of floater UI events +e={} +coro.launch(function () + e = leap.request("LLFloaterReg", {op="getFloaterEvents"})["events"] + leap.done() +end) +leap.process() + +function post(action) + leap.send(COMMAND_PUMP_NAME, action) +end + +function handleEvents(event_data) + if event_data.event == e.CLOSE_EVENT then + leap.done() + elseif event_data.event == e.POST_BUILD_EVENT 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 + element={value = uuid, columns ={column = "gesture_name", value = info.name}} + action_data.value = element + post(action_data) + end + elseif event_data.event == e.DOUBLE_CLICK_EVENT then + if event_data.ctrl_name == "gesture_list" then + LLGesture.startGesture(event_data.value) + end + end +end + +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 + +local key = {xml_path = XML_FILE_PATH, op = "showLuaFloater"} +--receive additional events for defined control {= {action1, action2, ...}} +key.extra_events={gesture_list = {e.DOUBLE_CLICK_EVENT}} +leap.send("LLFloaterReg", key) + +coro.launch(process_events, catch_events) +leap.process() -- cgit v1.2.3 From ba6784647b53919c09ef339fd99af152aa0f8458 Mon Sep 17 00:00:00 2001 From: Mnikolenko Productengine Date: Wed, 20 Mar 2024 23:21:48 +0200 Subject: LLLuaFloater code clean up --- indra/newview/scripts/lua/test_luafloater_demo.lua | 2 +- indra/newview/scripts/lua/test_luafloater_gesture_list.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/scripts') diff --git a/indra/newview/scripts/lua/test_luafloater_demo.lua b/indra/newview/scripts/lua/test_luafloater_demo.lua index a7bbdccb30..2cbafcec14 100644 --- a/indra/newview/scripts/lua/test_luafloater_demo.lua +++ b/indra/newview/scripts/lua/test_luafloater_demo.lua @@ -62,7 +62,7 @@ local key = {xml_path = XML_FILE_PATH, op = "showLuaFloater"} --sign for additional events for defined control {= {action1, action2, ...}} key.extra_events={show_time_lbl = {e.RIGHT_MOUSE_DOWN_EVENT, e.DOUBLE_CLICK_EVENT}} -leap.send("LLFloaterReg", key) +leap.send("LLFloaterReg", key, "floater1") coro.launch(process_events, catch_events) leap.process() diff --git a/indra/newview/scripts/lua/test_luafloater_gesture_list.lua b/indra/newview/scripts/lua/test_luafloater_gesture_list.lua index 070ff8415a..5ea2b1e30d 100644 --- a/indra/newview/scripts/lua/test_luafloater_gesture_list.lua +++ b/indra/newview/scripts/lua/test_luafloater_gesture_list.lua @@ -56,7 +56,7 @@ end local key = {xml_path = XML_FILE_PATH, op = "showLuaFloater"} --receive additional events for defined control {= {action1, action2, ...}} key.extra_events={gesture_list = {e.DOUBLE_CLICK_EVENT}} -leap.send("LLFloaterReg", key) +leap.send("LLFloaterReg", key, "floater1") coro.launch(process_events, catch_events) leap.process() -- cgit v1.2.3 From 76752d6fc00a2789d96480da2a1e862ffecc812a Mon Sep 17 00:00:00 2001 From: Mnikolenko Productengine Date: Thu, 21 Mar 2024 18:26:48 +0200 Subject: Switch to LLDispatchListener --- indra/newview/scripts/lua/test_luafloater_demo.lua | 19 ++++++++++--------- .../scripts/lua/test_luafloater_gesture_list.lua | 14 +++++++++----- 2 files changed, 19 insertions(+), 14 deletions(-) (limited to 'indra/newview/scripts') diff --git a/indra/newview/scripts/lua/test_luafloater_demo.lua b/indra/newview/scripts/lua/test_luafloater_demo.lua index 2cbafcec14..308cebcb88 100644 --- a/indra/newview/scripts/lua/test_luafloater_demo.lua +++ b/indra/newview/scripts/lua/test_luafloater_demo.lua @@ -39,12 +39,19 @@ function handleEvents(event_data) elseif event_data.event == e.CLOSE_EVENT then print_warning("Floater was closed") leap.done() - --script received event pump name, after floater was built - elseif event_data.event == e.POST_BUILD_EVENT then - COMMAND_PUMP_NAME = event_data.command_name end end +local key = {xml_path = XML_FILE_PATH, op = "showLuaFloater"} +--sign for additional events for defined control {= {action1, action2, ...}} +key.extra_events={show_time_lbl = {e.RIGHT_MOUSE_DOWN_EVENT, e.DOUBLE_CLICK_EVENT}} +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 @@ -58,12 +65,6 @@ function process_events(waitfor) end end -local key = {xml_path = XML_FILE_PATH, op = "showLuaFloater"} - ---sign for additional events for defined control {= {action1, action2, ...}} -key.extra_events={show_time_lbl = {e.RIGHT_MOUSE_DOWN_EVENT, e.DOUBLE_CLICK_EVENT}} -leap.send("LLFloaterReg", key, "floater1") - 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 index 5ea2b1e30d..57f737ce9b 100644 --- a/indra/newview/scripts/lua/test_luafloater_gesture_list.lua +++ b/indra/newview/scripts/lua/test_luafloater_gesture_list.lua @@ -40,6 +40,15 @@ function handleEvents(event_data) end end +local key = {xml_path = XML_FILE_PATH, op = "showLuaFloater"} +--receive additional events for defined control {= {action1, action2, ...}} +key.extra_events={gesture_list = {e.DOUBLE_CLICK_EVENT}} +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 @@ -53,10 +62,5 @@ function process_events(waitfor) end end -local key = {xml_path = XML_FILE_PATH, op = "showLuaFloater"} ---receive additional events for defined control {= {action1, action2, ...}} -key.extra_events={gesture_list = {e.DOUBLE_CLICK_EVENT}} -leap.send("LLFloaterReg", key, "floater1") - coro.launch(process_events, catch_events) leap.process() -- cgit v1.2.3 From 4ffdae72392ba2f081edf8d740b688b95ac4fc65 Mon Sep 17 00:00:00 2001 From: Mnikolenko Productengine Date: Thu, 21 Mar 2024 20:24:24 +0200 Subject: Accept an array for "add_list_item" and change EVENT_LIST type --- indra/newview/scripts/lua/test_luafloater_demo.lua | 20 ++++++++++++----- .../scripts/lua/test_luafloater_gesture_list.lua | 26 ++++++++++++++-------- indra/newview/scripts/lua/util.lua | 10 +++++++++ 3 files changed, 41 insertions(+), 15 deletions(-) (limited to 'indra/newview/scripts') diff --git a/indra/newview/scripts/lua/test_luafloater_demo.lua b/indra/newview/scripts/lua/test_luafloater_demo.lua index 308cebcb88..b81259c060 100644 --- a/indra/newview/scripts/lua/test_luafloater_demo.lua +++ b/indra/newview/scripts/lua/test_luafloater_demo.lua @@ -2,17 +2,25 @@ 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 -e={} +event_list={} coro.launch(function () - e = leap.request("LLFloaterReg", {op="getFloaterEvents"})["events"] + 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 @@ -23,7 +31,7 @@ function getCurrentTime() end function handleEvents(event_data) - if event_data.event == e.COMMIT_EVENT then + 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 @@ -32,11 +40,11 @@ function handleEvents(event_data) 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 == e.DOUBLE_CLICK_EVENT then + 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 == e.CLOSE_EVENT then + elseif event_data.event == _event("floater_close") then print_warning("Floater was closed") leap.done() end @@ -44,7 +52,7 @@ end local key = {xml_path = XML_FILE_PATH, op = "showLuaFloater"} --sign for additional events for defined control {= {action1, action2, ...}} -key.extra_events={show_time_lbl = {e.RIGHT_MOUSE_DOWN_EVENT, e.DOUBLE_CLICK_EVENT}} +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"] diff --git a/indra/newview/scripts/lua/test_luafloater_gesture_list.lua b/indra/newview/scripts/lua/test_luafloater_gesture_list.lua index 57f737ce9b..b46e36b4d9 100644 --- a/indra/newview/scripts/lua/test_luafloater_gesture_list.lua +++ b/indra/newview/scripts/lua/test_luafloater_gesture_list.lua @@ -2,26 +2,34 @@ 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 -e={} +event_list={} coro.launch(function () - e = leap.request("LLFloaterReg", {op="getFloaterEvents"})["events"] + 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 == e.CLOSE_EVENT then + if event_data.event == _event("floater_close") then leap.done() - elseif event_data.event == e.POST_BUILD_EVENT then + elseif event_data.event == _event("post_build") then COMMAND_PUMP_NAME = event_data.command_name gestures_uuid = LLGesture.getActiveGestures() local action_data = {} @@ -29,11 +37,11 @@ function handleEvents(event_data) action_data.ctrl_name = "gesture_list" gestures = {} for uuid, info in pairs(gestures_uuid) do - element={value = uuid, columns ={column = "gesture_name", value = info.name}} - action_data.value = element - post(action_data) + table.insert(gestures, {value = uuid, columns ={column = "gesture_name", value = info.name}}) end - elseif event_data.event == e.DOUBLE_CLICK_EVENT then + 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 @@ -42,7 +50,7 @@ end local key = {xml_path = XML_FILE_PATH, op = "showLuaFloater"} --receive additional events for defined control {= {action1, action2, ...}} -key.extra_events={gesture_list = {e.DOUBLE_CLICK_EVENT}} +key.extra_events={gesture_list = {_event("double_click")}} coro.launch(function () handleEvents(leap.request("LLFloaterReg", key)) leap.done() 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 -- cgit v1.2.3