summaryrefslogtreecommitdiff
path: root/indra/newview/scripts
diff options
context:
space:
mode:
authorMnikolenko Productengine <mnikolenko@productengine.com>2024-03-21 20:24:24 +0200
committerMnikolenko Productengine <mnikolenko@productengine.com>2024-03-21 20:24:24 +0200
commit4ffdae72392ba2f081edf8d740b688b95ac4fc65 (patch)
treed65d36378f1b264d7175470dc0ba28d06e86a113 /indra/newview/scripts
parent76752d6fc00a2789d96480da2a1e862ffecc812a (diff)
Accept an array for "add_list_item" and change EVENT_LIST type
Diffstat (limited to 'indra/newview/scripts')
-rw-r--r--indra/newview/scripts/lua/test_luafloater_demo.lua20
-rw-r--r--indra/newview/scripts/lua/test_luafloater_gesture_list.lua26
-rw-r--r--indra/newview/scripts/lua/util.lua10
3 files changed, 41 insertions, 15 deletions
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 {<control_name>= {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 {<control_name>= {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