charcreation runstate

This commit is contained in:
Llywelwyn 2023-09-30 06:40:35 +01:00
parent f4d4b414d5
commit c80cb01816
4 changed files with 1873 additions and 3025 deletions

File diff suppressed because it is too large Load diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

After

Width:  |  Height:  |  Size: 27 KiB

Before After
Before After

View file

@ -190,144 +190,51 @@ fn get_colour<T>(selected: T, desired: T) -> Color where T: PartialEq {
}
/// Handles the player character creation screen.
pub fn character_creation(gs: &mut State, ctx: &mut BTerm) -> CharCreateResult {
ctx.set_active_console(TEXT_LAYER);
pub fn character_creation(gs: &mut State, ctx: &mut App) -> CharCreateResult {
let runstate = gs.ecs.fetch::<RunState>();
let (ancestry, class) = match *runstate {
RunState::CharacterCreation { ancestry, class } => (ancestry, class),
_ => unreachable!("character_creation() called outside of CharacterCreation runstate."),
};
let mut x = 2;
let mut y = 11;
let column_width = 20;
ctx.print_color(x, y, RGB::named(WHITE), RGB::named(BLACK), CHAR_CREATE_HEADER);
y += 2;
if let RunState::CharacterCreation { ancestry, class } = *runstate {
let selected_fg = RGB::named(GREEN);
let unselected_fg = RGB::named(WHITE);
let mut fg;
let bg = RGB::named(BLACK);
// Ancestry
ctx.print_color(x, y, bg, unselected_fg, "Ancestry");
ctx.print_color(x + column_width, y, bg, unselected_fg, "Class");
y += 1;
let mut race_str = "human";
if ancestry == Ancestry::Human {
fg = selected_fg;
} else {
fg = unselected_fg;
}
ctx.print_color(x, y, fg, bg, "h. Human");
if ancestry == Ancestry::Elf {
fg = selected_fg;
race_str = "elf";
} else {
fg = unselected_fg;
}
ctx.print_color(x, y + 1, fg, bg, "e. Elf");
if ancestry == Ancestry::Dwarf {
fg = selected_fg;
race_str = "dwarf";
} else {
fg = unselected_fg;
}
ctx.print_color(x, y + 2, fg, bg, "d. Dwarf");
if ancestry == Ancestry::Catfolk {
fg = selected_fg;
race_str = "catfolk";
} else {
fg = unselected_fg;
}
ctx.print_color(x, y + 3, fg, bg, "c. Catfolk");
// Class
let mut class_str = "fighter";
x += column_width;
if class == Class::Fighter {
fg = selected_fg;
} else {
fg = unselected_fg;
}
ctx.print_color(x, y, fg, bg, "f. Fighter");
if class == Class::Rogue {
fg = selected_fg;
class_str = "rogue";
} else {
fg = unselected_fg;
}
ctx.print_color(x, y + 1, fg, bg, "r. Rogue");
if class == Class::Wizard {
fg = selected_fg;
class_str = "wizard";
} else {
fg = unselected_fg;
}
ctx.print_color(x, y + 2, fg, bg, "w. Wizard");
if class == Class::Villager {
fg = selected_fg;
class_str = "villager";
} else {
fg = unselected_fg;
}
ctx.print_color(x, y + 3, fg, bg, "v. Villager");
// Selected ancestry/class benefits
x += column_width;
ctx.print_color(x, y, selected_fg, bg, ANCESTRY_INFO_HEADER);
/*for line in ANCESTRY_CLASS_DATA.get(race_str).unwrap().iter() {
y += 1;
ctx.print_color(x + 1, y, unselected_fg, bg, line);
}
y += 2;
ctx.print_color(x, y, selected_fg, bg, CLASS_INFO_HEADER);
for line in ANCESTRY_CLASS_DATA.get(class_str).unwrap().iter() {
y += 1;
ctx.print_color(x + 1, y, unselected_fg, bg, line);
}*/
match ctx.key {
None => {
return CharCreateResult::NoSelection { ancestry, class };
}
Some(key) =>
match key {
VirtualKeyCode::Escape => {
let key = &ctx.keyboard;
for keycode in key.pressed.iter() {
match *keycode {
KeyCode::Escape => {
return CharCreateResult::Selected { ancestry: Ancestry::Unset, class };
}
VirtualKeyCode::Return => {
KeyCode::Return => {
return CharCreateResult::Selected { ancestry, class };
}
VirtualKeyCode::H => {
KeyCode::H => {
return CharCreateResult::NoSelection { ancestry: Ancestry::Human, class };
}
VirtualKeyCode::E => {
KeyCode::E => {
return CharCreateResult::NoSelection { ancestry: Ancestry::Elf, class };
}
VirtualKeyCode::D => {
KeyCode::D => {
return CharCreateResult::NoSelection { ancestry: Ancestry::Dwarf, class };
}
VirtualKeyCode::C => {
KeyCode::C => {
return CharCreateResult::NoSelection { ancestry: Ancestry::Catfolk, class };
}
VirtualKeyCode::F => {
KeyCode::F => {
return CharCreateResult::NoSelection { ancestry, class: Class::Fighter };
}
VirtualKeyCode::R => {
KeyCode::R => {
return CharCreateResult::NoSelection { ancestry, class: Class::Rogue };
}
VirtualKeyCode::W => {
KeyCode::W => {
return CharCreateResult::NoSelection { ancestry, class: Class::Wizard };
}
VirtualKeyCode::V => {
KeyCode::V => {
return CharCreateResult::NoSelection { ancestry, class: Class::Villager };
}
_ => {
_ => {}
};
}
return CharCreateResult::NoSelection { ancestry, class };
}
}
}
}
ctx.set_active_console(TILE_LAYER);
return CharCreateResult::NoSelection { ancestry: Ancestry::Human, class: Class::Fighter };
}
/// Handles player ancestry setup.
pub fn setup_player_ancestry(ecs: &mut World, ancestry: Ancestry) {

View file

@ -307,7 +307,25 @@ impl State {
}
}
}
// RunState::CharacterCreation
RunState::CharacterCreation { .. } => {
let result = gui::character_creation(self, ctx);
match result {
gui::CharCreateResult::NoSelection { ancestry, class } => {
new_runstate = RunState::CharacterCreation { ancestry, class };
}
gui::CharCreateResult::Selected { ancestry, class } => {
if ancestry == gui::Ancestry::Unset {
new_runstate = RunState::MainMenu {
menu_selection: gui::MainMenuSelection::NewGame,
};
} else {
gui::setup_player_ancestry(&mut self.ecs, ancestry);
gui::setup_player_class(&mut self.ecs, class, ancestry);
new_runstate = RunState::PreRun;
}
}
}
}
RunState::SaveGame => {
saveload_system::save_game(&mut self.ecs);
new_runstate = RunState::MainMenu {
@ -720,7 +738,10 @@ impl State {
}
}
RunState::CharacterCreation { .. } => {
let result = gui::character_creation(self, ctx);
let result = gui::CharCreateResult::NoSelection {
ancestry: gui::Ancestry::Human,
class: gui::Class::Fighter,
}; //gui::character_creation(self, ctx);
match result {
gui::CharCreateResult::NoSelection { ancestry, class } => {
new_runstate = RunState::CharacterCreation { ancestry, class };