first steps - extreme wip

1. need to finish curses12x24 first of all
2. bind everything to the viewport, and make scalable
This commit is contained in:
Llywelwyn 2023-09-03 01:45:18 +01:00
parent d018d9077d
commit 2a3c59ad33
11 changed files with 750 additions and 978 deletions

1102
Cargo.lock generated

File diff suppressed because it is too large Load diff

BIN
resources/curses12x24.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

BIN
resources/curses16x16.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

BIN
resources/nagidal24x24.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

View file

@ -2,13 +2,14 @@ use super::{ Hidden, Map, Mind, Position, Prop, Renderable };
use rltk::prelude::*; use rltk::prelude::*;
use specs::prelude::*; use specs::prelude::*;
use std::ops::Mul; use std::ops::Mul;
use super::data::visuals::{ VIEWPORT_W, VIEWPORT_H };
const SHOW_BOUNDARIES: bool = false; const SHOW_BOUNDARIES: bool = false;
pub fn get_screen_bounds(ecs: &World, _ctx: &mut Rltk) -> (i32, i32, i32, i32, i32, i32) { pub fn get_screen_bounds(ecs: &World, _ctx: &mut Rltk) -> (i32, i32, i32, i32, i32, i32) {
let player_pos = ecs.fetch::<Point>(); let player_pos = ecs.fetch::<Point>();
let map = ecs.fetch::<Map>(); let map = ecs.fetch::<Map>();
let (x_chars, y_chars, mut x_offset, mut y_offset) = (69, 41, 1, 10); let (x_chars, y_chars, mut x_offset, mut y_offset) = (VIEWPORT_W, VIEWPORT_H, 1, 10);
let centre_x = (x_chars / 2) as i32; let centre_x = (x_chars / 2) as i32;
let centre_y = (y_chars / 2) as i32; let centre_y = (y_chars / 2) as i32;
@ -52,7 +53,13 @@ pub fn render_camera(ecs: &World, ctx: &mut Rltk) {
ctx.set(x + x_offset, y + y_offset, fg, bg, glyph); ctx.set(x + x_offset, y + y_offset, fg, bg, glyph);
} }
} else if SHOW_BOUNDARIES { } else if SHOW_BOUNDARIES {
ctx.set(x + x_offset, y + y_offset, RGB::named(DARKSLATEGRAY), RGB::named(BLACK), rltk::to_cp437('#')); ctx.set(
x + x_offset,
y + y_offset,
RGB::named(DARKSLATEGRAY),
RGB::named(BLACK),
rltk::to_cp437('#')
);
} }
x += 1; x += 1;
} }
@ -112,7 +119,13 @@ pub fn render_camera(ecs: &World, ctx: &mut Rltk) {
} }
} }
if draw { if draw {
ctx.set(entity_offset_x + x_offset, entity_offset_y + y_offset, fg, bg, render.glyph); ctx.set(
entity_offset_x + x_offset,
entity_offset_y + y_offset,
fg,
bg,
render.glyph
);
} }
} }
} }
@ -141,7 +154,12 @@ pub fn render_debug_map(map: &Map, ctx: &mut Rltk) {
if tx >= 0 && tx < map_width && ty >= 0 && ty < map_height { if tx >= 0 && tx < map_width && ty >= 0 && ty < map_height {
let idx = map.xy_idx(tx, ty); let idx = map.xy_idx(tx, ty);
if map.revealed_tiles[idx] { if map.revealed_tiles[idx] {
let (glyph, fg, bg) = crate::map::themes::get_tile_renderables_for_id(idx, &*map, None, None); let (glyph, fg, bg) = crate::map::themes::get_tile_renderables_for_id(
idx,
&*map,
None,
None
);
ctx.set(x, y, fg, bg, glyph); ctx.set(x, y, fg, bg, glyph);
} }
} else if SHOW_BOUNDARIES { } else if SHOW_BOUNDARIES {

View file

@ -1,5 +1,7 @@
// POST-PROCESSING // POST-PROCESSING
pub const WITH_DARKEN_BY_DISTANCE: bool = true; // If further away tiles should get darkened, instead of a harsh transition to non-visible. pub const WITH_DARKEN_BY_DISTANCE: bool = true; // If further away tiles should get darkened, instead of a harsh transition to non-visible.
pub const VIEWPORT_W: i32 = 40;
pub const VIEWPORT_H: i32 = 30;
pub const BRIGHTEN_FG_COLOUR_BY: i32 = 16; pub const BRIGHTEN_FG_COLOUR_BY: i32 = 16;
pub const GLOBAL_OFFSET_MIN_CLAMP: f32 = -0.5; pub const GLOBAL_OFFSET_MIN_CLAMP: f32 = -0.5;

View file

@ -112,6 +112,7 @@ pub enum CharCreateResult {
/// Handles the player character creation screen. /// Handles the player character creation screen.
pub fn character_creation(gs: &mut State, ctx: &mut Rltk) -> CharCreateResult { pub fn character_creation(gs: &mut State, ctx: &mut Rltk) -> CharCreateResult {
ctx.set_active_console(1);
let runstate = gs.ecs.fetch::<RunState>(); let runstate = gs.ecs.fetch::<RunState>();
let mut x = 2; let mut x = 2;
@ -245,6 +246,7 @@ pub fn character_creation(gs: &mut State, ctx: &mut Rltk) -> CharCreateResult {
} }
} }
} }
ctx.set_active_console(0);
return CharCreateResult::NoSelection { ancestry: Ancestry::Human, class: Class::Fighter }; return CharCreateResult::NoSelection { ancestry: Ancestry::Human, class: Class::Fighter };
} }

View file

@ -23,7 +23,7 @@ pub fn show_farlook(gs: &mut State, ctx: &mut Rltk) -> FarlookResult {
); );
if let RunState::Farlook { x, y } = *runstate { if let RunState::Farlook { x, y } = *runstate {
let (screen_x, screen_y) = (69, 41); let (screen_x, screen_y) = (40, 30);
let x = x.clamp(x_offset, x_offset - 1 + (screen_x as i32)); let x = x.clamp(x_offset, x_offset - 1 + (screen_x as i32));
let y = y.clamp(y_offset, y_offset - 1 + (screen_y as i32)); let y = y.clamp(y_offset, y_offset - 1 + (screen_y as i32));

View file

@ -35,7 +35,14 @@ use super::{
data::ids::get_local_col, data::ids::get_local_col,
}; };
use crate::data::entity::CARRY_CAPACITY_PER_STRENGTH; use crate::data::entity::CARRY_CAPACITY_PER_STRENGTH;
use crate::data::visuals::{ TARGETING_LINE_COL, TARGETING_CURSOR_COL, TARGETING_AOE_COL, TARGETING_VALID_COL }; use crate::data::visuals::{
TARGETING_LINE_COL,
TARGETING_CURSOR_COL,
TARGETING_AOE_COL,
TARGETING_VALID_COL,
VIEWPORT_W,
VIEWPORT_H,
};
use rltk::prelude::*; use rltk::prelude::*;
use specs::prelude::*; use specs::prelude::*;
use std::collections::BTreeMap; use std::collections::BTreeMap;
@ -96,7 +103,10 @@ pub fn draw_lerping_bar(
ctx.print(sx + width, sy, "]"); ctx.print(sx + width, sy, "]");
} }
pub const TEXT_FONT_MOD: i32 = 2;
pub fn draw_ui(ecs: &World, ctx: &mut Rltk) { pub fn draw_ui(ecs: &World, ctx: &mut Rltk) {
ctx.set_active_console(1);
// Render stats // Render stats
let pools = ecs.read_storage::<Pools>(); let pools = ecs.read_storage::<Pools>();
let attributes = ecs.read_storage::<Attributes>(); let attributes = ecs.read_storage::<Attributes>();
@ -104,12 +114,18 @@ pub fn draw_ui(ecs: &World, ctx: &mut Rltk) {
let hunger = ecs.read_storage::<HungerClock>(); let hunger = ecs.read_storage::<HungerClock>();
let burden = ecs.read_storage::<Burden>(); let burden = ecs.read_storage::<Burden>();
let skills = ecs.read_storage::<Skills>(); let skills = ecs.read_storage::<Skills>();
for (_player, stats, attributes, hunger, skills) in (&players, &pools, &attributes, &hunger, &skills).join() { for (_player, stats, attributes, hunger, skills) in (
&players,
&pools,
&attributes,
&hunger,
&skills,
).join() {
// Draw hp/mana bars // Draw hp/mana bars
draw_lerping_bar( draw_lerping_bar(
ctx, ctx,
2, 2 * TEXT_FONT_MOD,
53, 53 * TEXT_FONT_MOD,
22, 22,
stats.hit_points.current, stats.hit_points.current,
stats.hit_points.max, stats.hit_points.max,
@ -118,8 +134,8 @@ pub fn draw_ui(ecs: &World, ctx: &mut Rltk) {
); );
draw_lerping_bar( draw_lerping_bar(
ctx, ctx,
2, 2 * TEXT_FONT_MOD,
54, 54 * TEXT_FONT_MOD,
22, 22,
stats.mana.current, stats.mana.current,
stats.mana.max, stats.mana.max,
@ -137,66 +153,169 @@ pub fn draw_ui(ecs: &World, ctx: &mut Rltk) {
armour_ac_bonus += ac.amount; armour_ac_bonus += ac.amount;
} }
} }
let armour_class = stats.bac - attributes.dexterity.bonus / 2 - skill_ac_bonus - armour_ac_bonus; let armour_class =
ctx.print_color(26, 53, RGB::named(rltk::PINK), RGB::named(rltk::BLACK), "AC"); stats.bac - attributes.dexterity.bonus / 2 - skill_ac_bonus - armour_ac_bonus;
ctx.print_color(28, 53, RGB::named(rltk::WHITE), RGB::named(rltk::BLACK), armour_class); ctx.print_color(
26 * TEXT_FONT_MOD,
53,
RGB::named(rltk::PINK),
RGB::named(rltk::BLACK),
"AC"
);
ctx.print_color(
28 * TEXT_FONT_MOD,
53,
RGB::named(rltk::WHITE),
RGB::named(rltk::BLACK),
armour_class
);
// Draw level // Draw level
ctx.print_color( ctx.print_color(
26, 26 * TEXT_FONT_MOD,
54, 54,
RGB::named(rltk::WHITE), RGB::named(rltk::WHITE),
RGB::named(rltk::BLACK), RGB::named(rltk::BLACK),
format!("XP{}/{}", stats.level, stats.xp) format!("XP{}/{}", stats.level, stats.xp)
); );
// Draw attributes // Draw attributes
let x = 38; let x = 38 * TEXT_FONT_MOD;
ctx.print_color(x, 53, RGB::named(rltk::RED), RGB::named(rltk::BLACK), "STR"); ctx.print_color(x, 53, RGB::named(rltk::RED), RGB::named(rltk::BLACK), "STR");
ctx.print_color(x + 3, 53, RGB::named(rltk::WHITE), RGB::named(rltk::BLACK), attributes.strength.base); ctx.print_color(
x + 3,
53,
RGB::named(rltk::WHITE),
RGB::named(rltk::BLACK),
attributes.strength.base
);
ctx.print_color(x + 7, 53, RGB::named(rltk::GREEN), RGB::named(rltk::BLACK), "DEX"); ctx.print_color(x + 7, 53, RGB::named(rltk::GREEN), RGB::named(rltk::BLACK), "DEX");
ctx.print_color(x + 10, 53, RGB::named(rltk::WHITE), RGB::named(rltk::BLACK), attributes.dexterity.base); ctx.print_color(
x + 10,
53,
RGB::named(rltk::WHITE),
RGB::named(rltk::BLACK),
attributes.dexterity.base
);
ctx.print_color(x + 14, 53, RGB::named(rltk::ORANGE), RGB::named(rltk::BLACK), "CON"); ctx.print_color(x + 14, 53, RGB::named(rltk::ORANGE), RGB::named(rltk::BLACK), "CON");
ctx.print_color(x + 17, 53, RGB::named(rltk::WHITE), RGB::named(rltk::BLACK), attributes.constitution.base); ctx.print_color(
x + 17,
53,
RGB::named(rltk::WHITE),
RGB::named(rltk::BLACK),
attributes.constitution.base
);
ctx.print_color(x, 54, RGB::named(rltk::CYAN), RGB::named(rltk::BLACK), "INT"); ctx.print_color(x, 54, RGB::named(rltk::CYAN), RGB::named(rltk::BLACK), "INT");
ctx.print_color(x + 3, 54, RGB::named(rltk::WHITE), RGB::named(rltk::BLACK), attributes.intelligence.base); ctx.print_color(
x + 3,
54,
RGB::named(rltk::WHITE),
RGB::named(rltk::BLACK),
attributes.intelligence.base
);
ctx.print_color(x + 7, 54, RGB::named(rltk::YELLOW), RGB::named(rltk::BLACK), "WIS"); ctx.print_color(x + 7, 54, RGB::named(rltk::YELLOW), RGB::named(rltk::BLACK), "WIS");
ctx.print_color(x + 10, 54, RGB::named(rltk::WHITE), RGB::named(rltk::BLACK), attributes.wisdom.base); ctx.print_color(
x + 10,
54,
RGB::named(rltk::WHITE),
RGB::named(rltk::BLACK),
attributes.wisdom.base
);
ctx.print_color(x + 14, 54, RGB::named(rltk::PURPLE), RGB::named(rltk::BLACK), "CHA"); ctx.print_color(x + 14, 54, RGB::named(rltk::PURPLE), RGB::named(rltk::BLACK), "CHA");
ctx.print_color(x + 17, 54, RGB::named(rltk::WHITE), RGB::named(rltk::BLACK), attributes.charisma.base); ctx.print_color(
x + 17,
54,
RGB::named(rltk::WHITE),
RGB::named(rltk::BLACK),
attributes.charisma.base
);
// Draw hunger // Draw hunger
match hunger.state { match hunger.state {
HungerState::Satiated => { HungerState::Satiated => {
ctx.print_color_right(70, 53, get_hunger_colour(hunger.state), RGB::named(rltk::BLACK), "Satiated"); ctx.print_color_right(
(VIEWPORT_W + 1) * TEXT_FONT_MOD,
53,
get_hunger_colour(hunger.state),
RGB::named(rltk::BLACK),
"Satiated"
);
} }
HungerState::Normal => {} HungerState::Normal => {}
HungerState::Hungry => { HungerState::Hungry => {
ctx.print_color_right(70, 53, get_hunger_colour(hunger.state), RGB::named(rltk::BLACK), "Hungry"); ctx.print_color_right(
(VIEWPORT_W + 1) * TEXT_FONT_MOD,
53,
get_hunger_colour(hunger.state),
RGB::named(rltk::BLACK),
"Hungry"
);
} }
HungerState::Weak => { HungerState::Weak => {
ctx.print_color_right(70, 53, get_hunger_colour(hunger.state), RGB::named(rltk::BLACK), "Weak"); ctx.print_color_right(
(VIEWPORT_W + 1) * TEXT_FONT_MOD,
53,
get_hunger_colour(hunger.state),
RGB::named(rltk::BLACK),
"Weak"
);
} }
HungerState::Fainting => { HungerState::Fainting => {
ctx.print_color_right(70, 53, get_hunger_colour(hunger.state), RGB::named(rltk::BLACK), "Fainting"); ctx.print_color_right(
(VIEWPORT_W + 1) * TEXT_FONT_MOD,
53,
get_hunger_colour(hunger.state),
RGB::named(rltk::BLACK),
"Fainting"
);
} }
HungerState::Starving => { HungerState::Starving => {
ctx.print_color_right(70, 53, get_hunger_colour(hunger.state), RGB::named(rltk::BLACK), "Starving"); ctx.print_color_right(
(VIEWPORT_W + 1) * TEXT_FONT_MOD,
53,
get_hunger_colour(hunger.state),
RGB::named(rltk::BLACK),
"Starving"
);
} }
} }
// Burden // Burden
if let Some(burden) = burden.get(*player_entity) { if let Some(burden) = burden.get(*player_entity) {
match burden.level { match burden.level {
crate::BurdenLevel::Burdened => { crate::BurdenLevel::Burdened => {
ctx.print_color_right(70, 50, RGB::named(rltk::BROWN1), RGB::named(rltk::BLACK), "Burdened"); ctx.print_color_right(
(VIEWPORT_W + 1) * TEXT_FONT_MOD,
50,
RGB::named(rltk::BROWN1),
RGB::named(rltk::BLACK),
"Burdened"
);
} }
crate::BurdenLevel::Strained => { crate::BurdenLevel::Strained => {
ctx.print_color_right(70, 50, RGB::named(rltk::ORANGE), RGB::named(rltk::BLACK), "Strained"); ctx.print_color_right(
(VIEWPORT_W + 1) * TEXT_FONT_MOD,
50,
RGB::named(rltk::ORANGE),
RGB::named(rltk::BLACK),
"Strained"
);
} }
crate::BurdenLevel::Overloaded => { crate::BurdenLevel::Overloaded => {
ctx.print_color_right(70, 50, RGB::named(rltk::RED), RGB::named(rltk::BLACK), "Overloaded"); ctx.print_color_right(
(VIEWPORT_W + 1) * TEXT_FONT_MOD,
50,
RGB::named(rltk::RED),
RGB::named(rltk::BLACK),
"Overloaded"
);
} }
} }
} }
if stats.god { if stats.god {
ctx.print_color(20, 20, RGB::named(rltk::YELLOW), RGB::named(rltk::BLACK), "--- GODMODE: ON ---"); ctx.print_color(
20 * TEXT_FONT_MOD,
20,
RGB::named(rltk::YELLOW),
RGB::named(rltk::BLACK),
"--- GODMODE: ON ---"
);
} }
// Draw equipment // Draw equipment
let renderables = ecs.read_storage::<Renderable>(); let renderables = ecs.read_storage::<Renderable>();
@ -214,47 +333,96 @@ pub fn draw_ui(ecs: &World, ctx: &mut Rltk) {
} }
let mut y = 1; let mut y = 1;
if !equipment.is_empty() { if !equipment.is_empty() {
ctx.print_color(72, y, RGB::named(rltk::BLACK), RGB::named(rltk::WHITE), "Equipment"); ctx.print_color(
(VIEWPORT_W + 3) * TEXT_FONT_MOD,
y,
RGB::named(rltk::BLACK),
RGB::named(rltk::WHITE),
"Equipment"
);
let mut j = 0; let mut j = 0;
for item in equipment { for item in equipment {
y += 1; y += 1;
ctx.set(72, y, RGB::named(rltk::YELLOW), RGB::named(rltk::BLACK), 97 + (j as rltk::FontCharType)); ctx.set(
(VIEWPORT_W + 3) * TEXT_FONT_MOD,
y,
RGB::named(rltk::YELLOW),
RGB::named(rltk::BLACK),
97 + (j as rltk::FontCharType)
);
j += 1; j += 1;
ctx.set(74, y, item.2, RGB::named(rltk::BLACK), item.3); ctx.set(
ctx.print_color(76, y, item.1, RGB::named(rltk::BLACK), &item.0); (VIEWPORT_W + 3) * TEXT_FONT_MOD + 2,
ctx.print_color(76 + &item.0.len() + 1, y, RGB::named(rltk::WHITE), RGB::named(rltk::BLACK), "(worn)"); y,
item.2,
RGB::named(rltk::BLACK),
item.3
);
ctx.print_color(
(VIEWPORT_W + 3) * TEXT_FONT_MOD + 4,
y,
item.1,
RGB::named(rltk::BLACK),
&item.0
);
ctx.print_color(
(VIEWPORT_W + 3) * TEXT_FONT_MOD + 4 + (item.0.len() as i32) + 1,
y,
RGB::named(rltk::WHITE),
RGB::named(rltk::BLACK),
"(worn)"
);
} }
y += 2; y += 2;
} }
// Draw consumables // Draw consumables
ctx.print_color(72, y, RGB::named(rltk::BLACK), RGB::named(rltk::WHITE), "Backpack");
ctx.print_color( ctx.print_color(
81, (VIEWPORT_W + 3) * TEXT_FONT_MOD,
y,
RGB::named(rltk::BLACK),
RGB::named(rltk::WHITE),
"Backpack"
);
ctx.print_color(
(VIEWPORT_W + 12) * TEXT_FONT_MOD,
y, y,
RGB::named(rltk::WHITE), RGB::named(rltk::WHITE),
RGB::named(rltk::BLACK), RGB::named(rltk::BLACK),
&format!( &format!(
"[{:.1}/{} lbs]", "[{:.1}/{} lbs]",
stats.weight, stats.weight,
(attributes.strength.base + attributes.strength.modifiers) * CARRY_CAPACITY_PER_STRENGTH (attributes.strength.base + attributes.strength.modifiers) *
CARRY_CAPACITY_PER_STRENGTH
) )
); );
y += 1; y += 1;
let player_inventory = get_player_inventory(&ecs); let player_inventory = get_player_inventory(&ecs);
y = print_options(&player_inventory, 72, y, ctx).0; y = print_options(&player_inventory, (VIEWPORT_W + 3) * TEXT_FONT_MOD, y, ctx).0;
// Draw spells - if we have any -- NYI! // Draw spells - if we have any -- NYI!
if let Some(known_spells) = ecs.read_storage::<KnownSpells>().get(*player_entity) { if let Some(known_spells) = ecs.read_storage::<KnownSpells>().get(*player_entity) {
y += 1; y += 1;
// Draw known spells // Draw known spells
ctx.print_color(72, y, RGB::named(BLACK), RGB::named(WHITE), "Known Spells"); ctx.print_color(
(VIEWPORT_W + 3) * TEXT_FONT_MOD,
y,
RGB::named(BLACK),
RGB::named(WHITE),
"Known Spells"
);
y += 1; y += 1;
let mut index = 1; let mut index = 1;
for spell in known_spells.list.iter() { for spell in known_spells.list.iter() {
ctx.print_color(72, y, RGB::named(YELLOW), RGB::named(BLACK), &format!("{}", index));
ctx.print_color( ctx.print_color(
74, (VIEWPORT_W + 3) * TEXT_FONT_MOD,
y,
RGB::named(YELLOW),
RGB::named(BLACK),
&format!("{}", index)
);
ctx.print_color(
(VIEWPORT_W + 3) * TEXT_FONT_MOD + 1,
y, y,
RGB::named(CYAN), RGB::named(CYAN),
RGB::named(BLACK), RGB::named(BLACK),
@ -311,32 +479,101 @@ pub fn draw_ui(ecs: &World, ctx: &mut Rltk) {
if !seen_entities.is_empty() { if !seen_entities.is_empty() {
y += 1; y += 1;
ctx.print_color(72, y, RGB::named(rltk::BLACK), RGB::named(rltk::WHITE), "In View"); ctx.print_color(
(VIEWPORT_W + 3) * TEXT_FONT_MOD,
y,
RGB::named(rltk::BLACK),
RGB::named(rltk::WHITE),
"In View"
);
for entity in seen_entities { for entity in seen_entities {
y += 1; y += 1;
ctx.set(72, y, entity.2, RGB::named(rltk::BLACK), entity.3); ctx.set(
ctx.print_color(74, y, entity.1, RGB::named(rltk::BLACK), entity.0); (VIEWPORT_W + 3) * TEXT_FONT_MOD,
y,
entity.2,
RGB::named(rltk::BLACK),
entity.3
);
ctx.print_color(
(VIEWPORT_W + 3) * TEXT_FONT_MOD + 1,
y,
entity.1,
RGB::named(rltk::BLACK),
entity.0
);
} }
} }
} }
// Render the message log at [1, 7], ascending, with 7 lines and a max width of 68. // Render the message log at [1, 7], ascending, with 7 lines and a max width of 68.
gamelog::print_log(&mut rltk::BACKEND_INTERNAL.lock().consoles[0].console, Point::new(1, 7), false, 7, 68); gamelog::print_log(
&mut rltk::BACKEND_INTERNAL.lock().consoles[1].console,
Point::new(1 * TEXT_FONT_MOD, 7),
false,
7,
(VIEWPORT_W - 1) * TEXT_FONT_MOD
);
// Render id // Render id
let map = ecs.fetch::<Map>(); let map = ecs.fetch::<Map>();
let id = if map.depth > 0 { format!("{}{}", map.short_name, map.depth) } else { format!("{}", map.short_name) }; let id = if map.depth > 0 {
ctx.print_color_right(70, 54, get_local_col(map.id), RGB::named(rltk::BLACK), &id); format!("{}{}", map.short_name, map.depth)
} else {
format!("{}", map.short_name)
};
ctx.print_color_right(
(VIEWPORT_W + 1) * TEXT_FONT_MOD,
54,
get_local_col(map.id),
RGB::named(rltk::BLACK),
&id
);
// Render turn // Render turn
let turns = crate::gamelog::get_event_count(EVENT::COUNT_TURN); let turns = crate::gamelog::get_event_count(EVENT::COUNT_TURN);
ctx.print_color_right(69 - id.len(), 54, RGB::named(rltk::YELLOW), RGB::named(rltk::BLACK), &format!("T{}", turns)); ctx.print_color_right(
VIEWPORT_W * TEXT_FONT_MOD - (id.len() as i32),
54,
RGB::named(rltk::YELLOW),
RGB::named(rltk::BLACK),
&format!("T{}", turns)
);
// Boxes and tooltips last, so they draw over everything else. // Boxes and tooltips last, so they draw over everything else.
ctx.draw_hollow_box(0, 0, 70, 8, RGB::named(rltk::WHITE), RGB::named(rltk::BLACK)); // Log box ctx.draw_hollow_box(
ctx.draw_hollow_box(0, 9, 70, 42, RGB::named(rltk::WHITE), RGB::named(rltk::BLACK)); // Camera box 0 * TEXT_FONT_MOD,
ctx.draw_hollow_box(0, 52, 70, 3, RGB::named(rltk::WHITE), RGB::named(rltk::BLACK)); // Stats box 0,
ctx.draw_hollow_box(71, 0, 33, 55, RGB::named(rltk::WHITE), RGB::named(rltk::BLACK)); // Side box (VIEWPORT_W + 1) * TEXT_FONT_MOD,
8,
RGB::named(rltk::WHITE),
RGB::named(rltk::BLACK)
); // Log box
ctx.draw_hollow_box(
0 * TEXT_FONT_MOD,
9,
(VIEWPORT_W + 1) * TEXT_FONT_MOD,
42,
RGB::named(rltk::WHITE),
RGB::named(rltk::BLACK)
); // Camera box
ctx.draw_hollow_box(
0 * TEXT_FONT_MOD,
52,
(VIEWPORT_W + 1) * TEXT_FONT_MOD,
3,
RGB::named(rltk::WHITE),
RGB::named(rltk::BLACK)
); // Stats box
ctx.draw_hollow_box(
(VIEWPORT_W + 2) * TEXT_FONT_MOD,
0,
33 * TEXT_FONT_MOD,
55,
RGB::named(rltk::WHITE),
RGB::named(rltk::BLACK)
); // Side box
ctx.set_active_console(0);
tooltip::draw_tooltips(ecs, ctx, None); tooltip::draw_tooltips(ecs, ctx, None);
} }
@ -403,7 +640,12 @@ pub enum ItemMenuResult {
Selected, Selected,
} }
pub fn print_options(inventory: &PlayerInventory, mut x: i32, mut y: i32, ctx: &mut Rltk) -> (i32, i32) { pub fn print_options(
inventory: &PlayerInventory,
mut x: i32,
mut y: i32,
ctx: &mut Rltk
) -> (i32, i32) {
let mut j = 0; let mut j = 0;
let initial_x: i32 = x; let initial_x: i32 = x;
let mut width: i32 = -1; let mut width: i32 = -1;
@ -411,10 +653,22 @@ pub fn print_options(inventory: &PlayerInventory, mut x: i32, mut y: i32, ctx: &
x = initial_x; x = initial_x;
// Print the character required to access this item. i.e. (a) // Print the character required to access this item. i.e. (a)
if j < 26 { if j < 26 {
ctx.set(x, y, RGB::named(rltk::YELLOW), RGB::named(rltk::BLACK), 97 + (j as rltk::FontCharType)); ctx.set(
x,
y,
RGB::named(rltk::YELLOW),
RGB::named(rltk::BLACK),
97 + (j as rltk::FontCharType)
);
} else { } else {
// If we somehow have more than 26, start using capitals // If we somehow have more than 26, start using capitals
ctx.set(x, y, RGB::named(rltk::YELLOW), RGB::named(rltk::BLACK), 65 - 26 + (j as rltk::FontCharType)); ctx.set(
x,
y,
RGB::named(rltk::YELLOW),
RGB::named(rltk::BLACK),
65 - 26 + (j as rltk::FontCharType)
);
} }
x += 2; x += 2;
@ -428,7 +682,13 @@ pub fn print_options(inventory: &PlayerInventory, mut x: i32, mut y: i32, ctx: &
// i.e. (a) 3 daggers // i.e. (a) 3 daggers
ctx.print_color(x, y, fg, RGB::named(rltk::BLACK), item_count); ctx.print_color(x, y, fg, RGB::named(rltk::BLACK), item_count);
x += 2; x += 2;
ctx.print_color(x, y, fg, RGB::named(rltk::BLACK), item.display_name.plural.to_string()); ctx.print_color(
x,
y,
fg,
RGB::named(rltk::BLACK),
item.display_name.plural.to_string()
);
let this_width = x - initial_x + (item.display_name.plural.len() as i32); let this_width = x - initial_x + (item.display_name.plural.len() as i32);
width = if width > this_width { width } else { this_width }; width = if width > this_width { width } else { this_width };
} else { } else {
@ -436,7 +696,9 @@ pub fn print_options(inventory: &PlayerInventory, mut x: i32, mut y: i32, ctx: &
ctx.print_color(x, y, fg, RGB::named(rltk::BLACK), "some"); ctx.print_color(x, y, fg, RGB::named(rltk::BLACK), "some");
x += 5; x += 5;
} else if } else if
['a', 'e', 'i', 'o', 'u'].iter().any(|&v| item.display_name.singular.to_lowercase().starts_with(v)) ['a', 'e', 'i', 'o', 'u']
.iter()
.any(|&v| item.display_name.singular.to_lowercase().starts_with(v))
{ {
// If one and starts with a vowel, print 'an' // If one and starts with a vowel, print 'an'
// i.e. (a) an apple // i.e. (a) an apple
@ -448,7 +710,13 @@ pub fn print_options(inventory: &PlayerInventory, mut x: i32, mut y: i32, ctx: &
ctx.print_color(x, y, fg, RGB::named(rltk::BLACK), "a"); ctx.print_color(x, y, fg, RGB::named(rltk::BLACK), "a");
x += 2; x += 2;
} }
ctx.print_color(x, y, fg, RGB::named(rltk::BLACK), item.display_name.singular.to_string()); ctx.print_color(
x,
y,
fg,
RGB::named(rltk::BLACK),
item.display_name.singular.to_string()
);
let this_width = x - initial_x + (item.display_name.singular.len() as i32); let this_width = x - initial_x + (item.display_name.singular.len() as i32);
width = if width > this_width { width } else { this_width }; width = if width > this_width { width } else { this_width };
} }
@ -463,18 +731,20 @@ pub fn print_options(inventory: &PlayerInventory, mut x: i32, mut y: i32, ctx: &
pub fn get_max_inventory_width(inventory: &PlayerInventory) -> i32 { pub fn get_max_inventory_width(inventory: &PlayerInventory) -> i32 {
let mut width: i32 = 0; let mut width: i32 = 0;
for (item, (_e, count)) in inventory { for (item, (_e, count)) in inventory {
let mut this_width = item.display_name.singular.len() as i32; let mut this_width = 4; // The spaces before and after the character to select this item, etc.
// Clean this up. It should use consts.
this_width += 4; // The spaces before and after the character to select this item, etc.
if count <= &1 { if count <= &1 {
this_width += item.display_name.singular.len() as i32;
if item.display_name.singular == item.display_name.plural { if item.display_name.singular == item.display_name.plural {
this_width += 4; // "some".len this_width += 4; // "some".len
} else if ['a', 'e', 'i', 'o', 'u'].iter().any(|&v| item.display_name.singular.starts_with(v)) { } else if
['a', 'e', 'i', 'o', 'u'].iter().any(|&v| item.display_name.singular.starts_with(v))
{
this_width += 2; // "an".len this_width += 2; // "an".len
} else { } else {
this_width += 1; // "a".len this_width += 1; // "a".len
} }
} else { } else {
this_width += item.display_name.plural.len() as i32;
this_width += count.to_string().len() as i32; // i.e. "12".len this_width += count.to_string().len() as i32; // i.e. "12".len
} }
width = if width > this_width { width } else { this_width }; width = if width > this_width { width } else { this_width };
@ -492,7 +762,10 @@ pub fn obfuscate_name(
dm: &MasterDungeonMap, dm: &MasterDungeonMap,
wand: Option<&ReadStorage<Charges>> wand: Option<&ReadStorage<Charges>>
) -> (String, String) { ) -> (String, String) {
let (mut singular, mut plural) = ("nameless item (bug)".to_string(), "nameless items (bug)".to_string()); let (mut singular, mut plural) = (
"nameless item (bug)".to_string(),
"nameless items (bug)".to_string(),
);
if let Some(name) = names.get(item) { if let Some(name) = names.get(item) {
if magic_items.get(item).is_some() { if magic_items.get(item).is_some() {
if dm.identified_items.contains(&name.name) { if dm.identified_items.contains(&name.name) {
@ -510,7 +783,10 @@ pub fn obfuscate_name(
} else if let Some(obfuscated) = obfuscated_names.get(item) { } else if let Some(obfuscated) = obfuscated_names.get(item) {
(singular, plural) = (obfuscated.name.clone(), obfuscated.plural.clone()); (singular, plural) = (obfuscated.name.clone(), obfuscated.plural.clone());
} else { } else {
(singular, plural) = ("unid magic item".to_string(), "unid magic items".to_string()); (singular, plural) = (
"unid magic item".to_string(),
"unid magic items".to_string(),
);
} }
} else { } else {
(singular, plural) = (name.name.clone(), name.plural.clone()); (singular, plural) = (name.name.clone(), name.plural.clone());
@ -534,7 +810,10 @@ pub fn obfuscate_name(
// Outside the ECS // Outside the ECS
pub fn obfuscate_name_ecs(ecs: &World, item: Entity) -> (String, String) { pub fn obfuscate_name_ecs(ecs: &World, item: Entity) -> (String, String) {
let (mut singular, mut plural) = ("nameless item (bug)".to_string(), "nameless items (bug)".to_string()); let (mut singular, mut plural) = (
"nameless item (bug)".to_string(),
"nameless items (bug)".to_string(),
);
if let Some(name) = ecs.read_storage::<Name>().get(item) { if let Some(name) = ecs.read_storage::<Name>().get(item) {
if ecs.read_storage::<MagicItem>().get(item).is_some() { if ecs.read_storage::<MagicItem>().get(item).is_some() {
let dm = ecs.fetch::<MasterDungeonMap>(); let dm = ecs.fetch::<MasterDungeonMap>();
@ -550,7 +829,10 @@ pub fn obfuscate_name_ecs(ecs: &World, item: Entity) -> (String, String) {
} else if let Some(obfuscated) = ecs.read_storage::<ObfuscatedName>().get(item) { } else if let Some(obfuscated) = ecs.read_storage::<ObfuscatedName>().get(item) {
(singular, plural) = (obfuscated.name.clone(), obfuscated.plural.clone()); (singular, plural) = (obfuscated.name.clone(), obfuscated.plural.clone());
} else { } else {
(singular, plural) = ("unid magic item".to_string(), "unid magic items".to_string()); (singular, plural) = (
"unid magic item".to_string(),
"unid magic items".to_string(),
);
} }
} else { } else {
(singular, plural) = (name.name.clone(), name.plural.clone()); (singular, plural) = (name.name.clone(), name.plural.clone());
@ -592,7 +874,11 @@ pub fn unobf_name_ecs(ecs: &World, item: Entity) -> (String, String) {
/// Gets renderable colour as tuple of u8 /// Gets renderable colour as tuple of u8
pub fn renderable_colour(renderables: &ReadStorage<Renderable>, entity: Entity) -> (u8, u8, u8) { pub fn renderable_colour(renderables: &ReadStorage<Renderable>, entity: Entity) -> (u8, u8, u8) {
return if let Some(renderable) = renderables.get(entity) { return if let Some(renderable) = renderables.get(entity) {
((renderable.fg.r * 255.0) as u8, (renderable.fg.g * 255.0) as u8, (renderable.fg.b * 255.0) as u8) (
(renderable.fg.r * 255.0) as u8,
(renderable.fg.g * 255.0) as u8,
(renderable.fg.b * 255.0) as u8,
)
} else { } else {
WHITE WHITE
}; };
@ -601,7 +887,11 @@ pub fn renderable_colour(renderables: &ReadStorage<Renderable>, entity: Entity)
/// Gets renderable colour as tuple of u8 /// Gets renderable colour as tuple of u8
pub fn renderable_colour_ecs(ecs: &World, entity: Entity) -> (u8, u8, u8) { pub fn renderable_colour_ecs(ecs: &World, entity: Entity) -> (u8, u8, u8) {
return if let Some(renderable) = ecs.read_storage::<Renderable>().get(entity) { return if let Some(renderable) = ecs.read_storage::<Renderable>().get(entity) {
((renderable.fg.r * 255.0) as u8, (renderable.fg.g * 255.0) as u8, (renderable.fg.b * 255.0) as u8) (
(renderable.fg.r * 255.0) as u8,
(renderable.fg.g * 255.0) as u8,
(renderable.fg.b * 255.0) as u8,
)
} else { } else {
WHITE WHITE
}; };
@ -660,7 +950,13 @@ pub fn show_help(ctx: &mut Rltk) -> YesNoResult {
let width = 25; let width = 25;
ctx.draw_box(x, y, width, height, RGB::named(rltk::WHITE), RGB::named(rltk::BLACK)); ctx.draw_box(x, y, width, height, RGB::named(rltk::WHITE), RGB::named(rltk::BLACK));
ctx.print_color(x + 3, y, RGB::named(rltk::YELLOW), RGB::named(rltk::BLACK), " Controls "); ctx.print_color(x + 3, y, RGB::named(rltk::YELLOW), RGB::named(rltk::BLACK), " Controls ");
ctx.print_color(x + 3, y + height, RGB::named(rltk::YELLOW), RGB::named(rltk::BLACK), " ESC/? to close "); ctx.print_color(
x + 3,
y + height,
RGB::named(rltk::YELLOW),
RGB::named(rltk::BLACK),
" ESC/? to close "
);
x += 2; x += 2;
y += 2; y += 2;
ctx.print_color(x, y, RGB::named(rltk::GREEN), RGB::named(rltk::BLACK), "MOVE COMMANDS"); ctx.print_color(x, y, RGB::named(rltk::GREEN), RGB::named(rltk::BLACK), "MOVE COMMANDS");
@ -767,10 +1063,12 @@ pub fn get_player_inventory(ecs: &World) -> PlayerInventory {
} }
pub fn show_inventory(gs: &mut State, ctx: &mut Rltk) -> (ItemMenuResult, Option<Entity>) { pub fn show_inventory(gs: &mut State, ctx: &mut Rltk) -> (ItemMenuResult, Option<Entity>) {
ctx.set_active_console(1);
let player_inventory = get_player_inventory(&gs.ecs); let player_inventory = get_player_inventory(&gs.ecs);
let count = player_inventory.len(); let count = player_inventory.len();
let (x_offset, y_offset) = (1, 10); let (x_offset, y_offset) = (1 * TEXT_FONT_MOD, 10);
let on_overmap = gs.ecs.fetch::<Map>().overmap; let on_overmap = gs.ecs.fetch::<Map>().overmap;
let message = if !on_overmap { let message = if !on_overmap {
@ -779,14 +1077,29 @@ pub fn show_inventory(gs: &mut State, ctx: &mut Rltk) -> (ItemMenuResult, Option
"You can't use items on the overmap [Esc.]" "You can't use items on the overmap [Esc.]"
}; };
ctx.print_color(1 + x_offset, 1 + y_offset, RGB::named(rltk::WHITE), RGB::named(rltk::BLACK), message); ctx.print_color(
1 + x_offset,
1 + y_offset,
RGB::named(rltk::WHITE),
RGB::named(rltk::BLACK),
message
);
let x = 1 + x_offset; let x = 1 + x_offset;
let y = 3 + y_offset; let y = 3 + y_offset;
let width = get_max_inventory_width(&player_inventory); let width = get_max_inventory_width(&player_inventory);
ctx.draw_box(x, y, width + 2, (count + 1) as i32, RGB::named(rltk::WHITE), RGB::named(rltk::BLACK)); ctx.draw_box(
x,
y,
width + 2,
(count + 1) as i32,
RGB::named(rltk::WHITE),
RGB::named(rltk::BLACK)
);
print_options(&player_inventory, x + 1, y + 1, ctx); print_options(&player_inventory, x + 1, y + 1, ctx);
ctx.set_active_console(0);
match ctx.key { match ctx.key {
None => (ItemMenuResult::NoResponse, None), None => (ItemMenuResult::NoResponse, None),
Some(key) => Some(key) =>
@ -796,7 +1109,10 @@ pub fn show_inventory(gs: &mut State, ctx: &mut Rltk) -> (ItemMenuResult, Option
let selection = letter_to_option::letter_to_option(key, ctx.shift); let selection = letter_to_option::letter_to_option(key, ctx.shift);
if selection > -1 && selection < (count as i32) { if selection > -1 && selection < (count as i32) {
if on_overmap { if on_overmap {
gamelog::Logger::new().append("You can't use items on the overmap.").log(); gamelog::Logger
::new()
.append("You can't use items on the overmap.")
.log();
} else { } else {
return ( return (
ItemMenuResult::Selected, ItemMenuResult::Selected,
@ -822,14 +1138,31 @@ pub fn drop_item_menu(gs: &mut State, ctx: &mut Rltk) -> (ItemMenuResult, Option
let (x_offset, y_offset) = (1, 10); let (x_offset, y_offset) = (1, 10);
let on_overmap = gs.ecs.fetch::<Map>().overmap; let on_overmap = gs.ecs.fetch::<Map>().overmap;
let message = if !on_overmap { "Drop what? [aA-zZ][Esc.]" } else { "You can't drop items on the overmap [Esc.]" }; let message = if !on_overmap {
"Drop what? [aA-zZ][Esc.]"
} else {
"You can't drop items on the overmap [Esc.]"
};
ctx.print_color(1 + x_offset, 1 + y_offset, RGB::named(rltk::WHITE), RGB::named(rltk::BLACK), message); ctx.print_color(
1 + x_offset,
1 + y_offset,
RGB::named(rltk::WHITE),
RGB::named(rltk::BLACK),
message
);
let x = 1 + x_offset; let x = 1 + x_offset;
let y = 3 + y_offset; let y = 3 + y_offset;
let width = get_max_inventory_width(&player_inventory); let width = get_max_inventory_width(&player_inventory);
ctx.draw_box(x, y, width + 2, (count + 1) as i32, RGB::named(rltk::WHITE), RGB::named(rltk::BLACK)); ctx.draw_box(
x,
y,
width + 2,
(count + 1) as i32,
RGB::named(rltk::WHITE),
RGB::named(rltk::BLACK)
);
print_options(&player_inventory, x + 1, y + 1, ctx); print_options(&player_inventory, x + 1, y + 1, ctx);
match ctx.key { match ctx.key {
@ -841,7 +1174,10 @@ pub fn drop_item_menu(gs: &mut State, ctx: &mut Rltk) -> (ItemMenuResult, Option
let selection = rltk::letter_to_option(key); let selection = rltk::letter_to_option(key);
if selection > -1 && selection < (count as i32) { if selection > -1 && selection < (count as i32) {
if on_overmap { if on_overmap {
gamelog::Logger::new().append("You can't drop items on the overmap.").log(); gamelog::Logger
::new()
.append("You can't drop items on the overmap.")
.log();
} else { } else {
return ( return (
ItemMenuResult::Selected, ItemMenuResult::Selected,
@ -879,7 +1215,9 @@ pub fn remove_item_menu(gs: &mut State, ctx: &mut Rltk) -> (ItemMenuResult, Opti
let mut equippable: Vec<(Entity, String)> = Vec::new(); let mut equippable: Vec<(Entity, String)> = Vec::new();
let mut width = 2; let mut width = 2;
for (entity, _pack) in (&entities, &backpack).join().filter(|item| item.1.owner == *player_entity) { for (entity, _pack) in (&entities, &backpack)
.join()
.filter(|item| item.1.owner == *player_entity) {
let this_name = &obfuscate_name_ecs(&gs.ecs, entity).0; let this_name = &obfuscate_name_ecs(&gs.ecs, entity).0;
let this_width = 5 + this_name.len(); let this_width = 5 + this_name.len();
width = if width > this_width { width } else { this_width }; width = if width > this_width { width } else { this_width };
@ -900,7 +1238,13 @@ pub fn remove_item_menu(gs: &mut State, ctx: &mut Rltk) -> (ItemMenuResult, Opti
} else { } else {
(RGB::named(rltk::WHITE), rltk::to_cp437('-')) (RGB::named(rltk::WHITE), rltk::to_cp437('-'))
}; };
ctx.set(x + 1, y, RGB::named(rltk::YELLOW), RGB::named(rltk::BLACK), 97 + (j as rltk::FontCharType)); ctx.set(
x + 1,
y,
RGB::named(rltk::YELLOW),
RGB::named(rltk::BLACK),
97 + (j as rltk::FontCharType)
);
ctx.set(x + 3, y, fg, RGB::named(rltk::BLACK), glyph); ctx.set(x + 3, y, fg, RGB::named(rltk::BLACK), glyph);
fg = RGB::named(item_colour_ecs(&gs.ecs, *e)); fg = RGB::named(item_colour_ecs(&gs.ecs, *e));
ctx.print_color(x + 5, y, fg, RGB::named(rltk::BLACK), name); ctx.print_color(x + 5, y, fg, RGB::named(rltk::BLACK), name);
@ -965,7 +1309,12 @@ pub fn ranged_target(
if distance <= (range as f32) { if distance <= (range as f32) {
let screen_x = idx.x - min_x; let screen_x = idx.x - min_x;
let screen_y = idx.y - min_y; let screen_y = idx.y - min_y;
if screen_x > 1 && screen_x < max_x - min_x - 1 && screen_y > 1 && screen_y < max_y - min_y - 1 { if
screen_x > 1 &&
screen_x < max_x - min_x - 1 &&
screen_y > 1 &&
screen_y < max_y - min_y - 1
{
ctx.set_bg(screen_x + x_offset, screen_y + y_offset, TARGETING_VALID_COL); ctx.set_bg(screen_x + x_offset, screen_y + y_offset, TARGETING_VALID_COL);
available_cells.push(idx); available_cells.push(idx);
} }
@ -977,8 +1326,11 @@ pub fn ranged_target(
// Draw mouse cursor // Draw mouse cursor
let mouse_pos = (x, y); let mouse_pos = (x, y);
let (min_x, _max_x, min_y, _max_y, x_offset, y_offset) = camera::get_screen_bounds(&gs.ecs, ctx); let (min_x, _max_x, min_y, _max_y, x_offset, y_offset) = camera::get_screen_bounds(
let (screen_x, screen_y) = (69, 41); &gs.ecs,
ctx
);
let (screen_x, screen_y) = (40, 30);
let x = x.clamp(x_offset, x_offset - 1 + (screen_x as i32)); let x = x.clamp(x_offset, x_offset - 1 + (screen_x as i32));
let y = y.clamp(y_offset, y_offset - 1 + (screen_y as i32)); let y = y.clamp(y_offset, y_offset - 1 + (screen_y as i32));
@ -1019,7 +1371,9 @@ pub fn ranged_target(
aoe, aoe,
&*map &*map
); );
blast_tiles.retain(|p| p.x > 0 && p.x < map.width - 1 && p.y > 0 && p.y < map.height - 1); blast_tiles.retain(
|p| p.x > 0 && p.x < map.width - 1 && p.y > 0 && p.y < map.height - 1
);
for tile in blast_tiles.iter() { for tile in blast_tiles.iter() {
let bg = if available_cells.contains(&tile) { let bg = if available_cells.contains(&tile) {
let col1 = TARGETING_AOE_COL; let col1 = TARGETING_AOE_COL;
@ -1040,7 +1394,10 @@ pub fn ranged_target(
Some(key) => Some(key) =>
match key { match key {
VirtualKeyCode::Return => { VirtualKeyCode::Return => {
return (TargetResult::Selected, Some(Point::new(mouse_pos_adjusted.0, mouse_pos_adjusted.1))); return (
TargetResult::Selected,
Some(Point::new(mouse_pos_adjusted.0, mouse_pos_adjusted.1)),
);
} }
_ => result, _ => result,
} }
@ -1106,10 +1463,22 @@ pub fn main_menu(gs: &mut State, ctx: &mut Rltk) -> MainMenuResult {
if save_exists { if save_exists {
if selection == MainMenuSelection::LoadGame { if selection == MainMenuSelection::LoadGame {
ctx.print_color(x + 2, y, RGB::named(rltk::YELLOW), RGB::named(rltk::BLACK), "["); ctx.print_color(x + 2, y, RGB::named(rltk::YELLOW), RGB::named(rltk::BLACK), "[");
ctx.print_color(x + 3, y, RGB::named(rltk::GREEN), RGB::named(rltk::BLACK), "continue"); ctx.print_color(
x + 3,
y,
RGB::named(rltk::GREEN),
RGB::named(rltk::BLACK),
"continue"
);
ctx.print_color(x + 11, y, RGB::named(rltk::YELLOW), RGB::named(rltk::BLACK), "]"); ctx.print_color(x + 11, y, RGB::named(rltk::YELLOW), RGB::named(rltk::BLACK), "]");
} else { } else {
ctx.print_color(x + 3, y, RGB::named(rltk::WHITE), RGB::named(rltk::BLACK), "continue"); ctx.print_color(
x + 3,
y,
RGB::named(rltk::WHITE),
RGB::named(rltk::BLACK),
"continue"
);
} }
y += 1; y += 1;
} }
@ -1142,7 +1511,9 @@ pub fn main_menu(gs: &mut State, ctx: &mut Rltk) -> MainMenuResult {
return MainMenuResult::NoSelection { selected: MainMenuSelection::NewGame }; return MainMenuResult::NoSelection { selected: MainMenuSelection::NewGame };
} }
VirtualKeyCode::L => { VirtualKeyCode::L => {
return MainMenuResult::NoSelection { selected: MainMenuSelection::LoadGame }; return MainMenuResult::NoSelection {
selected: MainMenuSelection::LoadGame,
};
} }
VirtualKeyCode::Up | VirtualKeyCode::Numpad8 | VirtualKeyCode::K => { VirtualKeyCode::Up | VirtualKeyCode::Numpad8 | VirtualKeyCode::K => {
let mut new_selection; let mut new_selection;
@ -1223,7 +1594,13 @@ pub fn game_over(ctx: &mut Rltk) -> YesNoResult {
format!("You survived for {} turns.", crate::gamelog::get_event_count(EVENT::COUNT_TURN)) format!("You survived for {} turns.", crate::gamelog::get_event_count(EVENT::COUNT_TURN))
); );
y += 2; y += 2;
ctx.print_color(x, y, RGB::named(rltk::GREEN), RGB::named(rltk::BLACK), format!("And in the process, you")); ctx.print_color(
x,
y,
RGB::named(rltk::GREEN),
RGB::named(rltk::BLACK),
format!("And in the process, you")
);
y += 1; y += 1;
if crate::gamelog::get_event_count(EVENT::COUNT_CHANGED_FLOOR) > 0 { if crate::gamelog::get_event_count(EVENT::COUNT_CHANGED_FLOOR) > 0 {
ctx.print_color( ctx.print_color(
@ -1231,7 +1608,10 @@ pub fn game_over(ctx: &mut Rltk) -> YesNoResult {
y, y,
RGB::named(rltk::WHITE), RGB::named(rltk::WHITE),
RGB::named(rltk::BLACK), RGB::named(rltk::BLACK),
format!("- changed floor {} times", crate::gamelog::get_event_count(EVENT::COUNT_CHANGED_FLOOR)) format!(
"- changed floor {} times",
crate::gamelog::get_event_count(EVENT::COUNT_CHANGED_FLOOR)
)
); );
y += 1; y += 1;
} }
@ -1255,7 +1635,10 @@ pub fn game_over(ctx: &mut Rltk) -> YesNoResult {
y, y,
RGB::named(rltk::WHITE), RGB::named(rltk::WHITE),
RGB::named(rltk::BLACK), RGB::named(rltk::BLACK),
format!("- slew {} other creature(s)", crate::gamelog::get_event_count(EVENT::COUNT_KILLED)) format!(
"- slew {} other creature(s)",
crate::gamelog::get_event_count(EVENT::COUNT_KILLED)
)
); );
y += 1; y += 1;
} }
@ -1265,7 +1648,10 @@ pub fn game_over(ctx: &mut Rltk) -> YesNoResult {
y, y,
RGB::named(rltk::WHITE), RGB::named(rltk::WHITE),
RGB::named(rltk::BLACK), RGB::named(rltk::BLACK),
format!("- forgot the controls {} time(s)", crate::gamelog::get_event_count(EVENT::COUNT_LOOKED_FOR_HELP)) format!(
"- forgot the controls {} time(s)",
crate::gamelog::get_event_count(EVENT::COUNT_LOOKED_FOR_HELP)
)
); );
} }

View file

@ -3,22 +3,28 @@ use specs::prelude::*;
use specs::saveload::{ SimpleMarker, SimpleMarkerAllocator }; use specs::saveload::{ SimpleMarker, SimpleMarkerAllocator };
use rltk::prelude::*; use rltk::prelude::*;
const DISPLAYWIDTH: i32 = 105; const DISPLAYWIDTH: i32 = 72;
const DISPLAYHEIGHT: i32 = 56; const DISPLAYHEIGHT: i32 = 56;
fn main() -> rltk::BError { fn main() -> rltk::BError {
// Embedded resources for use in wasm build // Embedded resources for use in wasm build
const CURSES_14_16_BYTES: &[u8] = include_bytes!("../resources/curses14x16.png"); const CURSES_16_16_BYTES: &[u8] = include_bytes!("../resources/nagidal24x24.png");
rltk::embedding::EMBED.lock().add_resource("resources/curses14x16.png".to_string(), CURSES_14_16_BYTES); const ISHMERIA_8_16_BYTES: &[u8] = include_bytes!("../resources/curses12x24.png");
rltk::embedding::EMBED
//rltk::link_resource!(CURSES14X16, "../resources/curses_14x16.png"); .lock()
.add_resource("resources/nagidal24x24.png".to_string(), CURSES_16_16_BYTES);
rltk::embedding::EMBED
.lock()
.add_resource("resources/curses12x24.png".to_string(), ISHMERIA_8_16_BYTES);
let mut context = RltkBuilder::new() let mut context = RltkBuilder::new()
.with_title("rust-rl") .with_title("rust-rl")
.with_dimensions(DISPLAYWIDTH, DISPLAYHEIGHT) .with_dimensions(DISPLAYWIDTH, DISPLAYHEIGHT)
.with_font("curses14x16.png", 14, 16) .with_font("nagidal24x24.png", 24, 24)
.with_tile_dimensions(14, 16) .with_font("curses12x24.png", 12, 24)
.with_simple_console(DISPLAYWIDTH, DISPLAYHEIGHT, "curses14x16.png") .with_tile_dimensions(24, 24)
.with_simple_console(DISPLAYWIDTH, DISPLAYHEIGHT, "nagidal24x24.png")
.with_sparse_console(DISPLAYWIDTH * 2, DISPLAYHEIGHT, "curses12x24.png")
.build()?; .build()?;
if config::CONFIG.visuals.with_scanlines { if config::CONFIG.visuals.with_scanlines {
context.with_post_scanlines(config::CONFIG.visuals.with_screen_burn); context.with_post_scanlines(config::CONFIG.visuals.with_screen_burn);
@ -26,7 +32,9 @@ fn main() -> rltk::BError {
let mut gs = State { let mut gs = State {
ecs: World::new(), ecs: World::new(),
mapgen_next_state: Some(RunState::MainMenu { menu_selection: gui::MainMenuSelection::NewGame }), mapgen_next_state: Some(RunState::MainMenu {
menu_selection: gui::MainMenuSelection::NewGame,
}),
mapgen_index: 0, mapgen_index: 0,
mapgen_history: Vec::new(), mapgen_history: Vec::new(),
mapgen_timer: 0.0, mapgen_timer: 0.0,

View file

@ -164,6 +164,9 @@ impl GameState for State {
new_runstate = *runstate; new_runstate = *runstate;
} }
// Clear screen // Clear screen
ctx.set_active_console(1);
ctx.cls();
ctx.set_active_console(0);
ctx.cls(); ctx.cls();
particle_system::particle_ticker(&mut self.ecs, ctx); particle_system::particle_ticker(&mut self.ecs, ctx);
@ -559,6 +562,9 @@ impl GameState for State {
new_runstate = self.mapgen_next_state.unwrap(); new_runstate = self.mapgen_next_state.unwrap();
} }
if self.mapgen_history.len() != 0 { if self.mapgen_history.len() != 0 {
ctx.set_active_console(1);
ctx.cls();
ctx.set_active_console(0);
ctx.cls(); ctx.cls();
camera::render_debug_map(&self.mapgen_history[self.mapgen_index], ctx); camera::render_debug_map(&self.mapgen_history[self.mapgen_index], ctx);