Skip to content

Commit

Permalink
Merge pull request #464 from grantramsay/fix/392/drag-off-gui
Browse files Browse the repository at this point in the history
Fix/392/drag off gui
  • Loading branch information
wheybags authored Feb 19, 2020
2 parents 2a15ddb + a789f9e commit 74bfedc
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 45 deletions.
54 changes: 26 additions & 28 deletions apps/freeablo/engine/engineinputmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,31 +123,35 @@ namespace Engine
{
NuklearMisc::handleNuklearMouseEvent(mNkCtx, x, y, key, true, isDoubleClick);

if (key == Input::Key::KEY_LEFT_MOUSE)
{
mMousePosition = Misc::Point{x, y};
mMouseDown = true;
mClick = true;
}
if (key == Input::Key::KEY_RIGHT_MOUSE)
mMousePosition = Misc::Point{x, y};

// Only pass relevant mouse clicks to game engine.
if (!mPaused && !nk_item_is_any_active(mNkCtx) && !mGuiManager->isModalDlgShown())
{
mMousePosition = Misc::Point{x, y};
mRightMouseDown = true;
mRightClick = true;
if (key == Input::Key::KEY_LEFT_MOUSE)
{
mMouseDown = true;
mClick = true;
}
if (key == Input::Key::KEY_RIGHT_MOUSE)
{
mRightMouseDown = true;
mRightClick = true;
}
}
}

void EngineInputManager::mouseRelease(int32_t x, int32_t y, Input::Key key)
{
NuklearMisc::handleNuklearMouseEvent(mNkCtx, x, y, key, false, false);

if (key == Input::Key::KEY_LEFT_MOUSE)
if (key == Input::Key::KEY_LEFT_MOUSE && mMouseDown)
{
mMouseDown = false;
if (!nk_item_is_any_active(mNkCtx) && !mGuiManager->isModalDlgShown())
notifyMouseObservers(MouseInputAction::MOUSE_RELEASE, mMousePosition, mMouseDown, mKbMods);
}
if (key == Input::Key::KEY_RIGHT_MOUSE)
if (key == Input::Key::KEY_RIGHT_MOUSE && mRightMouseDown)
{
mRightMouseDown = false;
if (!nk_item_is_any_active(mNkCtx) && !mGuiManager->isModalDlgShown())
Expand All @@ -159,10 +163,10 @@ namespace Engine
{
NuklearMisc::handleNuklearMouseMoveEvent(mNkCtx, x, y, xrel, yrel);

mMousePosition = Misc::Point{x, y};

if (!nk_item_is_any_active(mNkCtx))
notifyMouseObservers(MouseInputAction::MOUSE_MOVE, mMousePosition, mMouseDown, mKbMods);

mMousePosition = Misc::Point{x, y};
}

std::string EngineInputManager::keyboardActionToString(KeyboardInputAction action) const
Expand Down Expand Up @@ -221,24 +225,18 @@ namespace Engine
nk_input_begin(mNkCtx);
bool quit = mInput.processInput();

// TODO: bit nasty to use keybard observers for this, but meh
// TODO: bit nasty to use keyboard observers for this, but meh
if (quit)
notifyKeyboardObservers(KeyboardInputAction::quit);

nk_input_end(mNkCtx);

if (!paused && !nk_item_is_any_active(mNkCtx) && !mGuiManager->isModalDlgShown())
{
if (mMouseDown && mClick)
{
notifyMouseObservers(MouseInputAction::MOUSE_DOWN, mMousePosition, mMouseDown, mKbMods);
mClick = false;
}
if (mRightMouseDown && mRightClick)
{
notifyMouseObservers(MouseInputAction::RIGHT_MOUSE_DOWN, mMousePosition, mRightMouseDown, mKbMods);
mRightClick = false;
}
}
if (mMouseDown && mClick)
notifyMouseObservers(MouseInputAction::MOUSE_DOWN, mMousePosition, mMouseDown, mKbMods);
mClick = false;

if (mRightMouseDown && mRightClick)
notifyMouseObservers(MouseInputAction::RIGHT_MOUSE_DOWN, mMousePosition, mRightMouseDown, mKbMods);
mRightClick = false;
}
}
21 changes: 13 additions & 8 deletions apps/freeablo/engine/localinputhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ namespace Engine
{
auto clickedTile = FARender::Renderer::get()->getTileByScreenPos(mousePosition.x, mousePosition.y, player->getPos());

if (auto clickedActor = mWorld.targetedActor(mousePosition))
auto cursorItem = player->mInventory.getCursorHeld();
auto clickedActor = mWorld.targetedActor(mousePosition);
if (cursorItem.isEmpty() && clickedActor)
{
mInputs.emplace_back(FAWorld::PlayerInput::TargetActorData{clickedActor->getId()}, player->getId());
}
Expand All @@ -81,25 +83,28 @@ namespace Engine
Vec2Fix(clickedTile.pos.x - player->getPos().current().x, clickedTile.pos.y - player->getPos().current().y).getDirection();
mInputs.emplace_back(FAWorld::PlayerInput::AttackDirectionData{direction}, player->getId());
}
else if (player->getLevel()->isDoor(clickedTile.pos) || !cursorItem.isEmpty())
{
mInputs.emplace_back(FAWorld::PlayerInput::TargetTileData{clickedTile.pos.x, clickedTile.pos.y}, player->getId());
}
else
{
if (player->getLevel()->isDoor(clickedTile.pos) || !player->mInventory.getCursorHeld().isEmpty())
mInputs.emplace_back(FAWorld::PlayerInput::TargetTileData{clickedTile.pos.x, clickedTile.pos.y}, player->getId());
else
mInputs.emplace_back(FAWorld::PlayerInput::DragOverTileData{clickedTile.pos.x, clickedTile.pos.y}, player->getId());
mInputs.emplace_back(FAWorld::PlayerInput::DragOverTileData{clickedTile.pos.x, clickedTile.pos.y}, player->getId());
}

return;
}
case Engine::MouseInputAction::RIGHT_MOUSE_DOWN:
{
auto clickedTile = FARender::Renderer::get()->getTileByScreenPos(mousePosition.x, mousePosition.y, player->getPos());
mInputs.emplace_back(FAWorld::PlayerInput::CastSpellData{clickedTile.pos.x, clickedTile.pos.y}, player->getId());
if (player->mInventory.getCursorHeld().isEmpty())
mInputs.emplace_back(FAWorld::PlayerInput::CastSpellData{clickedTile.pos.x, clickedTile.pos.y}, player->getId());
else
mInputs.emplace_back(FAWorld::PlayerInput::TargetTileData{clickedTile.pos.x, clickedTile.pos.y}, player->getId());
return;
}
case Engine::MouseInputAction::MOUSE_MOVE:
{
if (mouseDown)
if (mouseDown && player->mInventory.getCursorHeld().isEmpty())
{
auto clickedTile = FARender::Renderer::get()->getTileByScreenPos(mousePosition.x, mousePosition.y, player->getPos());
mInputs.emplace_back(FAWorld::PlayerInput::DragOverTileData{clickedTile.pos.x, clickedTile.pos.y}, player->getId());
Expand Down
11 changes: 2 additions & 9 deletions apps/freeablo/faworld/playerbehaviour.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ namespace FAWorld

void PlayerBehaviour::addInput(const PlayerInput& input)
{
auto cursorItem = mPlayer->mInventory.getCursorHeld();

switch (input.mType)
{
case PlayerInput::Type::TargetTile:
Expand All @@ -61,6 +59,7 @@ namespace FAWorld
return;
}

auto cursorItem = mPlayer->mInventory.getCursorHeld();
if (!cursorItem.isEmpty())
{
mPlayer->dropItem(clickedPoint);
Expand All @@ -80,13 +79,7 @@ namespace FAWorld
}
case PlayerInput::Type::TargetActor:
{
if (!cursorItem.isEmpty())
{
auto clickedPoint = Misc::Point(input.mData.dataTargetTile.x, input.mData.dataTargetTile.y);
mPlayer->dropItem(clickedPoint);
}
else
mPlayer->mTarget = mPlayer->getWorld()->getActorById(input.mData.dataTargetActor.actorId);
mPlayer->mTarget = mPlayer->getWorld()->getActorById(input.mData.dataTargetActor.actorId);
return;
}
case PlayerInput::Type::TargetItemOnFloor:
Expand Down

0 comments on commit 74bfedc

Please sign in to comment.