1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-06-29 07:48:20 +02:00

made dropdowns only have high priority when opened and fixed panels sometimes ignoring priority

This commit is contained in:
Ellpeck 2019-11-18 22:36:55 +01:00
parent 89f957f8b6
commit 4888bb0fd7
3 changed files with 45 additions and 32 deletions

View file

@ -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;
} }

View file

@ -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.ForceUpdateSortedChildren();
}
public virtual void ForceUpdateSortedChildren() {
this.sortedChildrenDirty = false; this.sortedChildrenDirty = false;
this.sortedChildren.Clear(); this.sortedChildren.Clear();
this.sortedChildren.AddRange(this.Children); this.sortedChildren.AddRange(this.Children);
this.sortedChildren.Sort((e1, e2) => e1.Priority.CompareTo(e2.Priority)); 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() {

View file

@ -97,8 +97,15 @@ 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.scrollOverflow)
this.relevantChildrenDirty = true;
}
protected override List<Element> GetRelevantChildren() {
var relevant = base.GetRelevantChildren();
if (this.scrollOverflow) {
if (this.relevantChildrenDirty) { if (this.relevantChildrenDirty) {
this.relevantChildrenDirty = false; this.relevantChildrenDirty = false;
@ -117,10 +124,9 @@ namespace MLEM.Ui.Elements {
} }
} }
} }
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) {