some fix and new bug
This commit is contained in:
1 parent
ffe4b48479
commit
f9ce81ff07
4 files changed
+46
-61
No files matched your search
BIN
Binary file not shown.
|
Before Width: | Height: | Size: 34 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 204 KiB After Width: | Height: | Size: 771 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 589 KiB |
+46
-61
@@ -19,18 +19,6 @@ fn main() {
|
||||
|
||||
fn setup(mut commands: Commands, assets: Res<AssetServer>) {
|
||||
commands.spawn(Camera2d);
|
||||
commands
|
||||
.spawn((
|
||||
|
||||
Node {
|
||||
width: percent(100),
|
||||
height: percent(100),
|
||||
..default()
|
||||
},
|
||||
|
||||
Sprite::from_image(assets.load("scene/chessboard.png"))
|
||||
))
|
||||
.insert(RelativeCursorPosition::default());
|
||||
commands
|
||||
.spawn(Node {
|
||||
width: percent(100),
|
||||
@@ -40,72 +28,69 @@ fn setup(mut commands: Commands, assets: Res<AssetServer>) {
|
||||
flex_direction: FlexDirection::Column,
|
||||
..default()
|
||||
})
|
||||
.with_children(|parent| {
|
||||
parent
|
||||
.spawn((
|
||||
Node {
|
||||
width: px(512),
|
||||
height: px(512),
|
||||
margin: UiRect::bottom(px(15)),
|
||||
..default()
|
||||
},
|
||||
ImageNode::new(assets.load("scene/chessboard.png")),
|
||||
|
||||
))
|
||||
.insert(RelativeCursorPosition::default());
|
||||
});
|
||||
|
||||
commands
|
||||
.spawn(Node {
|
||||
width: percent(100),
|
||||
height: percent(100),
|
||||
align_items: AlignItems::Center,
|
||||
justify_content: JustifyContent::Center,
|
||||
flex_direction: FlexDirection::Column,
|
||||
left: percent(-40.0),
|
||||
top: percent(-40.0),
|
||||
..default()
|
||||
})
|
||||
.with_children(|parent| {
|
||||
parent.spawn((
|
||||
Text::new("who"),
|
||||
|
||||
TextFont {
|
||||
font: assets.load("fonts/Baskerville Bold Italic.ttf").into(),
|
||||
//font_size: FontSize::Px(33.0),
|
||||
font_size: 50.0,
|
||||
..default()
|
||||
},
|
||||
TextColor(Color::srgb(0.1, 0.1, 0.1)),
|
||||
TextColor(Color::srgb(1.0, 0.5, 1.0)),
|
||||
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
fn relative_cursor_position_system(rcp: Single<&RelativeCursorPosition>, text: Single<&mut Text>){
|
||||
//let ratio;
|
||||
let is_white = true;
|
||||
let mut output_text = text.into_inner();
|
||||
if let Some(pos) = rcp.normalized{
|
||||
let x = ((pos.x + 0.5) * 10.0) as i8;
|
||||
let mut coordinate_x: char;
|
||||
match x {
|
||||
1 => {coordinate_x = 'a'}
|
||||
2 => {coordinate_x = 'b'}
|
||||
3 => {coordinate_x = 'c'}
|
||||
4 => {coordinate_x = 'd'}
|
||||
5 => {coordinate_x = 'e'}
|
||||
6 => {coordinate_x = 'f'}
|
||||
7 => {coordinate_x = 'g'}
|
||||
8 => {coordinate_x = 'h'}
|
||||
_ => {coordinate_x = ' '}
|
||||
}
|
||||
|
||||
let y = ((pos.y * -1. + 0.5) * 10.0) as i8;
|
||||
let mut coordinate_y: char;
|
||||
match y {
|
||||
1 => {coordinate_y = '1'}
|
||||
2 => {coordinate_y = '2'}
|
||||
3 => {coordinate_y = '3'}
|
||||
4 => {coordinate_y = '4'}
|
||||
5 => {coordinate_y = '5'}
|
||||
6 => {coordinate_y = '6'}
|
||||
7 => {coordinate_y = '7'}
|
||||
8 => {coordinate_y = '8'}
|
||||
_ => {coordinate_y = ' '}
|
||||
}
|
||||
** output_text = format!("{}{}", coordinate_x, coordinate_y);
|
||||
let mut x = ((pos.x + 0.5) * 8.0) as usize + 1;
|
||||
let mut y;
|
||||
if is_white {
|
||||
y = ((pos.y - 0.5) * -8.0 ) as usize + 1;
|
||||
} else {
|
||||
** output_text = "uncnown".to_string();
|
||||
y = ((pos.y + 0.5) * 8.0) as usize + 1;
|
||||
}
|
||||
let m = ((y - 1) * 8) + x-1;
|
||||
x = (pos.x > -0.5 && pos.x < 0.5) as usize * x;
|
||||
let cx = [' ', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'];
|
||||
y = (pos.y > -0.5 && pos.y < 0.5) as usize * y;
|
||||
let cy = [' ', '1', '2', '3', '4', '5', '6', '7', '8'];
|
||||
|
||||
** output_text = format!("{}|{}|{}", cx[x], cy[y], m);
|
||||
} else {
|
||||
** output_text = " ".to_string();
|
||||
}
|
||||
}
|
||||
/*
|
||||
fn relative_cursor_position_system(
|
||||
relative_cursor_position: Single<&RelativeCursorPosition>,
|
||||
output_query: Single<(&mut Text, &mut TextColor)>,
|
||||
) {
|
||||
let (mut output, mut text_color) = output_query.into_inner();
|
||||
|
||||
**output = if let Some(relative_cursor_position) = relative_cursor_position.normalized {
|
||||
format!(
|
||||
"({}, {})",
|
||||
relative_cursor_position.x, relative_cursor_position.y
|
||||
)
|
||||
} else {
|
||||
"unknown".to_string()
|
||||
};
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct Chess {}
|
||||
*/
|
||||
Reference in new issue
Block a user