summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--indra/llui/llluafloater.cpp73
-rw-r--r--indra/llui/llluafloater.h1
-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
5 files changed, 88 insertions, 42 deletions
diff --git a/indra/llui/llluafloater.cpp b/indra/llui/llluafloater.cpp
index 4ae0e28963..23a336a1e8 100644
--- a/indra/llui/llluafloater.cpp
+++ b/indra/llui/llluafloater.cpp
@@ -35,22 +35,19 @@
const std::string LISTENER_NAME("LLLuaFloater");
-std::map<std::string, std::string> EVENT_LIST =
-{
- {"COMMIT_EVENT", "commit"},
- {"DOUBLE_CLICK_EVENT", "double_click"},
- {"MOUSE_ENTER_EVENT", "mouse_enter"},
- {"MOUSE_LEAVE_EVENT", "mouse_leave"},
- {"MOUSE_DOWN_EVENT", "mouse_down"},
- {"MOUSE_UP_EVENT", "mouse_up"},
- {"RIGHT_MOUSE_DOWN_EVENT", "right_mouse_down"},
- {"RIGHT_MOUSE_UP_EVENT", "right_mouse_up"},
- {"POST_BUILD_EVENT", "post_build"},
- {"CLOSE_EVENT", "floater_close"}
+std::set<std::string> EVENT_LIST = {
+ "commit",
+ "double_click",
+ "mouse_enter",
+ "mouse_leave",
+ "mouse_down",
+ "mouse_up",
+ "right_mouse_down",
+ "right_mouse_up",
+ "post_build",
+ "floater_close"
};
-
-
LLLuaFloater::LLLuaFloater(const LLSD &key) :
LLFloater(key),
mDispatchListener(LLUUID::generateNewID().asString(), "action"),
@@ -87,7 +84,18 @@ LLLuaFloater::LLLuaFloater(const LLSD &key) :
LLScrollListCtrl *ctrl = getChild<LLScrollListCtrl>(event["ctrl_name"].asString());
if(ctrl)
{
- ctrl->addElement(event["value"]);
+ LLSD element_data = event["value"];
+ if (element_data.isArray())
+ {
+ for (const auto &row : llsd::inArray(element_data))
+ {
+ ctrl->addElement(row);
+ }
+ }
+ else
+ {
+ ctrl->addElement(element_data);
+ }
}
}, requiredParams);
@@ -117,13 +125,12 @@ BOOL LLLuaFloater::postBuild()
{
LLSD data;
data["ctrl_name"] = view->getName();
- data["event"] = EVENT_LIST["COMMIT_EVENT"];
ctrl->setCommitCallback([this, data](LLUICtrl *ctrl, const LLSD &param)
{
LLSD event(data);
event["value"] = ctrl->getValue();
- post(event);
+ postEvent(event, "commit");
});
}
}
@@ -142,14 +149,20 @@ BOOL LLLuaFloater::postBuild()
}
//send pump name to the script after the floater is built
- post(llsd::map("command_name", mDispatchListener.getPumpName(), "event", EVENT_LIST["POST_BUILD_EVENT"]));
+ postEvent(llsd::map("command_name", mDispatchListener.getPumpName()), "post_build");
return true;
}
void LLLuaFloater::onClose(bool app_quitting)
{
- post(llsd::map("event", EVENT_LIST["CLOSE_EVENT"], "app_quitting", app_quitting));
+ postEvent(llsd::map("app_quitting", app_quitting), "floater_close");
+}
+
+bool event_is(const std::string &event_name, const std::string &list_event)
+{
+ llassert(EVENT_LIST.find(list_event) != EVENT_LIST.end());
+ return (event_name == list_event);
}
void LLLuaFloater::registerCallback(const std::string &ctrl_name, const std::string &event)
@@ -169,31 +182,31 @@ void LLLuaFloater::registerCallback(const std::string &ctrl_name, const std::str
post(event.with("x", x).with("y", y));
};
- if (event == EVENT_LIST["MOUSE_ENTER_EVENT"])
+ if (event_is(event, "mouse_enter"))
{
ctrl->setMouseEnterCallback(mouse_event_cb);
}
- else if (event == EVENT_LIST["MOUSE_LEAVE_EVENT"])
+ else if (event_is(event, "mouse_leave"))
{
ctrl->setMouseLeaveCallback(mouse_event_cb);
}
- else if (event == EVENT_LIST["MOUSE_DOWN_EVENT"])
+ else if (event_is(event, "mouse_down"))
{
ctrl->setMouseDownCallback(mouse_event_coords_cb);
}
- else if (event == EVENT_LIST["MOUSE_UP_EVENT"])
+ else if (event_is(event, "mouse_up"))
{
ctrl->setMouseUpCallback(mouse_event_coords_cb);
}
- else if (event == EVENT_LIST["RIGHT_MOUSE_DOWN_EVENT"])
+ else if (event_is(event, "right_mouse_down"))
{
ctrl->setRightMouseDownCallback(mouse_event_coords_cb);
}
- else if (event == EVENT_LIST["RIGHT_MOUSE_UP_EVENT"])
+ else if (event_is(event, "right_mouse_up"))
{
ctrl->setRightMouseUpCallback(mouse_event_coords_cb);
}
- else if (event == EVENT_LIST["DOUBLE_CLICK_EVENT"])
+ else if (event_is(event, "double_click"))
{
LLScrollListCtrl *list = dynamic_cast<LLScrollListCtrl *>(ctrl);
if (list)
@@ -224,6 +237,12 @@ void LLLuaFloater::post(const LLSD &data)
LLEventPumps::instance().obtain(mReplyPumpName).post(stamped_data);
}
+void LLLuaFloater::postEvent(LLSD data, const std::string &event_name)
+{
+ llassert(EVENT_LIST.find(event_name) != EVENT_LIST.end());
+ post(data.with("event", event_name));
+}
+
void LLLuaFloater::showLuaFloater(const LLSD &data)
{
std::filesystem::path fs_path(data["xml_path"].asString());
@@ -244,7 +263,7 @@ LLSD LLLuaFloater::getEventsData()
LLSD event_data;
for (auto &it : EVENT_LIST)
{
- event_data[it.first] = it.second;
+ event_data.append(it);
}
return event_data;
}
diff --git a/indra/llui/llluafloater.h b/indra/llui/llluafloater.h
index d4c16745ee..ccc3ccb39b 100644
--- a/indra/llui/llluafloater.h
+++ b/indra/llui/llluafloater.h
@@ -41,6 +41,7 @@ public:
void onClose(bool app_quitting);
void post(const LLSD &data);
+ void postEvent(LLSD data, const std::string &event);
static void showLuaFloater(const LLSD &data);
static LLSD getEventsData();
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