Skip to content

Commit 3976b02

Browse files
amylizzlewixoaGit
andauthored
Basic Maptext (#2108)
Co-authored-by: amylizzle <[email protected]> Co-authored-by: wixoa <[email protected]>
1 parent 75b5cf2 commit 3976b02

File tree

9 files changed

+224
-38
lines changed

9 files changed

+224
-38
lines changed

DMCompiler/DMStandard/Types/Atoms/_Atom.dm

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@
4141
var/gender = NEUTER
4242
var/density = FALSE
4343

44-
var/maptext as opendream_unimplemented
44+
var/maptext = null
4545

4646
var/list/filters = null
4747
var/appearance
4848
var/appearance_flags = 0
49-
var/maptext_width as opendream_unimplemented
50-
var/maptext_height as opendream_unimplemented
51-
var/maptext_x = 32 as opendream_unimplemented
52-
var/maptext_y = 32 as opendream_unimplemented
49+
var/maptext_width = 32
50+
var/maptext_height = 32
51+
var/maptext_x = 0
52+
var/maptext_y = 0
5353
var/step_x as opendream_unimplemented
5454
var/step_y as opendream_unimplemented
5555
var/render_source

DMCompiler/DMStandard/Types/Image.dm

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
var/list/filters = list()
1818
var/layer = FLOAT_LAYER
1919
var/luminosity = 0 as opendream_unimplemented
20-
var/maptext = "i" as opendream_unimplemented
21-
var/maptext_width = 32 as opendream_unimplemented
22-
var/maptext_height = 32 as opendream_unimplemented
23-
var/maptext_x = 0 as opendream_unimplemented
24-
var/maptext_y = 0 as opendream_unimplemented
20+
var/maptext = null
21+
var/maptext_width = 32
22+
var/maptext_height = 32
23+
var/maptext_x = 0
24+
var/maptext_y = 0
2525
var/mouse_over_pointer = 0 as opendream_unimplemented
2626
var/mouse_drag_pointer = 0 as opendream_unimplemented
2727
var/mouse_drop_pointer = 1 as opendream_unimplemented

OpenDreamClient/Rendering/DreamIcon.cs

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ public void Dispose() {
109109
TextureRenderOffset = Vector2.Zero;
110110
return frame;
111111
} else {
112+
if(textureOverride is not null)
113+
return FullRenderTexture(viewOverlay, handle, iconMetaData, frame).Texture; //no caching in the presence of overrides
112114
CachedTexture = FullRenderTexture(viewOverlay, handle, iconMetaData, frame);
113115
}
114116

@@ -323,11 +325,9 @@ private void UpdateAnimation() {
323325
_animatedAppearance.IconState = endAppearance.IconState;
324326
if (endAppearance.Invisibility != _appearance.Invisibility)
325327
_animatedAppearance.Invisibility = endAppearance.Invisibility;
328+
if (endAppearance.Maptext != _appearance.Maptext)
329+
_animatedAppearance.Maptext = endAppearance.Maptext;
326330

327-
/* TODO maptext
328-
if (endAppearance.MapText != _appearance.MapText)
329-
appearance.MapText = endAppearance.MapText;
330-
*/
331331
/* TODO suffix
332332
if (endAppearance.Suffix != _appearance.Suffix)
333333
appearance.Suffix = endAppearance.Suffix;
@@ -383,34 +383,30 @@ private void UpdateAnimation() {
383383
}
384384
*/
385385

386-
/* TODO maptext
387-
if (endAppearance.MapTextWidth != _appearance.MapTextWidth) {
388-
appearance.MapTextWidth = (ushort)Math.Clamp(((1-factor) * _appearance.MapTextWidth) + (factor * endAppearance.MapTextWidth), 0, 65535);
389-
}
386+
if (endAppearance.MaptextSize != _appearance.MaptextSize) {
387+
Vector2 startingOffset = _appearance.MaptextSize;
388+
Vector2 newMaptextSize = Vector2.Lerp(startingOffset, endAppearance.MaptextSize, factor);
390389

391-
if (endAppearance.MapTextHeight != _appearance.MapTextHeight) {
392-
appearance.MapTextHeight = (ushort)Math.Clamp(((1-factor) * _appearance.MapTextHeight) + (factor * endAppearance.MapTextHeight), 0, 65535);
390+
_animatedAppearance.MaptextSize = (Vector2i)newMaptextSize;
393391
}
394392

395-
if (endAppearance.MapTextX != _appearance.MapTextX) {
396-
appearance.MapTextX = (short)Math.Clamp(((1-factor) * _appearance.MapTextX) + (factor * endAppearance.MapTextX), -32768, 32767);
397-
}
393+
if (endAppearance.MaptextOffset != _appearance.MaptextOffset) {
394+
Vector2 startingOffset = _appearance.MaptextOffset;
395+
Vector2 newMaptextOffset = Vector2.Lerp(startingOffset, endAppearance.MaptextOffset, factor);
398396

399-
if (endAppearance.MapTextY != _appearance.MapTextY) {
400-
appearance.MapTextY = (short)Math.Clamp(((1-factor) * _appearance.MapTextY) + (factor * endAppearance.MapTextY), -32768, 32767);
397+
_animatedAppearance.MaptextOffset = (Vector2i)newMaptextOffset;
401398
}
402-
*/
403399

404400
if (endAppearance.PixelOffset != _appearance.PixelOffset) {
405401
Vector2 startingOffset = _appearance.PixelOffset;
406-
Vector2 newPixelOffset = Vector2.Lerp(startingOffset, endAppearance.PixelOffset, 1.0f-factor);
402+
Vector2 newPixelOffset = Vector2.Lerp(startingOffset, endAppearance.PixelOffset, factor);
407403

408404
_animatedAppearance.PixelOffset = (Vector2i)newPixelOffset;
409405
}
410406

411407
if (endAppearance.PixelOffset2 != _appearance.PixelOffset2) {
412408
Vector2 startingOffset = _appearance.PixelOffset2;
413-
Vector2 newPixelOffset = Vector2.Lerp(startingOffset, endAppearance.PixelOffset2, 1.0f-factor);
409+
Vector2 newPixelOffset = Vector2.Lerp(startingOffset, endAppearance.PixelOffset2, factor);
414410

415411
_animatedAppearance.PixelOffset2 = (Vector2i)newPixelOffset;
416412
}

OpenDreamClient/Rendering/DreamViewOverlay.cs

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using OpenDreamClient.Interface;
33
using Robust.Client.Graphics;
44
using Robust.Client.Player;
5-
using Robust.Shared.Enums;
65
using Robust.Shared.Map;
76
using OpenDreamShared.Dream;
87
using Robust.Shared.Console;
@@ -13,6 +12,8 @@
1312
using Robust.Shared.Profiling;
1413
using Vector3 = Robust.Shared.Maths.Vector3;
1514
using Matrix3x2 = System.Numerics.Matrix3x2;
15+
using Robust.Client.ResourceManagement;
16+
using Robust.Shared.Enums;
1617

1718
namespace OpenDreamClient.Rendering;
1819

@@ -40,6 +41,9 @@ internal sealed class DreamViewOverlay : Overlay {
4041
[Dependency] private readonly IClyde _clyde = default!;
4142
[Dependency] private readonly IPrototypeManager _protoManager = default!;
4243
[Dependency] private readonly ProfManager _prof = default!;
44+
[Dependency] private readonly IResourceCache _resourceCache = default!;
45+
46+
private readonly Font _defaultMaptextFont;
4347

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

@@ -83,6 +87,7 @@ public DreamViewOverlay(RenderTargetPool renderTargetPool, TransformSystem trans
8387
_appearanceSystem = appearanceSystem;
8488
_screenOverlaySystem = screenOverlaySystem;
8589
_clientImagesSystem = clientImagesSystem;
90+
_defaultMaptextFont = new VectorFont(_resourceCache.GetResource<FontResource>("/Fonts/NotoSans-Regular.ttf"),8);
8691

8792
_spriteQuery = _entityManager.GetEntityQuery<DMISpriteComponent>();
8893
_xformQuery = _entityManager.GetEntityQuery<TransformComponent>();
@@ -338,7 +343,35 @@ private void ProcessIconComponents(DreamIcon icon, Vector2 position, EntityUid u
338343
// TODO: vis_flags
339344
}
340345

341-
//TODO maptext - note colour + transform apply
346+
//maptext is basically just an image of rendered text added as an overlay
347+
if(icon.Appearance.Maptext != null){ //if has maptext
348+
RendererMetaData maptext = RentRendererMetaData();
349+
maptext.MainIcon = icon;
350+
maptext.Position = current.Position;
351+
maptext.Uid = current.Uid;
352+
maptext.ClickUid = current.Uid;
353+
maptext.IsScreen = current.IsScreen;
354+
tieBreaker++;
355+
maptext.TieBreaker = tieBreaker;
356+
maptext.Plane = current.Plane;
357+
maptext.Layer = current.Layer;
358+
maptext.RenderSource = null;
359+
maptext.RenderTarget = null;
360+
maptext.MouseOpacity = current.MouseOpacity;
361+
maptext.TransformToApply = current.TransformToApply;
362+
maptext.ColorToApply = current.ColorToApply;
363+
maptext.ColorMatrixToApply = current.ColorMatrixToApply;
364+
maptext.AlphaToApply = current.AlphaToApply;
365+
maptext.BlendMode = current.BlendMode;
366+
367+
maptext.AppearanceFlags = current.AppearanceFlags;
368+
maptext.AppearanceFlags &= ~AppearanceFlags.PlaneMaster; //doesn't make sense for maptext
369+
370+
maptext.Maptext = icon.Appearance.Maptext;
371+
maptext.MaptextSize = icon.Appearance.MaptextSize;
372+
maptext.Position += icon.Appearance.MaptextOffset/(float)EyeManager.PixelsPerMeter;
373+
result.Add(maptext);
374+
}
342375

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

@@ -400,6 +433,11 @@ public void DrawIcon(DrawingHandleWorld handle, Vector2i renderTargetSize, Rende
400433
positionOffset -= ((ktSize/EyeManager.PixelsPerMeter) - Vector2.One) * new Vector2(0.5f); //correct for KT group texture offset
401434
}
402435

436+
//Maptext
437+
if(iconMetaData.Maptext != null){
438+
iconMetaData.TextureOverride = GetTextureFromMaptext(iconMetaData.Maptext, iconMetaData.MaptextSize!.Value.X, iconMetaData.MaptextSize!.Value.Y, handle);
439+
}
440+
403441
var frame = iconMetaData.GetTexture(this, handle);
404442
var pixelPosition = (iconMetaData.Position + positionOffset) * EyeManager.PixelsPerMeter;
405443

@@ -756,6 +794,28 @@ private Texture ProcessKeepTogether(DrawingHandleWorld handle, RendererMetaData
756794
return ktTexture.Texture;
757795
}
758796

797+
public Texture GetTextureFromMaptext(string maptext, int width, int height, DrawingHandleWorld handle) {
798+
if(width == 0) width = 32;
799+
if(height == 0) height = 32;
800+
IRenderTexture tempTexture = _renderTargetPool.Rent(new Vector2i(width, height));
801+
handle.RenderInRenderTarget(tempTexture, () => {
802+
handle.SetTransform(CreateRenderTargetFlipMatrix(tempTexture.Size, Vector2.Zero));
803+
float scale = 1;
804+
var font = _defaultMaptextFont;
805+
var baseLine = new Vector2(0, 0);
806+
foreach (var rune in maptext.EnumerateRunes()){
807+
var metric = font.GetCharMetrics(rune, scale);
808+
Vector2 mod = new Vector2(0);
809+
if(metric.HasValue)
810+
mod.Y += metric.Value.BearingY - (metric.Value.Height - metric.Value.BearingY);
811+
812+
baseLine.X += font.DrawChar(handle, rune, baseLine+mod, scale, Color.White);
813+
}
814+
}, Color.Transparent);
815+
_renderTargetPool.ReturnAtEndOfFrame(tempTexture);
816+
return tempTexture.Texture;
817+
}
818+
759819
/// <summary>
760820
/// Creates a transformation matrix that counteracts RT's
761821
/// <see cref="DrawingHandleBase.RenderInRenderTarget(IRenderTarget,Action,System.Nullable{Robust.Shared.Maths.Color})"/> quirks
@@ -812,6 +872,8 @@ internal sealed class RendererMetaData : IComparable<RendererMetaData> {
812872
public BlendMode BlendMode;
813873
public MouseOpacity MouseOpacity;
814874
public Texture? TextureOverride;
875+
public string? Maptext;
876+
public Vector2i? MaptextSize;
815877

816878
public bool IsPlaneMaster => (AppearanceFlags & AppearanceFlags.PlaneMaster) != 0;
817879
public bool HasRenderSource => !string.IsNullOrEmpty(RenderSource);
@@ -841,6 +903,8 @@ public void Reset() {
841903
BlendMode = BlendMode.Default;
842904
MouseOpacity = MouseOpacity.Transparent;
843905
TextureOverride = null;
906+
Maptext = null;
907+
MaptextSize = null;
844908
}
845909

846910
public Texture? GetTexture(DreamViewOverlay viewOverlay, DrawingHandleWorld handle) {

OpenDreamRuntime/AtomManager.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,11 @@ public bool IsValidAppearanceVar(string name) {
257257
case "verbs":
258258
case "overlays":
259259
case "underlays":
260+
case "maptext":
261+
case "maptext_width":
262+
case "maptext_height":
263+
case "maptext_x":
264+
case "maptext_y":
260265
return true;
261266

262267
// Get/SetAppearanceVar doesn't handle filters right now
@@ -391,6 +396,24 @@ public void SetAppearanceVar(MutableAppearance appearance, string varName, Dream
391396
appearance.Verbs.Add(verb.VerbId!.Value);
392397
}
393398

399+
break;
400+
case "maptext":
401+
if(value == DreamValue.Null)
402+
appearance.Maptext = null;
403+
else
404+
value.TryGetValueAsString(out appearance.Maptext);
405+
break;
406+
case "maptext_height":
407+
value.TryGetValueAsInteger(out appearance.MaptextSize.Y);
408+
break;
409+
case "maptext_width":
410+
value.TryGetValueAsInteger(out appearance.MaptextSize.X);
411+
break;
412+
case "maptext_x":
413+
value.TryGetValueAsInteger(out appearance.MaptextOffset.X);
414+
break;
415+
case "maptext_y":
416+
value.TryGetValueAsInteger(out appearance.MaptextOffset.Y);
394417
break;
395418
case "appearance":
396419
throw new Exception("Cannot assign the appearance var on an appearance");
@@ -484,6 +507,18 @@ public DreamValue GetAppearanceVar(ImmutableAppearance appearance, string varNam
484507
transform[1], transform[3], transform[5]);
485508

486509
return new(matrix);
510+
case "maptext":
511+
return (appearance.Maptext != null)
512+
? new DreamValue(appearance.Maptext)
513+
: DreamValue.Null;
514+
case "maptext_height":
515+
return new(appearance.MaptextSize.Y);
516+
case "maptext_width":
517+
return new(appearance.MaptextSize.X);
518+
case "maptext_x":
519+
return new(appearance.MaptextOffset.X);
520+
case "maptext_y":
521+
return new(appearance.MaptextOffset.Y);
487522
case "appearance":
488523
MutableAppearance appearanceCopy = appearance.ToMutable(); // Return a copy
489524
return new(appearanceCopy);

OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -211,14 +211,16 @@ public static DreamValue NativeProc_animate(NativeProc.Bundle bundle, DreamObjec
211211
/* TODO these are not yet implemented
212212
if(!pixelZ.IsNull)
213213
pixelZ = new(pixelZ.UnsafeGetValueAsFloat() + obj.GetVariable("pixel_z").UnsafeGetValueAsFloat()); //TODO change to appearance when pixel_z is implemented
214+
*/
214215
if(!maptextWidth.IsNull)
215-
maptextWidth = new(maptextWidth.UnsafeGetValueAsFloat() + obj.GetVariable("maptext_width").UnsafeGetValueAsFloat()); //TODO change to appearance when maptext_width is implemented
216+
maptextWidth = new(maptextWidth.UnsafeGetValueAsFloat() + appearance.MaptextSize.X);
216217
if(!maptextHeight.IsNull)
217-
maptextHeight = new(maptextHeight.UnsafeGetValueAsFloat() + obj.GetVariable("maptext_height").UnsafeGetValueAsFloat()); //TODO change to appearance when maptext_height is implemented
218+
maptextHeight = new(maptextHeight.UnsafeGetValueAsFloat() + appearance.MaptextSize.Y);
218219
if(!maptextX.IsNull)
219-
maptextX = new(maptextX.UnsafeGetValueAsFloat() + obj.GetVariable("maptext_x").UnsafeGetValueAsFloat()); //TODO change to appearance when maptext_x is implemented
220+
maptextX = new(maptextX.UnsafeGetValueAsFloat() + appearance.MaptextOffset.X);
220221
if(!maptextY.IsNull)
221-
maptextY = new(maptextY.UnsafeGetValueAsFloat() + obj.GetVariable("maptext_y").UnsafeGetValueAsFloat()); //TODO change to appearance when maptext_y is implemented
222+
maptextY = new(maptextY.UnsafeGetValueAsFloat() + appearance.MaptextOffset.Y);
223+
/*
222224
if(!luminosity.IsNull)
223225
luminosity = new(luminosity.UnsafeGetValueAsFloat() + obj.GetVariable("luminosity").UnsafeGetValueAsFloat()); //TODO change to appearance when luminosity is implemented
224226
*/
@@ -274,17 +276,30 @@ public static DreamValue NativeProc_animate(NativeProc.Bundle bundle, DreamObjec
274276
}
275277
*/
276278

277-
/* TODO maptext
278279
if (!maptextX.IsNull) {
279280
obj.SetVariableValue("maptext_x", maptextX);
280-
maptextX.TryGetValueAsInteger(out appearance.MapTextOffset.X);
281+
maptextX.TryGetValueAsInteger(out appearance.MaptextOffset.X);
281282
}
282283

283284
if (!maptextY.IsNull) {
284285
obj.SetVariableValue("maptext_y", maptextY);
285-
maptextY.TryGetValueAsInteger(out appearance.MapTextOffset.Y);
286+
maptextY.TryGetValueAsInteger(out appearance.MaptextOffset.Y);
287+
}
288+
289+
if (!maptextWidth.IsNull) {
290+
obj.SetVariableValue("maptext_width", maptextWidth);
291+
maptextX.TryGetValueAsInteger(out appearance.MaptextSize.X);
292+
}
293+
294+
if (!maptextHeight.IsNull) {
295+
obj.SetVariableValue("maptext_y", maptextHeight);
296+
maptextY.TryGetValueAsInteger(out appearance.MaptextSize.Y);
297+
}
298+
299+
if(!maptext.IsNull){
300+
obj.SetVariableValue("maptext", maptext);
301+
maptext.TryGetValueAsString(out appearance.Maptext);
286302
}
287-
*/
288303

289304
if (!dir.IsNull) {
290305
obj.SetVariableValue("dir", dir);

0 commit comments

Comments
 (0)