diff options
-rw-r--r-- | indra/newview/llluamanager.cpp | 443 | ||||
-rw-r--r-- | scripts/lua/avatar.lua | 12 | ||||
-rw-r--r-- | scripts/lua/demo.lua | 145 |
3 files changed, 1 insertions, 599 deletions
diff --git a/indra/newview/llluamanager.cpp b/indra/newview/llluamanager.cpp index 09ca6e10a7..3e3ce45cb0 100644 --- a/indra/newview/llluamanager.cpp +++ b/indra/newview/llluamanager.cpp @@ -40,22 +40,8 @@ // skip all these link dependencies for integration testing #ifndef LL_TEST -#include "llagent.h" -#include "llappearancemgr.h" -#include "llcallbacklist.h" -#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 "lltoolplacer.h" -#include "llviewerregion.h" +#include "llviewercontrol.h" // FIXME extremely hacky way to get to the UI Listener framework. There's // a cleaner way. @@ -369,433 +355,6 @@ lua_function(print_warning) } #ifndef LL_TEST -lua_function(avatar_sit) -{ - gAgent.sitDown(); - return 0; -} - -lua_function(avatar_stand) -{ - gAgent.standUp(); - return 0; -} - -lua_function(nearby_chat_send) -{ - std::string msg(lua_tostring(L, 1)); - LLFloaterIMNearbyChat *nearby_chat = LLFloaterReg::findTypedInstance<LLFloaterIMNearbyChat>("nearby_chat"); - nearby_chat->sendChatFromViewer(msg, CHAT_TYPE_NORMAL, gSavedSettings.getBOOL("PlayChatAnim")); - - lua_pop(L, 1); - return 0; -} - -lua_function(wear_by_name) -{ - std::string folder_name(lua_tostring(L, 1)); - LLAppearanceMgr::instance().wearOutfitByName(folder_name); - - lua_pop(L, 1); - return 0; -} - -lua_function(open_floater) -{ - std::string floater_name(lua_tostring(L, 1)); - - LLSD key; - if (floater_name == "profile") - { - key["id"] = gAgentID; - } - LLFloaterReg::showInstance(floater_name, key); - - lua_pop(L, 1); - return 0; -} - -lua_function(close_floater) -{ - std::string floater_name(lua_tostring(L, 1)); - - LLSD key; - if (floater_name == "profile") - { - key["id"] = gAgentID; - } - LLFloaterReg::hideInstance(floater_name, key); - - lua_pop(L, 1); - return 0; -} - -lua_function(close_all_floaters) -{ - close_all_windows(); - return 0; -} - -lua_function(click_child) -{ - 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(); - - lua_pop(L, 2); - return 0; -} - -lua_function(snapshot_to_file) -{ - std::string filename(lua_tostring(L, 1)); - - //don't take snapshot from coroutine - doOnIdleOneTime([filename]() - { - gViewerWindow->saveSnapshot(filename, - gViewerWindow->getWindowWidthRaw(), - gViewerWindow->getWindowHeightRaw(), - gSavedSettings.getBOOL("RenderUIInSnapshot"), - gSavedSettings.getBOOL("RenderHUDInSnapshot"), - FALSE, - LLSnapshotModel::SNAPSHOT_TYPE_COLOR, - LLSnapshotModel::SNAPSHOT_FORMAT_PNG); - }); - - lua_pop(L, 1); - return 0; -} - -lua_function(open_wearing_tab) -{ - LLFloaterSidePanelContainer::showPanel("appearance", LLSD().with("type", "now_wearing")); - return 0; -} - -lua_function(set_debug_setting_bool) -{ - std::string setting_name(lua_tostring(L, 1)); - bool value(lua_toboolean(L, 2)); - - gSavedSettings.setBOOL(setting_name, value); - lua_pop(L, 2); - return 0; -} - -lua_function(get_avatar_name) -{ - std::string name = gAgentAvatarp->getFullname(); - luaL_checkstack(L, 1, nullptr); - lua_pushstdstring(L, name); - return 1; -} - -lua_function(is_avatar_flying) -{ - luaL_checkstack(L, 1, nullptr); - lua_pushboolean(L, gAgent.getFlying()); - return 1; -} - -lua_function(play_animation) -{ - // on exit, pop all passed arguments, so always return 0 - LuaPopper popper(L, lua_gettop(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 0; - } - } - LL_WARNS() << "No animation found for name " << anim_name << LL_ENDL; - - return 0; -} - -lua_function(env_setting_event) -{ - handle_env_setting_event(lua_tostring(L, 1)); - lua_pop(L, 1); - return 0; -} - -void handle_notification_dialog(const LLSD ¬ification, const LLSD &response, lua_State *L, std::string response_cb) -{ - if (!response_cb.empty()) - { - S32 option = LLNotificationsUtil::getSelectedOption(notification, response); - - luaL_checkstack(L, 1, nullptr); - lua_pushinteger(L, option); - lua_setglobal(L, response_cb.c_str()); - } -} - -lua_function(show_notification) -{ - std::string notification(lua_tostring(L, 1)); - - if (lua_type(L, 2) == LUA_TTABLE) - { - LLSD args = lua_tollsd(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); - } - - lua_settop(L, 0); - return 0; -} - -lua_function(add_menu_item) -{ - std::string menu(lua_tostring(L, 1)); - if (lua_type(L, 2) == LUA_TTABLE) - { - LLSD args = lua_tollsd(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); - } - - lua_settop(L, 0); - return 0; -} - -lua_function(add_menu_separator) -{ - std::string menu(lua_tostring(L, 1)); - gMenuBarView->findChildMenuByName(menu, true)->addSeparator(); - - lua_pop(L, 1); - return 0; -} - -lua_function(add_menu) -{ - if (lua_type(L, 1) == LUA_TTABLE) - { - LLSD args = lua_tollsd(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); - } - - lua_settop(L, 0); - return 0; -} - -lua_function(add_branch) -{ - std::string menu(lua_tostring(L, 1)); - if (lua_type(L, 2) == LUA_TTABLE) - { - LLSD args = lua_tollsd(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); - } - - lua_settop(L, 0); - return 0; -} - -// rez_prim({x, y}, prim_type) -// avatar is the reference point -lua_function(rez_prim) -{ - lua_rawgeti(L, 1, 1); - F32 x = lua_tonumber(L, -1); - lua_pop(L, 1); - lua_rawgeti(L, 1, 2); - F32 y = lua_tonumber(L, -1); - lua_pop(L, 1); - - S32 type(lua_tonumber(L, 2)); // primitive shapes 1-8 - - LLVector3 obj_pos = gAgent.getPositionAgent() + LLVector3(x, y, -0.5); - bool res = LLToolPlacer::rezNewObject(type, NULL, 0, TRUE, gAgent.getPositionAgent(), obj_pos, gAgent.getRegion(), 0); - - LL_INFOS() << "Rezing a prim: type " << LLPrimitive::pCodeToString(type) << ", coordinates: " << obj_pos << " Success: " << res << LL_ENDL; - - lua_pop(L, lua_gettop(L)); - return 0; -} - -// rez_prim2({x, y,z}, prim_type) -// avatar is the reference point -lua_function(rez_prim2) -{ - luaL_checktype(L, 1, LUA_TTABLE); - S32 type(lua_tonumber(L,2)); - lua_pop(L,1); - - lua_pushinteger(L, 1); - lua_gettable(L, -2); - F32 x = lua_tonumber(L,-1); - lua_pop(L,1); - - lua_pushinteger(L, 2); - lua_gettable(L, -2); - F32 y = lua_tonumber(L,-1); - lua_pop(L,1); - - lua_pushinteger(L, 3); - lua_gettable(L, -2); - F32 z = lua_tonumber(L,-1); - lua_pop(L,1); - - LL_INFOS() << "x " << x << " y " << y << " z " << z << " type " << type << LL_ENDL; - - LLVector3 obj_pos = gAgent.getPositionAgent() + LLVector3(x, y, z); - bool res = LLToolPlacer::rezNewObject(type, NULL, 0, TRUE, gAgent.getPositionAgent(), obj_pos, gAgent.getRegion(), 0); - - LL_INFOS() << "Rezing a prim: type " << LLPrimitive::pCodeToString(type) << ", coordinates: " << obj_pos << " Success: " << res << LL_ENDL; - - lua_settop(L, 0); - return 0; -} - - -void move_to_dest(const LLVector3d &target_global, lua_State *L, std::string response_cb) -{ - struct Data - { - lua_State *L; - std::string response_cb; - }; - - Data *data = new Data(); - data->L = L; - if (!response_cb.empty()) - { - data->response_cb = response_cb; - } - - auto handle_dest_reached = [](BOOL success, void *user_data) - { - Data *cb_data = static_cast<Data *>(user_data); - if (!cb_data->response_cb.empty()) - { - S32 result = success ? 1 : -1; - lua_pushinteger(cb_data->L, result); - lua_setglobal(cb_data->L, cb_data->response_cb.c_str()); - } - }; - - gAgent.startAutoPilotGlobal(target_global, std::string(), NULL, handle_dest_reached, data, 0.f, 0.03f, FALSE); -} - -// move_by({x,y}, "lua_cb_func") -// avatar is the reference point -lua_function(move_by) -{ - lua_rawgeti(L, 1, 1); - F32 x = lua_tonumber(L, -1); - lua_pop(L, 1); - lua_rawgeti(L, 1, 2); - F32 y = lua_tonumber(L, -1); - lua_pop(L, 1); - - LLVector3d dest = gAgent.getRegion()->getPosGlobalFromRegion(gAgent.getPositionAgent() + LLVector3(x, y, 0)); - - std::string response_cb; - if (lua_type(L, 2) == LUA_TSTRING) - { - response_cb = lua_tostring(L, 2); - } - move_to_dest(dest, L, response_cb); - - lua_settop(L, 0); - return 0; -} - -// move_to({x,y,z}, "lua_cb_func") -// region coordinates are used -lua_function(move_to) -{ - lua_rawgeti(L, 1, 1); - F32 x = lua_tonumber(L, -1); - lua_pop(L, 1); - lua_rawgeti(L, 1, 2); - F32 y = lua_tonumber(L, -1); - lua_rawgeti(L, 1, 3); - F32 z = lua_tonumber(L, -1); - lua_pop(L, 1); - - LLVector3d dest = gAgent.getRegion()->getPosGlobalFromRegion(LLVector3(x, y, z)); - - std::string response_cb; - if (lua_type(L, 2) == LUA_TSTRING) - { - response_cb = lua_tostring(L, 2); - } - move_to_dest(dest, L, response_cb); - - lua_settop(L, 0); - return 0; -} lua_function(run_ui_command) { diff --git a/scripts/lua/avatar.lua b/scripts/lua/avatar.lua deleted file mode 100644 index 159014fa04..0000000000 --- a/scripts/lua/avatar.lua +++ /dev/null @@ -1,12 +0,0 @@ - run_ui_command("World.EnvSettings", "midnight")
- sleep(1)
- run_ui_command("World.EnvSettings", "noon")
- sleep(1)
- wear_by_name("* AVL")
- run_ui_command("Avatar.ResetSelfSkeletonAndAnimations")
- sleep(5)
- wear_by_name("* Elephant")
- sleep(5)
- play_animation("Elephant_Fly");
- sleep(5)
- play_animation("Elephant_Fly",1);
\ No newline at end of file diff --git a/scripts/lua/demo.lua b/scripts/lua/demo.lua deleted file mode 100644 index 90eaf667bb..0000000000 --- a/scripts/lua/demo.lua +++ /dev/null @@ -1,145 +0,0 @@ -function popup_and_wait_ok(message) - args = {MESSAGE=message} - notif_response = nil - show_notification("GenericAlertOK", args, "notif_response") - while not notif_response do - sleep(0.2) - end - - local response = notif_response - return response -end - -function demo_environment() - popup_and_wait_ok("Change Environment") - run_ui_command("World.EnvSettings", "midnight") - sleep(2) - run_ui_command("World.EnvSettings", "sunrise") - sleep(2) - run_ui_command("World.EnvSettings", "noon") - sleep(2) -end - -function demo_rez() - for x=-1,1,1 do - for y=-1,1,1 do - rez_prim2({x,y,-1},1) - end - end -end - -function demo_avatar() - popup_and_wait_ok("Change Avatar") - - local dest = {10,10,0} - move_by(dest, "autopilot_response") - while not autopilot_response do - sleep(0.2) - end - - local response = autopilot_response - - if response == 1 then - sleep(1) - demo_rez() - sleep(2) - end - - wear_by_name("Greg") - run_ui_command("Avatar.ResetSelfSkeletonAndAnimations") - sleep(8) - - wear_by_name("Petrol Sue") - sleep(8) - - run_ui_command("Self.ToggleSitStand") - sleep(2) - run_ui_command("Self.ToggleSitStand") - sleep(2) - - --run_ui_command("View.ZoomOut") - run_ui_command("EditShape") - sleep(6) - close_floater("appearance") - -end - -function demo_ui() - - - -- adding items to 'Build' menu - -- popup_and_wait_ok("Extend UI") - - popup_and_wait_ok("UI interaction") - open_floater("inventory") - open_floater("preferences") - open_floater("nearby_chat") - nearby_chat_send("Hello World!") - - sleep(5) - close_all_floaters() - - - notif_response = nil - args = {MESSAGE="Customize the UI now?"} - show_notification("GenericAlertYesCancel", args, "notif_response") - while not notif_response do - sleep(0.2) - end - if notif_response ~= 0 then - popup_and_wait_ok("Exiting") - return - end - - menu_name = "BuildTools" - add_menu_separator(menu_name) - - params = {name="user_sit", - label="Sit!"} - params["function"]="Self.ToggleSitStand" - - add_menu_item(menu_name, params) - - params = {name="user_midnight",label="Set night",parameter="midnight"} - params["function"] = "World.EnvSettings" - - add_menu_item(menu_name, params) - - -- adding new custom menu - new_menu_name = "user_menu" - params = {name=new_menu_name,label="My Secret Menu",tear_off="true"} - add_menu(params) - - -- adding new item to the new menu - params = {name="user_debug",label="Console", - parameter="debug"} - params["function"] = "Advanced.ToggleConsole" - - add_menu_item(new_menu_name, params) - - -- adding new branch - new_branch = "user_floaters" - params = {name=new_branch, label="Open Floater",tear_off="true"} - add_branch(new_menu_name, params) - - -- adding items to the branch - params = {name="user_permissions",label="Default permissions", - parameter="perms_default"} - params["function"] = "Floater.ToggleOrBringToFront" - - - add_menu_item(new_branch, params) - - params = {name="user_beacons",label="Beacons", - parameter="beacons"} - params["function"] = "Floater.ToggleOrBringToFront" - - add_menu_item(new_branch, params) - sleep(5) - -end - -demo_environment() -demo_avatar() -demo_ui() - |