It is difficult to give a concrete answer, since you did not indicate (or did not mark) the platform for which it is necessary, so I will write a general answer.
The answer to your question:
"Is there a way to do this by storing the associated action in the OnActivated () function?"
Most likely, this is "No."
There are many tried and true patterns to solve the problem you are describing. This family of templates is the various Model-View-XXX models (MVC, MVP, Document-View, etc.). The basic premise of these templates is that there is a construction, usually a graph of objects that encapsulates the current state of the system (The Model) and a set of user interface elements (The Views) that display this state to the user. Whenever a model changes Views changes to match a new state. The details of how the model changes and the views are updated, set different templates in the family separately, and the used ones depend on how the input is processed for a particular system. MVC is suitable for Internet applications and many loop-based games because user input has a single entry point into the system. MVP, DV, and MVVM (which some claim to be the same as MVP) are better suited for desktop applications where input is actively managed in the GUI.
The disadvantage of using these templates is that the code for creating the view is rarely accompanied by the code for the associated action, but the advantages far exceed this disadvantage.
In your case, your model should have a property for the dialog text and a property for storing the current input handler (state template). Your main loop will do the following:
- Get the current input handler to update the model based on user input, if any (for example, change the position of the user sprite).
- Update the rest of the Model to reflect other elements in the game.
- UI update based on current model
When the user clicks in front of the NPC, the default input handler changes the input input value for the specific dialog box and the general view for the dialog box displays the text to the user.
When the user selects an action in the dialog box, the handler returns to the default input handler, and the property for the dialog returns to empty.
Steps 1 and 2 make up the Controller in the MVC template, and step 3 is an event-independent update; conversely, you can use the Observable-Observer pattern and have model throw events that are observed in views that change accordingly.