mirror of
https://github.com/overte-org/overte.git
synced 2025-04-14 07:27:04 +02:00
Android - Handshake - Make the Jump button use buttonsManager code
This commit is contained in:
parent
a6c1f3e8ff
commit
2e43912e92
2 changed files with 5 additions and 69 deletions
|
@ -91,16 +91,17 @@ void TouchscreenVirtualPadDevice::setupControlsPositions(VirtualPad::Manager& vi
|
||||||
float rightMargin = _screenDPI * VirtualPad::Manager::JUMP_BTN_RIGHT_MARGIN_PIXELS / VirtualPad::Manager::DPI;
|
float rightMargin = _screenDPI * VirtualPad::Manager::JUMP_BTN_RIGHT_MARGIN_PIXELS / VirtualPad::Manager::DPI;
|
||||||
float bottomMargin = _screenDPI * VirtualPad::Manager::JUMP_BTN_BOTTOM_MARGIN_PIXELS/ VirtualPad::Manager::DPI;
|
float bottomMargin = _screenDPI * VirtualPad::Manager::JUMP_BTN_BOTTOM_MARGIN_PIXELS/ VirtualPad::Manager::DPI;
|
||||||
_jumpButtonPosition = glm::vec2( eventScreen->availableSize().width() - rightMargin - jumpBtnPixelSize, eventScreen->availableSize().height() - bottomMargin - _jumpButtonRadius - _extraBottomMargin);
|
_jumpButtonPosition = glm::vec2( eventScreen->availableSize().width() - rightMargin - jumpBtnPixelSize, eventScreen->availableSize().height() - bottomMargin - _jumpButtonRadius - _extraBottomMargin);
|
||||||
virtualPadManager.setJumpButtonPosition(_jumpButtonPosition);
|
|
||||||
|
|
||||||
// RB button (use same size as jump)
|
// RB button (use same size as jump)
|
||||||
_rbButtonPosition = glm::vec2( eventScreen->availableSize().width() - rightMargin - jumpBtnPixelSize, eventScreen->availableSize().height() - 2 * bottomMargin - 3 * _rbButtonRadius - _extraBottomMargin);
|
_rbButtonPosition = glm::vec2( eventScreen->availableSize().width() - rightMargin - jumpBtnPixelSize, eventScreen->availableSize().height() - 2 * bottomMargin - 3 * _rbButtonRadius - _extraBottomMargin);
|
||||||
virtualPadManager.setRbButtonPosition(_rbButtonPosition);
|
|
||||||
|
|
||||||
// Avoid generating buttons in portrait mode
|
// Avoid generating buttons in portrait mode
|
||||||
if ( eventScreen->availableSize().width() > eventScreen->availableSize().height() && _buttonsManager.buttonsCount() == 0) {
|
if ( eventScreen->availableSize().width() > eventScreen->availableSize().height() && _buttonsManager.buttonsCount() == 0) {
|
||||||
//_buttonsManager.addButton(TouchscreenButton(JUMP_BUTTON_PRESS, JUMP, _jumpButtonRadius, _jumpButtonPosition, _inputDevice ));
|
_buttonsManager.addButton(TouchscreenButton(JUMP_BUTTON_PRESS, JUMP, _jumpButtonRadius, _jumpButtonPosition, _inputDevice ));
|
||||||
_buttonsManager.addButton(TouchscreenButton(RB, RB_BUTTON, _rbButtonRadius, _rbButtonPosition, _inputDevice ));
|
_buttonsManager.addButton(TouchscreenButton(RB, RB_BUTTON, _rbButtonRadius, _rbButtonPosition, _inputDevice ));
|
||||||
|
|
||||||
|
virtualPadManager.setJumpButtonPosition(_jumpButtonPosition);
|
||||||
|
virtualPadManager.setRbButtonPosition(_rbButtonPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -247,7 +248,6 @@ void TouchscreenVirtualPadDevice::touchEndEvent(const QTouchEvent* event) {
|
||||||
if (!virtualPadManager.isEnabled() && !virtualPadManager.isHidden()) {
|
if (!virtualPadManager.isEnabled() && !virtualPadManager.isHidden()) {
|
||||||
moveTouchEnd();
|
moveTouchEnd();
|
||||||
viewTouchEnd();
|
viewTouchEnd();
|
||||||
jumpTouchEnd();
|
|
||||||
_buttonsManager.endTouchForAll();
|
_buttonsManager.endTouchForAll();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -257,7 +257,6 @@ void TouchscreenVirtualPadDevice::touchEndEvent(const QTouchEvent* event) {
|
||||||
debugPoints(event, " END ----------------");
|
debugPoints(event, " END ----------------");
|
||||||
moveTouchEnd();
|
moveTouchEnd();
|
||||||
viewTouchEnd();
|
viewTouchEnd();
|
||||||
jumpTouchEnd();
|
|
||||||
_buttonsManager.endTouchForAll();
|
_buttonsManager.endTouchForAll();
|
||||||
_inputDevice->_axisStateMap.clear();
|
_inputDevice->_axisStateMap.clear();
|
||||||
_inputDevice->_buttonPressedMap.clear();
|
_inputDevice->_buttonPressedMap.clear();
|
||||||
|
@ -294,12 +293,9 @@ void TouchscreenVirtualPadDevice::touchUpdateEvent(const QTouchEvent* event) {
|
||||||
const QList<QTouchEvent::TouchPoint>& tPoints = event->touchPoints();
|
const QList<QTouchEvent::TouchPoint>& tPoints = event->touchPoints();
|
||||||
bool moveTouchFound = false;
|
bool moveTouchFound = false;
|
||||||
bool viewTouchFound = false;
|
bool viewTouchFound = false;
|
||||||
bool jumpTouchFound = false;
|
|
||||||
|
|
||||||
int idxMoveStartingPointCandidate = -1;
|
int idxMoveStartingPointCandidate = -1;
|
||||||
int idxViewStartingPointCandidate = -1;
|
int idxViewStartingPointCandidate = -1;
|
||||||
int idxJumpStartingPointCandidate = -1;
|
|
||||||
int idxRbStartingPointCandidate = -1;
|
|
||||||
|
|
||||||
_buttonsManager.resetEventValues();
|
_buttonsManager.resetEventValues();
|
||||||
|
|
||||||
|
@ -326,13 +322,6 @@ void TouchscreenVirtualPadDevice::touchUpdateEvent(const QTouchEvent* event) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!jumpTouchFound && _jumpHasValidTouch && _jumpCurrentTouchId == thisPointId) {
|
|
||||||
// valid if it's an ongoing touch
|
|
||||||
jumpTouchFound = true;
|
|
||||||
jumpTouchUpdate(thisPoint);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_buttonsManager.processOngoingTouch(thisPoint, thisPointId)) {
|
if (_buttonsManager.processOngoingTouch(thisPoint, thisPointId)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -349,20 +338,12 @@ void TouchscreenVirtualPadDevice::touchUpdateEvent(const QTouchEvent* event) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!jumpTouchFound && idxJumpStartingPointCandidate == -1 && jumpTouchBeginIsValid(thisPoint) &&
|
|
||||||
(!_unusedTouches.count(thisPointId) || _unusedTouches[thisPointId] == JUMP )) {
|
|
||||||
idxJumpStartingPointCandidate = i;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_buttonsManager.findStartingTouchPointCandidate(thisPoint, thisPointId, i, _unusedTouches)) {
|
if (_buttonsManager.findStartingTouchPointCandidate(thisPoint, thisPointId, i, _unusedTouches)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (moveTouchBeginIsValid(thisPoint)) {
|
if (moveTouchBeginIsValid(thisPoint)) {
|
||||||
unusedTouchesInEvent[thisPointId] = MOVE;
|
unusedTouchesInEvent[thisPointId] = MOVE;
|
||||||
} else if (jumpTouchBeginIsValid(thisPoint)) {
|
|
||||||
unusedTouchesInEvent[thisPointId] = JUMP;
|
|
||||||
} else if (viewTouchBeginIsValid(thisPoint)) {
|
} else if (viewTouchBeginIsValid(thisPoint)) {
|
||||||
unusedTouchesInEvent[thisPointId] = VIEW;
|
unusedTouchesInEvent[thisPointId] = VIEW;
|
||||||
} else {
|
} else {
|
||||||
|
@ -395,26 +376,13 @@ void TouchscreenVirtualPadDevice::touchUpdateEvent(const QTouchEvent* event) {
|
||||||
viewTouchEnd();
|
viewTouchEnd();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!jumpTouchFound) {
|
|
||||||
if (idxJumpStartingPointCandidate != -1) {
|
|
||||||
_jumpCurrentTouchId = tPoints[idxJumpStartingPointCandidate].id();
|
|
||||||
_unusedTouches.erase(_jumpCurrentTouchId);
|
|
||||||
thisPoint.x = tPoints[idxJumpStartingPointCandidate].pos().x();
|
|
||||||
thisPoint.y = tPoints[idxJumpStartingPointCandidate].pos().y();
|
|
||||||
jumpTouchBegin(thisPoint);
|
|
||||||
} else {
|
|
||||||
if (_jumpHasValidTouch) {
|
|
||||||
jumpTouchEnd();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_buttonsManager.processBeginOrEnd(thisPoint, tPoints, _unusedTouches);
|
_buttonsManager.processBeginOrEnd(thisPoint, tPoints, _unusedTouches);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TouchscreenVirtualPadDevice::viewTouchBeginIsValid(glm::vec2 touchPoint) {
|
bool TouchscreenVirtualPadDevice::viewTouchBeginIsValid(glm::vec2 touchPoint) {
|
||||||
return !moveTouchBeginIsValid(touchPoint) && !jumpTouchBeginIsValid(touchPoint) && _buttonsManager.touchBeginInvalidForAllButtons(touchPoint);
|
return !moveTouchBeginIsValid(touchPoint) && _buttonsManager.touchBeginInvalidForAllButtons(touchPoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TouchscreenVirtualPadDevice::moveTouchBeginIsValid(glm::vec2 touchPoint) {
|
bool TouchscreenVirtualPadDevice::moveTouchBeginIsValid(glm::vec2 touchPoint) {
|
||||||
|
@ -427,30 +395,6 @@ bool TouchscreenVirtualPadDevice::moveTouchBeginIsValid(glm::vec2 touchPoint) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TouchscreenVirtualPadDevice::jumpTouchBeginIsValid(glm::vec2 touchPoint) {
|
|
||||||
// position of button and boundaries
|
|
||||||
return glm::distance2(touchPoint, _jumpButtonPosition) < _jumpButtonRadius * _jumpButtonRadius;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TouchscreenVirtualPadDevice::jumpTouchBegin(glm::vec2 touchPoint) {
|
|
||||||
auto& virtualPadManager = VirtualPad::Manager::instance();
|
|
||||||
if (virtualPadManager.isEnabled() && !virtualPadManager.isHidden()) {
|
|
||||||
_jumpHasValidTouch = true;
|
|
||||||
|
|
||||||
_inputDevice->_buttonPressedMap.insert(TouchButtonChannel::JUMP_BUTTON_PRESS);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void TouchscreenVirtualPadDevice::jumpTouchUpdate(glm::vec2 touchPoint) {}
|
|
||||||
|
|
||||||
void TouchscreenVirtualPadDevice::jumpTouchEnd() {
|
|
||||||
if (_jumpHasValidTouch) {
|
|
||||||
_jumpHasValidTouch = false;
|
|
||||||
|
|
||||||
_inputDevice->_buttonPressedMap.erase(TouchButtonChannel::JUMP_BUTTON_PRESS);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void TouchscreenVirtualPadDevice::moveTouchBegin(glm::vec2 touchPoint) {
|
void TouchscreenVirtualPadDevice::moveTouchBegin(glm::vec2 touchPoint) {
|
||||||
auto& virtualPadManager = VirtualPad::Manager::instance();
|
auto& virtualPadManager = VirtualPad::Manager::instance();
|
||||||
if (virtualPadManager.isEnabled() && !virtualPadManager.isHidden()) {
|
if (virtualPadManager.isEnabled() && !virtualPadManager.isHidden()) {
|
||||||
|
|
|
@ -156,9 +156,6 @@ protected:
|
||||||
glm::vec2 _viewCurrentTouchPoint;
|
glm::vec2 _viewCurrentTouchPoint;
|
||||||
int _viewCurrentTouchId;
|
int _viewCurrentTouchId;
|
||||||
|
|
||||||
bool _jumpHasValidTouch;
|
|
||||||
int _jumpCurrentTouchId;
|
|
||||||
|
|
||||||
std::map<int, TouchType> _unusedTouches;
|
std::map<int, TouchType> _unusedTouches;
|
||||||
|
|
||||||
int _touchPointCount;
|
int _touchPointCount;
|
||||||
|
@ -189,11 +186,6 @@ protected:
|
||||||
void viewTouchEnd();
|
void viewTouchEnd();
|
||||||
bool viewTouchBeginIsValid(glm::vec2 touchPoint);
|
bool viewTouchBeginIsValid(glm::vec2 touchPoint);
|
||||||
|
|
||||||
void jumpTouchBegin(glm::vec2 touchPoint);
|
|
||||||
void jumpTouchUpdate(glm::vec2 touchPoint);
|
|
||||||
void jumpTouchEnd();
|
|
||||||
bool jumpTouchBeginIsValid(glm::vec2 touchPoint);
|
|
||||||
|
|
||||||
void setupControlsPositions(VirtualPad::Manager& virtualPadManager, bool force = false);
|
void setupControlsPositions(VirtualPad::Manager& virtualPadManager, bool force = false);
|
||||||
|
|
||||||
void processInputDeviceForMove(VirtualPad::Manager& virtualPadManager);
|
void processInputDeviceForMove(VirtualPad::Manager& virtualPadManager);
|
||||||
|
|
Loading…
Reference in a new issue