key inv display
This commit is contained in:
@@ -100,6 +100,10 @@ impl EditorState {
|
||||
/// Builds an editor session for `world`, starting on its designated start board.
|
||||
pub(crate) fn new(world: World) -> Self {
|
||||
let board_name = world.start.clone();
|
||||
let cursor = {
|
||||
let b = world.boards[&board_name].borrow();
|
||||
(b.width as i32 / 2, b.height as i32 / 2)
|
||||
};
|
||||
Self {
|
||||
world,
|
||||
board_name,
|
||||
@@ -107,7 +111,7 @@ impl EditorState {
|
||||
dialog: None,
|
||||
code_editor: None,
|
||||
glyph_dialog: None,
|
||||
cursor: (0, 0),
|
||||
cursor,
|
||||
current_archetype: Archetype::Wall,
|
||||
current_glyph: Archetype::Wall.default_glyph(),
|
||||
draw_mode: false,
|
||||
|
||||
@@ -342,7 +342,7 @@ fn draw_play(frame: &mut Frame, game: &GameState, ui: &mut Ui) {
|
||||
.spacing(Spacing::Overlap(1))
|
||||
.areas(frame.area());
|
||||
frame.render_widget(
|
||||
StatusSidebarWidget::new(game.player_health - 2, game.player_gems),
|
||||
StatusSidebarWidget::new(game.player_health - 2, game.player_gems, game.player_keys),
|
||||
sidebar_area,
|
||||
);
|
||||
rest
|
||||
|
||||
+28
-5
@@ -5,7 +5,9 @@
|
||||
//! presentational: it reads `health`/`gems` values handed in at construction and
|
||||
//! never mutates game state.
|
||||
|
||||
use std::collections::VecDeque;
|
||||
use crate::utils::rgba8_to_color;
|
||||
use kiln_core::game::Keyring;
|
||||
use kiln_core::{Archetype, Builtin};
|
||||
use kiln_core::cp437::tile_to_char;
|
||||
use ratatui::buffer::Buffer;
|
||||
@@ -24,19 +26,22 @@ const HEART_EMPTY: Color = Color::Rgb(90, 0, 0);
|
||||
|
||||
/// A ratatui widget that renders the play-mode status sidebar.
|
||||
///
|
||||
/// Shows a `Health:` label above a row of [`MAX_HEARTS`] heart glyphs (the first
|
||||
/// `health` filled bright red, the rest dark red) and a `Gems: ♦ N` line.
|
||||
/// Shows a `Health:` label above a row of [`MAX_HEARTS`] heart glyphs, a
|
||||
/// `Gems: ♦ N` line, and a `Keys:` row of 8 `♀` glyphs colored when held
|
||||
/// and dark gray when absent.
|
||||
pub struct StatusSidebarWidget {
|
||||
/// The player's current health, clamped to [`MAX_HEARTS`] when drawn.
|
||||
health: u32,
|
||||
/// The number of gems collected, shown as a count.
|
||||
gems: u32,
|
||||
/// The player's key inventory.
|
||||
keys: Keyring,
|
||||
}
|
||||
|
||||
impl StatusSidebarWidget {
|
||||
/// Builds a sidebar widget for the given player stats.
|
||||
pub fn new(health: u32, gems: u32) -> Self {
|
||||
Self { health, gems }
|
||||
pub fn new(health: u32, gems: u32, keys: Keyring) -> Self {
|
||||
Self { health, gems, keys }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,6 +63,22 @@ impl Widget for StatusSidebarWidget {
|
||||
let gem_char = tile_to_char(gem_glyph.tile).to_string();
|
||||
let gem_style = Style::default().fg(rgba8_to_color(gem_glyph.fg));
|
||||
|
||||
// Build the key row: 8 ♀ glyphs, colored when held, near-black when absent.
|
||||
let mut key_spans: VecDeque<_> = self
|
||||
.keys
|
||||
.colors()
|
||||
.iter()
|
||||
.filter_map(|(held, color)| {
|
||||
if *held {
|
||||
let fg = rgba8_to_color(*color);
|
||||
Some(Span::styled("♀", Style::default().fg(fg)))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
key_spans.push_front(Span::raw("Keys: "));
|
||||
|
||||
let lines = vec![
|
||||
Line::from("Health:"),
|
||||
Line::from(hearts),
|
||||
@@ -65,8 +86,10 @@ impl Widget for StatusSidebarWidget {
|
||||
Line::from(vec![
|
||||
Span::raw("Gems: "),
|
||||
Span::styled(gem_char, gem_style),
|
||||
Span::raw(format!(" {}", self.gems)),
|
||||
Span::raw(format!("{}", self.gems)),
|
||||
]),
|
||||
Line::from(""),
|
||||
Line::from_iter(key_spans.into_iter()),
|
||||
];
|
||||
|
||||
// A bordered block; `merge_borders` joins its right edge with the board
|
||||
|
||||
Reference in New Issue
Block a user