Fixed initialization order in animation manager.
[NALCG.git] / src / view / view.h
blob35617f72786fcf8a394da0f026f9ad71d12c3204
1 #ifndef _NALCG_VIEW_H_
2 #define _NALCG_VIEW_H_
4 #include "../enduser.h"
5 #include "viewframelistener.h"
7 #include <Ogre.h>
8 #include <CEGUI/CEGUI.h>
9 #include <OIS/OIS.h>
10 #include <OgreCEGUIRenderer.h>
12 using namespace Ogre;
14 class View : public WindowEventListener, public EndUser
16 public:
17 View() : mRoot(0), mKeyboard(0), mMouse(0), mInputManager(0),
18 mRenderer(0), mSystem(0), mListener(0), mBoardWidth(0),
19 mBoardHeight(0), mRound(0), mPast(false)
23 virtual void init(const Board* board, Middleman *middleman) {
24 EndUser::init(board, middleman);
25 try {
27 createRoot();
28 defineResources();
29 setupRenderSystem();
30 createRenderWindow();
31 initializeResourceGroups();
32 setupScene();
33 setupInputSystem();
34 setupCEGUI();
35 createFrameListener();
36 createGUI();
37 createScene();
38 createBoard(board);
39 createGround(false);
40 createInitialExplosion();
41 startRenderLoop();
42 } catch( Exception& e ) {
43 fprintf(stderr, "An exception has occurred: %s\n", e.what());
44 } catch (std::exception& e) {
45 std::cerr << "An exception has occured: " << e.what() << std::endl;
49 virtual void setBoard(const Board* const board, unsigned int round)
51 mListener->getAnimationManager().finishAnimations();
52 mSceneMgr->getRootSceneNode()->removeAndDestroyAllChildren();
53 mSceneMgr->destroyAllEntities();
54 createGround(true);
55 createBoard(board);
56 mRound = round;
57 recreateLog();
58 recreateDeadPieces();
60 virtual void move(int fromX, int fromY, int toX, int toY,
61 bool continuous = false)
63 mListener->move(fromX, fromY, toX, toY, continuous);
64 if (!continuous)
66 mRound++;
67 recreateLog();
70 virtual void promoteMove(int fromX, int fromY, int toX, int toY,
71 unsigned int promoteTo)
73 mListener->move(fromX, fromY, toX, toY, true, 0);
74 mListener->move(toX, toY, toX, toY, false, promoteTo);
75 mRound++;
76 recreateLog();
77 recreateDeadPieces();
79 virtual void setControl(bool white, bool black) { }
81 virtual int getBoardWidth() const { return mBoardWidth; }
82 virtual int getBoardHeight() const { return mBoardHeight; }
83 virtual bool isWhiteTurn() const { return mRound % 2 == 0; }
85 virtual void convertPosition(const Vector3& position, int* x, int* y) const;
86 virtual Vector3 convertPosition(double x, double y) const;
87 void createGround(bool visible);
88 virtual SceneNode* createPiece(char type, const std::string& modelName, const Vector3& location, SceneNode* parent = 0);
89 std::string getMeshName(char symbol) const;
90 CEGUI::Window* createGUIComponent(const std::string& text, double x, double y,
91 double sizeX, double sizeY, const std::string& type = "Button", bool setText = true, bool visible = true);
92 virtual void setPromotionMove(int fromX, int fromY, int toX, int toY);
93 void setChooseButtonsVisibility(bool visible);
94 virtual void windowClosed(RenderWindow* rw);
95 void ensureLatestState();
96 virtual void recreateDeadPieces();
97 virtual ~View();
99 protected:
100 Root* mRoot;
101 OIS::Keyboard* mKeyboard;
102 OIS::Mouse* mMouse;
103 OIS::InputManager* mInputManager;
104 CEGUI::OgreCEGUIRenderer* mRenderer;
105 CEGUI::System* mSystem;
106 ViewFrameListener* mListener;
107 SceneManager* mSceneMgr;
108 Camera* mCamera;
109 RenderWindow* mWindow;
110 std::size_t mBoardWidth;
111 std::size_t mBoardHeight;
112 unsigned int mRound;
113 std::vector<int> promotionMove;
114 bool mPast;
116 void createRoot();
117 void defineResources();
118 void setupRenderSystem();
119 void createRenderWindow();
120 void initializeResourceGroups();
121 void setupScene();
122 void setupInputSystem();
123 void setupCEGUI();
124 void createFrameListener();
125 void startRenderLoop();
126 virtual void createCamera();
127 virtual void createViewports();
128 virtual void createInitialExplosion();
129 virtual Entity* loadEntity(const std::string& entityName, const std::string& modelName);
130 virtual void recreateLog();
132 void createScene();
133 void createGUI();
134 void createBoard(const Board* board);
136 bool undo(const CEGUI::EventArgs& e);
137 bool restart(const CEGUI::EventArgs& e);
138 bool dev(const CEGUI::EventArgs& e);
139 bool visitSelectedLog(const CEGUI::EventArgs& e);
140 bool chooseQueen(const CEGUI::EventArgs& e);
141 bool chooseRook(const CEGUI::EventArgs& e);
142 bool chooseKnight(const CEGUI::EventArgs& e);
143 bool chooseBishop(const CEGUI::EventArgs& e);
144 void sendPromotionMove(unsigned int promoteTo);
147 #endif // _NALCG_VIEW_H_