fixes up farlooking - sprite, etc.
This commit is contained in:
parent
deb9988935
commit
f862f00f0b
7 changed files with 275 additions and 230 deletions
File diff suppressed because it is too large
Load diff
Binary file not shown.
|
Before Width: | Height: | Size: 4.9 KiB After Width: | Height: | Size: 4.9 KiB |
|
|
@ -21,7 +21,7 @@ pub struct Spritesize {
|
||||||
|
|
||||||
pub const TILESIZE: Spritesize = Spritesize {
|
pub const TILESIZE: Spritesize = Spritesize {
|
||||||
x: 16.0,
|
x: 16.0,
|
||||||
y: 24.0,
|
y: 16.0,
|
||||||
sprite_x: 16.0 * ZOOM_FACTOR,
|
sprite_x: 16.0 * ZOOM_FACTOR,
|
||||||
sprite_y: 24.0 * ZOOM_FACTOR,
|
sprite_y: 24.0 * ZOOM_FACTOR,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
use super::{ State, RunState, tooltip::draw_tooltips, camera::get_offset, VIEWPORT_H, VIEWPORT_W };
|
use super::{ State, RunState, World, tooltip::draw_tooltips, camera::get_offset };
|
||||||
use bracket_lib::prelude::*;
|
use bracket_lib::prelude::*;
|
||||||
use notan::prelude::*;
|
use notan::prelude::*;
|
||||||
use notan::draw::{ Draw, DrawImages };
|
use notan::draw::{ Draw, DrawImages };
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use crate::consts::visuals::{ TILES_IN_VIEWPORT_H, TILES_IN_VIEWPORT_W };
|
||||||
use crate::consts::TILESIZE;
|
use crate::consts::TILESIZE;
|
||||||
|
|
||||||
#[derive(PartialEq, Copy, Clone)]
|
#[derive(PartialEq, Copy, Clone)]
|
||||||
|
|
@ -16,10 +17,9 @@ pub enum FarlookResult {
|
||||||
|
|
||||||
pub fn show_farlook(gs: &mut State, ctx: &mut App) -> 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();
|
|
||||||
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(0, TILES_IN_VIEWPORT_W - 1);
|
||||||
let y = y.clamp(offsets.y, offsets.y - 1 + VIEWPORT_H);
|
let y = y.clamp(0, TILES_IN_VIEWPORT_H - 1);
|
||||||
let key = &ctx.keyboard;
|
let key = &ctx.keyboard;
|
||||||
// Movement
|
// Movement
|
||||||
for keycode in key.pressed.iter() {
|
for keycode in key.pressed.iter() {
|
||||||
|
|
@ -56,14 +56,21 @@ pub fn show_farlook(gs: &mut State, ctx: &mut App) -> FarlookResult {
|
||||||
}
|
}
|
||||||
return FarlookResult::NoResponse { x, y };
|
return FarlookResult::NoResponse { x, y };
|
||||||
} else {
|
} else {
|
||||||
let ppos = gs.ecs.fetch::<Point>();
|
return FarlookResult::NoResponse { x: TILES_IN_VIEWPORT_W / 2, y: TILES_IN_VIEWPORT_H / 2 };
|
||||||
return FarlookResult::NoResponse { x: ppos.x + offsets.x, y: ppos.x + offsets.y };
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw_farlook(x: i32, y: i32, draw: &mut Draw, atlas: &HashMap<String, Texture>) {
|
pub fn draw_farlook(
|
||||||
draw.image(atlas.get("ui_select_c1").unwrap()).position(
|
ecs: &World,
|
||||||
(x as f32) * TILESIZE.x,
|
x: i32,
|
||||||
(y as f32) * TILESIZE.x
|
y: i32,
|
||||||
);
|
draw: &mut Draw,
|
||||||
|
atlas: &HashMap<String, Texture>
|
||||||
|
) {
|
||||||
|
let placement = super::viewport_tile_to_px(x, y);
|
||||||
|
draw.image(atlas.get("select1").unwrap())
|
||||||
|
.position(placement.x, placement.y)
|
||||||
|
.size(TILESIZE.sprite_x, TILESIZE.sprite_y);
|
||||||
|
let _idx = super::viewport_tile_to_map_idx(ecs, x, y);
|
||||||
|
// Get tooltip for idx, etc.
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1880,3 +1880,32 @@ pub fn with_article(name: &String) -> String {
|
||||||
}
|
}
|
||||||
format!("a {}", name)
|
format!("a {}", name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the map index of a tile in the viewport.
|
||||||
|
pub fn viewport_tile_to_map_idx(ecs: &World, x: i32, y: i32) -> usize {
|
||||||
|
let bounds = crate::camera::get_screen_bounds(ecs, false);
|
||||||
|
let x = x + bounds.min_x;
|
||||||
|
let y = y + bounds.min_y;
|
||||||
|
return ecs.fetch::<Map>().xy_idx(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Denotes a pixel location on the screen.
|
||||||
|
pub struct Px {
|
||||||
|
x: f32,
|
||||||
|
y: f32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Px {
|
||||||
|
pub fn new(x: f32, y: f32) -> Self {
|
||||||
|
Self { x, y }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns the pixel location of a tile in the viewport.
|
||||||
|
pub fn viewport_tile_to_px(x: i32, y: i32) -> Px {
|
||||||
|
let offsets = crate::camera::get_offset();
|
||||||
|
Px::new(
|
||||||
|
(x as f32) * TILESIZE.sprite_x + (offsets.x as f32) * TILESIZE.x,
|
||||||
|
(y as f32) * TILESIZE.sprite_y + (offsets.y as f32) * TILESIZE.y
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -542,7 +542,7 @@ fn draw(app: &mut App, gfx: &mut Graphics, gs: &mut State) {
|
||||||
}
|
}
|
||||||
match runstate {
|
match runstate {
|
||||||
RunState::Farlook { x, y } => {
|
RunState::Farlook { x, y } => {
|
||||||
gui::draw_farlook(x, y, &mut draw, &gs.atlas);
|
gui::draw_farlook(&gs.ecs, x, y, &mut draw, &gs.atlas);
|
||||||
//draw_tooltips(&gs.ecs, ctx, Some((x, y))); TODO: Put this in draw loop
|
//draw_tooltips(&gs.ecs, ctx, Some((x, y))); TODO: Put this in draw loop
|
||||||
}
|
}
|
||||||
RunState::ShowCheatMenu => {
|
RunState::ShowCheatMenu => {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
use bracket_lib::prelude::*;
|
use bracket_lib::prelude::*;
|
||||||
|
use specs::prelude::*;
|
||||||
use serde::{ Deserialize, Serialize };
|
use serde::{ Deserialize, Serialize };
|
||||||
use std::collections::{ HashSet, HashMap };
|
use std::collections::{ HashSet, HashMap };
|
||||||
mod tiletype;
|
mod tiletype;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue