Skip to content

Commit

Permalink
eoc select cancel (CleverRaven#68625)
Browse files Browse the repository at this point in the history
  • Loading branch information
lispcoc authored and detahramet committed Nov 6, 2023
1 parent 3c8b3f5 commit 340b292
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
3 changes: 2 additions & 1 deletion data/json/effects_on_condition/example_eocs.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"names": [ "name_1", "name_2", "name_3", "should_fail" ],
"keys": [ "a", "b", "c", "d" ],
"descriptions": [ "option 1", "option 2", "option 3", "should not be available" ],
"variables": [ { "val": "8" } ]
"variables": [ { "val": "8" } ],
"allow_cancel": true
}
]
},
Expand Down
2 changes: 1 addition & 1 deletion doc/NPCs.md
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,7 @@ Effect | Description
`offer_mission: `string or [variable object](#variable-object) or array of them | Adds mission_type_id(s) to the npc's missions that they offer. Assumes if there is no beta talker that the alpha is an NPC.
`run_eocs :` effect_on_condition_array or single effect_condition_object | Will run up all members of the `effect_on_condition_array`. Members should either be the id of an effect_on_condition or an inline effect_on_condition.
`run_eoc_with :` single effect_condition_object, `variables :` Object with variable names and values as pairs `beta_loc` a variable containing a location | Runs the given EOC with the provided variables as context variables. EOC should either be the id of an effect_on_condition or an inline effect_on_condition. If `beta_loc` is provided then the creature at the given location will become the beta talker for the EOC to run.
`run_eoc_select :` array of strings or [variable objects](#variable-object), `variables :` Object with variable names and values as pairs, `names: ` string or variables, `keys: ` single character strings, `title: ` string, `hide_failing`: bool | Opens a menu with title `title` that lets you select one of the EOCs whos ids are in the array provided, they each get a matched `names`, `description`, and `keys` value if provided, selected EOC runs with the provided variables as context variables. EOC should either be the id of an effect_on_condition or variable containing the ID of an effect on condition. If `hide_failing` is true EOCs whos condition fail will be hidden instead of shown and unselectable.
`run_eoc_select:` array of strings or [variable objects](#variable-object), `variables:` Object with variable names and values as pairs, `names: ` string or variables, `keys: ` single character strings, (*optional* `title: ` string)(*optional* `hide_failing`: bool), (*optional* `allow_cancel`: bool) | Opens a menu with title `title` that lets you select one of the EOCs whos ids are in the array provided, they each get a matched `names`, `description`, and `keys` value if provided, selected EOC runs with the provided variables as context variables. EOC should either be the id of an effect_on_condition or variable containing the ID of an effect on condition. If `hide_failing`(defaults to false) is true EOCs whos condition fail will be hidden instead of shown and unselectable. If `allow_cancel` (defaults to false) is true it is allowed that quit menu without selecting option and running EOC.
`queue_eocs : effect_on_condition_array or single effect_condition_object`, `time_in_future: `duration or [variable object](#variable-object) | Will queue up all members of the `effect_on_condition_array`. Members should either be the id of an effect_on_condition or an inline effect_on_condition. Members will be run `time_in_future` in the future. If the eoc is global the avatar will be u and npc will be invalid. Otherwise it will be queued for the current alpha if they are a character and not be queued otherwise.
`queue_eoc_with :` single effect_condition_object, `variables :` Object with variable names and values as pairs, `time_in_future: `duration or [variable object](#variable-object) | Queues the given EOC with the provided variables as context variables. EOC should either be the id of an effect_on_condition or an inline effect_on_condition. EOC will be run `time_in_future` in the future. If the eoc is global the avatar will be u and npc will be invalid. Otherwise it will be queued for the current alpha if they are a character and not be queued otherwise.
`u_roll_remainder, npc_roll_remainder : `array of strings and/or [variable objects](#variable-object), `type: `string or [variable object](#variable-object), (*optional* `true_eocs: eocs_array`), (*optional* `false_eocs: eocs_array`), (*optional* `message: ` string or [variable object](#variable-object) ) | Type must be either `bionic`, `mutation`, `spell` or `recipe`. If the u or npc does not have all of the listed bionics, mutations, spells, or recipes they will be given one randomly and and then all of the effect_on_conditions in `true_eocs` are run, otherwise all the effect_on_conditions in `false_eocs` are run. If `message` is provided and a result is given then the `message` will be displayed as a message with the first instance of `%s` in it replaced with the name of the result selected.
Expand Down
12 changes: 10 additions & 2 deletions src/npctalk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4557,14 +4557,19 @@ void talk_effect_fun_t::set_run_eoc_selector( const JsonObject &jo, std::string_
hide_failing = jo.get_bool( "hide_failing" );
}

bool allow_cancel = false;
if( jo.has_bool( "allow_cancel" ) ) {
allow_cancel = jo.get_bool( "allow_cancel" );
}

std::string title = jo.get_string( "title", _( "Select an option." ) );

function = [eocs, context, title, eoc_names, eoc_keys, eoc_descriptions,
hide_failing]( dialogue & d ) {
hide_failing, allow_cancel]( dialogue & d ) {
uilist eoc_list;

eoc_list.text = title;
eoc_list.allow_cancel = false;
eoc_list.allow_cancel = allow_cancel;
eoc_list.desc_enabled = !eoc_descriptions.empty();

for( size_t i = 0; i < eocs.size(); i++ ) {
Expand Down Expand Up @@ -4605,6 +4610,9 @@ void talk_effect_fun_t::set_run_eoc_selector( const JsonObject &jo, std::string_
}

eoc_list.query();
if( eoc_list.ret < 0 ) {
return;
}

// add context variables
dialogue newDialog( d );
Expand Down

0 comments on commit 340b292

Please sign in to comment.