mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 11:37:28 +08:00
Avoid accessing container in each counter.
This commit is contained in:
parent
c70bf53486
commit
0da0d4f35e
@ -17,7 +17,7 @@ namespace osu.Game.Graphics.UserInterface
|
||||
private SpriteText countSpriteText;
|
||||
|
||||
public override string Name { get; }
|
||||
public KeyCounterCollection ParentCounter { get; set; }
|
||||
public bool IsCounting { get; set; }
|
||||
public int Count { get; private set; }
|
||||
|
||||
private bool isLit;
|
||||
@ -30,7 +30,7 @@ namespace osu.Game.Graphics.UserInterface
|
||||
{
|
||||
isLit = value;
|
||||
UpdateGlowSprite();
|
||||
if (value && ParentCounter.IsCounting)
|
||||
if (value && IsCounting)
|
||||
IncreaseCount();
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
|
||||
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System.Collections.Generic;
|
||||
using OpenTK;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
|
||||
@ -13,14 +14,29 @@ namespace osu.Game.Graphics.UserInterface
|
||||
Direction = FlowDirection.HorizontalOnly;
|
||||
}
|
||||
|
||||
private List<KeyCounter> counters = new List<KeyCounter>();
|
||||
//default capacity is 4, and osu! uses 4 keys usually, so it won't trouble
|
||||
public IReadOnlyList<KeyCounter> Counters => counters;
|
||||
|
||||
public void AddKey(KeyCounter key)
|
||||
{
|
||||
key.ParentCounter = this;
|
||||
counters.Add(key);
|
||||
key.IsCounting = this.IsCounting;
|
||||
base.Add(key);
|
||||
}
|
||||
|
||||
public override bool Contains(Vector2 screenSpacePos) => true;
|
||||
|
||||
public bool IsCounting { get; set; }
|
||||
private bool isCounting;
|
||||
public bool IsCounting
|
||||
{
|
||||
get { return isCounting; }
|
||||
set
|
||||
{
|
||||
isCounting = value;
|
||||
foreach (var child in counters)
|
||||
child.IsCounting = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user