Added keybinding shortcut in loading tips

This commit is contained in:
IsseW 2021-10-25 23:53:27 +02:00
parent 8e8d1a6624
commit 047cda179f
4 changed files with 55 additions and 19 deletions

View File

@ -85,9 +85,10 @@ https://veloren.net/account/."#,
vector_map: {
// The keybinding names can be found in voxygen/src/game_input.rs in the GameInput enum
"loading.tips": [
"Press 'G' to light your lantern.",
"Press 'F1' to see all default keybindings.",
"Press '{gameinput.togglelantern}' to light your lantern.",
"Press '{gameinput.help}' to see all default keybindings.",
"You can type /say or /s to only chat with players directly around you.",
"You can type /region or /r to only chat with players a couple of hundred blocks around you.",
"Admins can use the /build command to enter build mode.",
@ -96,16 +97,18 @@ https://veloren.net/account/."#,
"Keep an eye out for food, chests and other loot spread all around the world!",
"Inventory filled with food? Try crafting better food from it!",
"Wondering what there is to do? Try out one of the dungeons marked on the map!",
"Don't forget to adjust the graphics for your system. Press 'N' to open the settings.",
"Playing with others is fun! Press 'O' to see who is online.",
"Press 'J' to dance. Party!",
"Press 'L-Shift' to open your Glider and conquer the skies.",
"Don't forget to adjust the graphics for your system.",
"Playing with others is fun! Press '{gameinput.social}' to see who is online.",
"Press '{gameinput.dance}' to dance. Party!",
"Press '{gameinput.glide}' to open your Glider and conquer the skies.",
"Veloren is still in Pre-Alpha. We do our best to improve it every day!",
"If you want to join the dev team or just have a chat with us, join our Discord server.",
"You can toggle showing your amount of health on the healthbar in the settings.",
"Sit near a campfire (with the 'K' key) to slowly recover from your injuries.",
"Need more bags or better armor to continue your journey? Press 'C' to open the crafting menu!",
"Try jumping when rolling through creatures.",
"Sit near a campfire (with the '{gameinput.sit}' key) to slowly recover from your injuries.",
"Need more bags or better armor to continue your journey? Press '{gameinput.crafting}' to open the crafting menu!",
"Press '{gameinput.roll}' to roll. Rolling can be used to move faster and dodge enemy attacks.",
"Wondering what an item is used for? Search 'input:<item name>' in crafting to see what recipes it's used in.",
"Find something cool? Take a screenshot of it with '{gameinput.screenshot}'."
],
}
)

View File

@ -1,6 +1,6 @@
use serde::{Deserialize, Serialize};
use std::convert::AsRef;
use strum::{AsRefStr, EnumIter};
use strum::{AsRefStr, EnumIter, EnumString};
/// Represents a key that the game recognises after input mapping.
#[derive(
@ -16,6 +16,7 @@ use strum::{AsRefStr, EnumIter};
Serialize,
AsRefStr,
EnumIter,
EnumString,
)]
pub enum GameInput {
#[strum(serialize = "gameinput.primary")]

View File

@ -1,9 +1,15 @@
use std::str::FromStr;
use super::{ConnectionState, Imgs, Message};
use crate::ui::{
fonts::IcedFonts as Fonts,
ice::{component::neat_button, style, widget::Image, Element, IcedUi as Ui, Id},
Graphic,
use crate::{
game_input::GameInput,
settings::ControlSettings,
ui::{
fonts::IcedFonts as Fonts,
ice::{component::neat_button, style, widget::Image, Element, IcedUi as Ui, Id},
Graphic,
},
};
use common::assets::{self, AssetExt};
use i18n::Localization;
@ -84,6 +90,7 @@ impl Screen {
i18n: &Localization,
button_style: style::button::Style,
show_tip: bool,
controls: &ControlSettings,
) -> Element<Message> {
// TODO: add built in support for animated images
let frame_index = (time * self.loading_animation.speed_factor as f64)
@ -93,11 +100,35 @@ impl Screen {
let children = match connection_state {
ConnectionState::InProgress => {
let tip = if show_tip {
let tip = format!(
"{} {}",
&i18n.get("main.tip"),
&i18n.get_variation("loading.tips", self.tip_number)
);
let tip = &i18n.get_variation("loading.tips", self.tip_number);
let mut new_tip = String::with_capacity(tip.len());
let mut last_index = 0;
// This could be done with regex instead, but adding new dependencies is
// scary...
tip.match_indices("{gameinput.").for_each(|(start, s)| {
println!("start {}", start);
if let Some(end) = tip[start + s.len()..].find('}') {
let end = start + s.len() + end;
println!("end {}", end);
if let Ok(game_input) = GameInput::from_str(&tip[start + 1..end]) {
println!("input {:?}", game_input);
new_tip.push_str(&tip[last_index..start]);
new_tip.push_str(
controls.keybindings[&game_input]
.display_string(&None)
.as_str(),
);
last_index = end + 1;
}
}
});
// If there is any text left over append it
if last_index < tip.len() {
new_tip.push_str(&tip[last_index..]);
}
let tip = format!("{} {}", i18n.get("main.tip"), new_tip.as_str());
Container::new(Text::new(tip).size(fonts.cyri.scale(25)))
.width(Length::Fill)
.height(Length::Fill)

View File

@ -308,6 +308,7 @@ impl Controls {
&self.i18n.read(),
button_style,
settings.interface.loading_tips,
&settings.controls,
),
};