console/main/server: activate on receiving chat messages

This commit is contained in:
ice_iix 2021-01-24 16:38:44 -08:00
parent a37e1cf3f9
commit 5671c3ecdf
3 changed files with 14 additions and 0 deletions

View File

@ -290,6 +290,10 @@ impl Console {
self.active = !self.active;
}
pub fn activate(&mut self) {
self.active = true;
}
pub fn tick(
&mut self,
ui_container: &mut ui::Container,

View File

@ -559,6 +559,12 @@ fn tick_all(
game.screen_sys
.tick(delta, &mut game.renderer, &mut ui_container);
if let Some(received_chat_at) = game.server.received_chat_at {
if Instant::now().duration_since(received_chat_at).as_secs() < 5 {
game.console.lock().unwrap().activate()
// TODO: automatically deactivate the console after inactivity
}
}
game.console
.lock()
.unwrap()

View File

@ -25,6 +25,7 @@ use crate::types::Gamemode;
use crate::world;
use crate::world::block;
use cgmath::prelude::*;
use instant::Instant;
use log::{debug, error, info, warn};
use rand::{self, Rng};
use std::collections::HashMap;
@ -74,6 +75,7 @@ pub struct Server {
tick_timer: f64,
entity_tick_timer: f64,
pub received_chat_at: Option<Instant>,
sun_model: Option<sun::SunModel>,
target_info: target::Info,
@ -491,6 +493,7 @@ impl Server {
tick_timer: 0.0,
entity_tick_timer: 0.0,
received_chat_at: None,
sun_model: None,
target_info: target::Info::new(),
@ -1876,6 +1879,7 @@ impl Server {
_sender: Option<protocol::UUID>,
) {
info!("Received chat message: {}", message);
self.received_chat_at = Some(Instant::now());
}
fn load_block_entities(&mut self, block_entities: Vec<Option<crate::nbt::NamedTag>>) {