diff options
Diffstat (limited to 'indra')
-rw-r--r-- | indra/llui/llluafloater.cpp | 31 | ||||
-rw-r--r-- | indra/newview/llappearancelistener.cpp | 50 | ||||
-rw-r--r-- | indra/newview/llappearancelistener.h | 3 | ||||
-rw-r--r-- | indra/newview/llwearableitemslist.cpp | 13 | ||||
-rw-r--r-- | indra/newview/llwearableitemslist.h | 9 | ||||
-rw-r--r-- | indra/newview/scripts/lua/luafloater_outfits_list.xml | 36 | ||||
-rw-r--r-- | indra/newview/scripts/lua/require/LLAppearance.lua (renamed from indra/newview/scripts/lua/LLAppearance.lua) | 12 | ||||
-rw-r--r-- | indra/newview/scripts/lua/test_outfits_list.lua | 93 |
8 files changed, 225 insertions, 22 deletions
diff --git a/indra/llui/llluafloater.cpp b/indra/llui/llluafloater.cpp index e584a67a00..b08508bf9b 100644 --- a/indra/llui/llluafloater.cpp +++ b/indra/llui/llluafloater.cpp @@ -101,6 +101,15 @@ LLLuaFloater::LLLuaFloater(const LLSD &key) : } }, requiredParams); + mDispatchListener.add("clear_list", "", [this](const LLSD &event) + { + LLScrollListCtrl *ctrl = getChild<LLScrollListCtrl>(event["ctrl_name"].asString()); + if(ctrl) + { + ctrl->deleteAllItems(); + } + }, llsd::map("ctrl_name", LLSD())); + mDispatchListener.add("add_text", "", [this](const LLSD &event) { LLTextEditor *editor = getChild<LLTextEditor>(event["ctrl_name"].asString()); @@ -111,15 +120,35 @@ LLLuaFloater::LLLuaFloater(const LLSD &key) : } }, requiredParams); + mDispatchListener.add("set_label", "", [this](const LLSD &event) + { + LLButton *btn = getChild<LLButton>(event["ctrl_name"].asString()); + if (btn) + { + btn->setLabel((event["value"]).asString()); + } + }, requiredParams); + mDispatchListener.add("set_title", "", [this](const LLSD &event) { setTitle(event["value"].asString()); }, llsd::map("value", LLSD())); - + 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())); + + mDispatchListener.add("get_selected_id", "", [this](const LLSD &event) + { + LLScrollListCtrl *ctrl = getChild<LLScrollListCtrl>(event["ctrl_name"].asString()); + if (!ctrl) + { + LL_WARNS("LuaFloater") << "Control not found: " << event["ctrl_name"] << LL_ENDL; + return LLSD(); + } + return llsd::map("value", ctrl->getCurrentID()); + }, llsd::map("ctrl_name", LLSD(), "reqid", LLSD())); } LLLuaFloater::~LLLuaFloater() diff --git a/indra/newview/llappearancelistener.cpp b/indra/newview/llappearancelistener.cpp index 2d5ff6bee4..11037a0078 100644 --- a/indra/newview/llappearancelistener.cpp +++ b/indra/newview/llappearancelistener.cpp @@ -30,6 +30,7 @@ #include "llappearancemgr.h" #include "llinventoryfunctions.h" #include "stringize.h" +#include "llwearableitemslist.h" LLAppearanceListener::LLAppearanceListener() : LLEventAPI("LLAppearance", @@ -49,9 +50,23 @@ LLAppearanceListener::LLAppearanceListener() &LLAppearanceListener::wearOutfitByName, llsd::map("folder_name", LLSD(), "append", LLSD())); + add("wearItem", + "Wear item by item id: [item_id]", + &LLAppearanceListener::wearItem, + llsd::map("item_id", LLSD(), "replace", LLSD())); + + add("detachItem", + "Detach item by item id: [item_id]", + &LLAppearanceListener::detachItem, + llsd::map("item_id", LLSD())); + add("getOutfitsList", - "Return the table of Outfits(id and name) which are send to the script", + "Return the table with Outfits info(id and name)", &LLAppearanceListener::getOutfitsList); + + add("getOutfitItems", + "Return the table of items(id and name) inside specified outfit folder", + &LLAppearanceListener::getOutfitItems); } @@ -90,6 +105,16 @@ void LLAppearanceListener::wearOutfitByName(LLSD const &data) } } +void LLAppearanceListener::wearItem(LLSD const &data) +{ + LLAppearanceMgr::instance().wearItemOnAvatar(data["item_id"].asUUID(), true, data["replace"].asBoolean()); +} + +void LLAppearanceListener::detachItem(LLSD const &data) +{ + LLAppearanceMgr::instance().removeItemFromAvatar(data["item_id"].asUUID()); +} + void LLAppearanceListener::getOutfitsList(LLSD const &data) { Response response(LLSD(), data); @@ -108,3 +133,26 @@ void LLAppearanceListener::getOutfitsList(LLSD const &data) } response["outfits"] = outfits_data; } + +void LLAppearanceListener::getOutfitItems(LLSD const &data) +{ + Response response(LLSD(), data); + LLUUID outfit_id(data["outfit_id"].asUUID()); + LLViewerInventoryCategory *cat = gInventory.getCategory(outfit_id); + if (!cat || cat->getPreferredType() != LLFolderType::FT_OUTFIT) + { + response.error(stringize("Can't find outfit folder with id: ", outfit_id.asString())); + } + LLInventoryModel::cat_array_t cat_array; + LLInventoryModel::item_array_t item_array; + + gInventory.collectDescendentsIf(outfit_id, cat_array, item_array, LLInventoryModel::EXCLUDE_TRASH, LLFindOutfitItems()); + + LLSD items_data; + for (const LLPointer<LLViewerInventoryItem> &it : item_array) + { + items_data[it->getUUID().asString()] = it->getName(); + } + + response["items"] = items_data; +} diff --git a/indra/newview/llappearancelistener.h b/indra/newview/llappearancelistener.h index 8448b2ede9..00553c072f 100644 --- a/indra/newview/llappearancelistener.h +++ b/indra/newview/llappearancelistener.h @@ -37,7 +37,10 @@ public: private: void wearOutfit(LLSD const &data); void wearOutfitByName(LLSD const &data); + void wearItem(LLSD const &data); + void detachItem(LLSD const &data); void getOutfitsList(LLSD const &data); + void getOutfitItems(LLSD const &data); }; #endif // LL_LLAPPEARANCELISTENER_H diff --git a/indra/newview/llwearableitemslist.cpp b/indra/newview/llwearableitemslist.cpp index 676164fcc6..e122cc0360 100644 --- a/indra/newview/llwearableitemslist.cpp +++ b/indra/newview/llwearableitemslist.cpp @@ -33,7 +33,6 @@ #include "llagentwearables.h" #include "llappearancemgr.h" -#include "llinventoryfunctions.h" #include "llinventoryicon.h" #include "llgesturemgr.h" #include "lltransutil.h" @@ -41,14 +40,6 @@ #include "llviewermenu.h" #include "llvoavatarself.h" -class LLFindOutfitItems : public LLInventoryCollectFunctor -{ -public: - LLFindOutfitItems() {} - virtual ~LLFindOutfitItems() {} - virtual bool operator()(LLInventoryCategory* cat, - LLInventoryItem* item); -}; bool LLFindOutfitItems::operator()(LLInventoryCategory* cat, LLInventoryItem* item) @@ -60,10 +51,10 @@ bool LLFindOutfitItems::operator()(LLInventoryCategory* cat, || (item->getType() == LLAssetType::AT_OBJECT) || (item->getType() == LLAssetType::AT_GESTURE)) { - return TRUE; + return true; } } - return FALSE; + return false; } ////////////////////////////////////////////////////////////////////////// diff --git a/indra/newview/llwearableitemslist.h b/indra/newview/llwearableitemslist.h index 80e211ad6b..a24679961f 100644 --- a/indra/newview/llwearableitemslist.h +++ b/indra/newview/llwearableitemslist.h @@ -32,6 +32,7 @@ #include "llsingleton.h" // newview +#include "llinventoryfunctions.h" #include "llinventoryitemslist.h" #include "llinventorylistitem.h" #include "lllistcontextmenu.h" @@ -505,4 +506,12 @@ protected: LLWearableType::EType mMenuWearableType; }; +class LLFindOutfitItems : public LLInventoryCollectFunctor +{ + public: + LLFindOutfitItems() {} + virtual ~LLFindOutfitItems() {} + virtual bool operator()(LLInventoryCategory *cat, LLInventoryItem *item); +}; + #endif //LL_LLWEARABLEITEMSLIST_H diff --git a/indra/newview/scripts/lua/luafloater_outfits_list.xml b/indra/newview/scripts/lua/luafloater_outfits_list.xml index 1f6505cb8d..8cab864308 100644 --- a/indra/newview/scripts/lua/luafloater_outfits_list.xml +++ b/indra/newview/scripts/lua/luafloater_outfits_list.xml @@ -1,15 +1,15 @@ <?xml version="1.0" encoding="utf-8" standalone="yes" ?> <floater legacy_header_height="18" - height="185" + height="205" layout="topleft" name="lua_outfits" title="Outfits" - width="320"> + width="325"> <scroll_list draw_heading="false" left="5" - width="310" + width="315" height="150" top_pad ="25" follows="all" @@ -18,4 +18,34 @@ name="outfit_name" label="Name"/> </scroll_list> + <button + follows="left|bottom" + height="23" + label="Replace COF" + layout="topleft" + name="replace_btn" + enabled="false" + top_pad="5" + width="95" > + </button> + <button + follows="left|bottom" + height="23" + label="Add to COF" + left_pad="7" + layout="topleft" + name="add_btn" + enabled="false" + width="95" > + </button> + <button + follows="left|bottom" + height="23" + label="Show wearables" + left_pad="7" + layout="topleft" + name="select_btn" + enabled="false" + width="111" > + </button> </floater> diff --git a/indra/newview/scripts/lua/LLAppearance.lua b/indra/newview/scripts/lua/require/LLAppearance.lua index ec7a25197f..165bb6d06f 100644 --- a/indra/newview/scripts/lua/LLAppearance.lua +++ b/indra/newview/scripts/lua/require/LLAppearance.lua @@ -18,8 +18,20 @@ function LLAppearance.replaceOutfitByName(folder) leap.request('LLAppearance', {op='wearOutfitByName', append = false, folder_name=folder}) end +function LLAppearance.wearItem(item_id, replace) + leap.send('LLAppearance', {op='wearItem', replace = replace, item_id=item_id}) +end + +function LLAppearance.detachItem(item_id) + leap.send('LLAppearance', {op='detachItem', item_id=item_id}) +end + function LLAppearance.getOutfitsList() return leap.request('LLAppearance', {op='getOutfitsList'})['outfits'] end +function LLAppearance.getOutfitItems(id) + return leap.request('LLAppearance', {op='getOutfitItems', outfit_id = id})['items'] +end + return LLAppearance diff --git a/indra/newview/scripts/lua/test_outfits_list.lua b/indra/newview/scripts/lua/test_outfits_list.lua index 5875fd51da..dd5f914402 100644 --- a/indra/newview/scripts/lua/test_outfits_list.lua +++ b/indra/newview/scripts/lua/test_outfits_list.lua @@ -1,26 +1,107 @@ local Floater = require 'Floater' local LLAppearance = require 'LLAppearance' local startup = require 'startup' +local inspect = require 'inspect' + +local SHOW_OUTFITS = true +local SELECTED_OUTFIT_ID = {} +local DATA_MAP = {} + +local wearables_lbl = 'Show wearables' +local outfits_lbl = 'Show outfits' +local replace_cof_lbl = 'Replace COF' +local add_cof_lbl = 'Add to COF' +local outfits_title = 'Outfits' +local wear_lbl = 'Wear item' +local detach_lbl = 'Detach item' local flt = Floater:new( "luafloater_outfits_list.xml", {outfits_list = {"double_click"}}) -function flt:post_build(event_data) - local outfits_map = LLAppearance.getOutfitsList() +function get_selected_id() + return flt:request({action="get_selected_id", ctrl_name='outfits_list'}).value +end + +function populate_list() + if SHOW_OUTFITS then + DATA_MAP = LLAppearance.getOutfitsList() + else + DATA_MAP = LLAppearance.getOutfitItems(SELECTED_OUTFIT_ID) + end + local action_data = {} action_data.action = "add_list_element" action_data.ctrl_name = "outfits_list" local outfits = {} - for uuid, name in pairs(outfits_map) do + for uuid, name in pairs(DATA_MAP) do table.insert(outfits, {value = uuid, columns={column = "outfit_name", value = name}}) end action_data.value = outfits - self:post(action_data) + flt:post(action_data) +end + +function set_label(btn_name, value) + flt:post({action="set_label", ctrl_name=btn_name, value=value}) +end + +function set_enabled(btn_name, value) + flt:post({action="set_enabled", ctrl_name=btn_name, value=value}) +end + +function update_labels() + if SHOW_OUTFITS then + set_label('select_btn', wearables_lbl) + set_label('replace_btn', replace_cof_lbl) + set_label('add_btn', add_cof_lbl) + + set_enabled('select_btn', false) + flt:post({action="set_title", value=outfits_title}) + else + set_label('select_btn', outfits_lbl) + set_label('replace_btn', wear_lbl) + set_label('add_btn', detach_lbl) + + set_enabled('select_btn', true) + flt:post({action="set_title", value=DATA_MAP[SELECTED_OUTFIT_ID]}) + end + + set_enabled('replace_btn', false) + set_enabled('add_btn', false) +end + +function flt:post_build(event_data) + populate_list() +end + +function flt:commit_replace_btn(event_data) + if SHOW_OUTFITS then + LLAppearance.replaceOutfit(get_selected_id()) + else + LLAppearance.wearItem(get_selected_id(), false) + end +end + +function flt:commit_add_btn(event_data) + if SHOW_OUTFITS then + LLAppearance.addOutfit(get_selected_id()) + else + LLAppearance.detachItem(get_selected_id()) + end +end + +function flt:commit_select_btn(event_data) + SHOW_OUTFITS = not SHOW_OUTFITS + SELECTED_OUTFIT_ID = get_selected_id() + update_labels() + self:post({action="clear_list", ctrl_name='outfits_list'}) + populate_list() end -function flt:double_click_outfits_list(event_data) - LLAppearance.replaceOutfit(event_data.value) +function flt:commit_outfits_list(event_data) + set_enabled('replace_btn', true) + set_enabled('add_btn', true) + set_enabled('select_btn', true) end startup.wait('STATE_STARTED') |