remember "choose items" choice per building type

develop
Myk Taylor 2023-03-14 21:55:43 -07:00
parent 96c7c952cf
commit 4d8580d9e7
No known key found for this signature in database
3 changed files with 32 additions and 1 deletions

@ -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

@ -55,6 +55,7 @@ static PersistentDataItem config;
// for use in counting available materials for the UI
static map<string, std::pair<MaterialInfo, string>> mat_cache;
static unordered_map<BuildingTypeKey, vector<const df::job_item *>, BuildingTypeKeyHash> job_item_cache;
static unordered_map<BuildingTypeKey, bool, BuildingTypeKeyHash> cur_choose_items;
static unordered_map<BuildingTypeKey, HeatSafety, BuildingTypeKeyHash> cur_heat_safety;
static unordered_map<BuildingTypeKey, DefaultItemFilters, BuildingTypeKeyHash> 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

@ -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