Skip to content

Commit

Permalink
add calc interval bars to notefield, add lua access to beatbars too
Browse files Browse the repository at this point in the history
  • Loading branch information
poco0317 committed Jul 16, 2023
1 parent a2cfa87 commit 15c762f
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 2 deletions.
8 changes: 7 additions & 1 deletion Themes/Til Death/BGAnimations/_chartpreview.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions Themes/_fallback/metrics.ini
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,7 @@ ShowBeatBars=false
FadeBeforeTargetsPercent=0
FadeFailTime=1.5
#
CalcBarAlpha=0.6
BarMeasureAlpha=1
Bar4thAlpha=1
Bar8thAlpha=1
Expand Down
63 changes: 62 additions & 1 deletion src/Etterna/Actor/Gameplay/NoteField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ static ThemeMetric<bool> SHOW_BEAT_BARS("NoteField", "ShowBeatBars");
static ThemeMetric<float> FADE_BEFORE_TARGETS_PERCENT(
"NoteField",
"FadeBeforeTargetsPercent");
static ThemeMetric<float> CALC_BAR_ALPHA("NoteField", "CalcBarAlpha");
static ThemeMetric<float> BAR_MEASURE_ALPHA("NoteField", "BarMeasureAlpha");
static ThemeMetric<float> BAR_4TH_ALPHA("NoteField", "Bar4thAlpha");
static ThemeMetric<float> BAR_8TH_ALPHA("NoteField", "Bar8thAlpha");
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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++) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1076,6 +1123,18 @@ class LunaNoteField : public Luna<NoteField>
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);
Expand All @@ -1087,6 +1146,8 @@ class LunaNoteField : public Luna<NoteField>
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);
}
};

Expand Down
6 changes: 6 additions & 0 deletions src/Etterna/Actor/Gameplay/NoteField.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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;
Expand Down

0 comments on commit 15c762f

Please sign in to comment.