From b0f9ad644958485b16ccf2add6151e17ef13dbca Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Wed, 15 Mar 2023 14:02:59 -0700 Subject: [PATCH] add buildingplan reset for resetting all filters --- docs/changelog.txt | 1 + docs/plugins/buildingplan.rst | 5 +++++ plugins/buildingplan/buildingplan.cpp | 18 ++++++++++++++---- plugins/lua/buildingplan.lua | 2 ++ 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/docs/changelog.txt b/docs/changelog.txt index e32538566..c98d727f6 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -45,6 +45,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: -@ `buildingplan`: you can now attach multiple weapons to spike traps -@ `buildingplan`: can now filter by whether a slab is engraved -@ `buildingplan`: add "minimize" button to temporarily get the planner overlay out of the way if you would rather use the vanilla UI for placing the current building +-@ `buildingplan`: add ``buildingplan reset`` command for resetting all filters to defaults - `blueprint`: now writes blueprints to the ``dfhack-config/blueprints`` directory - `blueprint-library-guide`: library blueprints have moved from ``blueprints`` to ``hack/data/blueprints`` - player-created blueprints should now go in the ``dfhack-config/blueprints`` folder. please move your existing blueprints from ``blueprints`` to ``dfhack-config/blueprints``. you don't need to move the library blueprints -- those can be safely deleted from the old ``blueprints`` directory. diff --git a/docs/plugins/buildingplan.rst b/docs/plugins/buildingplan.rst index 68eb18f69..378d3b140 100644 --- a/docs/plugins/buildingplan.rst +++ b/docs/plugins/buildingplan.rst @@ -60,6 +60,7 @@ Usage buildingplan [status] buildingplan set (true|false) + buildingplan reset Examples -------- @@ -72,6 +73,10 @@ Examples When finding items to satisfy "building materials" requirements, don't select boulders. Use blocks or logs (if enabled) instead. +``buildingplan reset`` + Reset all settings and filters to their defaults. This command does not affect + existing planned buildings. + .. _buildingplan-settings: Global settings diff --git a/plugins/buildingplan/buildingplan.cpp b/plugins/buildingplan/buildingplan.cpp index c2b4431d9..d28a0aa31 100644 --- a/plugins/buildingplan/buildingplan.cpp +++ b/plugins/buildingplan/buildingplan.cpp @@ -261,13 +261,15 @@ static void validate_config(color_ostream &out, bool verbose = false) { set_config_bool(config, CONFIG_BARS, false); } -static void clear_state(color_ostream &out) { +static void reset_filters(color_ostream &out) { + cur_heat_safety.clear(); + cur_item_filters.clear(); call_buildingplan_lua(&out, "signal_reset"); - call_buildingplan_lua(&out, "reload_pens"); +} + +static void clear_state(color_ostream &out) { planned_buildings.clear(); tasks.clear(); - cur_heat_safety.clear(); - cur_item_filters.clear(); for (auto &entry : job_item_cache ) { for (auto &jitem : entry.second) { delete jitem; @@ -275,6 +277,8 @@ static void clear_state(color_ostream &out) { } job_item_cache.clear(); mat_cache.clear(); + reset_filters(out); + call_buildingplan_lua(&out, "reload_pens"); } DFhackCExport command_result plugin_load_data (color_ostream &out) { @@ -582,6 +586,11 @@ static bool setSetting(color_ostream &out, string name, bool value) { return true; } +static void resetFilters(color_ostream &out) { + DEBUG(status,out).print("entering resetFilters\n"); + reset_filters(out); +} + static bool isPlannableBuilding(color_ostream &out, df::building_type type, int16_t subtype, int32_t custom) { DEBUG(status,out).print("entering isPlannableBuilding\n"); return get_num_filters(out, BuildingTypeKey(type, subtype, custom)) >= 1; @@ -1104,6 +1113,7 @@ static void makeTopPriority(color_ostream &out, df::building *bld) { DFHACK_PLUGIN_LUA_FUNCTIONS { DFHACK_LUA_FUNCTION(printStatus), DFHACK_LUA_FUNCTION(setSetting), + DFHACK_LUA_FUNCTION(resetFilters), DFHACK_LUA_FUNCTION(isPlannableBuilding), DFHACK_LUA_FUNCTION(isPlannedBuilding), DFHACK_LUA_FUNCTION(addPlannedBuilding), diff --git a/plugins/lua/buildingplan.lua b/plugins/lua/buildingplan.lua index d606101be..3492e2ccd 100644 --- a/plugins/lua/buildingplan.lua +++ b/plugins/lua/buildingplan.lua @@ -42,6 +42,8 @@ function parse_commandline(...) printStatus() elseif command == 'set' and positionals then setSetting(positionals[1], positionals[2] == 'true') + elseif command == 'reset' then + resetFilters() else return false end