mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-26 14:38:34 +01:00
added the ability to add sounds to elements
This commit is contained in:
parent
deaa841657
commit
9aebce96e8
3 changed files with 16 additions and 5 deletions
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
|
using Microsoft.Xna.Framework.Audio;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
using Microsoft.Xna.Framework.Input;
|
using Microsoft.Xna.Framework.Input;
|
||||||
using MLEM.Extensions;
|
using MLEM.Extensions;
|
||||||
|
@ -140,6 +141,8 @@ namespace MLEM.Ui.Elements {
|
||||||
private bool areaDirty;
|
private bool areaDirty;
|
||||||
private bool sortedChildrenDirty;
|
private bool sortedChildrenDirty;
|
||||||
public StyleProp<NinePatch> SelectionIndicator;
|
public StyleProp<NinePatch> SelectionIndicator;
|
||||||
|
public StyleProp<SoundEffectInstance> ActionSound;
|
||||||
|
public StyleProp<SoundEffectInstance> SecondActionSound;
|
||||||
|
|
||||||
public Element(Anchor anchor, Vector2 size) {
|
public Element(Anchor anchor, Vector2 size) {
|
||||||
this.anchor = anchor;
|
this.anchor = anchor;
|
||||||
|
@ -498,6 +501,8 @@ namespace MLEM.Ui.Elements {
|
||||||
|
|
||||||
protected virtual void InitStyle(UiStyle style) {
|
protected virtual void InitStyle(UiStyle style) {
|
||||||
this.SelectionIndicator.SetFromStyle(style.SelectionIndicator);
|
this.SelectionIndicator.SetFromStyle(style.SelectionIndicator);
|
||||||
|
this.ActionSound.SetFromStyle(style.ActionSound);
|
||||||
|
this.SecondActionSound.SetFromStyle(style.ActionSound);
|
||||||
}
|
}
|
||||||
|
|
||||||
public delegate void TextInputCallback(Element element, Keys key, char character);
|
public delegate void TextInputCallback(Element element, Keys key, char character);
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
|
using Microsoft.Xna.Framework.Audio;
|
||||||
using MLEM.Font;
|
using MLEM.Font;
|
||||||
using MLEM.Formatting;
|
using MLEM.Formatting;
|
||||||
using MLEM.Textures;
|
using MLEM.Textures;
|
||||||
|
@ -36,6 +37,7 @@ namespace MLEM.Ui.Style {
|
||||||
public IGenericFont ItalicFont;
|
public IGenericFont ItalicFont;
|
||||||
public FormatSettings FormatSettings;
|
public FormatSettings FormatSettings;
|
||||||
public float TextScale = 1;
|
public float TextScale = 1;
|
||||||
|
public SoundEffectInstance ActionSound;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -81,11 +81,7 @@ namespace MLEM.Ui {
|
||||||
root.Element.ForceUpdateArea();
|
root.Element.ForceUpdateArea();
|
||||||
};
|
};
|
||||||
|
|
||||||
window.AddTextInputListener((sender, key, character) => {
|
window.AddTextInputListener((sender, key, character) => this.ApplyToAll(e => e.OnTextInput?.Invoke(e, key, character)));
|
||||||
foreach (var root in this.rootElements)
|
|
||||||
root.Element.AndChildren(e => e.OnTextInput?.Invoke(e, key, character));
|
|
||||||
});
|
|
||||||
|
|
||||||
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) => {
|
||||||
|
@ -93,6 +89,14 @@ namespace MLEM.Ui {
|
||||||
batch.Draw(element.SelectionIndicator, element.DisplayArea, Color.White * alpha, element.Scale / 2);
|
batch.Draw(element.SelectionIndicator, element.DisplayArea, Color.White * alpha, element.Scale / 2);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
this.OnElementPressed += e => {
|
||||||
|
if (e.OnPressed != null)
|
||||||
|
e.ActionSound.Value?.Replay();
|
||||||
|
};
|
||||||
|
this.OnElementSecondaryPressed += e => {
|
||||||
|
if (e.OnSecondaryPressed != null)
|
||||||
|
e.SecondActionSound.Value?.Replay();
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Update(GameTime time) {
|
public override void Update(GameTime time) {
|
||||||
|
|
Loading…
Reference in a new issue