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