mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Add setting for displaying character names in chat. Placate cargo clippy.
This commit is contained in:
parent
59db2fcd3b
commit
3d29c3254a
@ -259,7 +259,8 @@ magically infused items?"#,
|
||||
"hud.settings.values": "Values",
|
||||
"hud.settings.percentages": "Percentages",
|
||||
"hud.settings.chat": "Chat",
|
||||
"hud.settings.background_transparency": "Background Transparency",
|
||||
"hud.settings.background_transparency": "Background Transparency",
|
||||
"hud.settings.chat_character_name": "Show Character Names",
|
||||
|
||||
"hud.settings.pan_sensitivity": "Pan Sensitivity",
|
||||
"hud.settings.zoom_sensitivity": "Zoom Sensitivity",
|
||||
|
@ -82,9 +82,10 @@ fn main() {
|
||||
},
|
||||
};
|
||||
|
||||
const SHOW_NAME: bool = false;
|
||||
for event in events {
|
||||
match event {
|
||||
Event::Chat(m) => println!("{}", client.format_message(&m)),
|
||||
Event::Chat(m) => println!("{}", client.format_message(&m, SHOW_NAME)),
|
||||
Event::Disconnect => {}, // TODO
|
||||
Event::DisconnectionNotification(time) => {
|
||||
let message = match time {
|
||||
|
@ -79,43 +79,40 @@ fn nth_word(line: &str, n: usize) -> Option<usize> {
|
||||
None
|
||||
}
|
||||
|
||||
#[allow(clippy::chars_next_cmp)] // TODO: Pending review in #587
|
||||
pub fn complete(line: &str, client: &Client) -> Vec<String> {
|
||||
let word = if line.chars().last().map_or(true, char::is_whitespace) {
|
||||
""
|
||||
} else {
|
||||
line.split_whitespace().last().unwrap_or("")
|
||||
};
|
||||
if line.chars().next() == Some('/') {
|
||||
if line.starts_with('/') {
|
||||
let mut iter = line.split_whitespace();
|
||||
let cmd = iter.next().unwrap();
|
||||
let i = iter.count() + if word.is_empty() { 1 } else { 0 };
|
||||
if i == 0 {
|
||||
// Completing chat command name
|
||||
complete_command(word)
|
||||
} else {
|
||||
if let Ok(cmd) = cmd.parse::<ChatCommand>() {
|
||||
if let Some(arg) = cmd.data().args.get(i - 1) {
|
||||
// Complete ith argument
|
||||
arg.complete(word, &client)
|
||||
} else {
|
||||
// Complete past the last argument
|
||||
match cmd.data().args.last() {
|
||||
Some(ArgumentSpec::SubCommand) => {
|
||||
if let Some(index) = nth_word(line, cmd.data().args.len()) {
|
||||
complete(&line[index..], &client)
|
||||
} else {
|
||||
vec![]
|
||||
}
|
||||
},
|
||||
Some(ArgumentSpec::Message(_)) => complete_player(word, &client),
|
||||
_ => vec![], // End of command. Nothing to complete
|
||||
}
|
||||
}
|
||||
} else if let Ok(cmd) = cmd.parse::<ChatCommand>() {
|
||||
if let Some(arg) = cmd.data().args.get(i - 1) {
|
||||
// Complete ith argument
|
||||
arg.complete(word, &client)
|
||||
} else {
|
||||
// Completing for unknown chat command
|
||||
complete_player(word, &client)
|
||||
// Complete past the last argument
|
||||
match cmd.data().args.last() {
|
||||
Some(ArgumentSpec::SubCommand) => {
|
||||
if let Some(index) = nth_word(line, cmd.data().args.len()) {
|
||||
complete(&line[index..], &client)
|
||||
} else {
|
||||
vec![]
|
||||
}
|
||||
},
|
||||
Some(ArgumentSpec::Message(_)) => complete_player(word, &client),
|
||||
_ => vec![], // End of command. Nothing to complete
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Completing for unknown chat command
|
||||
complete_player(word, &client)
|
||||
}
|
||||
} else {
|
||||
// Not completing a command
|
||||
|
@ -875,7 +875,6 @@ impl Client {
|
||||
if self
|
||||
.state
|
||||
.read_component_cloned::<Uid>(self.entity)
|
||||
.map(|u| u.into())
|
||||
!= Some(entity)
|
||||
{
|
||||
self.state
|
||||
@ -1020,7 +1019,8 @@ impl Client {
|
||||
}
|
||||
|
||||
/// Format a message for the client (voxygen chat box or chat-cli)
|
||||
pub fn format_message(&self, comp::ChatMsg { chat_type, message }: &comp::ChatMsg) -> String {
|
||||
pub fn format_message(&self, msg: &comp::ChatMsg, character_name: bool) -> String {
|
||||
let comp::ChatMsg { chat_type, message } = &msg;
|
||||
let alias_of_uid = |uid| {
|
||||
self.player_list
|
||||
.get(uid)
|
||||
@ -1032,11 +1032,19 @@ impl Client {
|
||||
}
|
||||
})
|
||||
};
|
||||
let name_of_uid = |uid| {
|
||||
let ecs = self.state.ecs();
|
||||
(&ecs.read_storage::<comp::Stats>(), &ecs.read_storage::<Uid>())
|
||||
.join().find(|(_, u)| u == &uid).map(|(c, _)| c.name.clone())
|
||||
};
|
||||
let message_format = |uid, message, group| {
|
||||
if let Some(group) = group {
|
||||
format!("({}) [{}]: {}", group, alias_of_uid(uid), message)
|
||||
} else {
|
||||
format!("[{}]: {}", alias_of_uid(uid), message)
|
||||
let alias = alias_of_uid(uid);
|
||||
let name = if character_name { name_of_uid(uid) } else { None };
|
||||
match (group, name) {
|
||||
(Some(group), None) => format!("({}) [{}]: {}", group, alias, message),
|
||||
(None, None) => format!("[{}]: {}", alias, message),
|
||||
(Some(group), Some(name)) => format!("({}) [{}] {}: {}", group, alias, name, message),
|
||||
(None, Some(name)) => format!("[{}] {}: {}", alias, name, message),
|
||||
}
|
||||
};
|
||||
match chat_type {
|
||||
|
@ -443,7 +443,7 @@ impl FromStr for ChatCommand {
|
||||
if keyword.len() == 1 {
|
||||
if let Some(c) = keyword
|
||||
.chars()
|
||||
.nth(0)
|
||||
.next()
|
||||
.as_ref()
|
||||
.and_then(|k| CHAT_SHORTCUTS.get(k))
|
||||
{
|
||||
|
@ -254,7 +254,7 @@ impl SpeechBubble {
|
||||
{
|
||||
match &self.message {
|
||||
SpeechBubbleMessage::Plain(m) => m.to_string(),
|
||||
SpeechBubbleMessage::Localized(k, i) => i18n_variation(&k, *i).to_string(),
|
||||
SpeechBubbleMessage::Localized(k, i) => i18n_variation(&k, *i),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -457,19 +457,15 @@ fn handle_tp(
|
||||
} else if client != target {
|
||||
Some(client)
|
||||
} else {
|
||||
if client != target {
|
||||
Some(client)
|
||||
} else {
|
||||
server.notify_client(
|
||||
client,
|
||||
ChatType::CommandError.server_msg("You must specify a player name"),
|
||||
);
|
||||
server.notify_client(
|
||||
client,
|
||||
ChatType::CommandError.server_msg(action.help_string()),
|
||||
);
|
||||
return;
|
||||
}
|
||||
server.notify_client(
|
||||
client,
|
||||
ChatType::CommandError.server_msg("You must specify a player name"),
|
||||
);
|
||||
server.notify_client(
|
||||
client,
|
||||
ChatType::CommandError.server_msg(action.help_string()),
|
||||
);
|
||||
return;
|
||||
};
|
||||
if let Some(_pos) = server.state.read_component_cloned::<comp::Pos>(target) {
|
||||
if let Some(player) = opt_player {
|
||||
@ -1089,7 +1085,7 @@ fn handle_faction(
|
||||
if let Some(uid) = ecs.read_storage().get(client) {
|
||||
server
|
||||
.state
|
||||
.send_chat(mode.new_message(*uid, msg.to_string()));
|
||||
.send_chat(mode.new_message(*uid, msg));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -1123,7 +1119,7 @@ fn handle_group(
|
||||
if let Some(uid) = ecs.read_storage().get(client) {
|
||||
server
|
||||
.state
|
||||
.send_chat(mode.new_message(*uid, msg.to_string()));
|
||||
.send_chat(mode.new_message(*uid, msg));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -1159,7 +1155,7 @@ fn handle_region(
|
||||
if let Some(uid) = server.state.ecs().read_storage().get(client) {
|
||||
server
|
||||
.state
|
||||
.send_chat(mode.new_message(*uid, msg.to_string()));
|
||||
.send_chat(mode.new_message(*uid, msg));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1189,7 +1185,7 @@ fn handle_say(
|
||||
if let Some(uid) = server.state.ecs().read_storage().get(client) {
|
||||
server
|
||||
.state
|
||||
.send_chat(mode.new_message(*uid, msg.to_string()));
|
||||
.send_chat(mode.new_message(*uid, msg));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1219,7 +1215,7 @@ fn handle_world(
|
||||
if let Some(uid) = server.state.ecs().read_storage().get(client) {
|
||||
server
|
||||
.state
|
||||
.send_chat(mode.new_message(*uid, msg.to_string()));
|
||||
.send_chat(mode.new_message(*uid, msg));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ pub fn handle_possess(server: &Server, possessor_uid: Uid, possesse_uid: Uid) {
|
||||
let mut clients = ecs.write_storage::<Client>();
|
||||
if clients.get_mut(possesse).is_none() {
|
||||
if let Some(mut client) = clients.remove(possessor) {
|
||||
client.notify(ServerMsg::SetPlayerEntity(possesse_uid.into()));
|
||||
client.notify(ServerMsg::SetPlayerEntity(possesse_uid));
|
||||
clients
|
||||
.insert(possesse, client)
|
||||
.err()
|
||||
|
@ -53,9 +53,7 @@ pub fn handle_client_disconnect(server: &mut Server, entity: EcsEntity) -> Event
|
||||
state.read_storage::<Uid>().get(entity),
|
||||
state.read_storage::<comp::Player>().get(entity),
|
||||
) {
|
||||
state.notify_registered_clients(ServerMsg::PlayerListUpdate(PlayerListUpdate::Remove(
|
||||
(*uid).into(),
|
||||
)))
|
||||
state.notify_registered_clients(ServerMsg::PlayerListUpdate(PlayerListUpdate::Remove(*uid)))
|
||||
}
|
||||
|
||||
// Make sure to remove the player from the logged in list. (See AuthProvider)
|
||||
|
@ -147,7 +147,7 @@ impl<'a> System<'a> for Sys {
|
||||
.map(|key| !regions.contains(key))
|
||||
.unwrap_or(true)
|
||||
{
|
||||
client.notify(ServerMsg::DeleteEntity(uid.into()));
|
||||
client.notify(ServerMsg::DeleteEntity(uid));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -94,7 +94,7 @@ impl<'a> System<'a> for Sys {
|
||||
let player_list = (&uids, &players, stats.maybe(), admins.maybe())
|
||||
.join()
|
||||
.map(|(uid, player, stats, admin)| {
|
||||
((*uid).into(), PlayerInfo {
|
||||
(*uid, PlayerInfo {
|
||||
is_online: true,
|
||||
is_admin: admin.is_some(),
|
||||
player_alias: player.alias.clone(),
|
||||
@ -465,7 +465,7 @@ impl<'a> System<'a> for Sys {
|
||||
for entity in new_players {
|
||||
if let (Some(uid), Some(player)) = (uids.get(entity), players.get(entity)) {
|
||||
let msg =
|
||||
ServerMsg::PlayerListUpdate(PlayerListUpdate::Add((*uid).into(), PlayerInfo {
|
||||
ServerMsg::PlayerListUpdate(PlayerListUpdate::Add(*uid, PlayerInfo {
|
||||
player_alias: player.alias.clone(),
|
||||
is_online: true,
|
||||
is_admin: admins.get(entity).is_some(),
|
||||
|
@ -151,7 +151,7 @@ impl<'a> System<'a> for Sys {
|
||||
.map(|key| subscription.regions.contains(key))
|
||||
.unwrap_or(false)
|
||||
{
|
||||
client.notify(ServerMsg::DeleteEntity(uid.into()));
|
||||
client.notify(ServerMsg::DeleteEntity(uid));
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -159,7 +159,7 @@ impl<'a> System<'a> for Sys {
|
||||
}
|
||||
// Tell client to delete entities in the region
|
||||
for (&uid, _) in (&uids, region.entities()).join() {
|
||||
client.notify(ServerMsg::DeleteEntity(uid.into()));
|
||||
client.notify(ServerMsg::DeleteEntity(uid));
|
||||
}
|
||||
}
|
||||
// Send deleted entities since they won't be processed for this client in entity
|
||||
|
@ -327,12 +327,13 @@ impl<'a> Widget for Chat<'a> {
|
||||
});
|
||||
}
|
||||
|
||||
let show_char_name = self.global_state.settings.gameplay.chat_character_name;
|
||||
while let Some(item) = items.next(ui) {
|
||||
// This would be easier if conrod used the v-metrics from rusttype.
|
||||
if item.i < state.messages.len() {
|
||||
let message = &state.messages[item.i];
|
||||
let (color, icon) = render_chat_line(&message.chat_type, &self.imgs);
|
||||
let msg = self.client.format_message(message);
|
||||
let msg = self.client.format_message(message, show_char_name);
|
||||
let text = Text::new(&msg)
|
||||
.font_size(self.fonts.opensans.scale(15))
|
||||
.font_id(self.fonts.opensans.conrod_id)
|
||||
|
@ -256,6 +256,7 @@ pub enum Event {
|
||||
ChangeFluidMode(FluidMode),
|
||||
CrosshairTransp(f32),
|
||||
ChatTransp(f32),
|
||||
ChatCharName(bool),
|
||||
CrosshairType(CrosshairType),
|
||||
ToggleXpBar(XpBar),
|
||||
Intro(Intro),
|
||||
@ -1662,6 +1663,9 @@ impl Hud {
|
||||
settings_window::Event::ChatTransp(chat_transp) => {
|
||||
events.push(Event::ChatTransp(chat_transp));
|
||||
},
|
||||
settings_window::Event::ChatCharName(chat_char_name) => {
|
||||
events.push(Event::ChatCharName(chat_char_name));
|
||||
},
|
||||
settings_window::Event::ToggleZoomInvert(zoom_inverted) => {
|
||||
events.push(Event::ToggleZoomInvert(zoom_inverted));
|
||||
},
|
||||
|
@ -137,6 +137,8 @@ widget_ids! {
|
||||
chat_transp_title,
|
||||
chat_transp_text,
|
||||
chat_transp_slider,
|
||||
chat_char_name_text,
|
||||
chat_char_name_button,
|
||||
sct_title,
|
||||
sct_show_text,
|
||||
sct_show_radio,
|
||||
@ -240,6 +242,7 @@ pub enum Event {
|
||||
CrosshairType(CrosshairType),
|
||||
UiScale(ScaleChange),
|
||||
ChatTransp(f32),
|
||||
ChatCharName(bool),
|
||||
Sct(bool),
|
||||
SctPlayerBatch(bool),
|
||||
SctDamageBatch(bool),
|
||||
@ -1132,8 +1135,32 @@ impl<'a> Widget for SettingsWindow<'a> {
|
||||
events.push(Event::ChatTransp(new_val));
|
||||
}
|
||||
|
||||
// "Show character names in chat" toggle button
|
||||
let chat_char_name = ToggleButton::new(
|
||||
self.global_state.settings.gameplay.chat_character_name,
|
||||
self.imgs.checkbox,
|
||||
self.imgs.checkbox_checked,
|
||||
)
|
||||
.w_h(18.0, 18.0)
|
||||
.down_from(state.ids.chat_transp_slider, 20.0)
|
||||
.hover_images(self.imgs.checkbox_mo, self.imgs.checkbox_checked_mo)
|
||||
.press_images(self.imgs.checkbox_press, self.imgs.checkbox_checked)
|
||||
.set(state.ids.chat_char_name_button, ui);
|
||||
if self.global_state.settings.gameplay.chat_character_name != chat_char_name {
|
||||
events.push(Event::ChatCharName(
|
||||
!self.global_state.settings.gameplay.chat_character_name,
|
||||
));
|
||||
}
|
||||
Text::new(&self.localized_strings.get("hud.settings.chat_character_name"))
|
||||
.right_from(state.ids.chat_char_name_button, 20.0)
|
||||
.font_size(self.fonts.cyri.scale(14))
|
||||
.font_id(self.fonts.cyri.conrod_id)
|
||||
.color(TEXT_COLOR)
|
||||
.set(state.ids.chat_char_name_text, ui);
|
||||
|
||||
// Language select drop down
|
||||
Text::new(&self.localized_strings.get("common.languages"))
|
||||
.down_from(state.ids.chat_transp_slider, 20.0)
|
||||
.down_from(state.ids.chat_char_name_button, 20.0)
|
||||
.font_size(self.fonts.cyri.scale(18))
|
||||
.font_id(self.fonts.cyri.conrod_id)
|
||||
.color(TEXT_COLOR)
|
||||
|
@ -690,6 +690,10 @@ impl PlayState for SessionState {
|
||||
global_state.settings.gameplay.chat_transp = chat_transp;
|
||||
global_state.settings.save_to_file_warn();
|
||||
},
|
||||
HudEvent::ChatCharName(chat_char_name) => {
|
||||
global_state.settings.gameplay.chat_character_name = chat_char_name;
|
||||
global_state.settings.save_to_file_warn();
|
||||
},
|
||||
HudEvent::CrosshairType(crosshair_type) => {
|
||||
global_state.settings.gameplay.crosshair_type = crosshair_type;
|
||||
global_state.settings.save_to_file_warn();
|
||||
|
@ -463,6 +463,7 @@ pub struct GameplaySettings {
|
||||
pub smooth_pan_enable: bool,
|
||||
pub crosshair_transp: f32,
|
||||
pub chat_transp: f32,
|
||||
pub chat_character_name: bool,
|
||||
pub crosshair_type: CrosshairType,
|
||||
pub intro_show: Intro,
|
||||
pub xp_bar: XpBar,
|
||||
@ -490,6 +491,7 @@ impl Default for GameplaySettings {
|
||||
speech_bubble_icon: true,
|
||||
crosshair_transp: 0.6,
|
||||
chat_transp: 0.4,
|
||||
chat_character_name: true,
|
||||
crosshair_type: CrosshairType::Round,
|
||||
intro_show: Intro::Show,
|
||||
xp_bar: XpBar::Always,
|
||||
|
Loading…
Reference in New Issue
Block a user