コード例 #1
0
        private void fixSurfaces()
        {
            if (!fixedSurfaces)
            {
                Color origFill    = Water.FillColor;
                Color origSurface = Water.SurfaceColor;

                changeColor(fillColorField, origFill, fillColor);
                changeColor(surfaceColorField, origSurface, surfaceColor);

                bool hasTop    = Surfaces.Contains(TopSurface);
                bool hasBottom = Surfaces.Contains(BottomSurface);

                Surfaces.Clear();

                if (hasTop)
                {
                    TopSurface = new Water.Surface(Position + new Vector2(Width / 2f, 8f), new Vector2(0.0f, -1f), Width, Height);
                    Surfaces.Add(TopSurface);

                    actualTopSurface = TopSurface;
                    dummyTopSurface  = new Water.Surface(Position + new Vector2(Width / 2f, 8f), new Vector2(0.0f, -1f), Width, Height);
                }

                if (hasBottom)
                {
                    BottomSurface = new Water.Surface(Position + new Vector2(Width / 2f, Height - 8f), new Vector2(0.0f, 1f), Width, Height);
                    Surfaces.Add(BottomSurface);

                    actualBottomSurface = BottomSurface;
                    dummyBottomSurface  = new Water.Surface(Position + new Vector2(Width / 2f, Height - 8f), new Vector2(0.0f, 1f), Width, Height);
                }

                fixedSurfaces  = true;
                actualSurfaces = Surfaces;
                emptySurfaces  = new List <Surface>();

                changeColor(fillColorField, fillColor, origFill);
                changeColor(surfaceColorField, surfaceColor, origSurface);
            }
        }
コード例 #2
0
ファイル: ColoredWater.cs プロジェクト: Cruor/PandorasBox
        private void initializeSurfaces()
        {
            Color origFill    = Water.FillColor;
            Color origSurface = Water.SurfaceColor;

            changeColor(fillColorField, origFill, fillColor);
            changeColor(surfaceColorField, origSurface, surfaceColor);

            bool hasTop    = Surfaces.Contains(TopSurface);
            bool hasBottom = Surfaces.Contains(BottomSurface);

            Surfaces.Clear();

            if (hasTop)
            {
                TopSurface = new Water.Surface(Position + new Vector2(Width / 2f, 8f), new Vector2(0.0f, -1f), Width, Height);
                Surfaces.Add(TopSurface);

                actualTopSurface = TopSurface;
                dummyTopSurface  = new Water.Surface(Position + new Vector2(Width / 2f, 8f), new Vector2(0.0f, -1f), Width, Height);
            }

            if (hasBottom)
            {
                BottomSurface = new Water.Surface(Position + new Vector2(Width / 2f, Height - 8f), new Vector2(0.0f, 1f), Width, Height);
                Surfaces.Add(BottomSurface);

                actualBottomSurface = BottomSurface;
                dummyBottomSurface  = new Water.Surface(Position + new Vector2(Width / 2f, Height - 8f), new Vector2(0.0f, 1f), Width, Height);
            }

            if (hasLeftSurface)
            {
                LeftSurface = new Water.Surface(Position + new Vector2(8, Height / 2), new Vector2(-1f, 0f), Height, Width);
                Surfaces.Add(LeftSurface);

                actualLeftSurface = LeftSurface;
                dummyLeftSurface  = new Water.Surface(Position + new Vector2(8, Height / 2), new Vector2(-1f, 0f), Height, Width);
            }

            if (hasRightSurface)
            {
                RightSurface = new Water.Surface(Position + new Vector2(Width - 8, Height / 2), new Vector2(1f, 0f), Height, Width);
                Surfaces.Add(RightSurface);

                actualRightSurface = RightSurface;
                dummyRightSurface  = new Water.Surface(Position + new Vector2(Width - 8, Height / 2), new Vector2(1f, 0f), Height, Width);
            }

            // Update fill rectangle
            if (!hasUpdatedFill && (hasLeftSurface || hasRightSurface))
            {
                Rectangle fill     = (Rectangle)fillField.GetValue(this);
                int       newX     = fill.X;
                int       newWidth = fill.Width;

                if (hasLeftSurface)
                {
                    newX     += 8;
                    newWidth -= 8;
                }

                if (hasRightSurface)
                {
                    newWidth -= 8;
                }

                Rectangle newFill = new Rectangle(newX, fill.Y, newWidth, fill.Height);

                fillField.SetValue(this, newFill);

                hasUpdatedFill = true;
            }

            actualSurfaces = Surfaces;
            emptySurfaces  = new List <Surface>();

            changeColor(fillColorField, fillColor, origFill);
            changeColor(surfaceColorField, surfaceColor, origSurface);
        }