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