2019-08-13 21:23:20 +02:00
|
|
|
using Microsoft.Xna.Framework;
|
|
|
|
using MLEM.Input;
|
|
|
|
using MLEM.Ui.Style;
|
|
|
|
|
|
|
|
namespace MLEM.Ui.Elements {
|
|
|
|
public class RadioButton : Checkbox {
|
|
|
|
|
|
|
|
public string Group;
|
|
|
|
|
|
|
|
public RadioButton(Anchor anchor, Vector2 size, string label, bool defaultChecked = false, string group = "") :
|
|
|
|
base(anchor, size, label, defaultChecked) {
|
|
|
|
this.Group = group;
|
|
|
|
|
|
|
|
// don't += because we want to override the checking + unchecking behavior of Checkbox
|
2019-08-25 21:49:27 +02:00
|
|
|
this.OnPressed = element => {
|
|
|
|
this.Checked = true;
|
2019-09-12 12:39:18 +02:00
|
|
|
foreach (var sib in this.GetSiblings()) {
|
2019-08-25 21:49:27 +02:00
|
|
|
if (sib is RadioButton radio && radio.Group == this.Group)
|
|
|
|
radio.Checked = false;
|
2019-08-13 21:23:20 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void InitStyle(UiStyle style) {
|
|
|
|
base.InitStyle(style);
|
2019-10-14 21:28:12 +02:00
|
|
|
this.Texture.SetFromStyle(style.RadioTexture);
|
|
|
|
this.HoveredTexture.SetFromStyle(style.RadioHoveredTexture);
|
|
|
|
this.HoveredColor.SetFromStyle(style.RadioHoveredColor);
|
|
|
|
this.Checkmark.SetFromStyle(style.RadioCheckmark);
|
2019-08-13 21:23:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|