2023-01-19 03:56:45 +01:00
|
|
|
using System.Globalization;
|
2022-03-01 05:18:25 +03:00
|
|
|
using Robust.Client.AutoGenerated;
|
|
|
|
|
using Robust.Client.UserInterface;
|
|
|
|
|
using Robust.Client.UserInterface.Controls;
|
|
|
|
|
using Robust.Client.UserInterface.XAML;
|
|
|
|
|
using Robust.Shared;
|
|
|
|
|
using Robust.Shared.Configuration;
|
2022-08-21 10:32:09 +12:00
|
|
|
using Robust.Client.GameStates;
|
2022-09-11 18:52:37 +12:00
|
|
|
using Content.Client.Entry;
|
2022-03-01 05:18:25 +03:00
|
|
|
|
2022-09-11 20:42:12 -07:00
|
|
|
namespace Content.Client.Options.UI.Tabs
|
2022-03-01 05:18:25 +03:00
|
|
|
{
|
|
|
|
|
[GenerateTypedNameReferences]
|
|
|
|
|
public sealed partial class NetworkTab : Control
|
|
|
|
|
{
|
|
|
|
|
[Dependency] private readonly IConfigurationManager _cfg = default!;
|
2022-08-21 10:32:09 +12:00
|
|
|
[Dependency] private readonly IClientGameStateManager _stateMan = default!;
|
2022-03-01 05:18:25 +03:00
|
|
|
|
|
|
|
|
public NetworkTab()
|
|
|
|
|
{
|
2022-09-11 18:52:37 +12:00
|
|
|
|
2022-03-01 05:18:25 +03:00
|
|
|
RobustXamlLoader.Load(this);
|
|
|
|
|
IoCManager.InjectDependencies(this);
|
|
|
|
|
|
|
|
|
|
ApplyButton.OnPressed += OnApplyButtonPressed;
|
|
|
|
|
ResetButton.OnPressed += OnResetButtonPressed;
|
2022-09-11 18:52:37 +12:00
|
|
|
DefaultButton.OnPressed += OnDefaultButtonPressed;
|
2022-10-26 16:19:11 +13:00
|
|
|
NetPredictCheckbox.OnToggled += OnPredictToggled;
|
2022-09-11 18:52:37 +12:00
|
|
|
NetInterpRatioSlider.OnValueChanged += OnSliderChanged;
|
2022-08-21 10:32:09 +12:00
|
|
|
NetInterpRatioSlider.MinValue = _stateMan.MinBufferSize;
|
2022-09-11 18:52:37 +12:00
|
|
|
NetPredictTickBiasSlider.OnValueChanged += OnSliderChanged;
|
2022-10-26 16:19:11 +13:00
|
|
|
NetPvsSpawnSlider.OnValueChanged += OnSliderChanged;
|
2022-09-11 18:52:37 +12:00
|
|
|
NetPvsEntrySlider.OnValueChanged += OnSliderChanged;
|
|
|
|
|
NetPvsLeaveSlider.OnValueChanged += OnSliderChanged;
|
2022-03-01 05:18:25 +03:00
|
|
|
|
|
|
|
|
Reset();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Dispose(bool disposing)
|
|
|
|
|
{
|
|
|
|
|
ApplyButton.OnPressed -= OnApplyButtonPressed;
|
|
|
|
|
ResetButton.OnPressed -= OnResetButtonPressed;
|
2022-09-11 18:52:37 +12:00
|
|
|
DefaultButton.OnPressed -= OnDefaultButtonPressed;
|
2022-10-26 16:19:11 +13:00
|
|
|
NetPredictCheckbox.OnToggled -= OnPredictToggled;
|
2022-09-11 18:52:37 +12:00
|
|
|
NetInterpRatioSlider.OnValueChanged -= OnSliderChanged;
|
|
|
|
|
NetPredictTickBiasSlider.OnValueChanged -= OnSliderChanged;
|
2022-10-26 16:19:11 +13:00
|
|
|
NetPvsSpawnSlider.OnValueChanged -= OnSliderChanged;
|
2022-09-11 18:52:37 +12:00
|
|
|
NetPvsEntrySlider.OnValueChanged -= OnSliderChanged;
|
|
|
|
|
NetPvsLeaveSlider.OnValueChanged -= OnSliderChanged;
|
2022-03-01 05:18:25 +03:00
|
|
|
base.Dispose(disposing);
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-26 16:19:11 +13:00
|
|
|
private void OnPredictToggled(BaseButton.ButtonToggledEventArgs obj)
|
|
|
|
|
{
|
|
|
|
|
UpdateChanges();
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-11 18:52:37 +12:00
|
|
|
private void OnSliderChanged(Robust.Client.UserInterface.Controls.Range range)
|
2022-03-01 05:18:25 +03:00
|
|
|
{
|
|
|
|
|
UpdateChanges();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnApplyButtonPressed(BaseButton.ButtonEventArgs args)
|
|
|
|
|
{
|
2022-08-21 10:32:09 +12:00
|
|
|
_cfg.SetCVar(CVars.NetBufferSize, (int) NetInterpRatioSlider.Value - _stateMan.MinBufferSize);
|
2022-09-11 18:52:37 +12:00
|
|
|
_cfg.SetCVar(CVars.NetPredictTickBias, (int) NetPredictTickBiasSlider.Value);
|
2022-10-26 16:19:11 +13:00
|
|
|
_cfg.SetCVar(CVars.NetPVSEntityBudget, (int) NetPvsSpawnSlider.Value);
|
|
|
|
|
_cfg.SetCVar(CVars.NetPVSEntityEnterBudget, (int) NetPvsEntrySlider.Value);
|
2022-09-11 18:52:37 +12:00
|
|
|
_cfg.SetCVar(CVars.NetPVSEntityExitBudget, (int) NetPvsLeaveSlider.Value);
|
2022-10-26 16:19:11 +13:00
|
|
|
_cfg.SetCVar(CVars.NetPredict, NetPredictCheckbox.Pressed);
|
2022-09-11 18:52:37 +12:00
|
|
|
|
2022-03-01 05:18:25 +03:00
|
|
|
_cfg.SaveToFile();
|
|
|
|
|
UpdateChanges();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnResetButtonPressed(BaseButton.ButtonEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
Reset();
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-11 18:52:37 +12:00
|
|
|
private void OnDefaultButtonPressed(BaseButton.ButtonEventArgs obj)
|
|
|
|
|
{
|
|
|
|
|
NetPredictTickBiasSlider.Value = CVars.NetPredictTickBias.DefaultValue;
|
2022-10-26 16:19:11 +13:00
|
|
|
NetPvsSpawnSlider.Value = CVars.NetPVSEntityBudget.DefaultValue;
|
|
|
|
|
NetPvsEntrySlider.Value = CVars.NetPVSEntityEnterBudget.DefaultValue;
|
2022-09-11 18:52:37 +12:00
|
|
|
NetPvsLeaveSlider.Value = CVars.NetPVSEntityExitBudget.DefaultValue;
|
2022-12-20 23:25:03 +01:00
|
|
|
NetInterpRatioSlider.Value = CVars.NetBufferSize.DefaultValue + _stateMan.MinBufferSize;
|
2022-09-11 18:52:37 +12:00
|
|
|
|
|
|
|
|
UpdateChanges();
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-01 05:18:25 +03:00
|
|
|
private void Reset()
|
|
|
|
|
{
|
2022-08-21 10:32:09 +12:00
|
|
|
NetInterpRatioSlider.Value = _cfg.GetCVar(CVars.NetBufferSize) + _stateMan.MinBufferSize;
|
2022-09-11 18:52:37 +12:00
|
|
|
NetPredictTickBiasSlider.Value = _cfg.GetCVar(CVars.NetPredictTickBias);
|
2022-10-26 16:19:11 +13:00
|
|
|
NetPvsSpawnSlider.Value = _cfg.GetCVar(CVars.NetPVSEntityBudget);
|
|
|
|
|
NetPvsEntrySlider.Value = _cfg.GetCVar(CVars.NetPVSEntityEnterBudget);
|
2022-09-11 18:52:37 +12:00
|
|
|
NetPvsLeaveSlider.Value = _cfg.GetCVar(CVars.NetPVSEntityExitBudget);
|
2022-10-26 16:19:11 +13:00
|
|
|
NetPredictCheckbox.Pressed = _cfg.GetCVar(CVars.NetPredict);
|
2022-03-01 05:18:25 +03:00
|
|
|
UpdateChanges();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateChanges()
|
|
|
|
|
{
|
2022-09-11 18:52:37 +12:00
|
|
|
var isEverythingSame =
|
|
|
|
|
NetInterpRatioSlider.Value == _cfg.GetCVar(CVars.NetBufferSize) + _stateMan.MinBufferSize &&
|
|
|
|
|
NetPredictTickBiasSlider.Value == _cfg.GetCVar(CVars.NetPredictTickBias) &&
|
2022-10-26 16:19:11 +13:00
|
|
|
NetPredictCheckbox.Pressed == _cfg.GetCVar(CVars.NetPredict) &&
|
|
|
|
|
NetPvsSpawnSlider.Value == _cfg.GetCVar(CVars.NetPVSEntityBudget) &&
|
|
|
|
|
NetPvsEntrySlider.Value == _cfg.GetCVar(CVars.NetPVSEntityEnterBudget) &&
|
2022-09-11 18:52:37 +12:00
|
|
|
NetPvsLeaveSlider.Value == _cfg.GetCVar(CVars.NetPVSEntityExitBudget);
|
|
|
|
|
|
2022-03-01 05:18:25 +03:00
|
|
|
ApplyButton.Disabled = isEverythingSame;
|
|
|
|
|
ResetButton.Disabled = isEverythingSame;
|
2023-01-19 03:56:45 +01:00
|
|
|
NetInterpRatioLabel.Text = NetInterpRatioSlider.Value.ToString(CultureInfo.InvariantCulture);
|
|
|
|
|
NetPredictTickBiasLabel.Text = NetPredictTickBiasSlider.Value.ToString(CultureInfo.InvariantCulture);
|
|
|
|
|
NetPvsSpawnLabel.Text = NetPvsSpawnSlider.Value.ToString(CultureInfo.InvariantCulture);
|
|
|
|
|
NetPvsEntryLabel.Text = NetPvsEntrySlider.Value.ToString(CultureInfo.InvariantCulture);
|
|
|
|
|
NetPvsLeaveLabel.Text = NetPvsLeaveSlider.Value.ToString(CultureInfo.InvariantCulture);
|
2022-10-26 16:19:11 +13:00
|
|
|
|
|
|
|
|
// TODO disable / grey-out the predict and interp sliders if prediction is disabled.
|
|
|
|
|
// Currently no option to do this, but should be added to the slider control in general
|
2022-03-01 05:18:25 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|