From 9cf4998701e4e11038e273304817efb1f02647bd Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 12 May 2017 13:54:02 +0900 Subject: [PATCH] Make chat resizable via drag, save user set size --- osu.Game/Configuration/OsuConfigManager.cs | 6 +++- osu.Game/Overlays/ChatOverlay.cs | 33 +++++++++++++++++++--- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/osu.Game/Configuration/OsuConfigManager.cs b/osu.Game/Configuration/OsuConfigManager.cs index 3907496ca2..ba19d8592a 100644 --- a/osu.Game/Configuration/OsuConfigManager.cs +++ b/osu.Game/Configuration/OsuConfigManager.cs @@ -3,6 +3,7 @@ using osu.Framework.Configuration; using osu.Framework.Platform; +using osu.Game.Overlays; using osu.Game.Screens.Select; namespace osu.Game.Configuration @@ -19,6 +20,8 @@ namespace osu.Game.Configuration Set(OsuConfig.DisplayStarsMinimum, 0.0, 0, 10); Set(OsuConfig.DisplayStarsMaximum, 10.0, 0, 10); + Set(OsuConfig.ChatDisplayHeight, ChatOverlay.DEFAULT_HEIGHT, 0.2, 1); + // Online settings Set(OsuConfig.Username, string.Empty); @@ -102,6 +105,7 @@ namespace osu.Game.Configuration DisplayStarsMaximum, SnakingInSliders, SnakingOutSliders, - ShowFpsDisplay + ShowFpsDisplay, + ChatDisplayHeight } } diff --git a/osu.Game/Overlays/ChatOverlay.cs b/osu.Game/Overlays/ChatOverlay.cs index 75ddcd89b6..3630ad0518 100644 --- a/osu.Game/Overlays/ChatOverlay.cs +++ b/osu.Game/Overlays/ChatOverlay.cs @@ -7,6 +7,7 @@ using System.Diagnostics; using System.Linq; using OpenTK; using osu.Framework.Allocation; +using osu.Framework.Configuration; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Sprites; @@ -21,6 +22,7 @@ using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.UserInterface; using OpenTK.Graphics; using osu.Framework.Input; +using osu.Game.Configuration; namespace osu.Game.Overlays { @@ -38,14 +40,19 @@ namespace osu.Game.Overlays private const int transition_length = 500; + public const float DEFAULT_HEIGHT = 0.4f; + private GetMessagesRequest fetchReq; private readonly OsuTabControl channelTabs; + private Bindable chatHeight; + public ChatOverlay() { - RelativeSizeAxes = Axes.X; - Size = new Vector2(1, 300); + RelativeSizeAxes = Axes.Both; + RelativePositionAxes = Axes.Both; + Size = new Vector2(1, DEFAULT_HEIGHT); Anchor = Anchor.BottomLeft; Origin = Anchor.BottomLeft; @@ -93,6 +100,20 @@ namespace osu.Game.Overlays channelTabs.Current.ValueChanged += newChannel => CurrentChannel = newChannel; } + protected override bool OnDragStart(InputState state) + { + if (channelTabs.Hovering) + return true; + + return base.OnDragStart(state); + } + + protected override bool OnDrag(InputState state) + { + chatHeight.Value = Height - state.Mouse.Delta.Y / Parent.DrawSize.Y; + return base.OnDrag(state); + } + public void APIStateChanged(APIAccess api, APIState state) { switch (state) @@ -124,7 +145,7 @@ namespace osu.Game.Overlays protected override void PopOut() { - MoveToY(DrawSize.Y, transition_length, EasingTypes.InSine); + MoveToY(Height, transition_length, EasingTypes.InSine); FadeOut(transition_length, EasingTypes.InSine); inputTextBox.HoldFocus = false; @@ -132,10 +153,14 @@ namespace osu.Game.Overlays } [BackgroundDependencyLoader] - private void load(APIAccess api) + private void load(APIAccess api, OsuConfigManager config) { this.api = api; api.Register(this); + + chatHeight = config.GetBindable(OsuConfig.ChatDisplayHeight); + chatHeight.ValueChanged += h => Height = (float)h; + chatHeight.TriggerChange(); } private long? lastMessageId;