Add color to magic items
This commit is contained in:
parent
b0bdd44e18
commit
12bd24c1f7
@ -89,3 +89,8 @@ pub const WHEAT: RGB = new(0.96078, 0.87059, 0.70196);
|
|||||||
/// Hex: #FF0
|
/// Hex: #FF0
|
||||||
/// RGB: (255, 255, 0)
|
/// RGB: (255, 255, 0)
|
||||||
pub const YELLOW: RGB = new(1., 1., 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);
|
||||||
|
65
src/gui.rs
65
src/gui.rs
@ -4,12 +4,24 @@ use ::rltk::{Point, Rltk, VirtualKeyCode, RGB};
|
|||||||
use ::specs::prelude::*;
|
use ::specs::prelude::*;
|
||||||
|
|
||||||
use crate::components::{
|
use crate::components::{
|
||||||
Attribute, Attributes, Consumable, HungerClock, HungerState, InBackpack, Item, Name, Pools,
|
Attribute, Attributes, Consumable, HungerClock, HungerState, InBackpack, Item, MagicItemClass,
|
||||||
Position, Vendor, Viewshed,
|
Name, Pools, Position, Vendor, Viewshed,
|
||||||
};
|
};
|
||||||
use crate::game_log::GameLog;
|
use crate::game_log::GameLog;
|
||||||
use crate::rex_assets::RexAssets;
|
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::<MagicItem>().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(
|
pub fn draw_hollow_box(
|
||||||
console: &mut Rltk,
|
console: &mut Rltk,
|
||||||
@ -152,11 +164,18 @@ pub fn draw_ui(ecs: &World, ctx: &mut Rltk) {
|
|||||||
|
|
||||||
// Equipped
|
// Equipped
|
||||||
let mut y = 13;
|
let mut y = 13;
|
||||||
|
let entities = ecs.entities();
|
||||||
let equipped = ecs.read_storage::<Equipped>();
|
let equipped = ecs.read_storage::<Equipped>();
|
||||||
let name = ecs.read_storage::<Name>();
|
let name = ecs.read_storage::<Name>();
|
||||||
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 {
|
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;
|
y += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -166,10 +185,18 @@ pub fn draw_ui(ecs: &World, ctx: &mut Rltk) {
|
|||||||
let consumables = ecs.read_storage::<Consumable>();
|
let consumables = ecs.read_storage::<Consumable>();
|
||||||
let backpack = ecs.read_storage::<InBackpack>();
|
let backpack = ecs.read_storage::<InBackpack>();
|
||||||
let mut index = 1;
|
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 {
|
if carried_by.owner == *player_entity && index < 10 {
|
||||||
ctx.print_color(50, y, colors::YELLOW, colors::BLACK, &format!("↑{}", index));
|
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;
|
y += 1;
|
||||||
index += 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.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);
|
equippable.push(entity);
|
||||||
y += 1;
|
y += 1;
|
||||||
j += 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.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);
|
equippable.push(entity);
|
||||||
y += 1;
|
y += 1;
|
||||||
j += 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.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);
|
equippable.push(entity);
|
||||||
y += 1;
|
y += 1;
|
||||||
|
@ -13,6 +13,7 @@ pub struct Item {
|
|||||||
pub weight_lbs: Option<f32>,
|
pub weight_lbs: Option<f32>,
|
||||||
pub base_value: Option<f32>,
|
pub base_value: Option<f32>,
|
||||||
pub vendor_category: Option<String>,
|
pub vendor_category: Option<String>,
|
||||||
|
pub magic: Option<MagicItem>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Deserialize, Debug)]
|
||||||
@ -41,3 +42,8 @@ pub struct Wearable {
|
|||||||
pub armor_class: f32,
|
pub armor_class: f32,
|
||||||
pub slot: String,
|
pub slot: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Debug)]
|
||||||
|
pub struct MagicItem {
|
||||||
|
pub class: String,
|
||||||
|
}
|
||||||
|
@ -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());
|
return Some(eb.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user