20 [
Attribute(
"true", UIWidgets.CheckBox,
"Enables the sorting header")]
23 [
Attribute(
"true", UIWidgets.CheckBox,
"Enabled the filter panel functionality")]
26 [
Attribute(
"true", UIWidgets.CheckBox,
"Enables opening details menu of currently selected tile.")]
35 protected const ResourceName
LAYOUT_GRID_TILE =
"{67B0EFBDF7EAFF27}UI/layouts/Menus/ContentBrowser/Tile/WorkshopTile.layout";
114 fp.ResetToDefaultValues();
116 SCR_FilterEntry filterEntry = filterSet.FindFilterCategory(
"state").FindFilter(
"enabled");
117 filterEntry.SetSelected(
true);
118 fp.SelectFilter(filterEntry,
true, invokeOnChanged:
false);
125 super.OnTabCreate(menuRoot, buttonsLayout,
index);
133 m_Widgets.m_FilterPanelComponent.TryLoad();
174 m_NavFilter = CreateNavigationButton(
"MenuFilter",
"#AR-Editor_ContentBrowser_ButtonOpenFilter",
false);
177 m_NavEnable = CreateNavigationButton(
"MenuEnable",
"#AR-Workshop_ButtonEnable",
true);
179 m_NavPrimary = CreateNavigationButton(
"MenuSelectHold",
"#AR-Workshop_ButtonDownload",
true);
187 GetGame().GetInputManager().AddActionListener(
"MouseWheel", EActionTrigger.VALUE,
OnScrollPage);
258 if (connectedNew != connectedOld)
261 ContentBrowserUI._print(
"Connected");
263 ContentBrowserUI._print(
"Disconnected");
280 super.OnMenuFocusGained();
303 WorkshopItem.SetThumbnailGridScale(imageWidth);
343 m_Widgets.m_AddonDetailsPanelComponent.SetWorkshopItem(
null);
411 #ifdef WORKSHOP_DEBUG
440 string orderBy =
"name";
441 string currentSortingItem =
m_Widgets.m_SortingHeaderComponent.GetSortElementName();
442 bool sortAscending =
m_Widgets.m_SortingHeaderComponent.GetSortOrderAscending();
444 const string orderAsc =
"asc";
445 const string orderDesc =
"desc";
447 switch (currentSortingItem)
450 orderBy =
"popularity";
453 orderBy =
"averageRating";
455 case "recently_added":
456 orderBy =
"createdAt";
457 sortAscending = !sortAscending;
463 orderBy =
"subscriberCount";
467 string orderDirection = orderAsc;
469 orderDirection = orderDesc;
471 p.StoreString(
"orderBy", orderBy);
472 p.StoreString(
"orderDirection", orderDirection);
475 string searchStr =
m_Widgets.m_FilterPanelComponent.GetWidgets().m_FilterSearchComponent.GetValue();
476 if (!searchStr.IsEmpty() && !defaultValues)
478 p.StoreString(
"search", searchStr);
488 if (filterFav.GetSelected(defaultValues))
489 p.StoreBoolean(
"favorited",
true);
492 else if (filterRated.GetSelected(defaultValues))
494 p.StartObject(
"averageRating");
495 p.StoreFloat(
"gt", 0.75);
496 p.StoreFloat(
"lt", 1);
503 array<ref array<string>> tagArraysInclude = {};
504 array<string> tagsExclude = {};
508 if (typeCategory.GetAnySelected() && !defaultValues)
510 array<string> typeTags = {};
513 if (filter.GetSelected(defaultValues))
514 typeTags.Insert(filter.m_sInternalName);
516 tagArraysInclude.Insert(typeTags);
521 if (!testFilter.GetSelected(defaultValues))
522 tagsExclude.Insert(testFilter.m_sInternalName);
525 if (!tagArraysInclude.IsEmpty() || !tagsExclude.IsEmpty())
527 p.StartObject(
"tags");
529 if (!tagArraysInclude.IsEmpty())
531 p.StartArray(
"include");
533 foreach (array<string> tagArray : tagArraysInclude)
536 foreach (
string tag : tagArray)
546 if (!tagsExclude.IsEmpty())
548 p.StartArray(
"exclude");
549 foreach (
string tag : tagsExclude)
563 p.StoreBoolean(
"reported", reportedFilter.GetSelected(defaultValues));
564 p.StoreBoolean(
"hidden", reportedFilter.GetSelected(defaultValues));
597 array<WorkshopItem> rawWorkshopItems = {};
601 if (rawWorkshopItems.IsEmpty())
609 array<ref SCR_WorkshopItem> itemsUnfiltered = {};
610 foreach (WorkshopItem i : rawWorkshopItems)
613 itemsUnfiltered.Insert(itemRegistered);
620 if (itemsFiltered.IsEmpty())
628 array<SCR_WorkshopItem> itemsSortedWeakPtrs = {};
631 itemsSortedWeakPtrs.Insert(i);
634 bool sortOrder = !
m_Widgets.m_SortingHeaderComponent.GetSortOrderAscending();
635 string currentSortingItem =
m_Widgets.m_SortingHeaderComponent.GetSortElementName();
636 if (currentSortingItem.IsEmpty())
638 currentSortingItem =
"name";
642 switch (currentSortingItem)
645 SCR_Sorting<SCR_WorkshopItem, SCR_CompareWorkshopItemName>.HeapSort(itemsSortedWeakPtrs, sortOrder);
647 case "time_since_played":
648 SCR_Sorting<SCR_WorkshopItem, SCR_CompareWorkshopItemTimeSinceLastPlay>.HeapSort(itemsSortedWeakPtrs, sortOrder);
650 case "time_since_downloaded":
651 SCR_Sorting<SCR_WorkshopItem, SCR_CompareWorkshopItemTimeSinceFirstDownload>.HeapSort(itemsSortedWeakPtrs, sortOrder);
655 array<ref SCR_WorkshopItem> itemsSorted = {};
658 itemsSorted.Insert(i);
666 array<ref SCR_WorkshopItem> itemsAtPage =
SelectItemsAtPage(itemsSorted, pageId);
692 GridSlot.SetRow(w, rowId);
693 GridSlot.SetColumn(w, colId);
697 comp.SetWorkshopItem(
null);
713 comp.SetWorkshopItem(
null);
725 for (
int i = 0; i < nItems; i++)
728 comp.SetWorkshopItem(items[i]);
733 void SetPanelsMode(
bool showEmptyPanel,
bool forceFiltersList =
false,
string messagePresetTag =
string.Empty,
bool animateFiltersList =
false)
738 m_Widgets.m_EmptyPanel.SetVisible(showEmptyPanel);
739 m_Widgets.m_FilterPanel.SetVisible(!showEmptyPanel);
740 m_Widgets.m_LeftPanelArea.SetVisible(!showEmptyPanel);
743 m_Widgets.m_EmptyPanelMessage.SetVisible(!messagePresetTag.IsEmpty());
744 m_Widgets.m_MainPanelMessage.SetVisible(!messagePresetTag.IsEmpty());
747 if (!messagePresetTag.IsEmpty())
750 m_Widgets.m_EmptyPanelMessageComponent.SetContentFromPreset(messagePresetTag);
752 m_Widgets.m_MainPanelMessageComponent.SetContentFromPreset(messagePresetTag);
756 if (forceFiltersList)
758 m_Widgets.m_FilterPanelComponent.ShowFilterListBox(
true, animateFiltersList);
759 if (!
m_Widgets.m_FilterPanelComponent.GetFocused())
768 array<ref SCR_WorkshopItem>
SearchItems(array<ref SCR_WorkshopItem> items,
string searchStr)
770 array<ref SCR_WorkshopItem> itemsOut = {};
772 if (searchStr.IsEmpty())
782 string searchStrLower = searchStr;
783 searchStrLower.ToLower();
788 string nameLower = i.GetName();
790 if (nameLower.Contains(searchStrLower))
797 string authorNameLower = i.GetName();
798 authorNameLower.ToLower();
799 if (authorNameLower.Contains(searchStrLower))
806 string descriptionLower = i.GetDescription();
807 descriptionLower.ToLower();
808 if (descriptionLower.Contains(searchStrLower))
815 array<WorkshopTag> tags = {};
816 i.GetWorkshopItem().GetTags(tags);
817 bool foundTag =
false;
818 foreach (WorkshopTag tag : tags)
820 string tagNameLower = tag.Name();
821 tagNameLower.ToLower();
822 if (tagNameLower == searchStrLower)
846 string searchStr =
m_Widgets.m_FilterPanelComponent.GetEditBoxSearch().GetValue();
848 array<ref SCR_WorkshopItem> items =
SearchItems(itemsIn, searchStr);
854 array<ref array<ref SCR_WorkshopItem>> arraysFromCategories = {};
860 if (filterAll.GetSelected())
861 arraysFromCategories.Insert(items);
862 else if (filterFav.GetSelected())
866 array<WorkshopTag> selectedWorkshopTags = {};
871 if (filterEntryTag && filterEntryTag.GetSelected())
872 selectedWorkshopTags.Insert(filterEntryTag.GetWorkshopTag());
875 if (!selectedWorkshopTags.IsEmpty() && selectedWorkshopTags.Count() != catType.GetFilters().Count())
877 array<ref SCR_WorkshopItem> itemsFilteredByTags = {};
880 if (item.GetWorkshopItem().HasAnyTag(selectedWorkshopTags))
881 itemsFilteredByTags.Insert(item);
883 arraysFromCategories.Insert(itemsFilteredByTags);
891 if (catState.GetAllSelected() || catState.GetAllDeselected())
892 arraysFromCategories.Insert(items);
896 if (catState.FindFilter(
"enabled").GetSelected())
898 if (catState.FindFilter(
"disabled").GetSelected())
902 arraysFromCategories.Insert(queryResult);
907 if (catCondition.GetAllSelected() || catCondition.GetAllDeselected())
908 arraysFromCategories.Insert(items);
912 if (catCondition.FindFilter(
"ready").GetSelected())
914 if (catCondition.FindFilter(
"update_available").GetSelected())
916 if (catCondition.FindFilter(
"repair_required").GetSelected())
920 arraysFromCategories.Insert(queryResult);
933 array<ref SCR_WorkshopItem> result = {};
936 if (arrays.IsEmpty())
940 if (arrays.Count() == 1)
942 int count = arrays[0].Count();
943 result.Resize(count);
944 for (
int i = 0; i < count; i++)
946 result[i] = arrays[0][i];
953 auto array0 = arrays[0];
954 foreach (
auto item : array0)
957 bool foundInAll =
true;
958 for (
int arrayId = 1; arrayId < arrays.Count(); arrayId++)
961 if (!arrays[arrayId].
Contains(item))
981 m_Widgets.m_FilterPanelComponent.SetItemsFoundMessage(current, total, current != total);
1005 Widget focusedWidget =
GetGame().GetWorkspace().GetFocusedWidget();
1015 return comp.GetWorkshopItem();
1024 m_Widgets.m_PagingButtons.SetVisible(pageCount != 0);
1029 m_Widgets.m_PageIndicatorText.SetTextFormat(
"#AR-Editor_ContentBrowser_PageIndex_Text",
m_iCurrentPage + 1, pageCount);
1058 if (item.GetRestricted())
1067 auto actionThisItem = item.GetDownloadAction();
1068 auto actionDependencies = item.GetDependencyCompositeAction();
1069 bool downloading = actionThisItem || actionDependencies;
1074 if (!item.GetFavourite())
1081 m_NavEnable.SetEnabled(item.GetOffline() && !downloading);
1082 if (item.GetOffline())
1085 if (item.GetEnabled())
1086 enableLabel =
"#AR-Workshop_ButtonDisable";
1088 enableLabel =
"#AR-Workshop_ButtonEnable";
1094 if (!primaryLabel.IsEmpty())
1113 SCR_FilterEntry reportedFilter = otherCategory.FindFilter(
"reported");
1115 if (!reportedFilter)
1118 return reportedFilter.GetSelected();
1125 Widget wCurrent = WidgetManager.GetWidgetUnderCursor();
1130 wCurrent = wCurrent.GetParent();
1139 EInputDeviceType inputType = -1;
1141 inputType = EInputDeviceType.MOUSE;
1157 EInputDeviceType inputType = -1;
1159 inputType = EInputDeviceType.MOUSE;
1175 float value =
GetGame().GetInputManager().GetActionValue(
"MouseWheel");
1188 protected array<ref SCR_WorkshopItem>
SelectItemsAtPage(array<ref SCR_WorkshopItem> items,
int pageId)
1190 array<ref SCR_WorkshopItem> itemsOut = {};
1193 int nPages = Math.Ceil(items.Count() / nItemsPerPage);
1195 if (pageId < 0 || pageId >= nPages)
1198 int idStart = nItemsPerPage * pageId;
1199 int idEnd = nItemsPerPage * (pageId + 1) - 1;
1201 if (idEnd >= items.Count())
1202 idEnd = items.Count() - 1;
1204 for (
int i = idStart; i <= idEnd; i++)
1206 itemsOut.Insert(items[i]);
1220 case SCR_EListMenuWidgetFocus.LIST:
1225 focusTarget =
m_Widgets.m_Grid.GetChildren();
1230 case SCR_EListMenuWidgetFocus.FILTERING:
1232 focusTarget =
m_Widgets.m_FilterPanelComponent.GetWidgets().m_FilterButton;
1236 case SCR_EListMenuWidgetFocus.SORTING:
1238 focusTarget =
m_Widgets.m_SortingHeader.GetChildren();
1242 case SCR_EListMenuWidgetFocus.NULL:
1244 GetGame().GetWorkspace().SetFocusedWidget(
null);
1249 if (!focusTarget || !focusTarget.IsVisible())
1252 focusTarget =
m_Widgets.m_SortingHeader.GetChildren();
1255 GetGame().GetWorkspace().SetFocusedWidget(focusTarget);
1306 item = tile.GetWorkshopItem();
1308 if (!item ||
m_Widgets.m_AddonDetailsPanelComponent.GetItem() == item)
1311 m_Widgets.m_AddonDetailsPanelComponent.SetWorkshopItem(item);
1320 bool show = !
m_Widgets.m_FilterPanelComponent.GetFilterListBoxShown();
1321 m_Widgets.m_FilterPanelComponent.ShowFilterListBox(show);
1354 if (item.GetRestricted())
1357 bool fav = item.GetFavourite();
1358 item.SetFavourite(!fav);
1386 array<WorkshopItem> items = {};
1402 array<ref SCR_WorkshopItem> itemsRegistered = {};
1404 foreach (
auto i : items)
1408 itemsRegistered.Insert(iRegistered);
1411 if (!itemsRegistered.IsEmpty())
1427 if (!
m_Widgets.m_FilterPanelComponent.GetFilterListBoxShown() || !
m_Widgets.m_FilterPanelComponent.GetFocused())
1493 if (comp.GetWorkshopItem() == item)
1535 array<SCR_ContentBrowserTileComponent> tiles = {};
1561 SCR_ContentBrowser_AddonsSubMenu m_AddonsSubMenu;
1562 protected bool m_bUseDefaultValues;
1572 override void OnPack()
1579 class SCR_CompareWorkshopItemName : SCR_SortCompare<SCR_WorkshopItem>
1583 string name1 = left.GetName();
1584 string name2 = right.GetName();
1586 if (name1.Compare(name2) == -1)
1598 int timeLeft = left.GetTimeSinceLastPlay();
1600 timeLeft = 0x7FFFFFFF;
1601 int timeRight = right.GetTimeSinceLastPlay();
1603 timeRight = 0x7FFFFFFF;
1605 return timeLeft < timeRight;
1610 class SCR_CompareWorkshopItemTimeSinceFirstDownload : SCR_SortCompare<SCR_WorkshopItem>
1614 int timeLeft = left.GetTimeSinceFirstDownload();
1616 timeLeft = 0x7FFFFFFF;
1617 int timeRight = right.GetTimeSinceFirstDownload();
1619 timeRight = 0x7FFFFFFF;
1621 return timeLeft < timeRight;
1631 float leftSize = left.GetTargetRevisionPatchSize();
1632 float rightSize = right.GetTargetRevisionPatchSize();
1634 return leftSize < rightSize;