Skip to content

Commit

Permalink
Add pause button
Browse files Browse the repository at this point in the history
Based on @tckmn's code
  • Loading branch information
x-sheep authored Sep 1, 2024
1 parent d429708 commit e767781
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 3 deletions.
59 changes: 59 additions & 0 deletions src-ui/css/ui.css
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ h2#title {
background: linear-gradient(to bottom, #99334f, #993366);
}

.btn-warn {
background: yellow;
background: linear-gradient(to bottom, yellow, #cccc00);
}
.btn-warn:active {
background: #999900;
background: linear-gradient(to bottom, #999900, #cccc00);
Expand Down Expand Up @@ -216,6 +220,7 @@ div#auxeditorpanel div.childsel {

/* パズル表示部 */
div#quesboard {
position: relative;
margin: 16pt auto 16pt auto;
text-align: center;
}
Expand Down Expand Up @@ -608,3 +613,57 @@ form#fileform2 {
color: black;
content: "+";
}

div#timertext {
display: inline-block;
padding: 2pt 0;
}
body.paused div#timertext {
animation: pulse 2s ease-in-out infinite;
}
body.paused div#divques {
filter: brightness(0);
opacity: 0.15;
pointer-events: none;
}
body.paused div#btnarea {
opacity: 0.15;
pointer-events: none;
}
button#pausebtn,
button#resumebtn {
float: right;
margin: 0;
}
body.paused button#pausebtn {
display: none;
}
body:not(.paused) button#resumebtn {
display: none;
}
body:not(.paused) div#pauseoverlay {
display: none;
}
div#pauseoverlay {
position: absolute;
top: 20%;
left: 0;
right: 0;
text-align: center;
user-select: none;
}
div#pauseoverlay div.header {
color: blue;
font-size: 2em;
padding-bottom: 0.8em;
}

@keyframes pulse {
0%,
100% {
opacity: 1;
}
50% {
opacity: 0.25;
}
}
2 changes: 1 addition & 1 deletion src-ui/js/ui/Timer.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
//---------------------------------------------------------------------------
init: function() {
this.worstACtime = 0;
this.timerEL = document.getElementById("timerpanel");
this.timerEL = document.getElementById("timertext");
this.showtime(0);
},
start: function() {
Expand Down
9 changes: 9 additions & 0 deletions src-ui/js/ui/ToolArea.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ ui.toolarea = {
this.walkElement(getEL("usepanel"));
this.walkElement(getEL("checkpanel"));
this.walkElement(getEL("variantpanel"));
this.walkElement(getEL("timerpanel"));
this.walkElement(getEL("pauseoverlay"));
this.walkElement(getEL("btnarea"));
}
ui.misc.displayByPid(getEL("checkpanel"));
Expand Down Expand Up @@ -125,6 +127,9 @@ ui.toolarea = {
getEL("separator2").style.display =
hasTimer && ui.menuconfig.get("toolarea") ? "" : "none";
getEL("timerpanel").style.display = hasTimer ? "block" : "none";
getEL("pausedesc").innerText = ui.i18n(
pzpr.env.OS.mobile ? "pause.desc.mobile" : "pause.desc"
);
this.displayVariantPanel();

for (var idname in this.items) {
Expand Down Expand Up @@ -377,5 +382,9 @@ ui.toolarea = {
},
rejectTrial: function() {
ui.puzzle.rejectCurrentTrial();
},

togglePause: function() {
ui.puzzle.togglePause();
}
};
10 changes: 9 additions & 1 deletion src-ui/p.html
Original file line number Diff line number Diff line change
Expand Up @@ -442,11 +442,19 @@ <h2 id="title2">読み込み中です...</h2>
</div>
</div>
<hr class="separator" id="separator2">
<div id="timerpanel">経過時間:00:00</div>
<div id="timerpanel" style="display:none;">
<div id="timertext">経過時間:00:00</div>
<button type="button" class="btn" id="pausebtn" data-button-exec="togglePause">__pause__</button>
<button type="button" class="btn btn-warn" id="resumebtn" data-button-exec="togglePause">__resume__</button>
</div>
</div>

<div id="quesboard">
<div id="divques"></div> <!-- Canvas用 -->
<div id="pauseoverlay">
<div class="header">__pause.header__</div>
<div id="pausedesc">__pause.desc__</div>
</div>
</div>

<div id="btnarea" class="outofboard" style="display:none;"> <!-- Buttons below board下部のボタン -->
Expand Down
5 changes: 5 additions & 0 deletions src-ui/res/p.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@
"variant": "This puzzle uses variant rules",
"time": "Time:",
"timer.menu": "Show timer",
"pause": "Pause",
"pause.header": "Game Paused",
"pause.desc": "Click 'Resume' or press F4",
"pause.desc.mobile": "Press 'Resume' to continue",
"resume": "Resume",
"check": "Check",
"check.variant": "Check base type",
"undo": "<-",
Expand Down
2 changes: 2 additions & 0 deletions src-ui/res/p.ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@
"variant": "変種ルール",
"time": "経過時間:",
"timer.menu": "タイマーを表示",
"pause": "ポーズ",
"resume": "スタート",
"check": "チェック",
"check.variant": "本家ルールでチェック",
"undo": "",
Expand Down
8 changes: 8 additions & 0 deletions src/puzzle/KeyInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,14 @@ pzpr.classmgr.makeCommon({
puzzle.opemgr.updateStarts();
}

if (this.keydown && c === "F4" && puzzle.playeronly) {
puzzle.togglePause();
return;
}
if (puzzle.pausetime !== null) {
return;
}

puzzle.emit("key", c);
if (this.cancelEvent) {
return;
Expand Down
15 changes: 14 additions & 1 deletion src/puzzle/Puzzle.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
instancetype: "", // editpr/player/viewerのいずれか

starttime: 0,
pausetime: null,

canvas: null, // 描画canvas本体
subcanvas: null, // 補助canvas
Expand Down Expand Up @@ -235,7 +236,19 @@
this.starttime = pzpr.util.currentTime();
},
getTime: function() {
return pzpr.util.currentTime() - this.starttime;
return this.pausetime === null
? pzpr.util.currentTime() - this.starttime
: this.pausetime - this.starttime;
},
togglePause: function() {
if (this.pausetime === null) {
document.body.classList.add("paused");
this.pausetime = pzpr.util.currentTime();
} else {
document.body.classList.remove("paused");
this.starttime += pzpr.util.currentTime() - this.pausetime;
this.pausetime = null;
}
},

//---------------------------------------------------------------------------
Expand Down

0 comments on commit e767781

Please sign in to comment.