fix chat (1/2)
This commit is contained in:
@@ -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">
|
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
@@ -87,6 +87,8 @@
|
|||||||
<Compile Include="Traits\Player\TechTreeCache.cs" />
|
<Compile Include="Traits\Player\TechTreeCache.cs" />
|
||||||
<Compile Include="Traits\Modifiers\HiddenUnderFog.cs" />
|
<Compile Include="Traits\Modifiers\HiddenUnderFog.cs" />
|
||||||
<Compile Include="Traits\World\Shroud.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\ConnectionDialogsDelegate.cs" />
|
||||||
<Compile Include="Widgets\Delegates\CreateServerMenuDelegate.cs" />
|
<Compile Include="Widgets\Delegates\CreateServerMenuDelegate.cs" />
|
||||||
<Compile Include="Widgets\Delegates\DiplomacyDelegate.cs" />
|
<Compile Include="Widgets\Delegates\DiplomacyDelegate.cs" />
|
||||||
@@ -264,9 +266,4 @@
|
|||||||
<Target Name="AfterBuild">
|
<Target Name="AfterBuild">
|
||||||
</Target>
|
</Target>
|
||||||
-->
|
-->
|
||||||
<ItemGroup>
|
|
||||||
<Folder Include="Traits\" />
|
|
||||||
<Folder Include="Traits\" />
|
|
||||||
<Folder Include="Traits\Activities\" />
|
|
||||||
</ItemGroup>
|
|
||||||
</Project>
|
</Project>
|
||||||
90
OpenRA.Game/Widgets/ChatEntryWidget.cs
Normal file
90
OpenRA.Game/Widgets/ChatEntryWidget.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
33
OpenRA.Game/Widgets/Delegates/ChatDelegate.cs
Normal file
33
OpenRA.Game/Widgets/Delegates/ChatDelegate.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,6 +5,21 @@ Container@ROOT:
|
|||||||
Delegate:IngameChromeDelegate
|
Delegate:IngameChromeDelegate
|
||||||
Visible:false
|
Visible:false
|
||||||
Children:
|
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:
|
PostGame@POSTGAME_TEXT:
|
||||||
Id:POSTGAME_TEXT
|
Id:POSTGAME_TEXT
|
||||||
X:0
|
X:0
|
||||||
|
|||||||
Reference in New Issue
Block a user