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

Flatten vehicle menus, make appliances menu top level #60868

Merged
merged 17 commits into from
Sep 14, 2022
Merged
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
7 changes: 7 additions & 0 deletions data/raw/keybindings.json
Original file line number Diff line number Diff line change
Expand Up @@ -1605,6 +1605,13 @@
"name": "Take down appliance",
"bindings": [ { "input_method": "keyboard_any", "key": "r" } ]
},
{
"type": "keybinding",
"id": "PLUG",
"category": "APP_INTERACT",
"name": "Plug in appliance",
"bindings": [ { "input_method": "keyboard_any", "key": "g" } ]
},
{
"type": "keybinding",
"id": "UNPLUG",
Expand Down
152 changes: 146 additions & 6 deletions data/raw/keybindings/vehicle.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[
{
"id": "CONTROL_MANY_ELECTRONICS",
"id": "EXAMINE_VEHICLE",
"type": "keybinding",
"category": "VEHICLE",
"name": "Control multiple electronics",
"bindings": [ { "input_method": "keyboard_char", "key": "E" }, { "input_method": "keyboard_code", "key": "e", "mod": [ "shift" ] } ]
"name": "Examine vehicle",
"bindings": [ { "input_method": "keyboard_any", "key": "e" } ]
},
{
"id": "CONTROL_ENGINES",
Expand All @@ -27,13 +27,153 @@
"name": "Release controls",
"bindings": [ { "input_method": "keyboard_any", "key": "l" } ]
},
{
"id": "HOTWIRE",
"type": "keybinding",
"category": "VEHICLE",
"name": "Attempt to hotwire",
"bindings": [ { "input_method": "keyboard_any", "key": "h" } ]
},
{
"id": "PULL_HANDBRAKE",
"type": "keybinding",
"category": "VEHICLE",
"name": "Pull handbrake",
"bindings": [ { "input_method": "keyboard_any", "key": "H" } ]
},
{
"id": "USE_WORKBENCH",
"type": "keybinding",
"category": "VEHICLE",
"name": "Use workbench",
"bindings": [ { "input_method": "keyboard_char", "key": "&" }, { "input_method": "keyboard_code", "key": "7", "mod": [ "shift" ] } ]
},
{
"id": "SOUND_HORN",
"type": "keybinding",
"category": "VEHICLE",
"name": "Sound horn",
"bindings": [ { "input_method": "keyboard_any", "key": "n" } ]
},
{
"id": "CONTROL_AUTOPILOT_PATROL",
"type": "keybinding",
"category": "VEHICLE",
"name": "Set autopilot to patrol nearby zone",
"bindings": [ { "input_method": "keyboard_any", "key": "p" } ]
},
{
"id": "CONTROL_AUTOPILOT_FOLLOW",
"type": "keybinding",
"category": "VEHICLE",
"name": "Set autopilot to follow you",
"bindings": [ { "input_method": "keyboard_any", "key": "f" } ]
},
{
"id": "CONTROL_AUTOPILOT_STOP",
"type": "keybinding",
"category": "VEHICLE",
"name": "Set autopilot to stop all activities",
"bindings": [ { "input_method": "keyboard_any", "key": "s" } ]
},
{
"id": "CONTROL_SMART_ENGINE",
"type": "keybinding",
"category": "VEHICLE",
"name": "Smart controller settings",
"bindings": [ ]
},
{
"id": "TOGGLE_AUTOCLAVE",
"type": "keybinding",
"category": "VEHICLE",
"name": "Toggle autoclave",
"bindings": [ { "input_method": "keyboard_any", "key": "C" } ]
},
{
"id": "TOGGLE_WASHING_MACHINE",
"type": "keybinding",
"category": "VEHICLE",
"name": "Toggle washing machine",
"bindings": [ { "input_method": "keyboard_any", "key": "W" } ]
},
{
"id": "TOGGLE_DISHWASHER",
"type": "keybinding",
"category": "VEHICLE",
"name": "Toggle dishwasher",
"bindings": [ { "input_method": "keyboard_any", "key": "D" } ]
},
{
"id": "GET_ITEMS",
"type": "keybinding",
"category": "VEHICLE",
"name": "Get items",
"bindings": [ { "input_method": "keyboard_any", "key": "g" } ]
},
{
"id": "UNLOAD_TURRET",
"type": "keybinding",
"category": "VEHICLE",
"name": "Unload turret",
"bindings": [ { "input_method": "keyboard_any", "key": "u" } ]
},
{
"id": "RELOAD_TURRET",
"type": "keybinding",
"category": "VEHICLE",
"name": "Reload turret",
"bindings": [ { "input_method": "keyboard_any", "key": "r" } ]
},
{
"id": "CURTAIN_PEEK",
"type": "keybinding",
"category": "VEHICLE",
"name": "Peek through closed curtains",
"bindings": [ { "input_method": "keyboard_any", "key": "p" } ]
},
{
"id": "FAUCET_FILL",
"type": "keybinding",
"category": "VEHICLE",
"name": "Fill container with water from faucet",
"bindings": [ { "input_method": "keyboard_any", "key": "c" } ]
},
{
"id": "FAUCET_DRINK",
"type": "keybinding",
"category": "VEHICLE",
"name": "Drink from faucet",
"bindings": [ { "input_method": "keyboard_any", "key": "d" } ]
},
{
"id": "PURIFY_WATER",
"type": "keybinding",
"category": "VEHICLE",
"name": "Purify water in vehicle tank",
"bindings": [ { "input_method": "keyboard_any", "key": "P" } ]
},
{
"id": "USE_CAPTURE_MONSTER_VEH",
"type": "keybinding",
"category": "VEHICLE",
"name": "Capture or release a creature",
"bindings": [ { "input_method": "keyboard_any", "key": "G" } ]
},
{
"id": "USE_ANIMAL_CTRL",
"type": "keybinding",
"category": "VEHICLE",
"name": "Harness an animal",
"bindings": [ { "input_method": "keyboard_any", "key": "H" } ]
},
{
"id": "USE_PLANTER",
"type": "keybinding",
"category": "VEHICLE",
"name": "Reload seed drill with seeds",
"bindings": [ { "input_method": "keyboard_any", "key": "s" } ]
},
{
"id": "TOGGLE_AISLE_LIGHT",
"type": "keybinding",
Expand Down Expand Up @@ -81,7 +221,7 @@
"type": "keybinding",
"category": "VEHICLE",
"name": "Toggle cruise control",
"bindings": [ { "input_method": "keyboard_any", "key": "c" } ]
"bindings": [ ]
},
{
"id": "TOGGLE_DOME_LIGHT",
Expand All @@ -102,7 +242,7 @@
"type": "keybinding",
"category": "VEHICLE",
"name": "Toggle engine",
"bindings": [ { "input_method": "keyboard_any", "key": "e" } ]
"bindings": [ { "input_method": "keyboard_any", "key": "s" } ]
},
{
"id": "TOGGLE_FRIDGE",
Expand All @@ -123,7 +263,7 @@
"type": "keybinding",
"category": "VEHICLE",
"name": "Toggle space heater",
"bindings": [ { "input_method": "keyboard_any", "key": "s" } ]
"bindings": [ { "input_method": "keyboard_any", "key": "J" } ]
},
{
"id": "TOGGLE_HEATED_TANK",
Expand Down
22 changes: 15 additions & 7 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5232,6 +5232,12 @@ void game::control_vehicle()
{
int veh_part = -1;
vehicle *veh = remoteveh();
if( veh != nullptr ) {
for( const vpart_reference &vpr : veh->get_avail_parts( "REMOTE_CONTROLS" ) ) {
veh->interact_with( vpr.pos() );
return;
}
}
if( veh == nullptr ) {
if( const optional_vpart_position vp = m.veh_at( u.pos() ) ) {
veh = &vp->vehicle();
Expand All @@ -5240,7 +5246,7 @@ void game::control_vehicle()
}
if( veh != nullptr && veh->player_in_control( u ) &&
veh->avail_part_with_feature( veh_part, "CONTROLS" ) >= 0 ) {
veh->use_controls( u.pos() );
veh->interact_with( u.pos() );
} else if( veh && veh->player_in_control( u ) &&
veh->avail_part_with_feature( veh_part, "CONTROL_ANIMAL" ) >= 0 ) {
u.controlling_vehicle = false;
Expand All @@ -5249,8 +5255,8 @@ void game::control_vehicle()
( veh->avail_part_with_feature( veh_part, "CONTROL_ANIMAL" ) >= 0 &&
veh->has_engine_type( fuel_type_animal, false ) && veh->has_harnessed_animal() ) ) &&
u.in_vehicle ) {
if( !veh->interact_vehicle_locked() ) {
veh->handle_potential_theft( dynamic_cast<Character &>( u ) );
if( veh->is_locked ) {
veh->interact_with( u.pos() );
return;
}
if( veh->engine_on ) {
Expand Down Expand Up @@ -5305,9 +5311,7 @@ void game::control_vehicle()
if( !veh->handle_potential_theft( dynamic_cast<Character &>( u ) ) ) {
return;
}
veh->use_controls( *vehicle_position );
//May be folded up (destroyed), so need to re-get it
veh = g->remoteveh();
veh->interact_with( *vehicle_position );
}
}
if( veh ) {
Expand Down Expand Up @@ -5616,7 +5620,11 @@ void game::examine( const tripoint &examp, bool with_pickup )
const optional_vpart_position vp = m.veh_at( examp );
if( vp ) {
if( !u.is_mounted() || u.mounted_creature->has_flag( MF_RIDEABLE_MECH ) ) {
vp->vehicle().interact_with( *vp, with_pickup );
if( !vp->vehicle().has_tag( "APPLIANCE" ) ) {
vp->vehicle().interact_with( examp, with_pickup );
} else {
g->exam_appliance( vp->vehicle(), vp->mount() );
}
return;
} else {
add_msg( m_warning, _( "You cannot interact with a vehicle while mounted." ) );
Expand Down
4 changes: 2 additions & 2 deletions src/iuse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8038,9 +8038,9 @@ cata::optional<int> iuse::remoteveh( Character *p, item *it, bool t, const tripo
const auto rctrl_parts = veh->get_avail_parts( "REMOTE_CONTROLS" );
// Revert to original behavior if we can't find remote controls.
if( empty( rctrl_parts ) ) {
veh->use_controls( pos );
veh->interact_with( pos );
} else {
veh->use_controls( rctrl_parts.begin()->pos() );
veh->interact_with( rctrl_parts.begin()->pos() );
}
}

Expand Down
42 changes: 32 additions & 10 deletions src/veh_appliance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "units.h"
#include "veh_appliance.h"
#include "veh_type.h"
#include "veh_utils.h"
#include "vehicle.h"
#include "vpart_range.h"

Expand Down Expand Up @@ -458,6 +459,13 @@ void veh_app_interact::remove()
}
}

void veh_app_interact::plug()
{
const int part = veh->part_at( a_point );
const tripoint pos = veh->global_part_pos3( part );
veh->plug_in( get_map().getabs( pos ) );
}

void veh_app_interact::unplug()
{
veh->shed_loose_parts();
Expand Down Expand Up @@ -510,6 +518,13 @@ void veh_app_interact::populate_app_actions()
} );
imenu.addentry( -1, true, ctxt.keys_bound_to( "REMOVE" ).front(),
ctxt.get_action_name( "REMOVE" ) );
// Plug
app_actions.emplace_back( [this]() {
plug();
} );
imenu.addentry( -1, true, ctxt.keys_bound_to( "PLUG" ).front(),
ctxt.get_action_name( "PLUG" ) );

// Unplug
app_actions.emplace_back( [this]() {
unplug();
Expand All @@ -518,12 +533,14 @@ void veh_app_interact::populate_app_actions()
ctxt.get_action_name( "UNPLUG" ) );

/*************** Get part-specific actions ***************/
std::vector<uilist_entry> tmp_opts;
std::vector<std::function<void()>> tmp_acts;
veh->set_electronics_menu_options( tmp_opts, tmp_acts );
for( size_t i = 0; i < tmp_opts.size() && i < ctxt_letters.size(); i++ ) {
imenu.addentry( -1, tmp_opts[i].enabled, ctxt_letters[i], tmp_opts[i].txt );
app_actions.emplace_back( tmp_acts[i] );
veh_menu menu( veh, "IF YOU SEE THIS IT IS A BUG" );
veh->build_interact_menu( menu, veh->mount_to_tripoint( a_point ), false );
const std::vector<veh_menu_item> items = menu.get_items();
for( size_t i = 0; i < items.size(); i++ ) {
const veh_menu_item &it = items[i];
const char hotkey = i < ctxt_letters.size() ? ctxt_letters[i] : 0;
imenu.addentry( -1, it._enabled, hotkey, it._text );
app_actions.emplace_back( it._on_submit );
}
imenu.setup();
}
Expand Down Expand Up @@ -557,10 +574,15 @@ void veh_app_interact::app_loop()
populate_app_actions();
repop_actions = false;
}
shared_ptr_fast<ui_adaptor> current_ui = create_or_get_ui_adaptor();
ui_manager::redraw();
shared_ptr_fast<ui_adaptor> input_ui = imenu.create_or_get_ui_adaptor();
imenu.query();

// scope this tighter so that this ui is hidden when app_actions[ret]() triggers
{
shared_ptr_fast<ui_adaptor> current_ui = create_or_get_ui_adaptor();
ui_manager::redraw();
shared_ptr_fast<ui_adaptor> input_ui = imenu.create_or_get_ui_adaptor();
imenu.query();
}

int ret = imenu.ret;
if( ret < 0 || static_cast<size_t>( ret ) >= imenu.entries.size() ) {
done = true;
Expand Down
5 changes: 5 additions & 0 deletions src/veh_appliance.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ class veh_app_interact
* Turns the installed appliance into its base item.
*/
void remove();
/**
* Function associated with the "PLUG" action.
* Connects the power cable to selected tile.
*/
void plug();
/**
* Function associated with the "UNPLUG" action.
* Removes all power connections to other appliances and vehicles and drops
Expand Down
Loading