Simplify cycle logic

This commit is contained in:
Dean Herbert 2024-10-12 02:18:21 +09:00
parent d07a2fbb57
commit 05c8b3cbce
No known key found for this signature in database
1 changed files with 4 additions and 14 deletions

View File

@ -215,6 +215,8 @@ protected override void LoadComplete()
{
GridLinesRotation.Disabled = v.NewValue == PositionSnapGridType.Circle;
gridTypeButtons.Items[(int)v.NewValue].Select();
switch (v.NewValue)
{
case PositionSnapGridType.Square:
@ -243,28 +245,16 @@ private float normalizeRotation(float rotation, float period)
return ((rotation + 360 + period * 0.5f) % period) - period * 0.5f;
}
private void nextGridSize()
{
Spacing.Value = Spacing.Value * 2 >= max_automatic_spacing ? Spacing.Value / 8 : Spacing.Value * 2;
}
private void nextGridType()
{
int nextGridTypeIndex = (Array.IndexOf(grid_types, GridType.Value) + 1) % grid_types.Length;
GridType.Value = grid_types[nextGridTypeIndex];
gridTypeButtons.Items[nextGridTypeIndex].Select();
}
public bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
{
switch (e.Action)
{
case GlobalAction.EditorCycleGridSpacing:
nextGridSize();
Spacing.Value = Spacing.Value * 2 >= max_automatic_spacing ? Spacing.Value / 8 : Spacing.Value * 2;
return true;
case GlobalAction.EditorCycleGridType:
nextGridType();
GridType.Value = (PositionSnapGridType)(((int)GridType.Value + 1) % Enum.GetValues<PositionSnapGridType>().Length);
return true;
}