2018-04-26 00:11:10 +00:00
|
|
|
/**
|
|
|
|
* Script for overlay.ejs
|
|
|
|
*/
|
2017-11-30 08:00:06 +00:00
|
|
|
|
2018-04-06 16:33:20 +00:00
|
|
|
/* Overlay Wrapper Functions */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Toggle the visibility of the overlay.
|
|
|
|
*
|
|
|
|
* @param {boolean} toggleState True to display, false to hide.
|
2018-04-15 02:20:59 +00:00
|
|
|
* @param {boolean} dismissable Optional. True to show the dismiss option, otherwise false.
|
2018-04-25 21:06:10 +00:00
|
|
|
* @param {string} content Optional. The content div to be shown.
|
2018-04-06 16:33:20 +00:00
|
|
|
*/
|
2018-04-25 21:06:10 +00:00
|
|
|
function toggleOverlay(toggleState, dismissable = false, content = 'overlayContent'){
|
2018-04-06 16:33:20 +00:00
|
|
|
if(toggleState == null){
|
|
|
|
toggleState = !document.getElementById('main').hasAttribute('overlay')
|
|
|
|
}
|
2018-04-25 21:06:10 +00:00
|
|
|
if(typeof dismissable === 'string'){
|
|
|
|
content = dismissable
|
2018-05-08 10:34:16 +00:00
|
|
|
dismissable = false
|
2018-04-25 21:06:10 +00:00
|
|
|
}
|
2018-04-06 16:33:20 +00:00
|
|
|
if(toggleState){
|
|
|
|
document.getElementById('main').setAttribute('overlay', true)
|
2018-04-30 02:36:28 +00:00
|
|
|
// Make things untabbable.
|
2018-04-29 22:39:57 +00:00
|
|
|
$("#main *").attr('tabindex', '-1')
|
2018-04-25 21:06:10 +00:00
|
|
|
$('#' + content).parent().children().hide()
|
|
|
|
$('#' + content).show()
|
|
|
|
if(dismissable){
|
|
|
|
$('#overlayDismiss').show()
|
|
|
|
} else {
|
|
|
|
$('#overlayDismiss').hide()
|
|
|
|
}
|
|
|
|
$('#overlayContainer').fadeIn(250)
|
2018-04-06 16:33:20 +00:00
|
|
|
} else {
|
|
|
|
document.getElementById('main').removeAttribute('overlay')
|
2018-04-29 22:39:57 +00:00
|
|
|
// Make things tabbable.
|
|
|
|
$("#main *").removeAttr('tabindex')
|
2018-04-25 21:06:10 +00:00
|
|
|
$('#overlayContainer').fadeOut(250, () => {
|
|
|
|
$('#' + content).parent().children().hide()
|
|
|
|
$('#' + content).show()
|
|
|
|
if(dismissable){
|
|
|
|
$('#overlayDismiss').show()
|
|
|
|
} else {
|
|
|
|
$('#overlayDismiss').hide()
|
|
|
|
}
|
2018-04-15 02:20:59 +00:00
|
|
|
})
|
2018-04-07 17:29:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-27 04:04:09 +00:00
|
|
|
function toggleServerSelection(toggleState){
|
|
|
|
prepareServerSelectionList()
|
|
|
|
toggleOverlay(toggleState, 'serverSelectContent')
|
|
|
|
}
|
|
|
|
|
2018-04-07 17:29:40 +00:00
|
|
|
/**
|
|
|
|
* Set the content of the overlay.
|
|
|
|
*
|
|
|
|
* @param {string} title Overlay title text.
|
|
|
|
* @param {string} description Overlay description text.
|
|
|
|
* @param {string} acknowledge Acknowledge button text.
|
2018-04-15 02:20:59 +00:00
|
|
|
* @param {string} dismiss Dismiss button text.
|
2018-04-07 17:29:40 +00:00
|
|
|
*/
|
2018-04-15 02:20:59 +00:00
|
|
|
function setOverlayContent(title, description, acknowledge, dismiss = 'Dismiss'){
|
2018-04-07 17:29:40 +00:00
|
|
|
document.getElementById('overlayTitle').innerHTML = title
|
|
|
|
document.getElementById('overlayDesc').innerHTML = description
|
|
|
|
document.getElementById('overlayAcknowledge').innerHTML = acknowledge
|
2018-04-15 02:20:59 +00:00
|
|
|
document.getElementById('overlayDismiss').innerHTML = dismiss
|
2018-04-07 17:29:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the onclick handler of the overlay acknowledge button.
|
|
|
|
* If the handler is null, a default handler will be added.
|
|
|
|
*
|
|
|
|
* @param {function} handler
|
|
|
|
*/
|
|
|
|
function setOverlayHandler(handler){
|
|
|
|
if(handler == null){
|
|
|
|
document.getElementById('overlayAcknowledge').onclick = () => {
|
|
|
|
toggleOverlay(false)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
document.getElementById('overlayAcknowledge').onclick = handler
|
2018-04-06 16:33:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-15 02:20:59 +00:00
|
|
|
/**
|
|
|
|
* Set the onclick handler of the overlay dismiss button.
|
|
|
|
* If the handler is null, a default handler will be added.
|
|
|
|
*
|
|
|
|
* @param {function} handler
|
|
|
|
*/
|
|
|
|
function setDismissHandler(handler){
|
|
|
|
if(handler == null){
|
|
|
|
document.getElementById('overlayDismiss').onclick = () => {
|
|
|
|
toggleOverlay(false)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
document.getElementById('overlayDismiss').onclick = handler
|
|
|
|
}
|
2018-04-26 06:39:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Server Select View */
|
|
|
|
|
2018-04-27 04:04:09 +00:00
|
|
|
document.addEventListener('keydown', (e) => {
|
|
|
|
if(document.getElementById('serverSelectContent').style.display !== 'none'){
|
|
|
|
console.debug('ServSelLi Keydown Called:', document.getElementById('serverSelectContent').style.display)
|
|
|
|
if(e.key === 'Escape'){
|
|
|
|
document.getElementById('serverSelectCancel').click()
|
|
|
|
} else if(e.key === 'Enter'){
|
|
|
|
document.getElementById('serverSelectConfirm').click()
|
|
|
|
}
|
2018-05-10 02:23:37 +00:00
|
|
|
} else if(document.getElementById('accountSelectContent').style.display !== 'none'){
|
|
|
|
console.debug('ServSelLi Keydown Called:', document.getElementById('accountSelectContent').style.display)
|
|
|
|
if(e.key === 'Escape'){
|
|
|
|
document.getElementById('accountSelectCancel').click()
|
|
|
|
} else if(e.key === 'Enter'){
|
|
|
|
document.getElementById('accountSelectConfirm').click()
|
|
|
|
}
|
2018-04-27 04:04:09 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2018-04-26 22:41:26 +00:00
|
|
|
document.getElementById('serverSelectConfirm').addEventListener('click', () => {
|
|
|
|
const listings = document.getElementsByClassName('serverListing')
|
|
|
|
for(let i=0; i<listings.length; i++){
|
|
|
|
if(listings[i].hasAttribute('selected')){
|
2018-05-09 00:10:46 +00:00
|
|
|
const serv = AssetGuard.getServerById(listings[i].getAttribute('servid'))
|
2018-04-26 22:41:26 +00:00
|
|
|
ConfigManager.setSelectedServer(serv != null ? serv.id : null)
|
2018-04-27 04:04:09 +00:00
|
|
|
ConfigManager.save()
|
2018-04-26 22:41:26 +00:00
|
|
|
updateSelectedServer(serv != null ? serv.name : null)
|
|
|
|
setLaunchEnabled(serv != null)
|
|
|
|
refreshServerStatus(true)
|
|
|
|
toggleOverlay(false)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// None are selected? Not possible right? Meh, handle it.
|
|
|
|
if(listings.length > 0){
|
|
|
|
ConfigManager.setSelectedServer(listings[0].getAttribute('servid'))
|
2018-05-10 02:23:37 +00:00
|
|
|
ConfigManager.save()
|
2018-04-26 22:41:26 +00:00
|
|
|
updateSelectedServer()
|
|
|
|
toggleOverlay(false)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2018-05-10 02:23:37 +00:00
|
|
|
document.getElementById('accountSelectConfirm').addEventListener('click', () => {
|
|
|
|
const listings = document.getElementsByClassName('accountListing')
|
|
|
|
for(let i=0; i<listings.length; i++){
|
|
|
|
if(listings[i].hasAttribute('selected')){
|
|
|
|
const authAcc = ConfigManager.setSelectedAccount(listings[i].getAttribute('uuid'))
|
|
|
|
ConfigManager.save()
|
|
|
|
updateSelectedAccount(authAcc)
|
|
|
|
toggleOverlay(false)
|
|
|
|
validateSelectedAccount()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// None are selected? Not possible right? Meh, handle it.
|
|
|
|
if(listings.length > 0){
|
|
|
|
const authAcc = ConfigManager.setSelectedAccount(listings[0].getAttribute('uuid'))
|
|
|
|
ConfigManager.save()
|
|
|
|
updateSelectedAccount(authAcc)
|
|
|
|
toggleOverlay(false)
|
|
|
|
validateSelectedAccount()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2018-04-26 06:39:47 +00:00
|
|
|
// Bind server select cancel button.
|
|
|
|
document.getElementById('serverSelectCancel').addEventListener('click', () => {
|
|
|
|
toggleOverlay(false)
|
2018-04-26 22:41:26 +00:00
|
|
|
})
|
|
|
|
|
2018-05-10 02:23:37 +00:00
|
|
|
document.getElementById('accountSelectCancel').addEventListener('click', () => {
|
|
|
|
$('#accountSelectContent').fadeOut(250, () => {
|
|
|
|
$('#overlayContent').fadeIn(250)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-04-26 22:41:26 +00:00
|
|
|
function setServerListingHandlers(){
|
|
|
|
const listings = Array.from(document.getElementsByClassName('serverListing'))
|
|
|
|
listings.map((val) => {
|
|
|
|
val.onclick = e => {
|
|
|
|
if(val.hasAttribute('selected')){
|
|
|
|
return
|
|
|
|
}
|
|
|
|
const cListings = document.getElementsByClassName('serverListing')
|
|
|
|
for(let i=0; i<cListings.length; i++){
|
|
|
|
if(cListings[i].hasAttribute('selected')){
|
|
|
|
cListings[i].removeAttribute('selected')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
val.setAttribute('selected', '')
|
|
|
|
document.activeElement.blur()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2018-04-27 04:04:09 +00:00
|
|
|
|
2018-05-10 02:23:37 +00:00
|
|
|
function setAccountListingHandlers(){
|
|
|
|
const listings = Array.from(document.getElementsByClassName('accountListing'))
|
|
|
|
listings.map((val) => {
|
|
|
|
val.onclick = e => {
|
|
|
|
if(val.hasAttribute('selected')){
|
|
|
|
return
|
|
|
|
}
|
|
|
|
const cListings = document.getElementsByClassName('accountListing')
|
|
|
|
for(let i=0; i<cListings.length; i++){
|
|
|
|
if(cListings[i].hasAttribute('selected')){
|
|
|
|
cListings[i].removeAttribute('selected')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
val.setAttribute('selected', '')
|
|
|
|
document.activeElement.blur()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-04-27 04:04:09 +00:00
|
|
|
function populateServerListings(){
|
2018-05-09 00:10:46 +00:00
|
|
|
const distro = AssetGuard.getDistributionData()
|
2018-04-27 04:04:09 +00:00
|
|
|
const giaSel = ConfigManager.getSelectedServer()
|
|
|
|
const servers = distro.servers
|
|
|
|
let htmlString = ``
|
|
|
|
for(let i=0; i<servers.length; i++){
|
|
|
|
htmlString += `<button class="serverListing" servid="${servers[i].id}" ${servers[i].id === giaSel ? `selected` : ``}>
|
|
|
|
<img class="serverListingImg" src="${servers[i].icon_url}"/>
|
|
|
|
<div class="serverListingDetails">
|
|
|
|
<span class="serverListingName">${servers[i].name}</span>
|
|
|
|
<span class="serverListingDescription">${servers[i].description}</span>
|
|
|
|
<div class="serverListingInfo">
|
|
|
|
<div class="serverListingVersion">${servers[i].mc_version}</div>
|
|
|
|
<div class="serverListingRevision">${servers[i].revision}</div>
|
|
|
|
${servers[i].default_selected ? `<div class="serverListingStarWrapper">
|
|
|
|
<svg id="Layer_1" viewBox="0 0 107.45 104.74" width="20px" height="20px">
|
|
|
|
<defs>
|
|
|
|
<style>.cls-1{fill:#fff;}.cls-2{fill:none;stroke:#fff;stroke-miterlimit:10;}</style>
|
|
|
|
</defs>
|
|
|
|
<path class="cls-1" d="M100.93,65.54C89,62,68.18,55.65,63.54,52.13c2.7-5.23,18.8-19.2,28-27.55C81.36,31.74,63.74,43.87,58.09,45.3c-2.41-5.37-3.61-26.52-4.37-39-.77,12.46-2,33.64-4.36,39-5.7-1.46-23.3-13.57-33.49-20.72,9.26,8.37,25.39,22.36,28,27.55C39.21,55.68,18.47,62,6.52,65.55c12.32-2,33.63-6.06,39.34-4.9-.16,5.87-8.41,26.16-13.11,37.69,6.1-10.89,16.52-30.16,21-33.9,4.5,3.79,14.93,23.09,21,34C70,86.84,61.73,66.48,61.59,60.65,67.36,59.49,88.64,63.52,100.93,65.54Z"/>
|
|
|
|
<circle class="cls-2" cx="53.73" cy="53.9" r="38"/>
|
|
|
|
</svg>
|
|
|
|
<span class="serverListingStarTooltip">Main Server</span>
|
|
|
|
</div>` : ``}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</button>`
|
|
|
|
}
|
|
|
|
document.getElementById('serverSelectListScrollable').innerHTML = htmlString
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-05-10 02:23:37 +00:00
|
|
|
function populateAccountListings(){
|
|
|
|
const accountsObj = ConfigManager.getAuthAccounts()
|
|
|
|
const accounts = Array.from(Object.keys(accountsObj), v=>accountsObj[v]);
|
|
|
|
let htmlString = ``
|
|
|
|
for(let i=0; i<accounts.length; i++){
|
|
|
|
htmlString += `<button class="accountListing" uuid="${accounts[i].uuid}" ${i===0 ? 'selected' : ''}>
|
|
|
|
<img src="https://crafatar.com/renders/head/${accounts[i].uuid}?scale=2&default=MHF_Steve&overlay">
|
|
|
|
<div class="accountListingName">${accounts[i].displayName}</div>
|
|
|
|
</button>`
|
|
|
|
}
|
|
|
|
document.getElementById('accountSelectListScrollable').innerHTML = htmlString
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-04-27 04:04:09 +00:00
|
|
|
function prepareServerSelectionList(){
|
|
|
|
populateServerListings()
|
|
|
|
setServerListingHandlers()
|
2018-05-10 02:23:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function prepareAccountSelectionList(){
|
|
|
|
populateAccountListings()
|
|
|
|
setAccountListingHandlers()
|
2018-04-27 04:04:09 +00:00
|
|
|
}
|