1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-06-07 15:23:37 +02:00

made link clusters be selected properly

This commit is contained in:
Ellpeck 2020-05-27 15:19:17 +02:00
parent 5de1674351
commit b270fe3977
2 changed files with 11 additions and 16 deletions

View file

@ -250,11 +250,11 @@ namespace MLEM.Ui.Elements {
/// <summary>
/// Stores whether this element is currently being moused over.
/// </summary>
public bool IsMouseOver { get; private set; }
public bool IsMouseOver { get; protected set; }
/// <summary>
/// Stores whether this element is its <see cref="Root"/>'s <see cref="RootElement.SelectedElement"/>.
/// </summary>
public bool IsSelected { get; private set; }
public bool IsSelected { get; protected set; }
/// <summary>
/// Event that is called after this element is drawn, but before its children are drawn
@ -768,7 +768,7 @@ namespace MLEM.Ui.Elements {
/// <param name="matrix">The transformation matrix that is used for drawing</param>
public virtual void Draw(GameTime time, SpriteBatch batch, float alpha, BlendState blendState, SamplerState samplerState, Matrix matrix) {
this.System.OnElementDrawn?.Invoke(this, time, batch, alpha);
if (this.Controls.SelectedElement == this)
if (this.IsSelected)
this.System.OnSelectedElementDrawn?.Invoke(this, time, batch, alpha);
foreach (var child in this.GetRelevantChildren()) {

View file

@ -232,6 +232,14 @@ namespace MLEM.Ui.Elements {
public Link(Anchor anchor, Token token, Vector2 size, Link[] linkCluster) : base(anchor, size) {
this.Token = token;
this.LinkCluster = linkCluster;
this.OnSelected += e => {
foreach (var link in this.LinkCluster)
link.IsSelected = true;
};
this.OnDeselected += e => {
foreach (var link in this.LinkCluster)
link.IsSelected = false;
};
this.OnPressed += e => {
foreach (var code in token.AppliedCodes.OfType<LinkCode>()) {
try {
@ -243,19 +251,6 @@ namespace MLEM.Ui.Elements {
};
}
/// <inheritdoc />
public override void Draw(GameTime time, SpriteBatch batch, float alpha, BlendState blendState, SamplerState samplerState, Matrix matrix) {
if (this.LinkCluster.Length > 1 && this.Controls.SelectedElement == this) {
// also draw the selection box around all other links in the cluster
foreach (var link in this.LinkCluster) {
if (link == this)
continue;
this.System.OnSelectedElementDrawn?.Invoke(link, time, batch, alpha);
}
}
base.Draw(time, batch, alpha, blendState, samplerState, matrix);
}
}
}