1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-03 00:46:55 +02:00
Files
vcmi/client/windows/CAdvmapInterface.h

277 lines
8.2 KiB
C
Raw Permalink Normal View History

/*
* 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
*
*/
#pragma once
#include "../widgets/AdventureMapClasses.h"
#include "CWindowObject.h"
#include "../widgets/TextControls.h"
#include "../widgets/Buttons.h"
#include "../../lib/spells/ViewSpellInt.h"
class CCallback;
struct CGPath;
class CAdvMapInt;
class CGHeroInstance;
class CGTownInstance;
class CHeroWindow;
class CSpell;
class IShipyard;
enum class EMapAnimRedrawStatus;
class CFadeAnimation;
struct MapDrawingInfo;
/*****************************/
2015-01-13 20:57:41 +01:00
enum class EAdvMapMode
{
NORMAL,
WORLD_VIEW
};
/// Adventure options dialogue where you can view the world, dig, play the replay of the last turn,...
class CAdventureOptions : public CWindowObject
{
public:
CButton * exit, * viewWorld, * puzzle, * dig, * scenInfo /*, *replay*/;
CAdventureOptions();
static void showScenarioInfo();
};
/// Holds information about which tiles of the terrain are shown/not shown at the screen
class CTerrainRect : public CIntObject
{
SDL_Surface * fadeSurface;
EMapAnimRedrawStatus lastRedrawStatus;
CFadeAnimation * fadeAnim;
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);
/// handles start/finish of swipe (press/release of corresponding button); returns true if state change was handled
bool handleSwipeStateChange(bool btnPressed);
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)
CTerrainRect();
virtual ~CTerrainRect();
CGPath * currentPath;
void deactivate() override;
void clickLeft(tribool down, bool previousState) override;
void clickRight(tribool down, bool previousState) override;
void clickMiddle(tribool down, bool previousState) override;
void hover(bool on) override;
void mouseMoved(const SDL_MouseMotionEvent & sEvent) override;
void show(SDL_Surface * to) override;
void showAll(SDL_Surface * to) override;
void showAnim(SDL_Surface * to);
2009-11-14 20:14:15 +00:00
void showPath(const SDL_Rect * extRect, SDL_Surface * to);
int3 whichTileIsIt(const int x, const int y); //x,y are cursor position
int3 whichTileIsIt(); //uses current cursor pos
2015-01-13 20:57:41 +01:00
/// @returns number of visible tiles on screen respecting current map scaling
int3 tileCountOnScreen();
/// animates view by caching current surface and crossfading it with normal screen
void fadeFromCurrentView();
bool needsAnimUpdate();
};
/// Resources bar which shows information about how many gold, crystals,... you have
/// Current date is displayed too
class CResDataBar : public CIntObject
{
public:
SDL_Surface * bg;
std::vector<std::pair<int, int>> txtpos;
std::string datetext;
void clickRight(tribool down, bool previousState) override;
CResDataBar();
CResDataBar(const std::string & defname, int x, int y, int offx, int offy, int resdist, int datedist);
~CResDataBar();
void draw(SDL_Surface * to);
void show(SDL_Surface * to) override;
void showAll(SDL_Surface * to) override;
};
2015-01-13 20:57:41 +01: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.
class CAdvMapInt : public CIntObject
{
//Return object that must be active at this tile (=clickable)
const CGObjectInstance * getActiveObject(const int3 & tile);
2012-05-14 16:29:06 +00:00
public:
CAdvMapInt();
~CAdvMapInt();
int3 position; //top left corner of visible map part
2013-03-03 17:06:03 +00:00
PlayerColor player;
bool duringAITurn;
enum
{
LEFT=1,
RIGHT=2,
UP=4,
DOWN=8
};
ui8 scrollingDir; //uses enum: LEFT RIGHT, UP, DOWN
bool scrollingState;
bool swipeEnabled;
bool swipeMovementRequested;
int3 swipeTargetPosition;
enum
{
NA,
INGAME,
WAITING
} state;
bool updateScreen;
ui8 anim, animValHitCount; //animation frame
ui8 heroAnim, heroAnimValHitCount; //animation frame
2015-01-13 20:57:41 +01:00
EAdvMapMode mode;
float worldViewScale;
2016-10-18 04:09:52 +03:00
struct WorldViewOptions
{
bool showAllTerrain; //for expert viewEarth
2016-10-18 04:09:52 +03:00
std::vector<ObjectPosInfo> iconPositions;
2016-10-18 04:09:52 +03:00
WorldViewOptions();
2016-10-18 04:09:52 +03:00
void clear();
2016-10-18 04:09:52 +03:00
void adjustDrawingInfo(MapDrawingInfo & info);
};
2016-10-18 04:09:52 +03:00
WorldViewOptions worldViewOptions;
2015-01-13 20:57:41 +01:00
SDL_Surface * bg;
2015-01-13 20:57:41 +01:00
SDL_Surface * bgWorldView;
2016-10-18 04:09:52 +03:00
std::vector<CAnimImage *> gems;
CMinimap minimap;
CGStatusBar statusbar;
2009-04-14 10:46:42 +00:00
CButton * kingOverview;
CButton * underground;
CButton * questlog;
CButton * sleepWake;
CButton * moveHero;
CButton * spellbook;
CButton * advOptions;
CButton * sysOptions;
CButton * nextHero;
CButton * endTurn;
2015-01-13 20:57:41 +01:00
CButton * worldViewUnderground;
CTerrainRect terrain; //visible terrain
CResDataBar resdatabar;
CHeroList heroList;
CTownList townList;
CInfoBar infoBar;
CAdvMapPanel * panelMain; // panel that holds all right-side buttons in normal view
CAdvMapWorldViewPanel * panelWorldView; // panel that holds all buttons and other ui in world view
CAdvMapPanel * activeMapPanel; // currently active panel (either main or world view, depending on current mode)
std::shared_ptr<CAnimation> worldViewIcons; // images for world view overlay
2015-01-13 20:57:41 +01:00
const CSpell * spellBeingCasted; //nullptr if none
const CArmedInstance * selection; //currently selected town/hero
2009-06-24 03:04:59 +00:00
//functions bound to buttons
void fshowOverview();
2015-01-13 20:57:41 +01: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();
void activate() override;
void deactivate() override;
void show(SDL_Surface * to) override; //redraws terrain
void showAll(SDL_Surface * to) override; //shows and activates adv. map interface
void select(const CArmedInstance * sel, bool centerView = true);
void selectionChanged();
2015-02-02 17:42:42 +01:00
void centerOn(int3 on, bool fade = false);
void centerOn(const CGObjectInstance * obj, bool fade = false);
int3 verifyPos(int3 ver);
void handleRightClick(std::string text, tribool down);
void keyPressed(const SDL_KeyboardEvent & key) override;
void mouseMoved(const SDL_MouseMotionEvent & sEvent) override;
bool isActive();
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
2013-03-03 17:06:03 +00:00
void setPlayer(PlayerColor Player);
void startHotSeatWait(PlayerColor Player);
void startTurn();
void endingTurn();
void aiTurnStarted();
void adjustActiveness(bool aiTurnStart); //should be called every time at AI/human turn transition; blocks GUI during AI turn
void quickCombatLock(); //should be called when quick battle started
void quickCombatUnlock();
void tileLClicked(const int3 & mapPos);
void tileHovered(const int3 & mapPos);
void tileRClicked(const int3 & mapPos);
void enterCastingMode(const CSpell * sp);
void leaveCastingMode(bool cast = false, int3 dest = int3(-1, -1, -1));
const CGHeroInstance * curHero() const;
const CGTownInstance * curTown() const;
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 updateMoveHero(const CGHeroInstance * h, tribool hasPath = boost::logic::indeterminate);
void updateSpellbook(const CGHeroInstance * h);
void updateNextHero(const CGHeroInstance * h);
2015-01-13 20:57:41 +01:00
/// changes current adventure map mode; used to switch between default view and world view; scale is ignored if EAdvMapMode == NORMAL
void changeMode(EAdvMapMode newMode, float newScale = 0.36f);
void handleMapScrollingUpdate();
void handleSwipeUpdate();
};
extern CAdvMapInt * adventureInt;