-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathpauseScreen.html
More file actions
210 lines (196 loc) · 8.63 KB
/
pauseScreen.html
File metadata and controls
210 lines (196 loc) · 8.63 KB
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<!DOCTYPE html>
</form>
<script type="text/javascript">
//ONLOAD
loadplaylist();
loadButtons();
function loadplaylist(){
//console.log("Mytab | loading playlists");
let addhtml = '<option value=""></option> ';
for(let i = 0; i<game.playlists.size; i++){
addhtml += '<option value="'+game.playlists._source[i]._id+'">'+game.playlists._source[i].name+'</option>'
}
document.getElementById("pausePlaylistTrack").innerHTML = addhtml;
}
function loadButtons() {
if (game.settings.get('mytab', 'timePresets') != "") {
let timePresets = game.settings.get('mytab', 'timePresets').split(',');
for (i = 0; i < timePresets.length; i++) {
console.log("Button should appear");
let timetext, minText, secText = "";
minText = "";
if (timePresets[i] >= 60) {//check for Minutes
var minutes = timePresets[i] - (3600 * (Math.floor(timePresets[i] / 3600)));
var minutes = Math.floor(minutes / 60);
minText = "" + minutes + "m ";
}
else {
secText = "" + timePresets[1] + "s ";
}
timetext = minText + secText;
$(".quickbuttons").append('<button type="button" id="quickbutton" onclick="pausefunction(' + timePresets[i] + ')">' +timetext+'</button>')
}
}
}
</script>
<div pausecontainer style="display: flex;">
<div quickbuttons class="quickbuttons" style="margin-right: 10px;width: 150px;">
</div>
<div pausetimer>
<div class="window-resizable-handle"><i class="fas fa-arrows-alt-h"></i></div>
<div class="flexrow form-group" style="margin-bottom:10px;">
<input type="text" id="pauseTextInput" style="flex:1;" placeholder="(Standard Text)" value="{{standardText}}" onchange="saveScreenPrefs()"> <label style="flex:1;text-align-last: center;align-self: center;">Pause Text</label>
</div>
<div class="flexrow form-group" style="margin-bottom:10px;">
<select name="pausePlaylistTrack" id="pausePlaylistTrack" style="flex:1;">
</select> <label style="flex:1;text-align-last: center;align-self: center;">Choose a playlist</label>
</div>
<div class="flexrow form-group" style="margin-bottom:10px;align-items: center;text-align: center;">
<input type="number" id="pausehours" style="flex:1;margin-right:5px;" value="{{standardHours}}" onchange="saveScreenPrefs()"> Hours
<input type="number" id="pauseminutes" style="flex:1;margin-left: 10px;margin-right:5px;" value="{{standardMin}}" onchange="saveScreenPrefs()"> Minutes
<input type="number" id="pauseseconds" style="flex:1;margin-left: 10px;margin-right:5px;" value="{{standardSec}}" onchange="saveScreenPrefs()"> Seconds
</div>
</div>
</div>
<button type="button" id="pausegameButton" onclick="pausefunction(0)" data-action="none"> Pause Game </button>
<script>
function saveScreenPrefs() {
game.settings.set('mytab', 'lastPauseScreenText', document.getElementById("pauseTextInput").value);
let timeText = "" + document.getElementById("pausehours").value + "," + document.getElementById("pauseminutes").value + "," + document.getElementById("pauseseconds").value;
game.settings.set('mytab', 'lastPauseScreenTime', timeText);
return;
}
function pausefunction(time) {
if (game.settings.get('mytab', 'i_pausetime') > 0 && game.paused) {
ui.notifications.warn("MyTab | You can't start another countdown while one is already running, press Space to stop the current timer/pause");
if (document.getElementById("pausegameButton") != null)
document.getElementById("pausegameButton").disabled = true;
return;
}
let playingsonglistindex;
let pauseText = document.getElementById("pauseTextInput").value;
game.settings.set('mytab', 's_pText', "");
console.log("MyTab | Pause Started");
var timeleft = 0;
if (time == 0) {
if (document.getElementById("pauseseconds").value != "") {
timeleft += parseFloat(document.getElementById("pauseseconds").value);
}
if (document.getElementById("pauseminutes").value != "") {
timeleft += parseFloat(document.getElementById("pauseminutes").value) * 60;
}
if (document.getElementById("pausehours").value != "") {
timeleft += parseFloat(document.getElementById("pausehours").value) * 3600;
}
}
else {
timeleft = time;
}
game.togglePause(true, true)
let hourText, minText, secText;
let hourVal, minVal, secVal;
let once = false;
game.settings.set('mytab', 's_pText', pauseText)
var downloadTimer = setInterval(function(){
if(once == false){
document.getElementsByClassName("PauseTextContainer")[0].innerHTML = '';
for (var i = 0; i < pauseText.length; i++) {
let textI = document.createElement("h3");
textI.id = "pauseScreenText";
textI.innerHTML = pauseText[i];
if(pauseText[i] == " "){
textI.style="margin: 3px;"
}
else{
textI.style="--i:"+[i];
}
document.getElementsByClassName("PauseTextContainer")[0].append(textI);
//document.getElementsByClassName("PauseTextContainer")[0].innerHTML += pscreenText[i];
}
once = true;
}
if(!game.paused){
console.log("MyTab | Game is no longer paused");
timeleft = 0;
if (game.user.isGM) ui.notifications.notify("MyTab | Pause timer stopped");
if (document.getElementById("pausegameButton") != null)
document.getElementById("pausegameButton").disabled = false;
if(playingsonglistindex != undefined){
let playlistsong = playingsonglistindex -1 ;
game.playlists.find(track => track.data.name === game.playlists._source[playlistsong].name).stopAll()
game.togglePause(false, true);
playingsonglistindex == null;
}
game.settings.set('mytab', 's_pText', "");
clearInterval(downloadTimer);
}
if (timeleft <= 0) {
game.settings.set('mytab', 'i_pausetime', 0);
game.settings.set('mytab', 's_pText', "");
if (document.getElementById("countdown") == null) return;
document.getElementById("countdown").innerHTML != ""
clearInterval(downloadTimer);
game.togglePause(false, true);
game.settings.set('mytab', 's_pText', "");
if(playingsonglistindex != undefined){
let playlistsong = playingsonglistindex -1 ;
game.playlists.find(track => track.data.name === game.playlists._source[playlistsong].name).stopAll()
playingsonglistindex == null;
}
if (game.modules.get('ready-check')?.active === true && game.settings.get('mytab', 'ready-check-integration')) {
$(".crash-ready-check-sidebar").click()
}
return;
}
else{
if(timeleft >= 3600){//check for Hours
hourText = ""+Math.floor(timeleft / 3600)+"h | ";
}
else{
hourText = ""
}
if(timeleft >= 60){//check for Minutes
var minutes = timeleft - (3600 * (Math.floor(timeleft / 3600)));
var minutes = Math.floor(minutes / 60);
minText = ""+minutes+"m | ";
}
else{
minText = ""
}
if(timeleft <= 5){// fade out if less then 5 seconds remaining
//if(playingsonglistindex != undefined){
/*
let playlistsong = playingsonglistindex -1 ;
for(let i = 0; i < game.playlists.find(track => track.data.name === game.playlists._source[playlistsong].name).data.sounds.length; i++){
let savedSongVolume = [];
if(game.playlists.find(track => track.data.name === game.playlists._source[playlistsong].name).data.sounds[i].playing){
savedSongVolume[i] = game.playlists.find(track => track.data.name === game.playlists._source[playlistsong].name).data.sounds[i].volume;
game.playlists.find(track => track.data.name === game.playlists._source[playlistsong].name).data.sounds[i].volume = savedSongVolume[i] - (savedSongVolume[i] / timeleft);
}
}
game.playlists.find(track => track.data.name === game.playlists._source[playlistsong].name).data.sounds
game.playlists.playing[0]._data.sounds[0].playing
*/
AudioHelper.play({src: game.settings.get('mytab', 'pauseSFX'), volume:1, autoplay: true, loop: false}, true);
// }
}
if(timeleft >= 1){//check for seconds
var seconds = timeleft - (3600 * (Math.floor(timeleft / 3600)));
var seconds = timeleft - (60 * (Math.floor(timeleft / 60)));
secText = ""+seconds + " s";
}
let pausetime = ""+hourText + minText + secText;
game.settings.set('mytab', 'pausetime', pausetime)
}
timeleft -= 1;
console.log("MyTab | Pause time left: " + timeleft + "s");
game.settings.set('mytab', 'i_pausetime', timeleft);
}, 1000);
//Play playlist
if(document.getElementById("pausePlaylistTrack").options.selectedIndex != 0 && playingsonglistindex == null){
playingsonglistindex = document.getElementById("pausePlaylistTrack").options.selectedIndex;
game.playlists.find(track => track.data.name === document.getElementById("pausePlaylistTrack").options[playingsonglistindex].innerHTML).playAll()
}
}
</script>
</html>