mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
New group UI functions
This commit is contained in:
@ -65,7 +65,7 @@ VoxygenLocalization(
|
|||||||
"common.create": "Create",
|
"common.create": "Create",
|
||||||
"common.okay": "Okay",
|
"common.okay": "Okay",
|
||||||
"common.accept": "Accept",
|
"common.accept": "Accept",
|
||||||
"common.reject": "Reject",
|
"common.decline": "Decline",
|
||||||
"common.disclaimer": "Disclaimer",
|
"common.disclaimer": "Disclaimer",
|
||||||
"common.cancel": "Cancel",
|
"common.cancel": "Cancel",
|
||||||
"common.none": "None",
|
"common.none": "None",
|
||||||
@ -386,6 +386,8 @@ magically infused items?"#,
|
|||||||
"gameinput.autowalk": "Auto Walk",
|
"gameinput.autowalk": "Auto Walk",
|
||||||
"gameinput.dance": "Dance",
|
"gameinput.dance": "Dance",
|
||||||
"gameinput.select": "Select Entity",
|
"gameinput.select": "Select Entity",
|
||||||
|
"gameinput.acceptgroupinvite": "Accept Group Invite",
|
||||||
|
"gameinput.declinegroupinvite": "Decline Group Invite",
|
||||||
|
|
||||||
/// End GameInput section
|
/// End GameInput section
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ use common::{
|
|||||||
character::CharacterItem,
|
character::CharacterItem,
|
||||||
comp::{
|
comp::{
|
||||||
self, ControlAction, ControlEvent, Controller, ControllerInputs, GroupManip,
|
self, ControlAction, ControlEvent, Controller, ControllerInputs, GroupManip,
|
||||||
InventoryManip, InventoryUpdateEvent,
|
InventoryManip, InventoryUpdateEvent, group,
|
||||||
},
|
},
|
||||||
msg::{
|
msg::{
|
||||||
validate_chat_msg, ChatMsgValidationError, ClientMsg, ClientState, Notification,
|
validate_chat_msg, ChatMsgValidationError, ClientMsg, ClientState, Notification,
|
||||||
@ -34,7 +34,7 @@ use common::{
|
|||||||
use futures_executor::block_on;
|
use futures_executor::block_on;
|
||||||
use futures_timer::Delay;
|
use futures_timer::Delay;
|
||||||
use futures_util::{select, FutureExt};
|
use futures_util::{select, FutureExt};
|
||||||
use hashbrown::{HashMap, HashSet};
|
use hashbrown::HashMap;
|
||||||
use image::DynamicImage;
|
use image::DynamicImage;
|
||||||
use network::{
|
use network::{
|
||||||
Network, Participant, Pid, ProtocolAddr, Stream, PROMISES_CONSISTENCY, PROMISES_ORDERED,
|
Network, Participant, Pid, ProtocolAddr, Stream, PROMISES_CONSISTENCY, PROMISES_ORDERED,
|
||||||
@ -74,7 +74,6 @@ pub struct Client {
|
|||||||
pub server_info: ServerInfo,
|
pub server_info: ServerInfo,
|
||||||
pub world_map: (Arc<DynamicImage>, Vec2<u32>),
|
pub world_map: (Arc<DynamicImage>, Vec2<u32>),
|
||||||
pub player_list: HashMap<Uid, PlayerInfo>,
|
pub player_list: HashMap<Uid, PlayerInfo>,
|
||||||
pub group_members: HashSet<Uid>,
|
|
||||||
pub character_list: CharacterList,
|
pub character_list: CharacterList,
|
||||||
pub active_character_id: Option<i32>,
|
pub active_character_id: Option<i32>,
|
||||||
recipe_book: RecipeBook,
|
recipe_book: RecipeBook,
|
||||||
@ -82,6 +81,7 @@ pub struct Client {
|
|||||||
|
|
||||||
group_invite: Option<Uid>,
|
group_invite: Option<Uid>,
|
||||||
group_leader: Option<Uid>,
|
group_leader: Option<Uid>,
|
||||||
|
group_members: HashMap<Uid, group::Role>,
|
||||||
|
|
||||||
_network: Network,
|
_network: Network,
|
||||||
participant: Option<Participant>,
|
participant: Option<Participant>,
|
||||||
@ -212,7 +212,7 @@ impl Client {
|
|||||||
server_info,
|
server_info,
|
||||||
world_map,
|
world_map,
|
||||||
player_list: HashMap::new(),
|
player_list: HashMap::new(),
|
||||||
group_members: HashSet::new(),
|
group_members: HashMap::new(),
|
||||||
character_list: CharacterList::default(),
|
character_list: CharacterList::default(),
|
||||||
active_character_id: None,
|
active_character_id: None,
|
||||||
recipe_book,
|
recipe_book,
|
||||||
@ -434,11 +434,15 @@ impl Client {
|
|||||||
|
|
||||||
pub fn group_invite(&self) -> Option<Uid> { self.group_invite }
|
pub fn group_invite(&self) -> Option<Uid> { self.group_invite }
|
||||||
|
|
||||||
pub fn group_leader(&self) -> Option<Uid> { self.group_leader }
|
pub fn group_info(&self) -> Option<(String, Uid)> { self.group_leader.map(|l| ("TODO".into(), l)) }
|
||||||
|
|
||||||
|
pub fn group_members(&self) -> &HashMap<Uid, group::Role> { &self.group_members }
|
||||||
|
|
||||||
pub fn send_group_invite(&mut self, invitee: Uid) {
|
pub fn send_group_invite(&mut self, invitee: Uid) {
|
||||||
self.singleton_stream
|
self.singleton_stream
|
||||||
.send(ClientMsg::ControlEvent(ControlEvent::GroupManip( GroupManip::Invite(invitee) )))
|
.send(ClientMsg::ControlEvent(ControlEvent::GroupManip(
|
||||||
|
GroupManip::Invite(invitee),
|
||||||
|
)))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -448,37 +452,42 @@ impl Client {
|
|||||||
self.singleton_stream
|
self.singleton_stream
|
||||||
.send(ClientMsg::ControlEvent(ControlEvent::GroupManip(
|
.send(ClientMsg::ControlEvent(ControlEvent::GroupManip(
|
||||||
GroupManip::Accept,
|
GroupManip::Accept,
|
||||||
))).unwrap();
|
)))
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reject_group_invite(&mut self) {
|
pub fn decline_group_invite(&mut self) {
|
||||||
// Clear invite
|
// Clear invite
|
||||||
self.group_invite.take();
|
self.group_invite.take();
|
||||||
self.singleton_stream
|
self.singleton_stream
|
||||||
.send(ClientMsg::ControlEvent(ControlEvent::GroupManip(
|
.send(ClientMsg::ControlEvent(ControlEvent::GroupManip(
|
||||||
GroupManip::Reject,
|
GroupManip::Decline,
|
||||||
))).unwrap();
|
)))
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn leave_group(&mut self) {
|
pub fn leave_group(&mut self) {
|
||||||
self.singleton_stream
|
self.singleton_stream
|
||||||
.send(ClientMsg::ControlEvent(ControlEvent::GroupManip(
|
.send(ClientMsg::ControlEvent(ControlEvent::GroupManip(
|
||||||
GroupManip::Leave,
|
GroupManip::Leave,
|
||||||
))).unwrap();
|
)))
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn kick_from_group(&mut self, uid: Uid) {
|
pub fn kick_from_group(&mut self, uid: Uid) {
|
||||||
self.singleton_stream
|
self.singleton_stream
|
||||||
.send(ClientMsg::ControlEvent(ControlEvent::GroupManip(
|
.send(ClientMsg::ControlEvent(ControlEvent::GroupManip(
|
||||||
GroupManip::Kick(uid),
|
GroupManip::Kick(uid),
|
||||||
))).unwrap();
|
)))
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn assign_group_leader(&mut self, uid: Uid) {
|
pub fn assign_group_leader(&mut self, uid: Uid) {
|
||||||
self.singleton_stream
|
self.singleton_stream
|
||||||
.send(ClientMsg::ControlEvent(ControlEvent::GroupManip(
|
.send(ClientMsg::ControlEvent(ControlEvent::GroupManip(
|
||||||
GroupManip::AssignLeader(uid),
|
GroupManip::AssignLeader(uid),
|
||||||
))).unwrap();
|
)))
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_mounted(&self) -> bool {
|
pub fn is_mounted(&self) -> bool {
|
||||||
@ -993,47 +1002,47 @@ impl Client {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
ServerMsg::GroupUpdate(change_notification) => {
|
ServerMsg::GroupUpdate(change_notification) => {
|
||||||
use comp::group::ChangeNotification::*;
|
use comp::group::ChangeNotification::*;
|
||||||
// Note: we use a hashmap since this would not work with entities outside
|
// Note: we use a hashmap since this would not work with entities outside
|
||||||
// the view distance
|
// the view distance
|
||||||
match change_notification {
|
match change_notification {
|
||||||
Added(uid) => {
|
Added(uid, role) => {
|
||||||
if !self.group_members.insert(uid) {
|
if self.group_members.insert(uid, role) == Some(role) {
|
||||||
warn!(
|
warn!(
|
||||||
"Received msg to add uid {} to the group members but they \
|
"Received msg to add uid {} to the group members but they \
|
||||||
were already there",
|
were already there",
|
||||||
uid
|
uid
|
||||||
);
|
);
|
||||||
}
|
|
||||||
},
|
|
||||||
Removed(uid) => {
|
|
||||||
if !self.group_members.remove(&uid) {
|
|
||||||
warn!(
|
|
||||||
"Received msg to remove uid {} from group members but by \
|
|
||||||
they weren't in there!",
|
|
||||||
uid
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
NewLeader(leader) => {
|
|
||||||
self.group_leader = Some(leader);
|
|
||||||
},
|
|
||||||
NewGroup { leader, members } => {
|
|
||||||
self.group_leader = Some(leader);
|
|
||||||
self.group_members = members.into_iter().collect();
|
|
||||||
// Currently add/remove messages treat client as an implicit member
|
|
||||||
// of the group whereas this message explicitly included them so to
|
|
||||||
// be consistent for now we will remove the client from the
|
|
||||||
// received hashset
|
|
||||||
if let Some(uid) = self.uid() {
|
|
||||||
self.group_members.remove(&uid);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
NoGroup => {
|
|
||||||
self.group_leader = None;
|
|
||||||
self.group_members = HashSet::new();
|
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
Removed(uid) => {
|
||||||
|
if self.group_members.remove(&uid).is_none() {
|
||||||
|
warn!(
|
||||||
|
"Received msg to remove uid {} from group members but by they \
|
||||||
|
weren't in there!",
|
||||||
|
uid
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
NewLeader(leader) => {
|
||||||
|
self.group_leader = Some(leader);
|
||||||
|
},
|
||||||
|
NewGroup { leader, members } => {
|
||||||
|
self.group_leader = Some(leader);
|
||||||
|
self.group_members = members.into_iter().collect();
|
||||||
|
// Currently add/remove messages treat client as an implicit member
|
||||||
|
// of the group whereas this message explicitly included them so to
|
||||||
|
// be consistent for now we will remove the client from the
|
||||||
|
// received hashset
|
||||||
|
if let Some(uid) = self.uid() {
|
||||||
|
self.group_members.remove(&uid);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
NoGroup => {
|
||||||
|
self.group_leader = None;
|
||||||
|
self.group_members = HashMap::new();
|
||||||
|
},
|
||||||
|
}
|
||||||
},
|
},
|
||||||
ServerMsg::GroupInvite(uid) => {
|
ServerMsg::GroupInvite(uid) => {
|
||||||
self.group_invite = Some(uid);
|
self.group_invite = Some(uid);
|
||||||
@ -1189,9 +1198,7 @@ impl Client {
|
|||||||
pub fn entity(&self) -> EcsEntity { self.entity }
|
pub fn entity(&self) -> EcsEntity { self.entity }
|
||||||
|
|
||||||
/// Get the player's Uid.
|
/// Get the player's Uid.
|
||||||
pub fn uid(&self) -> Option<Uid> {
|
pub fn uid(&self) -> Option<Uid> { self.state.read_component_copied(self.entity) }
|
||||||
self.state.read_component_copied(self.entity)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get the client state
|
/// Get the client state
|
||||||
pub fn get_client_state(&self) -> ClientState { self.client_state }
|
pub fn get_client_state(&self) -> ClientState { self.client_state }
|
||||||
|
@ -22,7 +22,7 @@ pub enum InventoryManip {
|
|||||||
pub enum GroupManip {
|
pub enum GroupManip {
|
||||||
Invite(Uid),
|
Invite(Uid),
|
||||||
Accept,
|
Accept,
|
||||||
Reject,
|
Decline,
|
||||||
Leave,
|
Leave,
|
||||||
Kick(Uid),
|
Kick(Uid),
|
||||||
AssignLeader(Uid),
|
AssignLeader(Uid),
|
||||||
|
@ -11,7 +11,6 @@ use tracing::{error, warn};
|
|||||||
// - no support for more complex group structures
|
// - no support for more complex group structures
|
||||||
// - lack of complex enemy npc integration
|
// - lack of complex enemy npc integration
|
||||||
// - relies on careful management of groups to maintain a valid state
|
// - relies on careful management of groups to maintain a valid state
|
||||||
// - clients don't know what entities are their pets
|
|
||||||
// - the possesion rod could probably wreck this
|
// - the possesion rod could probably wreck this
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
|
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||||
@ -35,15 +34,21 @@ pub struct GroupInfo {
|
|||||||
pub name: String,
|
pub name: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
|
||||||
|
pub enum Role {
|
||||||
|
Member,
|
||||||
|
Pet,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub enum ChangeNotification<E> {
|
pub enum ChangeNotification<E> {
|
||||||
// :D
|
// :D
|
||||||
Added(E),
|
Added(E, Role),
|
||||||
// :(
|
// :(
|
||||||
Removed(E),
|
Removed(E),
|
||||||
NewLeader(E),
|
NewLeader(E),
|
||||||
// Use to put in a group overwriting existing group
|
// Use to put in a group overwriting existing group
|
||||||
NewGroup { leader: E, members: Vec<E> },
|
NewGroup { leader: E, members: Vec<(E, Role)> },
|
||||||
// No longer in a group
|
// No longer in a group
|
||||||
NoGroup,
|
NoGroup,
|
||||||
}
|
}
|
||||||
@ -54,14 +59,17 @@ pub enum ChangeNotification<E> {
|
|||||||
impl<E> ChangeNotification<E> {
|
impl<E> ChangeNotification<E> {
|
||||||
pub fn try_map<T>(self, f: impl Fn(E) -> Option<T>) -> Option<ChangeNotification<T>> {
|
pub fn try_map<T>(self, f: impl Fn(E) -> Option<T>) -> Option<ChangeNotification<T>> {
|
||||||
match self {
|
match self {
|
||||||
Self::Added(e) => f(e).map(ChangeNotification::Added),
|
Self::Added(e, r) => f(e).map(|t| ChangeNotification::Added(t, r)),
|
||||||
Self::Removed(e) => f(e).map(ChangeNotification::Removed),
|
Self::Removed(e) => f(e).map(ChangeNotification::Removed),
|
||||||
Self::NewLeader(e) => f(e).map(ChangeNotification::NewLeader),
|
Self::NewLeader(e) => f(e).map(ChangeNotification::NewLeader),
|
||||||
// Note just discards members that fail map
|
// Note just discards members that fail map
|
||||||
Self::NewGroup { leader, members } => {
|
Self::NewGroup { leader, members } => {
|
||||||
f(leader).map(|leader| ChangeNotification::NewGroup {
|
f(leader).map(|leader| ChangeNotification::NewGroup {
|
||||||
leader,
|
leader,
|
||||||
members: members.into_iter().filter_map(f).collect(),
|
members: members
|
||||||
|
.into_iter()
|
||||||
|
.filter_map(|(e, r)| f(e).map(|t| (t, r)))
|
||||||
|
.collect(),
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
Self::NoGroup => Some(ChangeNotification::NoGroup),
|
Self::NoGroup => Some(ChangeNotification::NoGroup),
|
||||||
@ -79,23 +87,21 @@ pub struct GroupManager {
|
|||||||
groups: Slab<GroupInfo>,
|
groups: Slab<GroupInfo>,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gather list of pets of the group member + member themselves
|
// Gather list of pets of the group member
|
||||||
// Note: iterating through all entities here could become slow at higher entity
|
// Note: iterating through all entities here could become slow at higher entity
|
||||||
// counts
|
// counts
|
||||||
fn with_pets(
|
fn pets(
|
||||||
entity: specs::Entity,
|
entity: specs::Entity,
|
||||||
uid: Uid,
|
uid: Uid,
|
||||||
alignments: &Alignments,
|
alignments: &Alignments,
|
||||||
entities: &specs::Entities,
|
entities: &specs::Entities,
|
||||||
) -> Vec<specs::Entity> {
|
) -> Vec<specs::Entity> {
|
||||||
let mut list = (entities, alignments)
|
(entities, alignments)
|
||||||
.join()
|
.join()
|
||||||
.filter_map(|(e, a)| {
|
.filter_map(|(e, a)| {
|
||||||
matches!(a, Alignment::Owned(owner) if *owner == uid && e != entity).then_some(e)
|
matches!(a, Alignment::Owned(owner) if *owner == uid && e != entity).then_some(e)
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>()
|
||||||
list.push(entity);
|
|
||||||
list
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns list of current members of a group
|
/// Returns list of current members of a group
|
||||||
@ -103,10 +109,23 @@ pub fn members<'a>(
|
|||||||
group: Group,
|
group: Group,
|
||||||
groups: impl Join<Type = &'a Group> + 'a,
|
groups: impl Join<Type = &'a Group> + 'a,
|
||||||
entities: &'a specs::Entities,
|
entities: &'a specs::Entities,
|
||||||
) -> impl Iterator<Item = specs::Entity> + 'a {
|
alignments: &'a Alignments,
|
||||||
(entities, groups)
|
uids: &'a Uids,
|
||||||
|
) -> impl Iterator<Item = (specs::Entity, Role)> + 'a {
|
||||||
|
(entities, groups, alignments, uids)
|
||||||
.join()
|
.join()
|
||||||
.filter_map(move |(e, g)| (*g == group).then_some(e))
|
.filter_map(move |(e, g, a, u)| {
|
||||||
|
(*g == group).then(|| {
|
||||||
|
(
|
||||||
|
e,
|
||||||
|
if matches!(a, Alignment::Owned(owner) if owner != u) {
|
||||||
|
Role::Pet
|
||||||
|
} else {
|
||||||
|
Role::Member
|
||||||
|
},
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: optimize add/remove for massive NPC groups
|
// TODO: optimize add/remove for massive NPC groups
|
||||||
@ -194,23 +213,30 @@ impl GroupManager {
|
|||||||
new_group
|
new_group
|
||||||
});
|
});
|
||||||
|
|
||||||
let member_plus_pets = with_pets(new_member, new_member_uid, alignments, entities);
|
let new_pets = pets(new_member, new_member_uid, alignments, entities);
|
||||||
|
|
||||||
// Inform
|
// Inform
|
||||||
members(group, &*groups, entities).for_each(|a| {
|
members(group, &*groups, entities, alignments, uids).for_each(|(e, role)| match role {
|
||||||
member_plus_pets.iter().for_each(|b| {
|
Role::Member => {
|
||||||
notifier(a, ChangeNotification::Added(*b));
|
notifier(e, ChangeNotification::Added(new_member, Role::Member));
|
||||||
notifier(*b, ChangeNotification::Added(a));
|
notifier(new_member, ChangeNotification::Added(e, Role::Member));
|
||||||
})
|
|
||||||
|
new_pets.iter().for_each(|p| {
|
||||||
|
notifier(e, ChangeNotification::Added(*p, Role::Pet));
|
||||||
|
})
|
||||||
|
},
|
||||||
|
Role::Pet => {
|
||||||
|
notifier(new_member, ChangeNotification::Added(e, Role::Pet));
|
||||||
|
},
|
||||||
});
|
});
|
||||||
// Note: pets not informed
|
|
||||||
notifier(new_member, ChangeNotification::NewLeader(leader));
|
notifier(new_member, ChangeNotification::NewLeader(leader));
|
||||||
|
|
||||||
// Add group id for new member and pets
|
// Add group id for new member and pets
|
||||||
// Unwrap should not fail since we just found these entities and they should
|
// Unwrap should not fail since we just found these entities and they should
|
||||||
// still exist
|
// still exist
|
||||||
// Note: if there is an issue replace with a warn
|
// Note: if there is an issue replace with a warn
|
||||||
member_plus_pets.iter().for_each(|e| {
|
let _ = groups.insert(new_member, group).unwrap();
|
||||||
|
new_pets.iter().for_each(|e| {
|
||||||
let _ = groups.insert(*e, group).unwrap();
|
let _ = groups.insert(*e, group).unwrap();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -221,6 +247,8 @@ impl GroupManager {
|
|||||||
owner: specs::Entity,
|
owner: specs::Entity,
|
||||||
groups: &mut GroupsMut,
|
groups: &mut GroupsMut,
|
||||||
entities: &specs::Entities,
|
entities: &specs::Entities,
|
||||||
|
alignments: &Alignments,
|
||||||
|
uids: &Uids,
|
||||||
notifier: &mut impl FnMut(specs::Entity, ChangeNotification<specs::Entity>),
|
notifier: &mut impl FnMut(specs::Entity, ChangeNotification<specs::Entity>),
|
||||||
) {
|
) {
|
||||||
let group = match groups.get(owner).copied() {
|
let group = match groups.get(owner).copied() {
|
||||||
@ -235,17 +263,15 @@ impl GroupManager {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Inform
|
// Inform
|
||||||
members(group, &*groups, entities).for_each(|a| {
|
members(group, &*groups, entities, alignments, uids).for_each(|(e, role)| match role {
|
||||||
notifier(a, ChangeNotification::Added(pet));
|
Role::Member => {
|
||||||
notifier(pet, ChangeNotification::Added(a));
|
notifier(e, ChangeNotification::Added(pet, Role::Pet));
|
||||||
|
},
|
||||||
|
Role::Pet => {},
|
||||||
});
|
});
|
||||||
|
|
||||||
// Add
|
// Add
|
||||||
groups.insert(pet, group).unwrap();
|
groups.insert(pet, group).unwrap();
|
||||||
|
|
||||||
if let Some(info) = self.group_info(group) {
|
|
||||||
notifier(pet, ChangeNotification::NewLeader(info.leader));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn leave_group(
|
pub fn leave_group(
|
||||||
@ -341,32 +367,30 @@ impl GroupManager {
|
|||||||
.for_each(|(owner, pets)| {
|
.for_each(|(owner, pets)| {
|
||||||
if let Some(owner) = owner {
|
if let Some(owner) = owner {
|
||||||
if !pets.is_empty() {
|
if !pets.is_empty() {
|
||||||
let mut members = pets.clone();
|
let mut members =
|
||||||
members.push(owner);
|
pets.iter().map(|e| (*e, Role::Pet)).collect::<Vec<_>>();
|
||||||
|
members.push((owner, Role::Member));
|
||||||
|
|
||||||
// New group
|
// New group
|
||||||
let new_group = self.create_group(owner);
|
let new_group = self.create_group(owner);
|
||||||
for &member in &members {
|
for (member, _) in &members {
|
||||||
groups.insert(member, new_group).unwrap();
|
groups.insert(*member, new_group).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
let notification = ChangeNotification::NewGroup {
|
notifier(owner, ChangeNotification::NewGroup {
|
||||||
leader: owner,
|
leader: owner,
|
||||||
members,
|
members,
|
||||||
};
|
});
|
||||||
|
|
||||||
// TODO: don't clone
|
|
||||||
notifier(owner, notification.clone());
|
|
||||||
pets.into_iter()
|
|
||||||
.for_each(|pet| notifier(pet, notification.clone()));
|
|
||||||
} else {
|
} else {
|
||||||
// If no pets just remove group
|
// If no pets just remove group
|
||||||
groups.remove(owner);
|
groups.remove(owner);
|
||||||
notifier(owner, ChangeNotification::NoGroup)
|
notifier(owner, ChangeNotification::NoGroup)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
pets.into_iter()
|
// Owner not found, potentially the were removed from the world
|
||||||
.for_each(|pet| notifier(pet, ChangeNotification::NoGroup));
|
pets.into_iter().for_each(|pet| {
|
||||||
|
groups.remove(pet);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@ -378,36 +402,47 @@ impl GroupManager {
|
|||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
let leaving = with_pets(member, leaving_member_uid, alignments, entities);
|
let leaving_pets = pets(member, leaving_member_uid, alignments, entities);
|
||||||
|
|
||||||
// If pets and not about to be deleted form new group
|
// If pets and not about to be deleted form new group
|
||||||
if leaving.len() > 1 && !to_be_deleted {
|
if !leaving_pets.is_empty() && !to_be_deleted {
|
||||||
let new_group = self.create_group(member);
|
let new_group = self.create_group(member);
|
||||||
|
|
||||||
let notification = ChangeNotification::NewGroup {
|
notifier(member, ChangeNotification::NewGroup {
|
||||||
leader: member,
|
leader: member,
|
||||||
members: leaving.clone(),
|
members: leaving_pets
|
||||||
};
|
.iter()
|
||||||
|
.map(|p| (*p, Role::Pet))
|
||||||
|
.chain(std::iter::once((member, Role::Member)))
|
||||||
|
.collect(),
|
||||||
|
});
|
||||||
|
|
||||||
leaving.iter().for_each(|&e| {
|
let _ = groups.insert(member, new_group).unwrap();
|
||||||
|
leaving_pets.iter().for_each(|&e| {
|
||||||
let _ = groups.insert(e, new_group).unwrap();
|
let _ = groups.insert(e, new_group).unwrap();
|
||||||
notifier(e, notification.clone());
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
leaving.iter().for_each(|&e| {
|
let _ = groups.remove(member);
|
||||||
|
notifier(member, ChangeNotification::NoGroup);
|
||||||
|
leaving_pets.iter().for_each(|&e| {
|
||||||
let _ = groups.remove(e);
|
let _ = groups.remove(e);
|
||||||
notifier(e, ChangeNotification::NoGroup);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(info) = self.group_info(group) {
|
if let Some(info) = self.group_info(group) {
|
||||||
// Inform remaining members
|
// Inform remaining members
|
||||||
let mut num_members = 0;
|
let mut num_members = 0;
|
||||||
members(group, &*groups, entities).for_each(|a| {
|
members(group, &*groups, entities, alignments, uids).for_each(|(e, role)| {
|
||||||
num_members += 1;
|
num_members += 1;
|
||||||
leaving.iter().for_each(|b| {
|
match role {
|
||||||
notifier(a, ChangeNotification::Removed(*b));
|
Role::Member => {
|
||||||
})
|
notifier(e, ChangeNotification::Removed(member));
|
||||||
|
leaving_pets.iter().for_each(|p| {
|
||||||
|
notifier(e, ChangeNotification::Removed(*p));
|
||||||
|
})
|
||||||
|
},
|
||||||
|
Role::Pet => {},
|
||||||
|
}
|
||||||
});
|
});
|
||||||
// If leader is the last one left then disband the group
|
// If leader is the last one left then disband the group
|
||||||
// Assumes last member is the leader
|
// Assumes last member is the leader
|
||||||
@ -430,6 +465,8 @@ impl GroupManager {
|
|||||||
new_leader: specs::Entity,
|
new_leader: specs::Entity,
|
||||||
groups: &Groups,
|
groups: &Groups,
|
||||||
entities: &specs::Entities,
|
entities: &specs::Entities,
|
||||||
|
alignments: &Alignments,
|
||||||
|
uids: &Uids,
|
||||||
mut notifier: impl FnMut(specs::Entity, ChangeNotification<specs::Entity>),
|
mut notifier: impl FnMut(specs::Entity, ChangeNotification<specs::Entity>),
|
||||||
) {
|
) {
|
||||||
let group = match groups.get(new_leader) {
|
let group = match groups.get(new_leader) {
|
||||||
@ -441,8 +478,9 @@ impl GroupManager {
|
|||||||
self.groups[group.0 as usize].leader = new_leader;
|
self.groups[group.0 as usize].leader = new_leader;
|
||||||
|
|
||||||
// Point to new leader
|
// Point to new leader
|
||||||
members(group, groups, entities).for_each(|e| {
|
members(group, &*groups, entities, alignments, uids).for_each(|(e, role)| match role {
|
||||||
notifier(e, ChangeNotification::NewLeader(new_leader));
|
Role::Member => notifier(e, ChangeNotification::NewLeader(new_leader)),
|
||||||
|
Role::Pet => {},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -569,6 +569,8 @@ fn handle_spawn(
|
|||||||
target,
|
target,
|
||||||
&mut state.ecs().write_storage(),
|
&mut state.ecs().write_storage(),
|
||||||
&state.ecs().entities(),
|
&state.ecs().entities(),
|
||||||
|
&state.ecs().read_storage(),
|
||||||
|
&uids,
|
||||||
&mut |entity, group_change| {
|
&mut |entity, group_change| {
|
||||||
clients
|
clients
|
||||||
.get_mut(entity)
|
.get_mut(entity)
|
||||||
|
@ -136,7 +136,7 @@ pub fn handle_group(server: &mut Server, entity: specs::Entity, manip: GroupMani
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
GroupManip::Reject => {
|
GroupManip::Decline => {
|
||||||
let mut clients = state.ecs().write_storage::<Client>();
|
let mut clients = state.ecs().write_storage::<Client>();
|
||||||
if let Some(inviter) = clients
|
if let Some(inviter) = clients
|
||||||
.get_mut(entity)
|
.get_mut(entity)
|
||||||
@ -144,8 +144,8 @@ pub fn handle_group(server: &mut Server, entity: specs::Entity, manip: GroupMani
|
|||||||
{
|
{
|
||||||
// Inform inviter of rejection
|
// Inform inviter of rejection
|
||||||
if let Some(client) = clients.get_mut(inviter) {
|
if let Some(client) = clients.get_mut(inviter) {
|
||||||
// TODO: say who rejected the invite
|
// TODO: say who declined the invite
|
||||||
client.notify(ChatType::Meta.server_msg("Invite rejected".to_owned()));
|
client.notify(ChatType::Meta.server_msg("Invite declined".to_owned()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -296,6 +296,8 @@ pub fn handle_group(server: &mut Server, entity: specs::Entity, manip: GroupMani
|
|||||||
target,
|
target,
|
||||||
&groups,
|
&groups,
|
||||||
&state.ecs().entities(),
|
&state.ecs().entities(),
|
||||||
|
&state.ecs().read_storage(),
|
||||||
|
&uids,
|
||||||
|entity, group_change| {
|
|entity, group_change| {
|
||||||
clients
|
clients
|
||||||
.get_mut(entity)
|
.get_mut(entity)
|
||||||
|
@ -236,6 +236,8 @@ pub fn handle_inventory(server: &mut Server, entity: EcsEntity, manip: comp::Inv
|
|||||||
entity,
|
entity,
|
||||||
&mut state.ecs().write_storage(),
|
&mut state.ecs().write_storage(),
|
||||||
&state.ecs().entities(),
|
&state.ecs().entities(),
|
||||||
|
&state.ecs().read_storage(),
|
||||||
|
&uids,
|
||||||
&mut |entity, group_change| {
|
&mut |entity, group_change| {
|
||||||
clients
|
clients
|
||||||
.get_mut(entity)
|
.get_mut(entity)
|
||||||
|
@ -57,6 +57,8 @@ pub fn handle_exit_ingame(server: &mut Server, entity: EcsEntity) {
|
|||||||
new_entity,
|
new_entity,
|
||||||
&state.ecs().read_storage(),
|
&state.ecs().read_storage(),
|
||||||
&state.ecs().entities(),
|
&state.ecs().entities(),
|
||||||
|
&state.ecs().read_storage(),
|
||||||
|
&state.ecs().read_storage(),
|
||||||
// Nothing actually changing
|
// Nothing actually changing
|
||||||
|_, _| {},
|
|_, _| {},
|
||||||
);
|
);
|
||||||
|
@ -5,8 +5,8 @@ use crate::{
|
|||||||
};
|
};
|
||||||
use common::{
|
use common::{
|
||||||
comp::{
|
comp::{
|
||||||
Admin, AdminList, CanBuild, ChatMode, UnresolvedChatMsg, ChatType, ControlEvent, Controller,
|
Admin, AdminList, CanBuild, ChatMode, ChatType, ControlEvent, Controller, ForceUpdate, Ori,
|
||||||
ForceUpdate, Ori, Player, Pos, Stats, Vel,
|
Player, Pos, Stats, UnresolvedChatMsg, Vel,
|
||||||
},
|
},
|
||||||
event::{EventBus, ServerEvent},
|
event::{EventBus, ServerEvent},
|
||||||
msg::{
|
msg::{
|
||||||
|
@ -1,13 +1,16 @@
|
|||||||
use super::{img_ids::Imgs, Show, TEXT_COLOR, TEXT_COLOR_3, TEXT_COLOR_GREY, UI_MAIN};
|
use super::{img_ids::Imgs, Show, TEXT_COLOR, TEXT_COLOR_3, TEXT_COLOR_GREY, UI_MAIN};
|
||||||
|
|
||||||
use crate::{i18n::VoxygenLocalization, ui::fonts::ConrodVoxygenFonts};
|
use crate::{
|
||||||
|
i18n::VoxygenLocalization, settings::Settings, ui::fonts::ConrodVoxygenFonts, window::GameInput,
|
||||||
|
};
|
||||||
use client::{self, Client};
|
use client::{self, Client};
|
||||||
use common::{
|
use common::{
|
||||||
comp::Stats,
|
comp::{group::Role, Stats},
|
||||||
sync::{Uid, WorldSyncExt},
|
sync::{Uid, WorldSyncExt},
|
||||||
};
|
};
|
||||||
use conrod_core::{
|
use conrod_core::{
|
||||||
color,
|
color,
|
||||||
|
position::{Place, Relative},
|
||||||
widget::{self, Button, Image, Rectangle, Scrollbar, Text},
|
widget::{self, Button, Image, Rectangle, Scrollbar, Text},
|
||||||
widget_ids, Colorable, Labelable, Positionable, Sizeable, Widget, WidgetCommon,
|
widget_ids, Colorable, Labelable, Positionable, Sizeable, Widget, WidgetCommon,
|
||||||
};
|
};
|
||||||
@ -25,60 +28,51 @@ widget_ids! {
|
|||||||
btn_link,
|
btn_link,
|
||||||
btn_kick,
|
btn_kick,
|
||||||
btn_leave,
|
btn_leave,
|
||||||
|
scroll_area,
|
||||||
|
scrollbar,
|
||||||
members[],
|
members[],
|
||||||
invite_bubble,
|
invite_bubble,
|
||||||
bubble_frame,
|
bubble_frame,
|
||||||
btn_accept,
|
btn_accept,
|
||||||
btn_decline,
|
btn_decline,
|
||||||
// TEST
|
|
||||||
test_leader,
|
|
||||||
test_member1,
|
|
||||||
test_member2,
|
|
||||||
test_member3,
|
|
||||||
test_member4,
|
|
||||||
test_member5,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct State {
|
pub struct State {
|
||||||
ids: Ids,
|
ids: Ids,
|
||||||
// Holds the time when selection is made since this selection can be overriden
|
|
||||||
// by selecting an entity in-game
|
|
||||||
selected_uid: Option<(Uid, Instant)>,
|
|
||||||
// Selected group member
|
// Selected group member
|
||||||
selected_member: Option<Uid>,
|
selected_member: Option<Uid>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(WidgetCommon)]
|
#[derive(WidgetCommon)]
|
||||||
pub struct Group<'a> {
|
pub struct Group<'a> {
|
||||||
show: &'a Show,
|
show: &'a mut Show,
|
||||||
client: &'a Client,
|
client: &'a Client,
|
||||||
|
settings: &'a Settings,
|
||||||
imgs: &'a Imgs,
|
imgs: &'a Imgs,
|
||||||
fonts: &'a ConrodVoxygenFonts,
|
fonts: &'a ConrodVoxygenFonts,
|
||||||
localized_strings: &'a std::sync::Arc<VoxygenLocalization>,
|
localized_strings: &'a std::sync::Arc<VoxygenLocalization>,
|
||||||
|
|
||||||
selected_entity: Option<(specs::Entity, Instant)>,
|
|
||||||
|
|
||||||
#[conrod(common_builder)]
|
#[conrod(common_builder)]
|
||||||
common: widget::CommonBuilder,
|
common: widget::CommonBuilder,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Group<'a> {
|
impl<'a> Group<'a> {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
show: &'a Show,
|
show: &'a mut Show,
|
||||||
client: &'a Client,
|
client: &'a Client,
|
||||||
|
settings: &'a Settings,
|
||||||
imgs: &'a Imgs,
|
imgs: &'a Imgs,
|
||||||
fonts: &'a ConrodVoxygenFonts,
|
fonts: &'a ConrodVoxygenFonts,
|
||||||
localized_strings: &'a std::sync::Arc<VoxygenLocalization>,
|
localized_strings: &'a std::sync::Arc<VoxygenLocalization>,
|
||||||
selected_entity: Option<(specs::Entity, Instant)>,
|
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
show,
|
show,
|
||||||
client,
|
client,
|
||||||
|
settings,
|
||||||
imgs,
|
imgs,
|
||||||
fonts,
|
fonts,
|
||||||
localized_strings,
|
localized_strings,
|
||||||
selected_entity,
|
|
||||||
common: widget::CommonBuilder::default(),
|
common: widget::CommonBuilder::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -87,7 +81,7 @@ impl<'a> Group<'a> {
|
|||||||
pub enum Event {
|
pub enum Event {
|
||||||
Close,
|
Close,
|
||||||
Accept,
|
Accept,
|
||||||
Reject,
|
Decline,
|
||||||
Kick(Uid),
|
Kick(Uid),
|
||||||
LeaveGroup,
|
LeaveGroup,
|
||||||
AssignLeader(Uid),
|
AssignLeader(Uid),
|
||||||
@ -101,7 +95,6 @@ impl<'a> Widget for Group<'a> {
|
|||||||
fn init_state(&self, id_gen: widget::id::Generator) -> Self::State {
|
fn init_state(&self, id_gen: widget::id::Generator) -> Self::State {
|
||||||
Self::State {
|
Self::State {
|
||||||
ids: Ids::new(id_gen),
|
ids: Ids::new(id_gen),
|
||||||
selected_uid: None,
|
|
||||||
selected_member: None,
|
selected_member: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -114,23 +107,63 @@ impl<'a> Widget for Group<'a> {
|
|||||||
|
|
||||||
let mut events = Vec::new();
|
let mut events = Vec::new();
|
||||||
|
|
||||||
let player_leader = true;
|
// Don't show pets
|
||||||
let in_group = true;
|
let group_members = self
|
||||||
let open_invite = false;
|
.client
|
||||||
|
.group_members()
|
||||||
|
.iter()
|
||||||
|
.filter_map(|(u, r)| match r {
|
||||||
|
Role::Member => Some(u),
|
||||||
|
Role::Pet => None,
|
||||||
|
})
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
if in_group || open_invite {
|
// Not considered in group for ui purposes if it is just pets
|
||||||
|
let in_group = !group_members.is_empty();
|
||||||
|
|
||||||
|
// Helper
|
||||||
|
let uid_to_name_text = |uid, client: &Client| match client.player_list.get(&uid) {
|
||||||
|
Some(player_info) => player_info
|
||||||
|
.character
|
||||||
|
.as_ref()
|
||||||
|
.map_or_else(|| format!("Player<{}>", uid), |c| c.name.clone()),
|
||||||
|
None => client
|
||||||
|
.state()
|
||||||
|
.ecs()
|
||||||
|
.entity_from_uid(uid.0)
|
||||||
|
.and_then(|entity| {
|
||||||
|
client
|
||||||
|
.state()
|
||||||
|
.ecs()
|
||||||
|
.read_storage::<Stats>()
|
||||||
|
.get(entity)
|
||||||
|
.map(|stats| stats.name.clone())
|
||||||
|
})
|
||||||
|
.unwrap_or_else(|| format!("Npc<{}>", uid)),
|
||||||
|
};
|
||||||
|
|
||||||
|
let open_invite = self.client.group_invite();
|
||||||
|
|
||||||
|
let my_uid = self.client.uid();
|
||||||
|
|
||||||
|
// TODO show something to the player when they click on the group button while
|
||||||
|
// they are not in a group so that it doesn't look like the button is
|
||||||
|
// broken
|
||||||
|
|
||||||
|
if in_group || open_invite.is_some() {
|
||||||
// Frame
|
// Frame
|
||||||
Rectangle::fill_with([220.0, 230.0], color::Color::Rgba(0.0, 0.0, 0.0, 0.8))
|
Rectangle::fill_with([220.0, 230.0], color::Color::Rgba(0.0, 0.0, 0.0, 0.8))
|
||||||
.bottom_left_with_margins_on(ui.window, 220.0, 10.0)
|
.bottom_left_with_margins_on(ui.window, 220.0, 10.0)
|
||||||
.set(state.ids.bg, ui);
|
.set(state.ids.bg, ui);
|
||||||
if open_invite {
|
if open_invite.is_some() {
|
||||||
// yellow animated border
|
// yellow animated border
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Buttons
|
// Buttons
|
||||||
if in_group {
|
if let Some((group_name, leader)) = self.client.group_info().filter(|_| in_group) {
|
||||||
Text::new("Group Name")
|
let selected = state.selected_member;
|
||||||
|
Text::new(&group_name)
|
||||||
.mid_top_with_margin_on(state.ids.bg, 2.0)
|
.mid_top_with_margin_on(state.ids.bg, 2.0)
|
||||||
.font_size(20)
|
.font_size(20)
|
||||||
.font_id(self.fonts.cyri.conrod_id)
|
.font_id(self.fonts.cyri.conrod_id)
|
||||||
@ -144,7 +177,7 @@ impl<'a> Widget for Group<'a> {
|
|||||||
.label("Add to Friends")
|
.label("Add to Friends")
|
||||||
.label_color(TEXT_COLOR_GREY) // Change this when the friendslist is working
|
.label_color(TEXT_COLOR_GREY) // Change this when the friendslist is working
|
||||||
.label_font_id(self.fonts.cyri.conrod_id)
|
.label_font_id(self.fonts.cyri.conrod_id)
|
||||||
.label_font_size(self.fonts.cyri.scale(10))
|
.label_font_size(self.fonts.cyri.scale(10))
|
||||||
.set(state.ids.btn_friend, ui)
|
.set(state.ids.btn_friend, ui)
|
||||||
.was_clicked()
|
.was_clicked()
|
||||||
{};
|
{};
|
||||||
@ -153,176 +186,209 @@ impl<'a> Widget for Group<'a> {
|
|||||||
.bottom_right_with_margins_on(state.ids.bg, 5.0, 5.0)
|
.bottom_right_with_margins_on(state.ids.bg, 5.0, 5.0)
|
||||||
.hover_image(self.imgs.button_hover)
|
.hover_image(self.imgs.button_hover)
|
||||||
.press_image(self.imgs.button_press)
|
.press_image(self.imgs.button_press)
|
||||||
.label("Leave Group")
|
.label(&self.localized_strings.get("hud.group.leave"))
|
||||||
.label_color(TEXT_COLOR)
|
.label_color(TEXT_COLOR)
|
||||||
.label_font_id(self.fonts.cyri.conrod_id)
|
.label_font_id(self.fonts.cyri.conrod_id)
|
||||||
.label_font_size(self.fonts.cyri.scale(10))
|
.label_font_size(self.fonts.cyri.scale(10))
|
||||||
.set(state.ids.btn_leave, ui)
|
.set(state.ids.btn_leave, ui)
|
||||||
.was_clicked()
|
.was_clicked()
|
||||||
{};
|
{
|
||||||
|
events.push(Event::LeaveGroup);
|
||||||
|
};
|
||||||
// Group leader functions
|
// Group leader functions
|
||||||
if player_leader {
|
if my_uid == Some(leader) {
|
||||||
if Button::image(self.imgs.button)
|
if Button::image(self.imgs.button)
|
||||||
.w_h(90.0, 22.0)
|
.w_h(90.0, 22.0)
|
||||||
.mid_bottom_with_margin_on(state.ids.btn_friend, -27.0)
|
.mid_bottom_with_margin_on(state.ids.btn_friend, -27.0)
|
||||||
.hover_image(self.imgs.button_hover)
|
.hover_image(self.imgs.button_hover)
|
||||||
.press_image(self.imgs.button_press)
|
.press_image(self.imgs.button_press)
|
||||||
.label("Assign Leader")
|
.label(&self.localized_strings.get("hud.group.assign_leader"))
|
||||||
.label_color(TEXT_COLOR) // Grey when no player is selected
|
.label_color(if state.selected_member.is_some() {
|
||||||
.label_font_id(self.fonts.cyri.conrod_id)
|
TEXT_COLOR
|
||||||
.label_font_size(self.fonts.cyri.scale(10))
|
} else {
|
||||||
.set(state.ids.btn_leader, ui)
|
TEXT_COLOR_GREY
|
||||||
.was_clicked()
|
})
|
||||||
{};
|
.label_font_id(self.fonts.cyri.conrod_id)
|
||||||
if Button::image(self.imgs.button)
|
.label_font_size(self.fonts.cyri.scale(10))
|
||||||
.w_h(90.0, 22.0)
|
.set(state.ids.btn_leader, ui)
|
||||||
.mid_bottom_with_margin_on(state.ids.btn_leader, -27.0)
|
.was_clicked()
|
||||||
.hover_image(self.imgs.button)
|
{
|
||||||
.press_image(self.imgs.button)
|
if let Some(uid) = selected {
|
||||||
.label("Link Group")
|
events.push(Event::AssignLeader(uid));
|
||||||
.label_color(TEXT_COLOR_GREY) // Change this when the linking is working
|
state.update(|s| {
|
||||||
.label_font_id(self.fonts.cyri.conrod_id)
|
s.selected_member = None;
|
||||||
.label_font_size(self.fonts.cyri.scale(10))
|
});
|
||||||
.set(state.ids.btn_link, ui)
|
}
|
||||||
.was_clicked()
|
};
|
||||||
{};
|
if Button::image(self.imgs.button)
|
||||||
if Button::image(self.imgs.button)
|
.w_h(90.0, 22.0)
|
||||||
.w_h(90.0, 22.0)
|
.mid_bottom_with_margin_on(state.ids.btn_leader, -27.0)
|
||||||
.mid_bottom_with_margin_on(state.ids.btn_link, -27.0)
|
.hover_image(self.imgs.button)
|
||||||
.down_from(state.ids.btn_link, 5.0)
|
.press_image(self.imgs.button)
|
||||||
.hover_image(self.imgs.button_hover)
|
.label("Link Group") // TODO: Localize
|
||||||
.press_image(self.imgs.button_press)
|
.label_color(TEXT_COLOR_GREY) // Change this when the linking is working
|
||||||
.label("Kick")
|
.label_font_id(self.fonts.cyri.conrod_id)
|
||||||
.label_color(TEXT_COLOR) // Grey when no player is selected
|
.label_font_size(self.fonts.cyri.scale(10))
|
||||||
.label_font_id(self.fonts.cyri.conrod_id)
|
.set(state.ids.btn_link, ui)
|
||||||
.label_font_size(self.fonts.cyri.scale(10))
|
.was_clicked()
|
||||||
.set(state.ids.btn_kick, ui)
|
{};
|
||||||
.was_clicked()
|
if Button::image(self.imgs.button)
|
||||||
{};
|
.w_h(90.0, 22.0)
|
||||||
}
|
.mid_bottom_with_margin_on(state.ids.btn_link, -27.0)
|
||||||
// Group Members, only character names, cut long names when they exceed the button size
|
.down_from(state.ids.btn_link, 5.0)
|
||||||
// TODO Insert loop here
|
.hover_image(self.imgs.button_hover)
|
||||||
if Button::image(self.imgs.nothing) // if selected self.imgs.selection
|
.press_image(self.imgs.button_press)
|
||||||
.w_h(90.0, 22.0)
|
.label(&self.localized_strings.get("hud.group.kick"))
|
||||||
|
.label_color(if state.selected_member.is_some() {
|
||||||
|
TEXT_COLOR
|
||||||
|
} else {
|
||||||
|
TEXT_COLOR_GREY
|
||||||
|
})
|
||||||
|
.label_font_id(self.fonts.cyri.conrod_id)
|
||||||
|
.label_font_size(self.fonts.cyri.scale(10))
|
||||||
|
.set(state.ids.btn_kick, ui)
|
||||||
|
.was_clicked()
|
||||||
|
{
|
||||||
|
if let Some(uid) = selected {
|
||||||
|
events.push(Event::Kick(uid));
|
||||||
|
state.update(|s| {
|
||||||
|
s.selected_member = None;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
// Group Members, only character names, cut long names when they exceed the
|
||||||
|
// button size
|
||||||
|
let group_size = group_members.len() + 1;
|
||||||
|
if state.ids.members.len() < group_size {
|
||||||
|
state.update(|s| {
|
||||||
|
s.ids
|
||||||
|
.members
|
||||||
|
.resize(group_size, &mut ui.widget_id_generator())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
// Scrollable area for group member names
|
||||||
|
Rectangle::fill_with([110.0, 192.0], color::TRANSPARENT)
|
||||||
.top_left_with_margins_on(state.ids.bg, 30.0, 5.0)
|
.top_left_with_margins_on(state.ids.bg, 30.0, 5.0)
|
||||||
.hover_image(self.imgs.selection_hover)
|
.scroll_kids()
|
||||||
.press_image(self.imgs.selection_press)
|
.scroll_kids_vertically()
|
||||||
.label("Leader") // Grey when no player is selected
|
.set(state.ids.scroll_area, ui);
|
||||||
.label_color(TEXT_COLOR)
|
Scrollbar::y_axis(state.ids.scroll_area)
|
||||||
.label_font_id(self.fonts.cyri.conrod_id)
|
.thickness(5.0)
|
||||||
.label_font_size(self.fonts.cyri.scale(12))
|
.rgba(0.33, 0.33, 0.33, 1.0)
|
||||||
.set(state.ids.test_leader, ui)
|
.set(state.ids.scrollbar, ui);
|
||||||
.was_clicked()
|
// List member names
|
||||||
|
for (i, &uid) in self
|
||||||
|
.client
|
||||||
|
.uid()
|
||||||
|
.iter()
|
||||||
|
.chain(group_members.iter().copied())
|
||||||
|
.enumerate()
|
||||||
{
|
{
|
||||||
//Select the Leader
|
let selected = state.selected_member.map_or(false, |u| u == uid);
|
||||||
};
|
let char_name = uid_to_name_text(uid, &self.client);
|
||||||
if Button::image(self.imgs.nothing) // if selected self.imgs.selection
|
|
||||||
.w_h(90.0, 22.0)
|
|
||||||
.down_from(state.ids.test_leader, 10.0)
|
|
||||||
.hover_image(self.imgs.selection_hover)
|
|
||||||
.press_image(self.imgs.selection_press)
|
|
||||||
.label("Other Player")
|
|
||||||
.label_color(TEXT_COLOR)
|
|
||||||
.label_font_id(self.fonts.cyri.conrod_id)
|
|
||||||
.label_font_size(self.fonts.cyri.scale(12))
|
|
||||||
.set(state.ids.test_member1, ui)
|
|
||||||
.was_clicked()
|
|
||||||
{
|
|
||||||
// Select the group member
|
|
||||||
};
|
|
||||||
if Button::image(self.imgs.nothing) // if selected self.imgs.selection
|
|
||||||
.w_h(90.0, 22.0)
|
|
||||||
.down_from(state.ids.test_member1, 10.0)
|
|
||||||
.hover_image(self.imgs.selection_hover)
|
|
||||||
.press_image(self.imgs.selection_press)
|
|
||||||
.label("Other Player")
|
|
||||||
.label_color(TEXT_COLOR)
|
|
||||||
.label_font_id(self.fonts.cyri.conrod_id)
|
|
||||||
.label_font_size(self.fonts.cyri.scale(12))
|
|
||||||
.set(state.ids.test_member2, ui)
|
|
||||||
.was_clicked()
|
|
||||||
{
|
|
||||||
// Select the group member
|
|
||||||
};
|
|
||||||
if Button::image(self.imgs.nothing) // if selected self.imgs.selection
|
|
||||||
.w_h(90.0, 22.0)
|
|
||||||
.down_from(state.ids.test_member2, 10.0)
|
|
||||||
.hover_image(self.imgs.selection_hover)
|
|
||||||
.press_image(self.imgs.selection_press)
|
|
||||||
.label("Other Player")
|
|
||||||
.label_color(TEXT_COLOR)
|
|
||||||
.label_font_id(self.fonts.cyri.conrod_id)
|
|
||||||
.label_font_size(self.fonts.cyri.scale(12))
|
|
||||||
.set(state.ids.test_member3, ui)
|
|
||||||
.was_clicked()
|
|
||||||
{
|
|
||||||
// Select the group member
|
|
||||||
};
|
|
||||||
if Button::image(self.imgs.nothing) // if selected self.imgs.selection
|
|
||||||
.w_h(90.0, 22.0)
|
|
||||||
.down_from(state.ids.test_member3, 10.0)
|
|
||||||
.hover_image(self.imgs.selection_hover)
|
|
||||||
.press_image(self.imgs.selection_press)
|
|
||||||
.label("Other Player")
|
|
||||||
.label_color(TEXT_COLOR)
|
|
||||||
.label_font_id(self.fonts.cyri.conrod_id)
|
|
||||||
.label_font_size(self.fonts.cyri.scale(12))
|
|
||||||
.set(state.ids.test_member4, ui)
|
|
||||||
.was_clicked()
|
|
||||||
{
|
|
||||||
// Select the group member
|
|
||||||
};
|
|
||||||
if Button::image(self.imgs.nothing) // if selected self.imgs.selection
|
|
||||||
.w_h(90.0, 22.0)
|
|
||||||
.down_from(state.ids.test_member4, 10.0)
|
|
||||||
.hover_image(self.imgs.selection_hover)
|
|
||||||
.press_image(self.imgs.selection_press)
|
|
||||||
.label("Other Player")
|
|
||||||
.label_color(TEXT_COLOR)
|
|
||||||
.label_font_id(self.fonts.cyri.conrod_id)
|
|
||||||
.label_font_size(self.fonts.cyri.scale(12))
|
|
||||||
.set(state.ids.test_member5, ui)
|
|
||||||
.was_clicked()
|
|
||||||
{
|
|
||||||
// Select the group member
|
|
||||||
};
|
|
||||||
// Maximum of 6 Players/Npcs per Group
|
|
||||||
// Player pets count as group members, too. They are not counted into the maximum group size.
|
|
||||||
|
|
||||||
|
// TODO: Do something special visually if uid == leader
|
||||||
|
if Button::image(if selected {
|
||||||
|
self.imgs.selection
|
||||||
|
} else {
|
||||||
|
self.imgs.nothing
|
||||||
|
})
|
||||||
|
.w_h(100.0, 22.0)
|
||||||
|
.and(|w| {
|
||||||
|
if i == 0 {
|
||||||
|
w.top_left_with_margins_on(state.ids.scroll_area, 5.0, 0.0)
|
||||||
|
} else {
|
||||||
|
w.down_from(state.ids.members[i - 1], 10.0)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.hover_image(self.imgs.selection_hover)
|
||||||
|
.press_image(self.imgs.selection_press)
|
||||||
|
.crop_kids()
|
||||||
|
.label_x(Relative::Place(Place::Start(Some(4.0))))
|
||||||
|
.label(&char_name)
|
||||||
|
.label_color(TEXT_COLOR)
|
||||||
|
.label_font_id(self.fonts.cyri.conrod_id)
|
||||||
|
.label_font_size(self.fonts.cyri.scale(12))
|
||||||
|
.set(state.ids.members[i], ui)
|
||||||
|
.was_clicked()
|
||||||
|
{
|
||||||
|
// Do nothing when clicking yourself
|
||||||
|
if Some(uid) != my_uid {
|
||||||
|
// Select the group member
|
||||||
|
state.update(|s| {
|
||||||
|
s.selected_member = if selected { None } else { Some(uid) }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
// Maximum of 6 Players/Npcs per Group
|
||||||
|
// Player pets count as group members, too. They are not counted
|
||||||
|
// into the maximum group size.
|
||||||
}
|
}
|
||||||
if open_invite {
|
if let Some(invite_uid) = open_invite {
|
||||||
//self.show.group = true; Auto open group menu
|
self.show.group = true; // Auto open group menu
|
||||||
Text::new("Player wants to invite you!")
|
// TODO: add group name here too
|
||||||
|
// Invite text
|
||||||
|
let name = uid_to_name_text(invite_uid, &self.client);
|
||||||
|
let invite_text = self
|
||||||
|
.localized_strings
|
||||||
|
.get("hud.group.invite_to_join")
|
||||||
|
.replace("{name}", &name);
|
||||||
|
Text::new(&invite_text)
|
||||||
.mid_top_with_margin_on(state.ids.bg, 20.0)
|
.mid_top_with_margin_on(state.ids.bg, 20.0)
|
||||||
.font_size(20)
|
.font_size(20)
|
||||||
.font_id(self.fonts.cyri.conrod_id)
|
.font_id(self.fonts.cyri.conrod_id)
|
||||||
.color(TEXT_COLOR)
|
.color(TEXT_COLOR)
|
||||||
.set(state.ids.title, ui);
|
.set(state.ids.title, ui);
|
||||||
|
// Accept Button
|
||||||
|
let accept_key = self
|
||||||
|
.settings
|
||||||
|
.controls
|
||||||
|
.get_binding(GameInput::AcceptGroupInvite)
|
||||||
|
.map_or_else(|| "".into(), |key| key.to_string());
|
||||||
if Button::image(self.imgs.button)
|
if Button::image(self.imgs.button)
|
||||||
.w_h(90.0, 22.0)
|
.w_h(90.0, 22.0)
|
||||||
.bottom_left_with_margins_on(state.ids.bg, 15.0, 15.0)
|
.bottom_left_with_margins_on(state.ids.bg, 15.0, 15.0)
|
||||||
.hover_image(self.imgs.button)
|
.hover_image(self.imgs.button_hover)
|
||||||
.press_image(self.imgs.button)
|
.press_image(self.imgs.button_press)
|
||||||
.label("[U] Accept")
|
.label(&format!(
|
||||||
.label_color(TEXT_COLOR_GREY) // Change this when the friendslist is working
|
"[{}] {}",
|
||||||
|
&accept_key,
|
||||||
|
&self.localized_strings.get("common.accept")
|
||||||
|
))
|
||||||
|
.label_color(TEXT_COLOR)
|
||||||
.label_font_id(self.fonts.cyri.conrod_id)
|
.label_font_id(self.fonts.cyri.conrod_id)
|
||||||
.label_font_size(self.fonts.cyri.scale(15))
|
.label_font_size(self.fonts.cyri.scale(15))
|
||||||
.set(state.ids.btn_friend, ui)
|
.set(state.ids.btn_accept, ui)
|
||||||
.was_clicked()
|
.was_clicked()
|
||||||
{};
|
{
|
||||||
|
events.push(Event::Accept);
|
||||||
|
};
|
||||||
|
// Decline button
|
||||||
|
let decline_key = self
|
||||||
|
.settings
|
||||||
|
.controls
|
||||||
|
.get_binding(GameInput::DeclineGroupInvite)
|
||||||
|
.map_or_else(|| "".into(), |key| key.to_string());
|
||||||
if Button::image(self.imgs.button)
|
if Button::image(self.imgs.button)
|
||||||
.w_h(90.0, 22.0)
|
.w_h(90.0, 22.0)
|
||||||
.bottom_right_with_margins_on(state.ids.bg, 15.0, 15.0)
|
.bottom_right_with_margins_on(state.ids.bg, 15.0, 15.0)
|
||||||
.hover_image(self.imgs.button)
|
.hover_image(self.imgs.button_hover)
|
||||||
.press_image(self.imgs.button)
|
.press_image(self.imgs.button_press)
|
||||||
.label("[I] Decline")
|
.label(&format!(
|
||||||
.label_color(TEXT_COLOR_GREY) // Change this when the friendslist is working
|
"[{}] {}",
|
||||||
|
&decline_key,
|
||||||
|
&self.localized_strings.get("common.decline")
|
||||||
|
))
|
||||||
|
.label_color(TEXT_COLOR)
|
||||||
.label_font_id(self.fonts.cyri.conrod_id)
|
.label_font_id(self.fonts.cyri.conrod_id)
|
||||||
.label_font_size(self.fonts.cyri.scale(15))
|
.label_font_size(self.fonts.cyri.scale(15))
|
||||||
.set(state.ids.btn_friend, ui)
|
.set(state.ids.btn_decline, ui)
|
||||||
.was_clicked()
|
.was_clicked()
|
||||||
{};
|
{
|
||||||
|
events.push(Event::Decline);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
events
|
events
|
||||||
}
|
}
|
||||||
|
@ -310,7 +310,7 @@ pub enum Event {
|
|||||||
CraftRecipe(String),
|
CraftRecipe(String),
|
||||||
InviteMember(common::sync::Uid),
|
InviteMember(common::sync::Uid),
|
||||||
AcceptInvite,
|
AcceptInvite,
|
||||||
RejectInvite,
|
DeclineInvite,
|
||||||
KickMember(common::sync::Uid),
|
KickMember(common::sync::Uid),
|
||||||
LeaveGroup,
|
LeaveGroup,
|
||||||
AssignLeader(common::sync::Uid),
|
AssignLeader(common::sync::Uid),
|
||||||
@ -1083,7 +1083,7 @@ impl Hud {
|
|||||||
h,
|
h,
|
||||||
i,
|
i,
|
||||||
uid,
|
uid,
|
||||||
client.group_members.contains(uid),
|
client.group_members().contains_key(uid),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.filter(|(entity, pos, _, stats, _, _, _, _, hpfl, _, in_group)| {
|
.filter(|(entity, pos, _, stats, _, _, _, _, hpfl, _, in_group)| {
|
||||||
@ -1945,30 +1945,25 @@ impl Hud {
|
|||||||
self.show.open_social_tab(social_tab)
|
self.show.open_social_tab(social_tab)
|
||||||
},
|
},
|
||||||
social::Event::Invite(uid) => events.push(Event::InviteMember(uid)),
|
social::Event::Invite(uid) => events.push(Event::InviteMember(uid)),
|
||||||
social::Event::Accept => events.push(Event::AcceptInvite),
|
|
||||||
social::Event::Reject => events.push(Event::RejectInvite),
|
|
||||||
social::Event::Kick(uid) => events.push(Event::KickMember(uid)),
|
|
||||||
social::Event::LeaveGroup => events.push(Event::LeaveGroup),
|
|
||||||
social::Event::AssignLeader(uid) => events.push(Event::AssignLeader(uid)),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Group Window
|
// Group Window
|
||||||
if self.show.group {
|
if self.show.group {
|
||||||
for event in Group::new(
|
for event in Group::new(
|
||||||
&self.show,
|
&mut self.show,
|
||||||
client,
|
client,
|
||||||
|
&global_state.settings,
|
||||||
&self.imgs,
|
&self.imgs,
|
||||||
&self.fonts,
|
&self.fonts,
|
||||||
&self.voxygen_i18n,
|
&self.voxygen_i18n,
|
||||||
info.selected_entity,
|
|
||||||
)
|
)
|
||||||
.set(self.ids.group_window, ui_widgets)
|
.set(self.ids.group_window, ui_widgets)
|
||||||
{
|
{
|
||||||
match event {
|
match event {
|
||||||
group::Event::Close => self.show.social(false),
|
group::Event::Close => self.show.social(false),
|
||||||
group::Event::Accept => events.push(Event::AcceptInvite),
|
group::Event::Accept => events.push(Event::AcceptInvite),
|
||||||
group::Event::Reject => events.push(Event::RejectInvite),
|
group::Event::Decline => events.push(Event::DeclineInvite),
|
||||||
group::Event::Kick(uid) => events.push(Event::KickMember(uid)),
|
group::Event::Kick(uid) => events.push(Event::KickMember(uid)),
|
||||||
group::Event::LeaveGroup => events.push(Event::LeaveGroup),
|
group::Event::LeaveGroup => events.push(Event::LeaveGroup),
|
||||||
group::Event::AssignLeader(uid) => events.push(Event::AssignLeader(uid)),
|
group::Event::AssignLeader(uid) => events.push(Event::AssignLeader(uid)),
|
||||||
|
@ -2,16 +2,12 @@ use super::{img_ids::Imgs, Show, TEXT_COLOR, TEXT_COLOR_3, UI_MAIN};
|
|||||||
|
|
||||||
use crate::{i18n::VoxygenLocalization, ui::fonts::ConrodVoxygenFonts};
|
use crate::{i18n::VoxygenLocalization, ui::fonts::ConrodVoxygenFonts};
|
||||||
use client::{self, Client};
|
use client::{self, Client};
|
||||||
use common::{
|
use common::sync::Uid;
|
||||||
comp::Stats,
|
|
||||||
sync::{Uid, WorldSyncExt},
|
|
||||||
};
|
|
||||||
use conrod_core::{
|
use conrod_core::{
|
||||||
color,
|
color,
|
||||||
widget::{self, Button, Image, Rectangle, Scrollbar, Text},
|
widget::{self, Button, Image, Rectangle, Scrollbar, Text},
|
||||||
widget_ids, Colorable, Labelable, Positionable, Sizeable, Widget, WidgetCommon,
|
widget_ids, Colorable, Labelable, Positionable, Sizeable, Widget, WidgetCommon,
|
||||||
};
|
};
|
||||||
use specs::WorldExt;
|
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
widget_ids! {
|
widget_ids! {
|
||||||
@ -31,15 +27,7 @@ widget_ids! {
|
|||||||
friends_test,
|
friends_test,
|
||||||
faction_test,
|
faction_test,
|
||||||
player_names[],
|
player_names[],
|
||||||
group,
|
|
||||||
group_invite,
|
|
||||||
member_names[],
|
|
||||||
accept_invite_button,
|
|
||||||
reject_invite_button,
|
|
||||||
invite_button,
|
invite_button,
|
||||||
kick_button,
|
|
||||||
assign_leader_button,
|
|
||||||
leave_button,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,8 +36,6 @@ pub struct State {
|
|||||||
// Holds the time when selection is made since this selection can be overriden
|
// Holds the time when selection is made since this selection can be overriden
|
||||||
// by selecting an entity in-game
|
// by selecting an entity in-game
|
||||||
selected_uid: Option<(Uid, Instant)>,
|
selected_uid: Option<(Uid, Instant)>,
|
||||||
// Selected group member
|
|
||||||
selected_member: Option<Uid>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum SocialTab {
|
pub enum SocialTab {
|
||||||
@ -95,13 +81,8 @@ impl<'a> Social<'a> {
|
|||||||
|
|
||||||
pub enum Event {
|
pub enum Event {
|
||||||
Close,
|
Close,
|
||||||
ChangeSocialTab(SocialTab),
|
|
||||||
Invite(Uid),
|
Invite(Uid),
|
||||||
Accept,
|
ChangeSocialTab(SocialTab),
|
||||||
Reject,
|
|
||||||
Kick(Uid),
|
|
||||||
LeaveGroup,
|
|
||||||
AssignLeader(Uid),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Widget for Social<'a> {
|
impl<'a> Widget for Social<'a> {
|
||||||
@ -113,7 +94,6 @@ impl<'a> Widget for Social<'a> {
|
|||||||
Self::State {
|
Self::State {
|
||||||
ids: Ids::new(id_gen),
|
ids: Ids::new(id_gen),
|
||||||
selected_uid: None,
|
selected_uid: None,
|
||||||
selected_member: None,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -270,86 +250,11 @@ impl<'a> Widget for Social<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Text::new(&self.localized_strings.get("hud.group"))
|
// Invite Button
|
||||||
.down(10.0)
|
if self
|
||||||
.font_size(self.fonts.cyri.scale(20))
|
|
||||||
.font_id(self.fonts.cyri.conrod_id)
|
|
||||||
.color(TEXT_COLOR)
|
|
||||||
.set(state.ids.group, ui);
|
|
||||||
|
|
||||||
// Helper
|
|
||||||
let uid_to_name_text = |uid, client: &Client| match client.player_list.get(&uid) {
|
|
||||||
Some(player_info) => {
|
|
||||||
let alias = &player_info.player_alias;
|
|
||||||
let character_name_level = match &player_info.character {
|
|
||||||
Some(character) => format!("{} Lvl {}", &character.name, &character.level),
|
|
||||||
None => "<None>".to_string(), // character select or spectating
|
|
||||||
};
|
|
||||||
format!("[{}] {}", alias, character_name_level)
|
|
||||||
},
|
|
||||||
None => self
|
|
||||||
.client
|
|
||||||
.state()
|
|
||||||
.ecs()
|
|
||||||
.entity_from_uid(uid.0)
|
|
||||||
.and_then(|entity| {
|
|
||||||
self.client
|
|
||||||
.state()
|
|
||||||
.ecs()
|
|
||||||
.read_storage::<Stats>()
|
|
||||||
.get(entity)
|
|
||||||
.map(|stats| stats.name.clone())
|
|
||||||
})
|
|
||||||
.unwrap_or_else(|| format!("NPC Uid: {}", uid)),
|
|
||||||
};
|
|
||||||
|
|
||||||
// Accept/Reject Invite
|
|
||||||
if let Some(invite_uid) = self.client.group_invite() {
|
|
||||||
let name = uid_to_name_text(invite_uid, &self.client);
|
|
||||||
let text = self
|
|
||||||
.localized_strings
|
|
||||||
.get("hud.group.invite_to_join")
|
|
||||||
.replace("{name}", &name);
|
|
||||||
Text::new(&text)
|
|
||||||
.down(10.0)
|
|
||||||
.font_size(self.fonts.cyri.scale(15))
|
|
||||||
.font_id(self.fonts.cyri.conrod_id)
|
|
||||||
.color(TEXT_COLOR)
|
|
||||||
.set(state.ids.group_invite, ui);
|
|
||||||
if Button::image(self.imgs.button)
|
|
||||||
.down(3.0)
|
|
||||||
.w_h(150.0, 30.0)
|
|
||||||
.hover_image(self.imgs.button_hover)
|
|
||||||
.press_image(self.imgs.button_press)
|
|
||||||
.label(&self.localized_strings.get("common.accept"))
|
|
||||||
.label_y(conrod_core::position::Relative::Scalar(3.0))
|
|
||||||
.label_color(TEXT_COLOR)
|
|
||||||
.label_font_size(self.fonts.cyri.scale(15))
|
|
||||||
.label_font_id(self.fonts.cyri.conrod_id)
|
|
||||||
.set(state.ids.accept_invite_button, ui)
|
|
||||||
.was_clicked()
|
|
||||||
{
|
|
||||||
events.push(Event::Accept);
|
|
||||||
}
|
|
||||||
if Button::image(self.imgs.button)
|
|
||||||
.down(3.0)
|
|
||||||
.w_h(150.0, 30.0)
|
|
||||||
.hover_image(self.imgs.button_hover)
|
|
||||||
.press_image(self.imgs.button_press)
|
|
||||||
.label(&self.localized_strings.get("common.reject"))
|
|
||||||
.label_y(conrod_core::position::Relative::Scalar(3.0))
|
|
||||||
.label_color(TEXT_COLOR)
|
|
||||||
.label_font_size(self.fonts.cyri.scale(15))
|
|
||||||
.label_font_id(self.fonts.cyri.conrod_id)
|
|
||||||
.set(state.ids.reject_invite_button, ui)
|
|
||||||
.was_clicked()
|
|
||||||
{
|
|
||||||
events.push(Event::Reject);
|
|
||||||
}
|
|
||||||
} else if self // Invite Button
|
|
||||||
.client
|
.client
|
||||||
.group_leader()
|
.group_info()
|
||||||
.map_or(true, |l_uid| self.client.uid() == Some(l_uid))
|
.map_or(true, |(_, l_uid)| self.client.uid() == Some(l_uid))
|
||||||
{
|
{
|
||||||
let selected = state.selected_uid.map(|s| s.0).or_else(|| {
|
let selected = state.selected_uid.map(|s| s.0).or_else(|| {
|
||||||
self.selected_entity
|
self.selected_entity
|
||||||
@ -381,129 +286,6 @@ impl<'a> Widget for Social<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show group members
|
|
||||||
if let Some(leader) = self.client.group_leader() {
|
|
||||||
let group_size = self.client.group_members.len() + 1;
|
|
||||||
if state.ids.member_names.len() < group_size {
|
|
||||||
state.update(|s| {
|
|
||||||
s.ids
|
|
||||||
.member_names
|
|
||||||
.resize(group_size, &mut ui.widget_id_generator())
|
|
||||||
})
|
|
||||||
}
|
|
||||||
// List member names
|
|
||||||
for (i, &uid) in self
|
|
||||||
.client
|
|
||||||
.uid()
|
|
||||||
.iter()
|
|
||||||
.chain(self.client.group_members.iter())
|
|
||||||
.enumerate()
|
|
||||||
{
|
|
||||||
let selected = state.selected_member.map_or(false, |u| u == uid);
|
|
||||||
let text = uid_to_name_text(uid, &self.client);
|
|
||||||
let text = if selected {
|
|
||||||
format!("-> {}", &text)
|
|
||||||
} else {
|
|
||||||
text
|
|
||||||
};
|
|
||||||
let text = if uid == leader {
|
|
||||||
format!("{} (Leader)", &text)
|
|
||||||
} else {
|
|
||||||
text
|
|
||||||
};
|
|
||||||
Text::new(&text)
|
|
||||||
.down(3.0)
|
|
||||||
.font_size(self.fonts.cyri.scale(15))
|
|
||||||
.font_id(self.fonts.cyri.conrod_id)
|
|
||||||
.color(TEXT_COLOR)
|
|
||||||
.set(state.ids.member_names[i], ui);
|
|
||||||
// Check for click
|
|
||||||
if ui
|
|
||||||
.widget_input(state.ids.member_names[i])
|
|
||||||
.clicks()
|
|
||||||
.left()
|
|
||||||
.next()
|
|
||||||
.is_some()
|
|
||||||
{
|
|
||||||
state.update(|s| {
|
|
||||||
s.selected_member = if selected { None } else { Some(uid) }
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Show more buttons if leader
|
|
||||||
if self.client.uid() == Some(leader) {
|
|
||||||
let selected = state.selected_member;
|
|
||||||
// Kick
|
|
||||||
if Button::image(self.imgs.button)
|
|
||||||
.down(3.0)
|
|
||||||
.w_h(150.0, 30.0)
|
|
||||||
.hover_image(self.imgs.button_hover)
|
|
||||||
.press_image(self.imgs.button_press)
|
|
||||||
.label(&self.localized_strings.get("hud.group.kick"))
|
|
||||||
.label_y(conrod_core::position::Relative::Scalar(3.0))
|
|
||||||
.label_color(if selected.is_some() {
|
|
||||||
TEXT_COLOR
|
|
||||||
} else {
|
|
||||||
TEXT_COLOR_3
|
|
||||||
})
|
|
||||||
.label_font_size(self.fonts.cyri.scale(15))
|
|
||||||
.label_font_id(self.fonts.cyri.conrod_id)
|
|
||||||
.set(state.ids.kick_button, ui)
|
|
||||||
.was_clicked()
|
|
||||||
{
|
|
||||||
if let Some(uid) = selected {
|
|
||||||
events.push(Event::Kick(uid));
|
|
||||||
state.update(|s| {
|
|
||||||
s.selected_member = None;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Assign leader
|
|
||||||
if Button::image(self.imgs.button)
|
|
||||||
.down(3.0)
|
|
||||||
.w_h(150.0, 30.0)
|
|
||||||
.hover_image(self.imgs.button_hover)
|
|
||||||
.press_image(self.imgs.button_press)
|
|
||||||
.label(&self.localized_strings.get("hud.group.assign_leader"))
|
|
||||||
.label_y(conrod_core::position::Relative::Scalar(3.0))
|
|
||||||
.label_color(if selected.is_some() {
|
|
||||||
TEXT_COLOR
|
|
||||||
} else {
|
|
||||||
TEXT_COLOR_3
|
|
||||||
})
|
|
||||||
.label_font_size(self.fonts.cyri.scale(15))
|
|
||||||
.label_font_id(self.fonts.cyri.conrod_id)
|
|
||||||
.set(state.ids.assign_leader_button, ui)
|
|
||||||
.was_clicked()
|
|
||||||
{
|
|
||||||
if let Some(uid) = selected {
|
|
||||||
events.push(Event::AssignLeader(uid));
|
|
||||||
state.update(|s| {
|
|
||||||
s.selected_member = None;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Leave group button
|
|
||||||
if Button::image(self.imgs.button)
|
|
||||||
.down(3.0)
|
|
||||||
.w_h(150.0, 30.0)
|
|
||||||
.hover_image(self.imgs.button_hover)
|
|
||||||
.press_image(self.imgs.button_press)
|
|
||||||
.label(&self.localized_strings.get("hud.group.leave"))
|
|
||||||
.label_y(conrod_core::position::Relative::Scalar(3.0))
|
|
||||||
.label_color(TEXT_COLOR)
|
|
||||||
.label_font_size(self.fonts.cyri.scale(15))
|
|
||||||
.label_font_id(self.fonts.cyri.conrod_id)
|
|
||||||
.set(state.ids.leave_button, ui)
|
|
||||||
.was_clicked()
|
|
||||||
{
|
|
||||||
events.push(Event::LeaveGroup);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Friends Tab
|
// Friends Tab
|
||||||
|
@ -957,8 +957,8 @@ impl PlayState for SessionState {
|
|||||||
HudEvent::AcceptInvite => {
|
HudEvent::AcceptInvite => {
|
||||||
self.client.borrow_mut().accept_group_invite();
|
self.client.borrow_mut().accept_group_invite();
|
||||||
},
|
},
|
||||||
HudEvent::RejectInvite => {
|
HudEvent::DeclineInvite => {
|
||||||
self.client.borrow_mut().reject_group_invite();
|
self.client.borrow_mut().decline_group_invite();
|
||||||
},
|
},
|
||||||
HudEvent::KickMember(uid) => {
|
HudEvent::KickMember(uid) => {
|
||||||
self.client.borrow_mut().kick_from_group(uid);
|
self.client.borrow_mut().kick_from_group(uid);
|
||||||
|
@ -169,7 +169,9 @@ impl ControlSettings {
|
|||||||
GameInput::Slot9 => KeyMouse::Key(VirtualKeyCode::Key9),
|
GameInput::Slot9 => KeyMouse::Key(VirtualKeyCode::Key9),
|
||||||
GameInput::Slot10 => KeyMouse::Key(VirtualKeyCode::Q),
|
GameInput::Slot10 => KeyMouse::Key(VirtualKeyCode::Q),
|
||||||
GameInput::SwapLoadout => KeyMouse::Key(VirtualKeyCode::LAlt),
|
GameInput::SwapLoadout => KeyMouse::Key(VirtualKeyCode::LAlt),
|
||||||
GameInput::Select => KeyMouse::Key(VirtualKeyCode::I),
|
GameInput::Select => KeyMouse::Key(VirtualKeyCode::Y),
|
||||||
|
GameInput::AcceptGroupInvite => KeyMouse::Key(VirtualKeyCode::U),
|
||||||
|
GameInput::DeclineGroupInvite => KeyMouse::Key(VirtualKeyCode::I),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -236,6 +238,8 @@ impl Default for ControlSettings {
|
|||||||
GameInput::Slot10,
|
GameInput::Slot10,
|
||||||
GameInput::SwapLoadout,
|
GameInput::SwapLoadout,
|
||||||
GameInput::Select,
|
GameInput::Select,
|
||||||
|
GameInput::AcceptGroupInvite,
|
||||||
|
GameInput::DeclineGroupInvite,
|
||||||
];
|
];
|
||||||
for game_input in game_inputs {
|
for game_input in game_inputs {
|
||||||
new_settings.insert_binding(game_input, ControlSettings::default_binding(game_input));
|
new_settings.insert_binding(game_input, ControlSettings::default_binding(game_input));
|
||||||
|
@ -68,6 +68,8 @@ pub enum GameInput {
|
|||||||
AutoWalk,
|
AutoWalk,
|
||||||
CycleCamera,
|
CycleCamera,
|
||||||
Select,
|
Select,
|
||||||
|
AcceptGroupInvite,
|
||||||
|
DeclineGroupInvite,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GameInput {
|
impl GameInput {
|
||||||
@ -125,6 +127,8 @@ impl GameInput {
|
|||||||
GameInput::Slot10 => "gameinput.slot10",
|
GameInput::Slot10 => "gameinput.slot10",
|
||||||
GameInput::SwapLoadout => "gameinput.swaploadout",
|
GameInput::SwapLoadout => "gameinput.swaploadout",
|
||||||
GameInput::Select => "gameinput.select",
|
GameInput::Select => "gameinput.select",
|
||||||
|
GameInput::AcceptGroupInvite => "gameinput.acceptgroupinvite",
|
||||||
|
GameInput::DeclineGroupInvite => "gameinput.declinegroupinvite",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user