mirror of
https://github.com/osukey/osukey.git
synced 2025-07-02 08:49:59 +09:00
Make Home, Settings and PlayMode buttons work.
This commit is contained in:
@ -2,6 +2,7 @@
|
|||||||
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
using osu.Framework.Configuration;
|
using osu.Framework.Configuration;
|
||||||
|
using osu.Game.GameModes.Play;
|
||||||
using osu.Game.Online.API;
|
using osu.Game.Online.API;
|
||||||
|
|
||||||
namespace osu.Game.Configuration
|
namespace osu.Game.Configuration
|
||||||
@ -17,6 +18,8 @@ namespace osu.Game.Configuration
|
|||||||
Set(OsuConfig.Username, string.Empty);
|
Set(OsuConfig.Username, string.Empty);
|
||||||
Set(OsuConfig.Password, string.Empty);
|
Set(OsuConfig.Password, string.Empty);
|
||||||
Set(OsuConfig.Token, string.Empty);
|
Set(OsuConfig.Token, string.Empty);
|
||||||
|
|
||||||
|
Set(OsuConfig.PlayMode, PlayMode.Osu);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,6 +30,7 @@ namespace osu.Game.Configuration
|
|||||||
MouseSensitivity,
|
MouseSensitivity,
|
||||||
Username,
|
Username,
|
||||||
Password,
|
Password,
|
||||||
Token
|
Token,
|
||||||
|
PlayMode
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ using OpenTK;
|
|||||||
|
|
||||||
namespace osu.Game.GameModes.Menu
|
namespace osu.Game.GameModes.Menu
|
||||||
{
|
{
|
||||||
internal class MainMenu : GameMode
|
public class MainMenu : GameMode
|
||||||
{
|
{
|
||||||
private ButtonSystem buttons;
|
private ButtonSystem buttons;
|
||||||
public override string Name => @"Main Menu";
|
public override string Name => @"Main Menu";
|
||||||
|
20
osu.Game/GameModes/Play/PlayMode.cs
Normal file
20
osu.Game/GameModes/Play/PlayMode.cs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
//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.ComponentModel;
|
||||||
|
|
||||||
|
namespace osu.Game.GameModes.Play
|
||||||
|
{
|
||||||
|
public enum PlayMode
|
||||||
|
{
|
||||||
|
[Description(@"osu!")]
|
||||||
|
Osu = 0,
|
||||||
|
[Description(@"taiko")]
|
||||||
|
Taiko = 1,
|
||||||
|
[Description(@"catch")]
|
||||||
|
Catch = 2,
|
||||||
|
[Description(@"mania")]
|
||||||
|
Mania = 3
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
|
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
|
using osu.Framework.Configuration;
|
||||||
using osu.Game.Configuration;
|
using osu.Game.Configuration;
|
||||||
using osu.Game.GameModes.Menu;
|
using osu.Game.GameModes.Menu;
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
@ -17,6 +18,9 @@ namespace osu.Game
|
|||||||
public class OsuGame : OsuGameBase
|
public class OsuGame : OsuGameBase
|
||||||
{
|
{
|
||||||
public Toolbar Toolbar;
|
public Toolbar Toolbar;
|
||||||
|
public MainMenu MainMenu;
|
||||||
|
|
||||||
|
public Bindable<PlayMode> PlayMode;
|
||||||
|
|
||||||
public override void SetHost(BasicGameHost host)
|
public override void SetHost(BasicGameHost host)
|
||||||
{
|
{
|
||||||
@ -36,9 +40,18 @@ namespace osu.Game
|
|||||||
new Background()
|
new Background()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
new MainMenu(),
|
MainMenu = new MainMenu(),
|
||||||
Toolbar = new Toolbar(),
|
Toolbar = new Toolbar
|
||||||
|
{
|
||||||
|
OnHome = delegate { MainMenu.MakeCurrent(); },
|
||||||
|
OnSettings = delegate { Options.PoppedOut = !Options.PoppedOut; },
|
||||||
|
OnPlayModeChange = delegate (PlayMode m) { PlayMode.Value = m; },
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
PlayMode = Config.GetBindable<PlayMode>(OsuConfig.PlayMode);
|
||||||
|
PlayMode.ValueChanged += delegate { Toolbar.SetGameMode(PlayMode.Value); };
|
||||||
|
PlayMode.TriggerChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool Invalidate(Invalidation invalidation = Invalidation.All, Drawable source = null, bool shallPropagate = true)
|
public override bool Invalidate(Invalidation invalidation = Invalidation.All, Drawable source = null, bool shallPropagate = true)
|
||||||
|
@ -10,6 +10,10 @@ using osu.Game.Graphics;
|
|||||||
using osu.Framework.Graphics.Sprites;
|
using osu.Framework.Graphics.Sprites;
|
||||||
using osu.Framework.Input;
|
using osu.Framework.Input;
|
||||||
using osu.Game.Configuration;
|
using osu.Game.Configuration;
|
||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using osu.Game.GameModes.Play;
|
||||||
|
using osu.Framework.Extensions;
|
||||||
|
|
||||||
namespace osu.Game.Overlays
|
namespace osu.Game.Overlays
|
||||||
{
|
{
|
||||||
@ -18,6 +22,12 @@ namespace osu.Game.Overlays
|
|||||||
const float height = 50;
|
const float height = 50;
|
||||||
private FlowContainer leftFlow;
|
private FlowContainer leftFlow;
|
||||||
private FlowContainer rightFlow;
|
private FlowContainer rightFlow;
|
||||||
|
private FlowContainer modeButtons;
|
||||||
|
|
||||||
|
public Action OnSettings;
|
||||||
|
public Action OnHome;
|
||||||
|
public Action<PlayMode> OnPlayModeChange;
|
||||||
|
|
||||||
|
|
||||||
public override void Load()
|
public override void Load()
|
||||||
{
|
{
|
||||||
@ -26,6 +36,27 @@ namespace osu.Game.Overlays
|
|||||||
RelativeSizeAxes = Axes.X;
|
RelativeSizeAxes = Axes.X;
|
||||||
Size = new Vector2(1, height);
|
Size = new Vector2(1, height);
|
||||||
|
|
||||||
|
modeButtons = new FlowContainer
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Y,
|
||||||
|
Direction = FlowDirection.HorizontalOnly
|
||||||
|
};
|
||||||
|
|
||||||
|
foreach (PlayMode m in Enum.GetValues(typeof(PlayMode)))
|
||||||
|
{
|
||||||
|
var localMode = m;
|
||||||
|
modeButtons.Add(new ToolbarModeButton
|
||||||
|
{
|
||||||
|
Mode = m,
|
||||||
|
Action = delegate
|
||||||
|
{
|
||||||
|
SetGameMode(localMode);
|
||||||
|
OnPlayModeChange?.Invoke(localMode);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
new Box
|
new Box
|
||||||
@ -37,15 +68,19 @@ namespace osu.Game.Overlays
|
|||||||
{
|
{
|
||||||
Direction = FlowDirection.HorizontalOnly,
|
Direction = FlowDirection.HorizontalOnly,
|
||||||
RelativeSizeAxes = Axes.Y,
|
RelativeSizeAxes = Axes.Y,
|
||||||
Size = new Vector2(0, 1),
|
|
||||||
Children = new []
|
Children = new []
|
||||||
{
|
{
|
||||||
new ToolbarButton(FontAwesome.gear),
|
new ToolbarButton
|
||||||
new ToolbarButton(FontAwesome.home),
|
{
|
||||||
new ToolbarModeButton(FontAwesome.fa_osu_osu_o, @"osu!"),
|
Icon = FontAwesome.gear,
|
||||||
new ToolbarModeButton(FontAwesome.fa_osu_taiko_o, @"taiko"),
|
Action = OnSettings
|
||||||
new ToolbarModeButton(FontAwesome.fa_osu_fruits_o, @"catch"),
|
},
|
||||||
new ToolbarModeButton(FontAwesome.fa_osu_mania_o, @"mania"),
|
new ToolbarButton
|
||||||
|
{
|
||||||
|
Icon = FontAwesome.home,
|
||||||
|
Action = OnHome
|
||||||
|
},
|
||||||
|
modeButtons
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
rightFlow = new FlowContainer
|
rightFlow = new FlowContainer
|
||||||
@ -57,32 +92,96 @@ namespace osu.Game.Overlays
|
|||||||
Size = new Vector2(0, 1),
|
Size = new Vector2(0, 1),
|
||||||
Children = new []
|
Children = new []
|
||||||
{
|
{
|
||||||
new ToolbarButton(FontAwesome.search),
|
new ToolbarButton
|
||||||
new ToolbarButton(FontAwesome.user, ((OsuGame)Game).Config.Get<string>(OsuConfig.Username)),
|
{
|
||||||
new ToolbarButton(FontAwesome.bars),
|
Icon = FontAwesome.search
|
||||||
|
},
|
||||||
|
new ToolbarButton
|
||||||
|
{
|
||||||
|
Icon = FontAwesome.user,
|
||||||
|
Text = ((OsuGame)Game).Config.Get<string>(OsuConfig.Username)
|
||||||
|
},
|
||||||
|
new ToolbarButton
|
||||||
|
{
|
||||||
|
Icon = FontAwesome.bars
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetGameMode(PlayMode mode)
|
||||||
|
{
|
||||||
|
foreach (var m in modeButtons.Children.Cast<ToolbarModeButton>())
|
||||||
|
{
|
||||||
|
m.Active = m.Mode == mode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public class ToolbarModeButton : ToolbarButton
|
public class ToolbarModeButton : ToolbarButton
|
||||||
{
|
{
|
||||||
public ToolbarModeButton(FontAwesome icon, string text = null) : base(icon, text)
|
private PlayMode mode;
|
||||||
|
public PlayMode Mode
|
||||||
{
|
{
|
||||||
|
get { return mode; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
mode = value;
|
||||||
|
Text = mode.GetDescription();
|
||||||
|
Icon = getModeIcon(mode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Active
|
||||||
|
{
|
||||||
|
set
|
||||||
|
{
|
||||||
|
Background.Colour = value ? new Color4(100, 100, 100, 140) : new Color4(20, 20, 20, 140);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private FontAwesome getModeIcon(PlayMode mode)
|
||||||
|
{
|
||||||
|
switch (mode)
|
||||||
|
{
|
||||||
|
default: return FontAwesome.fa_osu_osu_o;
|
||||||
|
case PlayMode.Taiko: return FontAwesome.fa_osu_taiko_o;
|
||||||
|
case PlayMode.Catch: return FontAwesome.fa_osu_fruits_o;
|
||||||
|
case PlayMode.Mania: return FontAwesome.fa_osu_mania_o;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Load()
|
public override void Load()
|
||||||
{
|
{
|
||||||
base.Load();
|
base.Load();
|
||||||
Icon.TextSize = height * 0.7f;
|
DrawableIcon.TextSize = height * 0.7f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ToolbarButton : FlowContainer
|
public class ToolbarButton : FlowContainer
|
||||||
{
|
{
|
||||||
public TextAwesome Icon;
|
public FontAwesome Icon
|
||||||
public SpriteText Text;
|
{
|
||||||
private Box background;
|
get { return DrawableIcon.Icon; }
|
||||||
|
set { DrawableIcon.Icon = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Text
|
||||||
|
{
|
||||||
|
get { return DrawableText.Text; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
DrawableText.Text = value;
|
||||||
|
paddingIcon.Alpha = string.IsNullOrEmpty(value) ? 0 : 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Action Action;
|
||||||
|
|
||||||
|
protected TextAwesome DrawableIcon;
|
||||||
|
protected SpriteText DrawableText;
|
||||||
|
protected Box Background;
|
||||||
|
protected Box HoverBackground;
|
||||||
private Drawable paddingLeft;
|
private Drawable paddingLeft;
|
||||||
private Drawable paddingRight;
|
private Drawable paddingRight;
|
||||||
private Drawable paddingIcon;
|
private Drawable paddingIcon;
|
||||||
@ -97,44 +196,60 @@ namespace osu.Game.Overlays
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ToolbarButton(FontAwesome icon, string text = null)
|
public ToolbarButton()
|
||||||
{
|
{
|
||||||
background = new Box
|
Background = new Box
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Colour = new Color4(20, 20, 20, 140),
|
Colour = new Color4(20, 20, 20, 140),
|
||||||
};
|
};
|
||||||
|
|
||||||
this.Icon = new TextAwesome()
|
HoverBackground = new Box
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Additive = true,
|
||||||
|
Colour = new Color4(20, 20, 20, 0),
|
||||||
|
Alpha = 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
DrawableIcon = new TextAwesome()
|
||||||
{
|
{
|
||||||
Icon = icon,
|
|
||||||
Anchor = Anchor.CentreLeft,
|
Anchor = Anchor.CentreLeft,
|
||||||
Origin = Anchor.CentreLeft,
|
Origin = Anchor.CentreLeft,
|
||||||
};
|
};
|
||||||
|
|
||||||
this.Text = new SpriteText
|
DrawableText = new SpriteText
|
||||||
{
|
{
|
||||||
Text = text,
|
|
||||||
Anchor = Anchor.CentreLeft,
|
Anchor = Anchor.CentreLeft,
|
||||||
Origin = Anchor.CentreLeft,
|
Origin = Anchor.CentreLeft,
|
||||||
};
|
};
|
||||||
|
|
||||||
paddingLeft = new Container { RelativeSizeAxes = Axes.Y };
|
paddingLeft = new Container { RelativeSizeAxes = Axes.Y };
|
||||||
paddingRight = new Container { RelativeSizeAxes = Axes.Y };
|
paddingRight = new Container { RelativeSizeAxes = Axes.Y };
|
||||||
paddingIcon = new Container { Size = new Vector2(string.IsNullOrEmpty(text) ? 0 : 5, 0) };
|
paddingIcon = new Container
|
||||||
|
{
|
||||||
|
Size = new Vector2(5, 0),
|
||||||
|
Alpha = 0
|
||||||
|
};
|
||||||
|
|
||||||
Padding = 10;
|
Padding = 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override bool OnClick(InputState state)
|
||||||
|
{
|
||||||
|
Action?.Invoke();
|
||||||
|
return base.OnClick(state);
|
||||||
|
}
|
||||||
|
|
||||||
protected override bool OnHover(InputState state)
|
protected override bool OnHover(InputState state)
|
||||||
{
|
{
|
||||||
background.FadeColour(new Color4(130, 130, 130, 160), 100);
|
HoverBackground.FadeTo(0.4f, 200);
|
||||||
return base.OnHover(state);
|
return base.OnHover(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnHoverLost(InputState state)
|
protected override void OnHoverLost(InputState state)
|
||||||
{
|
{
|
||||||
background.FadeColour(new Color4(20, 20, 20, 140), 100);
|
HoverBackground.FadeTo(0, 200);
|
||||||
base.OnHoverLost(state);
|
base.OnHoverLost(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,11 +262,12 @@ namespace osu.Game.Overlays
|
|||||||
|
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
background,
|
Background,
|
||||||
|
HoverBackground,
|
||||||
paddingLeft,
|
paddingLeft,
|
||||||
Icon,
|
DrawableIcon,
|
||||||
paddingIcon,
|
paddingIcon,
|
||||||
Text,
|
DrawableText,
|
||||||
paddingRight,
|
paddingRight,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -81,6 +81,7 @@
|
|||||||
<Compile Include="GameModes\Play\ModSelect.cs" />
|
<Compile Include="GameModes\Play\ModSelect.cs" />
|
||||||
<Compile Include="GameModes\Play\Player.cs" />
|
<Compile Include="GameModes\Play\Player.cs" />
|
||||||
<Compile Include="GameModes\Charts\ChartListing.cs" />
|
<Compile Include="GameModes\Charts\ChartListing.cs" />
|
||||||
|
<Compile Include="GameModes\Play\PlayMode.cs" />
|
||||||
<Compile Include="GameModes\Play\Results.cs" />
|
<Compile Include="GameModes\Play\Results.cs" />
|
||||||
<Compile Include="GameModes\Direct\OnlineListing.cs" />
|
<Compile Include="GameModes\Direct\OnlineListing.cs" />
|
||||||
<Compile Include="GameModes\Play\SongSelectPlay.cs" />
|
<Compile Include="GameModes\Play\SongSelectPlay.cs" />
|
||||||
|
Reference in New Issue
Block a user