diff --git a/OpenRA.Game/Widgets/ButtonWidget.cs b/OpenRA.Game/Widgets/ButtonWidget.cs index 53157dcae7..b7d5630ba4 100644 --- a/OpenRA.Game/Widgets/ButtonWidget.cs +++ b/OpenRA.Game/Widgets/ButtonWidget.cs @@ -24,8 +24,7 @@ namespace OpenRA.Widgets public string Font = ChromeMetrics.Get("ButtonFont"); public Func GetText; public Func IsDisabled = () => false; - public Func OnMouseDown = mi => false; - + public Action OnMouseDown = _ => {}; public Action OnClick = () => {}; public Action OnKeyPress = _ => {}; @@ -88,8 +87,11 @@ namespace OpenRA.Widgets if (mi.Event == MouseInputEvent.Down) { // OnMouseDown returns false if the button shouldn't be pressed - if (!OnMouseDown(mi)) + if (!IsDisabled()) + { + OnMouseDown(mi); Depressed = true; + } else LoseFocus(mi); } diff --git a/OpenRA.Mods.Cnc/Widgets/Logic/CncLobbyLogic.cs b/OpenRA.Mods.Cnc/Widgets/Logic/CncLobbyLogic.cs index edddac3f9e..3c146056c8 100644 --- a/OpenRA.Mods.Cnc/Widgets/Logic/CncLobbyLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/Logic/CncLobbyLogic.cs @@ -295,7 +295,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic } } - bool ShowSlotDropDown(DropDownButtonWidget dropdown, Session.Slot slot, Session.Client client) + void ShowSlotDropDown(DropDownButtonWidget dropdown, Session.Slot slot, Session.Client client) { var options = new List() { @@ -322,10 +322,9 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic }; dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 150, options, setupItem); - return true; } - bool ShowRaceDropDown(DropDownButtonWidget dropdown, Session.Client client) + void ShowRaceDropDown(DropDownButtonWidget dropdown, Session.Client client) { Func setupItem = (race, itemTemplate) => { @@ -340,10 +339,9 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic }; dropdown.ShowDropDown("RACE_DROPDOWN_TEMPLATE", 150, CountryNames.Keys.ToList(), setupItem); - return true; } - bool ShowTeamDropDown(DropDownButtonWidget dropdown, Session.Client client) + void ShowTeamDropDown(DropDownButtonWidget dropdown, Session.Client client) { Func setupItem = (ii, itemTemplate) => { @@ -356,10 +354,9 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic var options = Graphics.Util.MakeArray(Map.SpawnPoints.Count()+1, i => i).ToList(); dropdown.ShowDropDown("TEAM_DROPDOWN_TEMPLATE", 150, options, setupItem); - return true; } - bool ShowSpawnDropDown(DropDownButtonWidget dropdown, Session.Client client) + void ShowSpawnDropDown(DropDownButtonWidget dropdown, Session.Client client) { Func setupItem = (ii, itemTemplate) => { @@ -376,10 +373,9 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic var options = Graphics.Util.MakeArray(Map.SpawnPoints.Count() + 1, i => i).Except(taken).ToList(); dropdown.ShowDropDown("TEAM_DROPDOWN_TEMPLATE", 150, options, setupItem); - return true; } - bool ShowColorDropDown(DropDownButtonWidget color, Session.Client client) + void ShowColorDropDown(DropDownButtonWidget color, Session.Client client) { Action onSelect = c => { @@ -402,7 +398,6 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic }); color.AttachPanel(colorChooser); - return true; } void UpdatePlayerList() @@ -460,7 +455,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic name.IsVisible = () => true; name.IsDisabled = () => ready; name.GetText = () => client.Name; - name.OnMouseDown = _ => name.IsDisabled() ? true : ShowSlotDropDown(name, slot, client); + name.OnMouseDown = _ => ShowSlotDropDown(name, slot, client); } else { @@ -488,14 +483,14 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic var color = template.GetWidget("COLOR"); color.IsDisabled = () => slot.LockColor || ready; - color.OnMouseDown = _ => color.IsDisabled() ? true : ShowColorDropDown(color, client); + color.OnMouseDown = _ => ShowColorDropDown(color, client); var colorBlock = color.GetWidget("COLORBLOCK"); colorBlock.GetColor = () => client.ColorRamp.GetColor(0); var faction = template.GetWidget("FACTION"); faction.IsDisabled = () => slot.LockRace || ready; - faction.OnMouseDown = _ => faction.IsDisabled() ? true : ShowRaceDropDown(faction, client); + faction.OnMouseDown = _ => ShowRaceDropDown(faction, client); var factionname = faction.GetWidget("FACTIONNAME"); factionname.GetText = () => CountryNames[client.Country]; @@ -505,12 +500,12 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic var team = template.GetWidget("TEAM"); team.IsDisabled = () => slot.LockTeam || ready; - team.OnMouseDown = _ => team.IsDisabled() ? true : ShowTeamDropDown(team, client); + team.OnMouseDown = _ => ShowTeamDropDown(team, client); team.GetText = () => (client.Team == 0) ? "-" : client.Team.ToString(); var spawn = template.GetWidget("SPAWN"); spawn.IsDisabled = () => slot.LockSpawn || ready; - spawn.OnMouseDown = _ => spawn.IsDisabled() ? true : ShowSpawnDropDown(spawn, client); + spawn.OnMouseDown = _ => ShowSpawnDropDown(spawn, client); spawn.GetText = () => (client.SpawnPoint == 0) ? "-" : client.SpawnPoint.ToString(); if (client.Bot == null) @@ -589,7 +584,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic var color = template.GetWidget("COLOR"); color.IsDisabled = () => ready; - color.OnMouseDown = _ => color.IsDisabled() ? true : ShowColorDropDown(color, client); + color.OnMouseDown = _ => ShowColorDropDown(color, client); var colorBlock = color.GetWidget("COLORBLOCK"); colorBlock.GetColor = () => client.ColorRamp.GetColor(0); diff --git a/OpenRA.Mods.RA/Widgets/Logic/DiplomacyLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/DiplomacyLogic.cs index 69011af26f..2a4f3ba86e 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/DiplomacyLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/DiplomacyLogic.cs @@ -112,7 +112,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic GetText = () => world.LocalPlayer.Stances[ pp ].ToString(), }; - myStance.OnMouseDown = mi => { ShowDropDown(pp, myStance); return true; }; + myStance.OnMouseDown = mi => ShowDropDown(pp, myStance); bg.AddChild(myStance); controls.Add(myStance); diff --git a/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs index 3141b72b77..aac4f0dbf2 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs @@ -226,7 +226,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic } } - bool ShowSlotDropDown(DropDownButtonWidget dropdown, Session.Slot slot, Session.Client client) + void ShowSlotDropDown(DropDownButtonWidget dropdown, Session.Slot slot, Session.Client client) { var options = new List() { @@ -253,10 +253,9 @@ namespace OpenRA.Mods.RA.Widgets.Logic }; dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 150, options, setupItem); - return true; } - bool ShowRaceDropDown(DropDownButtonWidget dropdown, Session.Client client) + void ShowRaceDropDown(DropDownButtonWidget dropdown, Session.Client client) { Func setupItem = (race, itemTemplate) => { @@ -271,10 +270,9 @@ namespace OpenRA.Mods.RA.Widgets.Logic }; dropdown.ShowDropDown("RACE_DROPDOWN_TEMPLATE", 150, CountryNames.Keys.ToList(), setupItem); - return true; } - bool ShowTeamDropDown(DropDownButtonWidget dropdown, Session.Client client) + void ShowTeamDropDown(DropDownButtonWidget dropdown, Session.Client client) { Func setupItem = (ii, itemTemplate) => { @@ -287,10 +285,9 @@ namespace OpenRA.Mods.RA.Widgets.Logic var options = Graphics.Util.MakeArray(Map.PlayerCount, i => i).ToList(); dropdown.ShowDropDown("TEAM_DROPDOWN_TEMPLATE", 150, options, setupItem); - return true; } - bool ShowColorDropDown(DropDownButtonWidget color, Session.Client client) + void ShowColorDropDown(DropDownButtonWidget color, Session.Client client) { var colorChooser = Game.modData.WidgetLoader.LoadWidget( new WidgetArgs() { {"worldRenderer", worldRenderer} }, null, "COLOR_CHOOSER" ); var hueSlider = colorChooser.GetWidget("HUE_SLIDER"); @@ -319,7 +316,6 @@ namespace OpenRA.Mods.RA.Widgets.Logic }; color.AttachPanel(colorChooser); - return true; } void UpdatePlayerList() @@ -383,14 +379,14 @@ namespace OpenRA.Mods.RA.Widgets.Logic var color = template.GetWidget("COLOR"); color.IsDisabled = () => s.LockColor; - color.OnMouseDown = _ => { if (s.LockColor) return true; return ShowColorDropDown(color, c); }; + color.OnMouseDown = _ => ShowColorDropDown(color, c); var colorBlock = color.GetWidget("COLORBLOCK"); colorBlock.GetColor = () => c.ColorRamp.GetColor(0); var faction = template.GetWidget("FACTION"); faction.IsDisabled = () => s.LockRace; - faction.OnMouseDown = _ => { if (s.LockRace) return true; return ShowRaceDropDown(faction, c); }; + faction.OnMouseDown = _ => ShowRaceDropDown(faction, c); var factionname = faction.GetWidget("FACTIONNAME"); factionname.GetText = () => CountryNames[c.Country]; @@ -400,7 +396,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic var team = template.GetWidget("TEAM"); team.IsDisabled = () => s.LockTeam; - team.OnMouseDown = _ => { if (s.LockTeam) return true; return ShowTeamDropDown(team, c); }; + team.OnMouseDown = _ => ShowTeamDropDown(team, c); team.GetText = () => (c.Team == 0) ? "-" : c.Team.ToString(); var status = template.GetWidget("STATUS"); diff --git a/OpenRA.Mods.RA/Widgets/Logic/MainMenuButtonsLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/MainMenuButtonsLogic.cs index b09141180d..c74d253ee7 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/MainMenuButtonsLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/MainMenuButtonsLogic.cs @@ -74,7 +74,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic }); } - static bool ShowModsDropDown(DropDownButtonWidget dropdown) + static void ShowModsDropDown(DropDownButtonWidget dropdown) { Func setupItem = (m, itemTemplate) => { @@ -86,9 +86,6 @@ namespace OpenRA.Mods.RA.Widgets.Logic }; dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 150, Mod.AllMods.Keys.ToList(), setupItem); - return true; } - } - } diff --git a/OpenRA.Mods.RA/Widgets/Logic/OrderButtonsChromeLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/OrderButtonsChromeLogic.cs index 72b9cf3c0f..b207840c7a 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/OrderButtonsChromeLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/OrderButtonsChromeLogic.cs @@ -28,14 +28,14 @@ namespace OpenRA.Mods.RA.Widgets.Logic if (sell != null) { sell.Pressed = () => world.OrderGenerator is SellOrderGenerator; - sell.OnMouseDown = mi => { world.ToggleInputMode(); return true; }; + sell.OnMouseDown = mi => world.ToggleInputMode(); } var powerdown = moneybin.GetWidget("POWER_DOWN"); if (powerdown != null) { powerdown.Pressed = () => world.OrderGenerator is PowerDownOrderGenerator; - powerdown.OnMouseDown = mi => { world.ToggleInputMode(); return true; }; + powerdown.OnMouseDown = mi => world.ToggleInputMode(); } var repair = moneybin.GetWidget("REPAIR"); @@ -43,7 +43,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic { repair.Enabled = () => { return RepairOrderGenerator.PlayerIsAllowedToRepair( world ); }; repair.Pressed = () => world.OrderGenerator is RepairOrderGenerator; - repair.OnMouseDown = mi => { world.ToggleInputMode(); return true; }; + repair.OnMouseDown = mi => world.ToggleInputMode(); repair.GetLongDesc = () => { return repair.Enabled() ? repair.LongDesc : repair.LongDesc + "\n\nRequires: Construction Yard"; }; } }