Skip to content

Commit

Permalink
web client: listen for double-click events on ground in game window...
Browse files Browse the repository at this point in the history
Related issues:
- #298
- #254
  • Loading branch information
AntumDeluge committed Dec 24, 2019
1 parent b9888f2 commit d059b6e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
7 changes: 6 additions & 1 deletion srcjs/stendhal/entity/ground.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,19 @@ stendhal.zone.ground = {
return "url(/data/sprites/cursor/walk.png) 1 3, auto";
},

onclick: function(x, y) {
onclick: function(x, y, dblclick) {
var gameX = x + stendhal.ui.gamewindow.offsetX;
var gameY = y + stendhal.ui.gamewindow.offsetY;
var action = {
"type": "moveto",
"x": "" + Math.floor(gameX / 32),
"y": "" + Math.floor(gameY / 32)
};

if (typeof dblclick == "boolean" && dblclick) {
action["double_click"] = "";
}

var extend = this.calculateZoneChangeDirection(gameX, gameY);
if (extend) {
action.extend = extend;
Expand Down
1 change: 1 addition & 0 deletions srcjs/stendhal/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ stendhal.main = {
var gamewindow = document.getElementById("gamewindow");
gamewindow.setAttribute("draggable", true);
gamewindow.addEventListener("mousedown", stendhal.ui.gamewindow.onMouseDown);
gamewindow.addEventListener("dblclick", stendhal.ui.gamewindow.onMouseDown);
gamewindow.addEventListener("mousemove", stendhal.ui.gamewindow.onMouseMove);
gamewindow.addEventListener("dragstart", stendhal.ui.gamewindow.onDragStart);
gamewindow.addEventListener("dragover", stendhal.ui.gamewindow.onDragOver);
Expand Down
9 changes: 7 additions & 2 deletions srcjs/stendhal/ui/gamewindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,20 @@ stendhal.ui.gamewindow = {
stendhal.ui.globalpopup.close();
}

e.target.addEventListener("mousemove", onDrag);
e.target.addEventListener("mouseup", onMouseUp);
startX = e.offsetX;
startY = e.offsetY;

var x = e.offsetX + stendhal.ui.gamewindow.offsetX;
var y = e.offsetY + stendhal.ui.gamewindow.offsetY;
entity = stendhal.zone.entityAt(x, y);
timestampMouseDown = +new Date();

if (e.type !== "dblclick") {
e.target.addEventListener("mousemove", onDrag);
e.target.addEventListener("mouseup", onMouseUp);
} else if (entity == stendhal.zone.ground) {
entity.onclick(e.offsetX, e.offsetY, true);
}
}

function isRightClick(e) {
Expand Down

0 comments on commit d059b6e

Please sign in to comment.