diff options
author | metamuffin <metamuffin@disroot.org> | 2025-01-10 15:35:23 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-01-10 15:35:23 +0100 |
commit | 47e5b44576e581ae0b62ad1e3bed444b8a82cefd (patch) | |
tree | dc669acc78003dc9de405247106832d4700f4371 /client/src/state.rs | |
parent | dbfb01fa7b5b05686dcbdd9d73643d7866810668 (diff) | |
download | weareserver-47e5b44576e581ae0b62ad1e3bed444b8a82cefd.tar weareserver-47e5b44576e581ae0b62ad1e3bed444b8a82cefd.tar.bz2 weareserver-47e5b44576e581ae0b62ad1e3bed444b8a82cefd.tar.zst |
spawn ui in world with click
Diffstat (limited to 'client/src/state.rs')
-rw-r--r-- | client/src/state.rs | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/client/src/state.rs b/client/src/state.rs index b0d19e6..70746d8 100644 --- a/client/src/state.rs +++ b/client/src/state.rs @@ -14,13 +14,17 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. */ -use crate::{camera::Camera, download::Downloader, network::Network, renderer::Renderer}; +use crate::{ + camera::Camera, download::Downloader, network::Network, renderer::Renderer, ui::UiSurface, +}; use anyhow::{Context, Result}; +use egui::ViewportId; use glam::{Vec2, Vec3}; use log::{info, warn}; -use std::{net::TcpStream, time::Instant}; +use rand::random; +use std::{net::TcpStream, sync::Arc, time::Instant}; use weareshared::{store::ResourceStore, tree::SceneTree}; -use winit::window::Window; +use winit::event::MouseButton; pub struct State<'a> { pub network: Network, @@ -35,10 +39,11 @@ pub struct DeltaState { time: Instant, pub move_dir: Vec3, pub mouse_acc: Vec2, + pub cursor_pos: Vec2, } impl<'a> State<'a> { - pub fn new(conn: TcpStream, window: &'a Window) -> Result<State<'a>> { + pub fn new(conn: TcpStream, window: &'a winit::window::Window) -> Result<State<'a>> { info!("new state"); Ok(Self { camera: Camera::new(), @@ -50,6 +55,7 @@ impl<'a> State<'a> { time: Instant::now(), move_dir: Vec3::ZERO, mouse_acc: Vec2::ZERO, + cursor_pos: Vec2::ZERO, }, }) } @@ -62,6 +68,26 @@ impl<'a> State<'a> { self.renderer.resize(width, height); self.camera.aspect = width as f32 / height as f32; } + pub fn click(&mut self, button: MouseButton, down: bool) { + if !down || button != MouseButton::Right { + return; + } + self.renderer.ui_renderer.surfaces.insert( + ViewportId::from_hash_of(random::<u128>()), + UiSurface { + transform: self.camera.new_ui_affine(), + content: Arc::new(|ctx| { + egui::Window::new("Funny window") + .default_open(true) + .show(ctx, |ui| { + ui.label("world space ui actually kinda works now"); + ui.label("Does input work?"); + ui.button("Yes").clicked(); + }); + }), + }, + ); + } pub fn update(&mut self) -> Result<()> { let now = Instant::now(); let dt = (now - self.delta.time).as_secs_f32(); |