ui testing

This commit is contained in:
2025-04-21 09:58:33 -04:00
parent 5b4e96177c
commit cb95db862c
6 changed files with 41 additions and 171 deletions

View File

@@ -1,6 +1,7 @@
use crate::camera_system::components::PhosCamera;
use crate::map_rendering::map_init::MapInitPlugin;
use crate::map_rendering::render_distance_system::RenderDistancePlugin;
use crate::ui::build_ui::BuildUIPlugin;
use crate::utlis::editor_plugin::EditorPlugin;
use crate::utlis::tile_selection_plugin::TileSelectionPlugin;
use crate::{camera_system::camera_plugin::PhosCameraPlugin, utlis::debug_plugin::DebugPlugin};
@@ -38,6 +39,7 @@ impl Plugin for PhosGamePlugin {
MapInitPlugin,
RenderDistancePlugin,
BuildingPugin,
BuildUIPlugin,
SimpleAnimationPlugin,
UnitsPlugin,
DespawnPuglin,

View File

@@ -0,0 +1,38 @@
use bevy::{
prelude::*,
render::{camera::RenderTarget, view::RenderLayers},
};
use shared::{states::AssetLoadState, tags::MainCamera};
pub struct BuildUIPlugin;
impl Plugin for BuildUIPlugin {
fn build(&self, app: &mut App) {
app.add_systems(Startup, setup_cameras);
app.add_systems(Update, spawn_ui.run_if(in_state(AssetLoadState::LoadComplete)));
}
}
fn setup_cameras(mut commands: Commands) {
commands.spawn((Camera2d, IsDefaultUiCamera, UiBoxShadowSamples(6)));
}
fn spawn_ui(mut commands: Commands) {
commands
.spawn((Node {
width: Val::Percent(100.),
height: Val::Percent(100.),
justify_content: JustifyContent::Center,
align_items: AlignItems::End,
..default()
},))
.insert(PickingBehavior::IGNORE)
.with_children(|parent| {
parent.spawn((
Node {
width: Val::Px(500.),
..Default::default()
},
BackgroundColor(LinearRgba::GREEN.into()),
));
});
}

View File

@@ -1,74 +0,0 @@
// use bevy::{prelude::*, render::view::RenderLayers, sprite::Anchor};
// use bevy_lunex::prelude::*;
// pub struct BuildUiPlugin;
// impl Plugin for BuildUiPlugin {
// fn build(&self, app: &mut App) {
// app.add_systems(PostStartup, setup_ui);
// }
// }
// fn setup_ui(mut commands: Commands, assets: Res<AssetServer>, mut material: ResMut<Assets<StandardMaterial>>) {
// commands
// .spawn((
// UiTreeBundle::<MainUi> {
// tree: UiTree::new2d("BuildUi"),
// ..default()
// },
// Name::new("Build UI"),
// SourceFromCamera,
// RenderLayers::layer(1),
// ))
// .with_children(|ui| {
// ui.spawn((
// UiLink::<MainUi>::path("Root"),
// UiLayout::boundary()
// .pos1((Rl(0.), Rl(0.)))
// .pos2((Rl(100.), Rl(100.)))
// .pack::<Base>(),
// RenderLayers::layer(1),
// ));
// ui.spawn((
// UiLink::<MainUi>::path("Root/MainRect"),
// UiLayout::window()
// .anchor(Anchor::BottomCenter)
// .size((Ab(800.), Rl(100.)))
// .pos((Rl(50.), Rl(100.)))
// .pack::<Base>(),
// RenderLayers::layer(1),
// ));
// ui.spawn((
// UiLink::<MainUi>::path("Root/MainRect/Categories"),
// UiLayout::solid()
// .align_y(Align::END)
// .size((Rl(100.), Ab(30.)))
// .pack::<Base>(),
// RenderLayers::layer(1),
// ));
// for i in 0..5 {
// let path = format!("Root/MainRect/Categories/Button{}", i);
// ui.spawn((
// UiLink::<MainUi>::path(path),
// UiLayout::window()
// .size((Rl(100. / 5.), Ab(30.)))
// .x(Rl((100. / 5.) * i as f32))
// .pack::<Base>(),
// UiLayout::window()
// .size((Rl(100. / 5.), Ab(20.)))
// .x(Rl((100. / 5.) * i as f32))
// .pack::<Hover>(),
// UiImage2dBundle::from(assets.load("textures/world/test2.png")),
// RenderLayers::layer(1),
// ));
// // ui.spawn((
// // UiLink::<MainUi>::path(format!("{}/img", path)),
// // UiLayout::solid().size((Ab(30.), Ab(100.))).pack::<Base>(),
// // UiImage2dBundle::from(assets.load("textures/world/test2.png")),
// // ));
// }
// });
// }

View File

@@ -1 +0,0 @@
pub mod build_ui;

View File

@@ -1,94 +0,0 @@
// use bevy::{
// prelude::*,
// render::{
// render_resource::{Extent3d, TextureDescriptor, TextureDimension, TextureFormat, TextureUsages},
// view::RenderLayers,
// },
// window::PrimaryWindow,
// };
// use bevy_lunex::prelude::*;
// use shared::tags::MainCamera;
// pub struct LunexSetupPlugin;
// impl Plugin for LunexSetupPlugin {
// fn build(&self, app: &mut App) {
// app.add_plugins(UiDefaultPlugins);
// #[cfg(debug_assertions)]
// app.add_plugins(UiDebugPlugin::<MainUi>::new());
// app.add_systems(PostStartup, setup_cameras);
// }
// }
// fn setup_cameras(
// mut commands: Commands,
// assets: Res<AssetServer>,
// mut main_3d_camera_q: Query<&mut Camera, With<MainCamera>>,
// window_query: Query<&Window, With<PrimaryWindow>>,
// ) {
// //Prepare Render Texture
// let win = window_query.single();
// let size = Extent3d {
// width: win.physical_width(),
// height: win.physical_height(),
// ..default()
// };
// let mut image = Image {
// texture_descriptor: TextureDescriptor {
// label: None,
// size,
// dimension: TextureDimension::D2,
// format: TextureFormat::Bgra8UnormSrgb,
// mip_level_count: 1,
// sample_count: 1,
// usage: TextureUsages::TEXTURE_BINDING | TextureUsages::COPY_DST | TextureUsages::RENDER_ATTACHMENT,
// view_formats: &[],
// },
// ..default()
// };
// image.resize(size);
// //Configure 3D Camera
// let mut cam = main_3d_camera_q.single_mut();
// let render_image = assets.add(image);
// cam.target = render_image.clone().into();
// cam.order = -1;
// cam.clear_color = ClearColorConfig::Custom(LinearRgba::NONE.into());
// //Add Render Texture image
// commands
// .spawn((
// UiTreeBundle::<MainUi>::from(UiTree::new2d("Main UI")),
// SourceFromCamera,
// RenderLayers::layer(1),
// ))
// .with_children(|ui| {
// ui.spawn((
// UiLink::<MainUi>::path("Root"),
// UiLayout::window_full().size((Rl(100.), Rl(100.))).pack::<Base>(),
// RenderLayers::layer(1),
// ));
// ui.spawn((
// UiLink::<MainUi>::path("Root/Camera3D"),
// UiLayout::solid()
// .size((Rl(100.), Rl(100.)))
// .scaling(Scaling::Fill)
// .pack::<Base>(),
// UiImage2dBundle::from(render_image),
// PickingPortal,
// RenderLayers::layer(1),
// ));
// });
// //Spawn 2d UI Camera
// commands.spawn((
// MainUi,
// Camera2dBundle {
// transform: Transform::from_xyz(0.0, 0.0, 1000.0),
// ..default()
// },
// RenderLayers::from_layers(&[1]),
// ));
// }

View File

@@ -1,2 +1 @@
pub mod game;
pub mod lunex_setup_plugin;
pub mod build_ui;