From 9ab9b45c398de8db0d6f59e9b73640a8b68f684f Mon Sep 17 00:00:00 2001 From: Procyonae <45432782+Procyonae@users.noreply.github.com> Date: Thu, 12 Dec 2024 16:58:39 +0000 Subject: [PATCH 1/5] Add the ability to hide/unhide wall wiring sprite --- data/raw/keybindings.json | 7 +++++++ src/veh_appliance.cpp | 15 +++++++++++++++ src/veh_appliance.h | 5 +++++ src/vehicle.h | 3 +++ src/vehicle_display.cpp | 3 +++ 5 files changed, 33 insertions(+) diff --git a/data/raw/keybindings.json b/data/raw/keybindings.json index 4d005f545b637..389735123a80e 100644 --- a/data/raw/keybindings.json +++ b/data/raw/keybindings.json @@ -1799,6 +1799,13 @@ "name": "Plug in appliance", "bindings": [ { "input_method": "keyboard_any", "key": "g" } ] }, + { + "type": "keybinding", + "id": "HIDE", + "category": "APP_INTERACT", + "name": "Hide/Unhide wiring", + "bindings": [ { "input_method": "keyboard_any", "key": "h" } ] + }, { "type": "keybinding", "id": "DISCONNECT_GRID", diff --git a/src/veh_appliance.cpp b/src/veh_appliance.cpp index cbc5bac267d57..c79d83fcfd24d 100644 --- a/src/veh_appliance.cpp +++ b/src/veh_appliance.cpp @@ -536,6 +536,13 @@ void veh_app_interact::plug() } } +void veh_app_interact::hide() +{ + const int part_idx = veh->part_at( veh->coord_translate( a_point ) ); + vehicle_part &vp = veh->part( part_idx ); + vp.hidden = !vp.hidden; +} + void veh_app_interact::populate_app_actions() { map &here = get_map(); @@ -585,6 +592,14 @@ void veh_app_interact::populate_app_actions() string_format( "%s%s", ctxt.get_action_name( "PLUG" ), //~ An addendum to Plug In's description, as in: Plug in appliance / merge power grid". veh->is_powergrid() ? _( " / merge power grid" ) : "" ) ); +#if defined(TILES) + // Hide + app_actions.emplace_back( [this]() { + hide(); + } ); + imenu.addentry( -1, use_tiles && vp->info().has_flag( flag_WIRING ), + ctxt.keys_bound_to( "HIDE" ).front(), ctxt.get_action_name( "HIDE" ) ); +#endif if( veh->is_powergrid() && veh->part_count() > 1 && !vp->info().has_flag( VPFLAG_WALL_MOUNTED ) ) { // Disconnect from power grid diff --git a/src/veh_appliance.h b/src/veh_appliance.h index 923f6580efe15..e456ade5aac90 100644 --- a/src/veh_appliance.h +++ b/src/veh_appliance.h @@ -139,6 +139,11 @@ class veh_app_interact * Connects the power cable to selected tile. */ void plug(); + /** + * Function associated with the "HIDE" action. + * Hides the selected tiles sprite. + */ + void hide(); /** * The main loop of the appliance UI. Redraws windows, checks for input, and * performs selected actions. The loop exits once an activity is assigned diff --git a/src/vehicle.h b/src/vehicle.h index eb49f8986dc1a..0a680fa1b7634 100644 --- a/src/vehicle.h +++ b/src/vehicle.h @@ -519,6 +519,9 @@ struct vehicle_part { /** door is locked */ bool locked = false; + // If the part's sprite/symbol shouldn't be shown + bool hidden = false; + /** direction the part is facing */ units::angle direction = 0_degrees; diff --git a/src/vehicle_display.cpp b/src/vehicle_display.cpp index bb63d0e400723..7ad79c78a64dd 100644 --- a/src/vehicle_display.cpp +++ b/src/vehicle_display.cpp @@ -66,6 +66,9 @@ vpart_display vehicle::get_display_of_tile( const point_rel_ms &dp, bool rotate, } const vehicle_part &vp = part( part_idx ); + if( vp.hidden ) { + return {}; + } const vpart_info &vpi = vp.info(); auto variant_it = vpi.variants.find( vp.variant ); From af0f2987ecb663489f326ec5ed6fa634fe73669a Mon Sep 17 00:00:00 2001 From: Procyonae <45432782+Procyonae@users.noreply.github.com> Date: Thu, 12 Dec 2024 17:02:20 +0000 Subject: [PATCH 2/5] Add WIRED_WALL to walls missing it in parametrized_walls_palette --- data/json/furniture_and_terrain/terrain-walls.json | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/data/json/furniture_and_terrain/terrain-walls.json b/data/json/furniture_and_terrain/terrain-walls.json index 9a6cb3a9f98fe..7f2c4b700d136 100644 --- a/data/json/furniture_and_terrain/terrain-walls.json +++ b/data/json/furniture_and_terrain/terrain-walls.json @@ -59,7 +59,8 @@ "name": { "str": "abstract concrete wall", "//~": "NO_I18N" }, "description": "Encompasses most concrete-like walls. If you see this in-game, it's a bug.", "roof": "t_concrete_roof", - "color": "light_gray" + "color": "light_gray", + "extend": { "flags": [ "WIRED_WALL" ] } }, { "type": "terrain", @@ -68,7 +69,8 @@ "name": { "str": "abstract brick wall", "//~": "NO_I18N" }, "description": "Encompasses most brick-like walls. If you see this in-game, it's a bug.", "roof": "t_brick_roof", - "color": "brown" + "color": "brown", + "extend": { "flags": [ "WIRED_WALL" ] } }, { "type": "terrain", From 1398e7f46c8866b2e985f17067369db473553639 Mon Sep 17 00:00:00 2001 From: Procyonae <45432782+Procyonae@users.noreply.github.com> Date: Thu, 12 Dec 2024 18:10:14 +0000 Subject: [PATCH 3/5] Make the option fully hide when not relevant rather than just grayed out --- src/veh_appliance.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/veh_appliance.cpp b/src/veh_appliance.cpp index c79d83fcfd24d..91aab9ac0a4ca 100644 --- a/src/veh_appliance.cpp +++ b/src/veh_appliance.cpp @@ -1,3 +1,4 @@ +#include "cached_options.h" #include "game.h" #include "handle_liquid.h" #include "imgui/imgui.h" @@ -594,11 +595,12 @@ void veh_app_interact::populate_app_actions() veh->is_powergrid() ? _( " / merge power grid" ) : "" ) ); #if defined(TILES) // Hide - app_actions.emplace_back( [this]() { - hide(); - } ); - imenu.addentry( -1, use_tiles && vp->info().has_flag( flag_WIRING ), - ctxt.keys_bound_to( "HIDE" ).front(), ctxt.get_action_name( "HIDE" ) ); + if( use_tiles && vp->info().has_flag( flag_WIRING ) ) { + app_actions.emplace_back( [this]() { + hide(); + } ); + imenu.addentry( -1, true, ctxt.keys_bound_to( "HIDE" ).front(), ctxt.get_action_name( "HIDE" ) ); + } #endif if( veh->is_powergrid() && veh->part_count() > 1 && !vp->info().has_flag( VPFLAG_WALL_MOUNTED ) ) { From 3a03335db0ca620ee81d0d980593dd12439d4ce0 Mon Sep 17 00:00:00 2001 From: Procyonae <45432782+Procyonae@users.noreply.github.com> Date: Thu, 12 Dec 2024 20:32:06 +0000 Subject: [PATCH 4/5] Remove the keybind to avoid accidental keypresses --- data/raw/keybindings.json | 7 ------- src/veh_appliance.cpp | 2 +- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/data/raw/keybindings.json b/data/raw/keybindings.json index 389735123a80e..4d005f545b637 100644 --- a/data/raw/keybindings.json +++ b/data/raw/keybindings.json @@ -1799,13 +1799,6 @@ "name": "Plug in appliance", "bindings": [ { "input_method": "keyboard_any", "key": "g" } ] }, - { - "type": "keybinding", - "id": "HIDE", - "category": "APP_INTERACT", - "name": "Hide/Unhide wiring", - "bindings": [ { "input_method": "keyboard_any", "key": "h" } ] - }, { "type": "keybinding", "id": "DISCONNECT_GRID", diff --git a/src/veh_appliance.cpp b/src/veh_appliance.cpp index 91aab9ac0a4ca..672ba57e6e570 100644 --- a/src/veh_appliance.cpp +++ b/src/veh_appliance.cpp @@ -599,7 +599,7 @@ void veh_app_interact::populate_app_actions() app_actions.emplace_back( [this]() { hide(); } ); - imenu.addentry( -1, true, ctxt.keys_bound_to( "HIDE" ).front(), ctxt.get_action_name( "HIDE" ) ); + imenu.addentry( -1, true, 0, "Hide/Unhide wiring" ); } #endif From 772a4b9cb6f1cbececf705f5144ca82281208a4a Mon Sep 17 00:00:00 2001 From: Procyonae <45432782+Procyonae@users.noreply.github.com> Date: Fri, 13 Dec 2024 01:09:14 +0000 Subject: [PATCH 5/5] Add serialisation + deserialisation to hidden --- src/savegame_json.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/savegame_json.cpp b/src/savegame_json.cpp index f87d635107bc3..2228f254b7282 100644 --- a/src/savegame_json.cpp +++ b/src/savegame_json.cpp @@ -3234,6 +3234,7 @@ void vehicle_part::deserialize( const JsonObject &data ) data.read( "locked", locked ); data.read( "last_disconnected", last_disconnected ); data.read( "last_charged", last_charged ); + data.read( "hidden", hidden ); if( migration != nullptr ) { for( const itype_id &it : migration->add_veh_tools ) { @@ -3289,6 +3290,7 @@ void vehicle_part::serialize( JsonOut &json ) const json.member( "locked", locked ); json.member( "last_disconnected", last_disconnected ); json.member( "last_charged", last_charged ); + json.member( "hidden", hidden ); json.end_object(); }