Skip to content

Commit 4d9b188

Browse files
authored
Merge pull request #180 from EverestAPI/bird_tutorial_bubble_size
2 parents 64a4044 + 49421c6 commit 4d9b188

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

Entities/CustomBirdTutorial.cs

Lines changed: 27 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,8 @@ public CustomBirdTutorial(EntityData data, Vector2 offset) : base(data, offset)
4546
info = Dialog.Clean(infoString);
4647
}
4748

49+
int extraAdvance = 0;
50+
4851
// go ahead and parse the controls. Controls can be textures, VirtualButtons, directions or strings.
4952
string[] controlsStrings = data.Attr("controls").Split(',');
5053
controls = new object[controlsStrings.Length];
@@ -62,17 +65,36 @@ public CustomBirdTutorial(EntityData data, Vector2 offset) : base(data, offset)
6265
if (matchingInput?.GetValue(null)?.GetType() == typeof(VirtualButton)) {
6366
// this is a button.
6467
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));
6868
} else {
69-
// treat that as a plain string.
70-
controls[i] = controlString;
69+
// when BirdTutorialGui renders text, it is offset by 1px on the right.
70+
// width computation doesn't take this 1px into account, so we should add it back in.
71+
extraAdvance++;
72+
if (i == 0) {
73+
// as the text is rendered 1px to the right, if the first thing is a string, there will be 1px more padding on the left.
74+
// we should add that extra px on the right as well.
75+
extraAdvance++;
76+
}
77+
78+
if (controlString.StartsWith("dialog:")) {
79+
// treat that as a dialog key.
80+
controls[i] = Dialog.Clean(controlString.Substring("dialog:".Length));
81+
} else {
82+
// treat that as a plain string.
83+
controls[i] = controlString;
84+
}
7185
}
7286
}
7387
}
7488

7589
gui = new BirdTutorialGui(this, new Vector2(0f, -16f), info, controls);
90+
91+
DynData<BirdTutorialGui> guiData = new DynData<BirdTutorialGui>(gui);
92+
// if there is no first line, resize the bubble accordingly.
93+
if (string.IsNullOrEmpty(infoString)) {
94+
guiData["infoHeight"] = 0f;
95+
}
96+
// apply the extra width.
97+
guiData["controlsWidth"] = guiData.Get<float>("controlsWidth") + extraAdvance;
7698
}
7799

78100
public void TriggerShowTutorial() {

0 commit comments

Comments
 (0)