Show items, stats, and logs
This commit is contained in:
parent
bd81fbd9d9
commit
43adaee243
64
src/gui.rs
64
src/gui.rs
@ -2,7 +2,8 @@ use ::rltk::{Point, Rltk, VirtualKeyCode, RGB};
|
|||||||
use ::specs::prelude::*;
|
use ::specs::prelude::*;
|
||||||
|
|
||||||
use crate::components::{
|
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::game_log::GameLog;
|
||||||
use crate::rex_assets::RexAssets;
|
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::BLUE),
|
||||||
RGB::named(rltk::BLACK),
|
RGB::named(rltk::BLACK),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Attributes
|
||||||
|
let attributes = ecs.read_storage::<Attributes>();
|
||||||
|
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::<Equipped>();
|
||||||
|
let name = ecs.read_storage::<Name>();
|
||||||
|
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::<Consumable>();
|
||||||
|
let backpack = ecs.read_storage::<InBackpack>();
|
||||||
|
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::<HungerClock>();
|
||||||
|
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::<GameLog>();
|
||||||
|
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) {
|
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 mouse_pos = ctx.mouse_pos();
|
||||||
let mut mouse_map_pos = mouse_pos;
|
let mut mouse_map_pos = mouse_pos;
|
||||||
mouse_map_pos.0 += min_x;
|
mouse_map_pos.0 += min_x - 1;
|
||||||
mouse_map_pos.1 += min_y;
|
mouse_map_pos.1 += min_y - 1;
|
||||||
if mouse_map_pos.0 >= map.width - 1
|
if mouse_map_pos.0 >= map.width - 1
|
||||||
|| mouse_map_pos.1 >= map.height - 1
|
|| mouse_map_pos.1 >= map.height - 1
|
||||||
|| mouse_map_pos.0 < 1
|
|| mouse_map_pos.0 < 1
|
||||||
|
Loading…
Reference in New Issue
Block a user