Skip to content

Commit

Permalink
[Effects] [Bug] Music title: Consistently right-align based on render…
Browse files Browse the repository at this point in the history
…ed width

Unfortunately has a significant effect on the animation, especially for
shorter titles, but maintains consistency with the obviously
whitespace-trimmed title tags in the upcoming BGM mod packs. Let's fix
that animation later, in #55.

Completes P0272, funded by Ember2528.
  • Loading branch information
nmlgc committed Mar 8, 2024
1 parent 1070133 commit 3de48ab
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 9 deletions.
10 changes: 5 additions & 5 deletions GIAN07/EFFECT.CPP
Original file line number Diff line number Diff line change
Expand Up @@ -239,17 +239,17 @@ void SetMusicTitle(int y, Narrow::string_view s)
}
if(n==SEFFECT_MAX) return;

const auto extent = DrawGrdFont(MTitleRect, s);

// 曲のタイトルが長すぎる場合、どうしましょう? //
auto x = (640 - 128 - 16 - (9 * min(s.length(), (23 + 1))));
auto x = (640 - 128 - 32 - min(extent.w, 216));

SEffect[n].cmd = SEFC_MTITLE1;
SEffect[n].x = (x<<6);// + (64*2)*16;
SEffect[n].y = y<<6;
SEffect[n].time = 64*2;
SEffect[n].vx = (s.length() * 16);
SEffect[n].vy = 16;

DrawGrdFont(MTitleRect, s);
SEffect[n].vx = extent.w;
SEffect[n].vy = extent.h;
}

// エフェクトを動かす(仕様変更の可能性があります) //
Expand Down
7 changes: 5 additions & 2 deletions GIAN07/FONTUTY.CPP
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,10 @@ TEXTRENDER_GDI<GRAPHICS_DDRAW, SURFACE_DDRAW, GIAN_FONT_ID> TextObj = {
DxObj, GrText, GDIFonts.fonts
};

void DrawGrdFont(TEXTRENDER_RECT_ID rect_id, Narrow::string_view str)
PIXEL_SIZE DrawGrdFont(TEXTRENDER_RECT_ID rect_id, Narrow::string_view str)
{
TextObj.Prerender(rect_id, [&str](GIAN_TEXTRENDER_SESSION auto& s) {
PIXEL_SIZE extent = { 0, 0 };
TextObj.Prerender(rect_id, [&](GIAN_TEXTRENDER_SESSION auto& s) {
// The MIDI sequence titles passed to this function tend to come with
// lots of trailing whitespace. Adding 1 also turns `npos` to 0.
str = str.substr(0, (str.find_last_not_of(" ") + 1));
Expand All @@ -272,6 +273,7 @@ void DrawGrdFont(TEXTRENDER_RECT_ID rect_id, Narrow::string_view str)
s.Put({ 1, 2 }, str, RGBA{ 0, 0, 128 });
s.Put({ 1, 1 }, str, RGBA{ 255, 255, 255 });
s.Put({ 0, 1 }, str, RGBA{ 255, 255, 255 });
extent += s.Extent(str);

constexpr auto FSIZE = 8;
const PIXEL_COORD w = (str.size() * 16);
Expand All @@ -286,4 +288,5 @@ void DrawGrdFont(TEXTRENDER_RECT_ID rect_id, Narrow::string_view str)
}
}
});
return extent;
}
2 changes: 1 addition & 1 deletion GIAN07/FONTUTY.H
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ extern void GrpPutScore(int x, int y, char *s); // 得点アイテムのスコ
extern void GrpPutMidNum(int x, int y, int n); // MIDI 用フォントを描画する

// グラデーション付きフォントを描画する
void DrawGrdFont(TEXTRENDER_RECT_ID rect_id, Narrow::string_view str);
PIXEL_SIZE DrawGrdFont(TEXTRENDER_RECT_ID rect_id, Narrow::string_view str);


#endif
34 changes: 33 additions & 1 deletion game/bgm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,39 @@ std::chrono::duration<int32_t, std::milli> BGM_PlayTime(void)

Narrow::string_view BGM_Title(void)
{
return Mid_GetTitle();
auto ret = Mid_GetTitle();

// pbg bug: Four of the original track titles start with leading fullwidth
// spaces:
//
// #04: "   幻想帝都"
// #07: "  天空アーミー"
// #11: " 魔法少女十字軍"
// #16: "  シルクロードアリス"
//
// This looks like it was done on purpose to center the titles within the
// 216 maximum pixels that the original code designated for the in-game
// animation. However:
//
// • None of those actually has the correct amount of spaces that would
// have been required for exact centering.
// • If pbg intended to center all the tracks, there should have been
// leading whitespace in 14 of the track titles, and not just in 4.
//
// Since the in-game animation code does clearly intend these titles to be
// right-aligned, it makes more sense to just remove all leading
// whitespace. Doing this here will also benefit the Music Room.
const auto trim_leading = [](auto& str, Narrow::string_view prefix) {
const auto ret = str.starts_with(prefix);
if(ret) {
str.remove_prefix(prefix.size());
}
return ret;
};
while(trim_leading(ret, " ") || trim_leading(ret, "\x81\x40")) {
};

return ret;
}

bool BGM_ChangeMIDIDevice(int8_t direction)
Expand Down

0 comments on commit 3de48ab

Please sign in to comment.