mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-22 20:58:34 +01:00
parent
ee5111372b
commit
b3331834e1
15 changed files with 67 additions and 83 deletions
|
@ -17,21 +17,21 @@
|
||||||
/importer:FontDescriptionImporter
|
/importer:FontDescriptionImporter
|
||||||
/processor:FontDescriptionProcessor
|
/processor:FontDescriptionProcessor
|
||||||
/processorParam:PremultiplyAlpha=True
|
/processorParam:PremultiplyAlpha=True
|
||||||
/processorParam:TextureFormat=Color
|
/processorParam:TextureFormat=Compressed
|
||||||
/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=Color
|
/processorParam:TextureFormat=Compressed
|
||||||
/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=Color
|
/processorParam:TextureFormat=Compressed
|
||||||
/build:Fonts/TestFontItalic.spritefont
|
/build:Fonts/TestFontItalic.spritefont
|
||||||
|
|
||||||
#begin Textures/Anim.png
|
#begin Textures/Anim.png
|
||||||
|
|
|
@ -85,16 +85,16 @@ namespace MLEM.Ui.Elements {
|
||||||
public TabNextElementCallback GetTabNextElement;
|
public TabNextElementCallback GetTabNextElement;
|
||||||
public GamepadNextElementCallback GetGamepadNextElement;
|
public GamepadNextElementCallback GetGamepadNextElement;
|
||||||
|
|
||||||
private UiSystem uiSystem;
|
private UiSystem system;
|
||||||
public UiSystem UiSystem {
|
public UiSystem System {
|
||||||
get => this.uiSystem;
|
get => this.system;
|
||||||
internal set {
|
internal set {
|
||||||
this.uiSystem = value;
|
this.system = value;
|
||||||
if (this.uiSystem != null)
|
if (this.system != null)
|
||||||
this.InitStyle(this.uiSystem.Style);
|
this.InitStyle(this.system.Style);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
protected UiControls Controls => this.UiSystem.Controls;
|
protected UiControls Controls => this.System.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.UiSystem = this.UiSystem;
|
e.System = this.System;
|
||||||
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.UiSystem = null;
|
e.System = 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.uiSystem.Viewport;
|
var parentArea = this.Parent != null ? this.Parent.ChildPaddedArea : (RectangleF) this.system.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.UiSystem.OnElementAreaUpdated?.Invoke(this);
|
this.System.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.UiSystem.OnElementUpdated?.Invoke(this, time);
|
this.System.OnElementUpdated?.Invoke(this, time);
|
||||||
|
|
||||||
foreach (var child in this.GetRelevantChildren())
|
foreach (var child in this.GetRelevantChildren())
|
||||||
if (child.UiSystem != null)
|
if (child.System != 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.UiSystem.OnElementDrawn?.Invoke(this, time, batch, alpha);
|
this.System.OnElementDrawn?.Invoke(this, time, batch, alpha);
|
||||||
|
|
||||||
foreach (var child in this.GetRelevantChildren()) {
|
foreach (var child in this.GetRelevantChildren()) {
|
||||||
if (!child.IsHidden)
|
if (!child.IsHidden)
|
||||||
|
|
|
@ -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.UiSystem.GraphicsDevice, targetArea.Width, targetArea.Height);
|
this.renderTarget = targetArea.IsEmpty ? null : new RenderTarget2D(this.System.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 != null)
|
if (this.Texture.Value != null)
|
||||||
batch.Draw(this.Texture.Value, this.DisplayArea, Color.White * alpha, this.Scale);
|
batch.Draw(this.Texture, 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);
|
||||||
|
|
|
@ -36,8 +36,9 @@ 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 padHor = this.ProgressTexture != null ? this.ProgressTexture.Value.Padding.Width * this.Scale : 0;
|
var tex = this.ProgressTexture.Value;
|
||||||
var padVer = this.ProgressTexture != null ? this.ProgressTexture.Value.Padding.Height * this.Scale : 0;
|
var padHor = tex != null ? tex.Padding.Width * 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;
|
||||||
|
@ -60,7 +61,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 != null) {
|
if (this.ProgressTexture.Value != 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);
|
||||||
|
|
|
@ -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))) {
|
||||||
double scroll = this.Input.LastScrollWheel - this.Input.ScrollWheel;
|
var 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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,6 @@ 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;
|
||||||
|
@ -78,7 +77,6 @@ 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;
|
||||||
|
@ -86,7 +84,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 == null)
|
if (this.Font.Value == 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;
|
||||||
|
|
|
@ -23,12 +23,12 @@ namespace MLEM.Ui.Elements {
|
||||||
|
|
||||||
if (elementToHover != null) {
|
if (elementToHover != null) {
|
||||||
elementToHover.OnMouseEnter += element => {
|
elementToHover.OnMouseEnter += element => {
|
||||||
element.UiSystem.Add(element.GetType().Name + "Tooltip", this);
|
element.System.Add(element.GetType().Name + "Tooltip", this);
|
||||||
this.SnapPositionToMouse();
|
this.SnapPositionToMouse();
|
||||||
};
|
};
|
||||||
elementToHover.OnMouseExit += element => {
|
elementToHover.OnMouseExit += element => {
|
||||||
if (this.UiSystem != null)
|
if (this.System != null)
|
||||||
this.UiSystem.Remove(this.Root.Name);
|
this.System.Remove(this.Root.Name);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ namespace MLEM.Ui.Elements {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SnapPositionToMouse() {
|
public void SnapPositionToMouse() {
|
||||||
var viewport = this.UiSystem.Viewport.Size;
|
var viewport = this.System.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;
|
||||||
|
|
|
@ -12,8 +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) {
|
||||||
|
@ -22,7 +23,7 @@ namespace MLEM.Ui.Style {
|
||||||
}
|
}
|
||||||
|
|
||||||
public T OrDefault(T def) {
|
public T OrDefault(T def) {
|
||||||
return EqualityComparer<T>.Default.Equals(this.Value, default(T)) ? def : this.Value;
|
return EqualityComparer<T>.Default.Equals(this.Value, default) ? def : this.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static implicit operator T(StyleProp<T> prop) {
|
public static implicit operator T(StyleProp<T> prop) {
|
||||||
|
@ -33,13 +34,5 @@ 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -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 UiSystem;
|
protected readonly UiSystem System;
|
||||||
|
|
||||||
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 uiSystem, InputHandler inputHandler = null) {
|
public UiControls(UiSystem system, InputHandler inputHandler = null) {
|
||||||
this.UiSystem = uiSystem;
|
this.System = system;
|
||||||
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.UiSystem.GetRootElements().FirstOrDefault(root => root.CanSelectContent && !root.Element.IsHidden);
|
this.ActiveRoot = this.System.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.UiSystem.OnElementMouseExit?.Invoke(this.MousedElement);
|
this.System.OnElementMouseExit?.Invoke(this.MousedElement);
|
||||||
if (mousedNow != null)
|
if (mousedNow != null)
|
||||||
this.UiSystem.OnElementMouseEnter?.Invoke(mousedNow);
|
this.System.OnElementMouseEnter?.Invoke(mousedNow);
|
||||||
this.MousedElement = mousedNow;
|
this.MousedElement = mousedNow;
|
||||||
this.UiSystem.OnMousedElementChanged?.Invoke(mousedNow);
|
this.System.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.UiSystem.OnElementPressed?.Invoke(mousedNow);
|
this.System.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.UiSystem.OnElementSecondaryPressed?.Invoke(mousedNow);
|
this.System.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.UiSystem.OnElementSecondaryPressed?.Invoke(this.SelectedElement);
|
this.System.OnElementSecondaryPressed?.Invoke(this.SelectedElement);
|
||||||
} else {
|
} else {
|
||||||
// first action on element using space or enter
|
// first action on element using space or enter
|
||||||
this.UiSystem.OnElementPressed?.Invoke(this.SelectedElement);
|
this.System.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.UiSystem.OnElementPressed?.Invoke(tapped);
|
this.System.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.UiSystem.OnElementSecondaryPressed?.Invoke(held);
|
this.System.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.UiSystem.OnElementPressed?.Invoke(this.SelectedElement);
|
this.System.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.UiSystem.OnElementSecondaryPressed?.Invoke(this.SelectedElement);
|
this.System.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.UiSystem.GetRootElements()) {
|
foreach (var root in this.System.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).Concat(new[] {this.ActiveRoot.Element});
|
var children = this.ActiveRoot.Element.GetChildren(c => !c.IsHidden, true, true).Append(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).Concat(new[] {this.ActiveRoot.Element});
|
var children = this.ActiveRoot.Element.GetChildren(c => !c.IsHidden, true, true).Append(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.UiSystem.Viewport;
|
var (_, _, width, height) = this.System.Viewport;
|
||||||
switch (dir) {
|
switch (dir) {
|
||||||
case Direction2.Down:
|
case Direction2.Down:
|
||||||
searchArea.Height += height;
|
searchArea.Height += height;
|
||||||
|
|
|
@ -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.UiSystem = this);
|
root.Element.AndChildren(e => e.System = 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 != null) {
|
if (this.Controls.IsAutoNavMode && element.SelectionIndicator.Value != 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.UiSystem = this;
|
e.System = 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.UiSystem = null;
|
e.System = 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 UiSystem;
|
public readonly UiSystem System;
|
||||||
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.UiSystem.SortRoots();
|
this.System.SortRoots();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public float ActualScale => this.UiSystem.GlobalScale * this.Scale;
|
public float ActualScale => this.System.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 uiSystem) {
|
public RootElement(string name, Element element, UiSystem system) {
|
||||||
this.Name = name;
|
this.Name = name;
|
||||||
this.Element = element;
|
this.Element = element;
|
||||||
this.UiSystem = uiSystem;
|
this.System = system;
|
||||||
|
|
||||||
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.UiSystem.OnElementDeselected?.Invoke(this.SelectedElement);
|
this.System.OnElementDeselected?.Invoke(this.SelectedElement);
|
||||||
if (element != null)
|
if (element != null)
|
||||||
this.UiSystem.OnElementSelected?.Invoke(element);
|
this.System.OnElementSelected?.Invoke(element);
|
||||||
this.SelectedElement = element;
|
this.SelectedElement = element;
|
||||||
this.UiSystem.OnSelectedElementChanged?.Invoke(element);
|
this.System.OnSelectedElementChanged?.Invoke(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,9 +24,7 @@ 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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,13 +27,8 @@ 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
|
||||||
|
@ -144,7 +139,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).ToLower();
|
var rawCode = match.Value.Substring(1, match.Value.Length - 2).ToLowerInvariant();
|
||||||
FormattingCodes.TryGetValue(rawCode, out var val);
|
FormattingCodes.TryGetValue(rawCode, out var val);
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
|
@ -270,7 +270,6 @@ namespace MLEM.Input {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sample = default(GestureSample);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ namespace MLEM.Misc {
|
||||||
[DataContract]
|
[DataContract]
|
||||||
public struct RectangleF : IEquatable<RectangleF> {
|
public struct RectangleF : IEquatable<RectangleF> {
|
||||||
|
|
||||||
public static RectangleF Empty => default(RectangleF);
|
public static RectangleF Empty => default;
|
||||||
|
|
||||||
[DataMember]
|
[DataMember]
|
||||||
public float X;
|
public float X;
|
||||||
|
|
|
@ -40,7 +40,7 @@ namespace MLEM.Pathfinding {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override float GetManhattanDistance(Vector3 first, Vector3 second) {
|
protected override float GetManhattanDistance(Vector3 first, Vector3 second) {
|
||||||
return (float)(Math.Abs(second.X - first.X) + Math.Abs(second.Y - first.Y) + Math.Abs(second.Z - first.Z));
|
return Math.Abs(second.X - first.X) + Math.Abs(second.Y - first.Y) + Math.Abs(second.Z - first.Z);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue