Textfield editable names
This commit is contained in:
@@ -265,18 +265,7 @@ namespace OpenRA.Server
|
||||
}},
|
||||
{ "name",
|
||||
s =>
|
||||
{
|
||||
if (s.Trim() == "")
|
||||
{
|
||||
SendChatTo( conn, "Blank names are not permitted." );
|
||||
return true;
|
||||
}
|
||||
|
||||
if (s.Length > 10)
|
||||
{
|
||||
s = s.Substring(0,10);
|
||||
}
|
||||
|
||||
{
|
||||
Console.WriteLine("Player@{0} is now known as {1}", conn.socket.RemoteEndPoint, s);
|
||||
GetClient(conn).Name = s;
|
||||
SyncLobbyInfo();
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace OpenRA.Widgets.Delegates
|
||||
return true;
|
||||
};
|
||||
|
||||
var lockTeamsCheckbox = lobby.GetWidget("LOCKTEAMS_CHECKBOX") as CheckboxWidget;
|
||||
var lockTeamsCheckbox = lobby.GetWidget<CheckboxWidget>("LOCKTEAMS_CHECKBOX");
|
||||
lockTeamsCheckbox.IsVisible = () => true;
|
||||
lockTeamsCheckbox.Checked = () => Game.LobbyInfo.GlobalSettings.LockTeams;
|
||||
lockTeamsCheckbox.OnMouseDown = mi =>
|
||||
@@ -68,22 +68,28 @@ namespace OpenRA.Widgets.Delegates
|
||||
};
|
||||
|
||||
Game.LobbyInfoChanged += UpdatePlayerList;
|
||||
Chrome.chatWidget = lobby.GetWidget("CHAT_DISPLAY") as ChatDisplayWidget;
|
||||
Chrome.chatWidget = lobby.GetWidget<ChatDisplayWidget>("CHAT_DISPLAY");
|
||||
|
||||
|
||||
bool teamChat = false;
|
||||
var chatLabel = lobby.GetWidget("LABEL_CHATTYPE") as LabelWidget;
|
||||
var chatTextField = lobby.GetWidget("CHAT_TEXTFIELD") as TextFieldWidget;
|
||||
chatTextField.OnEnterKey = text =>
|
||||
var chatLabel = lobby.GetWidget<LabelWidget>("LABEL_CHATTYPE");
|
||||
var chatTextField = lobby.GetWidget<TextFieldWidget>("CHAT_TEXTFIELD");
|
||||
chatTextField.OnEnterKey = () =>
|
||||
{
|
||||
var order = (teamChat) ? Order.TeamChat( text ) : Order.Chat( text );
|
||||
if (chatTextField.Text.Length == 0)
|
||||
return true;
|
||||
|
||||
var order = (teamChat) ? Order.TeamChat( chatTextField.Text ) : Order.Chat( chatTextField.Text );
|
||||
Game.IssueOrder( order );
|
||||
chatTextField.Text = "";
|
||||
return true;
|
||||
};
|
||||
|
||||
chatTextField.OnTabKey = text =>
|
||||
chatTextField.OnTabKey = () =>
|
||||
{
|
||||
teamChat ^= true;
|
||||
chatLabel.Text = (teamChat) ? "Team:" : "Chat:";
|
||||
return true;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -101,6 +107,23 @@ namespace OpenRA.Widgets.Delegates
|
||||
if(client.Index == Game.LocalClient.Index && c.State != Session.ClientState.Ready)
|
||||
{
|
||||
template = LocalPlayerTemplate.Clone();
|
||||
var name = template.GetWidget<TextFieldWidget>("NAME");
|
||||
name.Text = c.Name;
|
||||
name.OnLoseFocus = () => name.Text = c.Name;
|
||||
name.OnEnterKey = () =>
|
||||
{
|
||||
name.Text = name.Text.Trim();
|
||||
if (name.Text.Length == 0)
|
||||
name.Text = c.Name;
|
||||
|
||||
if (name.Text == c.Name)
|
||||
return true;
|
||||
|
||||
Game.IssueOrder(Order.Chat( "/name "+name.Text ));
|
||||
Game.Settings.PlayerName = name.Text;
|
||||
Game.Settings.Save();
|
||||
return true;
|
||||
};
|
||||
|
||||
var color = template.GetWidget<ButtonWidget>("COLOR");
|
||||
color.OnMouseUp = CyclePalette;
|
||||
@@ -127,7 +150,7 @@ namespace OpenRA.Widgets.Delegates
|
||||
else
|
||||
{
|
||||
template = RemotePlayerTemplate.Clone();
|
||||
|
||||
template.GetWidget<LabelWidget>("NAME").GetText = () => c.Name;
|
||||
var color = template.GetWidget<ColorBlockWidget>("COLOR");
|
||||
color.GetColor = () => Game.world.PlayerColors()[c.PaletteIndex % Game.world.PlayerColors().Count].Color;
|
||||
|
||||
@@ -148,7 +171,6 @@ namespace OpenRA.Widgets.Delegates
|
||||
|
||||
template.Id = "PLAYER_{0}".F(c.Index);
|
||||
template.Parent = Players;
|
||||
template.GetWidget<LabelWidget>("NAME").GetText = () => c.Name;
|
||||
|
||||
template.Bounds = new Rectangle(0, offset, template.Bounds.Width, template.Bounds.Height);
|
||||
template.IsVisible = () => true;
|
||||
|
||||
@@ -25,11 +25,13 @@ namespace OpenRA.Widgets
|
||||
{
|
||||
class TextFieldWidget : Widget
|
||||
{
|
||||
public string TextBuffer = "";
|
||||
public string Text = "";
|
||||
public bool Bold = true;
|
||||
public int VisualHeight = 1;
|
||||
public Action<string> OnEnterKey = text => {};
|
||||
public Action<string> OnTabKey = text => {};
|
||||
|
||||
public Func<bool> OnEnterKey = () => {return false;};
|
||||
public Func<bool> OnTabKey = () => {return false;};
|
||||
public Action OnLoseFocus = () => {};
|
||||
|
||||
public TextFieldWidget()
|
||||
: base()
|
||||
{
|
||||
@@ -38,7 +40,7 @@ namespace OpenRA.Widgets
|
||||
public TextFieldWidget(Widget widget)
|
||||
:base(widget)
|
||||
{
|
||||
TextBuffer = (widget as TextFieldWidget).TextBuffer;
|
||||
Text = (widget as TextFieldWidget).Text;
|
||||
}
|
||||
|
||||
public override bool HandleInput(MouseInput mi)
|
||||
@@ -46,6 +48,7 @@ namespace OpenRA.Widgets
|
||||
// We get this first if we are focussed; if the click was somewhere else remove focus
|
||||
if (Chrome.selectedWidget == this && mi.Event == MouseInputEvent.Down && !GetEventBounds().Contains(mi.Location.X,mi.Location.Y))
|
||||
{
|
||||
OnLoseFocus();
|
||||
Chrome.selectedWidget = null;
|
||||
return false;
|
||||
}
|
||||
@@ -82,15 +85,11 @@ namespace OpenRA.Widgets
|
||||
if (Chrome.selectedWidget != this)
|
||||
return false;
|
||||
|
||||
if (e.KeyChar == '\r')
|
||||
{
|
||||
if (TextBuffer.Length > 0)
|
||||
OnEnterKey(TextBuffer);
|
||||
TextBuffer = "";
|
||||
}
|
||||
if (e.KeyChar == '\r' && OnEnterKey())
|
||||
return true;
|
||||
|
||||
if (e.KeyChar == '\t')
|
||||
OnTabKey(TextBuffer);
|
||||
if (e.KeyChar == '\t' && OnTabKey())
|
||||
return true;
|
||||
|
||||
TypeChar(e.KeyChar);
|
||||
return true;
|
||||
@@ -100,11 +99,11 @@ namespace OpenRA.Widgets
|
||||
{
|
||||
if (c == '\b' || c == 0x7f)
|
||||
{
|
||||
if (TextBuffer.Length > 0)
|
||||
TextBuffer = TextBuffer.Remove(TextBuffer.Length - 1);
|
||||
if (Text.Length > 0)
|
||||
Text = Text.Remove(Text.Length - 1);
|
||||
}
|
||||
else if (!char.IsControl(c))
|
||||
TextBuffer += c;
|
||||
Text += c;
|
||||
}
|
||||
|
||||
int blinkCycle = 10;
|
||||
@@ -122,10 +121,10 @@ namespace OpenRA.Widgets
|
||||
public override void DrawInner(World world)
|
||||
{
|
||||
int margin = 5;
|
||||
var font = Game.chrome.renderer.RegularFont;
|
||||
var font = (Bold) ? Game.chrome.renderer.BoldFont : Game.chrome.renderer.RegularFont;
|
||||
|
||||
var text = TextBuffer + ((showCursor && Chrome.selectedWidget == this) ? "|" : "");
|
||||
var textSize = font.Measure(TextBuffer);
|
||||
var text = Text + ((showCursor && Chrome.selectedWidget == this) ? "|" : "");
|
||||
var textSize = font.Measure(Text);
|
||||
var pos = DrawPosition();
|
||||
|
||||
WidgetUtils.DrawPanel("dialog3",
|
||||
|
||||
@@ -53,9 +53,9 @@ namespace OpenRA
|
||||
}
|
||||
|
||||
public void SetLocalPlayer(int index)
|
||||
{
|
||||
{
|
||||
localPlayerIndex = index;
|
||||
if (!string.IsNullOrEmpty(Game.Settings.PlayerName)
|
||||
if (Game.LobbyInfo.Clients.Count > 0 && !string.IsNullOrEmpty(Game.Settings.PlayerName)
|
||||
&& Game.LobbyInfo.Clients[index].Name != Game.Settings.PlayerName)
|
||||
Game.IssueOrder(Order.Chat("/name " + Game.Settings.PlayerName));
|
||||
}
|
||||
|
||||
@@ -332,13 +332,14 @@ Container:
|
||||
Height:30
|
||||
Visible:false
|
||||
Children:
|
||||
Label@NAME:
|
||||
TextField@NAME:
|
||||
Id:NAME
|
||||
Text:Name
|
||||
Width:95
|
||||
Height:25
|
||||
X:0
|
||||
Y:0
|
||||
Bold: true
|
||||
Button@COLOR:
|
||||
Id:COLOR
|
||||
Width:65
|
||||
|
||||
Reference in New Issue
Block a user