simplify teamchat code

This commit is contained in:
Chris Forbes
2011-09-24 22:10:02 +12:00
parent 1216cef981
commit 7b3de29f05
4 changed files with 13 additions and 27 deletions

View File

@@ -189,14 +189,10 @@ namespace OpenRA
// Named constructors for Orders. // Named constructors for Orders.
// Now that Orders are resolved by individual Actors, these are weird; you unpack orders manually, but not pack them. // Now that Orders are resolved by individual Actors, these are weird; you unpack orders manually, but not pack them.
public static Order Chat(string text)
{
return new Order("Chat", null, false) { IsImmediate = true, TargetString = text};
}
public static Order TeamChat(string text) public static Order Chat(bool team, string text)
{ {
return new Order("TeamChat", null, false) { IsImmediate = true, TargetString = text }; return new Order(team ? "TeamChat" : "Chat", null, false) { IsImmediate = true, TargetString = text};
} }
public static Order HandshakeResponse(string text) public static Order HandshakeResponse(string text)

View File

@@ -16,9 +16,6 @@ namespace OpenRA.Widgets
// a dirty hack of a widget, which likes to steal the focus when \r is pressed, and then // 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. // 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.
public class ChatEntryWidget : Widget public class ChatEntryWidget : Widget
{ {
string content = ""; string content = "";
@@ -27,6 +24,7 @@ namespace OpenRA.Widgets
public readonly bool UseContrast = false; public readonly bool UseContrast = false;
readonly OrderManager orderManager; readonly OrderManager orderManager;
[ObjectCreator.UseCtor] [ObjectCreator.UseCtor]
internal ChatEntryWidget( [ObjectCreator.Param] OrderManager orderManager ) internal ChatEntryWidget( [ObjectCreator.Param] OrderManager orderManager )
{ {
@@ -46,6 +44,7 @@ namespace OpenRA.Widgets
} }
public override Rectangle EventBounds { get { return Rectangle.Empty; } } public override Rectangle EventBounds { get { return Rectangle.Empty; } }
public override bool LoseFocus(MouseInput mi) public override bool LoseFocus(MouseInput mi)
{ {
return composing ? false : base.LoseFocus(mi); return composing ? false : base.LoseFocus(mi);
@@ -67,9 +66,7 @@ namespace OpenRA.Widgets
composing = false; composing = false;
if (content != "") if (content != "")
orderManager.IssueOrder(teamChat orderManager.IssueOrder(Order.Chat(teamChat, content));
? Order.TeamChat(content)
: Order.Chat(content));
content = ""; content = "";
LoseFocus(); LoseFocus();
@@ -79,14 +76,8 @@ namespace OpenRA.Widgets
{ {
TakeFocus(new MouseInput()); TakeFocus(new MouseInput());
composing = true; composing = true;
if (Game.Settings.Game.TeamChatToggle) teamChat = (Game.Settings.Game.TeamChatToggle && teamChat)
{ ^ e.Modifiers.HasModifier(Modifiers.Shift);
teamChat ^= e.Modifiers.HasModifier(Modifiers.Shift);
}
else
{
teamChat = e.Modifiers.HasModifier(Modifiers.Shift);
}
return true; return true;
} }
} }

View File

@@ -198,13 +198,13 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
bool teamChat = false; bool teamChat = false;
var chatLabel = lobby.GetWidget<LabelWidget>("LABEL_CHATTYPE"); var chatLabel = lobby.GetWidget<LabelWidget>("LABEL_CHATTYPE");
var chatTextField = lobby.GetWidget<TextFieldWidget>("CHAT_TEXTFIELD"); var chatTextField = lobby.GetWidget<TextFieldWidget>("CHAT_TEXTFIELD");
chatTextField.OnEnterKey = () => chatTextField.OnEnterKey = () =>
{ {
if (chatTextField.Text.Length == 0) if (chatTextField.Text.Length == 0)
return true; return true;
var order = (teamChat) ? Order.TeamChat(chatTextField.Text) : Order.Chat(chatTextField.Text); orderManager.IssueOrder(Order.Chat(teamChat, chatTextField.Text));
orderManager.IssueOrder(order);
chatTextField.Text = ""; chatTextField.Text = "";
return true; return true;
}; };

View File

@@ -146,8 +146,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
if (chatTextField.Text.Length == 0) if (chatTextField.Text.Length == 0)
return true; return true;
var order = (teamChat) ? Order.TeamChat(chatTextField.Text) : Order.Chat(chatTextField.Text); orderManager.IssueOrder(Order.Chat(teamChat, chatTextField.Text));
orderManager.IssueOrder(order);
chatTextField.Text = ""; chatTextField.Text = "";
return true; return true;
}; };