mirror of
https://github.com/vcmi/vcmi.git
synced 2025-03-21 21:17:49 +02:00
Implemented dragging map via left mouse click (off by default)
This commit is contained in:
parent
a4ba5a9b65
commit
61750d30c2
@ -87,6 +87,8 @@
|
||||
"vcmi.adventureOptions.showGrid.help" : "{Show Grid}\n\nShow the grid overlay, highlighting the borders between adventure map tiles.",
|
||||
"vcmi.adventureOptions.borderScroll.hover" : "Border Scrolling",
|
||||
"vcmi.adventureOptions.borderScroll.help" : "{Border Scrolling}\n\nScroll adventure map when cursor is adjacent to window edge. Can be disabled by holding down CTRL key.",
|
||||
"vcmi.adventureOptions.leftButtonDrag.hover" : "Left Click Drag Map",
|
||||
"vcmi.adventureOptions.leftButtonDrag.help" : "{Left Click Drag Map}\n\nWhen enabled, moving mouse with left button pressed will drag adventure map view",
|
||||
"vcmi.adventureOptions.mapScrollSpeed1.hover": "",
|
||||
"vcmi.adventureOptions.mapScrollSpeed5.hover": "",
|
||||
"vcmi.adventureOptions.mapScrollSpeed6.hover": "",
|
||||
|
@ -68,6 +68,8 @@
|
||||
"vcmi.adventureOptions.showGrid.help" : "{Показувати сітку}\n\n Відображає сітку, що показує межі між клітинками на мапі пригод.",
|
||||
"vcmi.adventureOptions.borderScroll.hover" : "Прокрутка по краю",
|
||||
"vcmi.adventureOptions.borderScroll.help" : "{{Прокрутка по краю}\n\nПрокручувати мапу пригод, коли курсор знаходиться біля краю вікна. Цю функцію можна вимкнути, утримуючи клавішу CTRL.",
|
||||
"vcmi.adventureOptions.leftButtonDrag.hover" : "Переміщення мапи лівою кнопкою",
|
||||
"vcmi.adventureOptions.leftButtonDrag.help" : "{Переміщення мапи лівою кнопкою}\n\nЯкщо увімкнено, переміщення миші з натиснутою лівою кнопкою буде перетягувати мапу пригод",
|
||||
"vcmi.adventureOptions.mapScrollSpeed1.hover": "",
|
||||
"vcmi.adventureOptions.mapScrollSpeed5.hover": "",
|
||||
"vcmi.adventureOptions.mapScrollSpeed6.hover": "",
|
||||
|
@ -29,11 +29,12 @@ MapViewActions::MapViewActions(MapView & owner, const std::shared_ptr<MapViewMod
|
||||
: model(model)
|
||||
, owner(owner)
|
||||
, pinchZoomFactor(1.0)
|
||||
, dragActive(false)
|
||||
{
|
||||
pos.w = model->getPixelsVisibleDimensions().x;
|
||||
pos.h = model->getPixelsVisibleDimensions().y;
|
||||
|
||||
addUsedEvents(LCLICK | SHOW_POPUP | GESTURE | HOVER | MOVE | WHEEL);
|
||||
addUsedEvents(LCLICK | SHOW_POPUP | DRAG | GESTURE | HOVER | MOVE | WHEEL);
|
||||
}
|
||||
|
||||
void MapViewActions::setContext(const std::shared_ptr<IMapRendererContext> & context)
|
||||
@ -43,10 +44,32 @@ void MapViewActions::setContext(const std::shared_ptr<IMapRendererContext> & con
|
||||
|
||||
void MapViewActions::clickPressed(const Point & cursorPosition)
|
||||
{
|
||||
int3 tile = model->getTileAtPoint(cursorPosition - pos.topLeft());
|
||||
if (!settings["adventure"]["leftButtonDrag"].Bool())
|
||||
{
|
||||
int3 tile = model->getTileAtPoint(cursorPosition - pos.topLeft());
|
||||
|
||||
if(context->isInMap(tile))
|
||||
adventureInt->onTileLeftClicked(tile);
|
||||
if(context->isInMap(tile))
|
||||
adventureInt->onTileLeftClicked(tile);
|
||||
}
|
||||
}
|
||||
|
||||
void MapViewActions::clickReleased(const Point & cursorPosition)
|
||||
{
|
||||
if (!dragActive && settings["adventure"]["leftButtonDrag"].Bool())
|
||||
{
|
||||
int3 tile = model->getTileAtPoint(cursorPosition - pos.topLeft());
|
||||
|
||||
if(context->isInMap(tile))
|
||||
adventureInt->onTileLeftClicked(tile);
|
||||
}
|
||||
dragActive = false;
|
||||
dragDistance = Point(0,0);
|
||||
}
|
||||
|
||||
void MapViewActions::clickCancel(const Point & cursorPosition)
|
||||
{
|
||||
dragActive = false;
|
||||
dragDistance = Point(0,0);
|
||||
}
|
||||
|
||||
void MapViewActions::showPopupWindow(const Point & cursorPosition)
|
||||
@ -67,6 +90,17 @@ void MapViewActions::wheelScrolled(int distance)
|
||||
adventureInt->hotkeyZoom(distance * 4);
|
||||
}
|
||||
|
||||
void MapViewActions::mouseDragged(const Point & cursorPosition, const Point & lastUpdateDistance)
|
||||
{
|
||||
dragDistance += lastUpdateDistance;
|
||||
|
||||
if (dragDistance.length() > 16)
|
||||
dragActive = true;
|
||||
|
||||
if (dragActive && settings["adventure"]["leftButtonDrag"].Bool())
|
||||
owner.onMapSwiped(lastUpdateDistance);
|
||||
}
|
||||
|
||||
void MapViewActions::gesturePanning(const Point & initialPosition, const Point & currentPosition, const Point & lastUpdateDistance)
|
||||
{
|
||||
owner.onMapSwiped(lastUpdateDistance);
|
||||
|
@ -22,7 +22,9 @@ class MapViewActions : public CIntObject
|
||||
std::shared_ptr<MapViewModel> model;
|
||||
std::shared_ptr<IMapRendererContext> context;
|
||||
|
||||
Point dragDistance;
|
||||
double pinchZoomFactor;
|
||||
bool dragActive;
|
||||
|
||||
void handleHover(const Point & cursorPosition);
|
||||
|
||||
@ -32,11 +34,14 @@ public:
|
||||
void setContext(const std::shared_ptr<IMapRendererContext> & context);
|
||||
|
||||
void clickPressed(const Point & cursorPosition) override;
|
||||
void clickReleased(const Point & cursorPosition) override;
|
||||
void clickCancel(const Point & cursorPosition) override;
|
||||
void showPopupWindow(const Point & cursorPosition) override;
|
||||
void gesturePanning(const Point & initialPosition, const Point & currentPosition, const Point & lastUpdateDistance) override;
|
||||
void gesturePinch(const Point & centerPosition, double lastUpdateFactor) override;
|
||||
void hover(bool on) override;
|
||||
void gesture(bool on, const Point & initialPosition, const Point & finalPosition) override;
|
||||
void mouseMoved(const Point & cursorPosition, const Point & lastUpdateDistance) override;
|
||||
void mouseDragged(const Point & cursorPosition, const Point & lastUpdateDistance) override;
|
||||
void wheelScrolled(int distance) override;
|
||||
};
|
||||
|
@ -36,6 +36,14 @@ AdventureOptionsTab::AdventureOptionsTab()
|
||||
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
|
||||
setRedrawParent(true);
|
||||
|
||||
#ifdef VCMI_MOBILE
|
||||
addConditional("mobile", true);
|
||||
addConditional("desktop", false);
|
||||
#else
|
||||
addConditional("mobile", false);
|
||||
addConditional("desktop", true);
|
||||
#endif
|
||||
|
||||
const JsonNode config(ResourceID("config/widgets/settings/adventureOptionsTab.json"));
|
||||
addCallback("playerHeroSpeedChanged", [this](int value)
|
||||
{
|
||||
@ -110,6 +118,10 @@ AdventureOptionsTab::AdventureOptionsTab()
|
||||
{
|
||||
return setBoolSetting("adventure", "borderScroll", value);
|
||||
});
|
||||
addCallback("leftButtonDragChanged", [](bool value)
|
||||
{
|
||||
return setBoolSetting("adventure", "leftButtonDrag", value);
|
||||
});
|
||||
build(config);
|
||||
|
||||
std::shared_ptr<CToggleGroup> playerHeroSpeedToggle = widget<CToggleGroup>("heroMovementSpeedPicker");
|
||||
@ -141,4 +153,8 @@ AdventureOptionsTab::AdventureOptionsTab()
|
||||
|
||||
std::shared_ptr<CToggleButton> borderScrollCheckbox = widget<CToggleButton>("borderScrollCheckbox");
|
||||
borderScrollCheckbox->setSelected(settings["adventure"]["borderScroll"].Bool());
|
||||
|
||||
std::shared_ptr<CToggleButton> leftButtonDragCheckbox = widget<CToggleButton>("leftButtonDragCheckbox");
|
||||
if (leftButtonDragCheckbox)
|
||||
leftButtonDragCheckbox->setSelected(settings["adventure"]["leftButtonDrag"].Bool());
|
||||
}
|
||||
|
@ -191,7 +191,7 @@
|
||||
"type" : "object",
|
||||
"additionalProperties" : false,
|
||||
"default" : {},
|
||||
"required" : [ "heroMoveTime", "enemyMoveTime", "scrollSpeedPixels", "heroReminder", "quickCombat", "objectAnimation", "terrainAnimation", "alwaysSkipCombat", "borderScroll" ],
|
||||
"required" : [ "heroMoveTime", "enemyMoveTime", "scrollSpeedPixels", "heroReminder", "quickCombat", "objectAnimation", "terrainAnimation", "alwaysSkipCombat", "borderScroll", "leftButtonDrag" ],
|
||||
"properties" : {
|
||||
"heroMoveTime" : {
|
||||
"type" : "number",
|
||||
@ -231,6 +231,10 @@
|
||||
"defaultIOS" : false,
|
||||
"defaultAndroid" : false,
|
||||
"default" : true
|
||||
},
|
||||
"leftButtonDrag" : {
|
||||
"type" : "boolean",
|
||||
"default" : false
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -340,6 +340,10 @@
|
||||
},
|
||||
{
|
||||
"text": "vcmi.adventureOptions.borderScroll.hover"
|
||||
},
|
||||
{
|
||||
"text": "vcmi.adventureOptions.leftButtonDrag.hover",
|
||||
"created" : "desktop"
|
||||
}
|
||||
]
|
||||
},
|
||||
@ -373,6 +377,12 @@
|
||||
"name": "borderScrollCheckbox",
|
||||
"help": "vcmi.adventureOptions.borderScroll",
|
||||
"callback": "borderScrollChanged"
|
||||
},
|
||||
{
|
||||
"name": "leftButtonDragCheckbox",
|
||||
"help": "vcmi.adventureOptions.leftButtonDrag",
|
||||
"callback": "leftButtonDragChanged",
|
||||
"created" : "desktop"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user