/// <summary> /// Creates a new pinned critter row. /// </summary> /// <param name="species">The species to pin.</param> /// <param name="type">The critter type to pin.</param> /// <returns>A pinned row with that critter type and species displayed.</returns> internal HierarchyReferences Create(Tag species, CritterType type) { var newRow = Util.KInstantiateUI(pinnedResources.linePrefab, pinnedResources.rowContainer, false); var refs = newRow.GetComponent <HierarchyReferences>(); // Set the image var imageData = Def.GetUISprite(species, "ui", false); if (imageData != null) { var icon = refs.GetReference <Image>("Icon"); icon.sprite = imageData.first; icon.color = imageData.second; } refs.GetReference <LocText>("NameLabel").SetText(CritterInventoryUtils.GetTitle( species, type)); refs.GetReference("NewLabel").gameObject.SetActive(false); var pinRow = newRow.AddComponent <PinnedCritterEntry>(); pinRow.CritterType = type; pinRow.Species = species; refs.GetReference <MultiToggle>("PinToggle").onClick = pinRow.OnUnpin; newRow.GetComponent <MultiToggle>().onClick += pinRow.OnCycleThrough; return(refs); }
/// <summary> /// Updates the graphs for the entire category. /// </summary> internal void UpdateCharts() { const float HISTORY = CritterInventoryUtils.CYCLES_TO_CHART * Constants.SECONDS_PER_CYCLE; float currentTime = GameClock.Instance.GetTime(); var tracker = CritterInventoryUtils.GetTracker <AllCritterTracker>(ClusterManager. Instance.activeWorldId, CritterType); var chart = refs.GetReference <SparkLayer>("Chart"); var chartableData = tracker.ChartableData(HISTORY); var xAxis = chart.graph.axis_x; if (chartableData.Length > 0) { xAxis.max_value = chartableData[chartableData.Length - 1].first; } else { xAxis.max_value = 0f; } xAxis.min_value = currentTime - HISTORY; chart.RefreshLine(chartableData, "resourceAmount"); foreach (var resource in resources) { resource.Value.UpdateChart(currentTime); } }
/// <summary> /// Cycles through critters of this type. /// </summary> internal void OnCycleThrough() { int id = ClusterManager.Instance.activeWorldId; var matching = ListPool <CreatureBrain, PinnedCritterEntry> .Allocate(); // Compile a list of critters matching this species CritterInventoryUtils.GetCritters(id, (creature) => { if (creature.GetCritterType() == CritterType) { matching.Add(creature); } }, Species); int n = matching.Count; if (selectionIndex >= n) { selectionIndex = 0; } else { selectionIndex = (selectionIndex + 1) % n; } if (n > 0) { PUtil.CenterAndSelect(matching[selectionIndex]); } matching.Recycle(); }
/// <summary> /// Filters rows by the user search query. /// </summary> /// <param name="search">The search query to use.</param> internal void SearchFilter(string search) { foreach (var resource in resources) { var cr = resource.Value; cr.IsVisible = CritterInventoryUtils.PassesSearchFilter(cr.Title, search); } }
#pragma warning restore IDE0044 #pragma warning restore CS0649 /// <summary> /// Highlights all critters matching this critter type on the active world. /// </summary> /// <param name="color">The color to highlight the critters.</param> internal void HighlightAllMatching(Color color) { var type = CritterType; int id = ClusterManager.Instance.activeWorldId; CritterInventoryUtils.GetCritters(id, (creature) => { if (creature.GetCritterType() == type) { PUtil.HighlightEntity(creature, color); } }); }
/// <summary> /// Highlights all critters matching this critter type on the active world. /// </summary> /// <param name="color">The color to highlight the critters.</param> /// <param name="species">The species type to highlight.</param> internal void HighlightAllMatching(Color color) { var type = CritterType; int id = ClusterManager.Instance.activeWorldId; CritterInventoryUtils.GetCritters(id, (kpid) => { if (kpid.GetCritterType() == type) { PGameUtils.HighlightEntity(kpid, color); } }, entry.Resource); }
/// <summary> /// Filters rows and categories by the user search query. /// </summary> /// <param name="search">The search query to use.</param> internal void SearchFilter(string search) { // Use current culture string searchUp = search.ToUpper(); foreach (var header in headers) { // Runs in prefix before SetRowsActive header.IsVisible = CritterInventoryUtils.PassesSearchFilter(header.Title, searchUp); header.SearchFilter(search); } }
/// <summary> /// Updates the line chart for this critter type. /// </summary> /// <param name="sparkChart">The chart object to update.</param> internal void UpdateChart(GameObject sparkChart) { var tracker = CritterInventoryUtils.GetTracker <AllCritterTracker>(ClusterManager. Instance.activeWorldId, CritterType); // Search for tracker that matches both world ID and wildness type if (tracker != null) { sparkChart.GetComponentInChildren <LineLayer>().RefreshLine(tracker. ChartableData(CritterInventoryUtils.CYCLES_TO_CHART * Constants. SECONDS_PER_CYCLE), "resourceAmount"); sparkChart.GetComponentInChildren <SparkLayer>().SetColor(Constants. NEUTRAL_COLOR); } }
/// <summary> /// Called when a tooltip is needed for a critter category. /// </summary> /// <returns>The tool tip text for a critter type (wild or tame).</returns> private string OnAllTooltip() { CritterInventory ci; var categoryTracker = CritterInventoryUtils.GetTracker <AllCritterTracker>( ClusterManager.Instance.activeWorldId, CritterType); var world = ClusterManager.Instance.activeWorld; string result = null; if (world != null && (ci = world.GetComponent <CritterInventory>()) != null) { float trend = (categoryTracker == null) ? 0.0f : categoryTracker.GetDelta( CritterInventoryUtils.TREND_INTERVAL); result = CritterInventoryUtils.FormatTooltip(header.elements.LabelText.text, ci.PopulateTotals(CritterType, null), trend); } return(result); }
/// <summary> /// Updates the graph for this critter species. /// </summary> /// <param name="currentTime">The current time from GameClock.</param> internal void UpdateChart(float currentTime) { const float HISTORY = CritterInventoryUtils.CYCLES_TO_CHART * Constants.SECONDS_PER_CYCLE; var tracker = CritterInventoryUtils.GetTracker<CritterTracker>(ClusterManager. Instance.activeWorldId, CritterType, (t) => t.Tag == Species); if (tracker != null) { var chart = References.GetReference<SparkLayer>("Chart"); var chartableData = tracker.ChartableData(HISTORY); var xAxis = chart.graph.axis_x; if (chartableData.Length > 0) xAxis.max_value = chartableData[chartableData.Length - 1].first; else xAxis.max_value = 0f; xAxis.min_value = currentTime - HISTORY; chart.RefreshLine(chartableData, "resourceAmount"); } }
/// <summary> /// Called when a tooltip is needed for a critter species. /// </summary> /// <returns>The tool tip text for a critter type and species.</returns> private string OnEntryTooltip() { var speciesTracker = CritterInventoryUtils.GetTracker <CritterTracker>( ClusterManager.Instance.activeWorldId, CritterType, (tracker) => tracker.Tag == entry.Resource); var world = ClusterManager.Instance.activeWorld; string result = null; if (world != null && world.TryGetComponent(out CritterInventory ci)) { float trend = (speciesTracker == null) ? 0.0f : speciesTracker.GetDelta( CritterInventoryUtils.TREND_INTERVAL); result = CritterInventoryUtils.FormatTooltip(entry.NameLabel.text, ci. GetBySpecies(CritterType, entry.Resource), trend); } return(result); }
/// <summary> /// Creates a resource category header for critters. /// </summary> /// <param name="resList">The parent category screen for this header.</param> /// <param name="prefab">The prefab to use for creating the headers.</param> /// <param name="type">The critter type to create.</param> internal void Create(ResourceCategoryScreen resList, GameObject prefab, CritterType type) { var tag = GameTags.BagableCreature; // Create a heading for Critter (Type) PUtil.LogDebug("Creating Critter ({0}) category".F(type.GetProperName())); var gameObject = Util.KInstantiateUI(prefab, resList.CategoryContainer.gameObject, false); gameObject.name = "CategoryHeader_{0}_{1}".F(tag.Name, type.ToString()); var header = gameObject.GetComponent <ResourceCategoryHeader>(); header.SetTag(tag, GameUtil.MeasureUnit.quantity); // Tag it with a wild/tame tag header.gameObject.AddComponent <CritterResourceHeader>().CritterType = type; header.elements.LabelText.SetText(CritterInventoryUtils.GetTitle(tag, type)); headers.Add(header); }
/// <summary> /// Caches the list of critters of this type. /// </summary> /// <param name="species">The critter type to populate.</param> /// <returns>The list of matching critters.</returns> internal IList <CreatureBrain> PopulateCache() { int id = ClusterManager.Instance.activeWorldId; var type = CritterType; if (CachedCritters != null) { CachedCritters.Clear(); } else { CachedCritters = new List <CreatureBrain>(32); } CritterInventoryUtils.GetCritters(id, (creature) => { if (creature.GetCritterType() == type) { CachedCritters.Add(creature); } }, entry.Resource); return(CachedCritters); }