public static void DrawHollowRect(this Batcher batcher, float x, float y, float width, float height, Color color, float thickness = 1) { var tl = new Vector2(x, y); var tr = new Vector2(x + width, y); var br = new Vector2(x + width, y + height); var bl = new Vector2(x, y + height); #if MG38 tl.Round(); tr.Round(); br.Round(); bl.Round(); #else tl = tl.Round(); tr = tr.Round(); br = br.Round(); bl = bl.Round(); #endif batcher.SetIgnoreRoundingDestinations(true); batcher.DrawLine(tl, tr, color, thickness); batcher.DrawLine(tr, br, color, thickness); batcher.DrawLine(br, bl, color, thickness); batcher.DrawLine(bl, tl, color, thickness); batcher.SetIgnoreRoundingDestinations(false); }
public static Point RoundToPoint(this Vector2 vec) { var roundedVec = vec; vec.Round(); return(new Point((int)roundedVec.X, (int)roundedVec.Y)); }
public bool MoveAndCollide(Vector2 direction, out Overlap overlap) { bool result = false; overlap = new Overlap(); direction = Vector2.Round(direction); if (direction == Vector2.Zero) { return(result); } if (Layout.Current.Grid.IsCollidingAtOffset(this, direction.X, 0f, out var overlapX)) { direction.X += overlapX.Depth.X; overlap = overlapX; result = true; } else if (Layout.Current.Grid.IsCollidingAtOffset(this, 0f, direction.Y, out var overlapY)) { direction.Y += overlapY.Depth.Y; overlap = overlapY; result = true; } BodyInfo.Position += direction; Layout.Current.Grid.Update(this); return(result); }
public void Arrange(Vector2 plane, Rectangle viewport) { this.Plane = plane; this.Viewport = viewport; this.ViewportCenter = Vector2.Round(this.Viewport.Center()); this.Center(); }
/// <summary> /// Initializes a new instance of the <see cref="EPPos" /> struct. /// </summary> /// <param name="start">The start.</param> /// <param name="end">The end.</param> public EPPos(Vector2 start, Vector2 end) { start = start.Round(3); end = end.Round(3); if (start.X < end.X) { Start = start; End = end; } else if (start.X > end.X) { Start = end; End = start; } else if (start.Y <= end.Y) { Start = start; End = end; } else { Start = end; End = start; } }
private void CheckKeyboard(GameTime gameTime) { KeyboardState keyState = Keyboard.GetState(); KeyboardState prevKeyState = GameState.Instance.GetPrevKeyboardState(); SetAnimation("idle"); Vector2 movement = new Vector2(0, 0); if (keyState.IsKeyDown(Keys.S)) { movement.Y += 1; } if (keyState.IsKeyDown(Keys.W)) { movement.Y -= 1; } if (keyState.IsKeyDown(Keys.A)) { this.horizontalFlip = false; movement.X -= 1; } if (keyState.IsKeyDown(Keys.D)) { this.horizontalFlip = true; movement.X += 1; } if (keyState.IsKeyDown(Keys.Down) && !prevKeyState.IsKeyDown(Keys.Down)) { SetAnimation("blob", true, true); } if (keyState.IsKeyDown(Keys.Up) && !prevKeyState.IsKeyDown(Keys.Up)) { SetAnimation("up", true, true); } if (keyState.IsKeyDown(Keys.Left) && !prevKeyState.IsKeyDown(Keys.Left)) { SetAnimation("left", true, true); } if (keyState.IsKeyDown(Keys.Right) && !prevKeyState.IsKeyDown(Keys.Right)) { SetAnimation("right", true, true); } if (movement.X != 0 && movement.Y != 0) { movement.Normalize(); } movement *= MOVE_SPEED; movement.Round(); this.Move(movement); }
public IEnumerator <object> Task() { var input = timeline.Overview.RootWidget.Input; while (true) { if (input.WasMouseReleased(1) || input.WasKeyPressed(Key.Mouse0DoubleClick)) { var pos = timeline.Overview.ContentWidget.LocalMousePosition(); var offset = pos - timeline.Grid.Size / 2; var maxScrollPos = Vector2.Max(Vector2.Zero, timeline.Grid.ContentSize - timeline.Grid.Size); timeline.Offset = Vector2.Clamp(offset, Vector2.Zero, maxScrollPos); Document.Current.History.DoTransaction(() => { var col = (input.MousePosition.X / (TimelineMetrics.ColWidth * timeline.Overview.ContentWidget.Scale.X)).Round(); SetCurrentColumn.Perform(col); }); } if (input.WasMousePressed()) { var originalMousePosition = input.MousePosition; var scrollPos = timeline.Offset; while (input.IsMousePressed()) { var mouseDelta = input.MousePosition - originalMousePosition; var scrollDelta = Vector2.Round(mouseDelta / timeline.Overview.ContentWidget.Scale); var maxScrollPos = Vector2.Max(Vector2.Zero, timeline.Grid.ContentSize - timeline.Grid.Size); timeline.Offset = Vector2.Clamp(scrollPos + scrollDelta, Vector2.Zero, maxScrollPos); yield return(null); } } yield return(null); } }
public static void DrawSpawn(MapSpawnValues spawn, ISpriteBatch spriteBatch, IDrawableMap map, Font font) { var spawnArea = spawn.SpawnArea; // Only draw if it does not cover the whole map if (!spawnArea.X.HasValue && !spawnArea.Y.HasValue && !spawnArea.Width.HasValue && !spawnArea.Height.HasValue) return; // Draw spawn area Vector2 cameraOffset = map.Camera.Min; Rectangle rect = spawnArea.ToRectangle(map); rect.X -= (int)cameraOffset.X; rect.Y -= (int)cameraOffset.Y; RenderRectangle.Draw(spriteBatch, rect, new Color(0, 255, 0, 75), new Color(0, 0, 0, 125), 2); // Draw name CharacterTemplate charTemp = CharacterTemplateManager.Instance[spawn.CharacterTemplateID]; if (charTemp != null) { string text = string.Format("{0}x {1} [{2}]", spawn.SpawnAmount, charTemp.TemplateTable.Name, spawn.CharacterTemplateID); Vector2 textPos = new Vector2(rect.X, rect.Y); textPos -= new Vector2(0, font.MeasureString(text).Y); textPos = textPos.Round(); spriteBatch.DrawStringShaded(font, text, textPos, Color.White, Color.Black); } }
public static Rectangle DrawString(this SpriteBatch sb, SpriteFont font, string txt, Vector2 position, Color color, Align align) { Vector2 txtSize = font.MeasureString(txt); Vector2 pos = position; switch (align) { case Align.MidLeft: pos.Y -= txtSize.Y * 0.5f; break; case Align.Center: pos.X -= txtSize.X * 0.5f; pos.Y -= txtSize.Y * 0.5f; break; case Align.MidRight: pos.X -= txtSize.X; pos.Y -= txtSize.Y * 0.5f; break; } pos.Round(); sb.DrawString(font, txt, pos, color); return(new Rectangle((int)pos.X, (int)pos.Y, (int)txtSize.X, (int)txtSize.Y)); }
public static void DrawSpawn(MapSpawnValues spawn, ISpriteBatch spriteBatch, IDrawableMap map, Font font) { var spawnArea = spawn.SpawnArea; // Only draw if it does not cover the whole map if (!spawnArea.X.HasValue && !spawnArea.Y.HasValue && !spawnArea.Width.HasValue && !spawnArea.Height.HasValue) { return; } // Draw spawn area Vector2 cameraOffset = map.Camera.Min; Rectangle rect = spawnArea.ToRectangle(map); rect.X -= (int)cameraOffset.X; rect.Y -= (int)cameraOffset.Y; RenderRectangle.Draw(spriteBatch, rect, new Color(0, 255, 0, 75), new Color(0, 0, 0, 125), 2); // Draw name CharacterTemplate charTemp = CharacterTemplateManager.Instance[spawn.CharacterTemplateID]; if (charTemp != null) { string text = string.Format("{0}x {1} [{2}]", spawn.SpawnAmount, charTemp.TemplateTable.Name, spawn.CharacterTemplateID); Vector2 textPos = new Vector2(rect.X, rect.Y); textPos -= new Vector2(0, font.MeasureString(text).Y); textPos = textPos.Round(); spriteBatch.DrawStringShaded(font, text, textPos, Color.White, Color.Black); } }
private void RenderAnswers( RendererParameters parameters, WindowTexture selectedAnswerWindowTexture, SpriteFont font, Matrix transformMatrix, IEnumerable <MessageTextAnswer> answers, Color shadowColor, Vector2 position) { answers = answers.ToArray(); int answerCount = answers.Count(); int totalAnswerPadding = ((answerCount - 1) * TextAdventure.Xna.Constants.MessageRenderer.AnswerHorizontalPadding); float lineWidth = answers.Sum(arg => arg.Size.X + (selectedAnswerWindowTexture.SpriteWidth * 2) + (TextAdventure.Xna.Constants.MessageRenderer.AnswerHorizontalTextPadding * 2)) + totalAnswerPadding; float lineHeight = answers.Max(arg => arg.Size.Y); position.X += (Window.AbsoluteClientRectangle.Width - lineWidth) / 2; foreach (MessageTextAnswer answer in answers) { var window = new BorderedWindow( new Rectangle( position.X.Round(), position.Y.Round(), (answer.Size.X + (selectedAnswerWindowTexture.SpriteWidth * 2) + (TextAdventure.Xna.Constants.MessageRenderer.AnswerHorizontalTextPadding * 2)).Round(), (lineHeight + (selectedAnswerWindowTexture.SpriteHeight * 2)).Round()), selectedAnswerWindowTexture.Padding); if (answer.Answer == _answerSelectionManager.SelectedAnswer) { _messageAnswerRenderer.Update( window.WindowRectangle, selectedAnswerWindowTexture.Padding, answer.SelectedAnswerBackgroundColor.ToXnaColor(), Alpha, Window.AbsoluteClientRectangle, transformMatrix); _messageAnswerRenderer.Render(parameters); } var textPosition = new Vector2( window.AbsoluteClientRectangle.X + ((window.AbsoluteClientRectangle.Width - answer.Size.X) / 2), window.AbsoluteClientRectangle.Y + ((window.AbsoluteClientRectangle.Height - lineHeight) / 2)); Color textColor = answer.Answer == _answerSelectionManager.SelectedAnswer ? answer.SelectedAnswerForegroundColor.ToXnaColor() : answer.UnselectedAnswerForegroundColor.ToXnaColor(); parameters.SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, new ScissoringRasterizerState(), null, transformMatrix); parameters.SpriteBatch.DrawStringWithShadow( font, answer.Text, textPosition.Round(), textColor * Alpha, shadowColor, Vector2.One); parameters.SpriteBatch.End(); position.X += window.WindowRectangle.Width + TextAdventure.Xna.Constants.MessageRenderer.AnswerHorizontalPadding; } }
public void Translate(Vector2f offset) { Vector2 spriteUpDirection = Matht.NormalAngleToVector(rotation); //Kierunek do góry sprite Vector2 spriteRightDirection = Matht.NormalAngleToVector(rotation + 90); //Kierunek do prawej sprite spriteUpDirection.y = -spriteUpDirection.y; // spriteRightDirection.y = -spriteRightDirection.y; //Trzeba to robić ze względu na to że y ma odwrotny kierunek w sfml: rośnie ku dołu spriteUpDirection.Round(5); spriteRightDirection.Round(5); if (offset.Y != 0) { //Console.WriteLine(-spriteUpDirection * ((Vector2)offset).y); position += -spriteUpDirection * ((Vector2)offset).y; } if (offset.X != 0) { //Console.WriteLine(spriteRightDirection * ((Vector2)offset).x); position += spriteRightDirection * ((Vector2)offset).x; } //Console.WriteLine(offset); }
public static void DrawCircle(SpriteBatch sprites, Color color, Vector2 pos, int radius) { pos = pos.Round(); for (float i = 0; i < Math.PI * 2; i += 1.0f / radius) { sprites.Draw(GameContent.Texture("pixel"), pos + new Vector2((float)Math.Sin(i) * radius, (float)Math.Cos(i) * radius), color); } }
public static void DrawLine(SpriteBatch sprites, Color color, Vector2 start, Vector2 end) { start = start.Round(); end = end.Round(); Vector2 line = end - start; float angle = (float)Math.Atan2(line.Y, line.X); sprites.Draw(GameContent.Texture("pixel"), new Rectangle((int)start.X, (int)start.Y, (int)line.Length(), 1), null, color, angle, new Vector2(0, 0), SpriteEffects.None, 0); }
// ------------------------------------------------------------------------------- // AddExploredSpace // ------------------------------------------------------------------------------- public void AddExploredSpace(string mapName, Vector2 pos) { pos = pos.Round(0); List <MapPing> floorData = this.GetFloorData(mapName); if (!floorData.Any(x => x.Position.x == pos.x && x.Position.y == pos.y)) { floorData.Add(new MapPing(pos, null)); } }
public static void DrawChatLines(SpriteBatch spriteBatch, SpriteFont font, IEnumerable<WrappedTextList.Line> messageLines, Vector2 textPos) { foreach (var line in messageLines) { if (line.ContainsPretext) { var splitIndex = line.Text.IndexOf('>'); if (splitIndex < 0) throw new ApplicationException("Pretext char not found"); var pretext = line.Text.Substring(0, splitIndex + 1); var properText = line.Text.Substring(splitIndex + 1); ModelRenderer.DrawBorderedText(spriteBatch, font, pretext, textPos.Round(), AW2.Game.PlayerMessage.PRETEXT_COLOR, 1, 1); var properPos = textPos + new Vector2(font.MeasureString(pretext).X, 0); ModelRenderer.DrawBorderedText(spriteBatch, font, properText, properPos.Round(), line.Color, 1, 1); } else ModelRenderer.DrawBorderedText(spriteBatch, font, line.Text, textPos.Round(), line.Color, 1, 1); textPos.Y += font.LineSpacing; } }
private Vector2 GetInput(float delta) { Vector2 inputVelocity = Vector2.Zero; if (!_sword.Swinging) { inputVelocity.x = Input.GetActionStrength("right") - Input.GetActionStrength("left"); inputVelocity.y = Input.GetActionStrength("down") - Input.GetActionStrength("up"); inputVelocity = inputVelocity.Normalized(); } if (inputVelocity == Vector2.Zero) { _isMoving = false; } else { _isMoving = true; if (inputVelocity.Abs() != Vector2.One) { _playerDirection = inputVelocity.Round(); } } if (_isMoving) { _aTreePlayback.Travel("Running"); _aTree.Set("parameters/AnimationNodeStateMachine/Idle/blend_position", inputVelocity); _aTree.Set("parameters/AnimationNodeStateMachine/Running/blend_position", inputVelocity); _currentSpeed += _acceleration * delta; if (_currentSpeed > _maxSpeed) { _currentSpeed = _maxSpeed; } float animationSpeed = 1 + 2 * (_currentSpeed / _maxSpeed); _aTree.Set("parameters/TimeScale/scale", animationSpeed); return(_velocity.MoveToward(inputVelocity * _currentSpeed, _acceleration * delta)); } _aTreePlayback.Travel("Idle"); _aTree.Set("parameter/playback", "Idle"); _currentSpeed = 0; return(_velocity.MoveToward(Vector2.Zero, _friction * delta)); }
public void CalculateVectors(float offsetX, float offsetY) { topLeft.Set(rect.xMin + offsetX, rect.yMax + offsetY); topRight.Set(rect.xMax + offsetX, rect.yMax + offsetY); bottomRight.Set(rect.xMax + offsetX, rect.yMin + offsetY); bottomLeft.Set(rect.xMin + offsetX, rect.yMin + offsetY); topLeft = topLeft.Round(); topRight = topRight.Round(); bottomRight = bottomRight.Round(); bottomLeft = bottomLeft.Round(); }
public static void DrawDottedCircle(SpriteBatch sprites, Color color, Vector2 pos, int radius, int sparsity) { pos = pos.Round(); for (float i = 0; i < (Math.PI * 2); i += (1.0f / radius) * sparsity) { if (i + (1.0f / radius) * sparsity < (Math.PI * 2)) { sprites.Draw(GameContent.Texture("pixel"), pos + new Vector2((float)Math.Sin(i) * radius, (float)Math.Cos(i) * radius), color); } } }
/// <summary> /// Draws a string with shading. /// </summary> /// <param name="spriteBatch"><see cref="ISpriteBatch"/> to use to draw.</param> /// <param name="font"><see cref="Font"/> to draw the string with.</param> /// <param name="text">The string to draw.</param> /// <param name="position">The position of the top-left corner of the string to draw.</param> /// <param name="fontColor">The font color.</param> /// <param name="borderColor">The shading color.</param> public static void DrawStringShaded(this ISpriteBatch spriteBatch, Font font, string text, Vector2 position, Color fontColor, Color borderColor) { position = position.Round(); spriteBatch.DrawString(font, text, position - new Vector2(0, 1), borderColor); spriteBatch.DrawString(font, text, position - new Vector2(1, 0), borderColor); spriteBatch.DrawString(font, text, position + new Vector2(0, 1), borderColor); spriteBatch.DrawString(font, text, position + new Vector2(1, 0), borderColor); spriteBatch.DrawString(font, text, position, fontColor); }
internal void Internal_GetMousePosition(out Vector2 resultAsRef) { resultAsRef = Vector2.Zero; if (Windows.GameWin != null && Windows.GameWin.ContainsFocus) { var win = Windows.GameWin.Root; if (win != null) { resultAsRef = Vector2.Round(Windows.GameWin.Viewport.PointFromWindow(win.MousePosition)); } } }
public void UpdateWithSpritePos(Vector2 spritePos) { SpritePos = spritePos; Index = CellIndex.FromSpritePos(spritePos); TopLeft = new Vector2(Index.X * 8, Index.Y * 8); CenterPos = TopLeft + Vector2s.Four; _isInCenter = CenterPos == spritePos.Round(); handleWrapping(); }
public virtual void update(double dt) { step = false; if (!moving) { animation.update(dt / 2f); // slow version of the run animation while idle } else if (moving && move == Vector2.Zero) { move = moves.Dequeue(); // get next queued move setDirection(getDirection(move)); } // work on current move if (move != Vector2.Zero) { animation.update(dt); float proposed = (float)dt * RUN_SPEED; if (move.X > 0) { float trueMove = Math.Min(move.X, proposed); move.X -= trueMove; location.X += trueMove; } else if (move.X < 0) { proposed *= -1; float trueMove = Math.Max(move.X, proposed); move.X -= trueMove; location.X += trueMove; } if (move.Y > 0) { float trueMove = Math.Min(move.Y, proposed); move.Y -= trueMove; location.Y += trueMove; } else if (move.Y < 0) { proposed *= -1; float trueMove = Math.Max(move.Y, proposed); move.Y -= trueMove; location.Y += trueMove; } if (!moving) // finished with this move { location = Vector2.Round(location); step = true; } } }
/// <summary> /// Prepares the graphics device for drawing sprites with specified blending, sorting, and render state options, /// and a global transform matrix. /// </summary> /// <param name="blendMode">Blending options to use when rendering.</param> /// <param name="position">The top-left corner of the view area.</param> /// <param name="size">The size of the view area.</param> /// <param name="rotation">The amount to rotation the view in degrees.</param> public void Begin(BlendMode blendMode, Vector2 position, Vector2 size, float rotation) { position = position.Round(); size = size.Round(); _view.Reset(new FloatRect(position.X, position.Y, size.X, size.Y)); _view.Rotate(rotation); _rt.SetView(_view); _renderState.BlendMode = blendMode; _isStarted = true; }
public void DrawText(string text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, bool cameraTransform = false) { beginSpriteBatch(); if (cameraTransform) { translatePosition(ref position); updateScale(ref scale); } float fontSize; SpriteFont spriteFont = Font.GetBestSizeSpriteFont(Font.DefaultSize * Math.Abs(scale.Y), out fontSize); SpriteEffects spriteEffects = getSpriteEffectsFromScale(ref scale); spriteBatch.DrawString(spriteFont, text, position.Round(), color, rotation, origin.Round(), Vector2.One, spriteEffects, 0.0f); }
internal void Internal_ScreenToGameViewport(ref Vector2 pos) { if (Windows.GameWin != null && Windows.GameWin.ContainsFocus) { var win = Windows.GameWin.Root; if (win != null && win.RootWindow is WindowRootControl root && root.Window.IsFocused) { pos = Vector2.Round(Windows.GameWin.Viewport.PointFromWindow(root.ScreenToClient(pos))); } else { pos = Vector2.Minimum; } }
public void RoundTest() { const int max = 1000; var r = new Random(578); for (var i = 0; i < 30; i++) { var v = new Vector2(r.NextFloat() * max, r.NextFloat() * max); var c = v.Round(); Assert.AreEqual(Math.Round(v.X), c.X); Assert.AreEqual(Math.Round(v.Y), c.Y); } }
public override void Update() { RetrieveStopperPoints(); if (Target != null) { var targetPosition = Target.Position - Vector2.UnitY * OffsetY; var targetDistance = GameMath.Distance(Camera.Position, targetPosition); var targetVector = (Camera.Position - targetPosition).GetSafeNormalize(); if (targetDistance > MaxDistance && MaxDistanceEnabled) { _position = (targetPosition + targetVector * MaxDistance); targetDistance = MaxDistance; } if (targetDistance > PullbackDistance) { var distanceToMax = targetDistance - PullbackDistance; distanceToMax *= (float)Math.Pow(PullbackMultiplier, TimeKeeper.GlobalTime()); _position = targetPosition + targetVector * (distanceToMax + PullbackDistance); } } // Restricting the camera. var adjustedTopLeftPoint = _topLeftPoint + Camera.Size / 2; var adjustedBottomRightPoint = _bottomRightPoint - Camera.Size / 2; if (_position.X < adjustedTopLeftPoint.X) { _position.X = adjustedTopLeftPoint.X; } if (_position.Y < adjustedTopLeftPoint.Y) { _position.Y = adjustedTopLeftPoint.Y; } if (_position.X > adjustedBottomRightPoint.X) { _position.X = adjustedBottomRightPoint.X; } if (_position.Y > adjustedBottomRightPoint.Y) { _position.Y = adjustedBottomRightPoint.Y; } // Restricting the camera. Camera.Position = _position.Round(); }
public static void DrawCircleOptimized(SpriteBatch sprites, Camera camera, Color color, Vector2 pos, int radius) { pos = pos.Round(); for (float i = 0; i < Math.PI * 2; i += 1.0f / radius) { Vector2 pixelPos = pos + new Vector2((float)Math.Sin(i) * radius, (float)Math.Cos(i) * radius); Rectangle frustum = new Rectangle((int)(camera.Position.X - camera.Size.X / 2), (int)(camera.Position.Y - camera.Size.Y / 2), (int)camera.Size.X, (int)camera.Size.Y); if (frustum.Contains(new Point((int)pixelPos.X, (int)pixelPos.Y))) { sprites.Draw(GameContent.Texture("pixel"), pixelPos, color); } } }
public void RoundVector2_ByValue_ByRef_CorrectResults() { Vector2 source = new Vector2(Random10(), Random10()); Vector2 result = source.Round(); Assert.Equal(Math.Round(source.X), result.X); Assert.Equal(Math.Round(source.Y), result.Y); result = source; MathHelper.Round(ref result); Assert.Equal(Math.Round(source.X), result.X); Assert.Equal(Math.Round(source.Y), result.Y); }
public static void DrawHollowRect(this Batcher batcher, float x, float y, float width, float height, Color color, float thickness = 1) { var tl = Vector2.Round(new Vector2(x, y)); var tr = Vector2.Round(new Vector2(x + width, y)); var br = Vector2.Round(new Vector2(x + width, y + height)); var bl = Vector2.Round(new Vector2(x, y + height)); batcher.SetIgnoreRoundingDestinations(true); batcher.DrawLine(tl, tr, color, thickness); batcher.DrawLine(tr, br, color, thickness); batcher.DrawLine(br, bl, color, thickness); batcher.DrawLine(bl, tl, color, thickness); batcher.SetIgnoreRoundingDestinations(false); }
public void Draw(GameTime gameTime, SpriteBatch spriteBatch) { if (!IsVisible) { return; } Vector2 pos = Parant.Position + GameControl.Hud.Camera; if (IntPosition) { pos = pos.Round(); } spriteBatch.Draw(Sprite, pos, gameTime, Color, Sprite.TextureOrigin, MathHelper.PiOver2 + Parant.Heading, 1, 0.5f + AdditionalLayerDepth + depthVarriation); }
private void DrawArenaInfo(Vector2 view, SpriteBatch spriteBatch) { var infoDisplayPos = MenuComponent.Pos - view + new Vector2(595, 220); var currentPos = infoDisplayPos; var lineHeight = new Vector2(0, 20); var infoWidth = new Vector2(320, 0); var arenaName = MenuEngine.Game.SelectedArenaName; var arenaInfo = ((AW2.Game.Arena)MenuEngine.Game.DataEngine.GetTypeTemplate((CanonicalString)arenaName)).Info; var content = MenuEngine.Game.Content; string previewName = content.Exists<Texture2D>(arenaInfo.PreviewName) ? arenaInfo.PreviewName : "no_preview"; var previewTexture = content.Load<Texture2D>(previewName); spriteBatch.DrawString(Content.FontBig, "Arena info", currentPos.Round(), Color.White); currentPos += new Vector2(0, 50); spriteBatch.DrawString(Content.FontSmall, "Current arena:", currentPos.Round(), Color.White); spriteBatch.DrawString(Content.FontSmall, arenaName, (currentPos + new Vector2(Content.FontSmall.MeasureString("Current arena: ").X, 0)).Round(), Color.GreenYellow); if (IsArenaSelectable) spriteBatch.DrawString(Content.FontSmall, "Press Enter to change.", (currentPos + infoWidth + new Vector2(10, 0)).Round(), new Color(218, 159, 33)); currentPos += new Vector2(0, Content.FontSmall.LineSpacing); spriteBatch.Draw(previewTexture, currentPos, null, Color.White, 0, new Vector2(0, 0), 0.6f, SpriteEffects.None, 0); }
private void RenderWords( RendererParameters parameters, SpriteFont font, Matrix transformMatrix, int lineIndex, IList<MessageTextWord> words, Color shadowColor, ref Vector2 position, ref Color textColor) { parameters.SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, new ScissoringRasterizerState(), null, transformMatrix); MessageTextAlignment alignment = _formatter.GetAlignmentByLine(lineIndex); Vector2 lineSize = _formatter.GetLineSizeByLine(lineIndex); if (alignment == MessageTextAlignment.Center) { position.X += (Window.AbsoluteClientRectangle.Width - lineSize.X) / 2; } for (int wordIndex = 0; wordIndex < words.Count; wordIndex++) { MessageTextWord word = words[wordIndex]; Engine.Common.Color color; if (_formatter.TryGetColorByWordCoordinate(new Coordinate(wordIndex, lineIndex), out color)) { textColor = color.ToXnaColor() * Alpha; } if (word.PrependSpace) { position.X += _formatter.SpaceWord.Size.X; } parameters.SpriteBatch.DrawStringWithShadow(font, word.Text, position.Round(), textColor, shadowColor, Vector2.One); position.X += word.Size.X; } position.X = Window.AbsoluteClientRectangle.X; position.Y += lineSize.Y; parameters.SpriteBatch.End(); }
private void RenderAnswers( RendererParameters parameters, WindowTexture selectedAnswerWindowTexture, SpriteFont font, Matrix transformMatrix, IEnumerable<MessageTextAnswer> answers, Color shadowColor, Vector2 position) { answers = answers.ToArray(); int answerCount = answers.Count(); int totalAnswerPadding = ((answerCount - 1) * TextAdventure.Xna.Constants.MessageRenderer.AnswerHorizontalPadding); float lineWidth = answers.Sum(arg => arg.Size.X + (selectedAnswerWindowTexture.SpriteWidth * 2) + (TextAdventure.Xna.Constants.MessageRenderer.AnswerHorizontalTextPadding * 2)) + totalAnswerPadding; float lineHeight = answers.Max(arg => arg.Size.Y); position.X += (Window.AbsoluteClientRectangle.Width - lineWidth) / 2; foreach (MessageTextAnswer answer in answers) { var window = new BorderedWindow( new Rectangle( position.X.Round(), position.Y.Round(), (answer.Size.X + (selectedAnswerWindowTexture.SpriteWidth * 2) + (TextAdventure.Xna.Constants.MessageRenderer.AnswerHorizontalTextPadding * 2)).Round(), (lineHeight + (selectedAnswerWindowTexture.SpriteHeight * 2)).Round()), selectedAnswerWindowTexture.Padding); if (answer.Answer == _answerSelectionManager.SelectedAnswer) { _messageAnswerRenderer.Update( window.WindowRectangle, selectedAnswerWindowTexture.Padding, answer.SelectedAnswerBackgroundColor.ToXnaColor(), Alpha, Window.AbsoluteClientRectangle, transformMatrix); _messageAnswerRenderer.Render(parameters); } var textPosition = new Vector2( window.AbsoluteClientRectangle.X + ((window.AbsoluteClientRectangle.Width - answer.Size.X) / 2), window.AbsoluteClientRectangle.Y + ((window.AbsoluteClientRectangle.Height - lineHeight) / 2)); Color textColor = answer.Answer == _answerSelectionManager.SelectedAnswer ? answer.SelectedAnswerForegroundColor.ToXnaColor() : answer.UnselectedAnswerForegroundColor.ToXnaColor(); parameters.SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, new ScissoringRasterizerState(), null, transformMatrix); parameters.SpriteBatch.DrawStringWithShadow( font, answer.Text, textPosition.Round(), textColor * Alpha, shadowColor, Vector2.One); parameters.SpriteBatch.End(); position.X += window.WindowRectangle.Width + TextAdventure.Xna.Constants.MessageRenderer.AnswerHorizontalPadding; } }
protected override void DrawContent(SpriteBatch spriteBatch) { var messageY = SHADOW_THICKNESS; foreach (var item in Messages.Take(VISIBLE_LINES)) { float alpha = GetMessageAlpha(item); if (alpha == 0) continue; var preTextSize = _chatBoxFont.MeasureString(item.Message.PreText); var textSize = _chatBoxFont.MeasureString(item.Message.Text); var preTextPos = new Vector2((Dimensions.X - textSize.X - preTextSize.X) / 2, messageY); var textPos = preTextPos + new Vector2(preTextSize.X, 0); ModelRenderer.DrawBorderedText(spriteBatch, _chatBoxFont, item.Message.PreText, preTextPos.Round(), PlayerMessage.PRETEXT_COLOR, alpha, SHADOW_THICKNESS); ModelRenderer.DrawBorderedText(spriteBatch, _chatBoxFont, item.Message.Text, textPos.Round(), item.Message.TextColor, alpha, SHADOW_THICKNESS); messageY += _chatBoxFont.LineSpacing; } }
private Color DrawHealthPercentage(SpriteBatch spriteBatch, float relativeHealth, float alpha) { var halfColor = Color.Multiply(Color.White, alpha * 1f); var halfBlackColor = Color.Multiply(Color.Black, alpha * 0.6f); var healthText = ((int)Math.Ceiling(relativeHealth * 100)).ToString() + "%"; var textSize = _healthFont.MeasureString(healthText); var textPos = new Vector2((Dimensions.X - textSize.X) / 2, (_barBackgroundTexture.Height / 2) - (textSize.Y / 2) + 1); spriteBatch.DrawString(_healthFont, healthText, textPos.Round() - Vector2.One, halfBlackColor); spriteBatch.DrawString(_healthFont, healthText, textPos.Round() + new Vector2(1, -1), halfBlackColor); spriteBatch.DrawString(_healthFont, healthText, textPos.Round() + Vector2.One, halfBlackColor); spriteBatch.DrawString(_healthFont, healthText, textPos.Round() + new Vector2(-1, 1), halfBlackColor); spriteBatch.DrawString(_healthFont, healthText, textPos.Round(), halfColor); return halfColor; }
public void Draw(SpriteBatch spriteBatch, Vector2 offset) { Vector2 destination = Position.Round().ToVector2() - offset.Round(); spriteBatch.Draw(CurrentFrame, destination, null, Color.White, Angle, Origin.ToVector2(), 1f, SpriteEffects.None, 1f); spriteBatch.Draw(GameSession.Current.Pixel, new Rectangle((int)destination.X + BoundingBox.X, (int)destination.Y + BoundingBox.Y, BoundingBox.Width, BoundingBox.Height), Color.Lime * 0.3f); }
static void adjustWorldPosition( Camera camera ) { _mouseWorldPos = Vector2.Transform( ScreenPosition, Matrix.Invert( camera.Matrix ) ) ; _mouseWorldPos = _mouseWorldPos.Round( ) ; }
public void Update(GameTime gameTime) { if (map == null) return; oldkstate = kstate; oldmstate = mstate; kstate = Keyboard.GetState(); mstate = Mouse.GetState(); int mwheeldelta = mstate.ScrollWheelValue - oldmstate.ScrollWheelValue; if (mwheeldelta > 0) { float zoom = (float)Math.Round(camera.Scale * 10) * 10.0f + 10.0f; MainWindow.Instance.zoomCombo.Text = zoom.ToString() + "%"; camera.Scale = zoom / 100.0f; } if (mwheeldelta < 0 ) { float zoom = (float)Math.Round(camera.Scale * 10) * 10.0f - 10.0f; if (zoom <= 0.0f) return; MainWindow.Instance.zoomCombo.Text = zoom.ToString() + "%"; camera.Scale = zoom / 100.0f; } //Camera movement float delta; if (kstate.IsKeyDown(Keys.LeftShift)) delta = Preferences.Instance.CameraFastSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds; else delta = Preferences.Instance.CameraSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds; if (kstate.IsKeyDown(Keys.W) && kstate.IsKeyUp(Keys.LeftControl)) camera.Position += (new Vector2(0, -delta)); if (kstate.IsKeyDown(Keys.S) && kstate.IsKeyUp(Keys.LeftControl)) camera.Position += (new Vector2(0, +delta)); if (kstate.IsKeyDown(Keys.A) && kstate.IsKeyUp(Keys.LeftControl)) camera.Position += (new Vector2(-delta, 0)); if (kstate.IsKeyDown(Keys.D) && kstate.IsKeyUp(Keys.LeftControl)) camera.Position += (new Vector2(+delta, 0)); if (kstate.IsKeyDown(Keys.Subtract)) { float zoom = (float)(camera.Scale * 0.995); MainWindow.Instance.zoomCombo.Text = (zoom * 100).ToString("###0.0") + "%"; camera.Scale = zoom; } if (kstate.IsKeyDown(Keys.Add)) { float zoom = (float)(camera.Scale * 1.005); MainWindow.Instance.zoomCombo.Text = (zoom * 100).ToString("###0.0") + "%"; camera.Scale = zoom; } //get mouse world position considering the ScrollSpeed of the current layer Vector2 maincameraposition = camera.Position; if (SelectedLayer != null) camera.Position *= SelectedLayer.ScrollSpeed; mouseworldpos = Vector2.Transform(new Vector2(mstate.X, mstate.Y), Matrix.Invert(camera.matrix)); mouseworldpos = mouseworldpos.Round(); camera.Position = maincameraposition; if (state == EditorState.idle) { //get item under mouse cursor Tile item = getItemAtPos(mouseworldpos); if (item != null) { item.onMouseOver(mouseworldpos); if (kstate.IsKeyDown(Keys.LeftControl)) MainWindow.Instance.drawingBox.Cursor = cursorDup; } if (item != lastTile && lastTile != null) lastTile.onMouseOut(); lastTile = item; //LEFT MOUSE BUTTON CLICK if ((mstate.LeftButton == ButtonState.Pressed && oldmstate.LeftButton == ButtonState.Released) || (kstate.IsKeyDown(Keys.D1) && oldkstate.IsKeyUp(Keys.D1))) { if (item != null) item.onMouseButtonDown(mouseworldpos); if (kstate.IsKeyDown(Keys.LeftControl) && item != null) { if (!SelectedTiles.Contains(item)) selectTile(item); beginCommand("Add Item(s)"); List<Tile> selecteditemscopy = new List<Tile>(); foreach (Tile selitem in SelectedTiles) { Tile i2 = (Tile)selitem.clone(); selecteditemscopy.Add(i2); } foreach (Tile selitem in selecteditemscopy) { selitem.Name = selitem.getNamePrefix() + map.getNextItemNumber(); addItem(selitem); } selectTile(selecteditemscopy[0]); updateTreeView(); for (int i = 1; i < selecteditemscopy.Count; i++) SelectedTiles.Add(selecteditemscopy[i]); startMoving(); } else if (kstate.IsKeyDown(Keys.LeftShift) && item != null) { if (SelectedTiles.Contains(item)) SelectedTiles.Remove(item); else SelectedTiles.Add(item); } else if (SelectedTiles.Contains(item)) { beginCommand("Change Item(s)"); startMoving(); } else if (!SelectedTiles.Contains(item)) { selectTile(item); if (item != null) { beginCommand("Change Item(s)"); startMoving(); } else { grabbedpoint = mouseworldpos; selectionrectangle = Rectangle.Empty; state = EditorState.selecting; } } } //MIDDLE MOUSE BUTTON CLICK if ((mstate.MiddleButton == ButtonState.Pressed && oldmstate.MiddleButton == ButtonState.Released) || (kstate.IsKeyDown(Keys.D2) && oldkstate.IsKeyUp(Keys.D2))) { if (item != null) item.onMouseOut(); if (kstate.IsKeyDown(Keys.LeftControl)) { grabbedpoint = new Vector2(mstate.X, mstate.Y); initialcampos = camera.Position; state = EditorState.cameramoving; MainWindow.Instance.drawingBox.Cursor = Forms.Cursors.SizeAll; } else { if (SelectedTiles.Count > 0) { grabbedpoint = mouseworldpos - SelectedTiles[0].pPosition; //save the initial rotation for each item initialrot.Clear(); foreach (Tile selitem in SelectedTiles) { initialrot.Add(selitem.Rotation); } state = EditorState.rotating; MainWindow.Instance.drawingBox.Cursor = cursorRot; beginCommand("Rotate Item(s)"); } } } //RIGHT MOUSE BUTTON CLICK if ((mstate.RightButton == ButtonState.Pressed && oldmstate.RightButton == ButtonState.Released) || (kstate.IsKeyDown(Keys.D3) && oldkstate.IsKeyUp(Keys.D3))) { if (item != null) item.onMouseOut(); if (SelectedTiles.Count > 0) { grabbedpoint = mouseworldpos - SelectedTiles[0].pPosition; //save the initial scale for each item initialscale.Clear(); foreach (Tile selitem in SelectedTiles) { initialscale.Add(selitem.Scale); } state = EditorState.scaling; MainWindow.Instance.drawingBox.Cursor = cursorScale; beginCommand("Scale Item(s)"); } } } if (state == EditorState.moving) { int i = 0; foreach (Tile selitem in SelectedTiles) { newPosition = initialpos[i] + mouseworldpos - grabbedpoint; if (Preferences.Instance.SnapToGrid || kstate.IsKeyDown(Keys.G)) newPosition = snapToGrid(newPosition); drawSnappedPoint = false; selitem.pPosition = newPosition; i++; } MainWindow.Instance.propertyGrid1.Refresh(); if ((mstate.LeftButton == ButtonState.Released && oldmstate.LeftButton == ButtonState.Pressed) || (kstate.IsKeyUp(Keys.D1) && oldkstate.IsKeyDown(Keys.D1))) { foreach (Tile selitem in SelectedTiles) selitem.onMouseButtonUp(mouseworldpos); state = EditorState.idle; MainWindow.Instance.drawingBox.Cursor = Forms.Cursors.Default; if (mouseworldpos != grabbedpoint) endCommand(); else abortCommand(); } } if (state == EditorState.rotating) { Vector2 newpos = mouseworldpos - SelectedTiles[0].pPosition; float deltatheta = (float)Math.Atan2(grabbedpoint.Y, grabbedpoint.X) - (float)Math.Atan2(newpos.Y, newpos.X); int i = 0; foreach (Tile selitem in SelectedTiles) { selitem.pRotation = initialrot[i] - deltatheta; if (kstate.IsKeyDown(Keys.LeftControl)) { selitem.pRotation = ((float)Math.Round(selitem.pRotation / MathHelper.PiOver4) * MathHelper.PiOver4); } i++; } MainWindow.Instance.propertyGrid1.Refresh(); if ((mstate.MiddleButton == ButtonState.Released && oldmstate.MiddleButton == ButtonState.Pressed) || (kstate.IsKeyUp(Keys.D2) && oldkstate.IsKeyDown(Keys.D2))) { state = EditorState.idle; MainWindow.Instance.drawingBox.Cursor = Forms.Cursors.Default; endCommand(); } } if (state == EditorState.scaling) { Vector2 newdistance = mouseworldpos - SelectedTiles[0].pPosition; float factor = newdistance.Length() / grabbedpoint.Length(); int i = 0; foreach (Tile selitem in SelectedTiles) { Vector2 newscale = initialscale[i]; if (!kstate.IsKeyDown(Keys.Y)) newscale.X = initialscale[i].X * (((factor - 1.0f) * 0.5f) + 1.0f); if (!kstate.IsKeyDown(Keys.X)) newscale.Y = initialscale[i].Y * (((factor - 1.0f) * 0.5f) + 1.0f); selitem.pScale = (newscale); if (kstate.IsKeyDown(Keys.LeftControl)) { Vector2 scale; scale.X = (float)Math.Round(selitem.pScale.X * 10) / 10; scale.Y = (float)Math.Round(selitem.pScale.Y * 10) / 10; selitem.pScale = (scale); } i++; } MainWindow.Instance.propertyGrid1.Refresh(); if ((mstate.RightButton == ButtonState.Released && oldmstate.RightButton == ButtonState.Pressed) || (kstate.IsKeyUp(Keys.D3) && oldkstate.IsKeyDown(Keys.D3))) { state = EditorState.idle; MainWindow.Instance.drawingBox.Cursor = Forms.Cursors.Default; endCommand(); } } if (state == EditorState.cameramoving) { Vector2 newpos = new Vector2(mstate.X, mstate.Y); Vector2 distance = (newpos - grabbedpoint) / camera.Scale; if (distance.Length() > 0) { camera.Position = initialcampos - distance; } if (mstate.MiddleButton == ButtonState.Released) { state = EditorState.idle; MainWindow.Instance.drawingBox.Cursor = Forms.Cursors.Default; } } if (state == EditorState.selecting) { if (SelectedLayer == null) return; Vector2 distance = mouseworldpos - grabbedpoint; if (distance.Length() > 0) { SelectedTiles.Clear(); selectionrectangle = Extensions.RectangleFromVectors(grabbedpoint, mouseworldpos); foreach (Tile i in SelectedLayer.Tiles) { if (i.Visible && selectionrectangle.Contains((int)i.pPosition.X, (int)i.pPosition.Y)) SelectedTiles.Add(i); } updateTreeViewSelection(); } if (mstate.LeftButton == ButtonState.Released) { state = EditorState.idle; MainWindow.Instance.drawingBox.Cursor = Forms.Cursors.Default; } } if (state == EditorState.brush) { if (Preferences.Instance.SnapToGrid || kstate.IsKeyDown(Keys.G)) { mouseworldpos = snapToGrid(mouseworldpos); } if (mstate.RightButton == ButtonState.Pressed && oldmstate.RightButton == ButtonState.Released) state = EditorState.idle; if (mstate.LeftButton == ButtonState.Pressed && oldmstate.LeftButton == ButtonState.Released) paintTextureBrush(true); } }
private Vector2 GetCustomAlignment() { if (_player.Ship == null) return Vector2.Zero; // Note: Screen Y axis points down and game Y axis points up. var newCustomAlignment = new Vector2(0, 40) + (_player.Ship.Pos + _player.Ship.DrawPosOffset - Viewport.CurrentLookAt).MirrorY(); var newCustomAlignmentPoint = newCustomAlignment.Round().ToPoint(); if (!_previousCustomAlignment.HasValue || !_customAlignmentDampBox.Contains(newCustomAlignmentPoint)) { _customAlignmentDampBox = _customAlignmentDampBox.MoveToContain(newCustomAlignmentPoint); _previousCustomAlignment = newCustomAlignment; return newCustomAlignment; } return _previousCustomAlignment.Value; }
public void update(GameTime gt) { if (level == null) return; oldkstate = kstate; oldmstate = mstate; kstate = Keyboard.GetState(); mstate = Mouse.GetState(); int mwheeldelta = mstate.ScrollWheelValue - oldmstate.ScrollWheelValue; if (mwheeldelta > 0 /* && kstate.IsKeyDown(Keys.LeftControl)*/) { float zoom = (float)Math.Round(camera.Scale * 10) * 10.0f + 10.0f; MainForm.Instance.zoomcombo.Text = zoom.ToString() + "%"; camera.Scale = zoom / 100.0f; } if (mwheeldelta < 0 /* && kstate.IsKeyDown(Keys.LeftControl)*/) { float zoom = (float)Math.Round(camera.Scale * 10) * 10.0f - 10.0f; if (zoom <= 0.0f) return; MainForm.Instance.zoomcombo.Text = zoom.ToString() + "%"; camera.Scale = zoom / 100.0f; } //Camera movement float delta; if (kstate.IsKeyDown(Keys.LeftShift)) delta = Constants.Instance.CameraFastSpeed * (float)gt.ElapsedGameTime.TotalSeconds; else delta = Constants.Instance.CameraSpeed * (float)gt.ElapsedGameTime.TotalSeconds; if (kstate.IsKeyDown(Keys.W) && kstate.IsKeyUp(Keys.LeftControl)) camera.Position += (new Vector2(0, -delta)); if (kstate.IsKeyDown(Keys.S) && kstate.IsKeyUp(Keys.LeftControl)) camera.Position += (new Vector2(0, +delta)); if (kstate.IsKeyDown(Keys.A) && kstate.IsKeyUp(Keys.LeftControl)) camera.Position += (new Vector2(-delta, 0)); if (kstate.IsKeyDown(Keys.D) && kstate.IsKeyUp(Keys.LeftControl)) camera.Position += (new Vector2(+delta, 0)); if (kstate.IsKeyDown(Keys.Subtract)) { float zoom = (float)(camera.Scale * 0.995); MainForm.Instance.zoomcombo.Text = (zoom * 100).ToString("###0.0") + "%"; camera.Scale = zoom; } if (kstate.IsKeyDown(Keys.Add)) { float zoom = (float)(camera.Scale * 1.005); MainForm.Instance.zoomcombo.Text = (zoom * 100).ToString("###0.0") + "%"; camera.Scale = zoom; } //get mouse world position considering the ScrollSpeed of the current layer Vector2 maincameraposition = camera.Position; if (SelectedLayer != null) camera.Position *= SelectedLayer.ScrollSpeed; mouseworldpos = Vector2.Transform(new Vector2(mstate.X, mstate.Y), Matrix.Invert(camera.matrix)); mouseworldpos = mouseworldpos.Round(); MainForm.Instance.toolStripStatusLabel3.Text = "Mouse: (" + mouseworldpos.X + ", " + mouseworldpos.Y + ")"; camera.Position = maincameraposition; if (state == EditorState.idle) { //get item under mouse cursor Item item = getItemAtPos(mouseworldpos); if (item != null) { MainForm.Instance.toolStripStatusLabel1.Text = item.Name; item.onMouseOver(mouseworldpos); if (kstate.IsKeyDown(Keys.LeftControl)) MainForm.Instance.pictureBox1.Cursor = cursorDup; } else { MainForm.Instance.toolStripStatusLabel1.Text = ""; } if (item != lastitem && lastitem != null) lastitem.onMouseOut(); lastitem = item; //LEFT MOUSE BUTTON CLICK if ((mstate.LeftButton == ButtonState.Pressed && oldmstate.LeftButton == ButtonState.Released) || (kstate.IsKeyDown(Keys.D1) && oldkstate.IsKeyUp(Keys.D1))) { if (item != null) item.onMouseButtonDown(mouseworldpos); if (kstate.IsKeyDown(Keys.LeftControl) && item != null) { if (!SelectedItems.Contains(item)) selectitem(item); beginCommand("Add Item(s)"); List<Item> selecteditemscopy = new List<Item>(); foreach (Item selitem in SelectedItems) { Item i2 = (Item)selitem.clone(); selecteditemscopy.Add(i2); } foreach (Item selitem in selecteditemscopy) { selitem.Name = selitem.getNamePrefix() + level.getNextItemNumber(); addItem(selitem); } selectitem(selecteditemscopy[0]); updatetreeview(); for (int i = 1; i < selecteditemscopy.Count; i++) SelectedItems.Add(selecteditemscopy[i]); startMoving(); } else if (kstate.IsKeyDown(Keys.LeftShift) && item != null) { if (SelectedItems.Contains(item)) SelectedItems.Remove(item); else SelectedItems.Add(item); } else if (SelectedItems.Contains(item)) { beginCommand("Change Item(s)"); startMoving(); } else if (!SelectedItems.Contains(item)) { selectitem(item); if (item != null) { beginCommand("Change Item(s)"); startMoving(); } else { grabbedpoint = mouseworldpos; selectionrectangle = Rectangle.Empty; state = EditorState.selecting; } } } //MIDDLE MOUSE BUTTON CLICK if ((mstate.MiddleButton == ButtonState.Pressed && oldmstate.MiddleButton == ButtonState.Released) || (kstate.IsKeyDown(AdesExtensions.KEY_ROTATE) && oldkstate.IsKeyUp(AdesExtensions.KEY_ROTATE))) { if (item != null) item.onMouseOut(); if (kstate.IsKeyDown(Keys.LeftControl)) { grabbedpoint = new Vector2(mstate.X, mstate.Y); initialcampos = camera.Position; state = EditorState.cameramoving; MainForm.Instance.pictureBox1.Cursor = Forms.Cursors.SizeAll; } else { if (SelectedItems.Count > 0) { grabbedpoint = mouseworldpos - SelectedItems[0].pPosition; //save the initial rotation for each item initialrot.Clear(); foreach (Item selitem in SelectedItems) { if (selitem.CanRotate()) { initialrot.Add(selitem.getRotation()); } } state = EditorState.rotating; MainForm.Instance.pictureBox1.Cursor = cursorRot; beginCommand("Rotate Item(s)"); } } } //RIGHT MOUSE BUTTON CLICK if ((mstate.RightButton == ButtonState.Pressed && oldmstate.RightButton == ButtonState.Released) || (kstate.IsKeyDown(Keys.D3) && oldkstate.IsKeyUp(Keys.D3))) { if (item != null) item.onMouseOut(); if (SelectedItems.Count > 0) { grabbedpoint = mouseworldpos - SelectedItems[0].pPosition; //save the initial scale for each item initialscale.Clear(); foreach (Item selitem in SelectedItems) { if (selitem.CanScale()) { initialscale.Add(selitem.getScale()); } } state = EditorState.scaling; MainForm.Instance.pictureBox1.Cursor = cursorScale; beginCommand("Scale Item(s)"); } } if (kstate.IsKeyDown(Keys.H) && oldkstate.GetPressedKeys().Length == 0 && SelectedItems.Count > 0) { beginCommand("Flip Item(s) Horizontally"); foreach (Item selitem in SelectedItems) { if (selitem is TextureItem) { TextureItem ti = (TextureItem)selitem; ti.FlipHorizontally = !ti.FlipHorizontally; } } MainForm.Instance.propertyGrid1.Refresh(); endCommand(); } if (kstate.IsKeyDown(Keys.V) && oldkstate.GetPressedKeys().Length == 0 && SelectedItems.Count > 0) { beginCommand("Flip Item(s) Vertically"); foreach (Item selitem in SelectedItems) { if (selitem is TextureItem) { TextureItem ti = (TextureItem)selitem; ti.FlipVertically = !ti.FlipVertically; } } MainForm.Instance.propertyGrid1.Refresh(); endCommand(); } } if (state == EditorState.moving) { int i = 0; foreach (Item selitem in SelectedItems) { newPosition = initialpos[i] + mouseworldpos - grabbedpoint; if (AdesExtensions.shouldSnapPosition(kstate) || kstate.IsKeyDown(Keys.G)) newPosition = snapToGrid(newPosition); drawSnappedPoint = false; selitem.setPosition(newPosition); i++; } MainForm.Instance.propertyGrid1.Refresh(); if ((mstate.LeftButton == ButtonState.Released && oldmstate.LeftButton == ButtonState.Pressed) || (kstate.IsKeyUp(Keys.D1) && oldkstate.IsKeyDown(Keys.D1))) { foreach (Item selitem in SelectedItems) selitem.onMouseButtonUp(mouseworldpos); state = EditorState.idle; MainForm.Instance.pictureBox1.Cursor = Forms.Cursors.Default; if (mouseworldpos != grabbedpoint) endCommand(); else abortCommand(); } } if (state == EditorState.rotating) { Vector2 newpos = mouseworldpos - SelectedItems[0].pPosition; float deltatheta = (float)Math.Atan2(grabbedpoint.Y, grabbedpoint.X) - (float)Math.Atan2(newpos.Y, newpos.X); int i = 0; foreach (Item selitem in SelectedItems) { if (selitem.CanRotate()) { selitem.setRotation(initialrot[i] - deltatheta); if (AdesExtensions.shouldSnapRotation(kstate)) { selitem.setRotation((float)Math.Round(selitem.getRotation() / MathHelper.PiOver4) * MathHelper.PiOver4); } i++; } } MainForm.Instance.propertyGrid1.Refresh(); if ((mstate.MiddleButton == ButtonState.Released && oldmstate.MiddleButton == ButtonState.Pressed) || (kstate.IsKeyUp(AdesExtensions.KEY_ROTATE) && oldkstate.IsKeyDown(AdesExtensions.KEY_ROTATE))) { state = EditorState.idle; MainForm.Instance.pictureBox1.Cursor = Forms.Cursors.Default; endCommand(); } } if (state == EditorState.scaling) { Vector2 newdistance = mouseworldpos - SelectedItems[0].pPosition; float factor = newdistance.Length() / grabbedpoint.Length(); int i = 0; foreach (Item selitem in SelectedItems) { if (selitem.CanScale()) { if (selitem is TextureItem) { MainForm.Instance.toolStripStatusLabel1.Text = "Hold down [X] or [Y] to limit scaling to the according dimension."; } Vector2 newscale = initialscale[i]; if (!kstate.IsKeyDown(Keys.Y)) newscale.X = initialscale[i].X * (((factor - 1.0f) * 0.5f) + 1.0f); if (!kstate.IsKeyDown(Keys.X)) newscale.Y = initialscale[i].Y * (((factor - 1.0f) * 0.5f) + 1.0f); selitem.setScale(newscale); if (kstate.IsKeyDown(Keys.LeftControl)) { Vector2 scale; scale.X = (float)Math.Round(selitem.getScale().X * 10) / 10; scale.Y = (float)Math.Round(selitem.getScale().Y * 10) / 10; selitem.setScale(scale); } i++; } } MainForm.Instance.propertyGrid1.Refresh(); if ((mstate.RightButton == ButtonState.Released && oldmstate.RightButton == ButtonState.Pressed) || (kstate.IsKeyUp(Keys.D3) && oldkstate.IsKeyDown(Keys.D3))) { state = EditorState.idle; MainForm.Instance.pictureBox1.Cursor = Forms.Cursors.Default; endCommand(); } } if (state == EditorState.cameramoving) { Vector2 newpos = new Vector2(mstate.X, mstate.Y); Vector2 distance = (newpos - grabbedpoint) / camera.Scale; if (distance.Length() > 0) { camera.Position = initialcampos - distance; } if (mstate.MiddleButton == ButtonState.Released) { state = EditorState.idle; MainForm.Instance.pictureBox1.Cursor = Forms.Cursors.Default; } } if (state == EditorState.selecting) { if (SelectedLayer == null) return; Vector2 distance = mouseworldpos - grabbedpoint; if (distance.Length() > 0) { SelectedItems.Clear(); selectionrectangle = Extensions.RectangleFromVectors(grabbedpoint, mouseworldpos); foreach (Item i in SelectedLayer.Items) { if (i.Visible && selectionrectangle.Contains((int)i.pPosition.X, (int)i.pPosition.Y)) SelectedItems.Add(i); } updatetreeviewselection(); } if (mstate.LeftButton == ButtonState.Released) { state = EditorState.idle; MainForm.Instance.pictureBox1.Cursor = Forms.Cursors.Default; } } if (state == EditorState.brush) { if (Constants.Instance.SnapToGrid || kstate.IsKeyDown(Keys.G)) { mouseworldpos = snapToGrid(mouseworldpos); } if (mstate.RightButton == ButtonState.Pressed && oldmstate.RightButton == ButtonState.Released) state = EditorState.idle; if (mstate.LeftButton == ButtonState.Pressed && oldmstate.LeftButton == ButtonState.Released) paintTextureBrush(true); } if (state == EditorState.brush_primitive) { if (Constants.Instance.SnapToGrid || kstate.IsKeyDown(Keys.G)) mouseworldpos = snapToGrid(mouseworldpos); if (kstate.IsKeyDown(Keys.LeftControl) && primitivestarted && currentprimitive == PrimitiveType.Rectangle) { Vector2 distance = mouseworldpos - clickedPoints[0]; float squareside = Math.Max(distance.X, distance.Y); mouseworldpos = clickedPoints[0] + new Vector2(squareside, squareside); } if ((mstate.LeftButton == ButtonState.Pressed && oldmstate.LeftButton == ButtonState.Released) || (kstate.IsKeyDown(Keys.D1) && oldkstate.IsKeyUp(Keys.D1))) { clickedPoints.Add(mouseworldpos); if (primitivestarted == false) { primitivestarted = true; switch (currentprimitive) { case PrimitiveType.Rectangle: MainForm.Instance.toolStripStatusLabel1.Text = Resources.Rectangle_Started; break; case PrimitiveType.Circle: MainForm.Instance.toolStripStatusLabel1.Text = Resources.Circle_Started; break; case PrimitiveType.Path: MainForm.Instance.toolStripStatusLabel1.Text = Resources.Path_Started; break; } } else { if (currentprimitive != PrimitiveType.Path) { paintPrimitiveBrush(); clickedPoints.Clear(); primitivestarted = false; } } } if (kstate.IsKeyDown(Keys.Back) && oldkstate.IsKeyUp(Keys.Back)) { if (currentprimitive == PrimitiveType.Path && clickedPoints.Count > 1) { clickedPoints.RemoveAt(clickedPoints.Count-1); } } if ((mstate.MiddleButton == ButtonState.Pressed && oldmstate.MiddleButton == ButtonState.Released) || (kstate.IsKeyDown(Keys.D2) && oldkstate.IsKeyUp(Keys.D2))) { if (currentprimitive == PrimitiveType.Path && primitivestarted) { paintPrimitiveBrush(); clickedPoints.Clear(); primitivestarted = false; MainForm.Instance.toolStripStatusLabel1.Text = Resources.Path_Entered; } } if ((mstate.RightButton == ButtonState.Pressed && oldmstate.RightButton == ButtonState.Released) || (kstate.IsKeyDown(Keys.D3) && oldkstate.IsKeyUp(Keys.D3))) { if (primitivestarted) { clickedPoints.Clear(); primitivestarted = false; switch (currentprimitive) { case PrimitiveType.Rectangle: MainForm.Instance.toolStripStatusLabel1.Text = Resources.Rectangle_Entered; break; case PrimitiveType.Circle: MainForm.Instance.toolStripStatusLabel1.Text = Resources.Circle_Entered; break; case PrimitiveType.Path: MainForm.Instance.toolStripStatusLabel1.Text = Resources.Path_Entered; break; } } else { destroyPrimitiveBrush(); clickedPoints.Clear(); primitivestarted = false; } } } }
private void DrawStaticText() { _spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend); var versionText = "Assault Wing " + MiscHelper.Version; _spriteBatch.DrawString(MenuContent.FontSmall, versionText, new Vector2(10, ViewportHeight - MenuContent.FontSmall.LineSpacing).Round(), Color.White); if (IsHelpTextVisible) { var helpTextPos = new Vector2( (int)(((float)ViewportWidth - MenuContent.FontSmall.MeasureString(ActiveComponent.HelpText).X) / 2), ViewportHeight - MenuContent.FontSmall.LineSpacing); _spriteBatch.DrawString(MenuContent.FontSmall, ActiveComponent.HelpText, helpTextPos.Round(), Color.White); } var copyrightText = "Studfarm Studios"; var copyrightTextPos = new Vector2( ViewportWidth - (int)MenuContent.FontSmall.MeasureString(copyrightText).X - 10, ViewportHeight - MenuContent.FontSmall.LineSpacing); _spriteBatch.DrawString(MenuContent.FontSmall, copyrightText, copyrightTextPos.Round(), Color.White); _spriteBatch.End(); }
public override void Draw2D(Matrix gameToScreen, SpriteBatch spriteBatch, float scale, Player viewer) { // Draw player name if (Owner == null || Owner.IsLocal) return; var screenPos = Vector2.Transform(Pos + DrawPosOffset, gameToScreen); var playerNameSize = PlayerNameFont.MeasureString(Owner.Name); var playerNamePos = new Vector2(screenPos.X - playerNameSize.X / 2, screenPos.Y + 35); var nameAlpha = (IsHiding ? Alpha : 1) * 0.8f; var nameColor = Color.Multiply(Owner.Color, nameAlpha); spriteBatch.DrawString(PlayerNameFont, Owner.Name, playerNamePos.Round(), nameColor); }