EGD Eric@Posted: Mon Nov 24, 2008 3:30 pm :
I've tried to call my own C++ function from the gui, and it doesn't seem to be happening. I tried declaring a script function in script_Thread.h, defining it in script_thread.cpp, but it still doesn't call it. Maybe I'm calling it wrong?
I put it in the onMouseEnter event of the buttons in the main menu, its called: "playRollover"
Code:
         
                                onMouseEnter {
            if ("desktop::active" == 0) {
               stoptransitions "main_b_newgame" ;
               
               set "main_b1::matcolor_w" "0.8" ;
               transition "main_t_b1::forecolor" "$desktop::white_8" "$desktop::orange" "0" ;
               transition "main_b1_corner::matcolor" "$desktop::corner" "$desktop::orange" "0" ;
               
               set "main_t_b1::textscale" "0.34" ;
               
               set "cmd" "play main_menu_mouseover" ;      
            }
            set "cmd" "playRollover";
         }

Here you can see I declared it as an event in script_thread.cpp:
Code:
   EVENT( EV_Thread_SetMatSort,         idThread::Event_SetMatSort )
// RAVEN END

//play rollover effect
   EVENT(EV_Thread_PlayRollover,         idThread::Event_PlayRollover)


And above that, I've declared it as an idEventDef:
Code:
const idEventDef EV_Thread_SetMatSort( "setMatSort", "ss", 0 );
// RAVEN END
const idEventDef EV_Thread_PlayRollover("playRollover", 0);



TinMan@Posted: Mon Nov 24, 2008 8:42 pm :
Ah, the event system isn't directly connected to the gui system.
The gui cmd is handled by the engine first then passed through to the game, which function depends on what type of gui.
Looking at your gui snippet it looks like you're working with the main menu.
In that case you'll have to work with
idGameLocal::HandleMainMenuCommands
Plenty of code there to figure out how it works, pretty simple if string == "nameofcommand".

Another approach would would be something along the lines of
Code:
..build command string into a token list..
..if token == "event"..
..read next token..
      
      const idEventDef * foundEvent = idEventDef::FindEvent( token ); // doesn't seem too fast from my quick look at the function, manual loop through all events and string compare.
      if ( foundEvent ) {
         // You could get more fancy here and read sucessive tokens to use as arguments for the event
         idThread * thread = new idThread(); // For the main menu, at pre-map load there isn't likely to be any idThreads around to repurpose, creating an idThread just for this may be a bit heavy, building a MainMenu class might be better.
         thread->PostEventMS( foundEvent, 0 );
         return true;
      }
   }

then you should be able to do this in the gui
set "cmd" "event myFabulousEvent";
To call the event called myFabulousEvent.

This could also be adapted for idEntity::HandleGuiCommands for entityguis



EGD Eric@Posted: Tue Nov 25, 2008 3:48 pm :
Thanks, that really helped! I've got the main menu calling my code, now I've just got to find where all the other guis are handled...
Edit: I just want to change code from the restart.gui as well, but I haven't yet found where in the code that's being handled. I've placed breakpoints in idEntity::HandleGuiCommands, idPlayer::HandleSingleGuiCommand, idMultiplayerGame::HandleGuiCommands, idEntity::HandleSingleGuiCommand, the restart gui (the one you get when you die in single player) doesn't seem to call use any of these functions to handle its commands...



simulation@Posted: Tue Nov 25, 2008 6:17 pm :
EGD Eric wrote:
Thanks, that really helped! I've got the main menu calling my code, now I've just got to find where all the other guis are handled...
Edit: I just want to change code from the restart.gui as well, but I haven't yet found where in the code that's being handled. I've placed breakpoints in idEntity::HandleGuiCommands, idPlayer::HandleSingleGuiCommand, idMultiplayerGame::HandleGuiCommands, idEntity::HandleSingleGuiCommand, the restart gui (the one you get when you die in single player) doesn't seem to call use any of these functions to handle its commands...

I think restart.gui is loaded and controlled by the main exe, not the gamecode. So unless it passes to the gamecode throught HandleMainmenuComamnds() then you're probably going to be out of luck with that one.

Out of interest, what is it that these custom events do for your GUIs?



EGD Eric@Posted: Mon Dec 01, 2008 10:16 pm :
Quote:
Out of interest, what is it that these custom events do for your GUIs?

sry, I want to tell you, but I'd be in breach of my NDA.



simulation@Posted: Tue Dec 02, 2008 9:43 am :
EGD Eric wrote:
Quote:
Out of interest, what is it that these custom events do for your GUIs?

sry, I want to tell you, but I'd be in breach of my NDA.

A mod team with an NDA for something based on a freely available SDK? Wow!



EGD Eric@Posted: Tue Dec 02, 2008 6:46 pm :
Its more like a demo (among many other demos) to show clients... something. I've said too much! :o