Hi sorry this is a big question but this will clear up a whole lot of things for me in the future. I am using the pgbutton. I am trying to make a quit button (for testing how to use the pgbutton) i tried to follow the manual but i have a whole lot more involved. Here is the C++ code for my menu :
/*MainMenu.cpp*/
# include "MainMenu.h"
//Sets up The Main menu with the PGui lib
// The arguements are pointers to the window and framework from the Game object
MainMenu::MainMenu(WindowFramework *window, PandaFramework * framework, Game * Game)
{
//Create the Start button
//TODO: MAKE THIS BUTTON LOAD THE LEVEL SELECTOR
btn_Start = new PGButton("Start");
btn_Start->setup("Start Game",0.1);
btn_Start->set_focus(true);
NodePath btn_Start_NP = window->get_aspect_2d().attach_new_node(btn_Start);
btn_Start_NP.set_scale(0.1);
btn_Start_NP.set_pos(-0.3 , 0 , 0.2);
//Create the Quit button
btn_Quit = new PGButton("Start");
btn_Quit->setup("Quit Game",0.1);
btn_Quit->set_focus(true);
NodePath btn_Quit_NP = window->get_aspect_2d().attach_new_node(btn_Quit);
btn_Quit_NP.set_scale(0.1);
btn_Quit_NP.set_pos(-0.3 , 0 , -0.2);
// Setup callback function
framework->define_key(btn_Quit->get_click_event(MouseButton::one() ), "button press", btn_Quit_Clicked, Game);
}
MainMenu::~MainMenu()
{
}
This class will be instanced by another class called game to draw and handle the mainmenu. I need that quit button to use the pointer to the game object (passed through as an argument in the creator function of MainMenu) To call the game objects GameExit() function.
Here is that code:
/*Game.cpp*/
# include "Game.h"
# include "MainMenu.h"
Game::Game(int argc, char *argv[]){
// Load the window and set its title.
framework.open_framework(argc, argv);
framework.set_window_title("");
window = framework.open_window();
// Initialize the game variables
GameStatus = GameMainMenu;
Process();
// Run the engine.
framework.main_loop();
// Shut down the engine when done.
framework.close_framework();
}
Game::~Game(){
}
//Process the game based on game state
void Game::Process (void)
{
switch (GameStatus)
{
case GameMainMenu:
ShowMenu();
break;
case GameRunning:
ShowGame();
break;
case GameExit:
ExitGame();
break;
default:
break;
}
}
//Create The main Menu for the game
void Game::ShowMenu()
{
//Instance the mainmenu class
MainMenu MainMenu(window, &framework, this);
}
//The game is rendered once a level is selected
void Game::ShowGame()
{
}
//terminate the game
void Game::ExitGame()
{
exit(0);
}
If anyone can help me with this I would greatly appreciate it!
Thanks!