wip settings

This commit is contained in:
griffi-gh 2024-05-02 02:06:23 +02:00
parent bb9107e912
commit a5fae8ad2b
3 changed files with 57 additions and 1 deletions

View file

@ -21,8 +21,8 @@ pub(crate) use ui::{
connecting_screen,
chat_ui,
crosshair_ui,
settings_ui,
};
pub(crate) mod rendering;
pub(crate) mod world;
pub(crate) mod player;
@ -93,6 +93,7 @@ use client_physics::{init_client_physics, update_client_physics_late};
use chat_ui::render_chat;
use chat::init_chat_manager;
use crosshair_ui::{init_crosshair_image, draw_crosshair};
use settings_ui::render_settings_ui;
/// stuff required to init the renderer and other basic systems
fn pre_startup() -> Workload {
@ -153,8 +154,10 @@ fn update() -> Workload {
update_raycasts,
update_block_placement,
apply_queued_blocks,
//UI:
render_chat,
draw_crosshair,
render_settings_ui,
).into_sequential_workload().run_if(is_ingame),
update_networking_late.run_if(is_multiplayer),
compute_cameras,

View file

@ -2,3 +2,4 @@ pub(crate) mod loading_screen;
pub(crate) mod connecting_screen;
pub(crate) mod chat_ui;
pub(crate) mod crosshair_ui;
pub(crate) mod settings_ui;

View file

@ -0,0 +1,52 @@
use hui::{color, element::{br::Break, container::Container, slider::Slider, text::Text, UiElementExt}, layout::{Alignment, Direction}, signal::Signal, size};
use shipyard::{NonSendSync, UniqueView, UniqueViewMut};
use winit::keyboard::KeyCode;
use crate::{hui_integration::UiState, input::RawKbmInputState, rendering::WindowSize, settings::GameSettings};
#[derive(Signal)]
enum SettingsSignal {
SetRenderDistance(f32),
}
pub fn render_settings_ui(
mut ui: NonSendSync<UniqueViewMut<UiState>>,
size: UniqueView<WindowSize>,
mut settings: UniqueViewMut<GameSettings>,
kbd: UniqueView<RawKbmInputState>,
) {
//f1 must be held down to open settings
if !kbd.keyboard_state.contains(KeyCode::F1 as u32) {
return
}
Container::default()
.with_size(size!(100%))
.with_align(Alignment::Center)
.with_children(|ui| {
Container::default()
.with_background(color::BLACK)
.with_size(size!(50%, 50%))
.with_direction(Direction::Horizontal)
.with_gap(10.)
.with_padding(10.)
.with_children(|ui| {
Text::new("Settings")
.add_child(ui);
Break.add_child(ui);
Text::new("Render Distance")
.add_child(ui);
Slider::new(settings.render_distance as f32 / 16.)
.with_size(size!(300, (Slider::DEFAULT_HEIGHT)))
.on_change(SettingsSignal::SetRenderDistance)
.add_child(ui);
Break.add_child(ui);
})
.add_child(ui);
})
.add_root(&mut ui.hui, size.0.as_vec2());
ui.hui.process_signals(|signal: SettingsSignal| match signal {
SettingsSignal::SetRenderDistance(value) => {
settings.render_distance = (value * 16.).round() as u8;
}
});
}