Kill CheckboxWidget.Bind and related
This commit is contained in:
@@ -20,45 +20,14 @@ namespace OpenRA.Widgets
|
|||||||
public Func<bool> IsChecked = () => false;
|
public Func<bool> IsChecked = () => false;
|
||||||
public int BaseLine = 1;
|
public int BaseLine = 1;
|
||||||
|
|
||||||
object boundObject;
|
|
||||||
bool boundReadOnly;
|
|
||||||
FieldInfo boundField;
|
|
||||||
[Obsolete] public event Action<bool> OnChange = _ => {};
|
|
||||||
|
|
||||||
public CheckboxWidget()
|
public CheckboxWidget()
|
||||||
: base()
|
: base()
|
||||||
{
|
{
|
||||||
OnClick = OldClickBehavior;
|
|
||||||
IsChecked = () => (boundObject != null && (bool)boundField.GetValue(boundObject));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected CheckboxWidget(CheckboxWidget widget)
|
protected CheckboxWidget(CheckboxWidget widget)
|
||||||
: base(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()
|
public override void DrawInner()
|
||||||
|
|||||||
@@ -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">
|
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
@@ -37,10 +37,6 @@
|
|||||||
<OutputPath>bin\Release\</OutputPath>
|
<OutputPath>bin\Release\</OutputPath>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<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" />
|
||||||
<Reference Include="System.Core">
|
<Reference Include="System.Core">
|
||||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||||
@@ -54,6 +50,10 @@
|
|||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="System.Data" />
|
<Reference Include="System.Data" />
|
||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
|
<Reference Include="ICSharpCode.SharpZipLib">
|
||||||
|
<SpecificVersion>False</SpecificVersion>
|
||||||
|
<HintPath>..\ICSharpCode.SharpZipLib.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="AcceptsSupplies.cs" />
|
<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>("GAME_TITLE").Text = settings.Server.Name ?? "";
|
||||||
cs.GetWidget<TextFieldWidget>("LISTEN_PORT").Text = settings.Server.ListenPort.ToString();
|
cs.GetWidget<TextFieldWidget>("LISTEN_PORT").Text = settings.Server.ListenPort.ToString();
|
||||||
cs.GetWidget<TextFieldWidget>("EXTERNAL_PORT").Text = settings.Server.ExternalPort.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");
|
var lockTeamsCheckbox = lobby.GetWidget<CheckboxWidget>("LOCKTEAMS_CHECKBOX");
|
||||||
lockTeamsCheckbox.IsChecked = () => orderManager.LobbyInfo.GlobalSettings.LockTeams;
|
lockTeamsCheckbox.IsChecked = () => orderManager.LobbyInfo.GlobalSettings.LockTeams;
|
||||||
lockTeamsCheckbox.OnChange += _ =>
|
lockTeamsCheckbox.OnClick = () =>
|
||||||
{
|
{
|
||||||
if (Game.IsHost)
|
if (Game.IsHost)
|
||||||
orderManager.IssueOrder(Order.Command(
|
orderManager.IssueOrder(Order.Command(
|
||||||
@@ -119,21 +119,20 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
|
|||||||
|
|
||||||
var allowCheats = lobby.GetWidget<CheckboxWidget>("ALLOWCHEATS_CHECKBOX");
|
var allowCheats = lobby.GetWidget<CheckboxWidget>("ALLOWCHEATS_CHECKBOX");
|
||||||
allowCheats.IsChecked = () => orderManager.LobbyInfo.GlobalSettings.AllowCheats;
|
allowCheats.IsChecked = () => orderManager.LobbyInfo.GlobalSettings.AllowCheats;
|
||||||
allowCheats.OnChange += _ =>
|
allowCheats.OnClick = () =>
|
||||||
{
|
{
|
||||||
if (Game.IsHost)
|
if (Game.IsHost)
|
||||||
orderManager.IssueOrder(Order.Command(
|
orderManager.IssueOrder(Order.Command(
|
||||||
"allowcheats {0}".F(!orderManager.LobbyInfo.GlobalSettings.AllowCheats)));
|
"allowcheats {0}".F(!orderManager.LobbyInfo.GlobalSettings.AllowCheats)));
|
||||||
};
|
};
|
||||||
|
|
||||||
var startGameButton = lobby.GetWidget("START_GAME_BUTTON");
|
var startGameButton = lobby.GetWidget<ButtonWidget>("START_GAME_BUTTON");
|
||||||
startGameButton.OnMouseUp = mi =>
|
startGameButton.OnClick = () =>
|
||||||
{
|
{
|
||||||
mapButton.Visible = false;
|
mapButton.Visible = false;
|
||||||
disconnectButton.Visible = false;
|
disconnectButton.Visible = false;
|
||||||
lockTeamsCheckbox.Visible = false;
|
lockTeamsCheckbox.Visible = false;
|
||||||
orderManager.IssueOrder(Order.Command("startgame"));
|
orderManager.IssueOrder(Order.Command("startgame"));
|
||||||
return true;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Todo: Only show if the map requirements are met for player slots
|
// 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");
|
var status = template.GetWidget<CheckboxWidget>("STATUS");
|
||||||
status.IsChecked = () => c.State == Session.ClientState.Ready;
|
status.IsChecked = () => c.State == Session.ClientState.Ready;
|
||||||
status.OnChange += CycleReady;
|
status.OnClick = CycleReady;
|
||||||
|
|
||||||
var spectator = template.GetWidget<LabelWidget>("SPECTATOR");
|
var spectator = template.GetWidget<LabelWidget>("SPECTATOR");
|
||||||
|
|
||||||
@@ -442,7 +441,7 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
|
|||||||
var status = template.GetWidget<CheckboxWidget>("STATUS");
|
var status = template.GetWidget<CheckboxWidget>("STATUS");
|
||||||
status.IsChecked = () => c.State == Session.ClientState.Ready;
|
status.IsChecked = () => c.State == Session.ClientState.Ready;
|
||||||
if (c.Index == orderManager.LocalClient.Index)
|
if (c.Index == orderManager.LocalClient.Index)
|
||||||
status.OnChange += CycleReady;
|
status.OnClick = CycleReady;
|
||||||
|
|
||||||
var spectator = template.GetWidget<LabelWidget>("SPECTATOR");
|
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); }
|
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"));
|
orderManager.IssueOrder(Order.Command("ready"));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,8 +82,14 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
|
|||||||
return bg.GetWidget("BUTTON_PLAY").OnMouseUp(mi);
|
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 = () =>
|
bg.GetWidget<LabelWidget>("TIME").GetText = () =>
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user