summaryrefslogtreecommitdiff
path: root/indra/newview/llluamanager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview/llluamanager.cpp')
-rw-r--r--indra/newview/llluamanager.cpp227
1 files changed, 214 insertions, 13 deletions
diff --git a/indra/newview/llluamanager.cpp b/indra/newview/llluamanager.cpp
index c4603e493c..0f984ca0ca 100644
--- a/indra/newview/llluamanager.cpp
+++ b/indra/newview/llluamanager.cpp
@@ -34,11 +34,14 @@
#include "llfloaterreg.h"
#include "llfloaterimnearbychat.h"
#include "llfloatersidepanelcontainer.h"
+#include "llnotificationsutil.h"
#include "llvoavatarself.h"
#include "llviewermenu.h"
#include "llviewermenufile.h"
#include "llviewerwindow.h"
#include "lluilistener.h"
+#include "llanimationstates.h"
+#include "llinventoryfunctions.h"
#include <boost/algorithm/string/replace.hpp>
@@ -66,6 +69,37 @@ int lua_printWarning(lua_State *L)
return 1;
}
+bool checkLua(lua_State *L, int r, std::string &error_msg)
+{
+ if (r != LUA_OK)
+ {
+ error_msg = lua_tostring(L, -1);
+
+ LL_WARNS() << error_msg << LL_ENDL;
+ return false;
+ }
+ return true;
+}
+
+LLSD luatable_to_llsd_string(lua_State *L, S32 idx)
+{
+ LLSD args;
+
+ // push first key
+ lua_pushnil(L);
+ while (lua_next(L, idx) != 0)
+ {
+ // right now -2 is key, -1 is value
+ lua_rawgeti(L, -1, 1);
+ lua_rawgeti(L, -2, 2);
+ std::string key = lua_tostring(L, -2);
+ std::string value = lua_tostring(L, -1);
+ args[key] = value;
+ lua_pop(L, 3);
+ }
+ return args;
+}
+
int lua_avatar_sit(lua_State *L)
{
gAgent.sitDown();
@@ -109,12 +143,38 @@ int lua_open_floater(lua_State *L)
return 1;
}
+int lua_close_floater(lua_State *L)
+{
+ std::string floater_name(lua_tostring(L, 1));
+
+ LLSD key;
+ if (floater_name == "profile")
+ {
+ key["id"] = gAgentID;
+ }
+ LLFloaterReg::hideInstance(floater_name, key);
+
+ return 1;
+}
+
int lua_close_all_floaters(lua_State *L)
{
close_all_windows();
return 1;
}
+int lua_click_child(lua_State *L)
+{
+ std::string parent_name(lua_tostring(L, 1));
+ std::string child_name(lua_tostring(L, 2));
+
+ LLFloater *floater = LLFloaterReg::findInstance(parent_name);
+ LLUICtrl *child = floater->getChild<LLUICtrl>(child_name, true);
+ child->onCommit();
+
+ return 1;
+}
+
int lua_snapshot_to_file(lua_State *L)
{
std::string filename(lua_tostring(L, 1));
@@ -150,7 +210,7 @@ int lua_set_debug_setting_bool(lua_State *L)
return 1;
}
- int lua_get_avatar_name(lua_State *L)
+int lua_get_avatar_name(lua_State *L)
{
std::string name = gAgentAvatarp->getFullname();
lua_pushstring(L, name.c_str());
@@ -163,12 +223,156 @@ int lua_is_avatar_flying(lua_State *L)
return 1;
}
+int lua_play_animation(lua_State *L)
+{
+ std::string anim_name = lua_tostring(L,1);
+
+ EAnimRequest req = ANIM_REQUEST_START;
+ if (lua_gettop(L) > 1)
+ {
+ req = (EAnimRequest) (int) lua_tonumber(L, 2);
+ }
+
+ LLInventoryModel::cat_array_t cat_array;
+ LLInventoryModel::item_array_t item_array;
+ LLNameItemCollector has_name(anim_name);
+ gInventory.collectDescendentsIf(gInventory.getRootFolderID(),
+ cat_array,
+ item_array,
+ LLInventoryModel::EXCLUDE_TRASH,
+ has_name);
+ for (auto& item: item_array)
+ {
+ if (item->getType() == LLAssetType::AT_ANIMATION)
+ {
+ LLUUID anim_id = item->getAssetUUID();
+ LL_INFOS() << "Playing animation " << anim_id << LL_ENDL;
+ gAgent.sendAnimationRequest(anim_id, req);
+ return 1;
+ }
+ }
+ LL_WARNS() << "No animation found for name " << anim_name << LL_ENDL;
+
+ return 1;
+}
+
int lua_env_setting_event(lua_State *L)
{
handle_env_setting_event(lua_tostring(L, 1));
return 1;
}
+void handle_notification_dialog(const LLSD &notification, const LLSD &response, lua_State *L, std::string response_cb)
+{
+ if (!response_cb.empty())
+ {
+ S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
+
+ lua_pushinteger(L, option);
+ lua_setglobal(L, response_cb.c_str());
+ }
+}
+
+int lua_show_notification(lua_State *L)
+{
+ std::string notification(lua_tostring(L, 1));
+
+ if (lua_type(L, 2) == LUA_TTABLE)
+ {
+ LLSD args = luatable_to_llsd_string(L, 2);
+
+ std::string response_cb;
+ if (lua_type(L, 3) == LUA_TSTRING)
+ {
+ response_cb = lua_tostring(L, 3);
+ }
+
+ LLNotificationsUtil::add(notification, args, LLSD(), boost::bind(handle_notification_dialog, _1, _2, L, response_cb));
+ }
+ else if (lua_type(L, 2) == LUA_TSTRING)
+ {
+ std::string response_cb = lua_tostring(L, 2);
+ LLNotificationsUtil::add(notification, LLSD(), LLSD(), boost::bind(handle_notification_dialog, _1, _2, L, response_cb));
+ }
+ else
+ {
+ LLNotificationsUtil::add(notification);
+ }
+
+ return 1;
+}
+
+int lua_add_menu_item(lua_State *L)
+{
+ std::string menu(lua_tostring(L, 1));
+ if (lua_type(L, 2) == LUA_TTABLE)
+ {
+ LLSD args = luatable_to_llsd_string(L, 2);
+
+ LLMenuItemCallGL::Params item_params;
+ item_params.name = args["name"];
+ item_params.label = args["label"];
+
+ LLUICtrl::CommitCallbackParam item_func;
+ item_func.function_name = args["function"];
+ if (args.has("parameter"))
+ {
+ item_func.parameter = args["parameter"];
+ }
+ item_params.on_click = item_func;
+
+ LLMenuItemCallGL *menu_item = LLUICtrlFactory::create<LLMenuItemCallGL>(item_params);
+ gMenuBarView->findChildMenuByName(menu, true)->append(menu_item);
+ }
+
+ return 1;
+}
+
+int lua_add_menu_separator(lua_State *L)
+{
+ std::string menu(lua_tostring(L, 1));
+ gMenuBarView->findChildMenuByName(menu, true)->addSeparator();
+
+ return 1;
+}
+
+int lua_add_menu(lua_State *L)
+{
+ if (lua_type(L, 1) == LUA_TTABLE)
+ {
+ LLSD args = luatable_to_llsd_string(L, 1);
+
+ LLMenuGL::Params item_params;
+ item_params.name = args["name"];
+ item_params.label = args["label"];
+ item_params.can_tear_off = args["tear_off"];
+
+ LLMenuGL *menu = LLUICtrlFactory::create<LLMenuGL>(item_params);
+ gMenuBarView->appendMenu(menu);
+ }
+
+ return 1;
+}
+
+int lua_add_branch(lua_State *L)
+{
+ std::string menu(lua_tostring(L, 1));
+ if (lua_type(L, 2) == LUA_TTABLE)
+ {
+ LLSD args = luatable_to_llsd_string(L, 2);
+
+ LLMenuGL::Params item_params;
+ item_params.name = args["name"];
+ item_params.label = args["label"];
+ item_params.can_tear_off = args["tear_off"];
+
+ LLMenuGL *branch = LLUICtrlFactory::create<LLMenuGL>(item_params);
+ gMenuBarView->findChildMenuByName(menu, true)->appendMenu(branch);
+ }
+
+ return 1;
+}
+
int lua_run_ui_command(lua_State *L)
{
int top = lua_gettop(L);
@@ -194,18 +398,6 @@ int lua_run_ui_command(lua_State *L)
return 1;
}
-bool checkLua(lua_State *L, int r, std::string &error_msg)
-{
- if (r != LUA_OK)
- {
- error_msg = lua_tostring(L, -1);
-
- LL_WARNS() << error_msg << LL_ENDL;
- return false;
- }
- return true;
-}
-
void initLUA(lua_State *L)
{
lua_register(L, "print_warning", lua_printWarning);
@@ -216,16 +408,25 @@ void initLUA(lua_State *L)
lua_register(L, "nearby_chat_send", lua_nearby_chat_send);
lua_register(L, "wear_by_name", lua_wear_by_name);
lua_register(L, "open_floater", lua_open_floater);
+ lua_register(L, "close_floater", lua_close_floater);
lua_register(L, "close_all_floaters", lua_close_all_floaters);
+ lua_register(L, "click_child", lua_click_child);
lua_register(L, "open_wearing_tab", lua_open_wearing_tab);
lua_register(L, "snapshot_to_file", lua_snapshot_to_file);
lua_register(L, "get_avatar_name", lua_get_avatar_name);
lua_register(L, "is_avatar_flying", lua_is_avatar_flying);
+ lua_register(L, "play_animation", lua_play_animation);
lua_register(L, "env_setting_event", lua_env_setting_event);
lua_register(L, "set_debug_setting_bool", lua_set_debug_setting_bool);
+ lua_register(L, "show_notification", lua_show_notification);
+ lua_register(L, "add_menu_separator", lua_add_menu_separator);
+ lua_register(L, "add_menu_item", lua_add_menu_item);
+ lua_register(L, "add_menu", lua_add_menu);
+ lua_register(L, "add_branch", lua_add_branch);
+
lua_register(L, "run_ui_command", lua_run_ui_command);
}