So the first thing I tried was pretty simple:
When something is clicked, a function executes that tells the clicked object to open the context menu.
Each object has an array of actions and sends that array.
The context menu creates buttons for each action, getting the button index that is clicked, sending back that index to the object.
The object, using that index, gets the index of the actions and performs that action.
Very simple and works really well.
However, often data is associated with options. So an action might be to go to a location. Well, then that location needs to be sent from the context menu to the object. Or it might have something to do with an actor, or another actor class. Getting that data back to the object proved difficult. Additionally, I didn’t want to clutter the context menu with methods, rather I wanted the button to know what is needed and only that.
So now, a button has a specific task - if it is clicked, get whatever data it is designed to get and send it directly to the object.
The Object still has the actions array. If the action requires data, a specific widget have been designed for that action and the context menu will add that widget.
If no data is needed, the previous method is used to send back the action index.
What I don’t like about this new method is that when the context menu is created, it creates each type of these special data-fetching widgets. So practically I have a context menu that has all possible actions that ANY object could make, it’s just not showing them. It feels like this defeats the purpose of a context menu, even if from a user perspective, it seems like any context menu.
Any thoughts on that would be appreciated.