Convert lobby checkboxes to new options backend.

This commit is contained in:
Paul Chote
2016-04-20 08:08:38 +02:00
parent 3e92c1944a
commit eb884ca76f
14 changed files with 134 additions and 328 deletions

View File

@@ -75,12 +75,17 @@ namespace OpenRA.Mods.Common.Widgets.Logic
}
// Debug/Cheats tab
if (lp != null && world.LobbyInfo.GlobalSettings.AllowCheats)
// Can't use DeveloperMode.Enabled because there is a hardcoded hack to *always*
// enable developer mode for singleplayer games, but we only want to show the button
// if it has been explicitly enabled
var def = world.Map.Rules.Actors["player"].TraitInfo<DeveloperModeInfo>().Enabled;
var developerEnabled = world.LobbyInfo.GlobalSettings.OptionOrDefault("cheats", def);
if (lp != null && developerEnabled)
{
numTabs++;
var debugTabButton = widget.Get<ButtonWidget>(string.Concat("BUTTON", numTabs.ToString()));
debugTabButton.Text = "Debug";
debugTabButton.IsVisible = () => lp != null && world.LobbyInfo.GlobalSettings.AllowCheats && numTabs > 1 && !hasError;
debugTabButton.IsVisible = () => lp != null && numTabs > 1 && !hasError;
debugTabButton.IsDisabled = () => world.IsGameOver;
debugTabButton.OnClick = () => activePanel = IngameInfoPanel.Debug;
debugTabButton.IsHighlighted = () => activePanel == IngameInfoPanel.Debug;

View File

@@ -12,6 +12,7 @@
using System;
using System.Linq;
using OpenRA.Mods.Common.Traits;
using OpenRA.Traits;
using OpenRA.Widgets;
namespace OpenRA.Mods.Common.Widgets.Logic
@@ -67,7 +68,12 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var debug = widget.GetOrNull<MenuButtonWidget>("DEBUG_BUTTON");
if (debug != null)
{
debug.IsVisible = () => world.LobbyInfo.GlobalSettings.AllowCheats;
// Can't use DeveloperMode.Enabled because there is a hardcoded hack to *always*
// enable developer mode for singleplayer games, but we only want to show the button
// if it has been explicitly enabled
var def = world.Map.Rules.Actors["player"].TraitInfo<DeveloperModeInfo>().Enabled;
var enabled = world.LobbyInfo.GlobalSettings.OptionOrDefault("cheats", def);
debug.IsVisible = () => enabled;
debug.IsDisabled = () => disableSystemButtons;
debug.OnClick = () => OpenMenuPanel(debug, new WidgetArgs()
{

View File

@@ -347,73 +347,31 @@ namespace OpenRA.Mods.Common.Widgets.Logic
forceStartBin.Get<ButtonWidget>("CANCEL_BUTTON").OnClick = () => panel = PanelType.Players;
// Options panel
var allowCheats = optionsBin.GetOrNull<CheckboxWidget>("ALLOWCHEATS_CHECKBOX");
if (allowCheats != null)
var optionCheckboxes = new Dictionary<string, string>()
{
var cheatsLocked = new CachedTransform<MapPreview, bool>(
map => map.Rules.Actors["player"].TraitInfo<DeveloperModeInfo>().Locked);
{ "EXPLORED_MAP_CHECKBOX", "explored" },
{ "CRATES_CHECKBOX", "crates" },
{ "SHORTGAME_CHECKBOX", "shortgame" },
{ "FOG_CHECKBOX", "fog" },
{ "ALLYBUILDRADIUS_CHECKBOX", "allybuild" },
{ "ALLOWCHEATS_CHECKBOX", "cheats" },
{ "CREEPS_CHECKBOX", "creeps" },
};
allowCheats.IsChecked = () => orderManager.LobbyInfo.GlobalSettings.AllowCheats;
allowCheats.IsDisabled = () => configurationDisabled() || cheatsLocked.Update(Map);
allowCheats.OnClick = () => orderManager.IssueOrder(Order.Command(
"allowcheats {0}".F(!orderManager.LobbyInfo.GlobalSettings.AllowCheats)));
}
var crates = optionsBin.GetOrNull<CheckboxWidget>("CRATES_CHECKBOX");
if (crates != null)
foreach (var kv in optionCheckboxes)
{
var cratesLocked = new CachedTransform<MapPreview, bool>(map =>
var checkbox = optionsBin.GetOrNull<CheckboxWidget>(kv.Key);
if (checkbox != null)
{
var crateSpawner = map.Rules.Actors["world"].TraitInfoOrDefault<CrateSpawnerInfo>();
return crateSpawner == null || crateSpawner.Locked;
});
var option = new CachedTransform<Session.Global, Session.LobbyOptionState>(
gs => gs.LobbyOptions[kv.Value]);
crates.IsChecked = () => orderManager.LobbyInfo.GlobalSettings.Crates;
crates.IsDisabled = () => configurationDisabled() || cratesLocked.Update(Map);
crates.OnClick = () => orderManager.IssueOrder(Order.Command(
"crates {0}".F(!orderManager.LobbyInfo.GlobalSettings.Crates)));
}
var creeps = optionsBin.GetOrNull<CheckboxWidget>("CREEPS_CHECKBOX");
if (creeps != null)
{
var creepsLocked = new CachedTransform<MapPreview, bool>(map =>
{
var mapCreeps = map.Rules.Actors["world"].TraitInfoOrDefault<MapCreepsInfo>();
return mapCreeps == null || mapCreeps.Locked;
});
creeps.IsChecked = () => orderManager.LobbyInfo.GlobalSettings.Creeps;
creeps.IsDisabled = () => configurationDisabled() || creepsLocked.Update(Map);
creeps.OnClick = () => orderManager.IssueOrder(Order.Command(
"creeps {0}".F(!orderManager.LobbyInfo.GlobalSettings.Creeps)));
}
var allybuildradius = optionsBin.GetOrNull<CheckboxWidget>("ALLYBUILDRADIUS_CHECKBOX");
if (allybuildradius != null)
{
var allyBuildRadiusLocked = new CachedTransform<MapPreview, bool>(map =>
{
var mapBuildRadius = map.Rules.Actors["world"].TraitInfoOrDefault<MapBuildRadiusInfo>();
return mapBuildRadius == null || mapBuildRadius.AllyBuildRadiusLocked;
});
allybuildradius.IsChecked = () => orderManager.LobbyInfo.GlobalSettings.AllyBuildRadius;
allybuildradius.IsDisabled = () => configurationDisabled() || allyBuildRadiusLocked.Update(Map);
allybuildradius.OnClick = () => orderManager.IssueOrder(Order.Command(
"allybuildradius {0}".F(!orderManager.LobbyInfo.GlobalSettings.AllyBuildRadius)));
}
var shortGame = optionsBin.GetOrNull<CheckboxWidget>("SHORTGAME_CHECKBOX");
if (shortGame != null)
{
var shortGameLocked = new CachedTransform<MapPreview, bool>(
map => map.Rules.Actors["world"].TraitInfo<MapOptionsInfo>().ShortGameLocked);
shortGame.IsChecked = () => orderManager.LobbyInfo.GlobalSettings.ShortGame;
shortGame.IsDisabled = () => configurationDisabled() || shortGameLocked.Update(Map);
shortGame.OnClick = () => orderManager.IssueOrder(Order.Command(
"shortgame {0}".F(!orderManager.LobbyInfo.GlobalSettings.ShortGame)));
checkbox.IsChecked = () => option.Update(orderManager.LobbyInfo.GlobalSettings).Enabled;
checkbox.IsDisabled = () => configurationDisabled() ||
option.Update(orderManager.LobbyInfo.GlobalSettings).Locked;
checkbox.OnClick = () => orderManager.IssueOrder(Order.Command(
"option {0} {1}".F(kv.Value, !option.Update(orderManager.LobbyInfo.GlobalSettings).Enabled)));
}
}
var difficulty = optionsBin.GetOrNull<DropDownButtonWidget>("DIFFICULTY_DROPDOWNBUTTON");
@@ -593,30 +551,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
};
}
var exploredMap = optionsBin.GetOrNull<CheckboxWidget>("EXPLORED_MAP_CHECKBOX");
if (exploredMap != null)
{
var exploredMapLocked = new CachedTransform<MapPreview, bool>(
map => map.Rules.Actors["player"].TraitInfo<ShroudInfo>().ExploredMapLocked);
exploredMap.IsChecked = () => !orderManager.LobbyInfo.GlobalSettings.Shroud;
exploredMap.IsDisabled = () => configurationDisabled() || exploredMapLocked.Update(Map);
exploredMap.OnClick = () => orderManager.IssueOrder(Order.Command(
"shroud {0}".F(!orderManager.LobbyInfo.GlobalSettings.Shroud)));
}
var enableFog = optionsBin.GetOrNull<CheckboxWidget>("FOG_CHECKBOX");
if (enableFog != null)
{
var fogLocked = new CachedTransform<MapPreview, bool>(
map => map.Rules.Actors["player"].TraitInfo<ShroudInfo>().FogLocked);
enableFog.IsChecked = () => orderManager.LobbyInfo.GlobalSettings.Fog;
enableFog.IsDisabled = () => configurationDisabled() || fogLocked.Update(Map);
enableFog.OnClick = () => orderManager.IssueOrder(Order.Command(
"fog {0}".F(!orderManager.LobbyInfo.GlobalSettings.Fog)));
}
var disconnectButton = lobby.Get<ButtonWidget>("DISCONNECT_BUTTON");
disconnectButton.OnClick = () => { CloseWindow(); onExit(); };