removes ctx arg from get_screen_bounds()
This commit is contained in:
parent
be1c7aa1c7
commit
683ab95531
9 changed files with 46 additions and 54 deletions
|
|
@ -7,7 +7,7 @@ use super::data::prelude::*;
|
||||||
|
|
||||||
const SHOW_BOUNDARIES: bool = false;
|
const SHOW_BOUNDARIES: bool = false;
|
||||||
|
|
||||||
pub fn get_screen_bounds(ecs: &World, _ctx: &mut BTerm) -> (i32, i32, i32, i32, i32, i32) {
|
pub fn get_screen_bounds(ecs: &World) -> (i32, i32, i32, i32, i32, i32) {
|
||||||
let player_pos = ecs.fetch::<Point>();
|
let player_pos = ecs.fetch::<Point>();
|
||||||
let map = ecs.fetch::<Map>();
|
let map = ecs.fetch::<Map>();
|
||||||
let (x_chars, y_chars, mut x_offset, mut y_offset) = (VIEWPORT_W, VIEWPORT_H, 1, 10);
|
let (x_chars, y_chars, mut x_offset, mut y_offset) = (VIEWPORT_W, VIEWPORT_H, 1, 10);
|
||||||
|
|
@ -35,7 +35,7 @@ pub fn get_screen_bounds(ecs: &World, _ctx: &mut BTerm) -> (i32, i32, i32, i32,
|
||||||
|
|
||||||
pub fn render_camera(ecs: &World, ctx: &mut BTerm) {
|
pub fn render_camera(ecs: &World, ctx: &mut BTerm) {
|
||||||
let map = ecs.fetch::<Map>();
|
let map = ecs.fetch::<Map>();
|
||||||
let (min_x, max_x, min_y, max_y, x_offset, y_offset) = get_screen_bounds(ecs, ctx);
|
let (min_x, max_x, min_y, max_y, x_offset, y_offset) = get_screen_bounds(ecs);
|
||||||
|
|
||||||
// Render map
|
// Render map
|
||||||
let mut y = 0;
|
let mut y = 0;
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ pub enum FarlookResult {
|
||||||
|
|
||||||
pub fn show_farlook(gs: &mut State, ctx: &mut BTerm) -> FarlookResult {
|
pub fn show_farlook(gs: &mut State, ctx: &mut BTerm) -> FarlookResult {
|
||||||
let runstate = gs.ecs.fetch::<RunState>();
|
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);
|
let (_min_x, _max_x, _min_y, _max_y, x_offset, y_offset) = get_screen_bounds(&gs.ecs);
|
||||||
|
|
||||||
ctx.print_color(
|
ctx.print_color(
|
||||||
1 + x_offset,
|
1 + x_offset,
|
||||||
|
|
|
||||||
|
|
@ -122,7 +122,7 @@ pub fn identify(gs: &mut State, ctx: &mut BTerm) -> (ItemMenuResult, Option<Enti
|
||||||
}
|
}
|
||||||
// Get display args
|
// Get display args
|
||||||
let width = get_max_inventory_width(&player_inventory);
|
let width = get_max_inventory_width(&player_inventory);
|
||||||
let (_, _, _, _, x_offset, y_offset) = crate::camera::get_screen_bounds(&gs.ecs, ctx);
|
let (_, _, _, _, x_offset, y_offset) = crate::camera::get_screen_bounds(&gs.ecs);
|
||||||
let (x, y) = (x_offset + 1, y_offset + 3);
|
let (x, y) = (x_offset + 1, y_offset + 3);
|
||||||
// Draw menu
|
// Draw menu
|
||||||
ctx.print_color(
|
ctx.print_color(
|
||||||
|
|
|
||||||
|
|
@ -549,7 +549,7 @@ pub fn get_input_direction(
|
||||||
ctx: &mut BTerm,
|
ctx: &mut BTerm,
|
||||||
function: fn(i: i32, j: i32, ecs: &mut World) -> RunState
|
function: fn(i: i32, j: i32, ecs: &mut World) -> RunState
|
||||||
) -> RunState {
|
) -> RunState {
|
||||||
let (_, _, _, _, x_offset, y_offset) = camera::get_screen_bounds(ecs, ctx);
|
let (_, _, _, _, x_offset, y_offset) = camera::get_screen_bounds(ecs);
|
||||||
|
|
||||||
ctx.print_color(
|
ctx.print_color(
|
||||||
1 + x_offset,
|
1 + x_offset,
|
||||||
|
|
@ -1191,7 +1191,7 @@ pub fn ranged_target(
|
||||||
range: i32,
|
range: i32,
|
||||||
aoe: i32
|
aoe: i32
|
||||||
) -> (TargetResult, Option<Point>) {
|
) -> (TargetResult, Option<Point>) {
|
||||||
let (min_x, max_x, min_y, max_y, x_offset, y_offset) = camera::get_screen_bounds(&gs.ecs, ctx);
|
let (min_x, max_x, min_y, max_y, x_offset, y_offset) = camera::get_screen_bounds(&gs.ecs);
|
||||||
let player_entity = gs.ecs.fetch::<Entity>();
|
let player_entity = gs.ecs.fetch::<Entity>();
|
||||||
let player_pos = gs.ecs.fetch::<Point>();
|
let player_pos = gs.ecs.fetch::<Point>();
|
||||||
let viewsheds = gs.ecs.read_storage::<Viewshed>();
|
let viewsheds = gs.ecs.read_storage::<Viewshed>();
|
||||||
|
|
@ -1231,10 +1231,7 @@ pub fn ranged_target(
|
||||||
|
|
||||||
// Draw mouse cursor
|
// Draw mouse cursor
|
||||||
let mouse_pos = (x, y);
|
let mouse_pos = (x, y);
|
||||||
let (min_x, _max_x, min_y, _max_y, x_offset, y_offset) = camera::get_screen_bounds(
|
let (min_x, _max_x, min_y, _max_y, x_offset, y_offset) = camera::get_screen_bounds(&gs.ecs);
|
||||||
&gs.ecs,
|
|
||||||
ctx
|
|
||||||
);
|
|
||||||
let x = x.clamp(x_offset, x_offset - 1 + VIEWPORT_W);
|
let x = x.clamp(x_offset, x_offset - 1 + VIEWPORT_W);
|
||||||
let y = y.clamp(y_offset, y_offset - 1 + VIEWPORT_H);
|
let y = y.clamp(y_offset, y_offset - 1 + VIEWPORT_H);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -117,7 +117,7 @@ pub fn remove_curse(gs: &mut State, ctx: &mut BTerm) -> (ItemMenuResult, Option<
|
||||||
}
|
}
|
||||||
// Get display args
|
// Get display args
|
||||||
let width = get_max_inventory_width(&player_inventory);
|
let width = get_max_inventory_width(&player_inventory);
|
||||||
let (_, _, _, _, x_offset, y_offset) = crate::camera::get_screen_bounds(&gs.ecs, ctx);
|
let (_, _, _, _, x_offset, y_offset) = crate::camera::get_screen_bounds(&gs.ecs);
|
||||||
let (x, y) = (x_offset + 1, y_offset + 3);
|
let (x, y) = (x_offset + 1, y_offset + 3);
|
||||||
// Draw menu
|
// Draw menu
|
||||||
ctx.print_color(
|
ctx.print_color(
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ impl Tooltip {
|
||||||
|
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
pub fn draw_tooltips(ecs: &World, ctx: &mut BTerm, xy: Option<(i32, i32)>) {
|
pub fn draw_tooltips(ecs: &World, ctx: &mut BTerm, xy: Option<(i32, i32)>) {
|
||||||
let (min_x, _max_x, min_y, _max_y, x_offset, y_offset) = get_screen_bounds(ecs, ctx);
|
let (min_x, _max_x, min_y, _max_y, x_offset, y_offset) = get_screen_bounds(ecs);
|
||||||
let map = ecs.fetch::<Map>();
|
let map = ecs.fetch::<Map>();
|
||||||
let names = ecs.read_storage::<Name>();
|
let names = ecs.read_storage::<Name>();
|
||||||
let positions = ecs.read_storage::<Position>();
|
let positions = ecs.read_storage::<Position>();
|
||||||
|
|
|
||||||
|
|
@ -168,5 +168,5 @@ fn idx_to_px(idx: usize, map: &Map) -> (f32, f32) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(app: &mut App, state: &mut State) {
|
fn update(app: &mut App, state: &mut State) {
|
||||||
// game loop
|
//state.tick(app);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -645,8 +645,21 @@ fn get_item(ecs: &mut World) -> RunState {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn player_input(gs: &mut State, ctx: &mut BTerm, on_overmap: bool) -> RunState {
|
use notan::prelude::*;
|
||||||
match ctx.key {
|
pub fn player_input(gs: &mut State, ctx: &mut App, on_overmap: bool) -> RunState {
|
||||||
|
let key = &ctx.keyboard;
|
||||||
|
if key.was_pressed(KeyCode::Numpad4) {
|
||||||
|
return try_move_player(-1, 0, &mut gs.ecs);
|
||||||
|
} else if key.was_pressed(KeyCode::Numpad6) {
|
||||||
|
return try_move_player(1, 0, &mut gs.ecs);
|
||||||
|
} else if key.was_pressed(KeyCode::Numpad8) {
|
||||||
|
return try_move_player(0, -1, &mut gs.ecs);
|
||||||
|
} else if key.was_pressed(KeyCode::Numpad2) {
|
||||||
|
return try_move_player(0, 1, &mut gs.ecs);
|
||||||
|
}
|
||||||
|
return RunState::AwaitingInput;
|
||||||
|
|
||||||
|
/*match ctx.key {
|
||||||
None => {
|
None => {
|
||||||
return RunState::AwaitingInput;
|
return RunState::AwaitingInput;
|
||||||
}
|
}
|
||||||
|
|
@ -776,7 +789,7 @@ pub fn player_input(gs: &mut State, ctx: &mut BTerm, on_overmap: bool) -> RunSta
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return RunState::AwaitingInput;
|
return RunState::AwaitingInput;*/
|
||||||
}
|
}
|
||||||
|
|
||||||
fn try_change_level(ecs: &mut World, backtracking: bool) -> Destination {
|
fn try_change_level(ecs: &mut World, backtracking: bool) -> Destination {
|
||||||
|
|
|
||||||
|
|
@ -162,33 +162,22 @@ impl State {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GameState for State {
|
impl State {
|
||||||
fn tick(&mut self, ctx: &mut BTerm) {
|
pub fn tick(&mut self, app: &mut App) {
|
||||||
let mut new_runstate;
|
let mut new_runstate;
|
||||||
{
|
{
|
||||||
let runstate = self.ecs.fetch::<RunState>();
|
let runstate = self.ecs.fetch::<RunState>();
|
||||||
new_runstate = *runstate;
|
new_runstate = *runstate;
|
||||||
}
|
}
|
||||||
// Clear screen
|
// Clear screen
|
||||||
ctx.set_active_console(0);
|
//particle_system::particle_ticker(&mut self.ecs, ctx);
|
||||||
ctx.cls();
|
|
||||||
ctx.set_active_console(HP_BAR_LAYER);
|
|
||||||
ctx.cls();
|
|
||||||
ctx.set_active_console(TEXT_LAYER);
|
|
||||||
ctx.cls();
|
|
||||||
ctx.set_active_console(ENTITY_LAYER);
|
|
||||||
ctx.cls();
|
|
||||||
ctx.set_active_console(TILE_LAYER);
|
|
||||||
ctx.cls();
|
|
||||||
particle_system::particle_ticker(&mut self.ecs, ctx);
|
|
||||||
|
|
||||||
match new_runstate {
|
match new_runstate {
|
||||||
RunState::MainMenu { .. } => {}
|
RunState::MainMenu { .. } | RunState::PreRun | RunState::CharacterCreation { .. } => {}
|
||||||
RunState::CharacterCreation { .. } => {}
|
|
||||||
_ => {
|
_ => {
|
||||||
// Draw map and ui
|
// Draw map and ui
|
||||||
camera::render_camera(&self.ecs, ctx);
|
//camera::render_camera(&self.ecs, ctx);
|
||||||
gui::draw_ui(&self.ecs, ctx);
|
//gui::draw_ui(&self.ecs, ctx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -217,7 +206,7 @@ impl GameState for State {
|
||||||
}
|
}
|
||||||
if can_act {
|
if can_act {
|
||||||
let on_overmap = self.ecs.fetch::<Map>().overmap;
|
let on_overmap = self.ecs.fetch::<Map>().overmap;
|
||||||
new_runstate = player_input(self, ctx, on_overmap);
|
new_runstate = player_input(self, app, on_overmap);
|
||||||
} else {
|
} else {
|
||||||
new_runstate = RunState::Ticking;
|
new_runstate = RunState::Ticking;
|
||||||
}
|
}
|
||||||
|
|
@ -248,7 +237,7 @@ impl GameState for 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 };
|
||||||
|
|
@ -259,7 +248,7 @@ impl GameState for State {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RunState::ShowCheatMenu => {
|
RunState::ShowCheatMenu => {
|
||||||
let result = gui::show_cheat_menu(self, ctx);
|
let result = gui::CheatMenuResult::Cancel; //gui::show_cheat_menu(self, ctx);
|
||||||
match result {
|
match result {
|
||||||
gui::CheatMenuResult::Cancel => {
|
gui::CheatMenuResult::Cancel => {
|
||||||
new_runstate = RunState::AwaitingInput;
|
new_runstate = RunState::AwaitingInput;
|
||||||
|
|
@ -302,7 +291,7 @@ impl GameState for State {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RunState::ShowInventory => {
|
RunState::ShowInventory => {
|
||||||
let result = gui::show_inventory(self, ctx);
|
let result = gui::ItemMenuResult::Cancel; //gui::show_inventory(self, ctx);
|
||||||
match result.0 {
|
match result.0 {
|
||||||
gui::ItemMenuResult::Cancel => {
|
gui::ItemMenuResult::Cancel => {
|
||||||
new_runstate = RunState::AwaitingInput;
|
new_runstate = RunState::AwaitingInput;
|
||||||
|
|
@ -316,7 +305,7 @@ impl GameState for State {
|
||||||
let is_aoe = self.ecs.read_storage::<AOE>();
|
let is_aoe = self.ecs.read_storage::<AOE>();
|
||||||
let aoe_item = is_aoe.get(item_entity);
|
let aoe_item = is_aoe.get(item_entity);
|
||||||
let (min_x, _max_x, min_y, _max_y, x_offset, y_offset) =
|
let (min_x, _max_x, min_y, _max_y, x_offset, y_offset) =
|
||||||
camera::get_screen_bounds(&self.ecs, ctx);
|
camera::get_screen_bounds(&self.ecs);
|
||||||
let ppos = self.ecs.fetch::<Point>();
|
let ppos = self.ecs.fetch::<Point>();
|
||||||
if let Some(aoe_item) = aoe_item {
|
if let Some(aoe_item) = aoe_item {
|
||||||
new_runstate = RunState::ShowTargeting {
|
new_runstate = RunState::ShowTargeting {
|
||||||
|
|
@ -477,7 +466,10 @@ impl GameState for State {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RunState::CharacterCreation { .. } => {
|
RunState::CharacterCreation { .. } => {
|
||||||
let result = gui::character_creation(self, ctx);
|
let result = gui::CharCreateResult::Selected {
|
||||||
|
ancestry: gui::Ancestry::Human,
|
||||||
|
class: gui::Class::Fighter,
|
||||||
|
}; //gui::character_creation(self, ctx);
|
||||||
match result {
|
match result {
|
||||||
gui::CharCreateResult::NoSelection { ancestry, class } => {
|
gui::CharCreateResult::NoSelection { ancestry, class } => {
|
||||||
new_runstate = RunState::CharacterCreation { ancestry, class };
|
new_runstate = RunState::CharacterCreation { ancestry, class };
|
||||||
|
|
@ -502,7 +494,7 @@ impl GameState for State {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
RunState::GameOver => {
|
RunState::GameOver => {
|
||||||
let result = gui::game_over(ctx);
|
let result = gui::YesNoResult::No; //gui::game_over(ctx);
|
||||||
let write_to_morgue: Option<bool> = match result {
|
let write_to_morgue: Option<bool> = match result {
|
||||||
gui::YesNoResult::NoSelection => None,
|
gui::YesNoResult::NoSelection => None,
|
||||||
gui::YesNoResult::No => Some(false),
|
gui::YesNoResult::No => Some(false),
|
||||||
|
|
@ -525,7 +517,7 @@ impl GameState for State {
|
||||||
new_runstate = RunState::MapGeneration;
|
new_runstate = RunState::MapGeneration;
|
||||||
}
|
}
|
||||||
RunState::HelpScreen => {
|
RunState::HelpScreen => {
|
||||||
let result = gui::show_help(ctx);
|
let result = gui::YesNoResult::Yes; //gui::show_help(ctx);
|
||||||
match result {
|
match result {
|
||||||
gui::YesNoResult::Yes => {
|
gui::YesNoResult::Yes => {
|
||||||
gamelog::record_event(EVENT::LookedForHelp(1));
|
gamelog::record_event(EVENT::LookedForHelp(1));
|
||||||
|
|
@ -574,19 +566,9 @@ impl GameState for State {
|
||||||
new_runstate = self.mapgen_next_state.unwrap();
|
new_runstate = self.mapgen_next_state.unwrap();
|
||||||
}
|
}
|
||||||
if self.mapgen_history.len() != 0 {
|
if self.mapgen_history.len() != 0 {
|
||||||
ctx.set_active_console(0);
|
//camera::render_debug_map(&self.mapgen_history[self.mapgen_index], ctx);
|
||||||
ctx.cls();
|
|
||||||
ctx.set_active_console(HP_BAR_LAYER);
|
|
||||||
ctx.cls();
|
|
||||||
ctx.set_active_console(TEXT_LAYER);
|
|
||||||
ctx.cls();
|
|
||||||
ctx.set_active_console(ENTITY_LAYER);
|
|
||||||
ctx.cls();
|
|
||||||
ctx.set_active_console(TILE_LAYER);
|
|
||||||
ctx.cls();
|
|
||||||
camera::render_debug_map(&self.mapgen_history[self.mapgen_index], ctx);
|
|
||||||
|
|
||||||
self.mapgen_timer += ctx.frame_time_ms;
|
//self.mapgen_timer += ctx.frame_time_ms;
|
||||||
if self.mapgen_timer > 300.0 {
|
if self.mapgen_timer > 300.0 {
|
||||||
self.mapgen_timer = 0.0;
|
self.mapgen_timer = 0.0;
|
||||||
self.mapgen_index += 1;
|
self.mapgen_index += 1;
|
||||||
|
|
@ -605,6 +587,6 @@ impl GameState for State {
|
||||||
|
|
||||||
damage_system::delete_the_dead(&mut self.ecs);
|
damage_system::delete_the_dead(&mut self.ecs);
|
||||||
|
|
||||||
let _ = render_draw_buffer(ctx);
|
//let _ = render_draw_buffer(ctx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue