Exemplo n.º 1
0
        private Vector2 CalculateSize()
        {
            if (GrowableSeeds.All(s => s == null))
            {
                return(Vector2.Zero);
            }

            Point     pos  = item.DrawPosition.ToPoint();
            Rectangle rect = new Rectangle(pos, Point.Zero);

            for (int i = 0; i < GrowableSeeds.Length; i++)
            {
                Growable  seed = GrowableSeeds[i];
                PlantSlot slot = PlantSlots.ContainsKey(i) ? PlantSlots[i] : NullSlot;
                if (seed == null)
                {
                    continue;
                }

                foreach (VineTile vine in seed.Vines)
                {
                    Rectangle worldRect = vine.Rect;
                    worldRect.Location += slot.Offset.ToPoint();
                    worldRect.Location += pos;
                    rect = Rectangle.Union(rect, worldRect);
                }
            }

            Vector2 result = new Vector2(MaxDistance(pos.X, rect.Left, rect.Right) * 2, MaxDistance(pos.Y, rect.Top, rect.Bottom) * 2);

            return(result);
Exemplo n.º 2
0
        public void CreateDebugHUD(Planter planter, PlantSlot slot)
        {
            Vector2       relativeSize = new Vector2(0.3f, 0.6f);
            GUIMessageBox msgBox       = new GUIMessageBox(item.Name, "", new[] { TextManager.Get("applysettingsbutton") }, relativeSize);

            GUILayoutGroup content = new GUILayoutGroup(new RectTransform(new Vector2(1f, 0.85f), msgBox.Content.RectTransform))
            {
                Stretch = true
            };
            GUINumberInput seedInput         = CreateIntEntry("Random Seed", seed, content.RectTransform);
            GUINumberInput vineTileSizeInput = CreateIntEntry("Vine Tile Size (Global)", VineTile.Size, content.RectTransform);

            GUINumberInput[] leafScaleRangeInput   = CreateMinMaxEntry("Leaf Scale Range (Global)", new [] { MinLeafScale, MaxLeafScale }, 1.5f, content.RectTransform);
            GUINumberInput[] flowerScaleRangeInput = CreateMinMaxEntry("Flower Scale Range (Global)", new [] { MinFlowerScale, MaxFlowerScale }, 1.5f, content.RectTransform);
            GUINumberInput   vineCountInput        = CreateIntEntry("Vine Count", MaximumVines, content.RectTransform);
            GUINumberInput   vineScaleInput        = CreateFloatEntry("Vine Scale", VineScale, content.RectTransform);
            GUINumberInput   flowerInput           = CreateIntEntry("Flower Quantity", FlowerQuantity, content.RectTransform);
            GUINumberInput   flowerScaleInput      = CreateFloatEntry("Flower Scale", BaseFlowerScale, content.RectTransform);
            GUINumberInput   leafScaleInput        = CreateFloatEntry("Leaf Scale", BaseLeafScale, content.RectTransform);
            GUINumberInput   leafProbabilityInput  = CreateFloatEntry("Leaf Probability", LeafProbability, content.RectTransform);

            GUINumberInput[] leafTintInputs   = CreateMinMaxEntry("Leaf Tint", new [] { LeafTint.R / 255f, LeafTint.G / 255f, LeafTint.B / 255f }, 1.0f, content.RectTransform);
            GUINumberInput[] flowerTintInputs = CreateMinMaxEntry("Flower Tint", new [] { FlowerTint.R / 255f, FlowerTint.G / 255f, FlowerTint.B / 255f }, 1.0f, content.RectTransform);
            GUINumberInput[] vineTintInputs   = CreateMinMaxEntry("Branch Tint", new [] { VineTint.R / 255f, VineTint.G / 255f, VineTint.B / 255f }, 1.0f, content.RectTransform);

            // Apply
            msgBox.Buttons[0].OnClicked = (button, o) =>
            {
                seed            = seedInput.IntValue;
                MaximumVines    = vineCountInput.IntValue;
                FlowerQuantity  = flowerInput.IntValue;
                BaseFlowerScale = flowerScaleInput.FloatValue;
                VineScale       = vineScaleInput.FloatValue;
                BaseLeafScale   = leafScaleInput.FloatValue;
                LeafProbability = leafProbabilityInput.FloatValue;
                VineTile.Size   = vineTileSizeInput.IntValue;

                MinFlowerScale = flowerScaleRangeInput[0].FloatValue;
                MaxFlowerScale = flowerScaleRangeInput[1].FloatValue;
                MinLeafScale   = leafScaleRangeInput[0].FloatValue;
                MaxLeafScale   = leafScaleRangeInput[1].FloatValue;

                LeafTint   = new Color(leafTintInputs[0].FloatValue, leafTintInputs[1].FloatValue, leafTintInputs[2].FloatValue);
                FlowerTint = new Color(flowerTintInputs[0].FloatValue, flowerTintInputs[1].FloatValue, flowerTintInputs[2].FloatValue);
                VineTint   = new Color(vineTintInputs[0].FloatValue, vineTintInputs[1].FloatValue, vineTintInputs[2].FloatValue);

                if (FlowerQuantity >= MaximumVines - 1)
                {
                    vineCountInput.Flash(Color.Red);
                    flowerInput.Flash(Color.Red);
                    return(false);
                }

                if (MinFlowerScale > MaxFlowerScale)
                {
                    foreach (GUINumberInput input in flowerScaleRangeInput)
                    {
                        input.Flash(Color.Red);
                    }

                    return(false);
                }

                if (MinLeafScale > MaxLeafScale)
                {
                    foreach (GUINumberInput input in leafScaleRangeInput)
                    {
                        input.Flash(Color.Red);
                    }

                    return(false);
                }

                msgBox.Close();

                Random random       = new Random(seed);
                Random flowerRandom = new Random(seed);
                Vines.Clear();
                GenerateFlowerTiles(flowerRandom);
                GenerateStem();

                Decayed    = false;
                FullyGrown = false;
                while (MaximumVines > Vines.Count)
                {
                    if (!CanGrowMore())
                    {
                        Decayed = true;
                        break;
                    }

                    TryGenerateBranches(planter, slot, random, flowerRandom);
                }

                if (!Decayed)
                {
                    FullyGrown = true;
                }

                foreach (VineTile vineTile in Vines)
                {
                    vineTile.GrowthStep = 2.0f;
                }

                return(true);
            };
        }