From cca02b53961c2cf66fc1c020013c773aea1998e8 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Wed, 9 Jun 2021 00:37:44 +0200 Subject: [PATCH] organized UiSystem constructor --- MLEM.Ui/UiSystem.cs | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/MLEM.Ui/UiSystem.cs b/MLEM.Ui/UiSystem.cs index 764025d..ff07df1 100644 --- a/MLEM.Ui/UiSystem.cs +++ b/MLEM.Ui/UiSystem.cs @@ -183,6 +183,22 @@ namespace MLEM.Ui { this.OnElementTouchEnter += e => e.OnTouchEnter?.Invoke(e); this.OnElementTouchExit += e => e.OnTouchExit?.Invoke(e); this.OnElementAreaUpdated += e => e.OnAreaUpdated?.Invoke(e); + this.OnMousedElementChanged += e => this.ApplyToAll(t => t.OnMousedElementChanged?.Invoke(t, e)); + this.OnTouchedElementChanged += e => this.ApplyToAll(t => t.OnTouchedElementChanged?.Invoke(t, e)); + this.OnSelectedElementChanged += e => this.ApplyToAll(t => t.OnSelectedElementChanged?.Invoke(t, e)); + this.OnSelectedElementDrawn += (element, time, batch, alpha) => { + if (this.Controls.IsAutoNavMode && element.SelectionIndicator.HasValue()) + batch.Draw(element.SelectionIndicator, element.DisplayArea, Color.White * alpha, element.Scale / 2); + }; + this.OnElementPressed += e => { + if (e.OnPressed != null) + e.ActionSound.Value?.Play(); + }; + this.OnElementSecondaryPressed += e => { + if (e.OnSecondaryPressed != null) + e.SecondActionSound.Value?.Play(); + }; + MlemPlatform.Current?.AddTextInputListener(game.Window, (sender, key, character) => this.ApplyToAll(e => e.OnTextInput?.Invoke(e, key, character))); if (automaticViewport) { this.Viewport = new Rectangle(Point.Zero, game.Window.ClientBounds.Size); @@ -194,25 +210,6 @@ namespace MLEM.Ui { }; } - if (MlemPlatform.Current != null) - MlemPlatform.Current.AddTextInputListener(game.Window, (sender, key, character) => this.ApplyToAll(e => e.OnTextInput?.Invoke(e, key, character))); - this.OnMousedElementChanged = e => this.ApplyToAll(t => t.OnMousedElementChanged?.Invoke(t, e)); - this.OnTouchedElementChanged = e => this.ApplyToAll(t => t.OnTouchedElementChanged?.Invoke(t, e)); - this.OnSelectedElementChanged = e => this.ApplyToAll(t => t.OnSelectedElementChanged?.Invoke(t, e)); - this.OnSelectedElementDrawn = (element, time, batch, alpha) => { - if (this.Controls.IsAutoNavMode && element.SelectionIndicator.HasValue()) { - batch.Draw(element.SelectionIndicator, element.DisplayArea, Color.White * alpha, element.Scale / 2); - } - }; - this.OnElementPressed += e => { - if (e.OnPressed != null) - e.ActionSound.Value?.Play(); - }; - this.OnElementSecondaryPressed += e => { - if (e.OnSecondaryPressed != null) - e.SecondActionSound.Value?.Play(); - }; - this.TextFormatter = new TextFormatter(); this.TextFormatter.Codes.Add(new Regex("]+))?>"), (f, m, r) => new LinkCode(m, r, 1 / 16F, 0.85F, t => this.Controls.MousedElement is Paragraph.Link l1 && l1.Token == t || this.Controls.TouchedElement is Paragraph.Link l2 && l2.Token == t));