1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
|
/**
* @file lloutfitgallery.cpp
* @author Pavlo Kryvych
* @brief Visual gallery of agent's outfits for My Appearance side panel
*
* $LicenseInfo:firstyear=2015&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2015, 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 "llviewerprecompiledheaders.h" // must be first include
#include "lloutfitgallery.h"
#include <boost/foreach.hpp>
// llcommon
#include "llcommonutils.h"
#include "llvfile.h"
#include "llappearancemgr.h"
#include "lleconomy.h"
#include "llerror.h"
#include "llfilepicker.h"
#include "llfloaterperms.h"
#include "llinventoryfunctions.h"
#include "llinventorymodel.h"
#include "lllocalbitmaps.h"
#include "llviewermenufile.h"
#include "llwearableitemslist.h"
static LLPanelInjector<LLOutfitGallery> t_outfit_gallery("outfit_gallery");
static LLOutfitGallery* gOutfitGallery = NULL;
LLOutfitGallery::LLOutfitGallery()
: LLOutfitListBase(),
mTexturesObserver(NULL),
mOutfitsObserver(NULL),
mScrollPanel(NULL),
mGalleryPanel(NULL),
galleryCreated(false),
mRowCount(0),
mItemsAddedCount(0),
mOutfitLinkPending(NULL)
{
}
BOOL LLOutfitGallery::postBuild()
{
BOOL rv = LLOutfitListBase::postBuild();
mScrollPanel = getChild<LLScrollContainer>("gallery_scroll_panel");
mGalleryPanel = getChild<LLPanel>("gallery_panel");
return rv;
}
void LLOutfitGallery::onOpen(const LLSD& info)
{
LLOutfitListBase::onOpen(info);
if (!galleryCreated)
{
loadPhotos();
uuid_vec_t cats;
getCurrentCategories(cats);
int n = cats.size();
buildGalleryPanel(n);
mScrollPanel->addChild(mGalleryPanel);
for (int i = 0; i < n; i++)
{
addToGallery(mOutfitMap[cats[i]]);
}
galleryCreated = true;
}
}
#define LAYOUT_STACK_HEIGHT 180
#define GALLERY_VERTICAL_GAP 10
#define GALLERY_HORIZONTAL_GAP 10
#define GALLERY_ITEM_WIDTH 150
#define GALLERY_ITEM_HEIGHT 175
#define GALLERY_ITEM_HGAP 16
#define ITEMS_IN_ROW 3
#define LAYOUT_STACK_WIDTH 166 * ITEMS_IN_ROW//498
#define GALLERY_WIDTH 163 * ITEMS_IN_ROW//485//290
LLPanel* LLOutfitGallery::addLastRow()
{
mRowCount++;
int row = 0;
int vgap = GALLERY_VERTICAL_GAP * row;
LLPanel* result = buildLayoutStak(0, row * LAYOUT_STACK_HEIGHT + vgap);
mGalleryPanel->addChild(result);
return result;
}
void LLOutfitGallery::moveRowUp(int row)
{
moveRow(row, mRowCount - 1 - row + 1);
}
void LLOutfitGallery::moveRowDown(int row)
{
moveRow(row, mRowCount - 1 - row - 1);
}
void LLOutfitGallery::moveRow(int row, int pos)
{
int vgap = GALLERY_VERTICAL_GAP * pos;
moveLayoutStak(mStacks[row], 0, pos * LAYOUT_STACK_HEIGHT + vgap);
}
void LLOutfitGallery::removeLastRow()
{
mRowCount--;
mGalleryPanel->removeChild(mLastRowStack);
mStacks.pop_back();
mLastRowStack = mStacks.back();
}
LLPanel* LLOutfitGallery::addToRow(LLPanel* row_stack, LLOutfitGalleryItem* item, int pos, int hgap)
{
LLPanel* lpanel = buildLayoutPanel(pos * GALLERY_ITEM_WIDTH + hgap);
lpanel->addChild(item);
row_stack->addChild(lpanel);
mPanels.push_back(lpanel);
return lpanel;
}
void LLOutfitGallery::addToGallery(LLOutfitGalleryItem* item)
{
mItemsAddedCount++;
mItemIndexMap[item] = mItemsAddedCount - 1;
int n = mItemsAddedCount;
int row_count = (n % ITEMS_IN_ROW) == 0 ? n / ITEMS_IN_ROW : n / ITEMS_IN_ROW + 1;
int n_prev = n - 1;
int row_count_prev = (n_prev % ITEMS_IN_ROW) == 0 ? n_prev / ITEMS_IN_ROW : n_prev / ITEMS_IN_ROW + 1;
bool add_row = row_count != row_count_prev;
int pos = 0;
if (add_row)
{
for (int i = 0; i < row_count_prev; i++)
{
moveRowUp(i);
}
mLastRowStack = addLastRow();
mStacks.push_back(mLastRowStack);
}
pos = (n - 1) % ITEMS_IN_ROW;
mItems.push_back(item);
addToRow(mLastRowStack, item, pos, GALLERY_HORIZONTAL_GAP * pos);
reshapeGalleryPanel(row_count);
}
void LLOutfitGallery::removeFromGalleryLast(LLOutfitGalleryItem* item)
{
int n_prev = mItemsAddedCount;
int n = mItemsAddedCount - 1;
int row_count = (n % ITEMS_IN_ROW) == 0 ? n / ITEMS_IN_ROW : n / ITEMS_IN_ROW + 1;
int row_count_prev = (n_prev % ITEMS_IN_ROW) == 0 ? n_prev / ITEMS_IN_ROW : n_prev / ITEMS_IN_ROW + 1;
mItemsAddedCount--;
bool remove_row = row_count != row_count_prev;
//int pos = (n_prev - 1) % ITEMS_IN_ROW;
removeFromLastRow(mItems[mItemsAddedCount]);
mItems.pop_back();
if (remove_row)
{
for (int i = 0; i < row_count_prev - 1; i++)
{
moveRowDown(i);
}
removeLastRow();
}
reshapeGalleryPanel(row_count);
}
void LLOutfitGallery::removeFromGalleryMiddle(LLOutfitGalleryItem* item)
{
int n = mItemIndexMap[item];
mItemIndexMap.erase(item);
std::vector<LLOutfitGalleryItem*> saved;
for (int i = mItemsAddedCount - 1; i > n; i--)
{
saved.push_back(mItems[i]);
removeFromGalleryLast(mItems[i]);
}
removeFromGalleryLast(mItems[n]);
int saved_count = saved.size();
for (int i = 0; i < saved_count; i++)
{
addToGallery(saved.back());
saved.pop_back();
}
}
void LLOutfitGallery::removeFromLastRow(LLOutfitGalleryItem* item)
{
mPanels.back()->removeChild(item);
mLastRowStack->removeChild(mPanels.back());
mPanels.pop_back();
}
LLOutfitGalleryItem* LLOutfitGallery::buildGalleryItem(std::string name)
{
LLOutfitGalleryItem::Params giparams;
LLOutfitGalleryItem* gitem = LLUICtrlFactory::create<LLOutfitGalleryItem>(giparams);
gitem->reshape(GALLERY_ITEM_WIDTH, GALLERY_ITEM_HEIGHT);
gitem->setVisible(true);
gitem->setFollowsLeft();
gitem->setFollowsTop();
gitem->setOutfitName(name);
return gitem;
}
void LLOutfitGallery::buildGalleryPanel(int row_count)
{
LLPanel::Params params;
mGalleryPanel = LLUICtrlFactory::create<LLPanel>(params);
reshapeGalleryPanel(row_count);
}
void LLOutfitGallery::reshapeGalleryPanel(int row_count)
{
int bottom = 0;
int left = 0;
int height = row_count * (LAYOUT_STACK_HEIGHT + GALLERY_VERTICAL_GAP);
LLRect rect = LLRect(left, bottom + height, left + GALLERY_WIDTH, bottom);
mGalleryPanel->setRect(rect);
mGalleryPanel->reshape(GALLERY_WIDTH, height);
mGalleryPanel->setVisible(true);
mGalleryPanel->setFollowsLeft();
mGalleryPanel->setFollowsTop();
}
LLPanel* LLOutfitGallery::buildLayoutPanel(int left)
{
LLPanel::Params lpparams;
int top = 0;
LLPanel* lpanel = LLUICtrlFactory::create<LLPanel>(lpparams);
LLRect rect = LLRect(left, top + GALLERY_ITEM_HEIGHT, left + GALLERY_ITEM_WIDTH + GALLERY_ITEM_HGAP, top);
lpanel->setRect(rect);
lpanel->reshape(GALLERY_ITEM_WIDTH + GALLERY_ITEM_HGAP, GALLERY_ITEM_HEIGHT);
lpanel->setVisible(true);
lpanel->setFollowsLeft();
lpanel->setFollowsTop();
return lpanel;
}
LLPanel* LLOutfitGallery::buildLayoutStak(int left, int bottom)
{
LLPanel::Params sparams;
LLPanel* stack = LLUICtrlFactory::create<LLPanel>(sparams);
moveLayoutStak(stack, left, bottom);
return stack;
}
void LLOutfitGallery::moveLayoutStak(LLPanel* stack, int left, int bottom)
{
LLRect rect = LLRect(left, bottom + LAYOUT_STACK_HEIGHT, left + LAYOUT_STACK_WIDTH, bottom);
stack->setRect(rect);
stack->reshape(LAYOUT_STACK_WIDTH, LAYOUT_STACK_HEIGHT);
stack->setVisible(true);
stack->setFollowsLeft();
stack->setFollowsTop();
}
LLOutfitGallery::~LLOutfitGallery()
{
if (gInventory.containsObserver(mTexturesObserver))
{
gInventory.removeObserver(mTexturesObserver);
}
delete mTexturesObserver;
}
void LLOutfitGallery::setFilterSubString(const std::string& string)
{
//TODO: Implement filtering
sFilterSubString = string;
}
void LLOutfitGallery::onHighlightBaseOutfit(LLUUID base_id, LLUUID prev_id)
{
if (mOutfitMap[base_id])
{
mOutfitMap[base_id]->setOutfitWorn(true);
}
if (mOutfitMap[prev_id])
{
mOutfitMap[prev_id]->setOutfitWorn(false);
}
}
void LLOutfitGallery::onSetSelectedOutfitByUUID(const LLUUID& outfit_uuid)
{
}
void LLOutfitGallery::getCurrentCategories(uuid_vec_t& vcur)
{
for (outfit_map_t::const_iterator iter = mOutfitMap.begin();
iter != mOutfitMap.end();
iter++)
{
if ((*iter).second != NULL)
{
vcur.push_back((*iter).first);
}
}
}
void LLOutfitGallery::updateAddedCategory(LLUUID cat_id)
{
LLViewerInventoryCategory *cat = gInventory.getCategory(cat_id);
if (!cat) return;
std::string name = cat->getName();
LLOutfitGalleryItem* item = buildGalleryItem(name);
mOutfitMap.insert(LLOutfitGallery::outfit_map_value_t(cat_id, item));
item->setRightMouseDownCallback(boost::bind(&LLOutfitListBase::outfitRightClickCallBack, this,
_1, _2, _3, cat_id));
LLWearableItemsList* list = NULL;
item->setFocusReceivedCallback(boost::bind(&LLOutfitListBase::ChangeOutfitSelection, this, list, cat_id));
if (galleryCreated)
{
addToGallery(item);
}
LLViewerInventoryCategory* outfit_category = gInventory.getCategory(cat_id);
if (!outfit_category)
return;
if (mOutfitsObserver == NULL)
{
mOutfitsObserver = new LLInventoryCategoriesObserver();
gInventory.addObserver(mOutfitsObserver);
}
// Start observing changes in "My Outits" category.
mOutfitsObserver->addCategory(cat_id,
boost::bind(&LLOutfitGallery::refreshOutfit, this, cat_id));
outfit_category->fetch();
refreshOutfit(cat_id);
}
void LLOutfitGallery::updateRemovedCategory(LLUUID cat_id)
{
outfit_map_t::iterator outfits_iter = mOutfitMap.find(cat_id);
if (outfits_iter != mOutfitMap.end())
{
// 0. Remove category from observer.
mOutfitsObserver->removeCategory(cat_id);
//const LLUUID& outfit_id = outfits_iter->first;
LLOutfitGalleryItem* item = outfits_iter->second;
// An outfit is removed from the list. Do the following:
// 2. Remove the outfit from selection.
//deselectOutfit(outfit_id);
// 3. Remove category UUID to accordion tab mapping.
mOutfitMap.erase(outfits_iter);
// 4. Remove outfit from gallery.
removeFromGalleryMiddle(item);
// kill removed item
if (item != NULL)
{
item->die();
}
}
}
void LLOutfitGallery::updateChangedCategoryName(LLViewerInventoryCategory *cat, std::string name)
{
outfit_map_t::iterator outfit_iter = mOutfitMap.find(cat->getUUID());
if (outfit_iter != mOutfitMap.end())
{
// Update name of outfit in gallery
LLOutfitGalleryItem* item = outfit_iter->second;
if (item)
{
item->setOutfitName(name);
}
}
}
void LLOutfitGallery::onOutfitRightClick(LLUICtrl* ctrl, S32 x, S32 y, const LLUUID& cat_id)
{
if (mOutfitMenu && cat_id.notNull())
{
uuid_vec_t selected_uuids;
selected_uuids.push_back(cat_id);
mOutfitMenu->show(ctrl, selected_uuids, x, y);
}
}
void LLOutfitGallery::onChangeOutfitSelection(LLWearableItemsList* list, const LLUUID& category_id)
{
if (mSelectedOutfitUUID == category_id)
return;
if (mOutfitMap[mSelectedOutfitUUID])
{
mOutfitMap[mSelectedOutfitUUID]->setSelected(FALSE);
}
if (mOutfitMap[category_id])
{
mOutfitMap[category_id]->setSelected(TRUE);
}
}
bool LLOutfitGallery::hasItemSelected()
{
return false;
}
bool LLOutfitGallery::canWearSelected()
{
return false;
}
LLOutfitListGearMenuBase* LLOutfitGallery::createGearMenu()
{
return new LLOutfitGalleryGearMenu(this);
}
static LLDefaultChildRegistry::Register<LLOutfitGalleryItem> r("outfit_gallery_item");
LLOutfitGalleryItem::LLOutfitGalleryItem(const Params& p)
: LLPanel(p),
mTexturep(NULL),
mSelected(false),
mWorn(false)
{
buildFromFile("panel_outfit_gallery_item.xml");
}
LLOutfitGalleryItem::~LLOutfitGalleryItem()
{
}
BOOL LLOutfitGalleryItem::postBuild()
{
setDefaultImage();
mOutfitNameText = getChild<LLTextBox>("outfit_name");
mOutfitWornText = getChild<LLTextBox>("outfit_worn_text");
mFotoBgPanel = getChild<LLPanel>("foto_bg_panel");
mTextBgPanel = getChild<LLPanel>("text_bg_panel");
setOutfitWorn(false);
return TRUE;
}
void LLOutfitGalleryItem::draw()
{
LLPanel::draw();
// Draw border
LLUIColor border_color = LLUIColorTable::instance().getColor(mSelected ? "OutfitGalleryItemSelected" : "OutfitGalleryItemUnselected", LLColor4::white);
LLRect border = getChildView("preview_outfit")->getRect();
border.mRight = border.mRight + 1;
gl_rect_2d(border, border_color.get(), FALSE);
// If the floater is focused, don't apply its alpha to the texture (STORM-677).
const F32 alpha = getTransparencyType() == TT_ACTIVE ? 1.0f : getCurrentTransparency();
if (mTexturep)
{
//if (mTexturep->getComponents() == 4)
//{
// gl_rect_2d_checkerboard(interior, alpha);
//}
// Interior
LLRect interior = border;
interior.stretch(-1);
gl_draw_scaled_image(interior.mLeft - 1, interior.mBottom, interior.getWidth(), interior.getHeight(), mTexturep, UI_VERTEX_COLOR % alpha);
// Pump the priority
mTexturep->addTextureStats((F32)(interior.getWidth() * interior.getHeight()));
}
}
void LLOutfitGalleryItem::setOutfitName(std::string name)
{
mOutfitNameText->setText(name);
}
void LLOutfitGalleryItem::setOutfitWorn(bool value)
{
mWorn = value;
//LLStringUtil::format_map_t string_args;
//std::string worn_text = getString("worn_text", string_args);
LLStringUtil::format_map_t worn_string_args;
std::string worn_string = getString("worn_string", worn_string_args);
LLUIColor text_color = LLUIColorTable::instance().getColor(mSelected ? "White" : (mWorn ? "OutfitGalleryItemWorn" : "White"), LLColor4::white);
mOutfitWornText->setReadOnlyColor(text_color.get());
mOutfitNameText->setReadOnlyColor(text_color.get());
mOutfitWornText->setValue(value ? worn_string : "");
}
void LLOutfitGalleryItem::setSelected(bool value)
{
mSelected = value;
mTextBgPanel->setBackgroundVisible(value);
setOutfitWorn(mWorn);
}
BOOL LLOutfitGalleryItem::handleMouseDown(S32 x, S32 y, MASK mask)
{
setFocus(TRUE);
return LLUICtrl::handleMouseDown(x, y, mask);
}
void LLOutfitGalleryItem::setImageAssetId(LLUUID image_asset_id)
{
mTexturep = LLViewerTextureManager::getFetchedTexture(image_asset_id);
mTexturep->setBoostLevel(LLGLTexture::BOOST_PREVIEW);
}
void LLOutfitGalleryItem::setDefaultImage()
{
/*
LLUUID imageAssetID("e417f443-a199-bac1-86b0-0530e177fb54");
mTexturep = LLViewerTextureManager::getFetchedTexture(imageAssetID);
mTexturep->setBoostLevel(LLGLTexture::BOOST_PREVIEW);
*/
mTexturep = NULL;
}
LLOutfitGalleryGearMenu::LLOutfitGalleryGearMenu(LLOutfitListBase* olist)
: LLOutfitListGearMenuBase(olist)
{
}
void LLOutfitGalleryGearMenu::onUpdateItemsVisibility()
{
if (!mMenu) return;
mMenu->setItemVisible("expand", FALSE);
mMenu->setItemVisible("collapse", FALSE);
mMenu->setItemVisible("upload_photo", TRUE);
mMenu->setItemVisible("load_assets", TRUE);
LLOutfitListGearMenuBase::onUpdateItemsVisibility();
}
void LLOutfitGalleryGearMenu::onUploadFoto()
{
LLUUID selected_outfit_id = getSelectedOutfitID();
LLOutfitGallery* gallery = dynamic_cast<LLOutfitGallery*>(mOutfitList);
if (gallery && selected_outfit_id.notNull())
{
gallery->uploadPhoto(selected_outfit_id);
}
}
void LLOutfitGalleryGearMenu::onLoadAssets()
{
LLOutfitGallery* gallery = dynamic_cast<LLOutfitGallery*>(mOutfitList);
if (gallery != NULL)
{
gallery->loadPhotos();
}
}
void LLOutfitGallery::loadPhotos()
{
//Iterate over inventory
LLUUID textures = gInventory.findCategoryUUIDForType(LLFolderType::FT_TEXTURE);
LLViewerInventoryCategory* textures_category = gInventory.getCategory(textures);
if (!textures_category)
return;
if (mTexturesObserver == NULL)
{
mTexturesObserver = new LLInventoryCategoriesObserver();
gInventory.addObserver(mTexturesObserver);
}
// Start observing changes in "Textures" category.
mTexturesObserver->addCategory(textures,
boost::bind(&LLOutfitGallery::refreshTextures, this, textures));
textures_category->fetch();
}
void LLOutfitGallery::refreshOutfit(const LLUUID& category_id)
{
LLViewerInventoryCategory* category = gInventory.getCategory(category_id);
{
bool photo_loaded = false;
LLInventoryModel::cat_array_t sub_cat_array;
LLInventoryModel::item_array_t outfit_item_array;
// Collect all sub-categories of a given category.
gInventory.collectDescendents(
category->getUUID(),
sub_cat_array,
outfit_item_array,
LLInventoryModel::EXCLUDE_TRASH);
BOOST_FOREACH(LLViewerInventoryItem* outfit_item, outfit_item_array)
{
LLViewerInventoryItem* linked_item = outfit_item->getLinkedItem();
if (linked_item->getActualType() == LLAssetType::AT_TEXTURE)
{
LLUUID asset_id = linked_item->getAssetUUID();
mOutfitMap[category_id]->setImageAssetId(asset_id);
photo_loaded = true;
break;
}
if (!photo_loaded)
{
mOutfitMap[category_id]->setDefaultImage();
}
}
}
}
void LLOutfitGallery::refreshTextures(const LLUUID& category_id)
{
LLInventoryModel::cat_array_t cat_array;
LLInventoryModel::item_array_t item_array;
// Collect all sub-categories of a given category.
LLIsType is_texture(LLAssetType::AT_TEXTURE);
gInventory.collectDescendentsIf(
category_id,
cat_array,
item_array,
LLInventoryModel::EXCLUDE_TRASH,
is_texture);
//Find texture which contain outfit ID string in name
LLViewerInventoryItem* photo_upload_item = NULL;
BOOST_FOREACH(LLViewerInventoryItem* item, item_array)
{
std::string name = item->getName();
if (!mOutfitLinkPending.isNull() && name == mOutfitLinkPending.asString())
{
photo_upload_item = item;
break;
}
}
if (photo_upload_item != NULL)
{
LLUUID upload_pending_id = photo_upload_item->getUUID();
LLInventoryObject* upload_object = gInventory.getObject(upload_pending_id);
if (!upload_object)
{
LL_WARNS() << "LLOutfitGallery::refreshTextures added_object is null!" << LL_ENDL;
}
else
{
LLViewerInventoryCategory *outfit_cat = gInventory.getCategory(mOutfitLinkPending);
linkPhotoToOutfit(upload_pending_id, mOutfitLinkPending);
LLStringUtil::format_map_t photo_string_args;
photo_string_args["OUTFIT_NAME"] = outfit_cat->getName();
std::string new_name = getString("outfit_photo_string", photo_string_args);
LLSD updates;
updates["name"] = new_name;
update_inventory_item(upload_pending_id, updates, NULL);
}
mOutfitLinkPending.setNull();
}
}
void LLOutfitGallery::onLoadComplete(LLVFS *vfs, const LLUUID& asset_uuid, LLAssetType::EType type, void* user_data, S32 status, LLExtStat ext_status)
{
LL_WARNS() << "asset_uuid: " << asset_uuid.asString() << LL_ENDL;
LLUUID* outfit_id = (LLUUID*)user_data;
if (!user_data)
return;
LL_WARNS() << "outfit_id: " << outfit_id->asString() << LL_ENDL;
outfit_map_t::iterator it = gOutfitGallery->mOutfitMap.find(*outfit_id);
if (it != gOutfitGallery->mOutfitMap.end() && !it->first.isNull())
{
}
}
void LLGalleryPhotoStoreCallback(const LLUUID &asset_id, void *user_data, S32 status, LLExtStat ext_status)
{
LL_WARNS() << "Photo stored as asset. UUID:" << asset_id.asString() << LL_ENDL;
}
void LLOutfitGallery::uploadPhoto(LLUUID outfit_id)
{
outfit_map_t::iterator outfit_it = mOutfitMap.find(outfit_id);
if (outfit_it == mOutfitMap.end() || outfit_it->first.isNull())
{
return;
}
LLFilePicker& picker = LLFilePicker::instance();
if (picker.getOpenFile(LLFilePicker::FFLOAD_IMAGE))
{
std::string filename = picker.getFirstFile();
LLLocalBitmap* unit = new LLLocalBitmap(filename);
if (unit->getValid())
{
S32 expected_upload_cost = LLGlobalEconomy::Singleton::getInstance()->getPriceUpload(); // kinda hack - assumes that unsubclassed LLFloaterNameDesc is only used for uploading chargeable assets, which it is right now (it's only used unsubclassed for the sound upload dialog, and THAT should be a subclass).
void *nruserdata = NULL;
nruserdata = (void *)&outfit_id;
LLViewerInventoryCategory *outfit_cat = gInventory.getCategory(outfit_id);
if (!outfit_cat) return;
checkRemovePhoto(outfit_id);
std::string upload_pending_name = outfit_id.asString();
LLUUID photo_id = upload_new_resource(filename, // file
upload_pending_name,
outfit_id.asString(),
0, LLFolderType::FT_NONE, LLInventoryType::IT_NONE,
LLFloaterPerms::getNextOwnerPerms("Uploads"),
LLFloaterPerms::getGroupPerms("Uploads"),
LLFloaterPerms::getEveryonePerms("Uploads"),
upload_pending_name, &LLGalleryPhotoStoreCallback, expected_upload_cost, nruserdata);
mOutfitLinkPending = outfit_id;
}
}
}
void LLOutfitGallery::linkPhotoToOutfit(LLUUID photo_id, LLUUID outfit_id)
{
LLPointer<LLInventoryCallback> cb = new LLUpdateGalleryOnPhotoUpload();
link_inventory_object(outfit_id, photo_id, cb);
}
bool LLOutfitGallery::checkRemovePhoto(LLUUID outfit_id)
{
//remove existing photo of outfit from inventory
texture_map_t::iterator texture_it = mTextureMap.find(outfit_id);
if (texture_it != mTextureMap.end()) {
gInventory.removeItem(texture_it->second->getUUID());
return true;
}
return false;
}
void LLOutfitGallery::setUploadedPhoto(LLUUID outfit_id, LLUUID asset_id)
{
}
void LLOutfitGallery::computeDifferenceOfTextures(
const LLInventoryModel::item_array_t& vtextures,
uuid_vec_t& vadded,
uuid_vec_t& vremoved)
{
uuid_vec_t vnew;
// Creating a vector of newly collected texture UUIDs.
for (LLInventoryModel::item_array_t::const_iterator iter = vtextures.begin();
iter != vtextures.end();
iter++)
{
vnew.push_back((*iter)->getUUID());
}
uuid_vec_t vcur;
// Creating a vector of currently uploaded texture UUIDs.
for (texture_map_t::const_iterator iter = mTextureMap.begin();
iter != mTextureMap.end();
iter++)
{
vcur.push_back((*iter).second->getUUID());
}
// getCurrentCategories(vcur);
LLCommonUtils::computeDifference(vnew, vcur, vadded, vremoved);
}
|