Skip to content

Commit

Permalink
Merge pull request #1124 from cwtickle/feature/0455-difficulty-name
Browse files Browse the repository at this point in the history
[0455/difficulty-name] プレイ画面に譜面名を追加、曲名長に合わせて文字サイズを調整
  • Loading branch information
cwtickle committed Sep 25, 2021
2 parents bf4d6b4 + 81194ec commit 9435cdc
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 18 deletions.
57 changes: 40 additions & 17 deletions js/danoni_main.js
Expand Up @@ -537,15 +537,15 @@ function getStrWidth(_str, _fontsize, _font) {
* @param {number} _maxWidth
* @param {string} _font
* @param {number} _maxFontsize
* @param {number} _minFontsize
*/
function getFontSize(_str, _maxWidth, _font = getBasicFont(), _maxFontsize = 64) {
const minSiz = 5;
for (let siz = _maxFontsize; siz >= minSiz; siz--) {
function getFontSize(_str, _maxWidth, _font = getBasicFont(), _maxFontsize = 64, _minFontsize = 5) {
for (let siz = _maxFontsize; siz >= _minFontsize; siz--) {
if (_maxWidth >= getStrWidth(_str, siz, _font)) {
return siz;
}
}
return minSiz;
return _minFontsize;
}

/**
Expand Down Expand Up @@ -2432,6 +2432,7 @@ function titleInit() {
const releaseDate = (g_headerObj.releaseDate !== `` ? ` @${g_headerObj.releaseDate}` : ``);

let reloadFlg = false;
const getLinkSiz = _name => getFontSize(_name, g_sWidth / 2 - 20, getBasicFont(), C_LBL_LNKSIZE, 12);

// ボタン描画
multiAppend(divRoot,
Expand All @@ -2455,7 +2456,7 @@ function titleInit() {
}
}, {
x: 0, y: g_sHeight - 20,
w: g_sWidth / 5, h: 16, siz: 12,
w: g_sWidth / 4, h: 16, siz: 12,
title: g_msgObj.dataReset,
resetFunc: _ => {
if (reloadFlg) {
Expand All @@ -2482,16 +2483,16 @@ function titleInit() {

// 製作者表示
createCss2Button(`lnkMaker`, `${g_lblNameObj.maker}: ${g_headerObj.tuningInit}`, _ => true, {
x: 20, y: g_sHeight - 45,
w: g_sWidth / 2 - 20, h: C_LNK_HEIGHT, siz: C_LBL_LNKSIZE, align: C_ALIGN_LEFT,
x: 0, y: g_sHeight - 50, w: g_sWidth / 2, h: C_LNK_HEIGHT,
siz: getLinkSiz(`${g_lblNameObj.maker}: ${g_headerObj.tuningInit}`), align: C_ALIGN_LEFT,
title: g_headerObj.creatorUrl,
resetFunc: _ => openLink(g_headerObj.creatorUrl),
}, g_cssObj.button_Default),

// アーティスト表示
createCss2Button(`lnkArtist`, `${g_lblNameObj.artist}: ${g_headerObj.artistName}`, _ => true, {
x: g_sWidth / 2, y: g_sHeight - 45,
w: g_sWidth / 2 - 20, h: C_LNK_HEIGHT, siz: C_LBL_LNKSIZE, align: C_ALIGN_LEFT,
x: g_sWidth / 2, y: g_sHeight - 50, w: g_sWidth / 2, h: C_LNK_HEIGHT,
siz: getLinkSiz(`${g_lblNameObj.artist}: ${g_headerObj.artistName}`), align: C_ALIGN_LEFT,
title: g_headerObj.artistUrl,
resetFunc: _ => openLink(g_headerObj.artistUrl),
}, g_cssObj.button_Default),
Expand All @@ -2503,7 +2504,7 @@ function titleInit() {
_ => true,
{
x: g_sWidth / 4, y: g_sHeight - 20,
w: g_sWidth * 3 / 4 - 30, h: 16, siz: 12, align: C_ALIGN_RIGHT,
w: g_sWidth * 3 / 4 - 20, h: 16, siz: 12, align: C_ALIGN_RIGHT,
title: g_msgObj.github,
resetFunc: _ => openLink(`https://github.com/cwtickle/danoniplus`),
},
Expand All @@ -2512,7 +2513,7 @@ function titleInit() {

// セキュリティリンク
createCss2Button(`lnkComparison`, `🛡`, _ => true, {
x: g_sWidth - 30, y: g_sHeight - 20,
x: g_sWidth - 20, y: g_sHeight - 20,
w: 20, h: 16, siz: 12,
title: g_msgObj.security,
resetFunc: _ => openLink(`https://github.com/cwtickle/danoniplus/security/policy`),
Expand Down Expand Up @@ -3328,6 +3329,9 @@ function headerConvert(_dosObj) {
// プレイ左上位置(X座標)
obj.playingX = setVal(_dosObj.playingX, 0, C_TYP_NUMBER);

// プレイ中クレジットを表示しないエリアのサイズ(X方向)
obj.customViewWidth = setVal(_dosObj.customViewWidth, 0, C_TYP_FLOAT);

// ジャストフレームの設定 (ローカル: 0フレーム, リモートサーバ上: 1フレーム以内)
obj.justFrames = (g_isLocal) ? 0 : 1;

Expand Down Expand Up @@ -7816,9 +7820,21 @@ function MainInit() {
lblInitColor = g_cssObj.life_Failed;
}

// 曲名・アーティスト名表示
// 曲名・アーティスト名、譜面名表示
const musicTitle = g_headerObj.musicTitles[g_headerObj.musicNos[g_stateObj.scoreId]] || g_headerObj.musicTitle;
const artistName = g_headerObj.artistNames[g_headerObj.musicNos[g_stateObj.scoreId]] || g_headerObj.artistName;
const assistFlg = (g_autoPlaysBase.includes(g_stateObj.autoPlay) ? `` : `-${g_stateObj.autoPlay}less`);

// 曲名・アーティスト名、譜面名のサイズ調整
const checkMusicSiz = (_text, _siz) => getFontSize(_text, g_headerObj.playingWidth - g_headerObj.customViewWidth - 125, getBasicFont(), _siz);

const makerView = g_headerObj.makerView ? ` (${g_headerObj.creatorNames[g_stateObj.scoreId]})` : ``;
let difName = `[${g_headerObj.keyLabels[g_stateObj.scoreId]} / ${g_headerObj.difLabels[g_stateObj.scoreId]}${assistFlg}${makerView}]`;
let creditName = `${musicTitle} / ${artistName}`;
if (checkMusicSiz(creditName, C_SIZ_MAIN) < 12) {
creditName = `${musicTitle}`;
difName = `/ ${artistName} ` + difName;
}

multiAppend(infoSprite,

Expand Down Expand Up @@ -7848,18 +7864,23 @@ function MainInit() {
}, g_cssObj.life_Border, g_cssObj.life_BorderColor),

// 曲名・アーティスト名表示
createDivCss2Label(`lblCredit`, `${musicTitle} / ${artistName}`, {
x: 125, y: g_sHeight - 30, w: g_headerObj.playingWidth - 125, h: 20, siz: C_SIZ_MAIN, align: C_ALIGN_LEFT,
createDivCss2Label(`lblCredit`, creditName, {
x: 125, y: g_sHeight - 35, w: g_headerObj.playingWidth - 125, h: 20, siz: checkMusicSiz(creditName, C_SIZ_MAIN), align: C_ALIGN_LEFT,
}),

// 譜面名表示
createDivCss2Label(`lblDifName`, difName, {
x: 125, y: g_sHeight - 18, w: g_headerObj.playingWidth, h: 20, siz: checkMusicSiz(difName, 12), align: C_ALIGN_LEFT,
}),

// 曲時間表示:現在時間
createDivCss2Label(`lblTime1`, `-:--`, {
x: 18, y: g_sHeight - 30, w: 40, h: 20, siz: C_SIZ_MAIN, align: C_ALIGN_RIGHT, display: g_workObj.musicinfoDisp,
x: 18, y: g_sHeight - 35, w: 40, h: 20, siz: C_SIZ_MAIN, align: C_ALIGN_RIGHT, display: g_workObj.musicinfoDisp,
}),

// 曲時間表示:総時間
createDivCss2Label(`lblTime2`, `/ ${fullTime}`, {
x: 60, y: g_sHeight - 30, w: 60, h: 20, siz: C_SIZ_MAIN, display: g_workObj.musicinfoDisp,
x: 60, y: g_sHeight - 35, w: 60, h: 20, siz: C_SIZ_MAIN, display: g_workObj.musicinfoDisp,
}),
);

Expand Down Expand Up @@ -7941,7 +7962,9 @@ function MainInit() {

// 曲情報OFF
if (g_stateObj.d_musicinfo === C_FLG_OFF) {
changeStyle(`lblCredit`, { x: 20, animationDuration: `4.0s`, animationName: `leftToRightFade`, animationFillMode: `both` });
[`lblCredit`, `lblDifName`].forEach(labelName => {
changeStyle(labelName, { x: 20, animationDuration: `4.0s`, animationName: `leftToRightFade`, animationFillMode: `both` });
});
}

// ローカル時のみフレーム数を残す
Expand Down
2 changes: 1 addition & 1 deletion js/lib/danoni_constants.js
Expand Up @@ -27,7 +27,7 @@ const C_LBL_LNKSIZE = 16;
const C_LBL_BASICFONT = `"Meiryo UI", sans-serif`;

const C_BTN_HEIGHT = 50;
const C_LNK_HEIGHT = 20;
const C_LNK_HEIGHT = 30;

// スプライト(ムービークリップ相当)のルート
const C_SPRITE_ROOT = `divRoot`;
Expand Down

0 comments on commit 9435cdc

Please sign in to comment.