Don't show own char in group menu, handle accept/decline key events

This commit is contained in:
Imbris 2020-07-30 23:46:08 -04:00 committed by Monty Marz
parent 58df00d80c
commit 1d69e85a50
4 changed files with 96 additions and 101 deletions

View File

@ -1,7 +1,7 @@
use super::{ use super::{
img_ids::{Imgs, ImgsRot}, img_ids::{Imgs, ImgsRot},
Show, BLACK, GROUP_COLOR, HP_COLOR, KILL_COLOR, LOW_HP_COLOR, MANA_COLOR, TEXT_COLOR, Show, BLACK, GROUP_COLOR, HP_COLOR, KILL_COLOR, LOW_HP_COLOR, MANA_COLOR, TEXT_COLOR,
TEXT_COLOR_GREY, TRANSPARENT, UI_HIGHLIGHT_0, TEXT_COLOR_GREY, UI_HIGHLIGHT_0,
}; };
use crate::{ use crate::{
@ -171,6 +171,9 @@ impl<'a> Widget for Group<'a> {
.collect::<Vec<_>>(); .collect::<Vec<_>>();
// Not considered in group for ui purposes if it is just pets // Not considered in group for ui purposes if it is just pets
let in_group = !group_members.is_empty(); let in_group = !group_members.is_empty();
if !in_group {
self.show.group_menu = false;
}
// Helper // Helper
let uid_to_name_text = |uid, client: &Client| match client.player_list.get(&uid) { let uid_to_name_text = |uid, client: &Client| match client.player_list.get(&uid) {
@ -238,7 +241,7 @@ impl<'a> Widget for Group<'a> {
self.show.group_menu = !self.show.group_menu; self.show.group_menu = !self.show.group_menu;
}; };
// Member panels // Member panels
let group_size = group_members.len() + 1; let group_size = group_members.len();
if state.ids.member_panels_bg.len() < group_size { if state.ids.member_panels_bg.len() < group_size {
state.update(|s| { state.update(|s| {
s.ids s.ids
@ -303,13 +306,7 @@ impl<'a> Widget for Group<'a> {
.ecs() .ecs()
.read_resource::<common::sync::UidAllocator>(); .read_resource::<common::sync::UidAllocator>();
for (i, &uid) in self for (i, &uid) in group_members.iter().copied().enumerate() {
.client
.uid()
.iter()
.chain(group_members.iter().copied())
.enumerate()
{
self.show.group = true; self.show.group = true;
let entity = uid_allocator.retrieve_entity_internal(uid.into()); let entity = uid_allocator.retrieve_entity_internal(uid.into());
let stats = entity.and_then(|entity| stats.get(entity)); let stats = entity.and_then(|entity| stats.get(entity));
@ -324,7 +321,7 @@ impl<'a> Widget for Group<'a> {
} else { } else {
110.0 110.0
}; };
let pos = if i == 0 { let back = if i == 0 {
Image::new(self.imgs.member_bg) Image::new(self.imgs.member_bg)
.top_left_with_margins_on(ui.window, offset, 20.0) .top_left_with_margins_on(ui.window, offset, 20.0)
} else { } else {
@ -340,21 +337,13 @@ impl<'a> Widget for Group<'a> {
}; };
// Don't show panel for the player! // Don't show panel for the player!
// Panel BG // Panel BG
pos.w_h(152.0, 36.0) back.w_h(152.0, 36.0)
.color(if i == 0 { .color(Some(TEXT_COLOR))
Some(TRANSPARENT)
} else {
Some(TEXT_COLOR)
})
.set(state.ids.member_panels_bg[i], ui); .set(state.ids.member_panels_bg[i], ui);
// Health // Health
Image::new(self.imgs.bar_content) Image::new(self.imgs.bar_content)
.w_h(148.0 * health_perc, 22.0) .w_h(148.0 * health_perc, 22.0)
.color(if i == 0 { .color(Some(health_col))
Some(TRANSPARENT)
} else {
Some(health_col)
})
.top_left_with_margins_on(state.ids.member_panels_bg[i], 2.0, 2.0) .top_left_with_margins_on(state.ids.member_panels_bg[i], 2.0, 2.0)
.set(state.ids.member_health[i], ui); .set(state.ids.member_health[i], ui);
if stats.is_dead { if stats.is_dead {
@ -363,7 +352,7 @@ impl<'a> Widget for Group<'a> {
.mid_top_with_margin_on(state.ids.member_panels_bg[i], 1.0) .mid_top_with_margin_on(state.ids.member_panels_bg[i], 1.0)
.font_size(20) .font_size(20)
.font_id(self.fonts.cyri.conrod_id) .font_id(self.fonts.cyri.conrod_id)
.color(if i == 0 { TRANSPARENT } else { KILL_COLOR }) .color(KILL_COLOR)
.set(state.ids.dead_txt[i], ui); .set(state.ids.dead_txt[i], ui);
} else { } else {
// Health Text // Health Text
@ -388,46 +377,34 @@ impl<'a> Widget for Group<'a> {
.mid_top_with_margin_on(state.ids.member_panels_bg[i], txt_offset) .mid_top_with_margin_on(state.ids.member_panels_bg[i], txt_offset)
.font_size(font_size) .font_size(font_size)
.font_id(self.fonts.cyri.conrod_id) .font_id(self.fonts.cyri.conrod_id)
.color(if i == 0 { .color(Color::Rgba(1.0, 1.0, 1.0, 0.5))
TRANSPARENT
} else {
Color::Rgba(1.0, 1.0, 1.0, 0.5)
})
.set(state.ids.health_txt[i], ui); .set(state.ids.health_txt[i], ui);
}; };
// Panel Frame // Panel Frame
Image::new(self.imgs.member_frame) Image::new(self.imgs.member_frame)
.w_h(152.0, 36.0) .w_h(152.0, 36.0)
.middle_of(state.ids.member_panels_bg[i]) .middle_of(state.ids.member_panels_bg[i])
.color(if i == 0 { .color(Some(UI_HIGHLIGHT_0))
Some(TRANSPARENT)
} else {
Some(UI_HIGHLIGHT_0)
})
.set(state.ids.member_panels_frame[i], ui); .set(state.ids.member_panels_frame[i], ui);
// Panel Text // Panel Text
Text::new(&char_name) Text::new(&char_name)
.top_left_with_margins_on(state.ids.member_panels_frame[i], -22.0, 0.0) .top_left_with_margins_on(state.ids.member_panels_frame[i], -22.0, 0.0)
.font_size(20) .font_size(20)
.font_id(self.fonts.cyri.conrod_id) .font_id(self.fonts.cyri.conrod_id)
.color(if i == 0 { TRANSPARENT } else { BLACK }) .color(BLACK)
.set(state.ids.member_panels_txt_bg[i], ui); .set(state.ids.member_panels_txt_bg[i], ui);
Text::new(&char_name) Text::new(&char_name)
.bottom_left_with_margins_on(state.ids.member_panels_txt_bg[i], 2.0, 2.0) .bottom_left_with_margins_on(state.ids.member_panels_txt_bg[i], 2.0, 2.0)
.font_size(20) .font_size(20)
.font_id(self.fonts.cyri.conrod_id) .font_id(self.fonts.cyri.conrod_id)
.color(if i == 0 { TRANSPARENT } else { GROUP_COLOR }) .color(GROUP_COLOR)
.set(state.ids.member_panels_txt[i], ui); .set(state.ids.member_panels_txt[i], ui);
if let Some(energy) = energy { if let Some(energy) = energy {
let stam_perc = energy.current() as f64 / energy.maximum() as f64; let stam_perc = energy.current() as f64 / energy.maximum() as f64;
// Stamina // Stamina
Image::new(self.imgs.bar_content) Image::new(self.imgs.bar_content)
.w_h(100.0 * stam_perc, 8.0) .w_h(100.0 * stam_perc, 8.0)
.color(if i == 0 { .color(Some(MANA_COLOR))
Some(TRANSPARENT)
} else {
Some(MANA_COLOR)
})
.top_left_with_margins_on(state.ids.member_panels_bg[i], 26.0, 2.0) .top_left_with_margins_on(state.ids.member_panels_bg[i], 26.0, 2.0)
.set(state.ids.member_stam[i], ui); .set(state.ids.member_stam[i], ui);
} }
@ -446,36 +423,28 @@ impl<'a> Widget for Group<'a> {
} else { } else {
110.0 110.0
}; };
let pos = if i == 0 { let back = if i == 0 {
Image::new(self.imgs.member_bg) Image::new(self.imgs.member_bg)
.top_left_with_margins_on(ui.window, offset, 20.0) .top_left_with_margins_on(ui.window, offset, 20.0)
} else { } else {
Image::new(self.imgs.member_bg) Image::new(self.imgs.member_bg)
.down_from(state.ids.member_panels_bg[i - 1], 40.0) .down_from(state.ids.member_panels_bg[i - 1], 40.0)
}; };
pos.w_h(152.0, 36.0) back.w_h(152.0, 36.0)
.color(if i == 0 { .color(Some(TEXT_COLOR))
Some(TRANSPARENT)
} else {
Some(TEXT_COLOR)
})
.set(state.ids.member_panels_bg[i], ui); .set(state.ids.member_panels_bg[i], ui);
// Panel Frame // Panel Frame
Image::new(self.imgs.member_frame) Image::new(self.imgs.member_frame)
.w_h(152.0, 36.0) .w_h(152.0, 36.0)
.middle_of(state.ids.member_panels_bg[i]) .middle_of(state.ids.member_panels_bg[i])
.color(if i == 0 { .color(Some(UI_HIGHLIGHT_0))
Some(TRANSPARENT)
} else {
Some(UI_HIGHLIGHT_0)
})
.set(state.ids.member_panels_frame[i], ui); .set(state.ids.member_panels_frame[i], ui);
// Panel Text // Panel Text
Text::new(&self.localized_strings.get("hud.group.out_of_range")) Text::new(&self.localized_strings.get("hud.group.out_of_range"))
.mid_top_with_margin_on(state.ids.member_panels_bg[i], 3.0) .mid_top_with_margin_on(state.ids.member_panels_bg[i], 3.0)
.font_size(16) .font_size(16)
.font_id(self.fonts.cyri.conrod_id) .font_id(self.fonts.cyri.conrod_id)
.color(if i == 0 { TRANSPARENT } else { TEXT_COLOR }) .color(TEXT_COLOR)
.set(state.ids.dead_txt[i], ui); .set(state.ids.dead_txt[i], ui);
} }
} }
@ -579,7 +548,7 @@ impl<'a> Widget for Group<'a> {
} }
// Group Members, only character names, cut long names when they exceed the // Group Members, only character names, cut long names when they exceed the
// button size // button size
let group_size = group_members.len() + 1; let group_size = group_members.len();
if state.ids.members.len() < group_size { if state.ids.members.len() < group_size {
state.update(|s| { state.update(|s| {
s.ids s.ids
@ -598,13 +567,7 @@ impl<'a> Widget for Group<'a> {
.rgba(0.33, 0.33, 0.33, 1.0) .rgba(0.33, 0.33, 0.33, 1.0)
.set(state.ids.scrollbar, ui); .set(state.ids.scrollbar, ui);
// List member names // List member names
for (i, &uid) in self for (i, &uid) in group_members.iter().copied().enumerate() {
.client
.uid()
.iter()
.chain(group_members.iter().copied())
.enumerate()
{
let selected = state.selected_member.map_or(false, |u| u == uid); let selected = state.selected_member.map_or(false, |u| u == uid);
let char_name = uid_to_name_text(uid, &self.client); let char_name = uid_to_name_text(uid, &self.client);

View File

@ -82,7 +82,7 @@ const HP_COLOR: Color = Color::Rgba(0.33, 0.63, 0.0, 1.0);
const LOW_HP_COLOR: Color = Color::Rgba(0.93, 0.59, 0.03, 1.0); const LOW_HP_COLOR: Color = Color::Rgba(0.93, 0.59, 0.03, 1.0);
const CRITICAL_HP_COLOR: Color = Color::Rgba(0.79, 0.19, 0.17, 1.0); const CRITICAL_HP_COLOR: Color = Color::Rgba(0.79, 0.19, 0.17, 1.0);
const MANA_COLOR: Color = Color::Rgba(0.29, 0.62, 0.75, 0.9); const MANA_COLOR: Color = Color::Rgba(0.29, 0.62, 0.75, 0.9);
const TRANSPARENT: Color = Color::Rgba(0.0, 0.0, 0.0, 0.0); //const TRANSPARENT: Color = Color::Rgba(0.0, 0.0, 0.0, 0.0);
//const FOCUS_COLOR: Color = Color::Rgba(1.0, 0.56, 0.04, 1.0); //const FOCUS_COLOR: Color = Color::Rgba(1.0, 0.56, 0.04, 1.0);
//const RAGE_COLOR: Color = Color::Rgba(0.5, 0.04, 0.13, 1.0); //const RAGE_COLOR: Color = Color::Rgba(0.5, 0.04, 0.13, 1.0);

View File

@ -351,7 +351,11 @@ impl<'a> Widget for Social<'a> {
}) })
}; };
// Create a name, level and zone row for every player in the list // Create a name, level and zone row for every player in the list
for (i, (&uid, player_info)) in players.enumerate() { // Filter out yourself from the online list
let my_uid = self.client.uid();
for (i, (&uid, player_info)) in
players.filter(|(uid, _)| Some(**uid) != my_uid).enumerate()
{
let selected = state.selected_uid.map_or(false, |u| u.0 == uid); let selected = state.selected_uid.map_or(false, |u| u.0 == uid);
let alias = &player_info.player_alias; let alias = &player_info.player_alias;
let name = match &player_info.character { let name = match &player_info.character {
@ -433,47 +437,63 @@ impl<'a> Widget for Social<'a> {
{ {
state.update(|s| s.selected_uid = Some((uid, Instant::now()))); state.update(|s| s.selected_uid = Some((uid, Instant::now())));
} }
let player = if name == self.stats.name { true } else { false }; }
if Button::image(self.imgs.button)
.w_h(106.0, 26.0) // Invite Button
.bottom_right_with_margins_on(state.ids.frame, 9.0, 7.0) let selected_ingame = state
.hover_image(if !player && selected { .selected_uid
self.imgs.button_hover .as_ref()
} else { .map(|(s, _)| *s)
self.imgs.button .filter(|selected| {
}) self.client
.press_image(if !player && selected { .player_list
self.imgs.button_press .get(selected)
} else { .map_or(false, |selected_player| {
self.imgs.button selected_player.is_online && selected_player.character.is_some()
}) })
.label(&self.localized_strings.get("hud.group.invite")) })
.label_y(conrod_core::position::Relative::Scalar(3.0)) .or_else(|| {
.label_color(if !player && selected { self.selected_entity
TEXT_COLOR .and_then(|s| self.client.state().read_component_copied(s.0))
} else { });
TEXT_COLOR_3
}) if Button::image(self.imgs.button)
.image_color(if !player && selected { .w_h(106.0, 26.0)
TEXT_COLOR .bottom_right_with_margins_on(state.ids.frame, 9.0, 7.0)
} else { .hover_image(if selected_ingame.is_some() {
TEXT_COLOR_3 self.imgs.button_hover
}) } else {
.label_font_size(self.fonts.cyri.scale(15)) self.imgs.button
.label_font_id(self.fonts.cyri.conrod_id) })
.set(state.ids.invite_button, ui) .press_image(if selected_ingame.is_some() {
.was_clicked() self.imgs.button_press
{ } else {
if !player && selected { self.imgs.button
events.push(Event::Invite(uid)); })
state.update(|s| { .label(&self.localized_strings.get("hud.group.invite"))
s.selected_uid = None; .label_y(conrod_core::position::Relative::Scalar(3.0))
}); .label_color(if selected_ingame.is_some() {
} TEXT_COLOR
} else {
TEXT_COLOR_3
})
.image_color(if selected_ingame.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.invite_button, ui)
.was_clicked()
{
if let Some(uid) = selected_ingame {
events.push(Event::Invite(uid));
state.update(|s| {
s.selected_uid = None;
});
} }
} }
// Invite Button
/* */
} // End of Online Tab } // End of Online Tab
// Alignment // Alignment

View File

@ -537,6 +537,18 @@ impl PlayState for SessionState {
self.target_entity.map(|e| (e, std::time::Instant::now())); self.target_entity.map(|e| (e, std::time::Instant::now()));
} }
}, },
Event::InputUpdate(GameInput::AcceptGroupInvite, true) => {
let mut client = self.client.borrow_mut();
if client.group_invite().is_some() {
client.accept_group_invite();
}
},
Event::InputUpdate(GameInput::DeclineGroupInvite, true) => {
let mut client = self.client.borrow_mut();
if client.group_invite().is_some() {
client.decline_group_invite();
}
},
Event::AnalogGameInput(input) => match input { Event::AnalogGameInput(input) => match input {
AnalogGameInput::MovementX(v) => { AnalogGameInput::MovementX(v) => {
self.key_state.analog_matrix.x = v; self.key_state.analog_matrix.x = v;