class PopOutManagerPanelElement extends UIElement { constructor() { super(...arguments); this.ingameUi = null; this.isInitialized = false; this.panelActive = false; this.webSocket = null; this.webSocketConnected = false; this.webSocketInterval = null; this.tryConnectWebSocket = () => { this.lockPanel(true); this.webSocket = new WebSocket("ws://localhost:27011/ws"); this.webSocket.onopen = () => { clearInterval(this.webSocketInterval); this.webSocketConnected = true; }; this.webSocket.onclose = () => { this.webSocketConnected = false; // Clear panel table this.createPanelConfigTableHeader(this.panelConfigTable); this.lockPanel(true); this.webSocketInterval = setInterval(() => { if (!this.webSocketConnected) this.tryConnectWebSocket(); }, 2000) }; this.webSocket.onerror = () => { this.webSocket.close(); }; this.webSocket.onmessage = (event) => { if (event.data !== undefined) { var panelData = JSON.parse(event.data); // only recreate panel rows if panel is refreshed (minimize/maximize, pop out) if (this.panelActive && document.getElementsByClassName("panelRow").length == 1) this.createPanelConfigTableBody(this.panelConfigTable, panelData); if (panelData !== undefined && panelData !== null && panelData.length !== 0) { this.lockPanel(false); this.bindPanelData(panelData); } } }; } this.webSocketInterval = setInterval(() => { if (!this.webSocketConnected) this.tryConnectWebSocket(); }, 2000) } connectedCallback() { super.connectedCallback(); this.ingameUi = this.querySelector('ingame-ui'); this.panelSelection = document.getElementById("panelSelection"); this.panelConfiguration = document.getElementById("panelConfiguration"); this.planeProfileName = document.getElementById("planeProfileName"); this.panelConfigTable = document.getElementById("panelConfigTable"); this.btnLockPanels = this.querySelector('#btnLockPanels'); this.btnPlusTen = this.querySelector('#btnPlusTen'); this.btnPlusOne = this.querySelector('#btnPlusOne'); this.btnMinusTen = this.querySelector('#btnMinusTen'); this.btnMinusOne = this.querySelector('#btnMinusOne'); this.dropdownProfile = this.querySelector("#dropdownProfile"); this.addProfile = document.getElementById("addProfile"); this.deleteProfile = document.getElementById("deleteProfile"); this.stepBeginDialog = document.getElementById("stepBeginDialog"); this.closeDialog = document.getElementById("closeDialog"); //this.deleteProfile.disable(!this.deleteProfile.disabled); //this.dropdownProfile.addEventListener("select", (event) = {}); let workflow = new Workflow(this); workflow.bindAllButtonEvents(); workflow.stepBegin(); this.addProfile.addEventListener("click", (event) => { addProfileDialog.style.display = "block"; //this.ingameUi.toggleExternPanel(true); document.body.classList.toggle('modal-open'); // let value = new DataValue; // value.name = "New Profile " + dropDownValues.length; // value.ID = dropDownValues.length; // dropDownValues.push(value); // this.dropdownProfile.setData(dropDownValues, dropDownValues.length - 1); }); this.deleteProfile.addEventListener("click", (event) => { // dropDownValues.splice(-1,1); // this.dropdownProfile.setData(dropDownValues, dropDownValues.length - 1); }); this.isLocked = false; let profiles = ["Kodiak", "172", "737"]; let dropDownValues = []; profiles.forEach((profile, index) => { let value = new DataValue; value.name = profile; value.ID = index; dropDownValues.push(value); }); setTimeout(() => { this.dropdownProfile.setData(dropDownValues, 2) }, 1000); this.btnLockPanels.addEventListener("click", () => { if (this.btnLockPanels.disabled) return; this.isLocked = !this.isLocked; this.lockPanel(this.isLocked); if (this.isLocked) { this.btnLockPanels.disabled = false; this.btnLockPanels.title = "Unlock Panels"; this.btnLockPanels.style.backgroundColor = "red"; } else { this.btnLockPanels.disabled = false; this.btnLockPanels.title = "Lock Panels"; this.btnLockPanels.style.backgroundColor = null; } this.panelSelection.style.display = 'block'; this.panelConfiguration.style.display = 'none'; }); if (this.ingameUi) { this.ingameUi.addEventListener("panelActive", (e) => { //document.getElementsByClassName("Extern")[0].style.display = "none"; // disable extern button this.createPanelConfigTableHeader(this.panelConfigTable); this.panelActive = true; this.lockPanel(true); if (this.webSocketConnected) this.webSocket.send("RequestPanelData"); }); } } createPanelConfigTableHeader(panelConfigTable) { let panelRow; // remove all child of panelConfigTable while (panelConfigTable.firstChild) { panelConfigTable.removeChild(panelConfigTable.firstChild); } // create header panelRow = this.createPanelRow(true); panelRow.appendChild(this.createPanelCell("div", "column1", "Panel Name")); panelRow.appendChild(this.createPanelCell("div", "column2", "X-Pos")); panelRow.appendChild(this.createPanelCell("div", "column3", "Y-Pos")); panelRow.appendChild(this.createPanelCell("div", "column4", "Width")); panelRow.appendChild(this.createPanelCell("div", "column5", "Height")); panelRow.appendChild(this.createPanelCell("div", "column6", "Always on Top")); panelRow.appendChild(this.createPanelCell("div", "column7", "Hide Title Bar")); panelRow.appendChild(this.createPanelCell("div", "column8", "Full Screen Mode")); panelRow.appendChild(this.createPanelCell("div", "column9", "Touch Enabled")); panelConfigTable.appendChild(panelRow); } createPanelConfigTableBody(panelConfigTable, panelData) { let panelRow; if (panelConfigTable !== undefined) { for (let index = 0; index < panelData.length; index++) { panelRow = this.createPanelRow(false); panelRow.appendChild(this.createPanelCell("div", "column1", this.createUiInput("PanelName_" + index))); panelRow.appendChild(this.createPanelCell("div", "column2", this.createUiInput("XPos_" + index))); panelRow.appendChild(this.createPanelCell("div", "column3", this.createUiInput("YPos_" + index))); panelRow.appendChild(this.createPanelCell("div", "column4", this.createUiInput("Width_" + index))); panelRow.appendChild(this.createPanelCell("div", "column5", this.createUiInput("Height_" + index))); panelRow.appendChild(this.createPanelCell("div", "column6", this.createCheckbox("AlwaysOnTop_" + index))); panelRow.appendChild(this.createPanelCell("div", "column7", this.createCheckbox("HideTitleBar_" + index))); panelRow.appendChild(this.createPanelCell("div", "column8", this.createCheckbox("FullScreenMode_" + index))); panelRow.appendChild(this.createPanelCell("div", "column9", this.createCheckbox("TouchEnabled_" + index))); panelConfigTable.appendChild(panelRow); } } } createPanelRow(isHeaderRow) { let panelRow = document.createElement("div"); if (isHeaderRow) panelRow.classList.add("panelHeaderRow"); panelRow.classList.add("panelRow"); return panelRow; } createPanelCell(cellType, classes = null, childElement) { let cell = document.createElement(cellType); cell.classList.add("panelCell"); if (classes !== undefined || classes !== null) { if (typeof (classes) === "string") { cell.classList.add(classes); } else { for (let index = 0; index < classes.length; index++) cell.classList.add(classes[index]); } } if (typeof (childElement) === "string") cell.innerHTML = `