emulation of old chat system
This commit is contained in:
@@ -28,6 +28,7 @@ namespace OpenRA.Widgets
|
||||
{
|
||||
const int logLength = 10;
|
||||
public string Notification = "";
|
||||
public bool DrawBackground = true;
|
||||
|
||||
public List<ChatLine> recentLines = new List<ChatLine>();
|
||||
|
||||
@@ -42,6 +43,8 @@ namespace OpenRA.Widgets
|
||||
var pos = RenderOrigin;
|
||||
var chatLogArea = new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height);
|
||||
var chatpos = new int2(chatLogArea.X + 10, chatLogArea.Bottom - 6);
|
||||
|
||||
if (DrawBackground)
|
||||
WidgetUtils.DrawPanel("dialog3", chatLogArea);
|
||||
|
||||
var renderer = Game.chrome.renderer;
|
||||
|
||||
@@ -26,36 +26,53 @@ 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.
|
||||
|
||||
// this emulates the previous chat support, with one improvement: shift+enter can toggle the
|
||||
// team/all mode *while* composing, not just on beginning to compose.
|
||||
|
||||
class ChatEntryWidget : Widget
|
||||
{
|
||||
string content = "";
|
||||
bool composing = true;
|
||||
bool composing = false;
|
||||
bool teamChat = false;
|
||||
|
||||
public override void DrawInner(World world)
|
||||
{
|
||||
//if (!composing)
|
||||
// return;
|
||||
if (composing)
|
||||
{
|
||||
var text = teamChat ? "Chat (Team): " : "Chat (All): ";
|
||||
var w = Game.chrome.renderer.BoldFont.Measure(text).X;
|
||||
|
||||
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.BoldFont.DrawText(text, RenderOrigin + new float2(3, 7), Color.White);
|
||||
Game.chrome.renderer.RegularFont.DrawText(content, RenderOrigin + new float2(3 + w, 7), Color.White);
|
||||
|
||||
Game.chrome.renderer.RgbaSpriteRenderer.Flush();
|
||||
}
|
||||
}
|
||||
|
||||
public override bool LoseFocus(MouseInput mi)
|
||||
{
|
||||
return composing ? false : base.LoseFocus(mi);
|
||||
}
|
||||
|
||||
public override bool HandleInput(MouseInput mi) { return false; }
|
||||
|
||||
public override bool HandleKeyPress(KeyPressEventArgs e, Modifiers modifiers)
|
||||
{
|
||||
if (e.KeyChar == '\r')
|
||||
{
|
||||
if (composing)
|
||||
{
|
||||
if (modifiers.HasModifier(Modifiers.Shift))
|
||||
{
|
||||
teamChat ^= true;
|
||||
return true;
|
||||
}
|
||||
|
||||
composing = false;
|
||||
if (content != "")
|
||||
Game.IssueOrder(Order.Chat(content));
|
||||
Game.IssueOrder(teamChat
|
||||
? Order.TeamChat(content)
|
||||
: Order.Chat(content));
|
||||
content = "";
|
||||
|
||||
LoseFocus();
|
||||
@@ -64,6 +81,8 @@ namespace OpenRA.Widgets
|
||||
else
|
||||
{
|
||||
TakeFocus(new MouseInput());
|
||||
composing = true;
|
||||
teamChat ^= modifiers.HasModifier(Modifiers.Shift);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -74,6 +93,7 @@ namespace OpenRA.Widgets
|
||||
{
|
||||
if (content.Length > 0)
|
||||
content = content.Remove(content.Length - 1);
|
||||
return true;
|
||||
}
|
||||
else if (!char.IsControl(e.KeyChar))
|
||||
{
|
||||
|
||||
@@ -5,21 +5,6 @@ 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
|
||||
@@ -140,6 +125,24 @@ Container@ROOT:
|
||||
Text:Diplomacy
|
||||
Align:Center
|
||||
Bold:True
|
||||
ChatDisplay@INGAME_CHAT_DISPLAY:
|
||||
Id:INGAME_CHAT_DISPLAY
|
||||
X:250
|
||||
Y:WINDOW_BOTTOM - HEIGHT - 30
|
||||
Width: 760
|
||||
Height: 200
|
||||
Visible: True
|
||||
Delegate: ChatDelegate
|
||||
ClickThrough: True
|
||||
DrawBackground: False
|
||||
ChatEntry@INGAME_CHAT_ENTRY:
|
||||
Id:INGAME_CHAT_ENTRY
|
||||
X:250
|
||||
Y:WINDOW_BOTTOM - HEIGHT
|
||||
Width: 760
|
||||
Height: 30
|
||||
Visible: True
|
||||
ClickThrough: True
|
||||
Background@PERF_BG:
|
||||
ClickThrough:true
|
||||
Id:PERF_BG
|
||||
|
||||
Reference in New Issue
Block a user