2017-07-13 10:26:03 +02:00
|
|
|
/*
|
2023-02-01 16:42:03 +02:00
|
|
|
* CTerrainRect.cpp, part of VCMI engine
|
2017-07-13 10:26:03 +02:00
|
|
|
*
|
|
|
|
* 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
|
|
|
#include "StdInc.h"
|
2023-02-01 20:42:06 +02:00
|
|
|
#include "CTerrainRect.h"
|
2011-12-14 00:23:17 +03:00
|
|
|
|
2023-02-01 20:42:06 +02:00
|
|
|
#include "mapHandler.h"
|
|
|
|
#include "CAdvMapInt.h"
|
2014-07-13 20:53:37 +03:00
|
|
|
|
|
|
|
#include "../CGameInfo.h"
|
|
|
|
#include "../CPlayerInterface.h"
|
2023-01-05 19:34:37 +02:00
|
|
|
#include "../gui/CursorHandler.h"
|
2014-07-13 20:53:37 +03:00
|
|
|
#include "../gui/CGuiHandler.h"
|
2023-02-01 20:42:06 +02:00
|
|
|
#include "../render/CAnimation.h"
|
|
|
|
#include "../render/CFadeAnimation.h"
|
|
|
|
#include "../render/IImage.h"
|
|
|
|
#include "../renderSDL/SDL_Extensions.h"
|
|
|
|
#include "../widgets/TextControls.h"
|
2023-02-03 18:23:53 +02:00
|
|
|
#include "../CMT.h"
|
2014-07-13 20:53:37 +03:00
|
|
|
|
|
|
|
#include "../../CCallback.h"
|
|
|
|
#include "../../lib/CConfigHandler.h"
|
|
|
|
#include "../../lib/mapping/CMap.h"
|
2023-02-01 20:42:06 +02:00
|
|
|
#include "../../lib/CPathfinder.h"
|
2008-12-21 21:17:35 +02:00
|
|
|
|
2023-02-02 18:02:25 +02:00
|
|
|
#include <SDL_surface.h>
|
2023-01-30 19:55:32 +02:00
|
|
|
|
2008-11-12 20:26:23 +02:00
|
|
|
#define ADVOPT (conf.go()->ac)
|
2009-01-12 22:05:56 +02:00
|
|
|
|
|
|
|
CTerrainRect::CTerrainRect()
|
2015-10-31 19:23:13 +02:00
|
|
|
: fadeSurface(nullptr),
|
2016-11-27 18:00:16 +02:00
|
|
|
lastRedrawStatus(EMapAnimRedrawStatus::OK),
|
2018-04-07 13:34:11 +02:00
|
|
|
fadeAnim(std::make_shared<CFadeAnimation>()),
|
2015-10-31 19:23:13 +02:00
|
|
|
curHoveredTile(-1,-1,-1),
|
2015-01-31 00:37:28 +02:00
|
|
|
currentPath(nullptr)
|
2007-08-17 20:42:21 +03:00
|
|
|
{
|
2009-06-14 18:10:59 +03:00
|
|
|
tilesw=(ADVOPT.advmapW+31)/32;
|
|
|
|
tilesh=(ADVOPT.advmapH+31)/32;
|
2008-11-28 03:36:34 +02:00
|
|
|
pos.x=ADVOPT.advmapX;
|
|
|
|
pos.y=ADVOPT.advmapY;
|
2009-06-14 18:10:59 +03:00
|
|
|
pos.w=ADVOPT.advmapW;
|
|
|
|
pos.h=ADVOPT.advmapH;
|
2008-10-17 19:30:56 +03:00
|
|
|
moveX = moveY = 0;
|
2017-06-07 22:42:41 +02:00
|
|
|
addUsedEvents(LCLICK | RCLICK | MCLICK | HOVER | MOVE);
|
2007-08-17 20:42:21 +03:00
|
|
|
}
|
2012-06-02 18:16:54 +03:00
|
|
|
|
2015-01-31 00:37:28 +02:00
|
|
|
CTerrainRect::~CTerrainRect()
|
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
if(fadeSurface)
|
2015-01-31 00:37:28 +02:00
|
|
|
SDL_FreeSurface(fadeSurface);
|
|
|
|
}
|
|
|
|
|
2007-08-04 22:01:22 +03:00
|
|
|
void CTerrainRect::deactivate()
|
|
|
|
{
|
2012-06-02 18:16:54 +03:00
|
|
|
CIntObject::deactivate();
|
2009-11-13 23:01:33 +02:00
|
|
|
curHoveredTile = int3(-1,-1,-1); //we lost info about hovered tile when disabling
|
2011-02-23 20:21:51 +02:00
|
|
|
}
|
2012-06-02 18:16:54 +03:00
|
|
|
|
2009-08-11 19:05:33 +03:00
|
|
|
void CTerrainRect::clickLeft(tribool down, bool previousState)
|
2007-09-22 04:16:31 +03:00
|
|
|
{
|
2017-05-25 19:57:20 +02:00
|
|
|
if(adventureInt->mode == EAdvMapMode::WORLD_VIEW)
|
2015-01-13 21:57:41 +02:00
|
|
|
return;
|
2017-05-25 19:57:20 +02:00
|
|
|
if(indeterminate(down))
|
2007-09-22 04:16:31 +03:00
|
|
|
return;
|
2010-03-21 00:17:19 +02:00
|
|
|
|
2023-02-27 12:00:13 +02:00
|
|
|
#if defined(VCMI_MOBILE)
|
2017-05-25 19:57:20 +02:00
|
|
|
if(adventureInt->swipeEnabled)
|
|
|
|
{
|
2019-01-24 17:34:58 +02:00
|
|
|
if(handleSwipeStateChange((bool)down == true))
|
2017-05-25 19:57:20 +02:00
|
|
|
{
|
|
|
|
return; // if swipe is enabled, we don't process "down" events and wait for "up" (to make sure this wasn't a swiping gesture)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
#endif
|
|
|
|
if(down == false)
|
|
|
|
return;
|
2023-02-27 12:00:13 +02:00
|
|
|
#if defined(VCMI_MOBILE)
|
2017-05-25 19:57:20 +02:00
|
|
|
}
|
|
|
|
#endif
|
2008-08-28 20:36:34 +03:00
|
|
|
int3 mp = whichTileIsIt();
|
2017-05-25 19:57:20 +02:00
|
|
|
if(mp.x < 0 || mp.y < 0 || mp.x >= LOCPLINT->cb->getMapSize().x || mp.y >= LOCPLINT->cb->getMapSize().y)
|
2008-08-28 20:36:34 +03:00
|
|
|
return;
|
2009-04-21 01:57:07 +03:00
|
|
|
|
2010-03-21 00:17:19 +02:00
|
|
|
adventureInt->tileLClicked(mp);
|
2007-09-22 04:16:31 +03:00
|
|
|
}
|
2012-06-02 18:16:54 +03:00
|
|
|
|
2009-08-11 19:05:33 +03:00
|
|
|
void CTerrainRect::clickRight(tribool down, bool previousState)
|
2007-09-22 04:16:31 +03:00
|
|
|
{
|
2023-02-27 12:00:13 +02:00
|
|
|
#if defined(VCMI_MOBILE)
|
2017-05-25 19:57:20 +02:00
|
|
|
if(adventureInt->swipeEnabled && isSwiping)
|
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
if(adventureInt->mode == EAdvMapMode::WORLD_VIEW)
|
2015-01-13 21:57:41 +02:00
|
|
|
return;
|
2009-01-14 21:01:20 +02:00
|
|
|
int3 mp = whichTileIsIt();
|
2009-10-22 05:25:12 +03:00
|
|
|
|
2017-05-25 19:57:20 +02:00
|
|
|
if(CGI->mh->map->isInTheMap(mp) && down)
|
2011-05-26 01:44:02 +03:00
|
|
|
adventureInt->tileRClicked(mp);
|
2007-09-22 04:16:31 +03:00
|
|
|
}
|
2011-05-26 01:44:02 +03:00
|
|
|
|
2017-06-07 22:42:41 +02:00
|
|
|
void CTerrainRect::clickMiddle(tribool down, bool previousState)
|
|
|
|
{
|
2019-01-24 17:30:09 +02:00
|
|
|
handleSwipeStateChange((bool)down == true);
|
2017-06-07 22:42:41 +02:00
|
|
|
}
|
|
|
|
|
2023-02-02 15:49:23 +02:00
|
|
|
void CTerrainRect::mouseMoved(const Point & cursorPosition)
|
2007-09-22 04:16:31 +03:00
|
|
|
{
|
2023-02-02 15:49:23 +02:00
|
|
|
handleHover(cursorPosition);
|
2017-05-25 19:57:20 +02:00
|
|
|
|
2017-06-07 22:42:41 +02:00
|
|
|
if(!adventureInt->swipeEnabled)
|
2017-05-25 19:57:20 +02:00
|
|
|
return;
|
|
|
|
|
2023-02-02 15:49:23 +02:00
|
|
|
handleSwipeMove(cursorPosition);
|
2017-05-25 19:57:20 +02:00
|
|
|
}
|
|
|
|
|
2023-02-02 15:49:23 +02:00
|
|
|
void CTerrainRect::handleSwipeMove(const Point & cursorPosition)
|
2017-05-25 19:57:20 +02:00
|
|
|
{
|
2023-02-27 12:00:13 +02:00
|
|
|
#if defined(VCMI_MOBILE)
|
2023-02-02 15:49:23 +02:00
|
|
|
if(!GH.isMouseButtonPressed() || GH.multifinger) // any "button" is enough on mobile
|
|
|
|
return;
|
2021-03-13 13:08:13 +02:00
|
|
|
#else
|
2023-02-02 15:49:23 +02:00
|
|
|
if(!GH.isMouseButtonPressed(MouseButton::MIDDLE)) // swipe only works with middle mouse on other platforms
|
2017-06-07 22:42:41 +02:00
|
|
|
return;
|
2023-02-02 15:49:23 +02:00
|
|
|
#endif
|
2017-06-07 22:42:41 +02:00
|
|
|
|
2017-05-25 19:57:20 +02:00
|
|
|
if(!isSwiping)
|
|
|
|
{
|
|
|
|
// try to distinguish if this touch was meant to be a swipe or just fat-fingering press
|
2023-02-02 15:49:23 +02:00
|
|
|
if(abs(cursorPosition.x - swipeInitialRealPos.x) > SwipeTouchSlop ||
|
|
|
|
abs(cursorPosition.y - swipeInitialRealPos.y) > SwipeTouchSlop)
|
2017-05-25 19:57:20 +02:00
|
|
|
{
|
|
|
|
isSwiping = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(isSwiping)
|
|
|
|
{
|
|
|
|
adventureInt->swipeTargetPosition.x =
|
2023-02-02 15:49:23 +02:00
|
|
|
swipeInitialMapPos.x + static_cast<si32>(swipeInitialRealPos.x - cursorPosition.x) / 32;
|
2017-05-25 19:57:20 +02:00
|
|
|
adventureInt->swipeTargetPosition.y =
|
2023-02-02 15:49:23 +02:00
|
|
|
swipeInitialMapPos.y + static_cast<si32>(swipeInitialRealPos.y - cursorPosition.y) / 32;
|
2017-05-25 19:57:20 +02:00
|
|
|
adventureInt->swipeMovementRequested = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-07 22:42:41 +02:00
|
|
|
bool CTerrainRect::handleSwipeStateChange(bool btnPressed)
|
|
|
|
{
|
|
|
|
if(btnPressed)
|
|
|
|
{
|
2023-02-02 15:49:23 +02:00
|
|
|
swipeInitialRealPos = Point(GH.getCursorPosition().x, GH.getCursorPosition().y);
|
2017-06-07 22:42:41 +02:00
|
|
|
swipeInitialMapPos = int3(adventureInt->position);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if(isSwiping) // only accept this touch if it wasn't a swipe
|
|
|
|
{
|
|
|
|
isSwiping = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2017-05-25 19:57:20 +02:00
|
|
|
|
2023-02-02 15:49:23 +02:00
|
|
|
void CTerrainRect::handleHover(const Point & cursorPosition)
|
2017-05-25 19:57:20 +02:00
|
|
|
{
|
2023-02-02 15:49:23 +02:00
|
|
|
int3 tHovered = whichTileIsIt(cursorPosition.x, cursorPosition.y);
|
2010-02-20 15:24:38 +02:00
|
|
|
int3 pom = adventureInt->verifyPos(tHovered);
|
2009-09-24 16:23:52 +03:00
|
|
|
|
|
|
|
if(tHovered != pom) //tile outside the map
|
|
|
|
{
|
2022-12-18 22:32:07 +02:00
|
|
|
CCS->curh->set(Cursor::Map::POINTER);
|
2009-09-24 16:23:52 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pom != curHoveredTile)
|
2017-05-25 19:57:20 +02:00
|
|
|
{
|
2015-11-18 02:14:58 +02:00
|
|
|
curHoveredTile = pom;
|
2017-05-25 19:57:20 +02:00
|
|
|
adventureInt->tileHovered(pom);
|
|
|
|
}
|
2007-09-22 04:16:31 +03:00
|
|
|
}
|
2017-05-25 19:57:20 +02:00
|
|
|
|
2007-10-07 17:51:09 +03:00
|
|
|
void CTerrainRect::hover(bool on)
|
|
|
|
{
|
|
|
|
if (!on)
|
2009-05-02 01:08:03 +03:00
|
|
|
{
|
2023-02-10 23:29:13 +02:00
|
|
|
GH.statusbar->clear();
|
2022-12-18 22:32:07 +02:00
|
|
|
CCS->curh->set(Cursor::Map::POINTER);
|
2009-05-02 01:08:03 +03:00
|
|
|
}
|
2009-08-11 19:05:33 +03:00
|
|
|
//Hoverable::hover(on);
|
2007-10-07 17:51:09 +03:00
|
|
|
}
|
2023-01-17 22:01:35 +02:00
|
|
|
void CTerrainRect::showPath(const Rect & extRect, SDL_Surface * to)
|
2007-08-04 22:01:22 +03:00
|
|
|
{
|
2011-05-21 11:44:02 +03:00
|
|
|
const static int pns[9][9] = {
|
|
|
|
{16, 17, 18, 7, -1, 19, 6, 5, -1},
|
|
|
|
{ 8, 9, 18, 7, -1, 19, 6, -1, 20},
|
|
|
|
{ 8, 1, 10, 7, -1, 19, -1, 21, 20},
|
|
|
|
{24, 17, 18, 15, -1, -1, 6, 5, 4},
|
|
|
|
{-1, -1, -1, -1, -1, -1, -1, -1, -1},
|
|
|
|
{ 8, 1, 2, -1, -1, 11, 22, 21, 20},
|
|
|
|
{24, 17, -1, 23, -1, 3, 14, 5, 4},
|
|
|
|
{24, -1, 2, 23, -1, 3, 22, 13, 4},
|
|
|
|
{-1, 1, 2, 23, -1, 3, 22, 21, 12}
|
|
|
|
}; //table of magic values TODO meaning, change variable name
|
|
|
|
|
2022-06-20 16:39:50 +02:00
|
|
|
for (int i = 0; i < -1 + (int)currentPath->nodes.size(); ++i)
|
2007-08-17 20:42:21 +03:00
|
|
|
{
|
2011-09-19 23:50:25 +03:00
|
|
|
const int3 &curPos = currentPath->nodes[i].coord, &nextPos = currentPath->nodes[i+1].coord;
|
|
|
|
if(curPos.z != adventureInt->position.z)
|
|
|
|
continue;
|
|
|
|
|
2007-12-22 16:40:27 +02:00
|
|
|
int pn=-1;//number of picture
|
|
|
|
if (i==0) //last tile
|
|
|
|
{
|
2011-09-19 23:50:25 +03:00
|
|
|
int x = 32*(curPos.x-adventureInt->position.x)+CGI->mh->offsetX + pos.x,
|
|
|
|
y = 32*(curPos.y-adventureInt->position.y)+CGI->mh->offsetY + pos.y;
|
2007-12-22 16:40:27 +02:00
|
|
|
if (x<0 || y<0 || x>pos.w || y>pos.h)
|
|
|
|
continue;
|
|
|
|
pn=0;
|
|
|
|
}
|
|
|
|
else
|
2007-08-17 20:42:21 +03:00
|
|
|
{
|
2011-09-19 23:50:25 +03:00
|
|
|
const int3 &prevPos = currentPath->nodes[i-1].coord;
|
|
|
|
std::vector<CGPathNode> & cv = currentPath->nodes;
|
|
|
|
|
2011-05-21 04:10:41 +03:00
|
|
|
/* Vector directions
|
|
|
|
* 0 1 2
|
2012-01-12 18:23:00 +03:00
|
|
|
* \ | /
|
2011-05-21 04:10:41 +03:00
|
|
|
* 3 - 4 - 5
|
|
|
|
* / | \
|
|
|
|
* 6 7 8
|
|
|
|
*For example:
|
|
|
|
* |
|
|
|
|
* |__\
|
|
|
|
* /
|
|
|
|
* is id1=7, id2=5 (pns[7][5])
|
2012-01-12 18:23:00 +03:00
|
|
|
*/
|
2011-09-19 23:50:25 +03:00
|
|
|
bool pathContinuous = curPos.areNeighbours(nextPos) && curPos.areNeighbours(prevPos);
|
2015-11-08 03:01:58 +02:00
|
|
|
if(pathContinuous && cv[i].action != CGPathNode::EMBARK && cv[i].action != CGPathNode::DISEMBARK)
|
2011-09-19 23:50:25 +03:00
|
|
|
{
|
|
|
|
int id1=(curPos.x-nextPos.x+1)+3*(curPos.y-nextPos.y+1); //Direction of entering vector
|
|
|
|
int id2=(cv[i-1].coord.x-curPos.x+1)+3*(cv[i-1].coord.y-curPos.y+1); //Direction of exiting vector
|
|
|
|
pn=pns[id1][id2];
|
|
|
|
}
|
|
|
|
else //path discontinuity or sea/land transition (eg. when moving through Subterranean Gate or Boat)
|
|
|
|
{
|
|
|
|
pn = 0;
|
|
|
|
}
|
2007-12-22 16:40:27 +02:00
|
|
|
}
|
2009-09-07 05:29:44 +03:00
|
|
|
if (currentPath->nodes[i].turns)
|
2007-12-22 16:40:27 +02:00
|
|
|
pn+=25;
|
|
|
|
if (pn>=0)
|
|
|
|
{
|
2018-03-30 13:02:04 +02:00
|
|
|
const auto arrow = graphics->heroMoveArrows->getImage(pn);
|
2016-10-18 09:31:31 +02:00
|
|
|
|
2011-09-19 23:50:25 +03:00
|
|
|
int x = 32*(curPos.x-adventureInt->position.x)+CGI->mh->offsetX + pos.x,
|
|
|
|
y = 32*(curPos.y-adventureInt->position.y)+CGI->mh->offsetY + pos.y;
|
2012-05-15 11:47:11 +03:00
|
|
|
if (x< -32 || y< -32 || x>pos.w || y>pos.h)
|
2007-12-22 16:40:27 +02:00
|
|
|
continue;
|
2016-10-18 09:31:31 +02:00
|
|
|
int hvx = (x + arrow->width()) - (pos.x + pos.w),
|
|
|
|
hvy = (y + arrow->height()) - (pos.y + pos.h);
|
2009-01-09 15:03:47 +02:00
|
|
|
|
2023-01-17 22:01:35 +02:00
|
|
|
Rect prevClip;
|
|
|
|
CSDL_Ext::getClipRect(to, prevClip);
|
|
|
|
CSDL_Ext::setClipRect(to, extRect); //preventing blitting outside of that rect
|
2009-01-09 15:03:47 +02:00
|
|
|
|
|
|
|
if(ADVOPT.smoothMove) //version for smooth hero move, with pos shifts
|
2007-12-22 16:40:27 +02:00
|
|
|
{
|
2009-01-09 15:03:47 +02:00
|
|
|
if (hvx<0 && hvy<0)
|
|
|
|
{
|
2016-10-18 09:31:31 +02:00
|
|
|
arrow->draw(to, x + moveX, y + moveY);
|
2009-01-09 15:03:47 +02:00
|
|
|
}
|
|
|
|
else if(hvx<0)
|
|
|
|
{
|
2023-02-03 19:17:59 +02:00
|
|
|
Rect srcRect (Point(0, 0), Point(arrow->height() - hvy, arrow->width()));
|
2016-10-18 09:31:31 +02:00
|
|
|
arrow->draw(to, x + moveX, y + moveY, &srcRect);
|
2009-01-09 15:03:47 +02:00
|
|
|
}
|
|
|
|
else if (hvy<0)
|
|
|
|
{
|
2023-02-03 19:17:59 +02:00
|
|
|
Rect srcRect (Point(0, 0), Point(arrow->height(), arrow->width() - hvx));
|
2016-10-18 09:31:31 +02:00
|
|
|
arrow->draw(to, x + moveX, y + moveY, &srcRect);
|
2009-01-09 15:03:47 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-02-03 19:17:59 +02:00
|
|
|
Rect srcRect (Point(0, 0), Point(arrow->height() - hvy, arrow->width() - hvx));
|
2016-10-18 09:31:31 +02:00
|
|
|
arrow->draw(to, x + moveX, y + moveY, &srcRect);
|
2009-01-09 15:03:47 +02:00
|
|
|
}
|
2007-08-17 20:42:21 +03:00
|
|
|
}
|
2009-01-09 15:03:47 +02:00
|
|
|
else //standard version
|
2008-02-10 19:44:51 +02:00
|
|
|
{
|
2009-01-09 15:03:47 +02:00
|
|
|
if (hvx<0 && hvy<0)
|
|
|
|
{
|
2016-10-18 09:31:31 +02:00
|
|
|
arrow->draw(to, x, y);
|
2009-01-09 15:03:47 +02:00
|
|
|
}
|
|
|
|
else if(hvx<0)
|
|
|
|
{
|
2023-02-03 19:17:59 +02:00
|
|
|
Rect srcRect (Point(0, 0), Point(arrow->height() - hvy, arrow->width()));
|
2016-10-18 09:31:31 +02:00
|
|
|
arrow->draw(to, x, y, &srcRect);
|
2009-01-09 15:03:47 +02:00
|
|
|
}
|
|
|
|
else if (hvy<0)
|
|
|
|
{
|
2023-02-03 19:17:59 +02:00
|
|
|
Rect srcRect (Point(0, 0), Point(arrow->height(), arrow->width() - hvx));
|
2016-10-18 09:31:31 +02:00
|
|
|
arrow->draw(to, x, y, &srcRect);
|
2009-01-09 15:03:47 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-02-03 19:17:59 +02:00
|
|
|
Rect srcRect (Point(0, 0), Point(arrow->height() - hvy, arrow->width() - hvx));
|
2016-10-18 09:31:31 +02:00
|
|
|
arrow->draw(to, x, y, &srcRect);
|
2009-01-09 15:03:47 +02:00
|
|
|
}
|
2008-02-10 19:44:51 +02:00
|
|
|
}
|
2023-01-17 22:01:35 +02:00
|
|
|
CSDL_Ext::setClipRect(to, prevClip);
|
2007-12-22 16:40:27 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
} //for (int i=0;i<currentPath->nodes.size()-1;i++)
|
|
|
|
}
|
2012-06-02 18:16:54 +03:00
|
|
|
|
2009-04-14 15:47:09 +03:00
|
|
|
void CTerrainRect::show(SDL_Surface * to)
|
2007-12-22 16:40:27 +02:00
|
|
|
{
|
2015-01-13 21:57:41 +02:00
|
|
|
if (adventureInt->mode == EAdvMapMode::NORMAL)
|
|
|
|
{
|
2023-01-17 22:01:35 +02:00
|
|
|
MapDrawingInfo info(adventureInt->position, LOCPLINT->cb->getVisibilityMap(), pos);
|
2015-01-18 19:53:40 +02:00
|
|
|
info.otherheroAnim = true;
|
|
|
|
info.anim = adventureInt->anim;
|
|
|
|
info.heroAnim = adventureInt->heroAnim;
|
2015-01-13 21:57:41 +02:00
|
|
|
if (ADVOPT.smoothMove)
|
2015-01-18 19:53:40 +02:00
|
|
|
info.movement = int3(moveX, moveY, 0);
|
2015-10-31 19:23:13 +02:00
|
|
|
|
2015-01-31 00:37:28 +02:00
|
|
|
lastRedrawStatus = CGI->mh->drawTerrainRectNew(to, &info);
|
|
|
|
if (fadeAnim->isFading())
|
|
|
|
{
|
|
|
|
Rect r(pos);
|
|
|
|
fadeAnim->update();
|
2023-01-17 22:01:35 +02:00
|
|
|
fadeAnim->draw(to, r.topLeft());
|
2015-01-31 00:37:28 +02:00
|
|
|
}
|
2012-01-12 18:23:00 +03:00
|
|
|
|
2015-01-13 21:57:41 +02:00
|
|
|
if (currentPath/* && adventureInt->position.z==currentPath->startPos().z*/) //drawing path
|
|
|
|
{
|
2023-01-17 22:01:35 +02:00
|
|
|
showPath(pos, to);
|
2015-01-13 21:57:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CTerrainRect::showAll(SDL_Surface * to)
|
|
|
|
{
|
|
|
|
// world view map is static and doesn't need redraw every frame
|
|
|
|
if (adventureInt->mode == EAdvMapMode::WORLD_VIEW)
|
2015-01-18 19:53:40 +02:00
|
|
|
{
|
2023-01-17 22:01:35 +02:00
|
|
|
MapDrawingInfo info(adventureInt->position, LOCPLINT->cb->getVisibilityMap(), pos, adventureInt->worldViewIcons);
|
2015-01-18 19:53:40 +02:00
|
|
|
info.scaled = true;
|
|
|
|
info.scale = adventureInt->worldViewScale;
|
2015-02-02 14:02:27 +02:00
|
|
|
adventureInt->worldViewOptions.adjustDrawingInfo(info);
|
2015-01-18 19:53:40 +02:00
|
|
|
CGI->mh->drawTerrainRectNew(to, &info);
|
|
|
|
}
|
2007-08-04 22:01:22 +03:00
|
|
|
}
|
2007-08-06 07:03:34 +03:00
|
|
|
|
2015-01-31 00:37:28 +02:00
|
|
|
void CTerrainRect::showAnim(SDL_Surface * to)
|
2015-10-31 19:23:13 +02:00
|
|
|
{
|
2023-02-10 17:26:31 +02:00
|
|
|
if (!needsAnimUpdate())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (fadeAnim->isFading() || lastRedrawStatus == EMapAnimRedrawStatus::REDRAW_REQUESTED)
|
2015-01-31 00:37:28 +02:00
|
|
|
show(to);
|
|
|
|
}
|
|
|
|
|
2016-01-09 14:32:42 +02:00
|
|
|
int3 CTerrainRect::whichTileIsIt(const int x, const int y)
|
2007-10-07 17:51:09 +03:00
|
|
|
{
|
|
|
|
int3 ret;
|
2016-01-09 14:32:42 +02:00
|
|
|
ret.x = adventureInt->position.x + ((x-CGI->mh->offsetX-pos.x)/32);
|
|
|
|
ret.y = adventureInt->position.y + ((y-CGI->mh->offsetY-pos.y)/32);
|
2010-02-20 15:24:38 +02:00
|
|
|
ret.z = adventureInt->position.z;
|
2007-10-07 17:51:09 +03:00
|
|
|
return ret;
|
|
|
|
}
|
2012-06-02 18:16:54 +03:00
|
|
|
|
2007-10-07 17:51:09 +03:00
|
|
|
int3 CTerrainRect::whichTileIsIt()
|
|
|
|
{
|
2023-01-27 00:27:06 +02:00
|
|
|
return whichTileIsIt(GH.getCursorPosition().x, GH.getCursorPosition().y);
|
2007-10-07 17:51:09 +03:00
|
|
|
}
|
2009-01-12 22:05:56 +02:00
|
|
|
|
2023-02-10 23:29:13 +02:00
|
|
|
Rect CTerrainRect::visibleTilesArea()
|
2015-01-13 21:57:41 +02:00
|
|
|
{
|
|
|
|
switch (adventureInt->mode)
|
|
|
|
{
|
|
|
|
default:
|
2017-08-11 13:38:10 +02:00
|
|
|
logGlobal->error("Unknown map mode %d", (int)adventureInt->mode);
|
2023-02-10 23:29:13 +02:00
|
|
|
return Rect();
|
2015-01-13 21:57:41 +02:00
|
|
|
case EAdvMapMode::NORMAL:
|
2023-02-10 23:29:13 +02:00
|
|
|
return Rect(adventureInt->position.x, adventureInt->position.y, tilesw, tilesh);
|
2015-01-13 21:57:41 +02:00
|
|
|
case EAdvMapMode::WORLD_VIEW:
|
2023-02-10 23:29:13 +02:00
|
|
|
return Rect(adventureInt->position.x, adventureInt->position.y, tilesw / adventureInt->worldViewScale, tilesh / adventureInt->worldViewScale);
|
2015-01-13 21:57:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-31 00:37:28 +02:00
|
|
|
void CTerrainRect::fadeFromCurrentView()
|
|
|
|
{
|
2015-02-02 20:38:30 +02:00
|
|
|
if (!ADVOPT.screenFading)
|
|
|
|
return;
|
2015-01-31 00:37:28 +02:00
|
|
|
if (adventureInt->mode == EAdvMapMode::WORLD_VIEW)
|
|
|
|
return;
|
2015-10-31 19:23:13 +02:00
|
|
|
|
2015-01-31 00:37:28 +02:00
|
|
|
if (!fadeSurface)
|
|
|
|
fadeSurface = CSDL_Ext::newSurface(pos.w, pos.h);
|
2023-01-17 22:01:35 +02:00
|
|
|
CSDL_Ext::blitSurface(screen, fadeSurface, Point(0,0));
|
2015-02-02 18:42:42 +02:00
|
|
|
fadeAnim->init(CFadeAnimation::EMode::OUT, fadeSurface);
|
2015-01-31 00:37:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CTerrainRect::needsAnimUpdate()
|
|
|
|
{
|
|
|
|
return fadeAnim->isFading() || lastRedrawStatus == EMapAnimRedrawStatus::REDRAW_REQUESTED;
|
|
|
|
}
|
|
|
|
|