draw_charcreation()

This commit is contained in:
Llywelwyn 2023-09-30 06:30:48 +01:00
parent ec8793180d
commit f4d4b414d5
5 changed files with 2983 additions and 1826 deletions

File diff suppressed because it is too large Load diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 38 KiB

Before After
Before After

View file

@ -30,7 +30,7 @@ use specs::prelude::*;
use std::collections::HashMap; use std::collections::HashMap;
use crate::consts::prelude::*; use crate::consts::prelude::*;
#[derive(Serialize, Deserialize, Copy, Clone, PartialEq)] #[derive(Serialize, Deserialize, Copy, Clone, PartialEq, Eq, Hash)]
pub enum Ancestry { pub enum Ancestry {
Unset, Unset,
Human, Human,
@ -40,7 +40,7 @@ pub enum Ancestry {
Catfolk, Catfolk,
} }
#[derive(Serialize, Deserialize, Copy, Clone, PartialEq)] #[derive(Serialize, Deserialize, Copy, Clone, PartialEq, Eq, Hash)]
pub enum Class { pub enum Class {
Unset, Unset,
Fighter, Fighter,
@ -50,48 +50,53 @@ pub enum Class {
} }
lazy_static! { lazy_static! {
static ref ANCESTRY_CLASS_DATA: HashMap<String, Vec<String>> = { static ref ANCESTRYDATA: HashMap<Ancestry, Vec<String>> = {
let mut m = HashMap::new(); let mut m = HashMap::new();
// Ancestry
m.insert( m.insert(
"human".to_string(), Ancestry::Human,
vec![ vec![
"nothing".to_string()]); "nothing".to_string()]);
m.insert( m.insert(
"dwarf".to_string(), Ancestry::Dwarf,
vec![ vec![
"a natural bonus to defence".to_string()]); "a natural bonus to defence".to_string()]);
m.insert( m.insert(
"elf".to_string(), Ancestry::Elf,
vec![ vec![
"minor telepathy".to_string(), "minor telepathy".to_string(),
"a slightly increased speed".to_string()]); "a slightly increased speed".to_string()]);
m.insert( m.insert(
"catfolk".to_string(), Ancestry::Catfolk,
vec![ vec![
"increased speed".to_string(), "increased speed".to_string(),
"increased unarmed damage".to_string()]); "increased unarmed damage".to_string()]);
// Class return m;
};
}
lazy_static! {
static ref CLASSDATA: HashMap<Class, Vec<String>> = {
let mut m = HashMap::new();
m.insert( m.insert(
"fighter".to_string(), Class::Fighter,
vec![ vec![
format!("a longsword, ring mail, and {} food", FIGHTER_STARTING_FOOD), format!("a longsword, ring mail, and {} food", FIGHTER_STARTING_FOOD),
"10 str, 8 dex, 10 con, 6 int, 6 wis, 8 cha".to_string(), "10 str, 8 dex, 10 con, 6 int, 6 wis, 8 cha".to_string(),
"and 27 random stat points".to_string()]); "and 27 random stat points".to_string()]);
m.insert( m.insert(
"rogue".to_string(), Class::Rogue,
vec![ vec![
format!("a rapier, leather armour, and {} food", ROGUE_STARTING_FOOD), format!("a rapier, leather armour, and {} food", ROGUE_STARTING_FOOD),
"8 str, 10 dex, 8 con, 6 int, 8 wis, 10 cha".to_string(), "8 str, 10 dex, 8 con, 6 int, 8 wis, 10 cha".to_string(),
"and 35 random stat points".to_string()]); "and 35 random stat points".to_string()]);
m.insert( m.insert(
"wizard".to_string(), Class::Wizard,
vec![ vec![
format!("a dagger, random scrolls/potions, and {} food", WIZARD_STARTING_FOOD), format!("a dagger, random scrolls/potions, and {} food", WIZARD_STARTING_FOOD),
"6 str, 8 dex, 6 con, 10 int, 10 wis, 8 cha".to_string(), "6 str, 8 dex, 6 con, 10 int, 10 wis, 8 cha".to_string(),
"and 17 random stat points".to_string()]); "and 17 random stat points".to_string()]);
m.insert( m.insert(
"villager".to_string(), Class::Villager,
vec![ vec![
format!("the first weapon you could find, and {} food", VILLAGER_STARTING_FOOD), format!("the first weapon you could find, and {} food", VILLAGER_STARTING_FOOD),
"6 str, 6 dex, 6 con, 6 int, 6 wis, 6 cha".to_string(), "6 str, 6 dex, 6 con, 6 int, 6 wis, 6 cha".to_string(),
@ -112,6 +117,78 @@ 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;
pub fn draw_charcreation(
ecs: &World,
draw: &mut Draw,
atlas: &HashMap<String, Texture>,
font: &Font
) {
let runstate = ecs.read_resource::<RunState>();
let (class, ancestry) = match *runstate {
RunState::CharacterCreation { class, ancestry } => (class, ancestry),
_ => unreachable!("draw_charcreation() called outside of CharacterCreation runstate."),
};
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?")
.size(FONTSIZE * 2.0)
.position(x, y)
.h_align_left();
y = draw.last_text_bounds().max_y();
let initial_y = y;
let ancestries = [
("h. Human", Ancestry::Human),
("e. Elf", Ancestry::Elf),
("d. Dwarf", Ancestry::Dwarf),
("c. Catfolk", Ancestry::Catfolk),
];
for (k, v) in &ancestries {
draw.text(font, k)
.size(FONTSIZE)
.position(x, y)
.h_align_left()
.color(get_colour(ancestry, *v));
y = draw.last_text_bounds().max_y();
}
y = initial_y;
x += COLUMN_WIDTH;
let classes = [
("f. Fighter", Class::Fighter),
("r. Rogue", Class::Rogue),
("w. Wizard", Class::Wizard),
("v. Villager", Class::Villager),
];
for (k, v) in &classes {
draw.text(font, k)
.size(FONTSIZE)
.position(x, y)
.h_align_left()
.color(get_colour(class, *v));
y = draw.last_text_bounds().max_y();
}
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();
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();
y = draw.last_text_bounds().max_y();
}
}
fn get_colour<T>(selected: T, desired: T) -> Color where T: PartialEq {
if selected == desired { Color::from_rgb(0.0, 1.0, 0.0) } else { Color::WHITE }
}
/// Handles the player character creation screen. /// Handles the player character creation screen.
pub fn character_creation(gs: &mut State, ctx: &mut BTerm) -> CharCreateResult { pub fn character_creation(gs: &mut State, ctx: &mut BTerm) -> CharCreateResult {
ctx.set_active_console(TEXT_LAYER); ctx.set_active_console(TEXT_LAYER);
@ -195,7 +272,7 @@ pub fn character_creation(gs: &mut State, ctx: &mut BTerm) -> CharCreateResult {
// Selected ancestry/class benefits // Selected ancestry/class benefits
x += column_width; x += column_width;
ctx.print_color(x, y, selected_fg, bg, ANCESTRY_INFO_HEADER); ctx.print_color(x, y, selected_fg, bg, ANCESTRY_INFO_HEADER);
for line in ANCESTRY_CLASS_DATA.get(race_str).unwrap().iter() { /*for line in ANCESTRY_CLASS_DATA.get(race_str).unwrap().iter() {
y += 1; y += 1;
ctx.print_color(x + 1, y, unselected_fg, bg, line); ctx.print_color(x + 1, y, unselected_fg, bg, line);
} }
@ -204,7 +281,7 @@ pub fn character_creation(gs: &mut State, ctx: &mut BTerm) -> CharCreateResult {
for line in ANCESTRY_CLASS_DATA.get(class_str).unwrap().iter() { for line in ANCESTRY_CLASS_DATA.get(class_str).unwrap().iter() {
y += 1; y += 1;
ctx.print_color(x + 1, y, unselected_fg, bg, line); ctx.print_color(x + 1, y, unselected_fg, bg, line);
} }*/
match ctx.key { match ctx.key {
None => { None => {

View file

@ -14,7 +14,7 @@ pub fn draw_mainmenu(ecs: &World, draw: &mut Draw, atlas: &HashMap<String, Textu
let save_exists = crate::saveload_system::does_save_exist(); let save_exists = crate::saveload_system::does_save_exist();
const MID_X: f32 = ((DISPLAYWIDTH as f32) * TILESIZE) / 2.0; const MID_X: f32 = ((DISPLAYWIDTH as f32) * TILESIZE) / 2.0;
let (x, mut y) = (MID_X, ((DISPLAYHEIGHT as f32) * TILESIZE) / 3.0); let (x, mut y) = (MID_X, ((DISPLAYHEIGHT as f32) * TILESIZE) / 4.0);
draw.text(font, "RUST-RL") draw.text(font, "RUST-RL")
.size(FONTSIZE * 2.0) .size(FONTSIZE * 2.0)
.position(x, y) .position(x, y)

View file

@ -496,7 +496,7 @@ fn draw(_app: &mut App, gfx: &mut Graphics, gs: &mut State) {
gui::draw_mainmenu(&gs.ecs, &mut draw, &gs.atlas, &gs.font); gui::draw_mainmenu(&gs.ecs, &mut draw, &gs.atlas, &gs.font);
} }
RunState::CharacterCreation { .. } => { RunState::CharacterCreation { .. } => {
// Draw character creation gui::draw_charcreation(&gs.ecs, &mut draw, &gs.atlas, &gs.font);
} }
RunState::PreRun { .. } => {} RunState::PreRun { .. } => {}
RunState::MapGeneration => { RunState::MapGeneration => {