From f3e58ad761d19c32fc59fa21fa881c48dfb0ba01 Mon Sep 17 00:00:00 2001 From: Llywelwyn Date: Mon, 25 Sep 2023 00:36:11 +0100 Subject: [PATCH] started on new ui fn --- src/gui/mod.rs | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/main.rs | 1 + 2 files changed, 51 insertions(+) diff --git a/src/gui/mod.rs b/src/gui/mod.rs index 264ccc7..fe52c1e 100644 --- a/src/gui/mod.rs +++ b/src/gui/mod.rs @@ -44,6 +44,10 @@ use crate::consts::visuals::{ VIEWPORT_W, VIEWPORT_H, }; +use crate::consts::{ TILESIZE, FONTSIZE }; +use notan::prelude::*; +use notan::draw::{ Draw, DrawTextSection }; +use std::collections::HashMap; use bracket_lib::prelude::*; use specs::prelude::*; use std::collections::BTreeMap; @@ -110,6 +114,52 @@ pub fn draw_lerping_bar( pub const TEXT_FONT_MOD: i32 = 2; +pub fn draw_ui2( + ecs: &World, + draw: &mut Draw, + atlas: &HashMap, + font: ¬an::draw::Font +) { + let pools = ecs.read_storage::(); + let attributes = ecs.read_storage::(); + let players = ecs.read_storage::(); + let hunger = ecs.read_storage::(); + let burden = ecs.read_storage::(); + let skills = ecs.read_storage::(); + for (_p, stats, attributes, hunger, skills) in ( + &players, + &pools, + &attributes, + &hunger, + &skills, + ).join() { + let initial_x = 26.0 * TILESIZE; + let mut x = initial_x; + let y = 53.0 * TILESIZE; + // TODO: Draw hp/mana bars + // Draw AC + let skill_ac_bonus = gamesystem::skill_bonus(Skill::Defence, &*skills); + let mut armour_ac_bonus = 0; + let equipped = ecs.read_storage::(); + let ac = ecs.read_storage::(); + let player_entity = ecs.fetch::(); + for (wielded, ac) in (&equipped, &ac).join() { + if wielded.owner == *player_entity { + armour_ac_bonus += ac.amount; + } + } + let armour_class = + stats.bac - attributes.dexterity.bonus / 2 - skill_ac_bonus - armour_ac_bonus; + draw.text(&font, "AC").position(x, y).color(Color::PINK).size(FONTSIZE); + x = draw.last_text_bounds().max_x(); + draw.text(&font, &format!("{}", armour_class)).position(x, y).size(FONTSIZE); + draw.text(&font, &format!("XP{}/{}", stats.level, stats.xp)) + .position(initial_x, y + TILESIZE) + .size(FONTSIZE); + // TODO: Finish ui (placeholder) + } +} + pub fn draw_ui(ecs: &World, ctx: &mut BTerm) { ctx.set_active_console(TEXT_LAYER); // Render stats diff --git a/src/main.rs b/src/main.rs index 47602a5..17049b6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -430,6 +430,7 @@ fn draw(app: &mut App, gfx: &mut Graphics, gs: &mut State) { _ => { draw_bg(&gs.ecs, &mut draw, &gs.atlas); draw_camera(&gs.ecs, &mut draw, &gs.atlas); + crate::gui::draw_ui2(&gs.ecs, &mut draw, &gs.atlas, &gs.font); } } match *gs.ecs.fetch::() {