Popup menu implementation

Posted by Khripunoff on Thu 07 May 2020 03:36 PM — 4 posts, 19,123 views.

#0
I play Discworld MUD and I decided to make a plugin that will enhance the item lists in shops.

This is an example snippet of a shop list:

The following items are for sale:
   A: a large watermelon for DjToon 25.00 (five left).
   B: a medium watermelon for DjToon 17.50 (four left).
   C: a small watermelon for DjToon 10.00 (seven left).
   D: an overripe plum for DjToon 1.87 (four left).
   E: a succulent pineapple for DjToon 6.00 (six left).
   F: a juicy peach for DjToon 5.00 (five left).
   G: an orange for DjToon 3.00 (seven left).
   H: a juicy nectarine for DjToon 5.00 (three left).
   I: a musk melon for DjToon 18.00 (five left).
   J: a small lemon for DjToon 2.50 (four left).

I made a regex that captures the item name, the currency and the price (the last two may be used later for other purpose) like this:
^   [A-Z]{1,2}: ?a?n? (?<Item>.*) for (?<Currency>\w+) (?<Price>[\d.]+) \(\w+ left\)\.$

My idea is to make every item entry a clickable link that can be right-clicked for a pop-up menu with command options such as |buy <Item>|browse <Item>|case <Item>|shoplift <Item>| etc.
I have some basic scripting knowledge but I would like some advise on what would be the best approach for realizing this? mxp? hyperlink? Is there a function dedicated to creating such thing?

Help and advice will be highly appreciated.

[EDIT] The currency and the price are captured in this case, but there are some currencies in the MUD with different formatting. I will have to come up with a better idea for capturing them properly, but for now this is far less important.
Amended on Thu 07 May 2020 06:08 PM by Khripunoff
USA Global Moderator #1
Quote:
the best approach


There are no best approaches, only ones that work and ones that don't.

Quote:
right-clicked for a pop-up menu

I don't know much about MXP, but the only function I know of in MUSHclient for that is WindowMenu. It requires creating a temporary miniwindow first, though I'm not sure why that is. But anyway you can make a hyperlink that calls a function that creates a miniwindow and then calls WindowMenu in that miniwindow. You can use the same miniwindow over and over, so you only have to create one once.
Amended on Fri 08 May 2020 05:39 PM by Fiendish
Australia Forum Administrator #2

Using MXP (from the server) you can make hyperlinks that have a menu. See Creating a popup menu in this link.

You could conceivably pretend MXP arrived by using the Simulate function — although it was not designed for that — and make a menu that way.

Amended on Sun 10 May 2020 06:57 AM by Nick Gammon
Australia Forum Administrator #3

Another approach would be to make a hyperlink and inside that call a function (see that link). That function could pop up a miniwindow — I think you can find out where the mouse currently is* — and make a menu of things you want to do in that.

* See GetInfo selectors 283 and 284.