Split Material and Dismantle crafting tabs

This commit is contained in:
juliancoffee 2021-06-26 21:05:48 +03:00
parent 12243bd0c0
commit 12b5d655cf
2 changed files with 15 additions and 11 deletions

View File

@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Players can press H to greet others - Players can press H to greet others
- Ability to toggle chat visibility - Ability to toggle chat visibility
- Added gem rings with various stat improvements. - Added gem rings with various stat improvements.
### Changed ### Changed
- Entity-entity pushback is no longer applied in forced movement states like rolling and leaping. - Entity-entity pushback is no longer applied in forced movement states like rolling and leaping.
@ -34,6 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Crafting Stations aren't exploadable anymore - Crafting Stations aren't exploadable anymore
- Cases where no audio output could be produced before. - Cases where no audio output could be produced before.
- Significantly improved the performance of playing sound effects - Significantly improved the performance of playing sound effects
- Dismantle and Material crafting tabs don't have duplicated recipes
## [0.10.0] - 2021-06-12 ## [0.10.0] - 2021-06-12

View File

@ -20,7 +20,7 @@ use common::{
}, },
Inventory, Inventory,
}, },
recipe::RecipeInput, recipe::{Recipe, RecipeInput},
terrain::SpriteKind, terrain::SpriteKind,
}; };
use conrod_core::{ use conrod_core::{
@ -151,7 +151,7 @@ pub enum CraftingTab {
} }
impl CraftingTab { impl CraftingTab {
fn name_key(&self) -> &str { fn name_key(self) -> &'static str {
match self { match self {
CraftingTab::All => "hud.crafting.tabs.all", CraftingTab::All => "hud.crafting.tabs.all",
CraftingTab::Armor => "hud.crafting.tabs.armor", CraftingTab::Armor => "hud.crafting.tabs.armor",
@ -167,7 +167,7 @@ impl CraftingTab {
} }
} }
fn img_id(&self, imgs: &Imgs) -> image::Id { fn img_id(self, imgs: &Imgs) -> image::Id {
match self { match self {
CraftingTab::All => imgs.icon_globe, CraftingTab::All => imgs.icon_globe,
CraftingTab::Armor => imgs.icon_armor, CraftingTab::Armor => imgs.icon_armor,
@ -183,7 +183,9 @@ impl CraftingTab {
} }
} }
fn satisfies(&self, item: &ItemDef) -> bool { fn satisfies(self, recipe: &Recipe) -> bool {
let (item, _count) = &recipe.output;
let recycling = recipe.is_recycling;
match self { match self {
CraftingTab::All => true, CraftingTab::All => true,
CraftingTab::Food => item.tags().contains(&ItemTag::Food), CraftingTab::Food => item.tags().contains(&ItemTag::Food),
@ -194,10 +196,10 @@ impl CraftingTab {
CraftingTab::Glider => matches!(item.kind(), ItemKind::Glider(_)), CraftingTab::Glider => matches!(item.kind(), ItemKind::Glider(_)),
CraftingTab::Potion => item.tags().contains(&ItemTag::Potion), CraftingTab::Potion => item.tags().contains(&ItemTag::Potion),
CraftingTab::ProcessedMaterial => { CraftingTab::ProcessedMaterial => {
item.tags().contains(&ItemTag::MetalIngot) (item.tags().contains(&ItemTag::MetalIngot)
| item.tags().contains(&ItemTag::Textile) || item.tags().contains(&ItemTag::Textile)
| item.tags().contains(&ItemTag::Leather) || item.tags().contains(&ItemTag::Leather)
| item.tags().contains(&ItemTag::BaseMaterial) || item.tags().contains(&ItemTag::BaseMaterial)) && !recycling
}, },
CraftingTab::Bag => item.tags().contains(&ItemTag::Bag), CraftingTab::Bag => item.tags().contains(&ItemTag::Bag),
CraftingTab::Tool => item.tags().contains(&ItemTag::CraftingTool), CraftingTab::Tool => item.tags().contains(&ItemTag::CraftingTool),
@ -206,7 +208,7 @@ impl CraftingTab {
ItemKind::Tool(_) => !item.tags().contains(&ItemTag::CraftingTool), ItemKind::Tool(_) => !item.tags().contains(&ItemTag::CraftingTool),
_ => false, _ => false,
}, },
CraftingTab::Dismantle => matches!(item.kind(), ItemKind::Ingredient { .. }), CraftingTab::Dismantle => recipe.is_recycling,
} }
} }
} }
@ -469,7 +471,7 @@ impl<'a> Widget for Crafting<'a> {
} }
for (i, (name, recipe, is_craftable)) in ordered_recipes for (i, (name, recipe, is_craftable)) in ordered_recipes
.into_iter() .into_iter()
.filter(|(_, recipe, _)| self.show.crafting_tab.satisfies(recipe.output.0.as_ref())) .filter(|(_, recipe, _)| self.show.crafting_tab.satisfies(&recipe))
.enumerate() .enumerate()
{ {
let button = Button::image(if state.selected_recipe.as_ref() == Some(name) { let button = Button::image(if state.selected_recipe.as_ref() == Some(name) {
@ -648,7 +650,7 @@ impl<'a> Widget for Crafting<'a> {
for (row, chunk) in CraftingTab::iter() for (row, chunk) in CraftingTab::iter()
.filter(|crafting_tab| match crafting_tab { .filter(|crafting_tab| match crafting_tab {
CraftingTab::All => false, CraftingTab::All => false,
_ => crafting_tab.satisfies(recipe.output.0.as_ref()), _ => crafting_tab.satisfies(&recipe),
}) })
.filter(|crafting_tab| crafting_tab != &self.show.crafting_tab) .filter(|crafting_tab| crafting_tab != &self.show.crafting_tab)
.collect::<Vec<_>>() .collect::<Vec<_>>()