Merge pull request #3983 from pchote/polish-chat-input
Polish chat input.
This commit is contained in:
@@ -129,7 +129,6 @@ namespace OpenRA.GameRules
|
||||
{
|
||||
public string[] Mods = { "ra" };
|
||||
|
||||
public bool TeamChatToggle = false;
|
||||
public bool ShowShellmap = true;
|
||||
|
||||
public bool ViewportEdgeScroll = true;
|
||||
|
||||
@@ -185,7 +185,6 @@
|
||||
<Compile Include="Widgets\BackgroundWidget.cs" />
|
||||
<Compile Include="Widgets\ButtonWidget.cs" />
|
||||
<Compile Include="Widgets\ChatDisplayWidget.cs" />
|
||||
<Compile Include="Widgets\ChatEntryWidget.cs" />
|
||||
<Compile Include="Widgets\CheckboxWidget.cs" />
|
||||
<Compile Include="Widgets\ChromeMetrics.cs" />
|
||||
<Compile Include="Widgets\ColorBlockWidget.cs" />
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
@@ -18,10 +19,9 @@ namespace OpenRA.Widgets
|
||||
{
|
||||
public readonly int RemoveTime = 0;
|
||||
public readonly bool UseContrast = false;
|
||||
public string Notification = "";
|
||||
|
||||
const int logLength = 9;
|
||||
public string Notification = "";
|
||||
public bool DrawBackground = true;
|
||||
int ticksUntilRemove = 0;
|
||||
|
||||
internal List<ChatLine> recentLines = new List<ChatLine>();
|
||||
@@ -35,13 +35,9 @@ 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 chatpos = new int2(chatLogArea.X + 5, chatLogArea.Bottom - 5);
|
||||
|
||||
var font = Game.Renderer.Fonts["Regular"];
|
||||
|
||||
Game.Renderer.EnableScissor(chatLogArea.Left, chatLogArea.Top, chatLogArea.Width, chatLogArea.Height);
|
||||
|
||||
foreach (var line in recentLines.AsEnumerable().Reverse())
|
||||
@@ -52,12 +48,14 @@ namespace OpenRA.Widgets
|
||||
if (!string.IsNullOrEmpty(line.Owner))
|
||||
{
|
||||
owner = line.Owner + ":";
|
||||
inset = font.Measure(owner).X + 10;
|
||||
inset = font.Measure(owner).X + 5;
|
||||
}
|
||||
|
||||
var text = WidgetUtils.WrapText(line.Text, chatLogArea.Width - inset, font);
|
||||
var textLines = text.Split(new[] { '\n' }).Count();
|
||||
chatpos.Y -= 20 * textLines;
|
||||
var text = WidgetUtils.WrapText(line.Text, chatLogArea.Width - inset - 6, font);
|
||||
chatpos.Y -= Math.Max(15, font.Measure(text).Y) + 5;
|
||||
|
||||
if (chatpos.Y < pos.Y)
|
||||
break;
|
||||
|
||||
if (owner != null)
|
||||
{
|
||||
@@ -80,12 +78,14 @@ namespace OpenRA.Widgets
|
||||
if (Notification != null)
|
||||
Sound.Play(Notification);
|
||||
|
||||
while (recentLines.Count > logLength) recentLines.RemoveAt(0);
|
||||
while (recentLines.Count > logLength)
|
||||
recentLines.RemoveAt(0);
|
||||
}
|
||||
|
||||
public void RemoveLine()
|
||||
{
|
||||
if (recentLines.Count > 0) recentLines.RemoveAt(0);
|
||||
if (recentLines.Count > 0)
|
||||
recentLines.RemoveAt(0);
|
||||
}
|
||||
|
||||
public void ClearChat()
|
||||
@@ -95,8 +95,12 @@ namespace OpenRA.Widgets
|
||||
|
||||
public override void Tick()
|
||||
{
|
||||
if (RemoveTime == 0) return;
|
||||
if (--ticksUntilRemove > 0) return;
|
||||
if (RemoveTime == 0)
|
||||
return;
|
||||
|
||||
if (--ticksUntilRemove > 0)
|
||||
return;
|
||||
|
||||
ticksUntilRemove = RemoveTime;
|
||||
RemoveLine();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,8 @@ namespace OpenRA.Widgets
|
||||
{
|
||||
public interface ILayout { void AdjustChild(Widget w); void AdjustChildren(); }
|
||||
|
||||
public enum ScrollPanelAlign { Bottom, Top }
|
||||
|
||||
public class ScrollPanelWidget : Widget
|
||||
{
|
||||
public int ScrollbarWidth = 24;
|
||||
@@ -28,6 +30,7 @@ namespace OpenRA.Widgets
|
||||
public int ContentHeight = 0;
|
||||
public ILayout Layout;
|
||||
public int MinimumThumbSize = 10;
|
||||
public ScrollPanelAlign Align = ScrollPanelAlign.Top;
|
||||
protected float ListOffset = 0;
|
||||
protected bool UpPressed = false;
|
||||
protected bool DownPressed = false;
|
||||
@@ -135,12 +138,15 @@ namespace OpenRA.Widgets
|
||||
|
||||
public void ScrollToBottom()
|
||||
{
|
||||
ListOffset = Math.Min(0,Bounds.Height - ContentHeight);
|
||||
ListOffset = Align == ScrollPanelAlign.Top ?
|
||||
Math.Min(0, Bounds.Height - ContentHeight) :
|
||||
Bounds.Height - ContentHeight;
|
||||
}
|
||||
|
||||
public void ScrollToTop()
|
||||
{
|
||||
ListOffset = 0;
|
||||
ListOffset = Align == ScrollPanelAlign.Top ? 0 :
|
||||
Math.Max(0, Bounds.Height - ContentHeight);
|
||||
}
|
||||
|
||||
public bool ScrolledToBottom
|
||||
|
||||
Reference in New Issue
Block a user