/// <summary> /// Populates the target fastlist with a list of target-specific trees or props. /// </summary> protected override void TargetList() { // Clear current selection. targetList.selectedIndex = -1; // List of prefabs that have passed filtering. List <TargetListItem> itemList = new List <TargetListItem>(); // Check to see if this building contains any lanes. if (SelectedNet?.m_lanes == null || SelectedNet.m_lanes.Length == 0) { // No lanes - show 'no props' label and return an empty list. noPropsLabel.Show(); targetList.rowsData = new FastList <object>(); return; } // Local reference. NetInfo.Lane[] lanes = SelectedNet.m_lanes; // Iterate through each lane. for (int lane = 0; lane < lanes.Length; ++lane) { // Local reference. NetLaneProps.Prop[] laneProps = lanes[lane].m_laneProps?.m_props; // If no props in this lane, skip it and go to the next one. if (laneProps == null) { continue; } // Iterate through each prop in lane. for (int propIndex = 0; propIndex < laneProps.Length; ++propIndex) { // Create new list item. NetTargetListItem targetListItem = new NetTargetListItem(); // Try to get relevant prefab (prop/tree), using finalProp. PrefabInfo finalInfo = IsTree ? (PrefabInfo)laneProps[propIndex]?.m_finalTree : (PrefabInfo)laneProps[propIndex]?.m_finalProp; // Check to see if we were succesful - if not (e.g. we only want trees and this is a prop), continue on to next building prop. if (finalInfo?.name == null) { continue; } // Get original (pre-replacement) tree/prop prefab and current probability (as default original probability). targetListItem.originalPrefab = finalInfo; targetListItem.originalProb = laneProps[propIndex].m_probability; targetListItem.originalAngle = laneProps[propIndex].m_angle; // Grouped or individual? if (CurrentMode == (int)ReplacementModes.Individual) { // Individual - set index to the current prop indexes. targetListItem.index = propIndex; targetListItem.lane = lane; } else { // Grouped - set index to -1 and add to our list of indexes. targetListItem.index = -1; targetListItem.lane = -1; targetListItem.indexes.Add(propIndex); targetListItem.lanes.Add(lane); } // All-network replacement and original probability (if any). BOBNetReplacement allNetReplacement = AllNetworkReplacement.Instance.ActiveReplacement(SelectedNet, lane, propIndex); if (allNetReplacement != null) { targetListItem.allPrefab = allNetReplacement.replacementInfo; targetListItem.allProb = allNetReplacement.probability; // Update original prop reference. targetListItem.originalPrefab = allNetReplacement.targetInfo; // See if we can find an active reference. Logging.Message("finding original probability - all-network"); NetPropReference originalReference = allNetReplacement?.references?.Find(x => x.netInfo == SelectedNet && x.laneIndex == lane && x.propIndex == propIndex); if (originalReference != null) { // Original reference found; update original probability. targetListItem.originalProb = originalReference.probability; } Logging.Message("original probability not found"); } // Network replacement and original probability (if any). BOBNetReplacement netReplacement = NetworkReplacement.Instance.ActiveReplacement(SelectedNet, lane, propIndex); if (netReplacement != null) { targetListItem.replacementPrefab = netReplacement.replacementInfo; targetListItem.replacementProb = netReplacement.probability; // Update original prop reference. targetListItem.originalPrefab = netReplacement.targetInfo; Logging.Message("finding original probability - grouped"); targetListItem.originalProb = netReplacement.references.Find(x => x.laneIndex == lane && x.propIndex == propIndex).probability; Logging.Message("original probability found"); } // Individual replacement and original probability (if any). BOBNetReplacement individualReplacement = IndividualNetworkReplacement.Instance.ActiveReplacement(SelectedNet, lane, propIndex); if (individualReplacement != null) { targetListItem.individualPrefab = individualReplacement.replacementInfo; targetListItem.individualProb = individualReplacement.probability; Logging.Message("finding original probability - individual"); targetListItem.originalProb = individualReplacement.references.Find(x => x.laneIndex == lane && x.propIndex == propIndex).probability; Logging.Message("original probability found"); // Update original prop reference. targetListItem.originalPrefab = individualReplacement.targetInfo; } // Replacement pack replacement and original probability (if any). BOBNetReplacement packReplacement = NetworkPackReplacement.Instance.ActiveReplacement(SelectedNet, lane, propIndex); if (packReplacement != null) { targetListItem.packagePrefab = packReplacement.replacementInfo; // Update original prop reference. targetListItem.originalPrefab = packReplacement.targetInfo; targetListItem.originalProb = packReplacement.references.Find(x => x.laneIndex == lane && x.propIndex == propIndex).probability; } // Are we grouping? if (targetListItem.index == -1) { // Yes, grouping - initialise a flag to show if we've matched. bool matched = false; // Iterate through each item in our existing list of props. foreach (NetTargetListItem item in itemList) { // Check to see if we already have this in the list - matching original prefab, individual replacement prefab, network replacement prefab, all-network replacement prefab, and probability. if (item.originalPrefab == targetListItem.originalPrefab && item.individualPrefab == targetListItem.individualPrefab && item.replacementPrefab == targetListItem.replacementPrefab && targetListItem.allPrefab == item.allPrefab) { // We've already got an identical grouped instance of this item - add this index and lane to the lists of indexes and lanes under that item and set the flag to indicate that we've done so. item.indexes.Add(propIndex); item.lanes.Add(lane); matched = true; // No point going any further through the list, since we've already found our match. break; } } // Did we get a match? if (matched) { // Yes - continue on to next network prop (without adding this item separately to the list). continue; } } // Add this item to our list. itemList.Add(targetListItem); } } // Create return fastlist from our filtered list, ordering by name. targetList.rowsData = new FastList <object>() { m_buffer = targetSearchStatus == (int)OrderBy.NameDescending ? itemList.OrderByDescending(item => item.DisplayName).ToArray() : itemList.OrderBy(item => item.DisplayName).ToArray(), m_size = itemList.Count }; targetList.Refresh(); // If the list is empty, show the 'no props' label; otherwise, hide it. if (itemList.Count == 0) { noPropsLabel.Show(); } else { noPropsLabel.Hide(); } }
/// <summary> /// Generates and displays a list row. /// </summary> /// <param name="data">Object to list</param> /// <param name="isRowOdd">If the row is an odd-numbered row (for background banding)</param> public virtual void Display(object data, bool isRowOdd) { // Perform initial setup for new rows. if (nameLabel == null) { isVisible = true; canFocus = true; isInteractive = true; width = parent.width; height = RowHeight; // Add object name label. nameLabel = AddUIComponent <UILabel>(); nameLabel.width = this.width - 10f; nameLabel.textScale = TextScale; // Add index text label. indexLabel = AddUIComponent <UILabel>(); indexLabel.width = IndexWidth; indexLabel.textScale = TextScale; indexLabel.relativePosition = new Vector2(IndexLabelX, PaddingY); } // Add line sprite if we need to (initially hidden). if (lineSprite == null) { lineSprite = AddUIComponent <UISprite>(); lineSprite.size = new Vector2(17f, 17f); lineSprite.relativePosition = new Vector2(3f, 3f); lineSprite.Hide(); } // Set initial label position. labelX = LeftMargin; // See if our attached data is a PropListItem replacement record). if (data is TargetListItem targetListItem) { // Hide any existing line sprites; it will be re-shown as necessary. if (lineSprite != null) { lineSprite.Hide(); // Adjust name label position to accomodate. labelX += PackageMargin; } // Text to display - StringBuilder due to the amount of manipulation we're doing. StringBuilder displayText = new StringBuilder(); // Set local references. thisItem = targetListItem; index = thisItem.index; // See if this is a network prop. NetTargetListItem thisNetItem = data as NetTargetListItem; // Clear label text. indexLabel.text = ""; // Display index number if this is an individual reference. if (thisItem.index >= 0) { // Display lane marker if this is a network prop. if (thisNetItem != null) { indexLabel.text += thisNetItem.lane.ToString() + " "; // Adjust name label position to accomodate lane number. labelX += IndexWidth; } indexLabel.text += thisItem.index.ToString(); // Adjust name label position to accomodate index number. labelX += IndexWidth; } bool hasReplacement = false; // Check to see if there's a currently active individual replacement. if (thisItem.individualPrefab != null) { // A replacement is currently active - include it in the text. displayText.Append(PrefabLists.GetDisplayName(thisItem.individualPrefab)); // Append probability to the label, if we're showing it. if (thisItem.showProbs) { displayText.Append(" "); displayText.Append(thisItem.individualProb); displayText.Append("%"); } // Set flag. hasReplacement = true; // Show building replacement sprite. lineSprite.atlas = TextureUtils.LoadSpriteAtlas(thisNetItem == null ? "BOB-BuildingSmall" : "BOB-RoadSmall"); lineSprite.spriteName = "normal"; lineSprite.tooltip = Translations.Translate(thisNetItem == null ? "BOB_SPR_SBL" : "BOB_SPR_SNT"); lineSprite.Show(); } // If no current individual replacement, check to see if there's a currently active building/network replacement. else if (thisItem.replacementPrefab != null) { // A replacement is currently active - include it in the text. displayText.Append(PrefabLists.GetDisplayName(thisItem.replacementPrefab)); // Append probability to the label, if we're showing it. if (thisItem.showProbs) { displayText.Append(" "); displayText.Append(thisItem.replacementProb); displayText.Append("%"); } // Set flag. hasReplacement = true; // Show building replacement sprite. lineSprite.atlas = TextureUtils.LoadSpriteAtlas(thisNetItem == null ? "BOB-BuildingSmall" : "BOB-RoadSmall"); lineSprite.spriteName = "normal"; lineSprite.tooltip = Translations.Translate(thisNetItem == null ? "BOB_SPR_SBL" : "BOB_SPR_SNT"); lineSprite.Show(); } // If no current building/network replacement, check to see if any all- replacement is currently active. else if (thisItem.allPrefab != null) { // An all- replacement is currently active; append name to the label. displayText.Append(PrefabLists.GetDisplayName(thisItem.allPrefab)); // Append probability if this is not a network item and we're showing probs. if (thisNetItem == null && thisItem.showProbs) { displayText.Append(" "); displayText.Append(thisItem.allProb); displayText.Append("%"); } // Set flag. hasReplacement = true; // Show all- replacement sprite. lineSprite.atlas = TextureUtils.LoadSpriteAtlas(thisNetItem == null ? "BOB-BuildingsSmall" : "BOB-RoadsSmall"); lineSprite.spriteName = "normal"; lineSprite.tooltip = Translations.Translate(thisNetItem == null ? "BOB_SPR_ABL" : "BOB_SPR_ANT"); lineSprite.Show(); } // If no other replacements, chek to see if any pack replacement is currently active else if (thisItem.packagePrefab != null) { // Yes; append name to the label. displayText.Append(PrefabLists.GetDisplayName(thisItem.packagePrefab)); // Set flag. hasReplacement = true; // Show package replacement sprite. lineSprite.atlas = TextureUtils.LoadSpriteAtlas("BOB-PropPackSmall"); lineSprite.spriteName = "normal"; lineSprite.tooltip = Translations.Translate("BOB_SPR_PCK"); lineSprite.Show(); } // Do we have a replacement? if (hasReplacement) { // Yes; append "was" to the display name. displayText.Append("; "); displayText.Append(Translations.Translate("BOB_ROW_WAS")); displayText.Append(" "); } // Original prefab display name. displayText.Append(PrefabLists.GetDisplayName(thisItem.originalPrefab)); // Show original probability in brackets immediately afterwards. if (thisItem.showProbs) { displayText.Append(" ("); displayText.Append(thisItem.originalProb); displayText.Append("%)"); } // Set display text. nameLabel.text = displayText.ToString(); } // Set label position nameLabel.relativePosition = new Vector2(labelX, PaddingY); // Set initial background as deselected state. Deselect(isRowOdd); }