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;
|
||||
|
||||
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 map = ecs.fetch::<Map>();
|
||||
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) {
|
||||
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
|
||||
let mut y = 0;
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ pub enum FarlookResult {
|
|||
|
||||
pub fn show_farlook(gs: &mut State, ctx: &mut BTerm) -> 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);
|
||||
let (_min_x, _max_x, _min_y, _max_y, x_offset, y_offset) = get_screen_bounds(&gs.ecs);
|
||||
|
||||
ctx.print_color(
|
||||
1 + x_offset,
|
||||
|
|
|
|||
|
|
@ -122,7 +122,7 @@ pub fn identify(gs: &mut State, ctx: &mut BTerm) -> (ItemMenuResult, Option<Enti
|
|||
}
|
||||
// Get display args
|
||||
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);
|
||||
// Draw menu
|
||||
ctx.print_color(
|
||||
|
|
|
|||
|
|
@ -549,7 +549,7 @@ pub fn get_input_direction(
|
|||
ctx: &mut BTerm,
|
||||
function: fn(i: i32, j: i32, ecs: &mut World) -> 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(
|
||||
1 + x_offset,
|
||||
|
|
@ -1191,7 +1191,7 @@ pub fn ranged_target(
|
|||
range: i32,
|
||||
aoe: i32
|
||||
) -> (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_pos = gs.ecs.fetch::<Point>();
|
||||
let viewsheds = gs.ecs.read_storage::<Viewshed>();
|
||||
|
|
@ -1231,10 +1231,7 @@ pub fn ranged_target(
|
|||
|
||||
// Draw mouse cursor
|
||||
let mouse_pos = (x, y);
|
||||
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 x = x.clamp(x_offset, x_offset - 1 + VIEWPORT_W);
|
||||
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
|
||||
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);
|
||||
// Draw menu
|
||||
ctx.print_color(
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ impl Tooltip {
|
|||
|
||||
#[rustfmt::skip]
|
||||
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 names = ecs.read_storage::<Name>();
|
||||
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) {
|
||||
// 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 {
|
||||
match ctx.key {
|
||||
use notan::prelude::*;
|
||||
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 => {
|
||||
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 {
|
||||
|
|
|
|||
|
|
@ -162,33 +162,22 @@ impl State {
|
|||
}
|
||||
}
|
||||
|
||||
impl GameState for State {
|
||||
fn tick(&mut self, ctx: &mut BTerm) {
|
||||
impl State {
|
||||
pub fn tick(&mut self, app: &mut App) {
|
||||
let mut new_runstate;
|
||||
{
|
||||
let runstate = self.ecs.fetch::<RunState>();
|
||||
new_runstate = *runstate;
|
||||
}
|
||||
// Clear screen
|
||||
ctx.set_active_console(0);
|
||||
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);
|
||||
//particle_system::particle_ticker(&mut self.ecs, ctx);
|
||||
|
||||
match new_runstate {
|
||||
RunState::MainMenu { .. } => {}
|
||||
RunState::CharacterCreation { .. } => {}
|
||||
RunState::MainMenu { .. } | RunState::PreRun | RunState::CharacterCreation { .. } => {}
|
||||
_ => {
|
||||
// Draw map and ui
|
||||
camera::render_camera(&self.ecs, ctx);
|
||||
gui::draw_ui(&self.ecs, ctx);
|
||||
//camera::render_camera(&self.ecs, ctx);
|
||||
//gui::draw_ui(&self.ecs, ctx);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -217,7 +206,7 @@ impl GameState for State {
|
|||
}
|
||||
if can_act {
|
||||
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 {
|
||||
new_runstate = RunState::Ticking;
|
||||
}
|
||||
|
|
@ -248,7 +237,7 @@ impl GameState for State {
|
|||
}
|
||||
}
|
||||
RunState::Farlook { .. } => {
|
||||
let result = gui::show_farlook(self, ctx);
|
||||
let result = gui::FarlookResult::Cancel; //gui::show_farlook(self, ctx);
|
||||
match result {
|
||||
gui::FarlookResult::NoResponse { x, y } => {
|
||||
new_runstate = RunState::Farlook { x, y };
|
||||
|
|
@ -259,7 +248,7 @@ impl GameState for State {
|
|||
}
|
||||
}
|
||||
RunState::ShowCheatMenu => {
|
||||
let result = gui::show_cheat_menu(self, ctx);
|
||||
let result = gui::CheatMenuResult::Cancel; //gui::show_cheat_menu(self, ctx);
|
||||
match result {
|
||||
gui::CheatMenuResult::Cancel => {
|
||||
new_runstate = RunState::AwaitingInput;
|
||||
|
|
@ -302,7 +291,7 @@ impl GameState for State {
|
|||
}
|
||||
}
|
||||
RunState::ShowInventory => {
|
||||
let result = gui::show_inventory(self, ctx);
|
||||
let result = gui::ItemMenuResult::Cancel; //gui::show_inventory(self, ctx);
|
||||
match result.0 {
|
||||
gui::ItemMenuResult::Cancel => {
|
||||
new_runstate = RunState::AwaitingInput;
|
||||
|
|
@ -316,7 +305,7 @@ impl GameState for State {
|
|||
let is_aoe = self.ecs.read_storage::<AOE>();
|
||||
let aoe_item = is_aoe.get(item_entity);
|
||||
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>();
|
||||
if let Some(aoe_item) = aoe_item {
|
||||
new_runstate = RunState::ShowTargeting {
|
||||
|
|
@ -477,7 +466,10 @@ impl GameState for State {
|
|||
}
|
||||
}
|
||||
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 {
|
||||
gui::CharCreateResult::NoSelection { ancestry, class } => {
|
||||
new_runstate = RunState::CharacterCreation { ancestry, class };
|
||||
|
|
@ -502,7 +494,7 @@ impl GameState for State {
|
|||
};
|
||||
}
|
||||
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 {
|
||||
gui::YesNoResult::NoSelection => None,
|
||||
gui::YesNoResult::No => Some(false),
|
||||
|
|
@ -525,7 +517,7 @@ impl GameState for State {
|
|||
new_runstate = RunState::MapGeneration;
|
||||
}
|
||||
RunState::HelpScreen => {
|
||||
let result = gui::show_help(ctx);
|
||||
let result = gui::YesNoResult::Yes; //gui::show_help(ctx);
|
||||
match result {
|
||||
gui::YesNoResult::Yes => {
|
||||
gamelog::record_event(EVENT::LookedForHelp(1));
|
||||
|
|
@ -574,19 +566,9 @@ impl GameState for State {
|
|||
new_runstate = self.mapgen_next_state.unwrap();
|
||||
}
|
||||
if self.mapgen_history.len() != 0 {
|
||||
ctx.set_active_console(0);
|
||||
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);
|
||||
//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 {
|
||||
self.mapgen_timer = 0.0;
|
||||
self.mapgen_index += 1;
|
||||
|
|
@ -605,6 +587,6 @@ impl GameState for State {
|
|||
|
||||
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