reimpl farlook (tooltips NYI)

This commit is contained in:
Llywelwyn 2023-09-24 19:16:47 +01:00
parent e8aa7494a4
commit e482b29fc6
5 changed files with 70 additions and 44 deletions

View file

@ -1,5 +1,6 @@
use super::{ State, RunState, tooltip::draw_tooltips, camera::get_offset, VIEWPORT_H, VIEWPORT_W };
use bracket_lib::prelude::*;
use notan::prelude::*;
#[derive(PartialEq, Copy, Clone)]
pub enum FarlookResult {
@ -10,44 +11,49 @@ pub enum FarlookResult {
Cancel,
}
pub fn show_farlook(gs: &mut State, ctx: &mut BTerm) -> FarlookResult {
pub fn show_farlook(gs: &mut State, ctx: &mut App) -> FarlookResult {
let runstate = gs.ecs.fetch::<RunState>();
let offsets = get_offset();
ctx.print_color(
1 + offsets.x,
1 + offsets.y,
RGB::named(WHITE),
RGB::named(BLACK),
"Look at what? [move keys][Esc.]"
);
if let RunState::Farlook { x, y } = *runstate {
let x = x.clamp(offsets.x, offsets.x - 1 + VIEWPORT_W);
let y = y.clamp(offsets.y, offsets.y - 1 + VIEWPORT_H);
ctx.set(x, y, RGB::named(WHITE), RGB::named(BLACK), 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 },
let key = &ctx.keyboard;
// Movement
for keycode in key.pressed.iter() {
match *keycode {
KeyCode::Escape | KeyCode::X => {
return FarlookResult::Cancel;
}
};
KeyCode::Numpad1 => {
return FarlookResult::NoResponse { x: x - 1, y: y + 1 };
}
KeyCode::Numpad2 => {
return FarlookResult::NoResponse { x, y: y + 1 };
}
KeyCode::Numpad3 => {
return FarlookResult::NoResponse { x: x + 1, y: y + 1 };
}
KeyCode::Numpad4 => {
return FarlookResult::NoResponse { x: x - 1, y };
}
KeyCode::Numpad6 => {
return FarlookResult::NoResponse { x: x + 1, y };
}
KeyCode::Numpad7 => {
return FarlookResult::NoResponse { x: x - 1, y: y - 1 };
}
KeyCode::Numpad8 => {
return FarlookResult::NoResponse { x, y: y - 1 };
}
KeyCode::Numpad9 => {
return FarlookResult::NoResponse { x: x + 1, y: y - 1 };
}
_ => {}
}
}
return 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 + offsets.x, y: ppos.x + offsets.y };
}
}