From 0f85752b1657e7b8024fb2715578712295979b3a Mon Sep 17 00:00:00 2001 From: tom barrett Date: Tue, 27 Aug 2019 03:33:50 -0500 Subject: cargo update and dialogbox now disappears and npc resumes wandering --- src/dialogbox.rs | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) (limited to 'src/dialogbox.rs') diff --git a/src/dialogbox.rs b/src/dialogbox.rs index 4bdce04..f2909d1 100644 --- a/src/dialogbox.rs +++ b/src/dialogbox.rs @@ -36,8 +36,8 @@ impl DialogTree { #[derive(Clone)] pub struct DialogBox { dialogtree: Option, + dialog: Option, font: Font, - text: Option, mesh: Mesh, conf: Conf, } @@ -48,8 +48,8 @@ impl DialogBox { DialogBox { dialogtree: None, + dialog: None, font: Font::new(context, "/fonts/SONORM__.ttf").unwrap(), - text: None, mesh: MeshBuilder::new() .rectangle( DrawMode::fill(), @@ -67,26 +67,28 @@ impl DialogBox { } } + pub fn is_visible(&self) -> bool { + self.dialogtree.is_some() + } + pub fn update(&mut self) { - if let Some(dialogtree) = &self.dialogtree { - if self.text.is_none() { - self.text = Some(Text::new( - TextFragment::new(dialogtree.dialogs.get(&0).unwrap().text.as_str()) - .font(self.font) - .scale(Scale::uniform(40.0)), - )); - } - } else { - self.text = None; + if self.dialogtree.is_none() { + self.dialog = None; } } pub fn draw(&self, context: &mut Context) -> GameResult { - if let Some(text) = &self.text { + if let Some(dialog) = &self.dialog { + let text = Text::new( + TextFragment::new(dialog.text.as_str()) + .font(self.font) + .scale(Scale::uniform(40.0)), + ); + graphics::draw(context, &self.mesh, DrawParam::default())?; graphics::draw( context, - text, + &text, DrawParam::default().dest(Point2::new( self.conf.window_mode.width * 0.11, 2.6 * self.conf.window_mode.height / 4.0, @@ -99,5 +101,8 @@ impl DialogBox { pub fn give_dialogtree(&mut self, dialogtree: Option) { self.dialogtree = dialogtree; + if let Some(dialogtree) = &self.dialogtree { + self.dialog = dialogtree.dialogs.get(&0).cloned(); + } } } -- cgit v1.2.3