public TileMenu(Map.Environment environment, Engine.Game game) { _environment = environment; Game = game; Rectangle = new TweenedRectangle(game, new Rectangle(0, 0, (int)TotalArea.X, 28)); _screenFade = new TweenedDouble(game, 0); Recreate(); }
public void Draw(Engine.Game game) { game.Batch.Scissor = Rectangle; if (!_isSearching) { game.Batch.Rectangle(Rectangle, Color.Black * 0.85f); } if (_screenFade != 1.0f) { game.Batch.Text(SpriteBatch.FontStyle.Bold, 15, SelectedTile.Name(null, _environment), new Vector2(Rectangle.Value.X + 8, Rectangle.Value.Y + 4), Color.White * (1.0f - _screenFade) * (Disabled ? 0.3f : 0.6f)); Rectangle tileRect = new Rectangle(Rectangle.Value.X + Rectangle.Value.Width - 4 - 16 - 2, Rectangle.Value.Y + 6, 16, 16); if (game.Assets.Get <Texture2D>(SelectedTile.TextureName(null, _environment)).Height > game.Assets.Get <Texture2D>(SelectedTile.TextureName(null, _environment)).Width) { tileRect.Width /= 2; tileRect.X += 8; } game.Batch.Outline(tileRect, Color.White * (1.0f - _screenFade) * 0.6f, 1, false); game.Batch.Texture(tileRect, game.Assets.Get <Texture2D>(SelectedTile.TextureName(null, _environment)), Color.White * (1.0f - _screenFade)); } if (_screenFade != 0.0f) { Matrix oldTransform = game.Batch.Transform; game.Batch.Transform = Matrix.CreateTranslation( Rectangle.Value.X + 8 + 18 + 10, (int)-Scroll + Rectangle.Value.Y + 6, 0); int y = 0; foreach (Category category in Categories) { DrawCategory(game, category, true, ref y); } game.Batch.Transform = oldTransform; int cY = 8; int categoryTop = 8 - (int)Scroll; foreach (Category category in Categories) { Rectangle rectC = new Rectangle( Rectangle.Value.X + 8, Rectangle.Value.Y + cY /* - (categoryTop < cY ? cY - categoryTop : 0) */, 18, 18); bool hoverC = rectC.Contains(game.Input.MousePosition); game.Batch.Texture(rectC, game.Assets.Get <Texture2D>(category.Icon), Color.White * _screenFade * (hoverC ? 1.0f : 0.6f)); if (game.Input.MousePressed(Engine.MouseButton.Left) && hoverC && CanInteractWith) { _scrollTarget = Math.Min(ScrollableAmount, categoryTop + (int)Scroll - 8); } /*if(categoryTop < cY) * cY -= Math.Min(cY - categoryTop, 24); */ cY += 24; categoryTop += CalculateCategorySize(category, true).Y; } if (ScrollableAmount > 0) { float scrollBarHeight = 1000 / ScrollableAmount; if (scrollBarHeight > Rectangle.Value.Height - 16) { scrollBarHeight = Rectangle.Value.Height - 16; } if (scrollBarHeight < 20) { scrollBarHeight = 20; } Rectangle fullScrollRectangle = new Rectangle(Rectangle.TargetValue.Right - 18, Rectangle.TargetValue.Y + 8, 20, Rectangle.TargetValue.Height - 16); if ((fullScrollRectangle.Contains(game.Input.MousePosition) || _isScrolling) && CanInteractWith) { fullScrollRectangle.X = Rectangle.TargetValue.Right - 10; fullScrollRectangle.Width = 2; game.Batch.Rectangle(fullScrollRectangle, Color.White * 0.4f * _screenFade); if (game.Input.MousePressed(Engine.MouseButton.Left) && !_isScrolling && CanInteractWith) { _isScrolling = true; } } game.Batch.Rectangle(new Rectangle( Rectangle.TargetValue.Right - 10, (int)(MathHelper.Lerp(Rectangle.TargetValue.Y + 8, Rectangle.TargetValue.Bottom - 8 - scrollBarHeight, Scroll / ScrollableAmount)), 2, (int)scrollBarHeight), Color.White * 0.5f * _screenFade); } Rectangle rect = new Rectangle( Rectangle.Value.X + 8, Rectangle.TargetValue.Bottom - 8 - 18, 18, 18); bool hover = rect.Contains(game.Input.MousePosition); game.Batch.Texture(rect, game.Assets.Get <Texture2D>("editor/tilemenu/search.png"), Color.White * _screenFade * (hover ? 1.0f : 0.6f)); if (game.Input.MousePressed(Engine.MouseButton.Left) && hover && CanInteractWith) { _isSearching = true; _quitQueued = true; TextInputEXT.TextInput += OnSearchInput; TextInputEXT.StartTextInput(); game.OnStateChange += RemoveSearchInput; } } if (_isSearching) { game.Batch.Rectangle(Rectangle, Color.Black * 0.85f); string text = _searchTerm; Vector2 measure = game.DefaultFonts.MonoBold.Measure(14, text + "|"); text += ((int)((game.Time * 4) % 2) == 0 ? "|" : ""); game.Batch.Text(SpriteBatch.FontStyle.MonoBold, 14, text, Rectangle.Value.Center.ToVector2() - measure / 2, Color.White); } game.Batch.Scissor = null; }
private void DrawCategory(Engine.Game game, Category category, bool first, ref int y) { game.Batch.Text(SpriteBatch.FontStyle.Bold, (first ? (uint)16 : 14), category.Title, new Vector2(0, y), Color.White * _screenFade); y += (first ? 16 : 14) + 10; for (int i = 0; i < category.Objects.Count; i++) { if (i != 0) { y += 4; } if (category.Objects[i] is Category) { DrawCategory(game, category.Objects[i] as Category, false, ref y); } else if ((category.Objects[i] as string) == Separator) { y += 8; } else { string layer = (category.Objects[i] as Tile).Layer.ToString(); Vector2 measure = Game.DefaultFonts.Bold.Measure(16, (category.Objects[i] as Tile).Name(null, _environment) + "\n" + layer); TileAtlas.Region region = Map.Atlas[(category.Objects[i] as Tile).TextureName(null, _environment)]; bool isTextBigger = measure.Y > region.Rectangle.Height * 2; int textureY = isTextBigger ? y + (int)(measure.Y / 2 - region.Rectangle.Height) : y; int textY = isTextBigger ? y : y + (int)(region.Rectangle.Height - measure.Y / 2); Rectangle fullRectangle = new Rectangle( Rectangle.Value.X + 8 + 28, (int)-Scroll + Rectangle.Value.Y + 6 + y, Rectangle.Value.Width - 8 - 48, Math.Max((int)measure.Y, region.Rectangle.Height * 2)); if (fullRectangle.Contains(game.Input.MousePosition) || SelectedTile == (category.Objects[i] as Tile)) { game.Batch.Rectangle( new Rectangle(-4, y - 2, fullRectangle.Width + 4, fullRectangle.Height + 4), Color.White * (SelectedTile == (category.Objects[i] as Tile) ? 0.15f : 0.1f)); } if (fullRectangle.Contains(game.Input.MousePosition) && SelectedTile != (category.Objects[i] as Tile) && game.Input.MousePressed(Engine.MouseButton.Left) && CanInteractWith) { SelectedTile = (category.Objects[i] as Tile); if (SelectionChanged != null) { SelectionChanged(this, SelectedTile); } } game.Batch.Texture( new Rectangle(0, textureY, region.Rectangle.Width * 2, region.Rectangle.Height * 2), region.Texture, Color.White * _screenFade, region.Rectangle); game.Batch.Text(SpriteBatch.FontStyle.Bold, 14, (category.Objects[i] as Tile).Name(null, _environment), new Vector2( region.Rectangle.Width * 2 + 12, textY), Color.White * 0.6f * _screenFade); game.Batch.Text(SpriteBatch.FontStyle.Bold, 14, layer, new Vector2( region.Rectangle.Width * 2 + 12, textY + 16), Color.White * 0.3f * _screenFade); y += Math.Max((int)measure.Y, region.Rectangle.Height * 2); } } y += 10; }