diff --git a/css/main.less b/css/main.less index 88d46b8..0a4df5f 100644 --- a/css/main.less +++ b/css/main.less @@ -126,6 +126,7 @@ body { position: absolute; bottom: 0px; right: 0px; + min-width: 100px; max-width: 300px; max-height: 60%; padding: 2px; @@ -167,6 +168,19 @@ body { display: none;// hmmmm } } + #instancefindwindow { + position: absolute; + top: @tabs-height; + right: 0px; + padding-right: 10px; + max-width: 300px; + max-height: 40%; + padding: 2px; + background-color: rgba(0,0,0,0.8); + overflow: auto; + white-space: nowrap; + scrollbar-width: thin; + } #statustextwindow { position: absolute; bottom: 0px; diff --git a/package.json b/package.json index 38adb93..73117b3 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", - "build-prod": "npm ci && rimraf ./dist && webpack --mode=production" + "build-prod": "npm ci && rimraf ./dist && webpack --mode=production", + "develop": "webpack-dev-server" }, "author": "", "license": "MIT", diff --git a/res/index.html b/res/index.html index f709d16..28426cb 100644 --- a/res/index.html +++ b/res/index.html @@ -18,6 +18,7 @@
+ diff --git a/src/editor.js b/src/editor.js index 26779f2..b7bcfd4 100644 --- a/src/editor.js +++ b/src/editor.js @@ -7,6 +7,7 @@ const Parser = require('./parser/parser.js'); const MapWindow = require('./mapwindow.js'); const ObjTreeWindow = require('./objtreewindow.js'); const InstanceWindow = require('./instancewindow.js'); +const InstanceFindWindow = require('./instancefindwindow.js'); const DMM = require('./parser/dmm.js'); const {FileMenu, OptionsMenu, HelpMenu} = require('./menu/menubar_menus.js'); const ProgressBarPanel = require('./panels/progress_bar_panel.js'); @@ -43,6 +44,7 @@ class Editor { this.map_window = new MapWindow(this); this.objtree_window = new ObjTreeWindow(this); this.instance_window = new InstanceWindow(this); + this.instance_find_window = new InstanceFindWindow(this); this.file_menu = new FileMenu(this); this.file_menu.add_to_menubar(document.getElementById("ui-menubar"), "File"); diff --git a/src/instancefindwindow.js b/src/instancefindwindow.js new file mode 100644 index 0000000..8d26db9 --- /dev/null +++ b/src/instancefindwindow.js @@ -0,0 +1,56 @@ +'use strict'; + +module.exports = class InstanceFindWindow { + /** + * + * @param {import("./editor")} editor + */ + constructor(editor) { + this.editor = editor; + this.container = document.getElementById("instancefindwindow"); + } + + set_instance_search(item) { + if(!item) return; + this.selected = item; + // Clear old entries + this.container.innerHTML = ''; + let found_tiles = []; + // Search the entire map + for(let x = 1; x <= this.editor.dmm.maxx; x++) { + for(let y = 1; y <= this.editor.dmm.maxy; y++) { + for(let z = 1; z <= this.editor.dmm.maxz; z++) { + let tile = this.editor.dmm.get_tile(x, y, z); + for(let content of tile.contents) { + if(content.toString() == item) { + found_tiles.push([x, y, z]); + } + } + } + } + } + for(let tile of found_tiles) { + let entry = document.createElement("div"); + entry.dataset.coordinates = tile; + let gotoButton = document.createElement("button"); + gotoButton.innerText = "Jump"; + gotoButton.addEventListener("click", this.on_goto.bind(this)) + let text = document.createElement("span"); + text.innerText = " at " + tile[0] + ", " + tile[1] + ", " + tile[2]; + entry.appendChild(gotoButton); + entry.appendChild(text); + this.container.appendChild(entry); + } + } + + on_goto(e) { + if(!e.target) return; + let leaf = e.target.closest("div"); + if(leaf && leaf.dataset.coordinates) { + let coord = leaf.dataset.coordinates.split(",") + this.editor.dmm.mapwindow_x = Math.min(Math.max(coord[0], 1), this.editor.dmm.maxx); + this.editor.dmm.mapwindow_y = Math.min(Math.max(coord[1], 1), this.editor.dmm.maxy); + this.editor.dmm.mapwindow_z = Math.min(Math.max(coord[2], 1), this.editor.dmm.maxz); + } + } +} diff --git a/src/instancewindow.js b/src/instancewindow.js index a238209..f562896 100644 --- a/src/instancewindow.js +++ b/src/instancewindow.js @@ -85,6 +85,13 @@ module.exports = class InstanceWindow { container.appendChild(label); } + let buttons = document.createElement("div"); + let instancesButton = document.createElement("button"); + instancesButton.innerText = "Search"; + instancesButton.addEventListener("click", this.handle_search_click.bind(this)); + buttons.append(instancesButton); + container.appendChild(buttons); + return container; } @@ -120,4 +127,14 @@ module.exports = class InstanceWindow { } } } + + handle_search_click(e) { + if(!e.target) return; + // cursed, but we need the variant-leaf + let leaf = e.target.closest(".vertical-node-container").firstChild; + if(leaf && leaf.dataset.instance) { + this.editor.instance_find_window.set_instance_search(leaf.dataset.instance); + } + } + } \ No newline at end of file