mirror of
https://github.com/ppy/osu.git
synced 2025-01-14 03:25:11 +08:00
Use null instead of -1
This commit is contained in:
parent
d495196b66
commit
32ef2405c4
@ -13,43 +13,51 @@ namespace osu.Game.Graphics.Containers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class SelectionCycleFillFlowContainer<T> : FillFlowContainer<T> where T : Drawable, ISelectable
|
public class SelectionCycleFillFlowContainer<T> : FillFlowContainer<T> where T : Drawable, ISelectable
|
||||||
{
|
{
|
||||||
private int selectedIndex = -1;
|
private int? selectedIndex;
|
||||||
|
|
||||||
private void setSelected(int value)
|
private void setSelected(int? value)
|
||||||
{
|
{
|
||||||
if (selectedIndex == value)
|
if (selectedIndex == value)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Deselect the previously-selected button
|
// Deselect the previously-selected button
|
||||||
if (selectedIndex != -1)
|
if (selectedIndex.HasValue)
|
||||||
this[selectedIndex].Selected = false;
|
this[selectedIndex.Value].Selected = false;
|
||||||
|
|
||||||
selectedIndex = value;
|
selectedIndex = value;
|
||||||
|
|
||||||
// Select the newly-selected button
|
// Select the newly-selected button
|
||||||
if (selectedIndex != -1)
|
if (selectedIndex.HasValue)
|
||||||
this[selectedIndex].Selected = true;
|
this[selectedIndex.Value].Selected = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SelectNext()
|
public void SelectNext()
|
||||||
{
|
{
|
||||||
if (selectedIndex == -1 || selectedIndex == Count - 1)
|
if (!selectedIndex.HasValue || selectedIndex == Count - 1)
|
||||||
setSelected(0);
|
setSelected(0);
|
||||||
else
|
else
|
||||||
setSelected(selectedIndex + 1);
|
setSelected(selectedIndex.Value + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SelectPrevious()
|
public void SelectPrevious()
|
||||||
{
|
{
|
||||||
if (selectedIndex == -1 || selectedIndex == 0)
|
if (!selectedIndex.HasValue || selectedIndex == 0)
|
||||||
setSelected(Count - 1);
|
setSelected(Count - 1);
|
||||||
else
|
else
|
||||||
setSelected(selectedIndex - 1);
|
setSelected(selectedIndex.Value - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Deselect() => setSelected(-1);
|
public void Deselect() => setSelected(null);
|
||||||
public void Select(T item) => setSelected(IndexOf(item));
|
public void Select(T item)
|
||||||
|
{
|
||||||
|
var newIndex = IndexOf(item);
|
||||||
|
|
||||||
public T Selected => (selectedIndex >= 0 && selectedIndex < Count) ? this[selectedIndex] : null;
|
if (newIndex < 0)
|
||||||
|
setSelected(null);
|
||||||
|
else
|
||||||
|
setSelected(IndexOf(item));
|
||||||
|
}
|
||||||
|
|
||||||
|
public T Selected => (selectedIndex >= 0 && selectedIndex < Count) ? this[selectedIndex.Value] : null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user