Skip to content

Commit 3f3f351

Browse files
committed
Custom Bird Tutorial: adjust width and height of bubble more accurately
1 parent 64a4044 commit 3f3f351

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

Entities/CustomBirdTutorial.cs

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Celeste.Mod.Entities;
22
using Microsoft.Xna.Framework;
33
using Monocle;
4+
using MonoMod.Utils;
45
using System.Collections.Generic;
56
using System.Reflection;
67

@@ -45,6 +46,9 @@ public CustomBirdTutorial(EntityData data, Vector2 offset) : base(data, offset)
4546
info = Dialog.Clean(infoString);
4647
}
4748

49+
int extraAdvance = 0;
50+
bool firstIsString = false;
51+
4852
// go ahead and parse the controls. Controls can be textures, VirtualButtons, directions or strings.
4953
string[] controlsStrings = data.Attr("controls").Split(',');
5054
controls = new object[controlsStrings.Length];
@@ -62,17 +66,39 @@ public CustomBirdTutorial(EntityData data, Vector2 offset) : base(data, offset)
6266
if (matchingInput?.GetValue(null)?.GetType() == typeof(VirtualButton)) {
6367
// this is a button.
6468
controls[i] = matchingInput.GetValue(null);
65-
} else if (controlString.StartsWith("dialog:")) {
66-
// treat that as a dialog key.
67-
controls[i] = Dialog.Clean(controlString.Substring("dialog:".Length));
6869
} else {
69-
// treat that as a plain string.
70-
controls[i] = controlString;
70+
// when BirdTutorialGui renders text, it is offset by 1px on the right.
71+
// width computation doesn't take this 1px into account, so we should add it back in.
72+
extraAdvance++;
73+
if (i == 0) {
74+
firstIsString = true;
75+
}
76+
77+
if (controlString.StartsWith("dialog:")) {
78+
// treat that as a dialog key.
79+
controls[i] = Dialog.Clean(controlString.Substring("dialog:".Length));
80+
} else {
81+
// treat that as a plain string.
82+
controls[i] = controlString;
83+
}
7184
}
7285
}
7386
}
7487

7588
gui = new BirdTutorialGui(this, new Vector2(0f, -16f), info, controls);
89+
90+
DynData<BirdTutorialGui> guiData = new DynData<BirdTutorialGui>(gui);
91+
// if there is no first line, resize the bubble accordingly.
92+
if (string.IsNullOrEmpty(infoString)) {
93+
guiData["infoHeight"] = 0f;
94+
}
95+
// as the text is rendered 1px to the right, if the first thing is a string, there will be 1px padding on the left.
96+
// we should add that extra px on the right as well.
97+
if (firstIsString) {
98+
extraAdvance++;
99+
}
100+
// apply the extra width.
101+
guiData["controlsWidth"] = guiData.Get<float>("controlsWidth") + extraAdvance;
76102
}
77103

78104
public void TriggerShowTutorial() {

0 commit comments

Comments
 (0)