mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-11-22 06:48:43 -06:00
dynamic crosshair stuff
This commit is contained in:
parent
66d3ea656b
commit
610d309ead
|
@ -19,6 +19,7 @@ pub struct GameSettings {
|
||||||
pub render_distance: u8,
|
pub render_distance: u8,
|
||||||
pub mouse_sensitivity: f32,
|
pub mouse_sensitivity: f32,
|
||||||
pub debug_draw_current_chunk_border: bool,
|
pub debug_draw_current_chunk_border: bool,
|
||||||
|
pub dynamic_crosshair: bool,
|
||||||
}
|
}
|
||||||
impl Default for GameSettings {
|
impl Default for GameSettings {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
|
@ -34,6 +35,7 @@ impl Default for GameSettings {
|
||||||
},
|
},
|
||||||
mouse_sensitivity: 1.,
|
mouse_sensitivity: 1.,
|
||||||
debug_draw_current_chunk_border: false, //cfg!(not(target_os = "android")) && cfg!(debug_assertions),
|
debug_draw_current_chunk_border: false, //cfg!(not(target_os = "android")) && cfg!(debug_assertions),
|
||||||
|
dynamic_crosshair: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use std::f32::consts::PI;
|
use std::f32::consts::PI;
|
||||||
|
|
||||||
use glam::uvec2;
|
use glam::{uvec2, Vec2};
|
||||||
use hui::{
|
use hui::{
|
||||||
draw::{ImageHandle, TextureFormat},
|
draw::{ImageHandle, TextureFormat},
|
||||||
element::{container::Container, image::Image, transformer::ElementTransformExt, UiElementExt},
|
element::{container::Container, image::Image, transformer::ElementTransformExt, UiElementExt},
|
||||||
|
@ -8,7 +8,7 @@ use hui::{
|
||||||
size
|
size
|
||||||
};
|
};
|
||||||
use shipyard::{AllStoragesViewMut, IntoIter, NonSendSync, Unique, UniqueView, UniqueViewMut, View};
|
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_SIZE: usize = 9;
|
||||||
const CROSSHAIR: &[u8] = &[
|
const CROSSHAIR: &[u8] = &[
|
||||||
|
@ -38,10 +38,15 @@ pub fn draw_crosshair(
|
||||||
size: UniqueView<WindowSize>,
|
size: UniqueView<WindowSize>,
|
||||||
player: View<MainPlayer>,
|
player: View<MainPlayer>,
|
||||||
raycast: View<LookingAtBlock>,
|
raycast: View<LookingAtBlock>,
|
||||||
|
settings: UniqueView<GameSettings>,
|
||||||
) {
|
) {
|
||||||
let mut cursor_active = false;
|
let mut active = false;
|
||||||
|
if settings.dynamic_crosshair {
|
||||||
if let Some((_, raycast)) = (&player, &raycast).iter().next() {
|
if let Some((_, raycast)) = (&player, &raycast).iter().next() {
|
||||||
cursor_active = raycast.0.is_some();
|
active = raycast.0.is_some();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
active = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Container::default()
|
Container::default()
|
||||||
|
@ -49,11 +54,11 @@ pub fn draw_crosshair(
|
||||||
.with_align(Alignment::Center)
|
.with_align(Alignment::Center)
|
||||||
.with_children(|ui| {
|
.with_children(|ui| {
|
||||||
Image::new(crosshair.0)
|
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))
|
.with_size(size!(18, 18))
|
||||||
.transform()
|
.transform()
|
||||||
.scale(glam::Vec2::splat(if cursor_active { 1. } else { 0.66 }))
|
.scale(Vec2::splat(if active { 1. } else { 0.66 }))
|
||||||
.rotate(if cursor_active { 0. } else { PI / 4. })
|
.rotate(if active { 0. } else { PI / 4. })
|
||||||
.add_child(ui);
|
.add_child(ui);
|
||||||
})
|
})
|
||||||
.add_root(&mut ui.hui, uvec2(size.0.x & !1, size.0.y & !1).as_vec2());
|
.add_root(&mut ui.hui, uvec2(size.0.x & !1, size.0.y & !1).as_vec2());
|
||||||
|
|
Loading…
Reference in a new issue