modular component tooltips

This commit is contained in:
Bryant Deters 2022-03-19 14:18:38 -05:00 committed by Sam
parent f6343ff4f9
commit 075fee5190
5 changed files with 121 additions and 53 deletions

View File

@ -1,5 +1,5 @@
ItemDef(
name: "Samll Fire Core",
name: "Small Fire Core",
description: "",
kind: ModularComponent(
ToolSecondaryComponent(

View File

@ -85,6 +85,7 @@ Is the client up to date?"#,
"common.tool.pick": "Pickaxe",
"common.tool.mining": "Mining",
"common.kind.modular_component": "Modular Component",
"common.kind.modular_component_partial": "Component",
"common.kind.glider": "Glider",
"common.kind.consumable": "Consumable",
"common.kind.throwable": "Can be thrown",
@ -101,6 +102,9 @@ Is the client up to date?"#,
"common.stats.power": "Power",
"common.stats.speed": "Speed",
"common.stats.poise": "Poise",
"common.stats.range": "Range",
"common.stats.energy_efficiency": "Energy Efficiency",
"common.stats.buff_strength": "Buff Strength",
"common.stats.crit_chance": "Crit Chance",
"common.stats.crit_mult": "Crit Mult",
"common.stats.armor": "Armor",

View File

@ -237,6 +237,13 @@ impl ModularComponent {
Self::ToolSecondaryComponent { stats, .. } => Some(*stats),
}
}
pub fn toolkind(&self) -> Option<ToolKind> {
match self {
Self::ToolPrimaryComponent { toolkind, .. }
| Self::ToolSecondaryComponent { toolkind, .. } => Some(*toolkind),
}
}
}
const SUPPORTED_TOOLKINDS: [ToolKind; 6] = [

View File

@ -4,8 +4,8 @@ use common::{
inventory::trade_pricing::TradePricing,
item::{
armor::{Armor, ArmorKind, Protection},
tool::{Hands, Stats, Tool, ToolKind},
Item, ItemDesc, ItemKind, MaterialKind, MaterialStatManifest, ModularComponent,
tool::{Hands, Tool, ToolKind},
ItemDesc, ItemKind, MaterialKind,
},
BuffKind,
},
@ -78,7 +78,17 @@ pub fn kind_text<'a, I: ItemDesc + ?Sized>(item: &I, i18n: &'a Localization) ->
tool_kind(tool, i18n),
tool_hands(tool, i18n)
)),
ItemKind::ModularComponent(_mc) => Cow::Borrowed(i18n.get("common.bag.shoulders")),
ItemKind::ModularComponent(mc) => {
if let Some(toolkind) = mc.toolkind() {
Cow::Owned(format!(
"{} {}",
i18n.get(&format!("common.weapons.{}", toolkind.identifier_name())),
i18n.get("common.kind.modular_component_partial")
))
} else {
Cow::Borrowed(i18n.get("common.kind.modular_component"))
}
},
ItemKind::Glider(_glider) => Cow::Borrowed(i18n.get("common.kind.glider")),
ItemKind::Consumable { .. } => Cow::Borrowed(i18n.get("common.kind.consumable")),
ItemKind::Throwable { .. } => Cow::Borrowed(i18n.get("common.kind.throwable")),
@ -99,30 +109,6 @@ pub fn material_kind_text<'a>(kind: &MaterialKind, i18n: &'a Localization) -> &'
}
}
// TODO: localization, refactor when mc are player facing
pub fn modular_component_desc(
mc: &ModularComponent,
components: &[Item],
msm: &MaterialStatManifest,
description: &str,
) -> String {
let mut result = format!("Modular Component\n\n{}", description);
if let Some(tool_stats) = mc.tool_stats(components, msm) {
let statblock = statblock_desc(&tool_stats);
result += "\n\n";
result += &statblock;
}
if !components.is_empty() {
result += "\n\nMade from:\n";
for component in components {
result += &component.name();
result += "\n"
}
result += "\n";
}
result
}
pub fn stats_count(item: &dyn ItemDesc) -> usize {
let mut count = match &*item.kind() {
ItemKind::Armor(armor) => {
@ -138,7 +124,7 @@ pub fn stats_count(item: &dyn ItemDesc) -> usize {
},
ItemKind::Tool(_) => 4,
ItemKind::Consumable { effects, .. } => effects.len(),
ItemKind::ModularComponent { .. } => 1,
ItemKind::ModularComponent { .. } => 7,
_ => 0,
};
@ -285,17 +271,6 @@ pub fn tool_hands<'a>(tool: &Tool, i18n: &'a Localization) -> &'a str {
hands
}
fn statblock_desc(stats: &Stats) -> String {
format!(
// TODO: Change display of Effect Power based on toolkind equipped and what effect power is
// affecting
"Power: {:0.1}\n\nPoise Strength: {:0.1}\n\nSpeed: {:0.1}\n\n",
stats.power * 10.0,
stats.effect_power * 10.0,
stats.speed,
) + &format!("Crit chance: {:0.1}%\n\n", stats.crit_chance * 100.0,)
}
/// Compare two type, output a colored character to show comparison
pub fn comparison<T: PartialOrd>(first: T, other: T) -> (&'static str, conrod_core::Color) {
if first == other {

View File

@ -1098,19 +1098,101 @@ impl<'a> Widget for ItemTooltip<'a> {
}
},
ItemKind::ModularComponent(mc) => {
widget::Text::new(&util::modular_component_desc(
mc,
item.components(),
self.msm,
item.description(),
))
.x_align_to(state.ids.item_frame, conrod_core::position::Align::Start)
.graphics_for(id)
.parent(id)
.with_style(self.style.desc)
.color(text_color)
.down_from(state.ids.item_frame, V_PAD)
.set(state.ids.stats[0], ui);
if let Some(stats) = mc.tool_stats(item.components(), self.msm) {
// Power
widget::Text::new(&format!(
"{} : {:.1}",
i18n.get("common.stats.power"),
stats.power
))
.x_align_to(state.ids.item_frame, conrod_core::position::Align::Start)
.graphics_for(id)
.parent(id)
.with_style(self.style.desc)
.color(text_color)
.down_from(state.ids.item_frame, V_PAD)
.set(state.ids.stats[0], ui);
// Speed
widget::Text::new(&format!(
"{} : {:+.0}%",
i18n.get("common.stats.speed"),
(stats.speed - 1.0) * 100.0
))
.graphics_for(id)
.parent(id)
.with_style(self.style.desc)
.color(text_color)
.down_from(state.ids.stats[0], V_PAD_STATS)
.set(state.ids.stats[1], ui);
// Effect Power
// TODO: Allow effect power to have different terminology based on what it is
// affecting.
widget::Text::new(&format!(
"{} : {:.1}",
i18n.get("common.stats.poise"),
stats.effect_power
))
.graphics_for(id)
.parent(id)
.with_style(self.style.desc)
.color(text_color)
.down_from(state.ids.stats[1], V_PAD_STATS)
.set(state.ids.stats[2], ui);
// Crit chance
widget::Text::new(&format!(
"{} : {:.1}%",
i18n.get("common.stats.crit_chance"),
stats.crit_chance
))
.graphics_for(id)
.parent(id)
.with_style(self.style.desc)
.color(text_color)
.down_from(state.ids.stats[2], V_PAD_STATS)
.set(state.ids.stats[3], ui);
// Range
widget::Text::new(&format!(
"{} : {:.1}%",
i18n.get("common.stats.range"),
(stats.range - 1.0) * 100.0
))
.graphics_for(id)
.parent(id)
.with_style(self.style.desc)
.color(text_color)
.down_from(state.ids.stats[3], V_PAD_STATS)
.set(state.ids.stats[4], ui);
// Energy Efficiency
widget::Text::new(&format!(
"{} : {:.1}%",
i18n.get("common.stats.energy_efficiency"),
stats.energy_efficiency
))
.graphics_for(id)
.parent(id)
.with_style(self.style.desc)
.color(text_color)
.down_from(state.ids.stats[4], V_PAD_STATS)
.set(state.ids.stats[5], ui);
// Buff Strength
widget::Text::new(&format!(
"{} : {:.1}%",
i18n.get("common.stats.buff_strength"),
stats.buff_strength
))
.graphics_for(id)
.parent(id)
.with_style(self.style.desc)
.color(text_color)
.down_from(state.ids.stats[5], V_PAD_STATS)
.set(state.ids.stats[6], ui);
}
},
_ => (),
}