summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNat Goodspeed <nat@lindenlab.com>2024-03-27 17:24:26 -0400
committerNat Goodspeed <nat@lindenlab.com>2024-03-27 17:24:26 -0400
commit29eee8bd6e92b94a52e8489b98cb81a396d230ed (patch)
tree22daf3061082bb5397462be58d41a1838eab0dcd
parentaf38e606865c2ed49a13bd6bd91d9604997798c8 (diff)
parent55c32761a0be05c7d4b4e17765e2d341efb0ebe6 (diff)
Merge 'release/luau-scripting' of secondlife/viewer into lua-startup
-rw-r--r--indra/llui/llluafloater.cpp40
-rw-r--r--indra/newview/scripts/lua/luafloater_demo.xml13
-rw-r--r--indra/newview/scripts/lua/test_luafloater_demo.lua24
-rw-r--r--indra/newview/scripts/lua/test_luafloater_gesture_list.lua21
4 files changed, 56 insertions, 42 deletions
diff --git a/indra/llui/llluafloater.cpp b/indra/llui/llluafloater.cpp
index afc287a864..268075b05d 100644
--- a/indra/llui/llluafloater.cpp
+++ b/indra/llui/llluafloater.cpp
@@ -32,6 +32,7 @@
#include "llcheckboxctrl.h"
#include "llcombobox.h"
#include "llscrolllistctrl.h"
+#include "lltexteditor.h"
const std::string LISTENER_NAME("LLLuaFloater");
@@ -45,7 +46,8 @@ std::set<std::string> EVENT_LIST = {
"right_mouse_down",
"right_mouse_up",
"post_build",
- "floater_close"
+ "floater_close",
+ "keystroke"
};
LLLuaFloater::LLLuaFloater(const LLSD &key) :
@@ -99,6 +101,16 @@ LLLuaFloater::LLLuaFloater(const LLSD &key) :
}
}, requiredParams);
+ mDispatchListener.add("add_text", "", [this](const LLSD &event)
+ {
+ LLTextEditor *editor = getChild<LLTextEditor>(event["ctrl_name"].asString());
+ if (editor)
+ {
+ editor->pasteTextWithLinebreaks(stringize(event["value"]));
+ editor->addLineBreakChar(true);
+ }
+ }, requiredParams);
+
mDispatchListener.add("set_title", "", [this](const LLSD &event)
{
setTitle(event["value"].asString());
@@ -182,6 +194,12 @@ void LLLuaFloater::registerCallback(const std::string &ctrl_name, const std::str
post(event.with("x", x).with("y", y));
};
+ auto post_with_value = [this, data](LLSD value)
+ {
+ LLSD event(data);
+ post(event.with("value", value));
+ };
+
if (event_is(event, "mouse_enter"))
{
ctrl->setMouseEnterCallback(mouse_event_cb);
@@ -211,18 +229,26 @@ void LLLuaFloater::registerCallback(const std::string &ctrl_name, const std::str
LLScrollListCtrl *list = dynamic_cast<LLScrollListCtrl *>(ctrl);
if (list)
{
- list->setDoubleClickCallback(
- [this, data, list]()
- {
- LLSD event(data);
- post(event.with("value", list->getCurrentID()));
- });
+ list->setDoubleClickCallback( [post_with_value, list](){ post_with_value(LLSD(list->getCurrentID())); });
}
else
{
ctrl->setDoubleClickCallback(mouse_event_coords_cb);
}
}
+ else if (event_is(event, "keystroke"))
+ {
+ LLTextEditor* text_editor = dynamic_cast<LLTextEditor*>(ctrl);
+ if (text_editor)
+ {
+ text_editor->setKeystrokeCallback([post_with_value](LLTextEditor *editor) { post_with_value(editor->getValue()); });
+ }
+ LLLineEditor* line_editor = dynamic_cast<LLLineEditor*>(ctrl);
+ if (line_editor)
+ {
+ line_editor->setKeystrokeCallback([post_with_value](LLLineEditor *editor, void* userdata) { post_with_value(editor->getValue()); }, NULL);
+ }
+ }
else
{
LL_WARNS("LuaFloater") << "Can't register callback for unknown event: " << event << " , control: " << ctrl_name << LL_ENDL;
diff --git a/indra/newview/scripts/lua/luafloater_demo.xml b/indra/newview/scripts/lua/luafloater_demo.xml
index 069f229128..b2273d7718 100644
--- a/indra/newview/scripts/lua/luafloater_demo.xml
+++ b/indra/newview/scripts/lua/luafloater_demo.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<floater
legacy_header_height="18"
- height="150"
+ height="300"
layout="topleft"
name="lua_demo"
title="LUA"
@@ -79,4 +79,15 @@
text_color="white"
left_delta="15"
name="time_lbl"/>
+ <text_editor
+ follows="top|left"
+ font="SansSerif"
+ height="140"
+ left="5"
+ enabled="false"
+ name="events_editor"
+ top_pad="15"
+ word_wrap="true"
+ max_length="65536"
+ width="310"/>
</floater>
diff --git a/indra/newview/scripts/lua/test_luafloater_demo.lua b/indra/newview/scripts/lua/test_luafloater_demo.lua
index 4e071e4abe..c375a2abc7 100644
--- a/indra/newview/scripts/lua/test_luafloater_demo.lua
+++ b/indra/newview/scripts/lua/test_luafloater_demo.lua
@@ -1,21 +1,15 @@
XML_FILE_PATH = "luafloater_demo.xml"
leap = require 'leap'
-coro = require 'coro'
-util = require 'util'
+fiber = require 'fiber'
--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()
+event_list=leap.request("LLFloaterReg", {op="getFloaterEvents"}).events
local function _event(event_name)
- if not util.contains(event_list, event_name) then
+ if not table.find(event_list, event_name) then
LL.print_warning("Incorrect event name: " .. event_name)
end
return event_name
@@ -31,6 +25,7 @@ function getCurrentTime()
end
function handleEvents(event_data)
+ post({action="add_text", ctrl_name="events_editor", value = 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)})
@@ -53,12 +48,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 = {_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()
+COMMAND_PUMP_NAME = leap.request("LLFloaterReg", key).command_name
catch_events = leap.WaitFor:new(-1, "all_events")
function catch_events:filter(pump, data)
@@ -73,6 +63,4 @@ function process_events(waitfor)
end
end
-coro.launch(process_events, catch_events)
-leap.process()
-LL.print_warning("End of the script")
+fiber.launch("catch_events", process_events, catch_events)
diff --git a/indra/newview/scripts/lua/test_luafloater_gesture_list.lua b/indra/newview/scripts/lua/test_luafloater_gesture_list.lua
index 9c718c353b..6d4a8e0cad 100644
--- a/indra/newview/scripts/lua/test_luafloater_gesture_list.lua
+++ b/indra/newview/scripts/lua/test_luafloater_gesture_list.lua
@@ -1,22 +1,16 @@
XML_FILE_PATH = "luafloater_gesture_list.xml"
leap = require 'leap'
-coro = require 'coro'
-util = require 'util'
+fiber = require 'fiber'
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()
+event_list=leap.request("LLFloaterReg", {op="getFloaterEvents"}).events
local function _event(event_name)
- if not util.contains(event_list, event_name) then
+ if not table.find(event_list, event_name) then
LL.print_warning("Incorrect event name: " .. event_name)
end
return event_name
@@ -51,11 +45,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 = {_event("double_click")}}
-coro.launch(function ()
- handleEvents(leap.request("LLFloaterReg", key))
- leap.done()
-end)
-leap.process()
+handleEvents(leap.request("LLFloaterReg", key))
catch_events = leap.WaitFor:new(-1, "all_events")
function catch_events:filter(pump, data)
@@ -70,5 +60,4 @@ function process_events(waitfor)
end
end
-coro.launch(process_events, catch_events)
-leap.process()
+fiber.launch("catch_events", process_events, catch_events)