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

@ -90,7 +90,7 @@ pub fn render_camera(ecs: &World, ctx: &mut BTerm) {
16 16
), ),
0, 0,
tint, RGBA::named(WHITE),
0 // Ya 0 // Ya
); );
ctx.set_active_console(TILE_LAYER); ctx.set_active_console(TILE_LAYER);

View file

@ -1,5 +1,6 @@
use super::{ State, RunState, tooltip::draw_tooltips, camera::get_offset, VIEWPORT_H, VIEWPORT_W }; use super::{ State, RunState, tooltip::draw_tooltips, camera::get_offset, VIEWPORT_H, VIEWPORT_W };
use bracket_lib::prelude::*; use bracket_lib::prelude::*;
use notan::prelude::*;
#[derive(PartialEq, Copy, Clone)] #[derive(PartialEq, Copy, Clone)]
pub enum FarlookResult { pub enum FarlookResult {
@ -10,44 +11,49 @@ pub enum FarlookResult {
Cancel, 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 runstate = gs.ecs.fetch::<RunState>();
let offsets = get_offset(); 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 { if let RunState::Farlook { x, y } = *runstate {
let x = x.clamp(offsets.x, offsets.x - 1 + VIEWPORT_W); let x = x.clamp(offsets.x, offsets.x - 1 + VIEWPORT_W);
let y = y.clamp(offsets.y, offsets.y - 1 + VIEWPORT_H); let y = y.clamp(offsets.y, offsets.y - 1 + VIEWPORT_H);
let key = &ctx.keyboard;
ctx.set(x, y, RGB::named(WHITE), RGB::named(BLACK), to_cp437('X')); // Movement
draw_tooltips(&gs.ecs, ctx, Some((x, y))); for keycode in key.pressed.iter() {
match *keycode {
return match ctx.key { KeyCode::Escape | KeyCode::X => {
None => FarlookResult::NoResponse { x, y }, return FarlookResult::Cancel;
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 },
} }
}; 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 { } else {
let ppos = gs.ecs.fetch::<Point>(); 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 }; return FarlookResult::NoResponse { x: ppos.x + offsets.x, y: ppos.x + offsets.y };
} }
} }

View file

@ -180,7 +180,7 @@ fn draw_camera(ecs: &World, draw: &mut Draw, atlas: &HashMap<String, Texture>) {
let minds = ecs.read_storage::<Mind>(); let minds = ecs.read_storage::<Mind>();
let pools = ecs.read_storage::<Pools>(); let pools = ecs.read_storage::<Pools>();
let entities = ecs.entities(); let entities = ecs.entities();
let mut data = (&positions, &renderables, &entities, !&hidden).join().collect::<Vec<_>>(); let data = (&positions, &renderables, &entities, !&hidden).join().collect::<Vec<_>>();
let mut to_draw: HashMap<DrawKey, DrawInfo> = HashMap::new(); let mut to_draw: HashMap<DrawKey, DrawInfo> = HashMap::new();
for (pos, render, e, _h) in data.iter() { for (pos, render, e, _h) in data.iter() {
let idx = map.xy_idx(pos.x, pos.y); let idx = map.xy_idx(pos.x, pos.y);
@ -255,6 +255,7 @@ fn draw_camera(ecs: &World, draw: &mut Draw, atlas: &HashMap<String, Texture>) {
(entry.0.x as f32) * TILESIZE, (entry.0.x as f32) * TILESIZE,
(entry.0.y as f32) * TILESIZE (entry.0.y as f32) * TILESIZE
); );
// TODO: Update map memory.
} }
_ => {} _ => {}
} }
@ -287,7 +288,7 @@ fn render_map_in_view(map: &Map, ecs: &World, draw: &mut Draw, atlas: &HashMap<S
map.xy_idx(tile_x + bounds.x_offset, tile_y + bounds.y_offset), map.xy_idx(tile_x + bounds.x_offset, tile_y + bounds.y_offset),
&map &map
); );
draw.image(atlas.get(id).unwrap()).position(px.0, px.1); draw.image(atlas.get(id).unwrap()).position(px.0, px.1).color(tint);
} }
} }
} else if SHOW_BOUNDARIES { } else if SHOW_BOUNDARIES {
@ -297,6 +298,13 @@ fn render_map_in_view(map: &Map, ecs: &World, draw: &mut Draw, atlas: &HashMap<S
} }
} }
fn draw_farlook(x: i32, y: i32, draw: &mut Draw, atlas: &HashMap<String, Texture>) {
draw.image(atlas.get("ui_select_a1").unwrap()).position(
(x as f32) * TILESIZE,
(y as f32) * TILESIZE
);
}
fn draw(app: &mut App, gfx: &mut Graphics, gs: &mut State) { fn draw(app: &mut App, gfx: &mut Graphics, gs: &mut State) {
let mut draw = gfx.create_draw(); let mut draw = gfx.create_draw();
draw.clear(Color::BLACK); draw.clear(Color::BLACK);
@ -308,12 +316,13 @@ fn draw(app: &mut App, gfx: &mut Graphics, gs: &mut State) {
draw_camera(&gs.ecs, &mut draw, &gs.atlas); draw_camera(&gs.ecs, &mut draw, &gs.atlas);
} }
} }
// Draw player (replace this with draw entities). match *gs.ecs.fetch::<RunState>() {
let map = gs.ecs.fetch::<Map>(); RunState::Farlook { x, y } => {
let ppos = gs.ecs.fetch::<Point>(); draw_farlook(x, y, &mut draw, &gs.atlas);
let offsets = crate::camera::get_offset(); //draw_tooltips(&gs.ecs, ctx, Some((x, y))); TODO: Put this in draw loop
let px = idx_to_px(map.xy_idx(ppos.x + offsets.x, ppos.y + offsets.y), &map); }
draw.image(gs.atlas.get("ui_heart_full").unwrap()).position(px.0, px.1); _ => {}
}
// Render batch // Render batch
gfx.render(&draw); gfx.render(&draw);
} }

View file

@ -4,8 +4,9 @@ use crate::config::CONFIG;
use crate::data::ids::*; use crate::data::ids::*;
use bracket_lib::prelude::*; use bracket_lib::prelude::*;
use std::ops::{ Add, Mul }; use std::ops::{ Add, Mul };
use notan::prelude::*;
pub fn get_sprite_for_id(idx: usize, map: &Map, other_pos: Option<Point>) -> (&str, RGBA) { pub fn get_sprite_for_id(idx: usize, map: &Map, other_pos: Option<Point>) -> (&str, Color) {
let x = (idx as i32) % map.width; let x = (idx as i32) % map.width;
let y = (idx as i32) / map.width; let y = (idx as i32) / map.width;
let sprite = map.tiles[idx].sprite(); let sprite = map.tiles[idx].sprite();
@ -15,9 +16,9 @@ pub fn get_sprite_for_id(idx: usize, map: &Map, other_pos: Option<Point>) -> (&s
}; };
let sprite_id = pick_variant(base, tile.variants(), idx, map);*/ let sprite_id = pick_variant(base, tile.variants(), idx, map);*/
let tint = if !map.visible_tiles[idx] { let tint = if !map.visible_tiles[idx] {
RGBA::from_f32(0.75, 0.75, 0.75, 1.0) Color::from_rgb(0.75, 0.75, 0.75)
} else { } else {
RGBA::named(WHITE) Color::WHITE
}; };
return (sprite, tint); return (sprite, tint);
} }

View file

@ -229,7 +229,17 @@ impl State {
} }
} }
} }
// RunState::Farlook 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 // RunState::ShowCheatMenu
// RunState::ShowInventory // RunState::ShowInventory
// RunState::ShowDropItem // RunState::ShowDropItem
@ -379,7 +389,7 @@ impl State {
} }
} }
RunState::Farlook { .. } => { RunState::Farlook { .. } => {
let result = gui::show_farlook(self, ctx); let result = gui::FarlookResult::Cancel; //gui::show_farlook(self, ctx);
match result { match result {
gui::FarlookResult::NoResponse { x, y } => { gui::FarlookResult::NoResponse { x, y } => {
new_runstate = RunState::Farlook { x, y }; new_runstate = RunState::Farlook { x, y };