tooltips for overmap tiles, and distinct fg-bg offsets
This commit is contained in:
parent
2890c16a3c
commit
537e19c4e7
8 changed files with 84 additions and 43 deletions
|
|
@ -4,7 +4,7 @@ use serde::{ Deserialize, Serialize };
|
|||
pub enum EVENT {
|
||||
TURN(i32),
|
||||
LEVEL(i32),
|
||||
CHANGED_FLOOR(i32),
|
||||
CHANGED_FLOOR(String),
|
||||
PLAYER_CONFUSED(i32),
|
||||
KICKED_SOMETHING(i32),
|
||||
BROKE_DOOR(i32),
|
||||
|
|
|
|||
|
|
@ -1,3 +1,7 @@
|
|||
use super::names::*;
|
||||
use super::visuals::*;
|
||||
use rltk::prelude::*;
|
||||
|
||||
pub const ID_OVERMAP: i32 = 1;
|
||||
|
||||
pub const ID_TOWN: i32 = 10;
|
||||
|
|
@ -5,3 +9,20 @@ pub const ID_TOWN2: i32 = ID_TOWN + 1;
|
|||
pub const ID_TOWN3: i32 = ID_TOWN + 2;
|
||||
|
||||
pub const ID_INFINITE: i32 = 1000;
|
||||
|
||||
pub fn get_local_desc(id: i32) -> String {
|
||||
let str = match id {
|
||||
ID_TOWN => NAME_STARTER_TOWN,
|
||||
ID_INFINITE => NAME_DUNGEON_RANDOM,
|
||||
_ => "an unnamed overmap tile",
|
||||
};
|
||||
return str.to_string();
|
||||
}
|
||||
|
||||
pub fn get_local_col(id: i32) -> RGB {
|
||||
let col = match id {
|
||||
ID_TOWN => TO_TOWN_COLOUR,
|
||||
_ => (255, 255, 255),
|
||||
};
|
||||
return RGB::from_u8(col.0, col.1, col.2);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ pub const LONG_PARTICLE_LIFETIME: f32 = 300.0;
|
|||
pub const BLOODSTAIN_COLOUR: (u8, u8, u8) = (153, 0, 0);
|
||||
// DEFAULT THEME
|
||||
pub const DEFAULT_BG_COLOUR: (u8, u8, u8) = (29, 50, 50);
|
||||
pub const DEFAULT_BG_OFFSETS: (i32, i32, i32) = (5, 5, 5);
|
||||
pub const WALL_COLOUR: (u8, u8, u8) = (229, 191, 94);
|
||||
pub const WALL_OFFSETS: (i32, i32, i32) = (48, 48, 48);
|
||||
pub const FLOOR_COLOUR: (u8, u8, u8) = (25, 204, 122);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
use std::collections::{ HashSet, HashMap };
|
||||
use std::sync::Mutex;
|
||||
use crate::data::events::EVENT;
|
||||
use crate::data::names::*;
|
||||
|
||||
lazy_static! {
|
||||
/// A count of each event that has happened over the run. i.e. "turns", "descended", "ascended"
|
||||
|
|
@ -8,9 +9,9 @@ lazy_static! {
|
|||
// A record of events that happened on a given turn. i.e. "Advanced to level 2".
|
||||
pub static ref EVENTS: Mutex<HashMap<u32, Vec<String>>> = Mutex::new(HashMap::new());
|
||||
// A record of floors visited, and monsters killed. Used to determine if an event is significant.
|
||||
static ref VISITED: Mutex<HashSet<i32>> = Mutex::new({
|
||||
static ref VISITED: Mutex<HashSet<String>> = Mutex::new({
|
||||
let mut set = HashSet::new();
|
||||
set.insert(1);
|
||||
set.insert(NAME_OVERMAP.to_string());
|
||||
set
|
||||
});
|
||||
static ref KILLED: Mutex<HashSet<String>> = Mutex::new(HashSet::new());
|
||||
|
|
@ -91,8 +92,8 @@ pub fn record_event(event: EVENT) {
|
|||
if VISITED.lock().unwrap().contains(&n) {
|
||||
significant_event = false;
|
||||
} else {
|
||||
VISITED.lock().unwrap().insert(n);
|
||||
new_event = format!("Visited floor {} for the first time", n);
|
||||
VISITED.lock().unwrap().insert(n.clone());
|
||||
new_event = format!("Visited {} for the first time", n);
|
||||
}
|
||||
}
|
||||
EVENT::KICKED_SOMETHING(n) => {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
use super::{ camera::get_screen_bounds, Attributes, Hidden, Map, Name, Pools, Position, Renderable, Rltk, World, RGB };
|
||||
use crate::TileType;
|
||||
use crate::data::ids::*;
|
||||
use rltk::prelude::*;
|
||||
use specs::prelude::*;
|
||||
|
||||
|
|
@ -70,6 +72,17 @@ pub fn draw_tooltips(ecs: &World, ctx: &mut Rltk) {
|
|||
}
|
||||
|
||||
let mut tooltips: Vec<Tooltip> = Vec::new();
|
||||
|
||||
match map.tiles[map.xy_idx(mouse_pos_adjusted.0, mouse_pos_adjusted.1)] {
|
||||
TileType::ToLocal(n) => {
|
||||
let name = get_local_desc(n);
|
||||
let mut tip = Tooltip::new();
|
||||
tip.add(format!("You see {}.", name), get_local_col(n));
|
||||
tooltips.push(tip);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
for (entity, position, renderable, _name, _hidden) in (&entities, &positions, &renderables, &names, !&hidden).join() {
|
||||
if position.x == mouse_pos_adjusted.0 && position.y == mouse_pos_adjusted.1 {
|
||||
let mut tip = Tooltip::new();
|
||||
|
|
@ -129,7 +142,7 @@ pub fn draw_tooltips(ecs: &World, ctx: &mut Rltk) {
|
|||
let arrow;
|
||||
let arrow_x;
|
||||
let arrow_y = mouse_pos.1;
|
||||
if mouse_pos.0 < 35 {
|
||||
if mouse_pos.0 > 35 {
|
||||
// Render to the left
|
||||
arrow = to_cp437('→');
|
||||
arrow_x = mouse_pos.0 - 1;
|
||||
|
|
@ -151,7 +164,7 @@ pub fn draw_tooltips(ecs: &World, ctx: &mut Rltk) {
|
|||
}
|
||||
|
||||
for t in tooltips.iter() {
|
||||
let x = if mouse_pos.0 < 35 {
|
||||
let x = if mouse_pos.0 > 35 {
|
||||
mouse_pos.0 - (1 + t.width())
|
||||
} else {
|
||||
mouse_pos.0 + (1 + 1)
|
||||
|
|
|
|||
|
|
@ -171,17 +171,12 @@ impl State {
|
|||
}
|
||||
|
||||
fn goto_id(&mut self, id: i32, dest_tile: TileType) {
|
||||
let current_id;
|
||||
{
|
||||
let worldmap_resource = self.ecs.fetch::<Map>();
|
||||
current_id = worldmap_resource.id;
|
||||
}
|
||||
// Freeze curr level
|
||||
map::dungeon::freeze_entities(&mut self.ecs);
|
||||
self.generate_world_map(id, dest_tile);
|
||||
let mapname = self.ecs.fetch::<Map>().name.clone();
|
||||
gamelog::Logger::new().append("You head to").npc_name_n(mapname).period().log();
|
||||
gamelog::record_event(EVENT::CHANGED_FLOOR(id));
|
||||
gamelog::Logger::new().append("You head to").npc_name_n(&mapname).period().log();
|
||||
gamelog::record_event(EVENT::CHANGED_FLOOR(mapname));
|
||||
}
|
||||
|
||||
fn game_over_cleanup(&mut self) {
|
||||
|
|
|
|||
|
|
@ -12,20 +12,25 @@ pub fn get_tile_renderables_for_id(
|
|||
other_pos: Option<Point>,
|
||||
debug: Option<bool>
|
||||
) -> (rltk::FontCharType, RGB, RGB) {
|
||||
let (glyph, mut fg, mut bg, offsets, bg_main_col) = match map.id {
|
||||
let (glyph, mut fg, mut bg, offsets) = match map.id {
|
||||
ID_TOWN2 => get_forest_theme_renderables(idx, map, debug),
|
||||
_ => get_default_theme_renderables(idx, map, debug),
|
||||
};
|
||||
|
||||
// If one of the colours was left blank, make them the same.
|
||||
let mut same_col: bool = false;
|
||||
if fg == RGB::new() {
|
||||
fg = bg;
|
||||
same_col = true;
|
||||
} else if bg == RGB::new() {
|
||||
bg = fg;
|
||||
same_col = true;
|
||||
}
|
||||
|
||||
fg = fg.add(map.additional_fg_offset);
|
||||
(fg, bg) = apply_colour_offset(fg, bg, map, idx, offsets, bg_main_col);
|
||||
if same_col {
|
||||
fg = fg.add(map.additional_fg_offset);
|
||||
}
|
||||
(fg, bg) = apply_colour_offset(fg, bg, map, idx, offsets);
|
||||
if CONFIG.visuals.with_scanlines && WITH_SCANLINES_BRIGHTEN_AMOUNT > 0.0 {
|
||||
(fg, bg) = brighten_by(fg, bg, WITH_SCANLINES_BRIGHTEN_AMOUNT);
|
||||
}
|
||||
|
|
@ -61,20 +66,20 @@ pub fn get_tile_renderables_for_id(
|
|||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
pub fn get_default_theme_renderables(idx: usize, map: &Map, debug: Option<bool>) -> (rltk::FontCharType, RGB, RGB, (i32, i32, i32), bool) {
|
||||
pub fn get_default_theme_renderables(idx: usize, map: &Map, debug: Option<bool>) -> (rltk::FontCharType, RGB, RGB, ((i32, i32, i32), (i32, i32, i32))) {
|
||||
let glyph: rltk::FontCharType;
|
||||
#[allow(unused_assignments)]
|
||||
let mut fg: RGB = RGB::new();
|
||||
#[allow(unused_assignments)]
|
||||
let mut bg: RGB = RGB::new();
|
||||
let mut offsets: (i32, i32, i32) = (0, 0, 0);
|
||||
let mut bg_main_col = true;
|
||||
let mut bg_offsets: (i32, i32, i32) = (-1, -1, -1);
|
||||
|
||||
match map.tiles[idx] {
|
||||
TileType::Floor => { glyph = rltk::to_cp437(FLOOR_GLYPH); fg = RGB::named(FLOOR_COLOUR); bg = RGB::named(DEFAULT_BG_COLOUR); offsets = FLOOR_OFFSETS; }
|
||||
TileType::WoodFloor => { glyph = rltk::to_cp437(WOOD_FLOOR_GLYPH); bg = RGB::named(WOOD_FLOOR_COLOUR); offsets = WOOD_FLOOR_OFFSETS; }
|
||||
TileType::Fence => { glyph = rltk::to_cp437(FENCE_GLYPH); fg = RGB::named(FENCE_FG_COLOUR); bg = RGB::named(FENCE_COLOUR); offsets = FENCE_OFFSETS; }
|
||||
TileType::Wall => { let x = idx as i32 % map.width; let y = idx as i32 / map.width; glyph = wall_glyph(&*map, x, y, debug); fg = RGB::named(WALL_COLOUR); bg = RGB::named(DEFAULT_BG_COLOUR); offsets = WALL_OFFSETS; bg_main_col = false; }
|
||||
TileType::Wall => { let x = idx as i32 % map.width; let y = idx as i32 / map.width; glyph = wall_glyph(&*map, x, y, debug); fg = RGB::named(WALL_COLOUR); bg = RGB::named(DEFAULT_BG_COLOUR); offsets = WALL_OFFSETS; bg_offsets = DEFAULT_BG_OFFSETS }
|
||||
TileType::DownStair => { glyph = rltk::to_cp437(DOWN_STAIR_GLYPH); fg = RGB::named(STAIR_COLOUR); bg = RGB::named(DEFAULT_BG_COLOUR); offsets = STAIR_OFFSETS;}
|
||||
TileType::UpStair => { glyph = rltk::to_cp437(UP_STAIR_GLYPH); fg = RGB::named(STAIR_COLOUR); bg = RGB::named(DEFAULT_BG_COLOUR); offsets = STAIR_OFFSETS; }
|
||||
TileType::Bridge => { glyph = rltk::to_cp437(BRIDGE_GLYPH); bg = RGB::named(BRIDGE_COLOUR); offsets = BRIDGE_OFFSETS; }
|
||||
|
|
@ -88,30 +93,35 @@ pub fn get_default_theme_renderables(idx: usize, map: &Map, debug: Option<bool>)
|
|||
TileType::DeepWater => { glyph = rltk::to_cp437(DEEP_WATER_GLYPH); bg = RGB::named(DEEP_WATER_COLOUR); offsets = DEEP_WATER_OFFSETS; }
|
||||
TileType::Bars => { glyph = rltk::to_cp437(BARS_GLYPH); fg = RGB::named(BARS_COLOUR); bg = RGB::named(FLOOR_COLOUR); }
|
||||
TileType::ImpassableMountain => { glyph = rltk::to_cp437(IMPASSABLE_MOUNTAIN_GLYPH); bg = RGB::named(IMPASSABLE_MOUNTAIN_COLOUR); offsets = IMPASSABLE_MOUNTAIN_OFFSETS }
|
||||
TileType::ToOvermap(_) => { glyph = rltk::to_cp437(TO_OVERMAP_GLYPH); fg = RGB::named(TO_OVERMAP_COLOUR); bg = RGB::named(DEFAULT_BG_COLOUR); bg_main_col = false; }
|
||||
TileType::ToLocal(_) => { glyph = rltk::to_cp437(TO_TOWN_GLYPH); fg = RGB::named(TO_TOWN_COLOUR); bg = RGB::named(DEFAULT_BG_COLOUR); bg_main_col = false; }
|
||||
TileType::ToOvermap(_) => { glyph = rltk::to_cp437(TO_OVERMAP_GLYPH); fg = RGB::named(TO_OVERMAP_COLOUR); bg = RGB::named(GRASS_COLOUR); }
|
||||
TileType::ToLocal(_) => { glyph = rltk::to_cp437(TO_TOWN_GLYPH); fg = RGB::named(TO_TOWN_COLOUR); bg = RGB::named(GRASS_COLOUR); }
|
||||
}
|
||||
return (glyph, fg, bg, offsets, bg_main_col);
|
||||
if bg_offsets == (-1, -1, -1) {
|
||||
bg_offsets = offsets;
|
||||
}
|
||||
return (glyph, fg, bg, (offsets, bg_offsets));
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
fn get_forest_theme_renderables(idx:usize, map: &Map, debug: Option<bool>) -> (rltk::FontCharType, RGB, RGB, (i32, i32, i32), bool) {
|
||||
fn get_forest_theme_renderables(idx:usize, map: &Map, debug: Option<bool>) -> (rltk::FontCharType, RGB, RGB, ((i32, i32, i32), (i32, i32, i32))) {
|
||||
let glyph;
|
||||
#[allow(unused_assignments)]
|
||||
let mut fg = RGB::new();
|
||||
#[allow(unused_assignments)]
|
||||
let mut bg = RGB::new();
|
||||
let mut offsets: (i32, i32, i32) = (0, 0, 0);
|
||||
let mut bg_main_col = true;
|
||||
let mut bg_offsets: (i32, i32, i32) = (-1, -1, -1);
|
||||
|
||||
match map.tiles[idx] {
|
||||
TileType::Wall => { glyph = rltk::to_cp437(FOREST_WALL_GLYPH); fg = RGB::named(FOREST_WALL_COLOUR); bg = RGB::named(GRASS_COLOUR) }
|
||||
TileType::Wall => { glyph = rltk::to_cp437(FOREST_WALL_GLYPH); fg = RGB::named(FOREST_WALL_COLOUR); bg = RGB::named(GRASS_COLOUR); offsets = GRASS_OFFSETS; }
|
||||
TileType::Road => { glyph = rltk::to_cp437(ROAD_GLYPH); bg = RGB::named(ROAD_COLOUR); }
|
||||
TileType::ShallowWater => { glyph = rltk::to_cp437(SHALLOW_WATER_GLYPH); bg = RGB::named(SHALLOW_WATER_COLOUR); }
|
||||
_ => { (glyph, fg, _, offsets, bg_main_col) = get_default_theme_renderables(idx, map, debug); bg = RGB::named(GRASS_COLOUR) }
|
||||
TileType::ShallowWater => { glyph = rltk::to_cp437(SHALLOW_WATER_GLYPH); bg = RGB::named(SHALLOW_WATER_COLOUR); offsets = SHALLOW_WATER_OFFSETS; }
|
||||
_ => { (glyph, fg, _, (offsets, bg_offsets)) = get_default_theme_renderables(idx, map, debug); bg = RGB::named(GRASS_COLOUR); bg_offsets = GRASS_OFFSETS; }
|
||||
}
|
||||
|
||||
(glyph, fg, bg, offsets, bg_main_col)
|
||||
if bg_offsets == (-1, -1, -1) {
|
||||
bg_offsets = offsets;
|
||||
}
|
||||
return (glyph, fg, bg, (offsets, bg_offsets));
|
||||
}
|
||||
|
||||
fn is_revealed_and_wall(map: &Map, x: i32, y: i32, debug: Option<bool>) -> bool {
|
||||
|
|
@ -261,24 +271,21 @@ fn apply_colour_offset(
|
|||
mut bg: RGB,
|
||||
map: &Map,
|
||||
idx: usize,
|
||||
offset: (i32, i32, i32),
|
||||
bg_main_col: bool
|
||||
offset: ((i32, i32, i32), (i32, i32, i32))
|
||||
) -> (RGB, RGB) {
|
||||
let offset_mod = map.colour_offset[idx];
|
||||
let fg_offset = (
|
||||
(offset.0 as f32) * offset_mod.0.0,
|
||||
(offset.1 as f32) * offset_mod.0.1,
|
||||
(offset.2 as f32) * offset_mod.0.2,
|
||||
(offset.0.0 as f32) * offset_mod.0.0,
|
||||
(offset.0.1 as f32) * offset_mod.0.1,
|
||||
(offset.0.2 as f32) * offset_mod.0.2,
|
||||
);
|
||||
fg = add_i32_offsets(fg, fg_offset);
|
||||
if bg_main_col {
|
||||
let bg_offset = (
|
||||
(offset.0 as f32) * offset_mod.1.0,
|
||||
(offset.1 as f32) * offset_mod.1.1,
|
||||
(offset.2 as f32) * offset_mod.1.2,
|
||||
);
|
||||
bg = add_i32_offsets(bg, bg_offset);
|
||||
}
|
||||
let bg_offset = (
|
||||
(offset.1.0 as f32) * offset_mod.1.0,
|
||||
(offset.1.1 as f32) * offset_mod.1.1,
|
||||
(offset.1.2 as f32) * offset_mod.1.2,
|
||||
);
|
||||
bg = add_i32_offsets(bg, bg_offset);
|
||||
|
||||
return (fg, bg);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -439,6 +439,9 @@ pub fn try_move_player(delta_x: i32, delta_y: i32, ecs: &mut World) -> RunState
|
|||
let mut ppos = ecs.write_resource::<Point>();
|
||||
ppos.x = pos.x;
|
||||
ppos.y = pos.y;
|
||||
if map.tiles[new_idx] == TileType::ToOvermap(map.id) {
|
||||
return RunState::GoToLevel(ID_OVERMAP, TileType::ToLocal(map.id));
|
||||
}
|
||||
return RunState::Ticking;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue