mirror of
https://github.com/SpaceManiac/SpacemanDMM.git
synced 2025-12-23 05:36:47 +00:00
Add tracking of tile currently under cursor
This commit is contained in:
parent
526bb6c88f
commit
fc26e8d6aa
4 changed files with 55 additions and 13 deletions
7
Cargo.lock
generated
7
Cargo.lock
generated
|
|
@ -245,6 +245,11 @@ dependencies = [
|
|||
"syn 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "divrem"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "dlib"
|
||||
version = "0.4.1"
|
||||
|
|
@ -1123,6 +1128,7 @@ dependencies = [
|
|||
name = "spaceman-dmm"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"divrem 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"dmm-tools 0.1.0",
|
||||
"dreammaker 0.1.0",
|
||||
"gfx 0.17.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
|
@ -1547,6 +1553,7 @@ dependencies = [
|
|||
"checksum crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2760899e32a1d58d5abb31129f8fae5de75220bc2176e77ff7c627ae45c918d9"
|
||||
"checksum deflate 0.7.18 (registry+https://github.com/rust-lang/crates.io-index)" = "32c8120d981901a9970a3a1c97cf8b630e0fa8c3ca31e75b6fd6fd5f9f427b31"
|
||||
"checksum derivative 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "67b3d6d0e84e53a5bdc263cc59340541877bb541706a191d762bfac6a481bdde"
|
||||
"checksum divrem 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc9f8914dcb99891bdfee82536bbff8d9aa612b0dbe83872afbc66902bdec0b9"
|
||||
"checksum dlib 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "77e51249a9d823a4cb79e3eca6dcd756153e8ed0157b6c04775d04bf1b13b76a"
|
||||
"checksum downcast-rs 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "18df8ce4470c189d18aa926022da57544f31e154631eb4cfe796aea97051fe6c"
|
||||
"checksum draw_state 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "33cf9537e2d06891448799b96d5a8c8083e0e90522a7fdabe6ebf4f41d79d651"
|
||||
|
|
|
|||
|
|
@ -19,3 +19,4 @@ imgui-gfx-renderer = "0.0.20"
|
|||
lodepng = "2.1.5"
|
||||
ndarray = "0.11.1"
|
||||
nfd = "0.0.4"
|
||||
divrem = "0.1.0"
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ extern crate imgui_gfx_renderer;
|
|||
extern crate lodepng;
|
||||
extern crate ndarray;
|
||||
extern crate nfd;
|
||||
extern crate divrem;
|
||||
|
||||
extern crate dreammaker as dm;
|
||||
extern crate dmm_tools;
|
||||
|
|
@ -24,6 +25,7 @@ use std::path::{Path, PathBuf};
|
|||
use std::borrow::Cow;
|
||||
|
||||
use imgui::*;
|
||||
use divrem::DivFloor;
|
||||
|
||||
use dm::objtree::{ObjectTree, TypeRef};
|
||||
use dmm_tools::dmm::Map;
|
||||
|
|
@ -54,6 +56,8 @@ pub struct EditorScene {
|
|||
maps: Vec<EditorMap>,
|
||||
map_current: usize,
|
||||
|
||||
target_tile: Option<(usize, usize)>,
|
||||
|
||||
tasks: Vec<Task<TaskResult>>,
|
||||
errors: Vec<Box<std::error::Error>>,
|
||||
last_errors: usize,
|
||||
|
|
@ -80,6 +84,8 @@ impl EditorScene {
|
|||
maps: Vec::new(),
|
||||
map_current: 0,
|
||||
|
||||
target_tile: None,
|
||||
|
||||
tasks: Vec::new(),
|
||||
errors: Vec::new(),
|
||||
last_errors: 0,
|
||||
|
|
@ -98,15 +104,6 @@ impl EditorScene {
|
|||
ed
|
||||
}
|
||||
|
||||
fn mouse_wheel(&mut self, ctrl: bool, shift: bool, _alt: bool, _x: f32, y: f32) {
|
||||
let (axis, mut mul) = if ctrl { (0, -1.0) } else { (1, 1.0) };
|
||||
if shift {
|
||||
mul *= 8.0;
|
||||
}
|
||||
|
||||
self.map_renderer.center[axis] += 4.0 * 32.0 * mul * y / self.map_renderer.zoom;
|
||||
}
|
||||
|
||||
fn render(&mut self, factory: &mut Factory, encoder: &mut Encoder, view: &RenderTargetView) {
|
||||
let mut tasks = std::mem::replace(&mut self.tasks, Vec::new());
|
||||
tasks.retain(|task| task.poll(|res| match res {
|
||||
|
|
@ -367,7 +364,8 @@ impl EditorScene {
|
|||
.build(|| {
|
||||
for (map_idx, map) in self.maps.iter_mut().enumerate() {
|
||||
if ui.collapsing_header(im_str!("{}##map_{}", file_name(&map.path), map.path.display())).default_open(true).build() {
|
||||
ui.text(im_str!("keys: {} / length: {}",
|
||||
ui.text(im_str!("{:?}, {} keys (len={})",
|
||||
map.dmm.dim_xyz(),
|
||||
map.dmm.dictionary.len(),
|
||||
map.dmm.key_length));
|
||||
for z in 0..map.dmm.dim_z() {
|
||||
|
|
@ -384,7 +382,7 @@ impl EditorScene {
|
|||
let mut ui_debug = self.ui_debug;
|
||||
ui.window(im_str!("Debug"))
|
||||
.position((320.0, 30.0), ImGuiCond::FirstUseEver)
|
||||
.size((300.0, 100.0), ImGuiCond::FirstUseEver)
|
||||
.size((300.0, 120.0), ImGuiCond::FirstUseEver)
|
||||
.opened(&mut ui_debug)
|
||||
.build(|| {
|
||||
ui.text(im_str!("zoom = {}, center = {:?}", self.map_renderer.zoom, self.map_renderer.center));
|
||||
|
|
@ -395,6 +393,9 @@ impl EditorScene {
|
|||
ui.text(im_str!("timings: {:?}", rendered.duration));
|
||||
}
|
||||
}
|
||||
if let Some((x, y)) = self.target_tile {
|
||||
ui.text(im_str!("target: {}, {}", x, y));
|
||||
}
|
||||
});
|
||||
self.ui_debug = ui_debug;
|
||||
}
|
||||
|
|
@ -416,6 +417,37 @@ impl EditorScene {
|
|||
continue_running
|
||||
}
|
||||
|
||||
fn mouse_moved(&mut self, (x, y): (i32, i32), view: &RenderTargetView) {
|
||||
self.target_tile = self.tile_under((x, y), view);
|
||||
}
|
||||
|
||||
fn tile_under(&self, (x, y): (i32, i32), view: &RenderTargetView) -> Option<(usize, usize)> {
|
||||
if let Some(map) = self.maps.get(self.map_current) {
|
||||
let (w, h, _, _) = view.get_dimensions();
|
||||
let (cx, cy) = (w / 2, h / 2);
|
||||
let tx = (x - cx as i32 + self.map_renderer.center[0].round() as i32).div_floor(32);
|
||||
let ty = (cy as i32 - y + self.map_renderer.center[1].round() as i32).div_floor(32);
|
||||
let (dim_x, dim_y, _) = map.dmm.dim_xyz();
|
||||
if tx >= 0 && ty >= 0 && tx < dim_x as i32 && ty < dim_y as i32 {
|
||||
Some((tx as usize, ty as usize))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn mouse_wheel(&mut self, ctrl: bool, shift: bool, _alt: bool, _x: f32, y: f32) {
|
||||
let (axis, mut mul) = if ctrl { (0, -1.0) } else { (1, 1.0) };
|
||||
if shift {
|
||||
mul *= 8.0;
|
||||
}
|
||||
|
||||
self.map_renderer.center[axis] += 4.0 * 32.0 * mul * y / self.map_renderer.zoom;
|
||||
// TODO: update target_tile
|
||||
}
|
||||
|
||||
#[deny(unreachable_patterns)]
|
||||
fn chord(&mut self, ctrl: bool, shift: bool, alt: bool, key: Key) {
|
||||
use Key::*;
|
||||
|
|
|
|||
|
|
@ -157,13 +157,15 @@ pub fn run(title: String, clear_color: [f32; 4]) -> ::EditorScene {
|
|||
}
|
||||
}
|
||||
},
|
||||
CursorMoved { position: pos, .. } => {
|
||||
CursorMoved { position, .. } => {
|
||||
// Rescale position from glutin logical coordinates to our logical
|
||||
// coordinates
|
||||
mouse_state.pos = pos
|
||||
let pos = position
|
||||
.to_physical(window_hidpi_factor)
|
||||
.to_logical(hidpi_factor)
|
||||
.into();
|
||||
mouse_state.pos = pos;
|
||||
scene.mouse_moved(pos, &main_color);
|
||||
},
|
||||
MouseInput { state, button, .. } => match button {
|
||||
MouseButton::Left => mouse_state.pressed[0] = state == Pressed,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue