add ability to filter by cloth and silk

develop
Myk Taylor 2023-04-11 03:49:28 -07:00
parent 99d1b85f13
commit 20bea5fa21
No known key found for this signature in database
3 changed files with 34 additions and 11 deletions

@ -48,6 +48,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences:
## Misc Improvements ## Misc Improvements
- `buildingplan`: items in the item selection dialog should now use the same item quality symbols as the base game - `buildingplan`: items in the item selection dialog should now use the same item quality symbols as the base game
- `buildingplan`: hide planner overlay while the DF tutorial is active so that it can detect when you have placed the carpenter's workshop and bed and allow you to finish the tutorial - `buildingplan`: hide planner overlay while the DF tutorial is active so that it can detect when you have placed the carpenter's workshop and bed and allow you to finish the tutorial
- `buildingplan`: can now filter by cloth and silk materials (for ropes)
-@ `buildingplan`: rearranged elements of ``planneroverlay`` interface -@ `buildingplan`: rearranged elements of ``planneroverlay`` interface
-@ `buildingplan`: rearranged elements of ``itemselection`` interface -@ `buildingplan`: rearranged elements of ``itemselection`` interface
- Mods: scripts in mods that are only in the steam workshop directory are now accessible. this means that a script-only mod that you never mark as "active" when generating a world will still receive automatic updates and be usable from in-game - Mods: scripts in mods that are only in the steam workshop directory are now accessible. this means that a script-only mod that you never mark as "active" when generating a world will still receive automatic updates and be usable from in-game

@ -12,6 +12,7 @@
#include "df/construction_type.h" #include "df/construction_type.h"
#include "df/item.h" #include "df/item.h"
#include "df/job_item.h" #include "df/job_item.h"
#include "df/organic_mat_category.h"
#include "df/world.h" #include "df/world.h"
using std::map; using std::map;
@ -150,6 +151,8 @@ static const df::dfhack_material_category wood_cat(df::dfhack_material_category:
static const df::dfhack_material_category metal_cat(df::dfhack_material_category::mask_metal); static const df::dfhack_material_category metal_cat(df::dfhack_material_category::mask_metal);
static const df::dfhack_material_category glass_cat(df::dfhack_material_category::mask_glass); static const df::dfhack_material_category glass_cat(df::dfhack_material_category::mask_glass);
static const df::dfhack_material_category clay_cat(df::dfhack_material_category::mask_clay); static const df::dfhack_material_category clay_cat(df::dfhack_material_category::mask_clay);
static const df::dfhack_material_category cloth_cat(df::dfhack_material_category::mask_cloth);
static const df::dfhack_material_category silk_cat(df::dfhack_material_category::mask_silk);
static void cache_matched(int16_t type, int32_t index) { static void cache_matched(int16_t type, int32_t index) {
MaterialInfo mi; MaterialInfo mi;
@ -169,11 +172,26 @@ static void cache_matched(int16_t type, int32_t index) {
} else if (mi.matches(clay_cat)) { } else if (mi.matches(clay_cat)) {
DEBUG(status).print("cached clay material: %s (%d, %d)\n", mi.toString().c_str(), type, index); DEBUG(status).print("cached clay material: %s (%d, %d)\n", mi.toString().c_str(), type, index);
mat_cache.emplace(mi.toString(), std::make_pair(mi, "clay")); mat_cache.emplace(mi.toString(), std::make_pair(mi, "clay"));
} else if (mi.matches(cloth_cat)) {
DEBUG(status).print("cached cloth material: %s (%d, %d)\n", mi.toString().c_str(), type, index);
mat_cache.emplace(mi.toString(), std::make_pair(mi, "cloth"));
} else if (mi.matches(silk_cat)) {
DEBUG(status).print("cached silk material: %s (%d, %d)\n", mi.toString().c_str(), type, index);
mat_cache.emplace(mi.toString(), std::make_pair(mi, "silk"));
} }
else else
TRACE(status).print("not matched: %s\n", mi.toString().c_str()); TRACE(status).print("not matched: %s\n", mi.toString().c_str());
} }
static void load_organic_material_cache(df::organic_mat_category cat) {
auto& mat_tab = world->raws.mat_table;
auto& cat_vec = mat_tab.organic_types[cat];
auto& cat_indices = mat_tab.organic_indexes[cat];
for (size_t i = 0; i < cat_vec.size(); i++) {
cache_matched(cat_vec[i], cat_indices[i]);
}
}
static void load_material_cache() { static void load_material_cache() {
df::world_raws &raws = world->raws; df::world_raws &raws = world->raws;
for (int i = 1; i < DFHack::MaterialInfo::NUM_BUILTIN; ++i) for (int i = 1; i < DFHack::MaterialInfo::NUM_BUILTIN; ++i)
@ -183,17 +201,9 @@ static void load_material_cache() {
for (size_t i = 0; i < raws.inorganics.size(); i++) for (size_t i = 0; i < raws.inorganics.size(); i++)
cache_matched(0, i); cache_matched(0, i);
for (size_t i = 0; i < raws.plants.all.size(); i++) { load_organic_material_cache(df::organic_mat_category::Wood);
df::plant_raw *p = raws.plants.all[i]; load_organic_material_cache(df::organic_mat_category::PlantFiber);
if (p->material.size() <= 1) load_organic_material_cache(df::organic_mat_category::Silk);
continue;
for (size_t j = 0; j < p->material.size(); j++) {
if (p->material[j]->id == "WOOD") {
cache_matched(DFHack::MaterialInfo::PLANT_BASE+j, i);
break;
}
}
}
} }
static HeatSafety get_heat_safety_filter(const BuildingTypeKey &key) { static HeatSafety get_heat_safety_filter(const BuildingTypeKey &key) {
@ -792,6 +802,10 @@ static int setMaterialMaskFilter(lua_State *L) {
mask |= glass_cat.whole; mask |= glass_cat.whole;
else if (cat == "clay") else if (cat == "clay")
mask |= clay_cat.whole; mask |= clay_cat.whole;
else if (cat == "cloth")
mask |= cloth_cat.whole;
else if (cat == "silk")
mask |= silk_cat.whole;
} }
DEBUG(status,*out).print( DEBUG(status,*out).print(
"setting material mask filter for building_type=%d subtype=%d custom=%d index=%d to %x\n", "setting material mask filter for building_type=%d subtype=%d custom=%d index=%d to %x\n",
@ -837,6 +851,8 @@ static int getMaterialMaskFilter(lua_State *L) {
ret.emplace("metal", !bits || bits & metal_cat.whole); ret.emplace("metal", !bits || bits & metal_cat.whole);
ret.emplace("glass", !bits || bits & glass_cat.whole); ret.emplace("glass", !bits || bits & glass_cat.whole);
ret.emplace("clay", !bits || bits & clay_cat.whole); ret.emplace("clay", !bits || bits & clay_cat.whole);
ret.emplace("cloth", !bits || bits & cloth_cat.whole);
ret.emplace("silk", !bits || bits & silk_cat.whole);
Lua::Push(L, ret); Lua::Push(L, ret);
return 1; return 1;
} }
@ -883,6 +899,10 @@ static int setMaterialFilter(lua_State *L) {
mask.whole |= glass_cat.whole; mask.whole |= glass_cat.whole;
else if (mat.matches(clay_cat)) else if (mat.matches(clay_cat))
mask.whole |= clay_cat.whole; mask.whole |= clay_cat.whole;
else if (mat.matches(cloth_cat))
mask.whole |= cloth_cat.whole;
else if (mat.matches(silk_cat))
mask.whole |= silk_cat.whole;
} }
filter.setMaterialMask(mask.whole); filter.setMaterialMask(mask.whole);
get_item_filters(*out, key).setItemFilter(*out, filter, index); get_item_filters(*out, key).setItemFilter(*out, filter, index);

@ -453,6 +453,8 @@ function QualityAndMaterialsPage:refresh()
make_cat_choice('Metal', 'metal', 'CUSTOM_SHIFT_M', cats), make_cat_choice('Metal', 'metal', 'CUSTOM_SHIFT_M', cats),
make_cat_choice('Glass', 'glass', 'CUSTOM_SHIFT_G', cats), make_cat_choice('Glass', 'glass', 'CUSTOM_SHIFT_G', cats),
make_cat_choice('Clay', 'clay', 'CUSTOM_SHIFT_C', cats), make_cat_choice('Clay', 'clay', 'CUSTOM_SHIFT_C', cats),
make_cat_choice('Cloth', 'cloth', 'CUSTOM_SHIFT_L', cats),
make_cat_choice('Silk', 'silk', 'CUSTOM_SHIFT_K', cats),
} }
self.subviews.materials_categories:setChoices(category_choices) self.subviews.materials_categories:setChoices(category_choices)