I was doing some code work on my game Quinlin.
The code was related to how in game menus are structured and I just realized I didn't implement a feature I had originally wanted.
The feature was the ability to define different forms of the same menu and also with regards to hiding and showing different menu selections.
I'm reading the code and then realize my document made no sense on how the menu selection handling worked.
It was something along the lines of
Each menu selection had an array called selection_key = [array values]
These were literally just numbers, a common thing I do (I use macros and enums too but sometimes I ignore this and use old habits).
So I then kind of trace the code and realize the way I explained how its supposed to work made no sense at all.
The menu itself was suppose to hold an array of values, the code reviewed those values to the menu's selections to determine how they'd display.
Bht the kicker was, this made no sense for how I imagined the system to work.
So I refactored and did this instead:
I created a variable used to track the index. Made the arrays represent states and then used that state to represent the selections.
Active_menu_index = 0
Selection_key = [0,1,1]
Basically, the menu wont show the selection in menu form 0.
But if the form (index) is 1 or 2, it shows.
Before the menu data would have required me to inject updates mid game, while this new design is preset and then updated mid game to properly show so I can now easily remove or add menu selections to a specific menu form of that menu.
Two examples:
- Tents - player owned tents have the pick up selection option. While NPC/Environmental tents do not.
- Let's say a menu requires players to obtain/have access to a specific item/location. The game can show the option but make it inert thus allowing the player to view details regarding that selection and possible requirements.
This was honestly such an odd thing. I also kind of hate it when I do something halfway thinking I'll do it later. My old system would have worked but was so confusing.