Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experimental screen edge loc implementation #2111

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion OpenDreamClient/Rendering/DreamViewOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -672,8 +672,16 @@
if (sprite.ScreenLocation.MapControl != null) // Don't render screen objects meant for other map controls
continue;

Vector2 position = sprite.ScreenLocation.GetViewPosition(worldAABB.BottomLeft, _interfaceManager.View, EyeManager.PixelsPerMeter);
Vector2 iconSize = sprite.Icon.DMI == null ? Vector2.Zero : sprite.Icon.DMI.IconSize / (float)EyeManager.PixelsPerMeter;
Interface.Descriptors.ControlDescriptorMap mapDescriptor = (Interface.Descriptors.ControlDescriptorMap) _interfaceManager.DefaultMap.ElementDescriptor;

Check warning

Code scanning / InspectCode

Dereference of a possibly null reference. Warning

Dereference of a possibly null reference
var viewport = _interfaceManager.DefaultMap.Viewport;
float mapZoom = mapDescriptor.IconSize.Value != 0 ? EyeManager.PixelsPerMeter / (float) mapDescriptor.IconSize.Value : 1;

Check warning

Code scanning / InspectCode

Redundant cast Warning

Type cast is redundant
// Limit the viewport drawbox just to what's visible on-screen.
var drawBox = viewport.GetDrawBox().Intersection(_interfaceManager.DefaultMap.Viewport.GlobalPixelRect.Intersection(_interfaceManager.DefaultMap.UIElement.GlobalPixelRect) ?? UIBox2i.FromDimensions(0, 0, 0, 0)) ?? UIBox2i.FromDimensions(0, 0, 0, 0);
Vector2 viewportTileSize = Vector2.Min(drawBox.Size, viewport.Size) * mapZoom / (float)EyeManager.PixelsPerMeter;

Check warning

Code scanning / InspectCode

Redundant cast Warning

Type cast is redundant
// WorldAABB.BottomLeft is offscreen, so instead we use drawBox to get the onscreen component.
MapCoordinates viewOffset = viewport.ScreenToMap(drawBox.BottomLeft);
Vector2 position = sprite.ScreenLocation.GetViewPosition(viewOffset.Position, _interfaceManager.View, EyeManager.PixelsPerMeter, iconSize, viewportTileSize);
for (int x = 0; x < sprite.ScreenLocation.RepeatX; x++) {
for (int y = 0; y < sprite.ScreenLocation.RepeatY; y++) {
tValue = 0;
Expand Down
57 changes: 41 additions & 16 deletions OpenDreamShared/Dream/ScreenLocation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,24 @@
using System.Linq;
using System.Text;
using Robust.Shared.Log;
using Robust.Shared.Maths;

Check warning

Code scanning / InspectCode

Redundant using directive Warning

Using directive is not required by the code and can be safely removed

namespace OpenDreamShared.Dream;

public enum HorizontalAnchor {
Left,
Center,
Right
Right,
West,
East
}

public enum VerticalAnchor {
Bottom,
Center,
Top
Top,
South,
North
}

[Serializable, NetSerializable]
Expand Down Expand Up @@ -66,20 +71,24 @@
ParseScreenLoc(screenLocation);
}

public Vector2 GetViewPosition(Vector2 viewOffset, ViewRange view, float iconSize) {
float x = (X + PixelOffsetX / iconSize);
public Vector2 GetViewPosition(Vector2 viewOffset, ViewRange view, float worldIconSize, Vector2 spriteIconSize, Vector2 controlSize) {
float x = (X + PixelOffsetX / worldIconSize);
x += HorizontalAnchor switch {
HorizontalAnchor.Left => 0,
HorizontalAnchor.Center => view.CenterX,
HorizontalAnchor.Right => view.Width - 1,
HorizontalAnchor.Left => spriteIconSize.X - 1,
HorizontalAnchor.West => 0,
HorizontalAnchor.Center => controlSize.X / 2,
HorizontalAnchor.East => view.Width - 1,
HorizontalAnchor.Right => controlSize.X - spriteIconSize.X,
_ => throw new Exception($"Invalid horizontal anchor {HorizontalAnchor}")
};

float y = (Y + PixelOffsetY / iconSize);
float y = (Y + PixelOffsetY / worldIconSize);
y += VerticalAnchor switch {
VerticalAnchor.Bottom => 0,
VerticalAnchor.Center => view.CenterY,
VerticalAnchor.Top => view.Height - 1,
VerticalAnchor.Bottom => spriteIconSize.Y - 1,
VerticalAnchor.South => 0,
VerticalAnchor.Center => controlSize.Y / 2,
VerticalAnchor.North => view.Height - 1,
VerticalAnchor.Top => controlSize.Y - spriteIconSize.Y,
_ => throw new Exception($"Invalid vertical anchor {VerticalAnchor}")
};

Expand Down Expand Up @@ -121,10 +130,14 @@

(HorizontalAnchor, VerticalAnchor) = coordinateSplit[0].Trim() switch {
"CENTER" => (HorizontalAnchor.Center, VerticalAnchor.Center),
"NORTHWEST" or "TOPLEFT" => (HorizontalAnchor.Left, VerticalAnchor.Top),
"NORTHEAST" or "TOPRIGHT" => (HorizontalAnchor.Right, VerticalAnchor.Top),
"SOUTHWEST" or "BOTTOMLEFT" => (HorizontalAnchor.Left, VerticalAnchor.Bottom),
"SOUTHEAST" or "BOTTOMRIGHT" => (HorizontalAnchor.Right, VerticalAnchor.Bottom),
"NORTHWEST" => (HorizontalAnchor.West, VerticalAnchor.North),
"TOPLEFT" => (HorizontalAnchor.Left, VerticalAnchor.Top),
"NORTHEAST" => (HorizontalAnchor.East, VerticalAnchor.North),
"TOPRIGHT" => (HorizontalAnchor.Right, VerticalAnchor.Top),
"SOUTHWEST" => (HorizontalAnchor.West, VerticalAnchor.South),
"BOTTOMLEFT" => (HorizontalAnchor.Left, VerticalAnchor.Bottom),
"SOUTHEAST" => (HorizontalAnchor.East, VerticalAnchor.South),
"BOTTOMRIGHT" => (HorizontalAnchor.Right, VerticalAnchor.Bottom),
_ => throw new Exception($"Invalid screen_loc {screenLoc}")
};

Expand Down Expand Up @@ -193,23 +206,35 @@

break;
case "WEST":
case "LEFT":
// Yes, this sets the horizontal anchor regardless of the isHorizontal arg.
// Every macro sets their respective axis regardless of which coordinate it's in
HorizontalAnchor = HorizontalAnchor.West;
settingHorizontal = true;
break;
case "LEFT":
HorizontalAnchor = HorizontalAnchor.Left;
settingHorizontal = true;
break;
case "EAST":
HorizontalAnchor = HorizontalAnchor.East;
settingHorizontal = true;
break;
case "RIGHT":
HorizontalAnchor = HorizontalAnchor.Right;
settingHorizontal = true;
break;
case "NORTH":
VerticalAnchor = VerticalAnchor.North;
settingHorizontal = false;
break;
case "TOP":
VerticalAnchor = VerticalAnchor.Top;
settingHorizontal = false;
break;
case "SOUTH":
VerticalAnchor = VerticalAnchor.South;
settingHorizontal = false;
break;
case "BOTTOM":
VerticalAnchor = VerticalAnchor.Bottom;
settingHorizontal = false;
Expand Down
Loading