From 5f3c0549c99b17b9441b09df4f545b7ed3f029cf Mon Sep 17 00:00:00 2001 From: WebFreak001 Date: Sat, 15 Sep 2018 23:44:22 +0200 Subject: [PATCH] Sprites in blinds mod & gameplay improvements 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 --- osu.Game.Rulesets.Osu/Mods/OsuModBlinds.cs | 4 +- .../Objects/Drawables/DrawableOsuBlinds.cs | 74 ++++++++++++++++++- .../Drawables/Pieces/ModBlindsPanelSprite.cs | 26 +++++++ osu.Game/Rulesets/UI/RulesetContainer.cs | 2 + 4 files changed, 101 insertions(+), 5 deletions(-) create mode 100644 osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/ModBlindsPanelSprite.cs diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModBlinds.cs b/osu.Game.Rulesets.Osu/Mods/OsuModBlinds.cs index cefaf02a17..a4441a2bdc 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModBlinds.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModBlinds.cs @@ -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 { @@ -16,7 +17,8 @@ public class OsuModBlinds : ModBlinds public override void ApplyToRulesetContainer(RulesetContainer 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) diff --git a/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableOsuBlinds.cs b/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableOsuBlinds.cs index ced5947ba6..69fc4a1d57 100644 --- a/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableOsuBlinds.cs +++ b/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableOsuBlinds.cs @@ -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 { @@ -14,10 +18,19 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables /// public class DrawableOsuBlinds : Container { + /// + /// Black background boxes behind blind panel textures. + /// 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; /// /// @@ -30,15 +43,21 @@ public class DrawableOsuBlinds : Container /// Infinity would mean the blinds are always outside the playfield except on 100% health. /// /// - private const float leniency = 0.2f; + private const float leniency = 0.1f; - public DrawableOsuBlinds(Container restrictTo) + /// + /// Multiplier for adding a gap when the Easy mod is also currently applied. + /// + 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; @@ -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() @@ -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; } /// @@ -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; + } + } } } diff --git a/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/ModBlindsPanelSprite.cs b/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/ModBlindsPanelSprite.cs new file mode 100644 index 0000000000..459ea920fa --- /dev/null +++ b/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/ModBlindsPanelSprite.cs @@ -0,0 +1,26 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// 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; + } + } +} diff --git a/osu.Game/Rulesets/UI/RulesetContainer.cs b/osu.Game/Rulesets/UI/RulesetContainer.cs index 02ec17e969..7b146f5b84 100644 --- a/osu.Game/Rulesets/UI/RulesetContainer.cs +++ b/osu.Game/Rulesets/UI/RulesetContainer.cs @@ -328,6 +328,8 @@ protected override void Update() Playfield.Size = GetAspectAdjustedSize() * PlayfieldArea; } + public IEnumerable ActiveMods { get => Mods; } + /// /// Computes the size of the in relative coordinate space after aspect adjustments. ///