simplify teamchat code
This commit is contained in:
@@ -189,14 +189,10 @@ namespace OpenRA
|
||||
|
||||
// Named constructors for Orders.
|
||||
// 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)
|
||||
|
||||
@@ -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
|
||||
// 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
|
||||
{
|
||||
string content = "";
|
||||
@@ -27,6 +24,7 @@ namespace OpenRA.Widgets
|
||||
public readonly bool UseContrast = false;
|
||||
|
||||
readonly OrderManager orderManager;
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
internal ChatEntryWidget( [ObjectCreator.Param] OrderManager orderManager )
|
||||
{
|
||||
@@ -46,6 +44,7 @@ namespace OpenRA.Widgets
|
||||
}
|
||||
|
||||
public override Rectangle EventBounds { get { return Rectangle.Empty; } }
|
||||
|
||||
public override bool LoseFocus(MouseInput mi)
|
||||
{
|
||||
return composing ? false : base.LoseFocus(mi);
|
||||
@@ -67,9 +66,7 @@ namespace OpenRA.Widgets
|
||||
|
||||
composing = false;
|
||||
if (content != "")
|
||||
orderManager.IssueOrder(teamChat
|
||||
? Order.TeamChat(content)
|
||||
: Order.Chat(content));
|
||||
orderManager.IssueOrder(Order.Chat(teamChat, content));
|
||||
content = "";
|
||||
|
||||
LoseFocus();
|
||||
@@ -79,14 +76,8 @@ namespace OpenRA.Widgets
|
||||
{
|
||||
TakeFocus(new MouseInput());
|
||||
composing = true;
|
||||
if (Game.Settings.Game.TeamChatToggle)
|
||||
{
|
||||
teamChat ^= e.Modifiers.HasModifier(Modifiers.Shift);
|
||||
}
|
||||
else
|
||||
{
|
||||
teamChat = e.Modifiers.HasModifier(Modifiers.Shift);
|
||||
}
|
||||
teamChat = (Game.Settings.Game.TeamChatToggle && teamChat)
|
||||
^ e.Modifiers.HasModifier(Modifiers.Shift);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,13 +198,13 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
||||
bool teamChat = false;
|
||||
var chatLabel = lobby.GetWidget<LabelWidget>("LABEL_CHATTYPE");
|
||||
var chatTextField = lobby.GetWidget<TextFieldWidget>("CHAT_TEXTFIELD");
|
||||
|
||||
chatTextField.OnEnterKey = () =>
|
||||
{
|
||||
if (chatTextField.Text.Length == 0)
|
||||
return true;
|
||||
|
||||
var order = (teamChat) ? Order.TeamChat(chatTextField.Text) : Order.Chat(chatTextField.Text);
|
||||
orderManager.IssueOrder(order);
|
||||
orderManager.IssueOrder(Order.Chat(teamChat, chatTextField.Text));
|
||||
chatTextField.Text = "";
|
||||
return true;
|
||||
};
|
||||
|
||||
@@ -146,8 +146,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
if (chatTextField.Text.Length == 0)
|
||||
return true;
|
||||
|
||||
var order = (teamChat) ? Order.TeamChat(chatTextField.Text) : Order.Chat(chatTextField.Text);
|
||||
orderManager.IssueOrder(order);
|
||||
orderManager.IssueOrder(Order.Chat(teamChat, chatTextField.Text));
|
||||
chatTextField.Text = "";
|
||||
return true;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user