restore after broken git

This commit is contained in:
nquidox 2026-04-10 20:28:55 +03:00
commit 138c62ac34
51 changed files with 7559 additions and 0 deletions

View file

@ -0,0 +1,8 @@
use bevy::prelude::Component;
#[derive(Component, Clone, Copy)]
#[derive(PartialEq)]
pub enum AudioAction {
Mute,
Unmute,
}

View file

@ -0,0 +1,8 @@
use bevy::prelude::*;
#[derive(Component)]
pub struct HoverStyle {
pub normal: Color,
pub hovered: Color,
pub pressed: Color,
}

2
src/ui/components/mod.rs Normal file
View file

@ -0,0 +1,2 @@
pub mod hover_style;
pub mod audio;

View file

@ -0,0 +1,6 @@
use bevy::prelude::Message;
#[derive(Message)]
pub struct ButtonClickMessage<T: Send + Sync + 'static> {
pub action: T,
}

1
src/ui/messages/mod.rs Normal file
View file

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

13
src/ui/mod.rs Normal file
View file

@ -0,0 +1,13 @@
pub mod components;pub mod messages;
pub use crate::ui::messages::*;
pub mod spawners;
pub use crate::ui::spawners::background::spawn_background;
pub use crate::ui::spawners::button::spawn_button;
pub mod systems;
pub use crate::ui::systems::*;
pub mod types;
pub use crate::ui::types::button_style::ButtonStyle;

View file

@ -0,0 +1,37 @@
use bevy::prelude::*;
pub fn spawn_background_ui(
commands: &mut Commands,
parent: Entity,
image: Handle<Image>,
) {
commands.entity(parent).with_children(|builder| {
builder.spawn((
Node {
position_type: PositionType::Absolute,
width: Val::Percent(100.0),
height: Val::Percent(100.0),
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
left: Val::Px(0.0),
top: Val::Px(0.0),
..default()
},
ImageNode::new(image),
ZIndex(-1),
Name::new("Background"),
));
});
}
pub fn spawn_background<B: Bundle>(
commands: &mut Commands,
image: Handle<Image>,
extra: B,
) -> Entity {
commands.spawn((
Sprite::from_image(image),
Transform::from_xyz(0.0, 0.0, -10.0),
extra,
)).id()
}

36
src/ui/spawners/button.rs Normal file
View file

@ -0,0 +1,36 @@
use bevy::prelude::*;
use crate::ui::ButtonStyle;
pub fn spawn_button<T: Component>(
commands: &mut Commands,
parent: Entity,
label: &str,
style: &ButtonStyle,
action: T,
) {
commands.entity(parent).with_children(|builder| {
builder.spawn((
Button,
Node {
width: style.width,
height: style.height,
margin: style.margin,
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
..default()
},
BackgroundColor(style.normal_bg),
action,
)).with_children(|b| {
b.spawn((
Text(label.to_string()),
TextFont {
font: style.font.clone(),
font_size: style.font_size,
..default()
},
TextColor(style.text_color),
));
});
});
}

4
src/ui/spawners/mod.rs Normal file
View file

@ -0,0 +1,4 @@
pub mod background;
pub mod button;
pub mod slider;

35
src/ui/spawners/slider.rs Normal file
View file

@ -0,0 +1,35 @@
use bevy::prelude::*;
pub fn spawn_slider(
commands: &mut Commands,
root: Entity,
){
let slider = commands
.spawn((
Node {
display: Display::Flex,
width: Val::Percent(30.0),
height: Val::Percent(3.0),
border: UiRect{
left: Val::Px(2.0),
right: Val::Px(2.0),
top: Val::Px(2.0),
bottom: Val::Px(2.0),
},
..default()
},
BackgroundColor(Color::srgb_u8(216, 223, 233)),
)).id();
let thumb = commands.spawn((
Node{
height: Val::Percent(100.0),
aspect_ratio: Some(1.0),
..default()
},
BackgroundColor(Color::srgb_u8(1, 226, 106)),
)).id();
commands.entity(slider).add_child(thumb);
commands.entity(root).add_child(slider);
}

View file

@ -0,0 +1,22 @@
use bevy::prelude::*;
pub fn button_hover(
mut interaction_query: Query<
(&Interaction, &mut BackgroundColor),
(Changed<Interaction>, With<Button>),
>,
) {
for (interaction, mut color) in &mut interaction_query {
match interaction {
Interaction::Pressed => {
*color = BackgroundColor(Color::linear_rgb(0.3, 0.3, 0.3));
}
Interaction::Hovered => {
*color = BackgroundColor(Color::linear_rgb(0.25, 0.25, 0.25));
}
Interaction::None => {
*color = BackgroundColor(Color::linear_rgb(0.15, 0.15, 0.15));
}
}
}
}

14
src/ui/systems/click.rs Normal file
View file

@ -0,0 +1,14 @@
use bevy::prelude::*;
use crate::ui::messages::button_click::ButtonClickMessage;
pub fn handle_click_system<T: Component + Copy + Send + Sync + 'static>(
query: Query<(&Interaction, &T), Changed<Interaction>>,
mut writer: MessageWriter<ButtonClickMessage<T>>,
) {
for (interaction, action) in &query {
if *interaction == Interaction::Pressed {
writer.write(ButtonClickMessage { action: *action });
}
}
}

2
src/ui/systems/mod.rs Normal file
View file

@ -0,0 +1,2 @@
pub mod button_hover;
pub mod click;

View file

@ -0,0 +1,14 @@
use bevy::prelude::*;
#[derive(Clone)]
pub struct ButtonStyle {
pub width: Val,
pub height: Val,
pub font: Handle<Font>,
pub font_size: f32,
pub text_color: Color,
pub normal_bg: Color,
pub hovered_bg: Color,
pub pressed_bg: Color,
pub margin: UiRect,
}

1
src/ui/types/mod.rs Normal file
View file

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