From eb6d24e531aa5faa251b7aaf8b13c62f06708696 Mon Sep 17 00:00:00 2001 From: Mnikolenko Productengine Date: Tue, 25 Jun 2024 14:51:53 +0300 Subject: Add wear/detach actions to Appearance listener; update example script --- indra/newview/scripts/lua/LLAppearance.lua | 25 ------ .../scripts/lua/luafloater_outfits_list.xml | 36 ++++++++- indra/newview/scripts/lua/require/LLAppearance.lua | 37 +++++++++ indra/newview/scripts/lua/test_outfits_list.lua | 93 ++++++++++++++++++++-- 4 files changed, 157 insertions(+), 34 deletions(-) delete mode 100644 indra/newview/scripts/lua/LLAppearance.lua create mode 100644 indra/newview/scripts/lua/require/LLAppearance.lua (limited to 'indra/newview/scripts') diff --git a/indra/newview/scripts/lua/LLAppearance.lua b/indra/newview/scripts/lua/LLAppearance.lua deleted file mode 100644 index ec7a25197f..0000000000 --- a/indra/newview/scripts/lua/LLAppearance.lua +++ /dev/null @@ -1,25 +0,0 @@ -leap = require 'leap' - -local LLAppearance = {} - -function LLAppearance.addOutfit(folder) - leap.request('LLAppearance', {op='wearOutfit', append = true, folder_id=folder}) -end - -function LLAppearance.replaceOutfit(folder) - leap.request('LLAppearance', {op='wearOutfit', append = false, folder_id=folder}) -end - -function LLAppearance.addOutfitByName(folder) - leap.request('LLAppearance', {op='wearOutfitByName', append = true, folder_name=folder}) -end - -function LLAppearance.replaceOutfitByName(folder) - leap.request('LLAppearance', {op='wearOutfitByName', append = false, folder_name=folder}) -end - -function LLAppearance.getOutfitsList() - return leap.request('LLAppearance', {op='getOutfitsList'})['outfits'] -end - -return LLAppearance 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 @@ + width="325"> + + + diff --git a/indra/newview/scripts/lua/require/LLAppearance.lua b/indra/newview/scripts/lua/require/LLAppearance.lua new file mode 100644 index 0000000000..165bb6d06f --- /dev/null +++ b/indra/newview/scripts/lua/require/LLAppearance.lua @@ -0,0 +1,37 @@ +leap = require 'leap' + +local LLAppearance = {} + +function LLAppearance.addOutfit(folder) + leap.request('LLAppearance', {op='wearOutfit', append = true, folder_id=folder}) +end + +function LLAppearance.replaceOutfit(folder) + leap.request('LLAppearance', {op='wearOutfit', append = false, folder_id=folder}) +end + +function LLAppearance.addOutfitByName(folder) + leap.request('LLAppearance', {op='wearOutfitByName', append = true, folder_name=folder}) +end + +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') -- cgit v1.2.3