feat: 2-char item glyphs in ASCII UI inventory
- Item.display_glyph() returns [char; 2] — base symbol + type code:
Dagger /) Sword || Bow ){ LeatherArmor [L PlateArmor {P
Shield OS HealthPotion !H ManaPotion !M Food %F Scroll ?S
- Item.display_string() returns the 2-char combo as a string
- Character panel inventory now shows 2-char glyphs with dimmed second char
- HUD weapon/armor display uses 2-char glyphs instead of truncated names
- Items in world grid still use single display_char() (1 cell = 1 char)
All 171 tests + 14 scenarios pass.
This commit is contained in:
@@ -54,6 +54,26 @@ impl Item {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn display_glyph(&self) -> [char; 2] {
|
||||||
|
match self.typ {
|
||||||
|
ItemType::Dagger => ['/', ')'],
|
||||||
|
ItemType::Sword => ['|', '|'],
|
||||||
|
ItemType::Bow => [')', '{'],
|
||||||
|
ItemType::LeatherArmor => ['[', 'L'],
|
||||||
|
ItemType::PlateArmor => ['{', 'P'],
|
||||||
|
ItemType::Shield => ['O', 'S'],
|
||||||
|
ItemType::HealthPotion => ['!', 'H'],
|
||||||
|
ItemType::ManaPotion => ['!', 'M'],
|
||||||
|
ItemType::Food => ['%', 'F'],
|
||||||
|
ItemType::Scroll => ['?', 'S'],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn display_string(&self) -> String {
|
||||||
|
let [a, b] = self.display_glyph();
|
||||||
|
format!("{}{}", a, b)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn color(&self) -> [u8; 3] {
|
pub fn color(&self) -> [u8; 3] {
|
||||||
match self.typ {
|
match self.typ {
|
||||||
ItemType::Dagger => [200, 200, 200],
|
ItemType::Dagger => [200, 200, 200],
|
||||||
|
|||||||
+23
-26
@@ -421,11 +421,22 @@ impl UiLayer {
|
|||||||
|
|
||||||
let inv_title = "INV:";
|
let inv_title = "INV:";
|
||||||
self.draw_text(start_x + 2, start_y + 37, inv_title, fg, 255);
|
self.draw_text(start_x + 2, start_y + 37, inv_title, fg, 255);
|
||||||
for (idx, item) in player_state.inventory.iter().take(6).enumerate() {
|
let mut ix = start_x + 14;
|
||||||
let ix = start_x + 14 + (idx as i32 * 4);
|
for item in player_state.inventory.iter().take(8) {
|
||||||
if ix < start_x + w - 2 {
|
if ix + 1 >= start_x + w - 1 {
|
||||||
self.set(ix, start_y + 38, item.display_char(), item.color(), bg);
|
break;
|
||||||
}
|
}
|
||||||
|
let [ch1, ch2] = item.display_glyph();
|
||||||
|
let col = item.color();
|
||||||
|
self.set(ix, start_y + 38, ch1, col, bg);
|
||||||
|
self.set(
|
||||||
|
ix + 1,
|
||||||
|
start_y + 38,
|
||||||
|
ch2,
|
||||||
|
[col[0] / 2, col[1] / 2, col[2] / 2],
|
||||||
|
bg,
|
||||||
|
);
|
||||||
|
ix += 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
let status = if let Some(p) = player {
|
let status = if let Some(p) = player {
|
||||||
@@ -470,30 +481,16 @@ impl UiLayer {
|
|||||||
let border = [160u8, 170, 210];
|
let border = [160u8, 170, 210];
|
||||||
let fill_alpha = 140u8;
|
let fill_alpha = 140u8;
|
||||||
let brush_name = material_name(brush);
|
let brush_name = material_name(brush);
|
||||||
let weapon_name = player_state
|
let weapon_glyph = player_state
|
||||||
.weapon
|
.weapon
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|i| {
|
.map(|i| i.display_string())
|
||||||
let n = i.name();
|
.unwrap_or(" ".to_string());
|
||||||
if n.len() > 12 {
|
let armor_glyph = player_state
|
||||||
&n[..12]
|
|
||||||
} else {
|
|
||||||
n
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.unwrap_or("NONE");
|
|
||||||
let armor_name = player_state
|
|
||||||
.armor
|
.armor
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|i| {
|
.map(|i| i.display_string())
|
||||||
let n = i.name();
|
.unwrap_or(" ".to_string());
|
||||||
if n.len() > 12 {
|
|
||||||
&n[..12]
|
|
||||||
} else {
|
|
||||||
n
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.unwrap_or("NONE");
|
|
||||||
|
|
||||||
let bar_h = 18i32;
|
let bar_h = 18i32;
|
||||||
let y_top = screen_h as i32 - bar_h;
|
let y_top = screen_h as i32 - bar_h;
|
||||||
@@ -539,8 +536,8 @@ impl UiLayer {
|
|||||||
|
|
||||||
let gear = format!(
|
let gear = format!(
|
||||||
"W:[{}] A:[{}] INV:{} FPS:{}",
|
"W:[{}] A:[{}] INV:{} FPS:{}",
|
||||||
weapon_name,
|
weapon_glyph,
|
||||||
armor_name,
|
armor_glyph,
|
||||||
player_state.inventory.len(),
|
player_state.inventory.len(),
|
||||||
fps as i32
|
fps as i32
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user