Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/server/g_local.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6063,7 +6063,7 @@ class Menu {
void Next();
void Prev();
void Select(gentity_t* ent);
void Render(gentity_t* ent) const;
void Render(gentity_t* ent);
void EnsureCurrentVisible();
};

Expand Down
37 changes: 35 additions & 2 deletions src/server/menu/menu_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,34 @@ Converts an entry index into its corresponding scrollable index position.
return count;
}

/*
=============
IsRenderable

Determines whether a menu entry will display content or an action.
=============
*/
bool IsRenderable(const MenuEntry& entry) {
return !entry.text.empty() || static_cast<bool>(entry.onSelect);
}

/*
=============
RebuildScrollability

Refreshes the scrollable state for entries that were not explicitly set,
marking only renderable lines as scrollable.
=============
*/
void RebuildScrollability(Menu& menu) {
for (MenuEntry& entry : menu.entries) {
if (entry.scrollableSet)
continue;

entry.scrollable = IsRenderable(entry);
}
}

/*
=============
CollectVisibleEntries
Expand All @@ -70,6 +98,9 @@ scroll offset.
visibleEntries.reserve(entries.size());

for (const MenuEntry& entry : entries) {
if (!IsRenderable(entry))
continue;

if (entry.scrollable) {
if (skippedScrollable > 0) {
--skippedScrollable;
Expand All @@ -89,7 +120,7 @@ scroll offset.
}

return visibleEntries;
}
}

} // namespace

Expand Down Expand Up @@ -163,10 +194,12 @@ void Menu::Select(gentity_t* ent) {
Menu::Render
===============
*/
void Menu::Render(gentity_t* ent) const {
void Menu::Render(gentity_t* ent) {
if (onUpdate)
onUpdate(ent, *this);

RebuildScrollability(*this);

// Do not early-return if current is invalid; still render the menu
const int selected = (current >= 0 && current < static_cast<int>(entries.size())) ? current : -1;

Expand Down