mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-22 12:58:33 +01:00
parent
ee5111372b
commit
b3331834e1
15 changed files with 67 additions and 83 deletions
|
@ -17,21 +17,21 @@
|
|||
/importer:FontDescriptionImporter
|
||||
/processor:FontDescriptionProcessor
|
||||
/processorParam:PremultiplyAlpha=True
|
||||
/processorParam:TextureFormat=Color
|
||||
/processorParam:TextureFormat=Compressed
|
||||
/build:Fonts/TestFont.spritefont
|
||||
|
||||
#begin Fonts/TestFontBold.spritefont
|
||||
/importer:FontDescriptionImporter
|
||||
/processor:FontDescriptionProcessor
|
||||
/processorParam:PremultiplyAlpha=True
|
||||
/processorParam:TextureFormat=Color
|
||||
/processorParam:TextureFormat=Compressed
|
||||
/build:Fonts/TestFontBold.spritefont
|
||||
|
||||
#begin Fonts/TestFontItalic.spritefont
|
||||
/importer:FontDescriptionImporter
|
||||
/processor:FontDescriptionProcessor
|
||||
/processorParam:PremultiplyAlpha=True
|
||||
/processorParam:TextureFormat=Color
|
||||
/processorParam:TextureFormat=Compressed
|
||||
/build:Fonts/TestFontItalic.spritefont
|
||||
|
||||
#begin Textures/Anim.png
|
||||
|
|
|
@ -85,16 +85,16 @@ namespace MLEM.Ui.Elements {
|
|||
public TabNextElementCallback GetTabNextElement;
|
||||
public GamepadNextElementCallback GetGamepadNextElement;
|
||||
|
||||
private UiSystem uiSystem;
|
||||
public UiSystem UiSystem {
|
||||
get => this.uiSystem;
|
||||
private UiSystem system;
|
||||
public UiSystem System {
|
||||
get => this.system;
|
||||
internal set {
|
||||
this.uiSystem = value;
|
||||
if (this.uiSystem != null)
|
||||
this.InitStyle(this.uiSystem.Style);
|
||||
this.system = value;
|
||||
if (this.system != null)
|
||||
this.InitStyle(this.system.Style);
|
||||
}
|
||||
}
|
||||
protected UiControls Controls => this.UiSystem.Controls;
|
||||
protected UiControls Controls => this.System.Controls;
|
||||
protected InputHandler Input => this.Controls.Input;
|
||||
public RootElement Root { get; internal set; }
|
||||
public float Scale => this.Root.ActualScale;
|
||||
|
@ -166,7 +166,7 @@ namespace MLEM.Ui.Elements {
|
|||
element.Parent = this;
|
||||
element.AndChildren(e => {
|
||||
e.Root = this.Root;
|
||||
e.UiSystem = this.UiSystem;
|
||||
e.System = this.System;
|
||||
if (this.Root != null)
|
||||
this.Root.OnElementAdded(e);
|
||||
});
|
||||
|
@ -180,7 +180,7 @@ namespace MLEM.Ui.Elements {
|
|||
element.Parent = null;
|
||||
element.AndChildren(e => {
|
||||
e.Root = null;
|
||||
e.UiSystem = null;
|
||||
e.System = null;
|
||||
if (this.Root != null)
|
||||
this.Root.OnElementRemoved(e);
|
||||
});
|
||||
|
@ -230,7 +230,7 @@ namespace MLEM.Ui.Elements {
|
|||
if (this.IsHidden)
|
||||
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 parentCenterY = parentArea.Y + parentArea.Height / 2;
|
||||
|
||||
|
@ -314,7 +314,7 @@ namespace MLEM.Ui.Elements {
|
|||
}
|
||||
|
||||
this.area = new RectangleF(pos, actualSize);
|
||||
this.UiSystem.OnElementAreaUpdated?.Invoke(this);
|
||||
this.System.OnElementAreaUpdated?.Invoke(this);
|
||||
|
||||
foreach (var child in this.Children)
|
||||
child.ForceUpdateArea();
|
||||
|
@ -451,15 +451,15 @@ namespace MLEM.Ui.Elements {
|
|||
}
|
||||
|
||||
public virtual void Update(GameTime time) {
|
||||
this.UiSystem.OnElementUpdated?.Invoke(this, time);
|
||||
this.System.OnElementUpdated?.Invoke(this, time);
|
||||
|
||||
foreach (var child in this.GetRelevantChildren())
|
||||
if (child.UiSystem != null)
|
||||
if (child.System != null)
|
||||
child.Update(time);
|
||||
}
|
||||
|
||||
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()) {
|
||||
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)
|
||||
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) {
|
||||
if (this.Texture != null)
|
||||
batch.Draw(this.Texture.Value, this.DisplayArea, Color.White * alpha, this.Scale);
|
||||
if (this.Texture.Value != null)
|
||||
batch.Draw(this.Texture, this.DisplayArea, Color.White * alpha, this.Scale);
|
||||
// if we handle overflow, draw using the render target in DrawUnbound
|
||||
if (!this.scrollOverflow || this.renderTarget == null) {
|
||||
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);
|
||||
|
||||
var percentage = this.CurrentValue / this.MaxValue;
|
||||
var padHor = this.ProgressTexture != null ? this.ProgressTexture.Value.Padding.Width * this.Scale : 0;
|
||||
var padVer = this.ProgressTexture != null ? this.ProgressTexture.Value.Padding.Height * this.Scale : 0;
|
||||
var tex = this.ProgressTexture.Value;
|
||||
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 height = percentage * (this.DisplayArea.Height - padVer) + padVer;
|
||||
RectangleF progressArea;
|
||||
|
@ -60,7 +61,7 @@ namespace MLEM.Ui.Elements {
|
|||
break;
|
||||
}
|
||||
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);
|
||||
} else {
|
||||
batch.Draw(batch.GetBlankTexture(), offsetArea, (Color) this.ProgressColor * alpha);
|
||||
|
|
|
@ -73,7 +73,7 @@ namespace MLEM.Ui.Elements {
|
|||
if (this.isMouseHeld)
|
||||
this.ScrollToPos(this.Input.MousePosition.Transform(this.Root.InvTransform));
|
||||
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)
|
||||
this.CurrentValue += this.StepPerScroll * Math.Sign(scroll);
|
||||
}
|
||||
|
|
|
@ -69,7 +69,6 @@ namespace MLEM.Ui.Elements {
|
|||
}
|
||||
};
|
||||
} else {
|
||||
#if !WEB
|
||||
this.OnPressed += async e => {
|
||||
if (!KeyboardInput.IsVisible) {
|
||||
var title = this.MobileTitle ?? this.PlaceholderText;
|
||||
|
@ -78,7 +77,6 @@ namespace MLEM.Ui.Elements {
|
|||
this.SetText(result.Replace('\n', ' '), true);
|
||||
}
|
||||
};
|
||||
#endif
|
||||
}
|
||||
this.OnDeselected += e => this.CaretPos = 0;
|
||||
this.OnSelected += e => this.CaretPos = this.text.Length;
|
||||
|
@ -86,7 +84,7 @@ namespace MLEM.Ui.Elements {
|
|||
|
||||
private void HandleTextChange(bool textChanged = true) {
|
||||
// not initialized yet
|
||||
if (this.Font == null)
|
||||
if (this.Font.Value == null)
|
||||
return;
|
||||
var length = this.Font.Value.MeasureString(this.text).X * this.TextScale;
|
||||
var maxWidth = this.DisplayArea.Width / this.Scale - this.TextOffsetX * 2;
|
||||
|
|
|
@ -23,12 +23,12 @@ namespace MLEM.Ui.Elements {
|
|||
|
||||
if (elementToHover != null) {
|
||||
elementToHover.OnMouseEnter += element => {
|
||||
element.UiSystem.Add(element.GetType().Name + "Tooltip", this);
|
||||
element.System.Add(element.GetType().Name + "Tooltip", this);
|
||||
this.SnapPositionToMouse();
|
||||
};
|
||||
elementToHover.OnMouseExit += element => {
|
||||
if (this.UiSystem != null)
|
||||
this.UiSystem.Remove(this.Root.Name);
|
||||
if (this.System != null)
|
||||
this.System.Remove(this.Root.Name);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ namespace MLEM.Ui.Elements {
|
|||
}
|
||||
|
||||
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;
|
||||
if (offset.X < 0)
|
||||
offset.X = 0;
|
||||
|
|
|
@ -12,8 +12,9 @@ namespace MLEM.Ui.Style {
|
|||
}
|
||||
|
||||
public void SetFromStyle(T value) {
|
||||
if (!this.isCustom)
|
||||
if (!this.isCustom) {
|
||||
this.Value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public void Set(T value) {
|
||||
|
@ -22,7 +23,7 @@ namespace MLEM.Ui.Style {
|
|||
}
|
||||
|
||||
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) {
|
||||
|
@ -33,13 +34,5 @@ namespace MLEM.Ui.Style {
|
|||
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;
|
||||
protected readonly bool IsInputOurs;
|
||||
protected readonly UiSystem UiSystem;
|
||||
protected readonly UiSystem System;
|
||||
|
||||
public RootElement ActiveRoot { get; private set; }
|
||||
public Element MousedElement { get; private set; }
|
||||
|
@ -34,8 +34,8 @@ namespace MLEM.Ui {
|
|||
|
||||
public bool IsAutoNavMode { get; private set; }
|
||||
|
||||
public UiControls(UiSystem uiSystem, InputHandler inputHandler = null) {
|
||||
this.UiSystem = uiSystem;
|
||||
public UiControls(UiSystem system, InputHandler inputHandler = null) {
|
||||
this.System = system;
|
||||
this.Input = inputHandler ?? new InputHandler();
|
||||
this.IsInputOurs = inputHandler == null;
|
||||
|
||||
|
@ -46,18 +46,18 @@ namespace MLEM.Ui {
|
|||
public virtual void Update() {
|
||||
if (this.IsInputOurs)
|
||||
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
|
||||
if (this.HandleMouse) {
|
||||
var mousedNow = this.GetElementUnderPos(this.Input.MousePosition.ToVector2());
|
||||
if (mousedNow != this.MousedElement) {
|
||||
if (this.MousedElement != null)
|
||||
this.UiSystem.OnElementMouseExit?.Invoke(this.MousedElement);
|
||||
this.System.OnElementMouseExit?.Invoke(this.MousedElement);
|
||||
if (mousedNow != null)
|
||||
this.UiSystem.OnElementMouseEnter?.Invoke(mousedNow);
|
||||
this.System.OnElementMouseEnter?.Invoke(mousedNow);
|
||||
this.MousedElement = mousedNow;
|
||||
this.UiSystem.OnMousedElementChanged?.Invoke(mousedNow);
|
||||
this.System.OnMousedElementChanged?.Invoke(mousedNow);
|
||||
}
|
||||
|
||||
if (this.Input.IsMouseButtonPressed(MouseButton.Left)) {
|
||||
|
@ -65,11 +65,11 @@ namespace MLEM.Ui {
|
|||
var selectedNow = mousedNow != null && mousedNow.CanBeSelected ? mousedNow : null;
|
||||
this.ActiveRoot?.SelectElement(selectedNow);
|
||||
if (mousedNow != null && mousedNow.CanBePressed)
|
||||
this.UiSystem.OnElementPressed?.Invoke(mousedNow);
|
||||
this.System.OnElementPressed?.Invoke(mousedNow);
|
||||
} else if (this.Input.IsMouseButtonPressed(MouseButton.Right)) {
|
||||
this.IsAutoNavMode = false;
|
||||
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.Input.IsModifierKeyDown(ModifierKey.Shift)) {
|
||||
// secondary action on element using space or enter
|
||||
this.UiSystem.OnElementSecondaryPressed?.Invoke(this.SelectedElement);
|
||||
this.System.OnElementSecondaryPressed?.Invoke(this.SelectedElement);
|
||||
} else {
|
||||
// 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)) {
|
||||
|
@ -103,13 +103,13 @@ namespace MLEM.Ui {
|
|||
var tapped = this.GetElementUnderPos(tap.Position);
|
||||
this.ActiveRoot?.SelectElement(tapped);
|
||||
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)) {
|
||||
this.IsAutoNavMode = false;
|
||||
var held = this.GetElementUnderPos(hold.Position);
|
||||
this.ActiveRoot?.SelectElement(held);
|
||||
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.GamepadButtons.Any(b => this.IsGamepadPressed(b))) {
|
||||
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))) {
|
||||
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)) {
|
||||
this.HandleGamepadNextElement(Direction2.Down);
|
||||
} else if (this.LeftButtons.Any(this.IsGamepadPressed)) {
|
||||
|
@ -134,7 +134,7 @@ namespace MLEM.Ui {
|
|||
}
|
||||
|
||||
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 moused = root.Element.GetElementUnderPos(pos);
|
||||
if (moused != null)
|
||||
|
@ -146,7 +146,7 @@ namespace MLEM.Ui {
|
|||
protected virtual Element GetTabNextElement(bool backward) {
|
||||
if (this.ActiveRoot == 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) {
|
||||
return backward ? children.LastOrDefault(c => c.CanBeSelected) : children.FirstOrDefault(c => c.CanBeSelected);
|
||||
} else {
|
||||
|
@ -174,7 +174,7 @@ namespace MLEM.Ui {
|
|||
protected virtual Element GetGamepadNextElement(RectangleF searchArea) {
|
||||
if (this.ActiveRoot == 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) {
|
||||
return children.FirstOrDefault(c => c.CanBeSelected);
|
||||
} else {
|
||||
|
@ -202,7 +202,7 @@ namespace MLEM.Ui {
|
|||
RectangleF searchArea = default;
|
||||
if (this.SelectedElement?.Root != null) {
|
||||
searchArea = this.SelectedElement.Area;
|
||||
var (_, _, width, height) = this.UiSystem.Viewport;
|
||||
var (_, _, width, height) = this.System.Viewport;
|
||||
switch (dir) {
|
||||
case Direction2.Down:
|
||||
searchArea.Height += height;
|
||||
|
|
|
@ -42,7 +42,7 @@ namespace MLEM.Ui {
|
|||
set {
|
||||
this.style = value;
|
||||
foreach (var root in this.rootElements) {
|
||||
root.Element.AndChildren(e => e.UiSystem = this);
|
||||
root.Element.AndChildren(e => e.System = this);
|
||||
root.Element.SetAreaDirty();
|
||||
}
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ namespace MLEM.Ui {
|
|||
this.OnMousedElementChanged = e => this.ApplyToAll(t => t.OnMousedElementChanged?.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 != null) {
|
||||
if (this.Controls.IsAutoNavMode && element.SelectionIndicator.Value != null) {
|
||||
batch.Draw(element.SelectionIndicator, element.DisplayArea, Color.White * alpha, element.Scale / 2);
|
||||
}
|
||||
};
|
||||
|
@ -134,7 +134,7 @@ namespace MLEM.Ui {
|
|||
this.rootElements.Add(root);
|
||||
root.Element.AndChildren(e => {
|
||||
e.Root = root;
|
||||
e.UiSystem = this;
|
||||
e.System = this;
|
||||
root.OnElementAdded(e);
|
||||
e.SetAreaDirty();
|
||||
});
|
||||
|
@ -151,7 +151,7 @@ namespace MLEM.Ui {
|
|||
root.SelectElement(null);
|
||||
root.Element.AndChildren(e => {
|
||||
e.Root = null;
|
||||
e.UiSystem = null;
|
||||
e.System = null;
|
||||
root.OnElementRemoved(e);
|
||||
e.SetAreaDirty();
|
||||
});
|
||||
|
@ -192,7 +192,7 @@ namespace MLEM.Ui {
|
|||
|
||||
public readonly string Name;
|
||||
public readonly Element Element;
|
||||
public readonly UiSystem UiSystem;
|
||||
public readonly UiSystem System;
|
||||
private float scale = 1;
|
||||
public float Scale {
|
||||
get => this.scale;
|
||||
|
@ -208,10 +208,10 @@ namespace MLEM.Ui {
|
|||
get => this.priority;
|
||||
set {
|
||||
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 InvTransform => Matrix.Invert(this.Transform);
|
||||
|
@ -222,10 +222,10 @@ namespace MLEM.Ui {
|
|||
public Element.GenericCallback OnElementAdded;
|
||||
public Element.GenericCallback OnElementRemoved;
|
||||
|
||||
public RootElement(string name, Element element, UiSystem uiSystem) {
|
||||
public RootElement(string name, Element element, UiSystem system) {
|
||||
this.Name = name;
|
||||
this.Element = element;
|
||||
this.UiSystem = uiSystem;
|
||||
this.System = system;
|
||||
|
||||
this.OnElementAdded += e => {
|
||||
if (e.CanBeSelected)
|
||||
|
@ -242,11 +242,11 @@ namespace MLEM.Ui {
|
|||
return;
|
||||
|
||||
if (this.SelectedElement != null)
|
||||
this.UiSystem.OnElementDeselected?.Invoke(this.SelectedElement);
|
||||
this.System.OnElementDeselected?.Invoke(this.SelectedElement);
|
||||
if (element != null)
|
||||
this.UiSystem.OnElementSelected?.Invoke(element);
|
||||
this.System.OnElementSelected?.Invoke(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 {
|
||||
|
||||
public static void Add(GameWindow window, TextInputCallback callback) {
|
||||
#if !WEB
|
||||
window.TextInput += (sender, args) => callback(sender, args.Key, args.Character);
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -27,13 +27,8 @@ namespace MLEM.Formatting {
|
|||
// color codes
|
||||
var colors = typeof(Color).GetProperties();
|
||||
foreach (var color in colors) {
|
||||
#if !WEB
|
||||
if (color.GetGetMethod().IsStatic)
|
||||
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
|
||||
|
@ -144,7 +139,7 @@ namespace MLEM.Formatting {
|
|||
}
|
||||
|
||||
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);
|
||||
return val;
|
||||
}
|
||||
|
|
|
@ -270,7 +270,6 @@ namespace MLEM.Input {
|
|||
return true;
|
||||
}
|
||||
}
|
||||
sample = default(GestureSample);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ namespace MLEM.Misc {
|
|||
[DataContract]
|
||||
public struct RectangleF : IEquatable<RectangleF> {
|
||||
|
||||
public static RectangleF Empty => default(RectangleF);
|
||||
public static RectangleF Empty => default;
|
||||
|
||||
[DataMember]
|
||||
public float X;
|
||||
|
|
|
@ -40,7 +40,7 @@ namespace MLEM.Pathfinding {
|
|||
}
|
||||
|
||||
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