diff --git a/crates/horizon-client-core/src/lib.rs b/crates/horizon-client-core/src/lib.rs index 2030165c5..7721668ca 100644 --- a/crates/horizon-client-core/src/lib.rs +++ b/crates/horizon-client-core/src/lib.rs @@ -16,6 +16,7 @@ pub mod lang; pub mod nbt_path; pub mod particle_type; pub mod pattern; +pub mod potions; pub mod registries; pub mod scoreboard; pub mod snbt; diff --git a/crates/horizon-client-core/src/potions.rs b/crates/horizon-client-core/src/potions.rs new file mode 100644 index 000000000..044b25e3a --- /dev/null +++ b/crates/horizon-client-core/src/potions.rs @@ -0,0 +1,249 @@ +//! The `MobEffects` and `Potions` registries (code in vanilla, ported as +//! tables): each effect's colour and category, each potion's effects, and the +//! potion colour mix. horizon-client re-exports them from `brewing`. +use std::{collections::HashMap, sync::OnceLock}; + +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum Category { + Beneficial, + Harmful, + Neutral, +} +/// A `MobEffect`: id (without namespace), colour, category, instantaneous. +#[derive(Clone, Copy, Debug)] +pub struct EffectDef { + pub id: &'static str, + pub color: u32, + pub category: Category, + pub instant: bool, +} +const fn fx(id: &'static str, color: u32, category: Category) -> EffectDef { + EffectDef { + id, + color, + category, + instant: false, + } +} +use Category::{Beneficial as B, Harmful as H, Neutral as N}; +/// `MobEffects` in registration order. +pub const EFFECTS: &[EffectDef] = &[ + fx("speed", 3402751, B), + fx("slowness", 9154528, H), + fx("haste", 14270531, B), + fx("mining_fatigue", 4866583, H), + fx("strength", 16762624, B), + EffectDef { + id: "instant_health", + color: 16262179, + category: B, + instant: true, + }, + EffectDef { + id: "instant_damage", + color: 11101546, + category: H, + instant: true, + }, + fx("jump_boost", 16646020, B), + fx("nausea", 5578058, H), + fx("regeneration", 13458603, B), + fx("resistance", 9520880, B), + fx("fire_resistance", 16750848, B), + fx("water_breathing", 10017472, B), + fx("invisibility", 16185078, B), + fx("blindness", 2039587, H), + fx("night_vision", 12779366, B), + fx("hunger", 5797459, H), + fx("weakness", 4738376, H), + fx("poison", 8889187, H), + fx("wither", 7561558, H), + fx("health_boost", 16284963, B), + fx("absorption", 2445989, B), + EffectDef { + id: "saturation", + color: 16262179, + category: B, + instant: true, + }, + fx("glowing", 9740385, N), + fx("levitation", 13565951, H), + fx("luck", 5882118, B), + fx("unluck", 12624973, H), + fx("slow_falling", 15978425, B), + fx("conduit_power", 1950417, B), + fx("dolphins_grace", 8954814, B), + fx("bad_omen", 745784, N), + fx("hero_of_the_village", 4521796, B), + fx("darkness", 2696993, H), + fx("trial_omen", 1484454, N), + fx("raid_omen", 14565464, N), + fx("wind_charged", 12438015, H), + fx("weaving", 7891290, H), + fx("oozing", 10092451, H), + fx("infested", 9214860, H), + fx("breath_of_the_nautilus", 65518, B), +]; +pub fn effect(id: &str) -> Option<&'static EffectDef> { + let id = id.trim_start_matches("minecraft:"); + EFFECTS.iter().find(|e| e.id == id) +} +/// Namespaced effect ids for mob effect storage. +pub fn namespaced(id: &'static str) -> &'static str { + static IDS: OnceLock> = OnceLock::new(); + IDS.get_or_init(|| { + EFFECTS + .iter() + .map(|e| { + ( + e.id, + &*Box::leak(format!("minecraft:{}", e.id).into_boxed_str()), + ) + }) + .collect() + }) + .get(id) + .copied() + .unwrap_or(id) +} +/// A `Potion`: id, name suffix (`item.minecraft.potion.effect.`) and +/// effects as (effect, duration ticks, amplifier). +#[derive(Clone, Copy, Debug)] +pub struct PotionDef { + pub id: &'static str, + pub name: &'static str, + pub effects: &'static [(&'static str, i32, i32)], +} +const fn p( + id: &'static str, + name: &'static str, + effects: &'static [(&'static str, i32, i32)], +) -> PotionDef { + PotionDef { id, name, effects } +} +/// `Potions` in registration order. +pub const POTIONS: &[PotionDef] = &[ + p("water", "water", &[]), + p("mundane", "mundane", &[]), + p("thick", "thick", &[]), + p("awkward", "awkward", &[]), + p("night_vision", "night_vision", &[("night_vision", 3600, 0)]), + p( + "long_night_vision", + "night_vision", + &[("night_vision", 9600, 0)], + ), + p("invisibility", "invisibility", &[("invisibility", 3600, 0)]), + p( + "long_invisibility", + "invisibility", + &[("invisibility", 9600, 0)], + ), + p("leaping", "leaping", &[("jump_boost", 3600, 0)]), + p("long_leaping", "leaping", &[("jump_boost", 9600, 0)]), + p("strong_leaping", "leaping", &[("jump_boost", 1800, 1)]), + p( + "fire_resistance", + "fire_resistance", + &[("fire_resistance", 3600, 0)], + ), + p( + "long_fire_resistance", + "fire_resistance", + &[("fire_resistance", 9600, 0)], + ), + p("swiftness", "swiftness", &[("speed", 3600, 0)]), + p("long_swiftness", "swiftness", &[("speed", 9600, 0)]), + p("strong_swiftness", "swiftness", &[("speed", 1800, 1)]), + p("slowness", "slowness", &[("slowness", 1800, 0)]), + p("long_slowness", "slowness", &[("slowness", 4800, 0)]), + p("strong_slowness", "slowness", &[("slowness", 400, 3)]), + p( + "turtle_master", + "turtle_master", + &[("slowness", 400, 3), ("resistance", 400, 2)], + ), + p( + "long_turtle_master", + "turtle_master", + &[("slowness", 800, 3), ("resistance", 800, 2)], + ), + p( + "strong_turtle_master", + "turtle_master", + &[("slowness", 400, 5), ("resistance", 400, 3)], + ), + p( + "water_breathing", + "water_breathing", + &[("water_breathing", 3600, 0)], + ), + p( + "long_water_breathing", + "water_breathing", + &[("water_breathing", 9600, 0)], + ), + p("healing", "healing", &[("instant_health", 1, 0)]), + p("strong_healing", "healing", &[("instant_health", 1, 1)]), + p("harming", "harming", &[("instant_damage", 1, 0)]), + p("strong_harming", "harming", &[("instant_damage", 1, 1)]), + p("poison", "poison", &[("poison", 900, 0)]), + p("long_poison", "poison", &[("poison", 1800, 0)]), + p("strong_poison", "poison", &[("poison", 432, 1)]), + p("regeneration", "regeneration", &[("regeneration", 900, 0)]), + p( + "long_regeneration", + "regeneration", + &[("regeneration", 1800, 0)], + ), + p( + "strong_regeneration", + "regeneration", + &[("regeneration", 450, 1)], + ), + p("strength", "strength", &[("strength", 3600, 0)]), + p("long_strength", "strength", &[("strength", 9600, 0)]), + p("strong_strength", "strength", &[("strength", 1800, 1)]), + p("weakness", "weakness", &[("weakness", 1800, 0)]), + p("long_weakness", "weakness", &[("weakness", 4800, 0)]), + p("luck", "luck", &[("luck", 6000, 0)]), + p("slow_falling", "slow_falling", &[("slow_falling", 1800, 0)]), + p( + "long_slow_falling", + "slow_falling", + &[("slow_falling", 4800, 0)], + ), + p("wind_charged", "wind_charged", &[("wind_charged", 3600, 0)]), + p("weaving", "weaving", &[("weaving", 3600, 0)]), + p("oozing", "oozing", &[("oozing", 3600, 0)]), + p("infested", "infested", &[("infested", 3600, 0)]), +]; +pub fn potion(id: &str) -> Option<&'static PotionDef> { + let id = id.trim_start_matches("minecraft:"); + POTIONS.iter().find(|p| p.id == id) +} +/// `PotionContents.BASE_POTION_COLOR` (ARGB -13083194) as RGB. +pub const BASE_POTION_COLOR: u32 = 0x385DC6; +/// `PotionContents.getColor`: amplifier-weighted mix of visible effect colours. +pub fn potion_color(id: Option<&str>) -> u32 { + let Some(def) = id.and_then(potion) else { + return BASE_POTION_COLOR; + }; + let (mut r, mut g, mut b, mut total) = (0u32, 0u32, 0u32, 0u32); + for (e, _, amp) in def.effects { + let Some(e) = effect(e) else { continue }; + let w = *amp as u32 + 1; + r += w * (e.color >> 16 & 255); + g += w * (e.color >> 8 & 255); + b += w * (e.color & 255); + total += w; + } + match ( + r.checked_div(total), + g.checked_div(total), + b.checked_div(total), + ) { + (Some(r), Some(g), Some(b)) => (r << 16) | (g << 8) | b, + _ => BASE_POTION_COLOR, + } +} diff --git a/crates/horizon-client/src/brewing.rs b/crates/horizon-client/src/brewing.rs index cdd988a7a..b3cda5f90 100644 --- a/crates/horizon-client/src/brewing.rs +++ b/crates/horizon-client/src/brewing.rs @@ -7,257 +7,12 @@ use crate::{ items::{ItemStack, Items}, }; use serde_json::Value; -use std::{ - collections::{HashMap, HashSet}, - fs, - path::Path, - sync::{Arc, OnceLock}, -}; +use std::{collections::HashSet, fs, path::Path, sync::Arc}; -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub enum Category { - Beneficial, - Harmful, - Neutral, -} -/// A `MobEffect`: id (without namespace), colour, category, instantaneous. -#[derive(Clone, Copy, Debug)] -pub struct EffectDef { - pub id: &'static str, - pub color: u32, - pub category: Category, - pub instant: bool, -} -const fn fx(id: &'static str, color: u32, category: Category) -> EffectDef { - EffectDef { - id, - color, - category, - instant: false, - } -} -use Category::{Beneficial as B, Harmful as H, Neutral as N}; -/// `MobEffects` in registration order. -pub const EFFECTS: &[EffectDef] = &[ - fx("speed", 3402751, B), - fx("slowness", 9154528, H), - fx("haste", 14270531, B), - fx("mining_fatigue", 4866583, H), - fx("strength", 16762624, B), - EffectDef { - id: "instant_health", - color: 16262179, - category: B, - instant: true, - }, - EffectDef { - id: "instant_damage", - color: 11101546, - category: H, - instant: true, - }, - fx("jump_boost", 16646020, B), - fx("nausea", 5578058, H), - fx("regeneration", 13458603, B), - fx("resistance", 9520880, B), - fx("fire_resistance", 16750848, B), - fx("water_breathing", 10017472, B), - fx("invisibility", 16185078, B), - fx("blindness", 2039587, H), - fx("night_vision", 12779366, B), - fx("hunger", 5797459, H), - fx("weakness", 4738376, H), - fx("poison", 8889187, H), - fx("wither", 7561558, H), - fx("health_boost", 16284963, B), - fx("absorption", 2445989, B), - EffectDef { - id: "saturation", - color: 16262179, - category: B, - instant: true, - }, - fx("glowing", 9740385, N), - fx("levitation", 13565951, H), - fx("luck", 5882118, B), - fx("unluck", 12624973, H), - fx("slow_falling", 15978425, B), - fx("conduit_power", 1950417, B), - fx("dolphins_grace", 8954814, B), - fx("bad_omen", 745784, N), - fx("hero_of_the_village", 4521796, B), - fx("darkness", 2696993, H), - fx("trial_omen", 1484454, N), - fx("raid_omen", 14565464, N), - fx("wind_charged", 12438015, H), - fx("weaving", 7891290, H), - fx("oozing", 10092451, H), - fx("infested", 9214860, H), - fx("breath_of_the_nautilus", 65518, B), -]; -pub fn effect(id: &str) -> Option<&'static EffectDef> { - let id = id.trim_start_matches("minecraft:"); - EFFECTS.iter().find(|e| e.id == id) -} -/// Namespaced effect ids for mob effect storage. -pub fn namespaced(id: &'static str) -> &'static str { - static IDS: OnceLock> = OnceLock::new(); - IDS.get_or_init(|| { - EFFECTS - .iter() - .map(|e| { - ( - e.id, - &*Box::leak(format!("minecraft:{}", e.id).into_boxed_str()), - ) - }) - .collect() - }) - .get(id) - .copied() - .unwrap_or(id) -} -/// A `Potion`: id, name suffix (`item.minecraft.potion.effect.`) and -/// effects as (effect, duration ticks, amplifier). -#[derive(Clone, Copy, Debug)] -pub struct PotionDef { - pub id: &'static str, - pub name: &'static str, - pub effects: &'static [(&'static str, i32, i32)], -} -const fn p( - id: &'static str, - name: &'static str, - effects: &'static [(&'static str, i32, i32)], -) -> PotionDef { - PotionDef { id, name, effects } -} -/// `Potions` in registration order. -pub const POTIONS: &[PotionDef] = &[ - p("water", "water", &[]), - p("mundane", "mundane", &[]), - p("thick", "thick", &[]), - p("awkward", "awkward", &[]), - p("night_vision", "night_vision", &[("night_vision", 3600, 0)]), - p( - "long_night_vision", - "night_vision", - &[("night_vision", 9600, 0)], - ), - p("invisibility", "invisibility", &[("invisibility", 3600, 0)]), - p( - "long_invisibility", - "invisibility", - &[("invisibility", 9600, 0)], - ), - p("leaping", "leaping", &[("jump_boost", 3600, 0)]), - p("long_leaping", "leaping", &[("jump_boost", 9600, 0)]), - p("strong_leaping", "leaping", &[("jump_boost", 1800, 1)]), - p( - "fire_resistance", - "fire_resistance", - &[("fire_resistance", 3600, 0)], - ), - p( - "long_fire_resistance", - "fire_resistance", - &[("fire_resistance", 9600, 0)], - ), - p("swiftness", "swiftness", &[("speed", 3600, 0)]), - p("long_swiftness", "swiftness", &[("speed", 9600, 0)]), - p("strong_swiftness", "swiftness", &[("speed", 1800, 1)]), - p("slowness", "slowness", &[("slowness", 1800, 0)]), - p("long_slowness", "slowness", &[("slowness", 4800, 0)]), - p("strong_slowness", "slowness", &[("slowness", 400, 3)]), - p( - "turtle_master", - "turtle_master", - &[("slowness", 400, 3), ("resistance", 400, 2)], - ), - p( - "long_turtle_master", - "turtle_master", - &[("slowness", 800, 3), ("resistance", 800, 2)], - ), - p( - "strong_turtle_master", - "turtle_master", - &[("slowness", 400, 5), ("resistance", 400, 3)], - ), - p( - "water_breathing", - "water_breathing", - &[("water_breathing", 3600, 0)], - ), - p( - "long_water_breathing", - "water_breathing", - &[("water_breathing", 9600, 0)], - ), - p("healing", "healing", &[("instant_health", 1, 0)]), - p("strong_healing", "healing", &[("instant_health", 1, 1)]), - p("harming", "harming", &[("instant_damage", 1, 0)]), - p("strong_harming", "harming", &[("instant_damage", 1, 1)]), - p("poison", "poison", &[("poison", 900, 0)]), - p("long_poison", "poison", &[("poison", 1800, 0)]), - p("strong_poison", "poison", &[("poison", 432, 1)]), - p("regeneration", "regeneration", &[("regeneration", 900, 0)]), - p( - "long_regeneration", - "regeneration", - &[("regeneration", 1800, 0)], - ), - p( - "strong_regeneration", - "regeneration", - &[("regeneration", 450, 1)], - ), - p("strength", "strength", &[("strength", 3600, 0)]), - p("long_strength", "strength", &[("strength", 9600, 0)]), - p("strong_strength", "strength", &[("strength", 1800, 1)]), - p("weakness", "weakness", &[("weakness", 1800, 0)]), - p("long_weakness", "weakness", &[("weakness", 4800, 0)]), - p("luck", "luck", &[("luck", 6000, 0)]), - p("slow_falling", "slow_falling", &[("slow_falling", 1800, 0)]), - p( - "long_slow_falling", - "slow_falling", - &[("slow_falling", 4800, 0)], - ), - p("wind_charged", "wind_charged", &[("wind_charged", 3600, 0)]), - p("weaving", "weaving", &[("weaving", 3600, 0)]), - p("oozing", "oozing", &[("oozing", 3600, 0)]), - p("infested", "infested", &[("infested", 3600, 0)]), -]; -pub fn potion(id: &str) -> Option<&'static PotionDef> { - let id = id.trim_start_matches("minecraft:"); - POTIONS.iter().find(|p| p.id == id) -} -/// `PotionContents.BASE_POTION_COLOR` (ARGB -13083194) as RGB. -pub const BASE_POTION_COLOR: u32 = 0x385DC6; -/// `PotionContents.getColor`: amplifier-weighted mix of visible effect colours. -pub fn potion_color(id: Option<&str>) -> u32 { - let Some(def) = id.and_then(potion) else { - return BASE_POTION_COLOR; - }; - let (mut r, mut g, mut b, mut total) = (0u32, 0u32, 0u32, 0u32); - for (e, _, amp) in def.effects { - let Some(e) = effect(e) else { continue }; - let w = *amp as u32 + 1; - r += w * (e.color >> 16 & 255); - g += w * (e.color >> 8 & 255); - b += w * (e.color & 255); - total += w; - } - match ( - r.checked_div(total), - g.checked_div(total), - b.checked_div(total), - ) { - (Some(r), Some(g), Some(b)) => (r << 16) | (g << 8) | b, - _ => BASE_POTION_COLOR, - } -} +pub use horizon_client_core::potions::{ + BASE_POTION_COLOR, Category, EFFECTS, EffectDef, POTIONS, PotionDef, effect, namespaced, + potion, potion_color, +}; /// `MobEffectUtil.formatDuration` at 20 TPS: m:ss or h:mm:ss. pub fn format_duration(ticks: i32) -> String { let secs = ticks / 20; diff --git a/crates/horizon-client/src/effects.rs b/crates/horizon-client/src/effects.rs index 387de78b6..9511fd112 100644 --- a/crates/horizon-client/src/effects.rs +++ b/crates/horizon-client/src/effects.rs @@ -2,7 +2,7 @@ //! add/update with hidden effects, per-tick application of the periodic //! effects (regeneration, poison, wither, hunger, saturation, instant //! effects), and the derived flags the movement and damage code read. -use crate::brewing; +use horizon_client_core::potions; #[derive(Clone, Debug, PartialEq)] pub struct EffectInstance { @@ -183,7 +183,7 @@ impl PlayerEffects { pub fn from_saved(saved: &[(String, i32, i32, bool, bool)]) -> Self { let mut effects = Self::default(); for (id, duration, amplifier, ambient, particles) in saved { - if let Some(def) = brewing::effect(id) { + if let Some(def) = potions::effect(id) { let mut e = EffectInstance::new(def.id, *duration, *amplifier); e.ambient = *ambient; e.visible = *particles; @@ -306,10 +306,10 @@ impl PlayerEffects { ) -> (Vec, Vec) { let mut lasting = Vec::new(); let mut now = Vec::new(); - if let Some(def) = potion.and_then(brewing::potion) { + if let Some(def) = potion.and_then(potions::potion) { for (id, duration, amp) in def.effects { - let id = brewing::effect(id).map_or("speed", |e| e.id); - if brewing::effect(id).is_some_and(|e| e.instant) { + let id = potions::effect(id).map_or("speed", |e| e.id); + if potions::effect(id).is_some_and(|e| e.instant) { now.extend(instant(id, *amp, 1.0)); } else { // withScaledDuration: max(floor(d * scale), 1). diff --git a/crates/horizon-client/src/hud_overlays.rs b/crates/horizon-client/src/hud_overlays.rs index c6b098f75..8af2c2a0d 100644 --- a/crates/horizon-client/src/hud_overlays.rs +++ b/crates/horizon-client/src/hud_overlays.rs @@ -107,10 +107,11 @@ pub struct EffectIcon { impl From<&crate::effects::EffectInstance> for EffectIcon { fn from(effect: &crate::effects::EffectInstance) -> Self { - let def = crate::brewing::effect(effect.id); + let def = horizon_client_core::potions::effect(effect.id); Self { id: effect.id.to_owned(), - beneficial: def.is_some_and(|d| d.category == crate::brewing::Category::Beneficial), + beneficial: def + .is_some_and(|d| d.category == horizon_client_core::potions::Category::Beneficial), color: def.map_or(0, |d| d.color as i32), ambient: effect.ambient, duration: effect.duration, diff --git a/docs/design-system.md b/docs/design-system.md index 0b171d4c2..aec060457 100644 --- a/docs/design-system.md +++ b/docs/design-system.md @@ -170,9 +170,12 @@ of the main action. The game's menus keep `LIGHT` and `DARK`. all rights reserved, so it is not shown. - **Partner banner**: the one exception to shipping no third-party pictures. Sculk, a server host, sponsors Horizon: its banner (`launcher/assets/sculk-banner.webp`, `launcher/src/partner.rs`) sits - under a muted mono "Partner" label at the end of the Servers page and of Home, below Play, and opens - Sculk's page in the browser. The website shows the same banner the same way on Home and the hosting - docs, as a `rel="sponsored"` link. + under a muted mono "Partner" label at the end of the Servers page and opens Sculk's page in the + browser. The sidebar of the other pages shows a card made for its width instead: Sculk's characters + and logo cropped from the same banner, and the text drawn by the launcher in its language, so it + stays readable; it keeps Sculk's dark card, cyan and rounded corners in both themes, as an ad does, + and turns compact (characters beside the text) when the window is too short. The website shows the + banner the same way on Home and the hosting docs, as a `rel="sponsored"` link. - **Pixel art drawn in code.** The stone behind the pages is close shades of the page colour (`TILE_SHADES`), never Minecraft's stone; the landscape is a banded sky, a sun cut in slices like the mark, hills and square trees (a sunset in dark, a dawn in light). The launcher bakes them in diff --git a/launcher/assets/sculk-card-art.webp b/launcher/assets/sculk-card-art.webp new file mode 100644 index 000000000..13b9e10e4 Binary files /dev/null and b/launcher/assets/sculk-card-art.webp differ diff --git a/launcher/assets/sculk-logo.webp b/launcher/assets/sculk-logo.webp new file mode 100644 index 000000000..8877cd1d9 Binary files /dev/null and b/launcher/assets/sculk-logo.webp differ diff --git a/launcher/lang/fr.json b/launcher/lang/fr.json index 68ef9f744..189577fb3 100644 --- a/launcher/lang/fr.json +++ b/launcher/lang/fr.json @@ -151,6 +151,11 @@ "Not played yet": "Pas encore joué", "under a minute": "moins d'une minute", "PARTNER": "PARTENAIRE", + "Your Minecraft server, {online}.": "Votre serveur Minecraft, {online}.", + "24/7 online": "en ligne 24h/24", + "Ready in under a minute": "Prêt en moins d'une minute", + "Get my server": "Obtenir mon serveur", + "15% off": "-15 %", "Not prepared. Horizon needs the files of your own Minecraft {version}.": "Pas préparé. Horizon a besoin des fichiers de votre propre Minecraft {version}.", "Prepared for Minecraft {version}": "Préparé pour Minecraft {version}", "Prepared for Minecraft {version}, without its sounds: the game will be silent. Prepare again to copy them from your Minecraft install.": "Préparé pour Minecraft {version}, sans ses sons : le jeu sera muet. Préparez à nouveau pour les copier depuis votre installation de Minecraft." diff --git a/launcher/lang/ru.json b/launcher/lang/ru.json index 48051bfac..a992ef819 100644 --- a/launcher/lang/ru.json +++ b/launcher/lang/ru.json @@ -151,6 +151,11 @@ "Not played yet": "Ещё не запускалась", "under a minute": "меньше минуты", "PARTNER": "ПАРТНЁР", + "Your Minecraft server, {online}.": "Ваш сервер Minecraft, {online}.", + "24/7 online": "онлайн 24/7", + "Ready in under a minute": "Готов меньше чем за минуту", + "Get my server": "Получить сервер", + "15% off": "скидка 15%", "Not prepared. Horizon needs the files of your own Minecraft {version}.": "Не подготовлено. Horizon нужны файлы вашего собственного Minecraft {version}.", "Prepared for Minecraft {version}": "Подготовлено для Minecraft {version}", "Prepared for Minecraft {version}, without its sounds: the game will be silent. Prepare again to copy them from your Minecraft install.": "Подготовлено для Minecraft {version}, но без звуков: игра будет беззвучной. Подготовьте заново, чтобы скопировать их из вашей установки Minecraft." diff --git a/launcher/src/main.rs b/launcher/src/main.rs index 83577f3c5..1eeb1477c 100644 --- a/launcher/src/main.rs +++ b/launcher/src/main.rs @@ -1703,7 +1703,7 @@ impl Launcher { /// The sidebar: Horizon and the imported modpacks, the player's servers, then the /// launcher's own update, the community links and its version. - fn sidebar(&mut self, cx: &mut Context) -> Stateful
{ + fn sidebar(&mut self, window: &Window, cx: &mut Context) -> Stateful
{ let t = self.theme; self.load_packs(); let heading = |label: String| { @@ -1752,12 +1752,14 @@ impl Launcher { this.open_instance_dialog(None); cx.notify(); })); + let items = self.instance_items(heading, cx); + let mut rows = items.len(); let list = div() .flex() .flex_col() .gap(px(4.)) .child(heading(tr("INSTANCES").into()).child(add)) - .children(self.instance_items(heading, cx)); + .children(items); let servers: Vec<_> = self .servers .sidebar_list() @@ -1767,6 +1769,8 @@ impl Launcher { if !servers.is_empty() { list = list.child(heading(tr("SERVERS").into())); } + rows += servers.len(); + let headings = 1 + usize::from(!servers.is_empty()); for e in servers { let up = self.servers.is_up(&e.dir); let open = self.page == Page::Servers && self.servers.open.as_ref() == Some(&e.dir); @@ -1856,12 +1860,20 @@ impl Launcher { } _ => {} } - // Sculk's banner, small, above the links: seen without scrolling, on every page but Servers, which - // shows it large. After a while on screen a "Hide" beside its label puts it away for good. + // Sculk's card above the links: seen without scrolling, on every page but Servers, which shows + // its wide banner. Tall where the sidebar has the height for it besides its rows (about 60 + // high each, under headings of about 40) and the links, compact otherwise. After a while on + // screen a "Hide" beside its label puts it away for good. if self.page != Page::Servers && !self.settings.partner_hidden { - let mut side = div().relative().mb(px(8.)).child(partner::banner( + let free = f32::from(window.viewport_size().height) + - theme::TOPBAR + - 40. * headings as f32 + - 60. * rows as f32 + - 110.; + let mut side = div().relative().mb(px(8.)).child(partner::card( "partner-side", theme::SIDEBAR - 20., + free < partner::TALL_HEIGHT, &t, )); if self.settings.partner_seen_secs >= partner::SEEN_BEFORE_HIDE { @@ -3646,7 +3658,7 @@ impl Render for Launcher { } let stone = self.art.stone(t.page_rgb, t.dark, window.scale_factor()); let topbar = self.topbar(window, cx); - let sidebar = self.sidebar(cx); + let sidebar = self.sidebar(window, cx); let mut root = div() .id("root") .track_focus(&self.root_focus) diff --git a/launcher/src/partner.rs b/launcher/src/partner.rs index 6242f9228..ae82ebd7f 100644 --- a/launcher/src/partner.rs +++ b/launcher/src/partner.rs @@ -1,8 +1,12 @@ -//! Sculk's banner: a server host that sponsors Horizon (Ludovic, 2026-10-26), large on the Servers page -//! and small at the foot of the sidebar on the other pages, where it shows without scrolling. The picture is in the binary, never fetched; a click opens Sculk's page in -//! the browser. A "Partner" label above it says it is an ad. +//! Sculk, a server host that sponsors Horizon (Ludovic, 2026-10-26): its wide banner on the Servers +//! page, and a card made for the sidebar on the other pages, where the banner's baked-in text was too +//! small to read. The pictures are in the binary, never fetched; a click opens Sculk's page in the +//! browser. A "Partner" label above each says it is an ad. use crate::theme::Theme; -use gpui::{div, img, prelude::*, px, ClickEvent, Div, Image, ImageFormat, Stateful}; +use gpui::{ + div, img, prelude::*, px, rgb, ClickEvent, Div, FontWeight, HighlightStyle, Image, ImageFormat, + Rgba, SharedString, Stateful, StyledText, +}; use std::sync::{Arc, LazyLock}; pub const URL: &str = "https://my.sculkhosting.com/ref/horizon"; @@ -51,9 +55,256 @@ pub fn banner(id: &'static str, width: f32, t: &Theme) -> Stateful
{ crate::keyboard(el, &t) } +/// Sculk's characters (Steve, Alex and the wolf) cropped from its banner at 2x the card's width. +/// Above `ART_TOP` (in the card's 228 logical pixels) the picture is transparent but for their heads +/// and the pickaxe, which stand out of the card; its foot and right edge fade into `CARD`. +const ART_WIDTH: f32 = 456.; +const ART_HEIGHT: f32 = 364.; +const ART_TOP: f32 = 11.; +static ART: LazyLock> = LazyLock::new(|| { + Arc::new(Image::from_bytes( + ImageFormat::Webp, + include_bytes!("../assets/sculk-card-art.webp").to_vec(), + )) +}); + +/// Sculk's mark and name, cropped from its banner, 2x for a 18 pixel height. +const LOGO_WIDTH: f32 = 191.; +const LOGO_HEIGHT: f32 = 36.; +static LOGO: LazyLock> = LazyLock::new(|| { + Arc::new(Image::from_bytes( + ImageFormat::Webp, + include_bytes!("../assets/sculk-logo.webp").to_vec(), + )) +}); + +/// Sculk's colours, taken from its banner: the card is Sculk's in both themes, as an ad is. +const CARD: u32 = 0x0b0d12; +const CYAN: u32 = 0x5dd4fb; +const CYAN_HOVER: u32 = 0x8fe3fd; +const WHITE: u32 = 0xf1f5f9; +const GREY: u32 = 0x9aa6b2; +const ON_CYAN: u32 = 0x062330; + +/// The promo code: Sculk's, never translated. +const CODE: &str = "HORIZON15"; + +/// What the tall card needs of the sidebar's height, label included, with room for a third line of +/// headline: below it the sidebar shows the compact card. +pub const TALL_HEIGHT: f32 = 410.; + +/// "Your Minecraft server, 24/7 online." with "24/7 online" in Sculk's cyan, in the launcher's +/// language. +fn headline() -> StyledText { + let online = horizon_launcher::i18n::tr("24/7 online"); + let line = horizon_launcher::i18n::tr("Your Minecraft server, {online}."); + let (before, after) = line.split_once("{online}").unwrap_or((line, "")); + let text = format!("{before}{online}{after}"); + let lit = before.len()..before.len() + online.len(); + StyledText::new(SharedString::from(text)).with_highlights([( + lit, + HighlightStyle { + color: Some(rgb(CYAN).into()), + ..Default::default() + }, + )]) +} + +/// "HORIZON15 · 15% off" in a dashed cyan frame, as on Sculk's banner. +fn code_chip(size: f32, height: f32) -> Div { + div() + .flex() + .items_center() + .justify_center() + .gap(px(6.)) + .h(px(height)) + .px(px(10.)) + .border_1() + .border_dashed() + .border_color(rgba(CYAN, 0.7)) + .rounded(px(6.)) + .font_family(crate::theme::MONO) + .text_size(px(size)) + .whitespace_nowrap() + .child( + div() + .text_color(rgb(WHITE)) + .font_weight(FontWeight::SEMIBOLD) + .child(CODE), + ) + .child(div().text_color(rgb(GREY)).child("·")) + .child( + div() + .text_color(rgb(CYAN)) + .child(horizon_launcher::i18n::tr("15% off")), + ) +} + +fn rgba(hex: u32, alpha: f32) -> Rgba { + Rgba { + a: alpha, + ..rgb(hex) + } +} + +/// Sculk's card for the sidebar, `width` logical pixels wide: its characters standing out of the top, +/// then its name, the headline, a line, a "Get my server" button and the promo code, all drawn by +/// the launcher so they stay sharp and follow its language. `compact` puts the characters beside a +/// shorter text, for windows too short for the tall card. Hovering lifts it a little. +pub fn card(id: &'static str, width: f32, compact: bool, t: &Theme) -> Stateful
{ + let t = *t; + let label = crate::text(crate::theme::MICRO) + .text_color(t.muted) + .group_hover(id, move |s| s.text_color(t.ink)) + .child(horizon_launcher::i18n::tr("PARTNER")); + let face = div() + .relative() + .flex() + .flex_none() + .w(px(width)) + .bg(rgb(CARD)) + .border_1() + .border_color(rgba(CYAN, 0.22)) + .rounded(px(10.)) + .group_hover(id, |s| s.top(px(-2.)).border_color(rgba(CYAN, 0.5))); + let logo = |height: f32| { + img(LOGO.clone()) + .flex_none() + .w(px(height * LOGO_WIDTH / LOGO_HEIGHT)) + .h(px(height)) + }; + let face = if compact { + // The characters beside the text, their faded foot melting into the card, the code under both. + let art_w = 104.; + face.flex_col() + .child( + div() + .flex() + .items_end() + .child( + div() + .flex() + .flex_col() + .flex_1() + .min_w_0() + .gap(px(8.)) + .pl(px(12.)) + .pt(px(12.)) + .child(logo(13.)) + .child( + div() + .text_size(px(15.)) + .line_height(px(19.)) + .font_weight(FontWeight::SEMIBOLD) + .text_color(rgb(WHITE)) + .child(headline()), + ), + ) + .child( + img(ART.clone()) + .flex_none() + .w(px(art_w)) + .h(px(art_w * ART_HEIGHT / ART_WIDTH)), + ), + ) + .child( + div() + .flex() + .px(px(12.)) + .pt(px(6.)) + .pb(px(12.)) + .child(code_chip(11., 26.).flex_1()), + ) + } else { + let art_h = width * ART_HEIGHT / ART_WIDTH; + let button = div() + .flex() + .items_center() + .justify_center() + .h(px(36.)) + .rounded(px(8.)) + .bg(rgb(CYAN)) + .group_hover(id, |s| s.bg(rgb(CYAN_HOVER))) + .text_color(rgb(ON_CYAN)) + .text_size(px(14.)) + .font_weight(FontWeight::SEMIBOLD) + .child(horizon_launcher::i18n::tr("Get my server")); + // The art stands out of the card's top; the text starts over its faded foot. + face.mt(px(ART_TOP)) + .flex_col() + .child( + img(ART.clone()) + .absolute() + .top(px(-ART_TOP)) + .left_0() + .w(px(width)) + .h(px(art_h)), + ) + .child( + div() + .flex() + .flex_col() + .pt(px(art_h - ART_TOP - 14.)) + .px(px(16.)) + .pb(px(16.)) + .child(logo(16.)) + .child( + div() + .mt(px(12.)) + .text_size(px(19.)) + .line_height(px(23.)) + .font_weight(FontWeight::SEMIBOLD) + .text_color(rgb(WHITE)) + .child(headline()), + ) + .child( + div() + .mt(px(6.)) + .text_size(px(13.)) + .line_height(px(18.)) + .text_color(rgb(GREY)) + .child(horizon_launcher::i18n::tr("Ready in under a minute")), + ) + .child(div().mt(px(16.)).child(button)) + .child(div().mt(px(8.)).flex().child(code_chip(12., 30.).flex_1())), + ) + }; + let el = div() + .id(id) + .group(id) + .flex() + .flex_col() + .gap(px(8.)) + .w(px(width)) + .cursor_pointer() + .child(label) + .child(face) + .on_click(|_: &ClickEvent, _, cx| cx.open_url(URL)); + crate::keyboard(el, &t) +} + #[cfg(test)] mod tests { - use super::{HEIGHT, WIDTH}; + use super::{ART_HEIGHT, ART_WIDTH, HEIGHT, LOGO_HEIGHT, LOGO_WIDTH, WIDTH}; + + /// Each bundled picture decodes as a WebP of the size the code lays it out at. + #[test] + fn the_card_pictures_decode() { + for (bytes, size) in [ + ( + &include_bytes!("../assets/sculk-card-art.webp")[..], + (ART_WIDTH, ART_HEIGHT), + ), + ( + &include_bytes!("../assets/sculk-logo.webp")[..], + (LOGO_WIDTH, LOGO_HEIGHT), + ), + ] { + let pic = image::load_from_memory_with_format(bytes, image::ImageFormat::WebP) + .expect("a WebP"); + assert_eq!((pic.width(), pic.height()), (size.0 as u32, size.1 as u32)); + } + } #[test] fn the_bundled_banner_decodes() {