console/main/server: activate on receiving chat messages
This commit is contained in:
parent
a37e1cf3f9
commit
5671c3ecdf
|
@ -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,
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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>>) {
|
||||
|
|
Loading…
Reference in New Issue