Example #1
0
        /// <summary>
        /// Updates the target item record for changes in replacement status (e.g. after applying or reverting changes).
        /// </summary>
        /// <param name="propListItem">Target item</param>
        protected override void UpdateTargetItem(PropListItem propListItem)
        {
            // Determine index to test - if no individaul index, just grab first one from list.
            int propIndex = propListItem.index;

            if (propIndex < 0)
            {
                propIndex = propListItem.indexes[0];
            }

            // All-building replacement and original probability (if any).
            BOBBuildingReplacement allBuildingReplacement = AllBuildingReplacement.instance.ActiveReplacement(currentBuilding, propIndex);

            if (allBuildingReplacement != null)
            {
                propListItem.allPrefab = allBuildingReplacement.replacementInfo;
                propListItem.allProb   = allBuildingReplacement.probability;
            }
            else
            {
                // If no active current record, ensure that it's reset to null.
                propListItem.allPrefab = null;
            }

            // Building replacement and original probability (if any).
            BOBBuildingReplacement buildingReplacement = BuildingReplacement.instance.ActiveReplacement(currentBuilding, propIndex);

            if (buildingReplacement != null)
            {
                propListItem.replacementPrefab = buildingReplacement.replacementInfo;
                propListItem.replacementProb   = buildingReplacement.probability;
            }
            else
            {
                // If no active current record, ensure that it's reset to null.
                propListItem.replacementPrefab = null;
            }

            // Individual replacement and original probability (if any).
            BOBBuildingReplacement individualReplacement = IndividualReplacement.instance.ActiveReplacement(currentBuilding, propIndex);

            if (individualReplacement != null)
            {
                propListItem.individualPrefab = individualReplacement.replacementInfo;
                propListItem.individualProb   = individualReplacement.probability;
            }
            else
            {
                // If no active current record, ensure that it's reset to null.
                propListItem.individualPrefab = null;
            }
        }
Example #2
0
        /// <summary>
        /// Updates the target item record for changes in replacement status (e.g. after applying or reverting changes).
        /// </summary>
        /// <param name="propListItem">Target item</param>
        protected override void UpdateTargetItem(PropListItem propListItem)
        {
            if (propListItem is NetPropListItem netItem)
            {
                // Determine lane and index to test - just grab first one from list.
                int lane      = netItem.lanes[0];
                int propIndex = netItem.indexes[0];

                // All-network replacement and original probability (if any).
                BOBNetReplacement allNetReplacement = AllNetworkReplacement.instance.ActiveReplacement(currentNet, lane, propIndex);
                if (allNetReplacement != null)
                {
                    propListItem.allPrefab = allNetReplacement.replacementInfo;
                    propListItem.allProb   = allNetReplacement.probability;
                }
                else
                {
                    // If no active current record, ensure that it's reset to null.
                    propListItem.allPrefab = null;
                }

                // Individual network replacement and original probability (if any).
                BOBNetReplacement netReplacement = NetworkReplacement.instance.ActiveReplacement(currentNet, lane, propIndex);
                if (netReplacement != null)
                {
                    propListItem.replacementPrefab = netReplacement.replacementInfo;
                    propListItem.replacementProb   = netReplacement.probability;
                }
                else
                {
                    // If no active current record, ensure that it's reset to null.
                    propListItem.replacementPrefab = null;
                }

                // Replacement pack replacement and original probability (if any).
                BOBNetReplacement packReplacement = PackReplacement.instance.ActiveReplacement(currentNet, lane, propIndex);
                if (packReplacement != null)
                {
                    propListItem.packagePrefab = packReplacement.replacementInfo;
                }
                else
                {
                    // If no active current record, ensure that it's reset to null.
                    propListItem.packagePrefab = null;
                }
            }
        }
Example #3
0
        /// <summary>
        /// Generates and displays a building 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 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 raw PropInfo (e.g an available prop item as opposed to a PropListItem replacment record).
            thisPrefab = data as PrefabInfo;
            if (thisPrefab == null)
            {
                // 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();

                // Not a raw PropInfo, so it should be a PropListItem replacement record.
                // Set local references.
                thisItem = data as PropListItem;
                index    = thisItem.index;

                // See if this is a network prop.
                NetPropListItem thisNetItem = data as NetPropListItem;

                // Display index number if this is an individual reference.
                if (thisItem.index >= 0)
                {
                    indexLabel.text = thisItem.index.ToString();

                    // Adjust name label position to accomodate.
                    labelX += IndexWidth;
                }
                else
                {
                    indexLabel.text = "";
                }

                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.name));

                    // 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;
                }
                // 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.name));

                    // 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_single_building_small" : "bob_road_small");
                    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.name));

                    // 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_buildings_small" : "bob_all_roads_small");
                    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.name));

                    // Set flag.
                    hasReplacement = true;

                    // Show package replacement sprite.
                    lineSprite.atlas      = TextureUtils.LoadSpriteAtlas("bob_prop_pack_small");
                    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.name));

                // 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();
            }
            else
            {
                // Attached data is a raw PropInfo; just display its (cleaned-up) name.
                nameLabel.text = PrefabLists.GetDisplayName(thisPrefab.name);
            }

            // Set label position
            nameLabel.relativePosition = new Vector2(labelX, PaddingY);

            // Set initial background as deselected state.
            Deselect(isRowOdd);
        }
Example #4
0
        /// <summary>
        /// Populates the target list with a list of map trees or props.
        /// </summary>
        protected override void TargetList()
        {
            // List of prefabs that have passed filtering.
            List <PropListItem> itemList = new List <PropListItem>();

            // Local references.
            TreeManager treeManager = Singleton <TreeManager> .instance;

            TreeInstance[] trees       = treeManager.m_trees.m_buffer;
            PropManager    propManager = Singleton <PropManager> .instance;

            PropInstance[] props = propManager.m_props.m_buffer;

            // Iterate through each tree instance map.
            for (int index = 0; index < (IsTree ? trees.Length : props.Length); ++index)
            {
                // Create new list item, hiding probabilities.
                PropListItem propListItem = new PropListItem {
                    showProbs = false
                };

                if (IsTree)
                {
                    // Local reference.
                    TreeInstance tree = trees[index];

                    // Skip non-existent trees (those with no flags).
                    if (tree.m_flags == (ushort)TreeInstance.Flags.None)
                    {
                        continue;
                    }

                    // Try to get any tree replacement.
                    propListItem.originalPrefab = MapTreeReplacement.instance.GetOriginal(tree.Info);

                    // DId we find a current replacment?
                    if (propListItem.originalPrefab == null)
                    {
                        // No - set current item as the original tree.
                        propListItem.originalPrefab = tree.Info;
                    }
                    else
                    {
                        // Yes - record current item as replacement.
                        propListItem.replacementPrefab = tree.Info;
                    }
                }
                else
                {
                    // Props.
                    PropInstance prop = props[index];

                    // Skip non-existent props (those with no flags).
                    if (prop.m_flags == (ushort)PropInstance.Flags.None)
                    {
                        continue;
                    }

                    // Try to get any prop replacement.
                    propListItem.originalPrefab = MapPropReplacement.instance.GetOriginal(prop.Info);

                    // DId we find a current replacment?
                    if (propListItem.originalPrefab == null)
                    {
                        // No - set current item as the original prop.
                        propListItem.originalPrefab = prop.Info;
                    }
                    else
                    {
                        // Yes - record current item as replacement.
                        propListItem.replacementPrefab = prop.Info;
                    }
                }

                // Check to see if we were succesful - if not (e.g. we only want trees and this is a prop), continue on to next instance.
                if (propListItem.originalPrefab?.name == null)
                {
                    continue;
                }

                // Map instances are always grouped, and we don't have lists of indexes - too many trees!
                propListItem.index = -1;

                // Are we grouping?
                if (propListItem.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 (PropListItem item in itemList)
                    {
                        // Check to see if we already have this in the list - matching original prefab.
                        if (item.originalPrefab == propListItem.originalPrefab)
                        {
                            // We've already got an identical grouped instance of this item - set the flag to indicate that we've match it.
                            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 tree (without adding this item separately to the list).
                        continue;
                    }
                }

                // Add this item to our list.
                itemList.Add(propListItem);
            }

            // Create return fastlist from our filtered list, ordering by name.
            targetList.m_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 (targetList.m_rowsData.m_size == 0)
            {
                noPropsLabel.Show();
            }
            else
            {
                noPropsLabel.Hide();
            }
        }
Example #5
0
        /// <summary>
        /// Populates the target fastlist with a list of target-specific trees or props.
        /// </summary>
        protected override void TargetList()
        {
            System.Diagnostics.Stopwatch targetStopwatch = new System.Diagnostics.Stopwatch();
            targetStopwatch.Start();

            // Clear current selection.
            targetList.selectedIndex = -1;

            // List of prefabs that have passed filtering.
            List <PropListItem> propList = new List <PropListItem>();

            // Check to see if this building contains any props.
            if (currentBuilding.m_props == null || currentBuilding.m_props.Length == 0)
            {
                // No props - show 'no props' label and return an empty list.
                noPropsLabel.Show();
                targetList.m_rowsData = new FastList <object>();
                return;
            }


            // Iterate through each prop in building.
            for (int propIndex = 0; propIndex < currentBuilding.m_props.Length; ++propIndex)
            {
                // Create new list item.
                PropListItem propListItem = new PropListItem();

                // Try to get relevant prefab (prop/tree), using finalProp.
                PrefabInfo finalInfo = IsTree ? (PrefabInfo)currentBuilding.m_props[propIndex]?.m_finalTree : (PrefabInfo)currentBuilding.m_props[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;
                }

                // Grouped or individual?
                if (indCheck.isChecked)
                {
                    // Individual - set index to the current building prop indexes.
                    propListItem.index = propIndex;
                }
                else
                {
                    // Grouped - set index to -1 and add to our list of indexes.
                    propListItem.index = -1;
                    propListItem.indexes.Add(propIndex);
                }

                // Get original (pre-replacement) tree/prop prefab and current probability (as default original probability).
                propListItem.originalPrefab = BuildingReplacement.instance.GetOriginal(currentBuilding, propIndex) ?? AllBuildingReplacement.instance.GetOriginal(currentBuilding, propIndex) ?? finalInfo;
                propListItem.originalProb   = currentBuilding.m_props[propIndex].m_probability;
                propListItem.originalAngle  = (currentBuilding.m_props[propIndex].m_radAngle * 180f) / Mathf.PI;

                // All-building replacement and original probability (if any).
                BOBBuildingReplacement allBuildingReplacement = AllBuildingReplacement.instance.ActiveReplacement(currentBuilding, propIndex);
                if (allBuildingReplacement != null)
                {
                    propListItem.allPrefab = allBuildingReplacement.replacementInfo;
                    propListItem.allProb   = allBuildingReplacement.probability;
                }

                // Building replacement and original probability (if any).
                BOBBuildingReplacement buildingReplacement = BuildingReplacement.instance.ActiveReplacement(currentBuilding, propIndex);
                if (buildingReplacement != null)
                {
                    propListItem.replacementPrefab = buildingReplacement.replacementInfo;
                    propListItem.replacementProb   = buildingReplacement.probability;
                }

                // Individual replacement and original probability (if any).
                BOBBuildingReplacement individualReplacement = IndividualReplacement.instance.ActiveReplacement(currentBuilding, propIndex);
                if (individualReplacement != null)
                {
                    propListItem.individualPrefab = individualReplacement.replacementInfo;
                    propListItem.individualProb   = individualReplacement.probability;
                }

                // Are we grouping?
                if (propListItem.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 (PropListItem item in propList)
                    {
                        // Check to see if we already have this in the list - matching original prefab, building replacement prefab, all-building replacement prefab, and probability.
                        if (item.originalPrefab == propListItem.originalPrefab && item.individualPrefab == propListItem.individualPrefab && item.replacementPrefab == propListItem.replacementPrefab && propListItem.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);
                            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 building prop (without adding this item separately to the list).
                        continue;
                    }
                }

                // Add this item to our list.
                propList.Add(propListItem);
            }

            Logging.Message("basic target list setup time ", targetStopwatch.ElapsedMilliseconds.ToString());

            // Create return fastlist from our filtered list, ordering by name.
            targetList.m_rowsData = new FastList <object>
            {
                m_buffer = targetSearchStatus == (int)OrderBy.NameDescending ? propList.OrderByDescending(item => item.DisplayName).ToArray() : propList.OrderBy(item => item.DisplayName).ToArray(),
                m_size   = propList.Count
            };
            targetList.Refresh();

            // If the list is empty, show the 'no props' label; otherwise, hide it.
            if (targetList.m_rowsData.m_size == 0)
            {
                noPropsLabel.Show();
            }
            else
            {
                noPropsLabel.Hide();
            }

            targetStopwatch.Stop();
            Logging.Message("target list sort time ", targetStopwatch.ElapsedMilliseconds.ToString());
        }
Example #6
0
        /// <summary>
        /// Performs initial setup
        /// </summary>
        /// <param name="parentTransform">Parent transform</param>
        /// <param name="targetPrefabInfo">Currently selected target prefab</param>
        internal override void Setup(Transform parentTransform, PrefabInfo targetPrefabInfo)
        {
            System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
            stopwatch.Start();

            // Set target reference.
            currentBuilding = targetPrefabInfo as BuildingInfo;

            // Base setup.
            base.Setup(parentTransform, targetPrefabInfo);

            Logging.Message("base setup time ", stopwatch.ElapsedMilliseconds.ToString());

            // Add group checkbox.
            indCheck = UIControls.LabelledCheckBox(this, 155f, TitleHeight + Margin, Translations.Translate("BOB_PNL_IND"), 12f, 0.7f);

            // Does this building have sub-buildings?
            if (currentBuilding.m_subBuildings != null && currentBuilding.m_subBuildings.Length > 0)
            {
                // Yes - create lists of sub-buildings (names and infos).
                int      numSubs          = currentBuilding.m_subBuildings.Length;
                int      numChoices       = numSubs + 1;
                string[] subBuildingNames = new string[numChoices];
                subBuildings        = new BuildingInfo[numChoices];
                subBuildingNames[0] = PrefabLists.GetDisplayName(currentBuilding.name);
                subBuildings[0]     = currentBuilding;

                for (int i = 0; i < numSubs; ++i)
                {
                    subBuildingNames[i + 1] = PrefabLists.GetDisplayName(currentBuilding.m_subBuildings[i].m_buildingInfo.name);
                    subBuildings[i + 1]     = currentBuilding.m_subBuildings[i].m_buildingInfo;
                }

                // Add sub-building menu.
                subBuildingMenu = UIControls.AddLabelledDropDown(this, 155f, indCheck.relativePosition.y + indCheck.height + (Margin / 2f), Translations.Translate("BOB_PNL_SUB"), 250f, 20f, 0.7f, 15, 4);
                subBuildingMenu.listBackground = "GenericPanelDark";
                subBuildingMenu.items          = subBuildingNames;
                subBuildingMenu.selectedIndex  = 0;

                // Sub-building menu event handler.
                subBuildingMenu.eventSelectedIndexChanged += (control, index) =>
                {
                    // Set current building.
                    currentBuilding = subBuildings[index];

                    // Reset current items.
                    CurrentTargetItem = null;
                    replacementPrefab = null;

                    // Reset loaded lists.
                    LoadedList();
                    TargetList();
                };
            }

            // Event handler for group checkbox.
            indCheck.eventCheckChanged += (control, isChecked) =>
            {
                // Rebuild target list.
                TargetList();

                // Clear selection.
                targetList.selectedIndex = -1;
                CurrentTargetItem        = null;

                // Store current group state as most recent state.
                ModSettings.lastInd = isChecked;

                // Toggle replace all button visibility.
                if (isChecked)
                {
                    replaceAllButton.Hide();
                }
                else
                {
                    replaceAllButton.Show();
                }
            };

            // Set grouped checkbox initial state according to preferences.
            switch (ModSettings.indDefault)
            {
            case 0:
                // Most recent state.
                indCheck.isChecked = ModSettings.lastInd;
                break;

            case 1:
                // Grouping off by default.
                indCheck.isChecked = false;
                break;

            case 2:
                // Grouping on by default.
                indCheck.isChecked = true;
                break;
            }

            // Populate target list and select target item.
            TargetList();

            Logging.Message("building setup time ", stopwatch.ElapsedMilliseconds.ToString());

            // Apply Harmony rendering patches.
            RenderOverlays.CurrentBuilding = selectedPrefab as BuildingInfo;
            Patcher.PatchBuildingOverlays(true);

            stopwatch.Stop();
            Logging.Message("Harmony patching time ", stopwatch.ElapsedMilliseconds.ToString());
        }