From 7d2c0954cd95bdabcb7ecf26f9225382ab078289 Mon Sep 17 00:00:00 2001 From: tom barrett Date: Wed, 24 Jul 2019 05:54:49 -0500 Subject: dialog box --- resources/fonts/SOBAD___.ttf | Bin 0 -> 50988 bytes resources/fonts/SOCOND__.ttf | Bin 0 -> 60708 bytes resources/fonts/SOEXT___.ttf | Bin 0 -> 57668 bytes resources/fonts/SONARR__.ttf | Bin 0 -> 55520 bytes resources/fonts/SONORM__.ttf | Bin 0 -> 55800 bytes resources/fonts/SOSHAD__.ttf | Bin 0 -> 117832 bytes resources/fonts/SOSUE___.ttf | Bin 0 -> 45124 bytes resources/fonts/SOWIDE__.ttf | Bin 0 -> 57184 bytes resources/fonts/readme.txt | 1 + src/constants.rs | 5 +++- src/dialogbox.rs | 61 +++++++++++++++++++++++++++++++++++++++++++ src/lib.rs | 1 + src/world.rs | 6 +++++ 13 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 resources/fonts/SOBAD___.ttf create mode 100644 resources/fonts/SOCOND__.ttf create mode 100644 resources/fonts/SOEXT___.ttf create mode 100644 resources/fonts/SONARR__.ttf create mode 100644 resources/fonts/SONORM__.ttf create mode 100644 resources/fonts/SOSHAD__.ttf create mode 100644 resources/fonts/SOSUE___.ttf create mode 100644 resources/fonts/SOWIDE__.ttf create mode 100644 resources/fonts/readme.txt create mode 100644 src/dialogbox.rs diff --git a/resources/fonts/SOBAD___.ttf b/resources/fonts/SOBAD___.ttf new file mode 100644 index 0000000..5787346 Binary files /dev/null and b/resources/fonts/SOBAD___.ttf differ diff --git a/resources/fonts/SOCOND__.ttf b/resources/fonts/SOCOND__.ttf new file mode 100644 index 0000000..f746afe Binary files /dev/null and b/resources/fonts/SOCOND__.ttf differ diff --git a/resources/fonts/SOEXT___.ttf b/resources/fonts/SOEXT___.ttf new file mode 100644 index 0000000..89e7425 Binary files /dev/null and b/resources/fonts/SOEXT___.ttf differ diff --git a/resources/fonts/SONARR__.ttf b/resources/fonts/SONARR__.ttf new file mode 100644 index 0000000..1c1e81a Binary files /dev/null and b/resources/fonts/SONARR__.ttf differ diff --git a/resources/fonts/SONORM__.ttf b/resources/fonts/SONORM__.ttf new file mode 100644 index 0000000..1768301 Binary files /dev/null and b/resources/fonts/SONORM__.ttf differ diff --git a/resources/fonts/SOSHAD__.ttf b/resources/fonts/SOSHAD__.ttf new file mode 100644 index 0000000..13c8e17 Binary files /dev/null and b/resources/fonts/SOSHAD__.ttf differ diff --git a/resources/fonts/SOSUE___.ttf b/resources/fonts/SOSUE___.ttf new file mode 100644 index 0000000..209354a Binary files /dev/null and b/resources/fonts/SOSUE___.ttf differ diff --git a/resources/fonts/SOWIDE__.ttf b/resources/fonts/SOWIDE__.ttf new file mode 100644 index 0000000..733063a Binary files /dev/null and b/resources/fonts/SOWIDE__.ttf differ diff --git a/resources/fonts/readme.txt b/resources/fonts/readme.txt new file mode 100644 index 0000000..63cf3c7 --- /dev/null +++ b/resources/fonts/readme.txt @@ -0,0 +1 @@ +This font is freeware and can be used as is in any context without permission from Apostrophic Laboratories, except to produce material that is racist, criminal and/or illegal in nature. It is prohibited to modify any Apostrophic Laboratories font(s) for repackaging and/or re-release without an express written authorization by the designer(s) of the font(s) or Apostrophic Laboratories. Under no circumstance shall any Apostrophic Laboratories design or font design be sold or purchased. Email info@apostrophiclab.com if you want more information. diff --git a/src/constants.rs b/src/constants.rs index 1f6bb9f..8a873c6 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -1,6 +1,6 @@ pub const TILE_WIDTH: f32 = 16.0; pub const TILE_HEIGHT: f32 = 16.0; -pub const TILE_SCALE: f32 = 2.5; +pub const TILE_SCALE: f32 = 2.75; pub const PLAYER_SPEED: f32 = 3.0; pub const WANDER_DISTANCE: f32 = 200.0; @@ -13,3 +13,6 @@ pub const FLIP_H: usize = 0x8000_0000; pub const FLIP_V: usize = 0x4000_0000; pub const FLIP_D: usize = 0x2000_0000; pub const FLIP_A: usize = FLIP_D | FLIP_H | FLIP_V; + +use ggez::graphics::Color; +pub const PURPLE: Color = Color::new(0.4, 0.0, 0.2, 1.0); diff --git a/src/dialogbox.rs b/src/dialogbox.rs new file mode 100644 index 0000000..1f6415b --- /dev/null +++ b/src/dialogbox.rs @@ -0,0 +1,61 @@ +use ggez::conf::Conf; +use ggez::graphics::{ + self, DrawMode, DrawParam, Font, Mesh, MeshBuilder, Rect, Scale, Text, TextFragment, +}; +use ggez::nalgebra::Point2; +use ggez::{Context, GameResult}; + +use crate::constants; + +pub struct DialogBox { + mesh: Mesh, + text: Text, + conf: Conf, + pub visible: bool, +} + +impl DialogBox { + pub fn new(context: &mut Context) -> DialogBox { + let conf = Conf::new(); + let font = Font::new(context, "/fonts/SONORM__.ttf").unwrap(); + + DialogBox { + text: Text::new( + TextFragment::new("Ave !") + .font(font) + .scale(Scale::uniform(40.0)), + ), + mesh: MeshBuilder::new() + .rectangle( + DrawMode::fill(), + Rect::new( + conf.window_mode.width * 0.10, + 2.5 * conf.window_mode.height / 4.0, + conf.window_mode.width * 0.80, + conf.window_mode.height / 4.0, + ), + constants::PURPLE, + ) + .build(context) + .unwrap(), + visible: false, + conf, + } + } + + pub fn draw(&self, context: &mut Context) -> GameResult { + if self.visible { + graphics::draw(context, &self.mesh, DrawParam::default())?; + graphics::draw( + context, + &self.text, + DrawParam::default().dest(Point2::new( + self.conf.window_mode.width * 0.11, + 2.6 * self.conf.window_mode.height / 4.0, + )), + )?; + } + + Ok(()) + } +} diff --git a/src/lib.rs b/src/lib.rs index a95028d..be462c9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,6 +2,7 @@ pub mod animations; pub mod camera; pub mod cell; pub mod constants; +pub mod dialogbox; pub mod entity; pub mod layer; pub mod map; diff --git a/src/world.rs b/src/world.rs index f89e9e7..abbb9c1 100644 --- a/src/world.rs +++ b/src/world.rs @@ -3,6 +3,7 @@ use ggez::graphics::{self, spritebatch::SpriteBatch, DrawParam, FilterMode, Imag use ggez::{filesystem, Context, GameResult}; use crate::camera::Camera; +use crate::dialogbox::DialogBox; use crate::entity::Operable; use crate::map::Map; use crate::npc::NPC; @@ -12,6 +13,7 @@ use crate::tileset::Tileset; pub struct World { map: Map, spritebatch: SpriteBatch, + dialogbox: DialogBox, camera: Camera, player: Player, npcs: Vec, @@ -30,6 +32,7 @@ impl World { Ok(World { map: map.clone(), spritebatch: SpriteBatch::new(image), + dialogbox: DialogBox::new(context), camera: Camera::new(map.get_dimensions()), player: Player::new( &tileset, @@ -68,6 +71,8 @@ impl EventHandler for World { DrawParam::default().dest(self.camera.draw), )?; + self.dialogbox.draw(context)?; + self.spritebatch.clear(); graphics::present(context)?; @@ -89,6 +94,7 @@ impl EventHandler for World { if !repeat { match keycode { KeyCode::Q => context.continuing = false, + KeyCode::E => self.dialogbox.visible = !self.dialogbox.visible, _ => self.player.give_key_down(keycode), } } -- cgit v1.2.3