1 /***************************************************************************
2  *   Copyright (C) 2009 by Andrey Afletdinov <fheroes2@gmail.com>          *
3  *                                                                         *
4  *   Part of the Free Heroes2 Engine:                                      *
5  *   http://sourceforge.net/projects/fheroes2                              *
6  *                                                                         *
7  *   This program is free software; you can redistribute it and/or modify  *
8  *   it under the terms of the GNU General Public License as published by  *
9  *   the Free Software Foundation; either version 2 of the License, or     *
10  *   (at your option) any later version.                                   *
11  *                                                                         *
12  *   This program is distributed in the hope that it will be useful,       *
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
15  *   GNU General Public License for more details.                          *
16  *                                                                         *
17  *   You should have received a copy of the GNU General Public License     *
18  *   along with this program; if not, write to the                         *
19  *   Free Software Foundation, Inc.,                                       *
20  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
21  ***************************************************************************/
22 
23 #ifndef H2GAMEINTERFACE_H
24 #define H2GAMEINTERFACE_H
25 
26 #include "interface_buttons.h"
27 #include "interface_cpanel.h"
28 #include "interface_gamearea.h"
29 #include "interface_icons.h"
30 #include "interface_radar.h"
31 #include "interface_status.h"
32 #include "players.h"
33 
34 class Castle;
35 class Heroes;
36 
37 namespace Maps
38 {
39     class Tiles;
40 }
41 
42 namespace GameFocus
43 {
44     enum
45     {
46         UNSEL = FOCUS_UNSEL,
47         HEROES = FOCUS_HEROES,
48         CASTLE = FOCUS_CASTLE,
49         FIRSTHERO
50     };
51 }
52 
53 namespace Interface
54 {
55     enum redraw_t
56     {
57         REDRAW_RADAR = 0x01,
58         REDRAW_HEROES = 0x02,
59         REDRAW_CASTLES = 0x04,
60         REDRAW_BUTTONS = 0x08,
61         REDRAW_STATUS = 0x10,
62         REDRAW_BORDER = 0x20,
63         REDRAW_GAMEAREA = 0x40,
64         REDRAW_CURSOR = 0x80,
65 
66         REDRAW_ICONS = REDRAW_HEROES | REDRAW_CASTLES,
67         REDRAW_ALL = 0xFF
68     };
69 
70     Castle * GetFocusCastle( void );
71     Heroes * GetFocusHeroes( void );
72     int GetFocusType( void );
73     fheroes2::Point GetFocusCenter( void );
74 
75     class Basic
76     {
77     public:
78         static Basic & Get( void );
79 
80         bool NeedRedraw( void ) const;
81         void SetRedraw( int );
82         int GetRedrawMask() const;
83         void Redraw( int f = 0 );
84 
85         const fheroes2::Rect & GetScrollLeft( void ) const;
86         const fheroes2::Rect & GetScrollRight( void ) const;
87         const fheroes2::Rect & GetScrollTop( void ) const;
88         const fheroes2::Rect & GetScrollBottom( void ) const;
89 
90         int32_t GetDimensionDoorDestination( const int32_t from, const int32_t distance, const bool water );
91 
92         GameArea & GetGameArea( void );
93         Radar & GetRadar( void );
94         IconsPanel & GetIconsPanel( void );
95         ButtonsArea & GetButtonsArea( void );
96         StatusWindow & GetStatusWindow( void );
97         ControlPanel & GetControlPanel( void );
98 
99         void SetFocus( Heroes * );
100         void SetFocus( Castle * );
101         void ResetFocus( int );
102         void RedrawFocus( void );
103 
104         void SetHideInterface( bool );
105 
106         void EventSwitchHeroSleeping( void );
107         fheroes2::GameMode EventDefaultAction( const fheroes2::GameMode gameMode );
108         void EventOpenFocus( void ) const;
109         fheroes2::GameMode EventSaveGame() const;
110         void EventPuzzleMaps( void ) const;
111         static fheroes2::GameMode EventGameInfo();
112         void EventSystemDialog() const;
113         void EventNextHero( void );
114         void EventNextTown( void );
115         void EventContinueMovement( void ) const;
116         void EventKingdomInfo( void ) const;
117         void EventCastSpell( void );
118         void EventSwitchShowRadar( void ) const;
119         void EventSwitchShowStatus( void ) const;
120         void EventSwitchShowButtons( void ) const;
121         void EventSwitchShowIcons( void );
122         void EventSwitchShowControlPanel( void ) const;
123 
124         fheroes2::GameMode EventNewGame() const;
125         fheroes2::GameMode EventLoadGame() const;
126         fheroes2::GameMode EventAdventureDialog();
127         void EventViewWorld();
128         fheroes2::GameMode EventFileDialog( void ) const;
129         fheroes2::GameMode EventEndTurn() const;
130         static fheroes2::GameMode EventExit();
131         fheroes2::GameMode EventDigArtifact();
132         void EventKeyArrowPress( int direct );
133 
134         fheroes2::GameMode StartGame();
135 
136         void MouseCursorAreaClickLeft( const int32_t index_maps );
137         void MouseCursorAreaPressRight( s32 ) const;
138 
139         static int GetCursorTileIndex( s32 );
140         static int GetCursorFocusCastle( const Castle &, const Maps::Tiles & );
141         static int GetCursorFocusHeroes( const Heroes &, const Maps::Tiles & );
142         static int GetCursorFocusShipmaster( const Heroes &, const Maps::Tiles & );
143         void CalculateHeroPath( Heroes * hero, s32 destinationIdx ) const;
144 
145         void Reset(); // call this function only when changing the resolution
146 
147     private:
148         Basic();
149         void ShowPathOrStartMoveHero( Heroes *, s32 );
150         void MoveHeroFromArrowKeys( Heroes & hero, int direct );
151         fheroes2::GameMode HumanTurn( bool );
152 
153         GameArea gameArea;
154         Radar radar;
155         IconsPanel iconsPanel;
156         ButtonsArea buttonsArea;
157         StatusWindow statusWindow;
158         ControlPanel controlPanel;
159 
160         int redraw;
161 
162         fheroes2::Rect scrollLeft;
163         fheroes2::Rect scrollRight;
164         fheroes2::Rect scrollBottom;
165         fheroes2::Rect scrollTop;
166     };
167 }
168 
169 #endif
170