From 11b34884ccc451580b8bef00b225e9f654377fc6 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Tue, 22 Oct 2013 21:47:58 +1300 Subject: [PATCH] Use the newly polished text entry in C&C. --- OpenRA.Game/GameRules/Settings.cs | 1 - OpenRA.Game/OpenRA.Game.csproj | 1 - OpenRA.Game/Widgets/ChatEntryWidget.cs | 107 ------------------ .../Widgets/Logic/CncIngameChromeLogic.cs | 16 +-- .../Widgets/Logic/CncSettingsLogic.cs | 4 - mods/cnc/chrome/ingame-chat.yaml | 66 +++++++++++ mods/cnc/chrome/ingame.yaml | 15 --- mods/cnc/chrome/settings.yaml | 14 --- mods/cnc/mod.yaml | 1 + 9 files changed, 69 insertions(+), 156 deletions(-) delete mode 100755 OpenRA.Game/Widgets/ChatEntryWidget.cs create mode 100644 mods/cnc/chrome/ingame-chat.yaml diff --git a/OpenRA.Game/GameRules/Settings.cs b/OpenRA.Game/GameRules/Settings.cs index 4000f15f1f..21d29f50d0 100644 --- a/OpenRA.Game/GameRules/Settings.cs +++ b/OpenRA.Game/GameRules/Settings.cs @@ -130,7 +130,6 @@ namespace OpenRA.GameRules { public string[] Mods = { "ra" }; - public bool TeamChatToggle = false; public bool ShowShellmap = true; public bool ViewportEdgeScroll = true; diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj index a60f54b7d9..108f137b14 100644 --- a/OpenRA.Game/OpenRA.Game.csproj +++ b/OpenRA.Game/OpenRA.Game.csproj @@ -185,7 +185,6 @@ - diff --git a/OpenRA.Game/Widgets/ChatEntryWidget.cs b/OpenRA.Game/Widgets/ChatEntryWidget.cs deleted file mode 100755 index 19c1f0e196..0000000000 --- a/OpenRA.Game/Widgets/ChatEntryWidget.cs +++ /dev/null @@ -1,107 +0,0 @@ -#region Copyright & License Information -/* - * Copyright 2007-2011 The OpenRA Developers (see AUTHORS) - * This file is part of OpenRA, which is free software. It is made - * available to you under the terms of the GNU General Public License - * as published by the Free Software Foundation. For more information, - * see COPYING. - */ -#endregion - -using System.Drawing; -using OpenRA.Network; - -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. - - public class ChatEntryWidget : Widget - { - string content = ""; - bool composing = false; - bool teamChat = false; - public readonly bool UseContrast = false; - - readonly OrderManager orderManager; - - [ObjectCreator.UseCtor] - internal ChatEntryWidget( OrderManager orderManager ) - { - this.orderManager = orderManager; - } - - public override void Draw() - { - if (composing) - { - var text = teamChat ? "Chat (Team): " : "Chat (All): "; - var w = Game.Renderer.Fonts["Bold"].Measure(text).X; - - Game.Renderer.Fonts["Bold"].DrawTextWithContrast(text, RenderOrigin + new float2(3, 7), Color.White, Color.Black, UseContrast ? 1 : 0); - Game.Renderer.Fonts["Regular"].DrawTextWithContrast(content, RenderOrigin + new float2(3 + w, 7), Color.White, Color.Black, UseContrast ? 1 : 0); - } - } - - public override Rectangle EventBounds { get { return Rectangle.Empty; } } - - public override bool HandleKeyPress(KeyInput e) - { - if (e.Event == KeyInputEvent.Up) return false; - - if (e.Key == Keycode.RETURN || e.Key == Keycode.KP_ENTER) - { - if (composing) - { - if (e.Modifiers.HasModifier(Modifiers.Shift)) - { - teamChat ^= true; - return true; - } - - composing = false; - if (content != "") - orderManager.IssueOrder(Order.Chat(teamChat, content)); - content = ""; - - YieldKeyboardFocus(); - return true; - } - else - { - TakeKeyboardFocus(); - composing = true; - teamChat = (Game.Settings.Game.TeamChatToggle && teamChat) - ^ e.Modifiers.HasModifier(Modifiers.Shift); - return true; - } - } - - if (composing) - { - if (e.Key == Keycode.ESCAPE) - { - composing = false; - content = ""; - YieldKeyboardFocus(); - return true; - } - else if (e.Key == Keycode.BACKSPACE) - { - if (content.Length > 0) - content = content.Remove(content.Length - 1); - return true; - } - else if (e.IsValidInput()) - { - content += e.UnicodeChar.ToString(); - return true; - } - - return false; - } - - return false; - } - } -} diff --git a/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameChromeLogic.cs b/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameChromeLogic.cs index 75f77f6f2c..181e1e7cb9 100644 --- a/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameChromeLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameChromeLogic.cs @@ -35,17 +35,6 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic () => world.OrderGenerator is T ? icon + "-active" : icon; } - void AddChatLine(Color c, string from, string text) - { - ingameRoot.Get("CHAT_DISPLAY").AddLine(c, from, text); - } - - void UnregisterEvents() - { - Game.AddChatLine -= AddChatLine; - Game.BeforeGameStart -= UnregisterEvents; - } - [ObjectCreator.UseCtor] public CncIngameChromeLogic(Widget widget, World world) { @@ -53,9 +42,6 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic world.WorldActor.Trait() .Fade(CncMenuPaletteEffect.EffectType.None); - Game.AddChatLine += AddChatLine; - Game.BeforeGameStart += UnregisterEvents; - ingameRoot = widget.Get("INGAME_ROOT"); var playerRoot = ingameRoot.Get("PLAYER_ROOT"); @@ -64,6 +50,8 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic InitObserverWidgets(world, playerRoot); else InitPlayerWidgets(world, playerRoot); + + Game.LoadWidget(world, "CHAT_PANEL", playerRoot, new WidgetArgs()); } public void OptionsClicked() diff --git a/OpenRA.Mods.Cnc/Widgets/Logic/CncSettingsLogic.cs b/OpenRA.Mods.Cnc/Widgets/Logic/CncSettingsLogic.cs index abda62714f..66dbf85ffe 100644 --- a/OpenRA.Mods.Cnc/Widgets/Logic/CncSettingsLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/Logic/CncSettingsLogic.cs @@ -153,10 +153,6 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic mouseScrollDropdown.OnMouseDown = _ => ShowMouseScrollDropdown(mouseScrollDropdown, gameSettings); mouseScrollDropdown.GetText = () => gameSettings.MouseScroll.ToString(); - var teamchatCheckbox = inputPane.Get("TEAMCHAT_CHECKBOX"); - teamchatCheckbox.IsChecked = () => gameSettings.TeamChatToggle; - teamchatCheckbox.OnClick = () => gameSettings.TeamChatToggle ^= true; - panel.Get("BACK_BUTTON").OnClick = () => { playerSettings.Name = nameTextfield.Text; diff --git a/mods/cnc/chrome/ingame-chat.yaml b/mods/cnc/chrome/ingame-chat.yaml new file mode 100644 index 0000000000..ce6b1e1c1f --- /dev/null +++ b/mods/cnc/chrome/ingame-chat.yaml @@ -0,0 +1,66 @@ +Container@CHAT_PANEL: + X:(WINDOW_RIGHT - WIDTH) / 2 + Y:WINDOW_BOTTOM - HEIGHT - 15 + Width:550 + Height:194 + Logic:IngameChatLogic + Children: + Container@CHAT_OVERLAY: + Width:PARENT_RIGHT-24 + Height:PARENT_BOTTOM-25 + Visible:false + Children: + ChatDisplay@CHAT_DISPLAY: + Width:PARENT_RIGHT + Height:PARENT_BOTTOM + RemoveTime:250 + UseContrast: yes + Container@CHAT_CHROME: + Width:PARENT_RIGHT + Height:PARENT_BOTTOM + Children: + Button@CHAT_MODE: + Y:PARENT_BOTTOM - HEIGHT + Width:50 + Height:25 + Text:Team + Font:Bold + TextField@CHAT_TEXTFIELD: + X:55 + Y:PARENT_BOTTOM - HEIGHT + Width:466 + Height:25 + Button@CHAT_CLOSE: + X:526 + Y:PARENT_BOTTOM - HEIGHT + Width:24 + Height:25 + Children: + Image: + ImageCollection:lobby-bits + ImageName:kick + X:6 + Y:8 + ScrollPanel@CHAT_SCROLLPANEL: + Y:PARENT_BOTTOM - HEIGHT - 30 + Width:550 + Height:164 + ItemSpacing:4 + Align:Bottom + Children: + Container@CHAT_TEMPLATE: + X:2 + Width:PARENT_RIGHT-27 + Height:16 + Children: + Label@NAME: + X:3 + Width:50 + Height:15 + VAlign:Top + Label@TEXT: + X:12 + Width:PARENT_RIGHT - 17 + Height:15 + WordWrap:true + VAlign:Top diff --git a/mods/cnc/chrome/ingame.yaml b/mods/cnc/chrome/ingame.yaml index 23645383f4..3533a7f621 100644 --- a/mods/cnc/chrome/ingame.yaml +++ b/mods/cnc/chrome/ingame.yaml @@ -7,21 +7,6 @@ Container@INGAME_ROOT: StrategicProgress@STRATEGIC_PROGRESS: X: WINDOW_RIGHT/2 Y: 40 - ChatDisplay@CHAT_DISPLAY: - X:250 - Y:WINDOW_BOTTOM - HEIGHT - 30 - Width: 760 - Height: 200 - DrawBackground: False - RemoveTime:250 - UseContrast: yes - Notification: scold1.aud - ChatEntry@CHAT_ENTRY: - X:250 - Y:WINDOW_BOTTOM - HEIGHT - Width: 760 - Height: 30 - UseContrast: yes Container@PERFORMANCE_INFO: Logic:PerfDebugLogic Children: diff --git a/mods/cnc/chrome/settings.yaml b/mods/cnc/chrome/settings.yaml index 58226a5550..7b3b7097d6 100644 --- a/mods/cnc/chrome/settings.yaml +++ b/mods/cnc/chrome/settings.yaml @@ -293,20 +293,6 @@ Container@SETTINGS_PANEL: Height:25 Font:Regular Text:Enabled - Label@KEYBOARD_TITLE: - X:375 - Y:20 - Width:340 - Font:Bold - Text:Keyboard Input - Align:Center - Checkbox@TEAMCHAT_CHECKBOX: - X:375 - Y:35 - Width:240 - Height:20 - Font:Regular - Text:Shift-Enter Toggles Team Chat Button@GENERAL_BUTTON: Y:319 Width:140 diff --git a/mods/cnc/mod.yaml b/mods/cnc/mod.yaml index 5779f2d1ac..acc99f5a70 100644 --- a/mods/cnc/mod.yaml +++ b/mods/cnc/mod.yaml @@ -76,6 +76,7 @@ ChromeLayout: mods/cnc/chrome/mapchooser.yaml mods/cnc/chrome/replaybrowser.yaml mods/cnc/chrome/ingame.yaml + mods/cnc/chrome/ingame-chat.yaml mods/cnc/chrome/ingamemenu.yaml mods/cnc/chrome/music.yaml mods/cnc/chrome/modchooser.yaml