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

Basic Maptext #2108

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
10 changes: 5 additions & 5 deletions DMCompiler/DMStandard/Types/Atoms/_Atom.dm
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@
var/gender = NEUTER
var/density = FALSE

var/maptext as opendream_unimplemented
var/maptext = null

var/list/filters = null
var/appearance
var/appearance_flags = 0
var/maptext_width as opendream_unimplemented
var/maptext_height as opendream_unimplemented
var/maptext_x = 32 as opendream_unimplemented
var/maptext_y = 32 as opendream_unimplemented
var/maptext_width = 32
var/maptext_height = 32
var/maptext_x = 0
var/maptext_y = 0
var/step_x as opendream_unimplemented
var/step_y as opendream_unimplemented
var/render_source
Expand Down
10 changes: 5 additions & 5 deletions DMCompiler/DMStandard/Types/Image.dm
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
var/list/filters = list()
var/layer = FLOAT_LAYER
var/luminosity = 0 as opendream_unimplemented
var/maptext = "i" as opendream_unimplemented
var/maptext_width = 32 as opendream_unimplemented
var/maptext_height = 32 as opendream_unimplemented
var/maptext_x = 0 as opendream_unimplemented
var/maptext_y = 0 as opendream_unimplemented
var/maptext = null
var/maptext_width = 32
var/maptext_height = 32
var/maptext_x = 0
var/maptext_y = 0
var/mouse_over_pointer = 0 as opendream_unimplemented
var/mouse_drag_pointer = 0 as opendream_unimplemented
var/mouse_drop_pointer = 1 as opendream_unimplemented
Expand Down
34 changes: 15 additions & 19 deletions OpenDreamClient/Rendering/DreamIcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@
TextureRenderOffset = Vector2.Zero;
return frame;
} else {
if(textureOverride is not null)
return FullRenderTexture(viewOverlay, handle, iconMetaData, frame).Texture; //no caching in the presence of overrides
CachedTexture = FullRenderTexture(viewOverlay, handle, iconMetaData, frame);
}

Expand Down Expand Up @@ -156,7 +158,7 @@
_appearanceAnimations[i] = lastAnim;
break;
}

_appearanceAnimations.Add(new AppearanceAnimation(start, duration, endingAppearance, easing, flags, delay, true));
}

Expand Down Expand Up @@ -319,11 +321,9 @@
if (endAppearance.Invisibility != _appearance.Invisibility) {
appearance.Invisibility = endAppearance.Invisibility;
}
/* TODO maptext
if (endAppearance.MapText != _appearance.MapText) {
appearance.MapText = endAppearance.MapText;
if (endAppearance.Maptext != _appearance.Maptext) {
Fixed Show fixed Hide fixed
appearance.Maptext = endAppearance.Maptext;
}
*/
/* TODO suffix
if (endAppearance.Suffix != _appearance.Suffix) {
appearance.Suffix = endAppearance.Suffix;
Expand Down Expand Up @@ -381,24 +381,20 @@
}
*/

/* TODO maptext
if (endAppearance.MapTextWidth != _appearance.MapTextWidth) {
appearance.MapTextWidth = (ushort)Math.Clamp(((1-factor) * _appearance.MapTextWidth) + (factor * endAppearance.MapTextWidth), 0, 65535);
}

if (endAppearance.MapTextHeight != _appearance.MapTextHeight) {
appearance.MapTextHeight = (ushort)Math.Clamp(((1-factor) * _appearance.MapTextHeight) + (factor * endAppearance.MapTextHeight), 0, 65535);
if (endAppearance.MaptextSize != _appearance.MaptextSize) {
appearance.MaptextSize = new Vector2i(
(int)Math.Round(((1-factor) * _appearance.MaptextSize.X) + (factor * endAppearance.MaptextSize.X)),
(int)Math.Round(((1-factor) * _appearance.MaptextSize.Y) + (factor * endAppearance.MaptextSize.Y))
);
}

if (endAppearance.MapTextX != _appearance.MapTextX) {
appearance.MapTextX = (short)Math.Clamp(((1-factor) * _appearance.MapTextX) + (factor * endAppearance.MapTextX), -32768, 32767);
if (endAppearance.MaptextOffset != _appearance.MaptextOffset) {
appearance.MaptextOffset = new Vector2i(
(int)Math.Round(((1-factor) * _appearance.MaptextOffset.X) + (factor * endAppearance.MaptextOffset.X)),
(int)Math.Round(((1-factor) * _appearance.MaptextOffset.Y) + (factor * endAppearance.MaptextOffset.Y))
);
}

if (endAppearance.MapTextY != _appearance.MapTextY) {
appearance.MapTextY = (short)Math.Clamp(((1-factor) * _appearance.MapTextY) + (factor * endAppearance.MapTextY), -32768, 32767);
}
*/

if (endAppearance.PixelOffset != _appearance.PixelOffset) {
Vector2 startingOffset = appearance.PixelOffset;
Vector2 newPixelOffset = Vector2.Lerp(startingOffset, endAppearance.PixelOffset, 1.0f-factor);
Expand Down
70 changes: 69 additions & 1 deletion OpenDreamClient/Rendering/DreamViewOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using OpenDreamClient.Interface;
using Robust.Client.Graphics;
using Robust.Client.Player;
using Robust.Client.UserInterface;
Fixed Show fixed Hide fixed
using Robust.Shared.Utility;
Fixed Show fixed Hide fixed
using Robust.Shared.Enums;
using Robust.Shared.Map;
using OpenDreamShared.Dream;
Expand All @@ -13,6 +15,8 @@
using Robust.Shared.Profiling;
using Vector3 = Robust.Shared.Maths.Vector3;
using Matrix3x2 = System.Numerics.Matrix3x2;
using Robust.Client.UserInterface.RichText;
Fixed Show fixed Hide fixed
using Robust.Client.ResourceManagement;

namespace OpenDreamClient.Rendering;

Expand Down Expand Up @@ -40,6 +44,9 @@
[Dependency] private readonly IClyde _clyde = default!;
[Dependency] private readonly IPrototypeManager _protoManager = default!;
[Dependency] private readonly ProfManager _prof = default!;
[Dependency] private readonly IResourceCache _resourceCache = default!;
Fixed Show fixed Hide fixed
amylizzle marked this conversation as resolved.
Show resolved Hide resolved

private Font _defaultMaptextFont;
Fixed Show fixed Hide fixed

private readonly ISawmill _sawmill = Logger.GetSawmill("opendream.view");

Expand Down Expand Up @@ -83,6 +90,7 @@
_appearanceSystem = appearanceSystem;
_screenOverlaySystem = screenOverlaySystem;
_clientImagesSystem = clientImagesSystem;
_defaultMaptextFont = new VectorFont(_resourceCache.GetResource<FontResource>("/Fonts/NotoSans-Regular.ttf"),8);

_spriteQuery = _entityManager.GetEntityQuery<DMISpriteComponent>();
_xformQuery = _entityManager.GetEntityQuery<TransformComponent>();
Expand Down Expand Up @@ -334,7 +342,35 @@
// TODO: vis_flags
}

//TODO maptext - note colour + transform apply
//maptext is basically just an image of rendered text added as an overlay
if(icon.Appearance.Maptext != null){ //if has maptext
RendererMetaData maptext = RentRendererMetaData();
maptext.MainIcon = icon;
maptext.Position = current.Position;
maptext.Uid = current.Uid;
maptext.ClickUid = current.Uid;
maptext.IsScreen = current.IsScreen;
tieBreaker++;
maptext.TieBreaker = tieBreaker;
maptext.Plane = current.Plane;
maptext.Layer = current.Layer;
maptext.RenderSource = null;
maptext.RenderTarget = null;
maptext.MouseOpacity = current.MouseOpacity;
maptext.TransformToApply = current.TransformToApply;
maptext.ColorToApply = current.ColorToApply;
maptext.ColorMatrixToApply = current.ColorMatrixToApply;
maptext.AlphaToApply = current.AlphaToApply;
maptext.BlendMode = current.BlendMode;

maptext.AppearanceFlags = current.AppearanceFlags;
maptext.AppearanceFlags &= ~AppearanceFlags.PlaneMaster; //doesn't make sense for maptext

maptext.Maptext = icon.Appearance.Maptext;
maptext.MaptextSize = icon.Appearance.MaptextSize;
maptext.Position += icon.Appearance.MaptextOffset/(float)EyeManager.PixelsPerMeter;
result.Add(maptext);
}

//TODO particles - colour and transform don't apply?

Expand Down Expand Up @@ -396,6 +432,11 @@
positionOffset -= ((ktSize/EyeManager.PixelsPerMeter) - Vector2.One) * new Vector2(0.5f); //correct for KT group texture offset
}

//Maptext
if(iconMetaData.Maptext != null){
iconMetaData.TextureOverride = GetTextureFromMaptext(iconMetaData.Maptext, iconMetaData.MaptextSize!.Value.X, iconMetaData.MaptextSize!.Value.Y, handle);
}

var frame = iconMetaData.GetTexture(this, handle);
var pixelPosition = (iconMetaData.Position + positionOffset) * EyeManager.PixelsPerMeter;

Expand Down Expand Up @@ -752,6 +793,29 @@
return ktTexture.Texture;
}

public Texture GetTextureFromMaptext(string maptext, int width, int height, DrawingHandleWorld handle) {
if(width == 0) width = 32;
if(height == 0) height = 32;
IRenderTexture tempTexture = _renderTargetPool.Rent(new Vector2i(width, height));
handle.RenderInRenderTarget(tempTexture, () => {
handle.SetTransform(CreateRenderTargetFlipMatrix(tempTexture.Size, Vector2.Zero));
float scale = 1;
var font = _defaultMaptextFont;
var baseLine = new Vector2(0, 0);
var lineHeight = font.GetLineHeight(scale);
Fixed Show fixed Hide fixed
foreach (var rune in maptext.EnumerateRunes()){
var metric = font.GetCharMetrics(rune, scale);
Vector2 mod = new Vector2(0);
if(metric.HasValue)
mod.Y += metric.Value.BearingY - (metric.Value.Height - metric.Value.BearingY);

baseLine.X += font.DrawChar(handle, rune, baseLine+mod, scale, Color.White);
}
}, Color.Transparent);
_renderTargetPool.ReturnAtEndOfFrame(tempTexture);
return tempTexture.Texture;
}

/// <summary>
/// Creates a transformation matrix that counteracts RT's
/// <see cref="DrawingHandleBase.RenderInRenderTarget(IRenderTarget,Action,System.Nullable{Robust.Shared.Maths.Color})"/> quirks
Expand Down Expand Up @@ -808,6 +872,8 @@
public BlendMode BlendMode;
public MouseOpacity MouseOpacity;
public Texture? TextureOverride;
public string? Maptext;
public Vector2i? MaptextSize;

public bool IsPlaneMaster => (AppearanceFlags & AppearanceFlags.PlaneMaster) != 0;
public bool HasRenderSource => !string.IsNullOrEmpty(RenderSource);
Expand Down Expand Up @@ -837,6 +903,8 @@
BlendMode = BlendMode.Default;
MouseOpacity = MouseOpacity.Transparent;
TextureOverride = null;
Maptext = null;
MaptextSize = null;
}

public Texture? GetTexture(DreamViewOverlay viewOverlay, DrawingHandleWorld handle) {
Expand Down
35 changes: 35 additions & 0 deletions OpenDreamRuntime/AtomManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,11 @@ public bool IsValidAppearanceVar(string name) {
case "verbs":
case "overlays":
case "underlays":
case "maptext":
case "maptext_width":
case "maptext_height":
case "maptext_x":
case "maptext_y":
return true;

// Get/SetAppearanceVar doesn't handle filters right now
Expand Down Expand Up @@ -367,6 +372,24 @@ public void SetAppearanceVar(IconAppearance appearance, string varName, DreamVal
appearance.Verbs.Add(verb.VerbId!.Value);
}

break;
case "maptext":
if(value == DreamValue.Null)
appearance.Maptext = null;
else
value.TryGetValueAsString(out appearance.Maptext);
break;
case "maptext_height":
value.TryGetValueAsInteger(out appearance.MaptextSize.Y);
break;
case "maptext_width":
value.TryGetValueAsInteger(out appearance.MaptextSize.X);
break;
case "maptext_x":
value.TryGetValueAsInteger(out appearance.MaptextOffset.X);
break;
case "maptext_y":
value.TryGetValueAsInteger(out appearance.MaptextOffset.Y);
break;
case "appearance":
throw new Exception("Cannot assign the appearance var on an appearance");
Expand Down Expand Up @@ -455,6 +478,18 @@ public DreamValue GetAppearanceVar(IconAppearance appearance, string varName) {
transform[1], transform[3], transform[5]);

return new(matrix);
case "maptext":
return (appearance.Maptext != null)
? new DreamValue(appearance.Maptext)
: DreamValue.Null;
case "maptext_height":
return new(appearance.MaptextSize.Y);
case "maptext_width":
return new(appearance.MaptextSize.X);
case "maptext_x":
return new(appearance.MaptextOffset.X);
case "maptext_y":
return new(appearance.MaptextOffset.Y);
case "appearance":
IconAppearance appearanceCopy = new IconAppearance(appearance); // Return a copy
return new(appearanceCopy);
Expand Down
33 changes: 24 additions & 9 deletions OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public static DreamValue NativeProc_animate(NativeProc.Bundle bundle, DreamObjec
return DreamValue.Null;
chainAnim = true;
}

bundle.LastAnimatedObject = new DreamValue(obj);
if(obj.IsSubtypeOf(bundle.ObjectTree.Filter)) {//TODO animate filters
return DreamValue.Null;
Expand Down Expand Up @@ -210,14 +210,16 @@ public static DreamValue NativeProc_animate(NativeProc.Bundle bundle, DreamObjec
/* TODO these are not yet implemented
if(!pixelZ.IsNull)
pixelZ = new(pixelZ.UnsafeGetValueAsFloat() + obj.GetVariable("pixel_z").UnsafeGetValueAsFloat()); //TODO change to appearance when pixel_z is implemented
*/
if(!maptextWidth.IsNull)
maptextWidth = new(maptextWidth.UnsafeGetValueAsFloat() + obj.GetVariable("maptext_width").UnsafeGetValueAsFloat()); //TODO change to appearance when maptext_width is implemented
maptextWidth = new(maptextWidth.UnsafeGetValueAsFloat() + appearance.MaptextSize.X);
if(!maptextHeight.IsNull)
maptextHeight = new(maptextHeight.UnsafeGetValueAsFloat() + obj.GetVariable("maptext_height").UnsafeGetValueAsFloat()); //TODO change to appearance when maptext_height is implemented
maptextHeight = new(maptextHeight.UnsafeGetValueAsFloat() + appearance.MaptextSize.Y);
if(!maptextX.IsNull)
maptextX = new(maptextX.UnsafeGetValueAsFloat() + obj.GetVariable("maptext_x").UnsafeGetValueAsFloat()); //TODO change to appearance when maptext_x is implemented
maptextX = new(maptextX.UnsafeGetValueAsFloat() + appearance.MaptextOffset.X);
if(!maptextY.IsNull)
maptextY = new(maptextY.UnsafeGetValueAsFloat() + obj.GetVariable("maptext_y").UnsafeGetValueAsFloat()); //TODO change to appearance when maptext_y is implemented
maptextY = new(maptextY.UnsafeGetValueAsFloat() + appearance.MaptextOffset.Y);
/*
if(!luminosity.IsNull)
luminosity = new(luminosity.UnsafeGetValueAsFloat() + obj.GetVariable("luminosity").UnsafeGetValueAsFloat()); //TODO change to appearance when luminosity is implemented
*/
Expand Down Expand Up @@ -273,17 +275,30 @@ public static DreamValue NativeProc_animate(NativeProc.Bundle bundle, DreamObjec
}
*/

/* TODO maptext
if (!maptextX.IsNull) {
obj.SetVariableValue("maptext_x", maptextX);
maptextX.TryGetValueAsInteger(out appearance.MapTextOffset.X);
maptextX.TryGetValueAsInteger(out appearance.MaptextOffset.X);
}

if (!maptextY.IsNull) {
obj.SetVariableValue("maptext_y", maptextY);
maptextY.TryGetValueAsInteger(out appearance.MapTextOffset.Y);
maptextY.TryGetValueAsInteger(out appearance.MaptextOffset.Y);
}

if (!maptextWidth.IsNull) {
obj.SetVariableValue("maptext_width", maptextWidth);
maptextX.TryGetValueAsInteger(out appearance.MaptextSize.X);
}

if (!maptextHeight.IsNull) {
obj.SetVariableValue("maptext_y", maptextHeight);
maptextY.TryGetValueAsInteger(out appearance.MaptextSize.Y);
}

if(!maptext.IsNull){
obj.SetVariableValue("maptext", maptext);
maptext.TryGetValueAsString(out appearance.Maptext);
}
*/

if (!dir.IsNull) {
obj.SetVariableValue("dir", dir);
Expand Down
9 changes: 9 additions & 0 deletions OpenDreamShared/Dream/IconAppearance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
[ViewVariables] public List<NetEntity> VisContents;
[ViewVariables] public List<DreamFilter> Filters;
[ViewVariables] public List<int> Verbs;
[ViewVariables] public Vector2i MaptextSize = new(32,32);
[ViewVariables] public Vector2i MaptextOffset = new(0,0);
[ViewVariables] public string? Maptext;

/// <summary>
/// An appearance can gain a color matrix filter by two possible forces: <br/>
Expand Down Expand Up @@ -107,6 +110,8 @@
Filters = new(appearance.Filters);
Verbs = new(appearance.Verbs);
Override = appearance.Override;
Maptext = appearance.Maptext;
MaptextSize = appearance.MaptextSize;

for (int i = 0; i < 6; i++) {
Transform[i] = appearance.Transform[i];
Expand Down Expand Up @@ -144,6 +149,8 @@
if (appearance.Filters.Count != Filters.Count) return false;
if (appearance.Verbs.Count != Verbs.Count) return false;
if (appearance.Override != Override) return false;
if (appearance.Maptext != Maptext) return false;
if (appearance.MaptextSize != MaptextSize) return false;

for (int i = 0; i < Filters.Count; i++) {
if (appearance.Filters[i] != Filters[i]) return false;
Expand Down Expand Up @@ -226,6 +233,8 @@
hashCode.Add(RenderTarget);
hashCode.Add(BlendMode);
hashCode.Add(AppearanceFlags);
hashCode.Add(Maptext);
amylizzle marked this conversation as resolved.
Show resolved Hide resolved
hashCode.Add(MaptextSize);
amylizzle marked this conversation as resolved.
Show resolved Hide resolved

foreach (int overlay in Overlays) {
hashCode.Add(overlay);
Expand Down
Loading
Loading