Creates a way for simulation scripts to show message boxes to users via the GUI Interface, using the function "PushPopupRequest" (i.e. cmpGuiInterface.PushPopupRequest(...) ).
Programmers may optionally attach a callback function to each button by specifying the component IID and function name to call, as well as the entities to call the function on. Callback functions are executed by passing this data to the network command "execute-component-function".
This feature could be particularly useful in scenario trigger scripts, where you can present choices to the player and create a sort of "choose-your-adventure" storyline, or display important information.
Details
- Reviewers
Freagarach - Group Reviewers
Restricted Owners Package (Owns No Changed Paths)
Created a demo scenario script at binaries/data/mods/public/maps/scenarios/demo_popup_choices_triggers.js.
Demo scenario script includes three different types of popup messages:
- One with no specified choices, which should default to a simple "ok" button
- One with both a callback function and a null "ok" button
- One with two specified choices, each with a callback function
Ran the scenario as both playable factions and as an observer, trying every possible combination of choices and ensuring that the specified callback functions (or lack thereof) were triggered.
Diff Detail
- Repository
- rP 0 A.D. Public Repository
- Lint
Lint Skipped - Unit
Unit Tests Skipped
Event Timeline
Thanks for making time and adding this. @Freagarach I believe from this https://wildfiregames.com/forum/topic/51086-popup-choices-for-scenario-scripts/?tab=comments#comment-446466 discussion you wanted to add this. BTW is it not similar to https://github.com/AlexanderOlkhovskiy/0ad-civ-choices-mod ? which also would be nice to add.
Hi,
while waiting for review, could you please transform comments above functions and classes into javadoc style?
https://trac.wildfiregames.com/wiki/Coding_Conventions#Documentation
Also please try to keep comments to minimum and comment only necessary parts
*JSDoc
binaries/data/mods/public/maps/scenarios/demo_popup_choices_triggers.js | ||
---|---|---|
9 | I don't think we support translating that. Might need to be in a json file or something. Anyway demo maps should be in a mod but that's another story. |
(With context I meant like described here: https://trac.wildfiregames.com/wiki/SubmittingPatches#Makingsomechanges.)
binaries/data/mods/public/simulation/helpers/Commands.js | ||
---|---|---|
917 | A problem with such a generic command is that it is easy to misuse in e.g. MP since we can't check input. |
Yes @Angen, will do!
Yes, that's a pretty big oversight on my part. Maybe I should only allow the command to call Trigger functions and rename it to "execute-trigger-function"? I don't think that would be easy to abuse in-game, would it?
Or better yet, GuiInterface should give every popup request an id (could be as simple as uneval(request) + Math.random()) and store the ids in a Set. The execute-component-function command will call a GuiInterface function called ExecutePopupCommand, which will verify the id before executing the function. That should disable you from executing a command that didn't originate from within a popup request.