mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Merge branch 'chat-world-after-group' into 'master'
after leaving a group, set chat mode to world Closes #958 See merge request veloren/veloren!2001
This commit is contained in:
commit
08b901490d
@ -179,6 +179,14 @@ impl<G> GenericChatMsg<G> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_group(&self) -> Option<&G> {
|
||||||
|
match &self.chat_type {
|
||||||
|
ChatType::GroupMeta(g) => Some(&g),
|
||||||
|
ChatType::Group(_, g) => Some(&g),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn to_bubble(&self) -> Option<(SpeechBubble, Uid)> {
|
pub fn to_bubble(&self) -> Option<(SpeechBubble, Uid)> {
|
||||||
let icon = self.icon();
|
let icon = self.icon();
|
||||||
if let ChatType::Npc(from, r) | ChatType::NpcSay(from, r) = self.chat_type {
|
if let ChatType::Npc(from, r) | ChatType::NpcSay(from, r) = self.chat_type {
|
||||||
|
@ -451,11 +451,15 @@ impl StateExt for State {
|
|||||||
|target, a: &comp::Pos, b: &comp::Pos| a.0.distance_squared(b.0) < target * target;
|
|target, a: &comp::Pos, b: &comp::Pos| a.0.distance_squared(b.0) < target * target;
|
||||||
|
|
||||||
let group_manager = ecs.read_resource::<comp::group::GroupManager>();
|
let group_manager = ecs.read_resource::<comp::group::GroupManager>();
|
||||||
let resolved_msg = msg.clone().map_group(|group_id| {
|
|
||||||
group_manager
|
let group_info = msg
|
||||||
.group_info(group_id)
|
.get_group()
|
||||||
.map_or_else(|| "???".into(), |i| i.name.clone())
|
.map(|g| group_manager.group_info(*g))
|
||||||
});
|
.flatten();
|
||||||
|
|
||||||
|
let resolved_msg = msg
|
||||||
|
.clone()
|
||||||
|
.map_group(|_| group_info.map_or_else(|| "???".to_string(), |i| i.name.clone()));
|
||||||
|
|
||||||
match &msg.chat_type {
|
match &msg.chat_type {
|
||||||
comp::ChatType::Offline(_)
|
comp::ChatType::Offline(_)
|
||||||
@ -544,17 +548,29 @@ impl StateExt for State {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
comp::ChatType::GroupMeta(g) | comp::ChatType::Group(_, g) => {
|
comp::ChatType::Group(from, g) => {
|
||||||
for (client, group) in (
|
if group_info.is_none() {
|
||||||
&ecs.read_storage::<Client>(),
|
// group not found, reply with command error
|
||||||
&ecs.read_storage::<comp::Group>(),
|
let reply = comp::ChatMsg {
|
||||||
)
|
chat_type: comp::ChatType::CommandError,
|
||||||
.join()
|
message: "You are using group chat but do not belong to a group. Use \
|
||||||
{
|
/world or /region to change chat."
|
||||||
if g == group {
|
.into(),
|
||||||
client.send_fallible(ServerGeneral::ChatMsg(resolved_msg.clone()));
|
};
|
||||||
|
|
||||||
|
if let Some((client, _)) =
|
||||||
|
(&ecs.read_storage::<Client>(), &ecs.read_storage::<Uid>())
|
||||||
|
.join()
|
||||||
|
.find(|(_, uid)| *uid == from)
|
||||||
|
{
|
||||||
|
client.send_fallible(ServerGeneral::ChatMsg(reply));
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
send_to_group(g, ecs, &resolved_msg);
|
||||||
|
},
|
||||||
|
comp::ChatType::GroupMeta(g) => {
|
||||||
|
send_to_group(g, ecs, &resolved_msg);
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -653,3 +669,16 @@ impl StateExt for State {
|
|||||||
res
|
res
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn send_to_group(g: &comp::Group, ecs: &specs::World, msg: &comp::ChatMsg) {
|
||||||
|
for (client, group) in (
|
||||||
|
&ecs.read_storage::<Client>(),
|
||||||
|
&ecs.read_storage::<comp::Group>(),
|
||||||
|
)
|
||||||
|
.join()
|
||||||
|
{
|
||||||
|
if g == group {
|
||||||
|
client.send_fallible(ServerGeneral::ChatMsg(msg.clone()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user