Skip to content

Commit

Permalink
Merge pull request #7 from Cvolton/impostor-playlayer
Browse files Browse the repository at this point in the history
Fix issues caused by impostor PlayLayers
  • Loading branch information
matcool authored Nov 26, 2023
2 parents 7e74bca + b9da72e commit 3e811b7
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/UILayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,18 @@ struct $modify(UILayer) {
return getChildOfType<PauseLayer>(PlayLayer::get()->getParent(), 0) != nullptr;
}

bool isCurrentPlayLayer() {
auto playLayer = getChildOfType<PlayLayer>(CCScene::get(), 0);
return playLayer != nullptr && playLayer == PlayLayer::get() && getChildOfType<UILayer>(playLayer, 0) == this;
}

bool init() {
if (!UILayer::init())
return false;

this->defineKeybind("robtop.geometry-dash/jump-p1", [=](bool down) {
// todo: event priority
if (PlayLayer::get() && !this->isPaused()) {
if (this->isCurrentPlayLayer() && !this->isPaused()) {
if (down) {
PlayLayer::get()->pushButton(platformButton(), true);
}
Expand All @@ -112,7 +117,7 @@ struct $modify(UILayer) {
}
});
this->defineKeybind("robtop.geometry-dash/jump-p2", [=](bool down) {
if (PlayLayer::get() && !this->isPaused()) {
if (this->isCurrentPlayLayer() && !this->isPaused()) {
if (down) {
PlayLayer::get()->pushButton(platformButton(), false);
}
Expand All @@ -122,17 +127,17 @@ struct $modify(UILayer) {
}
});
this->defineKeybind("robtop.geometry-dash/place-checkpoint", [=](bool down) {
if (down && PlayLayer::get() && PlayLayer::get()->m_isPracticeMode) {
if (down && this->isCurrentPlayLayer() && PlayLayer::get()->m_isPracticeMode) {
this->onCheck(nullptr);
}
});
this->defineKeybind("robtop.geometry-dash/delete-checkpoint", [=](bool down) {
if (down && PlayLayer::get() && PlayLayer::get()->m_isPracticeMode) {
if (down && this->isCurrentPlayLayer() && PlayLayer::get()->m_isPracticeMode) {
this->onDeleteCheck(nullptr);
}
});
this->defineKeybind("robtop.geometry-dash/pause-level", [=](bool down) {
if (down && PlayLayer::get() && !this->isPaused()) {
if (down && this->isCurrentPlayLayer() && !this->isPaused()) {
PlayLayer::get()->pauseGame(true);
}
});
Expand Down

0 comments on commit 3e811b7

Please sign in to comment.