Skip to content

Commit

Permalink
Merge pull request #71 from CommunalHelper/room-name
Browse files Browse the repository at this point in the history
more features / bugfixes for room names
  • Loading branch information
vitellaryjr authored Sep 21, 2024
2 parents f1ffe7c + 3a306d2 commit bb1baaf
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 7 deletions.
11 changes: 10 additions & 1 deletion Code/RoomNameController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using static FrostHelper.CustomZipMover;

namespace Celeste.Mod.Code.Entities
{
Expand All @@ -18,22 +19,30 @@ public class RoomNameController : Entity
public string Name;
private string bgColor;
private string textColor;
private string lineColor;
private float lineAmt;
private float timer;
private float scale;

public RoomNameController(EntityData data, Vector2 offset) : base(data.Position + offset)
{
Name = data.Attr("roomName");
bgColor = data.Attr("backgroundColor", "000000FF");
textColor = data.Attr("textColor", "FFFFFFFF");
lineColor = data.Attr("outlineColor", "000000FF");
lineAmt = data.Float("outlineThickness", 0f);
scale = data.Float("scale", 1f);

timer = data.Float("disappearTimer", -1f);
}
public override void Awake(Scene scene)
{
base.Awake(scene);
var display = RoomNameDisplay.GetDisplay(scene);
display.SetName(Name);
display.SetColor(Calc.HexToColorWithAlpha(textColor), Calc.HexToColorWithAlpha(bgColor));
display.SetColor(textColor, bgColor, lineColor, lineAmt);
display.SetTimer(Math.Max(timer, 0f));
display.scale = scale;
}
}
}
49 changes: 44 additions & 5 deletions Code/RoomNameDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,15 @@ public class RoomNameDisplay : Entity

public Color bgColor;
public Color textColor;
private Color lineColor;
private float colorLerp;
private Color bgColorStart;
private Color textColorStart;
private Color lineColorStart;
private float outline;
private float nextOutline;

public float scale;

private float outTimer;
public RoomNameDisplay() {
Expand Down Expand Up @@ -77,6 +83,7 @@ public override void Update()
if (textLerp == 0f)
{
text = nextText;
outline = nextOutline;
}
}

Expand All @@ -98,21 +105,28 @@ public override void Update()
public override void Render()
{
base.Render();
var y = Calc.LerpClamp(1080f, 1032f, Ease.CubeOut(drawLerp));
var y = Calc.LerpClamp(1080f, 1080f - (48f * scale), Ease.CubeOut(drawLerp));
Color bgC = bgColor;
if (colorLerp < 1f)
{
bgC = Color.Lerp(bgColorStart, bgColor, colorLerp);
}
Draw.Rect(-2f, y, 1920f + 4f, 48f + 2f, bgC);
Draw.Rect(-2f, y, 1920f + 4f, (48f * scale) + 2f, bgC);
if (text != "")
{
Color textC = textColor;
if (colorLerp < 1f) {
textC = Color.Lerp(textColorStart, textColor, colorLerp);
}
var texty = Calc.LerpClamp(1080f, 1032f, Ease.CubeOut(Calc.Min(textLerp, drawLerp)));
ActiveFont.Draw(text, new Vector2(960, texty - 6f), new Vector2(0.5f, 0f), new Vector2(1f, 1f), textC);
var texty = Calc.LerpClamp(1080f, 1080f - (48f * scale), Ease.CubeOut(Calc.Min(textLerp, drawLerp)));
if (outline > 0f)
{
ActiveFont.DrawOutline(text, new Vector2(960, texty - 6f), new Vector2(0.5f, 0f), new Vector2(scale, scale), textC, outline, lineColor);
}
else
{
ActiveFont.Draw(text, new Vector2(960, texty - 6f), new Vector2(0.5f, 0f), new Vector2(scale, scale), textC);
}
}
}

Expand All @@ -128,17 +142,23 @@ public void SetName(string name)
}
}

public void SetColor(Color text, Color bg)
public void SetColor(string textHex, string bgHex, string lineHex, float amt)
{
Color text = HexToColor(textHex);
Color bg = HexToColor(bgHex);
Color line = HexToColor(lineHex);

if (colorLerp < 1f)
{
bgColorStart = Color.Lerp(bgColorStart, bgColor, colorLerp);
textColorStart = Color.Lerp(textColorStart, textColor, colorLerp);
lineColorStart = Color.Lerp(lineColorStart, lineColor, colorLerp);
}
else
{
bgColorStart = bgColor;
textColorStart = textColor;
lineColorStart = lineColor;
}
colorLerp = 0f;
if (drawLerp == 0f)
Expand All @@ -147,6 +167,25 @@ public void SetColor(Color text, Color bg)
}
bgColor = bg;
textColor = text;
lineColor = line;
nextOutline = amt;
}

// Calc.HexToColorWithAlpha does not work correctly
// need to do it myself
public Color HexToColor(string hex)
{
if (hex[0] == '#')
{
hex = hex.Substring(1);
}
Color color = Calc.HexToColor(hex);
if (hex.Length == 6)
{
return color;
}
float alpha = (Calc.HexToByte(hex[6]) * 16 + Calc.HexToByte(hex[7])) / 255f;
return color * alpha;
}

public void SetTimer(float timer)
Expand Down
10 changes: 9 additions & 1 deletion Code/RoomNameTrigger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,22 @@ public class RoomNameTrigger : Trigger
public string Name;
private string bgColor;
private string textColor;
private string lineColor;
private float lineAmt;
private float timer;
private bool oneUse;
private bool instant;
private float scale;

public RoomNameTrigger(EntityData data, Vector2 offset) : base(data, offset)
{
Name = data.Attr("roomName");
bgColor = data.Attr("backgroundColor", "000000FF");
textColor = data.Attr("textColor", "FFFFFFFF");
lineColor = data.Attr("outlineColor", "000000FF");
lineAmt = data.Float("outlineThickness", 0f);
scale = data.Float("scale", 1f);

timer = data.Float("disappearTimer", -1f);
oneUse = data.Bool("oneUse", false);
instant = data.Bool("instant", false);
Expand All @@ -37,8 +44,9 @@ public override void OnEnter(Player player)
base.OnEnter(player);
var display = RoomNameDisplay.GetDisplay(player.Scene);
display.SetName(Name);
display.SetColor(Calc.HexToColorWithAlpha(textColor), Calc.HexToColorWithAlpha(bgColor));
display.SetColor(textColor, bgColor, lineColor, lineAmt);
display.SetTimer(Math.Max(timer, 0f));
display.scale = scale;
if (instant)
{
display.SetInstant();
Expand Down
9 changes: 9 additions & 0 deletions Loenn/entities/room_name.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ roomName.placements = {
backgroundColor = "000000FF",
textColor = "FFFFFFFF",
disappearTimer = -1,
outlineColor = "000000FF",
outlineThickness = 0,
scale = 1,
}
}
}
Expand All @@ -21,6 +24,12 @@ roomName.fieldInformation = {
textColor = {
fieldType = "color"
},
outlineColor = {
fieldType = "color"
},
scale = {
minimumValue = 0.01,
},
}

roomName.texture = "ahorn_roomname"
Expand Down
6 changes: 6 additions & 0 deletions Loenn/lang/en_gb.lang
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,9 @@ entities.vitellary/cassetteflags.attributes.description.greenFlag=The flag to en
entities.vitellary/roomname.attributes.description.roomName=The text to appear at the bottom of the screen. Accepts dialog keys.\nTo make text disappear, leave this as blank.
entities.vitellary/roomname.attributes.description.backgroundColor=The color of the rectangle behind the room name.
entities.vitellary/roomname.attributes.description.textColor=The color of the room name text.
entities.vitellary/roomname.attributes.description.outlineColor=The color of the text's outline, if it has one.
entities.vitellary/roomname.attributes.description.outlineThickness=The size of the text's outline. 0 means it won't have one.
entities.vitellary/roomname.attributes.description.scale=The scale multiplier of the room name.
entities.vitellary/roomname.attributes.description.disappearTimer=The amount of time until the room name goes away. Negative values means the text won't disappear.

# Remote Trigger
Expand Down Expand Up @@ -402,6 +405,9 @@ triggers.vitellary/bombtimer.attributes.description.resetOnDeath=Whether the pla
triggers.vitellary/roomnametrigger.attributes.description.roomName=The text to appear at the bottom of the screen. Accepts dialog keys.\nTo make text disappear, leave this as blank.
triggers.vitellary/roomnametrigger.attributes.description.backgroundColor=The color of the rectangle behind the room name.
triggers.vitellary/roomnametrigger.attributes.description.textColor=The color of the room name text.
triggers.vitellary/roomnametrigger.attributes.description.outlineColor=The color of the text's outline, if it has one.
triggers.vitellary/roomnametrigger.attributes.description.outlineThickness=The size of the text's outline. 0 means it won't have one.
triggers.vitellary/roomnametrigger.attributes.description.scale=The scale multiplier of the room name.
triggers.vitellary/roomnametrigger.attributes.description.disappearTimer=The amount of time until the room name goes away. Negative values means the text won't disappear.
triggers.vitellary/roomnametrigger.attributes.description.oneUse=Whether the trigger should only apply once.
triggers.vitellary/roomnametrigger.attributes.description.instant=Whether the text and colors should instantly appear, rather than easing in.
Expand Down
9 changes: 9 additions & 0 deletions Loenn/triggers/roomnametrigger.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ roomNameTrigger.placements = {
backgroundColor = "000000FF",
textColor = "FFFFFFFF",
disappearTimer = -1,
outlineColor = "000000FF",
outlineThickness = 0,
scale = 1,
oneUse = false,
instant = false,
}
Expand All @@ -22,6 +25,12 @@ roomNameTrigger.fieldInformation = {
textColor = {
fieldType = "color"
},
outlineColor = {
fieldType = "color"
},
scale = {
minimumValue = 0.01,
},
}

return roomNameTrigger

0 comments on commit bb1baaf

Please sign in to comment.