mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-12-25 05:08:21 -06:00
dynamic crosshair stuff
This commit is contained in:
parent
d57787059a
commit
748a0bf6d6
|
@ -1,47 +1,49 @@
|
|||
use shipyard::{Unique, AllStoragesView};
|
||||
|
||||
pub enum FullscreenMode {
|
||||
Borderless,
|
||||
Exclusive,
|
||||
}
|
||||
|
||||
pub struct FullscreenSettings {
|
||||
pub mode: FullscreenMode,
|
||||
}
|
||||
|
||||
#[derive(Unique)]
|
||||
pub struct GameSettings {
|
||||
pub vsync: bool,
|
||||
pub fullscreen: Option<FullscreenSettings>,
|
||||
pub msaa: Option<u8>,
|
||||
pub max_anisotropy: Option<u16>,
|
||||
/// there's a 1 chunk border of loaded but invisible around this
|
||||
pub render_distance: u8,
|
||||
pub mouse_sensitivity: f32,
|
||||
pub debug_draw_current_chunk_border: bool,
|
||||
}
|
||||
impl Default for GameSettings {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
vsync: false,
|
||||
fullscreen: None,
|
||||
msaa: Some(4),
|
||||
max_anisotropy: Some(16),
|
||||
render_distance: match true {
|
||||
cfg!(debug_assertions) => 5,
|
||||
cfg!(target_os = "android") => 6,
|
||||
#[allow(unreachable_patterns)] _ => 7,
|
||||
},
|
||||
mouse_sensitivity: 1.,
|
||||
debug_draw_current_chunk_border: false, //cfg!(not(target_os = "android")) && cfg!(debug_assertions),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn load_settings(
|
||||
storages: AllStoragesView
|
||||
) {
|
||||
log::info!("loading game settings");
|
||||
//todo
|
||||
storages.add_unique(GameSettings::default());
|
||||
}
|
||||
use shipyard::{Unique, AllStoragesView};
|
||||
|
||||
pub enum FullscreenMode {
|
||||
Borderless,
|
||||
Exclusive,
|
||||
}
|
||||
|
||||
pub struct FullscreenSettings {
|
||||
pub mode: FullscreenMode,
|
||||
}
|
||||
|
||||
#[derive(Unique)]
|
||||
pub struct GameSettings {
|
||||
pub vsync: bool,
|
||||
pub fullscreen: Option<FullscreenSettings>,
|
||||
pub msaa: Option<u8>,
|
||||
pub max_anisotropy: Option<u16>,
|
||||
/// there's a 1 chunk border of loaded but invisible around this
|
||||
pub render_distance: u8,
|
||||
pub mouse_sensitivity: f32,
|
||||
pub debug_draw_current_chunk_border: bool,
|
||||
pub dynamic_crosshair: bool,
|
||||
}
|
||||
impl Default for GameSettings {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
vsync: false,
|
||||
fullscreen: None,
|
||||
msaa: Some(4),
|
||||
max_anisotropy: Some(16),
|
||||
render_distance: match true {
|
||||
cfg!(debug_assertions) => 5,
|
||||
cfg!(target_os = "android") => 6,
|
||||
#[allow(unreachable_patterns)] _ => 7,
|
||||
},
|
||||
mouse_sensitivity: 1.,
|
||||
debug_draw_current_chunk_border: false, //cfg!(not(target_os = "android")) && cfg!(debug_assertions),
|
||||
dynamic_crosshair: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn load_settings(
|
||||
storages: AllStoragesView
|
||||
) {
|
||||
log::info!("loading game settings");
|
||||
//todo
|
||||
storages.add_unique(GameSettings::default());
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use std::f32::consts::PI;
|
||||
|
||||
use glam::uvec2;
|
||||
use glam::{uvec2, Vec2};
|
||||
use hui::{
|
||||
draw::{ImageHandle, TextureFormat},
|
||||
element::{container::Container, image::Image, transformer::ElementTransformExt, UiElementExt},
|
||||
|
@ -8,7 +8,7 @@ use hui::{
|
|||
size
|
||||
};
|
||||
use shipyard::{AllStoragesViewMut, IntoIter, NonSendSync, Unique, UniqueView, UniqueViewMut, View};
|
||||
use crate::{hui_integration::UiState, player::MainPlayer, rendering::WindowSize, world::raycast::LookingAtBlock};
|
||||
use crate::{hui_integration::UiState, player::MainPlayer, rendering::WindowSize, settings::GameSettings, world::raycast::LookingAtBlock};
|
||||
|
||||
const CROSSHAIR_SIZE: usize = 9;
|
||||
const CROSSHAIR: &[u8] = &[
|
||||
|
@ -38,10 +38,15 @@ pub fn draw_crosshair(
|
|||
size: UniqueView<WindowSize>,
|
||||
player: View<MainPlayer>,
|
||||
raycast: View<LookingAtBlock>,
|
||||
settings: UniqueView<GameSettings>,
|
||||
) {
|
||||
let mut cursor_active = false;
|
||||
if let Some((_, raycast)) = (&player, &raycast).iter().next() {
|
||||
cursor_active = raycast.0.is_some();
|
||||
let mut active = false;
|
||||
if settings.dynamic_crosshair {
|
||||
if let Some((_, raycast)) = (&player, &raycast).iter().next() {
|
||||
active = raycast.0.is_some();
|
||||
}
|
||||
} else {
|
||||
active = true;
|
||||
}
|
||||
|
||||
Container::default()
|
||||
|
@ -49,11 +54,11 @@ pub fn draw_crosshair(
|
|||
.with_align(Alignment::Center)
|
||||
.with_children(|ui| {
|
||||
Image::new(crosshair.0)
|
||||
.with_color((1., 1., 1., 0.5))
|
||||
.with_color((1., 1., 1., if active { 0.5 } else { 0.3 }))
|
||||
.with_size(size!(18, 18))
|
||||
.transform()
|
||||
.scale(glam::Vec2::splat(if cursor_active { 1. } else { 0.66 }))
|
||||
.rotate(if cursor_active { 0. } else { PI / 4. })
|
||||
.scale(Vec2::splat(if active { 1. } else { 0.66 }))
|
||||
.rotate(if active { 0. } else { PI / 4. })
|
||||
.add_child(ui);
|
||||
})
|
||||
.add_root(&mut ui.hui, uvec2(size.0.x & !1, size.0.y & !1).as_vec2());
|
||||
|
|
Loading…
Reference in a new issue