Skip to content

Commit 06bce4a

Browse files
committed
Auto-hide cursor in certain input modes
1 parent 3012e9c commit 06bce4a

9 files changed

Lines changed: 77 additions & 28 deletions

File tree

src/puzzle/KeyInput.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ pzpr.classmgr.makeCommon({
193193
// kc.inputKeys() キーボードイベントを実行する
194194
//---------------------------------------------------------------------------
195195
inputKeys: function(array) {
196+
this.cursor.isActive = true;
196197
for (var i = 0; i < arguments.length; i++) {
197198
var ca = arguments[i];
198199

@@ -257,6 +258,12 @@ pzpr.classmgr.makeCommon({
257258
if (!this.isenablemode()) {
258259
return;
259260
}
261+
if (this.keydown && !this.cursor.isActive) {
262+
this.cursor.isActive = true;
263+
this.cancelDefault = true;
264+
this.cursor.draw();
265+
return;
266+
}
260267
if (this.keydown && this.moveTarget(c)) {
261268
this.cancelDefault = true;
262269
return;
@@ -456,6 +463,7 @@ pzpr.classmgr.makeCommon({
456463
} else if (this.disableAnum && this.puzzle.playmode) {
457464
this.targetdir = 5;
458465
}
466+
this.isActive = !this.puzzle.playeronly;
459467
},
460468
init: function(bx, by) {
461469
this.bx = bx;
@@ -480,6 +488,7 @@ pzpr.classmgr.makeCommon({
480488
maxy: null,
481489

482490
crosstype: false,
491+
isActive: true,
483492

484493
//---------------------------------------------------------------------------
485494
// tc.initCursor() 初期化時にカーソルの位置を設定する

src/puzzle/MouseInput.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,11 +443,28 @@ pzpr.classmgr.makeCommon({
443443
) {
444444
this.inputMode = mode;
445445
this.savedInputMode[this.puzzle.editmode ? "edit" : "play"] = mode;
446+
this.autohide_cursor();
446447
this.puzzle.redraw();
447448
} else {
448449
throw Error("Invalid input mode: " + mode);
449450
}
450451
},
452+
autohide_cursor: function() {
453+
if (
454+
this.inputMode.startsWith("number") ||
455+
this.inputMode.startsWith("letter")
456+
) {
457+
this.cursor.isActive = true;
458+
} else if (this.inputMode !== "auto") {
459+
this.cursor.isActive = false;
460+
} else if (this.puzzle.editmode) {
461+
this.cursor.isActive = true;
462+
} else if (this.cursor.disableAnum) {
463+
this.cursor.isActive = false;
464+
}
465+
466+
this.cursor.draw();
467+
},
451468
getInputModeList: function(type) {
452469
if (this.puzzle.instancetype === "viewer") {
453470
return [];
@@ -611,12 +628,14 @@ pzpr.classmgr.makeCommon({
611628
setcursor: function(pos) {
612629
var pos0 = this.cursor.getaddr();
613630
this.cursor.setaddr(pos);
631+
this.cursor.isActive = true;
614632
pos0.draw();
615633
pos.draw();
616634
},
617635
setcursorsnum: function(pos) {
618636
var pos0 = this.cursor.getaddr();
619637
this.cursor.setaddr(pos);
638+
this.cursor.isActive = true;
620639
var target;
621640
var bx = this.inputPoint.bx,
622641
by = this.inputPoint.by;

src/puzzle/Puzzle.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,9 +357,10 @@
357357
this.playmode = !this.editmode;
358358

359359
if (!!this.klass) {
360-
this.cursor.adjust_modechange();
361360
this.key.keyreset();
362361
this.mouse.modechange();
362+
this.cursor.adjust_modechange();
363+
this.mouse.autohide_cursor();
363364
this.board.errclear();
364365
this.redraw();
365366
}

src/variety-common/Graphic.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2065,12 +2065,16 @@ pzpr.classmgr.makeCommon({
20652065
},
20662066

20672067
drawCursor: function(islarge, isdraw) {
2068+
if (isdraw !== false) {
2069+
isdraw = this.puzzle.getConfig("cursor") && this.puzzle.cursor.isActive;
2070+
}
2071+
20682072
this.drawRawCursor(
20692073
"target_cursor",
20702074
"",
20712075
this.puzzle.cursor,
20722076
islarge,
2073-
isdraw !== false && this.puzzle.getConfig("cursor"),
2077+
isdraw,
20742078
this.puzzle.editmode ? this.targetColorEdit : this.targetColorPlay
20752079
);
20762080
},
@@ -2177,10 +2181,7 @@ pzpr.classmgr.makeCommon({
21772181
var target = cursor.targetdir;
21782182
var cell = cursor.getc();
21792183

2180-
if (
2181-
cursor.disableAnum &&
2182-
this.puzzle.mouse.inputMode.indexOf("number") === -1
2183-
) {
2184+
if (!cursor.isActive) {
21842185
target = 0;
21852186
}
21862187

src/variety-common/MouseInput.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ pzpr.classmgr.makeCommon({
5151
cell.setQsub(this.inputData === unshade ? 1 : 0);
5252

5353
cell.draw();
54+
55+
if (this.cursor.isActive) {
56+
this.cursor.isActive = false;
57+
this.cursor.draw();
58+
}
5459
},
5560
initFirstCell: function(cell) {
5661
if (!this.firstCell.isnull) {
@@ -136,7 +141,7 @@ pzpr.classmgr.makeCommon({
136141
cell.noNum()
137142
) {
138143
this.setcursorsnum(cell);
139-
} else if (cell !== this.cursor.getc()) {
144+
} else if (cell !== this.cursor.getc() || !this.cursor.isActive) {
140145
this.setcursor(cell);
141146
} else {
142147
this.inputqnum_main(cell);
@@ -677,6 +682,11 @@ pzpr.classmgr.makeCommon({
677682
border.removeBorder();
678683
}
679684
border.draw();
685+
686+
if (this.cursor.isActive) {
687+
this.cursor.isActive = false;
688+
this.cursor.draw();
689+
}
680690
}
681691
this.prevPos = pos;
682692
},
@@ -697,6 +707,11 @@ pzpr.classmgr.makeCommon({
697707
border.setQsub(0);
698708
}
699709
border.draw();
710+
711+
if (this.cursor.isActive) {
712+
this.cursor.isActive = false;
713+
this.cursor.draw();
714+
}
700715
}
701716
this.prevPos = pos;
702717
},
@@ -740,6 +755,11 @@ pzpr.classmgr.makeCommon({
740755
border.removeLine();
741756
}
742757
border.draw();
758+
759+
if (this.cursor.isActive) {
760+
this.cursor.isActive = false;
761+
this.cursor.draw();
762+
}
743763
}
744764
this.prevPos = pos;
745765
},

src/variety/snakeegg.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,15 @@
6363
}
6464
},
6565
"MouseEvent@meidjuluk": {
66-
autoplay_func: "border",
6766
inputModes: {
6867
edit: ["number", "empty", "clear"],
6968
play: ["number", "border", "subline"]
69+
},
70+
mouseinputAutoPlay: function() {
71+
this.mouseinputAutoPlay_border();
72+
if (this.mouseend && this.notInputted()) {
73+
this.inputqnum();
74+
}
7075
}
7176
},
7277

@@ -450,7 +455,11 @@
450455
this.drawChassis();
451456

452457
this.drawBank();
453-
this.drawTarget();
458+
if (this.pid === "meidjuluk") {
459+
this.drawCursor();
460+
} else {
461+
this.drawTarget();
462+
}
454463
},
455464

456465
getNumberTextCore: function(num) {
@@ -480,14 +489,6 @@
480489
g.fillStyle = this.getBankPieceColor(piece);
481490
var str = piece.num >= 0 ? "" + piece.num : "";
482491
this.disptext(str, x, y, { ratio: 0.65 });
483-
},
484-
485-
drawTarget: function() {
486-
this.drawCursor(
487-
true,
488-
this.puzzle.editmode ||
489-
this.puzzle.mouse.inputMode.indexOf("number") >= 0
490-
);
491492
}
492493
},
493494
"Graphic@meidjuluk": {

src/variety/tachibk.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@
2828
},
2929

3030
autoedit_func: "qnum",
31-
autoplay_func: "border"
31+
32+
mouseinputAutoPlay: function() {
33+
this.mouseinputAutoPlay_border();
34+
if (this.mouseend && this.notInputted()) {
35+
this.inputqnum();
36+
}
37+
}
3238
},
3339
KeyEvent: {
3440
enablemake: true,
@@ -194,15 +200,7 @@
194200
this.drawQuesNumbers();
195201
this.drawSubNumbers(true);
196202

197-
this.drawTarget();
198-
},
199-
200-
drawTarget: function() {
201-
this.drawCursor(
202-
true,
203-
this.puzzle.editmode ||
204-
this.puzzle.mouse.inputMode.indexOf("number") >= 0
205-
);
203+
this.drawCursor();
206204
},
207205

208206
fontsizeratio: 0.75,

src/variety/yokeimoji.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@
7474
var consonant =
7575
cell.qchar === 0 ? "" : String.fromCharCode(97 + cell.qchar);
7676

77-
// TODO: Support alias of multiple letters
7877
if (ca === "enter") {
7978
this.cursor.toggleDir();
8079
} else if (ca === "BS") {

test/puzzle/input_test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ var pzpr = require("../../dist/js/pzpr.js");
77
var testdata = require("../load_testdata.js");
88

99
function execmouse(puzzle, strs) {
10+
puzzle.cursor.isActive = true;
1011
var buttons = strs[1].split("+");
1112
var button = buttons[buttons.length - 1];
1213

0 commit comments

Comments
 (0)