/// <summary> /// Sets the selection to the given random variation. /// If no item is found, clears the selection and resets the list. /// </summary> /// <param name="item">The item to find</param> public virtual void FindItem(BOBVariation variant) { // Iterate through the rows list. for (int i = 0; i < m_rowsData.m_size; ++i) { // Look for an index match; individual or grouped (contained within propListItem.indexes list). if (m_rowsData.m_buffer[i] is BOBVariation listItem && listItem == variant) { // Found a match; set the selected index to this one. selectedIndex = i; // If the selected index is outside the current visibility range, move the to show it. if (selectedIndex < listPosition || selectedIndex > listPosition + m_rows.m_size) { listPosition = selectedIndex; } // Done here; return. return; } } // If we got here, we didn't find a match; clear the selection and reset the list position. selectedIndex = -1; listPosition = 0f; }
/// <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 override void Display(object data, bool isRowOdd) { thisVariant = data as BOBVariation; // 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); } // Set label position, text and color. nameLabel.relativePosition = new Vector2(labelX, PaddingY); nameLabel.text = thisVariant?.DisplayName ?? "null"; nameLabel.textColor = thisVariant.prefab == null ? Color.gray : Color.white; // Set initial background as deselected state. Deselect(isRowOdd); // Probability locked sprite. if (lockSprite == null) { lockSprite = AddUIComponent <UISprite>(); lockSprite.size = new Vector2(17f, 17f); lockSprite.relativePosition = new Vector2(width - 20f, 3f); lockSprite.atlas = TextureUtils.LoadSpriteAtlas("BOB-Padlock"); SetLockSprite(); lockSprite.eventClicked += (control, clickEvent) => { if (thisVariant != null) { thisVariant.probLocked = !thisVariant.probLocked; SetLockSprite(); } }; } // Probability label. if (probLabel == null) { probLabel = AddUIComponent <UILabel>(); } probLabel.text = (thisVariant?.probability.ToString() ?? "0") + "%"; probLabel.relativePosition = new Vector2(width - 20f - 5f - probLabel.width, 3f); }