1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 11:37:28 +08:00

Merge pull request #27 from RemieRichards/update_to_new_children_syntax

Updates to latest osu-framework, Updates Load()s to use new Children syntax
This commit is contained in:
Dean Herbert 2016-09-19 10:12:54 +09:00 committed by GitHub
commit 9a5874b063
9 changed files with 145 additions and 1070 deletions

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

View File

@ -1,134 +0,0 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using OpenTK;
using OpenTK.Graphics;
using osu.Framework;
using osu.Framework.GameModes;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Drawables;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Transformations;
using osu.Framework.Input;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using osu.Framework.Threading;
namespace osu.Game.GameModes
{
internal class FieldTest : GameMode
{
private AutoSizeContainer container;
public override void Load()
{
base.Load();
OsuGame game = Game as OsuGame;
Add(new Box()
{
SizeMode = InheritMode.XY,
Size = new Vector2(1, 1),
Colour = Color4.DarkRed
});
ClickableBox button;
Add(button = new ClickableBox(Color4.Pink)
{
Size = new Vector2(50, 50)
});
button.Activated += () => ExitMode();
Add(container = new AutoSizeContainer()
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre
});
container.Add(new ClickableBox(Color4.SkyBlue)
{
SizeMode = InheritMode.XY,
Size = Vector2.One
});
container.Add(new ClickableBox(Color4.Orange)
{
Size = new Vector2(50, 50),
Anchor = Anchor.TopLeft,
Origin = Anchor.TopLeft
});
container.Add(new ClickableBox(Color4.Orange)
{
Size = new Vector2(50, 50),
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight
});
container.Add(new ClickableBox(Color4.Orange)
{
Size = new Vector2(50, 50),
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft
});
container.Add(new ClickableBox(Color4.Blue)
{
Size = new Vector2(10, 10),
Anchor = Anchor.Centre,
Origin = Anchor.Centre
});
container.Add(new ClickableBox(Color4.Orange)
{
Size = new Vector2(50, 50),
Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight
});
container.Add(new SpriteCircular(game.Textures.Get("coin"))
{
Position = new Vector2(100),
Origin = Anchor.Centre,
Anchor = Anchor.Centre
});
Add(new SpriteText(game.Textures)
{
Origin = Anchor.CentreLeft,
Anchor = Anchor.CentreLeft,
Text = "12345"
});
}
class ClickableBox : Box
{
public ClickableBox(Color4? colour = default(Color4?))
{
Colour = colour ?? Color4.White;
}
internal event Action Activated;
protected override bool OnClick(InputState state)
{
Scale = new Vector2(1.5f);
ScaleTo(1, 500, EasingTypes.In);
Activated?.Invoke();
return true;
}
}
}
}

View File

@ -1,52 +0,0 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using osu.Framework;
using osu.Framework.GameModes;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Drawables;
using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics.Containers;
using OpenTK;
namespace osu.Game.GameModes
{
class FontTest : OsuGameMode
{
private FlowContainer flow;
public override void Load()
{
base.Load();
flow = new FlowContainer()
{
Anchor = Anchor.TopLeft,
Direction = FlowDirection.VerticalOnly
};
Add(flow);
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()
{
base.Update();
}
}
}

View File

@ -50,41 +50,47 @@ namespace osu.Game.GameModes.Menu
{
base.Load();
osuLogo = new OsuLogo(onOsuLogo)
Children = new Drawable[]
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
buttonArea = new Container
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
SizeMode = InheritMode.X,
Size = new Vector2(1, button_area_height),
Alpha = 0,
Children = new Drawable[]
{
new Box
{
SizeMode = InheritMode.XY,
Colour = new Color4(50, 50, 50, 255)
},
buttonFlow = new FlowContainerWithOrigin
{
Anchor = Anchor.Centre,
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
}
}
},
osuLogo = new OsuLogo(onOsuLogo)
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre
}
};
Add(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()
{
SizeMode = InheritMode.XY,
Colour = new Color4(50, 50, 50, 255)
});
buttonArea.Add(buttonFlow = new FlowContainerWithOrigin()
{
Anchor = Anchor.Centre,
Position = new Vector2(wedge_width * 2 - (button_width + osuLogo.SizeForFlow / 4), 0),
Padding = new Vector2(-wedge_width, 0)
});
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) });
buttonFlow.Position = new Vector2(wedge_width * 2 - (button_width + osuLogo.SizeForFlow / 4), 0);
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)));
@ -95,8 +101,6 @@ namespace osu.Game.GameModes.Menu
buttonsTopLevel.Add((Button)buttonFlow.Add(new Button(@"osu!editor", @"edit", FontAwesome.fa_osu_edit_o, new Color4(238, 170, 0, 255), onEdit, 0, Key.E)));
buttonsTopLevel.Add((Button)buttonFlow.Add(new Button(@"osu!direct", @"direct", FontAwesome.fa_osu_chevron_down_o, new Color4(165, 204, 0, 255), onDirect, 0, Key.D)));
buttonsTopLevel.Add((Button)buttonFlow.Add(new Button(@"exit", @"exit", FontAwesome.fa_osu_cross_o, new Color4(238, 51, 153, 255), onExit, 0, Key.Q)));
buttonFlow.CentreTarget = iconFacade;
}
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
@ -285,38 +289,41 @@ namespace osu.Game.GameModes.Menu
{
base.Load();
Add(logoBounceContainer = new AutoSizeContainer());
Sprite ripple;
logo = new Sprite(Game.Textures.Get(@"menu-osu"))
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
};
logoBounceContainer.Add(logo);
Children = new Drawable[]
{
logoBounceContainer = new AutoSizeContainer
{
Children = new Drawable[]
{
logo = new Sprite(Game.Textures.Get(@"menu-osu"))
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre
},
ripple = new Sprite(Game.Textures.Get(@"menu-osu"))
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Alpha = 0.4f
},
vis = new MenuVisualisation
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = logo.Size,
Additive = true,
Alpha = 0.2f,
}
}
}
};
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()
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = logo.Size,
Additive = true,
//Radius = logo.Size.X / 2 * 0.96f,
Alpha = 0.2f,
});
ripple.ScaleTo(1.1f, 500);
ripple.FadeOut(500);
ripple.Loop(300);
}
public OsuLogo(Action action)
@ -414,46 +421,40 @@ namespace osu.Game.GameModes.Menu
this.text = text;
}
public override void Load()
{
base.Load();
Alpha = 0;
public override void Load()
{
base.Load();
Alpha = 0;
Add(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
{
Position = new Vector2(extraWidth / 2, 0),
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
};
Add(iconText);
icon = new TextAwesome(symbol, 40, Vector2.Zero)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Scale = new Vector2(0.7f),
};
iconText.Add(icon);
SpriteText ft = new SpriteText()
{
Direction = FlowDirection.HorizontalOnly,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Position = new Vector2(0, 25),
Text = text
};
iconText.Add(ft);
}
Children = 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
{
Position = new Vector2(extraWidth / 2, 0),
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Children = new Drawable[]
{
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
}
}
}
};
}
protected override bool OnHover(InputState state)
{

View File

@ -5,8 +5,9 @@ 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;
using osu.Framework.Graphics.UserInterface;
namespace osu.Game.GameModes.Menu
{
@ -16,28 +17,28 @@ namespace osu.Game.GameModes.Menu
private AudioTrackBass bgm;
public override void Load()
{
base.Load();
public override void Load()
{
base.Load();
AudioSample welcome = Game.Audio.Sample.Get(@"welcome");
//welcome.Play();
AudioSample welcome = Game.Audio.Sample.Get(@"welcome");
Add(new ButtonSystem());
Add(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()
{
Text = @"The quick brown fox jumped over the lazy dog.",
Position = new Vector2(50, 80),
Size = new Vector2(300, 20)
});
}
Children = 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)
},
new SpriteText
{
Text = @"The quick brown fox jumped over the lazy dog.",
Position = new Vector2(50, 80),
Size = new Vector2(300, 20)
}
};
}
}
}

View File

@ -1,36 +0,0 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Drawables;
using osu.Framework.Input;
using OpenTK;
namespace osu.Game.Graphics.Cursor
{
class CursorContainer : LargeContainer
{
private Cursor cursor;
public CursorContainer()
{
Add(cursor = new Cursor());
}
protected override bool OnMouseMove(InputState state)
{
cursor.Position = GetLocalPosition(state.Mouse.Position);
return base.OnMouseMove(state);
}
class Cursor : Box
{
public Cursor()
{
Size = new Vector2(5, 5);
Origin = Anchor.Centre;
}
}
}
}

View File

@ -1,706 +0,0 @@
using System;
using System.Collections.Generic;
using osu.Framework;
using osu.Framework.Audio.Sample;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Drawables;
using OpenTK.Graphics;
using osu.Framework.Graphics;
using OpenTK;
using osu.Framework.Cached;
using osu.Framework.Graphics.Transformations;
using OpenTK.Input;
using osu.Framework.Input;
using osu.Framework.Graphics.Sprites;
using osu.Framework.MathUtils;
using osu.Framework.Threading;
namespace osu.Game.Graphics.UserInterface
{
internal class TextBox : ProcessingContainer
{
private FlowContainer textFlow;
private Box background;
protected Box cursor;
protected Container TextContainer;
internal int? LengthLimit;
internal bool ResetTextOnEdit;
internal string textBeforeCommit;
internal virtual bool AllowClipboardExport => true;
protected virtual Color4 BackgroundCommit => new Color4(249, 90, 255, 200);
protected virtual Color4 BackgroundFocused => new Color4(100, 100, 100, 255);
protected virtual Color4 BackgroundUnfocused => new Color4(100, 100, 100, 120);
public bool ReadOnly;
TextInputSource textInput;
internal delegate void OnCommitHandler(TextBox sender, bool newText);
internal event OnCommitHandler OnCommit;
public event OnCommitHandler OnChange;
internal float SpaceWidth = 10;
private Scheduler textUpdateScheduler = new Scheduler();
public override void Load()
{
base.Load();
AddProcessing(new MaskingContainer());
Add(background = new Box()
{
Colour = BackgroundUnfocused,
SizeMode = InheritMode.XY,
});
Add(TextContainer = new Container() { SizeMode = InheritMode.XY });
textFlow = new FlowContainer()
{
Direction = FlowDirection.HorizontalOnly,
};
cursor = new Box()
{
Size = Vector2.One,
Colour = Color4.Transparent,
SizeMode = InheritMode.Y,
Alpha = 0
};
TextContainer.Add(cursor);
TextContainer.Add(textFlow);
}
private void resetSelection()
{
selectionStart = selectionEnd = text.Length;
cursorAndLayout.Invalidate();
}
protected override void Dispose(bool disposing)
{
OnChange = null;
OnCommit = null;
UnbindInput();
base.Dispose(disposing);
}
private float textContainerPosX;
protected virtual float TextContainerIconOffset => 0;
protected string TextAtLastLayout = string.Empty;
protected override void UpdateLayout()
{
base.UpdateLayout();
//have to run this after children flow
cursorAndLayout.Refresh(delegate
{
textUpdateScheduler.Update();
Vector2 cursorPos = Vector2.Zero;
if (text.Length > 0)
cursorPos.X = getPositionAt(selectionLeft);
float cursorPosEnd = getPositionAt(selectionEnd);
float cursorWidth = 2;
if (selectionLength > 0)
cursorWidth = getPositionAt(selectionRight) - cursorPos.X;
float cursorRelativePositionInBox = (cursorPosEnd - textContainerPosX) / Width;
//we only want to reposition the view when the cursor reaches near the extremities.
if (cursorRelativePositionInBox < 0.1 || cursorRelativePositionInBox > 0.9)
{
textContainerPosX = cursorPosEnd - Width / 2;
}
textContainerPosX = MathHelper.Clamp(textContainerPosX, 0, Math.Max(0, textFlow.Width - Width));
TextContainer.MoveToX(TextContainerIconOffset - textContainerPosX, 300, EasingTypes.OutExpo);
if (HasFocus)
{
cursor.ClearTransformations();
cursor.MoveTo(cursorPos, 60, EasingTypes.Out);
cursor.ScaleTo(new Vector2(cursorWidth, 1), 60, EasingTypes.Out);
if (selectionLength > 0)
{
cursor.FadeTo(0.5f, 200, EasingTypes.Out);
cursor.FadeColour(new Color4(249, 90, 255, 255), 200, EasingTypes.Out);
}
else
{
cursor.FadeTo(0.5f, 200, EasingTypes.Out);
cursor.FadeColour(Color4.White, 200, EasingTypes.Out);
cursor.Transforms.Add(new TransformAlpha(Clock)
{
StartValue = 0.5f,
EndValue = 0.2f,
StartTime = Time,
EndTime = Time + 500,
Easing = EasingTypes.InOutSine,
LoopCount = -1,
});
}
}
OnChange?.Invoke(this, TextAtLastLayout != text);
TextAtLastLayout = text;
return cursorPos;
});
}
private float getPositionAt(int index)
{
if (index > 0)
{
if (index < text.Length)
return textFlow.Children[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;
}
else
return 0;
}
private int getCharacterClosestTo(Vector2 pos)
{
pos = textFlow.GetLocalPosition(pos);
int i = 0;
foreach (Drawable d in textFlow.Children)
{
if (d.Position.X + d.Size.X / 2 > pos.X)
break;
i++;
}
return i;
}
internal bool HandleLeftRightArrows = true;
int selectionStart;
int selectionEnd;
int selectionLength => Math.Abs(selectionEnd - selectionStart);
int selectionLeft => Math.Min(selectionStart, selectionEnd);
int selectionRight => Math.Max(selectionStart, selectionEnd);
Cached<Vector2> cursorAndLayout = new Cached<Vector2>();
private void moveSelection(int offset, bool expand)
{
if (textInput?.ImeActive == true) return;
int oldStart = selectionStart;
int oldEnd = selectionEnd;
if (expand)
selectionEnd = MathHelper.Clamp(selectionEnd + offset, 0, text.Length);
else
{
if (selectionLength > 0 && Math.Abs(offset) <= 1)
{
//we don't want to move the location when "removing" an existing selection, just set the new location.
if (offset > 0)
selectionEnd = selectionStart = selectionRight;
else
selectionEnd = selectionStart = selectionLeft;
}
else
selectionEnd = selectionStart = MathHelper.Clamp((offset > 0 ? selectionRight : selectionLeft) + offset, 0, text.Length);
}
if (oldStart != selectionStart || oldEnd != selectionEnd)
{
Game.Audio.Sample.Get(@"Keyboard/key-movement")?.Play();
cursorAndLayout.Invalidate();
}
}
private bool removeCharacterOrSelection(bool sound = true)
{
if (text.Length == 0) return false;
if (selectionLength == 0 && selectionLeft == 0) return false;
int count = MathHelper.Clamp(selectionLength, 1, text.Length);
int start = MathHelper.Clamp(selectionLength > 0 ? selectionLeft : selectionLeft - 1, 0, text.Length - count);
if (count == 0) return false;
if (sound)
Game.Audio.Sample.Get(@"Keyboard/key-delete")?.Play();
for (int i = 0; i < count; i++)
{
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)
selectionStart = selectionEnd = selectionLeft;
else
selectionStart = selectionEnd = selectionLeft - 1;
cursorAndLayout.Invalidate();
return true;
}
protected virtual Drawable AddCharacterToFlow(char c)
{
for (int i = selectionLeft; i < text.Length; i++)
textFlow.Children[i].Depth = i + 1;
Drawable ch;
if (char.IsWhiteSpace(c))
{
float width = SpaceWidth / 2;
switch ((int)c)
{
case 0x3000: //double-width space
width = SpaceWidth;
break;
}
textFlow.Add(ch = new Container()
{
SizeMode = InheritMode.None,
Size = new Vector2(width, SpaceWidth),
Depth = selectionLeft
});
}
else
{
textFlow.Add(ch = new SpriteText()
{
Text = c.ToString(),
Depth = selectionLeft
});
}
return ch;
}
/// <summary>
/// Insert an arbitrary string into the text at the current position.
/// </summary>
/// <param name="text"></param>
private void insertString(string text)
{
foreach (char c in text)
{
if (char.IsControl(c)) continue;
addCharacter(c);
}
}
private Drawable addCharacter(char c)
{
if (selectionLength > 0)
removeCharacterOrSelection();
if (text.Length + 1 > LengthLimit)
{
if (background.Alpha > 0)
background.FlashColour(Color4.Red, 200);
else
textFlow.FlashColour(Color4.Red, 200);
return null;
}
Drawable ch = AddCharacterToFlow(c);
ch.Position = new Vector2(0, SpaceWidth);
ch.MoveToY(0, 200, EasingTypes.OutExpo);
text = text.Insert(selectionLeft, c.ToString());
selectionStart = selectionEnd = selectionLeft + 1;
cursorAndLayout.Invalidate();
return ch;
}
private string text;
internal virtual string Text
{
get
{
return text;
}
set
{
if (value == text)
return;
textUpdateScheduler.Add(delegate
{
int startBefore = selectionStart;
selectionStart = selectionEnd = 0;
textFlow?.Clear();
text = string.Empty;
foreach (char c in value)
addCharacter(c);
selectionStart = MathHelper.Clamp(startBefore, 0, text.Length);
}, true);
cursorAndLayout.Invalidate();
}
}
public string SelectedText => selectionLength > 0 ? Text.Substring(selectionLeft, selectionLength) : string.Empty;
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
{
if (!HasFocus)
return false;
if (textInput?.ImeActive == true) return true;
switch (args.Key)
{
case Key.Tab:
return false;
case Key.End:
moveSelection(text.Length, state.Keyboard.ShiftPressed);
return true;
case Key.Home:
moveSelection(-text.Length, state.Keyboard.ShiftPressed);
return true;
case Key.Left:
{
if (!HandleLeftRightArrows) return false;
if (selectionEnd == 0) return true;
int amount = 1;
if (state.Keyboard.ControlPressed)
{
int lastSpace = text.LastIndexOf(' ', Math.Max(0, selectionEnd - 2));
if (lastSpace >= 0)
amount = selectionEnd - lastSpace - 1;
else
amount = selectionEnd;
}
moveSelection(-amount, state.Keyboard.ShiftPressed);
}
return true;
case Key.Right:
{
if (!HandleLeftRightArrows) return false;
if (selectionEnd == text.Length) return true;
int amount = 1;
if (state.Keyboard.ControlPressed)
{
int nextSpace = text.IndexOf(' ', selectionEnd + 1);
if (nextSpace >= 0)
amount = nextSpace - selectionEnd;
else
amount = text.Length - selectionEnd;
}
moveSelection(amount, state.Keyboard.ShiftPressed);
}
return true;
case Key.Enter:
TriggerFocusLost(state);
return true;
case Key.Delete:
if (selectionLength == 0)
{
if (text.Length == selectionStart)
return true;
if (state.Keyboard.ControlPressed)
{
int spacePos = selectionStart;
while (text[spacePos] == ' ' && spacePos < text.Length)
spacePos++;
spacePos = MathHelper.Clamp(text.IndexOf(' ', spacePos), 0, text.Length);
selectionEnd = spacePos;
if (selectionStart == 0 && spacePos == 0)
selectionEnd = text.Length;
if (selectionLength == 0)
return true;
}
else
{
//we're deleting in front of the cursor, so move the cursor forward once first
selectionStart = selectionEnd = selectionStart + 1;
}
}
removeCharacterOrSelection();
return true;
case Key.Back:
if (selectionLength == 0 && state.Keyboard.ControlPressed)
{
int spacePos = selectionLeft >= 2 ? Math.Max(0, text.LastIndexOf(' ', selectionLeft - 2) + 1) : 0;
selectionStart = spacePos;
}
removeCharacterOrSelection();
return true;
}
if (state.Keyboard.ControlPressed)
{
//handling of function keys
switch (args.Key)
{
case Key.A:
selectionStart = 0;
selectionEnd = text.Length;
cursorAndLayout.Invalidate();
return true;
case Key.C:
if (string.IsNullOrEmpty(SelectedText) || !AllowClipboardExport) return true;
//System.Windows.Forms.Clipboard.SetText(SelectedText);
return true;
case Key.X:
if (string.IsNullOrEmpty(SelectedText)) return true;
//if (AllowClipboardExport)
// System.Windows.Forms.Clipboard.SetText(SelectedText);
removeCharacterOrSelection();
return true;
case Key.V:
//the text is pasted into the hidden textbox, so we don't need any direct clipboard interaction here.
//insertString(textInput.GetPendingText());
return true;
}
return false;
}
string str = textInput.GetPendingText();
if (!string.IsNullOrEmpty(str))
{
if (state.Keyboard.ShiftPressed)
Game.Audio.Sample.Get(@"Keyboard/key-caps")?.Play();
else
Game.Audio.Sample.Get($@"Keyboard/key-press-{RNG.Next(1, 5)}")?.Play();
insertString(str);
return true;
}
return false;
}
protected override bool OnDrag(InputState state)
{
//if (textInput?.ImeActive == true) return true;
if (text.Length == 0) return true;
selectionEnd = getCharacterClosestTo(state.Mouse.Position);
if (selectionLength > 0)
TriggerFocus();
cursorAndLayout.Invalidate();
return true;
}
protected override bool OnDragStart(InputState state)
{
//need to handle this so we get onDrag events.
return true;
}
protected override bool OnDoubleClick(InputState state)
{
if (textInput?.ImeActive == true) return true;
if (text.Length == 0) return true;
int hover = Math.Min(text.Length - 1, getCharacterClosestTo(state.Mouse.Position));
int lastSpace = text.LastIndexOf(' ', hover);
int nextSpace = text.IndexOf(' ', hover);
selectionStart = lastSpace >= 0 ? lastSpace + 1 : 0;
selectionEnd = nextSpace >= 0 ? nextSpace : text.Length;
cursorAndLayout.Invalidate();
return true;
}
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
{
if (textInput?.ImeActive == true) return true;
selectionStart = selectionEnd = getCharacterClosestTo(state.Mouse.Position);
cursorAndLayout.Invalidate();
return true;
}
protected override void OnFocusLost(InputState state)
{
UnbindInput();
cursor.ClearTransformations();
cursor.FadeOut(200);
if (state.Keyboard.Keys.Contains(Key.Enter))
{
background.Colour = BackgroundUnfocused;
background.ClearTransformations();
background.FlashColour(BackgroundCommit, 400);
Game.Audio.Sample.Get(@"Keyboard/key-confirm")?.Play();
OnCommit?.Invoke(this, true);
}
else
{
background.ClearTransformations();
background.FadeColour(BackgroundUnfocused, 200, EasingTypes.OutExpo);
}
cursorAndLayout.Invalidate();
}
protected override bool OnFocus(InputState state)
{
if (ReadOnly) return false;
BindInput();
textBeforeCommit = Text;
if (ResetTextOnEdit)
Text = string.Empty;
background.ClearTransformations();
background.FadeColour(BackgroundFocused, 200, EasingTypes.Out);
cursorAndLayout.Invalidate();
return true;
}
#region Native TextBox handling (winform specific)
protected void UnbindInput()
{
textInput?.Deactivate();
}
protected void BindInput()
{
if (textInput == null)
{
textInput = Game.Host.TextInput;
textInput.OnNewImeComposition += onImeComposition;
textInput.OnNewImeResult += onImeResult;
}
textInput.Activate();
}
private void onImeResult(string s)
{
//we only succeeded if there is pending data in the textbox
if (imeDrawables.Count > 0)
{
Game.Audio.Sample.Get($@"Keyboard/key-confirm")?.Play();
foreach (Drawable d in imeDrawables)
{
d.Colour = Color4.White;
d.FadeTo(1, 200, EasingTypes.Out);
}
}
imeDrawables.Clear();
}
List<Drawable> imeDrawables = new List<Drawable>();
private void onImeComposition(string s)
{
//search for unchanged characters..
int matchCount = 0;
bool matching = true;
bool didDelete = false;
int searchStart = text.Length - imeDrawables.Count;
//we want to keep processing to the end of the longest string (the current displayed or the new composition).
int maxLength = Math.Max(imeDrawables.Count, s.Length);
for (int i = 0; i < maxLength; i++)
{
if (matching && searchStart + i < text.Length && i < s.Length && text[searchStart + i] == s[i])
{
matchCount = i + 1;
continue;
}
matching = false;
if (matchCount < imeDrawables.Count)
{
//if we are no longer matching, we want to remove all further characters.
removeCharacterOrSelection(false);
imeDrawables.RemoveAt(matchCount);
didDelete = true;
}
}
if (matchCount == s.Length)
{
//in the case of backspacing (or a NOP), we can exit early here.
if (didDelete)
Game.Audio.Sample.Get($@"Keyboard/key-delete")?.Play();
return;
}
//add any new or changed characters
for (int i = matchCount; i < s.Length; i++)
{
Drawable dr = addCharacter(s[i]);
if (dr != null)
{
dr.Colour = Color4.Aqua;
dr.Alpha = 0.6f;
imeDrawables.Add(dr);
}
}
Game.Audio.Sample.Get($@"Keyboard/key-press-{RNG.Next(1, 5)}")?.Play();
}
#endregion
}
}

View File

@ -5,12 +5,12 @@ using System;
using System.Collections.Generic;
using osu.Game.Configuration;
using osu.Game.GameModes.Menu;
using osu.Game.Graphics.Cursor;
using osu.Game.Graphics.Processing;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using OpenTK;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Textures;
using osu.Framework.IO.Stores;
@ -29,7 +29,7 @@ namespace osu.Game
base.Load();
//this completely overrides the framework default. will need to change once we make a proper FontStore.
Fonts = new TextureStore(new GlyphStore(Resources, @"Fonts/Exo2.0-Regular")) { ScaleAdjust = 0.2f };
Fonts = new TextureStore(new GlyphStore(Resources, @"Fonts/Exo2.0-Regular")) { ScaleAdjust = 0.01f };
Parent.Size = new Vector2(Config.Get<int>(OsuConfig.Width), Config.Get<int>(OsuConfig.Height));
@ -40,18 +40,23 @@ namespace osu.Game
Token = Config.Get<string>(OsuConfig.Token)
};
//var req = new ListChannelsRequest();
//req.Success += content =>
//{
//};
//API.Queue(req);
//var req = new ListChannelsRequest();
//req.Success += content =>
//{
//};
//API.Queue(req);
AddProcessing(new RatioAdjust());
//Add(new FontTest());
Add(new MainMenu());
Add(new CursorContainer());
Children = new Drawable[]
{
new RatioAdjust
{
Children = new Drawable[]
{
new MainMenu(),
new CursorContainer()
}
}
};
}
protected override void Dispose(bool isDisposing)

View File

@ -46,17 +46,13 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Configuration\OsuConfigManager.cs" />
<Compile Include="GameModes\FontTest.cs" />
<Compile Include="GameModes\Menu\ButtonSystem.cs" />
<Compile Include="GameModes\Menu\MainMenu.cs" />
<Compile Include="GameModes\FieldTest.cs" />
<Compile Include="Graphics\Containers\OsuComponent.cs" />
<Compile Include="Graphics\Containers\OsuGameMode.cs" />
<Compile Include="Graphics\Containers\OsuLargeComponent.cs" />
<Compile Include="Graphics\Cursor\CursorContainer.cs" />
<Compile Include="Graphics\Processing\RatioAdjust.cs" />
<Compile Include="Graphics\TextAwesome.cs" />
<Compile Include="Graphics\UserInterface\TextBox.cs" />
<Compile Include="Online\API\APIAccess.cs" />
<Compile Include="Online\API\APIRequest.cs" />
<Compile Include="Online\API\OAuth.cs" />