Merge branch 'Quibble/item-buff-tooltips' into 'master'

Tooltips use item stats for buff information

See merge request veloren/veloren!1820
This commit is contained in:
Imbris 2021-03-05 22:00:24 +00:00
commit 575301c763
27 changed files with 97 additions and 34 deletions

View File

@ -1,6 +1,6 @@
ItemDef(
name: "Potent Potion",
description: "A potent healing potion.\n\nRestores 100 health on use",
description: "A potent healing potion.",
kind: Consumable(
kind: "Potion",
effect: [

View File

@ -1,6 +1,6 @@
ItemDef(
name: "Large Potion",
description: "Restores 200 Health",
description: "",
kind: Consumable(
kind: "PotionLarge",
effect: [

View File

@ -1,6 +1,6 @@
ItemDef(
name: "Medium Potion",
description: "Restores 100 Health",
description: "",
kind: Consumable(
kind: "PotionMed",
effect: [

View File

@ -1,6 +1,6 @@
ItemDef(
name: "Minor Potion",
description: "Restores 50 Health",
description: "",
kind: Consumable(
kind: "PotionMinor",
effect: [

View File

@ -1,6 +1,6 @@
ItemDef(
name: "Bowl",
description: "a simple bowl for preparing meals.",
description: "A simple bowl for preparing meals.",
kind: Ingredient(
kind: "Bowl",
),

View File

@ -1,6 +1,6 @@
ItemDef(
name: "Apple",
description: "Restores 10 Health over 10 seconds\n\nRed and juicy",
description: "Red and juicy",
kind: Consumable(
kind: "Apple",
effect: [

View File

@ -1,6 +1,6 @@
ItemDef(
name: "Mushroom Curry",
description: "Restores 120 Health over 10 seconds\n\nWho could say no to that?",
description: "Who could say no to that?",
kind: Consumable(
kind: "AppleShroomCurry",
effect: [

View File

@ -1,6 +1,6 @@
ItemDef(
name: "Apple Stick",
description: "Restores 25 Health over 10 seconds\n\nThe stick makes it easier to carry!",
description: "The stick makes it easier to carry!",
kind: Consumable(
kind: "AppleStick",
effect: [

View File

@ -1,6 +1,6 @@
ItemDef(
name: "Carrot",
description: "Restores 10 Health over 20 seconds\n\nAn orange root vegetable. They say it'll improve your vision!",
description: "An orange root vegetable. They say it'll improve your vision!",
kind: Consumable(
kind: "Carrot",
effect: [

View File

@ -1,6 +1,6 @@
ItemDef(
name: "Dwarven Cheese",
description: "Restores 15 Health over 10 seconds\n\nAromatic and nutritious",
description: "Aromatic and nutritious",
kind: Consumable(
kind: "Cheese",
effect: [

View File

@ -1,6 +1,6 @@
ItemDef(
name: "Coconut",
description: "Restores 20 health over 10 seconds\n\nReliable source of water and fat.\n\nNaturally growing at the top of palm trees.",
description: "Reliable source of water and fat.\n\nNaturally growing at the top of palm trees.",
kind: Consumable(
kind: "Coconut",
effect: [

View File

@ -1,6 +1,6 @@
ItemDef(
name: "Coltsfoot",
description: "Restores 10 Health over 20 seconds\n\nA daisy-like flower often used in herbal teas.",
description: "A daisy-like flower often used in herbal teas.",
kind: Consumable(
kind: "Coltsfoot",
effect: [

View File

@ -1,6 +1,6 @@
ItemDef(
name: "Dandelion",
description: "Restores 10 Health over 20 seconds\n\nA small, yellow flower. Uses the wind to spread its seeds.",
description: "A small, yellow flower. Uses the wind to spread its seeds.",
kind: Consumable(
kind: "Dandelion",
effect: [

View File

@ -1,6 +1,6 @@
ItemDef(
name: "Fish",
description: "Restores 10 Health over 20 seconds\n\nA fresh seafood steak, chopped from a fish.",
description: "A fresh seafood steak, chopped from a fish.",
kind: Consumable(
kind: "Fish",
effect: [

View File

@ -1,6 +1,6 @@
ItemDef(
name: "Garlic",
description: "Restores 10 Health over 20 seconds\n\nMake sure to brush your teeth after eating.",
description: "Make sure to brush your teeth after eating.",
kind: Consumable(
kind: "Garlic",
effect: [

View File

@ -1,6 +1,6 @@
ItemDef(
name: "Lettuce",
description: "Restores 10 Health over 20 seconds\n\nA vibrant green leafy vegetable. Lettuce make some salads!",
description: "A vibrant green leafy vegetable. Lettuce make some salads!",
kind: Consumable(
kind: "Lettuce",
effect: [

View File

@ -1,6 +1,6 @@
ItemDef(
name: "Meat",
description: "Restores 10 Health over 20 seconds\n\nMeat. The lifeblood of mankind.",
description: "Meat. The lifeblood of mankind.",
kind: Consumable(
kind: "Meat",
effect: [

View File

@ -1,6 +1,6 @@
ItemDef(
name: "Mushroom",
description: "Restores 5 Health over 10 seconds\n\nHopefully this one is not poisonous",
description: "Hopefully this one is not poisonous",
kind: Consumable(
kind: "Mushroom",
effect: [

View File

@ -1,6 +1,6 @@
ItemDef(
name: "Mushroom Stick",
description: "Restores 20 Health over 10 seconds\n\nRoasted mushrooms on a stick for easy carrying",
description: "Roasted mushrooms on a stick for easy carrying",
kind: Consumable(
kind: "MushroomStick",
effect: [

View File

@ -1,6 +1,6 @@
ItemDef(
name: "Onion",
description: "Restores 10 Health over 20 seconds\n\nA vegetable that's made the toughest men cry.",
description: "A vegetable that's made the toughest men cry.",
kind: Consumable(
kind: "Onion",
effect: [

View File

@ -1,6 +1,6 @@
ItemDef(
name: "Plain Salad",
description: "Restores 20 Health over 20 seconds\n\nLiterally just chopped lettuce. Does this even count as a salad?",
description: "Literally just chopped lettuce. Does this even count as a salad?",
kind: Consumable(
kind: "PlainSalad",
effect: [

View File

@ -1,6 +1,6 @@
ItemDef(
name: "Sage",
description: "Restores 10 Health over 20 seconds\n\nAn herb commonly used in tea.",
description: "A herb commonly used in tea.",
kind: Consumable(
kind: "Sage",
effect: [

View File

@ -1,6 +1,6 @@
ItemDef(
name: "Sunflower Ice Tea",
description: "Restores 50 Health over 10 seconds\n\nBrewed from freshly shelled sunflower seeds",
description: "Brewed from freshly shelled sunflower seeds",
kind: Consumable(
kind: "SunflowerTea",
effect: [

View File

@ -1,6 +1,6 @@
ItemDef(
name: "Tomato",
description: "Restores 10 Health over 20 seconds\n\nA red fruit. Not actually a vegetable.",
description: "A red fruit. Not actually a vegetable.",
kind: Consumable(
kind: "Tomato",
effect: [

View File

@ -1,6 +1,6 @@
ItemDef(
name: "Tomato Salad",
description: "Restores 30 Health over 20 seconds\n\nLeafy salad with some chopped, juicy tomatoes mixed in.",
description: "Leafy salad with some chopped, juicy tomatoes mixed in.",
kind: Consumable(
kind: "TomatoSalad",
effect: [

View File

@ -1,6 +1,6 @@
ItemDef(
name: "Velorite",
description: "Just a slight touch makes you feel\n\the knowledge of ancient times",
description: "Just a slight touch makes you feel\nthe knowledge of ancient times",
kind: Ingredient(
kind: "Velorite",
),

View File

@ -1,7 +1,13 @@
use common::comp::item::{
armor::{Armor, ArmorKind, Protection},
tool::{Hands, StatKind, Stats, Tool, ToolKind},
Item, ItemDesc, ItemKind, MaterialStatManifest, ModularComponent,
use common::{
comp::{
item::{
armor::{Armor, ArmorKind, Protection},
tool::{Hands, StatKind, Stats, Tool, ToolKind},
Item, ItemDesc, ItemKind, MaterialStatManifest, ModularComponent,
},
BuffKind,
},
effect::Effect,
};
use std::{borrow::Cow, fmt::Write};
@ -40,7 +46,9 @@ pub fn item_text<'a>(
item.description(),
)),
ItemKind::Glider(_glider) => Cow::Owned(glider_desc(item.description())),
ItemKind::Consumable { .. } => Cow::Owned(consumable_desc(item.description())),
ItemKind::Consumable { effect, .. } => {
Cow::Owned(consumable_desc(effect, item.description()))
},
ItemKind::Throwable { .. } => Cow::Owned(throwable_desc(item.description())),
ItemKind::Utility { .. } => Cow::Owned(utility_desc(item.description())),
ItemKind::Ingredient { .. } => Cow::Owned(ingredient_desc(
@ -78,8 +86,63 @@ fn modular_component_desc(
}
fn glider_desc(desc: &str) -> String { format!("Glider\n\n{}\n\n<Right-Click to use>", desc) }
fn consumable_desc(desc: &str) -> String {
format!("Consumable\n\n{}\n\n<Right-Click to use>", desc)
fn consumable_desc(effects: &[Effect], desc: &str) -> String {
// TODO: localization
let mut description = "Consumable".to_string();
for effect in effects {
if let Effect::Buff(buff) = effect {
let strength = buff.data.strength * 0.1;
let dur_secs = buff.data.duration.map(|d| d.as_secs_f32());
let str_total = dur_secs.map_or(strength, |secs| strength * secs);
let buff_desc = match buff.kind {
BuffKind::Saturation | BuffKind::Regeneration | BuffKind::Potion => {
format!("Restores {} Health", str_total)
},
BuffKind::IncreaseMaxEnergy => {
format!("Raises Maximum Stamina by {}", strength)
},
BuffKind::IncreaseMaxHealth => {
format!("Raises Maximum Health by {}", strength)
},
BuffKind::Invulnerability => "Grants invulnerability".to_string(),
BuffKind::Bleeding | BuffKind::CampfireHeal | BuffKind::Cursed => continue,
};
write!(&mut description, "\n\n{}", buff_desc).unwrap();
let dur_desc = if dur_secs.is_some() {
match buff.kind {
BuffKind::Saturation | BuffKind::Regeneration => {
format!("over {} seconds", dur_secs.unwrap())
},
BuffKind::IncreaseMaxEnergy
| BuffKind::IncreaseMaxHealth
| BuffKind::Invulnerability => {
format!("for {} seconds", dur_secs.unwrap())
},
BuffKind::Bleeding
| BuffKind::Potion
| BuffKind::CampfireHeal
| BuffKind::Cursed => continue,
}
} else if let BuffKind::Saturation | BuffKind::Regeneration = buff.kind {
"every second".to_string()
} else {
continue;
};
write!(&mut description, " {}", dur_desc).unwrap();
}
}
if !desc.is_empty() {
write!(&mut description, "\n\n{}", desc).unwrap();
}
write!(&mut description, "\n\n<Right-Click to use>").unwrap();
description
}
fn throwable_desc(desc: &str) -> String {
@ -224,7 +287,7 @@ mod tests {
assert_eq!(
"Consumable\n\nmushrooms\n\n<Right-Click to use>",
consumable_desc(item_description)
consumable_desc(&[], item_description)
);
}