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
176 changes: 75 additions & 101 deletions src/game/client/neo/ui/neo_root.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,18 +336,16 @@ void CNeoRootInput::OnThink()
}
}

constexpr WidgetInfo BTNS_INFO[BTNS_TOTAL] = {
{ "#GameUI_GameMenu_ResumeGame", false, "ResumeGame", true, STATE__TOTAL, FLAG_SHOWINGAME },
{ "#GameUI_GameMenu_FindServers", false, nullptr, true, STATE_SERVERBROWSER, FLAG_SHOWINGAME | FLAG_SHOWINMAIN },
{ "#GameUI_GameMenu_CreateServer", false, nullptr, true, STATE_NEWGAME, FLAG_SHOWINGAME | FLAG_SHOWINMAIN },
{ "#GameUI_GameMenu_Disconnect", false, "Disconnect", true, STATE__TOTAL, FLAG_SHOWINGAME },
{ "#GameUI_GameMenu_PlayerList", false, nullptr, true, STATE_PLAYERLIST, FLAG_SHOWINGAME },
{ "", true, nullptr, true, STATE__TOTAL, FLAG_SHOWINMAIN },
{ "#GameUI_GameMenu_Tutorial", false, "sv_use_steam_networking 0; map " TUTORIAL_MAP_CLASSES, false, STATE__TOTAL, FLAG_SHOWINMAIN},
{ "#GameUI_GameMenu_FiringRange", false, "sv_use_steam_networking 0; map " TUTORIAL_MAP_SHOOTING, false, STATE__TOTAL, FLAG_SHOWINMAIN},
{ "", true, nullptr, true, STATE__TOTAL, FLAG_SHOWINGAME | FLAG_SHOWINMAIN },
{ "#GameUI_GameMenu_Options", false, nullptr, true, STATE_SETTINGS, FLAG_SHOWINGAME | FLAG_SHOWINMAIN },
{ "#GameUI_GameMenu_Quit", false, nullptr, true, STATE_QUIT, FLAG_SHOWINGAME | FLAG_SHOWINMAIN },
constexpr const char *BTNS_LOCALIZE[MMBTN__TOTAL] = {
"#GameUI_GameMenu_ResumeGame",
"#GameUI_GameMenu_FindServers",
"#GameUI_GameMenu_CreateServer",
"#GameUI_GameMenu_Disconnect",
"#GameUI_GameMenu_PlayerList",
"#GameUI_GameMenu_Tutorial",
"#GameUI_GameMenu_FiringRange",
"#GameUI_GameMenu_Options",
"#GameUI_GameMenu_Quit",
};

CNeoRoot::CNeoRoot(VPANEL parent)
Expand All @@ -364,18 +362,20 @@ CNeoRoot::CNeoRoot(VPANEL parent)
enginevgui->GetPanel(PANEL_CLIENTDLL), "resource/ClientScheme.res", "ClientScheme");
SetScheme(neoscheme);

for (int i = 0; i < BTNS_TOTAL; ++i)
for (int i = 0; i < MMBTN__TOTAL; ++i)
{
const char *label = BTNS_INFO[i].label;
if (wchar_t *localizedWszStr = g_pVGuiLocalize->Find(label))
const char *pszLocalizeKey = BTNS_LOCALIZE[i];
wchar_t *localizedWszStr = g_pVGuiLocalize->Find(pszLocalizeKey);
Assert(localizedWszStr);
if (localizedWszStr)
{
V_wcsncpy(m_wszDispBtnTexts[i], localizedWszStr, sizeof(m_wszDispBtnTexts[i]));
V_wcsncpy(m_wszCachedTexts[i], localizedWszStr, sizeof(m_wszCachedTexts[i]));
}
else
{
g_pVGuiLocalize->ConvertANSIToUnicode(label, m_wszDispBtnTexts[i], sizeof(m_wszDispBtnTexts[i]));
Warning("ERROR: Cannot find localized text of %s", pszLocalizeKey);
g_pVGuiLocalize->ConvertANSIToUnicode(pszLocalizeKey, m_wszCachedTexts[i], sizeof(m_wszCachedTexts[i]));
}
m_iWszDispBtnTextsSizes[i] = V_wcslen(m_wszDispBtnTexts[i]);
}

NeoSettingsInit(&m_ns);
Expand Down Expand Up @@ -746,7 +746,7 @@ void CNeoRoot::MainLoopRoot(const MainLoopParam param)
const int iMarginHalf = iMargin * 0.5;
const int iTitleMarginTop = (param.tall * 0.2);
surface()->GetTextSize(g_uiCtx.fonts[NeoUI::FONT_LOGO].hdl, L"n", iTitleNWidth, iTitleNHeight);
g_uiCtx.dPanel.wide = (m_iTitleWidth) +iMargin;
g_uiCtx.dPanel.wide = (m_iTitleWidth) + iMargin;
g_uiCtx.dPanel.tall = param.tall;
g_uiCtx.dPanel.x = iBtnPlaceXMid - (m_iTitleWidth * 0.5) + (iTitleNWidth * 1.16) - iMarginHalf;
g_uiCtx.dPanel.y = iTitleMarginTop + (2 * iTitleNHeight);
Expand All @@ -757,60 +757,58 @@ void CNeoRoot::MainLoopRoot(const MainLoopParam param)
g_uiCtx.dPanel.x + g_uiCtx.dPanel.wide, param.tall);

NeoUI::BeginContext(&g_uiCtx, param.eMode, nullptr, "CtxRoot");
NeoUI::BeginSection(NeoUI::SECTIONFLAG_DEFAULTFOCUS);
NeoUI::BeginSection(NeoUI::SECTIONFLAG_DEFAULTFOCUS | NeoUI::SECTIONFLAG_PLAYBUTTONSOUNDS);
{
g_uiCtx.eButtonTextStyle = NeoUI::TEXTSTYLE_CENTER;
const int iFlagToMatch = IsInGame() ? FLAG_SHOWINGAME : FLAG_SHOWINMAIN;
bool mouseOverButton = false;
for (int i = 0; i < BTNS_TOTAL; ++i)
const bool bIsInGame = IsInGame();
if (bIsInGame && NeoUI::Button(m_wszCachedTexts[MMBTN_RESUME]).bPressed)
{
const auto btnInfo = BTNS_INFO[i];
if (btnInfo.flags & iFlagToMatch)
m_state = STATE_ROOT;
GetGameUI()->SendMainMenuCommand("ResumeGame");
}
if (NeoUI::Button(m_wszCachedTexts[MMBTN_FINDSERVER]).bPressed)
{
m_state = STATE_SERVERBROWSER;
}
if (NeoUI::Button(m_wszCachedTexts[MMBTN_CREATESERVER]).bPressed)
{
m_state = STATE_NEWGAME;
}
if (bIsInGame)
{
if (NeoUI::Button(m_wszCachedTexts[MMBTN_DISCONNECT]).bPressed)
{
if (btnInfo.isFake)
{
NeoUI::Pad();
continue;
}
const auto retBtn = NeoUI::Button(m_wszDispBtnTexts[i]);
if (retBtn.bPressed || (i == MMBTN_QUIT && !IsInGame() && NeoUI::BindKeyBack()))
{
surface()->PlaySound("ui/buttonclickrelease.wav");
if (btnInfo.command)
{
m_state = STATE_ROOT;
if (btnInfo.isMainMenuCommand)
{
GetGameUI()->SendMainMenuCommand(btnInfo.command);
}
else
{
engine->ClientCmd(btnInfo.command);
}
}
else if (btnInfo.nextState < STATE__TOTAL)
{
m_state = btnInfo.nextState;
if (m_state == STATE_SETTINGS)
{
NeoSettingsRestore(&m_ns);
}
}
}
if (retBtn.bMouseHover)
{
mouseOverButton = true;
if (i != m_iHoverBtn && param.eMode == NeoUI::MODE_MOUSEMOVED)
{ // Sound rollover feedback
surface()->PlaySound("ui/buttonrollover.wav");
m_iHoverBtn = i;
}
}
m_state = STATE_ROOT;
GetGameUI()->SendMainMenuCommand("Disconnect");
}
if (NeoUI::Button(m_wszCachedTexts[MMBTN_PLAYERLIST]).bPressed)
{
m_state = STATE_PLAYERLIST;
}
}
if (!mouseOverButton && m_iHoverBtn < BTNS_TOTAL && param.eMode == NeoUI::MODE_MOUSEMOVED)
else
{
m_iHoverBtn = -1;
NeoUI::Pad();
if (NeoUI::Button(m_wszCachedTexts[MMBTN_TUTORIAL]).bPressed)
{
m_state = STATE_ROOT;
engine->ClientCmd("sv_use_steam_networking 0; map " TUTORIAL_MAP_CLASSES);
}
if (NeoUI::Button(m_wszCachedTexts[MMBTN_FIRINGRANGE]).bPressed)
{
m_state = STATE_ROOT;
engine->ClientCmd("sv_use_steam_networking 0; map " TUTORIAL_MAP_SHOOTING);
}
}
NeoUI::Pad();
if (NeoUI::Button(m_wszCachedTexts[MMBTN_OPTIONS]).bPressed)
{
m_state = STATE_SETTINGS;
NeoSettingsRestore(&m_ns);
}
if (NeoUI::Button(m_wszCachedTexts[MMBTN_QUIT]).bPressed)
{
m_state = STATE_QUIT;
}
}
NeoUI::EndSection();
Expand Down Expand Up @@ -996,45 +994,21 @@ void CNeoRoot::MainLoopRoot(const MainLoopParam param)
g_uiCtx.dPanel.x = param.wide - 128;
g_uiCtx.dPanel.y = param.tall - 96;
g_uiCtx.dPanel.wide = 128;
g_uiCtx.dPanel.tall = 1;
NeoUI::BeginSection();
g_uiCtx.eButtonTextStyle = NeoUI::TEXTSTYLE_CENTER;
const auto musicPlayerBtn = NeoUI::Button(L"Music");
if (musicPlayerBtn.bPressed)
{
surface()->PlaySound("ui/buttonclickrelease.wav");
engine->ClientCmd("neo_mp3");

}
NeoUI::EndSection();

NeoUI::BeginSection();
g_uiCtx.dPanel.y = param.tall - 48;
const auto creditsBtn = NeoUI::Button(L"Credits");
if (creditsBtn.bPressed)
{
surface()->PlaySound("ui/buttonclickrelease.wav");
m_state = STATE_CREDITS;
}
NeoUI::EndSection();
g_uiCtx.dPanel.tall = param.tall;

if (param.eMode == NeoUI::MODE_MOUSEMOVED)
NeoUI::BeginSection(NeoUI::SECTIONFLAG_PLAYBUTTONSOUNDS);
{
if (musicPlayerBtn.bMouseHover && SMBTN_MP3 != m_iHoverBtn)
{ // Sound rollover feedback
surface()->PlaySound("ui/buttonrollover.wav");
m_iHoverBtn = SMBTN_MP3;
}
else if (creditsBtn.bMouseHover && SMBTN_CREDITS != m_iHoverBtn)
g_uiCtx.eButtonTextStyle = NeoUI::TEXTSTYLE_CENTER;
if (NeoUI::Button(L"Music").bPressed)
{
surface()->PlaySound("ui/buttonrollover.wav");
m_iHoverBtn = SMBTN_CREDITS;
engine->ClientCmd("neo_mp3");
}
else if ((!musicPlayerBtn.bMouseHover && SMBTN_MP3 == m_iHoverBtn) || (!creditsBtn.bMouseHover && SMBTN_CREDITS == m_iHoverBtn))
if (NeoUI::Button(L"Credits").bPressed)
{
m_iHoverBtn = -1;
m_state = STATE_CREDITS;
}
}
NeoUI::EndSection();

NeoUI::EndContext();
}
Expand Down Expand Up @@ -1067,7 +1041,7 @@ void CNeoRoot::MainLoopSettings(const MainLoopParam param)
g_uiCtx.dPanel.y = (param.tall / 2) - (iTallTotal / 2);
g_uiCtx.dPanel.tall = g_uiCtx.layout.iRowTall;
g_uiCtx.bgColor = COLOR_NEOPANELFRAMEBG;
NeoUI::BeginContext(&g_uiCtx, param.eMode, g_pNeoRoot->m_wszDispBtnTexts[MMBTN_OPTIONS], "CtxOptions");
NeoUI::BeginContext(&g_uiCtx, param.eMode, g_pNeoRoot->m_wszCachedTexts[MMBTN_OPTIONS], "CtxOptions");
{
NeoUI::BeginSection(NeoUI::SECTIONFLAG_ROWWIDGETS | NeoUI::SECTIONFLAG_EXCLUDECONTROLLER);
{
Expand Down Expand Up @@ -1164,7 +1138,7 @@ void CNeoRoot::MainLoopNewGame(const MainLoopParam param)
g_uiCtx.dPanel.y = (param.tall / 2) - (iTallTotal / 2);
g_uiCtx.dPanel.tall = g_uiCtx.layout.iRowTall * (g_iRowsInScreen + 1);
g_uiCtx.bgColor = COLOR_NEOPANELFRAMEBG;
NeoUI::BeginContext(&g_uiCtx, param.eMode, m_wszDispBtnTexts[MMBTN_CREATESERVER], "CtxNewGame");
NeoUI::BeginContext(&g_uiCtx, param.eMode, m_wszCachedTexts[MMBTN_CREATESERVER], "CtxNewGame");
{
NeoUI::BeginSection(NeoUI::SECTIONFLAG_DEFAULTFOCUS);
{
Expand Down Expand Up @@ -1382,7 +1356,7 @@ void CNeoRoot::MainLoopServerBrowser(const MainLoopParam param)
g_uiCtx.dPanel.y = (param.tall / 2) - (iTallTotal / 2);
g_uiCtx.dPanel.tall = g_uiCtx.layout.iRowTall * 2;
g_uiCtx.bgColor = COLOR_NEOPANELFRAMEBG;
NeoUI::BeginContext(&g_uiCtx, param.eMode, m_wszDispBtnTexts[MMBTN_FINDSERVER], "CtxServerBrowser");
NeoUI::BeginContext(&g_uiCtx, param.eMode, m_wszCachedTexts[MMBTN_FINDSERVER], "CtxServerBrowser");
{
bool bForceRefresh = false;
NeoUI::BeginSection(NeoUI::SECTIONFLAG_ROWWIDGETS);
Expand Down
28 changes: 2 additions & 26 deletions src/game/client/neo/ui/neo_root.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,41 +83,19 @@ enum RootState
STATE__TOTAL,
};

struct WidgetInfo
{
const char *label;
bool isFake;
const char *command; // TODO: Replace
bool isMainMenuCommand;
RootState nextState;
int flags;
};

enum WidgetInfoFlags
{
FLAG_NONE = 0,
FLAG_SHOWINGAME = 1 << 0,
FLAG_SHOWINMAIN = 1 << 1,
};

enum MainMenuButtons
{
MMBTN_RESUME = 0,
MMBTN_FINDSERVER,
MMBTN_CREATESERVER,
MMBTN_DISCONNECT,
MMBTN_PLAYERLIST,
MMBTN_SEPARATOR1,
MMBTN_TUTORIAL,
MMBTN_FIRINGRANGE,
MMBTN_SEPARATOR2,
MMBTN_OPTIONS,
MMBTN_QUIT,

BTNS_TOTAL,

SMBTN_MP3,
SMBTN_CREDITS,
MMBTN__TOTAL,
};

struct SprayInfo
Expand All @@ -143,12 +121,10 @@ class CNeoRoot : public vgui::EditablePanel, public CGameEventListener
void UpdateControls();

IGameUI *m_gameui = nullptr;
int m_iHoverBtn = -1;
RootState m_state = STATE_ROOT;
CAvatarImage *m_avImage = nullptr;

wchar_t m_wszDispBtnTexts[BTNS_TOTAL][64] = {};
int m_iWszDispBtnTextsSizes[BTNS_TOTAL] = {};
wchar_t m_wszCachedTexts[MMBTN__TOTAL][64] = {};

CNeoRootInput *m_panelCaptureInput = nullptr;
void OnRelayedKeyCodeTyped(vgui::KeyCode code);
Expand Down
28 changes: 24 additions & 4 deletions src/game/client/neo/ui/neo_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,14 +307,18 @@ void BeginContext(NeoUI::Context *pNextCtx, const NeoUI::Mode eMode, const wchar
vgui::surface()->DrawPrintText(wszTitle, V_wcslen(wszTitle));
}
break;
case MODE_MOUSEMOVED:
c->iHot = FOCUSOFF_NUM;
c->iHotSection = -1;
break;
default:
break;
}

c->iHotPersist = c->iHot;
c->iHotPersistSection = c->iHotSection;
if (c->eMode == MODE_MOUSEMOVED)
{
c->iHot = FOCUSOFF_NUM;
c->iHotSection = -1;
}

// Force SwapFont on main to prevent crash on startup
SwapFont(FONT_NTLARGE, true);
c->eButtonTextStyle = TEXTSTYLE_LEFT;
Expand Down Expand Up @@ -807,6 +811,7 @@ GetMouseinFocusedRet BeginWidget(const WidgetFlag eWidgetFlag)
// Check mouse hot/active states if WIDGETFLAG_MOUSE flag set
if (eWidgetFlag & WIDGETFLAG_MOUSE)
{
const bool bNotCurHot = (c->iHotPersist != c->iWidget || c->iHotPersistSection != c->iSection);
const bool bMouseIn = IN_BETWEEN_EQ(c->rWidgetArea.x0, c->iMouseAbsX, c->rWidgetArea.x1)
&& IN_BETWEEN_EQ(c->rWidgetArea.y0, c->iMouseAbsY, c->rWidgetArea.y1);
if (bMouseIn)
Expand Down Expand Up @@ -834,6 +839,7 @@ GetMouseinFocusedRet BeginWidget(const WidgetFlag eWidgetFlag)
return GetMouseinFocusedRet{
.bActive = bActive,
.bHot = bHot,
.bNewHot = bNotCurHot && bHot,
};
}

Expand Down Expand Up @@ -1064,6 +1070,20 @@ NeoUI::RetButton BaseButton(const wchar_t *wszText, const char *szTexturePath, c
}
}

if (c->iSectionFlags & SECTIONFLAG_PLAYBUTTONSOUNDS)
{
if (ret.bPressed)
{
vgui::surface()->PlaySound(c->pszSoundBtnPressed);
}
if (wdgState.bNewHot &&
((c->eMode == MODE_MOUSEMOVED && ret.bMouseHover) ||
(c->eMode == MODE_KEYPRESSED && !ret.bPressed)))
{
vgui::surface()->PlaySound(c->pszSoundBtnRollover);
}
}

EndWidget(wdgState);
return ret;
}
Expand Down
Loading