Page MenuHomeWildfire Games

Popup Choice Message Boxes
Needs ReviewPublic

Authored by hopeless-ponderer on Aug 13 2021, 8:28 AM.

Details

Reviewers
Freagarach
Group Reviewers
Restricted Owners Package(Owns No Changed Paths)
Summary

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.

Test Plan

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

hopeless-ponderer requested review of this revision.Aug 13 2021, 8:28 AM
hopeless-ponderer created this revision.
asterix added subscribers: Freagarach, asterix.

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.

marder added a subscriber: marder.Aug 13 2021, 9:46 AM

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

Stan added a subscriber: Stan.Aug 13 2021, 6:26 PM

*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.

Silier added a reviewer: Restricted Owners Package.Aug 13 2021, 7:24 PM
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.
So one can just call "delete" on an entity of the enemy (although that is probably filtered out at the top of this file), or "promote" on their own.

hopeless-ponderer added a comment.EditedAug 14 2021, 11:42 PM

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.

Silier removed a reviewer: Silier.Sep 11 2021, 11:35 AM