x to farlook, now playable with 0 mouse input

This commit is contained in:
Llywelwyn 2023-08-30 03:13:46 +01:00
parent 81a48d5a6e
commit 7da00ed2b1
5 changed files with 82 additions and 4 deletions

54
src/gui/farlook.rs Normal file
View file

@ -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::<RunState>();
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::<Point>();
// TODO: PPOS + offsets (should get these from screen_bounds())
return FarlookResult::NoResponse { x: ppos.x + x_offset, y: ppos.x + y_offset };
}
}

View file

@ -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;

View file

@ -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::<Map>();
let names = ecs.read_storage::<Name>();
@ -54,7 +54,7 @@ pub fn draw_tooltips(ecs: &World, ctx: &mut Rltk) {
let entities = ecs.entities();
let player_entity = ecs.fetch::<Entity>();
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;

View file

@ -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 {

View file

@ -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::<Point>();
let (x, y) = (ppos.x + x_offset - min_x, ppos.y + y_offset - min_y);
return RunState::Farlook { x, y };
}
_ => {
return RunState::AwaitingInput;
}