bool WindowManager::mouseReleaseEvent(QObject *object, QEvent *event) { Q_UNUSED(object); Q_UNUSED(event); resetDrag(); return false; }
void MenuManager::closeRight() { resetDrag(); inv->visible = false; pow->visible = false; talker->visible = false; exit->visible = false; npc->visible = false; book->visible = false; book->book_name = ""; }
void MenuManager::closeLeft() { resetDrag(); chr->visible = false; log->visible = false; vendor->visible = false; talker->visible = false; exit->visible = false; stash->visible = false; npc->visible = false; book->visible = false; book->book_name = ""; }
bool WindowManager::mouseMoveEvent(QObject *object, QEvent *event) { Q_UNUSED(object); // stop timer if (_dragTimer.isActive()){ _dragTimer.stop(); } // cast event and check drag distance QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event); if (!_dragInProgress) { if (_dragAboutToStart) { if (mouseEvent->globalPos() == _globalDragPoint) { // start timer, _dragAboutToStart = false; if (_dragTimer.isActive()) { _dragTimer.stop(); } _dragTimer.start(_dragDelay, this); } else { resetDrag(); } } else if (QPoint(mouseEvent->globalPos() - _globalDragPoint).manhattanLength() >= _dragDistance) { _dragTimer.start(0, this); } return true; } else if (!useWMMoveResize()) { // use QWidget::move for the grabbing /* this works only if the sending object and the target are identical */ QWidget *window(_target.data()->window()); window->move(window->pos() + mouseEvent->pos() - _dragPoint); return true; } else { return false; } }
void MenuManager::dragAndDropWithKeyboard() { // inventory menu if (inv->visible && inv->tablist.getCurrent() != -1 && drag_src != DRAG_SRC_ACTIONBAR) { CLICK_TYPE slotClick; Point src_slot; WidgetSlot * inv_slot; if (inv->tablist.getCurrent() < inv->getEquippedCount()) inv_slot = inv->inventory[EQUIPMENT].slots[inv->tablist.getCurrent()]; else inv_slot = inv->inventory[CARRIED].slots[inv->tablist.getCurrent() - inv->getEquippedCount()]; src_slot.x = inv_slot->pos.x; src_slot.y = inv_slot->pos.y; slotClick = inv_slot->checkClick(); // pick up item if (slotClick == CHECKED && drag_stack.item == 0) { drag_stack = inv->click(src_slot); if (drag_stack.item > 0) { keyboard_dragging = true; drag_src = DRAG_SRC_INVENTORY; } } // rearrange item else if (slotClick == CHECKED && drag_stack.item > 0) { inv->drop(src_slot, drag_stack); inv_slot->checked = false; drag_src = 0; drag_stack.item = 0; keyboard_dragging = false; } // sell, stash, or use item else if (slotClick == ACTIVATED && drag_stack.item > 0) { bool not_quest_item = items->items[drag_stack.item].type != "quest"; if (vendor->visible && inv->sell(drag_stack) && not_quest_item) { vendor->setTab(VENDOR_SELL); vendor->add(drag_stack); } else if (stash->visible && !stash->full(drag_stack.item) && not_quest_item) { stash->add(drag_stack); } else { inv->itemReturn(drag_stack); if (!vendor->visible && !stash->visible) inv->activate(src_slot); } inv->clearHighlight(); drag_src = 0; drag_stack.item = 0; keyboard_dragging = false; } } // vendor menu if (vendor->visible && vendor->tablist.getCurrent() != -1 && drag_src != DRAG_SRC_ACTIONBAR) { CLICK_TYPE slotClick; Point src_slot; WidgetSlot * vendor_slot; if (vendor->tablist.getCurrent() < (int)vendor->tablist.size()/2) vendor_slot = vendor->stock[VENDOR_BUY].slots[vendor->tablist.getCurrent()]; else vendor_slot = vendor->stock[VENDOR_SELL].slots[vendor->tablist.getCurrent() - vendor->tablist.size()/2]; src_slot.x = vendor_slot->pos.x; src_slot.y = vendor_slot->pos.y; slotClick = vendor_slot->checkClick(); // buy item if (slotClick == CHECKED && drag_stack.item == 0) { drag_stack = vendor->click(src_slot); if (drag_stack.item > 0) { keyboard_dragging = true; drag_src = DRAG_SRC_VENDOR; } } else if (slotClick == CHECKED && drag_stack.item > 0) { vendor->itemReturn(drag_stack); vendor_slot->checked = false; drag_src = 0; drag_stack.item = 0; keyboard_dragging = false; } else if (slotClick == ACTIVATED && drag_stack.item > 0) { if (!inv->buy(drag_stack,vendor->getTab())) { log->add(msg->get("Not enough %s.", CURRENCY), LOG_TYPE_MESSAGES); hudlog->add(msg->get("Not enough %s.", CURRENCY)); vendor->itemReturn(drag_stack); } else { if (inv->full(drag_stack)) { log->add(msg->get("Inventory is full."), LOG_TYPE_MESSAGES); hudlog->add(msg->get("Inventory is full.")); drop_stack.push(drag_stack); } else { inv->add(drag_stack); } } drag_src = 0; drag_stack.item = 0; keyboard_dragging = false; } } // stash menu if (stash->visible && stash->tablist.getCurrent() != -1 && drag_src != DRAG_SRC_ACTIONBAR) { CLICK_TYPE slotClick = stash->stock.slots[stash->tablist.getCurrent()]->checkClick(); Point src_slot(stash->stock.slots[stash->tablist.getCurrent()]->pos.x, stash->stock.slots[stash->tablist.getCurrent()]->pos.y); // pick up item if (slotClick == CHECKED && drag_stack.item == 0) { drag_stack = stash->click(src_slot); if (drag_stack.item > 0) { keyboard_dragging = true; drag_src = DRAG_SRC_STASH; } } // rearrange item else if (slotClick == CHECKED && drag_stack.item > 0) { stash->stock.slots[stash->tablist.getCurrent()]->checked = false; stash->drop(src_slot, drag_stack); drag_src = 0; drag_stack.item = 0; keyboard_dragging = false; } // send to inventory else if (slotClick == ACTIVATED && drag_stack.item > 0) { if (!inv->full(drag_stack)) { inv->add(drag_stack); } else { log->add(msg->get("Inventory is full."), LOG_TYPE_MESSAGES); hudlog->add(msg->get("Inventory is full.")); splitStack(drag_stack); } drag_src = 0; drag_stack.item = 0; keyboard_dragging = false; } } // powers menu if (pow->visible && pow->tablist.getCurrent() != -1 && drag_src != DRAG_SRC_ACTIONBAR) { CLICK_TYPE slotClick = pow->slots[pow->tablist.getCurrent()]->checkClick(); if (slotClick == CHECKED) { // check for unlock first Point src_slot(pow->slots[pow->tablist.getCurrent()]->pos.x, pow->slots[pow->tablist.getCurrent()]->pos.y); if (!pow->unlockClick(src_slot)) { // otherwise, check for dragging drag_power = pow->click(src_slot); if (drag_power > 0) { keyboard_dragging = true; drag_src = DRAG_SRC_POWERS; } } else { pow->slots[pow->tablist.getCurrent()]->checked = false; } } // clear power dragging if power slot was pressed twice else if (slotClick == ACTIVATED) { drag_src = 0; drag_power = 0; keyboard_dragging = false; } } // actionbar if (act->tablist.getCurrent() >= 0 && act->tablist.getCurrent() < 12) { CLICK_TYPE slotClick = act->slots[act->tablist.getCurrent()]->checkClick(); Point dest_slot(act->slots[act->tablist.getCurrent()]->pos.x, act->slots[act->tablist.getCurrent()]->pos.y); // pick up power if (slotClick == CHECKED && drag_stack.item == 0 && drag_power == 0) { drag_power = act->checkDrag(dest_slot); if (drag_power > 0) { keyboard_dragging = true; drag_src = DRAG_SRC_ACTIONBAR; } } // drop power/item from other menu else if (slotClick == CHECKED && drag_src != DRAG_SRC_ACTIONBAR && (drag_stack.item > 0 || drag_power > 0)) { if (drag_src == DRAG_SRC_POWERS) { act->drop(dest_slot, drag_power, 0); pow->slots[pow->tablist.getCurrent()]->checked = false; } else if (drag_src == DRAG_SRC_INVENTORY) { if (inv->tablist.getCurrent() < inv->getEquippedCount()) inv->inventory[EQUIPMENT].slots[inv->tablist.getCurrent()]->checked = false; else inv->inventory[CARRIED].slots[inv->tablist.getCurrent() - inv->getEquippedCount()]->checked = false; if (items->items[drag_stack.item].power != 0) { act->drop(dest_slot, items->items[drag_stack.item].power, false); } } act->slots[act->tablist.getCurrent()]->checked = false; resetDrag(); keyboard_dragging = false; } // rearrange actionbar else if ((slotClick == CHECKED || slotClick == ACTIVATED) && drag_src == DRAG_SRC_ACTIONBAR && drag_power > 0) { if (slotClick == CHECKED) act->slots[act->tablist.getCurrent()]->checked = false; act->drop(dest_slot, drag_power, 1); drag_src = 0; drag_power = 0; keyboard_dragging = false; inpt->lock[ACCEPT] = false; } } }
void MenuManager::logic() { bool clicking_character = false; bool clicking_inventory = false; bool clicking_powers = false; bool clicking_log = false; ItemStack stack; hp->update(stats->hp,stats->get(STAT_HP_MAX),inpt->mouse); mp->update(stats->mp,stats->get(STAT_MP_MAX),inpt->mouse); xp->update((stats->xp - stats->xp_table[stats->level-1]),(stats->xp_table[stats->level] - stats->xp_table[stats->level-1]),inpt->mouse,msg->get("XP: %d/%d", stats->xp, stats->xp_table[stats->level])); if (NO_MOUSE) handleKeyboardNavigation(); book->logic(); act->logic(); hudlog->logic(); enemy->logic(); chr->logic(); inv->logic(); vendor->logic(); pow->logic(); log->logic(); talker->logic(); stash->logic(); if (chr->checkUpgrade() || stats->level_up) { // apply equipment and max hp/mp inv->applyEquipment(inv->inventory[EQUIPMENT].storage); stats->hp = stats->get(STAT_HP_MAX); stats->mp = stats->get(STAT_MP_MAX); stats->level_up = false; } // only allow the vendor window to be open if the inventory is open if (vendor->visible && !(inv->visible)) { snd->play(vendor->sfx_close); closeAll(); } if (!inpt->pressing[INVENTORY] && !inpt->pressing[POWERS] && !inpt->pressing[CHARACTER] && !inpt->pressing[LOG]) key_lock = false; // handle npc action menu if (npc->visible) { npc->logic(); } // check if mouse-clicking a menu button act->checkMenu(clicking_character, clicking_inventory, clicking_powers, clicking_log); if (exit->visible) { exit->logic(); if (exit->isExitRequested()) { done = true; } } // cancel dragging and defocus menu tablists if (!key_lock && inpt->pressing[CANCEL] && !inpt->lock[CANCEL] && !stats->corpse) { if (keyboard_dragging || mouse_dragging) { inpt->lock[CANCEL] = true; resetDrag(); keyboard_dragging = false; mouse_dragging = false; } if (inv->tablist.getCurrent() != -1 || vendor->tablist.getCurrent() != -1 || stash->tablist.getCurrent() != -1 || act->tablist.getCurrent() != -1 || pow->tablist.getCurrent() != -1 || chr->tablist.getCurrent() != -1 || log->tablist.getCurrent() != -1 || book->tablist.getCurrent() != -1) { inpt->lock[CANCEL] = true; inv->tablist.defocus(); vendor->tablist.defocus(); stash->tablist.defocus(); act->tablist.defocus(); pow->tablist.defocus(); chr->tablist.defocus(); log->tablist.defocus(); book->tablist.defocus(); } } // exit menu toggle if ((!key_lock && !mouse_dragging && !keyboard_dragging) && !(stats->corpse && stats->permadeath)) { if (inpt->pressing[CANCEL] && !inpt->lock[CANCEL]) { inpt->lock[CANCEL] = true; key_lock = true; if (menus_open) { closeAll(); } else { exit->visible = !exit->visible; } } } // inventory menu toggle if ((inpt->pressing[INVENTORY] && !key_lock && !mouse_dragging && !keyboard_dragging) || clicking_inventory) { key_lock = true; if (inv->visible) { snd->play(inv->sfx_close); closeRight(); } else { closeRight(); act->requires_attention[MENU_INVENTORY] = false; inv->visible = true; snd->play(inv->sfx_open); } } // powers menu toggle if (((inpt->pressing[POWERS] && !key_lock && !mouse_dragging && !keyboard_dragging) || clicking_powers) && !stats->transformed) { key_lock = true; if (pow->visible) { snd->play(pow->sfx_close); closeRight(); } else { closeRight(); act->requires_attention[MENU_POWERS] = false; pow->visible = true; snd->play(pow->sfx_open); } } act->requires_attention[MENU_POWERS] = pow->getUnspent() > 0; // character menu toggleggle if ((inpt->pressing[CHARACTER] && !key_lock && !mouse_dragging && !keyboard_dragging) || clicking_character) { key_lock = true; if (chr->visible) { snd->play(chr->sfx_close); closeLeft(); } else { closeLeft(); act->requires_attention[MENU_CHARACTER] = false; chr->visible = true; snd->play(chr->sfx_open); // Make sure the stat list isn't scrolled when we open the character menu inpt->resetScroll(); } } act->requires_attention[MENU_CHARACTER] = chr->getUnspent() > 0; // log menu toggle if ((inpt->pressing[LOG] && !key_lock && !mouse_dragging && !keyboard_dragging) || clicking_log) { key_lock = true; if (log->visible) { snd->play(log->sfx_close); closeLeft(); } else { closeLeft(); act->requires_attention[MENU_LOG] = false; log->visible = true; snd->play(log->sfx_open); // Make sure the log isn't scrolled when we open the log menu inpt->resetScroll(); } } menus_open = (inv->visible || pow->visible || chr->visible || log->visible || vendor->visible || talker->visible || npc->visible || book->visible); pause = (MENUS_PAUSE && menus_open) || exit->visible; if (stats->alive) { // handle right-click if (!mouse_dragging && inpt->pressing[MAIN2] && !inpt->lock[MAIN2]) { // exit menu if (exit->visible && isWithin(exit->window_area, inpt->mouse)) { inpt->lock[MAIN2] = true; } // book menu if (book->visible && isWithin(book->window_area, inpt->mouse)) { inpt->lock[MAIN2] = true; } // activate inventory item else if (inv->visible && isWithin(inv->window_area, inpt->mouse)) { inpt->lock[MAIN2] = true; if (isWithin(inv->carried_area, inpt->mouse)) { inv->activate(inpt->mouse); } } } // handle left-click for book menu first if (!mouse_dragging && inpt->pressing[MAIN1] && !inpt->lock[MAIN1]) { if (book->visible && isWithin(book->window_area, inpt->mouse)) { inpt->lock[MAIN1] = true; } } // handle left-click if (!mouse_dragging && inpt->pressing[MAIN1] && !inpt->lock[MAIN1]) { // clear keyboard dragging if (keyboard_dragging) { resetDrag(); keyboard_dragging = false; } // exit menu if (exit->visible && isWithin(exit->window_area, inpt->mouse)) { inpt->lock[MAIN1] = true; } if (chr->visible && isWithin(chr->window_area, inpt->mouse)) { inpt->lock[MAIN1] = true; } if (vendor->visible && isWithin(vendor->window_area,inpt->mouse)) { inpt->lock[MAIN1] = true; vendor->tabsLogic(); if (inpt->pressing[CTRL]) { // buy item from a vendor stack = vendor->click(inpt->mouse); if (stack.item > 0) { if (!inv->buy(stack,vendor->getTab())) { log->add(msg->get("Not enough %s.", CURRENCY), LOG_TYPE_MESSAGES); hudlog->add(msg->get("Not enough %s.", CURRENCY)); vendor->itemReturn( stack); } else { if (inv->full(stack)) { log->add(msg->get("Inventory is full."), LOG_TYPE_MESSAGES); hudlog->add(msg->get("Inventory is full.")); drop_stack.push(stack); } else { inv->add(stack); } } } } else { // start dragging a vendor item drag_stack = vendor->click(inpt->mouse); if (drag_stack.item > 0) { mouse_dragging = true; drag_src = DRAG_SRC_VENDOR; } } } if (stash->visible && isWithin(stash->window_area,inpt->mouse)) { inpt->lock[MAIN1] = true; if (inpt->pressing[CTRL]) { // take an item from the stash stack = stash->click(inpt->mouse); if (stack.item > 0) { if (inv->full(stack)) { log->add(msg->get("Inventory is full."), LOG_TYPE_MESSAGES); hudlog->add(msg->get("Inventory is full.")); splitStack(stack); } else { inv->add(stack); } stash->updated = true; } } else { // start dragging a stash item drag_stack = stash->click(inpt->mouse); if (drag_stack.item > 0) { mouse_dragging = true; drag_src = DRAG_SRC_STASH; } } } if (log->visible && isWithin(log->window_area,inpt->mouse)) { inpt->lock[MAIN1] = true; } // pick up an inventory item if (inv->visible && isWithin(inv->window_area,inpt->mouse)) { if (inpt->pressing[CTRL]) { inpt->lock[MAIN1] = true; stack = inv->click(inpt->mouse); if (stack.item > 0) { if (stash->visible) { if (inv->stashAdd(stack) && !stash->full(stack.item)) { stash->add(stack); stash->updated = true; } else { inv->itemReturn(stack); } } else { // The vendor could have a limited amount of currency in the future. It will be tested here. if ((SELL_WITHOUT_VENDOR || vendor->visible) && inv->sell(stack)) { vendor->setTab(VENDOR_SELL); vendor->add(stack); } else { inv->itemReturn(stack); } } } } else { inpt->lock[MAIN1] = true; drag_stack = inv->click(inpt->mouse); if (drag_stack.item > 0) { mouse_dragging = true; drag_src = DRAG_SRC_INVENTORY; } } } // pick up a power if (pow->visible && isWithin(pow->window_area,inpt->mouse)) { inpt->lock[MAIN1] = true; // check for unlock first if (!pow->unlockClick(inpt->mouse)) { // otherwise, check for dragging drag_power = pow->click(inpt->mouse); if (drag_power > 0) { mouse_dragging = true; keyboard_dragging = false; drag_src = DRAG_SRC_POWERS; } } } // action bar if (isWithin(act->numberArea,inpt->mouse) || isWithin(act->mouseArea,inpt->mouse) || isWithin(act->menuArea, inpt->mouse)) { inpt->lock[MAIN1] = true; // ctrl-click action bar to clear that slot if (inpt->pressing[CTRL]) { act->remove(inpt->mouse); } // allow drag-to-rearrange action bar else if (!isWithin(act->menuArea, inpt->mouse)) { drag_power = act->checkDrag(inpt->mouse); if (drag_power > 0) { mouse_dragging = true; drag_src = DRAG_SRC_ACTIONBAR; } } // else, clicking action bar to use a power? // this check is done by GameEngine when calling Avatar::logic() } } // handle dropping if (mouse_dragging && !inpt->pressing[MAIN1]) { // putting a power on the Action Bar if (drag_src == DRAG_SRC_POWERS) { if (isWithin(act->numberArea,inpt->mouse) || isWithin(act->mouseArea,inpt->mouse)) { act->drop(inpt->mouse, drag_power, 0); } } // rearranging the action bar else if (drag_src == DRAG_SRC_ACTIONBAR) { if (isWithin(act->numberArea,inpt->mouse) || isWithin(act->mouseArea,inpt->mouse)) { act->drop(inpt->mouse, drag_power, 1); // for locked slots forbid power dropping } else if (act->locked[act->drag_prev_slot]) { act->hotkeys[act->drag_prev_slot] = drag_power; } drag_power = 0; } // rearranging inventory or dropping items else if (drag_src == DRAG_SRC_INVENTORY) { if (inv->visible && isWithin(inv->window_area, inpt->mouse)) { inv->drop(inpt->mouse, drag_stack); } else if (isWithin(act->numberArea,inpt->mouse) || isWithin(act->mouseArea,inpt->mouse)) { // The action bar is not storage! inv->itemReturn(drag_stack); // put an item with a power on the action bar if (items->items[drag_stack.item].power != 0) { act->drop(inpt->mouse, items->items[drag_stack.item].power, false); } } else if (vendor->visible && isWithin(vendor->slots_area, inpt->mouse)) { if (inv->sell( drag_stack)) { vendor->setTab(VENDOR_SELL); vendor->add( drag_stack); } else { inv->itemReturn(drag_stack); } } else if (stash->visible && isWithin(stash->slots_area, inpt->mouse)) { if (inv->stashAdd( drag_stack) && !stash->full(drag_stack.item)) { stash->drop(inpt->mouse, drag_stack); stash->updated = true; } else { inv->itemReturn(drag_stack); } } else { // if dragging and the source was inventory, drop item to the floor // quest items cannot be dropped if (items->items[drag_stack.item].type != "quest") { drop_stack.push(drag_stack); inv->clearHighlight(); } else { inv->itemReturn(drag_stack); } } } else if (drag_src == DRAG_SRC_VENDOR) { // dropping an item from vendor (we only allow to drop into the carried area) if (inv->visible && isWithin( inv->carried_area, inpt->mouse)) { if (!inv->buy(drag_stack,vendor->getTab())) { log->add(msg->get("Not enough %s.", CURRENCY), LOG_TYPE_MESSAGES); hudlog->add(msg->get("Not enough %s.", CURRENCY)); vendor->itemReturn( drag_stack); } else { if (inv->full(drag_stack)) { log->add(msg->get("Inventory is full."), LOG_TYPE_MESSAGES); hudlog->add(msg->get("Inventory is full.")); drop_stack.push(drag_stack); } else { inv->drop(inpt->mouse,drag_stack); } } } else { vendor->itemReturn(drag_stack); } } else if (drag_src == DRAG_SRC_STASH) { // dropping an item from stash (we only allow to drop into the carried area) if (inv->visible && isWithin( inv->carried_area, inpt->mouse)) { if (inv->full(drag_stack)) { log->add(msg->get("Inventory is full."), LOG_TYPE_MESSAGES); hudlog->add(msg->get("Inventory is full.")); splitStack(drag_stack); } else { inv->drop(inpt->mouse,drag_stack); } stash->updated = true; } else if (stash->visible && isWithin(stash->slots_area, inpt->mouse)) { stash->drop(inpt->mouse,drag_stack); } else { drop_stack.push(drag_stack); } } drag_stack.item = 0; drag_stack.quantity = 0; drag_power = 0; drag_src = 0; mouse_dragging = false; } if (NO_MOUSE) dragAndDropWithKeyboard(); } else { if (mouse_dragging || keyboard_dragging) { resetDrag(); mouse_dragging = false; keyboard_dragging = false; } } // handle equipment changes affecting hero stats if (inv->changed_equipment || inv->changed_artifact) { inv->applyEquipment(inv->inventory[EQUIPMENT].storage); inv->changed_artifact = false; // the equipment flag is reset after the new sprites are loaded } // for action-bar powers that represent items, lookup the current item count for (int i=0; i<12; i++) { act->slot_enabled[i] = true; act->slot_item_count[i] = -1; if (act->hotkeys[i] != -1) { int item_id = powers->powers[act->hotkeys[i]].requires_item; if (item_id != -1 && items->items[item_id].type == "consumable") { act->slot_item_count[i] = inv->getItemCountCarried(item_id); if (act->slot_item_count[i] == 0) { act->slot_enabled[i] = false; } } else if (item_id != -1) { // if a non-consumable item power is unequipped, disable that slot if (!inv->isItemEquipped(item_id)) { act->slot_item_count[i] = 0; act->slot_enabled[i] = false; } } } } if (drag_icon && !(mouse_dragging || keyboard_dragging)) { delete drag_icon; drag_icon = NULL; } }