mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-11-25 16:28:42 -06:00
rename ChatManager
to ChatHistory
This commit is contained in:
parent
907a5845fa
commit
e373aa758c
|
@ -19,11 +19,11 @@ pub enum ChatMessage {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Unique, Default)]
|
#[derive(Unique, Default)]
|
||||||
pub struct ChatManager {
|
pub struct ChatHistory {
|
||||||
pub messages: Vec<ChatMessage>,
|
pub messages: Vec<ChatMessage>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ChatManager {
|
impl ChatHistory {
|
||||||
pub fn add_message(&mut self, message: ChatMessage) {
|
pub fn add_message(&mut self, message: ChatMessage) {
|
||||||
self.messages.push(message);
|
self.messages.push(message);
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ impl ChatManager {
|
||||||
pub fn init_chat_manager(
|
pub fn init_chat_manager(
|
||||||
storages: AllStoragesView,
|
storages: AllStoragesView,
|
||||||
) {
|
) {
|
||||||
let mut chat_manager = ChatManager::default();
|
let mut chat_manager = ChatHistory::default();
|
||||||
chat_manager.add_system_message("Welcome to Kubi! Chat messages will appear here".to_string());
|
chat_manager.add_system_message("Welcome to Kubi! Chat messages will appear here".to_string());
|
||||||
storages.add_unique(chat_manager);
|
storages.add_unique(chat_manager);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ use kubi_shared::networking::{
|
||||||
channels::Channel,
|
channels::Channel,
|
||||||
};
|
};
|
||||||
use rand::prelude::*;
|
use rand::prelude::*;
|
||||||
use crate::{chat::ChatManager, player::{spawn_local_player_multiplayer, spawn_remote_player_multiplayer}};
|
use crate::{chat::ChatHistory, player::{spawn_local_player_multiplayer, spawn_remote_player_multiplayer}};
|
||||||
use super::{UdpClient, NetworkEvent};
|
use super::{UdpClient, NetworkEvent};
|
||||||
|
|
||||||
const USERNAME_BANK: &[&str] = &[
|
const USERNAME_BANK: &[&str] = &[
|
||||||
|
@ -96,7 +96,7 @@ pub fn check_server_hello_response(
|
||||||
log::info!("Joined the server!");
|
log::info!("Joined the server!");
|
||||||
|
|
||||||
// Send chat message
|
// Send chat message
|
||||||
let mut chat = storages.borrow::<UniqueViewMut<ChatManager>>().unwrap();
|
let mut chat = storages.borrow::<UniqueViewMut<ChatHistory>>().unwrap();
|
||||||
chat.add_player_join(client_id, username);
|
chat.add_player_join(client_id, username);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ use kubi_shared::{
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use crate::{
|
use crate::{
|
||||||
chat::ChatManager,
|
chat::ChatHistory,
|
||||||
events::player_actions::PlayerActionEvent,
|
events::player_actions::PlayerActionEvent,
|
||||||
player::spawn_remote_player_multiplayer,
|
player::spawn_remote_player_multiplayer,
|
||||||
};
|
};
|
||||||
|
@ -97,7 +97,7 @@ pub fn receive_player_connect_events(
|
||||||
for message in messages {
|
for message in messages {
|
||||||
let ServerToClientMessage::PlayerConnected { init } = message else { unreachable!() };
|
let ServerToClientMessage::PlayerConnected { init } = message else { unreachable!() };
|
||||||
log::info!("player connected: {} (id {})", init.username, init.client_id);
|
log::info!("player connected: {} (id {})", init.username, init.client_id);
|
||||||
let mut chat = storages.borrow::<UniqueViewMut<ChatManager>>().unwrap();
|
let mut chat = storages.borrow::<UniqueViewMut<ChatHistory>>().unwrap();
|
||||||
chat.add_player_join(init.client_id, init.username.clone());
|
chat.add_player_join(init.client_id, init.username.clone());
|
||||||
drop(chat);
|
drop(chat);
|
||||||
spawn_remote_player_multiplayer(&mut storages, init);
|
spawn_remote_player_multiplayer(&mut storages, init);
|
||||||
|
@ -132,7 +132,7 @@ pub fn receive_player_disconnect_events(
|
||||||
};
|
};
|
||||||
|
|
||||||
let username = storages.get::<&Username>(ent_id).unwrap();
|
let username = storages.get::<&Username>(ent_id).unwrap();
|
||||||
let mut chat = storages.borrow::<UniqueViewMut<ChatManager>>().unwrap();
|
let mut chat = storages.borrow::<UniqueViewMut<ChatHistory>>().unwrap();
|
||||||
chat.add_player_leave(id, username.0.to_string());
|
chat.add_player_leave(id, username.0.to_string());
|
||||||
|
|
||||||
drop(chat);
|
drop(chat);
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
use hui::{color, element::{container::Container, text::Text, UiElementExt}, layout::Alignment, size};
|
use hui::{color, element::{container::Container, text::Text, UiElementExt}, layout::Alignment, size};
|
||||||
use shipyard::{NonSendSync, UniqueView, UniqueViewMut};
|
use shipyard::{NonSendSync, UniqueView, UniqueViewMut};
|
||||||
use crate::{chat::{ChatManager, ChatMessage}, hui_integration::UiState, rendering::WindowSize};
|
use crate::{chat::{ChatHistory, ChatMessage}, hui_integration::UiState, rendering::WindowSize};
|
||||||
|
|
||||||
pub fn render_chat(
|
pub fn render_chat(
|
||||||
mut hui: NonSendSync<UniqueViewMut<UiState>>,
|
mut hui: NonSendSync<UniqueViewMut<UiState>>,
|
||||||
size: UniqueView<WindowSize>,
|
size: UniqueView<WindowSize>,
|
||||||
chat: UniqueView<ChatManager>,
|
chat: UniqueView<ChatHistory>,
|
||||||
) {
|
) {
|
||||||
let messages = chat.get_messages();
|
let messages = chat.get_messages();
|
||||||
if messages.is_empty() { return }
|
if messages.is_empty() { return }
|
||||||
|
|
Loading…
Reference in a new issue