fix chat (1/2)

This commit is contained in:
Chris Forbes
2010-07-14 20:55:07 +12:00
parent fed33fdb00
commit 093e445564
4 changed files with 141 additions and 6 deletions

View File

@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -87,6 +87,8 @@
<Compile Include="Traits\Player\TechTreeCache.cs" />
<Compile Include="Traits\Modifiers\HiddenUnderFog.cs" />
<Compile Include="Traits\World\Shroud.cs" />
<Compile Include="Widgets\ChatEntryWidget.cs" />
<Compile Include="Widgets\Delegates\ChatDelegate.cs" />
<Compile Include="Widgets\Delegates\ConnectionDialogsDelegate.cs" />
<Compile Include="Widgets\Delegates\CreateServerMenuDelegate.cs" />
<Compile Include="Widgets\Delegates\DiplomacyDelegate.cs" />
@@ -264,9 +266,4 @@
<Target Name="AfterBuild">
</Target>
-->
<ItemGroup>
<Folder Include="Traits\" />
<Folder Include="Traits\" />
<Folder Include="Traits\Activities\" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,90 @@
#region Copyright & License Information
/*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA.
*
* OpenRA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenRA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
using System.Drawing;
using System.Windows.Forms;
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.
class ChatEntryWidget : Widget
{
string content = "";
bool composing = true;
public override void DrawInner(World world)
{
//if (!composing)
// return;
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.RgbaSpriteRenderer.Flush();
}
public override bool LoseFocus(MouseInput mi)
{
return composing ? false : base.LoseFocus(mi);
}
public override bool HandleKeyPress(KeyPressEventArgs e, Modifiers modifiers)
{
if (e.KeyChar == '\r')
{
if (composing)
{
composing = false;
if (content != "")
Game.IssueOrder(Order.Chat(content));
content = "";
LoseFocus();
return true;
}
else
{
TakeFocus(new MouseInput());
return true;
}
}
if (composing)
{
if (e.KeyChar == '\b' || e.KeyChar == 0x7f)
{
if (content.Length > 0)
content = content.Remove(content.Length - 1);
}
else if (!char.IsControl(e.KeyChar))
{
content += e.KeyChar;
return true;
}
return false;
}
return base.HandleKeyPress(e, modifiers);
}
}
}

View File

@@ -0,0 +1,33 @@
#region Copyright & License Information
/*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA.
*
* OpenRA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenRA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
namespace OpenRA.Widgets.Delegates
{
public class ChatDelegate : IWidgetDelegate
{
public ChatDelegate()
{
var r = Chrome.rootWidget;
var chatDisplay = r.GetWidget<ChatDisplayWidget>("INGAME_CHAT_DISPLAY");
var chatEntry = r.GetWidget<ChatEntryWidget>("INGAME_CHAT_ENTRY");
Game.AddChatLine += chatDisplay.AddLine;
}
}
}

View File

@@ -5,6 +5,21 @@ 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