public override void Draw(TimeSpan ellapsedTime, ViewPort viewPort) { if (_actor.IsDestoryed) return; if (this.ResourceDictionary == null) return; var sprite = (SpriteResource)ResourceDictionary.GetResource(_resource.SpriteKey); var texture = (Texture2D)ResourceDictionary.GetResource(sprite.TextureKey); var location = ((ILocatable)_actor).Location; RunAnimations(); Color c; if (opacity != 1f) c = new Color(opacity, opacity, opacity, 1f); else c = Color.White; _spriteBatch.Draw(texture, new Rectangle((Int32)(location.X * viewPort.ResolutionX) + (Int32)XOffset, (Int32)(location.Y * viewPort.ResolutionY) + (Int32)YOffset, (Int32)(_resource.Width * viewPort.ResolutionX) + (Int32)WidthOffset, (Int32)(_resource.Height * viewPort.ResolutionY) + (Int32)HeightOffset), new Rectangle(sprite.UCoordinate, sprite.VCoordinate, sprite.Width, sprite.Height) /* texture source */, c ); }
public override void Draw(TimeSpan ellapsedTime, ViewPort viewPort) { base.Draw(ellapsedTime, viewPort); var font = (SpriteFont)ResourceDictionary.GetResource("TitleFont"); _spriteBatch.DrawString(font, "X" + ((UIToolButtonActor)_actor).AvailableCount.ToString(), new Vector2(_actor.Location.X + 60f + XOffset, _actor.Location.Y + 65f + YOffset), Color.White, 0f, Vector2.Zero, 0.8f, SpriteEffects.None, 0); }
public override void Draw(TimeSpan ellapsedTime, ViewPort viewPort) { Single XOffset = 0f; Single YOffset = 0f; Single WidthOffset = 0f; Single HeightOffset = 0f; Single opacity = _actor.Opacity; foreach (var animation in this._currentAnimations.ToArray()) { if (animation.IsComplete == true) { this._currentAnimations.Remove(animation); } else { if (animation.AnimatedProperty == "XOffset") XOffset = (Single)animation.AnimatedValue; else if (animation.AnimatedProperty == "YOffset") YOffset = (Single)animation.AnimatedValue; else if (animation.AnimatedProperty == "WidthOffset") WidthOffset = (Single)animation.AnimatedValue; else if (animation.AnimatedProperty == "HeightOffset") HeightOffset = (Single)animation.AnimatedValue; else if (animation.AnimatedProperty == "Opacity") opacity = (Single)animation.AnimatedValue; } } var sprite = (SpriteResource)ResourceDictionary.GetResource("SolidSprite"); _spriteBatch.Draw((Texture2D)ResourceDictionary.GetResource(sprite.TextureKey), new Rectangle((Int32)_actor.Location.X + (Int32)XOffset, (Int32)_actor.Location.Y + (Int32)YOffset, (Int32)this._resource.Width + (Int32)WidthOffset, (Int32)this._resource.Height + (Int32)HeightOffset), new Rectangle(sprite.UCoordinate, sprite.VCoordinate, sprite.Width, sprite.Height) /* texture source */, new Color(0.25f, 0.5f, 0.7f, 0.9f)); _spriteBatch.Draw((Texture2D)ResourceDictionary.GetResource(sprite.TextureKey), new Rectangle((Int32)_actor.Location.X + (Int32)XOffset, (Int32)_actor.Location.Y + (Int32)YOffset, 2, (Int32)this._resource.Height), new Rectangle(sprite.UCoordinate, sprite.VCoordinate, sprite.Width, sprite.Height) /* texture source */, Color.White); _spriteBatch.Draw((Texture2D)ResourceDictionary.GetResource(sprite.TextureKey), new Rectangle((Int32)_actor.Location.X + (Int32)XOffset, (Int32)_actor.Location.Y + (Int32)YOffset, (Int32)this._resource.Width, 2), new Rectangle(sprite.UCoordinate, sprite.VCoordinate, sprite.Width, sprite.Height) /* texture source */, Color.White); _spriteBatch.Draw((Texture2D)ResourceDictionary.GetResource(sprite.TextureKey), new Rectangle((Int32)_actor.Location.X + (Int32)XOffset, (Int32)_actor.Location.Y + (Int32)this._resource.Height + (Int32)YOffset + (Int32)HeightOffset, (Int32)this._resource.Width, 2), new Rectangle(sprite.UCoordinate, sprite.VCoordinate, sprite.Width, sprite.Height) /* texture source */, Color.White); _spriteBatch.Draw((Texture2D)ResourceDictionary.GetResource(sprite.TextureKey), new Rectangle((Int32)_actor.Location.X + (Int32)this._resource.Width + (Int32)WidthOffset + (Int32)XOffset, (Int32)_actor.Location.Y + (Int32)YOffset, 2, (Int32)this._resource.Height), new Rectangle(sprite.UCoordinate, sprite.VCoordinate, sprite.Width, sprite.Height) /* texture source */, Color.White); }
public override void Draw(TimeSpan ellapsedTime, ViewPort viewPort) { if (this.ResourceDictionary == null) return; _terrainSpriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.Opaque, SamplerState.PointWrap, DepthStencilState.None, RasterizerState.CullNone); var location = ((ILocatable)_actor).Location; var horizontalOffset = ((Int32)(viewPort.Left % _terrainResource.TileWidth) * viewPort.ZoomFactor * Phat.Settings.MetersToPixels); var verticalOffset = ((Int32)(viewPort.Top % _terrainResource.TileHeight) * viewPort.ZoomFactor * Phat.Settings.MetersToPixels); var horizontalTileResolution = Math.Min(_terrainResource.Columns, Math.Ceiling(viewPort.ResolutionX / (_terrainResource.TileWidth * viewPort.ZoomFactor * Phat.Settings.MetersToPixels))) + 1; var verticalTileResolution = Math.Min(_terrainResource.Rows, Math.Ceiling(viewPort.ResolutionY / (_terrainResource.TileHeight * viewPort.ZoomFactor * Phat.Settings.MetersToPixels))) + 1; var initialRow = viewPort.Top / (_terrainResource.TileHeight); var initialColumn = viewPort.Left / (_terrainResource.TileWidth); for (Int32 row = 0; row < verticalTileResolution && (row + initialRow) < _terrainResource.Rows; row++) { var tileYScreenLocation = (Int32)(Math.Floor(row * _terrainResource.TileHeight * viewPort.ZoomFactor * Phat.Settings.MetersToPixels)) - verticalOffset; for (Int32 column = 0; column < (horizontalTileResolution + 1) && (column + initialColumn) < _terrainResource.Columns; column++) { var tileXScreenLocation = (Int32)(Math.Floor(column * _terrainResource.TileWidth * viewPort.ZoomFactor * Phat.Settings.MetersToPixels)) - horizontalOffset; if (String.IsNullOrEmpty(_terrainResource.TileDefinitionKeys[((row + initialRow) * _terrainResource.Columns) + column + initialColumn])) continue; var tile = (TerrainTileDefinitionResource)ResourceDictionary.GetResource(_terrainResource.TileDefinitionKeys[((row + initialRow) * _terrainResource.Columns) + column + initialColumn]); var sprite = (SpriteResource)ResourceDictionary.GetResource(tile.SpriteKey); var texture = (Texture2D)ResourceDictionary.GetResource(sprite.TextureKey); var spriteEffect = SpriteEffects.None; if (sprite.HorizontalFlip) spriteEffect = SpriteEffects.FlipHorizontally; if (sprite.VerticalFlip) spriteEffect |= SpriteEffects.FlipVertically; _terrainSpriteBatch.Draw(texture, new Rectangle((Int32)tileXScreenLocation, (Int32)tileYScreenLocation, (Int32)(Math.Ceiling(_terrainResource.TileWidth * viewPort.ZoomFactor * Phat.Settings.MetersToPixels) + (viewPort.ZoomFactor == 1.0 ? 0 : 1)), (Int32)(Math.Ceiling(_terrainResource.TileHeight * viewPort.ZoomFactor * Phat.Settings.MetersToPixels)) + (viewPort.ZoomFactor == 1.0 ? 0 : 1)) /* destination */, new Rectangle(sprite.UCoordinate, sprite.VCoordinate, sprite.Width, sprite.Height) /* texture source */, Color.White /* no tint */, 0f, Vector2.Zero, spriteEffect, tile.Layer ); } } _terrainSpriteBatch.End(); }
public void Draw(TimeSpan ellapsedTime, ViewPort viewPort) { Single XOffset = 0f; Single YOffset = 0f; Single Scale = 1f; Single Opacity = 1f; var font = (SpriteFont)this._resourceDictionary.GetResource(_actor.FontKey); foreach (var animation in this._currentAnimations.ToArray()) { if (animation.IsComplete == true) { this._currentAnimations.Remove(animation); } else { if (animation.AnimatedProperty == "XOffset") XOffset = (Single)animation.AnimatedValue; else if (animation.AnimatedProperty == "YOffset") YOffset = (Single)animation.AnimatedValue; else if (animation.AnimatedProperty == "Opacity") Opacity = (Single)animation.AnimatedValue; else if (animation.AnimatedProperty == "Scale") Scale = (Single)animation.AnimatedValue; } } Vector2 stringLocation; switch (_actor.TextAlignment) { case UITextBlockActor.Alignment.Left: stringLocation = new Vector2(_actor.Location.X + XOffset, _actor.Location.Y + YOffset); break; case UITextBlockActor.Alignment.Center: stringLocation = new Vector2((viewPort.ResolutionX /2f) - ((font.MeasureString(_actor.Text).X) * _actor.Scale / 2f)+ _actor.Location.X + XOffset, _actor.Location.Y + YOffset); break; case UITextBlockActor.Alignment.Right: stringLocation = new Vector2(viewPort.ResolutionX + XOffset - _actor.Location.X - font.MeasureString(_actor.Text).X, _actor.Location.Y); break; default: throw new Exception("An unknown text alignment was assigned"); } Color c; if (Opacity != 1f) c = new Color(1f, 1f, 1f, Opacity); else c = _actor.Color; _spriteBatch.DrawString(font, _actor.Text, stringLocation, c, 0f, Vector2.Zero, Scale * _actor.Scale, SpriteEffects.None, 0); }
public override void Draw(TimeSpan ellapsedTime, ViewPort viewPort) { foreach (var animation in this._currentAnimations.ToArray()) { if (animation.IsComplete == true) { this._currentAnimations.Remove(animation); } else { if (animation.AnimatedProperty == "XOffset") XOffset = (Single)animation.AnimatedValue; else if (animation.AnimatedProperty == "YOffset") YOffset = (Single)animation.AnimatedValue; else if (animation.AnimatedProperty == "Width") width = (Single)animation.AnimatedValue; else if (animation.AnimatedProperty == "Height") height = (Single)animation.AnimatedValue; } } var sprite = (SpriteResource)ResourceDictionary.GetResource("SolidSprite"); var spriteFont = (SpriteFont)ResourceDictionary.GetResource("TextFont"); _spriteBatch.Draw((Texture2D)ResourceDictionary.GetResource(sprite.TextureKey), new Rectangle((Int32)x + (Int32)XOffset, (Int32)y + (Int32)YOffset, (Int32)width, (Int32)height), new Rectangle(sprite.UCoordinate, sprite.VCoordinate, sprite.Width, sprite.Height) /* texture source */, new Color(0.19f, 0.19f, 0.19f, 0.9f)); _spriteBatch.Draw((Texture2D)ResourceDictionary.GetResource(sprite.TextureKey), new Rectangle((Int32)x + (Int32)XOffset, (Int32)y + (Int32)YOffset, 2, (Int32)height), new Rectangle(sprite.UCoordinate, sprite.VCoordinate, sprite.Width, sprite.Height) /* texture source */, Color.Black); _spriteBatch.Draw((Texture2D)ResourceDictionary.GetResource(sprite.TextureKey), new Rectangle((Int32)x + (Int32)XOffset, (Int32)y + (Int32)YOffset, (Int32)width, 2), new Rectangle(sprite.UCoordinate, sprite.VCoordinate, sprite.Width, sprite.Height) /* texture source */, Color.Black); _spriteBatch.Draw((Texture2D)ResourceDictionary.GetResource(sprite.TextureKey), new Rectangle((Int32)x + (Int32)XOffset, (Int32)y + (Int32)height + (Int32)YOffset, (Int32)width, 2), new Rectangle(sprite.UCoordinate, sprite.VCoordinate, sprite.Width, sprite.Height) /* texture source */, Color.Black); _spriteBatch.Draw((Texture2D)ResourceDictionary.GetResource(sprite.TextureKey), new Rectangle((Int32)x + (Int32)width + (Int32)XOffset, (Int32)y + (Int32)YOffset, 2, (Int32)height), new Rectangle(sprite.UCoordinate, sprite.VCoordinate, sprite.Width, sprite.Height) /* texture source */, Color.Black); SpriteFont font = null; // (SpriteFont)ResourceDictionary.GetResource(_actor.FontFamily); if (width > 500) _spriteBatch.DrawString(font, ((UITextPanelActor)_actor).Text, new Vector2(x + 10 + XOffset, y + 10 + YOffset), Color.White); }
public override VisualHitTestResult GetHitResult(Vector2 location, ViewPort viewPort) { var screenLocation = new Vector2(_actor.Location.X * viewPort.ResolutionX, _actor.Location.Y * viewPort.ResolutionY); if (location.X >= screenLocation.X && location.X <= (screenLocation.X + _resource.Width * viewPort.ResolutionX) && location.Y >= screenLocation.Y && location.Y <= (screenLocation.Y + _resource.Height * viewPort.ResolutionY) ) { return new VisualHitTestResult(this._actor, new Vector2(location.X - screenLocation.X, location.Y - screenLocation.Y), true); } else { return new VisualHitTestResult(this._actor, new Vector2(0f, 0f), false); } }
public override VisualHitTestResult GetHitResult(Vector2 location, ViewPort viewPort) { var horizontalOffset = ((Int32)(viewPort.Left % _terrainResource.TileWidth)); var verticalOffset = ((Int32)(viewPort.Top % _terrainResource.TileHeight)); var relativeLocation = new Vector2((location.X / viewPort.ZoomFactor) - _actor.Location.X + viewPort.Left + horizontalOffset, (location.Y / viewPort.ZoomFactor) - _actor.Location.Y + viewPort.Top + verticalOffset); if (relativeLocation.X >= _actor.Location.X && relativeLocation.X <= (_actor.Location.X + _terrainResource.Columns * _terrainResource.TileWidth) && relativeLocation.Y >= _actor.Location.Y && relativeLocation.Y <= (_actor.Location.Y + _terrainResource.Rows * _terrainResource.TileHeight) ) { return new VisualHitTestResult(this._actor, new Vector2(relativeLocation.X, relativeLocation.Y), true); } else { return new VisualHitTestResult(this._actor, new Vector2(0f, 0f), false); } }
public override void Draw(TimeSpan ellapsedTime, ViewPort viewPort) { if (_actor.SpriteKeys.Count == 0) return; RunAnimations(); _actor.CurrentPosition += (_actor.Velocity * (Single)ellapsedTime.TotalSeconds * ScrollRate); if (_actor.Velocity < 0) { _actor.Velocity += _actor.Damping * (Single)ellapsedTime.TotalSeconds; if (_actor.Velocity > 0) _actor.Velocity = 0; } if (_actor.Velocity > 0) { _actor.Velocity -= _actor.Damping * (Single)ellapsedTime.TotalSeconds; if (_actor.Velocity < 0) _actor.Velocity = 0; } Int32 firstIndex = (Int32)Math.Max(0, Math.Floor(_actor.CurrentPosition)- ItemVisibilityDistance); for (; firstIndex < Math.Floor(_actor.CurrentPosition); firstIndex++) { DrawItem(_actor.SpriteKeys[firstIndex], firstIndex - (Int32)Math.Floor(_actor.CurrentPosition)); } Int32 lastIndex = (Int32)Math.Min(_actor.SpriteKeys.Count - 1, Math.Floor(_actor.CurrentPosition) + ItemVisibilityDistance); for (Int32 index = _actor.SelectedIndex; index <= lastIndex; index++) { DrawItem(_actor.SpriteKeys[index], index - (Int32)Math.Floor(_actor.CurrentPosition)); } DrawItem(_actor.SpriteKeys[(Int32)Math.Floor(_actor.CurrentPosition)], 0); }
public override Phat.Visual.VisualHitTestResult GetHitResult(Vector2 location, ViewPort viewPort) { return new Phat.Visual.VisualHitTestResult(this._actor, Vector2.Zero, false); }
public override VisualHitTestResult GetHitResult(Vector2 location, ViewPort viewPort) { if (location.X >= this.x && location.X <= (this.x + this.width) && location.Y >= this.y && location.Y <= (this.y + this.height) ) { return new VisualHitTestResult(this._actor, new Vector2(location.X - x, location.Y - y), true); } else { return new VisualHitTestResult(this._actor, new Vector2(0f, 0f), false); } }
public VisualHitTestResult GetHitResult(Vector2 location, ViewPort viewPort) { Vector2 stringLocation; var font = (SpriteFont)this._resourceDictionary.GetResource(_actor.FontKey); switch (_actor.TextAlignment) { case UITextBlockActor.Alignment.Left: stringLocation = new Vector2(_actor.Location.X, _actor.Location.Y); break; case UITextBlockActor.Alignment.Center: stringLocation = new Vector2((viewPort.ResolutionX / 2f) - (font.MeasureString(_actor.Text).X / 2f) + _actor.Location.X, _actor.Location.Y); break; case UITextBlockActor.Alignment.Right: stringLocation = new Vector2(viewPort.ResolutionX - _actor.Location.X - font.MeasureString(_actor.Text).X, _actor.Location.Y); break; default: throw new Exception("An unknown text alignment was assigned"); } if (location.X >= stringLocation.X && location.X <= (stringLocation.X + font.MeasureString(_actor.Text).X) && location.Y >= stringLocation.Y && location.Y <= (stringLocation.Y + font.MeasureString(_actor.Text).Y) ) { return new VisualHitTestResult(this._actor, new Vector2(location.X - stringLocation.X, location.Y - stringLocation.Y), true); } else { return new VisualHitTestResult(this._actor, new Vector2(0f, 0f), false); } }
public override void Draw(TimeSpan ellapsedTime, ViewPort viewPort) { var location = ((ILocatable)_actor).Location; Draw(ellapsedTime, new Rectangle((Int32)((location.X * Settings.MetersToPixels - viewPort.Left + _properties.XOffset * Settings.MetersToPixels) * viewPort.ZoomFactor), (Int32)((location.Y * Settings.MetersToPixels - viewPort.Top + _properties.YOffset * Settings.MetersToPixels) * viewPort.ZoomFactor), (Int32)(Math.Ceiling((_resource.Width + _properties.WidthOffset) * viewPort.ZoomFactor * Phat.Settings.MetersToPixels) + (viewPort.ZoomFactor == 1.0 ? 0 : 1)), (Int32)(Math.Ceiling((_resource.Height + _properties.HeightOffset) * viewPort.ZoomFactor * Phat.Settings.MetersToPixels)) + (viewPort.ZoomFactor == 1.0 ? 0 : 1)) ); }
void IGameSetters.SetViewPort(ViewPort viewPort) { throw new NotImplementedException(); }
public override VisualHitTestResult GetHitResult(Vector2 location, ViewPort viewPort) { if (location.X >= (Int32)_actor.Location.X && location.X <= ((Int32)_actor.Location.X + this._resource.Width) && location.Y >= (Int32)_actor.Location.Y && location.Y <= ((Int32)_actor.Location.Y + this._resource.Height) ) { return new VisualHitTestResult(this._actor, new Vector2(location.X - (Int32)_actor.Location.X, location.Y - (Int32)_actor.Location.Y), true); } else { return new VisualHitTestResult(this._actor, new Vector2(0f, 0f), false); } }
public void Draw(TimeSpan ellapsedTime, ViewPort viewPort) { }
public Phat.Visual.VisualHitTestResult GetHitResult(Microsoft.Xna.Framework.Vector2 location, ViewPort viewPort) { return new Phat.Visual.VisualHitTestResult(this._actor, Vector2.Zero, false); }