From c1ac90fa97ac69047844889ca6614f158ddb6baa Mon Sep 17 00:00:00 2001 From: Muhammad Nauman Raza Date: Mon, 4 Dec 2023 13:44:28 +0000 Subject: [PATCH] feat: produce the basis of player Former-commit-id: 375d2b8ac71d6e9cf979231abd90dddbe80fcba6 --- assets/black-square.png | Bin 0 -> 5077 bytes src/main.rs | 47 ++++++++++++++++++++++++++++++---------- 2 files changed, 36 insertions(+), 11 deletions(-) create mode 100644 assets/black-square.png diff --git a/assets/black-square.png b/assets/black-square.png new file mode 100644 index 0000000000000000000000000000000000000000..bf155803ba333fc6e87e55bc0dd6869e26e7edc7 GIT binary patch literal 5077 zcmeAS@N?(olHy`uVBq!ia0y~yVDQ}9s()O0*}aI1_r((Aj~*bn@^g7 zLAc%1#WAE}&fA-YU8?R&-3;TRtTPH3Fe4L&3 zKv1Nl;J#(r!T9*f!jr!~ef;=weQ5Eyr?(B;Vt1Fly|p#_`ntRRcm96=q{_e$Em+3D zAb5z6LBZ(;BZCWvHA4eOB0GbC;u{7Ar50HRhn5Y@3>^X_DS9-cSWmv+a9TdZE|8^l z@7C#)WCroBsrmWiM}*zHV!iu)hHt>016%lrW){i-!}77=u}^Cep?Uu9*P~PoLb&%k z^yTH{PansOKAKsWd~Ror&9R7mpkxB^;qRTh_Yspg9{spi?{Fc${_ofC_v`;ZZoj{; zHu_&{{QkOFm|@@V{C(IiU-#?f@~819{;RyPyZ?Uw|9{Wt*Vnz@&&06p+iCs%e?A_U zzyEvvijV6fh)jwd$vqouY@WyL<9%;;ezOfDL;j;(>%`@sp1uEfZCUL`l9Mky?D1s; zcp5*v`+23FKf{69JKq03>R$P|ync0TJO!BtpY0aMBp^xQ!@JKmr-d0lsI7Zl^)c|? zpS$<7u8UJ6>teCJ&+_@Fj}pm0&GuB!d;W=qVNd7peepF@%AA0xs@1M`-|NlK){#zsm z(qpZ=rnmkx(cMRUy*zMJXSBah$zTw?wFnO9k53;zPX1W|9AdCOwgEA~&`I0?1FBg> xxvKDt<@EmJ5~sIA2flzK8usPn^p*cHN1u9cp2s4u2^^() + .init_resource::() .add_systems(Startup, (setup, setup_ui)) .add_systems(Update, render_ui) .run(); @@ -58,8 +59,13 @@ struct UiState { password: String, } +#[derive(Default, Resource)] +struct OpenWindows { + login_open: bool, +} + // Bevy engine setup -fn setup(mut commands: Commands) { +fn setup(mut commands: Commands, asset_server: Res) { commands.spawn(Camera2dBundle { camera: Camera { hdr: true, @@ -68,6 +74,13 @@ fn setup(mut commands: Commands) { tonemapping: Tonemapping::TonyMcMapface, ..default() }); + commands.spawn(( + SpriteBundle { + texture: asset_server.load("black-square.png"), + transform: Transform::from_xyz(100., 0., 0.), + ..default() + } + )); } // On startup: setup some UI components @@ -87,16 +100,32 @@ fn setup_ui(mut contexts: EguiContexts) { } // On update: render the UI -fn render_ui(mut contexts: EguiContexts, mut windows: Query<&mut Window>, mut ui_state: ResMut) { +fn render_ui( + mut contexts: EguiContexts, + mut windows: Query<&mut Window>, + mut ui_state: ResMut, + mut open_windows: ResMut, + asset_server: Res, + keys: Res>, +) { let window = windows.single_mut(); let window_width = window.resolution.width(); let window_height = window.resolution.height(); + let ctx = contexts.ctx_mut(); + + if keys.just_pressed(KeyCode::Space) { + } + if keys.pressed(KeyCode::W) { + + } + egui::Window::new("Login") .anchor(egui::Align2::CENTER_CENTER, egui::Vec2::new(0., 0.)) .resizable(false) .title_bar(false) - .show(contexts.ctx_mut(), |ui| { + .open(&mut open_windows.login_open) + .show(ctx, |ui| { ui.set_width(window_width / 3.); ui.set_height(window_height / 3.); @@ -109,10 +138,8 @@ fn render_ui(mut contexts: EguiContexts, mut windows: Query<&mut Window>, mut ui // Define spacing between items (widgets) and add manually add some space // between the window border and the heading - ui.spacing_mut() - .item_spacing = egui::vec2(0., 10.); - ui.spacing_mut() - .button_padding = egui::vec2(20., 10.); + ui.spacing_mut().item_spacing = egui::vec2(0., 10.); + ui.spacing_mut().button_padding = egui::vec2(20., 10.); ui.add_space(window_height / 22.); ui.heading(egui::RichText::new("Login").size(30.).color(purple)); // The window 'title' @@ -137,13 +164,11 @@ fn render_ui(mut contexts: EguiContexts, mut windows: Query<&mut Window>, mut ui // Manually add some space between the text inputs and the 'confirm' button ui.add_space(window_height / 26.); - let button = ui.add(egui::Button::new("Confirm") - .fill(black)); + let button = ui.add(egui::Button::new("Confirm").fill(black)); // Manually add some space between the button and the bottom border of the // window...for scaling purposes ui.add_space(window_height / 22.); - }); }); }