1 /*
2  * Copyright 2010-2014 OpenXcom Developers.
3  *
4  * This file is part of OpenXcom.
5  *
6  * OpenXcom is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * OpenXcom is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with OpenXcom.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 #ifndef OPENXCOM_BASEVIEW_H
20 #define OPENXCOM_BASEVIEW_H
21 
22 #include "../Engine/InteractiveSurface.h"
23 
24 namespace OpenXcom
25 {
26 
27 class Base;
28 class SurfaceSet;
29 class BaseFacility;
30 class RuleBaseFacility;
31 class Font;
32 class Language;
33 class Timer;
34 
35 /**
36  * Interactive view of a base.
37  * Takes a certain base and displays all its facilities
38  * and status, allowing players to manage them.
39  */
40 class BaseView : public InteractiveSurface
41 {
42 private:
43 	static const int BASE_SIZE = 6;
44 	static const int GRID_SIZE = 32;
45 
46 	Base *_base;
47 	SurfaceSet *_texture;
48 	BaseFacility *_facilities[BASE_SIZE][BASE_SIZE], *_selFacility;
49 	Font *_big, *_small;
50 	Language *_lang;
51 	int _gridX, _gridY, _selSize;
52 	Surface *_selector;
53 	bool _blink;
54 	Timer *_timer;
55 	/// Updates the neighborFacility's build time. This is for internal use only (reCalcQueuedBuildings()).
56 	void updateNeighborFacilityBuildTime(BaseFacility* facility, BaseFacility* neighbor);
57 public:
58 	/// Creates a new base view at the specified position and size.
59 	BaseView(int width, int height, int x = 0, int y = 0);
60 	/// Cleans up the base view.
61 	~BaseView();
62 	/// Initializes the base view's various resources.
63 	void initText(Font *big, Font *small, Language *lang);
64 	/// Sets the base to display.
65 	void setBase(Base *base);
66 	/// Sets the texture for this base view.
67 	void setTexture(SurfaceSet *texture);
68 	/// Gets the currently selected facility.
69 	BaseFacility *getSelectedFacility() const;
70 	/// Prevents any mouseover bugs on dismantling base facilities before setBase has had time to update the base.
71 	void resetSelectedFacility();
72 	/// Gets the X position of the currently selected square.
73 	int getGridX() const;
74 	/// Gets the Y position of the currently selected square.
75 	int getGridY() const;
76 	/// Sets whether the base view is selectable.
77 	void setSelectable(int size);
78 	/// Checks if a facility can be placed.
79 	bool isPlaceable(RuleBaseFacility *rule) const;
80 	/// Checks if the placed facility is placed in queue or not.
81 	bool isQueuedBuilding(RuleBaseFacility *rule) const;
82 	/// ReCalculates the remaining build-time of all queued buildings.
83 	void reCalcQueuedBuildings();
84 	/// Handles the timers.
85 	void think();
86 	/// Blinks the selector.
87 	void blink();
88 	/// Draws the base view.
89 	void draw();
90 	/// Blits the base view onto another surface.
91 	void blit(Surface *surface);
92 	/// Special handling for mouse hovers.
93 	void mouseOver(Action *action, State *state);
94 	/// Special handling for mouse hovering out.
95 	void mouseOut(Action *action, State *state);
96 };
97 
98 }
99 
100 #endif
101