Move OnMouseUp onto ButtonWidget and drop its unnecessary plumbing.
This commit is contained in:
@@ -25,6 +25,9 @@ namespace OpenRA.Widgets
|
||||
public Func<string> GetText;
|
||||
public Func<bool> IsDisabled = () => false;
|
||||
public Action<MouseInput> OnMouseDown = _ => {};
|
||||
public Action<MouseInput> OnMouseUp = _ => {};
|
||||
|
||||
// Equivalent to OnMouseUp, but without an input arg
|
||||
public Action OnClick = () => {};
|
||||
public Action<KeyInput> OnKeyPress = _ => {};
|
||||
|
||||
@@ -32,7 +35,7 @@ namespace OpenRA.Widgets
|
||||
: base()
|
||||
{
|
||||
GetText = () => { return Text; };
|
||||
OnMouseUp = mi => { if (!IsDisabled()) OnClick(); return true; };
|
||||
OnMouseUp = _ => OnClick();
|
||||
OnKeyPress = _ => OnClick();
|
||||
}
|
||||
|
||||
@@ -46,7 +49,7 @@ namespace OpenRA.Widgets
|
||||
GetText = widget.GetText;
|
||||
OnMouseDown = widget.OnMouseDown;
|
||||
|
||||
OnMouseUp = mi => { if (!IsDisabled()) OnClick(); return true; };
|
||||
OnMouseUp = mi => OnClick();
|
||||
OnKeyPress = _ => OnClick();
|
||||
}
|
||||
|
||||
@@ -75,19 +78,19 @@ namespace OpenRA.Widgets
|
||||
if (mi.Event == MouseInputEvent.Down && !TakeFocus(mi))
|
||||
return false;
|
||||
|
||||
var disabled = IsDisabled();
|
||||
// Only fire the onMouseUp event if we successfully lost focus, and were pressed
|
||||
if (Focused && mi.Event == MouseInputEvent.Up)
|
||||
{
|
||||
if (Depressed)
|
||||
if (Depressed && !disabled)
|
||||
OnMouseUp(mi);
|
||||
|
||||
return LoseFocus(mi);
|
||||
}
|
||||
|
||||
if (mi.Event == MouseInputEvent.Down)
|
||||
{
|
||||
// OnMouseDown returns false if the button shouldn't be pressed
|
||||
if (!IsDisabled())
|
||||
if (!disabled)
|
||||
{
|
||||
OnMouseDown(mi);
|
||||
Depressed = true;
|
||||
|
||||
@@ -117,7 +117,6 @@ namespace OpenRA.Widgets
|
||||
public Func<bool> IsVisible;
|
||||
public Widget() { IsVisible = () => Visible; }
|
||||
protected readonly List<Widget> Children = new List<Widget>();
|
||||
public Func<MouseInput,bool> OnMouseUp = _ => false;
|
||||
|
||||
public Widget(Widget widget)
|
||||
{
|
||||
@@ -132,8 +131,6 @@ namespace OpenRA.Widgets
|
||||
Bounds = widget.Bounds;
|
||||
Parent = widget.Parent;
|
||||
|
||||
OnMouseUp = widget.OnMouseUp;
|
||||
|
||||
IsVisible = widget.IsVisible;
|
||||
|
||||
foreach (var child in widget.Children)
|
||||
@@ -269,16 +266,7 @@ namespace OpenRA.Widgets
|
||||
return HandleMouseInput(mi);
|
||||
}
|
||||
|
||||
// Hack: Don't eat mouse input that others want
|
||||
// TODO: Solve this properly
|
||||
public virtual bool HandleMouseInput(MouseInput mi)
|
||||
{
|
||||
// Apply any special logic added by event handlers; they return true if they caught the input
|
||||
if (mi.Event == MouseInputEvent.Up && OnMouseUp(mi)) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public virtual bool HandleMouseInput(MouseInput mi) { return false; }
|
||||
public virtual bool HandleKeyPressInner(KeyInput e) { return false; }
|
||||
public virtual bool HandleKeyPressOuter(KeyInput e)
|
||||
{
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.Traits;
|
||||
@@ -45,28 +46,17 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
||||
|
||||
void SetupProductionGroupButton(ButtonWidget button, string group)
|
||||
{
|
||||
Action<bool> selectTab = reverse =>
|
||||
{
|
||||
if (queueTabs.QueueGroup == group)
|
||||
queueTabs.SelectNextTab(reverse);
|
||||
else
|
||||
queueTabs.QueueGroup = group;
|
||||
};
|
||||
|
||||
button.IsDisabled = () => queueTabs.Groups[group].Tabs.Count == 0;
|
||||
|
||||
button.OnMouseUp = mi =>
|
||||
{
|
||||
if (button.IsDisabled())
|
||||
return true;
|
||||
|
||||
if (queueTabs.QueueGroup == group)
|
||||
queueTabs.SelectNextTab(mi.Modifiers.HasModifier(Modifiers.Shift));
|
||||
else
|
||||
queueTabs.QueueGroup = group;
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
button.OnKeyPress = e =>
|
||||
{
|
||||
if (queueTabs.QueueGroup == group)
|
||||
queueTabs.SelectNextTab(e.Modifiers.HasModifier(Modifiers.Shift));
|
||||
else
|
||||
queueTabs.QueueGroup = group;
|
||||
};
|
||||
button.OnMouseUp = mi => selectTab(mi.Modifiers.HasModifier(Modifiers.Shift));
|
||||
button.OnKeyPress = e => selectTab(e.Modifiers.HasModifier(Modifiers.Shift));
|
||||
}
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
|
||||
@@ -21,13 +21,12 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
[ObjectCreator.Param] string host,
|
||||
[ObjectCreator.Param] int port )
|
||||
{
|
||||
widget.GetWidget("CONNECTION_BUTTON_ABORT").OnMouseUp = mi => {
|
||||
widget.GetWidget<ButtonWidget>("CONNECTION_BUTTON_ABORT").OnMouseUp = mi => {
|
||||
widget.GetWidget("CONNECTION_BUTTON_ABORT").Parent.Visible = false;
|
||||
Game.Disconnect();
|
||||
Game.LoadShellMap();
|
||||
Widget.CloseWindow();
|
||||
Widget.OpenWindow("MAINMENU_BG");
|
||||
return true;
|
||||
};
|
||||
|
||||
widget.GetWidget<LabelWidget>("CONNECTING_DESC").GetText = () =>
|
||||
@@ -42,18 +41,15 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
[ObjectCreator.Param] Widget widget,
|
||||
[ObjectCreator.Param] OrderManager orderManager)
|
||||
{
|
||||
widget.GetWidget("CONNECTION_BUTTON_CANCEL").OnMouseUp = mi => {
|
||||
widget.GetWidget<ButtonWidget>("CONNECTION_BUTTON_CANCEL").OnMouseUp = mi => {
|
||||
widget.GetWidget("CONNECTION_BUTTON_CANCEL").Parent.Visible = false;
|
||||
Game.Disconnect();
|
||||
Game.LoadShellMap();
|
||||
Widget.CloseWindow();
|
||||
Widget.OpenWindow("MAINMENU_BG");
|
||||
return true;
|
||||
};
|
||||
widget.GetWidget("CONNECTION_BUTTON_RETRY").OnMouseUp = mi => {
|
||||
widget.GetWidget<ButtonWidget>("CONNECTION_BUTTON_RETRY").OnMouseUp = mi =>
|
||||
Game.JoinServer(orderManager.Host, orderManager.Port);
|
||||
return true;
|
||||
};
|
||||
|
||||
widget.GetWidget<LabelWidget>("CONNECTION_FAILED_DESC").GetText = () => string.IsNullOrEmpty(orderManager.ServerError) ?
|
||||
"Could not connect to {0}:{1}".F(orderManager.Host, orderManager.Port) : orderManager.ServerError;
|
||||
|
||||
@@ -22,12 +22,9 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
{
|
||||
var settings = Game.Settings;
|
||||
|
||||
cs.GetWidget("BUTTON_CANCEL").OnMouseUp = mi => {
|
||||
Widget.CloseWindow();
|
||||
return true;
|
||||
};
|
||||
|
||||
cs.GetWidget("BUTTON_START").OnMouseUp = mi => {
|
||||
cs.GetWidget<ButtonWidget>("BUTTON_CANCEL").OnMouseUp = mi => Widget.CloseWindow();
|
||||
cs.GetWidget<ButtonWidget>("BUTTON_START").OnMouseUp = mi =>
|
||||
{
|
||||
settings.Server.Name = cs.GetWidget<TextFieldWidget>("GAME_TITLE").Text;
|
||||
settings.Server.ListenPort = int.Parse(cs.GetWidget<TextFieldWidget>("LISTEN_PORT").Text);
|
||||
settings.Server.ExternalPort = int.Parse(cs.GetWidget<TextFieldWidget>("EXTERNAL_PORT").Text);
|
||||
@@ -37,7 +34,6 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
// Take a copy so that subsequent settings changes don't affect the server
|
||||
Game.CreateServer(new ServerSettings(Game.Settings.Server));
|
||||
Game.JoinServer(IPAddress.Loopback.ToString(), settings.Server.ListenPort);
|
||||
return true;
|
||||
};
|
||||
|
||||
cs.GetWidget<TextFieldWidget>("GAME_TITLE").Text = settings.Server.Name ?? "";
|
||||
|
||||
@@ -32,12 +32,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
{
|
||||
var devmodeBG = Widget.RootWidget.GetWidget("INGAME_ROOT").GetWidget("DEVELOPERMODE_BG");
|
||||
var devModeButton = Widget.RootWidget.GetWidget<ButtonWidget>("INGAME_DEVELOPERMODE_BUTTON");
|
||||
devModeButton.OnMouseUp = mi => devmodeBG.Visible ^= true;
|
||||
|
||||
devModeButton.OnMouseUp = mi =>
|
||||
{
|
||||
devmodeBG.Visible ^= true;
|
||||
return true;
|
||||
};
|
||||
|
||||
var devTrait = world.LocalPlayer.PlayerActor.Trait<DeveloperMode>();
|
||||
|
||||
|
||||
@@ -30,14 +30,13 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
this.world = world;
|
||||
var root = Widget.RootWidget.GetWidget("INGAME_ROOT");
|
||||
var diplomacyBG = root.GetWidget("DIPLOMACY_BG");
|
||||
var diplomacy = root.GetWidget("INGAME_DIPLOMACY_BUTTON");
|
||||
var diplomacy = root.GetWidget<ButtonWidget>("INGAME_DIPLOMACY_BUTTON");
|
||||
|
||||
diplomacy.OnMouseUp = mi =>
|
||||
{
|
||||
diplomacyBG.Visible = !diplomacyBG.Visible;
|
||||
if (diplomacyBG.IsVisible())
|
||||
LayoutDialog(diplomacyBG);
|
||||
return true;
|
||||
};
|
||||
|
||||
validPlayers = world.Players.Where(a => a != world.LocalPlayer && !a.NonCombatant).Count();
|
||||
|
||||
@@ -82,20 +82,19 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
void ShowInstallMethodDialog()
|
||||
{
|
||||
var window = Widget.OpenWindow("INIT_CHOOSEINSTALL");
|
||||
window.GetWidget("DOWNLOAD").OnMouseUp = mi => { ShowDownloadDialog(); return true; };
|
||||
window.GetWidget("FROMCD").OnMouseUp = mi => PromptForCD();
|
||||
window.GetWidget<ButtonWidget>("DOWNLOAD").OnMouseUp = mi => ShowDownloadDialog();
|
||||
window.GetWidget<ButtonWidget>("FROMCD").OnMouseUp = mi => PromptForCD();
|
||||
|
||||
window.GetWidget("QUIT").OnMouseUp = mi => { Game.Exit(); return true; };
|
||||
window.GetWidget<ButtonWidget>("QUIT").OnMouseUp = mi => Game.Exit();
|
||||
}
|
||||
|
||||
bool PromptForCD()
|
||||
void PromptForCD()
|
||||
{
|
||||
Game.Utilities.PromptFilepathAsync("Select MAIN.MIX on the CD", path =>
|
||||
{
|
||||
if (!string.IsNullOrEmpty(path))
|
||||
Game.RunAfterTick(() => InstallFromCD(Path.GetDirectoryName(path)));
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
void InstallFromCD(string path)
|
||||
@@ -106,8 +105,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
|
||||
// TODO: Handle cancelling copy
|
||||
window.GetWidget<ButtonWidget>("CANCEL").IsVisible = () => false;
|
||||
window.GetWidget("CANCEL").OnMouseUp = mi => { ShowInstallMethodDialog(); return true; };
|
||||
window.GetWidget("RETRY").OnMouseUp = mi => PromptForCD();
|
||||
window.GetWidget<ButtonWidget>("CANCEL").OnMouseUp = mi => ShowInstallMethodDialog();
|
||||
window.GetWidget<ButtonWidget>("RETRY").OnMouseUp = mi => PromptForCD();
|
||||
|
||||
var t = new Thread( _ =>
|
||||
{
|
||||
@@ -160,8 +159,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
};
|
||||
|
||||
var dl = new Download(Info.PackageURL, file, onDownloadChange, onDownloadComplete);
|
||||
window.GetWidget("CANCEL").OnMouseUp = mi => { dl.Cancel(); ShowInstallMethodDialog(); return true; };
|
||||
window.GetWidget("RETRY").OnMouseUp = mi => { dl.Cancel(); ShowDownloadDialog(); return true; };
|
||||
window.GetWidget<ButtonWidget>("CANCEL").OnMouseUp = mi => { dl.Cancel(); ShowInstallMethodDialog(); };
|
||||
window.GetWidget<ButtonWidget>("RETRY").OnMouseUp = mi => { dl.Cancel(); ShowDownloadDialog(); };
|
||||
}
|
||||
|
||||
void ShowError(Widget window, string e)
|
||||
|
||||
@@ -28,48 +28,26 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
gameRoot = r.GetWidget("INGAME_ROOT");
|
||||
var optionsBG = gameRoot.GetWidget("INGAME_OPTIONS_BG");
|
||||
|
||||
r.GetWidget("INGAME_OPTIONS_BUTTON").OnMouseUp = mi => {
|
||||
r.GetWidget<ButtonWidget>("INGAME_OPTIONS_BUTTON").OnMouseUp = mi =>
|
||||
optionsBG.Visible = !optionsBG.Visible;
|
||||
return true;
|
||||
};
|
||||
|
||||
optionsBG.GetWidget("DISCONNECT").OnMouseUp = mi => {
|
||||
optionsBG.GetWidget<ButtonWidget>("DISCONNECT").OnMouseUp = mi =>
|
||||
{
|
||||
optionsBG.Visible = false;
|
||||
Game.Disconnect();
|
||||
Game.LoadShellMap();
|
||||
Widget.CloseWindow();
|
||||
Widget.OpenWindow("MAINMENU_BG");
|
||||
return true;
|
||||
};
|
||||
|
||||
optionsBG.GetWidget("SETTINGS").OnMouseUp = mi => {
|
||||
Widget.OpenWindow("SETTINGS_MENU");
|
||||
return true;
|
||||
};
|
||||
optionsBG.GetWidget<ButtonWidget>("SETTINGS").OnMouseUp = mi => Widget.OpenWindow("SETTINGS_MENU");
|
||||
optionsBG.GetWidget<ButtonWidget>("MUSIC").OnMouseUp = mi => Widget.OpenWindow("MUSIC_MENU");
|
||||
optionsBG.GetWidget<ButtonWidget>("RESUME").OnMouseUp = mi => optionsBG.Visible = false;
|
||||
|
||||
optionsBG.GetWidget("MUSIC").OnMouseUp = mi => {
|
||||
Widget.OpenWindow("MUSIC_MENU");
|
||||
return true;
|
||||
};
|
||||
|
||||
optionsBG.GetWidget("RESUME").OnMouseUp = mi =>
|
||||
{
|
||||
optionsBG.Visible = false;
|
||||
return true;
|
||||
};
|
||||
|
||||
optionsBG.GetWidget("SURRENDER").OnMouseUp = mi =>
|
||||
{
|
||||
optionsBG.GetWidget<ButtonWidget>("SURRENDER").OnMouseUp = mi =>
|
||||
world.IssueOrder(new Order("Surrender", world.LocalPlayer.PlayerActor, false));
|
||||
return true;
|
||||
};
|
||||
|
||||
optionsBG.GetWidget("SURRENDER").IsVisible = () => (world.LocalPlayer != null && world.LocalPlayer.WinState == WinState.Undefined);
|
||||
|
||||
optionsBG.GetWidget("QUIT").OnMouseUp = mi => {
|
||||
Game.Exit();
|
||||
return true;
|
||||
};
|
||||
optionsBG.GetWidget<ButtonWidget>("QUIT").OnMouseUp = mi => Game.Exit();
|
||||
|
||||
var postgameBG = gameRoot.GetWidget("POSTGAME_BG");
|
||||
var postgameText = postgameBG.GetWidget<LabelWidget>("TEXT");
|
||||
|
||||
@@ -18,6 +18,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
{
|
||||
Widget gameRoot;
|
||||
|
||||
// WTF duplication
|
||||
[ObjectCreator.UseCtor]
|
||||
public IngameObserverChromeLogic([ObjectCreator.Param] World world)
|
||||
{
|
||||
@@ -28,42 +29,23 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
gameRoot = r.GetWidget("OBSERVER_ROOT");
|
||||
var optionsBG = gameRoot.GetWidget("INGAME_OPTIONS_BG");
|
||||
|
||||
r.GetWidget("INGAME_OPTIONS_BUTTON").OnMouseUp = mi => {
|
||||
r.GetWidget<ButtonWidget>("INGAME_OPTIONS_BUTTON").OnMouseUp = mi =>
|
||||
optionsBG.Visible = !optionsBG.Visible;
|
||||
return true;
|
||||
};
|
||||
|
||||
optionsBG.GetWidget("DISCONNECT").OnMouseUp = mi => {
|
||||
optionsBG.GetWidget<ButtonWidget>("DISCONNECT").OnMouseUp = mi =>
|
||||
{
|
||||
optionsBG.Visible = false;
|
||||
Game.Disconnect();
|
||||
Game.LoadShellMap();
|
||||
Widget.CloseWindow();
|
||||
Widget.OpenWindow("MAINMENU_BG");
|
||||
return true;
|
||||
};
|
||||
|
||||
optionsBG.GetWidget("SETTINGS").OnMouseUp = mi => {
|
||||
Widget.OpenWindow("SETTINGS_MENU");
|
||||
return true;
|
||||
};
|
||||
|
||||
optionsBG.GetWidget("MUSIC").OnMouseUp = mi => {
|
||||
Widget.OpenWindow("MUSIC_MENU");
|
||||
return true;
|
||||
};
|
||||
|
||||
optionsBG.GetWidget("RESUME").OnMouseUp = mi =>
|
||||
{
|
||||
optionsBG.Visible = false;
|
||||
return true;
|
||||
};
|
||||
|
||||
optionsBG.GetWidget("SURRENDER").IsVisible = () => false;
|
||||
|
||||
optionsBG.GetWidget("QUIT").OnMouseUp = mi => {
|
||||
Game.Exit();
|
||||
return true;
|
||||
};
|
||||
optionsBG.GetWidget<ButtonWidget>("SETTINGS").OnMouseUp = mi => Widget.OpenWindow("SETTINGS_MENU");
|
||||
optionsBG.GetWidget<ButtonWidget>("MUSIC").OnMouseUp = mi => Widget.OpenWindow("MUSIC_MENU");
|
||||
optionsBG.GetWidget<ButtonWidget>("RESUME").OnMouseUp = mi => optionsBG.Visible = false;
|
||||
optionsBG.GetWidget<ButtonWidget>("SURRENDER").IsVisible = () => false;
|
||||
optionsBG.GetWidget<ButtonWidget>("QUIT").OnMouseUp = mi => Game.Exit();
|
||||
}
|
||||
|
||||
public void UnregisterEvents()
|
||||
|
||||
@@ -97,7 +97,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
.ToDictionary(a => a.Race, a => a.Name);
|
||||
CountryNames.Add("random", "Random");
|
||||
|
||||
var mapButton = lobby.GetWidget("CHANGEMAP_BUTTON");
|
||||
var mapButton = lobby.GetWidget<ButtonWidget>("CHANGEMAP_BUTTON");
|
||||
mapButton.OnMouseUp = mi =>
|
||||
{
|
||||
Widget.OpenWindow("MAP_CHOOSER", new WidgetArgs()
|
||||
@@ -105,19 +105,17 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
{ "orderManager", orderManager },
|
||||
{ "mapName", MapUid }
|
||||
});
|
||||
return true;
|
||||
};
|
||||
|
||||
mapButton.IsVisible = () => mapButton.Visible && Game.IsHost;
|
||||
|
||||
var disconnectButton = lobby.GetWidget("DISCONNECT_BUTTON");
|
||||
var disconnectButton = lobby.GetWidget<ButtonWidget>("DISCONNECT_BUTTON");
|
||||
disconnectButton.OnMouseUp = mi =>
|
||||
{
|
||||
CloseWindow();
|
||||
Game.Disconnect();
|
||||
Game.LoadShellMap();
|
||||
Widget.OpenWindow("MAINMENU_BG");
|
||||
return true;
|
||||
};
|
||||
|
||||
var lockTeamsCheckbox = lobby.GetWidget<CheckboxWidget>("LOCKTEAMS_CHECKBOX");
|
||||
@@ -349,7 +347,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
var join = template.GetWidget<ButtonWidget>("JOIN");
|
||||
if (join != null)
|
||||
{
|
||||
join.OnMouseUp = _ => { orderManager.IssueOrder(Order.Command("slot " + s.PlayerReference)); return true; };
|
||||
join.OnMouseUp = _ => orderManager.IssueOrder(Order.Command("slot " + s.PlayerReference));
|
||||
join.IsVisible = () => !s.Closed && c == null && orderManager.LocalClient.State != Session.ClientState.Ready;
|
||||
}
|
||||
|
||||
@@ -427,11 +425,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
|
||||
var kickButton = template.GetWidget<ButtonWidget>("KICK");
|
||||
kickButton.IsVisible = () => Game.IsHost && c.Index != orderManager.LocalClient.Index;
|
||||
kickButton.OnMouseUp = mi =>
|
||||
{
|
||||
orderManager.IssueOrder(Order.Command("kick " + c.Slot));
|
||||
return true;
|
||||
};
|
||||
kickButton.OnMouseUp = mi => orderManager.IssueOrder(Order.Command("kick " + c.Slot));
|
||||
}
|
||||
|
||||
template.IsVisible = () => true;
|
||||
@@ -490,11 +484,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
|
||||
var kickButton = template.GetWidget<ButtonWidget>("KICK");
|
||||
kickButton.IsVisible = () => Game.IsHost && client.Index != orderManager.LocalClient.Index;
|
||||
kickButton.OnMouseUp = mi =>
|
||||
{
|
||||
orderManager.IssueOrder(Order.Command("kick " + client.Index));
|
||||
return true;
|
||||
};
|
||||
kickButton.OnMouseUp = mi => orderManager.IssueOrder(Order.Command("kick " + client.Index));
|
||||
}
|
||||
|
||||
template.IsVisible = () => true;
|
||||
@@ -506,7 +496,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
{
|
||||
var spec = NewSpectatorTemplate.Clone();
|
||||
var btn = spec.GetWidget<ButtonWidget>("SPECTATE");
|
||||
btn.OnMouseUp = _ => { orderManager.IssueOrder(Order.Command("spectate")); return true; };
|
||||
btn.OnMouseUp = _ => orderManager.IssueOrder(Order.Command("spectate"));;
|
||||
spec.IsVisible = () => true;
|
||||
Players.AddChild(spec);
|
||||
}
|
||||
|
||||
@@ -25,12 +25,12 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
public MainMenuButtonsLogic([ObjectCreator.Param] Widget widget)
|
||||
{
|
||||
Game.modData.WidgetLoader.LoadWidget( new WidgetArgs(), Widget.RootWidget, "PERF_BG" );
|
||||
widget.GetWidget("MAINMENU_BUTTON_JOIN").OnMouseUp = mi => { Widget.OpenWindow("JOINSERVER_BG"); return true; };
|
||||
widget.GetWidget("MAINMENU_BUTTON_CREATE").OnMouseUp = mi => { Widget.OpenWindow("CREATESERVER_BG"); return true; };
|
||||
widget.GetWidget("MAINMENU_BUTTON_SETTINGS").OnMouseUp = mi => { Widget.OpenWindow("SETTINGS_MENU"); return true; };
|
||||
widget.GetWidget("MAINMENU_BUTTON_MUSIC").OnMouseUp = mi => { Widget.OpenWindow("MUSIC_MENU"); return true; };
|
||||
widget.GetWidget("MAINMENU_BUTTON_REPLAY_VIEWER").OnMouseUp = mi => { Widget.OpenWindow("REPLAYBROWSER_BG"); return true; };
|
||||
widget.GetWidget("MAINMENU_BUTTON_QUIT").OnMouseUp = mi => { Game.Exit(); return true; };
|
||||
widget.GetWidget<ButtonWidget>("MAINMENU_BUTTON_JOIN").OnMouseUp = mi => Widget.OpenWindow("JOINSERVER_BG");
|
||||
widget.GetWidget<ButtonWidget>("MAINMENU_BUTTON_CREATE").OnMouseUp = mi => Widget.OpenWindow("CREATESERVER_BG");
|
||||
widget.GetWidget<ButtonWidget>("MAINMENU_BUTTON_SETTINGS").OnMouseUp = mi => Widget.OpenWindow("SETTINGS_MENU");
|
||||
widget.GetWidget<ButtonWidget>("MAINMENU_BUTTON_MUSIC").OnMouseUp = mi => Widget.OpenWindow("MUSIC_MENU");
|
||||
widget.GetWidget<ButtonWidget>("MAINMENU_BUTTON_REPLAY_VIEWER").OnMouseUp = mi => Widget.OpenWindow("REPLAYBROWSER_BG");
|
||||
widget.GetWidget<ButtonWidget>("MAINMENU_BUTTON_QUIT").OnMouseUp = mi => Game.Exit();
|
||||
|
||||
DisplayModSelector();
|
||||
}
|
||||
|
||||
@@ -47,14 +47,9 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
{
|
||||
orderManager.IssueOrder(Order.Command("map " + Map.Uid));
|
||||
Widget.CloseWindow();
|
||||
return true;
|
||||
};
|
||||
|
||||
bg.GetWidget<ButtonWidget>("BUTTON_CANCEL").OnMouseUp = mi =>
|
||||
{
|
||||
Widget.CloseWindow();
|
||||
return true;
|
||||
};
|
||||
bg.GetWidget<ButtonWidget>("BUTTON_CANCEL").OnMouseUp = mi => Widget.CloseWindow();
|
||||
|
||||
scrollpanel = bg.GetWidget<ScrollPanelWidget>("MAP_LIST");
|
||||
itemTemplate = scrollpanel.GetWidget<ScrollItemWidget>("MAP_TEMPLATE");
|
||||
|
||||
@@ -24,10 +24,9 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
var bg = Widget.RootWidget.GetWidget("MUSIC_MENU");
|
||||
CurrentSong = GetNextSong();
|
||||
|
||||
bg.GetWidget("BUTTON_CLOSE").OnMouseUp = mi => {
|
||||
bg.GetWidget<ButtonWidget>("BUTTON_CLOSE").OnMouseUp = mi => {
|
||||
Game.Settings.Save();
|
||||
Widget.CloseWindow();
|
||||
return true;
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -40,46 +39,42 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
*/
|
||||
bg.GetWidget("BUTTON_INSTALL").IsVisible = () => false;
|
||||
|
||||
bg.GetWidget("BUTTON_PLAY").OnMouseUp = mi =>
|
||||
bg.GetWidget<ButtonWidget>("BUTTON_PLAY").OnMouseUp = mi =>
|
||||
{
|
||||
if (CurrentSong == null)
|
||||
return true;
|
||||
return;
|
||||
|
||||
Sound.PlayMusicThen(Rules.Music[CurrentSong],
|
||||
() => bg.GetWidget(Game.Settings.Sound.Repeat ? "BUTTON_PLAY" : "BUTTON_NEXT").OnMouseUp(new MouseInput()));
|
||||
() => bg.GetWidget<ButtonWidget>(Game.Settings.Sound.Repeat ? "BUTTON_PLAY" : "BUTTON_NEXT")
|
||||
.OnMouseUp(new MouseInput()));
|
||||
bg.GetWidget("BUTTON_PLAY").Visible = false;
|
||||
bg.GetWidget("BUTTON_PAUSE").Visible = true;
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
bg.GetWidget("BUTTON_PAUSE").OnMouseUp = mi =>
|
||||
bg.GetWidget<ButtonWidget>("BUTTON_PAUSE").OnMouseUp = mi =>
|
||||
{
|
||||
Sound.PauseMusic();
|
||||
bg.GetWidget("BUTTON_PAUSE").Visible = false;
|
||||
bg.GetWidget("BUTTON_PLAY").Visible = true;
|
||||
return true;
|
||||
};
|
||||
|
||||
bg.GetWidget("BUTTON_STOP").OnMouseUp = mi =>
|
||||
bg.GetWidget<ButtonWidget>("BUTTON_STOP").OnMouseUp = mi =>
|
||||
{
|
||||
Sound.StopMusic();
|
||||
bg.GetWidget("BUTTON_PAUSE").Visible = false;
|
||||
bg.GetWidget("BUTTON_PLAY").Visible = true;
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
bg.GetWidget("BUTTON_NEXT").OnMouseUp = mi =>
|
||||
bg.GetWidget<ButtonWidget>("BUTTON_NEXT").OnMouseUp = mi =>
|
||||
{
|
||||
CurrentSong = GetNextSong();
|
||||
return bg.GetWidget("BUTTON_PLAY").OnMouseUp(mi);
|
||||
bg.GetWidget<ButtonWidget>("BUTTON_PLAY").OnMouseUp(mi);
|
||||
};
|
||||
|
||||
bg.GetWidget("BUTTON_PREV").OnMouseUp = mi =>
|
||||
bg.GetWidget<ButtonWidget>("BUTTON_PREV").OnMouseUp = mi =>
|
||||
{
|
||||
CurrentSong = GetPrevSong();
|
||||
return bg.GetWidget("BUTTON_PLAY").OnMouseUp(mi);
|
||||
bg.GetWidget<ButtonWidget>("BUTTON_PLAY").OnMouseUp(mi);
|
||||
};
|
||||
|
||||
|
||||
@@ -115,7 +110,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
if (CurrentSong == null)
|
||||
CurrentSong = song;
|
||||
|
||||
var item = ScrollItemWidget.Setup(itemTemplate, () => CurrentSong == song, () => { CurrentSong = song; bg.GetWidget("BUTTON_PLAY").OnMouseUp(new MouseInput()); });
|
||||
var item = ScrollItemWidget.Setup(itemTemplate, () => CurrentSong == song, () => { CurrentSong = song; bg.GetWidget<ButtonWidget>("BUTTON_PLAY").OnMouseUp(new MouseInput()); });
|
||||
item.GetWidget<LabelWidget>("TITLE").GetText = () => Rules.Music[song].Title;
|
||||
item.GetWidget<LabelWidget>("LENGTH").GetText = () => "{0:D1}:{1:D2}".F(Rules.Music[song].Length / 60, Rules.Music[song].Length % 60);
|
||||
ml.AddChild(item);
|
||||
|
||||
@@ -27,11 +27,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
{
|
||||
this.widget = widget;
|
||||
|
||||
widget.GetWidget("CANCEL_BUTTON").OnMouseUp = mi =>
|
||||
{
|
||||
Widget.CloseWindow();
|
||||
return true;
|
||||
};
|
||||
widget.GetWidget<ButtonWidget>("CANCEL_BUTTON").OnMouseUp = mi => Widget.CloseWindow();
|
||||
|
||||
/* find some replays? */
|
||||
var rl = widget.GetWidget<ScrollPanelWidget>("REPLAY_LIST");
|
||||
@@ -45,15 +41,14 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
foreach (var replayFile in Directory.GetFiles(replayDir, "*.rep").Reverse())
|
||||
AddReplay(rl, replayFile, template);
|
||||
|
||||
widget.GetWidget("WATCH_BUTTON").OnMouseUp = mi =>
|
||||
widget.GetWidget<ButtonWidget>("WATCH_BUTTON").OnMouseUp = mi =>
|
||||
{
|
||||
if (currentReplay != null)
|
||||
{
|
||||
if (currentReplay != null)
|
||||
{
|
||||
Widget.CloseWindow();
|
||||
Game.JoinReplay(CurrentReplay);
|
||||
}
|
||||
return true;
|
||||
};
|
||||
Widget.CloseWindow();
|
||||
Game.JoinReplay(CurrentReplay);
|
||||
}
|
||||
};
|
||||
|
||||
widget.GetWidget("REPLAY_INFO").IsVisible = () => currentReplay != null;
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
var sl = bg.GetWidget<ScrollPanelWidget>("SERVER_LIST");
|
||||
ServerTemplate = sl.GetWidget<ScrollItemWidget>("SERVER_TEMPLATE");
|
||||
|
||||
bg.GetWidget("REFRESH_BUTTON").OnMouseUp = mi =>
|
||||
bg.GetWidget<ButtonWidget>("REFRESH_BUTTON").OnMouseUp = mi =>
|
||||
{
|
||||
bg.GetWidget("JOINSERVER_PROGRESS_TITLE").Visible = true;
|
||||
bg.GetWidget<LabelWidget>("JOINSERVER_PROGRESS_TITLE").Text = "Fetching game list...";
|
||||
@@ -61,30 +61,22 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
currentServer = null;
|
||||
|
||||
ServerList.Query(RefreshServerList);
|
||||
return true;
|
||||
};
|
||||
|
||||
bg.GetWidget("CANCEL_BUTTON").OnMouseUp = mi =>
|
||||
{
|
||||
Widget.CloseWindow();
|
||||
return true;
|
||||
};
|
||||
|
||||
bg.GetWidget("DIRECTCONNECT_BUTTON").OnMouseUp = mi =>
|
||||
bg.GetWidget<ButtonWidget>("CANCEL_BUTTON").OnMouseUp = mi => Widget.CloseWindow();
|
||||
bg.GetWidget<ButtonWidget>("DIRECTCONNECT_BUTTON").OnMouseUp = mi =>
|
||||
{
|
||||
Widget.CloseWindow();
|
||||
Widget.OpenWindow("DIRECTCONNECT_BG");
|
||||
return true;
|
||||
};
|
||||
|
||||
bg.GetWidget("JOIN_BUTTON").OnMouseUp = mi =>
|
||||
bg.GetWidget<ButtonWidget>("JOIN_BUTTON").OnMouseUp = mi =>
|
||||
{
|
||||
if (currentServer == null)
|
||||
return false;
|
||||
return;
|
||||
|
||||
Widget.CloseWindow();
|
||||
Game.JoinServer(currentServer.Address.Split(':')[0], int.Parse(currentServer.Address.Split(':')[1]));
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -171,12 +163,12 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
|
||||
dc.GetWidget<TextFieldWidget>("SERVER_ADDRESS").Text = Game.Settings.Player.LastServer;
|
||||
|
||||
dc.GetWidget("JOIN_BUTTON").OnMouseUp = mi =>
|
||||
dc.GetWidget<ButtonWidget>("JOIN_BUTTON").OnMouseUp = mi =>
|
||||
{
|
||||
var address = dc.GetWidget<TextFieldWidget>("SERVER_ADDRESS").Text;
|
||||
var cpts = address.Split(':').ToArray();
|
||||
if (cpts.Length < 1 || cpts.Length > 2)
|
||||
return true;
|
||||
return;
|
||||
|
||||
int port;
|
||||
if (cpts.Length != 2 || !int.TryParse(cpts[1], out port))
|
||||
@@ -187,14 +179,12 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
|
||||
Widget.CloseWindow();
|
||||
Game.JoinServer(cpts[0], port);
|
||||
return true;
|
||||
};
|
||||
|
||||
dc.GetWidget("CANCEL_BUTTON").OnMouseUp = mi =>
|
||||
dc.GetWidget<ButtonWidget>("CANCEL_BUTTON").OnMouseUp = mi =>
|
||||
{
|
||||
Widget.CloseWindow();
|
||||
Widget.OpenWindow("MAINMENU_BG");
|
||||
return true;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user