mirror of
https://github.com/ppy/osu.git
synced 2024-09-22 01:27:29 +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;
|
private SpriteText countSpriteText;
|
||||||
|
|
||||||
public override string Name { get; }
|
public override string Name { get; }
|
||||||
public KeyCounterCollection ParentCounter { get; set; }
|
public bool IsCounting { get; set; }
|
||||||
public int Count { get; private set; }
|
public int Count { get; private set; }
|
||||||
|
|
||||||
private bool isLit;
|
private bool isLit;
|
||||||
@ -30,7 +30,7 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
{
|
{
|
||||||
isLit = value;
|
isLit = value;
|
||||||
UpdateGlowSprite();
|
UpdateGlowSprite();
|
||||||
if (value && ParentCounter.IsCounting)
|
if (value && IsCounting)
|
||||||
IncreaseCount();
|
IncreaseCount();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
|
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
|
|
||||||
@ -13,14 +14,29 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
Direction = FlowDirection.HorizontalOnly;
|
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)
|
public void AddKey(KeyCounter key)
|
||||||
{
|
{
|
||||||
key.ParentCounter = this;
|
counters.Add(key);
|
||||||
|
key.IsCounting = this.IsCounting;
|
||||||
base.Add(key);
|
base.Add(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool Contains(Vector2 screenSpacePos) => true;
|
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