diff --git a/src/gui/farlook.rs b/src/gui/farlook.rs new file mode 100644 index 0000000..ba2e3a0 --- /dev/null +++ b/src/gui/farlook.rs @@ -0,0 +1,54 @@ +use super::{ State, RunState, tooltip::draw_tooltips, camera::get_screen_bounds }; +use rltk::prelude::*; + +#[derive(PartialEq, Copy, Clone)] +pub enum FarlookResult { + NoResponse { + x: i32, + y: i32, + }, + Cancel, +} + +pub fn show_farlook(gs: &mut State, ctx: &mut Rltk) -> FarlookResult { + let runstate = gs.ecs.fetch::(); + let (min_x, _max_x, min_y, _max_y, x_offset, y_offset) = get_screen_bounds(&gs.ecs, ctx); + + ctx.print_color( + 1 + x_offset, + 1 + y_offset, + RGB::named(WHITE), + RGB::named(BLACK), + "Look at what? [move keys][Esc.]" + ); + + if let RunState::Farlook { x, y } = *runstate { + let (screen_x, screen_y) = (69, 41); + 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)); + + ctx.set(x, y, RGB::named(WHITE), RGB::named(BLACK), rltk::to_cp437('X')); + draw_tooltips(&gs.ecs, ctx, Some((x, y))); + + return match ctx.key { + None => FarlookResult::NoResponse { x, y }, + Some(key) => + match key { + VirtualKeyCode::Escape | VirtualKeyCode::X => FarlookResult::Cancel, + VirtualKeyCode::Numpad9 => FarlookResult::NoResponse { x: x + 1, y: y - 1 }, + VirtualKeyCode::Numpad8 => FarlookResult::NoResponse { x, y: y - 1 }, + VirtualKeyCode::Numpad7 => FarlookResult::NoResponse { x: x - 1, y: y - 1 }, + VirtualKeyCode::Numpad6 => FarlookResult::NoResponse { x: x + 1, y }, + VirtualKeyCode::Numpad4 => FarlookResult::NoResponse { x: x - 1, y }, + VirtualKeyCode::Numpad3 => FarlookResult::NoResponse { x: x + 1, y: y + 1 }, + VirtualKeyCode::Numpad2 => FarlookResult::NoResponse { x, y: y + 1 }, + VirtualKeyCode::Numpad1 => FarlookResult::NoResponse { x: x - 1, y: y + 1 }, + _ => FarlookResult::NoResponse { x, y }, + } + }; + } else { + let ppos = gs.ecs.fetch::(); + // TODO: PPOS + offsets (should get these from screen_bounds()) + return FarlookResult::NoResponse { x: ppos.x + x_offset, y: ppos.x + y_offset }; + } +} diff --git a/src/gui/mod.rs b/src/gui/mod.rs index 26bfc73..409fb5d 100644 --- a/src/gui/mod.rs +++ b/src/gui/mod.rs @@ -48,6 +48,8 @@ pub use identify_menu::*; mod tooltip; pub use cheat_menu::*; use crate::data::events::*; +mod farlook; +pub use farlook::*; /// Gives a popup box with a message and a title, and waits for a keypress. #[allow(unused)] @@ -338,7 +340,7 @@ pub fn draw_ui(ecs: &World, ctx: &mut Rltk) { ctx.draw_hollow_box(0, 9, 70, 42, RGB::named(rltk::WHITE), RGB::named(rltk::BLACK)); // Camera box ctx.draw_hollow_box(0, 52, 70, 3, RGB::named(rltk::WHITE), RGB::named(rltk::BLACK)); // Stats box ctx.draw_hollow_box(71, 0, 33, 55, RGB::named(rltk::WHITE), RGB::named(rltk::BLACK)); // Side box - tooltip::draw_tooltips(ecs, ctx); + tooltip::draw_tooltips(ecs, ctx, None); } pub fn get_input_direction( @@ -680,7 +682,7 @@ pub fn show_help(ctx: &mut Rltk) -> YesNoResult { y += 1; ctx.print(x, y, "o open c close"); y += 1; - ctx.print(x, y, "f force"); + ctx.print(x, y, "f force x farlook"); y += 2; ctx.print_color(x, y, RGB::named(rltk::GREEN), RGB::named(rltk::BLACK), "MOUSE CONTROL"); y += 2; diff --git a/src/gui/tooltip.rs b/src/gui/tooltip.rs index b43fd29..0af65b3 100644 --- a/src/gui/tooltip.rs +++ b/src/gui/tooltip.rs @@ -42,7 +42,7 @@ impl Tooltip { } #[rustfmt::skip] -pub fn draw_tooltips(ecs: &World, ctx: &mut Rltk) { +pub fn draw_tooltips(ecs: &World, ctx: &mut Rltk, xy: Option<(i32, i32)>) { let (min_x, _max_x, min_y, _max_y, x_offset, y_offset) = get_screen_bounds(ecs, ctx); let map = ecs.fetch::(); let names = ecs.read_storage::(); @@ -54,7 +54,7 @@ pub fn draw_tooltips(ecs: &World, ctx: &mut Rltk) { let entities = ecs.entities(); let player_entity = ecs.fetch::(); - let mouse_pos = ctx.mouse_pos(); + let mouse_pos = if xy.is_none() { ctx.mouse_pos() } else { xy.unwrap() }; let mut mouse_pos_adjusted = mouse_pos; mouse_pos_adjusted.0 += min_x - x_offset; mouse_pos_adjusted.1 += min_y - y_offset; diff --git a/src/main.rs b/src/main.rs index a70e341..c98feb9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -78,6 +78,10 @@ pub enum RunState { cursed: bool, }, // Animates magic mapping effect MapGeneration, + Farlook { + x: i32, + y: i32, + }, } pub struct State { @@ -286,6 +290,17 @@ impl GameState for State { } } } + RunState::Farlook { .. } => { + let result = gui::show_farlook(self, ctx); + match result { + gui::FarlookResult::NoResponse { x, y } => { + new_runstate = RunState::Farlook { x, y }; + } + gui::FarlookResult::Cancel => { + new_runstate = RunState::AwaitingInput; + } + } + } RunState::ShowCheatMenu => { let result = gui::show_cheat_menu(self, ctx); match result { diff --git a/src/player.rs b/src/player.rs index 039e306..bc48f9c 100644 --- a/src/player.rs +++ b/src/player.rs @@ -4,6 +4,7 @@ use super::{ gui::obfuscate_name_ecs, gui::renderable_colour_ecs, gui::item_colour_ecs, + camera::get_screen_bounds, raws::Reaction, Attributes, BlocksTile, @@ -672,6 +673,12 @@ pub fn player_input(gs: &mut State, ctx: &mut Rltk) -> RunState { VirtualKeyCode::Escape => { return RunState::SaveGame; } + VirtualKeyCode::X => { + let (min_x, _max_x, min_y, _max_y, x_offset, y_offset) = get_screen_bounds(&gs.ecs, ctx); + let ppos = gs.ecs.fetch::(); + let (x, y) = (ppos.x + x_offset - min_x, ppos.y + y_offset - min_y); + return RunState::Farlook { x, y }; + } _ => { return RunState::AwaitingInput; }