Add level progress menu to main menu#4
Conversation
Introduces a new 'PROGRESS' button in the main menu, allowing players to view their progress across accessible levels. The progress menu displays each level's status, title, and remaining enemies, and enables switching to any discovered but uncleared level. Supporting code includes new menu logic, button definitions, and a helper for gathering level statistics.
There was a problem hiding this comment.
Pull request overview
This PR adds a level progress menu to the main menu, enabling players to view and navigate their campaign progress. The feature displays accessible levels with their completion status, titles, and enemy counts, allowing players to switch to any discovered uncleared level.
Changes:
- Added a new "PROGRESS" button to the main menu (between BACK and SET LEVEL buttons)
- Implemented
create_progress_menu()function with scrollable level list and level selection functionality - Added helper function
get_accessible_levels()to determine which levels the player can access - Exposed
getLevelStats()function in level_picker.h header for reuse
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/picker.cpp | Implemented progress menu UI, button navigation updates, and accessible level calculation logic |
| src/level_picker.h | Exported getLevelStats function for use in progress menu |
| src/button.h | Added CREATE_PROGRESS_MENU constant and function declaration |
| src/button.cpp | Added case handler for CREATE_PROGRESS_MENU in button dispatch |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/picker.cpp
Outdated
|
|
||
| // Count enemies | ||
| int num_enemies = 0; | ||
| getLevelStats(ld, NULL, NULL, &num_enemies, NULL, *(new std::list<int>())); |
There was a problem hiding this comment.
Memory leak: A new std::list is allocated but never freed. Pass a temporary list object on the stack instead: std::list<int> temp_exits; getLevelStats(ld, NULL, NULL, &num_enemies, NULL, temp_exits);
| strncpy(lp.title, ld.title.c_str(), 20); | ||
| lp.title[20] = '\0'; |
There was a problem hiding this comment.
Buffer overflow risk: The title array is declared as char[24] at line 1106, but strncpy copies 20 characters and sets position 20 to null terminator. If the string is exactly 20 characters, this is correct, but the subsequent code (lines 1195-1199) checks strlen and modifies indices 17-19, which requires at least 21 bytes for proper null termination. Either copy 23 characters to match BrowserEntry pattern at level_picker.cpp:201, or reduce the array size to match the copy length.
| button("SAVE TEAM", KEYSTATE_UNKNOWN, 120, 100, 80, 15, CREATE_SAVE_MENU, -1, MenuNav::UpLeftRight(1, 3, 5)), | ||
| button("GO", KEYSTATE_UNKNOWN, 210, 100, 80, 15, GO_MENU, -1, MenuNav::UpDownLeft(2, 7, 4)), | ||
| button("GO", KEYSTATE_UNKNOWN, 210, 100, 80, 15, GO_MENU, -1, MenuNav::UpDownLeft(2, 8, 4)), | ||
|
|
There was a problem hiding this comment.
The BACK button width was changed from 60 to 50 pixels without explanation. This change appears unnecessary since the new PROGRESS button has its own space allocation. If this resize is intentional to accommodate the PROGRESS button layout, consider adding a comment explaining the UI layout constraints.
| // NOTE: BACK button width is intentionally 50px (instead of 60px) to fit alongside | |
| // the PROGRESS / SET LEVEL / SET CAMPAIGN buttons within the available horizontal space. |
PR Review: Add level progress menu to main menuOverviewThis PR adds a new "PROGRESS" button to the main menu that allows players to view their progress across accessible levels. The implementation includes menu logic, button definitions, and level statistics gathering. Code Quality & Best PracticesPositive Aspects✅ Good separation of concerns: The Issues & Suggestions1. Memory Leak
|
Fix memory leak in create_progress_menu(): - getLevelStats() was called with `*(new std::list<int>())` which allocated a list on the heap that was never freed - Changed to use a stack-allocated variable instead Revert BACK button width from 50 to 60 pixels: - The reduced width was unnecessary for the layout Review feedback analysis (issues not addressed): 1. Buffer overflow risk (lines 1193-1194): Not a bug. The title array is 24 bytes and the code intentionally limits to 20 chars + null terminator (21 bytes). The "..." truncation at positions 17-19 is a deliberate UI choice to fit titles in the display. No overflow is possible. 2. Level discovery algorithm: The suggestion to recursively discover all reachable levels is a design change, not a bug fix. Current behavior correctly shows cleared levels plus their direct exits (levels the player can actually navigate to). Showing levels 2+ hops away would display levels the player cannot yet select. 3. Button navigation indices: The GO button's down-navigation to button 8 (SET LEVEL) is correct based on the visual layout positions. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Introduces a new 'PROGRESS' button in the main menu, allowing players to view their progress across accessible levels. The progress menu displays each level's status, title, and remaining enemies, and enables switching to any discovered but uncleared level. Supporting code includes new menu logic, button definitions, and a helper for gathering level statistics.