Line data Source code
1 : /* Copyright (C) 2026 Wildfire Games. 2 : * This file is part of 0 A.D. 3 : * 4 : * 0 A.D. is free software: you can redistribute it and/or modify 5 : * it under the terms of the GNU General Public License as published by 6 : * the Free Software Foundation, either version 2 of the License, or 7 : * (at your option) any later version. 8 : * 9 : * 0 A.D. is distributed in the hope that it will be useful, 10 : * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 : * GNU General Public License for more details. 13 : * 14 : * You should have received a copy of the GNU General Public License 15 : * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. 16 : */ 17 : 18 : #ifndef INCLUDED_MINIMAP 19 : #define INCLUDED_MINIMAP 20 : 21 : #include "graphics/Color.h" 22 : #include "graphics/Texture.h" 23 : #include "gui/CGUISetting.h" 24 : #include "gui/ObjectBases/IGUIObject.h" 25 : #include "lib/posix/posix_types.h" 26 : #include "maths/Vector2D.h" 27 : #include "ps/CStr.h" 28 : 29 : #include <deque> 30 : #include <vector> 31 : 32 : class CCanvas2D; 33 : class CGUI; 34 : class CRect; 35 : class CVector3D; 36 : 37 : class CMiniMap : public IGUIObject 38 : { 39 0 : GUI_OBJECT(CMiniMap) 40 : 41 : public: 42 : CMiniMap(CGUI& pGUI); 43 : 44 : bool Flare(const CVector2D& pos, const CStr& colorStr); 45 : 46 : protected: 47 : struct MapFlare 48 : { 49 : CVector2D pos; 50 : CColor color; 51 : double time; 52 : }; 53 : 54 : virtual void Tick(); 55 : 56 : virtual void Draw(CCanvas2D& canvas); 57 : 58 : virtual void CreateJSObject(); 59 : 60 : /** 61 : * @see IGUIObject#HandleMessage() 62 : */ 63 : virtual void HandleMessage(SGUIMessage& Message); 64 : 65 : /** 66 : * @see IGUIObject#IsMouseOver() 67 : */ 68 : virtual bool IsMouseOver() const; 69 : 70 : private: 71 : void SetCameraPositionFromMousePosition(); 72 : 73 : bool FireWorldClickEvent(int button, int clicks); 74 : 75 : static const CStr EventNameWorldClick; 76 : 77 : // Whether or not the mouse is currently down 78 : bool m_Clicking; 79 : 80 : std::deque<MapFlare> m_MapFlares; 81 : 82 : std::vector<CTexturePtr> m_FlareTextures; 83 : 84 : CGUISimpleSetting<std::uint32_t> m_FlareTextureCount; 85 : CGUISimpleSetting<std::uint32_t> m_FlareRenderSize; 86 : CGUISimpleSetting<bool> m_FlareInterleave; 87 : CGUISimpleSetting<float> m_FlareAnimationSpeed; 88 : CGUISimpleSetting<float> m_FlareLifetimeSeconds; 89 : CGUISimpleSetting<float> m_FlareStartFadeSeconds; 90 : CGUISimpleSetting<float> m_FlareStopFadeSeconds; 91 : 92 : // Whether to draw a black square around and under the minimap. 93 : CGUISimpleSetting<bool> m_Mask; 94 : 95 : // map size 96 : ssize_t m_MapSize; 97 : 98 : // 1.f if map is circular or 1.414f if square (to shrink it inside the circle) 99 : float m_MapScale; 100 : 101 : void RecreateFlareTextures(); 102 : 103 : void DrawViewRect(CCanvas2D& canvas) const; 104 : 105 : void DrawFlare(CCanvas2D& canvas, const MapFlare& flare, double currentTime) const; 106 : void DrawFlareFrame(CCanvas2D& canvas, const std::uint32_t frameIndex, const CRect& destination, 107 : const CColor& color, float alpha) const; 108 : 109 : void GetMouseWorldCoordinates(float& x, float& z) const; 110 : 111 : float GetAngle() const; 112 : CVector2D WorldSpaceToMiniMapSpace(const CVector3D& worldPosition) const; 113 : }; 114 : 115 : #endif // INCLUDED_MINIMAP