Skip to content

Commit

Permalink
Sprites in blinds mod & gameplay improvements
Browse files Browse the repository at this point in the history
There are now skinnable actual blinds (shoji screen panels)
The black overlay is still behind them to avoid cheating with skins
The blinds don't open linearly anymore, they are health squared now
When easy mod is on, there is always a little gap open
  • Loading branch information
WebFreak001 committed Sep 15, 2018
1 parent 040a44d commit 5f3c054
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 5 deletions.
4 changes: 3 additions & 1 deletion osu.Game.Rulesets.Osu/Mods/OsuModBlinds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using osu.Game.Rulesets.Osu.Objects.Drawables;
using osu.Game.Rulesets.Scoring;
using osu.Game.Rulesets.UI;
using System.Linq;

namespace osu.Game.Rulesets.Osu.Mods
{
Expand All @@ -16,7 +17,8 @@ public class OsuModBlinds : ModBlinds<OsuHitObject>

public override void ApplyToRulesetContainer(RulesetContainer<OsuHitObject> rulesetContainer)
{
rulesetContainer.Overlays.Add(flashlight = new DrawableOsuBlinds(restrictTo: rulesetContainer.Playfield));
bool hasEasy = rulesetContainer.ActiveMods.Count(mod => mod is ModEasy) > 0;
rulesetContainer.Overlays.Add(flashlight = new DrawableOsuBlinds(restrictTo: rulesetContainer.Playfield, hasEasy: hasEasy));
}

public override void ApplyToScoreProcessor(ScoreProcessor scoreProcessor)
Expand Down
74 changes: 70 additions & 4 deletions osu.Game.Rulesets.Osu/Objects/Drawables/DrawableOsuBlinds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
using osu.Framework.Graphics.Shapes;
using OpenTK.Graphics;
using osu.Framework.Allocation;
using osu.Game.Skinning;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
using osu.Game.Rulesets.Osu.Objects.Drawables.Pieces;

namespace osu.Game.Rulesets.Osu.Objects.Drawables
{
Expand All @@ -14,10 +18,19 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
/// </summary>
public class DrawableOsuBlinds : Container
{
/// <summary>
/// Black background boxes behind blind panel textures.
/// </summary>
private Box box1, box2;
private Sprite panelLeft, panelRight;
private Sprite bgPanelLeft, bgPanelRight;
private ISkinSource skin;

private float target = 1;
private readonly float easing = 1;

private readonly Container restrictTo;
private readonly bool hasEasy;

/// <summary>
/// <para>
Expand All @@ -30,15 +43,21 @@ public class DrawableOsuBlinds : Container
/// Infinity would mean the blinds are always outside the playfield except on 100% health.
/// </para>
/// </summary>
private const float leniency = 0.2f;
private const float leniency = 0.1f;

public DrawableOsuBlinds(Container restrictTo)
/// <summary>
/// Multiplier for adding a gap when the Easy mod is also currently applied.
/// </summary>
private const float easy_position_multiplier = 0.95f;

public DrawableOsuBlinds(Container restrictTo, bool hasEasy)
{
this.restrictTo = restrictTo;
this.hasEasy = hasEasy;
}

[BackgroundDependencyLoader]
private void load()
private void load(ISkinSource skin, TextureStore textures)
{
RelativeSizeAxes = Axes.Both;
Width = 1;
Expand All @@ -62,6 +81,36 @@ private void load()
Width = 0,
Height = 1
});

Add(bgPanelLeft = new ModBlindsPanelSprite {
Origin = Anchor.TopRight,
Colour = Color4.Gray
});
Add(bgPanelRight = new ModBlindsPanelSprite {
Origin = Anchor.TopLeft,
Colour = Color4.Gray
});

Add(panelLeft = new ModBlindsPanelSprite {
Origin = Anchor.TopRight
});
Add(panelRight = new ModBlindsPanelSprite {
Origin = Anchor.TopLeft
});

this.skin = skin;
skin.SourceChanged += skinChanged;
PanelTexture = textures.Get("Play/osu/blinds-panel");
}

private void skinChanged()
{
PanelTexture = skin.GetTexture("Play/osu/blinds-panel");
}

private static float applyAdjustmentCurve(float value)
{
return value * value;
}

protected override void Update()
Expand All @@ -71,10 +120,16 @@ protected override void Update()
float rawWidth = end - start;
start -= rawWidth * leniency * 0.5f;
end += rawWidth * leniency * 0.5f;
float width = (end - start) * 0.5f * easing;

float width = (end - start) * 0.5f * applyAdjustmentCurve((hasEasy ? easy_position_multiplier : 1) * easing);
// different values in case the playfield ever moves from center to somewhere else.
box1.Width = start + width;
box2.Width = DrawWidth - end + width;

panelLeft.X = start + width;
panelRight.X = end - width;
bgPanelLeft.X = start;
bgPanelRight.X = end;
}

/// <summary>
Expand All @@ -92,5 +147,16 @@ public float Value
return target;
}
}

public Texture PanelTexture
{
set
{
panelLeft.Texture = value;
panelRight.Texture = value;
bgPanelLeft.Texture = value;
bgPanelRight.Texture = value;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE

using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;

namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
{
public class ModBlindsPanelSprite : Sprite
{
public ModBlindsPanelSprite()
{
RelativeSizeAxes = Axes.None;
Anchor = Anchor.TopLeft;
}

protected override void Update()
{
Height = Parent?.DrawHeight ?? 0;
if (Height == 0 || Texture is null)
Width = 0;
else
Width = Texture.Width / (float)Texture.Height * Height;
}
}
}
2 changes: 2 additions & 0 deletions osu.Game/Rulesets/UI/RulesetContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,8 @@ protected override void Update()
Playfield.Size = GetAspectAdjustedSize() * PlayfieldArea;
}

public IEnumerable<Mod> ActiveMods { get => Mods; }

/// <summary>
/// Computes the size of the <see cref="Playfield"/> in relative coordinate space after aspect adjustments.
/// </summary>
Expand Down

0 comments on commit 5f3c054

Please sign in to comment.