added cursor to mapedit
This commit is contained in:
parent
6d6d03db37
commit
365f30e893
Binary file not shown.
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 27 KiB |
|
@ -16,6 +16,8 @@ use winit::{
|
||||||
window::WindowBuilder,
|
window::WindowBuilder,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const SPR_CURSOR: usize = 0x01;
|
||||||
|
|
||||||
pub(crate) fn run_mapedit() {
|
pub(crate) fn run_mapedit() {
|
||||||
println!("running map edit");
|
println!("running map edit");
|
||||||
|
|
||||||
|
@ -34,6 +36,7 @@ pub(crate) fn run_mapedit() {
|
||||||
|
|
||||||
gsa.reset_bgs();
|
gsa.reset_bgs();
|
||||||
gsa.reset_sprites();
|
gsa.reset_sprites();
|
||||||
|
gsa.sprites[SPR_CURSOR].tile = 0x7308;
|
||||||
|
|
||||||
let event_loop = EventLoop::new();
|
let event_loop = EventLoop::new();
|
||||||
let size = LogicalSize::new(1280, 720);
|
let size = LogicalSize::new(1280, 720);
|
||||||
|
@ -50,12 +53,16 @@ pub(crate) fn run_mapedit() {
|
||||||
let mut surface = unsafe { softbuffer::Surface::new(&context, &window) }.unwrap();
|
let mut surface = unsafe { softbuffer::Surface::new(&context, &window) }.unwrap();
|
||||||
window.request_redraw();
|
window.request_redraw();
|
||||||
let mut mouse_pos = IVec2::ZERO;
|
let mut mouse_pos = IVec2::ZERO;
|
||||||
|
let mut tile_pos = IVec2::ZERO;
|
||||||
let mut left_down = false;
|
let mut left_down = false;
|
||||||
let mut middle_down = false;
|
let mut middle_down = false;
|
||||||
|
let mut right_down = false;
|
||||||
event_loop.run(move |event, _, control_flow| {
|
event_loop.run(move |event, _, control_flow| {
|
||||||
let mouse_pos = &mut mouse_pos;
|
let mouse_pos = &mut mouse_pos;
|
||||||
|
let tile_pos = &mut tile_pos;
|
||||||
let left_down = &mut left_down;
|
let left_down = &mut left_down;
|
||||||
let middle_down = &mut middle_down;
|
let middle_down = &mut middle_down;
|
||||||
|
let right_down = &mut right_down;
|
||||||
match event {
|
match event {
|
||||||
Event::WindowEvent { event, .. } => match event {
|
Event::WindowEvent { event, .. } => match event {
|
||||||
WindowEvent::KeyboardInput {
|
WindowEvent::KeyboardInput {
|
||||||
|
@ -81,6 +88,12 @@ pub(crate) fn run_mapedit() {
|
||||||
(winit::event::ElementState::Released, winit::event::MouseButton::Middle) => {
|
(winit::event::ElementState::Released, winit::event::MouseButton::Middle) => {
|
||||||
*middle_down = false;
|
*middle_down = false;
|
||||||
}
|
}
|
||||||
|
(winit::event::ElementState::Pressed, winit::event::MouseButton::Right) => {
|
||||||
|
*right_down = true;
|
||||||
|
}
|
||||||
|
(winit::event::ElementState::Released, winit::event::MouseButton::Right) => {
|
||||||
|
*right_down = false;
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
},
|
},
|
||||||
WindowEvent::CursorMoved { position, .. } => {
|
WindowEvent::CursorMoved { position, .. } => {
|
||||||
|
@ -95,16 +108,29 @@ pub(crate) fn run_mapedit() {
|
||||||
gsa.bgs[2].scroll -= delta;
|
gsa.bgs[2].scroll -= delta;
|
||||||
}
|
}
|
||||||
*mouse_pos = new_pos;
|
*mouse_pos = new_pos;
|
||||||
|
*tile_pos = (new_pos + gsa.bgs[0].scroll) / TILE_SIZE as i32;
|
||||||
|
let cursor_pos = *tile_pos * TILE_SIZE as i32 - gsa.bgs[0].scroll;
|
||||||
|
gsa.sprites[SPR_CURSOR].pos = cursor_pos;
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
},
|
},
|
||||||
|
|
||||||
Event::MainEventsCleared => {
|
Event::MainEventsCleared => {
|
||||||
if *left_down {
|
if *left_down {
|
||||||
let tile_x = (mouse_pos.x + gsa.bgs[0].scroll.x) as usize / TILE_SIZE;
|
if tile_pos.x >= 0
|
||||||
let tile_y = (mouse_pos.y + gsa.bgs[0].scroll.y) as usize / TILE_SIZE;
|
&& tile_pos.y >= 0
|
||||||
if tile_x < BACKGROUND_MAX_SIZE && tile_y < BACKGROUND_MAX_SIZE {
|
&& tile_pos.x < BACKGROUND_MAX_SIZE as i32
|
||||||
gsa.bgs[0].tiles[tile_x][tile_y] = 0;
|
&& tile_pos.y < BACKGROUND_MAX_SIZE as i32
|
||||||
|
{
|
||||||
|
gsa.bgs[0].tiles[tile_pos.x as usize][tile_pos.y as usize] = 0;
|
||||||
|
}
|
||||||
|
} else if *right_down {
|
||||||
|
if tile_pos.x >= 0
|
||||||
|
&& tile_pos.y >= 0
|
||||||
|
&& tile_pos.x < BACKGROUND_MAX_SIZE as i32
|
||||||
|
&& tile_pos.y < BACKGROUND_MAX_SIZE as i32
|
||||||
|
{
|
||||||
|
gsa.bgs[0].tiles[tile_pos.x as usize][tile_pos.y as usize] = EMPTY_TILE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue