MyGUI Events??

lelzmike143

22-07-2013 12:12:17

#include "IntermediateTutorial1.h"
#include "MyGUI.h"
#include "MyGUI_OgrePlatform.h"

//-------------------------------------------------------------------------------------
IntermediateTutorial1::IntermediateTutorial1(void)
{
}
//-------------------------------------------------------------------------------------
IntermediateTutorial1::~IntermediateTutorial1(void)
{
}

//-------------------------------------------------------------------------------------
void IntermediateTutorial1::createScene(void)
{
// Set the default lighting.
mSceneMgr->setAmbientLight(Ogre::ColourValue(1.0f, 1.0f, 1.0f));
// Create the entity

mEntity = mSceneMgr->createEntity("Robot", "civ1.mesh");

// Create the scene node
mNode = mSceneMgr->getRootSceneNode()->
createChildSceneNode("RobotNode", Ogre::Vector3(0.0f, 0.0f, 25.0f));
mNode->attachObject(mEntity);
// Create the walking list
mWalkList.push_back(Ogre::Vector3(550.0f, 0.0f, 50.0f ));
mWalkList.push_back(Ogre::Vector3(-100.0f, 0.0f, -200.0f));
// Create objects so we can see movement
Ogre::Entity *ent;
Ogre::SceneNode *node;

ent = mSceneMgr->createEntity("Ground", "samp_terrain.mesh");
node = mSceneMgr->getRootSceneNode()->createChildSceneNode("GroundNode",
Ogre::Vector3(0.0f, -10.0f, 25.0f));
node->attachObject(ent);
node->setScale(10, 10, 10);

ent = mSceneMgr->createEntity("Knot1", "knot.mesh");
node = mSceneMgr->getRootSceneNode()->createChildSceneNode("Knot1Node",
Ogre::Vector3(0.0f, -10.0f, 25.0f));
node->attachObject(ent);
node->setScale(0.1f, 0.1f, 0.1f);

ent = mSceneMgr->createEntity("Knot2", "knot.mesh");
node = mSceneMgr->getRootSceneNode()->createChildSceneNode("Knot2Node",
Ogre::Vector3(550.0f, -10.0f, 50.0f));
node->attachObject(ent);
node->setScale(0.1f, 0.1f, 0.1f);

ent = mSceneMgr->createEntity("Knot3", "knot.mesh");
node = mSceneMgr->getRootSceneNode()->createChildSceneNode("Knot3Node",
Ogre::Vector3(-100.0f, -10.0f,-200.0f));
node->attachObject(ent);
node->setScale(0.1f, 0.1f, 0.1f);
// Set the camera to look at our handiwork
mCamera->setPosition(90.0f, 280.0f, 535.0f);
mCamera->pitch(Ogre::Degree(-30.0f));
mCamera->yaw(Ogre::Degree(-15.0f));
}
void IntermediateTutorial1::createFrameListener(void){
BaseApplication::createFrameListener();
// Set idle animation
mAnimationState = mEntity->getAnimationState("Idle");
mAnimationState->setLoop(true);
mAnimationState->setEnabled(true);
// Set default values for variables
mWalkSpeed = 35.0f;
mDirection = Ogre::Vector3::ZERO;
}
bool IntermediateTutorial1::nextLocation(void){
if (mWalkList.empty())
return false;
mDestination = mWalkList.front(); // this gets the front of the deque
mWalkList.pop_front(); // this removes the front of the deque

mDirection = mDestination - mNode->getPosition();
mDistance = mDirection.normalise();
Ogre::Vector3 src = mNode->getOrientation() * Ogre::Vector3::UNIT_X;
if ((1.0f + src.dotProduct(mDirection)) < 0.0001f)
{
mNode->yaw(Ogre::Degree(180));
}
else
{
Ogre::Quaternion quat = src.getRotationTo(mDirection);
mNode->rotate(quat);
} // else
return true;}

bool IntermediateTutorial1::frameRenderingQueued(const Ogre::FrameEvent &evt){
if (mDirection == Ogre::Vector3::ZERO)
{
if (nextLocation())
{
// Set walking animation
mAnimationState = mEntity->getAnimationState("Walk");
mAnimationState->setLoop(true);
mAnimationState->setEnabled(true);
}
}else
{
Ogre::Real move = mWalkSpeed * evt.timeSinceLastFrame;
mDistance -= move;
if (mDistance <= 0.0f)
{
mNode->setPosition(mDestination);
mDirection = Ogre::Vector3::ZERO;
// Set animation based on if the robot has another point to walk to.
if (! nextLocation())
{
// Set Idle animation
mAnimationState = mEntity->getAnimationState("Idle");
mAnimationState->setLoop(true);
mAnimationState->setEnabled(true);
}
else
{
// Rotation Code will go here later
}
}else
{
mNode->translate(mDirection * move);
} // else
} // if
mAnimationState->addTime(evt.timeSinceLastFrame);
return BaseApplication::frameRenderingQueued(evt);
}

void BaseApplication::createViewports(void)
{
// Create one viewport, entire window
Ogre::Viewport* vp = mWindow->addViewport(mCamera);
vp->setBackgroundColour(Ogre::ColourValue(0,0,0));


MyGUI::Gui* mGUI;
MyGUI::OgrePlatform* mPlatform = new MyGUI::OgrePlatform();
mPlatform->initialise(mWindow, mSceneMgr); // mWindow is Ogre::RenderWindow*, mSceneManager is Ogre::SceneManager*
mGUI = new MyGUI::Gui();
mGUI->initialise();

MyGUI::LayoutManager::getInstance().load("OpenSaveFileDialog.layout");

//menuitem->eventMouseButtonClick += MyGUI::newDelegate(this, &BaseApplication::mygui);

//mGUI->findWidget<MyGUI::MenuBar>("MenuBar1");


//mGUI->findWidget<MyGUI::MenuBar>("MenuBar1", 100, 100, 100, 100, MyGUI::Align::Center,"Main");

//MyGUI::LayoutManager::getInstance().loadLayout("TestApp.layout");
/*
MyGUI::ListPtr List1 = mGUI->createWidget<MyGUI::ListBox>("ListBox", 350, 150, 300, 200, MyGUI::Align::Default,"Main");
List1->addItem("#FF0000NEW GAME");
List1->addItem("#FF0000OPTIONS");
List1->addItem("#FF0000HELP");
List1->addItem("#FF0000EXIT");
*/
/*

*/

//NewGame_Button->eventmousePressed += MyGUI::newDelegate(this, &StateMenu::notifyMouseSetFocus);
/*
MyGUI::ButtonPtr Options_Button = mGUI->createWidget<MyGUI::Button>("Button", 350, 200, 100, 50, MyGUI::Align::Default, "Main");
Options_Button->setCaption("#FF0000OPTIONS");
MyGUI::ButtonPtr Help_Button = mGUI->createWidget<MyGUI::Button>("Button", 350, 250, 100, 50, MyGUI::Align::Default, "Main");
Help_Button->setCaption("#FF0000HELP");
MyGUI::ButtonPtr Exit_Button = mGUI->createWidget<MyGUI::Button>("Button", 350, 300, 100, 50, MyGUI::Align::Default, "Main");
Exit_Button->setCaption("#FF0000EXIT");
*/


// Alter the camera aspect ratio to match the viewport
mCamera->setAspectRatio(
Ogre::Real(vp->getActualWidth()) / Ogre::Real(vp->getActualHeight()));

}

bool BaseApplication::keyReleased( const OIS::KeyEvent &arg )
{
MyGUI::InputManager::getInstance().injectKeyPress(MyGUI::KeyCode::Enum(arg.key), arg.text);
return true;

}

bool BaseApplication::mouseMoved( const OIS::MouseEvent &arg )
{
MyGUI::InputManager::getInstance().injectMouseMove(arg.state.X.abs, arg.state.Y.abs, arg.state.Z.abs);
//if (mTrayMgr->injectMouseMove(arg)) return true;
//mCameraMan->injectMouseMove(arg);
return true;
}

bool BaseApplication::mousePressed( const OIS::MouseEvent &arg, OIS::MouseButtonID id )
{
MyGUI::InputManager::getInstance().injectMousePress(arg.state.X.abs, arg.state.Y.abs, MyGUI::MouseButton::Enum(id));
return true;
}

bool BaseApplication::mouseReleased( const OIS::MouseEvent &arg, OIS::MouseButtonID id )
{
MyGUI::InputManager::getInstance().injectMouseRelease(arg.state.X.abs, arg.state.Y.abs, MyGUI::MouseButton::Enum(id));
return true;
}

#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"
#endif

#ifdef __cplusplus
extern "C" {
#endif

#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
#else
int main(int argc, char *argv[])
#endif
{
// Create application object
IntermediateTutorial1 app;

try {
app.go();
} catch( Ogre::Exception& e ) {
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
#else
std::cerr << "An exception has occured: " <<
e.getFullDescription().c_str() << std::endl;
#endif
}

return 0;
}

#ifdef __cplusplus
}
#endif


Can u help me with my code I have a problem on events where I wanted to put events and load my ogre mesh afterwards
Can Anyone help me please? :D