mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-28 23:06:24 +02:00
Moved swipe handling to TerrainRect class
This commit is contained in:
parent
f6cf8b23c2
commit
b9056ef248
@ -89,10 +89,12 @@ CAdvMapInt::CAdvMapInt():
|
||||
resdatabar(new CResDataBar),
|
||||
terrain(new CTerrainRect),
|
||||
state(NA),
|
||||
spellBeingCasted(nullptr), selection(nullptr),
|
||||
activeMapPanel(nullptr), duringAITurn(false), scrollingDir(0), scrollingState(false),
|
||||
swipeEnabled(settings["general"]["swipe"].Bool()), swipeMovementRequested(false),
|
||||
swipeTargetPosition(Point(0, 0))
|
||||
spellBeingCasted(nullptr),
|
||||
selection(nullptr),
|
||||
activeMapPanel(nullptr),
|
||||
duringAITurn(false),
|
||||
scrollingDir(0),
|
||||
scrollingState(false)
|
||||
{
|
||||
pos.x = pos.y = 0;
|
||||
pos.w = GH.screenDimensions().x;
|
||||
@ -558,16 +560,7 @@ void CAdvMapInt::show(SDL_Surface * to)
|
||||
if(state != INGAME)
|
||||
return;
|
||||
|
||||
if(swipeEnabled)
|
||||
{
|
||||
handleSwipeUpdate();
|
||||
}
|
||||
#if defined(VCMI_MOBILE) // on mobile, map-moving mode is exclusive (TODO technically it might work with both enabled; to be checked)
|
||||
else
|
||||
#endif
|
||||
{
|
||||
handleMapScrollingUpdate();
|
||||
}
|
||||
handleMapScrollingUpdate();
|
||||
|
||||
for(int i = 0; i < 4; i++)
|
||||
{
|
||||
@ -619,17 +612,6 @@ void CAdvMapInt::handleMapScrollingUpdate()
|
||||
}
|
||||
}
|
||||
|
||||
void CAdvMapInt::handleSwipeUpdate()
|
||||
{
|
||||
if(swipeMovementRequested)
|
||||
{
|
||||
terrain->setViewCenter(swipeTargetPosition, terrain->getLevel());
|
||||
CCS->curh->set(Cursor::Map::POINTER);
|
||||
minimap->redraw();
|
||||
swipeMovementRequested = false;
|
||||
}
|
||||
}
|
||||
|
||||
void CAdvMapInt::selectionChanged()
|
||||
{
|
||||
const CGTownInstance *to = LOCPLINT->towns[townList->getSelectedIndex()];
|
||||
@ -637,29 +619,21 @@ void CAdvMapInt::selectionChanged()
|
||||
select(to);
|
||||
}
|
||||
|
||||
void CAdvMapInt::centerOn(int3 on, bool fade)
|
||||
void CAdvMapInt::centerOn(int3 on)
|
||||
{
|
||||
bool switchedLevels = on.z != terrain->getLevel();
|
||||
|
||||
if (fade)
|
||||
{
|
||||
terrain->fadeFromCurrentView();
|
||||
}
|
||||
|
||||
terrain->setViewCenter(on);
|
||||
|
||||
underground->setIndex(on.z,true); //change underground switch button image
|
||||
underground->redraw();
|
||||
worldViewUnderground->setIndex(on.z, true);
|
||||
worldViewUnderground->redraw();
|
||||
if (switchedLevels)
|
||||
minimap->setLevel(terrain->getLevel());
|
||||
minimap->setLevel(terrain->getLevel());
|
||||
minimap->redraw();
|
||||
}
|
||||
|
||||
void CAdvMapInt::centerOn(const CGObjectInstance * obj, bool fade)
|
||||
void CAdvMapInt::centerOn(const CGObjectInstance * obj)
|
||||
{
|
||||
centerOn(obj->getSightCenter(), fade);
|
||||
centerOn(obj->getSightCenter());
|
||||
}
|
||||
|
||||
void CAdvMapInt::keyReleased(const SDL_Keycode &key)
|
||||
@ -929,13 +903,8 @@ void CAdvMapInt::select(const CArmedInstance *sel, bool centerView)
|
||||
|
||||
void CAdvMapInt::mouseMoved( const Point & cursorPosition )
|
||||
{
|
||||
#if defined(VCMI_MOBILE)
|
||||
if(swipeEnabled)
|
||||
return;
|
||||
#endif
|
||||
// adventure map scrolling with mouse
|
||||
// currently disabled in world view mode (as it is in OH3), but should work correctly if mode check is removed
|
||||
// don't scroll if there is no window in focus - these events don't seem to correspond to the actual mouse movement
|
||||
if(!GH.isKeyboardCtrlDown() && isActive() && mode == EAdvMapMode::NORMAL)
|
||||
{
|
||||
if(cursorPosition.x<15)
|
||||
|
@ -61,10 +61,6 @@ private:
|
||||
enum EDirections {LEFT=1, RIGHT=2, UP=4, DOWN=8};
|
||||
enum EGameStates {NA, INGAME, WAITING};
|
||||
|
||||
bool swipeEnabled;
|
||||
bool swipeMovementRequested;
|
||||
Point swipeTargetPosition;
|
||||
|
||||
EGameStates state;
|
||||
EAdvMapMode mode;
|
||||
|
||||
@ -140,7 +136,6 @@ private:
|
||||
void updateSpellbook(const CGHeroInstance *h);
|
||||
|
||||
void handleMapScrollingUpdate();
|
||||
void handleSwipeUpdate();
|
||||
|
||||
void showMoveDetailsInStatusbar(const CGHeroInstance & hero, const CGPathNode & pathNode);
|
||||
|
||||
@ -166,8 +161,8 @@ public:
|
||||
// public interface
|
||||
|
||||
void select(const CArmedInstance *sel, bool centerView = true);
|
||||
void centerOn(int3 on, bool fade = false);
|
||||
void centerOn(const CGObjectInstance *obj, bool fade = false);
|
||||
void centerOn(int3 on);
|
||||
void centerOn(const CGObjectInstance *obj);
|
||||
|
||||
bool isHeroSleeping(const CGHeroInstance *hero);
|
||||
void setHeroSleeping(const CGHeroInstance *hero, bool sleep);
|
||||
|
@ -31,13 +31,18 @@
|
||||
#include "../../lib/mapping/CMap.h"
|
||||
#include "../../lib/CPathfinder.h"
|
||||
|
||||
#include <SDL_surface.h>
|
||||
|
||||
#define ADVOPT (conf.go()->ac)
|
||||
|
||||
CTerrainRect::CTerrainRect()
|
||||
: curHoveredTile(-1, -1, -1)
|
||||
, isSwiping(false)
|
||||
#if defined(VCMI_ANDROID) || defined(VCMI_IOS)
|
||||
, swipeEnabled(settings["general"]["swipe"].Bool())
|
||||
#else
|
||||
, swipeEnabled(settings["general"]["swipeDesktop"].Bool())
|
||||
#endif
|
||||
, swipeMovementRequested(false)
|
||||
, swipeTargetPosition(Point(0, 0))
|
||||
{
|
||||
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
|
||||
|
||||
@ -73,8 +78,7 @@ void CTerrainRect::clickLeft(tribool down, bool previousState)
|
||||
if(indeterminate(down))
|
||||
return;
|
||||
|
||||
#if defined(VCMI_MOBILE)
|
||||
if(adventureInt->swipeEnabled)
|
||||
if(swipeEnabled)
|
||||
{
|
||||
if(handleSwipeStateChange((bool)down == true))
|
||||
{
|
||||
@ -82,7 +86,6 @@ void CTerrainRect::clickLeft(tribool down, bool previousState)
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
if(down == false)
|
||||
return;
|
||||
@ -97,10 +100,9 @@ void CTerrainRect::clickLeft(tribool down, bool previousState)
|
||||
|
||||
void CTerrainRect::clickRight(tribool down, bool previousState)
|
||||
{
|
||||
#if defined(VCMI_MOBILE)
|
||||
if(adventureInt->swipeEnabled && isSwiping)
|
||||
if(isSwiping)
|
||||
return;
|
||||
#endif
|
||||
|
||||
if(adventureInt->mode == EAdvMapMode::WORLD_VIEW)
|
||||
return;
|
||||
int3 mp = whichTileIsIt();
|
||||
@ -118,27 +120,26 @@ void CTerrainRect::mouseMoved(const Point & cursorPosition)
|
||||
{
|
||||
handleHover(cursorPosition);
|
||||
|
||||
if(!adventureInt->swipeEnabled)
|
||||
return;
|
||||
|
||||
handleSwipeMove(cursorPosition);
|
||||
}
|
||||
|
||||
void CTerrainRect::handleSwipeMove(const Point & cursorPosition)
|
||||
{
|
||||
#if defined(VCMI_MOBILE)
|
||||
if(!GH.isMouseButtonPressed() || GH.multifinger) // any "button" is enough on mobile
|
||||
// unless swipe is enabled, swipe move only works with middle mouse button
|
||||
if(!swipeEnabled && !GH.isMouseButtonPressed(MouseButton::MIDDLE))
|
||||
return;
|
||||
#else
|
||||
if(!GH.isMouseButtonPressed(MouseButton::MIDDLE)) // swipe only works with middle mouse on other platforms
|
||||
|
||||
// on mobile platforms with enabled swipe any button is enough
|
||||
if(swipeEnabled && (!GH.isMouseButtonPressed() || GH.multifinger))
|
||||
return;
|
||||
#endif
|
||||
|
||||
if(!isSwiping)
|
||||
{
|
||||
static constexpr int touchSwipeSlop = 16;
|
||||
|
||||
// try to distinguish if this touch was meant to be a swipe or just fat-fingering press
|
||||
if(std::abs(cursorPosition.x - swipeInitialRealPos.x) > SwipeTouchSlop ||
|
||||
std::abs(cursorPosition.y - swipeInitialRealPos.y) > SwipeTouchSlop)
|
||||
if(std::abs(cursorPosition.x - swipeInitialRealPos.x) > touchSwipeSlop ||
|
||||
std::abs(cursorPosition.y - swipeInitialRealPos.y) > touchSwipeSlop)
|
||||
{
|
||||
isSwiping = true;
|
||||
}
|
||||
@ -146,9 +147,9 @@ void CTerrainRect::handleSwipeMove(const Point & cursorPosition)
|
||||
|
||||
if(isSwiping)
|
||||
{
|
||||
adventureInt->swipeTargetPosition.x = swipeInitialViewPos.x + swipeInitialRealPos.x - cursorPosition.x;
|
||||
adventureInt->swipeTargetPosition.y = swipeInitialViewPos.y + swipeInitialRealPos.y - cursorPosition.y;
|
||||
adventureInt->swipeMovementRequested = true;
|
||||
swipeTargetPosition.x = swipeInitialViewPos.x + swipeInitialRealPos.x - cursorPosition.x;
|
||||
swipeTargetPosition.y = swipeInitialViewPos.y + swipeInitialRealPos.y - cursorPosition.y;
|
||||
swipeMovementRequested = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -211,11 +212,6 @@ Rect CTerrainRect::visibleTilesArea()
|
||||
return renderer->getModel()->getTilesTotalRect();
|
||||
}
|
||||
|
||||
void CTerrainRect::fadeFromCurrentView()
|
||||
{
|
||||
assert(0);//TODO
|
||||
}
|
||||
|
||||
void CTerrainRect::setLevel(int level)
|
||||
{
|
||||
renderer->getController()->setViewCenter(renderer->getModel()->getMapViewCenter(), level);
|
||||
@ -223,6 +219,10 @@ void CTerrainRect::setLevel(int level)
|
||||
|
||||
void CTerrainRect::moveViewBy(const Point & delta)
|
||||
{
|
||||
// ignore scrolling attempts while we are swiping
|
||||
if (isSwiping || swipeMovementRequested)
|
||||
return;
|
||||
|
||||
renderer->getController()->setViewCenter(renderer->getModel()->getMapViewCenter() + delta, getLevel());
|
||||
}
|
||||
|
||||
@ -241,7 +241,6 @@ void CTerrainRect::setTileSize(int sizePixels)
|
||||
renderer->getController()->setTileSize(Point(sizePixels, sizePixels));
|
||||
}
|
||||
|
||||
|
||||
void CTerrainRect::setTerrainVisibility(bool showAllTerrain)
|
||||
{
|
||||
renderer->getController()->setTerrainVisibility(showAllTerrain);
|
||||
@ -251,3 +250,14 @@ void CTerrainRect::setOverlayVisibility(const std::vector<ObjectPosInfo> & objec
|
||||
{
|
||||
renderer->getController()->setOverlayVisibility(objectPositions);
|
||||
}
|
||||
|
||||
void CTerrainRect::show(SDL_Surface * to)
|
||||
{
|
||||
if(swipeMovementRequested)
|
||||
{
|
||||
setViewCenter(swipeTargetPosition, getLevel());
|
||||
CCS->curh->set(Cursor::Map::POINTER);
|
||||
swipeMovementRequested = false;
|
||||
}
|
||||
CIntObject::show(to);
|
||||
}
|
||||
|
@ -24,16 +24,13 @@ class CTerrainRect : public CIntObject
|
||||
{
|
||||
std::shared_ptr<MapView> renderer;
|
||||
|
||||
bool swipeEnabled;
|
||||
bool swipeMovementRequested;
|
||||
Point swipeTargetPosition;
|
||||
Point swipeInitialViewPos;
|
||||
Point swipeInitialRealPos;
|
||||
bool isSwiping;
|
||||
|
||||
#if defined(VCMI_ANDROID) || defined(VCMI_IOS)
|
||||
static constexpr float SwipeTouchSlop = 16.0f; // touch UI
|
||||
#else
|
||||
static constexpr float SwipeTouchSlop = 1.0f; // mouse UI
|
||||
#endif
|
||||
|
||||
void handleHover(const Point & cursorPosition);
|
||||
void handleSwipeMove(const Point & cursorPosition);
|
||||
/// handles start/finish of swipe (press/release of corresponding button); returns true if state change was handled
|
||||
@ -43,20 +40,30 @@ class CTerrainRect : public CIntObject
|
||||
int3 whichTileIsIt(const Point & position); //x,y are cursor position
|
||||
int3 whichTileIsIt(); //uses current cursor pos
|
||||
|
||||
Point getViewCenter();
|
||||
|
||||
public:
|
||||
CTerrainRect();
|
||||
|
||||
void moveViewBy(const Point & delta);
|
||||
/// Handle swipe & selection of object
|
||||
void setViewCenter(const int3 & coordinates);
|
||||
void setViewCenter(const Point & position, int level);
|
||||
void setLevel(int level);
|
||||
void setTileSize(int sizePixels);
|
||||
|
||||
/// Edge scrolling
|
||||
void moveViewBy(const Point & delta);
|
||||
|
||||
/// Toggle undeground view button
|
||||
void setLevel(int level);
|
||||
int getLevel();
|
||||
|
||||
/// World view & View Earth/Air spells
|
||||
void setTerrainVisibility(bool showAllTerrain);
|
||||
void setOverlayVisibility(const std::vector<ObjectPosInfo> & objectPositions);
|
||||
void setTileSize(int sizePixels);
|
||||
|
||||
Point getViewCenter();
|
||||
int getLevel();
|
||||
/// Minimap access
|
||||
/// @returns number of visible tiles on screen respecting current map scaling
|
||||
Rect visibleTilesArea();
|
||||
|
||||
// CIntObject interface implementation
|
||||
void deactivate() override;
|
||||
@ -65,14 +72,8 @@ public:
|
||||
void clickMiddle(tribool down, bool previousState) override;
|
||||
void hover(bool on) override;
|
||||
void mouseMoved (const Point & cursorPosition) override;
|
||||
//void show(SDL_Surface * to) override;
|
||||
void show(SDL_Surface * to) override;
|
||||
//void showAll(SDL_Surface * to) override;
|
||||
|
||||
//void showAnim(SDL_Surface * to);
|
||||
|
||||
/// @returns number of visible tiles on screen respecting current map scaling
|
||||
Rect visibleTilesArea();
|
||||
|
||||
/// animates view by caching current surface and crossfading it with normal screen
|
||||
void fadeFromCurrentView();
|
||||
};
|
||||
|
@ -154,11 +154,7 @@ bool MapRendererContext::showOverlay() const
|
||||
|
||||
bool MapRendererContext::showGrid() const
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
return settings["gameTweaks"]["showGrid"].Bool();
|
||||
=======
|
||||
return settingsSessionShowGrid;
|
||||
>>>>>>> 9a847b520 (Working version of image caching)
|
||||
}
|
||||
|
||||
bool MapRendererContext::showVisitable() const
|
||||
|
@ -173,6 +173,7 @@ void MapViewController::onHeroMoved(const CGHeroInstance * obj, const int3 & fro
|
||||
{
|
||||
// instant movement
|
||||
context->addObject(movingObject);
|
||||
setViewCenter(movingObject->visitablePos());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -25,6 +25,7 @@
|
||||
"encoding",
|
||||
"language",
|
||||
"swipe",
|
||||
"swipeDesktop",
|
||||
"saveRandomMaps",
|
||||
"saveFrequency",
|
||||
"notifications",
|
||||
@ -58,6 +59,10 @@
|
||||
"type" : "boolean",
|
||||
"default" : true
|
||||
},
|
||||
"swipeDesktop" : {
|
||||
"type" : "boolean",
|
||||
"default" : false
|
||||
},
|
||||
"saveRandomMaps" : {
|
||||
"type" : "boolean",
|
||||
"default" : false
|
||||
|
Loading…
Reference in New Issue
Block a user