head damage ui
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 782 B After Width: | Height: | Size: 966 B |
BIN
assets/ui/head_damage.png
Normal file
BIN
assets/ui/head_damage.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.1 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 3.4 KiB After Width: | Height: | Size: 6.9 KiB |
@@ -1,11 +1,17 @@
|
|||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
#[derive(Component, Default)]
|
#[derive(Component, Reflect, Default)]
|
||||||
|
#[reflect(Component)]
|
||||||
struct HeadSelector(pub usize);
|
struct HeadSelector(pub usize);
|
||||||
|
|
||||||
#[derive(Component, Default)]
|
#[derive(Component, Reflect, Default)]
|
||||||
|
#[reflect(Component)]
|
||||||
struct HeadImage(pub usize);
|
struct HeadImage(pub usize);
|
||||||
|
|
||||||
|
#[derive(Component, Reflect, Default)]
|
||||||
|
#[reflect(Component)]
|
||||||
|
struct HeadDamage(pub usize);
|
||||||
|
|
||||||
#[derive(Resource, Default)]
|
#[derive(Resource, Default)]
|
||||||
struct HeadsImages {
|
struct HeadsImages {
|
||||||
heads: Vec<Handle<Image>>,
|
heads: Vec<Handle<Image>>,
|
||||||
@@ -21,6 +27,7 @@ struct ActiveHeads {
|
|||||||
pub struct HeadChanged(pub usize);
|
pub struct HeadChanged(pub usize);
|
||||||
|
|
||||||
pub fn plugin(app: &mut App) {
|
pub fn plugin(app: &mut App) {
|
||||||
|
app.register_type::<HeadDamage>();
|
||||||
app.add_systems(Startup, setup);
|
app.add_systems(Startup, setup);
|
||||||
app.add_systems(Update, (update, toggle_heads));
|
app.add_systems(Update, (update, toggle_heads));
|
||||||
}
|
}
|
||||||
@@ -28,6 +35,7 @@ pub fn plugin(app: &mut App) {
|
|||||||
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||||
let bg = asset_server.load("ui/head_bg.png");
|
let bg = asset_server.load("ui/head_bg.png");
|
||||||
let regular = asset_server.load("ui/head_regular.png");
|
let regular = asset_server.load("ui/head_regular.png");
|
||||||
|
let damage = asset_server.load("ui/head_damage.png");
|
||||||
let selector = asset_server.load("ui/selector.png");
|
let selector = asset_server.load("ui/selector.png");
|
||||||
|
|
||||||
commands
|
commands
|
||||||
@@ -39,11 +47,16 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
|||||||
..default()
|
..default()
|
||||||
})
|
})
|
||||||
.with_children(|parent| {
|
.with_children(|parent| {
|
||||||
spawn_head_ui(parent, bg.clone(), regular.clone(), selector.clone(), 0);
|
for i in 0..5 {
|
||||||
spawn_head_ui(parent, bg.clone(), regular.clone(), selector.clone(), 1);
|
spawn_head_ui(
|
||||||
spawn_head_ui(parent, bg.clone(), regular.clone(), selector.clone(), 2);
|
parent,
|
||||||
spawn_head_ui(parent, bg.clone(), regular.clone(), selector.clone(), 3);
|
bg.clone(),
|
||||||
spawn_head_ui(parent, bg.clone(), regular.clone(), selector.clone(), 4);
|
regular.clone(),
|
||||||
|
selector.clone(),
|
||||||
|
damage.clone(),
|
||||||
|
i,
|
||||||
|
);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let head_01 = asset_server.load("ui/heads/angry demonstrator.png");
|
let head_01 = asset_server.load("ui/heads/angry demonstrator.png");
|
||||||
@@ -67,20 +80,25 @@ fn spawn_head_ui(
|
|||||||
bg: Handle<Image>,
|
bg: Handle<Image>,
|
||||||
regular: Handle<Image>,
|
regular: Handle<Image>,
|
||||||
selector: Handle<Image>,
|
selector: Handle<Image>,
|
||||||
|
damage: Handle<Image>,
|
||||||
head: usize,
|
head: usize,
|
||||||
) {
|
) {
|
||||||
|
const SIZE: f32 = 90.0;
|
||||||
|
const DAMAGE_SIZE: f32 = 74.0;
|
||||||
|
|
||||||
parent
|
parent
|
||||||
.spawn((Node {
|
.spawn((Node {
|
||||||
position_type: PositionType::Relative,
|
position_type: PositionType::Relative,
|
||||||
justify_content: JustifyContent::Center,
|
justify_content: JustifyContent::Center,
|
||||||
width: Val::Px(74.0),
|
align_items: AlignItems::Center,
|
||||||
|
width: Val::Px(SIZE),
|
||||||
..default()
|
..default()
|
||||||
},))
|
},))
|
||||||
.with_children(|parent| {
|
.with_children(|parent| {
|
||||||
parent.spawn((
|
parent.spawn((
|
||||||
Node {
|
Node {
|
||||||
position_type: PositionType::Absolute,
|
position_type: PositionType::Absolute,
|
||||||
top: Val::Px(-20.0),
|
top: Val::Px(-30.0),
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
Visibility::Hidden,
|
Visibility::Hidden,
|
||||||
@@ -97,10 +115,8 @@ fn spawn_head_ui(
|
|||||||
parent.spawn((
|
parent.spawn((
|
||||||
Node {
|
Node {
|
||||||
position_type: PositionType::Absolute,
|
position_type: PositionType::Absolute,
|
||||||
left: Val::Px(2.0),
|
// width: Val::Px(66.0),
|
||||||
right: Val::Px(2.0),
|
// height: Val::Px(66.0),
|
||||||
top: Val::Px(2.0),
|
|
||||||
bottom: Val::Px(2.0),
|
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
ImageNode::default(),
|
ImageNode::default(),
|
||||||
@@ -114,6 +130,29 @@ fn spawn_head_ui(
|
|||||||
},
|
},
|
||||||
ImageNode::new(regular),
|
ImageNode::new(regular),
|
||||||
));
|
));
|
||||||
|
parent
|
||||||
|
.spawn((Node {
|
||||||
|
height: Val::Px(DAMAGE_SIZE),
|
||||||
|
width: Val::Px(DAMAGE_SIZE),
|
||||||
|
..default()
|
||||||
|
},))
|
||||||
|
.with_children(|parent| {
|
||||||
|
parent
|
||||||
|
.spawn((
|
||||||
|
HeadDamage(head),
|
||||||
|
Node {
|
||||||
|
position_type: PositionType::Absolute,
|
||||||
|
display: Display::Block,
|
||||||
|
overflow: Overflow::clip(),
|
||||||
|
top: Val::Px(0.),
|
||||||
|
left: Val::Px(0.),
|
||||||
|
right: Val::Px(0.),
|
||||||
|
height: Val::Percent(25.),
|
||||||
|
..default()
|
||||||
|
},
|
||||||
|
))
|
||||||
|
.with_child(ImageNode::new(damage));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user