Created
December 27, 2021 13:23
-
-
Save jjant/df603aef7ec7d8e34c50fb103105771f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use bevy::ecs::system::{IntoSystem, System}; | |
use bevy::math::Rect; | |
use bevy::prelude::{ | |
AssetServer, Assets, BuildChildren, ChildBuilder, Color, ImageBundle, NodeBundle, Res, ResMut, | |
TextBundle, VerticalAlign, | |
}; | |
use bevy::sprite::ColorMaterial; | |
use bevy::text::{Text, TextAlignment, TextStyle}; | |
use bevy::ui::{AlignContent, AlignItems, FlexWrap, JustifyContent, PositionType}; | |
use bevy::{ | |
math::Size, | |
prelude::{ButtonBundle, Commands, Plugin, UiCameraBundle}, | |
ui::{Style, Val}, | |
}; | |
pub struct InventoryPlugin; | |
impl Plugin for InventoryPlugin { | |
fn build(&self, app: &mut bevy::prelude::AppBuilder) { | |
app.add_startup_system(setup.system()); | |
} | |
} | |
fn setup(mut commands: Commands, mut materials: ResMut<Assets<ColorMaterial>>) { | |
// ui camera | |
commands.spawn_bundle(UiCameraBundle::default()); | |
// root node | |
commands | |
.spawn_bundle(NodeBundle { | |
style: Style { | |
size: Size::new(Val::Percent(100.0), Val::Percent(100.0)), | |
justify_content: JustifyContent::FlexEnd, | |
..Default::default() | |
}, | |
material: materials.add(Color::NONE.into()), | |
..Default::default() | |
}) | |
.with_children(|parent| { | |
// right vertical fill | |
parent | |
.spawn_bundle(NodeBundle { | |
style: Style { | |
size: Size::new(Val::Px(400.0), Val::Percent(100.0)), | |
border: Rect::all(Val::Px(2.0)), | |
..Default::default() | |
}, | |
material: materials.add(Color::rgb(0.65, 0.65, 0.65).into()), | |
..Default::default() | |
}) | |
.with_children(|parent| { | |
parent | |
.spawn_bundle(NodeBundle { | |
style: Style { | |
size: Size::new(Val::Percent(100.0), Val::Percent(100.0)), | |
flex_wrap: FlexWrap::Wrap, | |
align_content: AlignContent::Center, | |
..Default::default() | |
}, | |
material: materials.add(Color::rgb(0.15, 0.15, 0.15).into()), | |
..Default::default() | |
}) | |
.with_children(|parent| {}); | |
// render_inventory(materials, parent)}); | |
}); | |
}); | |
} | |
fn render_inventory(mut materials: ResMut<Assets<ColorMaterial>>, parent: &mut ChildBuilder) { | |
let rows = 5; | |
let cols = 5; | |
let size = 80.0; | |
for _ in 0..rows { | |
parent | |
.spawn_bundle(NodeBundle { | |
..Default::default() | |
}) | |
.with_children(|row| { | |
for _ in 0..cols { | |
row.spawn_bundle(NodeBundle { | |
style: Style { | |
size: Size::new(Val::Px(size), Val::Px(size)), | |
border: Rect::all(Val::Px(1.0)), | |
..Default::default() | |
}, | |
material: materials.add(Color::rgb(0.9, 0.9, 0.9).into()), | |
..Default::default() | |
}) | |
.with_children(|parent| { | |
parent | |
.spawn_bundle(NodeBundle { | |
style: Style { | |
size: Size::new(Val::Percent(100.0), Val::Percent(100.0)), | |
border: Rect::all(Val::Px(10.0)), | |
..Default::default() | |
}, | |
material: materials.add(Color::rgb(0.4, 0.4, 1.0).into()), | |
..Default::default() | |
}) | |
.with_children(|parent| { | |
parent.spawn_bundle(NodeBundle { | |
style: Style { | |
size: Size::new(Val::Percent(100.0), Val::Percent(100.0)), | |
..Default::default() | |
}, | |
material: materials.add(Color::rgb(0.8, 0.8, 1.0).into()), | |
..Default::default() | |
}); | |
}); | |
}); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment