diff --git a/src/colors.rs b/src/colors.rs index 2ebd17e..6c36b33 100644 --- a/src/colors.rs +++ b/src/colors.rs @@ -89,3 +89,8 @@ pub const WHEAT: RGB = new(0.96078, 0.87059, 0.70196); /// Hex: #FF0 /// RGB: (255, 255, 0) pub const YELLOW: RGB = new(1., 1., 0.); + +// Equipment colors +pub const EQUIP_COMMON: RGB = new(0.5, 1., 0.5); +pub const EQUIP_RARE: RGB = new(0., 1., 1.); +pub const EQUIP_LEGEND: RGB = new(0.71, 0.15, 0.93); diff --git a/src/gui.rs b/src/gui.rs index 82785ce..85f10d3 100644 --- a/src/gui.rs +++ b/src/gui.rs @@ -4,12 +4,24 @@ use ::rltk::{Point, Rltk, VirtualKeyCode, RGB}; use ::specs::prelude::*; use crate::components::{ - Attribute, Attributes, Consumable, HungerClock, HungerState, InBackpack, Item, Name, Pools, - Position, Vendor, Viewshed, + Attribute, Attributes, Consumable, HungerClock, HungerState, InBackpack, Item, MagicItemClass, + Name, Pools, Position, Vendor, Viewshed, }; use crate::game_log::GameLog; use crate::rex_assets::RexAssets; -use crate::{camera, colors, Equipped, Hidden, Map, RunState, State, VendorMode}; +use crate::{camera, colors, Equipped, Hidden, MagicItem, Map, RunState, State, VendorMode}; + +pub fn get_item_color(ecs: &World, item: Entity) -> RGB { + if let Some(magic) = ecs.read_storage::().get(item) { + match magic.class { + MagicItemClass::Common => colors::EQUIP_COMMON, + MagicItemClass::Rare => colors::EQUIP_RARE, + MagicItemClass::Legendary => colors::EQUIP_LEGEND, + } + } else { + colors::WHITE + } +} pub fn draw_hollow_box( console: &mut Rltk, @@ -152,11 +164,18 @@ pub fn draw_ui(ecs: &World, ctx: &mut Rltk) { // Equipped let mut y = 13; + let entities = ecs.entities(); let equipped = ecs.read_storage::(); let name = ecs.read_storage::(); - for (equipped_by, item_name) in (&equipped, &name).join() { + for (entity, equipped_by, item_name) in (&entities, &equipped, &name).join() { if equipped_by.owner == *player_entity { - ctx.print_color(50, y, colors::WHITE, colors::BLACK, &item_name.name); + ctx.print_color( + 50, + y, + get_item_color(ecs, entity), + colors::BLACK, + &item_name.name, + ); y += 1; } } @@ -166,10 +185,18 @@ pub fn draw_ui(ecs: &World, ctx: &mut Rltk) { 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() { + for (entity, carried_by, _consumable, item_name) in + (&entities, &backpack, &consumables, &name).join() + { if carried_by.owner == *player_entity && index < 10 { ctx.print_color(50, y, colors::YELLOW, colors::BLACK, &format!("↑{}", index)); - ctx.print_color(53, y, colors::GREEN, colors::BLACK, &item_name.name); + ctx.print_color( + 53, + y, + get_item_color(ecs, entity), + colors::BLACK, + &item_name.name, + ); y += 1; index += 1; } @@ -439,7 +466,13 @@ pub fn show_inventory(gs: &mut State, ctx: &mut Rltk) -> (ItemMenuResult, Option ); ctx.set(19, y, colors::WHITE, colors::BLACK, rltk::to_cp437(')')); - ctx.print(21, y, &name.name.to_string()); + ctx.print_color( + 21, + y, + get_item_color(&gs.ecs, entity), + colors::BLACK, + &name.name.to_string(), + ); equippable.push(entity); y += 1; j += 1; @@ -509,7 +542,13 @@ pub fn drop_item_menu(gs: &mut State, ctx: &mut Rltk) -> (ItemMenuResult, Option ); ctx.set(19, y, colors::WHITE, colors::BLACK, rltk::to_cp437(')')); - ctx.print(21, y, &name.name.to_string()); + ctx.print_color( + 21, + y, + get_item_color(&gs.ecs, entity), + colors::BLACK, + &name.name.to_string(), + ); equippable.push(entity); y += 1; j += 1; @@ -585,7 +624,13 @@ pub fn remove_item_menu(gs: &mut State, ctx: &mut Rltk) -> (ItemMenuResult, Opti ); ctx.set(19, y, colors::WHITE, colors::BLACK, rltk::to_cp437(')')); - ctx.print(21, y, &name.name.to_string()); + ctx.print_color( + 21, + y, + get_item_color(&gs.ecs, entity), + colors::BLACK, + &name.name.to_string(), + ); equippable.push(entity); y += 1; diff --git a/src/raws/item_structs.rs b/src/raws/item_structs.rs index ad443d9..9fe3056 100644 --- a/src/raws/item_structs.rs +++ b/src/raws/item_structs.rs @@ -13,6 +13,7 @@ pub struct Item { pub weight_lbs: Option, pub base_value: Option, pub vendor_category: Option, + pub magic: Option, } #[derive(Deserialize, Debug)] @@ -41,3 +42,8 @@ pub struct Wearable { pub armor_class: f32, pub slot: String, } + +#[derive(Deserialize, Debug)] +pub struct MagicItem { + pub class: String, +} diff --git a/src/raws/rawmaster.rs b/src/raws/rawmaster.rs index c1ae8f0..1019f64 100644 --- a/src/raws/rawmaster.rs +++ b/src/raws/rawmaster.rs @@ -327,6 +327,15 @@ pub fn spawn_named_item( }); } + if let Some(magic) = &item_template.magic { + let class = match magic.class.as_str() { + "rare" => MagicItemClass::Rare, + "legendary" => MagicItemClass::Legendary, + _ => MagicItemClass::Common, + }; + eb = eb.with(MagicItem { class }) + } + return Some(eb.build()); }