Skip to content

Commit

Permalink
Wall map development
Browse files Browse the repository at this point in the history
  • Loading branch information
TheArturZh committed Aug 13, 2023
1 parent 8ad8335 commit cddc6be
Show file tree
Hide file tree
Showing 9 changed files with 189 additions and 4 deletions.
15 changes: 15 additions & 0 deletions Content.Client/SS220/PictureViewer/PictureViewer.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Control xmlns="https://spacestation14.io"
MouseFilter="Stop"
MinSize="100 100">

<Label
Name="NoImageLabel" Text="{Loc 'image-viewer-no-image'}"
HorizontalAlignment="Center"
VerticalAlignment="Center"
MouseFilter="Ignore"/>

<TextureRect
Name="Picture"
Stretch="KeepCentered"
MouseFilter="Ignore"/>
</Control>
106 changes: 106 additions & 0 deletions Content.Client/SS220/PictureViewer/PictureViewer.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
using System.Numerics;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Input;
using Robust.Shared.Utility;

namespace Content.Client.SS220.PictureViewer;

[GenerateTypedNameReferences]
public sealed partial class PictureViewer : Control
{
private ResPath _viewedPicture;

private const float ScrollSensitivity = 0.1f;
private const float MaxZoom = 10f;

private float _zoom = 1f;
private bool _draggin = false;
private Vector2 _offset = Vector2.Zero;

public ResPath ViewedPicture
{
get => _viewedPicture;
set
{
_viewedPicture = value;
Picture.TexturePath = value.ToString();
}
}

private void UpdateZoom()
{
var invZoom = 1 / _zoom;
Picture.TextureScale = new Vector2(invZoom, invZoom);
}

private void UpdateOffset()
{
//Picture.Margin = new Thickness(_offset.X, _offset.Y);
var position = _offset;
var rect = UIBox2.FromDimensions(position, this.Size);
Picture.Arrange(rect);
}

protected override void MouseWheel(GUIMouseWheelEventArgs args)
{
base.MouseWheel(args);
_zoom -= args.Delta.Y * ScrollSensitivity;
_zoom = float.Clamp(_zoom, 1, MaxZoom);
Logger.DebugS("ZOOM: ", _zoom.ToString());
UpdateZoom();
UpdateOffset();

args.Handle();
}

protected override void KeyBindDown(GUIBoundKeyEventArgs args)
{
base.KeyBindDown(args);

if (args.Function == EngineKeyFunctions.Use)
{
_draggin = true;
}
}

protected override void KeyBindUp(GUIBoundKeyEventArgs args)
{
base.KeyBindUp(args);

if (args.Function == EngineKeyFunctions.Use)
{
_draggin = false;
}
}

protected override void MouseMove(GUIMouseMoveEventArgs args)
{
base.MouseMove(args);

if (!_draggin)
return;

//_recentering = false;
_offset += new Vector2(args.Relative.X, args.Relative.Y);
Logger.DebugS("OFFSET: ", _offset.ToString());
UpdateOffset();

/*
if (_offset != Vector2.Zero)
{
_recenter.Disabled = false;
}
else
{
_recenter.Disabled = true;
}
*/
}

public PictureViewer()
{
RobustXamlLoader.Load(this);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<DefaultWindow xmlns="https://spacestation14.io"
xmlns:pv="clr-namespace:Content.Client.SS220.PictureViewer"
Title="{Loc 'viewable-station-map-ui-window-title'}"
MinSize="300 300"
SetSize="725 725">
<pv:PictureViewer Name="Viewer"/>
</DefaultWindow>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Utility;

namespace Content.Client.SS220.ViewableStationMap.UI;

[GenerateTypedNameReferences]
public sealed partial class ViewableStationMapWindow : DefaultWindow
{
public ResPath ViewedMap
{
get => Viewer.ViewedPicture;
set => Viewer.ViewedPicture = value;
}

public ViewableStationMapWindow()
{
RobustXamlLoader.Load(this);
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,40 @@
using Robust.Client.GameObjects;
using Robust.Shared.Serialization.TypeSerializers.Implementations;
using Content.Client.SS220.ViewableStationMap.UI;
using Content.Shared.SS220.ViewableStationMap;
using JetBrains.Annotations;

namespace Content.Client.SS220.ViewableStationMap;

public sealed class ViewableStationMapBoundUserInterface : BoundUserInterface
[UsedImplicitly]
public sealed class StationViewableMapBoundUserInterface : BoundUserInterface
{
public ViewableStationMapBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
[Dependency] private readonly IEntityManager _entMan = default!;

private ViewableStationMapWindow? _window;

public StationViewableMapBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
}

/// <inheritdoc/>
protected override void Open()
{
base.Open();

_window = new ViewableStationMapWindow();
_window.OpenCentered();

_window.OnClose += Close;

if (_entMan.TryGetComponent(Owner, out ViewableStationMapComponent? comp))
_window.ViewedMap = SpriteSpecifierSerializer.TextureRoot/comp.MapTexture;
}

protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (disposing)
_window?.Dispose();
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using JetBrains.Annotations;
using Robust.Shared.Serialization;
using Robust.Shared.Utility;

namespace Content.Shared.SS220.ViewableStationMap;
Expand All @@ -7,9 +9,10 @@ public sealed class ViewableStationMapComponent : Component
{
[ViewVariables(VVAccess.ReadOnly)]
[DataField("mapTexture")]
public SpriteSpecifier? MapTexture;
public string MapTexture = string.Empty;
}

[Serializable, NetSerializable, UsedImplicitly]
public enum ViewableStationMapUiKey
{
Key,
Expand Down
1 change: 1 addition & 0 deletions Resources/Locale/ru-RU/ss220/picture-viewer.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
image-viewer-no-image = К сожалению карты для этой станции пока еще нет. Увы!
1 change: 1 addition & 0 deletions Resources/Locale/ru-RU/ss220/wall-map.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
viewable-station-map-ui-window-title = карта станции
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
- type: Sprite
state: metamap64x
sprite: Structures/Wallmounts/metamap.rsi
- type: ActivatableUI
key: enum.ViewableStationMapUiKey.Key
- type: ActivatableUIRequiresVision
- type: UserInterface
interfaces:
- key: enum.ViewableStationMapUiKey.Key
type: ViewableStationMapBoundUserInterface
type: StationViewableMapBoundUserInterface

0 comments on commit cddc6be

Please sign in to comment.