Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug menu: dialogue menu + talk_topic menu #76566

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/avatar.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ class avatar : public Character

// Dialogue and bartering--see npctalk.cpp
void talk_to( std::unique_ptr<talker> talk_with, bool radio_contact = false,
bool is_computer = false, bool is_not_conversation = false );
bool is_computer = false, bool is_not_conversation = false, std::string debug_topic = "" );

/**
* Try to disarm the NPC. May result in fail attempt, you receiving the weapon and instantly wielding it,
Expand Down
56 changes: 55 additions & 1 deletion src/debug_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
#include "mutation.h"
#include "npc.h"
#include "npc_class.h"
#include "npctalk.h"
#include "omdata.h"
#include "options.h"
#include "output.h"
Expand Down Expand Up @@ -270,6 +271,7 @@
case debug_menu::debug_menu_index::SIX_MILLION_DOLLAR_SURVIVOR: return "SIX_MILLION_DOLLAR_SURVIVOR";
case debug_menu::debug_menu_index::EDIT_FACTION: return "EDIT_FACTION";
case debug_menu::debug_menu_index::WRITE_CITY_LIST: return "WRITE_CITY_LIST";
case debug_menu::debug_menu_index::TALK_TOPIC: return "TALK_TOPIC";
// *INDENT-ON*
case debug_menu::debug_menu_index::last:
break;
Expand Down Expand Up @@ -915,7 +917,14 @@
return uilist( _( "Faction" ), uilist_initializer );
}

static int dialogue_uilist()
{
const std::vector<uilist_entry> uilist_initializer = {
{ uilist_entry( debug_menu_index::TALK_TOPIC, true, 't', _( "Display talk topic" ) ) }
};

return uilist( _( "Dialogue…" ), uilist_initializer );
}

/**
* Create the debug menu UI list.
Expand All @@ -926,7 +935,7 @@
static std::optional<debug_menu_index> debug_menu_uilist( bool display_all_entries = true )
{
enum {
D_INFO, D_GAME, D_SPAWNING, D_PLAYER, D_MONSTER, D_FACTION, D_VEHICLE, D_TELEPORT, D_MAP, D_QUICK_SETUP
D_INFO, D_GAME, D_SPAWNING, D_PLAYER, D_MONSTER, D_FACTION, D_VEHICLE, D_TELEPORT, D_MAP, D_DIALOGUE, D_QUICK_SETUP
};

std::vector<uilist_entry> menu = {
Expand All @@ -943,6 +952,7 @@
{ uilist_entry( D_VEHICLE, true, 'v', _( "Vehicle…" ) ) },
{ uilist_entry( D_TELEPORT, true, 't', _( "Teleport…" ) ) },
{ uilist_entry( D_MAP, true, 'm', _( "Map…" ) ) },
{ uilist_entry( D_DIALOGUE, true, 'd', _( "Dialogue…" ) ) },
{ uilist_entry( D_QUICK_SETUP, true, 'q', _( "Quick setup…" ) ) },
};

Expand Down Expand Up @@ -998,6 +1008,9 @@
case D_VEHICLE:
action = vehicle_uilist();
break;
case D_DIALOGUE:
action = dialogue_uilist();
break;
case D_QUICK_SETUP:
action = quick_setup_uilist();
break;
Expand Down Expand Up @@ -3055,6 +3068,43 @@
}
}

static void display_talk_topic()
{
avatar &a = get_avatar();
int menu_ind = 0;
uilist npc_menu;
npc_menu.text = _( "Choose NPC to hold topic:" );
std::vector<npc *> visible_npcs = g->get_npcs_if( [&]( const npc & n ) {
return a.sees( n );
} );
int npc_count = static_cast<int>( visible_npcs.size() );
if( npc_count > 0 ) {
for( npc *n : visible_npcs ) {
npc_menu.addentry( menu_ind, true, MENU_AUTOASSIGN, n->disp_name() );
}
npc_menu.query();
if( npc_menu.ret >= 0 && npc_menu.ret < npc_count ) {
npc *selected_npc = visible_npcs[npc_menu.ret];
std::vector<std::string> dialogue_ids = get_all_talk_topic_ids();
std::sort( dialogue_ids.begin(), dialogue_ids.end(), localized_compare );
uilist talk_topic_menu;
talk_topic_menu.text = _( "Choose talk topic to display:" );
int menu_ind = 0;
for( auto &elem : dialogue_ids ) {
talk_topic_menu.addentry( menu_ind, true, MENU_AUTOASSIGN, elem );
++menu_ind;
}
talk_topic_menu.query();
if( talk_topic_menu.ret >= 0 && talk_topic_menu.ret < static_cast<int>( dialogue_ids.size() ) ) {
const std::string selected_topic = dialogue_ids[talk_topic_menu.ret];
a.talk_to( get_talker_for( selected_npc ), false, false, false, selected_topic );
}
}
} else {
add_msg( m_bad, _( "You need an NPC to add a talk topic to." ) );
}
}

static void debug_menu_force_temperature()
{
uilist tempmenu;
Expand Down Expand Up @@ -4166,8 +4216,12 @@
break;

case debug_menu_index::WRITE_CITY_LIST:
write_city_list();

Check failure on line 4219 in src/debug_menu.cpp

View workflow job for this annotation

GitHub Actions / GCC 9, Curses, LTO

this statement may fall through [-Werror=implicit-fallthrough=]

case debug_menu_index::TALK_TOPIC:
display_talk_topic();
break;

case debug_menu_index::last:
return;
}
Expand Down
1 change: 1 addition & 0 deletions src/debug_menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ enum class debug_menu_index : int {
SIX_MILLION_DOLLAR_SURVIVOR,
EDIT_FACTION,
WRITE_CITY_LIST,
TALK_TOPIC,
last
};

Expand Down
28 changes: 21 additions & 7 deletions src/npctalk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1369,10 +1369,11 @@
}

void avatar::talk_to( std::unique_ptr<talker> talk_with, bool radio_contact,
bool is_computer, bool is_not_conversation )
bool is_computer, bool is_not_conversation, std::string debug_topic )

Check failure on line 1372 in src/npctalk.cpp

View workflow job for this annotation

GitHub Actions / build (src)

the parameter 'debug_topic' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param,-warnings-as-errors]
{
const bool has_mind_control = has_trait( trait_DEBUG_MIND_CONTROL );
if( !talk_with->will_talk_to_u( *this, has_mind_control ) ) {
const bool force_topic = debug_topic.size() > 0;

Check failure on line 1375 in src/npctalk.cpp

View workflow job for this annotation

GitHub Actions / build (src)

the 'empty' method should be used to check for emptiness instead of 'size' [readability-container-size-empty,-warnings-as-errors]
if( !talk_with->will_talk_to_u( *this, has_mind_control || force_topic ) ) {
return;
}
dialogue d( get_talker_for( *this ), std::move( talk_with ), {} );
Expand All @@ -1384,11 +1385,15 @@
d.missions_assigned.push_back( mission );
}
}
for( const std::string &topic_id : d.actor( true )->get_topics( radio_contact ) ) {
d.add_topic( topic_id );
}
for( const std::string &topic_id : d.actor( true )->get_topics( radio_contact ) ) {
d.add_topic( topic_id );
if( !force_topic ) {
for( const std::string &topic_id : d.actor( true )->get_topics( radio_contact ) ) {
d.add_topic( topic_id );
}
for( const std::string &topic_id : d.actor( true )->get_topics( radio_contact ) ) {
d.add_topic( topic_id );
}
} else {
d.add_topic( debug_topic );
}
dialogue_window d_win;
d_win.is_computer = is_computer;
Expand Down Expand Up @@ -7668,3 +7673,12 @@
return &it->second;
}

const std::vector<std::string> get_all_talk_topic_ids()

Check failure on line 7676 in src/npctalk.cpp

View workflow job for this annotation

GitHub Actions / build (src)

return type 'const std::vector<std::string>' (aka 'const vector<basic_string<char>>') is 'const'-qualified at the top level, which may reduce code readability without improving const correctness [readability-const-return-type,-warnings-as-errors]
{
std::vector<std::string> dialogue_ids;
for( auto &elem : json_talk_topics ) {
dialogue_ids.push_back( elem.first );

Check failure on line 7680 in src/npctalk.cpp

View workflow job for this annotation

GitHub Actions / build (src)

'push_back' is called inside a loop; consider pre-allocating the container capacity before the loop [performance-inefficient-vector-operation,-warnings-as-errors]
}
return dialogue_ids;
}

2 changes: 2 additions & 0 deletions src/npctalk.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ int calc_spell_training_cost( const Character &teacher, const Character &student

const json_talk_topic *get_talk_topic( const std::string &id );

const std::vector<std::string> get_all_talk_topic_ids();

std::vector<int> npcs_select_menu( const std::vector<Character *> &npc_list,
const std::string &prompt,
const std::function<bool( const Character * )> &exclude_func );
Expand Down
Loading