private bool CheckGrowableRICOFilter(Asset asset, UISearchBox.DropDownOptions filter) { BuildingInfo buildingInfo = asset.prefab as BuildingInfo; // Distinguish growable and rico if ((filter == UISearchBox.DropDownOptions.Growable) && (asset.assetType == Asset.AssetType.Rico)) { return(false); } if ((filter == UISearchBox.DropDownOptions.Rico) && (asset.assetType == Asset.AssetType.Growable)) { return(false); } // filter by size if (!CheckBuildingSize(asset.size, UISearchBox.instance.buildingSizeFilterIndex)) { return(false); } // filter by growable type if (!UIFilterGrowable.instance.IsAllSelected()) { UIFilterGrowable.Category category = UIFilterGrowable.GetCategory(buildingInfo.m_class); if (category == UIFilterGrowable.Category.None || !UIFilterGrowable.instance.IsSelected(category)) { return(false); } } return(true); }
/// <summary> /// Get relevance score. Metrics decided by SamsamTS. Unchanged in Find It 2 /// </summary> private float GetOverallScore(Asset asset, string keyword, UISearchBox.DropDownOptions filter) { float score = 0; if (!asset.author.IsNullOrWhiteSpace()) { score += 10 * GetScore(keyword, asset.author.ToLower(), null); } if (filter == UISearchBox.DropDownOptions.All && asset.assetType != Asset.AssetType.Invalid) { score += 10 * GetScore(keyword, asset.assetType.ToString().ToLower(), null); } if (asset.service != ItemClass.Service.None) { score += 10 * GetScore(keyword, asset.service.ToString().ToLower(), null); } if (asset.subService != ItemClass.SubService.None) { score += 10 * GetScore(keyword, asset.subService.ToString().ToLower(), null); } if (asset.size != Vector2.zero) { score += 10 * GetScore(keyword, asset.size.x + "x" + asset.size.y, null); } foreach (string tag in asset.tagsCustom) { score += 20 * GetScore(keyword, tag, tagsCustomDictionary); } foreach (string tag in asset.tagsTitle) { score += 5 * GetScore(keyword, tag, tagsTitleDictionary); } foreach (string tag in asset.tagsDesc) { score += GetScore(keyword, tag, tagsDescDictionary); } return(score); }
public void SetSelectedTab(UISearchBox.DropDownOptions option) { int type = -1; if (option == UISearchBox.DropDownOptions.Network) { type = (int)Category.Network; } else if (option == UISearchBox.DropDownOptions.Ploppable) { type = (int)Category.Ploppable; } else if (option == UISearchBox.DropDownOptions.Tree) { type = (int)Category.Tree; } else if (option == UISearchBox.DropDownOptions.Prop) { type = (int)Category.Prop; } else if (option == UISearchBox.DropDownOptions.Growable) { type = (int)Category.Growable; } else if (option == UISearchBox.DropDownOptions.GrwbRico) { type = (int)Category.GrowableRico; } else if (option == UISearchBox.DropDownOptions.Rico) { type = (int)Category.Rico; } else if (option == UISearchBox.DropDownOptions.Decal) { type = (int)Category.Decal; } SelectTab(type); }
private bool CheckAssetTypeFilter(Asset asset, UISearchBox.DropDownOptions filter) { if (asset.assetType != Asset.AssetType.Network && filter == UISearchBox.DropDownOptions.Network) { return(false); } if (asset.assetType != Asset.AssetType.Prop && filter == UISearchBox.DropDownOptions.Prop) { return(false); } if (asset.assetType != Asset.AssetType.Rico && filter == UISearchBox.DropDownOptions.Rico) { return(false); } if (asset.assetType != Asset.AssetType.Ploppable && filter == UISearchBox.DropDownOptions.Ploppable) { return(false); } if (asset.assetType != Asset.AssetType.Growable && filter == UISearchBox.DropDownOptions.Growable) { return(false); } if (asset.assetType != Asset.AssetType.Tree && filter == UISearchBox.DropDownOptions.Tree) { return(false); } if (asset.assetType != Asset.AssetType.Decal && filter == UISearchBox.DropDownOptions.Decal) { return(false); } if ((asset.assetType != Asset.AssetType.Rico && asset.assetType != Asset.AssetType.Growable) && filter == UISearchBox.DropDownOptions.GrwbRico) { return(false); } return(true); }
public void UpdatePrefabInstanceCount(UISearchBox.DropDownOptions filter) { prefabInstanceCountDictionary.Clear(); if (BuildingManager.exists && ((filter == UISearchBox.DropDownOptions.All) || (filter == UISearchBox.DropDownOptions.Growable) || (filter == UISearchBox.DropDownOptions.GrwbRico) || (filter == UISearchBox.DropDownOptions.Ploppable) || (filter == UISearchBox.DropDownOptions.Rico))) { foreach (Building building in BuildingManager.instance.m_buildings.m_buffer) { if (building.m_flags != Building.Flags.None && building.m_flags != Building.Flags.Deleted) { if (prefabInstanceCountDictionary.ContainsKey(building.Info)) { prefabInstanceCountDictionary[building.Info] += 1; } else { prefabInstanceCountDictionary.Add(building.Info, 1); } } } } if (PropManager.exists && ((filter == UISearchBox.DropDownOptions.All) || (filter == UISearchBox.DropDownOptions.Prop) || (filter == UISearchBox.DropDownOptions.Decal))) { foreach (PropInstance prop in PropManager.instance.m_props.m_buffer) { if ((PropInstance.Flags)prop.m_flags != PropInstance.Flags.None && (PropInstance.Flags)prop.m_flags != PropInstance.Flags.Deleted) { if (prefabInstanceCountDictionary.ContainsKey(prop.Info)) { prefabInstanceCountDictionary[prop.Info] += 1; } else { prefabInstanceCountDictionary.Add(prop.Info, 1); } } } } if (TreeManager.exists && ((filter == UISearchBox.DropDownOptions.All) || (filter == UISearchBox.DropDownOptions.Tree))) { foreach (TreeInstance tree in TreeManager.instance.m_trees.m_buffer) { if ((TreeInstance.Flags)tree.m_flags != TreeInstance.Flags.None && (TreeInstance.Flags)tree.m_flags != TreeInstance.Flags.Deleted) { if (prefabInstanceCountDictionary.ContainsKey(tree.Info)) { prefabInstanceCountDictionary[tree.Info] += 1; } else { prefabInstanceCountDictionary.Add(tree.Info, 1); } } } } if (NetManager.exists && ((filter == UISearchBox.DropDownOptions.All) || (filter == UISearchBox.DropDownOptions.Network))) { foreach (NetSegment segment in NetManager.instance.m_segments.m_buffer) { if (segment.m_flags != NetSegment.Flags.None && segment.m_flags != NetSegment.Flags.Deleted) { if (prefabInstanceCountDictionary.ContainsKey(segment.Info)) { prefabInstanceCountDictionary[segment.Info] += 1; } else { prefabInstanceCountDictionary.Add(segment.Info, 1); } } } } }
private bool CheckAssetFilters(Asset asset, UISearchBox.DropDownOptions filter) { if (!CheckAssetTypeFilter(asset, filter)) { return(false); } if (filter == UISearchBox.DropDownOptions.Growable || filter == UISearchBox.DropDownOptions.Rico || filter == UISearchBox.DropDownOptions.GrwbRico) { if (!CheckGrowableRICOFilter(asset, filter)) { return(false); } } else if (filter == UISearchBox.DropDownOptions.Ploppable) { if (!CheckPloppableFilter(asset)) { return(false); } } else if (filter == UISearchBox.DropDownOptions.Prop) { // filter by prop type if (!UIFilterProp.instance.IsAllSelected()) { UIFilterProp.Category category = UIFilterProp.GetCategory(asset.propType); if (category == UIFilterProp.Category.None || !UIFilterProp.instance.IsSelected(category)) { return(false); } } } else if (filter == UISearchBox.DropDownOptions.Tree) { // filter by tree type if (!UIFilterTree.instance.IsAllSelected()) { UIFilterTree.Category category = UIFilterTree.GetCategory(asset.treeType); if (category == UIFilterTree.Category.None || !UIFilterTree.instance.IsSelected(category)) { return(false); } } } else if (filter == UISearchBox.DropDownOptions.Network) { if (!CheckNetworkFilter(asset)) { return(false); } } // filter out marker prop if not in editor mode if ((!FindIt.inEditor && !Settings.showPropMarker) && (asset.propType == Asset.PropType.PropsMarker)) { return(false); } try { // check vanila & workshop filters if (!CheckVanillaWorkshopFilter(asset)) { return(false); } // filter out assets without matching custom tag if (UISearchBox.instance?.tagPanel != null) { if (UISearchBox.instance.tagPanel.tagDropDownCheckBox.isChecked && UISearchBox.instance.tagPanel.customTagListStrArray.Length > 0) { if (!asset.tagsCustom.Contains(UISearchBox.instance.tagPanel.GetDropDownListKey())) { return(false); } } } // extra filters check if (UISearchBox.instance?.extraFiltersPanel != null) { if (UISearchBox.instance.extraFiltersPanel.optionDropDownCheckBox.isChecked) { if (!CheckExtraFilters(asset)) { return(false); } } else { if (asset.isSubBuilding) { return(false); } } } // skip sub-buildings if not using the extra filters panel else { if (asset.isSubBuilding) { return(false); } } } catch (Exception e) { Debugging.LogException(e); } return(true); }
/// <summary> /// main backend search method. called by UISearchBox's search method /// </summary> public List <Asset> Find(string text, UISearchBox.DropDownOptions filter) { matches.Clear(); text = text.ToLower().Trim(); // if showing instance counts, refresh try { bool usingUsedUnusedFilterFlag = UISearchBox.instance?.extraFiltersPanel != null && (UISearchBox.instance.extraFiltersPanel.optionDropDownMenu.selectedIndex == (int)UIFilterExtra.DropDownOptions.UnusedAssets || UISearchBox.instance.extraFiltersPanel.optionDropDownMenu.selectedIndex == (int)UIFilterExtra.DropDownOptions.UsedAssets); if (Settings.showInstancesCounter || usingUsedUnusedFilterFlag) { UpdatePrefabInstanceCount(filter); if ((filter != UISearchBox.DropDownOptions.Tree) && (filter != UISearchBox.DropDownOptions.Network)) { if (FindIt.isPOEnabled && (Settings.includePOinstances || usingUsedUnusedFilterFlag)) { ProceduralObjectsTool.UpdatePOInfoList(); } } } } catch (Exception ex) { Debugging.LogException(ex); } // if there is something in the search input box if (!text.IsNullOrWhiteSpace()) { string[] keywords = Regex.Split(text, @"([^\w!#+%]|[-]|\s)+", RegexOptions.IgnoreCase); bool matched, orSearch; float score, orScore; foreach (Asset asset in assets.Values) { asset.RefreshRico(); if (asset.prefab != null) { if (!CheckAssetFilters(asset, filter)) { continue; } matched = true; asset.score = 0; score = 0; orSearch = false; orScore = 0; foreach (string keyword in keywords) { if (!keyword.IsNullOrWhiteSpace()) { if (keyword == "!" || keyword == "#" || keyword == "+" || keyword == "%") { continue; } if (keyword.StartsWith("!") && keyword.Length > 1) // exclude search { score = GetOverallScore(asset, keyword.Substring(1), filter); if (score > 0) { matched = false; break; } } else if (keyword.StartsWith("#") && keyword.Length > 1) // search for custom tag only { foreach (string tag in asset.tagsCustom) { score = GetScore(keyword.Substring(1), tag, tagsCustomDictionary); } if (score <= 0) { matched = false; break; } } else if (keyword.StartsWith("+") && keyword.Length > 1) // OR search { orSearch = true; score = GetOverallScore(asset, keyword.Substring(1), filter); orScore += score; asset.score += score; } else if (keyword.StartsWith("%") && keyword.Length > 1) // search by workshop id { if (asset.prefab.m_isCustomContent && asset.steamID != 0) { score = GetScore(keyword.Substring(1), asset.steamID.ToString(), null); if (score <= 0) { matched = false; break; } } else { matched = false; break; } } else { // Calculate relevance score. Algorithm decided by Sam. Unchanged. score = GetOverallScore(asset, keyword, filter); if (score <= 0) { matched = false; break; } else { asset.score += score; } } } } if (orSearch && orScore <= 0) { continue; } if (matched) { matches.Add(asset); if (Settings.instanceCounterSort != 0) { UpdateAssetInstanceCount(asset); } } } } } // if there isn't anything in the search input box else { foreach (Asset asset in assets.Values) { asset.RefreshRico(); if (asset.prefab != null) { if (!CheckAssetFilters(asset, filter)) { continue; } matches.Add(asset); if (Settings.instanceCounterSort != 0) { UpdateAssetInstanceCount(asset); } } } } return(matches); }
public List <Asset> Find(string text, UISearchBox.DropDownOptions filter) { matches.Clear(); text = text.ToLower().Trim(); // if showing instance counts, refresh try { if ((Settings.showInstancesCounter) || (UISearchBox.instance?.extraFiltersPanel != null && UISearchBox.instance.extraFiltersPanel.optionDropDownMenu.selectedIndex == 2)) { UpdatePrefabInstanceCount(); if (FindIt.isPOEnabled && Settings.includePOinstances) { FindIt.instance.POTool.UpdatePOInfoList(); } if (Settings.instanceCounterSort != 0) { UpdateAssetInstanceCount(); } } } catch (Exception ex) { Debugging.LogException(ex); } // if there is something in the search input box if (!text.IsNullOrWhiteSpace()) { string[] keywords = Regex.Split(text, @"([^\w!#+]|[_-]|\s)+", RegexOptions.IgnoreCase); bool matched = true; float score = 0; bool orSearch = false; float orScore = 0; foreach (Asset asset in assets.Values) { asset.RefreshRico(); if (asset.prefab != null) { if (!CheckAssetFilter(asset, filter)) { continue; } matched = true; asset.score = 0; score = 0; orSearch = false; orScore = 0; foreach (string keyword in keywords) { if (!keyword.IsNullOrWhiteSpace()) { if (keyword == "!" || keyword == "#" || keyword == "+") { continue; } if (keyword.StartsWith("!") && keyword.Length > 1) { score = GetOverallScore(asset, keyword.Substring(1), filter); if (score > 0) { matched = false; break; } } else if (keyword.StartsWith("#") && keyword.Length > 1) { foreach (string tag in asset.tagsCustom) { score = GetScore(keyword.Substring(1), tag, tagsCustomDictionary); } if (score <= 0) { matched = false; break; } } else if (keyword.StartsWith("+") && keyword.Length > 1) { orSearch = true; score = GetOverallScore(asset, keyword.Substring(1), filter); orScore += score; asset.score += score; } else { // Calculate relevance score. Algorithm decided by Sam. Unchanged. score = GetOverallScore(asset, keyword, filter); if (score <= 0) { matched = false; break; } else { asset.score += score; } } } } if (orSearch && orScore <= 0) { continue; } if (matched) { matches.Add(asset); } } } } // if there isn't anything in the search input box else { foreach (Asset asset in assets.Values) { asset.RefreshRico(); if (asset.prefab != null) { if (!CheckAssetFilter(asset, filter)) { continue; } matches.Add(asset); } } } return(matches); }
/// <summary> /// return true if the asset type matches UISearchbox filter dropdown options /// </summary> private bool CheckAssetFilter(Asset asset, UISearchBox.DropDownOptions filter) { if (asset.assetType != Asset.AssetType.Network && filter == UISearchBox.DropDownOptions.Network) { return(false); } if (asset.assetType != Asset.AssetType.Prop && filter == UISearchBox.DropDownOptions.Prop) { return(false); } if (asset.assetType != Asset.AssetType.Rico && filter == UISearchBox.DropDownOptions.Rico) { return(false); } if (asset.assetType != Asset.AssetType.Ploppable && filter == UISearchBox.DropDownOptions.Ploppable) { return(false); } if (asset.assetType != Asset.AssetType.Growable && filter == UISearchBox.DropDownOptions.Growable) { return(false); } if (asset.assetType != Asset.AssetType.Tree && filter == UISearchBox.DropDownOptions.Tree) { return(false); } if (asset.assetType != Asset.AssetType.Decal && filter == UISearchBox.DropDownOptions.Decal) { return(false); } if ((asset.assetType != Asset.AssetType.Rico && asset.assetType != Asset.AssetType.Growable) && filter == UISearchBox.DropDownOptions.GrwbRico) { return(false); } if (filter == UISearchBox.DropDownOptions.Growable || filter == UISearchBox.DropDownOptions.Rico || filter == UISearchBox.DropDownOptions.GrwbRico) { BuildingInfo buildingInfo = asset.prefab as BuildingInfo; // Distinguish growable and rico if ((filter == UISearchBox.DropDownOptions.Growable) && (asset.assetType == Asset.AssetType.Rico)) { return(false); } if ((filter == UISearchBox.DropDownOptions.Rico) && (asset.assetType == Asset.AssetType.Growable)) { return(false); } // filter by size if (!CheckBuildingSize(asset.size, UISearchBox.instance.buildingSizeFilterIndex)) { return(false); } // filter by growable type if (!UIFilterGrowable.instance.IsAllSelected()) { UIFilterGrowable.Category category = UIFilterGrowable.GetCategory(buildingInfo.m_class); if (category == UIFilterGrowable.Category.None || !UIFilterGrowable.instance.IsSelected(category)) { return(false); } } } else if (filter == UISearchBox.DropDownOptions.Ploppable) { BuildingInfo buildingInfo = asset.prefab as BuildingInfo; // filter by size if (!CheckBuildingSize(asset.size, UISearchBox.instance.buildingSizeFilterIndex)) { return(false); } // filter by ploppable type if (!UIFilterPloppable.instance.IsAllSelected()) { UIFilterPloppable.Category category = UIFilterPloppable.GetCategory(buildingInfo.m_class); if (category == UIFilterPloppable.Category.None || !UIFilterPloppable.instance.IsSelected(category)) { return(false); } } } else if (filter == UISearchBox.DropDownOptions.Prop) { // filter by prop type if (!UIFilterProp.instance.IsAllSelected()) { UIFilterProp.Category category = UIFilterProp.GetCategory(asset.propType); if (category == UIFilterProp.Category.None || !UIFilterProp.instance.IsSelected(category)) { return(false); } } } else if (filter == UISearchBox.DropDownOptions.Tree) { // filter by tree type if (!UIFilterTree.instance.IsAllSelected()) { UIFilterTree.Category category = UIFilterTree.GetCategory(asset.treeType); if (category == UIFilterTree.Category.None || !UIFilterTree.instance.IsSelected(category)) { return(false); } } } else if (filter == UISearchBox.DropDownOptions.Network) { // filter by network type if (!UIFilterNetwork.instance.IsAllSelected()) { UIFilterNetwork.Category category = UIFilterNetwork.GetCategory(asset.networkType); NetInfo info = asset.prefab as NetInfo; if (info == null) { return(false); } // not mutually exclusive with other categories. Handle them differently. if (UIFilterNetwork.instance.IsOnlySelected(UIFilterNetwork.Category.OneWay)) { if (!UIFilterNetwork.IsNormalRoads(asset.networkType)) { return(false); } if (!UIFilterNetwork.IsOneWay(info)) { return(false); } } else if (UIFilterNetwork.instance.IsOnlySelected(UIFilterNetwork.Category.Parking)) { if (!UIFilterNetwork.IsNormalRoads(asset.networkType)) { return(false); } if (!UIFilterNetwork.HasParking(info)) { return(false); } } else if (UIFilterNetwork.instance.IsOnlySelected(UIFilterNetwork.Category.NoParking)) { if (!UIFilterNetwork.IsNormalRoads(asset.networkType)) { return(false); } if (UIFilterNetwork.HasParking(info)) { return(false); } } else { if (category == UIFilterNetwork.Category.None || !UIFilterNetwork.instance.IsSelected(category)) { return(false); } } } } // filter out marker prop if not in editor mode if ((!FindIt.inEditor && !Settings.showPropMarker) && (asset.propType == Asset.PropType.PropsMarker)) { return(false); } try { if (UISearchBox.instance?.workshopFilter != null && UISearchBox.instance?.vanillaFilter != null) { // filter out custom asset if (asset.prefab.m_isCustomContent && !UISearchBox.instance.workshopFilter.isChecked) { return(false); } // filter out vanilla asset. will not filter out content creater pack assets if (!asset.prefab.m_isCustomContent && !UISearchBox.instance.vanillaFilter.isChecked && !asset.isCCP) { return(false); } // filter out assets without matching custom tag if (UISearchBox.instance?.tagPanel != null) { if (UISearchBox.instance.tagPanel.tagDropDownCheckBox.isChecked && UISearchBox.instance.tagPanel.customTagListStrArray.Length > 0) { if (!asset.tagsCustom.Contains(UISearchBox.instance.tagPanel.GetDropDownListKey())) { return(false); } } } // extra filters check if (UISearchBox.instance?.extraFiltersPanel != null) { if (UISearchBox.instance.extraFiltersPanel.optionDropDownCheckBox.isChecked) { // filter asset by asset creator if (UISearchBox.instance.extraFiltersPanel.optionDropDownMenu.selectedIndex == (int)UIFilterExtra.DropDownOptions.AssetCreator) { if (asset.author != UISearchBox.instance.extraFiltersPanel.GetAssetCreatorDropDownListKey()) { return(false); } } // filter asset by building height else if (UISearchBox.instance.extraFiltersPanel.optionDropDownMenu.selectedIndex == (int)UIFilterExtra.DropDownOptions.BuildingHeight) { if (asset.assetType == Asset.AssetType.Ploppable || asset.assetType == Asset.AssetType.Rico || asset.assetType == Asset.AssetType.Growable) { if (asset.buildingHeight > UISearchBox.instance.extraFiltersPanel.maxBuildingHeight) { return(false); } if (asset.buildingHeight < UISearchBox.instance.extraFiltersPanel.minBuildingHeight) { return(false); } } else { return(false); } } // filter asset by building level else if (UISearchBox.instance.extraFiltersPanel.optionDropDownMenu.selectedIndex == (int)UIFilterExtra.DropDownOptions.BuildingLevel) { if (!(asset.prefab is BuildingInfo)) { return(false); } BuildingInfo info = asset.prefab as BuildingInfo; ItemClass.Level level = (ItemClass.Level)UISearchBox.instance.extraFiltersPanel.buildingLevelDropDownMenu.selectedIndex; if (info.m_class.m_level != level) { return(false); } } // only show unused assets else if (UISearchBox.instance.extraFiltersPanel.optionDropDownMenu.selectedIndex == (int)UIFilterExtra.DropDownOptions.UnusedAssets) { if (prefabInstanceCountDictionary.ContainsKey(asset.prefab)) { if (prefabInstanceCountDictionary[asset.prefab] > 0) { return(false); } } if (FindIt.isPOEnabled && Settings.includePOinstances) { if (FindIt.instance.POTool.GetPrefabInstanceCount(asset.prefab) > 0) { return(false); } } } } } } } catch (Exception e) { Debugging.LogException(e); } return(true); }