Jump to content
Eternal Lands Official Forums
bluap

Simple, generic context menus (right click)

Recommended Posts

I thought we might be able to use a context menu system in the el user interface. That is, a simple, generic menu of options that can be activated by right clicking on a user interface component. I've just put together a prototype version that works and I used it to add a menu to the quick spell bar. The quick spell bar has mouse+key options to move up, move down and remove a spell. The context menu provides the same functions but as a menu of options when you right click on a spell. Once activated, the menu options are highlighted as you move the mouse over them, clicking a line selects that options. Clicking anywhere else closes the menu without taking any action. A picture paints a thousand words (there is a mouse cursor over the highlighted option BTW):

gallery_14814_13_13702.jpg

 

Hopefully, people will find this interface familiar. This context menu system can be added to any window with a single function call. Menu creation and activation is all done elsewhere. If an option is selected from the menu, the specified callback function is executed and passed the option chosen and mouse position from when the menu was originally activated.

 

I'd like to spend a bit more time adding a few more features and generally tidying up the code but I thought I'd see what the interest was before I went too far. The current interface has functions to replace the all the menu text, or just one line so it easy to have dynamic items such as "[x] Show thing" replaced with "[ ] Show thing" and such.

 

Anyway, here's the code used for the spells quickbar:

Index: spells.c
===================================================================
RCS file: /cvsroot/elc/elc/spells.c,v
retrieving revision 1.81
diff -a -u -r1.81 spells.c
--- spells.c	12 Feb 2008 19:22:50 -0000	  1.81
+++ spells.c	29 Feb 2008 18:35:48 -0000
@@ -3,6 +3,7 @@
#include "spells.h"
#include "asc.h"
#include "cursors.h"
+#include "ContextMenu.h"
#include "elwindows.h"
#include "eye_candy_wrapper.h"
#include "gamewin.h"
@@ -964,6 +965,21 @@
	return 0;
}

+static int context_quickspell_handler(window_info *win, int mx, int my, int option)
+{
+	   int pos=my/30+1;
+	   if(pos<7 && pos>=1 && mqb_data[pos])
+	   {
+			   switch (option)
+			   {
+					   case 0: move_spell_on_quickbar (pos,0); break;
+					   case 1: move_spell_on_quickbar (pos,1); break;
+					   case 2: remove_spell_from_quickbar (pos); break;
+			   }
+	   }
+	   return 1;
+}
+
void init_quickspell()
{
	if (quickspell_win < 0){
@@ -971,6 +987,7 @@
			set_window_handler(quickspell_win, ELW_HANDLER_DISPLAY, &display_quickspell_handler);
			set_window_handler(quickspell_win, ELW_HANDLER_CLICK, &click_quickspell_handler);
			set_window_handler(quickspell_win, ELW_HANDLER_MOUSEOVER, &mouseover_quickspell_handler );
+			   create_context_menu(quickspell_win, "Move Up\nMove Down\nRemove\n", &context_quickspell_handler);
	} else {
			show_window (quickspell_win);
			move_window (quickspell_win, -1, 0, window_width - quickspell_x, quickspell_y);

Edited by bluap

Share this post


Link to post
Share on other sites

That looks great, my only (very very minor) request would be that the delimiter be | as opposed to \n.

 

Does the context menu disappear when it loses mouse focus or is it sticky until the mouse clicks it or another part of the window?

Share this post


Link to post
Share on other sites
That looks great, my only (very very minor) request would be that the delimiter be | as opposed to \n.

Does the context menu disappear when it loses mouse focus or is it sticky until the mouse clicks it or another part of the window?

Not sure about using "|" instead of "\n"... It's sticky.

Share this post


Link to post
Share on other sites

Really nice feature bluap :confused:

I think it will add a lot of flexibility to the interface. We can maybe use such a thing to remove some options from the options window and put the options elsewhere. For example, using a context menu to show/hide things in the right tab would be nice IMO.

Share this post


Link to post
Share on other sites

Hey,

 

we also have the popup code I implemented, that was supposed to do similar things (although windowed and more complex).

 

We could adapt it and merge both code, if feasible.

 

Álvaro

Share this post


Link to post
Share on other sites
I think it will add a lot of flexibility to the interface. We can maybe use such a thing to remove some options from the options window and put the options elsewhere. For example, using a context menu to show/hide things in the right tab would be nice IMO.

That was my other choice as a demo. :)

 

we also have the popup code I implemented, that was supposed to do similar things (although windowed and more complex).

We could adapt it and merge both code, if feasible.

Possibly, but this has taken little code so far and is simpler for having just one function.

Share this post


Link to post
Share on other sites
That is awesome bluap. Could it be used for copying/pasting text as well (in the text field widget)?

Well awesome may be a tad overstated. Anyhow, the current interface allows you to add to any window but the same could the done for individual widgets too...

Share this post


Link to post
Share on other sites

That's very nice :P

@alvieboy: I think they should be separated, since they have different requirements and purpose. One of the reasons is that the GUI menus can allow for more customization, since the client has more data about them (precise location, style, and so on).

Share this post


Link to post
Share on other sites

Thanks to the positive feedback, I'm still working on this patch. I've now added simple check box option controls and aim to add screen regions and widget based menu options too. Here's a screen shot of the check boxes.

gallery_14814_13_5400.jpg

And here's the code for that menu - no callback needed for simple check boxes:

Index: hud.c
===================================================================
RCS file: /cvsroot/elc/elc/hud.c,v
retrieving revision 1.197
diff -a -u -r1.197 hud.c
--- hud.c	   12 Feb 2008 21:56:27 -0000	  1.197
+++ hud.c	   8 Mar 2008 22:24:57 -0000
@@ -5,6 +5,7 @@
#include "asc.h"
#include "buddy.h"
#include "consolewin.h"
+#include "ContextMenu.h"
#include "cursors.h"
#include "draw_scene.h"
#include "elconfig.h";
@@ -997,6 +999,11 @@
					set_window_handler(misc_win, ELW_HANDLER_DISPLAY, &display_misc_handler);
					set_window_handler(misc_win, ELW_HANDLER_CLICK, &click_misc_handler);
					set_window_handler(misc_win, ELW_HANDLER_MOUSEOVER, &mouseover_misc_handler );
+					   context_menu_create(misc_win, "Show Stats\nShow Stats Bars\nShow Digital Clock\nShow Analogue Clock\n", NULL);
+					   context_menu_bool_menu_entry(misc_win, 0, &show_stats_in_hud);
+					   context_menu_bool_menu_entry(misc_win, 1, &show_statbars_in_hud);
+					   context_menu_bool_menu_entry(misc_win, 2, &view_digital_clock);
+					   context_menu_bool_menu_entry(misc_win, 3, &view_analog_clock);
			}
	else
			{

Edited by bluap

Share this post


Link to post
Share on other sites
Could you commit this?

Yes I shall finish this very soon. I've been away from home with work two out of the last three weeks so my EL time has been very limited. Hopefully this week I'll finish this patch as I'm off again next week.

Share this post


Link to post
Share on other sites

I'm just finishing this work off and will hopefully be ready to submit/commit this evening. I've added a menu to the right hud panel to control the options there, a menu to the spells quickbar to control moving and removing spells, a menu to the quickbar to control it's movement (menu enabled/disabled from the hud menu to avoid interfering with normal right clicks), and a generic menu to all text widgets for cut/copy/paste. Other menus can be added as desired....

 

The changes to existing code are minor and conditionally compiled using a CONTEXT_MENU macro compile macro.

 

Entropy, I hope you want this code added to the client. Should I submit it as a patch or commit directly to CVS?

Share this post


Link to post
Share on other sites
Just commit it to the CVS, I hope it won't break anything :)

OK, it's done. Conditionally compiled with the CONTEXT_MENUS #ifdef which I've set on by default. Any comments on the interface are welcome; it's been through a few revisions but hopefully others will find the features useful and easy to use. I've added an additional menu for the main window to control the actor banner functions (activated when right-click has nothing under the cursor). Hopefully, this is useful but it can easily be removed (like the other menus) if folks don't like it.

Share this post


Link to post
Share on other sites
Just commit it to the CVS, I hope it won't break anything :)

OK, it's done. Conditionally compiled with the CONTEXT_MENUS #ifdef which I've set on by default. Any comments on the interface are welcome; it's been through a few revisions but hopefully others will find the features useful and easy to use. I've added an additional menu for the main window to control the actor banner functions (activated when right-click has nothing under the cursor). Hopefully, this is useful but it can easily be removed (like the other menus) if folks don't like it.

 

The context menus are a great option to have, however I would love to see a HUD option box for each type of context menu. For example, I use right click (with nothing under the cursor) to change cursor types (e.g. from eyeball (look at) to walk, or attack). As things are now, I have a context menu popping up at all the wrong moments.

Share this post


Link to post
Share on other sites
The context menus are a great option to have, however I would love to see a HUD option box for each type of context menu. For example, I use right click (with nothing under the cursor) to change cursor types (e.g. from eyeball (look at) to walk, or attack). As things are now, I have a context menu popping up at all the wrong moments.

If I understand you correctly, that's odd; I specifically made the banner menu only pop up if there was no option for the cursor to change. That is, previously, if you right clicked only the walk cursor was available. Today I have noticed that the banner context does not always pop up in this situation if "new selection" is disabled. It does not pop up in unintended situations, just fails to pop up when it should do; I'll be looking into that today.

 

As for having a config option to enable/disable each context menu, I don't know. One reason for adding this feature was to cut down on config options. I did think about doing this, or at least having one global option for all the context menus. However, if someone adds a context menu as the only interface to something, we don't want to be able to disable it. How about we see if anyone else has an opinion while I think some more... Thanks for your feedback though. :)

Share this post


Link to post
Share on other sites

I've stopped the banner context menu popping up while cancelling dragging or using and item.

 

The issue with new selection is weird and I hope someone like Schmurk can comment. With new selection enabled, the object_under_mouse variable is set to -1 for the normal background such as the ground and so I the code to pop up the banner context works fine. Without new selection (not compiled in or just config disabled), the same background objects have object_under_mouse set to 0; so the test to open the banner context fails. I could change the code in gamewin.c to check for <=0 which looks to work fine but I'd like some others opinions. :)

Share this post


Link to post
Share on other sites

The right clicking menus are nice! I do have just one comment on it though, I don't like how when you right click anywhere on the screen that's not on an object/actor it gives you that menu about nametags, etc...can that only come up if you actually click on the name/healthbar? I think it's annoying coming up all over the place the way it is.

Share this post


Link to post
Share on other sites
The right clicking menus are nice! I do have just one comment on it though, I don't like how when you right click anywhere on the screen that's not on an object/actor it gives you that menu about nametags, etc...can that only come up if you actually click on the name/healthbar? I think it's annoying coming up all over the place the way it is.

OK, you're the third person to say the same. I'll have a look what I can do with clicking on the banners or something but as Vegar just pointed out to me, if the banners are totally off, where do you click. I can always remove the banner context completely if nothing else can be done.

Share this post


Link to post
Share on other sites
... I don't like how when you right click anywhere on the screen that's not on an object/actor it gives you that menu about nametags, etc...can that only come up if you actually click on the name/healthbar?

I've changed the banner context menu to only pop-up if you right-click on your actors banner. If the banner is completely off, the menu pops up if you click approximately where the banner would be. As there is now only a small activation point, I've also changed things so that the menu pops up even if there is an object under the mouse - though only once in the cycle of cursors changes. Is that any better?

 

Actually, the new selection is done by Daniel (Xaphier). I'll let him know about it when I see him online.

Doh! OK. I also just noticed that with new selection off, you sometimes get a harvest cursor when you right click over your actors banner, even if there is nothing to harvest behind it. I checked the 1.6.0 release client and that has this issue too so its not down to me. :)

Share this post


Link to post
Share on other sites

Very good job on the new context menus.

 

Just some minor issues with the cut/copy/paste menu on console:

* the menu doesn't close when you leave console

* cut doesn't work at all

* cut and copy shouldn't be available (or disabled) when you haven't marked text and the mouse isn't in the input line (this also goes for the notepad)

* cut shouldn't be available (or disabled) on read-only the logs

Share this post


Link to post
Share on other sites
Just some minor issues with the cut/copy/paste menu on console:

Yeah, you're right. I have thought about doing do all of that. The context menus have options for greying out lines but I didn't get round to setting all that up that for the edit menu. I'll see if I can address your points over the weekend... Thanks :)

Edit: misread what you said about notepad so removed comment...

Edited by bluap

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×