public override void OnSelected(MenuElement lastElement) { base.OnSelected(lastElement); TextInputEXT.TextInput += OnTextInput; TextInputEXT.StartTextInput(); Page.Parent.Parent.Game.OnStateChange += OnStateChange; }
public StateMachine() { Content.RootDirectory = "Content"; ScratchContent = new ContentManager(Services, "Content"); // for big things to be unloaded graphicsDeviceManager = new GraphicsDeviceManager(this); #if SDL2 TextInputEXT.TextInput += TextInputEXT_TextInput; TextInputEXT.StartTextInput(); #else EventInput.EventInput.Initialize(this.Window); EventInput.EventInput.CharEntered += new EventInput.CharEnteredHandler(EventInput_CharEntered); EventInput.EventInput.KeyDown += new EventInput.KeyEventHandler(EventInput_KeyDown); EventInput.EventInput.KeyUp += new EventInput.KeyEventHandler(EventInput_KeyUp); #endif }
public void SetTextInputState(bool enabled) { if (!enabled) { TextInputEXT.StopTextInput(); return; } if (!IsTextInputRegistered) { IsTextInputRegistered = true; TextInputEXT.TextInput += TextInputEXT_TextInput; TextInputEXT.TextEditing += TextInputEXT_TextEditing; } TextInputEXT.StartTextInput(); }
public void Update(Game game) { if (_first) { TextInputEXT.TextInput += OnTextInput; TextInputEXT.StartTextInput(); game.OnStateChange += OnStateChange; _first = false; } if (game.Input.MousePressed(MouseButton.Left)) { bool oldFocused = Focused; Focused = Rectangle.Contains(game.Input.MousePosition); if (Focused != oldFocused && FocusChanged != null) { FocusChanged(this, Focused); } } }
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; }
public void Update(Game game) { if (!Disabled && ((Rectangle.Value.Contains(game.Input.MousePosition) && !Rectangle.Value.Contains(game.Input.PreviousMousePosition)) || (Game.Input.KeyPressed(Keys.S) && !_isSearching))) { Rectangle.TweenTo(new Rectangle(Rectangle.TargetValue.X, Rectangle.TargetValue.Y, (int)TotalArea.X, Math.Min((int)TotalArea.Y, MaxHeight)), TweenEaseType.EaseOutQuad, 0.1f); _screenFade.TweenTo(1, TweenEaseType.EaseOutQuad, 0.1f); if (Game.Input.KeyPressed(Keys.S)) { _isSearching = true; _quitQueued = true; TextInputEXT.TextInput += OnSearchInput; TextInputEXT.StartTextInput(); game.OnStateChange += RemoveSearchInput; } } else if (_quitQueued || (!Rectangle.Value.Contains(game.Input.MousePosition) && Rectangle.Value.Contains(game.Input.PreviousMousePosition))) { if (_isScrolling || _isSearching) { _quitQueued = true; } else { if (!Rectangle.Value.Contains(game.Input.MousePosition)) { Rectangle.TweenTo(new Rectangle(Rectangle.TargetValue.X, Rectangle.TargetValue.Y, (int)TotalArea.X, 28), TweenEaseType.EaseOutQuad, 0.1f); _screenFade.TweenTo(0, TweenEaseType.EaseOutQuad, 0.1f); } _quitQueued = false; } } if (_isSearching && game.Input.KeyPressed(Keys.Tab)) { string s = _searchTerm.ToLowerInvariant().Trim().Replace(" ", ""); foreach (Category category in Categories) { Tile searched = Search(s, category); if (searched != null) { _searchTerm = searched.Name(null, _environment); break; } } } if (_isSearching && game.Input.KeyPressed(Keys.Enter)) { _searchTerm = _searchTerm.ToLowerInvariant().Trim().Replace(" ", ""); foreach (Category category in Categories) { Tile searched = Search(_searchTerm, category); if (searched != null) { SelectedTile = searched; if (SelectionChanged != null) { SelectionChanged(this, SelectedTile); } } } _isSearching = false; _searchTerm = ""; TextInputEXT.TextInput -= OnSearchInput; TextInputEXT.StopTextInput(); game.OnStateChange -= RemoveSearchInput; } else if (_isSearching && game.Input.KeyPressed(Keys.Escape)) { _isSearching = false; _searchTerm = ""; TextInputEXT.TextInput -= OnSearchInput; TextInputEXT.StopTextInput(); game.OnStateChange -= RemoveSearchInput; } if (IsHovered && CanInteractWith) { float changed = _scrollTarget; if (game.Input.KeyPressed(Keys.Home)) { _scrollTarget = 0; } if (game.Input.KeyPressed(Keys.PageUp)) { _scrollTarget = Scroll - 180; } if (game.Input.KeyPressed(Keys.PageDown)) { _scrollTarget = Scroll + 180; } if (game.Input.KeyPressed(Keys.End)) { _scrollTarget = ScrollableAmount; } if (changed != _scrollTarget) { if (_scrollTarget < 0) { _scrollTarget = 0; } if (_scrollTarget > ScrollableAmount) { _scrollTarget = ScrollableAmount; } } } if (CanInteractWith) { if (_scrollTarget != -1) { Scroll = MathHelper.Lerp(Scroll, _scrollTarget, (float)Game.DeltaTime * 14f); if (Math.Abs(Scroll - _scrollTarget) <= 0.75f) { _scrollTarget = -1; } } else if (Rectangle.Value.Contains(game.Input.MousePosition)) { if ((game.Input.MouseScroll < 0 && Scroll < ScrollableAmount) || (game.Input.MouseScroll > 0 && Scroll > 0)) { Scroll -= game.Input.MouseScroll / 4f; } if (game.Input.Key(Keys.Up) && Scroll > 0) { Scroll = Math.Max(0, Scroll - ((float)game.DeltaTime * 140f)); } if (game.Input.Key(Keys.Down) && Scroll < ScrollableAmount) { Scroll = Math.Min(ScrollableAmount, Scroll + ((float)game.DeltaTime * 140f)); } } if (_isScrolling) { float at = game.Input.MousePosition.Y - (Rectangle.Value.Top + 8); float percentage = at / (Rectangle.Value.Height - 16); Scroll = percentage * ScrollableAmount; if (game.Input.MouseReleased(Engine.MouseButton.Left)) { _isScrolling = false; } } Scroll = MathHelper.Clamp(Scroll, 0, ScrollableAmount); } }
public override void OnEnter(GameState previousState) { _lastState = previousState; TextInputEXT.TextInput += OnTextInput; TextInputEXT.StartTextInput(); }
public void Update(Game game) { if (_first) { TextInputEXT.TextInput += OnTextInput; TextInputEXT.StartTextInput(); game.OnStateChange += OnStateChange; _first = false; RecalculateTotalArea(); } if (game.Input.MousePressed(MouseButton.Left) || _defocusQueued) { if (_isScrollingX || _isScrollingY) { if (!_defocusQueued) { _defocusQueued = true; } } else { _defocusQueued = false; bool oldFocused = Focused; Focused = Area.Value.Contains(game.Input.MousePosition); if (Focused != oldFocused && FocusChanged != null) { FocusChanged(this, Focused); } } } if (Area.Value.Contains(game.Input.MousePosition)) { if ((game.Input.MouseScroll < 0 && Scroll.Y < ScrollableAmount.Y) || (game.Input.MouseScroll > 0 && Scroll.Y > 0)) { Scroll.Y -= game.Input.MouseScroll / 4f; } if (game.Input.Key(Keys.Up) && Scroll.Y > 0) { Scroll.Y = Math.Max(0, Scroll.Y - ((float)game.DeltaTime * 140f)); } if (game.Input.Key(Keys.Down) && Scroll.Y < ScrollableAmount.Y) { Scroll.Y = Math.Min(ScrollableAmount.Y, Scroll.Y + ((float)game.DeltaTime * 140f)); } } if (_isScrollingX) { float at = game.Input.MousePosition.X - (Area.Value.Left + 8); float percentage = at / (Area.Value.Width - 16); Scroll.X = percentage * ScrollableAmount.X; if (game.Input.MouseReleased(Engine.MouseButton.Left)) { _isScrollingX = false; } } if (_isScrollingY) { float at = game.Input.MousePosition.Y - (Area.Value.Top + 8); float percentage = at / (Area.Value.Height - 16); Scroll.Y = percentage * ScrollableAmount.Y; if (game.Input.MouseReleased(Engine.MouseButton.Left)) { _isScrollingY = false; } } Scroll = Vector2.Clamp(Scroll, Vector2.Zero, ScrollableAmount); }