diff --git a/src/gui/cheat_menu.rs b/src/gui/cheat_menu.rs new file mode 100644 index 0000000..1d4e50b --- /dev/null +++ b/src/gui/cheat_menu.rs @@ -0,0 +1,45 @@ +use super::State; +use rltk::prelude::*; + +#[derive(PartialEq, Copy, Clone)] +pub enum CheatMenuResult { + NoResponse, + Cancel, + Ascend, + Descend, +} + +pub fn show_cheat_menu(_gs: &mut State, ctx: &mut Rltk) -> CheatMenuResult { + let (x_offset, y_offset) = (1, 10); + ctx.print_color( + 1 + x_offset, + 1 + y_offset, + RGB::named(rltk::RED), + RGB::named(rltk::BLACK), + "DEBUG MENU! [aA-zZ][Esc.]", + ); + let x = 1 + x_offset; + let mut y = 3 + y_offset; + let count = 2; + let width = 18; + + ctx.draw_box(x, y, width, (count + 1) as i32, RGB::named(rltk::RED), RGB::named(rltk::BLACK)); + y += 1; + // Asc + ctx.set(x_offset + 2, y, RGB::named(rltk::YELLOW), RGB::named(rltk::BLACK), rltk::to_cp437('a')); + ctx.print(x_offset + 4, y, "ASCEND A FLOOR"); + y += 1; + // Desc + ctx.set(x_offset + 2, y, RGB::named(rltk::YELLOW), RGB::named(rltk::BLACK), rltk::to_cp437('d')); + ctx.print(x_offset + 4, y, "DESCEND A FLOOR"); + // Match keys + match ctx.key { + None => CheatMenuResult::NoResponse, + Some(key) => match key { + VirtualKeyCode::A => CheatMenuResult::Ascend, + VirtualKeyCode::D => CheatMenuResult::Descend, + VirtualKeyCode::Escape => CheatMenuResult::Cancel, + _ => CheatMenuResult::NoResponse, + }, + } +} diff --git a/src/gui/mod.rs b/src/gui/mod.rs index a14b5b0..52b215b 100644 --- a/src/gui/mod.rs +++ b/src/gui/mod.rs @@ -6,8 +6,10 @@ use super::{ use rltk::{Rltk, VirtualKeyCode, RGB}; use specs::prelude::*; use std::collections::BTreeMap; +mod cheat_menu; mod letter_to_option; mod tooltip; +pub use cheat_menu::*; pub fn draw_lerping_bar( ctx: &mut Rltk, diff --git a/src/main.rs b/src/main.rs index 0f1b86c..9186653 100644 --- a/src/main.rs +++ b/src/main.rs @@ -50,9 +50,10 @@ pub const LOG_TICKS: bool = false; #[derive(PartialEq, Copy, Clone)] pub enum RunState { - AwaitingInput, + AwaitingInput, // Player's turn PreRun, - Ticking, + Ticking, // Tick systems + ShowCheatMenu, // Teleport, godmode, etc. - for debugging ShowInventory, ShowDropItem, ShowRemoveItem, @@ -64,7 +65,7 @@ pub enum RunState { NextLevel, PreviousLevel, HelpScreen, - MagicMapReveal { row: i32, cursed: bool }, + MagicMapReveal { row: i32, cursed: bool }, // Animates magic mapping effect MapGeneration, } @@ -136,16 +137,23 @@ impl State { } fn goto_level(&mut self, offset: i32) { - // Freeze the current level - map::dungeon::freeze_entities(&mut self.ecs); - // Build new map + place player let current_id; { let worldmap_resource = self.ecs.fetch::(); current_id = worldmap_resource.id; } - gamelog::record_event("descended", 1); + // Record the correct type of event + if offset > 0 { + gamelog::record_event("descended", 1); + } else if current_id == 1 { + gamelog::Logger::new().append("CHEAT MENU: YOU CAN'T DO THAT.").colour((255, 0, 0)).log(); + return; + } else { + gamelog::record_event("ascended", 1); + } + // Freeze the current level + map::dungeon::freeze_entities(&mut self.ecs); self.generate_world_map(current_id + offset, offset); let mapname = self.ecs.fetch::().name.clone(); gamelog::Logger::new().append("You head to").npc_name_n(mapname).period().log(); @@ -235,6 +243,23 @@ impl GameState for State { } } } + RunState::ShowCheatMenu => { + let result = gui::show_cheat_menu(self, ctx); + match result { + gui::CheatMenuResult::Cancel => new_runstate = RunState::AwaitingInput, + gui::CheatMenuResult::NoResponse => {} + gui::CheatMenuResult::Ascend => { + self.goto_level(-1); + self.mapgen_next_state = Some(RunState::PreRun); + new_runstate = RunState::MapGeneration; + } + gui::CheatMenuResult::Descend => { + self.goto_level(1); + self.mapgen_next_state = Some(RunState::PreRun); + new_runstate = RunState::MapGeneration; + } + } + } RunState::ShowInventory => { let result = gui::show_inventory(self, ctx); match result.0 { diff --git a/src/map_builders/mod.rs b/src/map_builders/mod.rs index fba91f0..69a46ef 100644 --- a/src/map_builders/mod.rs +++ b/src/map_builders/mod.rs @@ -361,6 +361,6 @@ pub fn level_builder( match new_id { 1 => town_builder(new_id, rng, width, height, 0, initial_player_level), 2 => forest_builder(new_id, rng, width, height, 1, initial_player_level), - _ => random_builder(new_id, rng, 64, 64, difficulty, initial_player_level), + _ => random_builder(new_id, rng, width, height, difficulty, initial_player_level), } } diff --git a/src/player.rs b/src/player.rs index 25fc53e..da6b37a 100644 --- a/src/player.rs +++ b/src/player.rs @@ -484,6 +484,8 @@ pub fn player_input(gs: &mut State, ctx: &mut Rltk) -> RunState { VirtualKeyCode::I => return RunState::ShowInventory, VirtualKeyCode::D => return RunState::ShowDropItem, VirtualKeyCode::R => return RunState::ShowRemoveItem, + // Other + VirtualKeyCode::Minus => return RunState::ShowCheatMenu, VirtualKeyCode::Escape => return RunState::SaveGame, _ => { return RunState::AwaitingInput;