Skip to content

Commit

Permalink
Merge pull request #1664 from andy840119/adjust-layout-in-lyric-composer
Browse files Browse the repository at this point in the history
Able to switch different layout in the composer if bottom editor changed.
  • Loading branch information
andy840119 authored Oct 15, 2022
2 parents b06f979 + 5427d83 commit 949663e
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@ protected override Drawable CreateInfo()
return new Container();
}

protected override Drawable CreateContent()
{
return new AdjustTimeTagScrollContainer
{
RelativeSizeAxes = Axes.X,
Height = 100,
};
}
protected override Drawable CreateContent() => new AdjustTimeTagScrollContainer();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,28 @@ private void load(ILyricEditorState state, LyricEditorColourProvider colourProvi
},
new GridContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.Both,
ColumnDimensions = new[]
{
new Dimension(GridSizeMode.Absolute, info_part_spacing),
new Dimension()
},
RowDimensions = new[] { new Dimension(GridSizeMode.Relative) },
Content = new[]
{
new[]
{
CreateInfo(),
CreateInfo().With(x =>
{
x.RelativeSizeAxes = Axes.Both;
}),
new Container
{
Masking = true,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Child = CreateContent(),
RelativeSizeAxes = Axes.Both,
Child = CreateContent().With(x =>
{
x.RelativeSizeAxes = Axes.Both;
}),
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@ protected override Drawable CreateInfo()
return new Container();
}

protected override Drawable CreateContent()
{
return new NoteEditor
{
RelativeSizeAxes = Axes.X,
Height = 150,
};
}
protected override Drawable CreateContent() => new NoteEditor();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@ protected override Drawable CreateInfo()
return new Container();
}

protected override Drawable CreateContent()
{
return new RecordingTimeTagScrollContainer
{
RelativeSizeAxes = Axes.X,
Height = 60,
};
}
protected override Drawable CreateContent() => new RecordingTimeTagScrollContainer();
}
}
137 changes: 90 additions & 47 deletions osu.Game.Rulesets.Karaoke/Edit/Lyrics/Compose/LyricComposer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.EnumExtensions;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
Expand Down Expand Up @@ -39,67 +40,75 @@ public class LyricComposer : CompositeDrawable
[Resolved, AllowNull]
private LyricEditorColourProvider colourProvider { get; set; }

private readonly GridContainer gridContainer;

private readonly Container centerEditArea;
private readonly Container mainEditorArea;

private readonly Container bottomEditArea;
private readonly Container<BaseBottomEditor> bottomEditorContainer;

public LyricComposer()
{
Box centerEditorBackground;
Box bottomEditorBackground;

InternalChildren = new Drawable[]
InternalChild = gridContainer = new GridContainer
{
centerEditArea = new Container
RelativeSizeAxes = Axes.Both,
Content = new[]
{
Name = "Edit area and action buttons",
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
new Drawable[]
{
centerEditorBackground = new Box
{
Name = "Background",
RelativeSizeAxes = Axes.Both,
},
mainEditorArea = new Container
centerEditArea = new Container
{
Name = "Edit area and action buttons",
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
new LyricEditor(),
new SpecialActionToolbar
centerEditorBackground = new Box
{
Name = "Toolbar",
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
Name = "Background",
RelativeSizeAxes = Axes.Both,
},
mainEditorArea = new Container
{
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
new LyricEditor(),
new SpecialActionToolbar
{
Name = "Toolbar",
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
},
}
}
}
}
}
},
bottomEditArea = new Container
{
Name = "Edit area and action buttons",
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
Children = new Drawable[]
},
},
new Drawable[]
{
bottomEditorBackground = new Box
new Container
{
Name = "Background",
Name = "Edit area and action buttons",
RelativeSizeAxes = Axes.Both,
Masking = true,
Children = new Drawable[]
{
bottomEditorBackground = new Box
{
Name = "Background",
RelativeSizeAxes = Axes.Both,
},
bottomEditorContainer = new Container<BaseBottomEditor>
{
RelativeSizeAxes = Axes.Both,
}
}
},
bottomEditorContainer = new Container<BaseBottomEditor>
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
}
}
},
}
};

bindableModeAndSubMode.BindValueChanged(e =>
Expand All @@ -112,7 +121,7 @@ public LyricComposer()
return;

centerEditorBackground.Colour = colourProvider.Background1(e.NewValue.Mode);
bottomEditorBackground.Colour = colourProvider.Background5(e.NewValue.Mode);
bottomEditorBackground.Colour = colourProvider.Background4(e.NewValue.Mode);
});
}, true);

Expand All @@ -126,7 +135,7 @@ public LyricComposer()
bindableBottomEditorType.BindValueChanged(e =>
{
assignBottomEditor(e.NewValue);
});
}, true);

foreach (var (type, bindable) in panelStatus)
{
Expand Down Expand Up @@ -292,13 +301,42 @@ private void toggleChangeBottomEditor()

private void assignBottomEditor(BottomEditorType? bottomEditorType)
{
bottomEditorContainer.Clear();
const double remove_old_editor_time = 200;
const double new_animation_time = 200;

var bottomEditor = createBottomEditor(bottomEditorType);
if (bottomEditor != null)
bottomEditorContainer.Add(bottomEditor);
bool hasOldButtonEditor = bottomEditorContainer.Children.Any();
var newButtonEditor = createBottomEditor(bottomEditorType).With(x =>
{
if (x == null)
return;

calculateBottomEditAreaSize(bottomEditor);
x.RelativePositionAxes = Axes.Y;
x.Y = -1;
x.Alpha = 0;
});

if (hasOldButtonEditor)
{
bottomEditorContainer.Children.ForEach(editor =>
{
editor.MoveToY(-1, remove_old_editor_time).FadeOut(remove_old_editor_time).Then().OnComplete(x =>
{
x.Expire();

updateBottomEditAreaSize(newButtonEditor);
});
});
}
else
{
updateBottomEditAreaSize(newButtonEditor);
}

if (newButtonEditor == null)
return;

bottomEditorContainer.Add(newButtonEditor);
newButtonEditor.Delay(hasOldButtonEditor ? remove_old_editor_time : 0).FadeIn(0).MoveToY(0, new_animation_time);

static BaseBottomEditor? createBottomEditor(BottomEditorType? bottomEditorType) =>
bottomEditorType switch
Expand All @@ -308,11 +346,16 @@ private void assignBottomEditor(BottomEditorType? bottomEditorType)
BottomEditorType.Note => new NoteBottomEditor(),
_ => null
};
}

private void calculateBottomEditAreaSize(BaseBottomEditor? bottomEditor)
{
float bottomEditorHeight = bottomEditor?.ContentHeight ?? 0;
void updateBottomEditAreaSize(BaseBottomEditor? bottomEditor)
{
float bottomEditorHeight = bottomEditor?.ContentHeight ?? 0;
gridContainer.RowDimensions = new[]
{
new Dimension(),
new Dimension(GridSizeMode.Absolute, bottomEditorHeight)
};
}
}

#endregion
Expand Down

0 comments on commit 949663e

Please sign in to comment.