Use the newly polished text entry in C&C.

This commit is contained in:
Paul Chote
2013-10-22 21:47:58 +13:00
parent 15de893cec
commit 11b34884cc
9 changed files with 69 additions and 156 deletions

View File

@@ -130,7 +130,6 @@ namespace OpenRA.GameRules
{ {
public string[] Mods = { "ra" }; public string[] Mods = { "ra" };
public bool TeamChatToggle = false;
public bool ShowShellmap = true; public bool ShowShellmap = true;
public bool ViewportEdgeScroll = true; public bool ViewportEdgeScroll = true;

View File

@@ -185,7 +185,6 @@
<Compile Include="Widgets\BackgroundWidget.cs" /> <Compile Include="Widgets\BackgroundWidget.cs" />
<Compile Include="Widgets\ButtonWidget.cs" /> <Compile Include="Widgets\ButtonWidget.cs" />
<Compile Include="Widgets\ChatDisplayWidget.cs" /> <Compile Include="Widgets\ChatDisplayWidget.cs" />
<Compile Include="Widgets\ChatEntryWidget.cs" />
<Compile Include="Widgets\CheckboxWidget.cs" /> <Compile Include="Widgets\CheckboxWidget.cs" />
<Compile Include="Widgets\ChromeMetrics.cs" /> <Compile Include="Widgets\ChromeMetrics.cs" />
<Compile Include="Widgets\ColorBlockWidget.cs" /> <Compile Include="Widgets\ColorBlockWidget.cs" />

View File

@@ -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;
}
}
}

View File

@@ -35,17 +35,6 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
() => world.OrderGenerator is T ? icon + "-active" : icon; () => world.OrderGenerator is T ? icon + "-active" : icon;
} }
void AddChatLine(Color c, string from, string text)
{
ingameRoot.Get<ChatDisplayWidget>("CHAT_DISPLAY").AddLine(c, from, text);
}
void UnregisterEvents()
{
Game.AddChatLine -= AddChatLine;
Game.BeforeGameStart -= UnregisterEvents;
}
[ObjectCreator.UseCtor] [ObjectCreator.UseCtor]
public CncIngameChromeLogic(Widget widget, World world) public CncIngameChromeLogic(Widget widget, World world)
{ {
@@ -53,9 +42,6 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
world.WorldActor.Trait<CncMenuPaletteEffect>() world.WorldActor.Trait<CncMenuPaletteEffect>()
.Fade(CncMenuPaletteEffect.EffectType.None); .Fade(CncMenuPaletteEffect.EffectType.None);
Game.AddChatLine += AddChatLine;
Game.BeforeGameStart += UnregisterEvents;
ingameRoot = widget.Get("INGAME_ROOT"); ingameRoot = widget.Get("INGAME_ROOT");
var playerRoot = ingameRoot.Get("PLAYER_ROOT"); var playerRoot = ingameRoot.Get("PLAYER_ROOT");
@@ -64,6 +50,8 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
InitObserverWidgets(world, playerRoot); InitObserverWidgets(world, playerRoot);
else else
InitPlayerWidgets(world, playerRoot); InitPlayerWidgets(world, playerRoot);
Game.LoadWidget(world, "CHAT_PANEL", playerRoot, new WidgetArgs());
} }
public void OptionsClicked() public void OptionsClicked()

View File

@@ -153,10 +153,6 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
mouseScrollDropdown.OnMouseDown = _ => ShowMouseScrollDropdown(mouseScrollDropdown, gameSettings); mouseScrollDropdown.OnMouseDown = _ => ShowMouseScrollDropdown(mouseScrollDropdown, gameSettings);
mouseScrollDropdown.GetText = () => gameSettings.MouseScroll.ToString(); mouseScrollDropdown.GetText = () => gameSettings.MouseScroll.ToString();
var teamchatCheckbox = inputPane.Get<CheckboxWidget>("TEAMCHAT_CHECKBOX");
teamchatCheckbox.IsChecked = () => gameSettings.TeamChatToggle;
teamchatCheckbox.OnClick = () => gameSettings.TeamChatToggle ^= true;
panel.Get<ButtonWidget>("BACK_BUTTON").OnClick = () => panel.Get<ButtonWidget>("BACK_BUTTON").OnClick = () =>
{ {
playerSettings.Name = nameTextfield.Text; playerSettings.Name = nameTextfield.Text;

View File

@@ -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

View File

@@ -7,21 +7,6 @@ Container@INGAME_ROOT:
StrategicProgress@STRATEGIC_PROGRESS: StrategicProgress@STRATEGIC_PROGRESS:
X: WINDOW_RIGHT/2 X: WINDOW_RIGHT/2
Y: 40 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: Container@PERFORMANCE_INFO:
Logic:PerfDebugLogic Logic:PerfDebugLogic
Children: Children:

View File

@@ -293,20 +293,6 @@ Container@SETTINGS_PANEL:
Height:25 Height:25
Font:Regular Font:Regular
Text:Enabled 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: Button@GENERAL_BUTTON:
Y:319 Y:319
Width:140 Width:140

View File

@@ -76,6 +76,7 @@ ChromeLayout:
mods/cnc/chrome/mapchooser.yaml mods/cnc/chrome/mapchooser.yaml
mods/cnc/chrome/replaybrowser.yaml mods/cnc/chrome/replaybrowser.yaml
mods/cnc/chrome/ingame.yaml mods/cnc/chrome/ingame.yaml
mods/cnc/chrome/ingame-chat.yaml
mods/cnc/chrome/ingamemenu.yaml mods/cnc/chrome/ingamemenu.yaml
mods/cnc/chrome/music.yaml mods/cnc/chrome/music.yaml
mods/cnc/chrome/modchooser.yaml mods/cnc/chrome/modchooser.yaml