////////////////////////////////////////////////////////////////////////////////
// LevelEd.h
// Simulation window for MechVM
// Copyright Bjoern Ganster
// Developed since 2020
////////////////////////////////////////////////////////////////////////////////

#ifndef LevelEd__h
#define LevelEd__h

#include "GLWindow.h"
#include "RenderableObject.h"
#include "Vehicles.h"
#include "VehicleAI.h"
#include "XMLTree.h"

#ifdef MECHVM
#include "MechWarriorIIPRJ.h"
#endif

////////////////////////////////////////////////////////////////////////////////
// Mech simulator window

class LevelEd: public GLWindow
{
public:
   // Constructor
    LevelEd();

   // Destructor
   ~LevelEd() OVERRIDE;

   // Receive messages
   void receiveMessage (VirtualClass* sender, int MessageType, VirtualClass* data = nullptr) OVERRIDE;

   // Update title with model graph name and framerate
   void updateTitle ();

   // Render
   virtual void render(int x, int y, int w, int h);

   // Keyboard event handlers
   void keypressed(BGKey key, bool shiftHeld, bool controlHeld, bool down, bool repeat) OVERRIDE;
   //virtual void specialKeyPressed (char key, bool shiftHeld, bool controlHeld);

   void setReturnVis(GLWindow* newVis)
   { returnVis = newVis; }

   void loadLevel(const PathChar* levelDir, const PathChar* xml);

   void createHeightField();

   GLWindow* buttonStateChanged (int /*button*/, bool /*down*/, int /*x*/, int /*y*/) OVERRIDE;
private:
   Point3D mViewerPos, mViewerDir, mRightDir, mTopDir;
   RenderableObject* m_sceneObjects;
   GLWindow* returnVis;
   size_t selectedObject;
   BGCPString xmlFilename;
   float FOVY;
   Point3D selPoint;
   double viewerSpeed;
   double moveSpeed;
   double rotationSpeed;

   void addSceneObjectsRecursively(RenderableObject* container, const PathChar* levelDir, XMLTreeConstIterator& iter, const Matrix& m);
   void saveXml();
};

#endif
