@@ -16,7 +16,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
{
|
||||
public class ConnectionLogic
|
||||
{
|
||||
Action onConnect, onRetry, onAbort;
|
||||
Action onConnect, onAbort;
|
||||
Action<string> onRetry;
|
||||
|
||||
void ConnectionStateChanged(OrderManager om)
|
||||
{
|
||||
@@ -44,11 +45,11 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
}
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public ConnectionLogic(Widget widget, string host, int port, Action onConnect, Action onRetry, Action onAbort)
|
||||
public ConnectionLogic(Widget widget, string host, int port, Action onConnect, Action onAbort, Action<string> onRetry)
|
||||
{
|
||||
this.onConnect = onConnect;
|
||||
this.onRetry = onRetry;
|
||||
this.onAbort = onAbort;
|
||||
this.onRetry = onRetry;
|
||||
|
||||
Game.ConnectionStateChanged += ConnectionStateChanged;
|
||||
|
||||
@@ -59,31 +60,81 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
"Connecting to {0}:{1}...".F(host, port);
|
||||
}
|
||||
|
||||
public static void Connect(string host, int port, Action onConnect, Action onAbort)
|
||||
public static void Connect(string host, int port, string password, Action onConnect, Action onAbort)
|
||||
{
|
||||
Game.JoinServer(host, port);
|
||||
Game.JoinServer(host, port, password);
|
||||
Action<string> onRetry = newPassword => Connect(host, port, newPassword, onConnect, onAbort);
|
||||
|
||||
Ui.OpenWindow("CONNECTING_PANEL", new WidgetArgs()
|
||||
{
|
||||
{ "host", host },
|
||||
{ "port", port },
|
||||
{ "onConnect", onConnect },
|
||||
{ "onAbort", onAbort },
|
||||
{ "onRetry", () => Connect(host, port, onConnect, onAbort) }
|
||||
{ "onRetry", onRetry }
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public class ConnectionFailedLogic
|
||||
{
|
||||
PasswordFieldWidget passwordField;
|
||||
bool passwordOffsetAdjusted;
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public ConnectionFailedLogic(Widget widget, OrderManager orderManager, Action onRetry, Action onAbort)
|
||||
public ConnectionFailedLogic(Widget widget, OrderManager orderManager, Action onAbort, Action<string> onRetry)
|
||||
{
|
||||
var panel = widget;
|
||||
panel.Get<ButtonWidget>("ABORT_BUTTON").OnClick = () => { Ui.CloseWindow(); onAbort(); };
|
||||
panel.Get<ButtonWidget>("RETRY_BUTTON").OnClick = () => { Ui.CloseWindow(); onRetry(); };
|
||||
var abortButton = panel.Get<ButtonWidget>("ABORT_BUTTON");
|
||||
var retryButton = panel.Get<ButtonWidget>("RETRY_BUTTON");
|
||||
|
||||
abortButton.OnClick = () => { Ui.CloseWindow(); onAbort(); };
|
||||
retryButton.OnClick = () =>
|
||||
{
|
||||
var password = passwordField != null && passwordField.IsVisible() ? passwordField.Text : orderManager.Password;
|
||||
|
||||
Ui.CloseWindow();
|
||||
onRetry(password);
|
||||
};
|
||||
|
||||
widget.Get<LabelWidget>("CONNECTING_DESC").GetText = () =>
|
||||
"Could not connect to {0}:{1}\n{2}".F(orderManager.Host, orderManager.Port, orderManager.ServerError);
|
||||
"Could not connect to {0}:{1}".F(orderManager.Host, orderManager.Port);
|
||||
|
||||
var connectionError = widget.Get<LabelWidget>("CONNECTION_ERROR");
|
||||
connectionError.GetText = () => orderManager.ServerError;
|
||||
|
||||
passwordField = panel.GetOrNull<PasswordFieldWidget>("PASSWORD");
|
||||
if (passwordField != null)
|
||||
{
|
||||
passwordField.Text = orderManager.Password;
|
||||
passwordField.IsVisible = () => orderManager.AuthenticationFailed;
|
||||
var passwordLabel = widget.Get<LabelWidget>("PASSWORD_LABEL");
|
||||
passwordLabel.IsVisible = passwordField.IsVisible;
|
||||
}
|
||||
|
||||
passwordOffsetAdjusted = false;
|
||||
var connectionFailedTicker = panel.GetOrNull<LogicTickerWidget>("CONNECTION_FAILED_TICKER");
|
||||
if (connectionFailedTicker != null)
|
||||
{
|
||||
connectionFailedTicker.OnTick = () =>
|
||||
{
|
||||
// Adjust the dialog once the AuthenticationError is parsed.
|
||||
if (passwordField.IsVisible() && !passwordOffsetAdjusted)
|
||||
{
|
||||
var offset = passwordField.Bounds.Y - connectionError.Bounds.Y;
|
||||
abortButton.Bounds.Y += offset;
|
||||
retryButton.Bounds.Y += offset;
|
||||
panel.Bounds.Height += offset;
|
||||
panel.Bounds.Y -= offset / 2;
|
||||
|
||||
var background = panel.GetOrNull("CONNECTION_BACKGROUND");
|
||||
if (background != null)
|
||||
background.Bounds.Height += offset;
|
||||
|
||||
passwordOffsetAdjusted = true;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user