diff --git a/.gitignore b/.gitignore index 6d00d4c..14bda14 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ target wasm/index.css wasm/index.html docs/gifs/* +resources/archived resources # VSCode/IDE config files Cargo.lock diff --git a/resources/Ac437_ATT_PC6300.ttf b/resources/Ac437_ATT_PC6300.ttf deleted file mode 100644 index 840a431..0000000 Binary files a/resources/Ac437_ATT_PC6300.ttf and /dev/null differ diff --git a/resources/PressStart2P-Regular.ttf b/resources/PressStart2P-Regular.ttf deleted file mode 100644 index 2442aff..0000000 Binary files a/resources/PressStart2P-Regular.ttf and /dev/null differ diff --git a/resources/Ubuntu-B.ttf b/resources/Ubuntu-B.ttf deleted file mode 100644 index b173da2..0000000 Binary files a/resources/Ubuntu-B.ttf and /dev/null differ diff --git a/resources/cp437.ttf b/resources/cp437.ttf deleted file mode 100644 index db29a29..0000000 Binary files a/resources/cp437.ttf and /dev/null differ diff --git a/resources/cp437_8x16.ttf b/resources/cp437_8x16.ttf deleted file mode 100644 index a6b4246..0000000 Binary files a/resources/cp437_8x16.ttf and /dev/null differ diff --git a/resources/curses11x20.png b/resources/curses11x20.png deleted file mode 100644 index 5f5e1e5..0000000 Binary files a/resources/curses11x20.png and /dev/null differ diff --git a/resources/curses12x24.png b/resources/curses12x24.png deleted file mode 100644 index 4504d0a..0000000 Binary files a/resources/curses12x24.png and /dev/null differ diff --git a/resources/curses14x16.png b/resources/curses14x16.png deleted file mode 100644 index a06abb6..0000000 Binary files a/resources/curses14x16.png and /dev/null differ diff --git a/resources/curses16x16.pdn b/resources/curses16x16.pdn deleted file mode 100644 index a13f60d..0000000 Binary files a/resources/curses16x16.pdn and /dev/null differ diff --git a/resources/curses16x16.png b/resources/curses16x16.png deleted file mode 100644 index 042abea..0000000 Binary files a/resources/curses16x16.png and /dev/null differ diff --git a/resources/curses8x16.pdn b/resources/curses8x16.pdn deleted file mode 100644 index 02b2112..0000000 Binary files a/resources/curses8x16.pdn and /dev/null differ diff --git a/resources/curses8x16.png b/resources/curses8x16.png deleted file mode 100644 index 4b83036..0000000 Binary files a/resources/curses8x16.png and /dev/null differ diff --git a/resources/fonts/Greybeard-16px-Bold.ttf b/resources/fonts/Greybeard-16px-Bold.ttf new file mode 100644 index 0000000..2572e2e Binary files /dev/null and b/resources/fonts/Greybeard-16px-Bold.ttf differ diff --git a/resources/fonts/Greybeard-16px-Italic.ttf b/resources/fonts/Greybeard-16px-Italic.ttf new file mode 100644 index 0000000..565f839 Binary files /dev/null and b/resources/fonts/Greybeard-16px-Italic.ttf differ diff --git a/resources/fonts/Greybeard-16px.ttf b/resources/fonts/Greybeard-16px.ttf new file mode 100644 index 0000000..9448244 Binary files /dev/null and b/resources/fonts/Greybeard-16px.ttf differ diff --git a/resources/fonts/Swanston-Bold.ttf b/resources/fonts/Swanston-Bold.ttf new file mode 100644 index 0000000..9522db0 Binary files /dev/null and b/resources/fonts/Swanston-Bold.ttf differ diff --git a/resources/fonts/Swanston.ttf b/resources/fonts/Swanston.ttf new file mode 100644 index 0000000..d4eda57 Binary files /dev/null and b/resources/fonts/Swanston.ttf differ diff --git a/resources/healthbar11x2.png b/resources/healthbar11x2.png deleted file mode 100644 index 96fb67c..0000000 Binary files a/resources/healthbar11x2.png and /dev/null differ diff --git a/resources/healthbar22x2.png b/resources/healthbar22x2.png deleted file mode 100644 index daa15d1..0000000 Binary files a/resources/healthbar22x2.png and /dev/null differ diff --git a/resources/nagidal22x20_centred.png b/resources/nagidal22x20_centred.png deleted file mode 100644 index 1383fb9..0000000 Binary files a/resources/nagidal22x20_centred.png and /dev/null differ diff --git a/resources/nagidal22x22_centred.png b/resources/nagidal22x22_centred.png deleted file mode 100644 index f941b27..0000000 Binary files a/resources/nagidal22x22_centred.png and /dev/null differ diff --git a/resources/nagidal24x24.png b/resources/nagidal24x24.png deleted file mode 100644 index 2d4aba9..0000000 Binary files a/resources/nagidal24x24.png and /dev/null differ diff --git a/resources/terminal10x10_gs_tc.png b/resources/terminal10x10_gs_tc.png deleted file mode 100644 index 5e0cdc9..0000000 Binary files a/resources/terminal10x10_gs_tc.png and /dev/null differ diff --git a/resources/vga8x16.png b/resources/vga8x16.png deleted file mode 100644 index 913e32c..0000000 Binary files a/resources/vga8x16.png and /dev/null differ diff --git a/resources/world16x16.png b/resources/world16x16.png deleted file mode 100644 index e05e1d5..0000000 Binary files a/resources/world16x16.png and /dev/null differ diff --git a/src/consts/mod.rs b/src/consts/mod.rs index 7713b62..0192f5f 100644 --- a/src/consts/mod.rs +++ b/src/consts/mod.rs @@ -13,6 +13,6 @@ pub mod prelude { } pub const TILESIZE: f32 = 16.0; -pub const FONTSIZE: f32 = 24.0; +pub const FONTSIZE: f32 = 16.0; pub const DISPLAYWIDTH: u32 = 100; pub const DISPLAYHEIGHT: u32 = 56; diff --git a/src/gamelog/logstore.rs b/src/gamelog/logstore.rs index 6724b4e..9b1b628 100644 --- a/src/gamelog/logstore.rs +++ b/src/gamelog/logstore.rs @@ -6,23 +6,30 @@ use notan::prelude::*; use notan::text::CreateText; use crate::consts::{ TILESIZE, FONTSIZE }; use crate::consts::visuals::VIEWPORT_W; +use crate::Fonts; lazy_static! { pub static ref LOG: Mutex>> = Mutex::new(BTreeMap::new()); } /// Render with defaults, to avoid having to pass so many args. -pub fn render(draw: bool, gfx: &mut Graphics, font: ¬an::draw::Font) { +pub fn render(draw: bool, gfx: &mut Graphics, font: &Fonts) { if draw { - render_log(gfx, &font, &(TILESIZE, TILESIZE * 8.0 + 4.0), (VIEWPORT_W as f32) * TILESIZE); + render_log( + gfx, + &font, + &(TILESIZE, TILESIZE * 8.0 + 4.0), + (VIEWPORT_W as f32) * TILESIZE, + 7 + ); } } /// Render with specificied params. -pub fn render_log(gfx: &mut Graphics, font: ¬an::draw::Font, pos: &(f32, f32), width: f32) { +pub fn render_log(gfx: &mut Graphics, font: &Fonts, pos: &(f32, f32), width: f32, entries: usize) { let mut text = gfx.create_text(); let log = LOG.lock().unwrap(); - let latest: Vec<_> = log.iter().rev().take(5).collect(); + let latest: Vec<_> = log.iter().rev().take(entries).collect(); let mut initialised = false; let mut y = pos.1; for (_, entries) in latest { @@ -30,7 +37,7 @@ pub fn render_log(gfx: &mut Graphics, font: ¬an::draw::Font, pos: &(f32, f32) for frag in entries.iter() { if !written_on_line { text.add(&frag.text) - .font(font) + .font(font.n()) .position(pos.0, y) .size(FONTSIZE) .max_width(width) diff --git a/src/gui/character_creation.rs b/src/gui/character_creation.rs index f3951d6..fed5222 100644 --- a/src/gui/character_creation.rs +++ b/src/gui/character_creation.rs @@ -119,15 +119,15 @@ pub enum CharCreateResult { use notan::prelude::*; use notan::draw::{ Draw, CreateDraw, DrawTextSection, Font }; -use specs::prelude::*; use super::{ FONTSIZE, DISPLAYWIDTH, TILESIZE, MainMenuSelection }; use crate::consts::DISPLAYHEIGHT; +use crate::Fonts; pub fn draw_charcreation( ecs: &World, draw: &mut Draw, atlas: &HashMap, - font: &Font + font: &Fonts ) { let runstate = ecs.read_resource::(); let (class, ancestry) = match *runstate { @@ -136,7 +136,7 @@ pub fn draw_charcreation( }; let (mut x, mut y) = (2.0 * TILESIZE, ((DISPLAYHEIGHT as f32) * TILESIZE) / 4.0); const COLUMN_WIDTH: f32 = 20.0 * TILESIZE; - draw.text(font, "Who are you?") + draw.text(&font.ib(), "Who are you?") .size(FONTSIZE * 2.0) .position(x, y) .h_align_left(); @@ -149,7 +149,7 @@ pub fn draw_charcreation( ("c. Catfolk", Ancestry::Catfolk), ]; for (k, v) in &ancestries { - draw.text(font, k) + draw.text(font.n(), k) .size(FONTSIZE) .position(x, y) .h_align_left() @@ -165,7 +165,7 @@ pub fn draw_charcreation( ("v. Villager", Class::Villager), ]; for (k, v) in &classes { - draw.text(font, k) + draw.text(font.n(), k) .size(FONTSIZE) .position(x, y) .h_align_left() @@ -175,12 +175,12 @@ pub fn draw_charcreation( y = initial_y; x += COLUMN_WIDTH; for line in ANCESTRYDATA.get(&ancestry).unwrap().iter() { - draw.text(font, line).size(FONTSIZE).position(x, y).h_align_left(); + draw.text(font.n(), line).size(FONTSIZE).position(x, y).h_align_left(); y = draw.last_text_bounds().max_y(); } y += TILESIZE; for line in CLASSDATA.get(&class).unwrap().iter() { - draw.text(font, line).size(FONTSIZE).position(x, y).h_align_left(); + draw.text(font.n(), line).size(FONTSIZE).position(x, y).h_align_left(); y = draw.last_text_bounds().max_y(); } } diff --git a/src/gui/cheat_menu.rs b/src/gui/cheat_menu.rs index 5c3df6f..8c01e72 100644 --- a/src/gui/cheat_menu.rs +++ b/src/gui/cheat_menu.rs @@ -47,7 +47,7 @@ pub fn show_cheat_menu(_gs: &mut State, ctx: &mut App) -> CheatMenuResult { pub fn draw_cheat_menu( draw: &mut notan::draw::Draw, _atlas: &HashMap, - font: ¬an::draw::Font + font: &crate::Fonts ) { let offsets = crate::camera::get_offset(); const DEBUG_MENU: &str = @@ -58,7 +58,7 @@ pub fn draw_cheat_menu( h - HEAL TO FULL m - MAGIC MAP REVEAL g - GOD MODE"#; - draw.text(&font, DEBUG_MENU) + draw.text(&font.n(), DEBUG_MENU) .position((1.0 + (offsets.x as f32)) * TILESIZE, (1.0 + (offsets.y as f32)) * TILESIZE) .color(Color::RED) .size(FONTSIZE); diff --git a/src/gui/inventory.rs b/src/gui/inventory.rs index e3eeb77..0b08274 100644 --- a/src/gui/inventory.rs +++ b/src/gui/inventory.rs @@ -2,8 +2,9 @@ use notan::prelude::*; use notan::draw::{ Draw, Font }; use specs::prelude::*; use super::TILESIZE; +use crate::Fonts; -pub fn draw_inventory(ecs: &World, draw: &mut Draw, font: &Font) { +pub fn draw_inventory(ecs: &World, draw: &mut Draw, font: &Fonts) { let inv = super::get_player_inventory(ecs); let offsets = crate::camera::get_offset(); super::print_options( diff --git a/src/gui/main_menu.rs b/src/gui/main_menu.rs index 9f44b72..18f1b3e 100644 --- a/src/gui/main_menu.rs +++ b/src/gui/main_menu.rs @@ -4,8 +4,9 @@ use specs::prelude::*; use std::collections::HashMap; use super::{ FONTSIZE, RunState, DISPLAYWIDTH, TILESIZE, MainMenuSelection }; use crate::consts::DISPLAYHEIGHT; +use crate::Fonts; -pub fn draw_mainmenu(ecs: &World, draw: &mut Draw, atlas: &HashMap, font: &Font) { +pub fn draw_mainmenu(ecs: &World, draw: &mut Draw, atlas: &HashMap, font: &Fonts) { let runstate = ecs.read_resource::(); let selected = match *runstate { RunState::MainMenu { menu_selection } => menu_selection, @@ -15,26 +16,26 @@ pub fn draw_mainmenu(ecs: &World, draw: &mut Draw, atlas: &HashMap, - font: ¬an::draw::Font -) { +pub fn draw_ui2(ecs: &World, draw: &mut Draw, atlas: &HashMap, font: &Fonts) { let pools = ecs.read_storage::(); let attributes = ecs.read_storage::(); let players = ecs.read_storage::(); @@ -227,26 +224,26 @@ pub fn draw_ui2( mp_colours.0, (stats.mana.current as f32) / (stats.mana.max as f32) ); - draw.text(&font, "HP").position(x, row1).size(FONTSIZE); + draw.text(&font.b(), "HP").position(x, row1).size(FONTSIZE); x = draw.last_text_bounds().max_x(); - draw.text(&font, &format!("{}", stats.hit_points.current)) + draw.text(&font.n(), &format!("{}", stats.hit_points.current)) .position(x, row1) .size(FONTSIZE) .color(Color::from_rgb(hp.r, hp.g, hp.b)); x = draw.last_text_bounds().max_x(); - draw.text(&font, &format!("({})", stats.hit_points.max)) + draw.text(&font.n(), &format!("({})", stats.hit_points.max)) .position(x, row1) .size(FONTSIZE) .color(Color::from_rgb(hp_colours.2.r, hp_colours.2.g, hp_colours.2.b)); x = initial_x; - draw.text(&font, "MP").position(x, row2).size(FONTSIZE); + draw.text(&font.b(), "MP").position(x, row2).size(FONTSIZE); x = draw.last_text_bounds().max_x(); - draw.text(&font, &format!("{}", stats.mana.current)) + draw.text(&font.n(), &format!("{}", stats.mana.current)) .position(x, row2) .size(FONTSIZE) .color(Color::from_rgb(mp.r, mp.g, mp.b)); x = draw.last_text_bounds().max_x(); - draw.text(&font, &format!("({})", stats.mana.max)) + draw.text(&font.n(), &format!("({})", stats.mana.max)) .position(x, row2) .size(FONTSIZE) .color(Color::from_rgb(mp_colours.2.r, mp_colours.2.g, mp_colours.2.b)); @@ -264,45 +261,47 @@ pub fn draw_ui2( x = draw.last_text_bounds().max_x() + 2.0 * TILESIZE; let armour_class = stats.bac - attributes.dexterity.modifier() / 2 - skill_ac_bonus - armour_ac_bonus; - draw.text(&font, "AC").position(x, row1).color(Color::PINK).size(FONTSIZE); + draw.text(&font.b(), "AC").position(x, row1).color(Color::PINK).size(FONTSIZE); let last_x = draw.last_text_bounds().max_x(); - draw.text(&font, &format!("{:<2}", armour_class)).position(last_x, row1).size(FONTSIZE); - draw.text(&font, &format!("XP{}/{}", stats.level, stats.xp)) - .position(x, row2) + draw.text(&font.n(), &format!("{:<2}", armour_class)).position(last_x, row1).size(FONTSIZE); + draw.text(&font.b(), &format!("XP")).position(x, row2).size(FONTSIZE); + let last_x = draw.last_text_bounds().max_x(); + draw.text(&font.n(), &format!("{}/{}", stats.level, stats.xp)) + .position(last_x, row2) .size(FONTSIZE); let attribute_x = draw.last_text_bounds().max_x() + 2.0 * TILESIZE; - draw.text(&font, "STR").position(attribute_x, row1).color(Color::RED).size(FONTSIZE); + draw.text(&font.b(), "STR").position(attribute_x, row1).color(Color::RED).size(FONTSIZE); x = draw.last_text_bounds().max_x(); - draw.text(&font, &format!("{:<2}", attributes.strength.base)) + draw.text(&font.n(), &format!("{:<2}", attributes.strength.base)) .position(x, row1) .size(FONTSIZE); x = draw.last_text_bounds().max_x() + TILESIZE; - draw.text(&font, "DEX").position(x, row1).color(Color::GREEN).size(FONTSIZE); + draw.text(&font.b(), "DEX").position(x, row1).color(Color::GREEN).size(FONTSIZE); x = draw.last_text_bounds().max_x(); - draw.text(&font, &format!("{:<2}", attributes.dexterity.base)) + draw.text(&font.n(), &format!("{:<2}", attributes.dexterity.base)) .position(x, row1) .size(FONTSIZE); x = draw.last_text_bounds().max_x() + TILESIZE; - draw.text(&font, "CON").position(x, row1).color(Color::ORANGE).size(FONTSIZE); + draw.text(&font.b(), "CON").position(x, row1).color(Color::ORANGE).size(FONTSIZE); x = draw.last_text_bounds().max_x(); - draw.text(&font, &format!("{:<2}", attributes.constitution.base)) + draw.text(&font.n(), &format!("{:<2}", attributes.constitution.base)) .position(x, row1) .size(FONTSIZE); - draw.text(&font, "INT").position(attribute_x, row2).color(Color::BLUE).size(FONTSIZE); + draw.text(&font.b(), "INT").position(attribute_x, row2).color(Color::BLUE).size(FONTSIZE); x = draw.last_text_bounds().max_x(); - draw.text(&font, &format!("{:<2}", attributes.intelligence.base)) + draw.text(&font.n(), &format!("{:<2}", attributes.intelligence.base)) .position(x, row2) .size(FONTSIZE); x = draw.last_text_bounds().max_x() + TILESIZE; - draw.text(&font, "WIS").position(x, row2).color(Color::YELLOW).size(FONTSIZE); + draw.text(&font.b(), "WIS").position(x, row2).color(Color::YELLOW).size(FONTSIZE); x = draw.last_text_bounds().max_x(); - draw.text(&font, &format!("{:<2}", attributes.wisdom.base)) + draw.text(&font.n(), &format!("{:<2}", attributes.wisdom.base)) .position(x, row2) .size(FONTSIZE); x = draw.last_text_bounds().max_x() + TILESIZE; - draw.text(&font, "CHA").position(x, row2).color(Color::PURPLE).size(FONTSIZE); + draw.text(&font.b(), "CHA").position(x, row2).color(Color::PURPLE).size(FONTSIZE); x = draw.last_text_bounds().max_x(); - draw.text(&font, &format!("{:<2}", attributes.charisma.base)) + draw.text(&font.n(), &format!("{:<2}", attributes.charisma.base)) .position(x, row2) .size(FONTSIZE); let hungertxt = match hunger.state { @@ -317,7 +316,7 @@ pub fn draw_ui2( HungerState::Normal => {} _ => { let col = get_hunger_colour(hunger.state); - draw.text(&font, hungertxt) + draw.text(&font.n(), hungertxt) .position(((VIEWPORT_W + 1) as f32) * TILESIZE, row1) .color(Color::from_bytes(col.0, col.1, col.2, 255)) .size(FONTSIZE) @@ -330,14 +329,14 @@ pub fn draw_ui2( } else { format!("{}", map.short_name) }; - draw.text(&font, &id) + draw.text(&font.n(), &id) .position(((VIEWPORT_W + 1) as f32) * TILESIZE, row2) .color(Color::WHITE) // get_local_col() .size(FONTSIZE) .h_align_right(); let turns = crate::gamelog::get_event_count(EVENT::COUNT_TURN); x = draw.last_text_bounds().min_x() - TILESIZE; - draw.text(&font, &format!("T{}", turns)) + draw.text(&font.n(), &format!("T{}", turns)) .position(x, row2) .color(Color::YELLOW) .size(FONTSIZE) @@ -349,14 +348,14 @@ pub fn draw_ui2( BurdenLevel::Strained => ("Strained", RGB::named(ORANGE)), BurdenLevel::Overloaded => ("Overloaded", RGB::named(RED)), }; - draw.text(&font, &text) + draw.text(&font.n(), &text) .position((VIEWPORT_W as f32) * TILESIZE, 50.0 * TILESIZE) .color(Color::from_rgb(colour.r, colour.g, colour.b)) .size(FONTSIZE) .h_align_right(); } if stats.god { - draw.text(&font, "--- GODMODE: ON ---") + draw.text(&font.n(), "--- GODMODE: ON ---") .position(20.0 * TILESIZE, 20.0 * TILESIZE) .color(Color::YELLOW) .size(FONTSIZE); @@ -378,32 +377,32 @@ pub fn draw_ui2( let mut y = 1; // TODO: Fix all of this to work with notan colours, and sprites. if !equipment.is_empty() { - draw.text(&font, "Equipment") + draw.text(&font.b(), "Equipment") .position(((VIEWPORT_W + 3) as f32) * TILESIZE, (y as f32) * TILESIZE) .size(FONTSIZE); let mut j: u8 = 0; for item in equipment { y += 1; x = ((VIEWPORT_W + 3) as f32) * TILESIZE; - draw.text(&font, &format!("{}", (97 + j) as char)) + draw.text(&font.b(), &format!("{} ", (97 + j) as char)) .position(x, (y as f32) * TILESIZE) .color(Color::YELLOW) .size(FONTSIZE); j += 1; - x = draw.last_text_bounds().max_x() + 1.0 * TILESIZE; + x = draw.last_text_bounds().max_x(); let mut col = item.2; - draw.text(&font, &format!("{}", item.3 as u8 as char)) + draw.text(&font.n(), &format!("{} ", item.3 as u8 as char)) .position(x, (y as f32) * TILESIZE) .size(FONTSIZE) .color(Color::from_rgb(col.r, col.g, col.b)); // Colours here - and below. - x = draw.last_text_bounds().max_x() + 1.0 * TILESIZE; + x = draw.last_text_bounds().max_x(); col = item.1; - draw.text(&font, &item.0) + draw.text(&font.n(), &item.0) .position(x, (y as f32) * TILESIZE) .size(FONTSIZE) .color(Color::from_rgb(col.r, col.g, col.b)); - x = draw.last_text_bounds().max_x() + 1.0 * TILESIZE; - draw.text(&font, "(worn)") + x = draw.last_text_bounds().max_x(); + draw.text(&font.n(), " (worn)") .position(x, (y as f32) * TILESIZE) .size(FONTSIZE); } @@ -411,11 +410,11 @@ pub fn draw_ui2( } // Backpack x = ((VIEWPORT_W + 3) as f32) * TILESIZE; - draw.text(&font, "Backpack") + draw.text(&font.b(), "Backpack") .position(x, (y as f32) * TILESIZE) .size(FONTSIZE); draw.text( - &font, + &font.b(), &format!( "[{:.1}/{} lbs]", stats.weight, @@ -916,7 +915,7 @@ pub enum ItemMenuResult { pub fn print_options( draw: &mut Draw, - font: ¬an::draw::Font, + font: &Fonts, inventory: &PlayerInventory, mut x: f32, mut y: f32 @@ -928,28 +927,28 @@ pub fn print_options( x = initial_x; // Print the character required to access this item. i.e. (a) if j < 26 { - draw.text(font, &format!("{}", (97 + j) as u8 as char)) + draw.text(&font.b(), &format!("{} ", (97 + j) as u8 as char)) .position(x, y) .color(Color::YELLOW) .size(FONTSIZE); } else { // If we somehow have more than 26, start using capitals - draw.text(font, &format!("{}", (65 - 26 + j) as u8 as char)) + draw.text(&font.b(), &format!("{} ", (65 - 26 + j) as u8 as char)) .position(x, y) .color(Color::YELLOW) .size(FONTSIZE); } - x = draw.last_text_bounds().max_x() + TILESIZE; + x = draw.last_text_bounds().max_x(); let fg = RGB::from_u8(item.renderables.0, item.renderables.1, item.renderables.2); - draw.text(font, &format!("{}", item.glyph as u8 as char)) + draw.text(&font.n(), &format!("{} ", item.glyph as u8 as char)) .position(x, y) .size(FONTSIZE) .color(Color::from_rgb(fg.r, fg.g, fg.b)); - x = draw.last_text_bounds().max_x() + TILESIZE; + x = draw.last_text_bounds().max_x(); let fg = RGB::from_u8(item.rgb.0, item.rgb.1, item.rgb.2); if item_count > &1 { - draw.text(font, &format!("{} {}", item_count, item.display_name.plural)) + draw.text(&font.n(), &format!("{} {}", item_count, item.display_name.plural)) .position(x, y) .color(Color::from_rgb(fg.r, fg.g, fg.b)) .size(FONTSIZE); @@ -965,7 +964,7 @@ pub fn print_options( } else { "a" }; - draw.text(font, &format!("{} {}", prefix, item.display_name.singular)) + draw.text(&font.n(), &format!("{} {}", prefix, item.display_name.singular)) .position(x, y) .color(Color::from_rgb(fg.r, fg.g, fg.b)) .size(FONTSIZE); diff --git a/src/lib.rs b/src/lib.rs index 5481482..3e9b288 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -41,3 +41,4 @@ use particle_system::ParticleBuilder; pub use map::*; pub use states::runstate::RunState; pub use states::state::State; +pub use states::state::Fonts; diff --git a/src/main.rs b/src/main.rs index d1f8a0a..b079714 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,6 +7,7 @@ use specs::saveload::{ SimpleMarker, SimpleMarkerAllocator }; use bracket_lib::prelude::*; use std::collections::HashMap; use crate::consts::{ DISPLAYHEIGHT, DISPLAYWIDTH, TILESIZE, FONTSIZE }; +use crate::states::state::Fonts; #[notan_main] fn main() -> Result<(), String> { @@ -33,7 +34,15 @@ fn setup(gfx: &mut Graphics) -> State { .unwrap(); let data = include_bytes!("../resources/td.json"); let atlas = create_textures_from_atlas(data, &texture).unwrap(); - let font = gfx.create_font(include_bytes!("../resources/Ac437_ATT_PC6300.ttf")).unwrap(); + let font = Fonts::new( + gfx.create_font(include_bytes!("../resources/fonts/Greybeard-16px.ttf")).unwrap(), + Some( + gfx.create_font(include_bytes!("../resources/fonts/Greybeard-16px-Bold.ttf")).unwrap() + ), + Some( + gfx.create_font(include_bytes!("../resources/fonts/Greybeard-16px-Italic.ttf")).unwrap() + ) + ); let mut gs = State { ecs: World::new(), base_texture: texture, @@ -173,7 +182,7 @@ fn draw_camera( ecs: &World, draw: &mut Draw, atlas: &HashMap, - font: ¬an::draw::Font + font: &Fonts ) { render_map_in_view(&*map, ecs, draw, atlas, false); { @@ -283,7 +292,7 @@ fn draw_camera( } else { // Fallback to drawing text. draw.text( - &font, + &font.b(), &format!("{}", bracket_lib::terminal::to_char(renderable.glyph as u8)) ) .position( @@ -547,9 +556,9 @@ fn update(ctx: &mut App, state: &mut State) { state.update(ctx); } -fn corner_text(text: &str, draw: &mut Draw, font: ¬an::draw::Font) { +fn corner_text(text: &str, draw: &mut Draw, font: &Fonts) { let offset = crate::camera::get_offset(); - draw.text(&font, &text) + draw.text(&font.n(), &text) .position(((offset.x + 1) as f32) * TILESIZE, ((offset.y + 1) as f32) * TILESIZE) .size(FONTSIZE); } diff --git a/src/states/state.rs b/src/states/state.rs index e34ca6b..9fcea38 100644 --- a/src/states/state.rs +++ b/src/states/state.rs @@ -26,12 +26,44 @@ use crate::damage_system; use std::collections::HashMap; use notan::prelude::*; +pub struct Fonts { + normal: notan::draw::Font, + bold: Option, + italic: Option, +} + +impl Fonts { + pub fn new( + normal: notan::draw::Font, + bold: Option, + italic: Option + ) -> Self { + Self { normal, bold, italic } + } + /// Returns the regular weight font. + pub fn n(&self) -> ¬an::draw::Font { + &self.normal + } + /// Returns the bold weight font, or the regular weight font if no bold font is available. + pub fn b(&self) -> notan::draw::Font { + if self.bold.is_some() { self.bold.unwrap() } else { self.normal } + } + /// Returns the italic weight font, or the regular weight font if no italic font is available. + pub fn i(&self) -> notan::draw::Font { + if self.italic.is_some() { self.italic.unwrap() } else { self.normal } + } + /// Returns in order of preference: italic, bold, regular font weights, depending on what is available. + pub fn ib(&self) -> notan::draw::Font { + if self.italic.is_some() { self.italic.unwrap() } else { self.b() } + } +} + #[derive(AppState)] pub struct State { pub ecs: World, pub base_texture: Texture, pub atlas: HashMap, - pub font: notan::draw::Font, + pub font: Fonts, pub mapgen_next_state: Option, pub mapgen_history: Vec, pub mapgen_index: usize,