Merge branch 'master' into 2020-08-19-firelocks

This commit is contained in:
Víctor Aguilera Puerto
2020-09-08 13:23:20 +02:00
3 changed files with 60 additions and 12 deletions

View File

@@ -5,6 +5,7 @@ using Robust.Client.UserInterface.Controls;
using Robust.Shared.Interfaces.Configuration; using Robust.Shared.Interfaces.Configuration;
using Robust.Shared.IoC; using Robust.Shared.IoC;
using Robust.Shared.Localization; using Robust.Shared.Localization;
using Robust.Shared.Maths;
namespace Content.Client.UserInterface namespace Content.Client.UserInterface
{ {
@@ -12,13 +13,24 @@ namespace Content.Client.UserInterface
{ {
private sealed class GraphicsControl : Control private sealed class GraphicsControl : Control
{ {
private static readonly float[] UIScaleOptions =
{
0f,
0.75f,
1f,
1.25f,
1.50f,
1.75f,
2f
};
private readonly IConfigurationManager _cfg; private readonly IConfigurationManager _cfg;
private readonly Button ApplyButton; private readonly Button ApplyButton;
private readonly CheckBox VSyncCheckBox; private readonly CheckBox VSyncCheckBox;
private readonly CheckBox FullscreenCheckBox; private readonly CheckBox FullscreenCheckBox;
private readonly OptionButton LightingPresetOption; private readonly OptionButton LightingPresetOption;
private readonly OptionButton _uiScaleOption;
public GraphicsControl(IConfigurationManager cfg) public GraphicsControl(IConfigurationManager cfg)
{ {
@@ -42,7 +54,7 @@ namespace Content.Client.UserInterface
LightingPresetOption.AddItem(Loc.GetString("High")); LightingPresetOption.AddItem(Loc.GetString("High"));
LightingPresetOption.OnItemSelected += OnLightingQualityChanged; LightingPresetOption.OnItemSelected += OnLightingQualityChanged;
var lightingHBox = new HBoxContainer contents.AddChild(new HBoxContainer
{ {
Children = Children =
{ {
@@ -50,8 +62,7 @@ namespace Content.Client.UserInterface
new Control {CustomMinimumSize = (4, 0)}, new Control {CustomMinimumSize = (4, 0)},
LightingPresetOption LightingPresetOption
} }
}; });
contents.AddChild(lightingHBox);
ApplyButton = new Button ApplyButton = new Button
{ {
@@ -61,10 +72,24 @@ namespace Content.Client.UserInterface
var resourceCache = IoCManager.Resolve<IResourceCache>(); var resourceCache = IoCManager.Resolve<IResourceCache>();
contents.AddChild(new Placeholder(resourceCache) _uiScaleOption = new OptionButton();
_uiScaleOption.AddItem(Loc.GetString("Automatic ({0}%)", UserInterfaceManager.DefaultUIScale * 100));
_uiScaleOption.AddItem(Loc.GetString("75%"));
_uiScaleOption.AddItem(Loc.GetString("100%"));
_uiScaleOption.AddItem(Loc.GetString("125%"));
_uiScaleOption.AddItem(Loc.GetString("150%"));
_uiScaleOption.AddItem(Loc.GetString("175%"));
_uiScaleOption.AddItem(Loc.GetString("200%"));
_uiScaleOption.OnItemSelected += OnUIScaleChanged;
contents.AddChild(new HBoxContainer
{ {
SizeFlagsVertical = SizeFlags.FillExpand, Children =
PlaceholderText = "UI Scaling" {
new Label {Text = Loc.GetString("UI Scale:")},
new Control {CustomMinimumSize = (4, 0)},
_uiScaleOption
}
}); });
contents.AddChild(new Placeholder(resourceCache) contents.AddChild(new Placeholder(resourceCache)
@@ -99,17 +124,24 @@ namespace Content.Client.UserInterface
VSyncCheckBox.Pressed = _cfg.GetCVar<bool>("display.vsync"); VSyncCheckBox.Pressed = _cfg.GetCVar<bool>("display.vsync");
FullscreenCheckBox.Pressed = ConfigIsFullscreen; FullscreenCheckBox.Pressed = ConfigIsFullscreen;
LightingPresetOption.SelectId(GetConfigLightingQuality()); LightingPresetOption.SelectId(GetConfigLightingQuality());
_uiScaleOption.SelectId(GetConfigUIScalePreset(ConfigUIScale));
AddChild(vBox); AddChild(vBox);
} }
private void OnUIScaleChanged(OptionButton.ItemSelectedEventArgs args)
{
_uiScaleOption.SelectId(args.Id);
UpdateApplyButton();
}
private void OnApplyButtonPressed(BaseButton.ButtonEventArgs args) private void OnApplyButtonPressed(BaseButton.ButtonEventArgs args)
{ {
_cfg.SetCVar("display.vsync", VSyncCheckBox.Pressed); _cfg.SetCVar("display.vsync", VSyncCheckBox.Pressed);
SetConfigLightingQuality(LightingPresetOption.SelectedId); SetConfigLightingQuality(LightingPresetOption.SelectedId);
_cfg.SetCVar("display.windowmode", _cfg.SetCVar("display.windowmode",
(int) (FullscreenCheckBox.Pressed ? WindowMode.Fullscreen : WindowMode.Windowed)); (int) (FullscreenCheckBox.Pressed ? WindowMode.Fullscreen : WindowMode.Windowed));
_cfg.SetCVar("display.uiScale", UIScaleOptions[_uiScaleOption.SelectedId]);
_cfg.SaveToFile(); _cfg.SaveToFile();
UpdateApplyButton(); UpdateApplyButton();
} }
@@ -130,12 +162,15 @@ namespace Content.Client.UserInterface
var isVSyncSame = VSyncCheckBox.Pressed == _cfg.GetCVar<bool>("display.vsync"); var isVSyncSame = VSyncCheckBox.Pressed == _cfg.GetCVar<bool>("display.vsync");
var isFullscreenSame = FullscreenCheckBox.Pressed == ConfigIsFullscreen; var isFullscreenSame = FullscreenCheckBox.Pressed == ConfigIsFullscreen;
var isLightingQualitySame = LightingPresetOption.SelectedId == GetConfigLightingQuality(); var isLightingQualitySame = LightingPresetOption.SelectedId == GetConfigLightingQuality();
ApplyButton.Disabled = isVSyncSame && isFullscreenSame && isLightingQualitySame; var isUIScaleSame = MathHelper.CloseTo(UIScaleOptions[_uiScaleOption.SelectedId], ConfigUIScale);
ApplyButton.Disabled = isVSyncSame && isFullscreenSame && isLightingQualitySame && isUIScaleSame;
} }
private bool ConfigIsFullscreen => private bool ConfigIsFullscreen =>
_cfg.GetCVar<int>("display.windowmode") == (int) WindowMode.Fullscreen; _cfg.GetCVar<int>("display.windowmode") == (int) WindowMode.Fullscreen;
private float ConfigUIScale => _cfg.GetCVar<float>("display.uiScale");
private int GetConfigLightingQuality() private int GetConfigLightingQuality()
{ {
var val = _cfg.GetCVar<int>("display.lightmapdivider"); var val = _cfg.GetCVar<int>("display.lightmapdivider");
@@ -180,6 +215,19 @@ namespace Content.Client.UserInterface
break; break;
} }
} }
private static int GetConfigUIScalePreset(float value)
{
for (var i = 0; i < UIScaleOptions.Length; i++)
{
if (MathHelper.CloseTo(UIScaleOptions[i], value))
{
return i;
}
}
return 0;
}
} }
} }
} }

View File

@@ -375,7 +375,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
else else
{ {
projectile = projectile =
Owner.EntityManager.SpawnEntity(baseProjectile.Prototype.ID, Owner.Transform.Coordinates); Owner.EntityManager.SpawnEntity(baseProjectile.Prototype.ID, Owner.Transform.MapPosition);
} }
Angle projectileAngle; Angle projectileAngle;
@@ -391,7 +391,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
var collidableComponent = projectile.GetComponent<ICollidableComponent>(); var collidableComponent = projectile.GetComponent<ICollidableComponent>();
collidableComponent.Status = BodyStatus.InAir; collidableComponent.Status = BodyStatus.InAir;
projectile.Transform.Coordinates = Owner.Transform.Coordinates; projectile.Transform.WorldPosition = Owner.Transform.MapPosition.Position;
var projectileComponent = projectile.GetComponent<ProjectileComponent>(); var projectileComponent = projectile.GetComponent<ProjectileComponent>();
projectileComponent.IgnoreEntity(shooter); projectileComponent.IgnoreEntity(shooter);