diff --git a/crates/horizon-client/src/game/advancements.rs b/crates/horizon-client/src/game/advancements.rs index 50382bb9d..1b12491b0 100644 --- a/crates/horizon-client/src/game/advancements.rs +++ b/crates/horizon-client/src/game/advancements.rs @@ -20,6 +20,26 @@ pub(super) struct Toast { frame: Frame, title: Text, shown: Option, + /// A `RecipeToast`: the icon is a recipe result. + recipe: bool, +} +impl Toast { + pub(super) fn is_recipe(&self) -> bool { + self.recipe + } + pub(super) fn was_shown(&self) -> bool { + self.shown.is_some() + } + /// `RecipeToast`: "New Recipe(s) Unlocked!" with the recipe's result. + pub(super) fn recipe(icon: &str) -> Self { + Self { + icon: icon.to_owned(), + frame: Frame::Task, + title: Text::literal(""), + shown: None, + recipe: true, + } + } } #[derive(Default)] pub(super) struct AdvState { @@ -27,7 +47,7 @@ pub(super) struct AdvState { pub(super) progress: Progress, loaded: bool, pub(super) recipes: BTreeSet, - toasts: VecDeque, + pub(super) toasts: VecDeque, /// Awards skip the toast (`/advancement grant ... everything`). pub(super) quiet: bool, /// The inventory last seen by `inventory_changed`. @@ -339,6 +359,7 @@ impl Game<'_> { frame: d.frame, title: text_of(&d.title), shown: None, + recipe: false, }); } if d.announce && self.ui.rules.bool("show_advancement_messages") { @@ -354,6 +375,7 @@ impl Game<'_> { )); } } + self.recipe_toast(&unlocked); for r in unlocked { self.trigger("minecraft:recipe_unlocked", |c, _| { c["recipes"].as_str() == Some(r.as_str()) @@ -576,7 +598,20 @@ impl Game<'_> { } else { 1.0 }; - let (title, frame, icon) = (t.title.clone(), t.frame, t.icon.clone()); + let (title, frame, icon, recipe) = (t.title.clone(), t.frame, t.icon.clone(), t.recipe); + if recipe { + // RecipeToast: black description under a purple title. + let atlas = &self.res.atlas; + let x = batch.width - 160.0 * slide; + batch.sprite(atlas, "gui/sprites/toast/recipe", x, 0.0); + let title = self.translate("recipe.toast.title", "New Recipe(s) Unlocked!"); + let description = self.translate("recipe.toast.description", "Check your recipe book"); + let atlas = &self.res.atlas; + batch.text(atlas, &title, x + 30.0, 7.0, 0xFF50_0050, false); + batch.text(atlas, &description, x + 30.0, 18.0, 0xFF00_0000, false); + self.draw_item(batch, &ItemStack::new(&icon, 1), x + 8.0, 8.0); + return; + } if frame == Frame::Challenge && ms < 50.0 { self.audio .play("minecraft:ui.toast.challenge_complete", None, 1.0, 1.0); diff --git a/crates/horizon-client/src/game/recipe_book.rs b/crates/horizon-client/src/game/recipe_book.rs index 995b2704c..658db4ada 100644 --- a/crates/horizon-client/src/game/recipe_book.rs +++ b/crates/horizon-client/src/game/recipe_book.rs @@ -173,6 +173,31 @@ impl Game<'_> { search.reset_blink(); } + /// The toast for newly unlocked recipes: one for a burst of unlocks. + pub(super) fn recipe_toast(&mut self, recipes: &[String]) { + if recipes.is_empty() || self.adv.quiet { + return; + } + self.ensure_book(); + let icon = self + .recipe_ui + .book + .as_ref() + .and_then(|b| recipes.iter().find_map(|id| b.entry(id))) + .map(|e| e.result.item.to_string()); + let Some(icon) = icon else { return }; + let fresh = self + .adv + .toasts + .back() + .is_some_and(|t| t.is_recipe() && !t.was_shown()); + if !fresh { + self.adv + .toasts + .push_back(super::advancements::Toast::recipe(&icon)); + } + } + // ---- recipes and what can be crafted ---- /// The grid size of the open crafting menu.