Example #1
0
        public ShrineUIPanel(float scale = 1f, float opacity = 1f) : base(scale, opacity)
        {
            Instance = this;

            Width.Set(width, 0);
            Height.Set(height, 0);
            Left.Set(Main.screenWidth / 2 - width, 0);
            Top.Set(Main.screenHeight / 2 - height, 0);
            SetPadding(0);
            BorderColor     = Microsoft.Xna.Framework.Color.Transparent;
            BackgroundColor = Microsoft.Xna.Framework.Color.Transparent;

            #region UI Initialization

            //Background
            CustomUIImage background =
                new CustomUIImage(GetTexture("LivingWorldMod/Textures/UIElements/ShrineMenu/Background"), 1f);
            background.Width.Set(0, 0);
            background.Height.Set(0f, 0);
            background.Left.Set(-12f, 0);
            background.Top.Set(-12f, 0);
            Append(background);

            //Cross to Close Menu
            CustomUIImage closeMenuCross =
                new CustomUIImage(GetTexture("LivingWorldMod/Textures/UIElements/ShrineMenu/CloseCross"), 1f);
            closeMenuCross.Width.Set(19f, 0);
            closeMenuCross.Height.Set(19f, 0);
            closeMenuCross.Left.Set(width - 35f, 0);
            closeMenuCross.Top.Set(-7f, 0);
            closeMenuCross.OnClick += (__, _) => Hide();
            Append(closeMenuCross);

            #region Item in itemSlot info

            //Gift Item Image
            CustomUIImage giftItem = new CustomUIImage(Main.itemTexture[0], 1f);
            giftItem.SetScaleToFit(true);
            giftItem.Left.Set(165f, 0);
            giftItem.Top.Set(35f, 0);
            Append(giftItem);
            giftItem.Hide();

            //Undiscovered Gift
            CustomUIText undiscoveredGift = new CustomUIText("?", 1f);
            undiscoveredGift.TextColor = Microsoft.Xna.Framework.Color.LightGray;
            undiscoveredGift.Left.Set(195f, 0);
            undiscoveredGift.Top.Set(40f, 0);
            Append(undiscoveredGift);
            undiscoveredGift.Hide();


            //Amount gifted
            CustomUIText giftAmount = new CustomUIText("", 0.9f);
            giftAmount.Left.Set(110f, 0);
            giftAmount.Top.Set(30f, 0);
            Append(giftAmount);
            giftAmount.Hide();


            //Liking Neutral
            CustomUIText giftLiking = new CustomUIText("", 0.9f);
            giftLiking.Left.Set(110f, 0);
            giftLiking.Top.Set(50f, 0);
            Append(giftLiking);
            giftLiking.Hide();

            #endregion

            //ItemSlot
            itemSlot = new CustomItemSlot();
            itemSlot.Width.Set(54f, 0);
            itemSlot.Height.Set(54f, 0);
            itemSlot.Left.Set(5f, 0);
            itemSlot.Top.Set(25f, 0);
            itemSlot.OnItemEquipped += _ => ShowItemSlotInfo();
            itemSlot.OnItemRemoved  += _ => HideItemSlotInfo();
            itemSlot.SetBackgroundTexture(GetTexture("LivingWorldMod/Textures/UIElements/ShrineMenu/ItemSlot"));
            Append(itemSlot);

            //Gift
            Texture2D     giftTexture  = GetTexture("LivingWorldMod/Textures/UIElements/ShrineMenu/Gift");
            Texture2D     giftTexture2 = GetTexture("LivingWorldMod/Textures/UIElements/ShrineMenu/Gift2");
            UIImageButton gift         = new UIImageButton(giftTexture);
            gift.Width.Set(26f, 0);
            gift.Height.Set(26f, 0);
            gift.Left.Set(66f, 0);
            gift.Top.Set(38f, 0);
            gift.SetVisibility(1f, 1f);
            gift.OnMouseOver += (__, _) => { gift.SetImage(giftTexture2); };
            gift.OnMouseOut  += (__, _) => { gift.SetImage(giftTexture); };
            gift.OnMouseDown += (__, _) =>
            {
                gift.Top.Set(gift.Top.Pixels + 1f, 0);
                GiftItem();
                HideItemSlotInfo();
            };
            gift.OnMouseUp += (__, _) => { gift.Top.Set(gift.Top.Pixels - 1f, 0); };
            Append(gift);

            //Gifts Text
            CustomUIText repText = new CustomUIText("Gifts: ", 0.8f);
            repText.Left.Set(8f, 0);
            repText.Top.Set(95f, 0);
            Append(repText);

            //Gifts ProgressBar
            Color             Color    = new Color(63, 113, 169);
            ShrineProgressBar repFrame = new ShrineProgressBar(true, 100, Color);
            repFrame.Width.Set(170f, 0);
            repFrame.Height.Set(16f, 0);
            repFrame.Left.Set(48f, 0);
            repFrame.Top.Set(95f, 0);
            repFrame.Activate();
            Append(repFrame);

            //Stage Text
            CustomUIText stageText = new CustomUIText("Stage: ", 0.8f);
            stageText.Left.Set(5f, 0);
            stageText.Top.Set(120f, 0);
            Append(stageText);

            //Stage ProgressBar
            ShrineProgressBar stageFrame = new ShrineProgressBar(false, 5, Color);
            stageFrame.Width.Set(170f, 0);
            stageFrame.Height.Set(16f, 0);
            stageFrame.Left.Set(48f, 0);
            stageFrame.Top.Set(120f, 0);
            stageFrame.Activate();
            Append(stageFrame);

            #region Methods

            void GiftItem()
            {
                int itemType = itemSlot.Item.type;

                LWMWorld.AddGiftToProgress(shrineType, itemType);
                itemSlot.Item.TurnToAir();
            }

            void ShowItemSlotInfo()
            {
                giftItem.SetImage(Main.itemTexture[itemSlot.Item.type]);
                giftItem.SetSize(24f, 24f);

                Color color;

                if (LWMWorld.GetGiftAmount(shrineType, itemSlot.Item.type) == 0)
                {
                    color = new Color(66, 66, 66);
                    giftItem.Show();
                    undiscoveredGift.Show();
                }
                else
                {
                    color = Microsoft.Xna.Framework.Color.White;
                }

                giftItem.SetOverlayColor(color);

                //Update Amount Gifted
                int    amount     = LWMWorld.GetGiftAmount(shrineType, itemSlot.Item.type);
                string amountText = "Gifted: " + (amount == 0 ? "" : amount.ToString());

                giftAmount.SetText(amountText);

                //Update Gift Liking
                int liking = LivingWorldMod.GetGiftValue(shrineType, itemSlot.Item.type);

                string likingText = "Liking: ";

                if (amount != 0 && Math.Abs(liking) == 3)
                {
                    likingText += liking > 0 ? "Good" : "Bad";
                }
                else if (amount != 0 && Math.Abs(liking) == 5)
                {
                    likingText += liking > 0 ? "Great" : "Awful";
                }
                else if (amount != 0 && liking == 0)
                {
                    likingText += "Neutral";
                }
                giftLiking.SetText(likingText);

                giftAmount.Show();
                giftLiking.Show();
            }

            void HideItemSlotInfo()
            {
                giftItem.Hide();
                giftAmount.Hide();
                giftLiking.Hide();
                undiscoveredGift.Hide();
            }

            #endregion

            #endregion
        }
Example #2
0
        public override void OnInitialize()
        {
            OldAverageColors.Add(new Color(1, 1, 1, 1));
            Background.HAlign = 0.7f;
            Background.VAlign = 0.5f;
            Append(Background);

            IngredientSlot[0] = new CustomItemSlot(0, 0.9f)
            {
                IsValidItem       = item => item.IsAir || !item.IsAir && PotionOverhaul.PotionIngredients.Contains(item.type),
                BackgroundTexture = backgroundTexture,
                EmptyTexture      = iconTextureIngredient,
                HoverText         = "Ingredient"
            };
            IngredientSlot[0].HAlign = 0.275f;
            IngredientSlot[0].VAlign = 0.125f;
            Background.Append(IngredientSlot[0]);
            IngredientSlot[1] = new CustomItemSlot(0, 0.9f)
            {
                IsValidItem       = item => item.IsAir || !item.IsAir && PotionOverhaul.PotionIngredients.Contains(item.type),
                BackgroundTexture = backgroundTexture,
                EmptyTexture      = iconTextureIngredient,
                HoverText         = "Ingredient"
            };
            IngredientSlot[1].HAlign = 0.50f;
            IngredientSlot[1].VAlign = 0.075f;
            Background.Append(IngredientSlot[1]);
            IngredientSlot[2] = new CustomItemSlot(0, 0.9f)
            {
                IsValidItem       = item => item.IsAir || !item.IsAir && PotionOverhaul.PotionIngredients.Contains(item.type),
                BackgroundTexture = backgroundTexture,
                EmptyTexture      = iconTextureIngredient,
                HoverText         = "Ingredient"
            };
            IngredientSlot[2].HAlign = 0.725f;
            IngredientSlot[2].VAlign = 0.125f;
            Background.Append(IngredientSlot[2]);

            PotionSlot = new CustomItemSlot(0, 0.9f)
            {
                IsValidItem       = item => item.IsAir,
                BackgroundTexture = backgroundTexture,
                EmptyTexture      = iconTexturePotion,
                HoverText         = "Potion"
            };
            PotionSlot.HAlign   = 0.50f;
            PotionSlot.VAlign   = 0.85f;
            PotionSlot.OnClick += OnPotionSlot;
            Background.Append(PotionSlot);

            NameBeingEdited.HAlign = 0.50f;
            NameBeingEdited.VAlign = 0.925f;
            Background.Append(NameBeingEdited);
            BrewButton.HAlign   = 0.50f;
            BrewButton.VAlign   = 0.45f;
            BrewButton.OnClick += OnBrewButton;
            Background.Append(BrewButton);
            SaveButton.HAlign   = 0.030f;
            SaveButton.VAlign   = 0.970f;
            SaveButton.OnClick += OnSaveButton;
            Background.Append(SaveButton);
            NameEditButton.HAlign   = 0.65f;
            NameEditButton.VAlign   = 0.825f;
            NameEditButton.OnClick += OnNameEdit;
            NameEditor              = new UIVirtualKeyboard("", PotionSlot.Item.Name, null, null, 0, false);
            NameEditor.HAlign       = 1f;
            NameEditor.VAlign       = 1f;
            NameEditor.RemoveAllChildren();

            OldIngredients = IngredientSlot.Select(e => e.Item.type).ToArray();
        }