Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 44 additions & 27 deletions src/game/client/neo/ui/neo_root.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1151,18 +1151,24 @@ void CNeoRoot::MainLoopRoot(const MainLoopParam param)
{
// Close equivalence to ~400px in 1080p (as 4:3 so 1440x1080)
const float flMP3Wide = 0.28f * m_flWideAs43;
g_uiCtx.dPanel.x = param.wide - flMP3Wide;
g_uiCtx.dPanel.y = param.tall - (flMP3Wide / 2) - g_uiCtx.layout.iRowTall;
const int NUM_ROWS = 4;
g_uiCtx.dPanel.x = param.wide - flMP3Wide - g_uiCtx.iMarginX;
g_uiCtx.dPanel.y = param.tall - (NUM_ROWS * g_uiCtx.layout.iRowTall) - g_uiCtx.iMarginY;
if (m_serverPingAutoJoin.m_serverInfo.m_NetAdr.GetIP() != 0)
{
g_uiCtx.dPanel.y -= g_uiCtx.layout.iDefRowTall;
Comment thread
nullsystem marked this conversation as resolved.
}
g_uiCtx.dPanel.wide = flMP3Wide;
g_uiCtx.dPanel.tall = param.tall;

NeoUI::BeginSection(NeoUI::SECTIONFLAG_PLAYBUTTONSOUNDS);
NeoUI::BeginSection();
Comment thread
nullsystem marked this conversation as resolved.

NeoUI::SwapFont(NeoUI::FONT_NTNORMAL);
g_uiCtx.eButtonTextStyle = NeoUI::TEXTSTYLE_LEFT;

wchar_t wszText[128] = {};

// Track Selection
NeoUI::SetPerRowLayout(1);
if (mps->songs[mps->iCurIdx].wszArtist[0])
{
Expand All @@ -1175,7 +1181,32 @@ void CNeoRoot::MainLoopRoot(const MainLoopParam param)
// wszTitle could also be fallback base filename
V_wcscpy_safe(wszText, mps->songs[mps->iCurIdx].wszTitle);
}
NeoUI::Label(wszText);

static int previousSongIndex = 0;
static float scrollStart = gpGlobals->realtime;
if (previousSongIndex != mps->iCurIdx)
{
scrollStart = gpGlobals->realtime;
previousSongIndex = mps->iCurIdx;
}

if (NeoUI::ButtonToggle(wszText, NeoUI::CurrentPopup() == NEOPOPUP_MP3, NeoUI::BUTTONFLAG_SCROLLTEXT, scrollStart).bPressed)
{
if (NeoUI::CurrentPopup() == NEOPOPUP_MP3)
{
NeoUI::ClosePopup();
}
else
{
const int iPopupTall = g_uiCtx.layout.iRowTall * 8;
NeoUI::OpenPopup(NEOPOPUP_MP3, NeoUI::Dim{
.x = g_uiCtx.dPanel.x,
.y = g_uiCtx.dPanel.y - iPopupTall,
.wide = g_uiCtx.dPanel.wide,
.tall = iPopupTall,
});
}
}

const float flNowSecsCursor = mps->flSecsCursor;
NeoUI::ProgressDrag(&mps->flSecsCursor, 0.0f, mps->flSecsLength);
Expand Down Expand Up @@ -1206,10 +1237,11 @@ void CNeoRoot::MainLoopRoot(const MainLoopParam param)
const int iSec = mps->flSecsLength - (iMin * FL_SECSINMIN);
V_swprintf_safe(wszText, L"%02d:%02d", iMin, iSec);
}
NeoUI::Label(wszText);
NeoUI::LabelExOpt labelOptions = { NeoUI::TEXTSTYLE_RIGHT, g_uiCtx.eFont };
NeoUI::Label(wszText, labelOptions);

static constexpr int ROWLAYOUT_MP3_CONTROLS[] = {18, 18, 28, 18, -1};
NeoUI::SetPerRowLayout(5, ROWLAYOUT_MP3_CONTROLS);
static constexpr int ROWLAYOUT_MP3_CONTROLS[] = {22, 22, 34, -1};
NeoUI::SetPerRowLayout(4, ROWLAYOUT_MP3_CONTROLS);

// Shuffle button
if (NeoUI::ButtonToggle(L"\u21B9", cvr_cl_neo_radio_shuffle.GetBool()).bPressed)
Expand Down Expand Up @@ -1238,7 +1270,7 @@ void CNeoRoot::MainLoopRoot(const MainLoopParam param)
}

// Play/Pause button
if (NeoUI::Button(mps->bPlaying ? L"\u25B6" : L"II").bPressed)
if (NeoUI::Button(mps->bPlaying ? L"II" : L"\u25B6").bPressed)
{
mps->flagsPlayStateNext = (mps->bPlaying)
? NeoMP3::PLAYSTATE_FLAG_PAUSED : NeoMP3::PLAYSTATE_FLAG_PLAY;
Expand All @@ -1252,28 +1284,11 @@ void CNeoRoot::MainLoopRoot(const MainLoopParam param)
NeoMP3::Update();
}

// Popup button
if (NeoUI::ButtonToggle(L"\u2261", NeoUI::CurrentPopup() == NEOPOPUP_MP3).bPressed)
{
if (NeoUI::CurrentPopup() == NEOPOPUP_MP3)
{
NeoUI::ClosePopup();
}
else
{
const int iPopupTall = g_uiCtx.layout.iRowTall * 8;
NeoUI::OpenPopup(NEOPOPUP_MP3, NeoUI::Dim{
.x = g_uiCtx.dPanel.x,
.y = g_uiCtx.dPanel.y - iPopupTall,
.wide = g_uiCtx.dPanel.wide,
.tall = iPopupTall,
});
}
}

g_uiCtx.eButtonTextStyle = NeoUI::TEXTSTYLE_LEFT;
NeoUI::EndSection();

NeoUI::Dim previousDPanel = g_uiCtx.dPanel; // See neo_ui.h "// NEO TODO (nullsystem): Popups should get its own XY offsets"

if (NeoUI::BeginPopup(NEOPOPUP_MP3))
{
for (int i = 0; i < mps->iSongsSize; ++i)
Expand All @@ -1293,6 +1308,8 @@ void CNeoRoot::MainLoopRoot(const MainLoopParam param)

NeoUI::EndPopup();
}

g_uiCtx.dPanel = previousDPanel;
}
NeoUI::EndSection();
}
Expand Down
62 changes: 57 additions & 5 deletions src/game/client/neo/ui/neo_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1445,7 +1445,7 @@ void Label(const wchar_t *wszLabel, const wchar_t *wszText)
Label(wszText);
}

NeoUI::RetButton BaseButton(const wchar_t *wszText, const char *szTexturePath, const EBaseButtonType eType, const bool bVal)
NeoUI::RetButton BaseButton(const wchar_t *wszText, const char *szTexturePath, const EBaseButtonType eType, const bool bVal, const ButtonFlags flags, const float flScrollStart)
{
const auto wdgState = BeginWidget(WIDGETFLAG_MOUSE | WIDGETFLAG_MARKACTIVE);

Expand Down Expand Up @@ -1473,8 +1473,60 @@ NeoUI::RetButton BaseButton(const wchar_t *wszText, const char *szTexturePath, c
const auto *pFontI = &c->fonts[c->eFont];
const int x = XPosFromText(wszText, pFontI, c->eButtonTextStyle);
const int y = pFontI->iYFontOffset;
vgui::surface()->DrawSetTextPos(c->rWidgetArea.x0 + x, c->rWidgetArea.y0 + y);
vgui::surface()->DrawPrintText(wszText, V_wcslen(wszText));
const int wszTextLen = V_wcslen(wszText);

bool drawn = false;
if (flags & BUTTONFLAG_SCROLLTEXT)
{
int textWidth = 0, textHeight = 0;
vgui::surface()->GetTextSize(pFontI->hdl, wszText, textWidth, textHeight);
const int textWidthOver = textWidth - c->dPanel.wide;
if (textWidthOver > 0)
{
// Draw with scrolling text // NEO TODO (Adam) could be useful for plain labels too
vgui::surface()->SetFullscreenViewport(c->dPanel.x, c->dPanel.y, c->dPanel.wide, c->dPanel.tall);
vgui::surface()->PushFullscreenViewport();

// Scrolling text
{
textWidth += textHeight; // Separation between two draws of wszText
const float PAUSE_BETWEEN_SCROLLS_SECONDS = 2.5f;
const float PAUSE_BETWEEN_SCROLLS_PIXELS = PAUSE_BETWEEN_SCROLLS_SECONDS * textHeight;
const float SCROLL_SPEED_TEXT_HEIGHT_PER_SECOND = 1.0f;
const float SCROLL_SPEED_PIXELS = SCROLL_SPEED_TEXT_HEIGHT_PER_SECOND * textHeight;
const int timeForScrollInPixels = textWidth + PAUSE_BETWEEN_SCROLLS_PIXELS;
// 1 pixel per second scroll speed if using just time, scale by size of font so text scrolls relatively fast even on large displays.
float timeSpentOnCurrentScrollInPixels = fmod((gpGlobals->realtime - flScrollStart) * SCROLL_SPEED_PIXELS, timeForScrollInPixels);
if (timeSpentOnCurrentScrollInPixels < PAUSE_BETWEEN_SCROLLS_PIXELS)
{
vgui::surface()->DrawSetTextPos(x, y);
vgui::surface()->DrawPrintText(wszText, wszTextLen);
}
else
{
timeSpentOnCurrentScrollInPixels -= PAUSE_BETWEEN_SCROLLS_PIXELS;
const int x1 = x - timeSpentOnCurrentScrollInPixels;
vgui::surface()->DrawSetTextPos(x1, y);
vgui::surface()->DrawPrintText(wszText, wszTextLen);

const int x2 = x1 + textWidth;
vgui::surface()->DrawSetTextPos(x2, y);
vgui::surface()->DrawPrintText(wszText, wszTextLen);
}
}

vgui::surface()->PopFullscreenViewport();
vgui::surface()->SetFullscreenViewport(0, 0, 0, 0);

drawn = true;
}
}

if (!drawn)
{
vgui::surface()->DrawSetTextPos(c->rWidgetArea.x0 + x, c->rWidgetArea.y0 + y);
vgui::surface()->DrawPrintText(wszText, wszTextLen);
}
} break;
Comment thread
nullsystem marked this conversation as resolved.
case BASEBUTTONTYPE_IMAGE:
{
Expand Down Expand Up @@ -1733,9 +1785,9 @@ NeoUI::RetButton ButtonCheckbox(const wchar_t *wszText, const bool bVal)
return BaseButton(wszText, "", BASEBUTTONTYPE_CHECKBOX, bVal);
}

NeoUI::RetButton ButtonToggle(const wchar_t *wszText, const bool bVal)
NeoUI::RetButton ButtonToggle(const wchar_t *wszText, const bool bVal, const ButtonFlags flags, const float flScrollStart)
{
return BaseButton(wszText, "", BASEBUTTONTYPE_TOGGLE, bVal);
return BaseButton(wszText, "", BASEBUTTONTYPE_TOGGLE, bVal, flags, flScrollStart);
}

void ResetTextures()
Expand Down
11 changes: 9 additions & 2 deletions src/game/client/neo/ui/neo_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,13 @@ struct Context
int *piTableVisColsWide = nullptr;
};

enum ButtonFlag_
{
BUTTONFLAG_NONE = 0,
BUTTONFLAG_SCROLLTEXT = 1 << 0, // If the button text is too long, scroll to show the whole text over time
};
typedef int ButtonFlags;

Comment thread
nullsystem marked this conversation as resolved.
struct RetButton
{
// Button + table row
Expand Down Expand Up @@ -556,12 +563,12 @@ struct TabsState
const TabsFlags flags = TABFLAG_DEFAULT,
TabsState *pState = nullptr);
/*1W*/ RetButton BaseButton(const wchar_t *wszText, const char *szTexturePath,
const EBaseButtonType eType, const bool bVal = false);
const EBaseButtonType eType, const bool bVal = false, const ButtonFlags flags = BUTTONFLAG_NONE, const float flScrollStart = 0.0f);
/*1W*/ RetButton Button(const wchar_t *wszText);
/*2W*/ RetButton Button(const wchar_t *wszLeftLabel, const wchar_t *wszText);
/*1W*/ RetButton ButtonTexture(const char *szTexturePath);
/*1W*/ RetButton ButtonCheckbox(const wchar_t *wszText, const bool bVal);
/*1W*/ RetButton ButtonToggle(const wchar_t *wszText, const bool bVal);
/*1W*/ RetButton ButtonToggle(const wchar_t *wszText, const bool bVal, const ButtonFlags flags = BUTTONFLAG_NONE, const float flScrollStart = 0.0f);
/*1W*/ void RingBoxFlag(const int iToggleFlag, int *iFlags, const wchar_t **wszLabelsCustomList = nullptr);
/*2W*/ void RingBoxFlag(const wchar_t *wszLeftLabel, const int iToggleFlag, int *iFlags, const wchar_t **wszLabelsCustomList = nullptr);
/*1W*/ void RingBoxBool(bool *bChecked, const wchar_t **wszLabelsCustomList = nullptr);
Expand Down
Loading