Port of retail gmMainChatUI::InitTalkFocusMenu @0x4cdc50 + HandleSelection @0x4cd540 → SetTalkFocus. Button shows active channel label; click opens a 12-item popup that extends UPWARD (chat sits at screen bottom); selecting an entry calls OnChannelChanged and updates Selected. BitmapFont? Font uses the fully-qualified type name to match UiChatInput convention. Includes 6 xunit tests covering channel table shape, default selection, and popup-pick routing. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
76 lines
2.6 KiB
C#
76 lines
2.6 KiB
C#
using AcDream.App.UI;
|
|
using AcDream.UI.Abstractions;
|
|
|
|
namespace AcDream.App.Tests.UI;
|
|
|
|
public class UiChannelMenuTests
|
|
{
|
|
[Fact]
|
|
public void Channels_HasExpected12Entries()
|
|
{
|
|
Assert.Equal(12, UiChannelMenu.Channels.Length);
|
|
}
|
|
|
|
[Fact]
|
|
public void Channels_FirstEntry_IsSay()
|
|
{
|
|
Assert.Equal(ChatChannelKind.Say, UiChannelMenu.Channels[0].Channel);
|
|
Assert.Equal("Say", UiChannelMenu.Channels[0].Label);
|
|
}
|
|
|
|
[Fact]
|
|
public void Channels_LastEntry_IsOlthoi()
|
|
{
|
|
var last = UiChannelMenu.Channels[^1];
|
|
Assert.Equal(ChatChannelKind.Olthoi, last.Channel);
|
|
Assert.Equal("Olthoi", last.Label);
|
|
}
|
|
|
|
[Fact]
|
|
public void Channels_ContainsAllExpectedKinds()
|
|
{
|
|
var kinds = new HashSet<ChatChannelKind>(UiChannelMenu.Channels.Select(c => c.Channel));
|
|
Assert.Contains(ChatChannelKind.Say, kinds);
|
|
Assert.Contains(ChatChannelKind.General, kinds);
|
|
Assert.Contains(ChatChannelKind.Trade, kinds);
|
|
Assert.Contains(ChatChannelKind.Lfg, kinds);
|
|
Assert.Contains(ChatChannelKind.Fellowship, kinds);
|
|
Assert.Contains(ChatChannelKind.Allegiance, kinds);
|
|
Assert.Contains(ChatChannelKind.Patron, kinds);
|
|
Assert.Contains(ChatChannelKind.Vassals, kinds);
|
|
Assert.Contains(ChatChannelKind.Monarch, kinds);
|
|
Assert.Contains(ChatChannelKind.Roleplay, kinds);
|
|
Assert.Contains(ChatChannelKind.Society, kinds);
|
|
Assert.Contains(ChatChannelKind.Olthoi, kinds);
|
|
}
|
|
|
|
[Fact]
|
|
public void DefaultSelected_IsSay()
|
|
{
|
|
var menu = new UiChannelMenu();
|
|
Assert.Equal(ChatChannelKind.Say, menu.Selected);
|
|
}
|
|
|
|
[Fact]
|
|
public void OnChannelChanged_FiredWhenSelectionMadeViaEvent()
|
|
{
|
|
var menu = new UiChannelMenu { Width = 80f, Height = 18f };
|
|
|
|
// Open the popup (click inside the button area — Data2 >= 0).
|
|
var openEvt = new UiEvent(0, menu, UiEventType.MouseDown, 0, 10, 5);
|
|
Assert.True(menu.OnEvent(openEvt));
|
|
|
|
// Click on the second item (General) in the upward popup.
|
|
// Popup renders UPWARD: top = -(12 * 16) = -192.
|
|
// Item i=1 (General) occupies y in [-192 + 16, -192 + 32) = [-176, -160).
|
|
// A click at ly = -176 + 8 = -168 hits item index = (int)((-168 + 192) / 16) = (int)(24/16) = 1.
|
|
ChatChannelKind? fired = null;
|
|
menu.OnChannelChanged = k => fired = k;
|
|
|
|
var selectEvt = new UiEvent(0, menu, UiEventType.MouseDown, 0, 10, -168);
|
|
Assert.True(menu.OnEvent(selectEvt));
|
|
|
|
Assert.Equal(ChatChannelKind.General, fired);
|
|
Assert.Equal(ChatChannelKind.General, menu.Selected);
|
|
}
|
|
}
|