From 43adaee243e2be4615dd26990ce088db8b5b83f6 Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Tue, 4 Jan 2022 12:24:04 -0500 Subject: [PATCH] Show items, stats, and logs --- src/gui.rs | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 61 insertions(+), 3 deletions(-) diff --git a/src/gui.rs b/src/gui.rs index 6dc3a3d..84b0e46 100644 --- a/src/gui.rs +++ b/src/gui.rs @@ -2,7 +2,8 @@ use ::rltk::{Point, Rltk, VirtualKeyCode, RGB}; use ::specs::prelude::*; use crate::components::{ - Attribute, HungerClock, HungerState, InBackpack, Name, Player, Pools, Position, Viewshed, + Attribute, Attributes, Consumable, HungerClock, HungerState, InBackpack, Name, Player, Pools, + Position, Viewshed, }; use crate::game_log::GameLog; use crate::rex_assets::RexAssets; @@ -99,6 +100,63 @@ pub fn draw_ui(ecs: &World, ctx: &mut Rltk) { RGB::named(rltk::BLUE), RGB::named(rltk::BLACK), ); + + // Attributes + let attributes = ecs.read_storage::(); + let attr = attributes.get(*player_entity).unwrap(); + draw_attribute("Might:", &attr.might, 4, ctx); + draw_attribute("Quickness:", &attr.quickness, 5, ctx); + draw_attribute("Fitness:", &attr.fitness, 6, ctx); + draw_attribute("Intelligence:", &attr.intelligence, 7, ctx); + + // Equipped + let mut y = 9; + let equipped = ecs.read_storage::(); + let name = ecs.read_storage::(); + for (equipped_by, item_name) in (&equipped, &name).join() { + if equipped_by.owner == *player_entity { + ctx.print_color(50, y, white, black, &item_name.name); + y += 1; + } + } + + // Consumables + y += 1; + let green = RGB::from_f32(0.0, 1.0, 0.0); + let yellow = RGB::named(rltk::YELLOW); + let consumables = ecs.read_storage::(); + let backpack = ecs.read_storage::(); + let mut index = 1; + for (carried_by, _consumable, item_name) in (&backpack, &consumables, &name).join() { + if carried_by.owner == *player_entity && index < 10 { + ctx.print_color(50, y, yellow, black, &format!("↑{}", index)); + ctx.print_color(53, y, green, black, &item_name.name); + y += 1; + index += 1; + } + } + + // Status + let hunger = ecs.read_storage::(); + let hc = hunger.get(*player_entity).unwrap(); + match hc.state { + HungerState::WellFed => ctx.print_color(50, 44, RGB::named(rltk::GREEN), black, "Well Fed"), + HungerState::Normal => {} + HungerState::Hungry => ctx.print_color(50, 44, RGB::named(rltk::ORANGE), black, "Hungry"), + HungerState::Starving => ctx.print_color(50, 44, RGB::named(rltk::RED), black, "Starving"), + } + + // Draw the log + let log = ecs.fetch::(); + let mut y = 46; + for s in log.entries.iter().rev() { + if y < 59 { + ctx.print(2, y, s); + } + y += 1; + } + + draw_tooltips(ecs, ctx); } fn draw_attribute(name: &str, attribute: &Attribute, y: i32, ctx: &mut Rltk) { @@ -136,8 +194,8 @@ fn draw_tooltips(ecs: &World, ctx: &mut Rltk) { let mouse_pos = ctx.mouse_pos(); let mut mouse_map_pos = mouse_pos; - mouse_map_pos.0 += min_x; - mouse_map_pos.1 += min_y; + mouse_map_pos.0 += min_x - 1; + mouse_map_pos.1 += min_y - 1; if mouse_map_pos.0 >= map.width - 1 || mouse_map_pos.1 >= map.height - 1 || mouse_map_pos.0 < 1