mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-22 20:58:34 +01:00
made dropdowns only have high priority when opened and fixed panels sometimes ignoring priority
This commit is contained in:
parent
89f957f8b6
commit
4888bb0fd7
3 changed files with 45 additions and 32 deletions
|
@ -6,15 +6,19 @@ namespace MLEM.Ui.Elements {
|
||||||
public readonly Panel Panel;
|
public readonly Panel Panel;
|
||||||
public bool IsOpen {
|
public bool IsOpen {
|
||||||
get => !this.Panel.IsHidden;
|
get => !this.Panel.IsHidden;
|
||||||
set => this.Panel.IsHidden = !value;
|
set {
|
||||||
|
this.Panel.IsHidden = !value;
|
||||||
|
this.OnOpenedOrClosed?.Invoke(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
public GenericCallback OnOpenedOrClosed;
|
||||||
|
|
||||||
public Dropdown(Anchor anchor, Vector2 size, string text = null, string tooltipText = null, float tooltipWidth = 50) : base(anchor, size, text, tooltipText, tooltipWidth) {
|
public Dropdown(Anchor anchor, Vector2 size, string text = null, string tooltipText = null, float tooltipWidth = 50) : base(anchor, size, text, tooltipText, tooltipWidth) {
|
||||||
this.Panel = this.AddChild(new Panel(Anchor.TopCenter, size, Vector2.Zero, true) {
|
this.Panel = this.AddChild(new Panel(Anchor.TopCenter, size, Vector2.Zero, true) {
|
||||||
IsHidden = true
|
IsHidden = true
|
||||||
});
|
});
|
||||||
this.OnAreaUpdated += e => this.Panel.PositionOffset = new Vector2(0, e.Area.Height / this.Scale);
|
this.OnAreaUpdated += e => this.Panel.PositionOffset = new Vector2(0, e.Area.Height / this.Scale);
|
||||||
this.Priority = 10000;
|
this.OnOpenedOrClosed += e => this.Priority = this.IsOpen ? 10000 : 0;
|
||||||
this.OnPressed += e => this.IsOpen = !this.IsOpen;
|
this.OnPressed += e => this.IsOpen = !this.IsOpen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -189,24 +189,27 @@ namespace MLEM.Ui.Elements {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetAreaDirty() {
|
|
||||||
this.areaDirty = true;
|
|
||||||
if (this.Anchor >= Anchor.AutoLeft && this.Parent != null)
|
|
||||||
this.Parent.SetAreaDirty();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetSortedChildrenDirty() {
|
public void SetSortedChildrenDirty() {
|
||||||
this.sortedChildrenDirty = true;
|
this.sortedChildrenDirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateSortedChildrenIfDirty() {
|
public void UpdateSortedChildrenIfDirty() {
|
||||||
if (this.sortedChildrenDirty) {
|
if (this.sortedChildrenDirty)
|
||||||
this.sortedChildrenDirty = false;
|
this.ForceUpdateSortedChildren();
|
||||||
|
}
|
||||||
|
|
||||||
this.sortedChildren.Clear();
|
public virtual void ForceUpdateSortedChildren() {
|
||||||
this.sortedChildren.AddRange(this.Children);
|
this.sortedChildrenDirty = false;
|
||||||
this.sortedChildren.Sort((e1, e2) => e1.Priority.CompareTo(e2.Priority));
|
|
||||||
}
|
this.sortedChildren.Clear();
|
||||||
|
this.sortedChildren.AddRange(this.Children);
|
||||||
|
this.sortedChildren.Sort((e1, e2) => e1.Priority.CompareTo(e2.Priority));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetAreaDirty() {
|
||||||
|
this.areaDirty = true;
|
||||||
|
if (this.Anchor >= Anchor.AutoLeft && this.Parent != null)
|
||||||
|
this.Parent.SetAreaDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateAreaIfDirty() {
|
public void UpdateAreaIfDirty() {
|
||||||
|
|
|
@ -97,30 +97,36 @@ namespace MLEM.Ui.Elements {
|
||||||
this.relevantChildrenDirty = true;
|
this.relevantChildrenDirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Update(GameTime time) {
|
public override void ForceUpdateSortedChildren() {
|
||||||
base.Update(time);
|
base.ForceUpdateSortedChildren();
|
||||||
if (this.relevantChildrenDirty) {
|
if (this.scrollOverflow)
|
||||||
this.relevantChildrenDirty = false;
|
this.relevantChildrenDirty = true;
|
||||||
|
}
|
||||||
|
|
||||||
var visible = this.GetRenderTargetArea();
|
protected override List<Element> GetRelevantChildren() {
|
||||||
this.relevantChildren.Clear();
|
var relevant = base.GetRelevantChildren();
|
||||||
foreach (var child in this.SortedChildren) {
|
if (this.scrollOverflow) {
|
||||||
if (child.Area.Intersects(visible)) {
|
if (this.relevantChildrenDirty) {
|
||||||
this.relevantChildren.Add(child);
|
this.relevantChildrenDirty = false;
|
||||||
} else {
|
|
||||||
foreach (var c in child.GetChildren(regardGrandchildren: true)) {
|
var visible = this.GetRenderTargetArea();
|
||||||
if (c.Area.Intersects(visible)) {
|
this.relevantChildren.Clear();
|
||||||
this.relevantChildren.Add(child);
|
foreach (var child in this.SortedChildren) {
|
||||||
break;
|
if (child.Area.Intersects(visible)) {
|
||||||
|
this.relevantChildren.Add(child);
|
||||||
|
} else {
|
||||||
|
foreach (var c in child.GetChildren(regardGrandchildren: true)) {
|
||||||
|
if (c.Area.Intersects(visible)) {
|
||||||
|
this.relevantChildren.Add(child);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
relevant = this.relevantChildren;
|
||||||
}
|
}
|
||||||
}
|
return relevant;
|
||||||
|
|
||||||
protected override List<Element> GetRelevantChildren() {
|
|
||||||
return this.scrollOverflow ? this.relevantChildren : base.GetRelevantChildren();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
|
|
Loading…
Reference in a new issue