mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-22 12:58:33 +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.Linq;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Audio;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using MLEM.Extensions;
|
||||
|
@ -140,6 +141,8 @@ namespace MLEM.Ui.Elements {
|
|||
private bool areaDirty;
|
||||
private bool sortedChildrenDirty;
|
||||
public StyleProp<NinePatch> SelectionIndicator;
|
||||
public StyleProp<SoundEffectInstance> ActionSound;
|
||||
public StyleProp<SoundEffectInstance> SecondActionSound;
|
||||
|
||||
public Element(Anchor anchor, Vector2 size) {
|
||||
this.anchor = anchor;
|
||||
|
@ -498,6 +501,8 @@ namespace MLEM.Ui.Elements {
|
|||
|
||||
protected virtual void InitStyle(UiStyle style) {
|
||||
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);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Audio;
|
||||
using MLEM.Font;
|
||||
using MLEM.Formatting;
|
||||
using MLEM.Textures;
|
||||
|
@ -36,6 +37,7 @@ namespace MLEM.Ui.Style {
|
|||
public IGenericFont ItalicFont;
|
||||
public FormatSettings FormatSettings;
|
||||
public float TextScale = 1;
|
||||
public SoundEffectInstance ActionSound;
|
||||
|
||||
}
|
||||
}
|
|
@ -81,11 +81,7 @@ namespace MLEM.Ui {
|
|||
root.Element.ForceUpdateArea();
|
||||
};
|
||||
|
||||
window.AddTextInputListener((sender, key, character) => {
|
||||
foreach (var root in this.rootElements)
|
||||
root.Element.AndChildren(e => e.OnTextInput?.Invoke(e, key, character));
|
||||
});
|
||||
|
||||
window.AddTextInputListener((sender, key, character) => this.ApplyToAll(e => e.OnTextInput?.Invoke(e, key, character)));
|
||||
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) => {
|
||||
|
@ -93,6 +89,14 @@ namespace MLEM.Ui {
|
|||
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) {
|
||||
|
|
Loading…
Reference in a new issue