Files
horizon-airdef/crates/horizon-client/src/game/titles.rs
T
Ludovic Marie 3c28f55ce3 Merge main into fix/banner-item-components
Resolve game.rs and titles.rs against the resources split (#537): layer
names and item names now come from self.pack, the atlas from self.atlas.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-17 00:47:22 +02:00

63 lines
2.4 KiB
Rust

//! Titles, the action bar and the selected item name: the state and layout
//! live in `hud_overlays` (`Titles`, `ToolHighlight`); this feeds and draws them.
use super::Game;
pub(super) use horizon_client::hud_overlays::Titles;
use horizon_client::{
hud::HudBatch,
hud_layout,
hud_overlays::HeldName,
item_tooltip,
text::{self, Text},
};
impl Game<'_> {
/// `Hud.extractOverlayMessage` and `extractTitle`.
pub(super) fn draw_titles(&self, batch: &mut HudBatch) {
let (w, h) = (batch.width as i32, batch.height as i32);
let partial = self.clock.fraction() as f32;
let background = self.settings.text_background(0.0);
let font = &self.atlas.font;
let mut draws = self.titles.overlay_message(w, h, partial, font, background);
draws.extend(self.titles.title(w, h, partial, font, background));
hud_layout::paint(batch, &self.atlas, &draws);
}
/// The selected stack as `Hud.tick` compares it for the name highlight.
fn held_name(&self) -> Option<HeldName> {
let stack = self.inventory.get(self.selected)?.as_ref()?;
let custom = stack.custom_name();
let default_rarity = self.item_rarity(&stack.item);
let rarity = item_tooltip::rarity(stack, &default_rarity);
Some(HeldName {
item: stack.item.to_string(),
hover_name: Text::literal(item_tooltip::name_line(stack, &|key| {
self.pack.names.get(key).map(str::to_owned)
})),
rarity_color: match rarity {
"uncommon" => text::YELLOW,
"rare" => text::AQUA,
"epic" => text::LIGHT_PURPLE,
_ => text::WHITE,
},
custom_name: custom.is_some(),
})
}
/// The title, action bar and selected-item parts of `Hud.tick`.
pub(super) fn tick_hud(&mut self) {
self.titles.tick();
let held = self.held_name();
self.tool_highlight
.tick(held, f64::from(self.settings.notification_display_time));
}
/// `Hud.extractSelectedItemName`.
pub(super) fn draw_selected_name(&self, batch: &mut HudBatch, can_hurt: bool) {
let draws = self.tool_highlight.draw(
batch.width as i32,
batch.height as i32,
can_hurt,
&self.atlas.font,
self.settings.text_background(0.0),
);
hud_layout::paint(batch, &self.atlas, &draws);
}
}