public static Tuple<Direction, Direction, Vector2> GetCorrectionVector(this Rectangle rect, Rectangle target)
        {
            Vector2 vector = new Vector2();
            Direction directionX = Direction.Unknown;
            Direction directionY = Direction.Unknown;

            float x1 = Math.Abs(rect.Right - target.Left);
            float x2 = Math.Abs(rect.Left - target.Right);
            float y1 = Math.Abs(rect.Bottom - target.Top);
            float y2 = Math.Abs(rect.Top - target.Bottom);

            if (x1 < x2)
            {
                vector.X = x1;
                directionX = Direction.Left;
            }
            else if (x1 > x2)
            {
                vector.X = x2;
                directionX = Direction.Right;
            }

            if (y1 < y2)
            {
                vector.Y = y1;
                directionY = Direction.Up;
            }
            else if (y1 > y2)
            {
                vector.Y = y2;
                directionY = Direction.Down;
            }

            return new Tuple<Direction, Direction, Vector2>(directionX, directionY, vector);
        }
Exemple #2
1
        public override void Draw(GameTime gameTime)
        {
            SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
            SpriteFont font = ScreenManager.TopScoresFont;

            ScreenManager.FadeBackBufferToBlack(TransitionAlpha * 2 / 3);

            Viewport viewport = ScreenManager.GraphicsDevice.Viewport;
            Vector2 viewportSize = new Vector2(viewport.Width, viewport.Height);
            Vector2 messageSize = font.MeasureString(message);
            Vector2 messagePosition = (viewportSize - messageSize) / 2;

            const int hPad = 32;
            const int vPad = 16;
            Rectangle backgroundRectangle = new Rectangle((int)messagePosition.X - hPad,
                                                          (int)messagePosition.Y - vPad,
                                                          (int)messageSize.X + hPad * 2,
                                                          (int)messageSize.Y + vPad * 2);

            Color color = Color.White * TransitionAlpha;

            spriteBatch.Begin();
            spriteBatch.Draw(questionFrameTex, backgroundRectangle, color);
            spriteBatch.DrawString(font, message, messagePosition, color);
            spriteBatch.End();
        }
        public MapTile(Texture2D texture, int type, int x, int y, int size)
        {
            this.TileTexture = texture;

            // Changes which column of the sprite sheet the game uses to draw
            int blockX = size * SpriteSheetXOffset;
            this.TileColour = Color.White;
            switch (type)
            {
                case 0: break;
                case 1: this.RectSlice = new Rectangle(blockX, size * 1, size, size); this.IsSolid = true; break;
                case 2: this.RectSlice = new Rectangle(blockX, size * 2, size, size); this.IsSolid = true; this.IsSpring = true; break;
                case 3: this.RectSlice = new Rectangle(blockX, size * 3, size, size); this.IsSolid = true; break;
                case 4: this.RectSlice = new Rectangle(blockX, size * 4, size, size); this.IsSolid = true; break;
                case 5: this.RectSlice = new Rectangle(blockX, size * 5, size, size); this.IsSolid = true; break;
                case 6: this.RectSlice = new Rectangle(blockX, size * 6, size, size); this.IsSolid = true; break;
                case 7:
                    this.RectSlice = new Rectangle(blockX, size * 7, size, size); this.IsSolid = false;
                    this.TileColour = new Color(255, 255, 255, 20);
                    this.IsWater = true;
                    break;
                default: this.RectSlice = new Rectangle(blockX, size * 0, size, size); this.IsSolid = true; break;
            }
            this.Width = size;
            this.Height = size;
            this.PositionRect = new Rectangle(x, y, this.Width, this.Height);
        }
 public Notification(GameFacet facet, Rectangle location, string text)
     : base(facet)
 {
     this.text = text;
     this.location = location;
     alpha = 255;
 }
Exemple #5
1
        public void Init(ContentManager content, Vector2 position, string normalTextureName, string hoverTextureName)
        {
            m_Normal = content.Load<Texture2D>(normalTextureName);
            m_Hover = content.Load<Texture2D>(hoverTextureName);

            m_ButtonRec = new Rectangle((int)position.X, (int)position.Y, m_Normal.Width, m_Normal.Height);
        }
        public void Update(GameTime gameTime)
        {
            position.X += Velocidade * direcao;

            Rect = new Rectangle((int)position.X, (int)position.Y, sprite.Width, sprite.Height);

            #region Movimentacao
            //position.X = MathHelper.Clamp((float)position.X, 0, viewportRect.Width - sprite.Width);

            if (position.X >= Game1.viewportRect.Width - sprite.Width)
            {
                position.X = Game1.viewportRect.Width - sprite.Width - 1;
                NaveFilho.direcao *= -1;
            }

            if (position.X <= 0)
            {
                position.X = +1;
                NaveFilho.direcao *= -1;
            }

            #endregion

            if (boolVermelhidao)
            {

                Vermelhidao(gameTime);
            }
        }
Exemple #7
1
        public void MouseClicked(int x, int y, ref GameType gameType)
        {
            mouseClick = new Rectangle(x, y, 10, 10);

            if (mouseClick.Intersects(Bouton_host))
            {
                c = new Client();
                Thread t = new Thread(new ThreadStart(Program2.Mainq));
                t.Start();
                t.IsBackground = true;
            }
            if (mouseClick.Intersects(Bouton_Exit))
            {
                Game1.GetGame().Exit();
            }
            else if (mouseClick.Intersects(Bouton_Options))
            {
                gameType = GameType.Menu_Option_Type;
            }
            else if (mouseClick.Intersects(Bouton_Multi))
            {
                gameType = GameType.Menu_Play_Multi_Type2;
            }
            else if (mouseClick.Intersects(Bouton_Play))
            {
                gameType = GameType.Menu_Play_Type;
            }
            else if (mouseClick.Intersects(Bouton_Solo))
            {
                gameType = GameType.Menu_Play_Solo_Type;
            }
        }
Exemple #8
1
        public Paddle(ContentManager theContent, string theAssetName, Input theInput, PaddlePosition thePosition)
            : base(theContent, theAssetName)
        {
            SourceRectangle = new Rectangle(0, 0, 1, 1);
            Scale = new Vector2(10.0f, 100.0f);
            mColor = Color.SlateBlue;

            mPaddlePosition = thePosition;
            switch (thePosition)
            {
                case PaddlePosition.Left:
                    {
                        Boundary = new Rectangle(140, 185, 10, 833);
                        break;
                    }

                case PaddlePosition.Right:
                    {
                        Boundary = new Rectangle(1130, 185, 10, 833);
                        break;
                    }
            }

            Position = Center(Boundary);

            mInput = theInput;
        }
        public ArtilleryTower(World world, Rectangle towerBase)
            : base(world, towerBase)
        {
            textureMM = world.texMMartillery;
            texture = world.texTowerArty;
            name = "Artillery Tower";
            fireSound = "artillery";
            volleyMode = true;
            range = 1250;
            dmg = 15;
            sDmg = 15;
            firingRate = 250.0f;
            pAcceleration = 0;
            imprecision = 40;
            maxMissiles = 30;
            missileInterval = 50;
            homing = false;
            pSpeed = 8.5f;
            sRange = 115;
            mmColor = Color.Orange;

            cost = 125;

            defaultRange = range;
            defaultFiringRate = firingRate;
            defaultDmg = dmg;
            baseDamage = defaultDmg;
        }
Exemple #10
1
        public static Rectangle[] GetNodeSourceRects(NodePiece nodePiece)
        {
            int x = textureOffsetX;
            int y = textureOffsetY;
            Rectangle[] nodeSourceRects = new Rectangle[3];

            // locate the "Type" sprite, make it the first entry in the return array.
            x += PieceWidth + texturePaddingX;
            y += Array.IndexOf(PieceTypes, nodePiece.Type) * (PieceHeight + texturePaddingY);

            nodeSourceRects[0] = new Rectangle(x, y, PieceWidth, PieceHeight);

            // locate the "State" sprite, make it the second entry in the return array.
            y = textureOffsetY;
            y += (Array.IndexOf(PieceStates, nodePiece.State) + StateSpriteOffset) * (PieceHeight + texturePaddingY);

            nodeSourceRects[1] = new Rectangle(x, y, PieceWidth, PieceHeight);

            // locate the "SecurityRating" sprite, make it the third entry in the return array.
            x += PieceWidth + texturePaddingX;

            y = textureOffsetY;
            y += Array.IndexOf(PieceStates, nodePiece.SecurityRating) * (PieceHeight + texturePaddingY); // WRONG

            nodeSourceRects[2] = new Rectangle(x, y, PieceWidth, PieceHeight);

            return nodeSourceRects;
        }
Exemple #11
1
		public Board(Game game, int posX = 224, int posY = 64, int width = 384, int height = 384)
			: base(game) {
			State = EBoardState.Initialize;
			Score = 0;

			Bounds = new Rectangle(posX, posY, width, height);
		}
        public MenuManager(Main game, String[] strMenuTextures,
            String strMenuFont, Integer2 textureBorderPadding)
            : base(game)
        {
            this.game = game;

            //nmcg - create an array of textures
            this.menuTextures = new Texture2D[strMenuTextures.Length];

            //nmcg - load the textures
            for (int i = 0; i < strMenuTextures.Length; i++)
            {
                this.menuTextures[i] =
                    game.Content.Load<Texture2D>(@"" + strMenuTextures[i]);
            }

            //nmcg - load menu font
            this.menuFont = game.Content.Load<SpriteFont>(@"" + strMenuFont);

            //nmcg - stores all menu item (e.g. Save, Resume, Exit) objects
            this.menuItemList = new List<MenuItem>();

            //sets menu texture to fullscreen minus and padding on XY
            this.textureRectangle = menuTextures[0].Bounds;
        }
Exemple #13
1
        public override void Update()
        {
            // Bounding Box
            rectangle = new Rectangle
            (
                (int)Position.X,
                (int)Position.Y,
                (int)Size.X,
                (int)Size.Y
            );

            KeyboardState keyboardState = Keyboard.GetState();
            if (Keyboard.GetState().IsKeyDown(Keys.D))
            {
                Position += movingVector;
                body.ApplyLinearImpulse(movingImpulse);
            }
            else if (Keyboard.GetState().IsKeyDown(Keys.A))
            {
                Position -= movingVector;
                body.ApplyLinearImpulse(-movingImpulse);
            }
            if (Keyboard.GetState().IsKeyDown(Keys.W) && !prevKeyboardState.IsKeyDown(Keys.W))
            {
                if ((DateTime.Now - previousJump).TotalSeconds >= jumpInterval)
                {
                    jumpEffect.Play();
                    body.ApplyLinearImpulse(jumpingImpulse);
                    previousJump = DateTime.Now;
                }
            }

            prevKeyboardState = keyboardState;
        }
 public Camera(Rectangle viewportRect)
 {
     speed = 4f;
     zoom = 1f;
     viewportRectangle = viewportRect;
     mode = CameraMode.Follow;
 }
Exemple #15
1
 public Asteroid ()
 {
     sourceRect = genRandAsteroid();
     Position = genRandPosition();
     Direction = genRandDirection();
     Speed = 1f;
 }
        public Inventory(int SCREEN_WIDTH, int SCREEN_HEIGHT, Pantheon gameReference)
        {
            locationBoxes = new List<Rectangle>();
            equippedBoxes = new List<Rectangle>();
            types = new List<int>();
            infoBox = new Rectangle();
            movingBox = new Rectangle();
            trashBox = new Rectangle();

            tempStorage = new Item();

            this.SCREEN_WIDTH = SCREEN_WIDTH;
            this.SCREEN_HEIGHT = SCREEN_HEIGHT;

            SetBoxes();

            selected = -1;
            hoveredOver = -1;

            color = new Color(34, 167, 222, 50);
            trashColor = Color.White;

            inventorySelector = gameReference.Content.Load<Texture2D>("Inventory/InvSelect");
            trashCan = gameReference.Content.Load<Texture2D>("Inventory/TrashCan");
            nullImage = new Texture2D(gameReference.GraphicsDevice, 1,1);
            nullImage.SetData(new[] { new Color(0,0,0,0) });
        }
Exemple #17
1
 public Scrolling(Texture2D texture, Rectangle rect, Vector2 Pos, float s)
 {
     this.texture = texture;
     this.rectangle = rect;
     this.Position = Pos;
     this.ObjectSpeed = s;
 }
 /// <summary>
 /// Draw a rectangle.
 /// </summary>
 /// <param name="rectangle">The rectangle to draw.</param>
 /// <param name="color">The draw color.</param>
 public void DrawRectangle(Rectangle rectangle, Color color)
 {
     this.Draw(this.WhiteTexture, new Rectangle(rectangle.Left, rectangle.Top, rectangle.Width, 1), color);
     this.Draw(this.WhiteTexture, new Rectangle(rectangle.Left, rectangle.Bottom, rectangle.Width, 1), color);
     this.Draw(this.WhiteTexture, new Rectangle(rectangle.Left, rectangle.Top, 1, rectangle.Height), color);
     this.Draw(this.WhiteTexture, new Rectangle(rectangle.Right, rectangle.Top, 1, rectangle.Height + 1), color);
 }
Exemple #19
1
        protected bool leftToRight = false; // Final boss can fire bolts left and right

        #endregion Fields

        #region Constructors

        public Bolt(Texture2D textureImage, Point sheetSize, Vector2 position, int millisecondsPerFrame, bool leftToRight, Rectangle window, ExplosionManager explosionManager)
            : base(textureImage, sheetSize,  position, Vector2.Zero, millisecondsPerFrame, window, explosionManager,null)
        {
            this.health = 100f;
            this.leftToRight = leftToRight;
            this.energyToLose = health / (sheetSize.Y * sheetSize.X);
        }
Exemple #20
1
        public static Vector2 GetIntersectionDepth(Rectangle rectA, Rectangle rectB)
        {
            // Calculate half sizes.
            float halfWidthA = rectA.Width / 2.0f;
            float halfHeightA = rectA.Height / 2.0f;
            float halfWidthB = rectB.Width / 2.0f;
            float halfHeightB = rectB.Height / 2.0f;

            // Calculate centers.
            Vector2 centerA = new Vector2(rectA.Left + halfWidthA, rectA.Top + halfHeightA);
            Vector2 centerB = new Vector2(rectB.Left + halfWidthB, rectB.Top + halfHeightB);

            // Calculate current and minimum-non-intersecting distances between centers.
            float distanceX = centerA.X - centerB.X;
            float distanceY = centerA.Y - centerB.Y;
            float minDistanceX = halfWidthA + halfWidthB;
            float minDistanceY = halfHeightA + halfHeightB;

            // If we are not intersecting at all, return (0, 0).
            if (Math.Abs(distanceX) >= minDistanceX || Math.Abs(distanceY) >= minDistanceY)
                return Vector2.Zero;

            // Calculate and return intersection depths.
            float depthX = distanceX > 0 ? minDistanceX - distanceX : -minDistanceX - distanceX;
            float depthY = distanceY > 0 ? minDistanceY - distanceY : -minDistanceY - distanceY;
            return new Vector2(depthX, depthY);
        }
 public Notification(GameFacet facet, string filename, Rectangle location)
     : base(facet)
 {
     this.filename = filename;
     this.location = location;
     alpha = 255;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="Paint.BrushSizeSelector"/> class.
        /// </summary>
        /// <param name='graphicsDisplay'>
        /// Graphics display.
        /// </param>
        /// <param name='brushSizeDefinition'>
        /// Brush size definition - layout of the control.
        /// </param>
        public BrushSizeSelector(IGraphicsDisplay graphicsDisplay, BrushSizeSelectorDefinition brushSizeDefinition)
            : base(brushSizeDefinition.BackgroundColor,
				brushSizeDefinition.BorderColor,
				brushSizeDefinition.BorderWidth,
				graphicsDisplay,
				brushSizeDefinition.Bounds)
        {
            this.brushSizeDefinition = brushSizeDefinition;

            this.color = brushSizeDefinition.StartColor;
            this.BrushSize = brushSizeDefinition.BrushSizeInitial;
            this.gaugeYPosition = Bounds.Y + brushSizeDefinition.GaugeVerticalMargin + this.brushSizeDefinition.BrushSizeMaximum;

            Rectangle gaugeBounds = new Rectangle(
                this.Bounds.X + ((this.Bounds.Width - this.brushSizeDefinition.GaugeWidth) / 2),
                this.gaugeYPosition,
                this.brushSizeDefinition.GaugeWidth,
                this.Bounds.Height - (this.brushSizeDefinition.BrushSizeMaximum + (this.brushSizeDefinition.GaugeVerticalMargin * 2)));

            float startMarkerValue =
                (float)(this.brushSizeDefinition.BrushSizeInitial - this.brushSizeDefinition.BrushSizeMinimum) /
                (float)(this.brushSizeDefinition.BrushSizeMaximum - this.brushSizeDefinition.BrushSizeMinimum);

            this.brushSizeGauge =
                new VerticalGauge(
                    this.BackgroundColor,
                    graphicsDisplay,
                    gaugeBounds,
                    this.brushSizeDefinition.GaugeMarkerWidth,
                    this.brushSizeDefinition.BorderColor,
                    startMarkerValue);

            this.brushSizeGauge.MarkerChanged += brushSizeGauge_MarkerChanged;
        }
Exemple #23
0
 public BaseSelector(Grid inGrid, Texture2D inTexture, Rectangle inRect, int inRow, int inCol)
     : base(inTexture, inRect)
 {
     grid = inGrid;
     originRow = inRow;
     originCol = inCol;
 }
        public void Draw(GameTime gameTime, SpriteBatch spriteBatch, Vector2 position, SpriteEffects spriteEffects)
        {
            if (Animation == null)
            {
                throw new NotSupportedException("No animation is currently playing.");
            }

            time += (float)gameTime.ElapsedGameTime.TotalSeconds;
            while (time > Animation.frameTime)
            {
                time -= Animation.frameTime;

                if (Animation.isLooping)
                {
                    frameIndex = (frameIndex + 1) % Animation.FrameCount;

                }
                else
                {
                    frameIndex = Math.Min(frameIndex + 1, Animation.FrameCount - 1);
                }
            }

            Rectangle source = new Rectangle(FrameIndex * Animation.FrameWidth, 0, Animation.FrameWidth, Animation.FrameHeight);

            spriteBatch.Draw(animation.texture, position, source, Color.White, 0.0f, Vector2.Zero, 0.5f, SpriteEffects.None, 0.0f);
        }
Exemple #25
0
        public static ETransformType CheckTransformRect(Rectangle r, Point point)
        {
            Microsoft.Xna.Framework.Point p = new Microsoft.Xna.Framework.Point(point.X, point.Y);
            Rectangle rectTL = GetTransformRect(r, ETransformType.TopLeft);
            if (rectTL.Contains(p)) return ETransformType.TopLeft;
            Rectangle rectTR = GetTransformRect(r, ETransformType.TopRight);
            if (rectTR.Contains(p)) return ETransformType.TopRight;
            Rectangle rectBL = GetTransformRect(r, ETransformType.BottomLeft);
            if (rectBL.Contains(p)) return ETransformType.BottomLeft;
            Rectangle rectBR = GetTransformRect(r, ETransformType.BottomRight);
            if (rectBR.Contains(p)) return ETransformType.BottomRight;

            Rectangle rectT = GetTransformRect(r, ETransformType.Top);
            if (rectT.Contains(p)) return ETransformType.Top;
            Rectangle rectB = GetTransformRect(r, ETransformType.Bottom);
            if (rectB.Contains(p)) return ETransformType.Bottom;
            Rectangle rectL = GetTransformRect(r, ETransformType.Left);
            if (rectL.Contains(p)) return ETransformType.Left;
            Rectangle rectR = GetTransformRect(r, ETransformType.Right);
            if (rectR.Contains(p)) return ETransformType.Right;

            Rectangle rectM = GetTransformRect(r, ETransformType.Middle);
            if (rectM.Contains(p)) return ETransformType.Middle;
            Rectangle rectC = GetTransformRect(r, ETransformType.Center);
            if (rectC.Contains(p)) return ETransformType.Center;

            return ETransformType.None;
        }
Exemple #26
0
 //, Component _Parent
 public Component(Rectangle _Bounds)
     : this()
 {
     this.bounds = _Bounds;
     this.sourceRectangle = new Rectangle(0, 0, this.bounds.Width, this.bounds.Height);
     //this.parent = _Parent;
 }
 public ColorPickerBox(AControl parent, Rectangle closedArea, Rectangle openArea, int swatchWidth, int swatchHeight, int[] hues, int index)
     : this(parent)
 {
     m_openArea = openArea;
     m_Index = index;
     buildGumpling(closedArea, swatchWidth, swatchHeight, hues);
 }
Exemple #28
0
        internal Movie( Movie movie )
            : base(movie.Name, movie.resourceName, Vector2.Zero, movie.order)
        {
            this.Width = movie.Width;
            this.Height = movie.Height;
            this.renderWidth = movie.renderWidth;
            this.renderHeight = movie.renderHeight;
            this.rate = movie.rate;
            this.currentRate = movie.currentRate;
            this.currentFrameCount = movie.currentFrameCount;
            this.CurrentSequenceName = movie.CurrentSequenceName;

            foreach ( MovieSequence sequence in movie.sequences.Values )
                this.sequences.Add ( sequence.Name, MovieSequence.Clone ( sequence ) );

            this.rotation = movie.rotation;
            this.rotationLocation = movie.rotationLocation;
            this.frameRectangle = movie.frameRectangle;
            this.sequenceNames.AddRange ( movie.sequenceNames );
            this.isVisible = movie.isVisible;

            this.location = movie.location;
            this.Texture = movie.Texture;

            Movie.Play ( this, this.CurrentSequenceName, true );
        }
 public void HandleBombsIntersection(Player p, BuildingHandler bh, ContentManager theContentManager)
 {
     if (p.bombs.Count > 0)
     {
         foreach (Bomb b in p.bombs)
         {
             bombRectangle = new Rectangle((int)b.X, (int)b.Y, 20, 20); //TODO: width, height if needed
             foreach (Building building in bh.buildings)
             {
                 buildingRectangle = new Rectangle((int)building.X, (int)building.Y - building.H + 10, building.W, building.H);
                 if (bombRectangle.Intersects(buildingRectangle))
                 {
                     building.Damaged = true;
                     p.score.AddPoints(50);
                     p.eh.CreateExplosion("huge", new Vector2(b.X - 48, b.Y - 16), theContentManager);
                     p.bombs.Remove(b);
                     bombRemoved = true;
                 }
             }
             if (bombRemoved)
             {
                 bombRemoved = false;
                 break;
             }
         }
     }
 }
        public void Render(RendererParameters parameters)
        {
            parameters.ThrowIfNull("parameters");

            if (!_state.Enabled || _state.TopLeftSelectionCoordinate == null)
            {
                return;
            }

            const int tileWidth = TextAdventure.Xna.Constants.Tile.TileWidth;
            const int tileHeight = TextAdventure.Xna.Constants.Tile.TileHeight;
            var topLeftPoint = new Point(
                _editorView.TopLeftPoint.X + (_state.TopLeftSelectionCoordinate.Value.X * tileWidth),
                _editorView.TopLeftPoint.Y + (_state.TopLeftSelectionCoordinate.Value.Y * tileHeight));
            var destinationRectangle = new Rectangle(topLeftPoint.X, topLeftPoint.Y, tileWidth * _state.SelectionSize, tileHeight * _state.SelectionSize);
            var topLine = new Rectangle(destinationRectangle.X, destinationRectangle.Y, destinationRectangle.Width, 1);
            var bottomLine = new Rectangle(destinationRectangle.X, destinationRectangle.Bottom - 1, destinationRectangle.Width, 1);
            var leftLine = new Rectangle(destinationRectangle.X, destinationRectangle.Y, 1, destinationRectangle.Height);
            var rightLine = new Rectangle(destinationRectangle.Right - 1, destinationRectangle.Y, 1, destinationRectangle.Height);
            Texture2D pixelTexture = parameters.TextureContent.Pixel;

            parameters.SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointWrap, DepthStencilState.None, new ScissoringRasterizerState());

            parameters.SpriteBatch.GraphicsDevice.ScissorRectangle = new Rectangle(0, 0, _editorView.VisibleBoardSizeInPixels.Width, _editorView.VisibleBoardSizeInPixels.Height);

            parameters.SpriteBatch.Draw(pixelTexture, topLine, Color.Red);
            parameters.SpriteBatch.Draw(pixelTexture, bottomLine, Color.Red);
            parameters.SpriteBatch.Draw(pixelTexture, leftLine, Color.Red);
            parameters.SpriteBatch.Draw(pixelTexture, rightLine, Color.Red);

            parameters.SpriteBatch.End();
        }
        /// <summary>A Harmony prefix patch that causes <see cref="BuildableGameLocation.isBuildable(Vector2)"/> to return true under more conditions.</summary>
        /// <param name="__instance">The buildable location on which this method is called.</param>
        /// <param name="tileLocation">The tile being checked.</param>
        /// <param name="__result">True if this tile should allow <see cref="Building"/> placement.</param>
        /// <returns>False if the original method (and any other patches) should be skipped.</returns>
        public static bool IsBuildable(BuildableGameLocation __instance, Vector2 tileLocation, ref bool __result)
        {
            try
            {
                if (ModEntry.Config.EverythingEnabled()) //if every feature is enabled
                {
                    __result = true;                     //this tile is buildable
                    return(false);                       //skip the original method
                }

                if (ModEntry.Config.EverythingDisabled())                                                                   //if every feature is disabled
                {
                    return(true);                                                                                           //run the original method (do nothing)
                }
                if (ModEntry.Config.BuildOnAllTerrainFeatures == false)                                                     //if most terrain features should prevent building (based on the original method's behavior)
                {
                    Rectangle tileLocationRect = new Rectangle((int)tileLocation.X * 64, (int)tileLocation.Y * 64, 64, 64); //get a rectangle representing this tile

                    if (__instance.terrainFeatures.TryGetValue(tileLocation, out TerrainFeature feature) && //if this tile has a terrain feature
                        tileLocationRect.Intersects(feature.getBoundingBox(tileLocation)))    //AND the feature's box overlaps with the tile (note: copied from GameLocation.isOccupiedForPlacement)
                    {
                        if (!__instance.terrainFeatures[tileLocation].isPassable() || //if the feature is impassable
                            (feature is HoeDirt dirt && dirt.crop != null)) //OR the feature is a crop
                        {
                            __result = false;                               //this tile is NOT buildable
                            return(false);                                  //skip the original method
                        }
                    }
                }

                if (ModEntry.Config.BuildOnOtherBuildings == false)                  //if collision with other buildings should prevent building
                {
                    foreach (Building building in __instance.buildings)              //for each existing building
                    {
                        if (building.isTileOccupiedForPlacement(tileLocation, null)) //if this building occupies this tile
                        {
                            __result = false;                                        //this tile is NOT buildable
                            return(false);                                           //skip the original method
                        }
                    }
                }

                if (ModEntry.Config.BuildOnWater == false) //if water should prevent building
                {
                    if (__instance.doesTileHaveProperty((int)tileLocation.X, (int)tileLocation.Y, "Water", "Back") != null && //if this tile is water
                        __instance.doesTileHaveProperty((int)tileLocation.X, (int)tileLocation.Y, "Passable", "Buildings") == null) //AND this tile does NOT specifically allow buildings
                    {
                        __result = false;                                                                                           //this tile is NOT buildable
                        return(false);                                                                                              //skip the original method
                    }
                }

                if (ModEntry.Config.BuildOnImpassableTiles == false)                                                                        //if impassable tiles should prevent building
                {
                    if (ModEntry.Config.BuildOnWater == false || __instance.isOpenWater((int)tileLocation.X, (int)tileLocation.Y) == false) //if this tile is NOT specifically allowed by the water setting
                    {
                        if (__instance.isTileOccupiedForPlacement(tileLocation) || //if this tile is occupied
                            __instance.isTilePassable(new Location((int)tileLocation.X, (int)tileLocation.Y), Game1.viewport) == false) //OR if this tile is NOT passable
                        {
                            __result = false;                                                                                           //this tile is NOT buildable
                            return(false);                                                                                              //skip the original method
                        }
                    }
                }

                if (ModEntry.Config.BuildOnNoFurnitureTiles == false)                                                             //if "no furniture" tiles should prevent building
                {
                    if (__instance.doesTileHaveProperty((int)tileLocation.X, (int)tileLocation.Y, "NoFurniture", "Back") != null) //if this tile has a "NoFurniture" property
                    {
                        __result = false;                                                                                         //this tile is NOT buildable
                        return(false);                                                                                            //skip the original method
                    }
                }

                if (ModEntry.Config.BuildOnCaveAndShippingZones == false) //if "no build" zones should prevent building
                {
                    //get the "no build" zones for this location
                    Rectangle caveNoBuildRect         = ModEntry.Instance.Helper.Reflection.GetField <Rectangle>(__instance, "caveNoBuildRect", true).GetValue();
                    Rectangle shippingAreaNoBuildRect = ModEntry.Instance.Helper.Reflection.GetField <Rectangle>(__instance, "shippingAreaNoBuildRect", true).GetValue();

                    if (caveNoBuildRect.Contains(Utility.Vector2ToPoint(tileLocation)) || //if this tile is within the cave entrance zone
                        shippingAreaNoBuildRect.Contains(Utility.Vector2ToPoint(tileLocation))) //OR this tile is within the shipping bin zone
                    {
                        __result = false;                                                       //this tile is NOT buildable
                        return(false);                                                          //skip the original method
                    }
                }

                //all checks have been successful

                __result = true; //this tile is buildable
                return(false);   //skip the original method
            }
            catch (Exception ex)
            {
                ModEntry.Instance.Monitor.LogOnce($"Encountered an error in Harmony patch \"{nameof(HarmonyPatch_BuildOnAnyTile)}\". The default building rules will be used instead. Full error message:\n-----\n{ex.ToString()}", LogLevel.Error);
                return(true); //run the original method
            }
        }
Exemple #32
0
 public Rectangle(int width, int height)
 {
     this._area = new Microsoft.Xna.Framework.Rectangle(0, 0, width, height);
 }
Exemple #33
0
 public void draw(SpriteBatch b)
 {
     if (this.showResultsTimer < 0)
     {
         b.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointClamp, (DepthStencilState)null, (RasterizerState)null);
         Game1.mapDisplayDevice.BeginScene(b);
         this.location.Map.GetLayer("Back").Draw(Game1.mapDisplayDevice, Game1.viewport, Location.Origin, false, Game1.pixelZoom);
         SpriteBatch spriteBatch   = b;
         Texture2D   shadowTexture = Game1.shadowTexture;
         Vector2     local         = Game1.GlobalToLocal(Game1.viewport, Game1.player.position + new Vector2(32f, 24f));
         Microsoft.Xna.Framework.Rectangle?sourceRectangle = new Microsoft.Xna.Framework.Rectangle?(Game1.shadowTexture.Bounds);
         Color  white = Color.White;
         double num1  = 0.0;
         Microsoft.Xna.Framework.Rectangle bounds = Game1.shadowTexture.Bounds;
         double x = (double)bounds.Center.X;
         bounds = Game1.shadowTexture.Bounds;
         double  y      = (double)bounds.Center.Y;
         Vector2 origin = new Vector2((float)x, (float)y);
         double  num2   = 4.0 - (Game1.player.running || Game1.player.usingTool ? (double)Math.Abs(FarmerRenderer.featureYOffsetPerFrame[Game1.player.FarmerSprite.CurrentFrame]) * 0.800000011920929 : 0.0);
         int     num3   = 0;
         double  num4   = (double)Math.Max(0.0f, (float)((double)Game1.player.getStandingY() / 10000.0 + 0.000110000000859145)) - 1.0000000116861E-07;
         spriteBatch.Draw(shadowTexture, local, sourceRectangle, white, (float)num1, origin, (float)num2, (SpriteEffects)num3, (float)num4);
         this.location.Map.GetLayer("Buildings").Draw(Game1.mapDisplayDevice, Game1.viewport, Location.Origin, false, Game1.pixelZoom);
         Game1.mapDisplayDevice.EndScene();
         b.End();
         b.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend, SamplerState.PointClamp, (DepthStencilState)null, (RasterizerState)null);
         this.location.draw(b);
         Game1.player.draw(b);
         if (!Game1.options.hardwareCursor)
         {
             b.Draw(Game1.mouseCursors, new Vector2((float)Game1.getMouseX(), (float)Game1.getMouseY()), new Microsoft.Xna.Framework.Rectangle?(Game1.getSourceRectForStandardTileSheet(Game1.mouseCursors, 0, 16, 16)), Color.White, 0.0f, Vector2.Zero, (float)Game1.pixelZoom + Game1.dialogueButtonScale / 150f, SpriteEffects.None, 1f);
         }
         foreach (TargetGame.Target target in this.targets)
         {
             target.draw(b);
         }
         b.End();
         b.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointClamp, (DepthStencilState)null, (RasterizerState)null);
         Game1.mapDisplayDevice.BeginScene(b);
         this.location.Map.GetLayer("Front").Draw(Game1.mapDisplayDevice, Game1.viewport, Location.Origin, false, Game1.pixelZoom);
         Game1.mapDisplayDevice.EndScene();
         if (!Game1.options.hardwareCursor)
         {
             b.Draw(Game1.mouseCursors, new Vector2((float)Game1.getMouseX(), (float)Game1.getMouseY()), new Microsoft.Xna.Framework.Rectangle?(Game1.getSourceRectForStandardTileSheet(Game1.mouseCursors, 0, 16, 16)), Color.White, 0.0f, Vector2.Zero, (float)Game1.pixelZoom + Game1.dialogueButtonScale / 150f, SpriteEffects.None, 1f);
         }
         Game1.player.CurrentTool.draw(b);
         Game1.drawWithBorder(Game1.content.LoadString("Strings\\StringsFromCSFiles:FishingGame.cs.10444", (object)TargetGame.score), Color.Black, Color.White, new Vector2((float)(Game1.tileSize / 2), (float)(Game1.tileSize / 2)));
         Game1.drawWithBorder(Game1.content.LoadString("Strings\\StringsFromCSFiles:Event.cs.1514", (object)(this.gameEndTimer / 1000)), Color.Black, Color.White, new Vector2((float)(Game1.tileSize / 2), (float)Game1.tileSize));
         if (TargetGame.shotsFired > 1)
         {
             Game1.drawWithBorder(Game1.content.LoadString("Strings\\StringsFromCSFiles:TargetGame.cs.12154", (object)(int)(Math.Round((double)((float)TargetGame.successShots / (float)(TargetGame.shotsFired - 1)), 2) * 100.0)), Color.Black, Color.White, new Vector2((float)(Game1.tileSize / 2), (float)(Game1.tileSize * 3 / 2)));
         }
         b.End();
     }
     else
     {
         b.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointClamp, (DepthStencilState)null, (RasterizerState)null);
         Vector2 position = new Vector2((float)(Game1.viewport.Width / 2 - Game1.tileSize * 2), (float)(Game1.viewport.Height / 2 - Game1.tileSize));
         if (this.showResultsTimer <= 16000)
         {
             Game1.drawWithBorder(Game1.content.LoadString("Strings\\StringsFromCSFiles:FishingGame.cs.10444", (object)TargetGame.score), Game1.textColor, this.showResultsTimer > 11000 || (double)this.modifierBonus <= 1.0 ? Color.White : Color.Lime, position);
         }
         if (this.showResultsTimer <= 14000)
         {
             position.Y += (float)(Game1.tileSize * 3 / 4);
             Game1.drawWithBorder(Game1.content.LoadString("Strings\\StringsFromCSFiles:TargetGame.cs.12157", (object)TargetGame.accuracy, (object)TargetGame.successShots, (object)TargetGame.shotsFired), Game1.textColor, Color.White, position);
         }
         if (this.showResultsTimer <= 11000)
         {
             position.Y += (float)(Game1.tileSize * 3 / 4);
             if ((double)this.modifierBonus > 1.0)
             {
                 Game1.drawWithBorder(Game1.content.LoadString("Strings\\StringsFromCSFiles:TargetGame.cs.12161", (object)this.modifierBonus), Game1.textColor, Color.Yellow, position);
             }
             else
             {
                 Game1.drawWithBorder(Game1.content.LoadString("Strings\\StringsFromCSFiles:TargetGame.cs.12163"), Game1.textColor, Color.Red, position);
             }
         }
         if (this.showResultsTimer <= 9000)
         {
             position.Y += (float)Game1.tileSize;
             if (TargetGame.starTokensWon > 0)
             {
                 float num = Math.Min(1f, (float)(this.showResultsTimer - 2000) / 4000f);
                 Game1.drawWithBorder(Game1.content.LoadString("Strings\\StringsFromCSFiles:FishingGame.cs.12013", (object)TargetGame.starTokensWon), Game1.textColor * 0.2f * num, Color.SkyBlue * 0.3f * num, position + new Vector2((float)Game1.random.Next(-1, 2), (float)Game1.random.Next(-1, 2)) * (float)Game1.pixelZoom * 2f, 0.0f, 1f, 1f);
                 Game1.drawWithBorder(Game1.content.LoadString("Strings\\StringsFromCSFiles:FishingGame.cs.12013", (object)TargetGame.starTokensWon), Game1.textColor * 0.2f * num, Color.SkyBlue * 0.3f * num, position + new Vector2((float)Game1.random.Next(-1, 2), (float)Game1.random.Next(-1, 2)) * (float)Game1.pixelZoom * 2f, 0.0f, 1f, 1f);
                 Game1.drawWithBorder(Game1.content.LoadString("Strings\\StringsFromCSFiles:FishingGame.cs.12013", (object)TargetGame.starTokensWon), Game1.textColor * 0.2f * num, Color.SkyBlue * 0.3f * num, position + new Vector2((float)Game1.random.Next(-1, 2), (float)Game1.random.Next(-1, 2)) * (float)Game1.pixelZoom * 2f, 0.0f, 1f, 1f);
                 Game1.drawWithBorder(Game1.content.LoadString("Strings\\StringsFromCSFiles:FishingGame.cs.12013", (object)TargetGame.starTokensWon), Game1.textColor, Color.SkyBlue, position, 0.0f, 1f, 1f);
             }
             else
             {
                 Game1.drawWithBorder(Game1.content.LoadString("Strings\\StringsFromCSFiles:FishingGame.cs.12021"), Game1.textColor, Color.Red, position);
             }
         }
         if (this.showResultsTimer <= 1000)
         {
             b.Draw(Game1.fadeToBlackRect, new Microsoft.Xna.Framework.Rectangle(0, 0, Game1.viewport.Width, Game1.viewport.Height), Color.Black * (float)(1.0 - (double)this.showResultsTimer / 1000.0));
         }
         b.Draw(Game1.fadeToBlackRect, new Microsoft.Xna.Framework.Rectangle(Game1.tileSize / 4, Game1.tileSize / 4, Game1.tileSize * 2 + (Game1.player.festivalScore > 999 ? Game1.tileSize / 4 : 0), Game1.tileSize), Color.Black * 0.75f);
         b.Draw(Game1.mouseCursors, new Vector2((float)(Game1.tileSize / 2), (float)(Game1.tileSize / 2)), new Microsoft.Xna.Framework.Rectangle?(new Microsoft.Xna.Framework.Rectangle(338, 400, 8, 8)), Color.White, 0.0f, Vector2.Zero, (float)Game1.pixelZoom, SpriteEffects.None, 1f);
         Game1.drawWithBorder(string.Concat((object)Game1.player.festivalScore), Color.Black, Color.White, new Vector2((float)(Game1.tileSize / 2 + 10 * Game1.pixelZoom), (float)(Game1.tileSize / 3 + Game1.pixelZoom * 2)), 0.0f, 1f, 1f, false);
         b.End();
     }
 }
 public override void gameWindowSizeChanged(Microsoft.Xna.Framework.Rectangle oldBounds, Microsoft.Xna.Framework.Rectangle newBounds)
 {
     base.gameWindowSizeChanged(oldBounds, newBounds);
     movePosition(0, Game1.viewport.Height - yPositionOnScreen - height);
     Game1.player.forceCanMove();
 }
Exemple #35
0
        public void LoadDataFromXMLDocument(string filename)
        {
            Font font = null;

            Microsoft.Xna.Framework.Graphics.Color color;
            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.Load(filename);
            XmlNode nextSibling = xmlDocument.FirstChild.NextSibling;
            XmlNode xmlNodes    = nextSibling.ChildNodes.Item(0);

            this.troopDetail.BackgroundSize.X  = int.Parse(xmlNodes.Attributes.GetNamedItem("Width").Value);
            this.troopDetail.BackgroundSize.Y  = int.Parse(xmlNodes.Attributes.GetNamedItem("Height").Value);
            this.troopDetail.BackgroundTexture = Texture2D.FromFile(this.graphicsDevice, string.Concat("GameComponents\\TroopDetail\\Data\\", xmlNodes.Attributes.GetNamedItem("FileName").Value));
            xmlNodes = nextSibling.ChildNodes.Item(1);
            Microsoft.Xna.Framework.Rectangle rectangle = StaticMethods.LoadRectangleFromXMLNode(xmlNodes);
            StaticMethods.LoadFontAndColorFromXMLNode(xmlNodes, out font, out color);
            this.troopDetail.TroopNameText          = new FreeText(this.graphicsDevice, font, color);
            this.troopDetail.TroopNameText.Position = rectangle;
            this.troopDetail.TroopNameText.Align    = (TextAlign)Enum.Parse(typeof(TextAlign), xmlNodes.Attributes.GetNamedItem("Align").Value);
            xmlNodes = nextSibling.ChildNodes.Item(2);
            this.troopDetail.PortraitClient = StaticMethods.LoadRectangleFromXMLNode(xmlNodes);
            xmlNodes = nextSibling.ChildNodes.Item(3);
            int num = 0;

            while (true)
            {
                bool count = num < xmlNodes.ChildNodes.Count;
                if (!count)
                {
                    break;
                }
                LabelText labelText = new LabelText();
                XmlNode   xmlNodes1 = xmlNodes.ChildNodes.Item(num);
                rectangle = StaticMethods.LoadRectangleFromXMLNode(xmlNodes1);
                StaticMethods.LoadFontAndColorFromXMLNode(xmlNodes1, out font, out color);
                labelText.Label          = new FreeText(this.graphicsDevice, font, color);
                labelText.Label.Position = rectangle;
                labelText.Label.Align    = (TextAlign)Enum.Parse(typeof(TextAlign), xmlNodes1.Attributes.GetNamedItem("Align").Value);
                labelText.Label.Text     = xmlNodes1.Attributes.GetNamedItem("Label").Value;
                xmlNodes1 = xmlNodes.ChildNodes.Item(num + 1);
                rectangle = StaticMethods.LoadRectangleFromXMLNode(xmlNodes1);
                StaticMethods.LoadFontAndColorFromXMLNode(xmlNodes1, out font, out color);
                labelText.Text          = new FreeText(this.graphicsDevice, font, color);
                labelText.Text.Position = rectangle;
                labelText.Text.Align    = (TextAlign)Enum.Parse(typeof(TextAlign), xmlNodes1.Attributes.GetNamedItem("Align").Value);
                labelText.PropertyName  = xmlNodes1.Attributes.GetNamedItem("PropertyName").Value;
                this.troopDetail.LabelTexts.Add(labelText);
                num = num + 2;
            }
            xmlNodes = nextSibling.ChildNodes.Item(4);
            this.troopDetail.OtherPersonClient            = StaticMethods.LoadRectangleFromXMLNode(xmlNodes);
            this.troopDetail.OtherPersonText.ClientWidth  = this.troopDetail.OtherPersonClient.Width;
            this.troopDetail.OtherPersonText.ClientHeight = this.troopDetail.OtherPersonClient.Height;
            this.troopDetail.OtherPersonText.RowMargin    = int.Parse(xmlNodes.Attributes.GetNamedItem("RowMargin").Value);
            StaticMethods.LoadFontAndColorFromXMLNode(xmlNodes, out font, out color);
            this.troopDetail.OtherPersonText.Builder.SetFreeTextBuilder(this.graphicsDevice, font);
            this.troopDetail.OtherPersonText.DefaultColor = color;
            xmlNodes = nextSibling.ChildNodes.Item(5);
            this.troopDetail.CombatMethodClient            = StaticMethods.LoadRectangleFromXMLNode(xmlNodes);
            this.troopDetail.CombatMethodText.ClientWidth  = this.troopDetail.CombatMethodClient.Width;
            this.troopDetail.CombatMethodText.ClientHeight = this.troopDetail.CombatMethodClient.Height;
            this.troopDetail.CombatMethodText.RowMargin    = int.Parse(xmlNodes.Attributes.GetNamedItem("RowMargin").Value);
            StaticMethods.LoadFontAndColorFromXMLNode(xmlNodes, out font, out color);
            this.troopDetail.CombatMethodText.Builder.SetFreeTextBuilder(this.graphicsDevice, font);
            this.troopDetail.CombatMethodText.DefaultColor = color;
            xmlNodes = nextSibling.ChildNodes.Item(6);
            this.troopDetail.StuntClient            = StaticMethods.LoadRectangleFromXMLNode(xmlNodes);
            this.troopDetail.StuntText.ClientWidth  = this.troopDetail.CombatMethodClient.Width;
            this.troopDetail.StuntText.ClientHeight = this.troopDetail.CombatMethodClient.Height;
            this.troopDetail.StuntText.RowMargin    = int.Parse(xmlNodes.Attributes.GetNamedItem("RowMargin").Value);
            StaticMethods.LoadFontAndColorFromXMLNode(xmlNodes, out font, out color);
            this.troopDetail.StuntText.Builder.SetFreeTextBuilder(this.graphicsDevice, font);
            this.troopDetail.StuntText.DefaultColor = color;
            xmlNodes = nextSibling.ChildNodes.Item(7);
            this.troopDetail.InfluenceClient            = StaticMethods.LoadRectangleFromXMLNode(xmlNodes);
            this.troopDetail.InfluenceText.ClientWidth  = this.troopDetail.InfluenceClient.Width;
            this.troopDetail.InfluenceText.ClientHeight = this.troopDetail.InfluenceClient.Height;
            this.troopDetail.InfluenceText.RowMargin    = int.Parse(xmlNodes.Attributes.GetNamedItem("RowMargin").Value);
            StaticMethods.LoadFontAndColorFromXMLNode(xmlNodes, out font, out color);
            this.troopDetail.InfluenceText.Builder.SetFreeTextBuilder(this.graphicsDevice, font);
            this.troopDetail.InfluenceText.DefaultColor = color;
        }
 public void FillRectangle(Rectangle rectangle, Color color)
 {
     base.Draw(singlePixel, rectangle, color);
 }
Exemple #37
0
 public static bool PointInRectangle(Microsoft.Xna.Framework.Point point, Microsoft.Xna.Framework.Rectangle rect)
 {
     return((((point.X > rect.Left) && (point.Y > rect.Top)) && (point.X < rect.Right)) && (point.Y < rect.Bottom));
 }
Exemple #38
0
 public static Microsoft.Xna.Framework.Rectangle CenterRectangle(Microsoft.Xna.Framework.Rectangle desRectangle, Microsoft.Xna.Framework.Rectangle rectangleToBeCentered)
 {
     return(new Microsoft.Xna.Framework.Rectangle(desRectangle.Left + ((desRectangle.Width - rectangleToBeCentered.Width) / 2), desRectangle.Top + (((desRectangle.Height - rectangleToBeCentered.Height) * 2) / 3), rectangleToBeCentered.Width, rectangleToBeCentered.Height));
 }
Exemple #39
0
 public static Microsoft.Xna.Framework.Rectangle RightRectangle(Microsoft.Xna.Framework.Rectangle desRectangle, Microsoft.Xna.Framework.Rectangle rectangleToBeRighted)
 {
     return(new Microsoft.Xna.Framework.Rectangle(desRectangle.Right - rectangleToBeRighted.Width, desRectangle.Top + (((desRectangle.Height - rectangleToBeRighted.Height) * 2) / 3), rectangleToBeRighted.Width, rectangleToBeRighted.Height));
 }
Exemple #40
0
 public static Microsoft.Xna.Framework.Rectangle GetBottomRightRectangle(Microsoft.Xna.Framework.Rectangle rectDes, Microsoft.Xna.Framework.Rectangle rect)
 {
     return(new Microsoft.Xna.Framework.Rectangle(rectDes.Right - rect.Width, rectDes.Bottom - rect.Height, rect.Width, rect.Height));
 }
        public bool isTileOccupiedIgnoreFloorsOverride(Vector2 tileLocation)
        {
            Microsoft.Xna.Framework.Rectangle tileLocationRect = new Microsoft.Xna.Framework.Rectangle((int)tileLocation.X * 64 + 1, (int)tileLocation.Y * 64 + 1, 62, 62);
            for (int i = 0; i < this.GameLocation.characters.Count; i++)
            {
                if (this.GameLocation.characters[i] != null &&
                    !this.GameLocation.characters[i].IsMonster &&
                    !this.thisCharacter.Equals(this.GameLocation.characters[i]) &&
                    this.goalCharacter != null &&
                    !this.goalCharacter.Equals(this.GameLocation.characters[i]) &&
                    this.GameLocation.characters[i].GetBoundingBox().Intersects(tileLocationRect))
                {
                    return(true);
                }
            }

            if (this.f != null)
            {
                foreach (FarmAnimal animal in this.f.animals.Values)
                {
                    if (animal.GetBoundingBox().Intersects(tileLocationRect))
                    {
                        return(true);
                    }
                }

                foreach (ResourceClump clump in this.f.resourceClumps)
                {
                    if (clump.occupiesTile((int)tileLocation.X, (int)tileLocation.Y))
                    {
                        return(true);
                    }
                }
            }
            else if (this.w != null)
            {
                foreach (ResourceClump stump in this.w.stumps)
                {
                    if (stump.occupiesTile((int)tileLocation.X, (int)tileLocation.Y))
                    {
                        return(true);
                    }
                }
            }
            else if (this.ah != null)
            {
                foreach (FarmAnimal animal in this.ah.animals.Values)
                {
                    if (animal.GetBoundingBox().Intersects(tileLocationRect))
                    {
                        return(true);
                    }
                }
            }
            else if (this.ms != null)
            {
                foreach (ResourceClump clump in this.ms.resourceClumps)
                {
                    if (clump.occupiesTile((int)tileLocation.X, (int)tileLocation.Y))
                    {
                        return(true);
                    }
                }
            }


            if (this.GameLocation.terrainFeatures.ContainsKey(tileLocation) && tileLocationRect.Intersects(this.GameLocation.terrainFeatures[tileLocation].getBoundingBox(tileLocation)) && !this.GameLocation.terrainFeatures[tileLocation].isPassable(null))
            {
                return(true);
            }
            if (this.GameLocation.largeTerrainFeatures.Count > 0)
            {
                foreach (StardewValley.TerrainFeatures.LargeTerrainFeature tf in this.GameLocation.largeTerrainFeatures)
                {
                    if (tf.getBoundingBox().Intersects(tileLocationRect))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Exemple #42
0
        public SDL2_GamePlatform(Game game) : base(game, SDL.SDL_GetPlatform())
        {
            /* SDL2 might complain if an OS that uses SDL_main has not actually
             * used SDL_main by the time you initialize SDL2.
             * The only platform that is affected is Windows, but we can skip
             * their WinMain. This was only added to prevent iOS from exploding.
             * -flibit
             */
            SDL.SDL_SetMainReady();

            // This _should_ be the first real SDL call we make...
            SDL.SDL_Init(
                SDL.SDL_INIT_VIDEO |
                SDL.SDL_INIT_JOYSTICK |
                SDL.SDL_INIT_GAMECONTROLLER |
                SDL.SDL_INIT_HAPTIC
                );

            // Set any hints to match XNA4 behavior...
            string hint = SDL.SDL_GetHint(SDL.SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS);

            if (String.IsNullOrEmpty(hint))
            {
                SDL.SDL_SetHint(
                    SDL.SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS,
                    "1"
                    );
            }

            // If available, load the SDL_GameControllerDB
            string mappingsDB = Path.Combine(
                TitleContainer.Location,
                "gamecontrollerdb.txt"
                );

            if (File.Exists(mappingsDB))
            {
                SDL.SDL_GameControllerAddMappingsFromFile(
                    mappingsDB
                    );
            }

            // Set and initialize the SDL2 window
            bool forceES2 = Environment.GetEnvironmentVariable(
                "FNA_OPENGL_FORCE_ES2"
                ) == "1";

            Window = new SDL2_GameWindow(
                forceES2 ||
                OSVersion.Equals("Emscripten") ||
                OSVersion.Equals("Android") ||
                OSVersion.Equals("iOS")
                );

            // Create the DisplayMode list
            displayIndex = SDL.SDL_GetWindowDisplayIndex(
                Window.Handle
                );
            INTERNAL_GenerateDisplayModes();

            // Disable the screensaver.
            SDL.SDL_DisableScreenSaver();

            // We hide the mouse cursor by default.
            if (IsMouseVisible)
            {
                IsMouseVisible = false;
            }
            else
            {
                /* Since IsMouseVisible is already false, OnMouseVisibleChanged
                 * will NOT be called! So we get to do it ourselves.
                 * -flibit
                 */
                SDL.SDL_ShowCursor(0);
            }

            // OSX has some fancy fullscreen features, let's use them!
            if (OSVersion.Equals("Mac OS X"))
            {
                hint = SDL.SDL_GetHint(SDL.SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES);
                INTERNAL_useFullscreenSpaces = (String.IsNullOrEmpty(hint) || hint.Equals("1"));
            }
            else
            {
                INTERNAL_useFullscreenSpaces = false;
            }

            // Initialize Active Key List
            keys = new List <Keys>();

            // Setup Text Input Control Character Arrays (Only 4 control keys supported at this time)
            INTERNAL_TextInputControlDown   = new bool[4];
            INTERNAL_TextInputControlRepeat = new int[4];

            // Assume we will have focus.
            IsActive = true;

            // Ready to run the loop!
            INTERNAL_runApplication = true;

#if WIIU_GAMEPAD
            wiiuStream = DRC.drc_new_streamer();
            if (wiiuStream == IntPtr.Zero)
            {
                System.Console.WriteLine("Failed to alloc GamePad stream!");
                return;
            }
            if (DRC.drc_start_streamer(wiiuStream) < 1)             // ???
            {
                System.Console.WriteLine("Failed to start GamePad stream!");
                DRC.drc_delete_streamer(wiiuStream);
                wiiuStream = IntPtr.Zero;
                return;
            }
            DRC.drc_enable_system_input_feeder(wiiuStream);
            Rectangle bounds = Window.ClientBounds;
            wiiuPixelData = new byte[bounds.Width * bounds.Height * 4];
#endif
        }
 public void FillRectangle(Rectangle rectangle, Color color, Vector2 origin)
 {
     rectangle.X -= (int)origin.X;
     rectangle.Y -= (int)origin.Y;
     base.Draw(singlePixel, rectangle, color);
 }
Exemple #44
0
        public ClipboardBuffer GetSelectionBuffer()
        {
            World world = _wvm.CurrentWorld;

            XNA.Rectangle area   = _wvm.Selection.SelectionArea;
            var           buffer = new ClipboardBuffer(new Vector2Int32(area.Width, area.Height));

            for (int x = 0; x < area.Width; x++)
            {
                for (int y = 0; y < area.Height; y++)
                {
                    Tile curTile = (Tile)world.Tiles[x + area.X, y + area.Y].Clone();

                    if (Tile.IsChest(curTile.Type))
                    {
                        if (buffer.GetChestAtTile(x, y) == null)
                        {
                            var anchor = world.GetAnchor(x + area.X, y + area.Y);
                            if (anchor.X == x + area.X && anchor.Y == y + area.Y)
                            {
                                var data = world.GetChestAtTile(x + area.X, y + area.Y);
                                if (data != null)
                                {
                                    var newChest = data.Copy();
                                    newChest.X = x;
                                    newChest.Y = y;
                                    buffer.Chests.Add(newChest);
                                }
                            }
                        }
                    }
                    if (Tile.IsSign(curTile.Type))
                    {
                        if (buffer.GetSignAtTile(x, y) == null)
                        {
                            var anchor = world.GetAnchor(x + area.X, y + area.Y);
                            if (anchor.X == x + area.X && anchor.Y == y + area.Y)
                            {
                                var data = world.GetSignAtTile(x + area.X, y + area.Y);
                                if (data != null)
                                {
                                    var newSign = data.Copy();
                                    newSign.X = x;
                                    newSign.Y = y;
                                    buffer.Signs.Add(newSign);
                                }
                            }
                        }
                    }
                    if (Tile.IsTileEntity(curTile.Type))
                    {
                        if (buffer.GetTileEntityAtTile(x, y) == null)
                        {
                            var anchor = world.GetAnchor(x + area.X, y + area.Y);
                            if (anchor.X == x + area.X && anchor.Y == y + area.Y)
                            {
                                var data = world.GetTileEntityAtTile(x + area.X, y + area.Y);
                                if (data != null)
                                {
                                    var newEntity = data.Copy();
                                    newEntity.PosX = (short)x;
                                    newEntity.PosY = (short)y;
                                    buffer.TileEntities.Add(newEntity);
                                }
                            }
                        }
                    }
                    buffer.Tiles[x, y] = curTile;
                }
            }

            buffer.RenderBuffer();
            return(buffer);
        }
Exemple #45
0
        public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor)
        {
            SpriteEffects effects1 = SpriteEffects.None;

            if (projectile.direction == 1)
            {
                effects1 = SpriteEffects.FlipHorizontally;
            }
            Microsoft.Xna.Framework.Color color3 = Lighting.GetColor((int)((double)projectile.position.X + (double)projectile.width * 0.5) / 16, (int)(((double)projectile.position.Y + (double)projectile.height * 0.5) / 16.0));
            {
                Texture2D texture = Main.projectileTexture[projectile.type];
                Texture2D glow    = Main.projectileTexture[projectile.type];
                int       height  = Main.projectileTexture[projectile.type].Height / Main.projFrames[projectile.type];
                Microsoft.Xna.Framework.Rectangle r = new Microsoft.Xna.Framework.Rectangle(0, height * projectile.frame, texture.Width, height);
                Vector2 origin = r.Size() / 2f;
                int     num2   = 5;
                int     num3   = 1;
                int     num4   = 1;
                float   num5   = 1f;
                float   num6   = 0.0f;
                num3 = 1;
                num5 = 3f;
                int index1 = num4;
                while (num3 > 0 && index1 < num2 || num3 < 0 && index1 > num2)
                {
                    Microsoft.Xna.Framework.Color newColor = color3;
                    newColor = Microsoft.Xna.Framework.Color.Lerp(newColor, Microsoft.Xna.Framework.Color.White, 2.5f);
                    Microsoft.Xna.Framework.Color color1 = projectile.GetAlpha(newColor);
                    float num7 = (float)(num2 - index1);
                    if (num3 < 0)
                    {
                        num7 = (float)(num4 - index1);
                    }
                    Microsoft.Xna.Framework.Color color2 = color1 * (num7 / ((float)ProjectileID.Sets.TrailCacheLength[projectile.type] * 1.5f));
                    Vector2       oldPo    = projectile.oldPos[index1];
                    float         rotation = projectile.rotation;
                    SpriteEffects effects2 = effects1;
                    if (ProjectileID.Sets.TrailingMode[projectile.type] == 2)
                    {
                        rotation = projectile.oldRot[index1];
                        effects2 = projectile.oldSpriteDirection[index1] == -1 ? SpriteEffects.FlipHorizontally : SpriteEffects.None;
                    }
                    Main.spriteBatch.Draw(glow, oldPo + projectile.Size / 2f - Main.screenPosition + new Vector2(0.0f, projectile.gfxOffY), new Microsoft.Xna.Framework.Rectangle?(r), color2, rotation + projectile.rotation * num6 * (float)(index1 - 1) * (float)-effects1.HasFlag((Enum)SpriteEffects.FlipHorizontally).ToDirectionInt(), origin, MathHelper.Lerp(projectile.scale, num5, (float)index1 / 15f), effects2, 0.0f);
label_709:
                    index1 += num3;
                }

                Microsoft.Xna.Framework.Color color4 = projectile.GetAlpha(color3);
                Main.spriteBatch.Draw(texture, projectile.Center - Main.screenPosition + new Vector2(0.0f, projectile.gfxOffY), new Microsoft.Xna.Framework.Rectangle?(r), new Color(255 - projectile.alpha, 255 - projectile.alpha, 255 - projectile.alpha, 175), projectile.rotation, origin, projectile.scale, effects1, 0.0f);
            }
            for (int a = 0; a < 1; a++)
            {
                SpriteEffects spriteEffects = SpriteEffects.None;
                if (projectile.spriteDirection == 1)
                {
                    spriteEffects = SpriteEffects.FlipHorizontally;
                }
                Texture2D texture   = Main.projectileTexture[projectile.type];
                Vector2   vector2_3 = new Vector2((float)(Main.projectileTexture[projectile.type].Width / 2), (float)(Main.projectileTexture[projectile.type].Height / 1 / 2));
                int       height    = Main.projectileTexture[projectile.type].Height / Main.projFrames[projectile.type];
                Microsoft.Xna.Framework.Rectangle r = new Microsoft.Xna.Framework.Rectangle(0, height * projectile.frame, texture.Width, height);
                float addY      = 0f;
                float addHeight = 0f;
                int   num7      = 5;
                float num9      = (float)(Math.Cos((double)Main.GlobalTime % 2.40000009536743 / 2.40000009536743 * 6.28318548202515) / 2.0 + 0.5);
                float num99     = (float)(Math.Cos((double)Main.GlobalTime % 2.40000009536743 / 2.40000009536743 * 6.28318548202515) / 4.0 + 0.5);
                float num8      = 0f;
                Microsoft.Xna.Framework.Color secondColor = Microsoft.Xna.Framework.Color.White;

                float   num10 = 0.0f;
                Vector2 bb    = projectile.Center - Main.screenPosition - new Vector2((float)texture.Width, (float)(texture.Height / 1)) * projectile.scale / 2f + vector2_3 * projectile.scale + new Vector2(0.0f, addY + addHeight + projectile.gfxOffY);
                Microsoft.Xna.Framework.Color color2 = new Microsoft.Xna.Framework.Color((int)sbyte.MaxValue - projectile.alpha, (int)sbyte.MaxValue - projectile.alpha, (int)sbyte.MaxValue - projectile.alpha, 0).MultiplyRGBA(Microsoft.Xna.Framework.Color.White);
                for (int index2 = 0; index2 < 4; ++index2)
                {
                    Microsoft.Xna.Framework.Color newColor2 = color2;
                    Microsoft.Xna.Framework.Color faa       = projectile.GetAlpha(newColor2) * (1f - num99);
                    Vector2 position2 = projectile.Center + ((float)((double)index2 / (double)4 * 6.28318548202515) + projectile.rotation + num10).ToRotationVector2() * (float)(8.0 * (double)num99 + 2.0) - Main.screenPosition - new Vector2((float)texture.Width, (float)(texture.Height / 1)) * projectile.scale / 2f + vector2_3 * projectile.scale + new Vector2(0.0f, addY + addHeight + projectile.gfxOffY);
                    Main.spriteBatch.Draw(Main.projectileTexture[projectile.type], position2, new Microsoft.Xna.Framework.Rectangle?(r), faa, projectile.rotation, vector2_3, projectile.scale, spriteEffects, 0.0f);
                }
            }

            Lighting.AddLight(projectile.Center, Color.Yellow.ToVector3() / 2f);

            return(false);
        }
Exemple #46
0
        /// <summary>Edit a matched asset.</summary>
        /// <param name="asset">A helper which encapsulates metadata about an asset and enables changes to it.</param>
        public void Edit <T>(IAssetData asset)
        {
            Monitor.Log("Editing asset" + asset.AssetName);
            if (asset.AssetName.EndsWith("outdoorsTileSheet"))
            {
                var image = asset.AsImage();
                int y     = 0;
                if (asset.AssetName.EndsWith("summer_outdoorsTileSheet"))
                {
                    y = 1;
                }
                else if (asset.AssetName.EndsWith("fall_outdoorsTileSheet"))
                {
                    y = 2;
                }
                else if (asset.AssetName.EndsWith("winter_outdoorsTileSheet"))
                {
                    y = 3;
                }
                Rectangle rect = new Rectangle(0, y * 16, 32, 16);

                image.PatchImage(tilesTexture, rect, new Rectangle(208, 1232, 32, 16));

                return;
            }
            else if (asset.AssetName.StartsWith("Maps"))
            {
                try
                {
                    var mapData = asset.AsMap();
                    for (int x = 0; x < mapData.Data.Layers[0].LayerWidth; x++)
                    {
                        for (int y = 0; y < mapData.Data.Layers[0].LayerHeight; y++)
                        {
                            //Monitor.Log($"{x},{y},{map.GetLayer("Buildings").Tiles[x, y]?.TileIndex},{map.GetLayer("Front").Tiles[x, y]?.TileIndex}",LogLevel.Warn);

                            if (mapData.Data.GetLayer("Buildings").Tiles[x, y]?.TileIndex == 1938)
                            {
                                Monitor.Log("Removing existing pet bowl.");
                                mapData.Data.GetLayer("Buildings").Tiles[x, y]      = null;
                                mapData.Data.GetLayer("Back").Tiles[x, y].TileIndex = 1938;
                                try
                                {
                                    mapData.Data.GetLayer("Back").Tiles[x - 1, y].Properties.Remove("NoFurniture");
                                    mapData.Data.GetLayer("Back").Tiles[x - 1, y].Properties.Remove("Placeable");
                                }
                                catch
                                {
                                }
                                try
                                {
                                    mapData.Data.GetLayer("Back").Tiles[x - 1, y + 1].Properties.Remove("NoFurniture");
                                    mapData.Data.GetLayer("Back").Tiles[x - 1, y + 1].Properties.Remove("Placeable");
                                }
                                catch
                                {
                                }
                                try
                                {
                                    mapData.Data.GetLayer("Back").Tiles[x, y + 1].Properties.Remove("NoFurniture");
                                    mapData.Data.GetLayer("Back").Tiles[x, y + 1].Properties.Remove("Placeable");
                                }
                                catch
                                {
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Monitor.Log($"Exception removing existing pet bowl.\n{ex}", LogLevel.Error);
                }
                return;
            }
        }
        public static MonoRect Scale(this MonoRect rect, float horizontal, float vertical)
        {
            Vector2 newSize = rect.Size.ToVector2() * new Microsoft.Xna.Framework.Vector2(horizontal, vertical);

            return(new MonoRect(rect.Location, newSize.ToPoint()));
        }
        private void OnDraw(object sender, GameTimerEventArgs e)
        {
            var camera = new CameraModel(level.Camera, RenderSize);

            var basicEffect = new BasicEffect(graphics);

            graphics.Clear(level.Skybox.Color);

            graphics.BlendState        = BlendState.Opaque;
            graphics.DepthStencilState = DepthStencilState.Default;

            basicEffect.EnableDefaultLighting();

            basicEffect.LightingEnabled    = true;
            basicEffect.TextureEnabled     = true;
            basicEffect.VertexColorEnabled = false;
            basicEffect.FogEnabled         = true;
            basicEffect.FogColor           = new Vector3(0.2f, 0.3f, 0.8f);
            basicEffect.FogStart           = 10f;
            basicEffect.FogEnd             = 75000f;

            basicEffect.DirectionalLight0.Enabled       = true;
            basicEffect.DirectionalLight0.DiffuseColor  = new Vector3(0, 0, 0);
            basicEffect.DirectionalLight0.Direction     = new Vector3(0, 1, 0);
            basicEffect.DirectionalLight0.SpecularColor = new Vector3(0, 0, 0);
            graphics.RasterizerState = RasterizerState.CullClockwise;

            foreach (var spaceship in level.Objects3D.OfType <Spaceship>())
            {
                var model = game.Resources.Models[spaceship.Id];
                model.Draw(Matrix.CreateRotationY(MathHelper.ToRadians(180)) * Matrix.CreateFromQuaternion(spaceship.Orientation * spaceship.ShipLeaning) * Matrix.CreateTranslation(spaceship.Position), camera.View, camera.Projection);
            }

            basicEffect.World      = Matrix.Identity;
            basicEffect.View       = camera.View;
            basicEffect.Projection = camera.Projection;

            graphics.RasterizerState = RasterizerState.CullCounterClockwise;

            game.Resources.Terrains[level.Terrain.Id].Draw(basicEffect, game.Resources.Sprites[Data.Grass]);

            var bounds = graphics.Viewport.Bounds;

            spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive);
            foreach (var explosion in level.Objects3D.OfType <Explosion>())
            {
                var transformed = graphics.Viewport.Project(explosion.Position, camera.Projection, camera.View, Matrix.Identity);
                var distance    = (explosion.Position - level.Camera.Position).Length();
                if (transformed.Z > 0 && transformed.Z < 1 && distance > 0)
                {
                    var sprite    = game.Resources.Sprites[explosion.Id];
                    var width     = explosion.CurrentSize * bounds.Width * (float)sprite.Width / distance;
                    var rectangle = new Microsoft.Xna.Framework.Rectangle((int)(transformed.X), (int)(transformed.Y), (int)width, (int)width);
                    if (rectangle.Intersects(graphics.Viewport.Bounds))
                    {
                        spriteBatch.Draw(sprite, rectangle, null, new Color(2 - explosion.Age, 2 - explosion.Age, 1 - explosion.Age, 2 - explosion.Age), explosion.StartSpin + explosion.Spin * explosion.Age, new Vector2(sprite.Width / 2), SpriteEffects.None, 0);
                    }
                }
            }
            spriteBatch.End();
            spriteBatch.Begin();
            foreach (var bullet in level.Objects3D.OfType <Bullet>())
            {
                var transformed = graphics.Viewport.Project(bullet.Position, camera.Projection, camera.View, Matrix.Identity);
                var distance    = (bullet.Position - level.Camera.Position).Length();
                if (transformed.Z > 0 && transformed.Z < 1 && distance > 0)
                {
                    var sprite    = game.Resources.Sprites[bullet.Id];
                    var width     = bullet.Boundary.Radius * 2 * bounds.Width * (float)sprite.Width / distance;
                    var rectangle = new Microsoft.Xna.Framework.Rectangle((int)(transformed.X), (int)(transformed.Y), (int)width, (int)width);
                    if (rectangle.Intersects(graphics.Viewport.Bounds))
                    {
                        spriteBatch.Draw(sprite, rectangle, null, Color.White, 0, new Vector2(sprite.Width / 2), SpriteEffects.None, 0);
                    }
                }
            }
            var enemyCount     = level.Objects3D.OfType <Spaceship>().Count();
            var enemyCountText = (enemyCount > 0 ? enemyCount - 1 : 0).ToString();
            var enemyCountSize = game.Resources.Fonts[Data.Font].MeasureString(enemyCountText).X;

            var osdBlend = Color.White * (1f - MathHelper.Clamp((fadeOut.HasValue ? fadeOut.Value : 0) * 1.5f - 1, 0, 1));

            if (fadeIn < 1f)
            {
                var timer   = (1 - fadeIn) * fadeInTime;
                var msg     = timer < 0.5 ? "go" : Math.Ceiling(timer).ToString();
                var msgSize = game.Resources.Fonts[Data.Font].MeasureString(msg).X;
                spriteBatch.DrawString(game.Resources.Fonts[Data.Font], msg, new Vector2(graphics.Viewport.Width - msgSize - 20, 10), osdBlend);
                spriteBatch.Draw(game.Resources.Sprites[Data.TutorialOverlay], new Microsoft.Xna.Framework.Rectangle(0, 0, graphics.Viewport.Width, graphics.Viewport.Height), new Color(1f, 1f, 1f) * MathHelper.Clamp(4 * (1 - fadeIn), 0, 1));
            }
            else
            {
                spriteBatch.DrawString(game.Resources.Fonts[Data.Font], enemyCountText, new Vector2(graphics.Viewport.Width - enemyCountSize - 20, 10), osdBlend);
            }

            if (fadeOut.HasValue)
            {
                spriteBatch.Draw(game.Resources.Sprites[Data.BlackBackground], new Microsoft.Xna.Framework.Rectangle(0, 0, graphics.Viewport.Width, graphics.Viewport.Height), new Color(0, 0, 0, fadeOut.Value / 2));
                if (dead == true)
                {
                    spriteBatch.Draw(game.Resources.Sprites[Data.GameOverOverlay], new Microsoft.Xna.Framework.Rectangle(0, 0, graphics.Viewport.Width, graphics.Viewport.Height), new Color(1f, 1f, 1f) * MathHelper.Clamp(fadeOut.Value * 2.5f - 1, 0, 1));
                }
                else if (won == true)
                {
                    spriteBatch.Draw(game.Resources.Sprites[Data.GameWonOverlay], new Microsoft.Xna.Framework.Rectangle(0, 0, graphics.Viewport.Width, graphics.Viewport.Height), new Color(1f, 1f, 1f) * MathHelper.Clamp(fadeOut.Value * 2.5f - 1, 0, 1));
                }
            }
            spriteBatch.End();
        }
        protected override void Draw()
        {
            DrawingManager.ViewPortSize = new Point(this.Width, this.Height);
            Update(1 / 60f);
            ParentEditor.ZoomBox.Camera.Position = new Vector2(-this.AutoScrollPosition.X, -this.AutoScrollPosition.Y);
            ParentEditor.ZoomBox.Camera.Update(1 / 60f);
            Vector2 sizeRatio = new Vector2(
                (float)this.Size.Width / ((float)this.Size.Width * ParentEditor.ZoomBox.Camera.Zoom.X),
                (float)this.Size.Height / ((float)this.Size.Height * ParentEditor.ZoomBox.Camera.Zoom.Y));

            GraphicsDevice.Clear(Color.White);
            // Use SpriteSortMode.Immediate, so we can apply custom renderstates.
            _spriteBatch.Begin(SpriteSortMode.Immediate, null, SamplerState.LinearWrap, null, null);
            // Set the texture addressing mode to wrap, so we can repeat
            // many copies of our tiled checkerboard texture.
            Rectangle fullRect = new Rectangle(0, 0, this.Width, this.Height);

            // Draw a tiled crossed pattern in the background.
            _spriteBatch.Draw(_crossTexture, fullRect, fullRect, Color.White);
            _spriteBatch.Draw(_checkerTexture, new Rectangle(0, 0, (int)(_tileGrid.BoundingRect.Width * ParentEditor.ZoomBox.Camera.Zoom.X),
                                                             (int)(_tileGrid.BoundingRect.Height * ParentEditor.ZoomBox.Camera.Zoom.Y)),
                              new Rectangle(0, 0, (int)(_tileGrid.BoundingRect.Width * ParentEditor.ZoomBox.Camera.Zoom.X),
                                            (int)(_tileGrid.BoundingRect.Height * ParentEditor.ZoomBox.Camera.Zoom.Y)), Color.White);
            _spriteBatch.End();

            this.AutoScrollMinSize = new System.Drawing.Size((int)(_tileGrid.BoundingRect.Width * ParentEditor.ZoomBox.Camera.Zoom.X),
                                                             (int)(_tileGrid.BoundingRect.Height * ParentEditor.ZoomBox.Camera.Zoom.Y));

            Vector2 pos = _tileGrid.Position;

            _tileGrid.Position = Vector2.Zero;
            _tileGrid.Pivot    = Vector2.Zero;
            _tileGrid.Draw(1 / 60f);
            _tileGrid.Position = pos;
            //_camera.Position += _tileGrid.Position;
            if (PaintMode == TileGridPaintMode.Brush)
            {
                DrawBrushTileHighlight(new Color(25, 255, 100, 150));
            }
            else if (PaintMode == TileGridPaintMode.Bucket)
            {
                DrawBrushTileHighlight(new Color(25, 100, 255, 150));
                _brushSize = new Point(1, 1);
            }
            else if (PaintMode == TileGridPaintMode.Eraser)
            {
                DrawBrushTileHighlight(new Color(255, 0, 0, 150));
            }
            else if (PaintMode == TileGridPaintMode.Edit)
            {
                foreach (Point tile in _selectedTiles)
                {
                    DrawTileSelection(tile.X, tile.Y);
                }
                if (_isPastingTiles)
                {
                    DrawPastingSelection(_drawPosPastingSelection.X,
                                         _drawPosPastingSelection.Y);
                }
            }
            else if (PaintMode == TileGridPaintMode.Passage)
            {
                for (int y = 0; y < _tileGrid.TileRows; ++y)
                {
                    for (int x = 0; x < _tileGrid.TileCols; ++x)
                    {
                        Color fillColor;
                        if (TileGrid.TileLayers[0].Tiles[x][y].Passable)
                        {
                            fillColor = new Color(80, 100, 150, 150);
                        }
                        else
                        {
                            fillColor = new Color(80, 0, 15, 150);
                        }

                        Vector2 position = new Vector2(x * TileGrid.TileSize.X * TileGrid.Scale.X,
                                                       y * TileGrid.TileSize.Y * TileGrid.Scale.Y);
                        Vector2 size = new Vector2(TileGrid.TileSize.X * TileGrid.Scale.X,
                                                   TileGrid.TileSize.Y * TileGrid.Scale.Y);
                        DrawingManager.DrawFilledRectangle(TileGrid.Layer, position, size,
                                                           fillColor, TileGrid.BlendingType);
                    }
                }
            }
            if (_drawGrid == true)
            {
                DrawGridLines();
            }
            SquidEditorForm.SwapCameraAndRenderScene(ParentEditor.ZoomBox.Camera);
            _parent.Update(1 / 60f);
        }
Exemple #50
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Text"/> class. Locates this <see cref="Text"/> within the given <see cref="Microsoft.Xna.Framework.Rectangle"/>.
        /// </summary>
        /// <param name="text">
        /// A <see cref="string"/> representing the <see cref="TextContent"/> to be drawn.
        /// </param>
        /// <param name="font">
        /// A <see cref="SpriteFont"/> indicating the font used to draw the <see cref="TextContent"/>.
        /// </param>
        /// <param name="color">
        /// A <see cref="Color"/> indicating the color in which the <see cref="TextContent"/> is drawn.
        /// </param>
        /// <param name="effects">
        /// A <see cref="SpriteEffects"/> indicating the effects used by the <see cref="TextContent"/>.
        /// </param>
        /// <param name="bounds">
        /// A <see cref="Rectangle"/> indicating the boundaries of this <see cref="Text"/>.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="color"/> or <paramref name="font"/> or <paramref name="text"/> is a null reference.
        /// </exception>
        public Text(string text, SpriteFont font, Color color, SpriteEffects effects, Microsoft.Xna.Framework.Rectangle bounds)
        {
            if (color == null)
            {
                throw new ArgumentNullException("color");
            }

            if (font == null)
            {
                throw new ArgumentNullException("font");
            }

            if (text == null)
            {
                throw new ArgumentNullException("text");
            }

            ////if (text.IsNullOrEmpty) {
            ////    throw new ArgumentException("text must consist of at least one character.", "text");
            ////}

            this.TextContent = text;
            this.Color       = color;
            this.effects     = effects;
            this.font        = font;
            this.bounds      = bounds;
            this.AdjustText(bounds);
            this.origin   = Vector2.Zero;
            this.rotation = 0F;
        }
Exemple #51
0
        public static void BuildOneSpouseRoom(FarmHouse farmHouse, string name, int count)
        {
            NPC    spouse    = Game1.getCharacterFromName(name);
            string back      = "Back";
            string buildings = "Buildings";
            string front     = "Front";

            if (spouse != null || name == "")
            {
                if (farmHouse.owner.friendshipData[spouse.Name] != null && farmHouse.owner.friendshipData[spouse.Name].IsEngaged())
                {
                    name = "";
                }
                Map refurbishedMap;
                if (name == "")
                {
                    refurbishedMap = PHelper.Content.Load <Map>("Maps\\" + farmHouse.Name + ((farmHouse.upgradeLevel == 0) ? "" : ((farmHouse.upgradeLevel == 3) ? "2" : string.Concat(farmHouse.upgradeLevel))) + "_marriage", ContentSource.GameContent);
                }
                else
                {
                    refurbishedMap = PHelper.Content.Load <Map>("Maps\\spouseRooms", ContentSource.GameContent);
                }
                int indexInSpouseMapSheet = -1;

                if (roomIndexes.ContainsKey(name))
                {
                    indexInSpouseMapSheet = roomIndexes[name];
                    if (name == "Emily")
                    {
                        farmHouse.temporarySprites.RemoveAll((s) => s is EmilysParrot);

                        int     offset       = (1 + count) * 7 * 64;
                        Vector2 parrotSpot   = new Vector2(2064f + offset, 160f);
                        int     upgradeLevel = farmHouse.upgradeLevel;
                        if (upgradeLevel > 1)
                        {
                            parrotSpot = new Vector2(2448f + offset, 736f);
                        }
                        ModEntry.PMonitor.Log($"Building Emily's parrot at {parrotSpot}, spouse room count {count}, upgrade level {upgradeLevel}");
                        farmHouse.temporarySprites.Add(new EmilysParrot(parrotSpot));
                    }
                }
                else if (tmxSpouseRooms.ContainsKey(name))
                {
                    refurbishedMap = tmxSpouseRooms[name];
                    if (refurbishedMap == null)
                    {
                        ModEntry.PMonitor.Log($"Couldn't load TMX spouse room for spouse {name}", LogLevel.Error);
                        return;
                    }
                    try
                    {
                        back      = refurbishedMap.Layers[0].Id;
                        buildings = refurbishedMap.Layers[1].Id;
                        front     = refurbishedMap.Layers[2].Id;
                    }
                    catch (Exception ex)
                    {
                        ModEntry.PMonitor.Log($"Couldn't load TMX spouse room layers for spouse {name}. Exception: {ex}", LogLevel.Error);
                    }

                    indexInSpouseMapSheet = 0;
                }
                else if (name != "")
                {
                    return;
                }


                Monitor.Log($"Building {name}'s room", LogLevel.Debug);

                Microsoft.Xna.Framework.Rectangle areaToRefurbish = (farmHouse.upgradeLevel == 1) ? new Microsoft.Xna.Framework.Rectangle(36 + (7 * count), 1, 6, 9) : new Microsoft.Xna.Framework.Rectangle(42 + (7 * count), 10, 6, 9);

                Point mapReader;
                if (name == "")
                {
                    mapReader = new Point(areaToRefurbish.X, areaToRefurbish.Y);
                }
                else
                {
                    mapReader = new Point(indexInSpouseMapSheet % 5 * 6, indexInSpouseMapSheet / 5 * 9);
                }
                farmHouse.map.Properties.Remove("DayTiles");
                farmHouse.map.Properties.Remove("NightTiles");


                List <string> sheetNames = new List <string>();
                for (int i = 0; i < farmHouse.map.TileSheets.Count; i++)
                {
                    sheetNames.Add(farmHouse.map.TileSheets[i].Id);
                    //Monitor.Log($"tilesheet id: {farmHouse.map.TileSheets[i].Id}");
                }
                int untitled   = sheetNames.IndexOf("untitled tile sheet");
                int floorsheet = sheetNames.IndexOf("walls_and_floors");
                int indoor     = sheetNames.IndexOf("indoor");


                int ox = ModEntry.config.ExistingSpouseRoomOffsetX;
                int oy = ModEntry.config.ExistingSpouseRoomOffsetY;
                if (farmHouse.upgradeLevel > 1)
                {
                    ox += 6;
                    oy += 9;
                }

                if (ModEntry.config.BuildAllSpousesRooms)
                {
                    for (int i = 0; i < 7; i++)
                    {
                        // bottom wall
                        farmHouse.setMapTileIndex(ox + 36 + i + (count * 7), oy + 10, 165, "Front", indoor);
                        farmHouse.setMapTileIndex(ox + 36 + i + (count * 7), oy + 11, 0, "Buildings", indoor);


                        farmHouse.removeTile(ox + 35 + (7 * count), oy + 4 + i, "Back");

                        if (count % 2 == 0)
                        {
                            // vert hall
                            farmHouse.setMapTileIndex(ox + 35 + (7 * count), oy + 4 + i, (i % 2 == 0 ? 352 : 336), "Back", floorsheet);
                            // horiz hall
                            farmHouse.setMapTileIndex(ox + 36 + i + (count * 7), oy + 10, (i % 2 == 0 ? 336 : 352), "Back", floorsheet);
                        }
                        else
                        {
                            // vert hall

                            farmHouse.setMapTileIndex(ox + 35 + (7 * count), oy + 4 + i, (i % 2 == 0 ? 336 : 352), "Back", floorsheet);
                            // horiz hall
                            farmHouse.setMapTileIndex(ox + 36 + i + (count * 7), oy + 10, (i % 2 == 0 ? 352 : 336), "Back", floorsheet);
                        }
                    }

                    for (int i = 0; i < 6; i++)
                    {
                        // top wall
                        farmHouse.setMapTileIndex(ox + 36 + i + (count * 7), oy + 0, 2, "Buildings", indoor);
                    }

                    // vert wall
                    farmHouse.setMapTileIndex(ox + 35 + (7 * count), oy + 0, 87, "Buildings", untitled);
                    farmHouse.setMapTileIndex(ox + 35 + (7 * count), oy + 1, 99, "Buildings", untitled);
                    farmHouse.setMapTileIndex(ox + 35 + (7 * count), oy + 2, 111, "Buildings", untitled);
                    farmHouse.setMapTileIndex(ox + 35 + (7 * count), oy + 3, 123, "Buildings", untitled);
                    farmHouse.setMapTileIndex(ox + 35 + (7 * count), oy + 4, 135, "Buildings", untitled);
                }
                for (int x = 0; x < areaToRefurbish.Width; x++)
                {
                    for (int y = 0; y < areaToRefurbish.Height; y++)
                    {
                        //PMonitor.Log($"x {x}, y {y}", LogLevel.Debug);
                        if (refurbishedMap.GetLayer(back).Tiles[mapReader.X + x, mapReader.Y + y] != null)
                        {
                            farmHouse.map.GetLayer("Back").Tiles[areaToRefurbish.X + x, areaToRefurbish.Y + y] = new StaticTile(farmHouse.map.GetLayer("Back"), farmHouse.map.GetTileSheet(refurbishedMap.GetLayer(back).Tiles[mapReader.X + x, mapReader.Y + y].TileSheet.Id), BlendMode.Alpha, refurbishedMap.GetLayer(back).Tiles[mapReader.X + x, mapReader.Y + y].TileIndex);
                        }
                        if (refurbishedMap.GetLayer(buildings).Tiles[mapReader.X + x, mapReader.Y + y] != null)
                        {
                            farmHouse.map.GetLayer("Buildings").Tiles[areaToRefurbish.X + x, areaToRefurbish.Y + y] = new StaticTile(farmHouse.map.GetLayer("Buildings"), farmHouse.map.GetTileSheet(refurbishedMap.GetLayer(buildings).Tiles[mapReader.X + x, mapReader.Y + y].TileSheet.Id), BlendMode.Alpha, refurbishedMap.GetLayer(buildings).Tiles[mapReader.X + x, mapReader.Y + y].TileIndex);

                            typeof(GameLocation).GetMethod("adjustMapLightPropertiesForLamp", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(farmHouse, new object[] { refurbishedMap.GetLayer(buildings).Tiles[mapReader.X + x, mapReader.Y + y].TileIndex, areaToRefurbish.X + x, areaToRefurbish.Y + y, "Buildings" });
                        }
                        else
                        {
                            farmHouse.map.GetLayer("Buildings").Tiles[areaToRefurbish.X + x, areaToRefurbish.Y + y] = null;
                        }
                        if (y < areaToRefurbish.Height - 1 && refurbishedMap.GetLayer(front).Tiles[mapReader.X + x, mapReader.Y + y] != null)
                        {
                            farmHouse.map.GetLayer("Front").Tiles[areaToRefurbish.X + x, areaToRefurbish.Y + y] = new StaticTile(farmHouse.map.GetLayer("Front"), farmHouse.map.GetTileSheet(refurbishedMap.GetLayer(front).Tiles[mapReader.X + x, mapReader.Y + y].TileSheet.Id), BlendMode.Alpha, refurbishedMap.GetLayer(front).Tiles[mapReader.X + x, mapReader.Y + y].TileIndex);
                            typeof(GameLocation).GetMethod("adjustMapLightPropertiesForLamp", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(farmHouse, new object[] { refurbishedMap.GetLayer(front).Tiles[mapReader.X + x, mapReader.Y + y].TileIndex, areaToRefurbish.X + x, areaToRefurbish.Y + y, "Front" });
                        }
                        else if (y < areaToRefurbish.Height - 1)
                        {
                            farmHouse.map.GetLayer("Front").Tiles[areaToRefurbish.X + x, areaToRefurbish.Y + y] = null;
                        }
                        if (x == 4 && y == 4)
                        {
                            try
                            {
                                farmHouse.map.GetLayer("Back").Tiles[areaToRefurbish.X + x, areaToRefurbish.Y + y].Properties["NoFurniture"] = new PropertyValue("T");
                            }
                            catch (Exception ex)
                            {
                                Monitor.Log(ex.ToString());
                            }
                        }
                    }
                }

                if (name == "Sebastian" && Game1.netWorldState.Value.hasWorldStateID("sebastianFrog"))
                {
                    Monitor.Log("building Sebastian's terrarium");
                    Vector2 spot = new Vector2(37 + (7 * count) + ox, 7 + oy);
                    farmHouse.removeTile((int)spot.X, (int)spot.Y - 1, "Front");
                    farmHouse.removeTile((int)spot.X + 1, (int)spot.Y - 1, "Front");
                    farmHouse.removeTile((int)spot.X + 2, (int)spot.Y - 1, "Front");
                    farmHouse.temporarySprites.Add(new TemporaryAnimatedSprite
                    {
                        texture               = Game1.mouseCursors,
                        sourceRect            = new Microsoft.Xna.Framework.Rectangle(641, 1534, 48, 37),
                        animationLength       = 1,
                        sourceRectStartingPos = new Vector2(641f, 1534f),
                        interval              = 5000f,
                        totalNumberOfLoops    = 9999,
                        position              = spot * 64f + new Vector2(0f, -5f) * 4f,
                        scale      = 4f,
                        layerDepth = (spot.Y + 2f + 0.1f) * 64f / 10000f
                    });
                    if (Game1.random.NextDouble() < 0.85)
                    {
                        Texture2D crittersText2 = Game1.temporaryContent.Load <Texture2D>("TileSheets\\critters");
                        farmHouse.TemporarySprites.Add(new SebsFrogs
                        {
                            texture               = crittersText2,
                            sourceRect            = new Microsoft.Xna.Framework.Rectangle(64, 224, 16, 16),
                            animationLength       = 1,
                            sourceRectStartingPos = new Vector2(64f, 224f),
                            interval              = 100f,
                            totalNumberOfLoops    = 9999,
                            position              = spot * 64f + new Vector2((float)((Game1.random.NextDouble() < 0.5) ? 22 : 25), (float)((Game1.random.NextDouble() < 0.5) ? 2 : 1)) * 4f,
                            scale      = 4f,
                            flipped    = (Game1.random.NextDouble() < 0.5),
                            layerDepth = (spot.Y + 2f + 0.11f) * 64f / 10000f,
                            Parent     = farmHouse
                        });
                    }
                    if (!Game1.player.activeDialogueEvents.ContainsKey("sebastianFrog2") && Game1.random.NextDouble() < 0.5)
                    {
                        Texture2D crittersText3 = Game1.temporaryContent.Load <Texture2D>("TileSheets\\critters");
                        farmHouse.TemporarySprites.Add(new SebsFrogs
                        {
                            texture               = crittersText3,
                            sourceRect            = new Microsoft.Xna.Framework.Rectangle(64, 240, 16, 16),
                            animationLength       = 1,
                            sourceRectStartingPos = new Vector2(64f, 240f),
                            interval              = 150f,
                            totalNumberOfLoops    = 9999,
                            position              = spot * 64f + new Vector2(8f, 3f) * 4f,
                            scale      = 4f,
                            layerDepth = (spot.Y + 2f + 0.11f) * 64f / 10000f,
                            flipped    = (Game1.random.NextDouble() < 0.5),
                            pingPong   = false,
                            Parent     = farmHouse
                        });
                    }
                }

                /*
                 * List<string> sheets = new List<string>();
                 * for (int i = 0; i < farmHouse.map.TileSheets.Count; i++)
                 * {
                 *      sheets.Add(farmHouse.map.TileSheets[i].Id);
                 * }
                 * for (int i = 0; i < 7; i++)
                 * {
                 *
                 *      // vert floor ext
                 *      farmHouse.removeTile(ox + 42 + (7 * count), oy + 4 + i, "Back");
                 *      farmHouse.setMapTileIndex(ox + 42 + (7 * count), oy + 4 + i, farmHouse.getTileIndexAt(ox + 41 + (7 * count), oy + 4 + i, "Back"), "Back", sheets.IndexOf(farmHouse.getTileSheetIDAt(ox + 41 + (7 * count), oy + 4 + i, "Back")));
                 * }
                 */
            }
        }
Exemple #52
0
 internal static Vector2 CenterString(SpriteFont font, string text, Microsoft.Xna.Framework.Rectangle boundaries)
 {
     return(Text.CenterString(font, text, boundaries, 1.0f));
 }
        public void _draw(Game1 tthis, GameTime gameTime, RenderTarget2D target_screen)
        {
            Game1.showingHealthBar = false;
            Color bgColor = Color.Black;
            {
                if (target_screen != null)
                {
                    tthis.GraphicsDevice.SetRenderTarget(target_screen);
                }
                {
                    tthis.GraphicsDevice.Clear(bgColor);

                    if (Game1.gameMode == (byte)11)
                    {
                        Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, (DepthStencilState)null, (RasterizerState)null);
                        Game1.spriteBatch.DrawString(Game1.dialogueFont, Game1.content.LoadString("Strings\\StringsFromCSFiles:Game1.cs.3685"), new Vector2(16f, 16f), Microsoft.Xna.Framework.Color.HotPink);
                        Game1.spriteBatch.DrawString(Game1.dialogueFont, Game1.content.LoadString("Strings\\StringsFromCSFiles:Game1.cs.3686"), new Vector2(16f, 32f), new Microsoft.Xna.Framework.Color(0, (int)byte.MaxValue, 0));
                        Game1.spriteBatch.DrawString(Game1.dialogueFont, Game1.parseText(Game1.errorMessage, Game1.dialogueFont, Game1.graphics.GraphicsDevice.Viewport.Width), new Vector2(16f, 48f), Microsoft.Xna.Framework.Color.White);
                        Game1.spriteBatch.End();
                    }
                    else if (Game1.gameMode == (byte)6 || Game1.gameMode == (byte)3 && Game1.currentLocation == null)
                    {
                        Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, (DepthStencilState)null, (RasterizerState)null);
                        string str1 = "";
                        for (int index = 0; (double)index < gameTime.TotalGameTime.TotalMilliseconds % 999.0 / 333.0; ++index)
                        {
                            str1 += ".";
                        }
                        string str2          = Game1.content.LoadString("Strings\\StringsFromCSFiles:Game1.cs.3688");
                        string s             = str2 + str1;
                        string str3          = str2 + "... ";
                        int    widthOfString = SpriteText.getWidthOfString(str3, 999999);
                        int    height        = 64;
                        int    x             = 64;
                        int    y             = Game1.graphics.GraphicsDevice.Viewport.GetTitleSafeArea().Bottom - height;
                        SpriteText.drawString(Game1.spriteBatch, s, x, y, 999999, widthOfString, height, 1f, 0.88f, false, 0, str3, -1, SpriteText.ScrollTextAlignment.Left);
                        Game1.spriteBatch.End();
                        if (target_screen != null)
                        {
                            tthis.GraphicsDevice.SetRenderTarget((RenderTarget2D)null);
                            tthis.GraphicsDevice.Clear(bgColor);
                            Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, DepthStencilState.Default, RasterizerState.CullNone);
                            Game1.spriteBatch.Draw((Texture2D)target_screen, Vector2.Zero, new Microsoft.Xna.Framework.Rectangle?(target_screen.Bounds), Microsoft.Xna.Framework.Color.White, 0.0f, Vector2.Zero, Game1.options.zoomLevel, SpriteEffects.None, 1f);
                            Game1.spriteBatch.End();
                        }
                        if (Game1.overlayMenu != null)
                        {
                            Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, (DepthStencilState)null, (RasterizerState)null);
                            Game1.overlayMenu.draw(Game1.spriteBatch);
                            Game1.spriteBatch.End();
                        }
                    }
                    else
                    {
                        Microsoft.Xna.Framework.Rectangle rectangle;
                        Viewport viewport;
                        if (Game1.gameMode == (byte)0)
                        {
                            Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, (DepthStencilState)null, (RasterizerState)null);
                        }
                        else
                        {
                            if (Game1.drawLighting)
                            {
                                tthis.GraphicsDevice.SetRenderTarget(Game1.lightmap);
                                tthis.GraphicsDevice.Clear(Microsoft.Xna.Framework.Color.White * 0.0f);
                                Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, SamplerState.PointClamp, (DepthStencilState)null, (RasterizerState)null);
                                Microsoft.Xna.Framework.Color color = !Game1.currentLocation.Name.StartsWith("UndergroundMine") || !(Game1.currentLocation is MineShaft) ? (Game1.ambientLight.Equals(Microsoft.Xna.Framework.Color.White) || Game1.isRaining && (bool)(NetFieldBase <bool, NetBool>)Game1.currentLocation.isOutdoors ? Game1.outdoorLight : Game1.ambientLight) : (Game1.currentLocation as MineShaft).getLightingColor(gameTime);
                                Game1.spriteBatch.Draw(Game1.staminaRect, Game1.lightmap.Bounds, color);
                                foreach (LightSource currentLightSource in Game1.currentLightSources)
                                {
                                    if (!Game1.isRaining && !Game1.isDarkOut() || currentLightSource.lightContext.Value != LightSource.LightContext.WindowLight)
                                    {
                                        if (currentLightSource.PlayerID != 0L && currentLightSource.PlayerID != Game1.player.UniqueMultiplayerID)
                                        {
                                            Farmer farmerMaybeOffline = Game1.getFarmerMaybeOffline(currentLightSource.PlayerID);
                                            if (farmerMaybeOffline == null || farmerMaybeOffline.currentLocation != null && farmerMaybeOffline.currentLocation.Name != Game1.currentLocation.Name || (bool)(NetFieldBase <bool, NetBool>)farmerMaybeOffline.hidden)
                                            {
                                                continue;
                                            }
                                        }
                                        if (Utility.isOnScreen((Vector2)(NetFieldBase <Vector2, NetVector2>)currentLightSource.position, (int)((double)(float)(NetFieldBase <float, NetFloat>)currentLightSource.radius * 64.0 * 4.0)))
                                        {
                                            Game1.spriteBatch.Draw(currentLightSource.lightTexture, Game1.GlobalToLocal(Game1.viewport, (Vector2)(NetFieldBase <Vector2, NetVector2>)currentLightSource.position) / (float)(Game1.options.lightingQuality / 2), new Microsoft.Xna.Framework.Rectangle?(currentLightSource.lightTexture.Bounds), (Microsoft.Xna.Framework.Color)(NetFieldBase <Microsoft.Xna.Framework.Color, NetColor>) currentLightSource.color, 0.0f, new Vector2((float)currentLightSource.lightTexture.Bounds.Center.X, (float)currentLightSource.lightTexture.Bounds.Center.Y), (float)(NetFieldBase <float, NetFloat>)currentLightSource.radius / (float)(Game1.options.lightingQuality / 2), SpriteEffects.None, 0.9f);
                                        }
                                    }
                                }
                                Game1.spriteBatch.End();
                                tthis.GraphicsDevice.SetRenderTarget(target_screen);
                            }
                            if (Game1.bloomDay && Game1.bloom != null)
                            {
                                Game1.bloom.BeginDraw();
                            }
                            tthis.GraphicsDevice.Clear(bgColor);
                            Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, (DepthStencilState)null, (RasterizerState)null);
                            if (Game1.background != null)
                            {
                                Game1.background.draw(Game1.spriteBatch);
                            }
                            Game1.mapDisplayDevice.BeginScene(Game1.spriteBatch);
                            Game1.currentLocation.Map.GetLayer("Back").Draw(Game1.mapDisplayDevice, Game1.viewport, xTile.Dimensions.Location.Origin, false, 4);
                            Game1.currentLocation.drawWater(Game1.spriteBatch);

                            if (!Game1.currentLocation.shouldHideCharacters())
                            {
                                if (Game1.CurrentEvent == null)
                                {
                                    foreach (NPC character in Game1.currentLocation.characters)
                                    {
                                        if (!(bool)(NetFieldBase <bool, NetBool>)character.swimming && !character.HideShadow && (!character.IsInvisible && !Game1.currentLocation.shouldShadowBeDrawnAboveBuildingsLayer(character.getTileLocation())))
                                        {
                                            Game1.spriteBatch.Draw(Game1.shadowTexture, Game1.GlobalToLocal(Game1.viewport, character.Position + new Vector2((float)(character.Sprite.SpriteWidth * 4) / 2f, (float)(character.GetBoundingBox().Height + (character.IsMonster ? 0 : 12)))), new Microsoft.Xna.Framework.Rectangle?(Game1.shadowTexture.Bounds), Microsoft.Xna.Framework.Color.White, 0.0f, new Vector2((float)Game1.shadowTexture.Bounds.Center.X, (float)Game1.shadowTexture.Bounds.Center.Y), (float)(4.0 + (double)character.yJumpOffset / 40.0) * (float)(NetFieldBase <float, NetFloat>)character.scale, SpriteEffects.None, Math.Max(0.0f, (float)character.getStandingY() / 10000f) - 1E-06f);
                                        }
                                    }
                                }
                                else
                                {
                                    foreach (NPC actor in Game1.CurrentEvent.actors)
                                    {
                                        if (!(bool)(NetFieldBase <bool, NetBool>)actor.swimming && !actor.HideShadow && !Game1.currentLocation.shouldShadowBeDrawnAboveBuildingsLayer(actor.getTileLocation()))
                                        {
                                            Game1.spriteBatch.Draw(Game1.shadowTexture, Game1.GlobalToLocal(Game1.viewport, actor.Position + new Vector2((float)(actor.Sprite.SpriteWidth * 4) / 2f, (float)(actor.GetBoundingBox().Height + (actor.IsMonster ? 0 : (actor.Sprite.SpriteHeight <= 16 ? -4 : 12))))), new Microsoft.Xna.Framework.Rectangle?(Game1.shadowTexture.Bounds), Microsoft.Xna.Framework.Color.White, 0.0f, new Vector2((float)Game1.shadowTexture.Bounds.Center.X, (float)Game1.shadowTexture.Bounds.Center.Y), (float)(4.0 + (double)actor.yJumpOffset / 40.0) * (float)(NetFieldBase <float, NetFloat>)actor.scale, SpriteEffects.None, Math.Max(0.0f, (float)actor.getStandingY() / 10000f) - 1E-06f);
                                        }
                                    }
                                }
                            }
                            xTile.Layers.Layer layer1 = Game1.currentLocation.Map.GetLayer("Buildings");
                            layer1.Draw(Game1.mapDisplayDevice, Game1.viewport, xTile.Dimensions.Location.Origin, false, 4);
                            Game1.mapDisplayDevice.EndScene();
                            Game1.spriteBatch.End();
                            Game1.spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend, SamplerState.PointClamp, (DepthStencilState)null, (RasterizerState)null);
                            if (!Game1.currentLocation.shouldHideCharacters())
                            {
                                if (Game1.CurrentEvent == null)
                                {
                                    foreach (NPC character in Game1.currentLocation.characters)
                                    {
                                        if (!(bool)(NetFieldBase <bool, NetBool>)character.swimming && !character.HideShadow && (!(bool)(NetFieldBase <bool, NetBool>)character.isInvisible && Game1.currentLocation.shouldShadowBeDrawnAboveBuildingsLayer(character.getTileLocation())))
                                        {
                                            Game1.spriteBatch.Draw(Game1.shadowTexture, Game1.GlobalToLocal(Game1.viewport, character.Position + new Vector2((float)(character.Sprite.SpriteWidth * 4) / 2f, (float)(character.GetBoundingBox().Height + (character.IsMonster ? 0 : 12)))), new Microsoft.Xna.Framework.Rectangle?(Game1.shadowTexture.Bounds), Microsoft.Xna.Framework.Color.White, 0.0f, new Vector2((float)Game1.shadowTexture.Bounds.Center.X, (float)Game1.shadowTexture.Bounds.Center.Y), (float)(4.0 + (double)character.yJumpOffset / 40.0) * (float)(NetFieldBase <float, NetFloat>)character.scale, SpriteEffects.None, Math.Max(0.0f, (float)character.getStandingY() / 10000f) - 1E-06f);
                                        }
                                    }
                                }
                                else
                                {
                                    foreach (NPC actor in Game1.CurrentEvent.actors)
                                    {
                                        if (!(bool)(NetFieldBase <bool, NetBool>)actor.swimming && !actor.HideShadow && Game1.currentLocation.shouldShadowBeDrawnAboveBuildingsLayer(actor.getTileLocation()))
                                        {
                                            Game1.spriteBatch.Draw(Game1.shadowTexture, Game1.GlobalToLocal(Game1.viewport, actor.Position + new Vector2((float)(actor.Sprite.SpriteWidth * 4) / 2f, (float)(actor.GetBoundingBox().Height + (actor.IsMonster ? 0 : 12)))), new Microsoft.Xna.Framework.Rectangle?(Game1.shadowTexture.Bounds), Microsoft.Xna.Framework.Color.White, 0.0f, new Vector2((float)Game1.shadowTexture.Bounds.Center.X, (float)Game1.shadowTexture.Bounds.Center.Y), (float)(4.0 + (double)actor.yJumpOffset / 40.0) * (float)(NetFieldBase <float, NetFloat>)actor.scale, SpriteEffects.None, Math.Max(0.0f, (float)actor.getStandingY() / 10000f) - 1E-06f);
                                        }
                                    }
                                }
                            }
                            if ((Game1.eventUp || Game1.killScreen) && (!Game1.killScreen && Game1.currentLocation.currentEvent != null))
                            {
                                Game1.currentLocation.currentEvent.draw(Game1.spriteBatch);
                            }
                            if (Game1.player.currentUpgrade != null && Game1.player.currentUpgrade.daysLeftTillUpgradeDone <= 3 && Game1.currentLocation.Name.Equals("Farm"))
                            {
                                Game1.spriteBatch.Draw(Game1.player.currentUpgrade.workerTexture, Game1.GlobalToLocal(Game1.viewport, Game1.player.currentUpgrade.positionOfCarpenter), new Microsoft.Xna.Framework.Rectangle?(Game1.player.currentUpgrade.getSourceRectangle()), Microsoft.Xna.Framework.Color.White, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, (float)(((double)Game1.player.currentUpgrade.positionOfCarpenter.Y + 48.0) / 10000.0));
                            }
                            Game1.currentLocation.draw(Game1.spriteBatch);
                            foreach (Vector2 key in Game1.crabPotOverlayTiles.Keys)
                            {
                                xTile.Tiles.Tile tile = layer1.Tiles[(int)key.X, (int)key.Y];
                                if (tile != null)
                                {
                                    Vector2 local = Game1.GlobalToLocal(Game1.viewport, key * 64f);
                                    xTile.Dimensions.Location location = new xTile.Dimensions.Location((int)local.X, (int)local.Y);
                                    Game1.mapDisplayDevice.DrawTile(tile, location, (float)(((double)key.Y * 64.0 - 1.0) / 10000.0));
                                }
                            }
                            if (Game1.eventUp && Game1.currentLocation.currentEvent != null)
                            {
                                string messageToScreen = Game1.currentLocation.currentEvent.messageToScreen;
                            }

                            if (Game1.currentLocation.Name.Equals("Farm"))
                            {
                                if (Game1.player.CoopUpgradeLevel > 0)
                                {
                                    Game1.spriteBatch.Draw(Game1.currentCoopTexture, Game1.GlobalToLocal(Game1.viewport, new Vector2(1280f, 320f)), new Microsoft.Xna.Framework.Rectangle?(Game1.currentCoopTexture.Bounds), Microsoft.Xna.Framework.Color.White, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, Math.Max(0.0f, 0.0576f));
                                }
                                switch (Game1.player.BarnUpgradeLevel)
                                {
                                case 1:
                                    Game1.spriteBatch.Draw(Game1.currentBarnTexture, Game1.GlobalToLocal(Game1.viewport, new Vector2(768f, 320f)), new Microsoft.Xna.Framework.Rectangle?(Game1.currentBarnTexture.Bounds), Microsoft.Xna.Framework.Color.White, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, Math.Max(0.0f, 0.0576f));
                                    break;

                                case 2:
                                    Game1.spriteBatch.Draw(Game1.currentBarnTexture, Game1.GlobalToLocal(Game1.viewport, new Vector2(640f, 256f)), new Microsoft.Xna.Framework.Rectangle?(Game1.currentBarnTexture.Bounds), Microsoft.Xna.Framework.Color.White, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, Math.Max(0.0f, 0.0576f));
                                    break;
                                }
                                if (Game1.player.hasGreenhouse)
                                {
                                    Game1.spriteBatch.Draw(Game1.greenhouseTexture, Game1.GlobalToLocal(Game1.viewport, new Vector2(64f, 320f)), new Microsoft.Xna.Framework.Rectangle?(Game1.greenhouseTexture.Bounds), Microsoft.Xna.Framework.Color.White, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, Math.Max(0.0f, 0.0576f));
                                }
                            }

                            Game1.mapDisplayDevice.BeginScene(Game1.spriteBatch);
                            Game1.currentLocation.Map.GetLayer("Front").Draw(Game1.mapDisplayDevice, Game1.viewport, xTile.Dimensions.Location.Origin, false, 4);
                            Game1.mapDisplayDevice.EndScene();
                            Game1.currentLocation.drawAboveFrontLayer(Game1.spriteBatch);
                            Game1.spriteBatch.End();
                            Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, (DepthStencilState)null, (RasterizerState)null);
                            if (Game1.displayFarmer && Game1.player.ActiveObject != null && ((bool)(NetFieldBase <bool, NetBool>)Game1.player.ActiveObject.bigCraftable && tthis.checkBigCraftableBoundariesForFrontLayer()) && Game1.currentLocation.Map.GetLayer("Front").PickTile(new xTile.Dimensions.Location(Game1.player.getStandingX(), Game1.player.getStandingY()), Game1.viewport.Size) == null)
                            {
                                Game1.drawPlayerHeldObject(Game1.player);
                            }
                            else if (Game1.displayFarmer && Game1.player.ActiveObject != null)
                            {
                                if (Game1.currentLocation.Map.GetLayer("Front").PickTile(new xTile.Dimensions.Location((int)Game1.player.Position.X, (int)Game1.player.Position.Y - 38), Game1.viewport.Size) == null || Game1.currentLocation.Map.GetLayer("Front").PickTile(new xTile.Dimensions.Location((int)Game1.player.Position.X, (int)Game1.player.Position.Y - 38), Game1.viewport.Size).TileIndexProperties.ContainsKey("FrontAlways"))
                                {
                                    xTile.Layers.Layer layer2 = Game1.currentLocation.Map.GetLayer("Front");
                                    rectangle = Game1.player.GetBoundingBox();
                                    xTile.Dimensions.Location mapDisplayLocation1 = new xTile.Dimensions.Location(rectangle.Right, (int)Game1.player.Position.Y - 38);
                                    xTile.Dimensions.Size     size1 = Game1.viewport.Size;
                                    if (layer2.PickTile(mapDisplayLocation1, size1) != null)
                                    {
                                        xTile.Layers.Layer layer3 = Game1.currentLocation.Map.GetLayer("Front");
                                        rectangle = Game1.player.GetBoundingBox();
                                        xTile.Dimensions.Location mapDisplayLocation2 = new xTile.Dimensions.Location(rectangle.Right, (int)Game1.player.Position.Y - 38);
                                        xTile.Dimensions.Size     size2 = Game1.viewport.Size;
                                        if (layer3.PickTile(mapDisplayLocation2, size2).TileIndexProperties.ContainsKey("FrontAlways"))
                                        {
                                            goto label_139;
                                        }
                                    }
                                    else
                                    {
                                        goto label_139;
                                    }
                                }
                                Game1.drawPlayerHeldObject(Game1.player);
                            }
label_139:
                            if ((Game1.player.UsingTool || Game1.pickingTool) && Game1.player.CurrentTool != null && ((!Game1.player.CurrentTool.Name.Equals("Seeds") || Game1.pickingTool) && (Game1.currentLocation.Map.GetLayer("Front").PickTile(new xTile.Dimensions.Location(Game1.player.getStandingX(), (int)Game1.player.Position.Y - 38), Game1.viewport.Size) != null && Game1.currentLocation.Map.GetLayer("Front").PickTile(new xTile.Dimensions.Location(Game1.player.getStandingX(), Game1.player.getStandingY()), Game1.viewport.Size) == null)))
                            {
                                Game1.drawTool(Game1.player);
                            }
                            if (Game1.currentLocation.Map.GetLayer("AlwaysFront") != null)
                            {
                                Game1.mapDisplayDevice.BeginScene(Game1.spriteBatch);
                                Game1.currentLocation.Map.GetLayer("AlwaysFront").Draw(Game1.mapDisplayDevice, Game1.viewport, xTile.Dimensions.Location.Origin, false, 4);
                                Game1.mapDisplayDevice.EndScene();
                            }
                            if ((double)Game1.toolHold > 400.0 && Game1.player.CurrentTool.UpgradeLevel >= 1 && Game1.player.canReleaseTool)
                            {
                                Microsoft.Xna.Framework.Color color = Microsoft.Xna.Framework.Color.White;
                                switch ((int)((double)Game1.toolHold / 600.0) + 2)
                                {
                                case 1:
                                    color = Tool.copperColor;
                                    break;

                                case 2:
                                    color = Tool.steelColor;
                                    break;

                                case 3:
                                    color = Tool.goldColor;
                                    break;

                                case 4:
                                    color = Tool.iridiumColor;
                                    break;
                                }
                                Game1.spriteBatch.Draw(Game1.littleEffect, new Microsoft.Xna.Framework.Rectangle((int)Game1.player.getLocalPosition(Game1.viewport).X - 2, (int)Game1.player.getLocalPosition(Game1.viewport).Y - (Game1.player.CurrentTool.Name.Equals("Watering Can") ? 0 : 64) - 2, (int)((double)Game1.toolHold % 600.0 * 0.0799999982118607) + 4, 12), Microsoft.Xna.Framework.Color.Black);
                                Game1.spriteBatch.Draw(Game1.littleEffect, new Microsoft.Xna.Framework.Rectangle((int)Game1.player.getLocalPosition(Game1.viewport).X, (int)Game1.player.getLocalPosition(Game1.viewport).Y - (Game1.player.CurrentTool.Name.Equals("Watering Can") ? 0 : 64), (int)((double)Game1.toolHold % 600.0 * 0.0799999982118607), 8), color);
                            }

                            if ((double)Game1.currentLocation.LightLevel > 0.0 && Game1.timeOfDay < 2000)
                            {
                                Game1.spriteBatch.Draw(Game1.fadeToBlackRect, Game1.graphics.GraphicsDevice.Viewport.Bounds, Microsoft.Xna.Framework.Color.Black * Game1.currentLocation.LightLevel);
                            }
                            if (Game1.screenGlow)
                            {
                                Game1.spriteBatch.Draw(Game1.fadeToBlackRect, Game1.graphics.GraphicsDevice.Viewport.Bounds, Game1.screenGlowColor * Game1.screenGlowAlpha);
                            }
                            Game1.currentLocation.drawAboveAlwaysFrontLayer(Game1.spriteBatch);

                            Game1.spriteBatch.End();
                            Game1.spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend, SamplerState.PointClamp, (DepthStencilState)null, (RasterizerState)null);
                            if (Game1.eventUp && Game1.currentLocation.currentEvent != null)
                            {
                                foreach (NPC actor in Game1.currentLocation.currentEvent.actors)
                                {
                                    if (actor.isEmoting)
                                    {
                                        Vector2 localPosition = actor.getLocalPosition(Game1.viewport);
                                        localPosition.Y -= 140f;
                                        if (actor.Age == 2)
                                        {
                                            localPosition.Y += 32f;
                                        }
                                        else if (actor.Gender == 1)
                                        {
                                            localPosition.Y += 10f;
                                        }
                                        Game1.spriteBatch.Draw(Game1.emoteSpriteSheet, localPosition, new Microsoft.Xna.Framework.Rectangle?(new Microsoft.Xna.Framework.Rectangle(actor.CurrentEmoteIndex * 16 % Game1.emoteSpriteSheet.Width, actor.CurrentEmoteIndex * 16 / Game1.emoteSpriteSheet.Width * 16, 16, 16)), Microsoft.Xna.Framework.Color.White, 0.0f, Vector2.Zero, 4f, SpriteEffects.None, (float)actor.getStandingY() / 10000f);
                                    }
                                }
                            }
                            Game1.spriteBatch.End();

                            Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, (DepthStencilState)null, (RasterizerState)null);
                            if (Game1.drawGrid)
                            {
                                int   num1 = -Game1.viewport.X % 64;
                                float num2 = (float)(-Game1.viewport.Y % 64);
                                int   num3 = num1;
                                while (true)
                                {
                                    int num4 = num3;
                                    viewport = Game1.graphics.GraphicsDevice.Viewport;
                                    int width = viewport.Width;
                                    if (num4 < width)
                                    {
                                        SpriteBatch spriteBatch = Game1.spriteBatch;
                                        Texture2D   staminaRect = Game1.staminaRect;
                                        int         x           = num3;
                                        int         y           = (int)num2;
                                        viewport = Game1.graphics.GraphicsDevice.Viewport;
                                        int height = viewport.Height;
                                        Microsoft.Xna.Framework.Rectangle destinationRectangle = new Microsoft.Xna.Framework.Rectangle(x, y, 1, height);
                                        Microsoft.Xna.Framework.Color     color = Microsoft.Xna.Framework.Color.Red * 0.5f;
                                        spriteBatch.Draw(staminaRect, destinationRectangle, color);
                                        num3 += 64;
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
                                float num5 = num2;
                                while (true)
                                {
                                    double num4 = (double)num5;
                                    viewport = Game1.graphics.GraphicsDevice.Viewport;
                                    double height = (double)viewport.Height;
                                    if (num4 < height)
                                    {
                                        SpriteBatch spriteBatch = Game1.spriteBatch;
                                        Texture2D   staminaRect = Game1.staminaRect;
                                        int         x           = num1;
                                        int         y           = (int)num5;
                                        viewport = Game1.graphics.GraphicsDevice.Viewport;
                                        int width = viewport.Width;
                                        Microsoft.Xna.Framework.Rectangle destinationRectangle = new Microsoft.Xna.Framework.Rectangle(x, y, width, 1);
                                        Microsoft.Xna.Framework.Color     color = Microsoft.Xna.Framework.Color.Red * 0.5f;
                                        spriteBatch.Draw(staminaRect, destinationRectangle, color);
                                        num5 += 64f;
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
                            }
                        }
                        Game1.spriteBatch.End();
                        tthis.CallAction("renderScreenBuffer", target_screen);
                    }
                }
            }
        }
Exemple #54
0
 public Rectangle(Microsoft.Xna.Framework.Rectangle area)
 {
     this._area = area;
 }
Exemple #55
0
        public void LoadDataFromXMLDocument(string filename)
        {
            Font font;

            Microsoft.Xna.Framework.Color color;
            XmlDocument document    = new XmlDocument();
            string      xml         = Platform.Current.LoadText(filename); document.LoadXml(xml);
            XmlNode     nextSibling = document.FirstChild.NextSibling;
            XmlNode     node        = nextSibling.ChildNodes.Item(0);

            this.troopTitle.BackgroundTexture = CacheManager.GetTempTexture(@"Content\Textures\GameComponents\TroopTitle\Data\" + node.Attributes.GetNamedItem("FileName").Value);
            this.troopTitle.PictureNull       = CacheManager.GetTempTexture(@"Content\Textures\GameComponents\TroopTitle\Data\" + node.Attributes.GetNamedItem("PictureNull").Value);
            this.troopTitle.BackgroundSize    = new  Microsoft.Xna.Framework.Point(int.Parse(node.Attributes.GetNamedItem("Width").Value), int.Parse(node.Attributes.GetNamedItem("Height").Value));
            node = nextSibling.ChildNodes.Item(1);
            this.troopTitle.PortraitPosition = StaticMethods.LoadRectangleFromXMLNode(node);
            node = nextSibling.ChildNodes.Item(2);
            this.troopTitle.FactionTexture  = CacheManager.GetTempTexture(@"Content\Textures\GameComponents\TroopTitle\Data\" + node.Attributes.GetNamedItem("FileName").Value);
            this.troopTitle.FactionPosition = StaticMethods.LoadRectangleFromXMLNode(node);
            node = nextSibling.ChildNodes.Item(3);
            Microsoft.Xna.Framework.Rectangle rectangle = StaticMethods.LoadRectangleFromXMLNode(node);
            StaticMethods.LoadFontAndColorFromXMLNode(node, out font, out color);
            this.troopTitle.NameText          = new FreeText(font, color);
            this.troopTitle.NameText.Position = rectangle;
            this.troopTitle.NameText.Align    = (TextAlign)Enum.Parse(typeof(TextAlign), node.Attributes.GetNamedItem("Align").Value);
            node = nextSibling.ChildNodes.Item(4);
            this.troopTitle.ActionDoneTexture     = CacheManager.GetTempTexture(@"Content\Textures\GameComponents\TroopTitle\Data\" + node.Attributes.GetNamedItem("Done").Value);
            this.troopTitle.ActionUndoneTexture   = CacheManager.GetTempTexture(@"Content\Textures\GameComponents\TroopTitle\Data\" + node.Attributes.GetNamedItem("Undone").Value);
            this.troopTitle.ActionAutoTexture     = CacheManager.GetTempTexture(@"Content\Textures\GameComponents\TroopTitle\Data\" + node.Attributes.GetNamedItem("Auto").Value);
            this.troopTitle.ActionAutoDoneTexture = CacheManager.GetTempTexture(@"Content\Textures\GameComponents\TroopTitle\Data\" + node.Attributes.GetNamedItem("AutoDone").Value);
            this.troopTitle.ActionIconPosition    = StaticMethods.LoadRectangleFromXMLNode(node);
            node = nextSibling.ChildNodes.Item(5);
            this.troopTitle.FoodNormalTexture   = CacheManager.GetTempTexture(@"Content\Textures\GameComponents\TroopTitle\Data\" + node.Attributes.GetNamedItem("Normal").Value);
            this.troopTitle.FoodShortageTexture = CacheManager.GetTempTexture(@"Content\Textures\GameComponents\TroopTitle\Data\" + node.Attributes.GetNamedItem("Shortage").Value);
            this.troopTitle.FoodIconPosition    = StaticMethods.LoadRectangleFromXMLNode(node);
            node = nextSibling.ChildNodes.Item(6);
            this.troopTitle.NoControlTexture      = CacheManager.GetTempTexture(@"Content\Textures\GameComponents\TroopTitle\Data\" + node.Attributes.GetNamedItem("NoControl").Value);
            this.troopTitle.NoControlIconPosition = StaticMethods.LoadRectangleFromXMLNode(node);
            node = nextSibling.ChildNodes.Item(7);
            this.troopTitle.StuntTexture      = CacheManager.GetTempTexture(@"Content\Textures\GameComponents\TroopTitle\Data\" + node.Attributes.GetNamedItem("Stunt").Value);
            this.troopTitle.StuntIconPosition = StaticMethods.LoadRectangleFromXMLNode(node);

            node = nextSibling.ChildNodes.Item(8);
            Microsoft.Xna.Framework.Rectangle rectangle1 = StaticMethods.LoadRectangleFromXMLNode(node);
            StaticMethods.LoadFontAndColorFromXMLNode(node, out font, out color);
            this.troopTitle.binglitext          = new FreeText(font, color);
            this.troopTitle.binglitext.Position = rectangle1;
            this.troopTitle.binglitext.Align    = (TextAlign)Enum.Parse(typeof(TextAlign), node.Attributes.GetNamedItem("Align").Value);

            node = nextSibling.ChildNodes.Item(9);
            this.troopTitle.shiqicaotupian = CacheManager.GetTempTexture(@"Content\Textures\GameComponents\TroopTitle\Data\" + node.Attributes.GetNamedItem("FileName").Value);
            this.troopTitle.shiqicaoweizhi = StaticMethods.LoadRectangleFromXMLNode(node);

            node = nextSibling.ChildNodes.Item(10);
            this.troopTitle.shiqitiaotupian = CacheManager.GetTempTexture(@"Content\Textures\GameComponents\TroopTitle\Data\" + node.Attributes.GetNamedItem("FileName").Value);
            this.troopTitle.shiqitiaoweizhi = StaticMethods.LoadRectangleFromXMLNode(node);

            node = nextSibling.ChildNodes.Item(15);
            this.troopTitle.Switch1 = node.Attributes.GetNamedItem("UIKind").Value;

            /*
             * this.troopTitle.Switch11 = node.Attributes.GetNamedItem("PersonPicture").Value;
             * this.troopTitle.Switch11 = node.Attributes.GetNamedItem("PersonPortrait").Value;
             * this.troopTitle.Switch21 = node.Attributes.GetNamedItem("FactionPicture").Value;
             * this.troopTitle.Switch22 = node.Attributes.GetNamedItem("FactionName").Value;
             * this.troopTitle.Switch23 = node.Attributes.GetNamedItem("FactionColour").Value;
             * this.troopTitle.Switch31 = node.Attributes.GetNamedItem("TroopKind").Value;
             * this.troopTitle.Switch36 = node.Attributes.GetNamedItem("Food").Value;
             * this.troopTitle.Switch37 = node.Attributes.GetNamedItem("Stunt").Value;
             * this.troopTitle.Switch38 = node.Attributes.GetNamedItem("Action").Value;
             * this.troopTitle.Switch41 = node.Attributes.GetNamedItem("shiqi").Value;
             * this.troopTitle.Switch42 = node.Attributes.GetNamedItem("zhanyi").Value;
             */
            node = nextSibling.ChildNodes.Item(21);
            this.troopTitle.TheBackground1Position = StaticMethods.LoadRectangleFromXMLNode(node);
            this.troopTitle.TheBackground1         = CacheManager.GetTempTexture(@"Content\Textures\GameComponents\TroopTitle\Data\" + node.Attributes.GetNamedItem("Background").Value);
            this.troopTitle.TheMask11 = CacheManager.GetTempTexture(@"Content\Textures\GameComponents\TroopTitle\Data\" + node.Attributes.GetNamedItem("Mask1").Value);
            this.troopTitle.TheMask12 = CacheManager.GetTempTexture(@"Content\Textures\GameComponents\TroopTitle\Data\" + node.Attributes.GetNamedItem("Mask2").Value);
            this.troopTitle.TheMask13 = CacheManager.GetTempTexture(@"Content\Textures\GameComponents\TroopTitle\Data\" + node.Attributes.GetNamedItem("Mask3").Value);
            this.troopTitle.TheMask14 = CacheManager.GetTempTexture(@"Content\Textures\GameComponents\TroopTitle\Data\" + node.Attributes.GetNamedItem("Mask4").Value);
            node = nextSibling.ChildNodes.Item(22);
            this.troopTitle.ThePortrait1Position = StaticMethods.LoadRectangleFromXMLNode(node);
            node      = nextSibling.ChildNodes.Item(26);
            rectangle = StaticMethods.LoadRectangleFromXMLNode(node);
            StaticMethods.LoadFontAndColorFromXMLNode(node, out font, out color);
            this.troopTitle.FactionName1Text            = new FreeText(font, color);
            this.troopTitle.FactionName1Text.Position   = rectangle;
            this.troopTitle.FactionName1Text.Align      = (TextAlign)Enum.Parse(typeof(TextAlign), node.Attributes.GetNamedItem("Align").Value);
            this.troopTitle.FactionName1Position.X      = int.Parse(node.Attributes.GetNamedItem("X").Value);
            this.troopTitle.FactionName1Position.Y      = int.Parse(node.Attributes.GetNamedItem("Y").Value);
            this.troopTitle.FactionName1Position.Width  = int.Parse(node.Attributes.GetNamedItem("Width").Value);
            this.troopTitle.FactionName1Position.Height = int.Parse(node.Attributes.GetNamedItem("Height").Value);
            this.troopTitle.FactionName1Kind            = node.Attributes.GetNamedItem("FactionNameKind").Value;
            this.troopTitle.ShowFactionName1Background  = node.Attributes.GetNamedItem("ShowFactionNameBackground").Value;
            this.troopTitle.FactionName1Background      = CacheManager.GetTempTexture(@"Content\Textures\GameComponents\TroopTitle\Data\FactionPicture\" + node.Attributes.GetNamedItem("Background").Value);
            node = nextSibling.ChildNodes.Item(27);
            this.troopTitle.FactionColor1Position   = StaticMethods.LoadRectangleFromXMLNode(node);
            this.troopTitle.FactionColor1Picture    = CacheManager.GetTempTexture(@"Content\Textures\GameComponents\TroopTitle\Data\FactionPicture\" + node.Attributes.GetNamedItem("ColorPicture").Value);
            this.troopTitle.FactionColor1Background = CacheManager.GetTempTexture(@"Content\Textures\GameComponents\TroopTitle\Data\FactionPicture\" + node.Attributes.GetNamedItem("ColorBackground").Value);
            node      = nextSibling.ChildNodes.Item(31);
            rectangle = StaticMethods.LoadRectangleFromXMLNode(node);
            StaticMethods.LoadFontAndColorFromXMLNode(node, out font, out color);
            this.troopTitle.TroopName1Text          = new FreeText(font, color);
            this.troopTitle.TroopName1Text.Position = rectangle;
            this.troopTitle.TroopName1Text.Align    = (TextAlign)Enum.Parse(typeof(TextAlign), node.Attributes.GetNamedItem("Align").Value);

            node = nextSibling.ChildNodes.Item(36);
            this.troopTitle.TheTroopKind1Position = StaticMethods.LoadRectangleFromXMLNode(node);
            this.troopTitle.TheTroopKind11Picture = CacheManager.GetTempTexture(@"Content\Textures\GameComponents\TroopTitle\Data\TroopKind\" + node.Attributes.GetNamedItem("TroopKind1").Value);
            this.troopTitle.TheTroopKind12Picture = CacheManager.GetTempTexture(@"Content\Textures\GameComponents\TroopTitle\Data\TroopKind\" + node.Attributes.GetNamedItem("TroopKind2").Value);
            this.troopTitle.TheTroopKind13Picture = CacheManager.GetTempTexture(@"Content\Textures\GameComponents\TroopTitle\Data\TroopKind\" + node.Attributes.GetNamedItem("TroopKind3").Value);
            this.troopTitle.TheTroopKind14Picture = CacheManager.GetTempTexture(@"Content\Textures\GameComponents\TroopTitle\Data\TroopKind\" + node.Attributes.GetNamedItem("TroopKind4").Value);
            this.troopTitle.TheTroopKind15Picture = CacheManager.GetTempTexture(@"Content\Textures\GameComponents\TroopTitle\Data\TroopKind\" + node.Attributes.GetNamedItem("TroopKind5").Value);

            node      = nextSibling.ChildNodes.Item(37);
            rectangle = StaticMethods.LoadRectangleFromXMLNode(node);
            StaticMethods.LoadFontAndColorFromXMLNode(node, out font, out color);
            this.troopTitle.Thebingli1Text          = new FreeText(font, color);
            this.troopTitle.Thebingli1Text.Position = rectangle;
            this.troopTitle.Thebingli1Text.Align    = (TextAlign)Enum.Parse(typeof(TextAlign), node.Attributes.GetNamedItem("Align").Value);

            node = nextSibling.ChildNodes.Item(41);
            this.troopTitle.TheActionIcon1Position    = StaticMethods.LoadRectangleFromXMLNode(node);
            this.troopTitle.TheActionDone1Texture     = CacheManager.GetTempTexture(@"Content\Textures\GameComponents\TroopTitle\Data\Icon\" + node.Attributes.GetNamedItem("Done").Value);
            this.troopTitle.TheActionUndone1Texture   = CacheManager.GetTempTexture(@"Content\Textures\GameComponents\TroopTitle\Data\Icon\" + node.Attributes.GetNamedItem("Undone").Value);
            this.troopTitle.TheActionAuto1Texture     = CacheManager.GetTempTexture(@"Content\Textures\GameComponents\TroopTitle\Data\Icon\" + node.Attributes.GetNamedItem("Auto").Value);
            this.troopTitle.TheActionAutoDone1Texture = CacheManager.GetTempTexture(@"Content\Textures\GameComponents\TroopTitle\Data\Icon\" + node.Attributes.GetNamedItem("AutoDone").Value);
            node = nextSibling.ChildNodes.Item(42);
            this.troopTitle.TheFoodIcon1Position    = StaticMethods.LoadRectangleFromXMLNode(node);
            this.troopTitle.TheFoodNormal1Texture   = CacheManager.GetTempTexture(@"Content\Textures\GameComponents\TroopTitle\Data\Icon\" + node.Attributes.GetNamedItem("Normal").Value);
            this.troopTitle.TheFoodShortage1Texture = CacheManager.GetTempTexture(@"Content\Textures\GameComponents\TroopTitle\Data\Icon\" + node.Attributes.GetNamedItem("Shortage").Value);
            node = nextSibling.ChildNodes.Item(43);
            this.troopTitle.TheNoControl1Texture      = CacheManager.GetTempTexture(@"Content\Textures\GameComponents\TroopTitle\Data\Icon\" + node.Attributes.GetNamedItem("NoControl").Value);
            this.troopTitle.TheNoControlIcon1Position = StaticMethods.LoadRectangleFromXMLNode(node);
            node = nextSibling.ChildNodes.Item(44);
            this.troopTitle.TheStunt1Texture      = CacheManager.GetTempTexture(@"Content\Textures\GameComponents\TroopTitle\Data\Icon\" + node.Attributes.GetNamedItem("Stunt").Value);
            this.troopTitle.TheStuntIcon1Position = StaticMethods.LoadRectangleFromXMLNode(node);

            node = nextSibling.ChildNodes.Item(46);
            this.troopTitle.Theshiqi1Texture  = CacheManager.GetTempTexture(@"Content\Textures\GameComponents\TroopTitle\Data\Icon\" + node.Attributes.GetNamedItem("FileName").Value);
            this.troopTitle.Theshiqi1Position = StaticMethods.LoadRectangleFromXMLNode(node);
            node = nextSibling.ChildNodes.Item(47);
            this.troopTitle.Thezhanyi1Texture  = CacheManager.GetTempTexture(@"Content\Textures\GameComponents\TroopTitle\Data\Icon\" + node.Attributes.GetNamedItem("FileName").Value);
            this.troopTitle.Thezhanyi1Position = StaticMethods.LoadRectangleFromXMLNode(node);

            node = nextSibling.ChildNodes.Item(51);
            this.troopTitle.TheBackground2Position = StaticMethods.LoadRectangleFromXMLNode(node);
            this.troopTitle.TheBackground2         = CacheManager.GetTempTexture(@"Content\Textures\GameComponents\TroopTitle\Data\" + node.Attributes.GetNamedItem("Background").Value);
            this.troopTitle.TheMask21 = CacheManager.GetTempTexture(@"Content\Textures\GameComponents\TroopTitle\Data\" + node.Attributes.GetNamedItem("Mask1").Value);
            this.troopTitle.TheMask22 = CacheManager.GetTempTexture(@"Content\Textures\GameComponents\TroopTitle\Data\" + node.Attributes.GetNamedItem("Mask2").Value);
            this.troopTitle.TheMask23 = CacheManager.GetTempTexture(@"Content\Textures\GameComponents\TroopTitle\Data\" + node.Attributes.GetNamedItem("Mask3").Value);
            this.troopTitle.TheMask24 = CacheManager.GetTempTexture(@"Content\Textures\GameComponents\TroopTitle\Data\" + node.Attributes.GetNamedItem("Mask4").Value);
            node = nextSibling.ChildNodes.Item(52);
            this.troopTitle.ThePortrait2Position = StaticMethods.LoadRectangleFromXMLNode(node);
            node      = nextSibling.ChildNodes.Item(56);
            rectangle = StaticMethods.LoadRectangleFromXMLNode(node);
            StaticMethods.LoadFontAndColorFromXMLNode(node, out font, out color);
            this.troopTitle.FactionName2Text            = new FreeText(font, color);
            this.troopTitle.FactionName2Text.Position   = rectangle;
            this.troopTitle.FactionName2Text.Align      = (TextAlign)Enum.Parse(typeof(TextAlign), node.Attributes.GetNamedItem("Align").Value);
            this.troopTitle.FactionName2Position.X      = int.Parse(node.Attributes.GetNamedItem("X").Value);
            this.troopTitle.FactionName2Position.Y      = int.Parse(node.Attributes.GetNamedItem("Y").Value);
            this.troopTitle.FactionName2Position.Width  = int.Parse(node.Attributes.GetNamedItem("Width").Value);
            this.troopTitle.FactionName2Position.Height = int.Parse(node.Attributes.GetNamedItem("Height").Value);
            this.troopTitle.FactionName2Kind            = node.Attributes.GetNamedItem("FactionNameKind").Value;
            this.troopTitle.ShowFactionName2Background  = node.Attributes.GetNamedItem("ShowFactionNameBackground").Value;
            this.troopTitle.FactionName2Background      = CacheManager.GetTempTexture(@"Content\Textures\GameComponents\TroopTitle\Data\FactionPicture\" + node.Attributes.GetNamedItem("Background").Value);
            node = nextSibling.ChildNodes.Item(57);
            this.troopTitle.FactionColor2Position   = StaticMethods.LoadRectangleFromXMLNode(node);
            this.troopTitle.FactionColor2Picture    = CacheManager.GetTempTexture(@"Content\Textures\GameComponents\TroopTitle\Data\FactionPicture\" + node.Attributes.GetNamedItem("ColorPicture").Value);
            this.troopTitle.FactionColor2Background = CacheManager.GetTempTexture(@"Content\Textures\GameComponents\TroopTitle\Data\FactionPicture\" + node.Attributes.GetNamedItem("ColorBackground").Value);
            node      = nextSibling.ChildNodes.Item(61);
            rectangle = StaticMethods.LoadRectangleFromXMLNode(node);
            StaticMethods.LoadFontAndColorFromXMLNode(node, out font, out color);
            this.troopTitle.TroopName2Text          = new FreeText(font, color);
            this.troopTitle.TroopName2Text.Position = rectangle;
            this.troopTitle.TroopName2Text.Align    = (TextAlign)Enum.Parse(typeof(TextAlign), node.Attributes.GetNamedItem("Align").Value);

            node = nextSibling.ChildNodes.Item(66);
            this.troopTitle.TheTroopKind2Position = StaticMethods.LoadRectangleFromXMLNode(node);
            this.troopTitle.TheTroopKind21Picture = CacheManager.GetTempTexture(@"Content\Textures\GameComponents\TroopTitle\Data\TroopKind\" + node.Attributes.GetNamedItem("TroopKind1").Value);
            this.troopTitle.TheTroopKind22Picture = CacheManager.GetTempTexture(@"Content\Textures\GameComponents\TroopTitle\Data\TroopKind\" + node.Attributes.GetNamedItem("TroopKind2").Value);
            this.troopTitle.TheTroopKind23Picture = CacheManager.GetTempTexture(@"Content\Textures\GameComponents\TroopTitle\Data\TroopKind\" + node.Attributes.GetNamedItem("TroopKind3").Value);
            this.troopTitle.TheTroopKind24Picture = CacheManager.GetTempTexture(@"Content\Textures\GameComponents\TroopTitle\Data\TroopKind\" + node.Attributes.GetNamedItem("TroopKind4").Value);
            this.troopTitle.TheTroopKind25Picture = CacheManager.GetTempTexture(@"Content\Textures\GameComponents\TroopTitle\Data\TroopKind\" + node.Attributes.GetNamedItem("TroopKind5").Value);

            node      = nextSibling.ChildNodes.Item(67);
            rectangle = StaticMethods.LoadRectangleFromXMLNode(node);
            StaticMethods.LoadFontAndColorFromXMLNode(node, out font, out color);
            this.troopTitle.Thebingli2Text          = new FreeText(font, color);
            this.troopTitle.Thebingli2Text.Position = rectangle;
            this.troopTitle.Thebingli2Text.Align    = (TextAlign)Enum.Parse(typeof(TextAlign), node.Attributes.GetNamedItem("Align").Value);

            node = nextSibling.ChildNodes.Item(71);
            this.troopTitle.TheActionIcon2Position    = StaticMethods.LoadRectangleFromXMLNode(node);
            this.troopTitle.TheActionDone2Texture     = CacheManager.GetTempTexture(@"Content\Textures\GameComponents\TroopTitle\Data\Icon\" + node.Attributes.GetNamedItem("Done").Value);
            this.troopTitle.TheActionUndone2Texture   = CacheManager.GetTempTexture(@"Content\Textures\GameComponents\TroopTitle\Data\Icon\" + node.Attributes.GetNamedItem("Undone").Value);
            this.troopTitle.TheActionAuto2Texture     = CacheManager.GetTempTexture(@"Content\Textures\GameComponents\TroopTitle\Data\Icon\" + node.Attributes.GetNamedItem("Auto").Value);
            this.troopTitle.TheActionAutoDone2Texture = CacheManager.GetTempTexture(@"Content\Textures\GameComponents\TroopTitle\Data\Icon\" + node.Attributes.GetNamedItem("AutoDone").Value);
            node = nextSibling.ChildNodes.Item(72);
            this.troopTitle.TheFoodIcon2Position    = StaticMethods.LoadRectangleFromXMLNode(node);
            this.troopTitle.TheFoodNormal2Texture   = CacheManager.GetTempTexture(@"Content\Textures\GameComponents\TroopTitle\Data\Icon\" + node.Attributes.GetNamedItem("Normal").Value);
            this.troopTitle.TheFoodShortage2Texture = CacheManager.GetTempTexture(@"Content\Textures\GameComponents\TroopTitle\Data\Icon\" + node.Attributes.GetNamedItem("Shortage").Value);
            node = nextSibling.ChildNodes.Item(73);
            this.troopTitle.TheNoControl2Texture      = CacheManager.GetTempTexture(@"Content\Textures\GameComponents\TroopTitle\Data\Icon\" + node.Attributes.GetNamedItem("NoControl").Value);
            this.troopTitle.TheNoControlIcon2Position = StaticMethods.LoadRectangleFromXMLNode(node);
            node = nextSibling.ChildNodes.Item(74);
            this.troopTitle.TheStunt2Texture      = CacheManager.GetTempTexture(@"Content\Textures\GameComponents\TroopTitle\Data\Icon\" + node.Attributes.GetNamedItem("Stunt").Value);
            this.troopTitle.TheStuntIcon2Position = StaticMethods.LoadRectangleFromXMLNode(node);

            node = nextSibling.ChildNodes.Item(76);
            this.troopTitle.Theshiqi2Texture  = CacheManager.GetTempTexture(@"Content\Textures\GameComponents\TroopTitle\Data\Icon\" + node.Attributes.GetNamedItem("FileName").Value);
            this.troopTitle.Theshiqi2Position = StaticMethods.LoadRectangleFromXMLNode(node);
            node = nextSibling.ChildNodes.Item(77);
            this.troopTitle.Thezhanyi2Texture  = CacheManager.GetTempTexture(@"Content\Textures\GameComponents\TroopTitle\Data\Icon\" + node.Attributes.GetNamedItem("FileName").Value);
            this.troopTitle.Thezhanyi2Position = StaticMethods.LoadRectangleFromXMLNode(node);
        }
        public static bool DamageMonsterByCompanion(
            this GameLocation location,
            Rectangle areaOfEffect,
            int minDamage,
            int maxDamage,
            float knockBackModifier,
            int addedPrecision,
            float critChance,
            float critMultiplier,
            bool triggerMonsterInvincibleTimer,
            Character who,
            Farmer leader)
        {
            if (Compat.IsModLoaded(ModUids.PACIFISTMOD_UID))
            {
                return(CuddleMonster(location, areaOfEffect, minDamage, maxDamage, false, knockBackModifier, addedPrecision, critChance, critMultiplier, triggerMonsterInvincibleTimer, who, leader));
            }

            bool flag1 = false;

            for (int j = location.characters.Count - 1; j >= 0; j--)
            {
                if (
                    j < location.characters.Count && location.characters[j].GetBoundingBox().Intersects(areaOfEffect) &&
                    location.characters[j].IsMonster &&
                    ((Monster)location.characters[j]).Health > 0 &&
                    !location.characters[j].IsInvisible &&
                    !(location.characters[j] as Monster).isInvincible())
                {
                    flag1 = true;
                    Microsoft.Xna.Framework.Rectangle boundingBox = location.characters[j].GetBoundingBox();
                    Vector2 trajectory = Helper.GetAwayFromCharacterTrajectory(boundingBox, who);
                    if (knockBackModifier > 0.0)
                    {
                        trajectory *= knockBackModifier;
                    }
                    else
                    {
                        trajectory = new Vector2(location.characters[j].xVelocity, location.characters[j].yVelocity);
                    }
                    if ((location.characters[j] as Monster).Slipperiness == -1)
                    {
                        trajectory = Vector2.Zero;
                    }
                    bool flag3 = false;
                    int  number;
                    if (maxDamage >= 0)
                    {
                        int num = Game1.random.Next(minDamage, maxDamage + 1);
                        if (who != null && Game1.random.NextDouble() < (double)critChance + (double)leader.LuckLevel * ((double)critChance / 40.0))
                        {
                            flag3 = true;
                            location.playSound("crit");
                        }
                        int damage = Math.Max(1, (flag3 ? (int)((double)num * (double)critMultiplier) : num) + (who != null ? leader.attack * 3 : 0));
                        number = ((Monster)location.characters[j]).takeDamage(damage, (int)trajectory.X, (int)trajectory.Y, false, (double)addedPrecision / 10.0, leader);

                        if (number == -1)
                        {
                            location.debris.Add(new Debris("Miss", 1, new Vector2(boundingBox.Center.X, (float)boundingBox.Center.Y), Color.LightGray, 1f, 0.0f));
                        }
                        else
                        {
                            location.debris.Filter(d =>
                            {
                                if (d.toHover != null && d.toHover.Equals((object)location.characters[j]) && !d.nonSpriteChunkColor.Equals(Color.Yellow))
                                {
                                    return((double)d.timeSinceDoneBouncing <= 900.0);
                                }
                                return(true);
                            });
                            location.debris.Add(new Debris(number, new Vector2((float)(boundingBox.Center.X + 16), (float)boundingBox.Center.Y), flag3 ? Color.Yellow : new Color((int)byte.MaxValue, 130, 0), flag3 ? (float)(1.0 + (double)number / 300.0) : 1f, location.characters[j]));
                        }
                        if (triggerMonsterInvincibleTimer)
                        {
                            (location.characters[j] as Monster).setInvincibleCountdown(450 / 2);
                        }
                    }
                    else
                    {
                        number = -2;
                        location.characters[j].setTrajectory(trajectory);
                        if (((Monster)location.characters[j]).Slipperiness > 10)
                        {
                            location.characters[j].xVelocity /= 2f;
                            location.characters[j].yVelocity /= 2f;
                        }
                    }
                    if (((Monster)location.characters[j]).Health <= 0)
                    {
                        if (!location.IsFarm)
                        {
                            leader.checkForQuestComplete((NPC)null, 1, 1, (Item)null, location.characters[j].Name, 4, -1);
                        }
                        Monster character = location.characters[j] as Monster;
                        location.monsterDrop(character, boundingBox.Center.X, boundingBox.Center.Y, leader);
                        location.characters.Remove(character);
                        ++Game1.stats.MonstersKilled;
                        Game1.stats.monsterKilled(character.Name);
                    }
                    else if (number > 0)
                    {
                        ((Monster)location.characters[j]).shedChunks(Game1.random.Next(1, 3));
                        if (flag3)
                        {
                            location.temporarySprites.Add(new TemporaryAnimatedSprite(362, (float)Game1.random.Next(15, 50), 6, 1, location.characters[j].getStandingPosition() - new Vector2(32f, 32f), false, Game1.random.NextDouble() < 0.5)
                            {
                                scale = 0.75f,
                                alpha = flag3 ? 0.75f : 0.5f
                            });
                            location.temporarySprites.Add(new TemporaryAnimatedSprite(362, (float)Game1.random.Next(15, 50), 6, 1, location.characters[j].getStandingPosition() - new Vector2((float)(32 + Game1.random.Next(-21, 21) + 32), (float)(32 + Game1.random.Next(-21, 21))), false, Game1.random.NextDouble() < 0.5)
                            {
                                scale = 0.5f,
                                delayBeforeAnimationStart = 50,
                                alpha = flag3 ? 0.75f : 0.5f
                            });
                            location.temporarySprites.Add(new TemporaryAnimatedSprite(362, (float)Game1.random.Next(15, 50), 6, 1, location.characters[j].getStandingPosition() - new Vector2((float)(32 + Game1.random.Next(-21, 21) - 32), (float)(32 + Game1.random.Next(-21, 21))), false, Game1.random.NextDouble() < 0.5)
                            {
                                scale = 0.5f,
                                delayBeforeAnimationStart = 100,
                                alpha = flag3 ? 0.75f : 0.5f
                            });
                            location.temporarySprites.Add(new TemporaryAnimatedSprite(362, (float)Game1.random.Next(15, 50), 6, 1, location.characters[j].getStandingPosition() - new Vector2((float)(32 + Game1.random.Next(-21, 21) + 32), (float)(32 + Game1.random.Next(-21, 21))), false, Game1.random.NextDouble() < 0.5)
                            {
                                scale = 0.5f,
                                delayBeforeAnimationStart = 150,
                                alpha = flag3 ? 0.75f : 0.5f
                            });
                            location.temporarySprites.Add(new TemporaryAnimatedSprite(362, (float)Game1.random.Next(15, 50), 6, 1, location.characters[j].getStandingPosition() - new Vector2((float)(32 + Game1.random.Next(-21, 21) - 32), (float)(32 + Game1.random.Next(-21, 21))), false, Game1.random.NextDouble() < 0.5)
                            {
                                scale = 0.5f,
                                delayBeforeAnimationStart = 200,
                                alpha = flag3 ? 0.75f : 0.5f
                            });
                        }
                    }
                }
            }

            return(flag1);
        }
Exemple #57
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Text"/> class. Locates this <see cref="Text"/> with the given values. Cuts this instance of <see cref="Text"/> off if it expands the boundaries of the given scissor rectangle.
        /// </summary>
        /// <param name="text">
        /// A <see cref="string"/> representing the <see cref="TextContent"/> to be drawn.
        /// </param>
        /// <param name="font">
        /// A <see cref="SpriteFont"/> indicating the font used to draw the <see cref="TextContent"/>.
        /// </param>
        /// <param name="color">
        /// A <see cref="Color"/> indicating the color in which the <see cref="TextContent"/> is drawn.
        /// </param>
        /// <param name="effects">
        /// A <see cref="SpriteEffects"/> indicating the effects used by the <see cref="TextContent"/>.
        /// </param>
        /// <param name="position">
        /// A <see cref="Vector2"/> indicating the position of this <see cref="Text"/>.
        /// </param>
        /// <param name="scale">
        /// A <see cref="float"/> indicating a multiplier for the drawing scale of the <see cref="TextContent"/>.
        /// </param>
        /// <param name="rotation">
        /// A <see cref="float"/> indicating the angles to this <see cref="Text"/> about its angle.
        /// </param>
        /// <param name="origin">
        /// A <see cref="Vector2"/> indicating the origin of this <see cref="Text"/>.
        /// </param>
        /// <param name="scissorRectangle">
        /// An instance of <see cref="Microsoft.Xna.Framework.Rectangle"/> indicating the boundaries where this instance of <see cref="Text"/> should be drawn.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="color"/> and/or <see cref="font"/> are NULL.
        /// </exception>
        public Text(string text, SpriteFont font, Color color, SpriteEffects effects, Vector2 position, float scale, float rotation, Vector2 origin, Microsoft.Xna.Framework.Rectangle scissorRectangle)
        {
            if (color == null)
            {
                throw new ArgumentNullException("color");
            }

            if (font == null)
            {
                throw new ArgumentNullException("font");
            }

            this.TextContent = text;
            this.font        = font;
            this.Color       = color;
            this.effects     = effects;
            Size measuredText = font.MeasureStringSize(this.TextContent);

            this.bounds          = new Microsoft.Xna.Framework.Rectangle((int)position.X, (int)position.Y, (int)(measuredText.Width * scale), (int)(measuredText.Height * scale));
            this.textScale       = scale;
            this.rotation        = rotation;
            this.origin          = origin;
            this.rasterizerState = new RasterizerState()
            {
                ScissorTestEnable = true
            };
            this.scissorRectangle = scissorRectangle;
            ////measuredText = new Vector2(measuredText.X * scale, measuredText.Y * scale);
            ////this.Position = new Microsoft.Xna.Framework.Rectangle((int)position.X, (int)position.Y, (int)measuredText.X, (int)measuredText.Y);
        }
        public void LoadDataFromXMLDocument(string filename)
        {
            Font font;

            Microsoft.Xna.Framework.Graphics.Color color;
            XmlDocument document = new XmlDocument();

            document.Load(filename);
            XmlNode nextSibling = document.FirstChild.NextSibling;
            XmlNode node        = nextSibling.ChildNodes.Item(0);

            this.createTroop.BackgroundSize.X  = int.Parse(node.Attributes.GetNamedItem("Width").Value);
            this.createTroop.BackgroundSize.Y  = int.Parse(node.Attributes.GetNamedItem("Height").Value);
            this.createTroop.BackgroundTexture = Texture2D.FromFile(this.graphicsDevice, @"GameComponents\CreateTroop\Data\" + node.Attributes.GetNamedItem("FileName").Value);
            node = nextSibling.ChildNodes.Item(1);
            Microsoft.Xna.Framework.Rectangle rectangle = StaticMethods.LoadRectangleFromXMLNode(node);
            StaticMethods.LoadFontAndColorFromXMLNode(node, out font, out color);
            this.createTroop.TroopNameText          = new FreeText(this.graphicsDevice, font, color);
            this.createTroop.TroopNameText.Position = rectangle;
            this.createTroop.TroopNameText.Align    = (TextAlign)Enum.Parse(typeof(TextAlign), node.Attributes.GetNamedItem("Align").Value);
            node = nextSibling.ChildNodes.Item(2);
            this.createTroop.PortraitClient = StaticMethods.LoadRectangleFromXMLNode(node);
            node = nextSibling.ChildNodes.Item(3);
            for (int i = 0; i < node.ChildNodes.Count; i += 2)
            {
                LabelText item  = new LabelText();
                XmlNode   node3 = node.ChildNodes.Item(i);
                rectangle = StaticMethods.LoadRectangleFromXMLNode(node3);
                StaticMethods.LoadFontAndColorFromXMLNode(node3, out font, out color);
                item.Label          = new FreeText(this.graphicsDevice, font, color);
                item.Label.Position = rectangle;
                item.Label.Align    = (TextAlign)Enum.Parse(typeof(TextAlign), node3.Attributes.GetNamedItem("Align").Value);
                item.Label.Text     = node3.Attributes.GetNamedItem("Label").Value;
                node3     = node.ChildNodes.Item(i + 1);
                rectangle = StaticMethods.LoadRectangleFromXMLNode(node3);
                StaticMethods.LoadFontAndColorFromXMLNode(node3, out font, out color);
                item.Text          = new FreeText(this.graphicsDevice, font, color);
                item.Text.Position = rectangle;
                item.Text.Align    = (TextAlign)Enum.Parse(typeof(TextAlign), node3.Attributes.GetNamedItem("Align").Value);
                item.PropertyName  = node3.Attributes.GetNamedItem("PropertyName").Value;
                this.createTroop.LabelTexts.Add(item);
            }
            node = nextSibling.ChildNodes.Item(4);
            this.createTroop.OtherPersonClient            = StaticMethods.LoadRectangleFromXMLNode(node);
            this.createTroop.OtherPersonText.ClientWidth  = this.createTroop.OtherPersonClient.Width;
            this.createTroop.OtherPersonText.ClientHeight = this.createTroop.OtherPersonClient.Height;
            this.createTroop.OtherPersonText.RowMargin    = int.Parse(node.Attributes.GetNamedItem("RowMargin").Value);
            StaticMethods.LoadFontAndColorFromXMLNode(node, out font, out color);
            this.createTroop.OtherPersonText.Builder.SetFreeTextBuilder(this.graphicsDevice, font);
            this.createTroop.OtherPersonText.DefaultColor = color;
            node = nextSibling.ChildNodes.Item(5);
            this.createTroop.CombatMethodClient            = StaticMethods.LoadRectangleFromXMLNode(node);
            this.createTroop.CombatMethodText.ClientWidth  = this.createTroop.CombatMethodClient.Width;
            this.createTroop.CombatMethodText.ClientHeight = this.createTroop.CombatMethodClient.Height;
            this.createTroop.CombatMethodText.RowMargin    = int.Parse(node.Attributes.GetNamedItem("RowMargin").Value);
            StaticMethods.LoadFontAndColorFromXMLNode(node, out font, out color);
            this.createTroop.CombatMethodText.Builder.SetFreeTextBuilder(this.graphicsDevice, font);
            this.createTroop.CombatMethodText.DefaultColor = color;
            node = nextSibling.ChildNodes.Item(6);
            this.createTroop.StuntClient            = StaticMethods.LoadRectangleFromXMLNode(node);
            this.createTroop.StuntText.ClientWidth  = this.createTroop.StuntClient.Width;
            this.createTroop.StuntText.ClientHeight = this.createTroop.StuntClient.Height;
            this.createTroop.StuntText.RowMargin    = int.Parse(node.Attributes.GetNamedItem("RowMargin").Value);
            StaticMethods.LoadFontAndColorFromXMLNode(node, out font, out color);
            this.createTroop.StuntText.Builder.SetFreeTextBuilder(this.graphicsDevice, font);
            this.createTroop.StuntText.DefaultColor = color;
            node = nextSibling.ChildNodes.Item(7);
            this.createTroop.InfluenceClient            = StaticMethods.LoadRectangleFromXMLNode(node);
            this.createTroop.InfluenceText.ClientWidth  = this.createTroop.InfluenceClient.Width;
            this.createTroop.InfluenceText.ClientHeight = this.createTroop.InfluenceClient.Height;
            this.createTroop.InfluenceText.RowMargin    = int.Parse(node.Attributes.GetNamedItem("RowMargin").Value);
            StaticMethods.LoadFontAndColorFromXMLNode(node, out font, out color);
            this.createTroop.InfluenceText.Builder.SetFreeTextBuilder(this.graphicsDevice, font);
            this.createTroop.InfluenceText.DefaultColor = color;
            node = nextSibling.ChildNodes.Item(8);
            this.createTroop.MilitaryButtonTexture         = Texture2D.FromFile(this.graphicsDevice, @"GameComponents\CreateTroop\Data\" + node.Attributes.GetNamedItem("FileName").Value);
            this.createTroop.MilitaryButtonSelectedTexture = Texture2D.FromFile(this.graphicsDevice, @"GameComponents\CreateTroop\Data\" + node.Attributes.GetNamedItem("Selected").Value);
            this.createTroop.MilitaryButtonDisabledTexture = Texture2D.FromFile(this.graphicsDevice, @"GameComponents\CreateTroop\Data\" + node.Attributes.GetNamedItem("Disabled").Value);
            this.createTroop.MilitaryButtonPosition        = StaticMethods.LoadRectangleFromXMLNode(node);
            this.createTroop.MilitaryButtonDisplayTexture  = this.createTroop.MilitaryButtonTexture;
            node = nextSibling.ChildNodes.Item(9);
            this.createTroop.PersonButtonTexture         = Texture2D.FromFile(this.graphicsDevice, @"GameComponents\CreateTroop\Data\" + node.Attributes.GetNamedItem("FileName").Value);
            this.createTroop.PersonButtonSelectedTexture = Texture2D.FromFile(this.graphicsDevice, @"GameComponents\CreateTroop\Data\" + node.Attributes.GetNamedItem("Selected").Value);
            this.createTroop.PersonButtonDisabledTexture = Texture2D.FromFile(this.graphicsDevice, @"GameComponents\CreateTroop\Data\" + node.Attributes.GetNamedItem("Disabled").Value);
            this.createTroop.PersonButtonPosition        = StaticMethods.LoadRectangleFromXMLNode(node);
            this.createTroop.PersonButtonDisplayTexture  = this.createTroop.PersonButtonTexture;
            node = nextSibling.ChildNodes.Item(10);
            this.createTroop.LeaderButtonTexture         = Texture2D.FromFile(this.graphicsDevice, @"GameComponents\CreateTroop\Data\" + node.Attributes.GetNamedItem("FileName").Value);
            this.createTroop.LeaderButtonSelectedTexture = Texture2D.FromFile(this.graphicsDevice, @"GameComponents\CreateTroop\Data\" + node.Attributes.GetNamedItem("Selected").Value);
            this.createTroop.LeaderButtonDisabledTexture = Texture2D.FromFile(this.graphicsDevice, @"GameComponents\CreateTroop\Data\" + node.Attributes.GetNamedItem("Disabled").Value);
            this.createTroop.LeaderButtonPosition        = StaticMethods.LoadRectangleFromXMLNode(node);
            this.createTroop.LeaderButtonDisplayTexture  = this.createTroop.LeaderButtonTexture;
            node = nextSibling.ChildNodes.Item(11);
            this.createTroop.RationButtonTexture         = Texture2D.FromFile(this.graphicsDevice, @"GameComponents\CreateTroop\Data\" + node.Attributes.GetNamedItem("FileName").Value);
            this.createTroop.RationButtonSelectedTexture = Texture2D.FromFile(this.graphicsDevice, @"GameComponents\CreateTroop\Data\" + node.Attributes.GetNamedItem("Selected").Value);
            this.createTroop.RationButtonDisabledTexture = Texture2D.FromFile(this.graphicsDevice, @"GameComponents\CreateTroop\Data\" + node.Attributes.GetNamedItem("Disabled").Value);
            this.createTroop.RationButtonPosition        = StaticMethods.LoadRectangleFromXMLNode(node);
            this.createTroop.RationButtonDisplayTexture  = this.createTroop.RationButtonTexture;
            node = nextSibling.ChildNodes.Item(12);
            this.createTroop.CreateButtonTexture         = Texture2D.FromFile(this.graphicsDevice, @"GameComponents\CreateTroop\Data\" + node.Attributes.GetNamedItem("FileName").Value);
            this.createTroop.CreateButtonSelectedTexture = Texture2D.FromFile(this.graphicsDevice, @"GameComponents\CreateTroop\Data\" + node.Attributes.GetNamedItem("Selected").Value);
            this.createTroop.CreateButtonDisabledTexture = Texture2D.FromFile(this.graphicsDevice, @"GameComponents\CreateTroop\Data\" + node.Attributes.GetNamedItem("Disabled").Value);
            this.createTroop.CreateButtonPosition        = StaticMethods.LoadRectangleFromXMLNode(node);
            this.createTroop.CreateButtonDisplayTexture  = this.createTroop.CreateButtonTexture;
            node = nextSibling.ChildNodes.Item(13);
            this.createTroop.zijinButtonTexture         = Texture2D.FromFile(this.graphicsDevice, @"GameComponents\CreateTroop\Data\" + node.Attributes.GetNamedItem("FileName").Value);
            this.createTroop.zijinButtonSelectedTexture = Texture2D.FromFile(this.graphicsDevice, @"GameComponents\CreateTroop\Data\" + node.Attributes.GetNamedItem("Selected").Value);
            this.createTroop.zijinButtonDisabledTexture = Texture2D.FromFile(this.graphicsDevice, @"GameComponents\CreateTroop\Data\" + node.Attributes.GetNamedItem("Disabled").Value);
            this.createTroop.zijinButtonPosition        = StaticMethods.LoadRectangleFromXMLNode(node);
            this.createTroop.zijinButtonDisplayTexture  = this.createTroop.zijinButtonTexture;
        }
Exemple #59
0
        private Texture2D RenderToTexture2DUsingImageData(IEnumerable lines, HorizontalAlignment horizontalAlignment, SystemManagers managers)
        {
            ImageData[] imageDatas = new ImageData[this.mTextures.Length];

            for (int i = 0; i < imageDatas.Length; i++)
            {
                // Only use the existing buffer on one-page fonts
                var bufferToUse = mColorBuffer;
                if (i > 0)
                {
                    bufferToUse = null;
                }
                imageDatas[i] = ImageData.FromTexture2D(this.mTextures[i], managers, bufferToUse);
            }

            Point point = new Point();

            int maxWidthSoFar  = 0;
            int requiredWidth  = 0;
            int requiredHeight = 0;

            List <int> widths = new List <int>();

            foreach (string line in lines)
            {
                requiredHeight += LineHeightInPixels;
                requiredWidth   = 0;

                requiredWidth = MeasureString(line);
                widths.Add(requiredWidth);
                maxWidthSoFar = System.Math.Max(requiredWidth, maxWidthSoFar);
            }

            const int MaxWidthAndHeight = 2048; // change this later?

            maxWidthSoFar  = System.Math.Min(maxWidthSoFar, MaxWidthAndHeight);
            requiredHeight = System.Math.Min(requiredHeight, MaxWidthAndHeight);



            ImageData imageData = null;

            if (maxWidthSoFar != 0)
            {
                imageData = new ImageData(maxWidthSoFar, requiredHeight, managers);

                int lineNumber = 0;

                foreach (string line in lines)
                {
                    point.X = 0;

                    if (horizontalAlignment == HorizontalAlignment.Right)
                    {
                        point.X = maxWidthSoFar - widths[lineNumber];
                    }
                    else if (horizontalAlignment == HorizontalAlignment.Center)
                    {
                        point.X = (maxWidthSoFar - widths[lineNumber]) / 2;
                    }

                    foreach (char c in line)
                    {
                        BitmapCharacterInfo characterInfo = GetCharacterInfo(c);

                        int sourceLeft   = characterInfo.GetPixelLeft(Texture);
                        int sourceTop    = characterInfo.GetPixelTop(Texture);
                        int sourceWidth  = characterInfo.GetPixelRight(Texture) - sourceLeft;
                        int sourceHeight = characterInfo.GetPixelBottom(Texture) - sourceTop;

                        int distanceFromTop = characterInfo.GetPixelDistanceFromTop(LineHeightInPixels);

                        // There could be some offset for this character
                        int xOffset = characterInfo.GetPixelXOffset(LineHeightInPixels);
                        point.X += xOffset;

                        point.Y = lineNumber * LineHeightInPixels + distanceFromTop;

                        Microsoft.Xna.Framework.Rectangle sourceRectangle = new Microsoft.Xna.Framework.Rectangle(
                            sourceLeft, sourceTop, sourceWidth, sourceHeight);

                        int pageIndex = characterInfo.PageNumber;

                        imageData.Blit(imageDatas[pageIndex], sourceRectangle, point);

                        point.X -= xOffset;
                        point.X += characterInfo.GetXAdvanceInPixels(LineHeightInPixels);
                    }
                    point.X = 0;
                    lineNumber++;
                }
            }


            if (imageData != null)
            {
                // We don't want
                // to generate mipmaps
                // because text is usually
                // rendered pixel-perfect.

                const bool generateMipmaps = false;


                return(imageData.ToTexture2D(generateMipmaps));
            }
            else
            {
                return(null);
            }
        }
Exemple #60
0
 public static Microsoft.Xna.Framework.Rectangle GetLeftRectangle(Microsoft.Xna.Framework.Rectangle rectDes, Microsoft.Xna.Framework.Rectangle rect)
 {
     return(new Microsoft.Xna.Framework.Rectangle(rectDes.Left, rectDes.Top + ((rectDes.Height - rect.Height) / 2), rect.Width, rect.Height));
 }