Home » MODDING HQ 1.13 » v1.13 Coding Talk » My popup widget (again) along with a demo
My popup widget (again) along with a demo[message #285561] Sun, 03 July 2011 23:26 Go to next message
The_Bob

 
Messages:406
Registered:May 2009
Location: Behind you.
or...
A quick attachment selection widget, based on my (updated) popup code.

[color:#EE0000]OLD VERSION:[/color]
http://www.fileden.com/files/2008/7/29/2025585//popup.7z

[color:#660000]Latest version in SVN 4622[/color]
...So either scroll down for my exe or grab the latest SCI, it should have this feature already.

http://www.fileden.com/files/2008/7/29/2025585//popup4.png

file contents:
JA2_PO_Release.exe	- a demo exe built with the attached patch, based on SVN 4553
popup.patch 		- a patch to SVN 4553 that should yield the exe
			  note that the patch is created one dir above 'Build'
popup.noareafix.patch	- above patch without the mouse area fix, for a clear picture
			  since the fix alters ~50 files. This version will crash easily.


The demo / quick attachment selection widget:
It should show up after clicking on an empty attachment slot, provided these criteria are met:
we are on the mapscreen
the sector inventory is open
the selected merc is in this sector
there is no combat in this sector

The popup will list attachments available for the given slot on the current weapon. Ones not in sector inventory will be greyed out.
It only considers the stuff in the sector inventory. The order in which attachments are picked depends on which one the widget finds first.

Just drop the .exe in your gamedir and it should work with the current (SVN 4553) game files.

Known bugs (quick attachment widget):
	The bullet icon overlaps muzzle/taclight boxes
	Boxes may extend beyond the attachment window, in which case they may:
	-	be covered by surrounding graphics
	-	not respond to mouse events properly
	-	not clean up the boxes completely, leaving parts of borders/background until the next screen refresh
	If an attachment is removed from the attachment window and placed in the sector inventory, it will not be immediately accounted for by the widget.

In other words, there's still stuff to be fixed, but it works, and since I don't know when will I be able to work on this project again, I figured I'd be better to let anyone interested use it as it is. Bug reports are welcome, so is constrictive criticism of my code.

The popup:
The popup widget is an abstraction layer between the low-level popup menu framework present in JA2 and what usually needs to be done. To reproduce effects presented in the examples below, the low-level code would've taken a few screenfulls of code.
It is still an early version, so not everything is customizable, more elaborate boxes
(eg. sector summary + inventory button) are not yet possible through my code. So far I've concentrated
on making it work (at all) and relative stability. And it works, or at least when I test it it seems to work.

The callbacks:
In order to make life easier for myself, I put together a simple template-based function wrapper (a c++ functor I suppose)
which I use to bind callbacks to the popup box. So far I have one abstract class, PopupCallback, and one used for binding
c++ functions with one or zero parameters, like so:
	returnType someFunction(paramType param){/*...*/}

	popupCallback * fun = new popupCallbackFunction(&someFunction,paramValue);

Either of the parameters can be of type void
	returnType someOtherFunction(void){/*...*/}
	void anotherFunction(paramType param){/*...*/}

	popupCallback * fun2 = new popupCallbackFunction(&someOtherFunction);
	popupCallback * fun3 = new popupCallbackFunction(&anotherFunction,paramValue);

These callbacks then nicely fit into the popup box class and its options

POPUP * p = new POPUP();
p->setCallback(POPUP_CALLBACK_SHOW,fun);

p->addOption( &std::wstring( L"Run the fun again" ), fun );

POPUPOPTION * o = new POPUPOPTION(&std::wstring( L"Run more fun" ), fun );
o->setAvail( fun2 );	// available only when fun2 returns something (whatever it is) that evaluates to TRUE.
o->setHover( fun3 );	// calls fun3 when mouse flies over it.

p->addOption(o);


The popup menu itself has four callbacks so far:
POPUP_CALLBACK_INIT 	(before creating the menu)
POPUP_CALLBACK_SHOW 	(before running the code that registers and displays the popup)
POPUP_CALLBACK_HIDE 	(after hiding)
POPUP_CALLBACK_END	(at the end of the class destructor)


Also, each option has three:
setAction(popupCallback*fun);	(what happens when it gets clicked)
setAvail(popupCallback *fun);	(should return BOOLEAN, the option will be greyed out on false, eg. areWeInTactical() )
setHover(popupCallback *fun);	(this would be called whenever mouse moves over the option. Could highlight items in sector inv. or do other fancy stuff.)	


I have plans for restoring Lua support in the popup box, but so far that's what they are, just plans.

Here's a tiny example of how the popup could be used in practice.
Unfortunately, I lack the will to produce anything substantial at this point, so printing silly messages will have to do.

in Turn Based Input.cpp
in function GetPolledKeyboardInput
in real time processing block add:
	if( _KeyDown( TAB ) && _KeyDown( SHIFT ) && !gfTacticalHelpPopup )
	{
		TacticalHelpPopup();
	}

TacticalHelpPopup.cpp:
	// some other includes
	#include "popup_class.h"
	#include "popup_callback.h"
	#include "TacticalHelpPopup.h"

	BOOLEAN gfTacticalHelpPopup = FALSE;
	POPUP * thp = NULL;

	void TacticalHelpPopup_hide(void){
		gfTacticalHelpPopup = FALSE;
	}

	void TacticalHelpPopup_test(void){
		ScreenMsg( FONT_MCOLOR_LTYELLOW, MSG_INTERFACE, L"TACTICAL HELP TEST" );
	}

	void TacticalHelpPopup_test2(void){
		ScreenMsg( FONT_MCOLOR_LTYELLOW, MSG_INTERFACE, L"TACTICAL HELP TEST 2" );
	}

	void TacticalHelpPopup(){

		// just to make sure that something _shoud_ appear suun
		ScreenMsg( FONT_MCOLOR_LTYELLOW, MSG_INTERFACE, L"TACTICAL HELP POPUP!" );

		// if we don't have a popup yet, create and setup one
		if ( !thp ){
			// create a popup
			thp = new POPUP("TACTICAL PLEH POPUP");	// at this point the name is used mainly for debug output
			
			// add a callback that lets the keyboard handler know we're done (and ready to pop up again)
			thp->setCallback(POPUP_CALLBACK_HIDE, new popupCallbackFunction( &TacticalHelpPopup_hide ) );
			
			// add two options as a test
			thp->addOption( &std::wstring( L"Test the popup" ), new popupCallbackFunction( &TacticalHelpPopup_test ) );
			thp->addOption( &std::wstring( L"Test the popup again" ), new popupCallbackFunction( &TacticalHelpPopup_test2 ) );
		} 
		
		// either way, we should have a popup at this point
		thp->show();
		gfTacticalHelpPopup = TRUE;
	}

TacticalHelpPopup.h:
	#ifndef TACTICAL_HELP_POPUP

		#define TACTICAL_HELP_POPUP

		extern BOOLEAN gfTacticalHelpPopup;
		extern void TacticalHelpPopup();

	#endif


Also, here are the source files (drop/overwrite on SVN 4553) in case the patch gives you any trouble. This is not a complete SVN checkout.
http://www.fileden.com/files/2008/7/29/2025585//Build.4553.7z
And here, just the popup class. It should just work when added to a 1.13 VC++ project.
http://www.fileden.com/files/2008/7/29/2025585//4.7z

Re: My popup widget (again) along with a demo[message #285592] Mon, 04 July 2011 11:42 Go to previous messageGo to next message
putadshere

 
Messages:16
Registered:June 2010
Looks neat, but I can't seem to see the screenshots you posted. Am I missing something?
Re: My popup widget (again) along with a demo[message #285604] Mon, 04 July 2011 12:56 Go to previous messageGo to next message
The_Bob

 
Messages:406
Registered:May 2009
Location: Behind you.
Nah, this ain't a visually intensive mod. Not much to show anyway.

BTW, I ran into a bug in my code, the popups stop reacting to mouse clicks after 255 of them have been created/destroyed. I already fixed this and will upload an updated version when I have the time.

In case the popup gets stuck and nothing else can be clicked, pressing escape will close it. Restarting the game temporarily fixes the problem.

Re: My popup widget (again) along with a demo[message #286839] Mon, 18 July 2011 00:50 Go to previous messageGo to next message
The_Bob

 
Messages:406
Registered:May 2009
Location: Behind you.
Update:

http://www.fileden.com/files/2008/7/29/2025585//PACK2.7z

Package contents:
POPUP2.patch		patch file for 1.13 SVN 4573
JA2_PO_Release.exe	latest(SVN 4573) binary with the quick attachment popup
popup/*			popup widget code, should work with most recent 1.13 versions
demo/*			some demo code for the popup, nothing fancy


Fixes:
Fixed the id overflow bug (caused popups to stop responding after a while)
Restored sub-popup functionality
Properly highlight available attachments after one was just removed and put in sector inventory.

To run the demo press shift-tab in tactical, it just shows a popup menu with some nested submenus. Its just a thingy that shows that this thing works. Let me know if it doesn't Wink

Re: My popup widget (again) along with a demo[message #286941] Mon, 18 July 2011 21:57 Go to previous messageGo to next message
Anonymous
Nice work man.
Re: My popup widget (again) along with a demo[message #286956] Tue, 19 July 2011 01:19 Go to previous messageGo to next message
The_Bob

 
Messages:406
Registered:May 2009
Location: Behind you.
Minor update:

http://www.fileden.com/files/2008/7/29/2025585//popup3.7z

The 7z contents are similar to the previous package, sans the demo files. The binary is SVN 4579 with updated game version info and the quick attachment popup.

This time I actually checked if the patch file works and it seems to work ok on a separate SVN checkout. Let me know if it gives you any trouble. This time the patch file was made from the Build folder, rather then the one above it. It was made from SVN 4579, just like the attached binary.

The popup source files now have a fix that makes them work without remapping all of the mouse area priorities in the code.

I dropped the mouse region priority fix, I think I've found an acceptable workaround. This reduces the changes to three source files (+ the project file and three new ones) and appears to work well enough. Still, I think there should be more priority levels defined and most things currently assigned to MSYS_PRIORITY_HIGHEST can be reduced to something less extreme.

edit: Also, here's the Russian version of the exe: http://www.fileden.com/files/2008/7/29/2025585//JA2_PO_Release_ru.7z

[Updated on: Wed, 20 July 2011 00:08] by Moderator


Re: My popup widget (again) along with a demo[message #287211] Thu, 21 July 2011 02:15 Go to previous messageGo to next message
The_Bob

 
Messages:406
Registered:May 2009
Location: Behind you.
http://www.fileden.com/files/2008/7/29/2025585//popup4.png

update: http://www.fileden.com/files/2008/7/29/2025585//popup4.7z
(built on SVN 4579)

fixes (quick attachment popup):
fixed problems with popups extending beyond the description box (and looking weird there)
fixed the problem with the bullet icon overlapping the popup boxes

changes (popup widget):
Fixed positioning code (was a bit random. Now it is less random.)
Added more positioning options (set coordinates translated to top/bottom, left/right corners of the box)
Added options to position sub-popups (relative to parent or absolute)


The quick attachment popup is an example of how this stuff works in practice.

Also:
The patch file (contained in the package above): http://www.fileden.com/files/2008/7/29/2025585//POPUP4.patch

Russian exe: http://www.fileden.com/files/2008/7/29/2025585//JA2_PO_Release_ru.2.7z

let me know if I should build other languages.

Re: My popup widget (again) along with a demo[message #287213] Thu, 21 July 2011 02:20 Go to previous messageGo to next message
PasHancock

 
Messages:738
Registered:February 2011
Location: Estonia,Tallinn
thanks bob,for Russian Version,i will download it later(gotta go sleep)
Re: My popup widget (again) along with a demo[message #287214] Thu, 21 July 2011 02:25 Go to previous messageGo to next message
Cell

 
Messages:618
Registered:February 2011
User deleted
Re: My popup widget (again) along with a demo[message #287284] Fri, 22 July 2011 08:56 Go to previous messageGo to next message
usrbid

 
Messages:1558
Registered:December 2008
Wow, awesome work Bob!! Well, he is an SMP coder after all... Very Happy


Re: My popup widget (again) along with a demo[message #287288] Fri, 22 July 2011 10:31 Go to previous messageGo to next message
The_Bob

 
Messages:406
Registered:May 2009
Location: Behind you.
I've noticed there still are cases in which the popups spill out of the description area and get messed up. In particular, when attaching grenades to 6-shot GLs (bottom two) and when selecting attachments that go on the underslung grenade launcher. Also, attachment slots created by attaching new items are not handled yet - in particular, the slot for bipod/foregrip attached on the GL and the grenade slot. Reopening the item description fixes the last problem.

Additionally, the first UDB tab disappears when the popups are open. This might be a bug in the button system code since it started to happen after I hid the bullet icon(button).

I'll try to fix these in the next update, which should be sometime this weekend.

Re: My popup widget (again) along with a demo[message #287459] Sun, 24 July 2011 01:47 Go to previous messageGo to next message
The_Bob

 
Messages:406
Registered:May 2009
Location: Behind you.
Update: http://www.fileden.com/files/2008/7/29/2025585//POPUP5.7z

This time its only the patch file and the .exe, no important changes were made to the popup class.

Fixes (quick attachment popup):
- Fixed the disappearing UDB tab
- Repositioned popups to (mostly) fit in the item frame
- Fixed popups on dynamically added attachment slots

Additionally, this .exe has my patch for the crash that may happen when entering Estoni, it was likely introduced in the recent (officially unreleased) SVN versions. A patch file for that is here.

Re: My popup widget (again) along with a demo[message #289426] Fri, 19 August 2011 10:15 Go to previous messageGo to next message
RoWa21

 
Messages:2039
Registered:October 2005
Location: Austria
@The_Bob: I tried to include your patch file in the latest official source, but the game always ASSERTS, when trying to select an attachment from your popup list.

The assertion takes place in "popupbox.cpp", Line 1067.

I also tried your compiled EXE and with your EXE it works fine. So maybe the patch (popup5.7z) is not the latest one. Can you please upload your latest patch file, cause I really like to include that in official 1.13.

Thanks.


Re: My popup widget (again) along with a demo[message #289579] Sun, 21 August 2011 17:01 Go to previous messageGo to next message
Searry

 
Messages:12
Registered:June 2009
I encountered a weird bug in AIMNAS v20 with big strat map(tais' version).

Enemy attacked Alma northwest but the autoresolve between the government and militia didn't happen.
Now they just coexist peacefully together. Very Happy
This doesn't happen with the exe that came with the SCI.

Great work BTW! UI is still the biggest issue in this game. :3

[Updated on: Sun, 21 August 2011 17:02] by Moderator

Re: My popup widget (again) along with a demo[message #289580] Sun, 21 August 2011 17:23 Go to previous messageGo to next message
PasHancock

 
Messages:738
Registered:February 2011
Location: Estonia,Tallinn
what does UI means?
Re: My popup widget (again) along with a demo[message #289581] Sun, 21 August 2011 17:59 Go to previous messageGo to next message
takami

 
Messages:12
Registered:August 2011
User Interface?

Not that I'd agree though :confused:
Re: My popup widget (again) along with a demo[message #289587] Sun, 21 August 2011 20:46 Go to previous messageGo to next message
The_Bob

 
Messages:406
Registered:May 2009
Location: Behind you.
Here's the latest ( SVN 4619 ) version of my exe along with a patch file and patched files.
http://www.fileden.com/files/2008/7/29/2025585//A.7z

No changes since the previous release, at least not on my end.


Re: My popup widget (again) along with a demo[message #289596] Mon, 22 August 2011 00:22 Go to previous messageGo to next message
Randok

 
Messages:313
Registered:March 2004
I tried your popup. It is super.
@RoWa21 When it will be in 1.13?
Smile
Re: My popup widget (again) along with a demo[message #289597] Mon, 22 August 2011 00:25 Go to previous messageGo to next message
PasHancock

 
Messages:738
Registered:February 2011
Location: Estonia,Tallinn
Randok,wait for new Release,Rowa also has to make this popup on all Languages(German,Russian,Polish)
Re: My popup widget (again) along with a demo[message #289598] Mon, 22 August 2011 00:47 Go to previous messageGo to next message
Randok

 
Messages:313
Registered:March 2004
I wait for new Realise.
And I wait too for your super new animations Smile

[Updated on: Mon, 22 August 2011 09:37] by Moderator

Re: My popup widget (again) along with a demo[message #289599] Mon, 22 August 2011 00:56 Go to previous messageGo to next message
The_Bob

 
Messages:406
Registered:May 2009
Location: Behind you.
Update:

devel branch (SVN 4618): http://www.fileden.com/files/2008/7/29/2025585//dev.7z
stable branch (SVN 4619): http://www.fileden.com/files/2008/7/29/2025585//stable.7z

I added some sanity checks to the popup class and fixed the attachment callback which (potentially) messed things up a bit. Everything should work like it did before, maybe even a tiny bit faster. Still no changes though, just fixes.

Let me know if this last version bugs you with too many failed assertions in popup_class.cpp file.

Re: My popup widget (again) along with a demo[message #289600] Mon, 22 August 2011 01:25 Go to previous messageGo to next message
PasHancock

 
Messages:738
Registered:February 2011
Location: Estonia,Tallinn
Randok
I wait for new Realise.
And I wait too for your super new animation Smile


Well Sandro's progress is 50% in implementing new animation,lets hope that he will implement it at least at this week.
Re: My popup widget (again) along with a demo[message #289605] Mon, 22 August 2011 09:52 Go to previous messageGo to next message
Randok

 
Messages:313
Registered:March 2004
Do you can do when it gets popup shopping? When I buy a gun, show a possible attachments. It would be nice if I can select from this list selected for shopping.
Re: My popup widget (again) along with a demo[message #289606] Mon, 22 August 2011 09:59 Go to previous messageGo to next message
Cell

 
Messages:618
Registered:February 2011
User deleted
Re: My popup widget (again) along with a demo[message #289717] Tue, 23 August 2011 21:38 Go to previous messageGo to next message
The_Bob

 
Messages:406
Registered:May 2009
Location: Behind you.
The last version of my popup widget / quick attachment popup have been added to the SVN trunk.

Thus, coders can now easily create popup windows and users may quickly outfit their guns without relying on a custom exe.

Please report any crashes and failed assertions that happen while using the quick attachment popup in this thread.

Ideas and feature requests go in the other thread.


Re: My popup widget (again) along with a demo[message #293522] Mon, 14 November 2011 17:32 Go to previous messageGo to next message
usrbid

 
Messages:1558
Registered:December 2008
Damn nice work Bob!! What do you want to work on next, any ideas?


Re: My popup widget (again) along with a demo[message #293689] Wed, 16 November 2011 16:14 Go to previous messageGo to next message
The_Bob

 
Messages:406
Registered:May 2009
Location: Behind you.
When I get some free time, I'll try doing some of the things I mentioned in the other thread. Stuff to make inventory selection a bit smoother. I dunno when will that happen though, life looks pretty busy nowadays.

Re: My popup widget (again) along with a demo[message #293700] Wed, 16 November 2011 21:08 Go to previous messageGo to next message
Headrock

 
Messages:1781
Registered:March 2006
Location: Jerusalem
Wow Bob, this is ridiculously useful, and when I use the term ridiculously I mean "to degrees man had not yet conceived". There are about a zillion applications to this... and I'm about to create one.


Re: My popup widget (again) along with a demo[message #293704] Wed, 16 November 2011 21:33 Go to previous messageGo to next message
Headrock

 
Messages:1781
Registered:March 2006
Location: Jerusalem
I do have one question: How do I destroy the menu after it's been created? I used your demo template above to create mine (it worked like a charm), but I need a way to not just hide it, but remove it from memory so it can be recreated later without wasting more memory space... I looked through the operators for the POPUP struct but couldn't find anything relevant to this.

Help?

[EDIT: Yeah deleting the damn popup didn't actually work in practice. I got an exception]

Also, I've got build 4792, but I don't have the POPUPOPTION struct... Hard to work without that, especially because I can't find any other way to set an option as unavailable...

Ok, it's POPUP_OPTION now, that should probably be stated above.

However the setAvail() function doesn't seem to be working. I set it to a function that always returns false, and that didn't do anything - the option is still green (valid) and clickable.

Yeah, I forgot to set the return value as bool (it was void). So that works now.

Finally, is there a way to set tooltips while hovering over an option? I saw that options have the "hint" variable, but it doesn't seem to be used at all. Should I be making tooltips appear manually?


Re: My popup widget (again) along with a demo[message #293725] Thu, 17 November 2011 12:19 Go to previous messageGo to next message
The_Bob

 
Messages:406
Registered:May 2009
Location: Behind you.
Headrock
Wow Bob, this is ridiculously useful, and when I use the term ridiculously I mean "to degrees man had not yet conceived". There are about a zillion applications to this... and I'm about to create one.


Thanks. Let me know if the widget gives you more trouble then it should.

Creating a wrapper for the old popup box code was IMO necessary, because it took screenfulls of code to do the simplest things.

Headrock
I do have one question: How do I destroy the menu after it's been created? I used your demo template above to create mine (it worked like a charm), but I need a way to not just hide it, but remove it from memory so it can be recreated later without wasting more memory space... I looked through the operators for the POPUP struct but couldn't find anything relevant to this.

Help?

[EDIT: Yeah deleting the damn popup didn't actually work in practice. I got an exception]

Also, I've got build 4792, but I don't have the POPUPOPTION struct... Hard to work without that, especially because I can't find any other way to set an option as unavailable...

Ok, it's POPUP_OPTION now, that should probably be stated above.

Sorry about all that, I probably should have documented it more clearly.

About deleting popups/options, I think there's still a bunch of bugs in the cleanup code somewhere, so make sure to thoroughly test every part where you explicitly delete them. AFAIK, things work just fine in the quick attachment code, so I recommend you use that as a reference - it was a field for the popup widget, helped me fix a lot of tiny bugs and work around some quirks.

Headrock

Finally, is there a way to set tooltips while hovering over an option? I saw that options have the "hint" variable, but it doesn't seem to be used at all. Should I be making tooltips appear manually?


That one didn't make it into the current version. Either add it to the class (should be easy, tooltip code is surprisingly elegant) or try looping over gPopupRegionIndex to find regions for a given popup. In gPopupRegionIndex, regionId property refers to MOUSE_REGION::IDNumber, classId to POPUP::id. Do MSYS_GetRegionUserData( pRegion, 1 ) to see if it triggers an option or a subpopup, MSYS_GetRegionUserData( pRegion, 0 ) to check which one.

I'd prefer the former though, it would be a lot cleaner to do this while creating the popup rather then adding it from the outside. I'm not working on the code right now so you can just add whatever you need to the class and post your (improved) version.

Re: My popup widget (again) along with a demo[message #293727] Thu, 17 November 2011 13:52 Go to previous messageGo to next message
Headrock

 
Messages:1781
Registered:March 2006
Location: Jerusalem
Quote:
About deleting popups/options, I think there's still a bunch of bugs in the cleanup code somewhere, so make sure to thoroughly test every part where you explicitly delete them. AFAIK, things work just fine in the quick attachment code, so I recommend you use that as a reference - it was a field for the popup widget, helped me fix a lot of tiny bugs and work around some quirks.


Unfortunately that wasn't suitable for what I was doing. I had to delete the IDB while the menu was running a callback function, and as a result ended up causing assertion errors. I found another route though, by destroying and recreating the menu each time the appropriate region was clicked. Then I used globals to make sure that the menu is never deleted when it is still running. It was a headache to be sure, but it works now - with little more than delete(menupointer).

So no worries on that. Smile

Quote:
That one didn't make it into the current version. Either add it to the class (should be easy, tooltip code is surprisingly elegant) or try looping over gPopupRegionIndex to find regions for a given popup. In gPopupRegionIndex, regionId property refers to MOUSE_REGION::IDNumber, classId to POPUP::id. Do MSYS_GetRegionUserData( pRegion, 1 ) to see if it triggers an option or a subpopup, MSYS_GetRegionUserData( pRegion, 0 ) to check which one.


Sorry, you lost me there...

I'll see if I can't finagle some simpler system that only works for my pop-up (i.e. a kludge), then that could be removed easily later and replaced with whatever you end up writing officially for the pop-up system.

----

Also there are some things painfully missing from the pop-up system. One is manually setting availability for lines, i.e. not relying on any functions to test availability. Second is setting color for each line individually - which may allow us to make menu headers in a different color. Also stuff like deciding what color an option's highlight would be. It's very cosmetic stuff, but many pop-ups currently use these things to good effect for many purposes, it does feel like I'm missing features I would've had if I could use the game's original pop-up system...

Not that I could use it. I mean, I don't mind writing out lots of text, but I don't think it would've been anywhere near as easy to write a new pop-up menu from scratch. Your functions certainly make it easier to use, it's fantastic work.

p.s. I think your issue with buttons overlapping the pop-ups is because buttons get marked "dirty" and are then redrawn on top of everything else. It should theoretically be possible to just push your pop-ups so that they draw even later than that, causing buttons - even dirty ones - to be drawn below them. I'll see if I can't find a way to do this.


Re: My popup widget (again) along with a demo[message #293744] Thu, 17 November 2011 16:27 Go to previous messageGo to next message
The_Bob

 
Messages:406
Registered:May 2009
Location: Behind you.
Headrock
Also there are some things painfully missing from the pop-up system. One is manually setting availability for lines, i.e. not relying on any functions to test availability. Second is setting color for each line individually - which may allow us to make menu headers in a different color. Also stuff like deciding what color an option's highlight would be. It's very cosmetic stuff, but many pop-ups currently use these things to good effect for many purposes, it does feel like I'm missing features I would've had if I could use the game's original pop-up system...

For manually disabling lines, you can either:
- assign an availability function that just returns false to disable an option, assign one that returns true to enable it.
- try something like this:

bool gOptAvail[2];

bool checkAvail(INT8 i){
  return gOptAvail[i];
}

// o1, o2 are POPUP_OPTIONs
o1->setAvail( new popupCallbackFunction(&checkAvail,0) );
o2->setAvail( new popupCallbackFunction(&checkAvail,1) );

gOptAvail[0] = FALSE; //option 1 unavailable
gOptAvail[1] = TRUE; //option 2 available


As for setting colors - I kinda kept reminding myself about it when working on the popup class, but always found more important stuff that needed fixing before I got around to adding more features.

Headrock
I think your issue with buttons overlapping the pop-ups is because buttons get marked "dirty" and are then redrawn on top of everything else. It should theoretically be possible to just push your pop-ups so that they draw even later than that, causing buttons - even dirty ones - to be drawn below them. I'll see if I can't find a way to do this.


The problem with buttons drawn over popups is caused by two things:
1 - the popup system draws its boxes (all of them, including the ones defined by my popup class - after all, it is just a wrapper) before buttons are drawn. This can't be changed globally since some popups have buttons in them (sector summary, militia assignment...) and there is no easy way of splitting the display process for things defined by my class and the old system.
2 - even if drawn after the buttons (on top of them), the popup boxes are not refreshed every frame. Or at least, not every part of them, IIRC only the text lines are refreshed, the background gets covered up by whatever else is drawn there. I remember from my experiments that even if I forced the popups to be completely redrawn every frame on top of other things, line highlighting didn't work properly.

I think there is no elegant solution for this other then reimplementing the drawing code in my class, so every box can display itself exactly when it should. That looks like a lot of copy-paste though...

Re: My popup widget (again) along with a demo[message #293746] Thu, 17 November 2011 16:43 Go to previous messageGo to next message
Headrock

 
Messages:1781
Registered:March 2006
Location: Jerusalem
Quote:

For manually disabling lines...


Methinks you need to supply one of these functions (the one with the argument) by default so we'll all use the same one. Call it "BOOLEAN Popup_SetAvailability (BOOLEAN fToggle)" or something.

Quote:
As for setting colors - I kinda kept reminding myself about it when working on the popup class, but always found more important stuff that needed fixing before I got around to adding more features.


That's a shame, I think it's very important - even more than tooltips. The #1 reason is to make options that don't get highlighted, but can be clicked (this is how yellow lines work in other pop-up menus).

Or of course, as I said, header lines. Too many menus without titles and headers = confusing interface.

Oh and before I forget it: Determining box justification. It's not always the best idea to align-center, sometimes it's better to align-left. Dunno how complex that would be to do though.

Hopefully if you can get all that stuff working, it may be possible (or indeed crucial) to replace all existing pop-ups with your pop-up system.

Quote:
1 - the popup system draws its boxes (all of them, including the ones defined by my popup class - after all, it is just a wrapper) before buttons are drawn. This can't be changed globally since some popups have buttons in them (sector summary, militia assignment...) and there is no easy way of splitting the display process for things defined by my class and the old system.


Maybe the solution is:
1) Have two points in the code that render the buttons
2) Use a flag assigned to each button to determine whether it gets drawn during the first event or the second event.

Of course then we'd have to figure out which buttons are inside pop-up boxes and which aren't, and flag them all appropriately... so yeah it is a lot of work, but on the other hand you may end up running into worse issues with having to constantly show and hide buttons to keep them from drawing over your menus.

P.S. - From looking at your attachment pop-ups, what I don't understand is why you build them when the IDB is opened. IMHO it might be a significantly better idea to create them when an empty attachment slot is clicked - and only create the specific pop-up menu for that attachment slot. Possibly even destroy the menu when it's hidden. Currently you have a lot of different values being monitored and altered in many different places just because you're keeping all these menus "alive" and hidden in the background - regardless of whether the user is even aware that they exist...


Re: My popup widget (again) along with a demo[message #293772] Thu, 17 November 2011 20:52 Go to previous messageGo to next message
Headrock

 
Messages:1781
Registered:March 2006
Location: Jerusalem
(on tooltips)

Quote:
That one didn't make it into the current version. Either add it to the class (should be easy, tooltip code is surprisingly elegant) or try looping over gPopupRegionIndex to find regions for a given popup. In gPopupRegionIndex, regionId property refers to MOUSE_REGION::IDNumber, classId to POPUP::id. Do MSYS_GetRegionUserData( pRegion, 1 ) to see if it triggers an option or a subpopup, MSYS_GetRegionUserData( pRegion, 0 ) to check which one.


Surprisingly the solution was actually much simpler. The POPUP struct contains the MOUSE_REGIONs for the menu lines - and it is possible to simply run SetFastHelpText on each of these mouse regions while creating each menu line! The game handles everything else automagically, so I've got tooltips working now! Very Happy

[EDIT] This is not without issues either. The help-text has to be set up AFTER the popup is initialized with the "show()" operator - otherwise I get an assertion error for trying to change the tooltip text. That means having to iterate through all the possible transformations first to create each menu line, then showing the menu, and then iterate through the transformations AGAIN to read each one's tooltips and apply them correctly to the lines. This is a mess.


Re: My popup widget (again) along with a demo[message #293781] Thu, 17 November 2011 23:18 Go to previous messageGo to next message
Cell

 
Messages:618
Registered:February 2011
User deleted
Re: My popup widget (again) along with a demo[message #293802] Fri, 18 November 2011 12:26 Go to previous messageGo to next message
The_Bob

 
Messages:406
Registered:May 2009
Location: Behind you.
@Monade: I won't be making anything like that anytime soon. When I get the time to do some work on, I will improve the popup class a bit and perhaps code some more inventory management helpers.

@Headrock: I thought that the method that creates mouse areas for each menu line would be the right place to add tooltips. IIRC They are created and destroyed every time the box is shown and destroyed when hiding it. It should work as long as you properly destroy the tooltips when hiding the menu.

Re: My popup widget (again) along with a demo[message #293807] Fri, 18 November 2011 13:50 Go to previous messageGo to next message
Headrock

 
Messages:1781
Registered:March 2006
Location: Jerusalem
Quote:
@Headrock: I thought that the method that creates mouse areas for each menu line would be the right place to add tooltips. IIRC They are created and destroyed every time the box is shown and destroyed when hiding it. It should work as long as you properly destroy the tooltips when hiding the menu.


I see, that would explain it. Well as I said, these problems are less relevant to me because I completely destroy+recreate the box every time it is activated, which IMHO you should've done with your attachment popups as well - no need to create them all in advance.

BTW adding tooltips AFTER the menu is created is... also not the best idea. I would imagine that any menu created dynamically will be drawing the titles for each row to construct the menu, so it would make more sense to assign tooltips at the same time because they're probably drawn from the same source. For me, I draw the titles and tooltip text from the same source, but now I have to do it twice - once when constructing the menu, and once after it's shown. Needlessly tricky.

Also, there's no logistical reason to create mouse-regions only when a menu is rendered - they should exist from the moment of creation. If you don't want interaction with the menu while it's hidden, you can always set those mouse-regions to "disabled" state. But again, it makes much more sense to ONLY create a menu just before it appears on-screen, and destroy it after it's removed from the screen.

I hope that wasn't too confusing...


Re: My popup widget (again) along with a demo[message #293819] Fri, 18 November 2011 14:45 Go to previous messageGo to next message
The_Bob

 
Messages:406
Registered:May 2009
Location: Behind you.
Headrock
I see, that would explain it. Well as I said, these problems are less relevant to me because I completely destroy+recreate the box every time it is activated, which IMHO you should've done with your attachment popups as well - no need to create them all in advance.


The reason I define all the boxes in the function responsible for showing EDB is that there already is a loop there that goes through all the attachments the given slot can take, along with all the variables initialized and loaded with data for me to use. I'd have to copy that loop to the attachment slot click callback to create the boxes only when they are needed.

The availability function that searches the sector inventory is only called when the box is displayed, so I'm not adding too much overhead to EDB display function.

Headrock

Also, there's no logistical reason to create mouse-regions only when a menu is rendered - they should exist from the moment of creation. If you don't want interaction with the menu while it's hidden, you can always set those mouse-regions to "disabled" state. But again, it makes much more sense to ONLY create a menu just before it appears on-screen, and destroy it after it's removed from the screen.


Its a lot easier to create them when displaying the menu, destroy them when hiding it - otherwise I'd need to keep track of whether the menu was changed somehow - option names changed or an option being no longer available - and update the mouse areas then. It would be more elegant, I know, that's the best I could do given the limited amount of time.

Also, that's how the old popup box system works, or at lest the parts I used as reference. Most of the class is just the militia command box split into more or less logical chunks and fed class variables rather then the old, hardcoded ones.

I'm not even past the point of implementing all of the old popup box functionality in my class, so improvements and optimizations will have to wait. Right now its still a bit of a patchwork of old and new code, but at least it works well enough to be usable.

Ultimately, popup options should be creating their own mouse areas and be aware of their regions on screen, passing them to their callbacks somehow, along with references to themselves and their parent.

Re: My popup widget (again) along with a demo[message #293823] Fri, 18 November 2011 15:03 Go to previous messageGo to next message
Headrock

 
Messages:1781
Registered:March 2006
Location: Jerusalem
Quote:
The availability function that searches the sector inventory is only called when the box is displayed, so I'm not adding too much overhead to EDB display function.


It's much less a question of overhead than it is of manageability (though currently it takes ages to open the DB in Debug Mode, though I guess NAS is mostly to blame for this).

Moreso it's a question of managing the menus. Why create a dozen menus and keep them alive in the background, when only one will actually appear and by used at any given time?

Of course, if you want to ride a loop that already exists, I guess that's one reason to do so, but I think that for the code's sake it may still be better to create them only when they are actually being activated.

Quote:
Its a lot easier to create them when displaying the menu, destroy them when hiding it - otherwise I'd need to keep track of whether the menu was changed somehow - option names changed or an option being no longer available - and update the mouse areas then. It would be more elegant, I know, that's the best I could do given the limited amount of time.


Yeah, as I said this issue is moot if the menu is only created when you're going to use it, and destroyed afterwards (or, as I'm doing now, recreated every time it's about to be used). That way all data on the menu is ALWAYS relevant because you've just created it and can't do anything else until it's destroyed.

Quote:
Also, that's how the old popup box system works, or at lest the parts I used as reference. Most of the class is just the militia command box split into more or less logical chunks and fed class variables rather then the old, hardcoded ones.


The Militia Box may not have been the best example to work with - since it was made for 1.13, rather than originating from JA2... The Assignment Menu probably would've been a better "role-model"...

Quote:
I'm not even past the point of implementing all of the old popup box functionality in my class, so improvements and optimizations will have to wait. Right now its still a bit of a patchwork of old and new code, but at least it works well enough to be usable.


As I said, I'm patient - and I hope that some day your system can replace ALL existing pop-ups.

Quote:

Ultimately, popup options should be creating their own mouse areas and be aware of their regions on screen, passing them to their callbacks somehow, along with references to themselves and their parent.


That would be ideal.


Re: My popup widget (again) along with a demo[message #299466] Sun, 19 February 2012 22:09 Go to previous messageGo to previous message
The_Bob

 
Messages:406
Registered:May 2009
Location: Behind you.
Update:

popup class:
Fixed a tiny bug in the popup class dealing with option count,
added support for callbacks with 2 and 3 parameters. Use them like this:
popupCallbackFunction2(void * newFun, P1 param, P2 param2) // two params, some return value
popupCallbackFunction2(void * newFun, P1 param, P2 param2) // two params, no return value

popupCallbackFunction3(void * newFun, P1 param, P2 param2, P3 param3) // three params, some return value
popupCallbackFunction3(void * newFun, P1 param, P2 param2, P3 param3) // three params, no return value

// in short, popupCallbackFunction2 for two params, popupCallbackFunction3 for three.
// return type goes first, omit it for void.

new widget:
I'm working on a mag-maker widget - a thingy that created magazines (also clips, loose rounds and soon ammo boxes) for the weapons in merc inventory.

how to use it:
make sure the sector with your merc is loaded (best go to tactical then back to mapscreen), open sector inventory, open merc inventory (order irrelevant), click empty inventory slots in merc inventory. A popup will show up listing available ammo types for weapons in selected merc's inventory.

how it works, and when:
ammo is taken only from ammo crates. the boxes show only when in sector inventory, outside of combat, only for mercs in active sector.

It is still an early version, so expect bugs. One nasty bug that I know of is that creating mags is somehow slow. I've yet to find out why.

http://www.fileden.com/files/2008/7/29/2025585/ammoPopups2.png

source: http://www.fileden.com/files/2008/7/29/2025585/ammoPopupSrc.7z
recent exe: http://www.fileden.com/files/2008/7/29/2025585/JA2_PO_Release_4947.7z
old exe:http://www.fileden.com/files/2008/7/29/2025585/JA2_PO_Release_old.7z

edit:
Look for 'THE_BOB' to find my recent changes, also in (in case anyone has a use for these) are two functions I made for this:
std::vector * getSoldierGuns( SOLDIERTYPE *pTeamSoldier ) // returns a vector of guns (and launchers I think) found on the soldier
UINT16 pocketTypeInSlot(SOLDIERTYPE *pSoldier, INT16 sPocket) 	// matches the pocket to the stuff in Pockets.xml / LBEPocketType vector 
								// eg. LBEPocketType[pocketTypeInSlot(pSoldier, pocket)] 

[Updated on: Sun, 19 February 2012 22:19] by Moderator


Previous Topic: New BR Misc Filters
Next Topic: STOMP ( v1.2 )
Goto Forum:
  


Current Time: Wed Oct 17 02:01:42 EEST 2018

Total time taken to generate the page: 0.01548 seconds