Menus: Horizon-style options screen, pause polish, screenshots
Options open as the launcher's Settings page: a sidebar with the sliding selection (Video, Audio, Controls, Accessibility, Language, Chat, Interface) and rows with a switch, slider or value button per option (options_horizon.rs; new sections or rows slot into SECTIONS). Key binds, the language list and resource packs open vanilla's pages. Interface holds Menu style (Horizon / Classic). The pause menu hides the in-game HUD over the blurred world. Scripted and frame-limited runs default to Classic, so the harnesses see vanilla's screens. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -3007,7 +3007,8 @@ impl Game<'_> {
|
||||
// the sleep overlay, debug screen and open screens still draw.
|
||||
let spectator = self.spectator();
|
||||
let (wi, hi) = (w as i32, h as i32);
|
||||
if !self.ui.hide_gui {
|
||||
// Horizon's pause menu sits over the blurred world alone.
|
||||
if !self.ui.hide_gui && !self.horizon_pause() {
|
||||
self.draw_spyglass(&mut batch);
|
||||
// Hud.extractCrosshair / extractItemHotbar / extractPlayerHealth /
|
||||
// extractVehicleHealth and the experience bar, laid out by hud_layout.
|
||||
@@ -8047,6 +8048,7 @@ impl ApplicationHandler for Game<'_> {
|
||||
+ (turn(KeyCode::ArrowDown) - turn(KeyCode::ArrowUp)) * 90.0 * secs)
|
||||
.clamp(-90.0, 90.0);
|
||||
self.update_backdrop()?;
|
||||
horizon_client::ui_theme::set_backdrop(self.backdrop_fade());
|
||||
if self.screen != Screen::Paused {
|
||||
self.pause_since = None;
|
||||
}
|
||||
@@ -8298,6 +8300,13 @@ pub fn run() -> Result<()> {
|
||||
let game_root = options.resources.clone();
|
||||
let mut settings = Settings::load(&std::env::current_dir()?.join("options.txt"));
|
||||
horizon_client::ui_theme::load_preferences(&std::env::current_dir()?);
|
||||
// Scripted and frame-limited runs (the parity harnesses) see vanilla's
|
||||
// screens unless HORIZON_MENU_STYLE asks otherwise.
|
||||
if (options.frames.is_some() || options.control.is_some())
|
||||
&& std::env::var_os("HORIZON_MENU_STYLE").is_none()
|
||||
{
|
||||
horizon_client::ui_theme::set_style(horizon_client::ui_theme::MenuStyle::Classic);
|
||||
}
|
||||
if let Some(d) = options.distance_override {
|
||||
settings.render_distance = d;
|
||||
}
|
||||
|
||||
@@ -80,6 +80,7 @@ pub mod nbt_path;
|
||||
pub mod net;
|
||||
pub mod options_file;
|
||||
pub mod options_fixes;
|
||||
pub mod options_horizon;
|
||||
pub mod options_ui;
|
||||
pub mod pack_screen;
|
||||
pub mod packs;
|
||||
|
||||
@@ -0,0 +1,518 @@
|
||||
//! The options screen in Horizon's menu style, laid out like the launcher's
|
||||
//! Settings page: a sidebar with the sliding selection (one item per
|
||||
//! section), then the section's page header and settings rows (label column,
|
||||
//! value, control on the right) between 1px dividers.
|
||||
//!
|
||||
//! Adding settings (for example the Simple/Advanced graphics menu): add rows
|
||||
//! to a section in [`SECTIONS`], or a new section. A row is an [`HRow`]: an
|
||||
//! existing option (`Opt`, drawn as a switch, a slider or a value button from
|
||||
//! its kind), a header, or a button opening one of vanilla's pages. New kinds
|
||||
//! of control belong in `ui_theme` so the launcher-matching look stays in one
|
||||
//! place. Everything else (sliders dragging, scrolling, Done) is handled here.
|
||||
use crate::{
|
||||
hud::{HudAtlas, HudBatch},
|
||||
options_ui::{Event, Kind, Opt, OptionsUi, Page, apply_preset},
|
||||
settings::{SOUND_SOURCES, Settings},
|
||||
ui_theme::{
|
||||
self as t, CONTROL, Face, Kind as Button, MenuStyle, ROW_LABEL, SIDEBAR, SMALL, Ui, color,
|
||||
id,
|
||||
},
|
||||
};
|
||||
|
||||
/// One row of a section.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub enum HRow {
|
||||
Header(&'static str),
|
||||
Opt(Opt),
|
||||
/// A label, a value and a button opening one of vanilla's pages.
|
||||
Page(&'static str, &'static str, Page),
|
||||
/// Menu style: Horizon / Classic.
|
||||
Style,
|
||||
}
|
||||
/// A sidebar section: name, description, rows.
|
||||
pub struct Section {
|
||||
pub name: &'static str,
|
||||
pub blurb: &'static str,
|
||||
pub rows: fn(&Settings) -> Vec<HRow>,
|
||||
}
|
||||
pub const SECTIONS: &[Section] = &[
|
||||
Section {
|
||||
name: "Video",
|
||||
blurb: "Display, quality and how the world is drawn.",
|
||||
rows: |_| {
|
||||
let mut r = vec![HRow::Header("Display")];
|
||||
r.extend(
|
||||
[
|
||||
Opt::Fullscreen,
|
||||
Opt::Vsync,
|
||||
Opt::MaxFps,
|
||||
Opt::InactivityFps,
|
||||
Opt::GuiScale,
|
||||
Opt::Gamma,
|
||||
]
|
||||
.map(HRow::Opt),
|
||||
);
|
||||
r.push(HRow::Header("Quality"));
|
||||
r.extend(
|
||||
[
|
||||
Opt::Preset,
|
||||
Opt::RenderDistance,
|
||||
Opt::SimulationDistance,
|
||||
Opt::SmoothLighting,
|
||||
Opt::Clouds,
|
||||
Opt::CloudRange,
|
||||
Opt::Particles,
|
||||
Opt::Mipmaps,
|
||||
Opt::EntityShadows,
|
||||
Opt::EntityDistance,
|
||||
Opt::BiomeBlend,
|
||||
Opt::CutoutLeaves,
|
||||
Opt::ImprovedTransparency,
|
||||
Opt::WeatherRadius,
|
||||
Opt::ChunkBuilder,
|
||||
]
|
||||
.map(HRow::Opt),
|
||||
);
|
||||
r.push(HRow::Header("Preferences"));
|
||||
r.extend(
|
||||
[
|
||||
Opt::Fov,
|
||||
Opt::ViewBobbing,
|
||||
Opt::Autosave,
|
||||
Opt::Vignette,
|
||||
Opt::AttackIndicator,
|
||||
Opt::ChunkFade,
|
||||
]
|
||||
.map(HRow::Opt),
|
||||
);
|
||||
r
|
||||
},
|
||||
},
|
||||
Section {
|
||||
name: "Audio",
|
||||
blurb: "Volume for every kind of sound, and subtitles.",
|
||||
rows: |_| {
|
||||
let mut r: Vec<HRow> = (0..SOUND_SOURCES.len())
|
||||
.map(|i| HRow::Opt(Opt::Volume(i)))
|
||||
.collect();
|
||||
r.push(HRow::Opt(Opt::ShowSubtitles));
|
||||
r
|
||||
},
|
||||
},
|
||||
Section {
|
||||
name: "Controls",
|
||||
blurb: "Keys, the mouse and how movement keys behave.",
|
||||
rows: |_| {
|
||||
let mut r = vec![HRow::Page(
|
||||
"Key binds",
|
||||
"Every action and its key",
|
||||
Page::KeyBinds,
|
||||
)];
|
||||
r.push(HRow::Header("Mouse"));
|
||||
r.extend(
|
||||
[
|
||||
Opt::Sensitivity,
|
||||
Opt::WheelSensitivity,
|
||||
Opt::InvertY,
|
||||
Opt::DiscreteScroll,
|
||||
]
|
||||
.map(HRow::Opt),
|
||||
);
|
||||
r.push(HRow::Header("Movement"));
|
||||
r.extend([Opt::ToggleCrouch, Opt::ToggleSprint, Opt::AutoJump].map(HRow::Opt));
|
||||
r
|
||||
},
|
||||
},
|
||||
Section {
|
||||
name: "Accessibility",
|
||||
blurb: "Contrast, motion, text backgrounds and notifications.",
|
||||
rows: |_| {
|
||||
[
|
||||
Opt::HighContrast,
|
||||
Opt::MenuBlur,
|
||||
Opt::TextBackgroundOpacity,
|
||||
Opt::NotificationDisplayTime,
|
||||
Opt::ShowSubtitles,
|
||||
Opt::ViewBobbing,
|
||||
Opt::ChatLineSpacing,
|
||||
]
|
||||
.map(HRow::Opt)
|
||||
.to_vec()
|
||||
},
|
||||
},
|
||||
Section {
|
||||
name: "Language",
|
||||
blurb: "The game's language and its font.",
|
||||
rows: |_| {
|
||||
vec![
|
||||
HRow::Page("Language", "", Page::Language),
|
||||
HRow::Opt(Opt::ForceUnicode),
|
||||
HRow::Opt(Opt::JapaneseGlyphs),
|
||||
]
|
||||
},
|
||||
},
|
||||
Section {
|
||||
name: "Chat",
|
||||
blurb: "What chat shows and how it looks.",
|
||||
rows: |_| {
|
||||
[
|
||||
Opt::ChatVisibility,
|
||||
Opt::ChatColors,
|
||||
Opt::ChatLinks,
|
||||
Opt::ChatOpacity,
|
||||
Opt::ChatScale,
|
||||
Opt::ChatWidth,
|
||||
Opt::ChatHeightFocused,
|
||||
Opt::ChatHeightUnfocused,
|
||||
Opt::AutoSuggestions,
|
||||
Opt::ReducedDebugInfo,
|
||||
]
|
||||
.map(HRow::Opt)
|
||||
.to_vec()
|
||||
},
|
||||
},
|
||||
Section {
|
||||
name: "Interface",
|
||||
blurb: "Menus and resource packs.",
|
||||
rows: |_| {
|
||||
vec![
|
||||
HRow::Style,
|
||||
HRow::Page("Resource packs", "Textures, sounds and fonts", Page::Packs),
|
||||
]
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
const NAV: u64 = id("options.nav", 0);
|
||||
const DONE: u64 = id("options.done", 0);
|
||||
const ROW: u64 = id("options.row", 0);
|
||||
const STYLE: u64 = id("options.style", 0);
|
||||
const ROW_H: f32 = 12.0 + CONTROL + 12.0;
|
||||
const HEADER_H: f32 = 40.0;
|
||||
|
||||
/// Whether an option is an on/off switch, and its value.
|
||||
fn switch_value(opt: Opt, s: &Settings) -> Option<bool> {
|
||||
Some(match opt {
|
||||
Opt::InvertY => s.invert_y,
|
||||
Opt::DiscreteScroll => s.discrete_scroll,
|
||||
Opt::ViewBobbing => s.view_bobbing,
|
||||
Opt::Vsync => s.vsync,
|
||||
Opt::Fullscreen => s.fullscreen,
|
||||
Opt::SmoothLighting => s.smooth_lighting,
|
||||
Opt::EntityShadows => s.entity_shadows,
|
||||
Opt::Vignette => s.vignette,
|
||||
Opt::Autosave => s.autosave_indicator,
|
||||
Opt::CutoutLeaves => s.cutout_leaves,
|
||||
Opt::ImprovedTransparency => s.improved_transparency,
|
||||
Opt::AutoJump => s.auto_jump,
|
||||
Opt::ChatColors => s.chat_colors,
|
||||
Opt::ChatLinks => s.chat_links,
|
||||
Opt::AutoSuggestions => s.auto_suggestions,
|
||||
Opt::ReducedDebugInfo => s.reduced_debug_info,
|
||||
Opt::HighContrast => s.high_contrast,
|
||||
Opt::ShowSubtitles => s.show_subtitles,
|
||||
Opt::ForceUnicode => s.force_unicode,
|
||||
Opt::JapaneseGlyphs => s.japanese_glyphs,
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
/// The option's caption and value text, from its vanilla label
|
||||
/// ("Caption: Value") and its caption key.
|
||||
fn caption_value(opt: Opt, s: &Settings) -> (String, String) {
|
||||
let label = opt.label(s).plain();
|
||||
let caption = crate::text::Text::translate(opt.caption(), &[]).plain();
|
||||
if let Some(rest) = label.strip_prefix(&caption) {
|
||||
return (caption, rest.trim_start_matches([':', ' ']).to_owned());
|
||||
}
|
||||
match label.split_once(": ") {
|
||||
Some((c, v)) => (c.to_owned(), v.to_owned()),
|
||||
None => (caption, label),
|
||||
}
|
||||
}
|
||||
/// What a click hit.
|
||||
enum Target {
|
||||
Nav(usize),
|
||||
Done,
|
||||
Row(usize),
|
||||
Slider(Opt, f32),
|
||||
Style(usize),
|
||||
}
|
||||
impl OptionsUi {
|
||||
/// Lay out (and draw, on a real frame) the Horizon options shell.
|
||||
/// Returns the sliders' tracks (option, x, width) for dragging.
|
||||
fn horizon_layout(&mut self, s: &Settings, ui: &mut Ui, backdrop: f32) -> Vec<(Opt, f32, f32)> {
|
||||
let (w, h) = (ui.w, ui.h);
|
||||
if self.in_world {
|
||||
ui.atmosphere(0.45, 1.0);
|
||||
} else {
|
||||
if backdrop < 1.0 {
|
||||
ui.cold_background(1.0 - backdrop);
|
||||
}
|
||||
ui.atmosphere(0.66, 1.0);
|
||||
}
|
||||
let section = self.section.min(SECTIONS.len() - 1);
|
||||
// The sidebar.
|
||||
ui.fill(0.0, 0.0, SIDEBAR, h, color::with_alpha(color::SIDEBAR, 0.8));
|
||||
ui.vline(SIDEBAR - 1.0, 0.0, h, color::BORDER);
|
||||
ui.text_line(
|
||||
Face::Display,
|
||||
22.0,
|
||||
30.0,
|
||||
22.0,
|
||||
16.0,
|
||||
color::TEXT,
|
||||
"Options",
|
||||
);
|
||||
let names: Vec<&str> = SECTIONS.iter().map(|s| s.name).collect();
|
||||
ui.sidebar_list(NAV, 12.0, 66.0, SIDEBAR - 24.0, &names, section);
|
||||
let dy = h - 12.0 - CONTROL;
|
||||
ui.button(
|
||||
DONE,
|
||||
[12.0, dy, SIDEBAR - 24.0, CONTROL],
|
||||
"Done",
|
||||
Button::Secondary,
|
||||
true,
|
||||
);
|
||||
// The page fades in and rises 8 when the section changes.
|
||||
let p = ui.tween(id("options.page", section as u64), 1.0, t::move_());
|
||||
if self.section_shown != Some(section) {
|
||||
self.section_shown = Some(section);
|
||||
ui.restart(id("options.page", section as u64), 0.0, 1.0, t::move_());
|
||||
}
|
||||
let x = SIDEBAR + 48.0;
|
||||
let cw = (w - x - 48.0).min(760.0);
|
||||
ui.opacity = p;
|
||||
ui.offset = (0.0, 8.0 * (1.0 - p));
|
||||
let sec = &SECTIONS[section];
|
||||
let mut y = 36.0;
|
||||
y += ui.page_header(x, y, sec.name, sec.blurb) + 24.0;
|
||||
let top = y;
|
||||
let rows = (sec.rows)(s);
|
||||
let content: f32 = rows
|
||||
.iter()
|
||||
.map(|r| {
|
||||
if matches!(r, HRow::Header(_)) {
|
||||
HEADER_H
|
||||
} else {
|
||||
ROW_H
|
||||
}
|
||||
})
|
||||
.sum();
|
||||
let bottom = h - 24.0;
|
||||
let max = (content - (bottom - top)).max(0.0);
|
||||
self.hscroll = self.hscroll.clamp(0.0, max);
|
||||
y -= self.hscroll;
|
||||
let vstart = ui.batch.vertices.len();
|
||||
let hstart = ui.hits.len();
|
||||
let mut sliders = Vec::new();
|
||||
ui.divider(x, y, cw);
|
||||
let control_x = x + cw;
|
||||
for (i, row) in rows.iter().enumerate() {
|
||||
match *row {
|
||||
HRow::Header(label) => {
|
||||
ui.text(Face::Medium, SMALL, x, y + 18.0, color::FAINT, label);
|
||||
y += HEADER_H;
|
||||
ui.divider(x, y, cw);
|
||||
continue;
|
||||
}
|
||||
HRow::Opt(opt) => {
|
||||
let (caption, value) = caption_value(opt, s);
|
||||
let cy = y + ROW_H / 2.0;
|
||||
if let Some(on) = switch_value(opt, s) {
|
||||
ui.row(x, y, &caption, "", 0.0);
|
||||
ui.switch(ROW + i as u64, control_x, cy, on);
|
||||
} else if let Kind::Slider(v) = opt.kind(s) {
|
||||
let sw = 220.0_f32.min(cw - ROW_LABEL - 200.0).max(80.0);
|
||||
ui.row(x, y, &caption, &value, cw - ROW_LABEL - 16.0 - sw - 24.0);
|
||||
let sx = control_x - sw - 8.0;
|
||||
ui.slider(ROW + i as u64, sx, cy, sw, v);
|
||||
sliders.push((opt, sx, sw));
|
||||
} else {
|
||||
ui.row(x, y, &caption, "", 0.0);
|
||||
let bw = ui.button_width(&value, false).max(96.0);
|
||||
ui.button(
|
||||
ROW + i as u64,
|
||||
[control_x - bw, y + 12.0, bw, CONTROL],
|
||||
&value,
|
||||
Button::Secondary,
|
||||
true,
|
||||
);
|
||||
}
|
||||
}
|
||||
HRow::Page(label, value, _) => {
|
||||
let value = if value.is_empty() {
|
||||
self.languages
|
||||
.iter()
|
||||
.find(|l| l.code == s.language)
|
||||
.map_or_else(|| s.language.clone(), |l| l.label())
|
||||
} else {
|
||||
value.to_owned()
|
||||
};
|
||||
ui.row(x, y, label, &value, cw - ROW_LABEL - 140.0);
|
||||
let bw = ui.button_width("Change…", false);
|
||||
let open = if label == "Language" {
|
||||
"Change…"
|
||||
} else {
|
||||
"Open…"
|
||||
};
|
||||
let bw = bw.max(ui.button_width(open, false));
|
||||
ui.button(
|
||||
ROW + i as u64,
|
||||
[control_x - bw, y + 12.0, bw, CONTROL],
|
||||
open,
|
||||
Button::Secondary,
|
||||
true,
|
||||
);
|
||||
}
|
||||
HRow::Style => {
|
||||
ui.row(x, y, "Menu style", "", 0.0);
|
||||
let labels = ["Horizon", "Classic"];
|
||||
let probe = ui.segmented(STYLE, -10_000.0, -10_000.0, &labels, 0);
|
||||
let selected = usize::from(t::style() == MenuStyle::Classic);
|
||||
ui.segmented(STYLE, control_x - probe, y + 12.0 - 3.0, &labels, selected);
|
||||
}
|
||||
}
|
||||
y += ROW_H;
|
||||
ui.divider(x, y, cw);
|
||||
}
|
||||
// Clip the rows to the page below the header, like the launcher's scroll view.
|
||||
let (ox, oy) = ui.offset;
|
||||
let scale = ui.batch.scale;
|
||||
let k = ui.density / scale;
|
||||
let (y0, y1) = ((top - 1.0 + oy) * k, (bottom + oy) * k);
|
||||
ui.batch.clip_since(vstart, 0.0, y0, ui.batch.width, y1);
|
||||
let (cy0, cy1) = (top - 1.0 + oy, bottom + oy);
|
||||
let kept: Vec<_> = ui
|
||||
.hits
|
||||
.drain(hstart..)
|
||||
.filter(|h| h.rect[1] >= cy0 && h.rect[3] <= cy1)
|
||||
.collect();
|
||||
ui.hits.extend(kept);
|
||||
if max > 0.0 {
|
||||
// A thin scroll indicator.
|
||||
let track = bottom - top;
|
||||
let bar = (track * track / (track + max)).max(24.0);
|
||||
let by = top + (track - bar) * (self.hscroll / max);
|
||||
ui.rounded(
|
||||
x + cw + 16.0,
|
||||
by,
|
||||
3.0,
|
||||
bar,
|
||||
1.5,
|
||||
color::with_alpha(color::MUTED, 0.35),
|
||||
);
|
||||
}
|
||||
let _ = ox;
|
||||
ui.opacity = 1.0;
|
||||
ui.offset = (0.0, 0.0);
|
||||
sliders
|
||||
}
|
||||
pub(crate) fn draw_horizon(
|
||||
&mut self,
|
||||
s: &Settings,
|
||||
batch: &mut HudBatch,
|
||||
atlas: &HudAtlas,
|
||||
cursor: (f32, f32),
|
||||
) {
|
||||
let mut ui = Ui::new(atlas, batch, cursor);
|
||||
let backdrop = t::backdrop();
|
||||
self.horizon_layout(s, &mut ui, backdrop);
|
||||
ui.finish();
|
||||
}
|
||||
fn horizon_target(&mut self, s: &Settings, atlas: &HudAtlas, x: f32, y: f32) -> Option<Target> {
|
||||
let mut batch = t::scratch_batch();
|
||||
let mut ui = Ui::dry(atlas, &mut batch, (x, y));
|
||||
let sliders = self.horizon_layout(s, &mut ui, 1.0);
|
||||
let hit = ui.hit((x, y))?;
|
||||
let section = self.section.min(SECTIONS.len() - 1);
|
||||
if (NAV..NAV + SECTIONS.len() as u64).contains(&hit) {
|
||||
return Some(Target::Nav((hit - NAV) as usize));
|
||||
}
|
||||
if hit == DONE {
|
||||
return Some(Target::Done);
|
||||
}
|
||||
if hit == STYLE || hit == STYLE + 1 {
|
||||
return Some(Target::Style((hit - STYLE) as usize));
|
||||
}
|
||||
let i = hit.checked_sub(ROW)? as usize;
|
||||
let rows = (SECTIONS[section].rows)(s);
|
||||
if let Some(HRow::Opt(opt)) = rows.get(i)
|
||||
&& let Some(&(_, sx, sw)) = sliders.iter().find(|(o, ..)| o == opt)
|
||||
{
|
||||
let v = t::slider_value(&ui, sx, sw, x);
|
||||
return Some(Target::Slider(*opt, v));
|
||||
}
|
||||
(i < rows.len()).then_some(Target::Row(i))
|
||||
}
|
||||
/// A click (or a drag with the button held) on the Horizon shell.
|
||||
pub(crate) fn click_horizon(
|
||||
&mut self,
|
||||
s: &mut Settings,
|
||||
atlas: &HudAtlas,
|
||||
x: f32,
|
||||
y: f32,
|
||||
drag: bool,
|
||||
right: bool,
|
||||
) -> Vec<Event> {
|
||||
let mut events = Vec::new();
|
||||
if drag {
|
||||
if let Some(opt) = self.dragging {
|
||||
let mut batch = t::scratch_batch();
|
||||
let mut ui = Ui::dry(atlas, &mut batch, (x, y));
|
||||
let sliders = self.horizon_layout(s, &mut ui, 1.0);
|
||||
if let Some(&(_, sx, sw)) = sliders.iter().find(|(o, ..)| *o == opt) {
|
||||
opt.set_slider(s, t::slider_value(&ui, sx, sw, x));
|
||||
if opt == Opt::Preset {
|
||||
apply_preset(s);
|
||||
}
|
||||
events.push(Event::Changed);
|
||||
}
|
||||
}
|
||||
return events;
|
||||
}
|
||||
match self.horizon_target(s, atlas, x, y) {
|
||||
Some(Target::Nav(i)) => {
|
||||
self.section = i;
|
||||
self.hscroll = 0.0;
|
||||
}
|
||||
Some(Target::Done) => events.extend(self.back(s)),
|
||||
Some(Target::Style(i)) => {
|
||||
t::set_style(if i == 1 {
|
||||
MenuStyle::Classic
|
||||
} else {
|
||||
MenuStyle::Horizon
|
||||
});
|
||||
if let Ok(dir) = std::env::current_dir() {
|
||||
t::save_preferences(&dir);
|
||||
}
|
||||
}
|
||||
Some(Target::Slider(opt, v)) => {
|
||||
self.dragging = Some(opt);
|
||||
opt.set_slider(s, v);
|
||||
if opt == Opt::Preset {
|
||||
apply_preset(s);
|
||||
}
|
||||
events.push(Event::Changed);
|
||||
}
|
||||
Some(Target::Row(i)) => {
|
||||
let section = self.section.min(SECTIONS.len() - 1);
|
||||
match (SECTIONS[section].rows)(s).get(i) {
|
||||
Some(HRow::Opt(opt)) => {
|
||||
opt.cycle(s, right);
|
||||
if *opt == Opt::Preset {
|
||||
apply_preset(s);
|
||||
}
|
||||
events.push(Event::Changed);
|
||||
}
|
||||
Some(HRow::Page(_, _, page)) => self.open_page(*page),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
events
|
||||
}
|
||||
pub(crate) fn scroll_horizon(&mut self, amount: f32) {
|
||||
self.hscroll -= amount * 40.0;
|
||||
}
|
||||
}
|
||||
@@ -92,13 +92,13 @@ fn chat_px(caption: &str, px: f32) -> Text {
|
||||
&[tr(caption), Text::literal((px as i32).to_string())],
|
||||
)
|
||||
}
|
||||
enum Kind {
|
||||
pub(crate) enum Kind {
|
||||
/// Slider position 0..1.
|
||||
Slider(f32),
|
||||
Cycle,
|
||||
}
|
||||
impl Opt {
|
||||
fn caption(self) -> &'static str {
|
||||
pub(crate) fn caption(self) -> &'static str {
|
||||
match self {
|
||||
Opt::Fov => "options.fov",
|
||||
Opt::RenderDistance => "options.renderDistance",
|
||||
@@ -155,7 +155,7 @@ impl Opt {
|
||||
Opt::JapaneseGlyphs => "options.japaneseGlyphVariants",
|
||||
}
|
||||
}
|
||||
fn kind(self, s: &Settings) -> Kind {
|
||||
pub(crate) fn kind(self, s: &Settings) -> Kind {
|
||||
let unit = |v: f32, lo: f32, hi: f32| Kind::Slider(((v - lo) / (hi - lo)).clamp(0.0, 1.0));
|
||||
match self {
|
||||
Opt::Fov => unit(s.fov, 30.0, 110.0),
|
||||
@@ -590,7 +590,12 @@ pub enum Event {
|
||||
pub struct OptionsUi {
|
||||
pub stack: Vec<Page>,
|
||||
scroll: f32,
|
||||
dragging: Option<Opt>,
|
||||
pub(crate) dragging: Option<Opt>,
|
||||
/// Horizon style: the selected sidebar section, the one last drawn and
|
||||
/// the rows' scroll in dp (`options_horizon`).
|
||||
pub section: usize,
|
||||
pub(crate) section_shown: Option<usize>,
|
||||
pub(crate) hscroll: f32,
|
||||
/// Key Binds: the mapping waiting for a key.
|
||||
pub selected_key: Option<&'static str>,
|
||||
pub languages: Vec<LanguageInfo>,
|
||||
@@ -615,6 +620,9 @@ impl Default for OptionsUi {
|
||||
stack: vec![Page::Main],
|
||||
scroll: 0.0,
|
||||
dragging: None,
|
||||
section: 0,
|
||||
section_shown: None,
|
||||
hscroll: 0.0,
|
||||
selected_key: None,
|
||||
languages: Vec::new(),
|
||||
language_choice: None,
|
||||
@@ -693,6 +701,10 @@ impl OptionsUi {
|
||||
self.in_world = in_world;
|
||||
self.selected_key = None;
|
||||
}
|
||||
/// Open one of vanilla's pages over the current one.
|
||||
pub(crate) fn open_page(&mut self, page: Page) {
|
||||
self.push(page);
|
||||
}
|
||||
fn push(&mut self, page: Page) {
|
||||
self.stack.push(page);
|
||||
self.scroll = 0.0;
|
||||
@@ -1175,6 +1187,10 @@ impl OptionsUi {
|
||||
cursor: (f32, f32),
|
||||
) {
|
||||
let (w, h) = (batch.width, batch.height);
|
||||
if crate::ui_theme::horizon() && self.page() == Page::Main {
|
||||
self.draw_horizon(s, batch, atlas, cursor);
|
||||
return;
|
||||
}
|
||||
if self.page() == Page::Packs {
|
||||
ui::menu_background(batch, atlas, 0.0, 0.0, w, h, self.in_world);
|
||||
let blink = self.pack_focus.elapsed().as_millis() as u64;
|
||||
@@ -1324,6 +1340,9 @@ impl OptionsUi {
|
||||
drag: bool,
|
||||
right: bool,
|
||||
) -> Vec<Event> {
|
||||
if crate::ui_theme::horizon() && self.page() == Page::Main {
|
||||
return self.click_horizon(s, atlas, x, y, drag, right);
|
||||
}
|
||||
if self.page() == Page::Packs {
|
||||
let mut events = Vec::new();
|
||||
if drag || right {
|
||||
@@ -1427,6 +1446,10 @@ impl OptionsUi {
|
||||
}
|
||||
/// The mouse wheel at the cursor.
|
||||
pub fn scroll_at(&mut self, cursor: (f32, f32), amount: f32) {
|
||||
if crate::ui_theme::horizon() && self.page() == Page::Main {
|
||||
self.scroll_horizon(amount);
|
||||
return;
|
||||
}
|
||||
match &mut self.pack_screen {
|
||||
Some(p) if self.stack.last() == Some(&Page::Packs) => {
|
||||
p.scroll(cursor.0 as f64, cursor.1 as f64, amount as f64)
|
||||
|
||||
@@ -117,6 +117,20 @@ pub fn quick() -> f32 {
|
||||
pub fn move_() -> f32 {
|
||||
horizon_theme::MOVE.as_secs_f32()
|
||||
}
|
||||
/// How visible the live title backdrop is (0..1), set by the game each frame.
|
||||
static BACKDROP: std::sync::atomic::AtomicU32 = std::sync::atomic::AtomicU32::new(0);
|
||||
pub fn set_backdrop(fade: f32) {
|
||||
BACKDROP.store(fade.to_bits(), Ordering::Relaxed);
|
||||
}
|
||||
pub fn backdrop() -> f32 {
|
||||
f32::from_bits(BACKDROP.load(Ordering::Relaxed))
|
||||
}
|
||||
/// The window size of the last drawn frame, for hit-testing passes.
|
||||
static WINDOW: std::sync::Mutex<[u32; 2]> = std::sync::Mutex::new([1280, 800]);
|
||||
/// An empty batch at the last frame's window size (for [`Ui::dry`]).
|
||||
pub fn scratch_batch() -> HudBatch {
|
||||
HudBatch::new(*WINDOW.lock().unwrap_or_else(|e| e.into_inner()))
|
||||
}
|
||||
/// Whether the left mouse button is held (the primary button's press state).
|
||||
static PRESSED: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);
|
||||
pub fn set_pressed(down: bool) {
|
||||
@@ -398,6 +412,9 @@ impl<'a> Ui<'a> {
|
||||
let scale = batch.scale;
|
||||
let (pw, ph) = (batch.width * scale, batch.height * scale);
|
||||
let density = (pw / 1040.0).min(ph / 700.0).clamp(1.0, 4.0);
|
||||
if let Ok(mut w) = WINDOW.lock() {
|
||||
*w = [pw.round() as u32, ph.round() as u32];
|
||||
}
|
||||
with_cache(atlas, |c| {
|
||||
let now = Instant::now();
|
||||
c.dt = c
|
||||
|
||||
@@ -7,6 +7,7 @@ To play, use [the launcher](../launcher/README.md). These pages are for develope
|
||||
- [Build from source](../README.md#build-from-source): your own copy of the game, resource preparation, `cargo run`.
|
||||
- [Native client](native-client.md): options, controls, the dedicated server, `horizon-ctl` scripting, packaging, architecture.
|
||||
- [Launcher](../launcher/README.md): installs, updates and starts builds; its CLI and MCP server; releasing it.
|
||||
- Menus: the title, world list, create world, multiplayer, options and pause screens share the launcher's design tokens and fonts (`crates/horizon-theme`), drawn by `ui_theme` over a live frozen backdrop (`game/backdrop.rs`, blurred and graded by `post.rs`). Options → Interface → Menu style switches to vanilla's screens (Classic, kept in `horizon.txt`; `HORIZON_MENU_STYLE=horizon|classic` overrides it, and scripted runs default to Classic). [Title](media/menu-title.png) ([webm](media/menu-title.webm)), [worlds](media/menu-worlds.png), [options](media/menu-options.png), [pause](media/menu-pause.png).
|
||||
|
||||
## Parity
|
||||
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 325 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 474 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 377 KiB |
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 350 KiB |
Reference in New Issue
Block a user