Skip to content

Commit

Permalink
NeoUI::LabelWrap, cleanup neo_loading a bit
Browse files Browse the repository at this point in the history
* fixes #603
  • Loading branch information
nullsystem committed Oct 5, 2024
1 parent af15987 commit c811740
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 41 deletions.
35 changes: 12 additions & 23 deletions mp/src/game/client/neo/ui/neo_loading.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,27 +137,20 @@ void CNeoLoading::FetchGameUIPanels()
{
continue;
}
#define NAME_EQ(STRCHECK) (V_strcmp(curLoadChPanelName, STRCHECK) == 0)
#define CLASS_EQ(CNAME_CHECK) (V_strcmp(curLoadChPanelClass, CNAME_CHECK) == 0)
if (NAME_EQ("Progress"))
if (V_strcmp(curLoadChPanelName, "Progress") == 0)
{
Assert(CLASS_EQ("ProgressBar"));
Assert(V_strcmp(curLoadChPanelClass, "ProgressBar") == 0);
m_pProgressBarMain = static_cast<vgui::ProgressBar *>(pPanel);
}
else if (NAME_EQ("InfoLabel"))
else if (V_strcmp(curLoadChPanelName, "InfoLabel") == 0)
{
Assert(CLASS_EQ("Label"));
Assert(V_strcmp(curLoadChPanelClass, "Label") == 0);
m_pLabelInfo = static_cast<vgui::Label *>(pPanel);
}
#if 0
else if (NAME_EQ("TimeRemainingLabel"))
{
Assert(CLASS_EQ("Label"));
m_pLabelTimeRemaining = static_cast<vgui::Label *>(pPanel);
}
#endif
#undef CLASS_EQ
#undef NAME_EQ
// NEO NOTE (nullsystem): Unused panels:
// "Progress2" - Don't seem utilized
// "TimeRemainingLabel" - Don't seem utilized
// "CancelButton" - Can't do mouse input proper/workaround doesn't work well
}
}

Expand All @@ -181,12 +174,9 @@ void CNeoLoading::OnMainLoop(const NeoUI::Mode eMode)
// NEO JANK (nullsystem): Since we don't have proper access to loading internals,
// determining by localization text index should be good enough to differ between
// loading and disconnect state.
const StringIndex_t iStrIdx = m_pLoadingPanel->_title->_unlocalizedTextSymbol;
NeoUI::BeginContext(&m_uiCtx, eMode,
(m_pLoadingPanel && m_pLoadingPanel->_title) ?
m_pLoadingPanel->_title->GetUText() :
L"Loading...",
"NeoLoadingMainCtx");
vgui::TextImage *pTITitle = m_pLoadingPanel ? m_pLoadingPanel->TITitlePtr() : nullptr;
const StringIndex_t iStrIdx = pTITitle ? pTITitle->GetUnlocalizedTextSymbol() : INVALID_LOCALIZE_STRING_INDEX;
NeoUI::BeginContext(&m_uiCtx, eMode, pTITitle ? pTITitle->GetUText() : L"Loading...", "NeoLoadingMainCtx");
if (iStrIdx == m_aStrIdxMap[LOADINGSTATE_LOADING])
{
NeoUI::BeginSection();
Expand Down Expand Up @@ -214,8 +204,7 @@ void CNeoLoading::OnMainLoop(const NeoUI::Mode eMode)
m_uiCtx.bgColor = COLOR_NEOPANELFRAMEBG;
NeoUI::BeginSection(true);
{
// TODO: Text-Wrappable label
if (m_pLabelInfo) NeoUI::Label(m_pLabelInfo->GetTextImage()->GetUText());
if (m_pLabelInfo) NeoUI::LabelWrap(m_pLabelInfo->GetTextImage()->GetUText());
NeoUI::Pad();
NeoUI::Label(L"Press ESC to go back");
}
Expand Down
3 changes: 0 additions & 3 deletions mp/src/game/client/neo/ui/neo_loading.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ class CNeoLoading : public vgui::EditablePanel
vgui::Frame *m_pLoadingPanel = nullptr;
vgui::ProgressBar *m_pProgressBarMain = nullptr;
vgui::Label *m_pLabelInfo = nullptr;
#if 0
vgui::Label *m_pLabelTimeRemaining = nullptr;
#endif

enum ELoadingState
{
Expand Down
61 changes: 61 additions & 0 deletions mp/src/game/client/neo/ui/neo_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,67 @@ void GCtxSkipActive()
}
}

void LabelWrap(const wchar_t *wszText)
{
if (!wszText || wszText[0] == '\0')
{
NeoUI::Pad();
return;
}

GCtxSkipActive();
int iLines = 0;
if (IN_BETWEEN_AR(0, g_pCtx->iLayoutY, g_pCtx->dPanel.tall))
{
const auto *pFontI = &g_pCtx->fonts[g_pCtx->eFont];
const int iWszSize = V_wcslen(wszText);
int iSumWidth = 0;
int iStart = 0;
int iYOffset = 0;
int iLastSpace = 0;
for (int i = 0; i < iWszSize; ++i)
{
const wchar_t ch = wszText[i];
if (ch == L' ')
{
iLastSpace = i;
}
const int chWidth = surface()->GetCharacterWidth(pFontI->hdl, ch);
iSumWidth += chWidth;
if (iSumWidth >= g_pCtx->dPanel.wide)
{
if (g_pCtx->eMode == MODE_PAINT)
{
GCtxDrawSetTextPos(g_pCtx->iMarginX, g_pCtx->iLayoutY + pFontI->iYOffset + iYOffset);
surface()->DrawPrintText(wszText + iStart, iLastSpace - iStart);
}
++iLines;

iYOffset += g_pCtx->iRowTall;
iSumWidth = 0;
iStart = iLastSpace + 1;
i = iLastSpace;
}
}
if (iSumWidth > 0)
{
if (g_pCtx->eMode == MODE_PAINT)
{
GCtxDrawSetTextPos(g_pCtx->iMarginX, g_pCtx->iLayoutY + pFontI->iYOffset + iYOffset);
surface()->DrawPrintText(wszText + iStart, iWszSize - iStart);
}
++iLines;
}
}

g_pCtx->iPartitionY += iLines;
g_pCtx->iLayoutY += (g_pCtx->iRowTall * iLines);

++g_pCtx->iWidget;
surface()->DrawSetColor(g_pCtx->normalBgColor);
surface()->DrawSetTextColor(COLOR_NEOPANELTEXTNORMAL);
}

void Label(const wchar_t *wszText)
{
GCtxSkipActive();
Expand Down
1 change: 1 addition & 0 deletions mp/src/game/client/neo/ui/neo_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ struct RetButton
bool bMouseDoublePressed;
};
void Pad();
void LabelWrap(const wchar_t *wszText);
void Label(const wchar_t *wszText);
void Label(const wchar_t *wszLabel, const wchar_t *wszText);
void Tabs(const wchar_t **wszLabelsList, const int iLabelsSize, int *iIndex);
Expand Down
10 changes: 4 additions & 6 deletions mp/src/public/vgui_controls/Frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ class Frame : public EditablePanel
// Temporarily enables or disables the fade effect rather than zeroing the fade times as done in DisableFadeEffect
void SetFadeEffectDisableOverride( bool disabled );

#ifdef NEO
TextImage *TITitlePtr() { return _title; }
#endif

protected:
// Respond to mouse presses
virtual void OnMousePressed(MouseCode code);
Expand Down Expand Up @@ -206,13 +210,7 @@ class Frame : public EditablePanel
Color _titleBarDisabledFgColor;
Color m_InFocusBgColor;
Color m_OutOfFocusBgColor;
#ifdef NEO
public:
TextImage *_title;
private:
#else
TextImage *_title;
#endif

#if !defined( _X360 )
Panel *_topGrip;
Expand Down
3 changes: 0 additions & 3 deletions mp/src/public/vgui_controls/ProgressBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ class ProgressBar : public Panel

protected:
int m_iProgressDirection;
#ifdef NEO
public: // Get out of my way
#endif
float _progress;

private:
Expand Down
6 changes: 0 additions & 6 deletions mp/src/public/vgui_controls/TextImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,7 @@ class TextImage : public Image
int _drawWidth; // this is the width of the window we are drawing into.
// if there is not enough room truncate the txt and add an elipsis

#ifdef NEO
public:
StringIndex_t _unlocalizedTextSymbol;
private:
#else
StringIndex_t _unlocalizedTextSymbol; // store off the unlocalized text index for build mode
#endif
wchar_t *m_pwszEllipsesPosition;

bool m_bRecalculateTruncation : 1;
Expand Down

0 comments on commit c811740

Please sign in to comment.