moved ShowItemListEvent and ShowOutfitListEvent out of EventRegistry

This commit is contained in:
Hendrik Brummermann 2025-12-22 17:02:31 +01:00
parent ccee5a42b3
commit 6f783d3ef6
4 changed files with 170 additions and 120 deletions

View file

@ -12,7 +12,7 @@ Changelog
*bug fixes*
- fixed invalid head outfit index of Mr Ross
- fixed silent NPC fixed paths
- fixed silent NPC paths
- fixed desktop webview client window freezing on Windows when closed
- fixed nativehelper extension process not exiting cleanly on Windows
- set User-Agent string for Wikipedia API requests

View file

@ -24,14 +24,11 @@ import { PlayerLoggedOnEvent } from "./event/PlayerLoggedOnEvent";
import { PlayerLoggedOutEvent } from "./event/PlayerLoggedOutEvent";
import { ProgressStatusEvent } from "./event/ProgressStatusEvent";
import { RPEvent } from "./event/RPEvent";
import { ShowItemListEvent } from "./event/ShowItemListEvent";
import { ShowOutfitListEvent } from "./event/ShowOutfitListEvent";
import { SoundEvent } from "./event/SoundEvent";
import { TradeEvent } from "./event/TradeEvent";
import { ViewChangeEvent } from "./event/ViewChangeEvent";
import { ui } from "./ui/UI";
import { DialogContentComponent } from "./ui/toolkit/DialogContentComponent";
import { Chat } from "./util/Chat";
@ -155,120 +152,8 @@ export class EventRegistry {
}
}); // reached_achievement
this.register("show_item_list", {
execute: function(rpobject: RPObject) {
let title = "Items";
let caption = "";
let items = [];
if (this.hasOwnProperty("title")) {
title = this["title"];
}
if (this.hasOwnProperty("caption")) {
caption = this["caption"];
}
if (this.hasOwnProperty("content")) {
for (var obj in this["content"]) {
if (this["content"].hasOwnProperty(obj)) {
var slotObj = this["content"][obj];
var data = this["content"][obj]["a"];
const i = {
clazz: data["class"],
subclass: data["subclass"],
img: data["class"] + "/" + data["subclass"] + ".png",
price: data["price"],
desc: data["description_info"]
}
// seller shops prefix prices with "-"
if (i.price.startsWith("-")) {
i.price = i.price.substr(1);
}
items.push(i);
}
}
}
const content = new class extends DialogContentComponent {} ("empty-div-template");
content.componentElement.classList.add("shopsign");
const captionElement = document.createElement("div");
captionElement.className = "horizontalgroup shopcaption";
captionElement.textContent = caption + "\nItem\t-\tPrice\t-\tDescription";
content.componentElement.appendChild(captionElement);
const itemList = document.createElement("div");
itemList.className = "shoplist";
content.componentElement.appendChild(itemList);
// TODO: organize in columns & show item sprites
for (const i of items) {
const row = document.createElement("div");
row.className = "horizontalgroup shoprow";
const img = document.createElement("div");
img.className = "shopcol";
img.appendChild(stendhal.data.sprites.get(stendhal.paths.sprites + "/items/" + i.img));
row.appendChild(img);
const price = document.createElement("div");
price.className = "shopcol";
price.textContent = i.price;
row.appendChild(price);
const desc = document.createElement("div");
desc.className = "shopcol shopcolr";
desc.textContent = i.desc;
row.appendChild(desc);
itemList.appendChild(row);
}
stendhal.ui.globalInternalWindow.set(
ui.createSingletonFloatingWindow(title, content, 20, 20));
}
}); // show_item_list
this.register("show_outfit_list", {
execute: function(rpobject: RPObject) {
let title = "Outfits";
let caption = "";
let outfits = [];
if (this.hasOwnProperty("title")) {
title = this["title"];
}
if (this.hasOwnProperty("caption")) {
caption = this["caption"];
}
if (this.hasOwnProperty("outfits")) {
for (let o of this["outfits"].split(":")) {
o = o.split(";");
if (o.length > 2) {
outfits.push([o[0], o[1], o[2]]);
}
}
}
if (this.hasOwnProperty("show_base")) {
//Chat.log("normal", this["show_base"]);
}
const content = new class extends DialogContentComponent {} ("empty-div-template");
content.componentElement.classList.add("shopsign");
const captionElement = document.createElement("div");
captionElement.className = "horizontalgroup shopcaption";
captionElement.textContent = caption;
content.componentElement.appendChild(captionElement);
const itemList = document.createElement("div");
itemList.className = "shoplist";
content.componentElement.appendChild(itemList);
// TODO: organize in columns & show outfit sprites
for (const o of outfits) {
const row = document.createElement("div");
row.className = "horizontalgroup shoprow";
row.textContent = o[0] + ": " + o[2];
itemList.appendChild(row);
}
stendhal.ui.globalInternalWindow.set(
ui.createSingletonFloatingWindow(title, content, 20, 20));
}
}); // show_outfit_list
this.register("show_item_list", new ShowItemListEvent());
this.register("show_outfit_list", new ShowOutfitListEvent());
this.register("sound_event", new SoundEvent());

View file

@ -0,0 +1,94 @@
/***************************************************************************
* Copyright © 2024 - 2025 Faiumoni e. V. *
***************************************************************************
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Affero General Public License as *
* published by the Free Software Foundation; either version 3 of the *
* License, or (at your option) any later version. *
* *
***************************************************************************/
import { RPEvent } from "./RPEvent";
import { ui } from "../ui/UI";
import { DialogContentComponent } from "../ui/toolkit/DialogContentComponent";
declare var stendhal: any;
export class ShowItemListEvent extends RPEvent {
title!: string;
caption!: string;
content!: any;
execute(_entity: any) {
let title = "Items";
let caption = "";
let items = [];
console.log("Items", this);
if (this.hasOwnProperty("title")) {
title = this["title"];
}
if (this.hasOwnProperty("caption")) {
caption = this["caption"];
}
if (this.hasOwnProperty("content")) {
for (var obj in this["content"]) {
if (this["content"].hasOwnProperty(obj)) {
var slotObj = this["content"][obj];
var data = this["content"][obj]["a"];
const i = {
clazz: data["class"],
subclass: data["subclass"],
img: data["class"] + "/" + data["subclass"] + ".png",
price: data["price"],
desc: data["description_info"]
}
// seller shops prefix prices with "-"
if (i.price.startsWith("-")) {
i.price = i.price.substr(1);
}
items.push(i);
}
}
}
const content = new class extends DialogContentComponent { }("empty-div-template");
content.componentElement.classList.add("shopsign");
const captionElement = document.createElement("div");
captionElement.className = "horizontalgroup shopcaption";
captionElement.textContent = caption + "\nItem\t-\tPrice\t-\tDescription";
content.componentElement.appendChild(captionElement);
const itemList = document.createElement("div");
itemList.className = "shoplist";
content.componentElement.appendChild(itemList);
// TODO: organize in columns & show item sprites
for (const i of items) {
const row = document.createElement("div");
row.className = "horizontalgroup shoprow";
const img = document.createElement("div");
img.className = "shopcol";
img.appendChild(stendhal.data.sprites.get(stendhal.paths.sprites + "/items/" + i.img));
row.appendChild(img);
const price = document.createElement("div");
price.className = "shopcol";
price.textContent = i.price;
row.appendChild(price);
const desc = document.createElement("div");
desc.className = "shopcol shopcolr";
desc.textContent = i.desc;
row.appendChild(desc);
itemList.appendChild(row);
}
stendhal.ui.globalInternalWindow.set(
ui.createSingletonFloatingWindow(title, content, 20, 20));
}
}

View file

@ -0,0 +1,71 @@
/***************************************************************************
* Copyright © 2024 - 2025 Faiumoni e. V. *
***************************************************************************
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Affero General Public License as *
* published by the Free Software Foundation; either version 3 of the *
* License, or (at your option) any later version. *
* *
***************************************************************************/
import { RPEvent } from "./RPEvent";
import { ui } from "../ui/UI";
import { DialogContentComponent } from "../ui/toolkit/DialogContentComponent";
declare var stendhal: any;
export class ShowOutfitListEvent extends RPEvent {
title!: string;
caption!: string;
outfits!: string;
execute(_entity: any) {
let title = "Outfits";
let caption = "";
let outfits = [];
if (this.hasOwnProperty("title")) {
title = this["title"];
}
if (this.hasOwnProperty("caption")) {
caption = this["caption"];
}
if (this.hasOwnProperty("outfits")) {
for (let o of this["outfits"].split(":")) {
let parts = o.split(";");
if (parts.length > 2) {
outfits.push([parts[0], parts[1], parts[2]]);
}
}
}
if (this.hasOwnProperty("show_base")) {
//Chat.log("normal", this["show_base"]);
}
const content = new class extends DialogContentComponent { }("empty-div-template");
content.componentElement.classList.add("shopsign");
const captionElement = document.createElement("div");
captionElement.className = "horizontalgroup shopcaption";
captionElement.textContent = caption;
content.componentElement.appendChild(captionElement);
const itemList = document.createElement("div");
itemList.className = "shoplist";
content.componentElement.appendChild(itemList);
// TODO: organize in columns & show outfit sprites
for (const o of outfits) {
const row = document.createElement("div");
row.className = "horizontalgroup shoprow";
row.textContent = o[0] + ": " + o[2];
itemList.appendChild(row);
}
stendhal.ui.globalInternalWindow.set(
ui.createSingletonFloatingWindow(title, content, 20, 20));
}
}