1 /*
2     Bastet - tetris clone with embedded bastard block chooser
3     (c) 2005-2009 Federico Poloni <f.polonithirtyseven@sns.it> minus 37
4 
5     This program is free software: you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation, either version 3 of the License, or
8     (at your option) any later version.
9 
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14 
15     You should have received a copy of the GNU General Public License
16     along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef UI_HPP
20 #define UI_HPP
21 
22 #include "Well.hpp"
23 #include "BlockPosition.hpp"
24 #include "BlockChooser.hpp"
25 #include "Config.hpp"
26 
27 #include <string>
28 #include <curses.h>
29 
30 namespace Bastet{
31   typedef std::pair<int,int> Score; //(points, lines)
32   Score &operator +=(Score &a, const Score &b);
33 
34   class BorderedWindow{
35   private:
36     WINDOW *_window;
37     WINDOW *_border;
38   public:
39     BorderedWindow(int height, int width, int y=-1, int x=-1); ///w and h are "inner" dimensions, excluding the border. y and x are "outer", including the border. y=-1,x=-1 means "center"
40     ~BorderedWindow();
41     operator WINDOW *(); //returns the inner window
42     void RedrawBorder();
43     int GetMinX(); ///these are including border
44     int GetMinY();
45     int GetMaxX();
46     int GetMaxY();
47     void DrawDot(const Dot &d, Color c);
48   };
49 
50   class Curses{
51   public:
52     Curses();
53   };
54 
55   class Ui{
56   public:
57     Ui();
58     void MessageDialog(const std::string &message); //shows msg, ask for "space"
59     std::string InputDialog(const std::string &message); //asks for a string
60     int KeyDialog(const std::string &message); //asks for a single key
61     int MenuDialog(const std::vector<std::string> &choices); //asks to choose one, returns index
62     void RedrawStatic(); //redraws the "static" parts of the screen
63     void RedrawWell(const Well *well, BlockType falling, const BlockPosition &pos);
64     void ClearNext(); //clear the next block display
65     void RedrawNext(BlockType next); //redraws the next block display
66     void RedrawScore();
67     void CompletedLinesAnimation(const LinesCompleted &completed);
68     void DropBlock(BlockType b, Well *w); //returns <score,lines>
69 
70     void ChooseLevel();
71     void Play(BlockChooser *bc);
72     void HandleHighScores(difficulty_t diff); ///if needed, asks name for highscores
73     void ShowHighScores(difficulty_t diff);
74     void CustomizeKeys();
75   private:
76     //    difficulty_t _difficulty; //unused for now
77     int _level;
78     int _points;
79     int _lines;
80     Curses _curses;
81     BorderedWindow _wellWin;
82     BorderedWindow _nextWin;
83     BorderedWindow _scoreWin;
84     /**
85      * this is a kind of "well" structure to store the colors used to draw the blocks.
86      */
87     typedef boost::array<Color,WellWidth> ColorWellLine;
88     typedef boost::array<ColorWellLine,RealWellHeight> ColorWell;
89     ColorWell _colors;
90   };
91 }
92 
93 #endif //UI_HPP
94