2017-07-13 10:26:03 +02:00
/*
* CAdvmapInterface . 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
*
*/
2011-12-14 00:23:17 +03:00
# pragma once
2014-07-13 20:53:37 +03:00
# include "../widgets/AdventureMapClasses.h"
2014-07-15 10:14:49 +03:00
# include "CWindowObject.h"
# include "../widgets/TextControls.h"
# include "../widgets/Buttons.h"
2011-12-14 00:23:17 +03:00
2015-02-26 16:15:17 +02:00
# include "../../lib/spells/ViewSpellInt.h"
2022-07-26 15:07:42 +02:00
VCMI_LIB_NAMESPACE_BEGIN
2009-09-07 05:29:44 +03:00
struct CGPath ;
2008-12-27 03:01:59 +02:00
class CGHeroInstance ;
class CGTownInstance ;
2010-03-21 00:17:19 +02:00
class CSpell ;
2010-07-13 08:25:40 +03:00
class IShipyard ;
2022-07-26 15:07:42 +02:00
VCMI_LIB_NAMESPACE_END
class CCallback ;
class CAdvMapInt ;
class CHeroWindow ;
2015-01-31 00:37:28 +02:00
enum class EMapAnimRedrawStatus ;
class CFadeAnimation ;
2010-07-13 08:25:40 +03:00
2015-02-02 14:02:27 +02:00
struct MapDrawingInfo ;
2008-12-27 03:01:59 +02:00
/*****************************/
2009-04-15 17:03:31 +03:00
2015-01-13 21:57:41 +02:00
enum class EAdvMapMode
{
NORMAL ,
WORLD_VIEW
} ;
2018-04-07 13:34:11 +02:00
/// Adventure options dialog where you can view the world, dig, play the replay of the last turn,...
2014-07-15 10:14:49 +03:00
class CAdventureOptions : public CWindowObject
{
public :
2018-04-07 13:34:11 +02:00
std : : shared_ptr < CButton > exit ;
std : : shared_ptr < CButton > viewWorld ;
std : : shared_ptr < CButton > puzzle ;
std : : shared_ptr < CButton > dig ;
std : : shared_ptr < CButton > scenInfo ;
/*std::shared_ptr<CButton> replay*/
2014-07-15 10:14:49 +03:00
CAdventureOptions ( ) ;
static void showScenarioInfo ( ) ;
} ;
2011-02-22 13:52:36 +02:00
/// Holds information about which tiles of the terrain are shown/not shown at the screen
2018-04-07 13:34:11 +02:00
class CTerrainRect : public CIntObject
2008-12-27 03:01:59 +02:00
{
2015-01-31 00:37:28 +02:00
SDL_Surface * fadeSurface ;
EMapAnimRedrawStatus lastRedrawStatus ;
2018-04-07 13:34:11 +02:00
std : : shared_ptr < CFadeAnimation > fadeAnim ;
2017-05-25 19:57:20 +02:00
int3 swipeInitialMapPos ;
int3 swipeInitialRealPos ;
bool isSwiping ;
static constexpr float SwipeTouchSlop = 16.0f ;
2017-06-08 21:07:09 +02:00
void handleHover ( const SDL_MouseMotionEvent & sEvent ) ;
void handleSwipeMove ( const SDL_MouseMotionEvent & sEvent ) ;
2017-06-07 22:42:41 +02:00
/// handles start/finish of swipe (press/release of corresponding button); returns true if state change was handled
bool handleSwipeStateChange ( bool btnPressed ) ;
2008-12-27 03:01:59 +02:00
public :
int tilesw , tilesh ; //width and height of terrain to blit in tiles
int3 curHoveredTile ;
int moveX , moveY ; //shift between actual position of screen and the one we wil blit; ranges from -31 to 31 (in pixels)
2018-04-07 13:34:11 +02:00
CGPath * currentPath ;
2008-12-27 03:01:59 +02:00
CTerrainRect ( ) ;
2015-01-31 00:37:28 +02:00
virtual ~ CTerrainRect ( ) ;
2015-10-12 15:47:10 +02:00
void deactivate ( ) override ;
void clickLeft ( tribool down , bool previousState ) override ;
void clickRight ( tribool down , bool previousState ) override ;
2017-06-07 22:42:41 +02:00
void clickMiddle ( tribool down , bool previousState ) override ;
2015-10-12 15:47:10 +02:00
void hover ( bool on ) override ;
void mouseMoved ( const SDL_MouseMotionEvent & sEvent ) override ;
void show ( SDL_Surface * to ) override ;
void showAll ( SDL_Surface * to ) override ;
2015-01-31 00:37:28 +02:00
void showAnim ( SDL_Surface * to ) ;
2009-11-14 22:14:15 +02:00
void showPath ( const SDL_Rect * extRect , SDL_Surface * to ) ;
2016-01-09 14:32:42 +02:00
int3 whichTileIsIt ( const int x , const int y ) ; //x,y are cursor position
2008-12-27 03:01:59 +02:00
int3 whichTileIsIt ( ) ; //uses current cursor pos
2015-01-13 21:57:41 +02:00
/// @returns number of visible tiles on screen respecting current map scaling
int3 tileCountOnScreen ( ) ;
2015-01-31 00:37:28 +02:00
/// animates view by caching current surface and crossfading it with normal screen
void fadeFromCurrentView ( ) ;
bool needsAnimUpdate ( ) ;
2008-12-27 03:01:59 +02:00
} ;
2011-02-22 13:52:36 +02:00
/// Resources bar which shows information about how many gold, crystals,... you have
/// Current date is displayed too
2012-06-13 16:04:06 +03:00
class CResDataBar : public CIntObject
2008-12-27 03:01:59 +02:00
{
public :
2018-04-07 13:34:11 +02:00
std : : shared_ptr < CPicture > background ;
2008-12-27 03:01:59 +02:00
std : : vector < std : : pair < int , int > > txtpos ;
std : : string datetext ;
2015-10-12 15:47:10 +02:00
void clickRight ( tribool down , bool previousState ) override ;
2008-12-27 03:01:59 +02:00
CResDataBar ( ) ;
CResDataBar ( const std : : string & defname , int x , int y , int offx , int offy , int resdist , int datedist ) ;
~ CResDataBar ( ) ;
2009-04-14 15:47:09 +03:00
void draw ( SDL_Surface * to ) ;
2015-10-12 15:47:10 +02:00
void show ( SDL_Surface * to ) override ;
void showAll ( SDL_Surface * to ) override ;
2008-12-27 03:01:59 +02:00
} ;
2011-02-22 13:52:36 +02:00
2015-01-13 21:57:41 +02:00
/// 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.
2011-02-22 13:52:36 +02:00
class CAdvMapInt : public CIntObject
2008-12-27 03:01:59 +02:00
{
2014-07-01 17:19:08 +03:00
//Return object that must be active at this tile (=clickable)
const CGObjectInstance * getActiveObject ( const int3 & tile ) ;
2012-05-14 19:29:06 +03:00
2008-12-27 03:01:59 +02:00
public :
2010-02-20 15:24:38 +02:00
CAdvMapInt ( ) ;
2008-12-27 03:01:59 +02:00
~ CAdvMapInt ( ) ;
int3 position ; //top left corner of visible map part
2013-03-03 20:06:03 +03:00
PlayerColor player ;
2008-12-27 03:01:59 +02:00
2012-02-22 16:41:27 +03:00
bool duringAITurn ;
2008-12-27 03:01:59 +02:00
2009-02-11 19:03:30 +02:00
enum { LEFT = 1 , RIGHT = 2 , UP = 4 , DOWN = 8 } ;
ui8 scrollingDir ; //uses enum: LEFT RIGHT, UP, DOWN
2016-10-17 12:44:47 +02:00
bool scrollingState ;
2017-05-25 19:57:20 +02:00
bool swipeEnabled ;
bool swipeMovementRequested ;
int3 swipeTargetPosition ;
2009-06-11 20:21:06 +03:00
2010-02-20 15:24:38 +02:00
enum { NA , INGAME , WAITING } state ;
2012-06-13 16:04:06 +03:00
bool updateScreen ;
2011-12-14 00:23:17 +03:00
ui8 anim , animValHitCount ; //animation frame
ui8 heroAnim , heroAnimValHitCount ; //animation frame
2008-12-27 03:01:59 +02:00
2015-01-13 21:57:41 +02:00
EAdvMapMode mode ;
float worldViewScale ;
2016-10-18 03:09:52 +02:00
2015-02-02 14:02:27 +02:00
struct WorldViewOptions
{
bool showAllTerrain ; //for expert viewEarth
2016-10-18 03:09:52 +02:00
2015-02-26 16:15:17 +02:00
std : : vector < ObjectPosInfo > iconPositions ;
2016-10-18 03:09:52 +02:00
2015-02-02 14:02:27 +02:00
WorldViewOptions ( ) ;
2016-10-18 03:09:52 +02:00
2015-02-02 14:02:27 +02:00
void clear ( ) ;
2016-10-18 03:09:52 +02:00
void adjustDrawingInfo ( MapDrawingInfo & info ) ;
2015-02-02 14:02:27 +02:00
} ;
2016-10-18 03:09:52 +02:00
WorldViewOptions worldViewOptions ;
2015-01-13 21:57:41 +02:00
2008-12-27 03:01:59 +02:00
SDL_Surface * bg ;
2015-01-13 21:57:41 +02:00
SDL_Surface * bgWorldView ;
2018-04-07 13:34:11 +02:00
std : : vector < std : : shared_ptr < CAnimImage > > gems ;
2009-06-11 20:21:06 +03:00
CMinimap minimap ;
2018-08-26 18:09:56 +02:00
std : : shared_ptr < CGStatusBar > statusbar ;
2009-04-14 13:46:42 +03:00
2018-04-07 13:34:11 +02:00
std : : shared_ptr < CButton > kingOverview ;
std : : shared_ptr < CButton > underground ;
std : : shared_ptr < CButton > questlog ;
std : : shared_ptr < CButton > sleepWake ;
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 ;
2008-12-27 03:01:59 +02:00
2018-04-07 13:34:11 +02:00
std : : shared_ptr < CButton > worldViewUnderground ;
2015-01-13 21:57:41 +02:00
2008-12-27 03:01:59 +02:00
CTerrainRect terrain ; //visible terrain
CResDataBar resdatabar ;
CHeroList heroList ;
CTownList townList ;
CInfoBar infoBar ;
2018-04-07 13:34:11 +02:00
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)
2015-01-15 01:22:20 +02:00
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
2013-06-26 14:18:27 +03:00
const CSpell * spellBeingCasted ; //nullptr if none
2010-03-21 00:17:19 +02:00
2009-06-11 20:21:06 +03:00
const CArmedInstance * selection ; //currently selected town/hero
2008-12-27 03:01:59 +02:00
2009-06-24 06:04:59 +03:00
//functions bound to buttons
2008-12-27 03:01:59 +02:00
void fshowOverview ( ) ;
2015-01-13 21:57:41 +02:00
void fworldViewBack ( ) ;
void fworldViewScale1x ( ) ;
void fworldViewScale2x ( ) ;
void fworldViewScale4x ( ) ;
2008-12-27 03:01:59 +02:00
void fswitchLevel ( ) ;
void fshowQuestlog ( ) ;
void fsleepWake ( ) ;
void fmoveHero ( ) ;
void fshowSpellbok ( ) ;
void fadventureOPtions ( ) ;
void fsystemOptions ( ) ;
void fnextHero ( ) ;
void fendTurn ( ) ;
2015-10-12 15:47:10 +02:00
void activate ( ) override ;
void deactivate ( ) override ;
2008-12-27 03:01:59 +02:00
2015-10-12 15:47:10 +02:00
void show ( SDL_Surface * to ) override ; //redraws terrain
void showAll ( SDL_Surface * to ) override ; //shows and activates adv. map interface
2008-12-27 03:01:59 +02:00
2010-03-21 00:17:19 +02:00
void select ( const CArmedInstance * sel , bool centerView = true ) ;
2008-12-27 03:01:59 +02:00
void selectionChanged ( ) ;
2015-02-02 18:42:42 +02:00
void centerOn ( int3 on , bool fade = false ) ;
void centerOn ( const CGObjectInstance * obj , bool fade = false ) ;
2008-12-27 03:01:59 +02:00
int3 verifyPos ( int3 ver ) ;
2010-03-21 00:17:19 +02:00
void handleRightClick ( std : : string text , tribool down ) ;
2015-10-12 15:47:10 +02:00
void keyPressed ( const SDL_KeyboardEvent & key ) override ;
void mouseMoved ( const SDL_MouseMotionEvent & sEvent ) override ;
2009-12-28 06:08:24 +02:00
bool isActive ( ) ;
2010-02-20 15:24:38 +02:00
2011-09-24 19:46:23 +03:00
bool isHeroSleeping ( const CGHeroInstance * hero ) ;
void setHeroSleeping ( const CGHeroInstance * hero , bool sleep ) ;
2011-10-04 22:43:49 +03:00
int getNextHeroIndex ( int startIndex ) ; //for Next Hero button - cycles awake heroes with movement only
2011-09-24 19:46:23 +03:00
2013-03-03 20:06:03 +03:00
void setPlayer ( PlayerColor Player ) ;
void startHotSeatWait ( PlayerColor Player ) ;
2010-02-20 15:24:38 +02:00
void startTurn ( ) ;
2011-09-24 19:46:23 +03:00
void endingTurn ( ) ;
2012-02-22 16:41:27 +03:00
void aiTurnStarted ( ) ;
2014-03-23 15:59:03 +03:00
void adjustActiveness ( bool aiTurnStart ) ; //should be called every time at AI/human turn transition; blocks GUI during AI turn
2016-01-10 17:00:24 +02:00
void quickCombatLock ( ) ; //should be called when quick battle started
void quickCombatUnlock ( ) ;
2012-05-14 19:29:06 +03:00
void tileLClicked ( const int3 & mapPos ) ;
void tileHovered ( const int3 & mapPos ) ;
void tileRClicked ( const int3 & mapPos ) ;
2010-03-21 00:17:19 +02:00
void enterCastingMode ( const CSpell * sp ) ;
void leaveCastingMode ( bool cast = false , int3 dest = int3 ( - 1 , - 1 , - 1 ) ) ;
const CGHeroInstance * curHero ( ) const ;
const CGTownInstance * curTown ( ) const ;
2013-06-26 14:18:27 +03:00
const IShipyard * ourInaccessibleShipyard ( const CGObjectInstance * obj ) const ; //checks if obj is our ashipyard and cursor is 0,0 -> returns shipyard or nullptr else
2011-10-04 22:43:49 +03:00
//button updates
2015-01-13 21:57:41 +02:00
void updateSleepWake ( const CGHeroInstance * h ) ;
2013-04-21 15:28:26 +03:00
void updateMoveHero ( const CGHeroInstance * h , tribool hasPath = boost : : logic : : indeterminate ) ;
2015-12-06 02:12:39 +02:00
void updateSpellbook ( const CGHeroInstance * h ) ;
2011-10-04 22:43:49 +03:00
void updateNextHero ( const CGHeroInstance * h ) ;
2015-01-13 21:57:41 +02:00
/// changes current adventure map mode; used to switch between default view and world view; scale is ignored if EAdvMapMode == NORMAL
2015-01-19 21:08:19 +02:00
void changeMode ( EAdvMapMode newMode , float newScale = 0.36f ) ;
2017-05-25 19:57:20 +02:00
void handleMapScrollingUpdate ( ) ;
void handleSwipeUpdate ( ) ;
2008-12-27 03:01:59 +02:00
} ;
2010-02-20 15:24:38 +02:00
2018-07-25 00:36:48 +02:00
extern std : : shared_ptr < CAdvMapInt > adventureInt ;