1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-05-29 03:23:37 +02:00

made tooltips be panels and remove the weird paragraph background thing

This commit is contained in:
Ellpeck 2019-12-31 14:08:13 +01:00
parent e2682e866d
commit 43b665642d
5 changed files with 42 additions and 46 deletions

View file

@ -22,8 +22,6 @@ namespace MLEM.Ui.Elements {
public StyleProp<IGenericFont> ItalicFont;
public StyleProp<FormatSettings> FormatSettings;
public StyleProp<NinePatch> Background;
public StyleProp<Color> BackgroundColor;
public StyleProp<Color> TextColor;
public StyleProp<float> TextScale;
public string Text {
@ -82,9 +80,6 @@ namespace MLEM.Ui.Elements {
}
public override void Draw(GameTime time, SpriteBatch batch, float alpha, BlendState blendState, SamplerState samplerState, Matrix matrix) {
if (this.Background.Value != null)
batch.Draw(this.Background, this.Area, (Color) this.BackgroundColor * alpha);
var pos = this.DisplayArea.Location;
var sc = this.TextScale * this.Scale;

View file

@ -5,19 +5,20 @@ using MLEM.Font;
using MLEM.Ui.Style;
namespace MLEM.Ui.Elements {
public class Tooltip : Group {
public class Tooltip : Panel {
public Vector2 MouseOffset = new Vector2(2, 3);
public StyleProp<Vector2> MouseOffset;
public Paragraph Paragraph;
public Tooltip(float width, string text = null, Element elementToHover = null) :
base(Anchor.TopLeft, Vector2.One) {
base(Anchor.TopLeft, Vector2.One, Vector2.Zero) {
if (text != null) {
this.Paragraph = this.AddChild(new Paragraph(Anchor.TopLeft, width, text));
this.Paragraph.AutoAdjustWidth = true;
this.Paragraph.Padding = new Vector2(2);
this.SetWidthBasedOnChildren = true;
}
this.SetWidthBasedOnChildren = true;
this.SetHeightBasedOnChildren = true;
this.ChildPadding = new Vector2(2);
this.CanBeMoused = false;
if (elementToHover != null) {
@ -27,7 +28,7 @@ namespace MLEM.Ui.Elements {
};
elementToHover.OnMouseExit += element => {
if (this.System != null)
this.System.Remove(element.GetType().Name + "Tooltip");
this.System.Remove(this.Root.Name);
};
}
}
@ -45,10 +46,8 @@ namespace MLEM.Ui.Elements {
protected override void InitStyle(UiStyle style) {
base.InitStyle(style);
if (this.Paragraph != null) {
this.Paragraph.Background.SetFromStyle(style.TooltipBackground);
this.Paragraph.BackgroundColor.SetFromStyle(style.TooltipBackgroundColor);
}
this.Texture.SetFromStyle(style.TooltipBackground);
this.MouseOffset.SetFromStyle(style.TooltipOffset);
}
public void SnapPositionToMouse() {

View file

@ -25,7 +25,7 @@ namespace MLEM.Ui.Style {
public Color RadioHoveredColor;
public TextureRegion RadioCheckmark;
public NinePatch TooltipBackground;
public Color TooltipBackgroundColor;
public Vector2 TooltipOffset;
public NinePatch ProgressBarTexture;
public Color ProgressBarColor;
public Vector2 ProgressBarProgressPadding;

View file

@ -2,6 +2,7 @@ using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MLEM.Extensions;
using MLEM.Font;
using MLEM.Textures;
@ -9,46 +10,29 @@ namespace MLEM.Ui.Style {
public class UntexturedStyle : UiStyle {
public UntexturedStyle(SpriteBatch batch) {
this.SelectionIndicator = GenerateTexture(batch, Color.Transparent, Color.Red);
this.ButtonTexture = GenerateTexture(batch, Color.CadetBlue);
this.SelectionIndicator = batch.GenerateTexture(Color.Transparent, Color.Red);
this.ButtonTexture = batch.GenerateTexture(Color.CadetBlue);
this.ButtonHoveredColor = Color.LightGray;
this.PanelTexture = GenerateTexture(batch, Color.Gray);
this.TextFieldTexture = GenerateTexture(batch, Color.MediumBlue);
this.PanelTexture = batch.GenerateTexture(Color.Gray);
this.TextFieldTexture = batch.GenerateTexture(Color.MediumBlue);
this.TextFieldHoveredColor = Color.LightGray;
this.ScrollBarBackground = GenerateTexture(batch, Color.LightBlue);
this.ScrollBarScrollerTexture = GenerateTexture(batch, Color.Blue);
this.CheckboxTexture = GenerateTexture(batch, Color.LightBlue);
this.ScrollBarBackground = batch.GenerateTexture(Color.LightBlue);
this.ScrollBarScrollerTexture = batch.GenerateTexture(Color.Blue);
this.CheckboxTexture = batch.GenerateTexture(Color.LightBlue);
this.CheckboxHoveredColor = Color.LightGray;
this.CheckboxCheckmark = GenerateTexture(batch, Color.Blue).Region;
this.RadioTexture = GenerateTexture(batch, Color.AliceBlue);
this.CheckboxCheckmark = batch.GenerateTexture(Color.Blue).Region;
this.RadioTexture = batch.GenerateTexture(Color.AliceBlue);
this.RadioHoveredColor = Color.LightGray;
this.RadioCheckmark = GenerateTexture(batch, Color.CornflowerBlue).Region;
this.TooltipBackground = GenerateTexture(batch, Color.DarkGray);
this.TooltipBackgroundColor = new Color(Color.Black, 0.65F);
this.ProgressBarTexture = GenerateTexture(batch, Color.RoyalBlue);
this.RadioCheckmark = batch.GenerateTexture(Color.CornflowerBlue).Region;
this.TooltipBackground = batch.GenerateTexture(Color.Black * 0.65F, Color.Black * 0.65F);
this.TooltipOffset = new Vector2(2, 3);
this.ProgressBarTexture = batch.GenerateTexture(Color.RoyalBlue);
this.ProgressBarColor = Color.White;
this.ProgressBarProgressPadding = new Vector2(1);
this.ProgressBarProgressColor = Color.Red;
this.Font = new EmptyFont();
}
private static NinePatch GenerateTexture(SpriteBatch batch, Color color, Color? outlineColor = null) {
var outli = outlineColor ?? Color.Black;
var tex = new Texture2D(batch.GraphicsDevice, 3, 3);
tex.SetData(new[] {
outli, outli, outli,
outli, color, outli,
outli, outli, outli
});
batch.Disposing += (sender, args) => {
if (tex != null) {
tex.Dispose();
tex = null;
}
};
return new NinePatch(tex, 1);
}
private class EmptyFont : IGenericFont {
public float LineHeight => 1;

View file

@ -1,6 +1,7 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MLEM.Misc;
using MLEM.Textures;
namespace MLEM.Extensions {
public static class SpriteBatchExtensions {
@ -21,6 +22,23 @@ namespace MLEM.Extensions {
return blankTexture;
}
public static NinePatch GenerateTexture(this SpriteBatch batch, Color color, Color? outlineColor = null) {
var outli = outlineColor ?? Color.Black;
var tex = new Texture2D(batch.GraphicsDevice, 3, 3);
tex.SetData(new[] {
outli, outli, outli,
outli, color, outli,
outli, outli, outli
});
batch.Disposing += (sender, args) => {
if (tex != null) {
tex.Dispose();
tex = null;
}
};
return new NinePatch(tex, 1);
}
public static void DrawCenteredString(this SpriteBatch batch, SpriteFont font, string text, Vector2 position, float scale, Color color, bool horizontal = true, bool vertical = false, float addedScale = 0) {
var size = font.MeasureString(text);
var center = new Vector2(