1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-22 20:58:34 +01:00
This commit is contained in:
Ellpeck 2020-02-06 01:33:24 +01:00
parent 64749c31ce
commit ee5111372b
15 changed files with 83 additions and 67 deletions

View file

@ -17,21 +17,21 @@
/importer:FontDescriptionImporter /importer:FontDescriptionImporter
/processor:FontDescriptionProcessor /processor:FontDescriptionProcessor
/processorParam:PremultiplyAlpha=True /processorParam:PremultiplyAlpha=True
/processorParam:TextureFormat=Compressed /processorParam:TextureFormat=Color
/build:Fonts/TestFont.spritefont /build:Fonts/TestFont.spritefont
#begin Fonts/TestFontBold.spritefont #begin Fonts/TestFontBold.spritefont
/importer:FontDescriptionImporter /importer:FontDescriptionImporter
/processor:FontDescriptionProcessor /processor:FontDescriptionProcessor
/processorParam:PremultiplyAlpha=True /processorParam:PremultiplyAlpha=True
/processorParam:TextureFormat=Compressed /processorParam:TextureFormat=Color
/build:Fonts/TestFontBold.spritefont /build:Fonts/TestFontBold.spritefont
#begin Fonts/TestFontItalic.spritefont #begin Fonts/TestFontItalic.spritefont
/importer:FontDescriptionImporter /importer:FontDescriptionImporter
/processor:FontDescriptionProcessor /processor:FontDescriptionProcessor
/processorParam:PremultiplyAlpha=True /processorParam:PremultiplyAlpha=True
/processorParam:TextureFormat=Compressed /processorParam:TextureFormat=Color
/build:Fonts/TestFontItalic.spritefont /build:Fonts/TestFontItalic.spritefont
#begin Textures/Anim.png #begin Textures/Anim.png

View file

@ -85,16 +85,16 @@ namespace MLEM.Ui.Elements {
public TabNextElementCallback GetTabNextElement; public TabNextElementCallback GetTabNextElement;
public GamepadNextElementCallback GetGamepadNextElement; public GamepadNextElementCallback GetGamepadNextElement;
private UiSystem system; private UiSystem uiSystem;
public UiSystem System { public UiSystem UiSystem {
get => this.system; get => this.uiSystem;
internal set { internal set {
this.system = value; this.uiSystem = value;
if (this.system != null) if (this.uiSystem != null)
this.InitStyle(this.system.Style); this.InitStyle(this.uiSystem.Style);
} }
} }
protected UiControls Controls => this.System.Controls; protected UiControls Controls => this.UiSystem.Controls;
protected InputHandler Input => this.Controls.Input; protected InputHandler Input => this.Controls.Input;
public RootElement Root { get; internal set; } public RootElement Root { get; internal set; }
public float Scale => this.Root.ActualScale; public float Scale => this.Root.ActualScale;
@ -166,7 +166,7 @@ namespace MLEM.Ui.Elements {
element.Parent = this; element.Parent = this;
element.AndChildren(e => { element.AndChildren(e => {
e.Root = this.Root; e.Root = this.Root;
e.System = this.System; e.UiSystem = this.UiSystem;
if (this.Root != null) if (this.Root != null)
this.Root.OnElementAdded(e); this.Root.OnElementAdded(e);
}); });
@ -180,7 +180,7 @@ namespace MLEM.Ui.Elements {
element.Parent = null; element.Parent = null;
element.AndChildren(e => { element.AndChildren(e => {
e.Root = null; e.Root = null;
e.System = null; e.UiSystem = null;
if (this.Root != null) if (this.Root != null)
this.Root.OnElementRemoved(e); this.Root.OnElementRemoved(e);
}); });
@ -230,7 +230,7 @@ namespace MLEM.Ui.Elements {
if (this.IsHidden) if (this.IsHidden)
return; return;
var parentArea = this.Parent != null ? this.Parent.ChildPaddedArea : (RectangleF) this.system.Viewport; var parentArea = this.Parent != null ? this.Parent.ChildPaddedArea : (RectangleF) this.uiSystem.Viewport;
var parentCenterX = parentArea.X + parentArea.Width / 2; var parentCenterX = parentArea.X + parentArea.Width / 2;
var parentCenterY = parentArea.Y + parentArea.Height / 2; var parentCenterY = parentArea.Y + parentArea.Height / 2;
@ -314,7 +314,7 @@ namespace MLEM.Ui.Elements {
} }
this.area = new RectangleF(pos, actualSize); this.area = new RectangleF(pos, actualSize);
this.System.OnElementAreaUpdated?.Invoke(this); this.UiSystem.OnElementAreaUpdated?.Invoke(this);
foreach (var child in this.Children) foreach (var child in this.Children)
child.ForceUpdateArea(); child.ForceUpdateArea();
@ -451,15 +451,15 @@ namespace MLEM.Ui.Elements {
} }
public virtual void Update(GameTime time) { public virtual void Update(GameTime time) {
this.System.OnElementUpdated?.Invoke(this, time); this.UiSystem.OnElementUpdated?.Invoke(this, time);
foreach (var child in this.GetRelevantChildren()) foreach (var child in this.GetRelevantChildren())
if (child.System != null) if (child.UiSystem != null)
child.Update(time); child.Update(time);
} }
public virtual void Draw(GameTime time, SpriteBatch batch, float alpha, BlendState blendState, SamplerState samplerState, Matrix matrix) { public virtual void Draw(GameTime time, SpriteBatch batch, float alpha, BlendState blendState, SamplerState samplerState, Matrix matrix) {
this.System.OnElementDrawn?.Invoke(this, time, batch, alpha); this.UiSystem.OnElementDrawn?.Invoke(this, time, batch, alpha);
foreach (var child in this.GetRelevantChildren()) { foreach (var child in this.GetRelevantChildren()) {
if (!child.IsHidden) if (!child.IsHidden)

View file

@ -85,7 +85,7 @@ namespace MLEM.Ui.Elements {
if (this.renderTarget == null || targetArea.Width != this.renderTarget.Width || targetArea.Height != this.renderTarget.Height) { if (this.renderTarget == null || targetArea.Width != this.renderTarget.Width || targetArea.Height != this.renderTarget.Height) {
if (this.renderTarget != null) if (this.renderTarget != null)
this.renderTarget.Dispose(); this.renderTarget.Dispose();
this.renderTarget = targetArea.IsEmpty ? null : new RenderTarget2D(this.System.GraphicsDevice, targetArea.Width, targetArea.Height); this.renderTarget = targetArea.IsEmpty ? null : new RenderTarget2D(this.UiSystem.GraphicsDevice, targetArea.Width, targetArea.Height);
} }
} }
} }
@ -132,8 +132,8 @@ namespace MLEM.Ui.Elements {
} }
public override void Draw(GameTime time, SpriteBatch batch, float alpha, BlendState blendState, SamplerState samplerState, Matrix matrix) { public override void Draw(GameTime time, SpriteBatch batch, float alpha, BlendState blendState, SamplerState samplerState, Matrix matrix) {
if (this.Texture.Value != null) if (this.Texture != null)
batch.Draw(this.Texture, this.DisplayArea, Color.White * alpha, this.Scale); batch.Draw(this.Texture.Value, this.DisplayArea, Color.White * alpha, this.Scale);
// if we handle overflow, draw using the render target in DrawUnbound // if we handle overflow, draw using the render target in DrawUnbound
if (!this.scrollOverflow || this.renderTarget == null) { if (!this.scrollOverflow || this.renderTarget == null) {
base.Draw(time, batch, alpha, blendState, samplerState, matrix); base.Draw(time, batch, alpha, blendState, samplerState, matrix);

View file

@ -36,9 +36,8 @@ namespace MLEM.Ui.Elements {
batch.Draw(this.Texture, this.DisplayArea, (Color) this.Color * alpha, this.Scale); batch.Draw(this.Texture, this.DisplayArea, (Color) this.Color * alpha, this.Scale);
var percentage = this.CurrentValue / this.MaxValue; var percentage = this.CurrentValue / this.MaxValue;
var tex = this.ProgressTexture.Value; var padHor = this.ProgressTexture != null ? this.ProgressTexture.Value.Padding.Width * this.Scale : 0;
var padHor = tex != null ? tex.Padding.Width * this.Scale : 0; var padVer = this.ProgressTexture != null ? this.ProgressTexture.Value.Padding.Height * this.Scale : 0;
var padVer = tex != null ? tex.Padding.Height * this.Scale : 0;
var width = percentage * (this.DisplayArea.Width - padHor) + padHor; var width = percentage * (this.DisplayArea.Width - padHor) + padHor;
var height = percentage * (this.DisplayArea.Height - padVer) + padVer; var height = percentage * (this.DisplayArea.Height - padVer) + padVer;
RectangleF progressArea; RectangleF progressArea;
@ -61,7 +60,7 @@ namespace MLEM.Ui.Elements {
break; break;
} }
var offsetArea = progressArea.Shrink(this.ProgressPadding.Value * this.Scale); var offsetArea = progressArea.Shrink(this.ProgressPadding.Value * this.Scale);
if (this.ProgressTexture.Value != null) { if (this.ProgressTexture != null) {
batch.Draw(this.ProgressTexture, offsetArea, (Color) this.ProgressColor * alpha, this.Scale); batch.Draw(this.ProgressTexture, offsetArea, (Color) this.ProgressColor * alpha, this.Scale);
} else { } else {
batch.Draw(batch.GetBlankTexture(), offsetArea, (Color) this.ProgressColor * alpha); batch.Draw(batch.GetBlankTexture(), offsetArea, (Color) this.ProgressColor * alpha);

View file

@ -73,7 +73,7 @@ namespace MLEM.Ui.Elements {
if (this.isMouseHeld) if (this.isMouseHeld)
this.ScrollToPos(this.Input.MousePosition.Transform(this.Root.InvTransform)); this.ScrollToPos(this.Input.MousePosition.Transform(this.Root.InvTransform));
if (!this.Horizontal && moused != null && (moused == this.Parent || moused.GetParentTree().Contains(this.Parent))) { if (!this.Horizontal && moused != null && (moused == this.Parent || moused.GetParentTree().Contains(this.Parent))) {
var scroll = this.Input.LastScrollWheel - this.Input.ScrollWheel; double scroll = this.Input.LastScrollWheel - this.Input.ScrollWheel;
if (scroll != 0) if (scroll != 0)
this.CurrentValue += this.StepPerScroll * Math.Sign(scroll); this.CurrentValue += this.StepPerScroll * Math.Sign(scroll);
} }

View file

@ -69,6 +69,7 @@ namespace MLEM.Ui.Elements {
} }
}; };
} else { } else {
#if !WEB
this.OnPressed += async e => { this.OnPressed += async e => {
if (!KeyboardInput.IsVisible) { if (!KeyboardInput.IsVisible) {
var title = this.MobileTitle ?? this.PlaceholderText; var title = this.MobileTitle ?? this.PlaceholderText;
@ -77,6 +78,7 @@ namespace MLEM.Ui.Elements {
this.SetText(result.Replace('\n', ' '), true); this.SetText(result.Replace('\n', ' '), true);
} }
}; };
#endif
} }
this.OnDeselected += e => this.CaretPos = 0; this.OnDeselected += e => this.CaretPos = 0;
this.OnSelected += e => this.CaretPos = this.text.Length; this.OnSelected += e => this.CaretPos = this.text.Length;
@ -84,7 +86,7 @@ namespace MLEM.Ui.Elements {
private void HandleTextChange(bool textChanged = true) { private void HandleTextChange(bool textChanged = true) {
// not initialized yet // not initialized yet
if (this.Font.Value == null) if (this.Font == null)
return; return;
var length = this.Font.Value.MeasureString(this.text).X * this.TextScale; var length = this.Font.Value.MeasureString(this.text).X * this.TextScale;
var maxWidth = this.DisplayArea.Width / this.Scale - this.TextOffsetX * 2; var maxWidth = this.DisplayArea.Width / this.Scale - this.TextOffsetX * 2;

View file

@ -23,12 +23,12 @@ namespace MLEM.Ui.Elements {
if (elementToHover != null) { if (elementToHover != null) {
elementToHover.OnMouseEnter += element => { elementToHover.OnMouseEnter += element => {
element.System.Add(element.GetType().Name + "Tooltip", this); element.UiSystem.Add(element.GetType().Name + "Tooltip", this);
this.SnapPositionToMouse(); this.SnapPositionToMouse();
}; };
elementToHover.OnMouseExit += element => { elementToHover.OnMouseExit += element => {
if (this.System != null) if (this.UiSystem != null)
this.System.Remove(this.Root.Name); this.UiSystem.Remove(this.Root.Name);
}; };
} }
} }
@ -51,7 +51,7 @@ namespace MLEM.Ui.Elements {
} }
public void SnapPositionToMouse() { public void SnapPositionToMouse() {
var viewport = this.System.Viewport.Size; var viewport = this.UiSystem.Viewport.Size;
var offset = this.Input.MousePosition.ToVector2() / this.Scale + this.MouseOffset; var offset = this.Input.MousePosition.ToVector2() / this.Scale + this.MouseOffset;
if (offset.X < 0) if (offset.X < 0)
offset.X = 0; offset.X = 0;

View file

@ -12,10 +12,9 @@ namespace MLEM.Ui.Style {
} }
public void SetFromStyle(T value) { public void SetFromStyle(T value) {
if (!this.isCustom) { if (!this.isCustom)
this.Value = value; this.Value = value;
} }
}
public void Set(T value) { public void Set(T value) {
this.isCustom = true; this.isCustom = true;
@ -23,7 +22,7 @@ namespace MLEM.Ui.Style {
} }
public T OrDefault(T def) { public T OrDefault(T def) {
return EqualityComparer<T>.Default.Equals(this.Value, default) ? def : this.Value; return EqualityComparer<T>.Default.Equals(this.Value, default(T)) ? def : this.Value;
} }
public static implicit operator T(StyleProp<T> prop) { public static implicit operator T(StyleProp<T> prop) {
@ -34,5 +33,13 @@ namespace MLEM.Ui.Style {
return new StyleProp<T>(prop); return new StyleProp<T>(prop);
} }
public static bool operator ==(StyleProp<T> left, StyleProp<T> right) {
return EqualityComparer<T>.Default.Equals(left.Value, right.Value);
}
public static bool operator !=(StyleProp<T> left, StyleProp<T> right) {
return !(left == right);
}
} }
} }

View file

@ -13,7 +13,7 @@ namespace MLEM.Ui {
public readonly InputHandler Input; public readonly InputHandler Input;
protected readonly bool IsInputOurs; protected readonly bool IsInputOurs;
protected readonly UiSystem System; protected readonly UiSystem UiSystem;
public RootElement ActiveRoot { get; private set; } public RootElement ActiveRoot { get; private set; }
public Element MousedElement { get; private set; } public Element MousedElement { get; private set; }
@ -34,8 +34,8 @@ namespace MLEM.Ui {
public bool IsAutoNavMode { get; private set; } public bool IsAutoNavMode { get; private set; }
public UiControls(UiSystem system, InputHandler inputHandler = null) { public UiControls(UiSystem uiSystem, InputHandler inputHandler = null) {
this.System = system; this.UiSystem = uiSystem;
this.Input = inputHandler ?? new InputHandler(); this.Input = inputHandler ?? new InputHandler();
this.IsInputOurs = inputHandler == null; this.IsInputOurs = inputHandler == null;
@ -46,18 +46,18 @@ namespace MLEM.Ui {
public virtual void Update() { public virtual void Update() {
if (this.IsInputOurs) if (this.IsInputOurs)
this.Input.Update(); this.Input.Update();
this.ActiveRoot = this.System.GetRootElements().FirstOrDefault(root => root.CanSelectContent && !root.Element.IsHidden); this.ActiveRoot = this.UiSystem.GetRootElements().FirstOrDefault(root => root.CanSelectContent && !root.Element.IsHidden);
// MOUSE INPUT // MOUSE INPUT
if (this.HandleMouse) { if (this.HandleMouse) {
var mousedNow = this.GetElementUnderPos(this.Input.MousePosition.ToVector2()); var mousedNow = this.GetElementUnderPos(this.Input.MousePosition.ToVector2());
if (mousedNow != this.MousedElement) { if (mousedNow != this.MousedElement) {
if (this.MousedElement != null) if (this.MousedElement != null)
this.System.OnElementMouseExit?.Invoke(this.MousedElement); this.UiSystem.OnElementMouseExit?.Invoke(this.MousedElement);
if (mousedNow != null) if (mousedNow != null)
this.System.OnElementMouseEnter?.Invoke(mousedNow); this.UiSystem.OnElementMouseEnter?.Invoke(mousedNow);
this.MousedElement = mousedNow; this.MousedElement = mousedNow;
this.System.OnMousedElementChanged?.Invoke(mousedNow); this.UiSystem.OnMousedElementChanged?.Invoke(mousedNow);
} }
if (this.Input.IsMouseButtonPressed(MouseButton.Left)) { if (this.Input.IsMouseButtonPressed(MouseButton.Left)) {
@ -65,11 +65,11 @@ namespace MLEM.Ui {
var selectedNow = mousedNow != null && mousedNow.CanBeSelected ? mousedNow : null; var selectedNow = mousedNow != null && mousedNow.CanBeSelected ? mousedNow : null;
this.ActiveRoot?.SelectElement(selectedNow); this.ActiveRoot?.SelectElement(selectedNow);
if (mousedNow != null && mousedNow.CanBePressed) if (mousedNow != null && mousedNow.CanBePressed)
this.System.OnElementPressed?.Invoke(mousedNow); this.UiSystem.OnElementPressed?.Invoke(mousedNow);
} else if (this.Input.IsMouseButtonPressed(MouseButton.Right)) { } else if (this.Input.IsMouseButtonPressed(MouseButton.Right)) {
this.IsAutoNavMode = false; this.IsAutoNavMode = false;
if (mousedNow != null && mousedNow.CanBePressed) if (mousedNow != null && mousedNow.CanBePressed)
this.System.OnElementSecondaryPressed?.Invoke(mousedNow); this.UiSystem.OnElementSecondaryPressed?.Invoke(mousedNow);
} }
} }
@ -79,10 +79,10 @@ namespace MLEM.Ui {
if (this.SelectedElement?.Root != null && this.SelectedElement.CanBePressed) { if (this.SelectedElement?.Root != null && this.SelectedElement.CanBePressed) {
if (this.Input.IsModifierKeyDown(ModifierKey.Shift)) { if (this.Input.IsModifierKeyDown(ModifierKey.Shift)) {
// secondary action on element using space or enter // secondary action on element using space or enter
this.System.OnElementSecondaryPressed?.Invoke(this.SelectedElement); this.UiSystem.OnElementSecondaryPressed?.Invoke(this.SelectedElement);
} else { } else {
// first action on element using space or enter // first action on element using space or enter
this.System.OnElementPressed?.Invoke(this.SelectedElement); this.UiSystem.OnElementPressed?.Invoke(this.SelectedElement);
} }
} }
} else if (this.Input.IsKeyPressed(Keys.Tab)) { } else if (this.Input.IsKeyPressed(Keys.Tab)) {
@ -103,13 +103,13 @@ namespace MLEM.Ui {
var tapped = this.GetElementUnderPos(tap.Position); var tapped = this.GetElementUnderPos(tap.Position);
this.ActiveRoot?.SelectElement(tapped); this.ActiveRoot?.SelectElement(tapped);
if (tapped != null && tapped.CanBePressed) if (tapped != null && tapped.CanBePressed)
this.System.OnElementPressed?.Invoke(tapped); this.UiSystem.OnElementPressed?.Invoke(tapped);
} else if (this.Input.GetGesture(GestureType.Hold, out var hold)) { } else if (this.Input.GetGesture(GestureType.Hold, out var hold)) {
this.IsAutoNavMode = false; this.IsAutoNavMode = false;
var held = this.GetElementUnderPos(hold.Position); var held = this.GetElementUnderPos(hold.Position);
this.ActiveRoot?.SelectElement(held); this.ActiveRoot?.SelectElement(held);
if (held != null && held.CanBePressed) if (held != null && held.CanBePressed)
this.System.OnElementSecondaryPressed?.Invoke(held); this.UiSystem.OnElementSecondaryPressed?.Invoke(held);
} }
} }
@ -117,10 +117,10 @@ namespace MLEM.Ui {
if (this.HandleGamepad) { if (this.HandleGamepad) {
if (this.GamepadButtons.Any(b => this.IsGamepadPressed(b))) { if (this.GamepadButtons.Any(b => this.IsGamepadPressed(b))) {
if (this.SelectedElement?.Root != null && this.SelectedElement.CanBePressed) if (this.SelectedElement?.Root != null && this.SelectedElement.CanBePressed)
this.System.OnElementPressed?.Invoke(this.SelectedElement); this.UiSystem.OnElementPressed?.Invoke(this.SelectedElement);
} else if (this.SecondaryGamepadButtons.Any(b => this.IsGamepadPressed(b))) { } else if (this.SecondaryGamepadButtons.Any(b => this.IsGamepadPressed(b))) {
if (this.SelectedElement?.Root != null && this.SelectedElement.CanBePressed) if (this.SelectedElement?.Root != null && this.SelectedElement.CanBePressed)
this.System.OnElementSecondaryPressed?.Invoke(this.SelectedElement); this.UiSystem.OnElementSecondaryPressed?.Invoke(this.SelectedElement);
} else if (this.DownButtons.Any(this.IsGamepadPressed)) { } else if (this.DownButtons.Any(this.IsGamepadPressed)) {
this.HandleGamepadNextElement(Direction2.Down); this.HandleGamepadNextElement(Direction2.Down);
} else if (this.LeftButtons.Any(this.IsGamepadPressed)) { } else if (this.LeftButtons.Any(this.IsGamepadPressed)) {
@ -134,7 +134,7 @@ namespace MLEM.Ui {
} }
public virtual Element GetElementUnderPos(Vector2 position, bool transform = true) { public virtual Element GetElementUnderPos(Vector2 position, bool transform = true) {
foreach (var root in this.System.GetRootElements()) { foreach (var root in this.UiSystem.GetRootElements()) {
var pos = transform ? Vector2.Transform(position, root.InvTransform) : position; var pos = transform ? Vector2.Transform(position, root.InvTransform) : position;
var moused = root.Element.GetElementUnderPos(pos); var moused = root.Element.GetElementUnderPos(pos);
if (moused != null) if (moused != null)
@ -146,7 +146,7 @@ namespace MLEM.Ui {
protected virtual Element GetTabNextElement(bool backward) { protected virtual Element GetTabNextElement(bool backward) {
if (this.ActiveRoot == null) if (this.ActiveRoot == null)
return null; return null;
var children = this.ActiveRoot.Element.GetChildren(c => !c.IsHidden, true, true).Append(this.ActiveRoot.Element); var children = this.ActiveRoot.Element.GetChildren(c => !c.IsHidden, true, true).Concat(new[] {this.ActiveRoot.Element});
if (this.SelectedElement?.Root != this.ActiveRoot) { if (this.SelectedElement?.Root != this.ActiveRoot) {
return backward ? children.LastOrDefault(c => c.CanBeSelected) : children.FirstOrDefault(c => c.CanBeSelected); return backward ? children.LastOrDefault(c => c.CanBeSelected) : children.FirstOrDefault(c => c.CanBeSelected);
} else { } else {
@ -174,7 +174,7 @@ namespace MLEM.Ui {
protected virtual Element GetGamepadNextElement(RectangleF searchArea) { protected virtual Element GetGamepadNextElement(RectangleF searchArea) {
if (this.ActiveRoot == null) if (this.ActiveRoot == null)
return null; return null;
var children = this.ActiveRoot.Element.GetChildren(c => !c.IsHidden, true, true).Append(this.ActiveRoot.Element); var children = this.ActiveRoot.Element.GetChildren(c => !c.IsHidden, true, true).Concat(new[] {this.ActiveRoot.Element});
if (this.SelectedElement?.Root != this.ActiveRoot) { if (this.SelectedElement?.Root != this.ActiveRoot) {
return children.FirstOrDefault(c => c.CanBeSelected); return children.FirstOrDefault(c => c.CanBeSelected);
} else { } else {
@ -202,7 +202,7 @@ namespace MLEM.Ui {
RectangleF searchArea = default; RectangleF searchArea = default;
if (this.SelectedElement?.Root != null) { if (this.SelectedElement?.Root != null) {
searchArea = this.SelectedElement.Area; searchArea = this.SelectedElement.Area;
var (_, _, width, height) = this.System.Viewport; var (_, _, width, height) = this.UiSystem.Viewport;
switch (dir) { switch (dir) {
case Direction2.Down: case Direction2.Down:
searchArea.Height += height; searchArea.Height += height;

View file

@ -42,7 +42,7 @@ namespace MLEM.Ui {
set { set {
this.style = value; this.style = value;
foreach (var root in this.rootElements) { foreach (var root in this.rootElements) {
root.Element.AndChildren(e => e.System = this); root.Element.AndChildren(e => e.UiSystem = this);
root.Element.SetAreaDirty(); root.Element.SetAreaDirty();
} }
} }
@ -85,7 +85,7 @@ namespace MLEM.Ui {
this.OnMousedElementChanged = e => this.ApplyToAll(t => t.OnMousedElementChanged?.Invoke(t, e)); this.OnMousedElementChanged = e => this.ApplyToAll(t => t.OnMousedElementChanged?.Invoke(t, e));
this.OnSelectedElementChanged = e => this.ApplyToAll(t => t.OnSelectedElementChanged?.Invoke(t, e)); this.OnSelectedElementChanged = e => this.ApplyToAll(t => t.OnSelectedElementChanged?.Invoke(t, e));
this.OnSelectedElementDrawn = (element, time, batch, alpha) => { this.OnSelectedElementDrawn = (element, time, batch, alpha) => {
if (this.Controls.IsAutoNavMode && element.SelectionIndicator.Value != null) { if (this.Controls.IsAutoNavMode && element.SelectionIndicator != null) {
batch.Draw(element.SelectionIndicator, element.DisplayArea, Color.White * alpha, element.Scale / 2); batch.Draw(element.SelectionIndicator, element.DisplayArea, Color.White * alpha, element.Scale / 2);
} }
}; };
@ -134,7 +134,7 @@ namespace MLEM.Ui {
this.rootElements.Add(root); this.rootElements.Add(root);
root.Element.AndChildren(e => { root.Element.AndChildren(e => {
e.Root = root; e.Root = root;
e.System = this; e.UiSystem = this;
root.OnElementAdded(e); root.OnElementAdded(e);
e.SetAreaDirty(); e.SetAreaDirty();
}); });
@ -151,7 +151,7 @@ namespace MLEM.Ui {
root.SelectElement(null); root.SelectElement(null);
root.Element.AndChildren(e => { root.Element.AndChildren(e => {
e.Root = null; e.Root = null;
e.System = null; e.UiSystem = null;
root.OnElementRemoved(e); root.OnElementRemoved(e);
e.SetAreaDirty(); e.SetAreaDirty();
}); });
@ -192,7 +192,7 @@ namespace MLEM.Ui {
public readonly string Name; public readonly string Name;
public readonly Element Element; public readonly Element Element;
public readonly UiSystem System; public readonly UiSystem UiSystem;
private float scale = 1; private float scale = 1;
public float Scale { public float Scale {
get => this.scale; get => this.scale;
@ -208,10 +208,10 @@ namespace MLEM.Ui {
get => this.priority; get => this.priority;
set { set {
this.priority = value; this.priority = value;
this.System.SortRoots(); this.UiSystem.SortRoots();
} }
} }
public float ActualScale => this.System.GlobalScale * this.Scale; public float ActualScale => this.UiSystem.GlobalScale * this.Scale;
public Matrix Transform = Matrix.Identity; public Matrix Transform = Matrix.Identity;
public Matrix InvTransform => Matrix.Invert(this.Transform); public Matrix InvTransform => Matrix.Invert(this.Transform);
@ -222,10 +222,10 @@ namespace MLEM.Ui {
public Element.GenericCallback OnElementAdded; public Element.GenericCallback OnElementAdded;
public Element.GenericCallback OnElementRemoved; public Element.GenericCallback OnElementRemoved;
public RootElement(string name, Element element, UiSystem system) { public RootElement(string name, Element element, UiSystem uiSystem) {
this.Name = name; this.Name = name;
this.Element = element; this.Element = element;
this.System = system; this.UiSystem = uiSystem;
this.OnElementAdded += e => { this.OnElementAdded += e => {
if (e.CanBeSelected) if (e.CanBeSelected)
@ -242,11 +242,11 @@ namespace MLEM.Ui {
return; return;
if (this.SelectedElement != null) if (this.SelectedElement != null)
this.System.OnElementDeselected?.Invoke(this.SelectedElement); this.UiSystem.OnElementDeselected?.Invoke(this.SelectedElement);
if (element != null) if (element != null)
this.System.OnElementSelected?.Invoke(element); this.UiSystem.OnElementSelected?.Invoke(element);
this.SelectedElement = element; this.SelectedElement = element;
this.System.OnSelectedElementChanged?.Invoke(element); this.UiSystem.OnSelectedElementChanged?.Invoke(element);
} }
} }

View file

@ -24,7 +24,9 @@ namespace MLEM.Extensions {
private static class TextInputAdder { private static class TextInputAdder {
public static void Add(GameWindow window, TextInputCallback callback) { public static void Add(GameWindow window, TextInputCallback callback) {
#if !WEB
window.TextInput += (sender, args) => callback(sender, args.Key, args.Character); window.TextInput += (sender, args) => callback(sender, args.Key, args.Character);
#endif
} }
} }

View file

@ -27,8 +27,13 @@ namespace MLEM.Formatting {
// color codes // color codes
var colors = typeof(Color).GetProperties(); var colors = typeof(Color).GetProperties();
foreach (var color in colors) { foreach (var color in colors) {
#if !WEB
if (color.GetGetMethod().IsStatic) if (color.GetGetMethod().IsStatic)
FormattingCodes[color.Name.ToLowerInvariant()] = new FormattingCode((Color) color.GetValue(null)); FormattingCodes[color.Name.ToLowerInvariant()] = new FormattingCode((Color) color.GetValue(null));
#else
if (color.GetMethod.IsStatic)
FormattingCodes[color.Name.ToLower()] = new FormattingCode((Color) color.GetValue(null));
#endif
} }
// animations // animations
@ -139,7 +144,7 @@ namespace MLEM.Formatting {
} }
private static FormattingCode FromMatch(Capture match) { private static FormattingCode FromMatch(Capture match) {
var rawCode = match.Value.Substring(1, match.Value.Length - 2).ToLowerInvariant(); var rawCode = match.Value.Substring(1, match.Value.Length - 2).ToLower();
FormattingCodes.TryGetValue(rawCode, out var val); FormattingCodes.TryGetValue(rawCode, out var val);
return val; return val;
} }

View file

@ -270,6 +270,7 @@ namespace MLEM.Input {
return true; return true;
} }
} }
sample = default(GestureSample);
return false; return false;
} }

View file

@ -7,7 +7,7 @@ namespace MLEM.Misc {
[DataContract] [DataContract]
public struct RectangleF : IEquatable<RectangleF> { public struct RectangleF : IEquatable<RectangleF> {
public static RectangleF Empty => default; public static RectangleF Empty => default(RectangleF);
[DataMember] [DataMember]
public float X; public float X;

View file

@ -40,7 +40,7 @@ namespace MLEM.Pathfinding {
} }
protected override float GetManhattanDistance(Vector3 first, Vector3 second) { protected override float GetManhattanDistance(Vector3 first, Vector3 second) {
return Math.Abs(second.X - first.X) + Math.Abs(second.Y - first.Y) + Math.Abs(second.Z - first.Z); return (float)(Math.Abs(second.X - first.X) + Math.Abs(second.Y - first.Y) + Math.Abs(second.Z - first.Z));
} }
} }