private static void LocateNextPOInstance(PrefabInfo prefab) { Vector3 position = ProceduralObjectsTool.GetPOInstancePosition(prefab); if (position == Vector3.zero) { return; } SetCameraPosition(position); }
public void UpdateAssetInstanceCount(Asset asset, bool forceUpdatePO = false) { if (!prefabInstanceCountDictionary.ContainsKey(asset.prefab)) { asset.instanceCount = 0; } else { asset.instanceCount = prefabInstanceCountDictionary[asset.prefab]; } if ((Settings.includePOinstances || forceUpdatePO) && FindIt.isPOEnabled) { asset.poInstanceCount = ProceduralObjectsTool.GetPrefabPOInstanceCount(asset.prefab); } }
public static void ExportUsed(bool exportAllUsed) { // get steam id of all workship assets HashSet <ulong> steamIds = new HashSet <ulong>(); if (exportAllUsed) { foreach (Asset asset in AssetTagList.instance.assets.Values) { if (!asset.prefab.m_isCustomContent) { continue; } if (asset.steamID == 0) { continue; } steamIds.Add(asset.steamID); } } else // only export assets from last search { foreach (Asset asset in UISearchBox.instance.matches) { if (!asset.prefab.m_isCustomContent) { continue; } if (asset.steamID == 0) { continue; } steamIds.Add(asset.steamID); } } // update instance count AssetTagList.instance.UpdatePrefabInstanceCount(UISearchBox.DropDownOptions.All); if (FindIt.isPOEnabled) { ProceduralObjectsTool.UpdatePOInfoList(); } // filter out unused assets Dictionary <ulong, int> usedIDs = new Dictionary <ulong, int>(); foreach (Asset asset in AssetTagList.instance.assets.Values) { if (!asset.prefab.m_isCustomContent) { continue; } if (asset.steamID == 0) { continue; } AssetTagList.instance.UpdateAssetInstanceCount(asset, true); if (asset.instanceCount > 0 || asset.poInstanceCount > 0) { if (usedIDs.ContainsKey(asset.steamID)) { usedIDs[asset.steamID] += 1; } else { usedIDs.Add(asset.steamID, 1); } } } string currentTime = GetFormattedDateTime(); string path = Path.Combine(DataLocation.localApplicationData, $"FindItExportUsedWorkshopID_{currentTime}.html"); if (File.Exists(path)) { File.Delete(path); } using (System.IO.StreamWriter file = new System.IO.StreamWriter(path, true)) { file.WriteLine($"City Name: {GetCityName()}<br>"); file.WriteLine($"Export Date: {currentTime}<br>"); file.WriteLine($"<br>This list only considers asset types that are monitored by Find It 2<br>"); file.WriteLine($"<br>Some mods are bundled with assets for other purpose. Ignore mods in the list<br>"); file.WriteLine($"<br>If you ever copied assets from the workshop download folder to the local asset folder, the information here can be inaccurate<br>"); if (FindIt.isPOEnabled) { file.WriteLine($"<br>It seems like you're using Procedural Objects. This list already considers POs<br>"); } foreach (ulong id in steamIds) { if (usedIDs.ContainsKey(id)) { file.WriteLine($"<br><a href=\"https://steamcommunity.com/sharedfiles/filedetails/?id={id}\">{id}</a><br>\n"); file.WriteLine($"This workshop ID contains {usedIDs[id]} used asset(s).<br>\n"); } } if (steamIds.Count == 0) { file.WriteLine($"Can't find any used workshop asset.<br>\n"); } } ExceptionPanel panel = UIView.library.ShowModal <ExceptionPanel>("ExceptionPanel"); panel.SetMessage("Find It 2", $"FindItExportUsedWorkshopID.html is exported.\n\nIt only considers asset types that are monitored by Find It 2.\n\n{path}", false); }
public void Start() { try { GameObject gameObject = GameObject.Find("FindItMainButton"); if (gameObject != null) { return; } isRicoEnabled = IsRicoEnabled(); isPOEnabled = IsPOEnabled(); isTVPPatchEnabled = IsTVPPatchEnabled(); if (isPOEnabled) { POTool = new ProceduralObjectsTool(); } list = AssetTagList.instance; UITabstrip tabstrip = ToolsModifierControl.mainToolbar.component as UITabstrip; m_defaultXPos = tabstrip.relativePosition.x; UpdateMainToolbar(); GameObject asGameObject = UITemplateManager.GetAsGameObject("MainToolbarButtonTemplate"); GameObject asGameObject2 = UITemplateManager.GetAsGameObject("ScrollableSubPanelTemplate"); mainButton = tabstrip.AddTab("FindItMainButton", asGameObject, asGameObject2, new Type[] { typeof(UIGroupPanel) }) as UIButton; mainButton.atlas = atlas; mainButton.normalBgSprite = "ToolbarIconGroup6Normal"; mainButton.focusedBgSprite = "ToolbarIconGroup6Focused"; mainButton.hoveredBgSprite = "ToolbarIconGroup6Hovered"; mainButton.pressedBgSprite = "ToolbarIconGroup6ressed"; mainButton.disabledBgSprite = "ToolbarIconGroup6Disabled"; mainButton.normalFgSprite = "FindIt"; mainButton.focusedFgSprite = "FindItFocused"; mainButton.hoveredFgSprite = "FindItHovered"; mainButton.pressedFgSprite = "FindItPressed"; mainButton.disabledFgSprite = "FindItDisabled"; mainButton.tooltip = "Find It! " + (ModInfo.isBeta ? "[BETA] " : "") + ModInfo.version; Locale locale = (Locale)typeof(LocaleManager).GetField("m_Locale", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(LocaleManager.instance); Locale.Key key = new Locale.Key { m_Identifier = "TUTORIAL_ADVISER_TITLE", m_Key = mainButton.name }; if (!locale.Exists(key)) { locale.AddLocalizedString(key, "Find It! " + ModInfo.version); } key = new Locale.Key { m_Identifier = "TUTORIAL_ADVISER", m_Key = mainButton.name }; if (!locale.Exists(key)) { locale.AddLocalizedString(key, "Thanks for subscribing to Find It! 2.\n\nStart typing some keywords into the input field to find the desired asset.\n\nCheck the workshop page occasionally for new features or bug reports."); } FieldInfo m_ObjectIndex = typeof(MainToolbar).GetField("m_ObjectIndex", BindingFlags.Instance | BindingFlags.NonPublic); m_ObjectIndex.SetValue(ToolsModifierControl.mainToolbar, (int)m_ObjectIndex.GetValue(ToolsModifierControl.mainToolbar) + 1); mainButton.gameObject.GetComponent <TutorialUITag>().tutorialTag = name; m_groupPanel = tabstrip.GetComponentInContainer(mainButton, typeof(UIGroupPanel)) as UIGroupPanel; if (m_groupPanel != null) { m_groupPanel.name = "FindItGroupPanel"; m_groupPanel.enabled = true; m_groupPanel.component.isInteractive = true; m_groupPanel.m_OptionsBar = ToolsModifierControl.mainToolbar.m_OptionsBar; m_groupPanel.m_DefaultInfoTooltipAtlas = ToolsModifierControl.mainToolbar.m_DefaultInfoTooltipAtlas; if (ToolsModifierControl.mainToolbar.enabled) { m_groupPanel.RefreshPanel(); } scrollPanel = UIScrollPanel.Create(m_groupPanel.GetComponentInChildren <UIScrollablePanel>()); scrollPanel.eventClicked += OnButtonClicked; scrollPanel.eventVisibilityChanged += (c, p) => { HideAllOptionPanels(); if (p && scrollPanel.selectedItem != null) { // Simulate item click UIScrollPanelItem.ItemData item = scrollPanel.selectedItem; UIScrollPanelItem panelItem = scrollPanel.GetItem(0); panelItem.Display(scrollPanel.selectedItem, 0); panelItem.component.SimulateClick(); scrollPanel.selectedItem = item; scrollPanel.Refresh(); } }; scrollPanel.eventTooltipEnter += (c, p) => { UIScrollPanelItem.RefreshTooltipAltas(p.source); }; searchBox = scrollPanel.parent.AddUIComponent <UISearchBox>(); searchBox.scrollPanel = scrollPanel; searchBox.relativePosition = new Vector3(0, 0); searchBox.Search(); } else { Debugging.Message("GroupPanel not found"); } m_roadsPanel = FindObjectOfType <RoadsPanel>(); m_beautificationPanel = FindObjectOfType <BeautificationPanel>(); defaultPanel = GameObject.Find("FindItDefaultPanel").GetComponent <UIPanel>(); defaultPanelAtlas = defaultPanel.atlas; defaultPanelBackgroundSprite = defaultPanel.backgroundSprite; UpdateDefaultPanelBackground(); Debugging.Message("Initialized"); } catch (Exception e) { Debugging.Message("Start failed"); Debugging.LogException(e); enabled = false; } }
private bool CheckExtraFilters(Asset asset) { // filter out sub-builsings if sub-building filter not enabled if (asset.isSubBuilding && UISearchBox.instance.extraFiltersPanel.optionDropDownMenu.selectedIndex != (int)UIFilterExtra.DropDownOptions.SubBuildings) { return(false); } // 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 sub-buildings else if (UISearchBox.instance.extraFiltersPanel.optionDropDownMenu.selectedIndex == (int)UIFilterExtra.DropDownOptions.SubBuildings) { if (!asset.isSubBuilding) { return(false); } if (asset.assetType != Asset.AssetType.Invalid) { 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 (ProceduralObjectsTool.GetPrefabPOInstanceCount(asset.prefab) > 0) { return(false); } } } // only show used assets else if (UISearchBox.instance.extraFiltersPanel.optionDropDownMenu.selectedIndex == (int)UIFilterExtra.DropDownOptions.UsedAssets) { uint counter = 0; if (prefabInstanceCountDictionary.ContainsKey(asset.prefab)) { counter += prefabInstanceCountDictionary[asset.prefab]; } if (FindIt.isPOEnabled && Settings.includePOinstances) { counter += ProceduralObjectsTool.GetPrefabPOInstanceCount(asset.prefab); } if (counter < 1) { return(false); } } // only show assets with custom tags else if (UISearchBox.instance.extraFiltersPanel.optionDropDownMenu.selectedIndex == (int)UIFilterExtra.DropDownOptions.WithCustomTag) { if (asset.tagsCustom.Count < 1) { return(false); } } // only show assets without custom tags else if (UISearchBox.instance.extraFiltersPanel.optionDropDownMenu.selectedIndex == (int)UIFilterExtra.DropDownOptions.WithoutCustomTag) { if (asset.tagsCustom.Count > 0) { return(false); } } // DLC & CCP filter else if (UISearchBox.instance.extraFiltersPanel.optionDropDownMenu.selectedIndex == (int)UIFilterExtra.DropDownOptions.DLC) { if (!CheckDLCFilters(asset.prefab.m_dlcRequired)) { return(false); } } // local custom filter else if (UISearchBox.instance.extraFiltersPanel.optionDropDownMenu.selectedIndex == (int)UIFilterExtra.DropDownOptions.LocalCustom) { if (!asset.prefab.m_isCustomContent) { return(false); } if (!localWorkshopIDs.Contains(asset.steamID) && asset.steamID != 0) { return(false); } } // workshop subscription assets else if (UISearchBox.instance.extraFiltersPanel.optionDropDownMenu.selectedIndex == (int)UIFilterExtra.DropDownOptions.WorkshopCustom) { if (!asset.prefab.m_isCustomContent) { return(false); } if (localWorkshopIDs.Contains(asset.steamID)) { return(false); } if (asset.steamID == 0) { return(false); } } // Terrain conforming else if (UISearchBox.instance.extraFiltersPanel.optionDropDownMenu.selectedIndex == (int)UIFilterExtra.DropDownOptions.TerrainConforming) { if (!CheckTerrainConforming(asset, true)) { return(false); } } // Non-Terrain conforming else if (UISearchBox.instance.extraFiltersPanel.optionDropDownMenu.selectedIndex == (int)UIFilterExtra.DropDownOptions.NonTerrainConforming) { if (!CheckTerrainConforming(asset, false)) { return(false); } } 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); }