Added dropdown prompt menu
This commit is contained in:
parent
319c3c6f30
commit
7fbee3ebf5
|
|
@ -17,86 +17,130 @@ let oreChances = {
|
|||
|
||||
let promptMenus = {};
|
||||
let keys = ["OK", "Cancel", "Confirm", "Input", "Choices", "Dirs", "Dropdown"];
|
||||
|
||||
Object.defineProperty(String.prototype, 'capitalize', {
|
||||
value: function() {
|
||||
return this.charAt(0).toUpperCase() + this.slice(1);
|
||||
},
|
||||
enumerable: false
|
||||
});
|
||||
runAfterLoad(()=>{
|
||||
let dropDown = document.createElement("select");
|
||||
dropDown.id = "promptDropdown";
|
||||
dropDown.style.position = "absolute";
|
||||
dropDown.style.top = "50%";
|
||||
dropDown.style.left = "50%";
|
||||
dropDown.style.top = "15%";
|
||||
dropDown.style.left = "42.5%";
|
||||
dropDown.style.width = "15%";
|
||||
dropDown.title = "prompt";
|
||||
dropDown.style.display = "none";
|
||||
document.getElementById("promptParent").appendChild(dropDown);
|
||||
document.getElementById("promptMenu").appendChild(dropDown);
|
||||
|
||||
for(let key of keys){
|
||||
promptMenus[key] = document.getElementById(`prompt${key}`);
|
||||
promptMenus[key].style.display = "none";
|
||||
}
|
||||
|
||||
function prompt
|
||||
//function prompt
|
||||
|
||||
function showPromptScreen() {
|
||||
if (!promptState) return;
|
||||
closeMenu("prompt");
|
||||
paused = true;
|
||||
checkPause();
|
||||
var promptParent = document.getElementById("promptParent");
|
||||
var menuTitle = document.querySelector("#promptMenu .menuTitle");
|
||||
menuTitle.innerText = promptState.title || "Notice";
|
||||
menuTitle.style.color = promptState.titleColor || "unset";
|
||||
var promptMenuText = document.getElementById("promptMenuText");
|
||||
promptMenuText.innerText = promptState.text || "";
|
||||
if (promptState.html) {
|
||||
promptMenuText.insertAdjacentHTML("beforeend",promptState.html);
|
||||
}
|
||||
let promptOK = document.getElementById("promptOK");
|
||||
let promptCancel = document.getElementById("promptCancel");
|
||||
let promptConfirm = document.getElementById("promptConfirm");
|
||||
let promptInput = document.getElementById("promptInput");
|
||||
let promptChoices = document.getElementById("promptChoices");
|
||||
let promptDirs = document.getElementById("promptDirs");
|
||||
for(let key of promptMenus){
|
||||
promptMenus[key].style.display = "none";
|
||||
}
|
||||
promptConfirm.classList.remove("danger");
|
||||
if (promptState.type === "text") {
|
||||
promptOK.style.display = "block";
|
||||
}
|
||||
else if (promptState.type === "confirm") {
|
||||
promptCancel.style.display = "block";
|
||||
promptConfirm.style.display = "block";
|
||||
if (promptState.danger) promptConfirm.classList.add("danger");
|
||||
}
|
||||
else if (promptState.type === "input") {
|
||||
promptInput.value = "";
|
||||
promptInput.style.display = "block";
|
||||
if (promptState.defaultInput !== undefined) {
|
||||
promptInput.value = ""+promptState.defaultInput;
|
||||
}
|
||||
}
|
||||
else if (promptState.type === "choose" && promptState.choices) {
|
||||
promptChoices.innerHTML = "";
|
||||
for (let i = 0; i < promptState.choices.length; i++) {
|
||||
const choice = promptState.choices[i];
|
||||
let span = document.createElement("span");
|
||||
span.className = "promptChoice";
|
||||
span.onclick = function(){ handlePrompt(choice) };
|
||||
span.innerText = choice;
|
||||
promptChoices.appendChild(span);
|
||||
}
|
||||
promptChoices.style.display = "block";
|
||||
}
|
||||
else if (promptState.type === "dir") {
|
||||
promptDirs.style.display = "block";
|
||||
}
|
||||
promptParent.style.display = "block";
|
||||
showingMenu = "prompt";
|
||||
if (promptState.type === "input") {
|
||||
document.getElementById("promptInput").focus();
|
||||
document.getElementById("promptInput").select();
|
||||
|
||||
});
|
||||
function showPromptScreen() {
|
||||
if (!promptState) return;
|
||||
closeMenu("prompt");
|
||||
paused = true;
|
||||
checkPause();
|
||||
var promptParent = document.getElementById("promptParent");
|
||||
var menuTitle = document.querySelector("#promptMenu .menuTitle");
|
||||
menuTitle.innerText = promptState.title || "Notice";
|
||||
menuTitle.style.color = promptState.titleColor || "unset";
|
||||
var promptMenuText = document.getElementById("promptMenuText");
|
||||
promptMenuText.innerText = promptState.text || "";
|
||||
if (promptState.html) {
|
||||
promptMenuText.insertAdjacentHTML("beforeend",promptState.html);
|
||||
}
|
||||
let promptOK = document.getElementById("promptOK");
|
||||
let promptCancel = document.getElementById("promptCancel");
|
||||
let promptConfirm = document.getElementById("promptConfirm");
|
||||
let promptInput = document.getElementById("promptInput");
|
||||
let promptChoices = document.getElementById("promptChoices");
|
||||
let promptDirs = document.getElementById("promptDirs");
|
||||
let dropDown = document.getElementById("promptDropdown");
|
||||
for(let key in promptMenus){
|
||||
promptMenus[key].style.display = "none";
|
||||
}
|
||||
promptConfirm.classList.remove("danger");
|
||||
if (promptState.type === "text") {
|
||||
promptOK.style.display = "block";
|
||||
}
|
||||
else if (promptState.type === "confirm") {
|
||||
promptCancel.style.display = "block";
|
||||
promptConfirm.style.display = "block";
|
||||
if (promptState.danger) promptConfirm.classList.add("danger");
|
||||
}
|
||||
else if (promptState.type === "input") {
|
||||
promptInput.value = "";
|
||||
promptInput.style.display = "block";
|
||||
if (promptState.defaultInput !== undefined) {
|
||||
promptInput.value = ""+promptState.defaultInput;
|
||||
}
|
||||
}
|
||||
});
|
||||
else if (promptState.type === "choose" && promptState.choices) {
|
||||
promptChoices.innerHTML = "";
|
||||
for (let i = 0; i < promptState.choices.length; i++) {
|
||||
const choice = promptState.choices[i];
|
||||
let span = document.createElement("span");
|
||||
span.className = "promptChoice";
|
||||
span.onclick = function(){ handlePrompt(choice) };
|
||||
span.innerText = choice;
|
||||
promptChoices.appendChild(span);
|
||||
}
|
||||
promptChoices.style.display = "block";
|
||||
}
|
||||
else if (promptState.type == "dropdown" && promptState.choices != undefined) {
|
||||
dropDown.innerHTML = "";
|
||||
//promptParent.appendChild(promptDropdown);
|
||||
|
||||
for(let choice of promptState.choices){
|
||||
dropDown.innerHTML += `<option value="${choice}">${choice.capitalize()}</option>`;
|
||||
}
|
||||
let span = document.createElement("span");
|
||||
span.className = "promptOK";
|
||||
span.textContent = "Select";
|
||||
span.onclick = ()=>{
|
||||
let c = dropDown.value;
|
||||
console.log(c);
|
||||
handlePrompt(c);
|
||||
document.getElementById("promptMenu").removeChild(span);
|
||||
};
|
||||
document.getElementById("promptMenu").appendChild(span);
|
||||
dropDown.style.display = "block";
|
||||
|
||||
}
|
||||
else if (promptState.type === "dir") {
|
||||
promptDirs.style.display = "block";
|
||||
}
|
||||
promptParent.style.display = "block";
|
||||
showingMenu = "prompt";
|
||||
if (promptState.type === "input") {
|
||||
document.getElementById("promptInput").focus();
|
||||
document.getElementById("promptInput").select();
|
||||
}
|
||||
}
|
||||
|
||||
function promptDropdown(title, choices, handler){
|
||||
let pause = false;
|
||||
if (promptState) { pause = promptState.wasPaused }
|
||||
else if (paused) { pause = true }
|
||||
promptState = {
|
||||
type: "dropdown",
|
||||
text: "",
|
||||
choices: choices,
|
||||
handler: handler,
|
||||
title: title || "Choose",
|
||||
wasPaused: pause
|
||||
}
|
||||
showPromptScreen();
|
||||
}
|
||||
|
||||
function makeCurve(pos, w, dir, div = 200){
|
||||
let prevX = pos[0], prevY = pos[1];
|
||||
let res = [];
|
||||
|
|
@ -408,16 +452,15 @@ elements.SeedGenerate = {
|
|||
let arr = [];
|
||||
let txt = shiftDown;
|
||||
Object.keys(biomes).forEach(function(b){arr.push(b);});
|
||||
txt = (arr.length >= 7) ? true : txt;
|
||||
promptInput("Leave blank to generate new seed or C to keep current seed. Your current seed is: " + seed, function(i){
|
||||
seed = (i != null && i.toLowerCase() == "c") ? seed : parseFloat(i) || Math.random()*(2**32);
|
||||
seed = seed % (2**32);
|
||||
if(!txt){
|
||||
promptChoose("", arr, (choice)=>{
|
||||
promptDropdown( "Select a biome to generate: ", arr, (choice)=>{
|
||||
biomes[choice].generate(seed);
|
||||
promptText("World generation complete.");
|
||||
selectElement('dirt');
|
||||
}, "Select a biome to generate: ");
|
||||
});
|
||||
} else {
|
||||
let str = "";
|
||||
for(let key in biomes){
|
||||
|
|
@ -443,7 +486,6 @@ elements.RandomGen = {
|
|||
let arr = [];
|
||||
let txt = shiftDown;
|
||||
Object.keys(biomes).forEach(function(b){arr.push(b);});
|
||||
txt = (arr.length >= 7) ? true : txt;
|
||||
seed = Math.random()*(2**32);
|
||||
//seed %= 2**32;
|
||||
if(txt){
|
||||
|
|
@ -465,10 +507,11 @@ elements.RandomGen = {
|
|||
}, "Enter Biome Name: ");
|
||||
|
||||
} else {
|
||||
promptChoose("", arr, (choice)=>{
|
||||
biomes[choice].generate(seed);
|
||||
selectElement("dirt");
|
||||
}, "Biome Selection");
|
||||
promptDropdown( "Select a biome to generate: ", arr, (choice)=>{
|
||||
biomes[choice].generate(seed);
|
||||
promptText("World generation complete.");
|
||||
selectElement('dirt');
|
||||
});
|
||||
}
|
||||
},
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue