Skip to content

Commit 1491cbc

Browse files
committed
Add ability to manually change particles direction
1 parent 615fca4 commit 1491cbc

File tree

4 files changed

+49
-30
lines changed

4 files changed

+49
-30
lines changed

osu.Game.Rulesets.Sandbox/Configuration/SandboxRulesetConfigManager.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.ComponentModel;
22
using osu.Game.Configuration;
33
using osu.Game.Rulesets.Configuration;
4+
using osu.Game.Rulesets.Sandbox.Screens.Visualizer.Components;
45

56
namespace osu.Game.Rulesets.Sandbox.Configuration
67
{
@@ -26,6 +27,7 @@ protected override void InitialiseDefaults()
2627
SetDefault(SandboxRulesetSetting.VisualizerLayout, VisualizerLayout.TypeA);
2728
SetDefault(SandboxRulesetSetting.ShowSettingsTip, true);
2829
SetDefault(SandboxRulesetSetting.ParticlesColour, "#ffffff");
30+
SetDefault(SandboxRulesetSetting.ParticlesDirection, ParticlesDirection.Random);
2931

3032
// TypeA settings
3133
SetDefault(SandboxRulesetSetting.Radius, 350, 200, 500);
@@ -67,6 +69,7 @@ public enum SandboxRulesetSetting
6769
VisualizerLayout,
6870
ShowSettingsTip,
6971
ParticlesColour,
72+
ParticlesDirection,
7073

7174
// TypeA settings
7275
Radius,

osu.Game.Rulesets.Sandbox/Screens/Visualizer/Components/Particles.cs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace osu.Game.Rulesets.Sandbox.Screens.Visualizer.Components
99
public class Particles : CurrentRateContainer
1010
{
1111
private readonly Bindable<string> colour = new Bindable<string>("#ffffff");
12+
private readonly Bindable<ParticlesDirection> direction = new Bindable<ParticlesDirection>();
1213

1314
private ParticlesDrawable particles;
1415

@@ -25,23 +26,32 @@ public Particles()
2526
private void load()
2627
{
2728
config?.BindWith(SandboxRulesetSetting.ParticlesColour, colour);
29+
config?.BindWith(SandboxRulesetSetting.ParticlesDirection, direction);
2830
}
2931

3032
protected override void LoadComplete()
3133
{
3234
base.LoadComplete();
3335

34-
IsKiai.BindValueChanged(kiai =>
36+
direction.BindValueChanged(_ => updateDirection());
37+
IsKiai.BindValueChanged(_ => updateDirection(), true);
38+
39+
colour.BindValueChanged(c => particles.Colour = Colour4.FromHex(c.NewValue), true);
40+
}
41+
42+
private void updateDirection()
43+
{
44+
if (direction.Value == ParticlesDirection.Random)
3545
{
36-
if (kiai.NewValue)
37-
{
46+
if (IsKiai.Value)
3847
particles.SetRandomDirection();
39-
}
4048
else
41-
particles.Direction.Value = MoveDirection.Forward;
42-
});
43-
44-
colour.BindValueChanged(c => particles.Colour = Colour4.FromHex(c.NewValue), true);
49+
particles.Direction.Value = ParticlesDirection.Forward;
50+
}
51+
else
52+
{
53+
particles.Direction.Value = direction.Value;
54+
}
4555
}
4656
}
4757
}

osu.Game.Rulesets.Sandbox/Screens/Visualizer/Components/ParticlesDrawable.cs

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class ParticlesDrawable : Sprite
2323
private const float depth_speed_multiplier = 0.05f;
2424
private const float side_speed_multiplier = 0.0005f;
2525

26-
public readonly Bindable<MoveDirection> Direction = new Bindable<MoveDirection>();
26+
public readonly Bindable<ParticlesDirection> Direction = new Bindable<ParticlesDirection>();
2727

2828
[Resolved(canBeNull: true)]
2929
private SandboxRulesetConfigManager config { get; set; }
@@ -61,8 +61,8 @@ public void Restart(int particleCount)
6161

6262
public void SetRandomDirection()
6363
{
64-
var count = Enum.GetValues(typeof(MoveDirection)).Length;
65-
var newDirection = (MoveDirection)RNG.Next(count);
64+
var count = Enum.GetValues(typeof(ParticlesDirection)).Length;
65+
var newDirection = (ParticlesDirection)RNG.Next(1, count);
6666

6767
if (Direction.Value == newDirection)
6868
{
@@ -169,21 +169,21 @@ private class Particle
169169

170170
public Particle()
171171
{
172-
reset(MoveDirection.Forward, false);
172+
reset(ParticlesDirection.Forward, false);
173173
}
174174

175-
private void reset(MoveDirection direction, bool maxDepth = true)
175+
private void reset(ParticlesDirection direction, bool maxDepth = true)
176176
{
177177
switch (direction)
178178
{
179179
default:
180-
case MoveDirection.Backwards:
180+
case ParticlesDirection.Backwards:
181181
initialPosition = new Vector2(RNG.NextSingle(-0.5f, 0.5f), RNG.NextSingle(-0.5f, 0.5f)) * max_depth;
182182
CurrentPosition = getPositionOnTheEdge(Vector2.Divide(initialPosition.Value, max_depth));
183183
currentDepth = initialPosition.Value.X / CurrentPosition.X;
184184
break;
185185

186-
case MoveDirection.Forward:
186+
case ParticlesDirection.Forward:
187187
currentDepth = maxDepth ? max_depth : RNG.NextSingle(min_depth, max_depth);
188188
initialPosition = new Vector2(RNG.NextSingle(-0.5f, 0.5f), RNG.NextSingle(-0.5f, 0.5f)) * max_depth;
189189
CurrentPosition = getCurrentPosition(direction);
@@ -194,32 +194,32 @@ private void reset(MoveDirection direction, bool maxDepth = true)
194194
}
195195
break;
196196

197-
case MoveDirection.Left:
197+
case ParticlesDirection.Left:
198198
CurrentPosition = getRandomPositionAtTheLeft();
199199
break;
200200

201-
case MoveDirection.Right:
201+
case ParticlesDirection.Right:
202202
CurrentPosition = getRandomPositionAtTheRight();
203203
break;
204204

205-
case MoveDirection.Up:
205+
case ParticlesDirection.Up:
206206
CurrentPosition = getRandomPositionAtTheTop();
207207
break;
208208

209-
case MoveDirection.Down:
209+
case ParticlesDirection.Down:
210210
CurrentPosition = getRandomPositionAtTheBottom();
211211
break;
212212
}
213213

214214
updateProperties();
215215
}
216216

217-
public void UpdateCurrentPosition(float timeDifference, MoveDirection direction, float multiplier, bool horizontalIsFaster)
217+
public void UpdateCurrentPosition(float timeDifference, ParticlesDirection direction, float multiplier, bool horizontalIsFaster)
218218
{
219219
switch (direction)
220220
{
221221
default:
222-
case MoveDirection.Forward:
222+
case ParticlesDirection.Forward:
223223
currentDepth -= timeDifference;
224224

225225
if (currentDepth < min_depth)
@@ -238,7 +238,7 @@ public void UpdateCurrentPosition(float timeDifference, MoveDirection direction,
238238

239239
break;
240240

241-
case MoveDirection.Backwards:
241+
case ParticlesDirection.Backwards:
242242
currentDepth += timeDifference;
243243

244244
if (currentDepth > max_depth)
@@ -250,7 +250,7 @@ public void UpdateCurrentPosition(float timeDifference, MoveDirection direction,
250250
CurrentPosition = getCurrentPosition(direction);
251251
break;
252252

253-
case MoveDirection.Left:
253+
case ParticlesDirection.Left:
254254
initialPosition = null;
255255
CurrentPosition += new Vector2(max_depth / currentDepth * timeDifference * (horizontalIsFaster ? multiplier : 1) * side_speed_multiplier, 0);
256256

@@ -260,7 +260,7 @@ public void UpdateCurrentPosition(float timeDifference, MoveDirection direction,
260260
}
261261
break;
262262

263-
case MoveDirection.Right:
263+
case ParticlesDirection.Right:
264264
initialPosition = null;
265265
CurrentPosition -= new Vector2(max_depth / currentDepth * timeDifference * (horizontalIsFaster ? multiplier : 1) * side_speed_multiplier, 0);
266266

@@ -270,7 +270,7 @@ public void UpdateCurrentPosition(float timeDifference, MoveDirection direction,
270270
}
271271
break;
272272

273-
case MoveDirection.Up:
273+
case ParticlesDirection.Up:
274274
initialPosition = null;
275275
CurrentPosition += new Vector2(0, max_depth / currentDepth * timeDifference * (horizontalIsFaster ? 1 : multiplier) * side_speed_multiplier);
276276

@@ -280,7 +280,7 @@ public void UpdateCurrentPosition(float timeDifference, MoveDirection direction,
280280
}
281281
break;
282282

283-
case MoveDirection.Down:
283+
case ParticlesDirection.Down:
284284
initialPosition = null;
285285
CurrentPosition -= new Vector2(0, max_depth / currentDepth * timeDifference * (horizontalIsFaster ? 1 : multiplier) * side_speed_multiplier);
286286

@@ -300,13 +300,13 @@ private void updateProperties()
300300
CurrentAlpha = CurrentSize < 1 ? MathExtensions.Map(CurrentSize, particle_min_size, 1, 0, 1) : 1;
301301
}
302302

303-
private Vector2 getCurrentPosition(MoveDirection direction)
303+
private Vector2 getCurrentPosition(ParticlesDirection direction)
304304
{
305305
switch (direction)
306306
{
307307
default:
308-
case MoveDirection.Forward:
309-
case MoveDirection.Backwards:
308+
case ParticlesDirection.Forward:
309+
case ParticlesDirection.Backwards:
310310
if (initialPosition.HasValue)
311311
{
312312
return Vector2.Divide(initialPosition.Value, currentDepth);
@@ -350,8 +350,9 @@ private static Vector2 getPositionOnTheEdge(Vector2 inBoundsPosition)
350350
}
351351
}
352352

353-
public enum MoveDirection
353+
public enum ParticlesDirection
354354
{
355+
Random,
355356
Forward,
356357
Backwards,
357358
Left,

osu.Game.Rulesets.Sandbox/Screens/Visualizer/Components/Settings/BackgroundSection.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ private void load(OsuConfigManager config, SandboxRulesetConfigManager rulesetCo
2626
LabelText = "Show particles",
2727
Current = rulesetConfig.GetBindable<bool>(SandboxRulesetSetting.ShowParticles)
2828
},
29+
new SettingsEnumDropdown<ParticlesDirection>
30+
{
31+
LabelText = "Particles direction",
32+
Current = rulesetConfig.GetBindable<ParticlesDirection>(SandboxRulesetSetting.ParticlesDirection)
33+
},
2934
new ColourPickerDropdown("Particles colour", SandboxRulesetSetting.ParticlesColour),
3035
new SettingsSlider<int>
3136
{

0 commit comments

Comments
 (0)