Skip to content

Commit

Permalink
Merge pull request #153 from ojh050118/sprite-text
Browse files Browse the repository at this point in the history
Code cleanup
  • Loading branch information
ojh050118 authored May 17, 2023
2 parents 5b04027 + 5b5616b commit 36c810b
Show file tree
Hide file tree
Showing 30 changed files with 391 additions and 105 deletions.
5 changes: 5 additions & 0 deletions Circle.Game/Beatmaps/BeatmapInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,17 @@ public BeatmapInfo(Beatmap beatmap, FileInfo info)
{
Beatmap = beatmap;
fileInfo = info;

if (info == null)
return;

Directory = fileInfo.Directory?.Name ?? string.Empty;
DirectoryName = fileInfo.DirectoryName ?? string.Empty;
Name = fileInfo.Name;
Extension = fileInfo.Extension;
Exists = fileInfo.Exists;
BeatmapPath = fileInfo.FullName;

if (!string.IsNullOrEmpty(Directory))
RelativeBeatmapPath = Path.Combine(Directory, Name);

Expand Down
41 changes: 41 additions & 0 deletions Circle.Game/Beatmaps/DummyBeatmap.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#nullable disable

using System;
using osu.Framework.Graphics;

namespace Circle.Game.Beatmaps
{
public class DummyBeatmap : Beatmap
{
public DummyBeatmap()
{
AngleData = Array.Empty<float>();
Settings = new Settings
{
Artist = "please load a beatmap!",
Song = "no beatmaps available!",
SongFileName = string.Empty,
Author = string.Empty,
SeparateCountdownTime = false,
PreviewSongStart = 0,
PreviewSongDuration = 0,
BeatmapDesc = string.Empty,
Difficulty = 0,
Bpm = 0,
Volume = 0,
Offset = 0,
VidOffset = 0,
Pitch = 0,
CountdownTicks = 0,
BgImage = string.Empty,
BgVideo = string.Empty,
RelativeTo = Relativity.Player,
Position = Array.Empty<float>(),
Rotation = 0,
Zoom = 0,
PlanetEasing = Easing.None
};
Actions = Array.Empty<Actions>();
}
}
}
12 changes: 12 additions & 0 deletions Circle.Game/Beatmaps/DummyBeatmapInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#nullable disable

namespace Circle.Game.Beatmaps
{
public class DummyBeatmapInfo : BeatmapInfo
{
public DummyBeatmapInfo()
: base(new DummyBeatmap(), null)
{
}
}
}
66 changes: 66 additions & 0 deletions Circle.Game/Graphics/CircleFont.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#nullable disable

using osu.Framework.Graphics.Sprites;

namespace Circle.Game.Graphics
{
public class CircleFont
{
public const float DEFAULT_FONT_SIZE = 24;

public static FontUsage Default => GetFont();

public static FontUsage GetFont(Typeface typeface = Typeface.OpenSans, float size = DEFAULT_FONT_SIZE, FontWeight weight = FontWeight.Medium, bool italics = false, bool fixedWidth = false)
{
string familyString = GetFamilyString(typeface);
return new FontUsage(familyString, size, GetWeightString(familyString, weight), getItalics(italics), fixedWidth);
}

private static bool getItalics(in bool italicsRequested)
{
return false;
}

public static string GetFamilyString(Typeface typeface)
{
switch (typeface)
{
case Typeface.OpenSans:
return @"OpenSans";
}

return null;
}

public static string GetWeightString(string family, FontWeight weight)
{
return weight.ToString();
}
}

public static class TetrisFontExtensions
{
public static FontUsage With(this FontUsage usage, Typeface? typeface = null, float? size = null, FontWeight? weight = null, bool? italics = null, bool? fixedWidth = null)
{
string familyString = typeface != null ? CircleFont.GetFamilyString(typeface.Value) : usage.Family;
string weightString = weight != null ? CircleFont.GetWeightString(familyString, weight.Value) : usage.Weight;

return usage.With(familyString, size, weightString, italics, fixedWidth);
}
}

public enum Typeface
{
OpenSans
}

public enum FontWeight
{
Light = 300,
Regular = 400,
Medium = 500,
SemiBold = 600,
Bold = 700,
Black = 900
}
}
3 changes: 3 additions & 0 deletions Circle.Game/Graphics/Containers/BackgroundColorContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public BackgroundColorContainer(Background target)
target.BackgroundColorChanged += async t => await backgroundColorChanged(t);
}

[BackgroundDependencyLoader]
private void load() => Colour = DefaultColour;

private async Task backgroundColorChanged(string texturePath)
{
dataGetCancellation?.Cancel();
Expand Down
15 changes: 15 additions & 0 deletions Circle.Game/Graphics/Sprites/CircleSpriteText.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#nullable disable

using osu.Framework.Graphics.Sprites;

namespace Circle.Game.Graphics.Sprites
{
public partial class CircleSpriteText : SpriteText
{
public CircleSpriteText()
{
Shadow = true;
Font = CircleFont.Default;
}
}
}
112 changes: 112 additions & 0 deletions Circle.Game/Graphics/Sprites/GlowingSpriteText.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#nullable disable

using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Localisation;
using osuTK;

namespace Circle.Game.Graphics.Sprites
{
public partial class GlowingSpriteText : Container, IHasText
{
private readonly CircleSpriteText spriteText, blurredText;
private readonly BufferedContainer blurContainer;

public LocalisableString Text
{
get => spriteText.Text;
set => blurredText.Text = spriteText.Text = value;
}

public FontUsage Font
{
get => spriteText.Font;
set => blurredText.Font = spriteText.Font = value;
}

public Vector2 TextSize
{
get => spriteText.Size;
set => blurredText.Size = spriteText.Size = value;
}

public ColourInfo TextColour
{
get => spriteText.Colour;
set => spriteText.Colour = value;
}

public ColourInfo GlowColour
{
get => blurredText.Colour;
set => blurredText.Colour = value;
}

public Vector2 Spacing
{
get => spriteText.Spacing;
set => spriteText.Spacing = blurredText.Spacing = value;
}

public bool UseFullGlyphHeight
{
get => spriteText.UseFullGlyphHeight;
set => spriteText.UseFullGlyphHeight = blurredText.UseFullGlyphHeight = value;
}

public Bindable<string> Current
{
get => spriteText.Current;
set => spriteText.Current = value;
}

public float BlurSigma
{
get => blurContainer.BlurSigma.X;
set => blurContainer.BlurSigma = new Vector2(value);
}

public BlendingParameters GlowBlending
{
get => blurContainer.Blending;
set => blurContainer.Blending = value;
}

public GlowingSpriteText()
{
AutoSizeAxes = Axes.Both;

Children = new Drawable[]
{
blurContainer = new BufferedContainer(cachedFrameBuffer: true)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
BlurSigma = new Vector2(7),
RedrawOnScale = false,
RelativeSizeAxes = Axes.Both,
Blending = BlendingParameters.Inherit,
Size = new Vector2(3f),
Children = new[]
{
blurredText = new CircleSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Font = CircleFont.Default
},
},
},
spriteText = new CircleSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Font = CircleFont.Default
},
};
}
}
}
8 changes: 4 additions & 4 deletions Circle.Game/Graphics/UserInterface/BoxButton.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
#nullable disable

using Circle.Game.Graphics.Sprites;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;

namespace Circle.Game.Graphics.UserInterface
{
public partial class BoxButton : CircleButton
{
private readonly SpriteText sprite;
private readonly CircleSpriteText sprite;

public BoxButton(bool useBackground = true)
: base(useBackground)
{
RelativeSizeAxes = Axes.X;
Height = 40;
Content.Add(sprite = new SpriteText
Content.Add(sprite = new CircleSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Padding = new MarginPadding(10),
Font = FontUsage.Default.With(size: 22)
Font = CircleFont.Default.With(size: 22)
});
}

Expand Down
7 changes: 7 additions & 0 deletions Circle.Game/Graphics/UserInterface/CircleButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ private void load(AudioManager audio, CircleColour colours)
Content.CornerRadius = CornerRadius;
}

protected override void Update()
{
base.Update();

Content.CornerRadius = Height / 6;
}

protected override bool OnHover(HoverEvent e)
{
hoverSample?.Play();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#nullable disable

using System.IO;
using Circle.Game.Graphics.Sprites;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
Expand All @@ -11,10 +12,10 @@ namespace Circle.Game.Graphics.UserInterface
{
internal partial class CircleDirectorySelectorBreadcrumbDisplay : DirectorySelectorBreadcrumbDisplay
{
protected override Drawable CreateCaption() => new SpriteText
protected override Drawable CreateCaption() => new CircleSpriteText
{
Text = "Current directory: ",
Font = FontUsage.Default.With(size: CircleDirectorySelector.ITEM_HEIGHT)
Font = CircleFont.Default.With(size: CircleDirectorySelector.ITEM_HEIGHT)
};

protected override DirectorySelectorDirectory CreateRootDirectoryItem() => new CircleBreadcrumbDisplayComputer();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#nullable disable

using System.IO;
using Circle.Game.Graphics.Sprites;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
Expand Down Expand Up @@ -39,7 +40,7 @@ private void load()
});
}

protected override SpriteText CreateSpriteText() => new SpriteText();
protected override SpriteText CreateSpriteText() => new CircleSpriteText { Font = CircleFont.Default.With(size: CircleDirectorySelector.ITEM_HEIGHT) };

internal partial class Background : CompositeDrawable
{
Expand Down
6 changes: 4 additions & 2 deletions Circle.Game/Graphics/UserInterface/CircleDropdown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using System.Linq;
using Circle.Game.Graphics.Containers;
using Circle.Game.Graphics.Sprites;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
Expand Down Expand Up @@ -291,7 +292,7 @@ public LocalisableString Text
public partial class CircleDropdownHeader : DropdownHeader
{
protected readonly SpriteIcon Icon;
protected readonly SpriteText Text;
protected readonly CircleSpriteText Text;

public CircleDropdownHeader()
{
Expand Down Expand Up @@ -319,12 +320,13 @@ public CircleDropdownHeader()
{
new Drawable[]
{
Text = new SpriteText
Text = new CircleSpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
RelativeSizeAxes = Axes.X,
Truncate = true,
Font = CircleFont.Default.With(size: 22)
},
Icon = new SpriteIcon
{
Expand Down
Loading

0 comments on commit 36c810b

Please sign in to comment.