/// <summary> /// Places a <see cref="MapGrh"/> on the map. /// </summary> /// <param name="map">The map to place the <see cref="MapGrh"/> on.</param> /// <param name="camera">The <see cref="ICamera2D"/>.</param> /// <param name="screenPos">The screen position to place the <see cref="MapGrh"/>.</param> /// <param name="useTileMode">If TileMode should be used.</param> /// <param name="gd">The <see cref="GrhData"/> to place. Set to null to attempt to use the <see cref="GrhData"/> that is /// currently selected in the <see cref="GlobalState"/>.</param> /// <returns>The <see cref="MapGrh"/> instance that was added, or null if the the <see cref="MapGrh"/> could not be /// added for any reason.</returns> public static MapGrh PlaceMapGrhAtScreenPos(Map map, ICamera2D camera, Vector2 screenPos, bool useTileMode, GrhData gd = null) { // Get the world position to place it var worldPos = camera.ToWorld(screenPos); return(PlaceMapGrhAtWorldPos(map, worldPos, useTileMode, gd)); }
/// <summary> /// Draws a <see cref="Skeleton"/>. /// </summary> /// <param name="skeleton">The <see cref="Skeleton"/> to draw.</param> /// <param name="camera">Camera to use.</param> /// <param name="sb">The <see cref="ISpriteBatch"/> to draw with.</param> /// <param name="selectedNode">The <see cref="SkeletonNode"/> to draw as selected.</param> public static void Draw(Skeleton skeleton, ICamera2D camera, ISpriteBatch sb, SkeletonNode selectedNode = null) { if (skeleton == null) { Debug.Fail("skeleton is null."); return; } if (skeleton.RootNode == null) { Debug.Fail("skeleton contains no root node."); return; } if (sb == null) { Debug.Fail("sb is null."); return; } if (sb.IsDisposed) { Debug.Fail("sb is disposed."); return; } if (camera == null) { Debug.Fail("camera is null."); return; } RecursiveDraw(camera, sb, selectedNode, skeleton.RootNode, 0); }
/// <summary> /// Initializes a new instance of the <see cref="World"/> class. /// </summary> /// <param name="getTime">Interface to get the current time.</param> /// <param name="camera">Primary world view camera.</param> /// <param name="userInfo">The user info. Can be null.</param> public World(IGetTime getTime, ICamera2D camera, UserInfo userInfo) { _userInfo = userInfo; _getTime = getTime; _camera = camera; MapDrawingExtensions.Add(new EmoticonMapDrawingExtension<Emoticon, EmoticonInfo<Emoticon>>(_emoticonDisplayManager)); if (userInfo != null) { Func<QuestID, bool> questStartReqs = x => UserInfo.HasStartQuestRequirements.HasRequirements(x) ?? false; Func<QuestID, bool> questFinishReqs = x => UserInfo.QuestInfo.ActiveQuests.Contains(x) && (UserInfo.HasFinishQuestRequirements.HasRequirements(x) ?? false); var e = new QuestMapDrawingExtension<Character>(userInfo.QuestInfo, questStartReqs, questFinishReqs, m => m.Spatial.GetMany<Character>(m.Camera.GetViewArea(), c => !c.ProvidedQuests.IsEmpty()), c => c.ProvidedQuests) { QuestAvailableCanStartIndicator = new Grh(GrhInfo.GetData("Quest", "can start")), QuestStartedIndicator = new Grh(GrhInfo.GetData("Quest", "started")), QuestAvailableCannotStartIndicator = new Grh(GrhInfo.GetData("Quest", "cannot start")), QuestTurnInIndicator = new Grh(GrhInfo.GetData("Quest", "turnin")) }; MapDrawingExtensions.Add(e); } }
/// <summary> /// Initializes a new instance of the <see cref="MapScreenControl"/> class. /// </summary> public MapScreenControl() { if (!DesignMode && LicenseManager.UsageMode != LicenseUsageMode.Runtime) { return; } _drawingManager = new DrawingManager(); _transBoxManager = new TransBoxManager(); _camera = new Camera2D(ClientSize.ToVector2()) { KeepInMap = true }; if (DrawingManager.LightManager.DefaultSprite == null) { DrawingManager.LightManager.DefaultSprite = new Grh(GrhInfo.GetData("Effect", "light")); } GlobalState.Instance.Map.SelectedObjsManager.SelectedChanged += SelectedObjsManager_SelectedChanged; lock (_instancesSync) { _instances.Add(this); } }
/// <summary> /// Gets the buffer then draws it to a <see cref="RenderTarget"/>. /// </summary> /// <param name="target">The <see cref="RenderTarget"/> to draw to.</param> /// <param name="camera">The <see cref="ICamera2D"/> to use when drawing.</param> /// <returns>True if the buffer was successfully drawn to the <paramref name="target"/>; otherwise false.</returns> protected bool DrawBufferToTarget(RenderTarget target, ICamera2D camera) { // Get the buffer var bufferImage = GetBuffer(camera); if (bufferImage == null) { return(false); } // Set up the sprite _drawToTargetSprite.Texture = bufferImage; _drawToTargetSprite.Position = target.MapPixelToCoords(Vector2.Zero).Round(); var bufferImageSize = bufferImage.Size; _drawToTargetSprite.TextureRect = new IntRect(0, 0, (int)bufferImageSize.X, (int)bufferImageSize.Y); // Reset RenderStates _renderStates.Shader = DrawToTargetShader; _renderStates.BlendMode = BlendMode.Alpha; _renderStates.Transform = Transform.Identity; _renderStates.Texture = null; // Draw to the target HandleDrawBufferToTarget(bufferImage, _drawToTargetSprite, target, camera, _renderStates); return(true); }
public void Initialize(Game game, SpriteBatch spriteBatch, ICamera2D camera) { for (int i = 0; i < _nanobots.Count; i++) { _nanobots[i].Initialize(game, spriteBatch, camera); } }
public void Draw(IDrawStage stage, ICamera2D camera, IRenderTarget target) { if (stage == null) { throw new Yak2DException("Unable to queue DrawStage. Stage is null", new ArgumentNullException()); } if (camera == null) { throw new Yak2DException("Unable to queue DrawStage. Camera is null", new ArgumentNullException()); } if (target == null) { throw new Yak2DException("Unable to queue DrawStage. Target is null", new ArgumentNullException()); } _commandQueue.Add(RenderCommandType.DrawStage, stage.Id, target.Id, camera.Id, 0UL, 0UL, 0UL, 0UL, RgbaFloat.Clear); }
/// <summary> /// Initializes a new instance of the <see cref="World"/> class. /// </summary> /// <param name="getTime">Interface to get the current time.</param> /// <param name="camera">Primary world view camera.</param> /// <param name="userInfo">The user info. Can be null.</param> public World(IGetTime getTime, ICamera2D camera, UserInfo userInfo) { _userInfo = userInfo; _getTime = getTime; _camera = camera; MapDrawingExtensions.Add(new EmoticonMapDrawingExtension <Emoticon, EmoticonInfo <Emoticon> >(_emoticonDisplayManager)); if (userInfo != null) { Func <QuestID, bool> questStartReqs = x => UserInfo.HasStartQuestRequirements.HasRequirements(x) ?? false; Func <QuestID, bool> questFinishReqs = x => UserInfo.QuestInfo.ActiveQuests.Contains(x) && (UserInfo.HasFinishQuestRequirements.HasRequirements(x) ?? false); var e = new QuestMapDrawingExtension <Character>(userInfo.QuestInfo, questStartReqs, questFinishReqs, m => m.Spatial.GetMany <Character>(m.Camera.GetViewArea(), c => !c.ProvidedQuests.IsEmpty()), c => c.ProvidedQuests) { QuestAvailableCanStartIndicator = new Grh(GrhInfo.GetData("Quest", "can start")), QuestStartedIndicator = new Grh(GrhInfo.GetData("Quest", "started")), QuestAvailableCannotStartIndicator = new Grh(GrhInfo.GetData("Quest", "cannot start")), QuestTurnInIndicator = new Grh(GrhInfo.GetData("Quest", "turnin")) }; MapDrawingExtensions.Add(e); } }
/// <summary> /// Initializes a new instance of the <see cref="MoveManyTransBox"/> class. /// </summary> /// <param name="owner">The <see cref="TransBoxManager"/>.</param> /// <param name="spatials">The <see cref="ISpatial"/>s.</param> /// <param name="position">The position.</param> /// <param name="camera">The camera.</param> public MoveManyTransBox(TransBoxManager owner, IEnumerable<ISpatial> spatials, Vector2 position, ICamera2D camera) { _owner = owner; _camera = camera; _position = position; _spatials = spatials.ToImmutable(); }
/// <summary> /// Recursively draws the joints and bones of a skeleton. /// </summary> /// <param name="camera">Camera to use.</param> /// <param name="sb"><see cref="ISpriteBatch"/> to draw to.</param> /// <param name="selectedNode">SpriteBatch to draw to.</param> /// <param name="node">Current node being drawn.</param> /// <param name="colorIndex">Index of the color to use from the ColorList.</param> static void RecursiveDraw(ICamera2D camera, ISpriteBatch sb, SkeletonNode selectedNode, SkeletonNode node, int colorIndex) { // Find the color of the joint var color = _colorList[colorIndex]; if (node == selectedNode) color = _nodeColorSelected; else if (node.Parent == null) color = _nodeColorRoot; // Draw the joint var scale = 1f / camera.Scale; var origin = SkeletonNode.HalfJointVector; _joint.Draw(sb, node.Position, color, SpriteEffects.None, 0f, origin, scale); // Iterate through the children foreach (var child in node.Nodes) { colorIndex++; if (colorIndex == _colorList.Length) colorIndex = 0; // Draw the bone to the child RenderLine.Draw(sb, node.Position, child.Position, _colorList[colorIndex], (1f / camera.Scale) * 2f); // Draw the child RecursiveDraw(camera, sb, selectedNode, child, colorIndex); } }
public override void Initialize(Game game, SpriteBatch spriteBatch, ICamera2D camera) { var state = game.Services.GetService<GameState>(); for (int index = 0; index < Enemies.Count; index++) { var enemy = Enemies[index]; enemy.Initialize(game, spriteBatch, camera); //var range = enemy as IRangeEnemy; //if (range != null) //{ // _enemyScripts.Add(enemy, // new RangeEnemyAttackScript(game, Random.Next((int) range.AttackInterval)) {Combatant = range}); //} //else if (enemy is CloseCombatEnemy) //{ // _enemyScripts.Add(enemy, new CloseCombatEnemyAttackScript // { // Combatant = (CloseCombatEnemy) enemy, // Target = state.Player.Nanobots[Random.Next(state.Player.Nanobots.Count())] // }); //} } Reactions.Add(PlayerAction.Shoot, ShootReaction); Length = 400; base.Initialize(game, spriteBatch, camera); }
public JointUpdateable(I2DScene scene, FarseerWorld world,ICamera2D camera) : base(scene) { this.camera = camera; this.world = world; this.Start(); }
/// <summary> /// Draws a <see cref="Skeleton"/>. /// </summary> /// <param name="skeleton">The <see cref="Skeleton"/> to draw.</param> /// <param name="camera">Camera to use.</param> /// <param name="sb">The <see cref="ISpriteBatch"/> to draw with.</param> /// <param name="selectedNode">The <see cref="SkeletonNode"/> to draw as selected.</param> public static void Draw(Skeleton skeleton, ICamera2D camera, ISpriteBatch sb, SkeletonNode selectedNode = null) { if (skeleton == null) { Debug.Fail("skeleton is null."); return; } if (skeleton.RootNode == null) { Debug.Fail("skeleton contains no root node."); return; } if (sb == null) { Debug.Fail("sb is null."); return; } if (sb.IsDisposed) { Debug.Fail("sb is disposed."); return; } if (camera == null) { Debug.Fail("camera is null."); return; } RecursiveDraw(camera, sb, selectedNode, skeleton.RootNode, 0); }
public JointUpdateable(I2DScene scene, FarseerWorld world, ICamera2D camera) : base(scene) { this.camera = camera; this.world = world; this.Start(); }
protected override void OnEnable() { instance = this; this.camera = Rendering.CreateCameraWorld(this.SceneObject, ClientAmbientOcclusion.RenderingTag, -1000); this.camera.ClearColor = ClientAmbientOcclusion.IsDisplayMask ? Color.FromArgb(0x99, 0xFF, 0xFF, 0xFF) : Color.FromArgb(0x00, 0x00, 0x00, 0x00); // transparent black this.camera.DrawMode = CameraDrawMode.Manual; this.blurPostEffect = new BlurPostEffect { RenderTextureDownsampling = 1, Passes = 2, IsEnabled = true }; this.layerRenderer = Client.Rendering.CreateLayerRenderer( this.SceneObject, TextureResource.NoTexture, drawOrder: ClientAmbientOcclusion.IsDisplayMask // display as overlay (over everything) ? DrawOrder.Overlay : DrawOrder.Occlusion); this.layerRenderer.CustomDraw += this.LayerRendererBeforeDrawHandler; this.effectInstanceCompose = EffectInstance.Create(EffectResourceAmbientOcclusionCompose); }
/// <summary> /// Initializes a new instance of the <see cref="MoveManyTransBox"/> class. /// </summary> /// <param name="owner">The <see cref="TransBoxManager"/>.</param> /// <param name="spatials">The <see cref="ISpatial"/>s.</param> /// <param name="position">The position.</param> /// <param name="camera">The camera.</param> public MoveManyTransBox(TransBoxManager owner, IEnumerable <ISpatial> spatials, Vector2 position, ICamera2D camera) { _owner = owner; _camera = camera; _position = position; _spatials = spatials.ToImmutable(); }
/// <summary> /// Handles when the mouse moves. /// </summary> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param> /// <param name="camera">The <see cref="ICamera2D"/> describing the current view.</param> /// <returns>True if the <see cref="TransBoxManager"/> handled the event; otherwise false.</returns> public bool HandleMouseMove(MouseEventArgs e, ICamera2D camera) { if (_transBoxes.Count == 0) { return(false); } var worldPos = camera.ToWorld(e.Position()); _lastWorldPos = worldPos; // Update what transbox is under the cursor if (SelectedTransBox != null) { UnderCursor = SelectedTransBox; } else { UnderCursor = FindBoxAt(worldPos); } // Update position if (SelectedTransBox != null) { SelectedTransBox.CursorMoved(_lastWorldPos); } return(SelectedTransBox != null); }
/// <summary> /// Sets the <see cref="ISpatial"/>s to place a transformation boxes over. Items that are the /// same <see cref="Type"/> as the <see cref="Type"/>s define din <see cref="TypesToIgnore"/> will not be added, /// and neither will <see cref="ISpatial"/>s where <see cref="ISpatial.SupportsMove"/> and /// <see cref="ISpatial.SupportsResize"/> is false. /// </summary> /// <param name="items">The <see cref="ISpatial"/>s to place transformation boxes over. Using a null or /// empty collection is synonymous with just using <see cref="Clear"/>.</param> /// <param name="camera">The camera describing the view area.</param> public void SetItems(IEnumerable <ISpatial> items, ICamera2D camera) { // Clear Clear(camera); if (items == null) { return; } // Get the items to add // If it doesn't support moving, don't add it, even if it supports resizing since a lot of our resizing requires moving var toAdd = items.Where(x => x.SupportsMove && TypesToIgnore.All(y => x.GetType() != y)); if (toAdd.IsEmpty()) { return; } // Add the items _items.AddRange(toAdd); // Update UpdateTransBoxes(camera); }
/// <summary> /// Draws the <see cref="TransBoxManager"/> and all transformation boxes in it. /// </summary> /// <param name="spriteBatch">The <see cref="ISpriteBatch"/> to use to draw.</param> /// <param name="camera">The <see cref="ICamera2D"/> describing the current view.</param> public void Draw(ISpriteBatch spriteBatch, ICamera2D camera) { foreach (var tb in _transBoxes) { tb.Draw(spriteBatch, camera); } }
/// <summary> /// Finds the map position of the image using the given <paramref name="camera"/>. /// </summary> /// <param name="mapSize">Size of the map that this image is on.</param> /// <param name="camera">Camera that describes the current view.</param> /// <param name="spriteSize">Size of the Sprite that will be drawn.</param> /// <returns>The map position of the image using the given <paramref name="camera"/>.</returns> protected Vector2 GetPosition(Vector2 mapSize, ICamera2D camera, Vector2 spriteSize) { // Can't draw a sprite that has no size... if (spriteSize == Vector2.Zero) { return(Vector2.Zero); } // Get the position from the alignment var alignmentPosition = AlignmentHelper.FindOffset(Alignment, spriteSize, mapSize); // Add the custom offset var position = alignmentPosition + Offset; // Find the difference between the position and the camera's min position var diff = camera.Min - position; // Use the multiplier to align it to the correct part of the camera diff += (camera.Size - spriteSize) * GetOffsetMultiplier(Alignment); // Compensate for the depth diff *= ((1 / Depth) - 1); // Add the difference to the position position -= diff; return(position); }
/// <summary> /// Handles when a key is raised on a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected override void MapContainer_KeyUp(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, KeyEventArgs e) { // Handle deletes if (e.KeyCode == Keys.Delete) { // Only delete when it is an Entity that is on this map var removed = new List<object>(); foreach (var x in SOM.SelectedObjects.OfType<Entity>().ToImmutable()) { if (map.Spatial.CollectionContains(x)) { map.RemoveEntity(x); if (!x.IsDisposed) x.Dispose(); removed.Add(x); } } SOM.SetManySelected(SOM.SelectedObjects.Except(removed).ToImmutable()); } base.MapContainer_KeyUp(sender, map, camera, e); }
private void DrawMapBorders(GraphicsContext graphicsContext, ICamera2D camera) { // Room borders const int RoomBorderThickness = 2; for(int x = 0; x < _map.WidthInRooms; x++) { for(int y = 0; y < _map.HeightInRooms; y++) { Vector2i roomSize = new Vector2i(Room.Width * Tile.Size, Room.Height * Tile.Size); // Draw room sub-borders for (int x1 = 0; x1 < 4; x1++) { for (int y1 = 0; y1 < 4; y1++) { graphicsContext.PrimitiveRenderer.DrawRectangleOutlines( graphicsContext, new RectangleF(x * roomSize.X + x1 * roomSize.X / 4f, y * roomSize.Y + y1 * roomSize.Y / 4f, roomSize.X / 4f, roomSize.Y / 4f), Color.RoyalBlue.MultiplyRGB(0.5f) * 0.5f, RoomBorderThickness / camera.Zoom); } } // Draw room borders graphicsContext.PrimitiveRenderer.DrawRectangleOutlines(graphicsContext, new Rectangle(x * roomSize.X, y * roomSize.Y, roomSize.X, roomSize.Y), Color.RoyalBlue, RoomBorderThickness / camera.Zoom); } } // Full map borders const int MapBorderThickness = 4; graphicsContext.PrimitiveRenderer.DrawRectangleOutlines(graphicsContext, new Rectangle(0, 0, _map.Width * Tile.Size, _map.Height * Tile.Size), Color.White, MapBorderThickness / camera.Zoom); }
/// <summary> /// Draws the <see cref="ITransBox"/>. /// </summary> /// <param name="spriteBatch">The <see cref="ISpriteBatch"/> to draw to.</param> /// <param name="camera">The <see cref="ICamera2D"/>.</param> public void Draw(ISpriteBatch spriteBatch, ICamera2D camera) { var p = camera.ToScreen(Position).Round(); var s = Size.Round(); var r = new Rectangle((int)p.X, (int)p.Y, (int)s.X, (int)s.Y); SystemSprites.Move.Draw(spriteBatch, r, Color.White); }
//private TextureManager _textureManager; #endregion #region Ctors public PlayingView(Microsoft.Xna.Framework.Game game) : base(game) { _entities = new List<ISpriteEntity>(); camera = new Camera2D(Game); _gameScore = new GameScore(); _hud = new HudView(Game); }
/// <summary> /// Draws the <see cref="ITransBox"/>. /// </summary> /// <param name="spriteBatch">The <see cref="ISpriteBatch"/> to draw to.</param> /// <param name="camera">The <see cref="ICamera2D"/>.</param> public void Draw(ISpriteBatch spriteBatch, ICamera2D camera) { Vector2 p = camera.ToScreen(Position).Round(); Vector2 s = Size.Round(); Rectangle r = new Rectangle(p.X, p.Y, s.X, s.Y); SystemSprites.Move.Draw(spriteBatch, r, Color.White); }
/// <summary> /// Handles both mouse clicks and moves (does the place/deletes of grhs). /// </summary> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> void HandleMouseClickAndMove(EditorMap map, ICamera2D camera, MouseEventArgs e) { // Update some vars var cursorPos = e.Position(); _mouseOverMap = map; _mousePos = cursorPos; // Don't do any place/deletes while selecting if (IsSelecting) { return; } Vector2 worldPos = camera.ToWorld(cursorPos); // Handle mouse if (e.Button == MouseButtons.Left) { if (!Input.IsShiftDown) { // Place grh PlaceMapGrhAtScreenPos(map, camera, cursorPos, !Input.IsCtrlDown); } else { // Select grh under cursor var grhToSelect = GetGrhToSelect(map, worldPos); if (grhToSelect != null) { GlobalState.Instance.Map.SetGrhToPlace(grhToSelect.Grh.GrhData.GrhIndex); GlobalState.Instance.Map.Layer = grhToSelect.MapRenderLayer; GlobalState.Instance.Map.LayerDepth = grhToSelect.LayerDepth; } } } else if (e.Button == MouseButtons.Right) { if (!Input.IsShiftDown) { // Delete from current layer var grhToDelete = GetGrhToSelect(map, worldPos, mustBeOnLayer: GlobalState.Instance.Map.Layer); if (grhToDelete != null) { map.RemoveMapGrh(grhToDelete); } } else { // Delete from all layers var grhToSelect = GetGrhToSelect(map, worldPos); if (grhToSelect != null) { map.RemoveMapGrh(grhToSelect); } } } }
private void Draw(SpriteBatch spriteBatch, ICamera2D camera) { spriteBatch.Begin(SpriteSortMode.Texture, BlendState.Additive, transformMatrix: camera.TransformationMatrix); grid.Draw(spriteBatch); player1.Draw(spriteBatch); player2.Draw(spriteBatch); particles.Draw(spriteBatch); spriteBatch.End(); }
public ParallaxScene(GraphicsDevice graphics, ICamera2D camera) : base(graphics, camera) { _bkgSpriteBatch = new SpriteBatch(graphics); _overlaySpriteBatch = new SpriteBatch(graphics); BackgroundBlendState = BlendState.AlphaBlend; ParallaxLayers = new List <ParallaxSurface>(); }
/// <summary> /// Initializes a new instance of the <see cref="ParticleEffectScreenControl"/> class. /// </summary> public ParticleEffectScreenControl() { if (!DesignMode && LicenseManager.UsageMode == LicenseUsageMode.Runtime) { _camera = new Camera2D(new Vector2(400, 300)); _drawingManager = new DrawingManager(); DrawingManager.BackgroundColor = BackColor.ToColor(); } }
/// <summary> /// Checks if in the object is in view of the specified <paramref name="camera"/>. /// </summary> /// <param name="camera">The <see cref="ICamera2D"/> to check if this object is in view of.</param> /// <returns>True if the object is in view of the camera, else False.</returns> public bool InView(ICamera2D camera) { if (ParticleEffect == null) { return(false); } return(ParticleEffect.InView(camera)); }
public static void Draw(ISpriteBatch sb, ICamera2D camera, WallEntityBase wall, Vector2 offset) { // Find the positon to draw to var p = wall.Position + offset; var dest = new Rectangle((int)p.X, (int)p.Y, (int)wall.Size.X, (int)wall.Size.Y); // Draw the collision area RenderRectangle.Draw(sb, dest, _wallColor); }
public ViewModelInventorySkeletonViewData( ICharacter character, IClientSceneObject sceneObjectCamera, IClientSceneObject sceneObjectSkeleton, ICamera2D camera, IRenderTarget2D renderTarget2D, string renderingTag, float textureWidth, float textureHeight) { this.character = character; this.equipmentContainer = (IClientItemsContainer)character .GetPublicState <ICharacterPublicStateWithEquipment>() .ContainerEquipment; this.equipmentContainer.StateHashChanged += this.EquipmentContainerStateHashChangedHandler; this.sceneObjectCamera = sceneObjectCamera; this.sceneObjectSkeleton = sceneObjectSkeleton; this.camera = camera; this.renderTarget2D = renderTarget2D; this.renderingTag = renderingTag; this.textureWidth = textureWidth; this.textureHeight = textureHeight; this.ImageBrush = InventorySkeletonViewHelper.Client.UI.CreateImageBrushForRenderTarget( renderTarget2D); this.ImageBrush.Stretch = Stretch.Uniform; // subscribe on change of the face // commented out - no need, the skeleton will be rebuilt completely //var publicState = PlayerCharacter.GetPublicState(character); //publicState.ClientSubscribe( // _ => _.FaceStyle, // _ => this.OnNeedRefreshEquipment(), // this); // subscribe on change of the equipment var clientState = PlayerCharacter.GetClientState(character); clientState.ClientSubscribe( _ => _.LastEquipmentContainerHash, _ => this.OnNeedRefreshEquipment(), this); var publicState = PlayerCharacter.GetPublicState(character); publicState.ClientSubscribe( _ => _.IsHeadEquipmentHiddenForSelfAndPartyMembers, _ => this.OnNeedRefreshEquipment(), this); //this.RefreshEquipment(); this.OnNeedRefreshEquipment(); }
/// <summary> /// Initializes a new instance of the <see cref="ParticleEffectScreenControl"/> class. /// </summary> public ParticleEffectScreenControl() { if (!DesignMode && LicenseManager.UsageMode == LicenseUsageMode.Runtime) { _camera = new Camera2D(new Vector2(400, 300)); _drawingManager = new DrawingManager(); DrawingManager.BackgroundColor = BackColor.ToColor(); } }
public Vector2 WorldFromScreen(Vector2 position, ICamera2D camera) { if (camera == null) { return(Vector2.Zero); } return(WorldFromScreen(position, camera.Id)); }
public void SetCamera2DRotation(ICamera2D camera, float angle) { if (camera == null) { return; } _cameraManager.RetrieveCameraModel2D(camera.Id)?.SetWorldRotationRadiansClockwiseFromPositiveY(angle); }
public void SetCamera2DFocusZoomAndRotation(ICamera2D camera, Vector2 focus, float zoom, float angle) { if (camera == null) { return; } _cameraManager.RetrieveCameraModel2D(camera.Id)?.SetWorldFocusZoomAndRotationRadiansAngleClockwiseFromPositiveY(focus, zoom, angle); }
public void SetCamera2DFocusAndZoom(ICamera2D camera, Vector2 focus, float zoom) { if (camera == null) { return; } _cameraManager.RetrieveCameraModel2D(camera.Id)?.SetWorldFocusAndZoom(focus, zoom); }
public void SetCamera2DRotation(ICamera2D camera, Vector2 up) { if (camera == null) { return; } _cameraManager.RetrieveCameraModel2D(camera.Id)?.SetWorldRotationUsingUpVector(up); }
public void SetCamera2DVirtualResolution(ICamera2D camera, uint width, uint height) { if (camera == null) { return; } _cameraManager.RetrieveCameraModel2D(camera.Id)?.SetVirtualResolution(width, height); }
public void SetCamera2DFocusZoomAndRotation(ICamera2D camera, Vector2 focus, float zoom, Vector2 up) { if (camera == null) { return; } _cameraManager.RetrieveCameraModel2D(camera.Id)?.SetWorldFocusZoomAndRotationUsingUpVector(focus, zoom, up); }
public void Initialize(Game game, SpriteBatch spriteBatch, ICamera2D camera) { foreach (ScrollingBackground t in _layers) { t.Initialize(game, spriteBatch, camera); } _isInitialized = true; }
public void Draw(RenderHelper render, ICamera2D cam) { render.SetSamplerState(SamplerState.AnisotropicWrap, 0); render.PushRasterizerState(RasterizerState.CullNone); _basicEffect.Projection = cam.SimProjection; _basicEffect.View = cam.SimView; render.RenderUserPrimitive(_basicEffect, PrimitiveType.TriangleList, _borderVerts, 0, 8); render.PopRasterizerState(); }
public LevelScreen(IGameObjectsFactory gameObjectsFactory, IUserInterfaceFactory interfaceFactory, IMathFunctionsFactory functionsFactory, ICamera2D camera2D, IContentLoader contentLoader) { this.contentLoader = contentLoader; this.camera = camera2D; player = new Player(); this.objectsFactory = gameObjectsFactory; scene2d = new Scene2D(gameObjectsFactory, new GameplayFactory(gameObjectsFactory), interfaceFactory); this.functionsFactory = functionsFactory; }
public MenuScene(Microsoft.Xna.Framework.Game game) : base(game) { camera = new Camera2D(Game); //Game.Components.Add((IGameComponent)camera); screen = EntityFactory.CreateSprite("default"); MenuConfiguration menuConfiguration = Game.Content.Load<MenuConfiguration>("Menu.Config"); screen.LoadContent(menuConfiguration.AssetName); screen.Scale = menuConfiguration.Scale; }
public override void Initialize(Game game, SpriteBatch spriteBatch, ICamera2D camera) { Thrombus.Initialize(game, spriteBatch, camera); Thrombus.WorldPosition = new Vector2(StartPosition + Thrombus.CollisionRectangle.Width / 2f + 40f, -60); _textRenderer.Initialize(spriteBatch); Reactions.Add(PlayerAction.Shoot, Shoot); base.Initialize(game, spriteBatch, camera); }
/// <summary> /// Initializes a new instance of the <see cref="TransBox"/> class. /// </summary> /// <param name="owner">The <see cref="TransBoxManager"/>.</param> /// <param name="type">The <see cref="TransBoxType"/>.</param> /// <param name="spatial">The <see cref="ISpatial"/>.</param> TransBox(TransBoxManager owner, TransBoxType type, ISpatial spatial, ICamera2D camera) { _owner = owner; _camera = camera; _type = type; _spatial = spatial; _size = GetTransBoxSize(type); _position = GetPosition(); }
public void Initialize(Game game, SpriteBatch spriteBatch, ICamera2D camera) { if (Target == null) { throw new InvalidOperationException("You have to specify think cloud target before calling Initialize."); } _spriteBatch = spriteBatch; _camera = camera; Animation = Animation.FromMetadata(game.Content.Load<AnimationMetadata>(AssetName), game.Content); }
protected TiledGame() { loader = new ModuleLoader(); loader.Load(); this.stateManager = loader.GetStateManager(); this.spriteDrawer = loader.GetDrawer(); this.spriteFontDawer = loader.GetFontDrawer(); this.inputManager = loader.GetInputManager(); this.virtualScreen = loader.GetVirtualScreen(); this.camera = loader.GetCamera(); this.contentLoader = loader.GetContentLoader(); }
/// <summary> /// Initializes a new instance of the <see cref="MapScreenControl"/> class. /// </summary> public GrhAtlasView() { TilesetConfiguration = null; if (!DesignMode && LicenseManager.UsageMode != LicenseUsageMode.Runtime) return; _transBoxManager = new TransBoxManager(); _camera = new Camera2D(ClientSize.ToVector2()) { KeepInMap = false }; }
/// <summary> /// Handles when a key is pressed on a map. /// </summary> /// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param> /// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param> /// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param> protected override void MapContainer_KeyDown(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, KeyEventArgs e) { if (map != null) { // Save (Ctrl + Shift + S) if (e.KeyCode == Keys.S && e.Control && e.Shift) { MapHelper.SaveMapAs(map, false); return; } } base.MapContainer_KeyDown(sender, map, camera, e); }
public override void Initialize() { LoadingScreen.ScreenLoaded += OnScreenLoaded; _camera = new Camera2D(); _camera.Initialize(_screenManager.Game); _backgroundController = BackgroundController.FromMetadata( _screenManager.Game.Content.Load<BackgroundMetadata>(@"Backgrounds\Default"), _screenManager.Game.Content); _backgroundController.Initialize(_screenManager.Game, _screenManager.SpriteBatch, _camera); base.Initialize(); }
/// <summary> /// When overridden in the derived class, handles drawing to the buffer. /// </summary> /// <param name="rt">The <see cref="RenderTarget"/> to draw to.</param> /// <param name="sb">The <see cref="ISpriteBatch"/> to use to draw to the <paramref name="rt"/>. The derived class /// is required to handle making Begin()/End() calls on it.</param> /// <param name="camera">The <see cref="ICamera2D"/> to use when drawing.</param> /// <returns>True if the drawing was successful; false if there were any errors while drawing.</returns> protected override bool HandleDrawBuffer(RenderTarget rt, ISpriteBatch sb, ICamera2D camera) { // Draw the lights sb.Begin(BlendMode.Add, camera); foreach (var light in this) { if (camera.InView(light)) light.Draw(sb); } sb.End(); return true; }
public virtual void Initialize(Game game, SpriteBatch spriteBatch, ICamera2D camera) { if (Target == null) { throw new InvalidOperationException("You have to specify target before calling Initialize."); } SpriteBatch = spriteBatch; Camera = camera; if (!String.IsNullOrEmpty(AssetName)) { Content = AnimatedObject.FromMetadata(game.Content.Load<AnimatedObjectMetadata>(AssetName), game.Content); } }
/// <summary> /// Draws a TeleportEntity. /// </summary> /// <param name="sb"><see cref="ISpriteBatch"/> to draw to.</param> /// <param name="camera">The <see cref="ICamera2D"/> that describes the current view.</param> /// <param name="tele">TeleportEntity to draw.</param> public static void Draw(ISpriteBatch sb, ICamera2D camera, TeleportEntityBase tele) { // Draw the source rectangle Draw(sb, tele, _teleSourceColor); // Draw the destination rectangle and the arrow pointing to it only if the map is the same if (camera.Map != null && camera.Map.ID == tele.DestinationMap) { Draw(sb, tele.Destination, tele.Size, _teleDestColor); // Arrow var centerOffset = tele.Size / 2; RenderArrow.Draw(sb, tele.Position + centerOffset, tele.Destination + centerOffset, _arrowColor); } }
/// <summary> /// Draws an Entity. /// </summary> /// <param name="sb"><see cref="ISpriteBatch"/> to draw to.</param> /// <param name="camera">The <see cref="ICamera2D"/> that describes the current view.</param> /// <param name="entity">Entity to draw.</param> public static void Draw(ISpriteBatch sb, ICamera2D camera, Entity entity) { WallEntityBase wallEntity; TeleportEntity teleportEntity; // Check for a different entity type if ((wallEntity = entity as WallEntityBase) != null) Draw(sb, camera, wallEntity); else if ((teleportEntity = entity as TeleportEntity) != null) Draw(sb, camera, teleportEntity); else { // Draw a normal entity using the CollisionBox Draw(sb, entity, _entityColor); } }
/// <summary> /// Initializes a new instance of the <see cref="MapScreenControl"/> class. /// </summary> public MapScreenControl() { if (!DesignMode && LicenseManager.UsageMode != LicenseUsageMode.Runtime) return; _drawingManager = new DrawingManager(); _transBoxManager = new TransBoxManager(); _camera = new Camera2D(ClientSize.ToVector2()) { KeepInMap = true }; if (DrawingManager.LightManager.DefaultSprite == null) DrawingManager.LightManager.DefaultSprite = new Grh(GrhInfo.GetData("Effect", "light")); GlobalState.Instance.Map.SelectedObjsManager.SelectedChanged += SelectedObjsManager_SelectedChanged; lock (_instancesSync) { _instances.Add(this); } }
/// <summary> /// Draws the map borders. /// </summary> /// <param name="sb"><see cref="ISpriteBatch"/> to draw to.</param> /// <param name="map">Map to draw the borders for.</param> /// <param name="camera">Camera used to view the map.</param> public virtual void Draw(ISpriteBatch sb, IMap map, ICamera2D camera) { if (sb == null || sb.IsDisposed) return; if (map == null) return; if (camera == null) return; // Left border and corners if (camera.Min.X < 0) { var min = camera.Min; var max = new Vector2(Math.Min(0, camera.Max.X), camera.Max.Y); DrawBorder(sb, min, max); } // Right border and corners if (camera.Max.X > map.Width) { var min = new Vector2(Math.Max(camera.Min.X, map.Width), camera.Min.Y); var max = camera.Max; DrawBorder(sb, min, max); } // Top border if (camera.Min.Y < 0) { var min = new Vector2(Math.Max(camera.Min.X, 0), camera.Min.Y); var max = new Vector2(Math.Min(camera.Max.X, map.Width), Math.Min(camera.Max.Y, 0)); DrawBorder(sb, min, max); } // Bottom border if (camera.Max.Y > map.Height) { var min = new Vector2(Math.Max(camera.Min.X, 0), Math.Max(camera.Min.Y, map.Height)); var max = new Vector2(Math.Min(camera.Max.X, map.Width), camera.Max.Y); DrawBorder(sb, min, max); } }
/// <summary> /// When overridden in the derived class, handles drawing to the map after all of the map drawing finishes. /// </summary> /// <param name="map">The map the drawing is taking place on.</param> /// <param name="spriteBatch">The <see cref="ISpriteBatch"/> to draw to.</param> /// <param name="camera">The <see cref="ICamera2D"/> that describes the view of the map being drawn.</param> protected override void HandleDrawAfterMap(IDrawableMap map, ISpriteBatch spriteBatch, ICamera2D camera) { var msc = MapScreenControl.TryFindInstance(map); if (msc == null) return; var dm = msc.DrawingManager; if (dm == null) return; var lm = dm.LightManager; if (lm == null) return; var lightSprite = SystemSprites.Lightblub; var offset = lightSprite.Size / 2f; foreach (var light in lm) { lightSprite.Draw(spriteBatch, light.Center - offset); } }
/// <summary> /// Checks if in the object is in view of the specified <paramref name="camera"/>. /// </summary> /// <param name="camera">The <see cref="ICamera2D"/> to check if this object is in view of.</param> /// <returns> /// True if the object is in view of the camera, else False. /// </returns> public bool InView(ICamera2D camera) { return camera.InView(this); }
/// <summary> /// Gets the position for the Camera to focus on this Character. /// </summary> /// <param name="camera">The <see cref="ICamera2D"/> to get the position for.</param> /// <returns> /// Position for the Camera to focus on this Character. /// </returns> public Vector2 GetCameraPos(ICamera2D camera) { var pos = DrawPosition + (Size / 2.0f) - (camera.Size / 2.0f); return pos.Round(); }