converted stendhal.ui.html into static class HTMLUtil
This commit is contained in:
parent
d350c2b494
commit
8b2727f392
17 changed files with 77 additions and 82 deletions
|
|
@ -140,7 +140,6 @@ export class Client {
|
|||
private initUI() {
|
||||
stendhal.ui = stendhal.ui || {};
|
||||
stendhal.ui.equip = singletons.getInventory();
|
||||
stendhal.ui.html = singletons.getHTMLManager();
|
||||
stendhal.ui.viewport = singletons.getViewPort();
|
||||
// alias for backward-compat until changed in all source
|
||||
stendhal.ui.gamewindow = stendhal.ui.viewport;
|
||||
|
|
|
|||
|
|
@ -35,7 +35,6 @@ import { SoundManager } from "./data/sound/SoundManager";
|
|||
import { ui } from "./ui/UI";
|
||||
import { UIComponentEnum } from "./ui/UIComponentEnum";
|
||||
import { HeldObjectManager } from "./ui/HeldObject";
|
||||
import { HTMLManager } from "./ui/HTMLManager";
|
||||
import { Inventory } from "./ui/Inventory";
|
||||
import { SoftwareJoystickController } from "./ui/SoftwareJoystickController";
|
||||
import { UIUpdateObserver } from "./ui/UIUpdateObserver";
|
||||
|
|
@ -92,10 +91,6 @@ export class SingletonRepo {
|
|||
return HeldObjectManager.get();
|
||||
}
|
||||
|
||||
static getHTMLManager(): HTMLManager {
|
||||
return HTMLManager.get();
|
||||
}
|
||||
|
||||
static getInventory(): Inventory {
|
||||
return Inventory.get();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ import { singletons } from "../SingletonRepo";
|
|||
import { marauroa } from "marauroa"
|
||||
import { stendhal } from "../stendhal";
|
||||
import { ImageSprite } from "../sprite/image/ImageSprite";
|
||||
import { HTMLUtil } from "ui/HTMLUtil";
|
||||
|
||||
/**
|
||||
* General entity
|
||||
|
|
@ -184,7 +185,7 @@ export class Entity extends RPObject {
|
|||
// action replaces "Look" command (e. g. "look closely" on signs)
|
||||
if (this["action"]) {
|
||||
list.push({
|
||||
title: stendhal.ui.html.niceName(this["action"]),
|
||||
title: HTMLUtil.niceName(this["action"]),
|
||||
type: this.actionAliasToAction(this["action"])
|
||||
});
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import { stendhal } from "../stendhal";
|
|||
import { RenderingContext2D } from "util/Types";
|
||||
import { Color } from "../data/color/Color";
|
||||
import { Pair } from "../util/Pair";
|
||||
import { HTMLUtil } from "ui/HTMLUtil";
|
||||
|
||||
|
||||
export abstract class TextBubble {
|
||||
|
|
@ -110,7 +111,7 @@ export abstract class TextBubble {
|
|||
* Mouse or touch event executed on canvas context.
|
||||
*/
|
||||
onClick(evt: MouseEvent|TouchEvent) {
|
||||
const pos = stendhal.ui.html.extractPosition(evt);
|
||||
const pos = HTMLUtil.extractPosition(evt);
|
||||
const screenRect = document.getElementById("viewport")!.getBoundingClientRect();
|
||||
const pointX = pos.clientX - screenRect.x + stendhal.ui.gamewindow.offsetX;
|
||||
const pointY = pos.clientY - screenRect.y + stendhal.ui.gamewindow.offsetY + TextBubble.adjustY;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/***************************************************************************
|
||||
* (C) Copyright 2003-2024 - Stendhal *
|
||||
* (C) Copyright 2003-2026 - Stendhal *
|
||||
***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
|
|
@ -13,21 +13,7 @@
|
|||
/**
|
||||
* HTML code manipulation.
|
||||
*/
|
||||
export class HTMLManager {
|
||||
|
||||
/** Singleton instance. */
|
||||
private static instance: HTMLManager;
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves singleton instance.
|
||||
*/
|
||||
static get(): HTMLManager {
|
||||
if (!HTMLManager.instance) {
|
||||
HTMLManager.instance = new HTMLManager();
|
||||
}
|
||||
return HTMLManager.instance;
|
||||
}
|
||||
export class HTMLUtil {
|
||||
|
||||
/**
|
||||
* Hidden singleton constructor.
|
||||
|
|
@ -36,7 +22,7 @@ export class HTMLManager {
|
|||
// do nothing
|
||||
}
|
||||
|
||||
esc(msg: string, filter=[]) {
|
||||
public static esc(msg: string, filter: string[]=[]) {
|
||||
msg = msg.replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/\n/g, "<br>");
|
||||
// restore filtered tags
|
||||
for (const tag of filter) {
|
||||
|
|
@ -47,7 +33,7 @@ export class HTMLManager {
|
|||
return msg;
|
||||
}
|
||||
|
||||
niceName(s: string): string {
|
||||
public static niceName(s: string): string {
|
||||
if (!s) {
|
||||
return "";
|
||||
}
|
||||
|
|
@ -63,7 +49,7 @@ export class HTMLManager {
|
|||
* @return {EventTarget}
|
||||
* Translated event target.
|
||||
*/
|
||||
extractTarget(event: any): EventTarget {
|
||||
public static extractTarget(event: any): EventTarget {
|
||||
if (event.changedTouches) {
|
||||
// FIXME: Always uses last index. Any way to detect which touch index was engaged?
|
||||
const tidx = event.changedTouches.length - 1;
|
||||
|
|
@ -88,9 +74,9 @@ export class HTMLManager {
|
|||
* @return {any}
|
||||
* Normalized event.
|
||||
*/
|
||||
extractPosition(event: any): any {
|
||||
public static extractPosition(event: any): any {
|
||||
let pos = event;
|
||||
const target = this.extractTarget(event);
|
||||
const target = HTMLUtil.extractTarget(event);
|
||||
const canvas = target as HTMLCanvasElement;
|
||||
if (event.changedTouches) {
|
||||
// FIXME: Always uses last index. Any way to detect which touch index was engaged?
|
||||
|
|
@ -117,7 +103,7 @@ export class HTMLManager {
|
|||
return pos;
|
||||
}
|
||||
|
||||
formatTallyMarks(line: string): any {
|
||||
public static formatTallyMarks(line: string): any {
|
||||
let tmp = line.split("<tally>");
|
||||
const pre = tmp[0];
|
||||
tmp = tmp[1].split("</tally>");
|
||||
|
|
@ -157,7 +143,7 @@ export class HTMLManager {
|
|||
* @return {string}
|
||||
* Slot name.
|
||||
*/
|
||||
parseSlotName(id: string): string {
|
||||
public static parseSlotName(id: string): string {
|
||||
if (id.includes("-")) {
|
||||
return id.split("-")[0];
|
||||
}
|
||||
|
|
@ -13,6 +13,7 @@
|
|||
import { stendhal } from "../stendhal";
|
||||
|
||||
import { Point } from "../util/Point";
|
||||
import { HTMLUtil } from "./HTMLUtil";
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -146,7 +147,7 @@ export class HeldObjectManager {
|
|||
* Handles event to update held object drawing position.
|
||||
*/
|
||||
private onDragWhileHeld(e: Event) {
|
||||
const pos = stendhal.ui.html.extractPosition(e);
|
||||
const pos = HTMLUtil.extractPosition(e);
|
||||
HeldObjectManager.get().setPosition(pos.pageX, pos.pageY);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
import { stendhal } from "../stendhal";
|
||||
|
||||
import { Point } from "../util/Point";
|
||||
import { HTMLUtil } from "./HTMLUtil";
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -117,7 +118,7 @@ export class TouchHandler {
|
|||
const durationMatch = (this.timestampTouchEnd - this.timestampTouchStart > this.longTouchDuration);
|
||||
let positionMatch = true;
|
||||
if (evt && this.origin) {
|
||||
const pos = stendhal.ui.html.extractPosition(evt);
|
||||
const pos = HTMLUtil.extractPosition(evt);
|
||||
// if position has moved too much it's not a long touch
|
||||
positionMatch = (Math.abs(pos.pageX - this.origin.x) <= this.moveThreshold)
|
||||
&& (Math.abs(pos.pageY - this.origin.y) <= this.moveThreshold);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/***************************************************************************
|
||||
* (C) Copyright 2003-2025 - Stendhal *
|
||||
* (C) Copyright 2003-2026 - Stendhal *
|
||||
***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
|
|
@ -36,6 +36,7 @@ import { Debug } from "../util/Debug";
|
|||
import { TileMap } from "data/TileMap";
|
||||
import { HTMLImageElementUtil } from "sprite/image/HTMLImageElementUtil";
|
||||
import { TouchHandler } from "./TouchHandler";
|
||||
import { HTMLUtil } from "./HTMLUtil";
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -87,8 +88,6 @@ export class ViewPort {
|
|||
/** Singleton instance. */
|
||||
private static instance: ViewPort;
|
||||
|
||||
private touchHandler = TouchHandler.get();
|
||||
|
||||
/**
|
||||
* Retrieves singleton instance.
|
||||
*/
|
||||
|
|
@ -500,7 +499,7 @@ export class ViewPort {
|
|||
|
||||
mHandle._onMouseDown = function(e: MouseEvent|TouchEvent) {
|
||||
let touchHandler = TouchHandler.get();
|
||||
var pos = stendhal.ui.html.extractPosition(e);
|
||||
var pos = HTMLUtil.extractPosition(e);
|
||||
if (touchHandler.isTouchEvent(e)) {
|
||||
if (touchHandler.holding()) {
|
||||
// prevent default viewport action when item is "held"
|
||||
|
|
@ -548,12 +547,13 @@ export class ViewPort {
|
|||
}
|
||||
|
||||
mHandle.onMouseUp = function(e: MouseEvent|TouchEvent) {
|
||||
const is_touch = this.touchHandler.isTouchEvent(e);
|
||||
let touchHandler = TouchHandler.get();
|
||||
const is_touch = touchHandler.isTouchEvent(e);
|
||||
if (is_touch) {
|
||||
this.touchHandler.onTouchEnd(e);
|
||||
touchHandler.onTouchEnd();
|
||||
}
|
||||
var pos = stendhal.ui.html.extractPosition(e);
|
||||
const long_touch = is_touch && this.touchHandler.isLongTouch(e);
|
||||
var pos = HTMLUtil.extractPosition(e);
|
||||
const long_touch = is_touch && touchHandler.isLongTouch(e);
|
||||
if ((e instanceof MouseEvent && mHandle.isRightClick(e)) || long_touch) {
|
||||
if (entity != stendhal.zone.ground) {
|
||||
const append: any[] = [];
|
||||
|
|
@ -574,11 +574,11 @@ export class ViewPort {
|
|||
}
|
||||
|
||||
mHandle.onDrag = function(e: MouseEvent) {
|
||||
if (this.touchHandler.isTouchEvent(e)) {
|
||||
if (TouchHandler.get().isTouchEvent(e)) {
|
||||
stendhal.ui.gamewindow.onDragStart(e);
|
||||
}
|
||||
|
||||
var pos = stendhal.ui.html.extractPosition(e);
|
||||
var pos = HTMLUtil.extractPosition(e);
|
||||
var xDiff = startX - pos.offsetX;
|
||||
var yDiff = startY - pos.offsetY;
|
||||
// It's not really a click if the mouse has moved too much.
|
||||
|
|
@ -605,7 +605,7 @@ export class ViewPort {
|
|||
* Updates cursor style when positioned over an element or entity.
|
||||
*/
|
||||
onMouseMove(e: MouseEvent) {
|
||||
var pos = stendhal.ui.html.extractPosition(e);
|
||||
var pos = HTMLUtil.extractPosition(e);
|
||||
var x = pos.canvasRelativeX + stendhal.ui.gamewindow.offsetX;
|
||||
var y = pos.canvasRelativeY + stendhal.ui.gamewindow.offsetY;
|
||||
var entity = stendhal.zone.entityAt(x, y);
|
||||
|
|
@ -649,7 +649,7 @@ export class ViewPort {
|
|||
* Handles engaging an item or corpse to be dragged.
|
||||
*/
|
||||
onDragStart(e: DragEvent) {
|
||||
var pos = stendhal.ui.html.extractPosition(e);
|
||||
var pos = HTMLUtil.extractPosition(e);
|
||||
let draggedEntity;
|
||||
for (const obj of stendhal.zone.getEntitiesAt(pos.canvasRelativeX + stendhal.ui.gamewindow.offsetX,
|
||||
pos.canvasRelativeY + stendhal.ui.gamewindow.offsetY)) {
|
||||
|
|
@ -679,9 +679,10 @@ export class ViewPort {
|
|||
return;
|
||||
}
|
||||
|
||||
if (this.touchHandler.isTouchEvent(e)) {
|
||||
let touchHandler = TouchHandler.get();
|
||||
if (touchHandler.isTouchEvent(e)) {
|
||||
singletons.getHeldObjectManager().set(heldObject, img, new Point(pos.pageX, pos.pageY));
|
||||
this.touchHandler.setHolding(true);
|
||||
touchHandler.setHolding(true);
|
||||
} else {
|
||||
stendhal.ui.heldObject = heldObject;
|
||||
}
|
||||
|
|
@ -708,8 +709,8 @@ export class ViewPort {
|
|||
*/
|
||||
onDrop(e: DragEvent) {
|
||||
if (stendhal.ui.heldObject) {
|
||||
var pos = stendhal.ui.html.extractPosition(e);
|
||||
const targetSlot = stendhal.ui.html.parseSlotName((pos.target as HTMLElement).id);
|
||||
var pos = HTMLUtil.extractPosition(e);
|
||||
const targetSlot = HTMLUtil.parseSlotName((pos.target as HTMLElement).id);
|
||||
const action: any = {
|
||||
"zone": stendhal.ui.heldObject.zone
|
||||
};
|
||||
|
|
@ -730,7 +731,7 @@ export class ViewPort {
|
|||
let objectId = marauroa.me["id"];
|
||||
if (e.type === "touchend" && targetSlot === "content") {
|
||||
// find the actual target ID for touch events
|
||||
const container = stendhal.ui.equip.getByElement(stendhal.ui.html.extractTarget(event).parentElement!);
|
||||
const container = stendhal.ui.equip.getByElement((HTMLUtil.extractTarget(event) as HTMLElement).parentElement!);
|
||||
if (container && container.object) {
|
||||
objectId = container.object.id;
|
||||
}
|
||||
|
|
@ -745,7 +746,7 @@ export class ViewPort {
|
|||
// item was dropped
|
||||
stendhal.ui.heldObject = undefined;
|
||||
|
||||
const touch_held = this.touchHandler.holding() && quantity > 1;
|
||||
const touch_held = TouchHandler.get().holding() && quantity > 1;
|
||||
// if ctrl is pressed or holding stackable item from touch event, we ask for the quantity
|
||||
// NOTE: don't create selector if touch source is ground
|
||||
if (e.ctrlKey || (touch_held && sourceSlot !== targetSlot)) {
|
||||
|
|
@ -764,11 +765,12 @@ export class ViewPort {
|
|||
* This is a workaround until it's figured out how to make it work using the same methods as mouse event.
|
||||
*/
|
||||
onTouchEnd(e: TouchEvent) {
|
||||
this.touchHandler.onTouchEnd();
|
||||
let touchHandler = TouchHandler.get();
|
||||
touchHandler.onTouchEnd();
|
||||
stendhal.ui.gamewindow.onDrop(e);
|
||||
if (this.touchHandler.holding()) {
|
||||
this.touchHandler.setHolding(false);
|
||||
this.touchHandler.unsetOrigin();
|
||||
if (touchHandler.holding()) {
|
||||
touchHandler.setHolding(false);
|
||||
touchHandler.unsetOrigin();
|
||||
}
|
||||
// execute here because "touchend" event propagation is cancelled on the veiwport
|
||||
Client.handleClickIndicator(e);
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import { stendhal } from "stendhal";
|
|||
|
||||
|
||||
import { marauroa } from "marauroa"
|
||||
import { HTMLUtil } from "ui/HTMLUtil";
|
||||
|
||||
/**
|
||||
* displays the player stats
|
||||
|
|
@ -71,7 +72,7 @@ export class BuddyListComponent extends Component {
|
|||
} else {
|
||||
html += Paths.gui + "/buddy_offline.png";
|
||||
}
|
||||
html += "\"> " + stendhal.ui.html.esc(buddies[i].name) + "</li>";
|
||||
html += "\"> " + HTMLUtil.esc(buddies[i].name) + "</li>";
|
||||
}
|
||||
|
||||
if (this.lastHtml !== html) {
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ import { Chat } from "../../util/Chat";
|
|||
|
||||
import { stendhal } from "../../stendhal";
|
||||
import { TouchHandler } from "ui/TouchHandler";
|
||||
import { HTMLUtil } from "ui/HTMLUtil";
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -41,7 +42,7 @@ export class ChatLogComponent extends Component {
|
|||
this.onContextMenu(evt)
|
||||
});
|
||||
this.componentElement.addEventListener("touchstart", (evt: TouchEvent) => {
|
||||
const pos = stendhal.ui.html.extractPosition(evt);
|
||||
const pos = HTMLUtil.extractPosition(evt);
|
||||
touchHandler.onTouchStart(pos.pageX, pos.pageY);
|
||||
}, {passive: true});
|
||||
this.componentElement.addEventListener("touchend", (evt: TouchEvent) => {
|
||||
|
|
@ -368,7 +369,7 @@ export class ChatLogComponent extends Component {
|
|||
options.unshift(new MenuItem("Copy", function() { log.exportContents(); }));
|
||||
}
|
||||
|
||||
const pos = stendhal.ui.html.extractPosition(evt);
|
||||
const pos = HTMLUtil.extractPosition(evt);
|
||||
stendhal.ui.actionContextMenu.set(ui.createSingletonFloatingWindow("Action",
|
||||
new LogContextMenu(options), pos.pageX - 50, pos.pageY - 5));
|
||||
|
||||
|
|
@ -393,7 +394,7 @@ class LogContextMenu extends Component {
|
|||
|
||||
let content = "<div class=\"actionmenu verticalgroup\">";
|
||||
for (let i = 0; i < this.options.length; i++) {
|
||||
content += "<button class=\"actionbutton\" id=\"actionbutton." + i + "\">" + stendhal.ui.html.esc(this.options[i].title) + "</button>";
|
||||
content += "<button class=\"actionbutton\" id=\"actionbutton." + i + "\">" + HTMLUtil.esc(this.options[i].title) + "</button>";
|
||||
}
|
||||
content += "</div>";
|
||||
this.componentElement.innerHTML = content;
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import { Point } from "../../util/Point";
|
|||
import { Paths } from "../../data/Paths";
|
||||
import { HTMLImageElementUtil } from "sprite/image/HTMLImageElementUtil";
|
||||
import { TouchHandler } from "ui/TouchHandler";
|
||||
import { HTMLUtil } from "ui/HTMLUtil";
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -201,7 +202,7 @@ export class ItemContainerImplementation {
|
|||
} else if (this.touchHandler.isTouchEvent(event)) {
|
||||
this.touchHandler.setHolding(true);
|
||||
// TODO: move when supported by mouse events
|
||||
const pos = stendhal.ui.html.extractPosition(event);
|
||||
const pos = HTMLUtil.extractPosition(event);
|
||||
singletons.getHeldObjectManager().set(heldObject, img, new Point(pos.pageX, pos.pageY));
|
||||
}
|
||||
} else {
|
||||
|
|
@ -248,9 +249,9 @@ export class ItemContainerImplementation {
|
|||
private onDrop(event: DragEvent|TouchEvent) {
|
||||
const myobject = this.object || marauroa.me;
|
||||
if (stendhal.ui.heldObject) {
|
||||
const pos = stendhal.ui.html.extractPosition(event);
|
||||
const pos = HTMLUtil.extractPosition(event);
|
||||
const id = (pos.target as HTMLElement).id;
|
||||
const targetSlot = stendhal.ui.html.parseSlotName(id);
|
||||
const targetSlot = HTMLUtil.parseSlotName(id);
|
||||
if (event.type === "touchend" && id === "viewport") {
|
||||
stendhal.ui.gamewindow.onDrop(event);
|
||||
event.stopPropagation();
|
||||
|
|
@ -262,7 +263,7 @@ export class ItemContainerImplementation {
|
|||
if (event.type === "touchend") {
|
||||
// find the actual target ID for touch events
|
||||
if (targetSlot === "content") {
|
||||
const container = stendhal.ui.equip.getByElement(stendhal.ui.html.extractTarget(event).parentElement!);
|
||||
const container = stendhal.ui.equip.getByElement((HTMLUtil.extractTarget(event) as HTMLElement).parentElement!);
|
||||
if (container && container.object) {
|
||||
objectId = container.object.id;
|
||||
}
|
||||
|
|
@ -292,7 +293,7 @@ export class ItemContainerImplementation {
|
|||
const touch_held = this.touchHandler.holding() && quantity > 1;
|
||||
const split_action = !sameSlot && ((event instanceof DragEvent && event.ctrlKey) || touch_held);
|
||||
if (split_action) {
|
||||
const pos = stendhal.ui.html.extractPosition(event);
|
||||
const pos = HTMLUtil.extractPosition(event);
|
||||
ui.createSingletonFloatingWindow("Quantity",
|
||||
new DropQuantitySelectorDialog(action, touch_held),
|
||||
pos.pageX - 50, pos.pageY - 25);
|
||||
|
|
@ -322,9 +323,9 @@ export class ItemContainerImplementation {
|
|||
if (this.timestampMouseDown - this.timestampMouseDownPrev <= this.rightClickDuration) {
|
||||
// reset so subsequent single clicks/taps aren't counted
|
||||
this.timestampMouseDown = 0;
|
||||
return (stendhal.ui.html.extractTarget(evt) as HTMLElement).id === this.lastClickedId;
|
||||
return (HTMLUtil.extractTarget(evt) as HTMLElement).id === this.lastClickedId;
|
||||
}
|
||||
this.lastClickedId = (stendhal.ui.html.extractTarget(evt) as HTMLElement).id;
|
||||
this.lastClickedId = (HTMLUtil.extractTarget(evt) as HTMLElement).id;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -344,7 +345,7 @@ export class ItemContainerImplementation {
|
|||
return;
|
||||
}
|
||||
|
||||
let event = stendhal.ui.html.extractPosition(evt);
|
||||
let event = HTMLUtil.extractPosition(evt);
|
||||
if ((event.target as any).dataItem) {
|
||||
const long_touch = this.touchHandler.isLongTouch(evt);
|
||||
const context_action = (evt instanceof MouseEvent && this.isRightClick(evt)) || long_touch;
|
||||
|
|
@ -402,7 +403,7 @@ export class ItemContainerImplementation {
|
|||
}
|
||||
|
||||
private onTouchStart(evt: TouchEvent) {
|
||||
const pos = stendhal.ui.html.extractPosition(evt);
|
||||
const pos = HTMLUtil.extractPosition(evt);
|
||||
this.touchHandler.onTouchStart(pos.pageX, pos.pageY);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ import { Color } from "../../data/color/Color";
|
|||
import { RenderingContext2D } from "util/Types";
|
||||
import { stendhal } from "stendhal";
|
||||
import { TileMap } from "data/TileMap";
|
||||
import { HTMLUtil } from "ui/HTMLUtil";
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -220,7 +221,7 @@ export class MiniMapComponent extends Component {
|
|||
if (!stendhal.config.getBoolean("pathfinding.minimap")) {
|
||||
return;
|
||||
}
|
||||
let pos = stendhal.ui.html.extractPosition(event);
|
||||
let pos = HTMLUtil.extractPosition(event);
|
||||
let x = Math.floor((pos.canvasRelativeX + this.xOffset) / this.scale);
|
||||
let y = Math.floor((pos.canvasRelativeY + this.yOffset) / this.scale);
|
||||
if (!this.map.collision(x, y)) {
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ import { ChatInputComponent } from "../component/ChatInputComponent";
|
|||
|
||||
import { marauroa } from "marauroa"
|
||||
import { stendhal } from "../../stendhal";
|
||||
import { HTMLUtil } from "ui/HTMLUtil";
|
||||
|
||||
export class ActionContextMenu extends Component {
|
||||
private entity: any;
|
||||
|
|
@ -31,7 +32,7 @@ export class ActionContextMenu extends Component {
|
|||
var content = "<div class=\"actionmenu verticalgroup\">";
|
||||
for (var i = 0; i < this.actions.length; i++) {
|
||||
// FIXME: the addition of "sub-actionbutton" class should no longer be needed
|
||||
content += "<button class=\"actionbutton" + (i > 0 ? " sub-actionbutton" : "") + "\" id=\"actionbutton." + i + "\">" + stendhal.ui.html.esc(this.actions[i].title) + "</button>";
|
||||
content += "<button class=\"actionbutton" + (i > 0 ? " sub-actionbutton" : "") + "\" id=\"actionbutton." + i + "\">" + HTMLUtil.esc(this.actions[i].title) + "</button>";
|
||||
}
|
||||
content += "</div>";
|
||||
this.componentElement.innerHTML = content;
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ import { singletons } from "../../SingletonRepo";
|
|||
|
||||
import { Debug } from "../../util/Debug";
|
||||
import { ScreenCapture } from "../../util/ScreenCapture";
|
||||
import { HTMLUtil } from "ui/HTMLUtil";
|
||||
|
||||
|
||||
interface MenuAction {
|
||||
|
|
@ -136,14 +137,14 @@ export class ApplicationMenuDialog extends DialogContentComponent {
|
|||
|
||||
var content = "";
|
||||
for (var i = 0; i < this.actions.length; i++) {
|
||||
content += "<div class=\"inlineblock buttonColumn\"><h4 class=\"menugroup\">" + stendhal.ui.html.esc(this.actions[i].title) + "</h4>"
|
||||
content += "<div class=\"inlineblock buttonColumn\"><h4 class=\"menugroup\">" + HTMLUtil.esc(this.actions[i].title) + "</h4>"
|
||||
for (var j = 0; j < this.actions[i].children.length; j++) {
|
||||
const action = this.actions[i].children[j];
|
||||
let title = action.title;
|
||||
if (action.alt && action.condition && action.condition()) {
|
||||
title = action.alt;
|
||||
}
|
||||
content += "<button id=\"menubutton." + action.action + "\" class=\"menubutton\">" + stendhal.ui.html.esc(title) + "</button><br>";
|
||||
content += "<button id=\"menubutton." + action.action + "\" class=\"menubutton\">" + HTMLUtil.esc(title) + "</button><br>";
|
||||
}
|
||||
content += "</div>";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ import { UIComponentEnum } from "../UIComponentEnum";
|
|||
|
||||
import { marauroa } from "marauroa"
|
||||
import { stendhal } from "../../stendhal";
|
||||
import { HTMLUtil } from "ui/HTMLUtil";
|
||||
|
||||
/**
|
||||
* a dialog to display images
|
||||
|
|
@ -58,9 +59,9 @@ export class TravelLogDialog extends DialogContentComponent {
|
|||
private createHtml(dataItems: string[]) {
|
||||
let buttons = "";
|
||||
for (var i = 0; i < dataItems.length; i++) {
|
||||
buttons = buttons + "<button id=\"" + stendhal.ui.html.esc(dataItems[i])
|
||||
buttons = buttons + "<button id=\"" + HTMLUtil.esc(dataItems[i])
|
||||
+ "\" class=\"progressTypeButton\">"
|
||||
+ stendhal.ui.html.esc(dataItems[i]) + "</button>";
|
||||
+ HTMLUtil.esc(dataItems[i]) + "</button>";
|
||||
}
|
||||
this.child(".tavellogtabpanel")!.innerHTML = buttons;
|
||||
|
||||
|
|
@ -136,8 +137,8 @@ export class TravelLogDialog extends DialogContentComponent {
|
|||
var html = "";
|
||||
for (var i = 0; i < dataItems.length; i++) {
|
||||
const currentItem = dataItems[i];
|
||||
html += "<option value=\"" + stendhal.ui.html.esc(currentItem) + "\">"
|
||||
+ stendhal.ui.html.esc(currentItem);
|
||||
html += "<option value=\"" + HTMLUtil.esc(currentItem) + "\">"
|
||||
+ HTMLUtil.esc(currentItem);
|
||||
if (this.repeatable[currentItem]) {
|
||||
html += " (R)";
|
||||
}
|
||||
|
|
@ -165,23 +166,23 @@ export class TravelLogDialog extends DialogContentComponent {
|
|||
|
||||
const detailsSpan = document.createElement("span");
|
||||
|
||||
detailsSpan.innerHTML = "<h3>" + stendhal.ui.html.esc(selectedItem) + "</h3>";
|
||||
detailsSpan.innerHTML = "<h3>" + HTMLUtil.esc(selectedItem) + "</h3>";
|
||||
if (this.repeatable[selectedItem]) {
|
||||
detailsSpan.innerHTML += "<p id=\"travellogrepeatable\">"
|
||||
+ "<img src=\"" + Paths.gui + "/rp.png\" /> <em>I can do this quest again.</em></p>";
|
||||
}
|
||||
|
||||
detailsSpan.innerHTML += "<p id=\"travellogdescription\">"
|
||||
+ stendhal.ui.html.esc(description) + "</p>";
|
||||
+ HTMLUtil.esc(description) + "</p>";
|
||||
|
||||
const ul = document.createElement("ul");
|
||||
ul.className = "uniform";
|
||||
|
||||
for (var i = 0; i < dataItems.length; i++) {
|
||||
let content = []
|
||||
let html = stendhal.ui.html.esc(dataItems[i], ["em", "tally"]);
|
||||
let html = HTMLUtil.esc(dataItems[i], ["em", "tally"]);
|
||||
if (html.includes("<tally>") && html.includes("</tally>")) {
|
||||
content = stendhal.ui.html.formatTallyMarks(html);
|
||||
content = HTMLUtil.formatTallyMarks(html);
|
||||
} else {
|
||||
content.push(html);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import { Direction } from "../../util/Direction";
|
|||
import { MathUtil } from "../../util/MathUtil";
|
||||
import { Pair } from "../../util/Pair";
|
||||
import { Point } from "../../util/Point";
|
||||
import { HTMLUtil } from "ui/HTMLUtil";
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -270,7 +271,7 @@ export class Joystick extends JoystickImpl {
|
|||
}
|
||||
|
||||
// update inner button position
|
||||
const pos = stendhal.ui.html.extractPosition(e);
|
||||
const pos = HTMLUtil.extractPosition(e);
|
||||
this.updateInner(pos.pageX, pos.pageY);
|
||||
|
||||
// set new direction of movement
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
* *
|
||||
***************************************************************************/
|
||||
|
||||
import { HTMLUtil } from "ui/HTMLUtil";
|
||||
import { stendhal } from "../stendhal";
|
||||
|
||||
|
||||
|
|
@ -50,7 +51,7 @@ export class ElementClickListener {
|
|||
});
|
||||
element.addEventListener("touchend", (evt: TouchEvent) => {
|
||||
evt.preventDefault();
|
||||
const target = stendhal.ui.html.extractTarget(evt);
|
||||
const target = HTMLUtil.extractTarget(evt);
|
||||
if (this.touchEngaged == evt.changedTouches.length && target == element && this.onClick) {
|
||||
// FIXME: should veto if moved too much before release
|
||||
this.onClick(evt);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue