Skip to content

Commit

Permalink
Re-instate action context menu for entities in viewport
Browse files Browse the repository at this point in the history
Closes: #459
  • Loading branch information
AntumDeluge committed Nov 25, 2023
1 parent 0a53a1a commit dd0d8ff
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions srcjs/stendhal/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ export class Client {
gamewindow.addEventListener("dblclick", stendhal.ui.gamewindow.onMouseDown);
gamewindow.addEventListener("dragstart", stendhal.ui.gamewindow.onDragStart);
gamewindow.addEventListener("mousemove", stendhal.ui.gamewindow.onMouseMove);
gamewindow.addEventListener("touchstart", stendhal.ui.gamewindow.onMouseDown);
gamewindow.addEventListener("touchend", stendhal.ui.gamewindow.onTouchEnd);
gamewindow.addEventListener("dragover", stendhal.ui.gamewindow.onDragOver);
gamewindow.addEventListener("drop", stendhal.ui.gamewindow.onDrop);
Expand Down
20 changes: 17 additions & 3 deletions srcjs/stendhal/ui/ViewPort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,10 @@ export class ViewPort {

const mHandle: any = {};

mHandle._onMouseDown = function(e: MouseEvent) {
mHandle._onMouseDown = function(e: MouseEvent|TouchEvent) {
if (e instanceof TouchEvent) {
stendhal.ui.touch.onTouchStart();
}
var pos = stendhal.ui.html.extractPosition(e);
if (stendhal.ui.globalpopup) {
stendhal.ui.globalpopup.close();
Expand Down Expand Up @@ -349,11 +352,20 @@ export class ViewPort {
}

mHandle.onMouseUp = function(e: MouseEvent|TouchEvent) {
if (e instanceof TouchEvent) {
stendhal.ui.touch.onTouchEnd();
}
var pos = stendhal.ui.html.extractPosition(e);
if (e instanceof MouseEvent && mHandle.isRightClick(e)) {
const long_touch = stendhal.ui.touch.isLongTouch();
if ((e instanceof MouseEvent && mHandle.isRightClick(e)
|| (e instanceof TouchEvent && long_touch))) {
if (entity != stendhal.zone.ground) {
const append: any[] = [];
if (long_touch) {
// TODO: add option for "hold" to allow splitting item stacks
}
stendhal.ui.actionContextMenu.set(ui.createSingletonFloatingWindow("Action",
new ActionContextMenu(entity), pos.pageX - 50, pos.pageY - 5));
new ActionContextMenu(entity, append), pos.pageX - 50, pos.pageY - 5));
}
} else {
entity.onclick(pos.canvasRelativeX, pos.canvasRelativeY);
Expand Down Expand Up @@ -506,8 +518,10 @@ export class ViewPort {
}

onTouchEnd(e: TouchEvent) {
stendhal.ui.touch.onTouchEnd();
if (stendhal.ui.touch.held) {
// don't call this.onMouseUp
// FIXME: not preventing default action
e.preventDefault();

stendhal.ui.gamewindow.onDrop(e);
Expand Down

0 comments on commit dd0d8ff

Please sign in to comment.