Skip to content

Commit

Permalink
add lil chat history withotu popup open
Browse files Browse the repository at this point in the history
  • Loading branch information
robtfm committed Oct 14, 2024
1 parent c92c6f1 commit cfdb228
Show file tree
Hide file tree
Showing 14 changed files with 637 additions and 286 deletions.
2 changes: 1 addition & 1 deletion assets/ui/avatar.dui
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
>
</bounds>
<div style="margin: 5px">
<med-text text="@name" />
<med-text text="@name" style="text-align: center;" />
</div>
</div>
</div>
Expand Down
18 changes: 13 additions & 5 deletions assets/ui/chat.dui
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
<define-template id="chat-history">
<div style="flex-grow: 1; min-height: 0px; width: 45vmin; min-width: 30vmin; justify-content: flex-end; flex-direction: column;">
<space />
<div id="chat-content" style="min-width: 100%; min-height: 0px; justify-content: flex-end; flex-direction: column; overflow-y: hidden;">
</div>
</div>
</define-template>

<define-template id="chat">
<bounds
style="display: none; width: 90vmin; min-width: 75vmin; flex-direction: column; margin: auto 0px 0px 0px;"
Expand All @@ -19,7 +27,7 @@
<tab-group id="tabs" style="justify-content: flex-start; width: 100%; flex-wrap: wrap-reverse;" tabs="@chat-tabs" onchanged="@tab-changed" initial="@initial-tab" edge-scale="1px 1px -0px 1px"/>
</div>
<div style="max-height: 31vmin; flex-direction: column;">
<div style="border: 0.2vmin; border-colorx: #b2a1bf; min-height: 0px;">
<div style="border: 0.2vmin; min-height: 0px;">
<vscroll id="chat-output" interact="true" start-position="end">
<div id="chat-output-inner" interact="true" style="flex-direction: column; justify-content: flex-end; width: 100%;" />
</vscroll>
Expand Down Expand Up @@ -115,14 +123,14 @@
</div>
</define-template>

<define-template id="me-chat-container">
<define-template id="chat-container-me">
<bounds
style="margin: 0px 2vmin 0px 5vmin;"
corner-size="2vmin"
blend-size="0.25vmin"
border-size="0.5vmin"
border-color="#7f569e"
color="#ccccff"
color="@color"
>
<div id="content" style="flex-grow: 1; align-self: center; flex-direction: column;" />
<div style="flex-direction: column; align-items: flex-end;">
Expand All @@ -132,14 +140,14 @@
</bounds>
</define-template>

<define-template id="other-chat-container">
<define-template id="chat-container-other">
<bounds
style="margin: 0px 7vmin 0px 0vmin;"
corner-size="2vmin"
blend-size="0.25vmin"
border-size="0.5vmin"
border-color="#7f569e"
color="#ccffcc"
color="@color"
>
<div style="flex-direction: column; align-items: flex-end;">
<space />
Expand Down
2 changes: 1 addition & 1 deletion assets/ui/minimap.dui
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<define-template id="minimap">
<bounds
style="flex-direction: column; position-type: absolute; left: 1vmin; top: 1vmin; width: 25vmin; overflow-x: hidden;"
style="flex-direction: column; left: 1vmin; top: 1vmin; width: 25vmin; overflow-x: hidden;"
corner-size="2vmin"
blend-size="0.25vmin"
border-size="1vmin"
Expand Down
6 changes: 3 additions & 3 deletions crates/avatar/src/colliders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use common::{
dynamics::{PLAYER_COLLIDER_HEIGHT, PLAYER_COLLIDER_OVERLAP, PLAYER_COLLIDER_RADIUS},
rpc::{RpcCall, RpcEventSender},
sets::SceneSets,
structs::{PrimaryCamera, ShowProfileEvent, ToolTips},
structs::{PrimaryCamera, ShowProfileEvent, ToolTips, TooltipSource},
util::{AsH160, FireEventEx},
};
use comms::{global_crdt::ForeignPlayer, profile::UserProfile};
Expand Down Expand Up @@ -129,7 +129,7 @@ fn update_avatar_collider_actions(
senders.push(sender.clone());
}

tooltips.0.remove("avatar_pointer");
tooltips.0.remove(&TooltipSource::Label("avatar_pointer"));

// check for scene ui
if !matches!(*ui_target, UiPointerTarget::None) {
Expand Down Expand Up @@ -209,7 +209,7 @@ fn update_avatar_collider_actions(
}

tooltips.0.insert(
"avatar_pointer",
TooltipSource::Label("avatar_pointer"),
vec![("Middle Click : Profile".to_owned(), true)],
);

Expand Down
8 changes: 7 additions & 1 deletion crates/common/src/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,14 @@ pub struct PrimaryCameraRes(pub Entity);
#[derive(Component)]
pub struct UiRoot;

#[derive(PartialEq, Eq, Hash, PartialOrd, Ord, Clone, Copy)]
pub enum TooltipSource {
Label(&'static str),
Entity(Entity),
}

#[derive(Resource, Default)]
pub struct ToolTips(pub HashMap<&'static str, Vec<(String, bool)>>);
pub struct ToolTips(pub HashMap<TooltipSource, Vec<(String, bool)>>);

// web3 authorization chain link
#[derive(Serialize, Deserialize, Clone, Debug)]
Expand Down
6 changes: 4 additions & 2 deletions crates/scene_runner/src/update_world/pointer_events.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use bevy::prelude::*;
use common::structs::ToolTips;
use common::structs::{ToolTips, TooltipSource};
use input_manager::InputMap;

use crate::update_scene::pointer_results::{PointerTarget, PointerTargetInfo};
Expand Down Expand Up @@ -74,5 +74,7 @@ fn hover_text(
}
}

tooltip.0.insert("pointer_events", texts);
tooltip
.0
.insert(TooltipSource::Label("pointer_events"), texts);
}
117 changes: 71 additions & 46 deletions crates/system_ui/src/chat/conversation_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ use wallet::Wallet;

use crate::chat::friends::PendingProfileUiImage;

use super::{friends::PrivateChat, ChatBox};
use super::friends::PrivateChat;

#[derive(Component)]
pub struct ChatContainer(pub Option<Address>);
pub struct ChatBubble(pub Option<Address>, pub Color);

#[allow(clippy::type_complexity)]
#[derive(SystemParam)]
pub struct ConversationManager<'w, 's> {
chatbox: Query<'w, 's, (Entity, Option<&'static Children>), With<ChatBox>>,
containers: Query<'w, 's, (&'static ChatContainer, &'static DuiEntities)>,
children: Query<'w, 's, &'static Children>,
containers: Query<'w, 's, (&'static ChatBubble, &'static DuiEntities)>,
commands: Commands<'w, 's>,
dui: Res<'w, DuiRegistry>,
wallet: Res<'w, Wallet>,
Expand All @@ -28,20 +28,26 @@ pub struct ConversationManager<'w, 's> {
's,
Option<(
u32,
Option<(Option<Address>, Entity)>,
Option<(Option<Address>, Entity)>,
Option<(Option<Address>, Color, (Entity, Entity))>,
Option<(Option<Address>, Color, (Entity, Entity))>,
)>,
>,
}

impl<'w, 's> ConversationManager<'w, 's> {
fn existing_container(&self, address: Option<Address>, historic: bool) -> Option<Entity> {
fn existing_bubble(
&self,
container: Entity,
address: Option<Address>,
color: Color,
historic: bool,
) -> Option<(Entity, Entity)> {
if let Some((frame, top, bottom)) = self.added_this_frame.as_ref() {
if *frame == self.frame.0 {
if let Some((existing_address, existing_entity)) =
if let Some((existing_address, existing_color, existing_entity)) =
if historic { top } else { bottom }
{
if *existing_address == address {
if *existing_address == address && *existing_color == color {
return Some(*existing_entity);
} else {
return None;
Expand All @@ -50,8 +56,7 @@ impl<'w, 's> ConversationManager<'w, 's> {
}
}

let (_, children) = self.chatbox.get_single().ok()?;
let children = children?;
let children = self.children.get(container).ok()?;

let potential_container = if historic {
children.iter().next()
Expand All @@ -60,16 +65,15 @@ impl<'w, 's> ConversationManager<'w, 's> {
}?;

let (potential_container, entities) = self.containers.get(*potential_container).ok()?;
(potential_container.0 == address).then_some(entities.named("content"))
(potential_container.0 == address && potential_container.1 == color)
.then_some((entities.root, entities.named("content")))
}

pub fn clear(&mut self) {
self.commands
.entity(self.chatbox.single().0)
.despawn_descendants();
pub fn clear(&mut self, container: Entity) {
self.commands.entity(container).despawn_descendants();
}

pub fn add_history_button(&mut self, chat_ent: Entity) {
pub fn add_history_button(&mut self, container: Entity, private_chat_ent: Entity) {
let button = self
.commands
.spawn_template(
Expand All @@ -87,7 +91,7 @@ impl<'w, 's> ConversationManager<'w, 's> {
if let Ok(parent) = parent.get(caller.0) {
commands.entity(parent.get()).despawn_recursive();
}
if let Ok(mut chat) = private_chats.get_mut(chat_ent) {
if let Ok(mut chat) = private_chats.get_mut(private_chat_ent) {
chat.wants_history_count = 10;
}
},
Expand All @@ -98,19 +102,29 @@ impl<'w, 's> ConversationManager<'w, 's> {
.root;

self.commands
.entity(self.chatbox.single().0)
.entity(container)
.insert_children(0, &[button]);
}

pub fn get_container(&mut self, address: Option<Address>, historic: bool) -> Entity {
if let Some(content) = self.existing_container(address, historic) {
return content;
pub fn get_bubble(
&mut self,
container: Entity,
address: Option<Address>,
color: Color,
historic: bool,
) -> (Entity, Entity) {
if let Some((bubble, content)) = self.existing_bubble(container, address, color, historic) {
return (bubble, content);
}

let components = if let Some(address) = address {
let components = self
.commands
.spawn_template(&self.dui, "other-chat-container", DuiProps::new())
.spawn_template(
&self.dui,
"chat-container-other",
DuiProps::new().with_prop("color", color),
)
.unwrap();
if address != Address::zero() {
self.commands
Expand All @@ -120,7 +134,11 @@ impl<'w, 's> ConversationManager<'w, 's> {
components
} else {
self.commands
.spawn_template(&self.dui, "me-chat-container", DuiProps::default())
.spawn_template(
&self.dui,
"chat-container-me",
DuiProps::new().with_prop("color", color),
)
.unwrap()
};
if let Some(address) = address.or_else(|| self.wallet.address()) {
Expand All @@ -137,13 +155,13 @@ impl<'w, 's> ConversationManager<'w, 's> {
));
}
}
self.commands
.entity(components.root)
.insert(ChatContainer(address));

let bubble = components.root;
let content = components.named("content");

let chatbox = self.chatbox.get_single().unwrap().0;
self.commands
.entity(bubble)
.insert(ChatBubble(address, color));

let added = self.added_this_frame.get_or_insert_with(Default::default);
if added.0 != self.frame.0 {
Expand All @@ -153,24 +171,34 @@ impl<'w, 's> ConversationManager<'w, 's> {
}
if historic {
self.commands
.entity(chatbox)
.insert_children(0, &[components.root]);
added.1 = Some((address, content));
.entity(container)
.insert_children(0, &[bubble]);
added.1 = Some((address, color, (bubble, content)));
} else {
self.commands
.entity(chatbox)
.push_children(&[components.root]);
added.2 = Some((address, content));
self.commands.entity(container).push_children(&[bubble]);
added.2 = Some((address, color, (bubble, content)));
}

debug!("{:?} -> new {}", address, content);
content
debug!("{:?} -> new {:?}", address, (bubble, content));
(bubble, content)
}

pub fn add_message(&mut self, sender: Option<Address>, message: impl ToString, historic: bool) {
pub fn add_message(
&mut self,
container: Entity,
sender: Option<Address>,
color: Color,
message: impl ToString,
historic: bool,
) -> (Entity, Entity) {
let me_speaking = sender.is_none() || self.wallet.address() == sender;
let container = self.get_container((!me_speaking).then(|| sender.unwrap()), historic);
debug!("container: {container:?}");
let (bubble, content) = self.get_bubble(
container,
(!me_speaking).then(|| sender.unwrap()),
color,
historic,
);
debug!("container: {content:?}");

let message_body = message.to_string();
let message = self
Expand Down Expand Up @@ -209,14 +237,11 @@ impl<'w, 's> ConversationManager<'w, 's> {
.unwrap()
.root;
if historic {
self.commands
.entity(container)
.insert_children(0, &[message]);
self.commands.entity(content).insert_children(0, &[message]);
} else {
self.commands
.entity(container)
.try_push_children(&[message]);
self.commands.entity(content).try_push_children(&[message]);
}
debug!("added");
(bubble, message)
}
}
Loading

0 comments on commit cfdb228

Please sign in to comment.