1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-16 10:19:47 +02:00
vcmi/client/adventureMap/CAdventureMapInterface.h

245 lines
7.5 KiB
C
Raw Normal View History

/*
2023-02-01 16:42:03 +02:00
* CAdvMapInt.h, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#pragma once
#include "../gui/CIntObject.h"
#include "../../lib/int3.h"
#include "../../lib/GameConstants.h"
VCMI_LIB_NAMESPACE_BEGIN
class CGObjectInstance;
class CGHeroInstance;
class CGTownInstance;
class CArmedInstance;
class IShipyard;
struct CGPathNode;
struct ObjectPosInfo;
struct Component;
VCMI_LIB_NAMESPACE_END
class CButton;
class IImage;
class CAnimImage;
class CGStatusBar;
class CAdvMapPanel;
class CAdvMapWorldViewPanel;
class CAnimation;
class MapView;
class CResDataBar;
class CHeroList;
class CTownList;
class CInfoBar;
class CMinimap;
2023-03-01 17:20:05 +02:00
class MapAudioPlayer;
struct MapDrawingInfo;
2015-01-13 21:57:41 +02:00
enum class EAdvMapMode
{
NORMAL,
WORLD_VIEW
};
/// That's a huge class which handles general adventure map actions and
/// shows the right menu(questlog, spellbook, end turn,..) from where you
/// can get to the towns and heroes.
class CAdventureMapInterface : public CIntObject
{
2023-02-10 23:29:13 +02:00
private:
enum EDirections {LEFT=1, RIGHT=2, UP=4, DOWN=8};
enum class EGameStates {NA, INGAME, WAITING};
2023-02-10 23:29:13 +02:00
EGameStates state;
2015-01-13 21:57:41 +02:00
EAdvMapMode mode;
2016-10-18 03:09:52 +02:00
2023-02-10 23:29:13 +02:00
/// Currently selected object, can be town, hero or null
const CArmedInstance *selection;
2016-10-18 03:09:52 +02:00
2023-02-10 23:29:13 +02:00
/// currently acting player
PlayerColor player;
2016-10-18 03:09:52 +02:00
2023-02-10 23:29:13 +02:00
bool duringAITurn;
2016-10-18 03:09:52 +02:00
2023-02-10 23:29:13 +02:00
/// uses EDirections enum
ui8 scrollingDir;
bool scrollingState;
2016-10-18 03:09:52 +02:00
2023-02-10 23:29:13 +02:00
const CSpell *spellBeingCasted; //nullptr if none
2015-01-13 21:57:41 +02:00
std::vector<std::shared_ptr<CAnimImage>> gems;
2009-04-14 13:46:42 +03:00
2023-02-10 23:29:13 +02:00
std::shared_ptr<IImage> bg;
std::shared_ptr<IImage> bgWorldView;
std::shared_ptr<CButton> kingOverview;
2023-02-10 23:29:13 +02:00
std::shared_ptr<CButton> sleepWake;
std::shared_ptr<CButton> underground;
std::shared_ptr<CButton> questlog;
std::shared_ptr<CButton> moveHero;
std::shared_ptr<CButton> spellbook;
std::shared_ptr<CButton> advOptions;
std::shared_ptr<CButton> sysOptions;
std::shared_ptr<CButton> nextHero;
std::shared_ptr<CButton> endTurn;
std::shared_ptr<CButton> worldViewUnderground;
2015-01-13 21:57:41 +02:00
std::shared_ptr<MapView> terrain;
2023-02-10 23:29:13 +02:00
std::shared_ptr<CMinimap> minimap;
std::shared_ptr<CHeroList> heroList;
std::shared_ptr<CTownList> townList;
std::shared_ptr<CInfoBar> infoBar;
2023-02-10 23:29:13 +02:00
std::shared_ptr<CGStatusBar> statusbar;
std::shared_ptr<CResDataBar> resdatabar;
std::shared_ptr<CAdvMapPanel> panelMain; // panel that holds all right-side buttons in normal view
std::shared_ptr<CAdvMapWorldViewPanel> panelWorldView; // panel that holds all buttons and other ui in world view
std::shared_ptr<CAdvMapPanel> activeMapPanel; // currently active panel (either main or world view, depending on current mode)
2016-10-18 04:46:07 +02:00
std::shared_ptr<CAnimation> worldViewIcons;// images for world view overlay
2015-01-13 21:57:41 +02:00
2023-03-01 17:20:05 +02:00
std::shared_ptr<MapAudioPlayer> mapAudio;
2023-02-10 23:29:13 +02:00
private:
2009-06-24 06:04:59 +03:00
//functions bound to buttons
void fshowOverview();
2015-01-13 21:57:41 +02:00
void fworldViewBack();
void fworldViewScale1x();
void fworldViewScale2x();
void fworldViewScale4x();
void fswitchLevel();
void fshowQuestlog();
void fsleepWake();
void fmoveHero();
void fshowSpellbok();
void fadventureOPtions();
void fsystemOptions();
void fnextHero();
void fendTurn();
2023-02-10 23:29:13 +02:00
void setScrollingCursor(ui8 direction) const;
void selectionChanged();
bool isActive();
void adjustActiveness(bool aiTurnStart); //should be called every time at AI/human turn transition; blocks GUI during AI turn
const IShipyard * ourInaccessibleShipyard(const CGObjectInstance *obj) const; //checks if obj is our ashipyard and cursor is 0,0 -> returns shipyard or nullptr else
//button updates
void updateSleepWake(const CGHeroInstance *h);
void updateSpellbook(const CGHeroInstance *h);
void handleMapScrollingUpdate();
void showMoveDetailsInStatusbar(const CGHeroInstance & hero, const CGPathNode & pathNode);
const CGObjectInstance *getActiveObject(const int3 &tile);
2023-04-16 19:42:56 +02:00
std::optional<Point> keyToMoveDirection(const SDL_Keycode & key);
2023-02-10 23:29:13 +02:00
bool isHeroSleeping(const CGHeroInstance *hero);
void setHeroSleeping(const CGHeroInstance *hero, bool sleep);
int getNextHeroIndex(int startIndex); //for Next Hero button - cycles awake heroes with movement only
void endingTurn();
2023-02-10 23:29:13 +02:00
public:
CAdventureMapInterface();
2023-02-10 23:29:13 +02:00
// CIntObject interface implementation
void activate() override;
void deactivate() override;
2023-02-10 23:29:13 +02:00
void show(SDL_Surface * to) override;
void showAll(SDL_Surface * to) override;
void keyPressed(const SDL_Keycode & key) override;
void keyReleased(const SDL_Keycode & key) override;
void mouseMoved (const Point & cursorPosition) override;
// public interface
void startHotSeatWait(PlayerColor Player);
void startTurn();
void initializeNewTurn();
void aiTurnStarted();
/// Called by PlayerInterface when hero is forced to wake up, e.g. on moving sleeping hero
void onHeroWokeUp(const CGHeroInstance * hero);
/// Called by PlayerInterface when current player changes in hotseat
void onCurrentPlayerChanged(PlayerColor Player);
/// Called by PlayerInterface when specific map tile changed and must be updated on minimap
void onMapTileChanged(const int3 & mapPosition);
/// Called by PlayerInterface when unknown number of tiles changed and minimap should redraw
void onMapTilesChanged();
/// Called by PlayerInterface when hero state changed and hero list must be updated
void onHeroChanged(const CGHeroInstance * hero);
/// Called by PlayerInterface when town state changed and town list must be updated
void onTownChanged(const CGTownInstance * town);
2023-03-01 17:20:05 +02:00
/// Called when map audio should be paused, e.g. on combat or town scren access
void onAudioPaused();
/// Called when map audio should be resume, opposite to onPaused
void onAudioResumed();
/// Requests to display provided information inside infobox
void showInfoBoxMessage(const std::vector<Component> & components, std::string message, int timer);
/// Changes currently selected object
void setSelection(const CArmedInstance *sel, bool centerView = true);
/// Changes position on map to center selected location
void centerOnTile(int3 on);
void centerOnObject(const CGObjectInstance *obj);
/// called by MapView whenever currently visible area changes
/// visibleArea describes now visible map section measured in tiles
void onMapViewMoved(const Rect & visibleArea, int mapLevel);
2023-02-10 23:29:13 +02:00
/// called by MapView whenever tile is clicked
void onTileLeftClicked(const int3 & mapPos);
/// called by MapView whenever tile is hovered
void onTileHovered(const int3 & mapPos);
/// called by MapView whenever tile is clicked
void onTileRightClicked(const int3 & mapPos);
2023-02-10 23:29:13 +02:00
void enterCastingMode(const CSpell * sp);
void leaveCastingMode(bool cast = false, int3 dest = int3(-1, -1, -1));
2023-02-10 23:29:13 +02:00
const CGHeroInstance * getCurrentHero() const;
const CGTownInstance * getCurrentTown() const;
const CArmedInstance * getCurrentArmy() const;
2015-01-13 21:57:41 +02:00
2023-02-10 23:29:13 +02:00
/// returns area of screen covered by terrain (main game area)
Rect terrainAreaPixels() const;
/// exits currently opened world view mode and returns to normal map
void exitWorldView();
/// opens world view at default scale
void openWorldView();
/// opens world view at specific scale
void openWorldView(int tileSize);
/// opens world view with specific info, e.g. after View Earth/Air is shown
void openWorldView(const std::vector<ObjectPosInfo>& objectPositions, bool showTerrain);
};
extern std::shared_ptr<CAdventureMapInterface> adventureInt;