mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-11-16 04:18:42 -06:00
dynamic crosshair stuff
This commit is contained in:
parent
66d3ea656b
commit
610d309ead
|
@ -1,47 +1,49 @@
|
||||||
use shipyard::{Unique, AllStoragesView};
|
use shipyard::{Unique, AllStoragesView};
|
||||||
|
|
||||||
pub enum FullscreenMode {
|
pub enum FullscreenMode {
|
||||||
Borderless,
|
Borderless,
|
||||||
Exclusive,
|
Exclusive,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct FullscreenSettings {
|
pub struct FullscreenSettings {
|
||||||
pub mode: FullscreenMode,
|
pub mode: FullscreenMode,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Unique)]
|
#[derive(Unique)]
|
||||||
pub struct GameSettings {
|
pub struct GameSettings {
|
||||||
pub vsync: bool,
|
pub vsync: bool,
|
||||||
pub fullscreen: Option<FullscreenSettings>,
|
pub fullscreen: Option<FullscreenSettings>,
|
||||||
pub msaa: Option<u8>,
|
pub msaa: Option<u8>,
|
||||||
pub max_anisotropy: Option<u16>,
|
pub max_anisotropy: Option<u16>,
|
||||||
/// there's a 1 chunk border of loaded but invisible around this
|
/// there's a 1 chunk border of loaded but invisible around this
|
||||||
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 {
|
}
|
||||||
fn default() -> Self {
|
impl Default for GameSettings {
|
||||||
Self {
|
fn default() -> Self {
|
||||||
vsync: false,
|
Self {
|
||||||
fullscreen: None,
|
vsync: false,
|
||||||
msaa: Some(4),
|
fullscreen: None,
|
||||||
max_anisotropy: Some(16),
|
msaa: Some(4),
|
||||||
render_distance: match true {
|
max_anisotropy: Some(16),
|
||||||
cfg!(debug_assertions) => 5,
|
render_distance: match true {
|
||||||
cfg!(target_os = "android") => 6,
|
cfg!(debug_assertions) => 5,
|
||||||
#[allow(unreachable_patterns)] _ => 7,
|
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),
|
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
|
|
||||||
) {
|
pub fn load_settings(
|
||||||
log::info!("loading game settings");
|
storages: AllStoragesView
|
||||||
//todo
|
) {
|
||||||
storages.add_unique(GameSettings::default());
|
log::info!("loading game settings");
|
||||||
}
|
//todo
|
||||||
|
storages.add_unique(GameSettings::default());
|
||||||
|
}
|
||||||
|
|
|
@ -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 let Some((_, raycast)) = (&player, &raycast).iter().next() {
|
if settings.dynamic_crosshair {
|
||||||
cursor_active = raycast.0.is_some();
|
if let Some((_, raycast)) = (&player, &raycast).iter().next() {
|
||||||
|
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