Exemplo n.º 1
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");
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adds an icon toggle checkbox.
        /// </summary>
        /// <param name="parent">Parent component</param>
        /// <param name="xPos">Relative X position</param>
        /// <param name="yPos">Relative Y position</param>
        /// <param name="atlasName">Atlas name (for loading from file)</param>
        /// <param name="tooltipKey">Tooltip translation key</param>
        /// <returns>New checkbox</returns>
        protected UICheckBox IconToggleCheck(UIComponent parent, float xPos, float yPos, string atlasName, string tooltipKey)
        {
            // Size and position.
            UICheckBox checkBox = parent.AddUIComponent <UICheckBox>();

            checkBox.width            = ToggleSize;
            checkBox.height           = ToggleSize;
            checkBox.clipChildren     = true;
            checkBox.relativePosition = new Vector2(xPos, yPos);

            // Checkbox sprites.
            UISprite sprite = checkBox.AddUIComponent <UISprite>();

            sprite.name             = "UncheckedSprite";
            sprite.atlas            = TextureUtils.LoadSpriteAtlas(atlasName);
            sprite.spriteName       = "disabled";
            sprite.size             = new Vector2(ToggleSize, ToggleSize);
            sprite.relativePosition = Vector3.zero;

            checkBox.checkedBoxObject = sprite.AddUIComponent <UISprite>();
            ((UISprite)checkBox.checkedBoxObject).atlas      = TextureUtils.LoadSpriteAtlas(atlasName);
            ((UISprite)checkBox.checkedBoxObject).spriteName = "pressed";
            checkBox.checkedBoxObject.size             = new Vector2(ToggleSize, ToggleSize);
            checkBox.checkedBoxObject.relativePosition = Vector3.zero;

            checkBox.tooltip = Translations.Translate(tooltipKey);

            return(checkBox);
        }
Exemplo n.º 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-Props") : TextureUtils.LoadSpriteAtlas("BOB-Trees");
            replaceButton.tooltip = Translations.Translate(ReplaceTooltipKey);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Constructor.
        /// </summary>
        internal BOBMapInfoPanel()
        {
            try
            {
                // Replace button.
                replaceButton = AddIconButton(this, MidControlX, ReplaceY, BigIconSize, ReplaceTooltipKey, TextureUtils.LoadSpriteAtlas("BOB-Trees"));
                replaceButton.eventClicked += Replace;

                // Populate loaded list.
                LoadedList();
            }
            catch (Exception e)
            {
                // Log and report any exception.
                Logging.LogException(e, "exception creating map panel");
            }
        }
Exemplo n.º 6
0
        /// <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");
            }
        }
Exemplo n.º 7
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 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);
        }