Created
March 11, 2025 23:47
-
-
Save CodaBool/0371fb9b8d8dceec6c1f8a94d55d1a6a to your computer and use it in GitHub Desktop.
V11 Dialog Choose background
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const backgrounds = [ | |
"/full/path/to/file.webp", | |
"https://or.even.urls" | |
// ... list of images here | |
] | |
// Generate the dialog content | |
let content = '<form><div class="form-group" style="display: flex">'; | |
backgrounds.forEach((bg, index) => { | |
content += ` | |
<div style="flex:none"> | |
<input type="radio" name="background" value="${index}" id="bg-${index}"> | |
<img src="${bg}" width="300" height="200" style="margin: 1px;"> | |
</div>` | |
}) | |
content += '</div></form>' | |
// Create and render the dialog | |
const dialog = new Dialog({ | |
title: "Choose a Scene Background", | |
content, | |
buttons: { | |
select: { | |
label: "Select", | |
callback: html => { | |
const selected = html.find('input[name="background"]:checked').val() | |
if (!selected) return | |
// Get the selected background image | |
const background = backgrounds[selected] | |
// Update the scene's background | |
canvas.scene.update({ "background.src": background }) | |
} | |
} | |
}, | |
default: "select" | |
}).render(true); | |
setTimeout(() => { | |
dialog.setPosition({ | |
width: window.innerWidth * .8, | |
height: window.innerHeight * .8, | |
}) | |
}, 200) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment