Checkmate now works with promotion but still behaves strangely with en passant and...
[NALCG.git] / src / view / view.h
blob25b66d2cc458d5154b3363f80ed8053fe19092f6
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, true, promoteTo);
75 mRound++;
76 recreateLog();
78 virtual void setControl(bool white, bool black) { }
80 virtual int getBoardWidth() const { return mBoardWidth; }
81 virtual int getBoardHeight() const { return mBoardHeight; }
82 virtual bool isWhiteTurn() const { return mRound % 2 == 0; }
84 virtual void convertPosition(const Vector3& position, int* x, int* y) const;
85 virtual Vector3 convertPosition(double x, double y) const;
86 void createGround(bool visible);
87 virtual SceneNode* createPiece(char type, const std::string& modelName, const Vector3& location, SceneNode* parent = 0);
88 std::string getMeshName(char symbol) const;
89 CEGUI::Window* createGUIComponent(const std::string& text, double x, double y,
90 double sizeX, double sizeY, const std::string& type = "Button", bool setText = true, bool visible = true);
91 virtual void setPromotionMove(int fromX, int fromY, int toX, int toY);
92 void setChooseButtonsVisibility(bool visible);
93 virtual void windowClosed(RenderWindow* rw);
94 void ensureLatestState();
95 virtual void recreateDeadPieces();
96 virtual ~View();
98 protected:
99 Root* mRoot;
100 OIS::Keyboard* mKeyboard;
101 OIS::Mouse* mMouse;
102 OIS::InputManager* mInputManager;
103 CEGUI::OgreCEGUIRenderer* mRenderer;
104 CEGUI::System* mSystem;
105 ViewFrameListener* mListener;
106 SceneManager* mSceneMgr;
107 Camera* mCamera;
108 RenderWindow* mWindow;
109 std::size_t mBoardWidth;
110 std::size_t mBoardHeight;
111 unsigned int mRound;
112 std::vector<int> promotionMove;
113 bool mPast;
115 void createRoot();
116 void defineResources();
117 void setupRenderSystem();
118 void createRenderWindow();
119 void initializeResourceGroups();
120 void setupScene();
121 void setupInputSystem();
122 void setupCEGUI();
123 void createFrameListener();
124 void startRenderLoop();
125 virtual void createCamera();
126 virtual void createViewports();
127 virtual void createInitialExplosion();
128 virtual Entity* loadEntity(const std::string& entityName, const std::string& modelName);
129 virtual void recreateLog();
131 void createScene();
132 void createGUI();
133 void createBoard(const Board* board);
135 bool undo(const CEGUI::EventArgs& e);
136 bool restart(const CEGUI::EventArgs& e);
137 bool visitSelectedLog(const CEGUI::EventArgs& e);
138 bool chooseQueen(const CEGUI::EventArgs& e);
139 bool chooseRook(const CEGUI::EventArgs& e);
140 bool chooseKnight(const CEGUI::EventArgs& e);
141 bool chooseBishop(const CEGUI::EventArgs& e);
142 void sendPromotionMove(unsigned int promoteTo);
145 #endif // _NALCG_VIEW_H_