Implement state prediction for lobby checkboxes.
This commit is contained in:
@@ -101,18 +101,25 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
}
|
||||
|
||||
var checkbox = checkboxColumns.Dequeue();
|
||||
var optionValue = new CachedTransform<Session.Global, Session.LobbyOptionState>(
|
||||
gs => gs.LobbyOptions[option.Id]);
|
||||
var optionEnabled = new PredictedCachedTransform<Session.Global, bool>(
|
||||
gs => gs.LobbyOptions[option.Id].IsEnabled);
|
||||
|
||||
var optionLocked = new CachedTransform<Session.Global, bool>(
|
||||
gs => gs.LobbyOptions[option.Id].IsLocked);
|
||||
|
||||
checkbox.GetText = () => option.Name;
|
||||
if (option.Description != null)
|
||||
checkbox.GetTooltipText = () => option.Description;
|
||||
|
||||
checkbox.IsVisible = () => true;
|
||||
checkbox.IsChecked = () => optionValue.Update(orderManager.LobbyInfo.GlobalSettings).IsEnabled;
|
||||
checkbox.IsDisabled = () => configurationDisabled() || optionValue.Update(orderManager.LobbyInfo.GlobalSettings).IsLocked;
|
||||
checkbox.OnClick = () => orderManager.IssueOrder(Order.Command(
|
||||
$"option {option.Id} {!optionValue.Update(orderManager.LobbyInfo.GlobalSettings).IsEnabled}"));
|
||||
checkbox.IsChecked = () => optionEnabled.Update(orderManager.LobbyInfo.GlobalSettings);
|
||||
checkbox.IsDisabled = () => configurationDisabled() || optionLocked.Update(orderManager.LobbyInfo.GlobalSettings);
|
||||
checkbox.OnClick = () =>
|
||||
{
|
||||
var state = !optionEnabled.Update(orderManager.LobbyInfo.GlobalSettings);
|
||||
orderManager.IssueOrder(Order.Command($"option {option.Id} {state}"));
|
||||
optionEnabled.Predict(state);
|
||||
};
|
||||
}
|
||||
|
||||
foreach (var option in allOptions.Where(o => !(o is LobbyBooleanOption)))
|
||||
|
||||
Reference in New Issue
Block a user