From 72d68cbc078cf2c1b9dc3ff81c2c1965f5d6f8c5 Mon Sep 17 00:00:00 2001 From: Mnikolenko Productengine Date: Tue, 12 Mar 2024 16:48:49 +0200 Subject: Initial implementation of LLLuaFloater --- indra/llui/CMakeLists.txt | 2 + indra/llui/llfloater.cpp | 4 + indra/llui/llfloater.h | 3 + indra/llui/llfloaterreglistener.cpp | 15 ++++ indra/llui/llfloaterreglistener.h | 2 + indra/llui/llluafloater.cpp | 162 ++++++++++++++++++++++++++++++++++++ indra/llui/llluafloater.h | 52 ++++++++++++ 7 files changed, 240 insertions(+) create mode 100644 indra/llui/llluafloater.cpp create mode 100644 indra/llui/llluafloater.h (limited to 'indra/llui') diff --git a/indra/llui/CMakeLists.txt b/indra/llui/CMakeLists.txt index a0314cb5f2..69e1b57245 100644 --- a/indra/llui/CMakeLists.txt +++ b/indra/llui/CMakeLists.txt @@ -49,6 +49,7 @@ set(llui_SOURCE_FILES lllineeditor.cpp llloadingindicator.cpp lllocalcliprect.cpp + llluafloater.cpp llmenubutton.cpp llmenugl.cpp llmodaldialog.cpp @@ -164,6 +165,7 @@ set(llui_HEADER_FILES lllineeditor.h llloadingindicator.h lllocalcliprect.h + llluafloater.h llmenubutton.h llmenugl.h llmodaldialog.h diff --git a/indra/llui/llfloater.cpp b/indra/llui/llfloater.cpp index de3de53569..b9b69b5a33 100644 --- a/indra/llui/llfloater.cpp +++ b/indra/llui/llfloater.cpp @@ -3623,6 +3623,10 @@ void LLFloater::applyRelativePosition() translate(new_center.mX - cur_center.mX, new_center.mY - cur_center.mY); } +bool LLFloater::isDefaultBtnName(const std::string& name) +{ + return (std::find(std::begin(sButtonNames), std::end(sButtonNames), name) != std::end(sButtonNames)); +} LLCoordFloater::LLCoordFloater(F32 x, F32 y, LLFloater& floater) : coord_t((S32)x, (S32)y) diff --git a/indra/llui/llfloater.h b/indra/llui/llfloater.h index 88f9e77777..9d49c4538e 100644 --- a/indra/llui/llfloater.h +++ b/indra/llui/llfloater.h @@ -372,6 +372,9 @@ public: void enableResizeCtrls(bool enable, bool width = true, bool height = true); bool isPositioning(LLFloaterEnums::EOpenPositioning p) const { return (p == mPositioning); } + + static bool isDefaultBtnName(const std::string& name); + protected: void applyControlsAndPosition(LLFloater* other); diff --git a/indra/llui/llfloaterreglistener.cpp b/indra/llui/llfloaterreglistener.cpp index 7525b8cab3..6fee688121 100644 --- a/indra/llui/llfloaterreglistener.cpp +++ b/indra/llui/llfloaterreglistener.cpp @@ -37,6 +37,7 @@ #include "llfloaterreg.h" #include "llfloater.h" #include "llbutton.h" +#include "llluafloater.h" LLFloaterRegListener::LLFloaterRegListener(): LLEventAPI("LLFloaterReg", @@ -72,6 +73,15 @@ LLFloaterRegListener::LLFloaterRegListener(): "Simulate clicking the named [\"button\"] in the visible floater named in [\"name\"]", &LLFloaterRegListener::clickButton, requiredNameButton); + + LLSD requiredParams; + requiredParams["xml_path"] = LLSD(); + requiredParams["command_pump"] = LLSD(); + requiredParams["reqid"] = LLSD(); + add("showLuaFloater", + "Open the new floater using XML file specified in [\"xml_path\"]" + "with ID in [\"reqid\"], which sends UI events to even pump specified in [\"command_pump\"]", + &LLFloaterRegListener::showLuaFloater, requiredParams); } void LLFloaterRegListener::getBuildMap(const LLSD& event) const @@ -154,3 +164,8 @@ void LLFloaterRegListener::clickButton(const LLSD& event) const LLEventPumps::instance().obtain(replyPump).post(reply); } } + +void LLFloaterRegListener::showLuaFloater(const LLSD &event) const +{ + LLLuaFloater::showLuaFloater(event); +} diff --git a/indra/llui/llfloaterreglistener.h b/indra/llui/llfloaterreglistener.h index 24311a2dfa..2d58303aa0 100644 --- a/indra/llui/llfloaterreglistener.h +++ b/indra/llui/llfloaterreglistener.h @@ -49,6 +49,8 @@ private: void toggleInstance(const LLSD& event) const; void instanceVisible(const LLSD& event) const; void clickButton(const LLSD& event) const; + + void showLuaFloater(const LLSD &event) const; }; #endif /* ! defined(LL_LLFLOATERREGLISTENER_H) */ diff --git a/indra/llui/llluafloater.cpp b/indra/llui/llluafloater.cpp new file mode 100644 index 0000000000..3507c907a0 --- /dev/null +++ b/indra/llui/llluafloater.cpp @@ -0,0 +1,162 @@ +/** + * @file llluafloater.cpp + * + * $LicenseInfo:firstyear=2024&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2024, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + * + */ + +#include "llluafloater.h" + +#include +#include "llevents.h" + +#include "llcheckboxctrl.h" +#include "llcombobox.h" + +const std::string LISTENER_NAME("LLLuaFloater"); + +LLLuaFloater::LLLuaFloater(const LLSD &key) : + LLFloater(key), + mCommandPumpName(key["command_pump"].asString()), + mDispatcher("LLLuaFloater", "action"), + mReqID(key) +{ + mListenerPumpName = LLUUID::generateNewID().asString(); + + mBoundListener = LLEventPumps::instance().obtain(mListenerPumpName).listen(LISTENER_NAME, [this](const LLSD &event) + { + if (event.has("action")) + { + mDispatcher.try_call(event); + } + else + { + LL_WARNS("LuaFloater") << "Unknown message: " << event << LL_ENDL; + } + return false; + }); + + LLSD requiredParams; + requiredParams["ctrl_name"] = LLSD(); + requiredParams["value"] = LLSD(); + mDispatcher.add("set_enabled", "", [this](const LLSD &event) + { + LLUICtrl *ctrl = getChild(event["ctrl_name"].asString()); + if(ctrl) + { + ctrl->setEnabled(event["value"].asBoolean()); + } + }, requiredParams); + mDispatcher.add("set_visible", "", [this](const LLSD &event) + { + LLUICtrl *ctrl = getChild(event["ctrl_name"].asString()); + if(ctrl) + { + ctrl->setVisible(event["value"].asBoolean()); + } + }, requiredParams); + mDispatcher.add("set_value", "", [this](const LLSD &event) + { + LLUICtrl *ctrl = getChild(event["ctrl_name"].asString()); + if(ctrl) + { + ctrl->setValue(event["value"]); + } + }, requiredParams); + + requiredParams = LLSD().with("value", LLSD()); + mDispatcher.add("set_title", "", [this](const LLSD &event) + { + setTitle(event["value"].asString()); + }); +} + +BOOL LLLuaFloater::postBuild() +{ + child_list_t::const_iterator iter = getChildList()->begin(); + child_list_t::const_iterator end = getChildList()->end(); + for (; iter != end; ++iter) + { + LLView *view = *iter; + if (!view) continue; + + LLSD data; + data["ctrl_name"] = view->getName(); + data["event"] = "click"; + + LLButton* btn = dynamic_cast(view); + if (btn && !isDefaultBtnName(btn->getName())) + { + data["ctrl_type"] = "LLButton"; + btn->setCommitCallback([this, data](LLUICtrl *ctrl, const LLSD ¶m) { post(data); }); + } + LLCheckBoxCtrl* check = dynamic_cast(view); + if (check) + { + data["ctrl_type"] = "LLCheckBoxCtrl"; + check->setCommitCallback([this, data](LLUICtrl *ctrl, const LLSD ¶m) + { + LLSD event(data); + event["value"] = ctrl->getValue(); + post(event); + }); + } + LLComboBox *combo = dynamic_cast(view); + if (combo) + { + data["ctrl_type"] = "LLComboBox"; + combo->setCommitCallback([this, data](LLUICtrl* ctrl, const LLSD ¶m) + { + LLSD event(data); + event["value"] = dynamic_cast(ctrl)->getValue(); + post(event); + }); + } + } + + post(LLSD().with("command_name", mListenerPumpName).with("event", "post_build")); + + return true; +} + +void LLLuaFloater::onClose(bool app_quitting) +{ + post(LLSD().with("event", "floater_close")); +} + +void LLLuaFloater::post(const LLSD &data) +{ + LLSD stamped_data(data); + mReqID.stamp(stamped_data); + LLEventPumps::instance().obtain(mCommandPumpName).post(stamped_data); +} + +void LLLuaFloater::showLuaFloater(const LLSD &data) +{ + std::filesystem::path fs_path(data["xml_path"].asString()); + + LLLuaFloater *floater = new LLLuaFloater(data); + floater->buildFromFile(fs_path.lexically_normal().string()); + floater->openFloater(floater->getKey()); +} + + diff --git a/indra/llui/llluafloater.h b/indra/llui/llluafloater.h new file mode 100644 index 0000000000..0b7e86746a --- /dev/null +++ b/indra/llui/llluafloater.h @@ -0,0 +1,52 @@ +/** + * @file llluafloater.h + * + * $LicenseInfo:firstyear=2024&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2024, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#ifndef LL_LLLUAFLOATER_H +#define LL_LLLUAFLOATER_H + +#include "llfloater.h" +#include "lleventdispatcher.h" +#include "llevents.h" + +class LLLuaFloater : public LLFloater +{ +public: + LLLuaFloater(const LLSD &key); + BOOL postBuild(); + + void onClose(bool app_quitting); + + void post(const LLSD &data); + static void showLuaFloater(const LLSD &data); + +private: + LLReqID mReqID; + LLEventDispatcher mDispatcher; + LLTempBoundListener mBoundListener; + + std::string mListenerPumpName; + std::string mCommandPumpName; +}; +#endif -- cgit v1.2.3 From 45fcb914c89ff721833497bfb021b7583f24bd1c Mon Sep 17 00:00:00 2001 From: Mnikolenko Productengine Date: Thu, 14 Mar 2024 15:29:47 +0200 Subject: Send additional events to the script when specified --- indra/llui/llluafloater.cpp | 78 ++++++++++++++++++++++++++++++++++++++++++++- indra/llui/llluafloater.h | 1 + 2 files changed, 78 insertions(+), 1 deletion(-) (limited to 'indra/llui') diff --git a/indra/llui/llluafloater.cpp b/indra/llui/llluafloater.cpp index 3507c907a0..5b50d85811 100644 --- a/indra/llui/llluafloater.cpp +++ b/indra/llui/llluafloater.cpp @@ -34,6 +34,15 @@ const std::string LISTENER_NAME("LLLuaFloater"); +const std::string COMMIT_EVENT("commit"); +const std::string MOUSE_ENTER_EVENT("mouse_enter"); +const std::string MOUSE_LEAVE_EVENT("mouse_leave"); +const std::string MOUSE_DOWN_EVENT("mouse_down"); +const std::string MOUSE_UP_EVENT("mouse_up"); +const std::string RIGHT_MOUSE_DOWN_EVENT("right_mouse_down"); +const std::string RIGHT_MOUSE_UP_EVENT("right_mouse_up"); +const std::string DOUBLE_CLICK_EVENT("double_click"); + LLLuaFloater::LLLuaFloater(const LLSD &key) : LLFloater(key), mCommandPumpName(key["command_pump"].asString()), @@ -101,7 +110,7 @@ BOOL LLLuaFloater::postBuild() LLSD data; data["ctrl_name"] = view->getName(); - data["event"] = "click"; + data["event"] = COMMIT_EVENT; LLButton* btn = dynamic_cast(view); if (btn && !isDefaultBtnName(btn->getName())) @@ -133,6 +142,22 @@ BOOL LLLuaFloater::postBuild() } } + //optional field to send additional specified events to the script + if (mKey.has("extra_events")) + { + //the first value is ctrl name, the second contains array of events to send + const LLSD &events_map = mKey["extra_events"]; + for (LLSD::map_const_iterator it = events_map.beginMap(); it != events_map.endMap(); ++it) + { + std::string name = (*it).first; + LLSD data = (*it).second; + for (LLSD::array_const_iterator events_it = data.beginArray(); events_it != data.endArray(); ++events_it) + { + registerCallback(name, events_it->asString()); + } + } + } + post(LLSD().with("command_name", mListenerPumpName).with("event", "post_build")); return true; @@ -143,6 +168,57 @@ void LLLuaFloater::onClose(bool app_quitting) post(LLSD().with("event", "floater_close")); } +void LLLuaFloater::registerCallback(const std::string &ctrl_name, const std::string &event) +{ + LLUICtrl *ctrl = getChild(ctrl_name); + if (!ctrl) return; + + LLSD data; + data["ctrl_name"] = ctrl_name; + data["event"] = event; + + auto mouse_event_cb = [this, data](LLUICtrl *ctrl, const LLSD ¶m) { post(data); }; + + auto mouse_event_coords_cb = [this, data](LLUICtrl *ctrl, S32 x, S32 y, MASK mask) + { + LLSD event(data); + post(event.with("x", x).with("y", y)); + }; + + if (event == MOUSE_ENTER_EVENT) + { + ctrl->setMouseEnterCallback(mouse_event_cb); + } + else if (event == MOUSE_LEAVE_EVENT) + { + ctrl->setMouseLeaveCallback(mouse_event_cb); + } + else if (event == MOUSE_DOWN_EVENT) + { + ctrl->setMouseDownCallback(mouse_event_coords_cb); + } + else if (event == MOUSE_UP_EVENT) + { + ctrl->setMouseUpCallback(mouse_event_coords_cb); + } + else if (event == RIGHT_MOUSE_DOWN_EVENT) + { + ctrl->setRightMouseDownCallback(mouse_event_coords_cb); + } + else if (event == RIGHT_MOUSE_UP_EVENT) + { + ctrl->setRightMouseUpCallback(mouse_event_coords_cb); + } + else if (event == DOUBLE_CLICK_EVENT) + { + ctrl->setDoubleClickCallback(mouse_event_coords_cb); + } + else + { + LL_WARNS("LuaFloater") << "Can't register callback for unknown event: " << event << " ,control: " << ctrl_name << LL_ENDL; + } +} + void LLLuaFloater::post(const LLSD &data) { LLSD stamped_data(data); diff --git a/indra/llui/llluafloater.h b/indra/llui/llluafloater.h index 0b7e86746a..eec6180bee 100644 --- a/indra/llui/llluafloater.h +++ b/indra/llui/llluafloater.h @@ -36,6 +36,7 @@ public: LLLuaFloater(const LLSD &key); BOOL postBuild(); + void registerCallback(const std::string &ctrl_name, const std::string &event); void onClose(bool app_quitting); void post(const LLSD &data); -- cgit v1.2.3 From fdfff5305bc9d97bb27d36a7fe18bab693e42aed Mon Sep 17 00:00:00 2001 From: Mnikolenko Productengine Date: Fri, 15 Mar 2024 18:20:42 +0200 Subject: set commit callback for all buttons including minimize, maximize --- indra/llui/llluafloater.cpp | 77 +++++++++++++++++++-------------------------- 1 file changed, 33 insertions(+), 44 deletions(-) (limited to 'indra/llui') diff --git a/indra/llui/llluafloater.cpp b/indra/llui/llluafloater.cpp index 5b50d85811..b60a893f12 100644 --- a/indra/llui/llluafloater.cpp +++ b/indra/llui/llluafloater.cpp @@ -34,14 +34,19 @@ const std::string LISTENER_NAME("LLLuaFloater"); -const std::string COMMIT_EVENT("commit"); -const std::string MOUSE_ENTER_EVENT("mouse_enter"); -const std::string MOUSE_LEAVE_EVENT("mouse_leave"); -const std::string MOUSE_DOWN_EVENT("mouse_down"); -const std::string MOUSE_UP_EVENT("mouse_up"); -const std::string RIGHT_MOUSE_DOWN_EVENT("right_mouse_down"); -const std::string RIGHT_MOUSE_UP_EVENT("right_mouse_up"); -const std::string DOUBLE_CLICK_EVENT("double_click"); +std::map 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"} +}; LLLuaFloater::LLLuaFloater(const LLSD &key) : LLFloater(key), @@ -108,36 +113,18 @@ BOOL LLLuaFloater::postBuild() LLView *view = *iter; if (!view) continue; - LLSD data; - data["ctrl_name"] = view->getName(); - data["event"] = COMMIT_EVENT; - - LLButton* btn = dynamic_cast(view); - if (btn && !isDefaultBtnName(btn->getName())) + LLUICtrl *ctrl = dynamic_cast(view); + if (ctrl) { - data["ctrl_type"] = "LLButton"; - btn->setCommitCallback([this, data](LLUICtrl *ctrl, const LLSD ¶m) { post(data); }); - } - LLCheckBoxCtrl* check = dynamic_cast(view); - if (check) - { - data["ctrl_type"] = "LLCheckBoxCtrl"; - check->setCommitCallback([this, data](LLUICtrl *ctrl, const LLSD ¶m) + LLSD data; + data["ctrl_name"] = view->getName(); + data["event"] = EVENT_LIST["COMMIT_EVENT"]; + + ctrl->setCommitCallback([this, data](LLUICtrl *ctrl, const LLSD ¶m) { LLSD event(data); event["value"] = ctrl->getValue(); - post(event); - }); - } - LLComboBox *combo = dynamic_cast(view); - if (combo) - { - data["ctrl_type"] = "LLComboBox"; - combo->setCommitCallback([this, data](LLUICtrl* ctrl, const LLSD ¶m) - { - LLSD event(data); - event["value"] = dynamic_cast(ctrl)->getValue(); - post(event); + post(event); }); } } @@ -158,14 +145,15 @@ BOOL LLLuaFloater::postBuild() } } - post(LLSD().with("command_name", mListenerPumpName).with("event", "post_build")); + //send pump name to the script after the floater is built + post(LLSD().with("command_name", mListenerPumpName).with("event", EVENT_LIST["POST_BUILD_EVENT"])); return true; } void LLLuaFloater::onClose(bool app_quitting) { - post(LLSD().with("event", "floater_close")); + post(LLSD().with("event", EVENT_LIST["CLOSE_EVENT"])); } void LLLuaFloater::registerCallback(const std::string &ctrl_name, const std::string &event) @@ -185,42 +173,43 @@ void LLLuaFloater::registerCallback(const std::string &ctrl_name, const std::str post(event.with("x", x).with("y", y)); }; - if (event == MOUSE_ENTER_EVENT) + if (event == EVENT_LIST["MOUSE_ENTER_EVENT"]) { ctrl->setMouseEnterCallback(mouse_event_cb); } - else if (event == MOUSE_LEAVE_EVENT) + else if (event == EVENT_LIST["MOUSE_LEAVE_EVENT"]) { ctrl->setMouseLeaveCallback(mouse_event_cb); } - else if (event == MOUSE_DOWN_EVENT) + else if (event == EVENT_LIST["MOUSE_DOWN_EVENT"]) { ctrl->setMouseDownCallback(mouse_event_coords_cb); } - else if (event == MOUSE_UP_EVENT) + else if (event == EVENT_LIST["MOUSE_UP_EVENT"]) { ctrl->setMouseUpCallback(mouse_event_coords_cb); } - else if (event == RIGHT_MOUSE_DOWN_EVENT) + else if (event == EVENT_LIST["RIGHT_MOUSE_DOWN_EVENT"]) { ctrl->setRightMouseDownCallback(mouse_event_coords_cb); } - else if (event == RIGHT_MOUSE_UP_EVENT) + else if (event == EVENT_LIST["RIGHT_MOUSE_UP_EVENT"]) { ctrl->setRightMouseUpCallback(mouse_event_coords_cb); } - else if (event == DOUBLE_CLICK_EVENT) + else if (event == EVENT_LIST["DOUBLE_CLICK_EVENT"]) { ctrl->setDoubleClickCallback(mouse_event_coords_cb); } else { - LL_WARNS("LuaFloater") << "Can't register callback for unknown event: " << event << " ,control: " << ctrl_name << LL_ENDL; + LL_WARNS("LuaFloater") << "Can't register callback for unknown event: " << event << " , control: " << ctrl_name << LL_ENDL; } } void LLLuaFloater::post(const LLSD &data) { + //send event data to the script signed with ["reqid"] key LLSD stamped_data(data); mReqID.stamp(stamped_data); LLEventPumps::instance().obtain(mCommandPumpName).post(stamped_data); -- cgit v1.2.3 From 052fdac5187cc529bbbe9be0c8d0f27516058ebd Mon Sep 17 00:00:00 2001 From: Mnikolenko Productengine Date: Mon, 18 Mar 2024 15:13:25 +0200 Subject: update to use new lua leap; initial support for scroll list --- indra/llui/llfloaterreglistener.cpp | 21 ++++++++--- indra/llui/llfloaterreglistener.h | 1 + indra/llui/llluafloater.cpp | 70 ++++++++++++++++++++++++++++++------- indra/llui/llluafloater.h | 3 +- 4 files changed, 77 insertions(+), 18 deletions(-) (limited to 'indra/llui') diff --git a/indra/llui/llfloaterreglistener.cpp b/indra/llui/llfloaterreglistener.cpp index 6fee688121..bdf26c1db8 100644 --- a/indra/llui/llfloaterreglistener.cpp +++ b/indra/llui/llfloaterreglistener.cpp @@ -76,12 +76,12 @@ LLFloaterRegListener::LLFloaterRegListener(): LLSD requiredParams; requiredParams["xml_path"] = LLSD(); - requiredParams["command_pump"] = LLSD(); - requiredParams["reqid"] = LLSD(); add("showLuaFloater", - "Open the new floater using XML file specified in [\"xml_path\"]" - "with ID in [\"reqid\"], which sends UI events to even pump specified in [\"command_pump\"]", + "Open the new floater using XML file specified in [\"xml_path\"]", &LLFloaterRegListener::showLuaFloater, requiredParams); + add("getFloaterEvents", + "Return the table of Lua Floater events which are send to the script", + &LLFloaterRegListener::getLuaFloaterEvents); } void LLFloaterRegListener::getBuildMap(const LLSD& event) const @@ -169,3 +169,16 @@ void LLFloaterRegListener::showLuaFloater(const LLSD &event) const { LLLuaFloater::showLuaFloater(event); } + +void LLFloaterRegListener::getLuaFloaterEvents(const LLSD &event) const +{ + if (event.has("reply")) + { + LLSD events_data = LLLuaFloater::getEventsData(); + + LLReqID reqID(event); + LLSD reply(reqID.makeResponse()); + LLEventPumps::instance().obtain(event["reply"]).post(reply.with("events", events_data)); + } +} + diff --git a/indra/llui/llfloaterreglistener.h b/indra/llui/llfloaterreglistener.h index 2d58303aa0..cbfb7855b9 100644 --- a/indra/llui/llfloaterreglistener.h +++ b/indra/llui/llfloaterreglistener.h @@ -51,6 +51,7 @@ private: void clickButton(const LLSD& event) const; void showLuaFloater(const LLSD &event) const; + void getLuaFloaterEvents(const LLSD &event) const; }; #endif /* ! defined(LL_LLFLOATERREGLISTENER_H) */ diff --git a/indra/llui/llluafloater.cpp b/indra/llui/llluafloater.cpp index b60a893f12..36dd0d58bd 100644 --- a/indra/llui/llluafloater.cpp +++ b/indra/llui/llluafloater.cpp @@ -31,6 +31,7 @@ #include "llcheckboxctrl.h" #include "llcombobox.h" +#include "llscrolllistctrl.h" const std::string LISTENER_NAME("LLLuaFloater"); @@ -50,9 +51,8 @@ std::map EVENT_LIST = LLLuaFloater::LLLuaFloater(const LLSD &key) : LLFloater(key), - mCommandPumpName(key["command_pump"].asString()), - mDispatcher("LLLuaFloater", "action"), - mReqID(key) + mCommandPumpName(key["reply"].asString()), + mDispatcher("LLLuaFloater", "action") { mListenerPumpName = LLUUID::generateNewID().asString(); @@ -69,9 +69,7 @@ LLLuaFloater::LLLuaFloater(const LLSD &key) : return false; }); - LLSD requiredParams; - requiredParams["ctrl_name"] = LLSD(); - requiredParams["value"] = LLSD(); + LLSD requiredParams = LLSD().with("ctrl_name", LLSD()).with("value", LLSD()); mDispatcher.add("set_enabled", "", [this](const LLSD &event) { LLUICtrl *ctrl = getChild(event["ctrl_name"].asString()); @@ -96,12 +94,39 @@ LLLuaFloater::LLLuaFloater(const LLSD &key) : ctrl->setValue(event["value"]); } }, requiredParams); + mDispatcher.add("add_list_element", "", [this](const LLSD &event) + { + LLScrollListCtrl *ctrl = getChild(event["ctrl_name"].asString()); + if(ctrl) + { + ctrl->addElement(event["value"]); + } + }, requiredParams); requiredParams = LLSD().with("value", LLSD()); mDispatcher.add("set_title", "", [this](const LLSD &event) { setTitle(event["value"].asString()); - }); + }, requiredParams); + + requiredParams = LLSD().with("ctrl_name", LLSD()).with("reqid", LLSD()); + mDispatcher.add("get_value", "", [this](const LLSD &event) + { + LLUICtrl *ctrl = getChild(event["ctrl_name"].asString()); + if(ctrl) + { + LLSD response; + response["value"] = ctrl->getValue(); + response["reqid"] = event["reqid"]; + post(response); + } + }, requiredParams); +} + +LLLuaFloater::~LLLuaFloater() +{ + //post empty LLSD() to indicate done, in case it wasn't handled by the script after CLOSE_EVENT + post(LLSD()); } BOOL LLLuaFloater::postBuild() @@ -199,7 +224,20 @@ void LLLuaFloater::registerCallback(const std::string &ctrl_name, const std::str } else if (event == EVENT_LIST["DOUBLE_CLICK_EVENT"]) { - ctrl->setDoubleClickCallback(mouse_event_coords_cb); + LLScrollListCtrl *list = dynamic_cast(ctrl); + if (list) + { + list->setDoubleClickCallback( + [this, data, list]() + { + LLSD event(data); + post(event.with("value", list->getCurrentID())); + }); + } + else + { + ctrl->setDoubleClickCallback(mouse_event_coords_cb); + } } else { @@ -209,10 +247,8 @@ void LLLuaFloater::registerCallback(const std::string &ctrl_name, const std::str void LLLuaFloater::post(const LLSD &data) { - //send event data to the script signed with ["reqid"] key - LLSD stamped_data(data); - mReqID.stamp(stamped_data); - LLEventPumps::instance().obtain(mCommandPumpName).post(stamped_data); + //send event data to the script + LLEventPumps::instance().obtain(mCommandPumpName).post(data); } void LLLuaFloater::showLuaFloater(const LLSD &data) @@ -224,4 +260,12 @@ void LLLuaFloater::showLuaFloater(const LLSD &data) floater->openFloater(floater->getKey()); } - +LLSD LLLuaFloater::getEventsData() +{ + LLSD event_data; + for (auto &it : EVENT_LIST) + { + event_data[it.first] = it.second; + } + return event_data; +} diff --git a/indra/llui/llluafloater.h b/indra/llui/llluafloater.h index eec6180bee..0dd39e7d1e 100644 --- a/indra/llui/llluafloater.h +++ b/indra/llui/llluafloater.h @@ -35,15 +35,16 @@ class LLLuaFloater : public LLFloater public: LLLuaFloater(const LLSD &key); BOOL postBuild(); + virtual ~LLLuaFloater(); void registerCallback(const std::string &ctrl_name, const std::string &event); void onClose(bool app_quitting); void post(const LLSD &data); static void showLuaFloater(const LLSD &data); + static LLSD getEventsData(); private: - LLReqID mReqID; LLEventDispatcher mDispatcher; LLTempBoundListener mBoundListener; -- cgit v1.2.3 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/llui/llluafloater.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'indra/llui') diff --git a/indra/llui/llluafloater.cpp b/indra/llui/llluafloater.cpp index 36dd0d58bd..27ae85c844 100644 --- a/indra/llui/llluafloater.cpp +++ b/indra/llui/llluafloater.cpp @@ -254,9 +254,15 @@ void LLLuaFloater::post(const LLSD &data) void LLLuaFloater::showLuaFloater(const LLSD &data) { std::filesystem::path fs_path(data["xml_path"].asString()); - + std::string path = fs_path.lexically_normal().string(); + if (!fs_path.is_absolute()) + { + std::string lib_path = gDirUtilp->getExpandedFilename(LL_PATH_SCRIPTS, "lua"); + path = (std::filesystem::path(lib_path) / path).u8string(); + } + LLLuaFloater *floater = new LLLuaFloater(data); - floater->buildFromFile(fs_path.lexically_normal().string()); + floater->buildFromFile(path); floater->openFloater(floater->getKey()); } -- 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/llui/llfloater.cpp | 4 ---- indra/llui/llfloater.h | 3 --- indra/llui/llfloaterreglistener.cpp | 20 +++---------------- indra/llui/llfloaterreglistener.h | 1 - indra/llui/llluafloater.cpp | 39 +++++++++++++++---------------------- indra/llui/llluafloater.h | 3 ++- 6 files changed, 21 insertions(+), 49 deletions(-) (limited to 'indra/llui') diff --git a/indra/llui/llfloater.cpp b/indra/llui/llfloater.cpp index b9b69b5a33..de3de53569 100644 --- a/indra/llui/llfloater.cpp +++ b/indra/llui/llfloater.cpp @@ -3623,10 +3623,6 @@ void LLFloater::applyRelativePosition() translate(new_center.mX - cur_center.mX, new_center.mY - cur_center.mY); } -bool LLFloater::isDefaultBtnName(const std::string& name) -{ - return (std::find(std::begin(sButtonNames), std::end(sButtonNames), name) != std::end(sButtonNames)); -} LLCoordFloater::LLCoordFloater(F32 x, F32 y, LLFloater& floater) : coord_t((S32)x, (S32)y) diff --git a/indra/llui/llfloater.h b/indra/llui/llfloater.h index 9d49c4538e..88f9e77777 100644 --- a/indra/llui/llfloater.h +++ b/indra/llui/llfloater.h @@ -372,9 +372,6 @@ public: void enableResizeCtrls(bool enable, bool width = true, bool height = true); bool isPositioning(LLFloaterEnums::EOpenPositioning p) const { return (p == mPositioning); } - - static bool isDefaultBtnName(const std::string& name); - protected: void applyControlsAndPosition(LLFloater* other); diff --git a/indra/llui/llfloaterreglistener.cpp b/indra/llui/llfloaterreglistener.cpp index bdf26c1db8..8316101264 100644 --- a/indra/llui/llfloaterreglistener.cpp +++ b/indra/llui/llfloaterreglistener.cpp @@ -74,11 +74,9 @@ LLFloaterRegListener::LLFloaterRegListener(): &LLFloaterRegListener::clickButton, requiredNameButton); - LLSD requiredParams; - requiredParams["xml_path"] = LLSD(); add("showLuaFloater", - "Open the new floater using XML file specified in [\"xml_path\"]", - &LLFloaterRegListener::showLuaFloater, requiredParams); + "Open the new floater using XML file specified in [\"xml_path\"] with ID in [\"reqid\"]", + &LLLuaFloater::showLuaFloater, {llsd::map("xml_path", LLSD(), "reqid", LLSD())}); add("getFloaterEvents", "Return the table of Lua Floater events which are send to the script", &LLFloaterRegListener::getLuaFloaterEvents); @@ -165,20 +163,8 @@ void LLFloaterRegListener::clickButton(const LLSD& event) const } } -void LLFloaterRegListener::showLuaFloater(const LLSD &event) const -{ - LLLuaFloater::showLuaFloater(event); -} - void LLFloaterRegListener::getLuaFloaterEvents(const LLSD &event) const { - if (event.has("reply")) - { - LLSD events_data = LLLuaFloater::getEventsData(); - - LLReqID reqID(event); - LLSD reply(reqID.makeResponse()); - LLEventPumps::instance().obtain(event["reply"]).post(reply.with("events", events_data)); - } + Response response(llsd::map("events", LLLuaFloater::getEventsData()), event); } diff --git a/indra/llui/llfloaterreglistener.h b/indra/llui/llfloaterreglistener.h index cbfb7855b9..9cb0af2de5 100644 --- a/indra/llui/llfloaterreglistener.h +++ b/indra/llui/llfloaterreglistener.h @@ -50,7 +50,6 @@ private: void instanceVisible(const LLSD& event) const; void clickButton(const LLSD& event) const; - void showLuaFloater(const LLSD &event) const; void getLuaFloaterEvents(const LLSD &event) const; }; diff --git a/indra/llui/llluafloater.cpp b/indra/llui/llluafloater.cpp index 27ae85c844..668c0edc53 100644 --- a/indra/llui/llluafloater.cpp +++ b/indra/llui/llluafloater.cpp @@ -51,8 +51,9 @@ std::map EVENT_LIST = LLLuaFloater::LLLuaFloater(const LLSD &key) : LLFloater(key), - mCommandPumpName(key["reply"].asString()), - mDispatcher("LLLuaFloater", "action") + mReplyPumpName(key["reply"].asString()), + mDispatcher("LLLuaFloater", "action"), + mReqID(key) { mListenerPumpName = LLUUID::generateNewID().asString(); @@ -69,7 +70,7 @@ LLLuaFloater::LLLuaFloater(const LLSD &key) : return false; }); - LLSD requiredParams = LLSD().with("ctrl_name", LLSD()).with("value", LLSD()); + LLSD requiredParams = llsd::map("ctrl_name", LLSD(), "value", LLSD()); mDispatcher.add("set_enabled", "", [this](const LLSD &event) { LLUICtrl *ctrl = getChild(event["ctrl_name"].asString()); @@ -103,13 +104,11 @@ LLLuaFloater::LLLuaFloater(const LLSD &key) : } }, requiredParams); - requiredParams = LLSD().with("value", LLSD()); mDispatcher.add("set_title", "", [this](const LLSD &event) { setTitle(event["value"].asString()); - }, requiredParams); + }, llsd::map("value", LLSD())); - requiredParams = LLSD().with("ctrl_name", LLSD()).with("reqid", LLSD()); mDispatcher.add("get_value", "", [this](const LLSD &event) { LLUICtrl *ctrl = getChild(event["ctrl_name"].asString()); @@ -120,7 +119,7 @@ LLLuaFloater::LLLuaFloater(const LLSD &key) : response["reqid"] = event["reqid"]; post(response); } - }, requiredParams); + }, llsd::map("ctrl_name", LLSD(), "reqid", LLSD())); } LLLuaFloater::~LLLuaFloater() @@ -131,13 +130,8 @@ LLLuaFloater::~LLLuaFloater() BOOL LLLuaFloater::postBuild() { - child_list_t::const_iterator iter = getChildList()->begin(); - child_list_t::const_iterator end = getChildList()->end(); - for (; iter != end; ++iter) + for (LLView *view : *getChildList()) { - LLView *view = *iter; - if (!view) continue; - LLUICtrl *ctrl = dynamic_cast(view); if (ctrl) { @@ -158,27 +152,24 @@ BOOL LLLuaFloater::postBuild() if (mKey.has("extra_events")) { //the first value is ctrl name, the second contains array of events to send - const LLSD &events_map = mKey["extra_events"]; - for (LLSD::map_const_iterator it = events_map.beginMap(); it != events_map.endMap(); ++it) + for (const auto &[name, data] : llsd::inMap(mKey["extra_events"])) { - std::string name = (*it).first; - LLSD data = (*it).second; - for (LLSD::array_const_iterator events_it = data.beginArray(); events_it != data.endArray(); ++events_it) + for (const auto &event : llsd::inArray(data)) { - registerCallback(name, events_it->asString()); + registerCallback(name, event); } } } //send pump name to the script after the floater is built - post(LLSD().with("command_name", mListenerPumpName).with("event", EVENT_LIST["POST_BUILD_EVENT"])); + post(llsd::map("command_name", mListenerPumpName, "event", EVENT_LIST["POST_BUILD_EVENT"])); return true; } void LLLuaFloater::onClose(bool app_quitting) { - post(LLSD().with("event", EVENT_LIST["CLOSE_EVENT"])); + post(llsd::map("event", EVENT_LIST["CLOSE_EVENT"], "app_quitting", app_quitting)); } void LLLuaFloater::registerCallback(const std::string &ctrl_name, const std::string &event) @@ -247,8 +238,10 @@ void LLLuaFloater::registerCallback(const std::string &ctrl_name, const std::str void LLLuaFloater::post(const LLSD &data) { - //send event data to the script - LLEventPumps::instance().obtain(mCommandPumpName).post(data); + // send event data to the script signed with ["reqid"] key + LLSD stamped_data(data); + mReqID.stamp(stamped_data); + LLEventPumps::instance().obtain(mReplyPumpName).post(stamped_data); } void LLLuaFloater::showLuaFloater(const LLSD &data) diff --git a/indra/llui/llluafloater.h b/indra/llui/llluafloater.h index 0dd39e7d1e..b9f96f0ad3 100644 --- a/indra/llui/llluafloater.h +++ b/indra/llui/llluafloater.h @@ -45,10 +45,11 @@ public: static LLSD getEventsData(); private: + LLReqID mReqID; LLEventDispatcher mDispatcher; LLTempBoundListener mBoundListener; std::string mListenerPumpName; - std::string mCommandPumpName; + std::string mReplyPumpName; }; #endif -- 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/llui/llluafloater.cpp | 68 ++++++++++++++++----------------------------- indra/llui/llluafloater.h | 4 +-- 2 files changed, 25 insertions(+), 47 deletions(-) (limited to 'indra/llui') diff --git a/indra/llui/llluafloater.cpp b/indra/llui/llluafloater.cpp index 668c0edc53..4ae0e28963 100644 --- a/indra/llui/llluafloater.cpp +++ b/indra/llui/llluafloater.cpp @@ -49,53 +49,40 @@ std::map EVENT_LIST = {"CLOSE_EVENT", "floater_close"} }; + + LLLuaFloater::LLLuaFloater(const LLSD &key) : - LLFloater(key), + LLFloater(key), + mDispatchListener(LLUUID::generateNewID().asString(), "action"), mReplyPumpName(key["reply"].asString()), - mDispatcher("LLLuaFloater", "action"), mReqID(key) { - mListenerPumpName = LLUUID::generateNewID().asString(); - - mBoundListener = LLEventPumps::instance().obtain(mListenerPumpName).listen(LISTENER_NAME, [this](const LLSD &event) - { - if (event.has("action")) - { - mDispatcher.try_call(event); - } - else + auto ctrl_lookup = [this](const LLSD &event, std::function cb) + { + LLUICtrl *ctrl = getChild(event["ctrl_name"].asString()); + if (!ctrl) { - LL_WARNS("LuaFloater") << "Unknown message: " << event << LL_ENDL; + LL_WARNS("LuaFloater") << "Control not found: " << event["ctrl_name"] << LL_ENDL; + return LLSD(); } - return false; - }); + return cb(ctrl, event); + }; LLSD requiredParams = llsd::map("ctrl_name", LLSD(), "value", LLSD()); - mDispatcher.add("set_enabled", "", [this](const LLSD &event) + mDispatchListener.add("set_enabled", "", [this, ctrl_lookup](const LLSD &event) { - LLUICtrl *ctrl = getChild(event["ctrl_name"].asString()); - if(ctrl) - { - ctrl->setEnabled(event["value"].asBoolean()); - } + return ctrl_lookup(event, [](LLUICtrl *ctrl, const LLSD &event) { ctrl->setEnabled(event["value"].asBoolean()); return LLSD(); }); }, requiredParams); - mDispatcher.add("set_visible", "", [this](const LLSD &event) + mDispatchListener.add("set_visible", "", [this, ctrl_lookup](const LLSD &event) { - LLUICtrl *ctrl = getChild(event["ctrl_name"].asString()); - if(ctrl) - { - ctrl->setVisible(event["value"].asBoolean()); - } + return ctrl_lookup(event, [](LLUICtrl *ctrl, const LLSD &event) { ctrl->setVisible(event["value"].asBoolean()); return LLSD(); }); }, requiredParams); - mDispatcher.add("set_value", "", [this](const LLSD &event) + mDispatchListener.add("set_value", "", [this, ctrl_lookup](const LLSD &event) { - LLUICtrl *ctrl = getChild(event["ctrl_name"].asString()); - if(ctrl) - { - ctrl->setValue(event["value"]); - } + return ctrl_lookup(event, [](LLUICtrl *ctrl, const LLSD &event) { ctrl->setValue(event["value"]); return LLSD(); }); }, requiredParams); - mDispatcher.add("add_list_element", "", [this](const LLSD &event) + + mDispatchListener.add("add_list_element", "", [this](const LLSD &event) { LLScrollListCtrl *ctrl = getChild(event["ctrl_name"].asString()); if(ctrl) @@ -104,21 +91,14 @@ LLLuaFloater::LLLuaFloater(const LLSD &key) : } }, requiredParams); - mDispatcher.add("set_title", "", [this](const LLSD &event) + mDispatchListener.add("set_title", "", [this](const LLSD &event) { setTitle(event["value"].asString()); }, llsd::map("value", LLSD())); - mDispatcher.add("get_value", "", [this](const LLSD &event) + mDispatchListener.add("get_value", "", [this, ctrl_lookup](const LLSD &event) { - LLUICtrl *ctrl = getChild(event["ctrl_name"].asString()); - if(ctrl) - { - LLSD response; - response["value"] = ctrl->getValue(); - response["reqid"] = event["reqid"]; - post(response); - } + return ctrl_lookup(event, [](LLUICtrl *ctrl, const LLSD &event) { return llsd::map("value", ctrl->getValue()); }); }, llsd::map("ctrl_name", LLSD(), "reqid", LLSD())); } @@ -162,7 +142,7 @@ BOOL LLLuaFloater::postBuild() } //send pump name to the script after the floater is built - post(llsd::map("command_name", mListenerPumpName, "event", EVENT_LIST["POST_BUILD_EVENT"])); + post(llsd::map("command_name", mDispatchListener.getPumpName(), "event", EVENT_LIST["POST_BUILD_EVENT"])); return true; } diff --git a/indra/llui/llluafloater.h b/indra/llui/llluafloater.h index b9f96f0ad3..d4c16745ee 100644 --- a/indra/llui/llluafloater.h +++ b/indra/llui/llluafloater.h @@ -46,10 +46,8 @@ public: private: LLReqID mReqID; - LLEventDispatcher mDispatcher; - LLTempBoundListener mBoundListener; + LLDispatchListener mDispatchListener; - std::string mListenerPumpName; std::string mReplyPumpName; }; #endif -- 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/llui/llluafloater.cpp | 73 ++++++++++++++++++++++++++++----------------- indra/llui/llluafloater.h | 1 + 2 files changed, 47 insertions(+), 27 deletions(-) (limited to 'indra/llui') 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 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 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(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 ¶m) { 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(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(); -- cgit v1.2.3 From 7b149485e091880269dd9d7941cca47da49e652f Mon Sep 17 00:00:00 2001 From: Mnikolenko Productengine Date: Thu, 21 Mar 2024 22:05:37 +0200 Subject: mac build fix --- indra/llui/llluafloater.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'indra/llui') diff --git a/indra/llui/llluafloater.cpp b/indra/llui/llluafloater.cpp index 23a336a1e8..afc287a864 100644 --- a/indra/llui/llluafloater.cpp +++ b/indra/llui/llluafloater.cpp @@ -66,15 +66,15 @@ LLLuaFloater::LLLuaFloater(const LLSD &key) : }; LLSD requiredParams = llsd::map("ctrl_name", LLSD(), "value", LLSD()); - mDispatchListener.add("set_enabled", "", [this, ctrl_lookup](const LLSD &event) + mDispatchListener.add("set_enabled", "", [ctrl_lookup](const LLSD &event) { return ctrl_lookup(event, [](LLUICtrl *ctrl, const LLSD &event) { ctrl->setEnabled(event["value"].asBoolean()); return LLSD(); }); }, requiredParams); - mDispatchListener.add("set_visible", "", [this, ctrl_lookup](const LLSD &event) + mDispatchListener.add("set_visible", "", [ctrl_lookup](const LLSD &event) { return ctrl_lookup(event, [](LLUICtrl *ctrl, const LLSD &event) { ctrl->setVisible(event["value"].asBoolean()); return LLSD(); }); }, requiredParams); - mDispatchListener.add("set_value", "", [this, ctrl_lookup](const LLSD &event) + mDispatchListener.add("set_value", "", [ctrl_lookup](const LLSD &event) { return ctrl_lookup(event, [](LLUICtrl *ctrl, const LLSD &event) { ctrl->setValue(event["value"]); return LLSD(); }); }, requiredParams); @@ -104,7 +104,7 @@ LLLuaFloater::LLLuaFloater(const LLSD &key) : setTitle(event["value"].asString()); }, llsd::map("value", LLSD())); - mDispatchListener.add("get_value", "", [this, ctrl_lookup](const LLSD &event) + mDispatchListener.add("get_value", "", [ctrl_lookup](const LLSD &event) { return ctrl_lookup(event, [](LLUICtrl *ctrl, const LLSD &event) { return llsd::map("value", ctrl->getValue()); }); }, llsd::map("ctrl_name", LLSD(), "reqid", LLSD())); -- cgit v1.2.3