From dcd05507bc9dd1bc908b24e307e45cae474bcc01 Mon Sep 17 00:00:00 2001 From: ghostly_zsh Date: Thu, 27 Mar 2025 17:05:33 -0500 Subject: [PATCH] crafing gui exists and follows modules --- crates/client/src/components.rs | 3 +++ crates/client/src/lib.rs | 2 +- crates/client/src/networking/mod.rs | 2 +- crates/client/src/ui/mod.rs | 18 +++++++++++++++++- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/crates/client/src/components.rs b/crates/client/src/components.rs index 836ce30438ef4d966bc9b75407370ae90da9d03b..9e8824522ee6efb388c99b379b634a8c3dadd8b7 100644 --- a/crates/client/src/components.rs +++ b/crates/client/src/components.rs @@ -82,6 +82,9 @@ pub struct Part(pub bool); // Part(attached) #[derive(Component, Debug, Clone, Copy)] pub struct ServerId(pub u32); +#[derive(Component, Debug, Clone, Copy)] +pub struct Menu; + #[derive(Event, Clone, PartialEq)] pub struct SendPacket(pub Packet); #[derive(Event, Clone, PartialEq)] diff --git a/crates/client/src/lib.rs b/crates/client/src/lib.rs index 0f3618acbf5a5060421b7aefeb316b1cda223102..da0a3ca9554f7cec0fb49ca150e6213c60af3442 100644 --- a/crates/client/src/lib.rs +++ b/crates/client/src/lib.rs @@ -1,5 +1,5 @@ use bevy_ecs::{event::Events, world::World}; -use components::{Camera, Chat, Part, Player, RecvPacket, SendPacket, Texture, Transform}; +use components::{Camera, Chat, Menu, Part, Player, RecvPacket, SendPacket, Texture, Transform}; use nalgebra::{Rotation2, Rotation3, Scale2, Scale3, Translation2, Translation3, Vector3}; use networking::ws::Ws; use rendering::{assets::Assets, App}; diff --git a/crates/client/src/networking/mod.rs b/crates/client/src/networking/mod.rs index 36b717d4996db2883ea91475c1f21f68d5ed6dc1..931d4e3f939731bdc1cd354277127707b48685fc 100644 --- a/crates/client/src/networking/mod.rs +++ b/crates/client/src/networking/mod.rs @@ -9,7 +9,7 @@ use bevy_ecs::{ use nalgebra::{Rotation2, Scale2, Scale3, Translation3}; use starkingdoms_common::{packet::Packet, PartType, PlanetType}; -use crate::components::{Camera, Chat, Part, Planet, Player, PlayerResources, RecvPacket, SendPacket, ServerId, SpriteBundle, Texture, Transform}; +use crate::components::{Camera, Chat, Menu, Part, Planet, Player, PlayerResources, RecvPacket, SendPacket, ServerId, SpriteBundle, Texture, Transform}; #[cfg(target_arch = "wasm32")] #[path = "ws_wasm.rs"] diff --git a/crates/client/src/ui/mod.rs b/crates/client/src/ui/mod.rs index 19b9ec30d6a73e8fb2154eee805d196ba1a7c6a5..7e7a61ed74ebc8b443d45bc8e90e2e04117cfa45 100644 --- a/crates/client/src/ui/mod.rs +++ b/crates/client/src/ui/mod.rs @@ -3,12 +3,13 @@ mod widgets; use std::f32; +use bevy_ecs::entity::Entity; use bevy_ecs::event::Events; use bevy_ecs::prelude::With; use bevy_ecs::world::World; use egui::{Align, Align2, CornerRadius, CursorIcon, Layout, Margin, Order, ProgressBar, RichText, Shadow, Stroke, Visuals}; use starkingdoms_common::packet::Packet; -use crate::components::{Chat, Player, PlayerResources, SendPacket, Transform}; +use crate::components::{Camera, Chat, Menu, Player, PlayerResources, SendPacket, Transform}; use crate::ui::widgets::{progress_bar, RichTextExt}; pub fn init_ui(ctx: egui::Context) { @@ -55,6 +56,7 @@ pub fn init_ui(ctx: egui::Context) { pub fn draw_ui(ctx: &egui::Context, world: &mut World, send_packet_events: &mut Events) { draw_status_bar(ctx, world); draw_chat(ctx, world, send_packet_events); + draw_crafting(ctx, world); } pub fn draw_status_bar(ctx: &egui::Context, world: &mut World) { @@ -131,3 +133,17 @@ pub fn draw_chat(ctx: &egui::Context, world: &mut World, send_packet_events: &mu }); }); } + +pub fn draw_crafting(ctx: &egui::Context, world: &mut World) { + let mut menus = world.query_filtered::<(Entity, &Transform), With>(); + let camera = world.resource::(); + for (entity, menu) in menus.iter(&world) { + egui::Window::new("Crafting") + .id(format!("Crafting{}", entity.index()).into()) + .pivot(Align2::LEFT_BOTTOM) + .fixed_pos(((menu.translation.x + camera.x) * camera.zoom + camera.width as f32 / 2.0, + (menu.translation.y + camera.y) * camera.zoom + camera.height as f32 / 2.0)) + .show(ctx, |ui| { + }); + } +}