Skip to content

Commit

Permalink
Implement MAP's icon-size property
Browse files Browse the repository at this point in the history
  • Loading branch information
wixoaGit committed Mar 2, 2024
1 parent 39f99ac commit a59e8af
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
26 changes: 19 additions & 7 deletions OpenDreamClient/Interface/Controls/ControlMap.cs
Original file line number Diff line number Diff line change
@@ -1,37 +1,49 @@
using OpenDreamClient.Input;
using OpenDreamClient.Interface.Descriptors;
using OpenDreamShared.Dream;
using Robust.Client.Graphics;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Input;

namespace OpenDreamClient.Interface.Controls;

public sealed class ControlMap : InterfaceControl {
public sealed class ControlMap(ControlDescriptor controlDescriptor, ControlWindow window) : InterfaceControl(controlDescriptor, window) {
public ScalingViewport Viewport { get; private set; }

[Dependency] private readonly IEntitySystemManager _entitySystemManager = default!;
private MouseInputSystem _mouseInput;
private MouseInputSystem? _mouseInput;

public ControlMap(ControlDescriptor controlDescriptor, ControlWindow window) : base(controlDescriptor, window) { }
private ControlDescriptorMap MapDescriptor => (ControlDescriptorMap)ElementDescriptor;

protected override void UpdateElementDescriptor() {
base.UpdateElementDescriptor();

ControlDescriptorMap mapDescriptor = (ControlDescriptorMap)ElementDescriptor;

Viewport.StretchMode = mapDescriptor.ZoomMode switch {
Viewport.StretchMode = MapDescriptor.ZoomMode switch {
"blur" => ScalingViewportStretchMode.Bilinear,
"distort" => ScalingViewportStretchMode.Nearest,

// TODO: "tries to keep the look of individual pixels,
// but will adjust to non-integer zooms (like 1.1x) by blending neighboring pixels"
"normal" or _ => ScalingViewportStretchMode.Nearest
};

UpdateViewRange(_interfaceManager.View);
}

public void UpdateViewRange(ViewRange view) {
Viewport.ViewportSize = (Math.Max(view.Width, 1) * 32, Math.Max(view.Height, 1) * 32);
var viewWidth = Math.Max(view.Width, 1);
var viewHeight = Math.Max(view.Height, 1);

Viewport.ViewportSize = new Vector2i(viewWidth, viewHeight) * EyeManager.PixelsPerMeter;
if (MapDescriptor.IconSize != 0) {
Viewport.SetWidth = MapDescriptor.IconSize * viewWidth;
Viewport.SetHeight = MapDescriptor.IconSize * viewHeight;
} else {
// icon-size of 0 means stretch to fit the available space
Viewport.SetWidth = float.NaN;
Viewport.SetHeight = float.NaN;
}
}

protected override Control CreateUIElement() {
Expand Down
2 changes: 2 additions & 0 deletions OpenDreamClient/Interface/Descriptors/ControlDescriptors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ public sealed partial class ControlDescriptorMap : ControlDescriptor {
public string? OnHideCommand;
[DataField("zoom-mode")]
public string ZoomMode = "normal";
[DataField("icon-size")]
public int IconSize;
}

public sealed partial class ControlDescriptorBrowser : ControlDescriptor {
Expand Down

0 comments on commit a59e8af

Please sign in to comment.