diff --git a/docs/changelog.txt b/docs/changelog.txt index 91c1168dd..af9dba787 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -36,6 +36,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: ## New Plugins ## Fixes +-@ `buildingplan`: remember choice per building type for whether the player wants to choose specific items -@ `buildingplan`: items are now attached correctly to screw pumps and other multi-item buildings ## Misc Improvements diff --git a/plugins/buildingplan/buildingplan.cpp b/plugins/buildingplan/buildingplan.cpp index ba9cbf5fb..ef808c09b 100644 --- a/plugins/buildingplan/buildingplan.cpp +++ b/plugins/buildingplan/buildingplan.cpp @@ -55,6 +55,7 @@ static PersistentDataItem config; // for use in counting available materials for the UI static map> mat_cache; static unordered_map, BuildingTypeKeyHash> job_item_cache; +static unordered_map cur_choose_items; static unordered_map cur_heat_safety; static unordered_map cur_item_filters; // building id -> PlannedBuilding @@ -266,6 +267,7 @@ static void clear_state(color_ostream &out) { call_buildingplan_lua(&out, "reload_pens"); planned_buildings.clear(); tasks.clear(); + cur_choose_items.clear(); cur_heat_safety.clear(); cur_item_filters.clear(); for (auto &entry : job_item_cache ) { @@ -890,6 +892,28 @@ static int getMaterialFilter(lua_State *L) { return 1; } +static void setChooseItems(color_ostream &out, df::building_type type, int16_t subtype, int32_t custom, bool choose) { + DEBUG(status,out).print("entering setChooseItems\n"); + BuildingTypeKey key(type, subtype, custom); + cur_choose_items[key] = choose; + // no need to reset signal; no change to the state of any other UI element +} + +static int getChooseItems(lua_State *L) { + color_ostream *out = Lua::GetOutput(L); + if (!out) + out = &Core::getInstance().getConsole(); + df::building_type type = (df::building_type)luaL_checkint(L, 1); + int16_t subtype = luaL_checkint(L, 2); + int32_t custom = luaL_checkint(L, 3); + DEBUG(status,*out).print( + "entering getChooseItems building_type=%d subtype=%d custom=%d\n", + type, subtype, custom); + BuildingTypeKey key(type, subtype, custom); + Lua::Push(L, cur_choose_items[key]); + return 1; +} + static void setHeatSafetyFilter(color_ostream &out, df::building_type type, int16_t subtype, int32_t custom, int heat) { DEBUG(status,out).print("entering setHeatSafetyFilter\n"); BuildingTypeKey key(type, subtype, custom); @@ -1061,6 +1085,7 @@ DFHACK_PLUGIN_LUA_FUNCTIONS { DFHACK_LUA_FUNCTION(countAvailableItems), DFHACK_LUA_FUNCTION(hasFilter), DFHACK_LUA_FUNCTION(clearFilter), + DFHACK_LUA_FUNCTION(setChooseItems), DFHACK_LUA_FUNCTION(setHeatSafetyFilter), DFHACK_LUA_FUNCTION(setQualityFilter), DFHACK_LUA_FUNCTION(getDescString), @@ -1076,6 +1101,7 @@ DFHACK_PLUGIN_LUA_COMMANDS { DFHACK_LUA_COMMAND(getMaterialMaskFilter), DFHACK_LUA_COMMAND(setMaterialFilter), DFHACK_LUA_COMMAND(getMaterialFilter), + DFHACK_LUA_COMMAND(getChooseItems), DFHACK_LUA_COMMAND(getHeatSafetyFilter), DFHACK_LUA_COMMAND(getQualityFilter), DFHACK_LUA_END diff --git a/plugins/lua/buildingplan/planneroverlay.lua b/plugins/lua/buildingplan/planneroverlay.lua index a45ab8ca0..0276f3a0d 100644 --- a/plugins/lua/buildingplan/planneroverlay.lua +++ b/plugins/lua/buildingplan/planneroverlay.lua @@ -401,6 +401,9 @@ function PlannerOverlay:init() end end end, + on_change=function(choose) + buildingplan.setChooseItems(uibs.building_type, uibs.building_subtype, uibs.custom_type, choose) + end, }, widgets.CycleHotkeyLabel{ view_id='safety', @@ -541,7 +544,6 @@ function PlannerOverlay:onInput(keys) end self.selected = 1 self.subviews.hollow:setOption(false) - self.subviews.choose:setOption(false) self:reset() reset_counts_flag = true return false @@ -627,6 +629,8 @@ function PlannerOverlay:onRenderFrame(dc, rect) if reset_counts_flag then self:reset() + self.subviews.choose:setOption(require('plugins.buildingplan').getChooseItems( + uibs.building_type, uibs.building_subtype, uibs.custom_type)) self.subviews.safety:setOption(require('plugins.buildingplan').getHeatSafetyFilter( uibs.building_type, uibs.building_subtype, uibs.custom_type)) end