1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-13 13:32:54 +08:00

Updates to latest osu-framework, Updates existing Load() methods to use Children = new Drawable[]{} syntax

This commit is contained in:
Remie Richards 2016-09-17 21:33:46 +01:00
parent b52c3074ef
commit 1a5c2b5221
6 changed files with 260 additions and 260 deletions

@ -1 +1 @@
Subproject commit 0b60779e350bb5c316a5fb0454989ea831001087
Subproject commit 6dcee1dcf50f33f87722104f12b990d7cd6d8eef

View File

@ -27,88 +27,80 @@ namespace osu.Game.GameModes
public override void Load()
{
base.Load();
OsuGame game = Game as OsuGame;
Add(new Box()
ClickableBox button;
Add(new Drawable[]
{
new Box()
{
SizeMode = InheritMode.XY,
Size = new Vector2(1, 1),
Colour = Color4.DarkRed
});
ClickableBox button;
Add(button = new ClickableBox(Color4.Pink)
},
button = new ClickableBox(Color4.Pink)
{
Size = new Vector2(50, 50)
});
button.Activated += () => ExitMode();
Add(container = new AutoSizeContainer()
},
container = new AutoSizeContainer()
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre
});
container.Add(new ClickableBox(Color4.SkyBlue)
Origin = Anchor.Centre,
Children = new Drawable[]
{
new ClickableBox(Color4.SkyBlue)
{
SizeMode = InheritMode.XY,
Size = Vector2.One
});
container.Add(new ClickableBox(Color4.Orange)
},
new ClickableBox(Color4.Orange)
{
Size = new Vector2(50, 50),
Anchor = Anchor.TopLeft,
Origin = Anchor.TopLeft
});
container.Add(new ClickableBox(Color4.Orange)
},
new ClickableBox(Color4.Orange)
{
Size = new Vector2(50, 50),
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight
});
container.Add(new ClickableBox(Color4.Orange)
},
new ClickableBox(Color4.Orange)
{
Size = new Vector2(50, 50),
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft
});
container.Add(new ClickableBox(Color4.Blue)
},
new ClickableBox(Color4.Blue)
{
Size = new Vector2(10, 10),
Anchor = Anchor.Centre,
Origin = Anchor.Centre
});
container.Add(new ClickableBox(Color4.Orange)
},
new ClickableBox(Color4.Orange)
{
Size = new Vector2(50, 50),
Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight
});
container.Add(new SpriteCircular(game.Textures.Get("coin"))
},
new SpriteCircular(game.Textures.Get("coin"))
{
Position = new Vector2(100),
Origin = Anchor.Centre,
Anchor = Anchor.Centre
});
Add(new SpriteText(game.Textures)
Anchor = Anchor.Centre,
Origin = Anchor.Centre
},
new SpriteText(game.Textures)
{
Origin = Anchor.CentreLeft,
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Text = "12345"
}
}
}
});
button.Activated += () => ExitMode();
}
class ClickableBox : Box

View File

@ -25,23 +25,25 @@ namespace osu.Game.GameModes
{
base.Load();
flow = new FlowContainer()
Drawable[] flowChildren = new Drawable[50];
for (int i = 0; i < 50; i++)
{
int j = i + 1;
flowChildren[i] = new SpriteText()
{
Text = $@"Font testy at size {j}",
Scale = new Vector2(j)
};
}
Add(flow = new FlowContainer()
{
Anchor = Anchor.TopLeft,
Direction = FlowDirection.VerticalOnly
};
Add(flow);
Direction = FlowDirection.VerticalOnly,
Children = flowChildren,
});
for (int i = 1; i < 50; i++)
{
SpriteText text = new SpriteText()
{
Text = $@"Font testy at size {i}",
Scale = new Vector2(i)
};
flow.Add(text);
}
}
protected override void Update()

View File

@ -50,42 +50,47 @@ namespace osu.Game.GameModes.Menu
{
base.Load();
Add(new Drawable[]
{
osuLogo = new OsuLogo(onOsuLogo)
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
};
Add(buttonArea = new Container()
Anchor = Anchor.Centre
},
buttonArea = new Container()
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
SizeMode = InheritMode.X,
Size = new Vector2(1, button_area_height),
Alpha = 0
});
Add(osuLogo);
buttonArea.Add(new Box()
Alpha = 0,
Children = new Drawable[]
{
new Box()
{
SizeMode = InheritMode.XY,
Colour = new Color4(50, 50, 50, 255)
});
buttonArea.Add(buttonFlow = new FlowContainerWithOrigin()
},
buttonFlow = new FlowContainerWithOrigin()
{
Anchor = Anchor.Centre,
Position = new Vector2(wedge_width * 2 - (button_width + osuLogo.SizeForFlow / 4), 0),
Padding = new Vector2(-wedge_width, 0)
Padding = new Vector2(-wedge_width, 0),
Children = new Drawable[]
{
settingsButton = new Button(@"settings", @"options", FontAwesome.gear, new Color4(85, 85, 85, 255), onSettings, -wedge_width, Key.O),
backButton = new Button(@"back", @"back", FontAwesome.fa_osu_left_o, new Color4(51, 58, 94, 255), onBack, -wedge_width, Key.Escape),
iconFacade = new Container() //need a container to make the osu! icon flow properly.
{
Size = new Vector2(0, button_area_height)
}
},
CentreTarget = iconFacade
}
}
}
});
buttonFlow.Add(settingsButton = new Button(@"settings", @"options", FontAwesome.gear, new Color4(85, 85, 85, 255), onSettings, -wedge_width, Key.O));
buttonFlow.Add(backButton = new Button(@"back", @"back", FontAwesome.fa_osu_left_o, new Color4(51, 58, 94, 255), onBack, -wedge_width, Key.Escape));
//need a container to make the osu! icon flow properly.
buttonFlow.Add(iconFacade = new Container() { Size = new Vector2(0, button_area_height) });
buttonsPlay.Add((Button)buttonFlow.Add(new Button(@"solo", @"freeplay", FontAwesome.user, new Color4(102, 68, 204, 255), onSolo, wedge_width, Key.P)));
buttonsPlay.Add((Button)buttonFlow.Add(new Button(@"multi", @"multiplayer", FontAwesome.users, new Color4(94, 63, 186, 255), onMulti, 0, Key.M)));
buttonsPlay.Add((Button)buttonFlow.Add(new Button(@"chart", @"charts", FontAwesome.fa_osu_charts, new Color4(80, 53, 160, 255), onChart)));
@ -285,37 +290,35 @@ namespace osu.Game.GameModes.Menu
{
base.Load();
Add(logoBounceContainer = new AutoSizeContainer());
logo = new Sprite(Game.Textures.Get(@"menu-osu"))
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
};
logoBounceContainer.Add(logo);
Sprite ripple = new Sprite(Game.Textures.Get(@"menu-osu"))
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Alpha = 0.4f
};
logoBounceContainer.Add(ripple);
ripple.ScaleTo(1.1f, 500);
ripple.FadeOut(500);
ripple.Loop(300);
logoBounceContainer.Add(vis = new MenuVisualisation()
Add(logoBounceContainer = new AutoSizeContainer()
{
Children = new Drawable[]
{
logo = new Sprite(Game.Textures.Get(@"menu-osu"))
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre
},
ripple,
vis = new MenuVisualisation()
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = logo.Size,
Additive = true,
//Radius = logo.Size.X / 2 * 0.96f,
Alpha = 0.2f,
}
}
});
}
@ -419,40 +422,34 @@ namespace osu.Game.GameModes.Menu
base.Load();
Alpha = 0;
Add(box = new WedgedBox(new Vector2(button_width + Math.Abs(extraWidth), button_area_height), wedge_width)
Add(new Drawable[]
{
box = new WedgedBox(new Vector2(button_width + Math.Abs(extraWidth), button_area_height), wedge_width)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Colour = colour,
Scale = new Vector2(0, 1)
});
iconText = new AutoSizeContainer
Scale = new Vector2(0, 2)
},
iconText = new AutoSizeContainer()
{
Position = new Vector2(extraWidth / 2, 0),
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
};
Add(iconText);
icon = new TextAwesome(symbol, 40, Vector2.Zero)
Children = new Drawable[]
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Scale = new Vector2(0.7f),
};
iconText.Add(icon);
SpriteText ft = new SpriteText()
icon = new TextAwesome(symbol, 40, Vector2.Zero),
new SpriteText()
{
Direction = FlowDirection.HorizontalOnly,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Position = new Vector2(0, 25),
Text = text
};
iconText.Add(ft);
}
}
}
});
}
protected override bool OnHover(InputState state)

View File

@ -5,6 +5,7 @@ using OpenTK;
using osu.Framework.Audio.Sample;
using osu.Framework.Audio.Track;
using osu.Framework.GameModes;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
@ -21,22 +22,22 @@ namespace osu.Game.GameModes.Menu
base.Load();
AudioSample welcome = Game.Audio.Sample.Get(@"welcome");
//welcome.Play();
Add(new ButtonSystem());
Add(new TextBox()
Add(new Drawable[]
{
new ButtonSystem(),
new TextBox()
{
Text = @"The quick brown fox jumped over the lazy dog.",
Position = new Vector2(50, 50),
Size = new Vector2(300, 20)
});
Add(new SpriteText()
},
new SpriteText()
{
Text = @"The quick brown fox jumped over the lazy dog.",
Position = new Vector2(50, 80),
Size = new Vector2(300, 20)
}
});
}
}

View File

@ -14,6 +14,8 @@ using osu.Framework.Input;
using osu.Framework.Graphics.Sprites;
using osu.Framework.MathUtils;
using osu.Framework.Threading;
using System.Linq;
using osu.Framework.Extensions.IEnumerableExtensions;
namespace osu.Game.Graphics.UserInterface
{
@ -49,32 +51,34 @@ namespace osu.Game.Graphics.UserInterface
public override void Load()
{
base.Load();
AddProcessing(new MaskingContainer());
Add(background = new Box()
Add(new Drawable[]
{
new MaskingContainer(),
background = new Box()
{
Colour = BackgroundUnfocused,
SizeMode = InheritMode.XY,
});
Add(TextContainer = new Container() { SizeMode = InheritMode.XY });
textFlow = new FlowContainer()
SizeMode = InheritMode.XY
},
TextContainer = new Container()
{
SizeMode = InheritMode.XY,
Children = new Drawable[]
{
Direction = FlowDirection.HorizontalOnly,
};
cursor = new Box()
{
Size = Vector2.One,
Colour = Color4.Transparent,
SizeMode = InheritMode.Y,
Alpha = 0
};
},
textFlow = new FlowContainer()
{
Direction = FlowDirection.HorizontalOnly
}
}
},
TextContainer.Add(cursor);
TextContainer.Add(textFlow);
});
}
private void resetSelection()
@ -169,9 +173,12 @@ namespace osu.Game.Graphics.UserInterface
if (index > 0)
{
if (index < text.Length)
return textFlow.Children[index].Position.X + textFlow.Position.X;
return textFlow.Children.ElementAt(index).Position.X + textFlow.Position.X;
else
return textFlow.Children[index - 1].Position.X + textFlow.Children[index - 1].Size.X + textFlow.Padding.X + textFlow.Position.X;
{
var d = textFlow.Children.ElementAt(index - 1);
return d.Position.X + d.Size.X + textFlow.Padding.X + textFlow.Position.X;
}
}
else
return 0;
@ -247,16 +254,16 @@ namespace osu.Game.Graphics.UserInterface
if (sound)
Game.Audio.Sample.Get(@"Keyboard/key-delete")?.Play();
for (int i = 0; i < count; i++)
textFlow.Children.Skip(start).Take(count).ToList().ForEach(d =>
{
Drawable d = textFlow.Children[start];
textFlow.Remove(d);
TextContainer.Add(d);
d.FadeOut(200);
d.MoveToY(d.Size.Y, 200, EasingTypes.InExpo);
d.Expire();
}
});
text = text.Remove(start, count);
if (selectionLength > 0)
@ -270,8 +277,9 @@ namespace osu.Game.Graphics.UserInterface
protected virtual Drawable AddCharacterToFlow(char c)
{
for (int i = selectionLeft; i < text.Length; i++)
textFlow.Children[i].Depth = i + 1;
int i = selectionLeft;
foreach (Drawable dd in textFlow.Children.Skip(selectionLeft).Take(text.Length - selectionLeft))
dd.Depth = i + 1;
Drawable ch;