Kill CheckboxWidget.Bind and related
This commit is contained in:
@@ -19,48 +19,17 @@ namespace OpenRA.Widgets
|
||||
{
|
||||
public Func<bool> IsChecked = () => false;
|
||||
public int BaseLine = 1;
|
||||
|
||||
object boundObject;
|
||||
bool boundReadOnly;
|
||||
FieldInfo boundField;
|
||||
[Obsolete] public event Action<bool> OnChange = _ => {};
|
||||
|
||||
|
||||
public CheckboxWidget()
|
||||
: base()
|
||||
{
|
||||
OnClick = OldClickBehavior;
|
||||
IsChecked = () => (boundObject != null && (bool)boundField.GetValue(boundObject));
|
||||
}
|
||||
|
||||
protected CheckboxWidget(CheckboxWidget widget)
|
||||
: base(widget)
|
||||
{
|
||||
OnClick = OldClickBehavior;
|
||||
IsChecked = () => (boundObject != null && (bool)boundField.GetValue(boundObject));
|
||||
}
|
||||
|
||||
[Obsolete] public void Bind(object obj, string field) { Bind(obj, field, false); }
|
||||
[Obsolete] public void BindReadOnly(object obj, string field) { Bind(obj, field, true); }
|
||||
|
||||
void Bind(object obj, string field, bool readOnly)
|
||||
{
|
||||
boundObject = obj;
|
||||
boundReadOnly = readOnly;
|
||||
boundField = obj.GetType().GetField(field);
|
||||
}
|
||||
|
||||
void OldClickBehavior()
|
||||
{
|
||||
bool newVal = !IsChecked();
|
||||
if (boundObject != null && !boundReadOnly)
|
||||
{
|
||||
newVal = !(bool)boundField.GetValue(boundObject);
|
||||
boundField.SetValue(boundObject, newVal);
|
||||
}
|
||||
|
||||
OnChange(newVal);
|
||||
}
|
||||
|
||||
|
||||
public override void DrawInner()
|
||||
{
|
||||
var font = Game.Renderer.Fonts[Font];
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
@@ -37,10 +37,6 @@
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="ICSharpCode.SharpZipLib, Version=0.86.0.518, Culture=neutral, PublicKeyToken=1b03e6acf1164f73, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\ICSharpCode.SharpZipLib.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
@@ -54,6 +50,10 @@
|
||||
</Reference>
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="ICSharpCode.SharpZipLib">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\ICSharpCode.SharpZipLib.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AcceptsSupplies.cs" />
|
||||
|
||||
@@ -43,8 +43,10 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
|
||||
cs.GetWidget<TextFieldWidget>("GAME_TITLE").Text = settings.Server.Name ?? "";
|
||||
cs.GetWidget<TextFieldWidget>("LISTEN_PORT").Text = settings.Server.ListenPort.ToString();
|
||||
cs.GetWidget<TextFieldWidget>("EXTERNAL_PORT").Text = settings.Server.ExternalPort.ToString();
|
||||
cs.GetWidget<CheckboxWidget>("CHECKBOX_ONLINE").Bind(settings.Server, "AdvertiseOnline");
|
||||
cs.GetWidget<CheckboxWidget>("CHECKBOX_ONLINE").OnChange += _ => settings.Save();
|
||||
|
||||
var onlineCheckbox = cs.GetWidget<CheckboxWidget>("CHECKBOX_ONLINE");
|
||||
onlineCheckbox.IsChecked = () => settings.Server.AdvertiseOnline;
|
||||
onlineCheckbox.OnClick = () => { settings.Server.AdvertiseOnline ^= true; settings.Save(); };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
|
||||
|
||||
var lockTeamsCheckbox = lobby.GetWidget<CheckboxWidget>("LOCKTEAMS_CHECKBOX");
|
||||
lockTeamsCheckbox.IsChecked = () => orderManager.LobbyInfo.GlobalSettings.LockTeams;
|
||||
lockTeamsCheckbox.OnChange += _ =>
|
||||
lockTeamsCheckbox.OnClick = () =>
|
||||
{
|
||||
if (Game.IsHost)
|
||||
orderManager.IssueOrder(Order.Command(
|
||||
@@ -119,21 +119,20 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
|
||||
|
||||
var allowCheats = lobby.GetWidget<CheckboxWidget>("ALLOWCHEATS_CHECKBOX");
|
||||
allowCheats.IsChecked = () => orderManager.LobbyInfo.GlobalSettings.AllowCheats;
|
||||
allowCheats.OnChange += _ =>
|
||||
allowCheats.OnClick = () =>
|
||||
{
|
||||
if (Game.IsHost)
|
||||
orderManager.IssueOrder(Order.Command(
|
||||
"allowcheats {0}".F(!orderManager.LobbyInfo.GlobalSettings.AllowCheats)));
|
||||
};
|
||||
|
||||
var startGameButton = lobby.GetWidget("START_GAME_BUTTON");
|
||||
startGameButton.OnMouseUp = mi =>
|
||||
var startGameButton = lobby.GetWidget<ButtonWidget>("START_GAME_BUTTON");
|
||||
startGameButton.OnClick = () =>
|
||||
{
|
||||
mapButton.Visible = false;
|
||||
disconnectButton.Visible = false;
|
||||
lockTeamsCheckbox.Visible = false;
|
||||
orderManager.IssueOrder(Order.Command("startgame"));
|
||||
return true;
|
||||
};
|
||||
|
||||
// Todo: Only show if the map requirements are met for player slots
|
||||
@@ -409,7 +408,7 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
|
||||
|
||||
var status = template.GetWidget<CheckboxWidget>("STATUS");
|
||||
status.IsChecked = () => c.State == Session.ClientState.Ready;
|
||||
status.OnChange += CycleReady;
|
||||
status.OnClick = CycleReady;
|
||||
|
||||
var spectator = template.GetWidget<LabelWidget>("SPECTATOR");
|
||||
|
||||
@@ -442,7 +441,7 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
|
||||
var status = template.GetWidget<CheckboxWidget>("STATUS");
|
||||
status.IsChecked = () => c.State == Session.ClientState.Ready;
|
||||
if (c.Index == orderManager.LocalClient.Index)
|
||||
status.OnChange += CycleReady;
|
||||
status.OnClick = CycleReady;
|
||||
|
||||
var spectator = template.GetWidget<LabelWidget>("SPECTATOR");
|
||||
|
||||
@@ -471,7 +470,7 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
|
||||
|
||||
bool SpawnPointAvailable(int index) { return (index == 0) || orderManager.LobbyInfo.Clients.All(c => c.SpawnPoint != index); }
|
||||
|
||||
void CycleReady(bool ready)
|
||||
void CycleReady()
|
||||
{
|
||||
orderManager.IssueOrder(Order.Command("ready"));
|
||||
}
|
||||
|
||||
@@ -82,9 +82,15 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
|
||||
return bg.GetWidget("BUTTON_PLAY").OnMouseUp(mi);
|
||||
};
|
||||
|
||||
bg.GetWidget<CheckboxWidget>("SHUFFLE").Bind(Game.Settings.Sound, "Shuffle");
|
||||
bg.GetWidget<CheckboxWidget>("REPEAT").Bind(Game.Settings.Sound, "Repeat");
|
||||
|
||||
|
||||
var shuffleCheckbox = bg.GetWidget<CheckboxWidget>("SHUFFLE");
|
||||
shuffleCheckbox.IsChecked = () => Game.Settings.Sound.Shuffle;
|
||||
shuffleCheckbox.OnClick = () => Game.Settings.Sound.Shuffle ^= true;
|
||||
|
||||
var repeatCheckbox = bg.GetWidget<CheckboxWidget>("REPEAT");
|
||||
repeatCheckbox.IsChecked = () => Game.Settings.Sound.Repeat;
|
||||
repeatCheckbox.OnClick = () => Game.Settings.Sound.Repeat ^= true;
|
||||
|
||||
bg.GetWidget<LabelWidget>("TIME").GetText = () =>
|
||||
{
|
||||
if (CurrentSong == null)
|
||||
|
||||
Reference in New Issue
Block a user