From 15c762f3f2cff15335e29b54196bb784e8845d5f Mon Sep 17 00:00:00 2001 From: Barinade Date: Sun, 16 Jul 2023 18:15:17 -0500 Subject: [PATCH] add calc interval bars to notefield, add lua access to beatbars too --- .../Til Death/BGAnimations/_chartpreview.lua | 8 ++- Themes/_fallback/metrics.ini | 1 + src/Etterna/Actor/Gameplay/NoteField.cpp | 63 ++++++++++++++++++- src/Etterna/Actor/Gameplay/NoteField.h | 6 ++ 4 files changed, 76 insertions(+), 2 deletions(-) diff --git a/Themes/Til Death/BGAnimations/_chartpreview.lua b/Themes/Til Death/BGAnimations/_chartpreview.lua index f2279059bb..aaffcc2a11 100644 --- a/Themes/Til Death/BGAnimations/_chartpreview.lua +++ b/Themes/Til Death/BGAnimations/_chartpreview.lua @@ -126,7 +126,13 @@ local t = Def.ActorFrame { else self:LoadDummyNoteData() end - end + end, + CalcInfoOnMessageCommand = function(self) + self:show_interval_bars(true) + end, + CalcInfoOffMessageCommand = function(self) + self:show_interval_bars(false) + end, }, Def.Quad { diff --git a/Themes/_fallback/metrics.ini b/Themes/_fallback/metrics.ini index 6b8a8a401e..e38196a73e 100644 --- a/Themes/_fallback/metrics.ini +++ b/Themes/_fallback/metrics.ini @@ -668,6 +668,7 @@ ShowBeatBars=false FadeBeforeTargetsPercent=0 FadeFailTime=1.5 # +CalcBarAlpha=0.6 BarMeasureAlpha=1 Bar4thAlpha=1 Bar8thAlpha=1 diff --git a/src/Etterna/Actor/Gameplay/NoteField.cpp b/src/Etterna/Actor/Gameplay/NoteField.cpp index 2572a6a941..97a9da9ef1 100644 --- a/src/Etterna/Actor/Gameplay/NoteField.cpp +++ b/src/Etterna/Actor/Gameplay/NoteField.cpp @@ -32,6 +32,7 @@ static ThemeMetric SHOW_BEAT_BARS("NoteField", "ShowBeatBars"); static ThemeMetric FADE_BEFORE_TARGETS_PERCENT( "NoteField", "FadeBeforeTargetsPercent"); +static ThemeMetric CALC_BAR_ALPHA("NoteField", "CalcBarAlpha"); static ThemeMetric BAR_MEASURE_ALPHA("NoteField", "BarMeasureAlpha"); static ThemeMetric BAR_4TH_ALPHA("NoteField", "Bar4thAlpha"); static ThemeMetric BAR_8TH_ALPHA("NoteField", "Bar8thAlpha"); @@ -450,6 +451,32 @@ NoteField::DrawBeatBar(const float fBeat, BeatBarType type, int iMeasureIndex) m_sprBeatBars.Draw(); } +void +NoteField::DrawCalcIntervalBar(const float fBeat) +{ + const auto fYOffset = ArrowEffects::GetYOffset(m_pPlayerState, 0, fBeat); + const auto fYPos = + ArrowEffects::GetYPos(0, fYOffset, m_fYReverseOffsetPixels); + + const float fAlpha = CALC_BAR_ALPHA; + const int iState = 0; + + const auto fWidth = GetWidth(); + const auto fFrameWidth = m_sprBeatBars.GetUnzoomedWidth(); + + m_sprBeatBars.SetX(0); + m_sprBeatBars.SetY(fYPos); + m_sprBeatBars.SetDiffuse(RageColor(1, 1, 1, fAlpha)); + m_sprBeatBars.SetState(iState); + m_sprBeatBars.SetCustomTextureRect( + RectF(0, + SCALE(iState, 0.f, 4.f, 0.f, 1.f), + fWidth / fFrameWidth, + SCALE(iState + 1, 0.f, 4.f, 0.f, 1.f))); + m_sprBeatBars.SetZoomX(fWidth / m_sprBeatBars.GetUnzoomedWidth()); + m_sprBeatBars.Draw(); +} + void NoteField::DrawBoard(int iDrawDistanceAfterTargetsPixels, int iDrawDistanceBeforeTargetsPixels) @@ -751,7 +778,7 @@ NoteField::DrawPrimitives() unsigned i = 0; // Draw beat bars - if (SHOW_BEAT_BARS && pTiming != nullptr) { + if ((SHOW_BEAT_BARS || showBeatBars) && pTiming != nullptr) { const auto& tSigs = *segs[SEGMENT_TIME_SIG]; auto iMeasureIndex = 0; for (i = 0; i < tSigs.size(); i++) { @@ -791,6 +818,26 @@ NoteField::DrawPrimitives() } } } + if (showCalcBars && pTiming != nullptr) { + const auto intervalSize = + 0.5F * GAMESTATE->m_SongOptions.GetCurrent().m_fMusicRate; + + const auto firstIntervalStart = + pTiming->GetElapsedTimeFromBeat(m_pNoteData->GetFirstBeat()); + const auto visibleSecondStart = + GAMESTATE->m_Position.m_fMusicSecondsVisible; + const auto visibleSecondEnd = + pTiming->GetElapsedTimeFromBeat(m_FieldRenderArgs.last_beat); + + const auto distanceThroughInterval = + fmodf(visibleSecondStart - firstIntervalStart, intervalSize); + const auto realStart = visibleSecondStart - distanceThroughInterval; + for (auto timePos = realStart; timePos <= visibleSecondEnd; + timePos += intervalSize) { + const auto fBeat = pTiming->GetBeatFromElapsedTime(timePos); + DrawCalcIntervalBar(fBeat); + } + } // Optimization is very important here because there are so many arrows to // draw. Draw the arrows in order of column. This minimizes texture switches @@ -1076,6 +1123,18 @@ class LunaNoteField : public Luna return 1; } + static int show_beat_bars(T* p, lua_State* L) + { + p->SetShowBeatBars(BArg(1)); + COMMON_RETURN_SELF; + } + + static int show_interval_bars(T* p, lua_State* L) + { + p->SetShowIntervalBars(BArg(1)); + COMMON_RETURN_SELF; + } + LunaNoteField() { ADD_METHOD(set_step_callback); @@ -1087,6 +1146,8 @@ class LunaNoteField : public Luna ADD_METHOD(did_tap_note); ADD_METHOD(did_hold_note); ADD_METHOD(get_column_actors); + ADD_METHOD(show_beat_bars); + ADD_METHOD(show_interval_bars); } }; diff --git a/src/Etterna/Actor/Gameplay/NoteField.h b/src/Etterna/Actor/Gameplay/NoteField.h index 05e08f5f94..cf9e1ed27a 100644 --- a/src/Etterna/Actor/Gameplay/NoteField.h +++ b/src/Etterna/Actor/Gameplay/NoteField.h @@ -52,6 +52,9 @@ class NoteField : public ActorFrame void PushSelf(lua_State* L) override; + void SetShowBeatBars(bool b) { showBeatBars = b; } + void SetShowIntervalBars(bool b) { showCalcBars = b; } + // Allows the theme to modify the parameters to Step, SetPressed, // DidTapNote, and DidHoldNote before they pass on to the ghost arrows or // receptors. -Kyz @@ -86,6 +89,7 @@ class NoteField : public ActorFrame quarter_beat }; void DrawBeatBar(float fBeat, BeatBarType type, int iMeasureIndex); + void DrawCalcIntervalBar(const float fBeat); void DrawMarkerBar(int fBeat); void DrawAreaHighlight(int iStartBeat, int iEndBeat); void set_text_measure_number_for_draw(float beat, @@ -112,6 +116,8 @@ class NoteField : public ActorFrame int m_iDrawDistanceAfterTargetsPixels; // this should be a negative number int m_iDrawDistanceBeforeTargetsPixels; // this should be a positive number float m_fYReverseOffsetPixels; + bool showCalcBars = false; + bool showBeatBars = false; // This exists so that the board can be drawn underneath combo/judge. -Kyz bool m_drawing_board_primitive;