mirror of
https://github.com/ppy/osu
synced 2025-01-30 01:42:54 +00:00
Merge pull request #21916 from Joehuu/remember-chat-textbox-per-channel
Save / sync chat text box messages per channel
This commit is contained in:
commit
b97d4b571e
@ -530,6 +530,52 @@ namespace osu.Game.Tests.Visual.Online
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestTextBoxSavePerChannel()
|
||||
{
|
||||
var testPMChannel = new Channel(testUser);
|
||||
|
||||
AddStep("show overlay", () => chatOverlay.Show());
|
||||
joinTestChannel(0);
|
||||
joinChannel(testPMChannel);
|
||||
|
||||
AddAssert("listing is visible", () => listingIsVisible);
|
||||
AddStep("search for 'number 2'", () => chatOverlayTextBox.Text = "number 2");
|
||||
AddAssert("'number 2' saved to selector", () => channelManager.CurrentChannel.Value.TextBoxMessage.Value == "number 2");
|
||||
|
||||
AddStep("select normal channel", () => clickDrawable(getChannelListItem(testChannel1)));
|
||||
AddAssert("text box cleared on normal channel", () => chatOverlayTextBox.Text == string.Empty);
|
||||
AddAssert("nothing saved on normal channel", () => channelManager.CurrentChannel.Value.TextBoxMessage.Value == string.Empty);
|
||||
AddStep("type '727'", () => chatOverlayTextBox.Text = "727");
|
||||
AddAssert("'727' saved to normal channel", () => channelManager.CurrentChannel.Value.TextBoxMessage.Value == "727");
|
||||
|
||||
AddStep("select PM channel", () => clickDrawable(getChannelListItem(testPMChannel)));
|
||||
AddAssert("text box cleared on PM channel", () => chatOverlayTextBox.Text == string.Empty);
|
||||
AddAssert("nothing saved on PM channel", () => channelManager.CurrentChannel.Value.TextBoxMessage.Value == string.Empty);
|
||||
AddStep("type 'hello'", () => chatOverlayTextBox.Text = "hello");
|
||||
AddAssert("'hello' saved to PM channel", () => channelManager.CurrentChannel.Value.TextBoxMessage.Value == "hello");
|
||||
|
||||
AddStep("select normal channel", () => clickDrawable(getChannelListItem(testChannel1)));
|
||||
AddAssert("text box contains '727'", () => chatOverlayTextBox.Text == "727");
|
||||
|
||||
AddStep("select PM channel", () => clickDrawable(getChannelListItem(testPMChannel)));
|
||||
AddAssert("text box contains 'hello'", () => chatOverlayTextBox.Text == "hello");
|
||||
AddStep("click close button", () =>
|
||||
{
|
||||
ChannelListItemCloseButton closeButton = getChannelListItem(testPMChannel).ChildrenOfType<ChannelListItemCloseButton>().Single();
|
||||
clickDrawable(closeButton);
|
||||
});
|
||||
|
||||
AddAssert("listing is visible", () => listingIsVisible);
|
||||
AddAssert("text box contains 'channel 2'", () => chatOverlayTextBox.Text == "number 2");
|
||||
AddUntilStep("only channel 2 visible", () =>
|
||||
{
|
||||
IEnumerable<ChannelListingItem> listingItems = chatOverlay.ChildrenOfType<ChannelListingItem>()
|
||||
.Where(item => item.IsPresent);
|
||||
return listingItems.Count() == 1 && listingItems.Single().Channel == testChannel2;
|
||||
});
|
||||
}
|
||||
|
||||
private void joinTestChannel(int i)
|
||||
{
|
||||
AddStep($"Join test channel {i}", () => channelManager.JoinChannel(testChannels[i]));
|
||||
|
@ -50,6 +50,8 @@ namespace osu.Game.Tests.Visual.Online
|
||||
private ChannelManager channelManager;
|
||||
|
||||
private TestStandAloneChatDisplay chatDisplay;
|
||||
private TestStandAloneChatDisplay chatWithTextBox;
|
||||
private TestStandAloneChatDisplay chatWithTextBox2;
|
||||
private int messageIdSequence;
|
||||
|
||||
private Channel testChannel;
|
||||
@ -78,7 +80,7 @@ namespace osu.Game.Tests.Visual.Online
|
||||
|
||||
private void reinitialiseDrawableDisplay()
|
||||
{
|
||||
Children = new[]
|
||||
Children = new Drawable[]
|
||||
{
|
||||
chatDisplay = new TestStandAloneChatDisplay
|
||||
{
|
||||
@ -88,13 +90,28 @@ namespace osu.Game.Tests.Visual.Online
|
||||
Size = new Vector2(400, 80),
|
||||
Channel = { Value = testChannel },
|
||||
},
|
||||
new TestStandAloneChatDisplay(true)
|
||||
new FillFlowContainer
|
||||
{
|
||||
Anchor = Anchor.CentreRight,
|
||||
Origin = Anchor.CentreRight,
|
||||
AutoSizeAxes = Axes.Both,
|
||||
Direction = FillDirection.Vertical,
|
||||
Margin = new MarginPadding(20),
|
||||
Size = new Vector2(400, 150),
|
||||
Channel = { Value = testChannel },
|
||||
Children = new[]
|
||||
{
|
||||
chatWithTextBox = new TestStandAloneChatDisplay(true)
|
||||
{
|
||||
Margin = new MarginPadding(20),
|
||||
Size = new Vector2(400, 150),
|
||||
Channel = { Value = testChannel },
|
||||
},
|
||||
chatWithTextBox2 = new TestStandAloneChatDisplay(true)
|
||||
{
|
||||
Margin = new MarginPadding(20),
|
||||
Size = new Vector2(400, 150),
|
||||
Channel = { Value = testChannel },
|
||||
},
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -351,6 +368,13 @@ namespace osu.Game.Tests.Visual.Online
|
||||
checkScrolledToBottom();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestTextBoxSync()
|
||||
{
|
||||
AddStep("type 'hello' to text box 1", () => chatWithTextBox.ChildrenOfType<StandAloneChatDisplay.ChatTextBox>().Single().Text = "hello");
|
||||
AddAssert("text box 2 contains 'hello'", () => chatWithTextBox2.ChildrenOfType<StandAloneChatDisplay.ChatTextBox>().Single().Text == "hello");
|
||||
}
|
||||
|
||||
private void fillChat(int count = 10)
|
||||
{
|
||||
AddStep("fill chat", () =>
|
||||
|
@ -98,6 +98,11 @@ namespace osu.Game.Online.Chat
|
||||
/// </summary>
|
||||
public Bindable<Message> HighlightedMessage = new Bindable<Message>();
|
||||
|
||||
/// <summary>
|
||||
/// The current text box message while in this <see cref="Channel"/>.
|
||||
/// </summary>
|
||||
public Bindable<string> TextBoxMessage = new Bindable<string>(string.Empty);
|
||||
|
||||
[JsonConstructor]
|
||||
public Channel()
|
||||
{
|
||||
|
@ -111,8 +111,13 @@ namespace osu.Game.Online.Chat
|
||||
{
|
||||
drawableChannel?.Expire();
|
||||
|
||||
if (e.OldValue != null)
|
||||
TextBox?.Current.UnbindFrom(e.OldValue.TextBoxMessage);
|
||||
|
||||
if (e.NewValue == null) return;
|
||||
|
||||
TextBox?.Current.BindTo(e.NewValue.TextBoxMessage);
|
||||
|
||||
drawableChannel = CreateDrawableChannel(e.NewValue);
|
||||
drawableChannel.CreateChatLineAction = CreateMessage;
|
||||
drawableChannel.Padding = new MarginPadding { Bottom = postingTextBox ? text_box_height : 0 };
|
||||
|
@ -128,9 +128,8 @@ namespace osu.Game.Overlays.Chat
|
||||
chattingTextContainer.FadeTo(showSearch ? 0 : 1);
|
||||
searchIconContainer.FadeTo(showSearch ? 1 : 0);
|
||||
|
||||
// Clear search terms if any exist when switching back to chat mode
|
||||
if (!showSearch)
|
||||
OnSearchTermsChanged?.Invoke(string.Empty);
|
||||
if (showSearch)
|
||||
OnSearchTermsChanged?.Invoke(chatTextBox.Current.Value);
|
||||
}, true);
|
||||
|
||||
currentChannel.BindValueChanged(change =>
|
||||
@ -151,6 +150,12 @@ namespace osu.Game.Overlays.Chat
|
||||
chattingText.Text = ChatStrings.TalkingIn(newChannel.Name);
|
||||
break;
|
||||
}
|
||||
|
||||
if (change.OldValue != null)
|
||||
chatTextBox.Current.UnbindFrom(change.OldValue.TextBoxMessage);
|
||||
|
||||
if (newChannel != null)
|
||||
chatTextBox.Current.BindTo(newChannel.TextBoxMessage);
|
||||
}, true);
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,6 @@ namespace osu.Game.Overlays.Chat
|
||||
bool showSearch = change.NewValue;
|
||||
|
||||
PlaceholderText = showSearch ? HomeStrings.SearchPlaceholder : ChatStrings.InputPlaceholder;
|
||||
Text = string.Empty;
|
||||
}, true);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user