From fdf570398af4642231801dde34e893816aa82de1 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sat, 10 Jul 2010 19:25:00 +1200 Subject: [PATCH] Replace the lobby chat textfield with the widget; teamchat and ingame chat don't work yet --- OpenRA.Game/Chat.cs | 32 ----------------------- OpenRA.Game/Chrome.cs | 13 ++-------- OpenRA.Game/Game.cs | 36 ++++++++++---------------- OpenRA.Game/Widgets/TextFieldWidget.cs | 28 +++++++++++++++----- mods/cnc/menus.yaml | 21 ++++++++------- 5 files changed, 49 insertions(+), 81 deletions(-) diff --git a/OpenRA.Game/Chat.cs b/OpenRA.Game/Chat.cs index 5e6b700a84..5cb48c8ddc 100644 --- a/OpenRA.Game/Chat.cs +++ b/OpenRA.Game/Chat.cs @@ -29,39 +29,7 @@ namespace OpenRA class Chat { const int logLength = 10; - public List recentLines = new List(); - public string typing = ""; - public bool isChatting = true; - public bool isTeamChat = false; - - public void Toggle() - { - if( isChatting && typing.Length > 0 ) - Game.IssueOrder( isTeamChat ? Order.TeamChat( typing ) : Order.Chat( typing ) ); - - typing = ""; - if( Game.orderManager.GameStarted ) - isChatting ^= true; - } - - public void Reset() - { - typing = ""; - isChatting = false; - recentLines.Clear(); - } - - public void TypeChar(char c) - { - if (c == '\b' || c == 0x7f) - { - if (typing.Length > 0) - typing = typing.Remove(typing.Length - 1); - } - else if (!char.IsControl(c)) - typing += c; - } public void AddLine(Session.Client p, string text) { diff --git a/OpenRA.Game/Chrome.cs b/OpenRA.Game/Chrome.cs index 7c51369dd2..2c472e159c 100644 --- a/OpenRA.Game/Chrome.cs +++ b/OpenRA.Game/Chrome.cs @@ -173,7 +173,6 @@ namespace OpenRA var typingBox = new Rectangle(r.Left + 20, r.Bottom - 77, r.Width - 40, 27); var chatBox = new Rectangle(r.Left + 20, r.Bottom - 269, r.Width - 40, 190); - DrawDialogBackground(typingBox, "dialog2"); DrawDialogBackground(chatBox, "dialog3"); DrawChat(typingBox, chatBox); @@ -192,14 +191,6 @@ namespace OpenRA var chatpos = new int2(chatLogArea.X + 10, chatLogArea.Bottom - 6); ChatWidth = chatLogArea.Width - 10; - renderer.Device.EnableScissor(typingArea.Left, typingArea.Top, typingArea.Width, typingArea.Height); - if (Game.chat.isChatting) - RenderChatLine(new ChatLine { Owner = Game.chat.isTeamChat ? "TeamChat:" : "Chat:", Text = Game.chat.typing }, - new int2(typingArea.X + 10, typingArea.Y + 6)); - - rgbaRenderer.Flush(); - renderer.Device.DisableScissor(); - renderer.Device.EnableScissor(chatLogArea.Left, chatLogArea.Top, chatLogArea.Width, chatLogArea.Height); foreach (var line in Game.chat.recentLines.AsEnumerable().Reverse()) { @@ -222,8 +213,8 @@ namespace OpenRA public int2 lastMousePos; public bool HandleInput(World world, MouseInput mi) { - if (selectedWidget != null) - return selectedWidget.HandleInput(mi); + if (selectedWidget != null && selectedWidget.HandleInput(mi)) + return true; if (rootWidget.HandleInput(mi)) return true; diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index 4cbd868230..94b7e8d8fb 100644 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -405,8 +405,8 @@ namespace OpenRA { LoadMap(LobbyInfo.GlobalSettings.Map); if (orderManager.GameStarted) return; - chat.Reset(); - + Chrome.selectedWidget = null; + world.Queries = new World.AllQueries(world); foreach (var gs in world.WorldActor.traits.WithInterface()) @@ -497,29 +497,21 @@ namespace OpenRA if (chrome.HandleKeyPress(e, modifiers)) return; - if (e.KeyChar == '\r') - { - chat.Toggle(); - chat.isTeamChat = modifiers.HasModifier(Modifiers.Shift); - } - else if (Game.chat.isChatting) - chat.TypeChar(e.KeyChar); - else - { - var c = RemapKeys.ContainsKey(e.KeyChar) ? RemapKeys[e.KeyChar] : e.KeyChar; + var c = RemapKeys.ContainsKey(e.KeyChar) ? RemapKeys[e.KeyChar] : e.KeyChar; - if (c >= '0' && c <= '9') - Game.controller.selection.DoControlGroup(world, - c - '0', modifiers); + if (c >= '0' && c <= '9') + Game.controller.selection.DoControlGroup(world, + c - '0', modifiers); - if (c == 08) - Game.controller.GotoNextBase(); + if (c == 08) + Game.controller.GotoNextBase(); - if (c == 09) - BuildPaletteWidget.TabChange((Control.ModifierKeys & Keys.Shift) == Keys.Shift ? true : false); - - BuildPaletteWidget.DoBuildingHotkey(c, world); - } + if (c == 09) + BuildPaletteWidget.TabChange((Control.ModifierKeys & Keys.Shift) == Keys.Shift ? true : false); + + // Todo: move this into the widget + BuildPaletteWidget.DoBuildingHotkey(c, world); + if (sync != Game.world.SyncHash()) throw new InvalidOperationException("Desync in OnKeyPress"); diff --git a/OpenRA.Game/Widgets/TextFieldWidget.cs b/OpenRA.Game/Widgets/TextFieldWidget.cs index e0eb1ed286..dfaf74d547 100644 --- a/OpenRA.Game/Widgets/TextFieldWidget.cs +++ b/OpenRA.Game/Widgets/TextFieldWidget.cs @@ -25,7 +25,7 @@ namespace OpenRA.Widgets { class TextFieldWidget : Widget { - string TextBuffer = "zomg text"; + string TextBuffer = ""; public int VisualHeight = 1; public TextFieldWidget() @@ -52,24 +52,41 @@ namespace OpenRA.Widgets if (!Visible || !GetEventBounds().Contains(mi.Location.X,mi.Location.Y)) return base.HandleInput(mi); - if (base.HandleInput(mi)) return true; if (mi.Event == MouseInputEvent.Down) { - Chrome.selectedWidget = this; + Focus(); return true; } return false; } - public override bool HandleKeyPress(System.Windows.Forms.KeyPressEventArgs e, Modifiers modifiers) + void Focus() { + Chrome.selectedWidget = this; + blinkCycle = 10; + showCursor = true; + } + + public override bool HandleKeyPress(System.Windows.Forms.KeyPressEventArgs e, Modifiers modifiers) + { if (base.HandleKeyPress(e,modifiers)) return true; + // Only take input if we are selected + if (Chrome.selectedWidget != this) + return false; + + if (e.KeyChar == '\r') + { + if (TextBuffer.Length > 0) + Game.IssueOrder( Order.Chat( TextBuffer ) ); + TextBuffer = ""; + } + TypeChar(e.KeyChar); return true; } @@ -101,8 +118,7 @@ namespace OpenRA.Widgets public override void DrawInner(World world) { int margin = 5; - var font = Game.chrome.renderer.BoldFont; - + var font = Game.chrome.renderer.RegularFont; var text = TextBuffer + ((showCursor && Chrome.selectedWidget == this) ? "|" : ""); var textSize = font.Measure(TextBuffer); diff --git a/mods/cnc/menus.yaml b/mods/cnc/menus.yaml index 0db4c7ccea..682e24bca7 100644 --- a/mods/cnc/menus.yaml +++ b/mods/cnc/menus.yaml @@ -491,19 +491,20 @@ Container: Width:120 Height:25 Text:Change Map + Label@LABEL_LOBBY_TEAM: + Id:LABEL_LOBBY_TEAM + Width:70 + Height:25 + X:0 + Y:PARENT_BOTTOM - 75 + Text:Chat: + Align:Right TextField@CHAT_TEXTFIELD: Id:CHAT_TEXTFIELD Visible:true - X:PARENT_RIGHT-550 - Y:300 - Width:300 - Height:25 - TextField@CHAT_TEXTFIELD2: - Id:CHAT_TEXTFIELD2 - Visible:true - X:PARENT_RIGHT-550 - Y:250 - Width:300 + X:75 + Y:PARENT_BOTTOM - 75 + Width:700 Height:25 Button@DISCONNECT_BUTTON: Id:DISCONNECT_BUTTON