Merge pull request #2773 from ludovic111/feat/sculk-sidebar-card
🤖 Agent: merging the Sculk sidebar card (Ludovic approved the screenshots); fmt, clippy -D warnings and launcher tests pass on the head merged with main.
This commit is contained in:
@@ -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
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 20 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 5.0 KiB |
@@ -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."
|
||||
|
||||
@@ -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."
|
||||
|
||||
+18
-6
@@ -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<Self>) -> Stateful<Div> {
|
||||
fn sidebar(&mut self, window: &Window, cx: &mut Context<Self>) -> Stateful<Div> {
|
||||
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)
|
||||
|
||||
+256
-5
@@ -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<Div> {
|
||||
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<Arc<Image>> = 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<Arc<Image>> = 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<Div> {
|
||||
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() {
|
||||
|
||||
Reference in New Issue
Block a user