コード例 #1
0
ファイル: NetInfoPanel.cs プロジェクト: Alexof/BOB
        /// <summary>
        /// Constructor.
        /// </summary>
        internal BOBNetInfoPanel()
        {
            try
            {
                // Add pack button.
                UIButton packButton = AddIconButton(this, PackButtonX, ToggleY, ToggleSize, "BOB_PNL_PKB", TextureUtils.LoadSpriteAtlas("BOB-PropPack"));
                packButton.eventClicked += (component, clickEvent) => PackPanelManager.Create();

                // Populate loaded list.
                LoadedList();
            }
            catch (Exception e)
            {
                // Log and report any exception.
                Logging.LogException(e, "exception creating network panel");
            }
        }
コード例 #2
0
        /// <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);
        }
コード例 #3
0
        /// <summary>
        /// Prop check event handler.
        /// </summary>
        /// <param name="control">Calling component (unused)</param>
        /// <param name="isChecked">New checked state</param>
        protected override void PropCheckChanged(UIComponent control, bool isChecked)
        {
            base.PropCheckChanged(control, isChecked);

            // Toggle replace button atlas.
            replaceButton.atlas = isChecked ? TextureUtils.LoadSpriteAtlas("bob_props3_large") : TextureUtils.LoadSpriteAtlas("bob_trees");
        }
コード例 #4
0
ファイル: UIPropRowTypes.cs プロジェクト: Alexof/BOB
        /// <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);
        }