diff --git a/OpenRA.Game/Widgets/ChatDisplayWidget.cs b/OpenRA.Game/Widgets/ChatDisplayWidget.cs index 9daf5e2139..163b6dc6a2 100644 --- a/OpenRA.Game/Widgets/ChatDisplayWidget.cs +++ b/OpenRA.Game/Widgets/ChatDisplayWidget.cs @@ -8,6 +8,7 @@ */ #endregion +using System; using System.Collections.Generic; using System.Drawing; using System.Linq; @@ -18,10 +19,9 @@ namespace OpenRA.Widgets { public readonly int RemoveTime = 0; public readonly bool UseContrast = false; + public string Notification = ""; const int logLength = 9; - public string Notification = ""; - public bool DrawBackground = true; int ticksUntilRemove = 0; internal List recentLines = new List(); @@ -35,13 +35,9 @@ namespace OpenRA.Widgets { var pos = RenderOrigin; var chatLogArea = new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height); - var chatpos = new int2(chatLogArea.X + 10, chatLogArea.Bottom - 6); - - if (DrawBackground) - WidgetUtils.DrawPanel("dialog3", chatLogArea); + var chatpos = new int2(chatLogArea.X + 5, chatLogArea.Bottom - 5); var font = Game.Renderer.Fonts["Regular"]; - Game.Renderer.EnableScissor(chatLogArea.Left, chatLogArea.Top, chatLogArea.Width, chatLogArea.Height); foreach (var line in recentLines.AsEnumerable().Reverse()) @@ -52,12 +48,14 @@ namespace OpenRA.Widgets if (!string.IsNullOrEmpty(line.Owner)) { owner = line.Owner + ":"; - inset = font.Measure(owner).X + 10; + inset = font.Measure(owner).X + 5; } - var text = WidgetUtils.WrapText(line.Text, chatLogArea.Width - inset, font); - var textLines = text.Split(new[] { '\n' }).Count(); - chatpos.Y -= 20 * textLines; + var text = WidgetUtils.WrapText(line.Text, chatLogArea.Width - inset - 6, font); + chatpos.Y -= Math.Max(15, font.Measure(text).Y) + 5; + + if (chatpos.Y < pos.Y) + break; if (owner != null) { @@ -80,12 +78,14 @@ namespace OpenRA.Widgets if (Notification != null) Sound.Play(Notification); - while (recentLines.Count > logLength) recentLines.RemoveAt(0); + while (recentLines.Count > logLength) + recentLines.RemoveAt(0); } public void RemoveLine() { - if (recentLines.Count > 0) recentLines.RemoveAt(0); + if (recentLines.Count > 0) + recentLines.RemoveAt(0); } public void ClearChat() @@ -95,8 +95,12 @@ namespace OpenRA.Widgets public override void Tick() { - if (RemoveTime == 0) return; - if (--ticksUntilRemove > 0) return; + if (RemoveTime == 0) + return; + + if (--ticksUntilRemove > 0) + return; + ticksUntilRemove = RemoveTime; RemoveLine(); } diff --git a/OpenRA.Mods.RA/Widgets/Logic/IngameChatLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/IngameChatLogic.cs index 7c40bc2382..d61d5768ef 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/IngameChatLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/IngameChatLogic.cs @@ -10,71 +10,65 @@ using System; using System.Drawing; -using OpenRA.Widgets; using OpenRA.Network; +using OpenRA.Widgets; namespace OpenRA.Mods.RA.Widgets.Logic { public class IngameChatLogic { - internal World World; - internal readonly ContainerWidget ChatOverlay; - internal readonly ChatDisplayWidget ChatOverlayDisplay; + readonly ContainerWidget chatOverlay; + readonly ChatDisplayWidget chatOverlayDisplay; + readonly ContainerWidget chatChrome; + readonly ScrollPanelWidget chatScrollPanel; + readonly ContainerWidget chatTemplate; + readonly TextFieldWidget chatText; - internal readonly ContainerWidget ChatChrome; - internal readonly ScrollPanelWidget ChatScrollPanel; - internal readonly ContainerWidget ChatTemplate; - internal readonly TextFieldWidget ChatText; - - private bool teamChat = false; - internal bool TeamChat - { - get { return World.LocalPlayer == null ? false : teamChat; } - set { teamChat = value; } - } + bool teamChat; [ObjectCreator.UseCtor] public IngameChatLogic(Widget widget, OrderManager orderManager, World world) { - World = world; - var chatPanel = (ContainerWidget) widget; + teamChat = world.LocalPlayer != null; + var chatPanel = (ContainerWidget)widget; + chatOverlay = chatPanel.Get("CHAT_OVERLAY"); + chatOverlayDisplay = chatOverlay.Get("CHAT_DISPLAY"); + chatOverlay.Visible = false; - ChatOverlay = chatPanel.Get("CHAT_OVERLAY"); - ChatOverlayDisplay = ChatOverlay.Get("CHAT_DISPLAY"); - ChatOverlay.Visible = false; + chatChrome = chatPanel.Get("CHAT_CHROME"); + chatChrome.Visible = true; - ChatChrome = chatPanel.Get("CHAT_CHROME"); - ChatChrome.Visible = true; + var chatMode = chatChrome.Get("CHAT_MODE"); + chatMode.GetText = () => teamChat ? "Team" : "All"; + chatMode.OnClick = () => teamChat ^= true; + chatMode.IsDisabled = () => world.LocalPlayer == null; - var chatMode = ChatChrome.Get("CHAT_MODE"); - chatMode.GetText = () => TeamChat ? "Team" : "All"; - chatMode.OnClick = () => TeamChat = !TeamChat; - - ChatText = ChatChrome.Get("CHAT_TEXTFIELD"); - ChatText.OnTabKey = () => { TeamChat = !TeamChat; return true; }; - ChatText.OnEnterKey = () => + chatText = chatChrome.Get("CHAT_TEXTFIELD"); + chatText.OnTabKey = () => { teamChat ^= true; return true; }; + chatText.OnEnterKey = () => { - ChatText.Text = ChatText.Text.Trim(); - if (ChatText.Text != "") - orderManager.IssueOrder(Order.Chat(TeamChat, ChatText.Text)); + var team = teamChat && world.LocalPlayer != null; + if (chatText.Text != "") + orderManager.IssueOrder(Order.Chat(team, chatText.Text.Trim())); + CloseChat(); return true; }; - ChatText.OnEscKey = () => {CloseChat(); return true; }; - var chatClose = ChatChrome.Get("CHAT_CLOSE"); + chatText.OnEscKey = () => { CloseChat(); return true; }; + + var chatClose = chatChrome.Get("CHAT_CLOSE"); chatClose.OnClick += () => CloseChat(); chatPanel.OnKeyPress = (e) => { - if (e.Event == KeyInputEvent.Up) return false; - if (!IsOpen && (e.Key == Keycode.RETURN || e.Key == Keycode.KP_ENTER)) + if (e.Event == KeyInputEvent.Up) + return false; + + if (!chatChrome.IsVisible() && (e.Key == Keycode.RETURN || e.Key == Keycode.KP_ENTER)) { - var shift = e.Modifiers.HasModifier(Modifiers.Shift); - var toggle = Game.Settings.Game.TeamChatToggle ; - TeamChat = (!toggle && shift) || ( toggle && (TeamChat ^ shift) ); OpenChat(); return true; } @@ -82,14 +76,14 @@ namespace OpenRA.Mods.RA.Widgets.Logic return false; }; - ChatScrollPanel = ChatChrome.Get("CHAT_SCROLLPANEL"); - ChatTemplate = ChatScrollPanel.Get("CHAT_TEMPLATE"); + chatScrollPanel = chatChrome.Get("CHAT_SCROLLPANEL"); + chatTemplate = chatScrollPanel.Get("CHAT_TEMPLATE"); + chatScrollPanel.RemoveChildren(); Game.AddChatLine += AddChatLine; Game.BeforeGameStart += UnregisterEvents; CloseChat(); - ChatOverlayDisplay.AddLine(Color.White, null, "Use RETURN key to open chat window..."); } void UnregisterEvents() @@ -100,33 +94,32 @@ namespace OpenRA.Mods.RA.Widgets.Logic public void OpenChat() { - ChatText.Text = ""; - ChatOverlay.Visible = false; - ChatChrome.Visible = true; - ChatText.TakeKeyboardFocus(); + chatText.Text = ""; + chatOverlay.Visible = false; + chatChrome.Visible = true; + chatScrollPanel.ScrollToBottom(); + chatText.TakeKeyboardFocus(); } public void CloseChat() { - ChatOverlay.Visible = true; - ChatChrome.Visible = false; - ChatText.YieldKeyboardFocus(); + chatOverlay.Visible = true; + chatChrome.Visible = false; + chatText.YieldKeyboardFocus(); } - public bool IsOpen { get { return ChatChrome.IsVisible(); } } - public void AddChatLine(Color c, string from, string text) { + chatOverlayDisplay.AddLine(c, from, text); - ChatOverlayDisplay.AddLine(c, from, text); - - var template = ChatTemplate.Clone(); + var template = chatTemplate.Clone(); var nameLabel = template.Get("NAME"); var textLabel = template.Get("TEXT"); var name = ""; if (!string.IsNullOrEmpty(from)) name = from + ":"; + var font = Game.Renderer.Fonts[nameLabel.Font]; var nameSize = font.Measure(from); @@ -146,10 +139,9 @@ namespace OpenRA.Mods.RA.Widgets.Logic template.Bounds.Height += dh; } - ChatScrollPanel.AddChild(template); - ChatScrollPanel.ScrollToBottom(); + chatScrollPanel.AddChild(template); + chatScrollPanel.ScrollToBottom(); Sound.PlayNotification(null, "Sounds", "ChatLine", null); } } -} - +} \ No newline at end of file diff --git a/OpenRA.Mods.RA/Widgets/Logic/SettingsMenuLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/SettingsMenuLogic.cs index aedc3103d3..9211218cce 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/SettingsMenuLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/SettingsMenuLogic.cs @@ -65,10 +65,6 @@ namespace OpenRA.Mods.RA.Widgets.Logic inversescroll.IsChecked = () => Game.Settings.Game.MouseScroll == MouseScrollType.Inverted; inversescroll.OnClick = () => Game.Settings.Game.MouseScroll = (Game.Settings.Game.MouseScroll == MouseScrollType.Inverted) ? MouseScrollType.Standard : MouseScrollType.Inverted; - var teamchatCheckbox = general.Get("TEAMCHAT_TOGGLE"); - teamchatCheckbox.IsChecked = () => Game.Settings.Game.TeamChatToggle; - teamchatCheckbox.OnClick = () => Game.Settings.Game.TeamChatToggle ^= true; - var showShellmapCheckbox = general.Get("SHOW_SHELLMAP"); showShellmapCheckbox.IsChecked = () => Game.Settings.Game.ShowShellmap; showShellmapCheckbox.OnClick = () => Game.Settings.Game.ShowShellmap ^= true; diff --git a/mods/ra/chrome/ingame-chat.yaml b/mods/ra/chrome/ingame-chat.yaml index f2f987bad9..72e197c01b 100644 --- a/mods/ra/chrome/ingame-chat.yaml +++ b/mods/ra/chrome/ingame-chat.yaml @@ -2,59 +2,50 @@ Container@CHAT_PANEL: X:(WINDOW_RIGHT - WIDTH) / 2 Y:WINDOW_BOTTOM - HEIGHT - 15 Width:550 - Height:180 + Height:194 Logic:IngameChatLogic Children: Container@CHAT_OVERLAY: - X:0 - Y:0 - Width:PARENT_RIGHT - Height:PARENT_BOTTOM-30 - Visible: false + Width:PARENT_RIGHT-24 + Height:PARENT_BOTTOM-25 + Visible:false Children: ChatDisplay@CHAT_DISPLAY: - X:0 - Y:0 - Width: PARENT_RIGHT - Height: PARENT_BOTTOM - DrawBackground: False + Width:PARENT_RIGHT + Height:PARENT_BOTTOM RemoveTime:250 UseContrast: yes Container@CHAT_CHROME: - X:0 - Y:0 Width:PARENT_RIGHT Height:PARENT_BOTTOM Children: Button@CHAT_MODE: - X:0 Y:PARENT_BOTTOM - HEIGHT - Width: 50 - Height: 25 - Text: Team - Font: Bold + Width:50 + Height:25 + Text:Team + Font:Bold TextField@CHAT_TEXTFIELD: X:55 Y:PARENT_BOTTOM - HEIGHT - Width:465 + Width:466 Height:25 Button@CHAT_CLOSE: - X:525 + X:526 Y:PARENT_BOTTOM - HEIGHT - Width: 25 - Height: 25 - Text: X - Font: Bold + Width:24 + Height:25 + Text:X + Font:Bold ScrollPanel@CHAT_SCROLLPANEL: - X:0 Y:PARENT_BOTTOM - HEIGHT - 30 Width:550 - Height:150 - ItemSpacing:1 + Height:164 + ItemSpacing:4 + Align:Bottom Children: Container@CHAT_TEMPLATE: X:2 - Y:0 Width:PARENT_RIGHT-27 Height:16 Children: @@ -64,8 +55,8 @@ Container@CHAT_PANEL: Height:15 VAlign:Top Label@TEXT: - X:10 - Width:PARENT_RIGHT - 60 + X:12 + Width:PARENT_RIGHT - 17 Height:15 WordWrap:true VAlign:Top diff --git a/mods/ra/chrome/settings.yaml b/mods/ra/chrome/settings.yaml index 84056ab4df..0fe50d30b2 100644 --- a/mods/ra/chrome/settings.yaml +++ b/mods/ra/chrome/settings.yaml @@ -104,12 +104,6 @@ Background@SETTINGS_MENU: Width:200 Height:20 Text: Invert Mouse Drag Scrolling - Checkbox@TEAMCHAT_TOGGLE: - X:0 - Y:120 - Width:200 - Height:20 - Text: Shift-Enter Toggles Team Chat Checkbox@SHOW_SHELLMAP: X:0 Y:150