diff --git a/.gitignore b/.gitignore index a87c7553..e241c8a0 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,10 @@ packages *.user tools TestResults* +.vs/** +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates \ No newline at end of file diff --git a/Demos/UiDemo.cs b/Demos/UiDemo.cs index 8855fc1d..3cbb3768 100644 --- a/Demos/UiDemo.cs +++ b/Demos/UiDemo.cs @@ -57,7 +57,7 @@ public override void LoadContent() { }; var untexturedStyle = new UntexturedStyle(this.SpriteBatch) { TextScale = style.TextScale, - Font = style.Font + Font = style.Font, }; // set the defined style as the current one this.UiSystem.Style = style; diff --git a/MLEM.Ui/Elements/Button.cs b/MLEM.Ui/Elements/Button.cs index 6c9187b2..f0d87a2b 100644 --- a/MLEM.Ui/Elements/Button.cs +++ b/MLEM.Ui/Elements/Button.cs @@ -160,6 +160,7 @@ public override void Draw(GameTime time, SpriteBatch batch, float alpha, SpriteB protected override void InitStyle(UiStyle style) { base.InitStyle(style); this.Texture = this.Texture.OrStyle(style.ButtonTexture); + this.NormalColor = this.NormalColor.OrStyle(style.ButtonColor); this.HoveredTexture = this.HoveredTexture.OrStyle(style.ButtonHoveredTexture); this.HoveredColor = this.HoveredColor.OrStyle(style.ButtonHoveredColor); this.DisabledTexture = this.DisabledTexture.OrStyle(style.ButtonDisabledTexture); diff --git a/MLEM.Ui/Elements/Checkbox.cs b/MLEM.Ui/Elements/Checkbox.cs index 7658c527..8cdc85e0 100644 --- a/MLEM.Ui/Elements/Checkbox.cs +++ b/MLEM.Ui/Elements/Checkbox.cs @@ -18,6 +18,10 @@ public class Checkbox : Element { /// public StyleProp Texture; /// + /// The color that this checkbox uses for drawing. + /// + public StyleProp BackColor; + /// /// The texture that this checkbox uses when it is hovered. /// If this is null, the default is used. /// @@ -39,6 +43,16 @@ public class Checkbox : Element { /// The texture that is rendered on top of this checkbox when it is . /// public StyleProp Checkmark; + /// + /// The color of the check mark that is rendered on top of this checkbox when it is . + /// + public StyleProp CheckColor; + /// + /// The color of the check mark that is rendered on top of this checkbox when it is not . + /// Set alpha to 0 to disable this behavior. + /// + public StyleProp UncheckColor; + /// /// The label that displays next to this checkbox /// @@ -117,7 +131,7 @@ public override void SetAreaAndUpdateChildren(RectangleF area) { /// public override void Draw(GameTime time, SpriteBatch batch, float alpha, SpriteBatchContext context) { var tex = this.Texture; - var color = Color.White * alpha; + var color = this.BackColor.OrDefault(Color.White) * alpha; if (this.IsDisabled) { tex = this.DisabledTexture.OrDefault(tex); color = (Color) this.DisabledColor * alpha; @@ -128,8 +142,12 @@ public override void Draw(GameTime time, SpriteBatch batch, float alpha, SpriteB var boxDisplayArea = new RectangleF(this.DisplayArea.Location, new Vector2(this.DisplayArea.Height)); batch.Draw(tex, boxDisplayArea, color, this.Scale); + var uncheckedColor = this.UncheckColor.OrDefault(Color.Transparent); if (this.Checked) - batch.Draw(this.Checkmark, boxDisplayArea, Color.White * alpha); + batch.Draw(this.Checkmark, boxDisplayArea, this.CheckColor.OrDefault(Color.White) * alpha); + else if(uncheckedColor.A != 0) { + batch.Draw(this.Checkmark, boxDisplayArea, uncheckedColor * alpha); + } base.Draw(time, batch, alpha, context); } @@ -137,11 +155,14 @@ public override void Draw(GameTime time, SpriteBatch batch, float alpha, SpriteB protected override void InitStyle(UiStyle style) { base.InitStyle(style); this.Texture = this.Texture.OrStyle(style.CheckboxTexture); + this.BackColor = this.BackColor.OrStyle(style.CheckboxColor); this.HoveredTexture = this.HoveredTexture.OrStyle(style.CheckboxHoveredTexture); this.HoveredColor = this.HoveredColor.OrStyle(style.CheckboxHoveredColor); this.DisabledTexture = this.DisabledTexture.OrStyle(style.CheckboxDisabledTexture); this.DisabledColor = this.DisabledColor.OrStyle(style.CheckboxDisabledColor); this.Checkmark = this.Checkmark.OrStyle(style.CheckboxCheckmark); + this.CheckColor = this.CheckColor.OrStyle(style.CheckboxCheckColor); + this.UncheckColor = this.UncheckColor.OrStyle(style.CheckboxUncheckedColor); this.TextOffsetX = this.TextOffsetX.OrStyle(style.CheckboxTextOffsetX); } diff --git a/MLEM.Ui/Elements/Element.cs b/MLEM.Ui/Elements/Element.cs index 71fa6c05..e7320e30 100644 --- a/MLEM.Ui/Elements/Element.cs +++ b/MLEM.Ui/Elements/Element.cs @@ -349,6 +349,10 @@ public StyleProp Style { /// public StyleProp SelectionIndicator; /// + /// A style property that contains the color of the selection indicator that is displayed on this element if it is the + /// + public StyleProp SelectionColor; + /// /// A style property that contains the sound effect that is played when this element's is called /// public StyleProp ActionSound; diff --git a/MLEM.Ui/Elements/RadioButton.cs b/MLEM.Ui/Elements/RadioButton.cs index 1f725245..de59da5a 100644 --- a/MLEM.Ui/Elements/RadioButton.cs +++ b/MLEM.Ui/Elements/RadioButton.cs @@ -40,9 +40,12 @@ public RadioButton(Anchor anchor, Vector2 size, string label, bool defaultChecke protected override void InitStyle(UiStyle style) { base.InitStyle(style); this.Texture = this.Texture.OrStyle(style.RadioTexture); + this.BackColor = this.BackColor.OrStyle(style.RadioColor); this.HoveredTexture = this.HoveredTexture.OrStyle(style.RadioHoveredTexture); this.HoveredColor = this.HoveredColor.OrStyle(style.RadioHoveredColor); this.Checkmark = this.Checkmark.OrStyle(style.RadioCheckmark); + this.CheckColor = this.CheckColor.OrStyle(style.RadioCheckColor); + this.UncheckColor = this.UncheckColor.OrStyle(style.RadioUncheckedColor); } } diff --git a/MLEM.Ui/Elements/ScrollBar.cs b/MLEM.Ui/Elements/ScrollBar.cs index 098b3968..02d10434 100644 --- a/MLEM.Ui/Elements/ScrollBar.cs +++ b/MLEM.Ui/Elements/ScrollBar.cs @@ -27,10 +27,18 @@ public class ScrollBar : Element { /// public StyleProp Background; /// + /// The background color for this scroll bar + /// + public StyleProp BackColor; + /// /// The texture of this scroll bar's scroller indicator /// public StyleProp ScrollerTexture; /// + /// The color of this scroll bar's scroller indicator + /// + public StyleProp ScrollerColor; + /// /// Whether smooth scrolling should be enabled for this scroll bar. /// Smooth scrolling causes the to change gradually rather than instantly when scrolling. /// @@ -231,10 +239,10 @@ private void ScrollToPos(Vector2 position) { /// public override void Draw(GameTime time, SpriteBatch batch, float alpha, SpriteBatchContext context) { - batch.Draw(this.Background, this.DisplayArea, Color.White * alpha, this.Scale); + batch.Draw(this.Background, this.DisplayArea, this.BackColor.OrDefault(Color.White) * alpha, this.Scale); if (this.MaxValue > 0) { var scrollerRect = new RectangleF(this.ScrollerPosition, this.ScrollerSize * this.Scale); - batch.Draw(this.ScrollerTexture, scrollerRect, Color.White * alpha, this.Scale); + batch.Draw(this.ScrollerTexture, scrollerRect, this.ScrollerColor.OrDefault(Color.White) * alpha, this.Scale); } base.Draw(time, batch, alpha, context); } @@ -243,7 +251,9 @@ public override void Draw(GameTime time, SpriteBatch batch, float alpha, SpriteB protected override void InitStyle(UiStyle style) { base.InitStyle(style); this.Background = this.Background.OrStyle(style.ScrollBarBackground); + this.BackColor = this.BackColor.OrStyle(style.ScrollBarBackColor); this.ScrollerTexture = this.ScrollerTexture.OrStyle(style.ScrollBarScrollerTexture); + this.ScrollerColor = this.ScrollerColor.OrStyle(style.ScrollBarScrollerColor); this.SmoothScrolling = this.SmoothScrolling.OrStyle(style.ScrollBarSmoothScrolling); this.SmoothScrollFactor = this.SmoothScrollFactor.OrStyle(style.ScrollBarSmoothScrollFactor); } diff --git a/MLEM.Ui/Elements/TextField.cs b/MLEM.Ui/Elements/TextField.cs index b11eeaec..676833c1 100644 --- a/MLEM.Ui/Elements/TextField.cs +++ b/MLEM.Ui/Elements/TextField.cs @@ -56,6 +56,10 @@ public class TextField : Element { /// public StyleProp Texture; /// + /// This text field's background color + /// + public StyleProp BackColor; + /// /// This text field's texture while it is hovered /// public StyleProp HoveredTexture; @@ -239,7 +243,7 @@ public override void Update(GameTime time) { /// public override void Draw(GameTime time, SpriteBatch batch, float alpha, SpriteBatchContext context) { var tex = this.Texture; - var color = Color.White * alpha; + var color = (Color) this.BackColor * alpha; if (this.IsMouseOver) { tex = this.HoveredTexture.OrDefault(tex); color = (Color) this.HoveredColor * alpha; @@ -278,7 +282,9 @@ protected override void InitStyle(UiStyle style) { base.InitStyle(style); this.TextScale = this.TextScale.OrStyle(style.TextScale); this.Font = this.Font.OrStyle(style.Font); + this.TextColor = this.TextColor.OrStyle(style.TextFieldTextColor); this.Texture = this.Texture.OrStyle(style.TextFieldTexture); + this.BackColor = this.BackColor.OrStyle(style.TextFieldColor); this.HoveredTexture = this.HoveredTexture.OrStyle(style.TextFieldHoveredTexture); this.HoveredColor = this.HoveredColor.OrStyle(style.TextFieldHoveredColor); this.TextOffsetX = this.TextOffsetX.OrStyle(style.TextFieldTextOffsetX); diff --git a/MLEM.Ui/Elements/Tooltip.cs b/MLEM.Ui/Elements/Tooltip.cs index 23ae328c..b00a734c 100644 --- a/MLEM.Ui/Elements/Tooltip.cs +++ b/MLEM.Ui/Elements/Tooltip.cs @@ -168,6 +168,7 @@ public override void ForceUpdateArea() { protected override void InitStyle(UiStyle style) { base.InitStyle(style); this.Texture = this.Texture.OrStyle(style.TooltipBackground); + this.DrawColor = this.DrawColor.OrStyle(style.TooltipBackColor); this.MouseOffset = this.MouseOffset.OrStyle(style.TooltipOffset); this.AutoNavOffset = this.AutoNavOffset.OrStyle(style.TooltipAutoNavOffset); this.MouseAnchor = this.MouseAnchor.OrStyle(style.TooltipMouseAnchor); diff --git a/MLEM.Ui/Style/UiStyle.cs b/MLEM.Ui/Style/UiStyle.cs index 8724e6e1..48e90261 100644 --- a/MLEM.Ui/Style/UiStyle.cs +++ b/MLEM.Ui/Style/UiStyle.cs @@ -23,6 +23,10 @@ public class UiStyle : GenericDataHolder { /// public NinePatch SelectionIndicator; /// + /// The color of the selector that is rendered on top of the + /// + public Color SelectionColor = Color.White; + /// /// A that is played when the mouse enters an element. /// public UiAnimation MouseEnterAnimation; @@ -35,6 +39,10 @@ public class UiStyle : GenericDataHolder { /// public NinePatch ButtonTexture; /// + /// The color that the element renders + /// + public Color ButtonColor = Color.White; + /// /// The texture that the element uses when it is moused over () /// Note that, if you just want to change the button's color when hovered, use . /// @@ -76,10 +84,18 @@ public class UiStyle : GenericDataHolder { /// public float PanelScrollBarOffset = 1; /// + /// The text color of text the element uses + /// + public Color TextFieldTextColor = Color.White; + /// /// The texture that the element uses /// public NinePatch TextFieldTexture; /// + /// The color that the renders with when it is idle + /// + public Color TextFieldColor = Color.LightGray; + /// /// The texture that the element uses when it is moused over () /// public NinePatch TextFieldHoveredTexture; @@ -100,10 +116,18 @@ public class UiStyle : GenericDataHolder { /// public NinePatch ScrollBarBackground; /// + /// The background color that the element uses + /// + public Color ScrollBarBackColor = Color.White; + /// /// The texture that the scroll indicator of the element uses /// public NinePatch ScrollBarScrollerTexture; /// + /// The color that the scroll indicator of the element uses + /// + public Color ScrollBarScrollerColor = Color.White; + /// /// Whether or not a should use smooth scrolling /// public bool ScrollBarSmoothScrolling; @@ -116,6 +140,10 @@ public class UiStyle : GenericDataHolder { /// public NinePatch CheckboxTexture; /// + /// The color that the element uses + /// + public Color CheckboxColor = Color.White; + /// /// The texture that the element uses when it is moused over () /// public NinePatch CheckboxHoveredTexture; @@ -136,6 +164,15 @@ public class UiStyle : GenericDataHolder { /// public TextureRegion CheckboxCheckmark; /// + /// The color of the check mark that the element uses when it is + /// + public Color CheckboxCheckColor = Color.White; + /// + /// The color of the check mark that the element uses when it is not . + /// Set alpha to 0 to disable this behavior + /// + public Color CheckboxUncheckedColor = Color.Transparent; + /// /// The width of the space between a and its /// public float CheckboxTextOffsetX = 2; @@ -144,6 +181,10 @@ public class UiStyle : GenericDataHolder { /// public NinePatch RadioTexture; /// + /// The color that the element uses + /// + public Color RadioColor = Color.White; + /// /// The texture that the element uses when it is moused over () /// public NinePatch RadioHoveredTexture; @@ -156,10 +197,23 @@ public class UiStyle : GenericDataHolder { /// public TextureRegion RadioCheckmark; /// + /// The color of the check mark that the uses when it is + /// + public Color RadioCheckColor = Color.White; + /// + /// The color of the check mark that the uses when it is not + /// Set the alpha to 0 to disable this behavior + /// + public Color RadioUncheckedColor = Color.Transparent; + /// /// The texture that the uses for its background /// public NinePatch TooltipBackground; /// + /// The color that the uses for its background + /// + public Color TooltipBackColor = Color.White; + /// /// The offset of the element's top left corner from the mouse position /// public Vector2 TooltipOffset = new Vector2(8, 16); @@ -286,9 +340,11 @@ public UiStyle() {} /// The original style settings, to copy into the new instance. public UiStyle(UiStyle original) { this.SelectionIndicator = original.SelectionIndicator; + this.SelectionColor = original.SelectionColor; this.MouseEnterAnimation = original.MouseEnterAnimation; this.MouseExitAnimation = original.MouseExitAnimation; this.ButtonTexture = original.ButtonTexture; + this.ButtonColor = original.ButtonColor; this.ButtonHoveredTexture = original.ButtonHoveredTexture; this.ButtonHoveredColor = original.ButtonHoveredColor; this.ButtonDisabledTexture = original.ButtonDisabledTexture; @@ -300,26 +356,36 @@ public UiStyle(UiStyle original) { this.PanelScrollerSize = original.PanelScrollerSize; this.PanelScrollBarOffset = original.PanelScrollBarOffset; this.TextFieldTexture = original.TextFieldTexture; + this.TextFieldColor = original.TextFieldColor; this.TextFieldHoveredTexture = original.TextFieldHoveredTexture; this.TextFieldHoveredColor = original.TextFieldHoveredColor; this.TextFieldTextOffsetX = original.TextFieldTextOffsetX; this.TextFieldCaretWidth = original.TextFieldCaretWidth; this.ScrollBarBackground = original.ScrollBarBackground; + this.ScrollBarBackColor = original.ScrollBarBackColor; this.ScrollBarScrollerTexture = original.ScrollBarScrollerTexture; + this.ScrollBarScrollerColor = original.ScrollBarScrollerColor; this.ScrollBarSmoothScrolling = original.ScrollBarSmoothScrolling; this.ScrollBarSmoothScrollFactor = original.ScrollBarSmoothScrollFactor; this.CheckboxTexture = original.CheckboxTexture; + this.CheckboxColor = original.CheckboxColor; this.CheckboxHoveredTexture = original.CheckboxHoveredTexture; this.CheckboxHoveredColor = original.CheckboxHoveredColor; this.CheckboxDisabledTexture = original.CheckboxDisabledTexture; this.CheckboxDisabledColor = original.CheckboxDisabledColor; this.CheckboxCheckmark = original.CheckboxCheckmark; + this.CheckboxCheckColor = original.CheckboxCheckColor; + this.CheckboxUncheckedColor = original.CheckboxUncheckedColor; this.CheckboxTextOffsetX = original.CheckboxTextOffsetX; this.RadioTexture = original.RadioTexture; + this.RadioColor = original.RadioColor; this.RadioHoveredTexture = original.RadioHoveredTexture; this.RadioHoveredColor = original.RadioHoveredColor; this.RadioCheckmark = original.RadioCheckmark; + this.RadioCheckColor = original.RadioCheckColor; + this.RadioUncheckedColor = original.RadioUncheckedColor; this.TooltipBackground = original.TooltipBackground; + this.TooltipBackColor = original.TooltipBackColor; this.TooltipOffset = original.TooltipOffset; this.TooltipAutoNavOffset = original.TooltipAutoNavOffset; this.TooltipAutoNavAnchor = original.TooltipAutoNavAnchor; diff --git a/MLEM.Ui/UiSystem.cs b/MLEM.Ui/UiSystem.cs index 2bcad3be..57c243c6 100644 --- a/MLEM.Ui/UiSystem.cs +++ b/MLEM.Ui/UiSystem.cs @@ -211,7 +211,7 @@ public UiSystem(Game game, UiStyle style, InputHandler inputHandler = null, bool this.OnSelectedElementChanged += e => this.ApplyToAll(t => t.OnSelectedElementChanged?.Invoke(t, e)); this.OnSelectedElementDrawn += (element, time, batch, alpha, context) => { if (this.Controls.IsAutoNavMode && element.SelectionIndicator.HasValue()) - batch.Draw(element.SelectionIndicator, element.DisplayArea, Color.White * alpha, element.Scale / 2); + batch.Draw(element.SelectionIndicator, element.DisplayArea, element.SelectionColor.OrDefault(Color.White) * alpha, element.Scale / 2); }; this.OnElementPressed += e => { if (e.OnPressed != null)