From 5e912a316df601dde71282b883e80c7edbad4ae6 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Wed, 14 Jul 2010 21:11:06 +1200 Subject: [PATCH] emulation of old chat system --- OpenRA.Game/Widgets/ChatDisplayWidget.cs | 5 +++- OpenRA.Game/Widgets/ChatEntryWidget.cs | 34 +++++++++++++++++++----- mods/ra/chrome/ingame.yaml | 33 ++++++++++++----------- 3 files changed, 49 insertions(+), 23 deletions(-) diff --git a/OpenRA.Game/Widgets/ChatDisplayWidget.cs b/OpenRA.Game/Widgets/ChatDisplayWidget.cs index a26a4c215a..cb1030cf6c 100644 --- a/OpenRA.Game/Widgets/ChatDisplayWidget.cs +++ b/OpenRA.Game/Widgets/ChatDisplayWidget.cs @@ -28,6 +28,7 @@ namespace OpenRA.Widgets { const int logLength = 10; public string Notification = ""; + public bool DrawBackground = true; public List recentLines = new List(); @@ -42,7 +43,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); - WidgetUtils.DrawPanel("dialog3", chatLogArea); + + if (DrawBackground) + WidgetUtils.DrawPanel("dialog3", chatLogArea); var renderer = Game.chrome.renderer; var font = renderer.RegularFont; diff --git a/OpenRA.Game/Widgets/ChatEntryWidget.cs b/OpenRA.Game/Widgets/ChatEntryWidget.cs index dac7ec7fc7..4c6acd8dc1 100644 --- a/OpenRA.Game/Widgets/ChatEntryWidget.cs +++ b/OpenRA.Game/Widgets/ChatEntryWidget.cs @@ -26,20 +26,27 @@ namespace OpenRA.Widgets // a dirty hack of a widget, which likes to steal the focus when \r is pressed, and then // refuse to give it up until \r is pressed again. + // this emulates the previous chat support, with one improvement: shift+enter can toggle the + // team/all mode *while* composing, not just on beginning to compose. + class ChatEntryWidget : Widget { string content = ""; - bool composing = true; + bool composing = false; + bool teamChat = false; public override void DrawInner(World world) { - //if (!composing) - // return; + if (composing) + { + var text = teamChat ? "Chat (Team): " : "Chat (All): "; + var w = Game.chrome.renderer.BoldFont.Measure(text).X; - Game.chrome.renderer.BoldFont.DrawText("Chat:", RenderOrigin + new float2(3, 7), Color.White); - Game.chrome.renderer.RegularFont.DrawText(content, RenderOrigin + new float2(40, 7), Color.White); + Game.chrome.renderer.BoldFont.DrawText(text, RenderOrigin + new float2(3, 7), Color.White); + Game.chrome.renderer.RegularFont.DrawText(content, RenderOrigin + new float2(3 + w, 7), Color.White); - Game.chrome.renderer.RgbaSpriteRenderer.Flush(); + Game.chrome.renderer.RgbaSpriteRenderer.Flush(); + } } public override bool LoseFocus(MouseInput mi) @@ -47,15 +54,25 @@ namespace OpenRA.Widgets return composing ? false : base.LoseFocus(mi); } + public override bool HandleInput(MouseInput mi) { return false; } + public override bool HandleKeyPress(KeyPressEventArgs e, Modifiers modifiers) { if (e.KeyChar == '\r') { if (composing) { + if (modifiers.HasModifier(Modifiers.Shift)) + { + teamChat ^= true; + return true; + } + composing = false; if (content != "") - Game.IssueOrder(Order.Chat(content)); + Game.IssueOrder(teamChat + ? Order.TeamChat(content) + : Order.Chat(content)); content = ""; LoseFocus(); @@ -64,6 +81,8 @@ namespace OpenRA.Widgets else { TakeFocus(new MouseInput()); + composing = true; + teamChat ^= modifiers.HasModifier(Modifiers.Shift); return true; } } @@ -74,6 +93,7 @@ namespace OpenRA.Widgets { if (content.Length > 0) content = content.Remove(content.Length - 1); + return true; } else if (!char.IsControl(e.KeyChar)) { diff --git a/mods/ra/chrome/ingame.yaml b/mods/ra/chrome/ingame.yaml index 224bee1e95..4eb6a4ca12 100644 --- a/mods/ra/chrome/ingame.yaml +++ b/mods/ra/chrome/ingame.yaml @@ -5,21 +5,6 @@ Container@ROOT: Delegate:IngameChromeDelegate Visible:false Children: - ChatDisplay@INGAME_CHAT_DISPLAY: - Id:INGAME_CHAT_DISPLAY - X:220 - Y:WINDOW_BOTTOM - HEIGHT - 30 - Width: 760 - Height: 200 - Visible: True - Delegate: ChatDelegate - ChatEntry@INGAME_CHAT_ENTRY: - Id:INGAME_CHAT_ENTRY - X:220 - Y:WINDOW_BOTTOM - HEIGHT - Width: 760 - Height: 30 - Visible: True PostGame@POSTGAME_TEXT: Id:POSTGAME_TEXT X:0 @@ -140,6 +125,24 @@ Container@ROOT: Text:Diplomacy Align:Center Bold:True + ChatDisplay@INGAME_CHAT_DISPLAY: + Id:INGAME_CHAT_DISPLAY + X:250 + Y:WINDOW_BOTTOM - HEIGHT - 30 + Width: 760 + Height: 200 + Visible: True + Delegate: ChatDelegate + ClickThrough: True + DrawBackground: False + ChatEntry@INGAME_CHAT_ENTRY: + Id:INGAME_CHAT_ENTRY + X:250 + Y:WINDOW_BOTTOM - HEIGHT + Width: 760 + Height: 30 + Visible: True + ClickThrough: True Background@PERF_BG: ClickThrough:true Id:PERF_BG