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
|
|
The_Bob |
![](/images/ranks/master_sergeant.png) |
Messages:415
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](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
Report message to a moderator
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: My popup widget (again) along with a demo[message #293704]
|
Wed, 16 November 2011 21:33 ![Go to previous message Go to previous message](/theme/Bear_Classic_Brown/images/up.png)
|
|
Headrock |
![](/images/ranks/sergeant_major.png) |
Messages:1760
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?
Report message to a moderator
|
|
|
|
Re: My popup widget (again) along with a demo[message #293725]
|
Thu, 17 November 2011 12:19 ![Go to previous message Go to previous message](/theme/Bear_Classic_Brown/images/up.png)
|
|
The_Bob |
![](/images/ranks/master_sergeant.png) |
Messages:415
Registered:May 2009 Location: Behind you. |
|
|
HeadrockWow 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.
HeadrockI 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.
Report message to a moderator
|
|
|
|
Re: My popup widget (again) along with a demo[message #293727]
|
Thu, 17 November 2011 13:52 ![Go to previous message Go to previous message](/theme/Bear_Classic_Brown/images/up.png)
|
|
Headrock |
![](/images/ranks/sergeant_major.png) |
Messages:1760
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](images/smiley_icons/icon_smile.gif)
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.
Report message to a moderator
|
|
|
|
Re: My popup widget (again) along with a demo[message #293744]
|
Thu, 17 November 2011 16:27 ![Go to previous message Go to previous message](/theme/Bear_Classic_Brown/images/up.png)
|
|
The_Bob |
![](/images/ranks/master_sergeant.png) |
Messages:415
Registered:May 2009 Location: Behind you. |
|
|
HeadrockAlso 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.
HeadrockI 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...
Report message to a moderator
|
|
|
|
Re: My popup widget (again) along with a demo[message #293746]
|
Thu, 17 November 2011 16:43 ![Go to previous message Go to previous message](/theme/Bear_Classic_Brown/images/up.png)
|
|
Headrock |
![](/images/ranks/sergeant_major.png) |
Messages:1760
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...
Report message to a moderator
|
|
|
|
Re: My popup widget (again) along with a demo[message #293772]
|
Thu, 17 November 2011 20:52 ![Go to previous message Go to previous message](/theme/Bear_Classic_Brown/images/up.png)
|
|
Headrock |
![](/images/ranks/sergeant_major.png) |
Messages:1760
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](images/smiley_icons/icon_biggrin.gif)
[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.
Report message to a moderator
|
|
|
|
|
Re: My popup widget (again) along with a demo[message #293807]
|
Fri, 18 November 2011 13:50 ![Go to previous message Go to previous message](/theme/Bear_Classic_Brown/images/up.png)
|
|
Headrock |
![](/images/ranks/sergeant_major.png) |
Messages:1760
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...
Report message to a moderator
|
|
|
|
Re: My popup widget (again) along with a demo[message #293819]
|
Fri, 18 November 2011 14:45 ![Go to previous message Go to previous message](/theme/Bear_Classic_Brown/images/up.png)
|
|
The_Bob |
![](/images/ranks/master_sergeant.png) |
Messages:415
Registered:May 2009 Location: Behind you. |
|
|
HeadrockI 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.
Report message to a moderator
|
|
|
|
Re: My popup widget (again) along with a demo[message #293823]
|
Fri, 18 November 2011 15:03 ![Go to previous message Go to previous message](/theme/Bear_Classic_Brown/images/up.png)
|
|
Headrock |
![](/images/ranks/sergeant_major.png) |
Messages:1760
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.
Report message to a moderator
|
|
|
|
Re: My popup widget (again) along with a demo[message #299466]
|
Sun, 19 February 2012 22:09 ![Go to previous message Go to previous message](/theme/Bear_Classic_Brown/images/up.png)
|
|
The_Bob |
![](/images/ranks/master_sergeant.png) |
Messages:415
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](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 Report message to a moderator
|
|
|
|
|
|
|
Goto Forum:
Current Time: Mon Feb 17 09:25:24 GMT+2 2025
Total time taken to generate the page: 0.01830 seconds
|