-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogramcontrols.js
156 lines (126 loc) · 4.92 KB
/
programcontrols.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
//GŁÓWNA FUNKCJA BUDUJĄCA STEROWANIE Z TABELEK
function elementControlContainer() {
const container = document.createElement('div');
container.id = 'elementControlContainer';
Object.keys(window.soundControl).forEach((controlType) => {
const controlSubContainer = document.createElement('div');
controlSubContainer.classList.add('control-subContainer');
controlSubContainer.id = controlType;
Object.keys(window.soundControl[controlType]).forEach((option) => {
const checkboxId = `${controlType}-${option}`;
// Create div and checkbox
const controlButton = document.createElement('div');
const checkbox = document.createElement('input');
checkbox.type = 'checkbox';
checkbox.classList.add('control-checkbox');
checkbox.dataset.group = controlType;
checkbox.dataset.option = option;
checkbox.checked = window.soundControl[controlType][option] === 1; // Set initial state
checkbox.id = checkboxId;
controlButton.innerHTML = `<label for="${checkboxId}" class="control-button-label">${window.controlIcons[controlType][option]}</label>`;
controlButton.classList.add('control-button');
controlButton.prepend(checkbox);
controlButton.addEventListener('click', (event) => {
if (event.target !== checkbox && event.target.tagName !== 'LABEL') {
event.preventDefault();
checkbox.checked = !checkbox.checked; // Toggle checkbox state
}
window.soundControl[controlType][option] = checkbox.checked ? 1 : 0;
// Ensure at least one checkbox remains selected in the group
const groupCheckboxes = Array.from(
document.querySelectorAll(`input[data-group="${controlType}"]`)
);
const selectedCount = groupCheckboxes.filter((cb) => cb.checked).length;
if (selectedCount === 0) {
// GDY ZOSTAŁ JEDEN
checkbox.checked = true;
window.soundControl[controlType][option] = 1;
}
// console.log(`${option} toggled to:`, checkbox.checked);
// console.log('Current group state:', window.soundControl[controlType]);
});
controlSubContainer.appendChild(controlButton);
});
container.appendChild(controlSubContainer);
});
return container;
}
//DEZAKTYWACJA PRZYCISKÓW (ODZNACZENIE)
function disableElementCSS(container) {
// Disable interaction visually
container.style.pointerEvents = 'none';
container.style.opacity = '0.5';
const inputs = container.querySelectorAll('input');
inputs.forEach((input) => {
input.setAttribute('disabled', 'true');
});
}
//REAKTYWACJA PRZYCISKÓW
function enableElementCSS(container) {
container.style.pointerEvents = '';
container.style.opacity = '1';
const inputs = container.querySelectorAll('input');
inputs.forEach((input) => {
input.removeAttribute('disabled');
});
}
//MAKSYMALNA ILOŚĆ BŁĘDÓW
function elementMaxError(init) {
const container = document.createElement('div');
container.id = 'elementMaxError';
const maxErrorLabel = document.createElement('label');
maxErrorLabel.textContent = '\u274c';
maxErrorLabel.className = 'control-subContainer-label';
maxErrorLabel.setAttribute('for', 'maxErrorSelect');
container.appendChild(maxErrorLabel);
//dropdown
const select = document.createElement('select');
select.id = 'maxErrorSelect';
select.className = 'dropdown-select';
//wybory
['0', '1', '2', '3', '4'].forEach((labelText, i) => {
const option = document.createElement('option');
option.value = i;
option.textContent = labelText;
if (i === init) option.selected = true;
select.appendChild(option);
});
//logika
select.addEventListener('change', () => {
window.maxError = select.value;
window.refreshCharts();
});
container.appendChild(select);
window.maxError = init;
return container;
}
//GŁOŚNOŚĆ DŹWIĘKU
function elementSoundVolume(init) {
const container = document.createElement('div');
container.id = 'elementSoundVolume';
//etykieta
const soundVolumeLabel = document.createElement('label');
soundVolumeLabel.innerHTML = `<img id="svg-icon-speaker" src="../svg/speaker.svg" alt="Głośność" />`;
soundVolumeLabel.className = 'control-subContainer-label';
soundVolumeLabel.setAttribute('for', 'soundVolumeSelect');
container.appendChild(soundVolumeLabel);
//dropdown
const select = document.createElement('select');
select.id = 'soundVolumeSelect';
select.className = 'dropdown';
//wybory
['20%', '40%', '60%', '80%', '100%'].forEach((labelText, i) => {
const option = document.createElement('option');
option.value = (i + 1) * 20; //numer
option.textContent = labelText; //tekst
if ((i + 1) * 20 === init) option.selected = true;
select.appendChild(option);
});
container.appendChild(select);
//logika
select.addEventListener('change', () => {
window.soundVolume = select.value;
});
window.soundVolume = init;
return container;
}