public override void Update(GameTime gameTime) { if (!Game.IsActive) { return; } //check for drag-drop here MouseState currentState = Mouse.GetState(); if (!m_beingDragged && MouseOverPreviously && MouseOver && PreviousMouseState.LeftButton == ButtonState.Pressed && currentState.LeftButton == ButtonState.Pressed) { //Conditions for starting are the mouse is over, the button is pressed, and no other items are being dragged if (((EOInventory)parent).NoItemsDragging()) { //start the drag operation and hide the item label m_beingDragged = true; m_nameLabel.Visible = false; m_preDragDrawOrder = DrawOrder; m_preDragParent = parent; //make sure the offsets are maintained! //required to enable dragging past bounds of the inventory panel m_oldOffX = xOff; m_oldOffY = yOff; SetParent(null); m_alpha = 128; DrawOrder = 100; //arbitrarily large constant so drawn on top while dragging } } if (m_beingDragged && PreviousMouseState.LeftButton == ButtonState.Pressed && currentState.LeftButton == ButtonState.Pressed) { //dragging has started. continue dragging until mouse is released, update position based on mouse location DrawLocation = new Vector2(currentState.X - (DrawArea.Width / 2), currentState.Y - (DrawArea.Height / 2)); } else if (m_beingDragged && PreviousMouseState.LeftButton == ButtonState.Pressed && currentState.LeftButton == ButtonState.Released) { //need to check for: drop on map (drop action) // drop on button junk/drop // drop on grid (inventory move action) // drop on chest dialog (chest add action) DrawOrder = m_preDragDrawOrder; m_alpha = 255; SetParent(m_preDragParent); if (((EOInventory)parent).IsOverDrop() || (World.Instance.ActiveMapRenderer.MouseOver && EOChestDialog.Instance == null && EOPaperdollDialog.Instance == null && EOLockerDialog.Instance == null)) { Microsoft.Xna.Framework.Point loc = World.Instance.ActiveMapRenderer.MouseOver ? World.Instance.ActiveMapRenderer.GridCoords: new Microsoft.Xna.Framework.Point(World.Instance.MainPlayer.ActiveCharacter.X, World.Instance.MainPlayer.ActiveCharacter.Y); //in range if maximum coordinate difference is <= 2 away bool inRange = Math.Abs(Math.Max(World.Instance.MainPlayer.ActiveCharacter.X - loc.X, World.Instance.MainPlayer.ActiveCharacter.Y - loc.Y)) <= 2; if (m_itemData.Special == ItemSpecial.Lore) { EODialog.Show(DATCONST1.ITEM_IS_LORE_ITEM, XNADialogButtons.Ok, EODialogStyle.SmallDialogSmallHeader); } else if (World.Instance.JailMap == World.Instance.MainPlayer.ActiveCharacter.CurrentMap) { EODialog.Show(World.GetString(DATCONST2.JAIL_WARNING_CANNOT_DROP_ITEMS), World.GetString(DATCONST2.STATUS_LABEL_TYPE_WARNING), XNADialogButtons.Ok, EODialogStyle.SmallDialogSmallHeader); } else if (m_inventory.amount > 1 && inRange) { EOItemTransferDialog dlg = new EOItemTransferDialog(m_itemData.Name, EOItemTransferDialog.TransferType.DropItems, m_inventory.amount); dlg.DialogClosing += (sender, args) => { if (args.Result == XNADialogResult.OK) { //note: not sure of the actual limit. 10000 is arbitrary here if (dlg.SelectedAmount > 10000 && m_inventory.id == 1 && !safetyCommentHasBeenShown) { EODialog.Show(DATCONST1.DROP_MANY_GOLD_ON_GROUND, XNADialogButtons.Ok, EODialogStyle.SmallDialogSmallHeader, (o, e) => { safetyCommentHasBeenShown = true; }); } else if (!m_api.DropItem(m_inventory.id, dlg.SelectedAmount, (byte)loc.X, (byte)loc.Y)) { ((EOGame)Game).LostConnectionDialog(); } } }; } else if (inRange) { if (!m_api.DropItem(m_inventory.id, 1, (byte)loc.X, (byte)loc.Y)) { ((EOGame)Game).LostConnectionDialog(); } } else /*if (!inRange)*/ { EOGame.Instance.Hud.SetStatusLabel(DATCONST2.STATUS_LABEL_TYPE_WARNING, DATCONST2.STATUS_LABEL_ITEM_DROP_OUT_OF_RANGE); } } else if (((EOInventory)parent).IsOverJunk()) { if (m_inventory.amount > 1) { EOItemTransferDialog dlg = new EOItemTransferDialog(m_itemData.Name, EOItemTransferDialog.TransferType.JunkItems, m_inventory.amount, DATCONST2.DIALOG_TRANSFER_JUNK); dlg.DialogClosing += (sender, args) => { if (args.Result == XNADialogResult.OK && !m_api.JunkItem(m_inventory.id, dlg.SelectedAmount)) { ((EOGame)Game).LostConnectionDialog(); } }; } else if (!m_api.JunkItem(m_inventory.id, 1)) { ((EOGame)Game).LostConnectionDialog(); } } else if (EOChestDialog.Instance != null && EOChestDialog.Instance.MouseOver && EOChestDialog.Instance.MouseOverPreviously) { if (m_itemData.Special == ItemSpecial.Lore) { EODialog.Show(DATCONST1.ITEM_IS_LORE_ITEM, XNADialogButtons.Ok, EODialogStyle.SmallDialogSmallHeader); } else if (m_inventory.amount > 1) { EOItemTransferDialog dlg = new EOItemTransferDialog(m_itemData.Name, EOItemTransferDialog.TransferType.DropItems, m_inventory.amount); dlg.DialogClosing += (sender, args) => { if (args.Result == XNADialogResult.OK && !m_api.ChestAddItem(EOChestDialog.Instance.CurrentChestX, EOChestDialog.Instance.CurrentChestY, m_inventory.id, dlg.SelectedAmount)) { EOGame.Instance.LostConnectionDialog(); } }; } else { if (!m_api.ChestAddItem(EOChestDialog.Instance.CurrentChestX, EOChestDialog.Instance.CurrentChestY, m_inventory.id, 1)) { EOGame.Instance.LostConnectionDialog(); } } } else if (EOPaperdollDialog.Instance != null && EOPaperdollDialog.Instance.MouseOver && EOPaperdollDialog.Instance.MouseOverPreviously) { //equipable items should be equipped //other item types should do nothing switch (m_itemData.Type) { case ItemType.Accessory: case ItemType.Armlet: case ItemType.Armor: case ItemType.Belt: case ItemType.Boots: case ItemType.Bracer: case ItemType.Gloves: case ItemType.Hat: case ItemType.Necklace: case ItemType.Ring: case ItemType.Shield: case ItemType.Weapon: _handleDoubleClick(); break; } } else if (EOLockerDialog.Instance != null && EOLockerDialog.Instance.MouseOver && EOLockerDialog.Instance.MouseOverPreviously) { if (m_inventory.id == 1) { EODialog.Show(DATCONST1.LOCKER_DEPOSIT_GOLD_ERROR, XNADialogButtons.Ok, EODialogStyle.SmallDialogSmallHeader); } else if (m_inventory.amount > 1) { EOItemTransferDialog dlg = new EOItemTransferDialog(m_itemData.Name, EOItemTransferDialog.TransferType.ShopTransfer, m_inventory.amount, DATCONST2.DIALOG_TRANSFER_TRANSFER); dlg.DialogClosing += (sender, args) => { if (args.Result == XNADialogResult.OK) { if (EOLockerDialog.Instance.GetNewItemAmount(m_inventory.id, dlg.SelectedAmount) > Constants.LockerMaxSingleItemAmount) { EODialog.Show(DATCONST1.LOCKER_FULL_SINGLE_ITEM_MAX, XNADialogButtons.Ok, EODialogStyle.SmallDialogSmallHeader); } else if (!Handlers.Locker.AddItem(m_inventory.id, dlg.SelectedAmount)) { EOGame.Instance.LostConnectionDialog(); } } }; } else { if (EOLockerDialog.Instance.GetNewItemAmount(m_inventory.id, 1) > Constants.LockerMaxSingleItemAmount) { EODialog.Show(DATCONST1.LOCKER_FULL_SINGLE_ITEM_MAX, XNADialogButtons.Ok, EODialogStyle.SmallDialogSmallHeader); } else if (!Handlers.Locker.AddItem(m_inventory.id, 1)) { EOGame.Instance.LostConnectionDialog(); } } } else if (EOBankAccountDialog.Instance != null && EOBankAccountDialog.Instance.MouseOver && EOBankAccountDialog.Instance.MouseOverPreviously && m_inventory.id == 1) { if (m_inventory.amount == 0) { EODialog.Show(DATCONST1.BANK_ACCOUNT_UNABLE_TO_DEPOSIT, XNADialogButtons.Ok, EODialogStyle.SmallDialogSmallHeader); } else if (m_inventory.amount > 1) { EOItemTransferDialog dlg = new EOItemTransferDialog(m_itemData.Name, EOItemTransferDialog.TransferType.BankTransfer, m_inventory.amount, DATCONST2.DIALOG_TRANSFER_DEPOSIT); dlg.DialogClosing += (o, e) => { if (e.Result == XNADialogResult.Cancel) { return; } if (!Handlers.Bank.BankDeposit(dlg.SelectedAmount)) { EOGame.Instance.LostConnectionDialog(); } }; } else { if (!Handlers.Bank.BankDeposit(1)) { EOGame.Instance.LostConnectionDialog(); } } } //update the location - if it isn't on the grid, the bounds check will set it back to where it used to be originally //Item amount will be updated or item will be removed in packet response to the drop operation UpdateItemLocation(ItemCurrentSlot()); //mouse has been released. finish dragging. m_beingDragged = false; m_nameLabel.Visible = true; } if (!m_beingDragged && PreviousMouseState.LeftButton == ButtonState.Pressed && currentState.LeftButton == ButtonState.Released && MouseOver && MouseOverPreviously) { Interlocked.Increment(ref m_recentClickCount); if (m_recentClickCount == 2) { _handleDoubleClick(); } } if (!MouseOverPreviously && MouseOver && !m_beingDragged) { m_nameLabel.Visible = true; EOGame.Instance.Hud.SetStatusLabel(DATCONST2.STATUS_LABEL_TYPE_ITEM, m_nameLabel.Text); } else if (!MouseOver && !m_beingDragged && m_nameLabel != null && m_nameLabel.Visible) { m_nameLabel.Visible = false; } base.Update(gameTime); //sets mouseoverpreviously = mouseover, among other things }
public override void Update(GameTime gameTime) { if (!Game.IsActive) return; //check for drag-drop here MouseState currentState = Mouse.GetState(); if (!m_beingDragged && MouseOverPreviously && MouseOver && PreviousMouseState.LeftButton == ButtonState.Pressed && currentState.LeftButton == ButtonState.Pressed) { //Conditions for starting are the mouse is over, the button is pressed, and no other items are being dragged if (((EOInventory) parent).NoItemsDragging()) { //start the drag operation and hide the item label m_beingDragged = true; m_nameLabel.Visible = false; m_preDragDrawOrder = DrawOrder; m_preDragParent = parent; //make sure the offsets are maintained! //required to enable dragging past bounds of the inventory panel m_oldOffX = xOff; m_oldOffY = yOff; SetParent(null); m_alpha = 128; DrawOrder = 100; //arbitrarily large constant so drawn on top while dragging } } if (m_beingDragged && PreviousMouseState.LeftButton == ButtonState.Pressed && currentState.LeftButton == ButtonState.Pressed) { //dragging has started. continue dragging until mouse is released, update position based on mouse location DrawLocation = new Vector2(currentState.X - (DrawArea.Width/2), currentState.Y - (DrawArea.Height/2)); } else if (m_beingDragged && PreviousMouseState.LeftButton == ButtonState.Pressed && currentState.LeftButton == ButtonState.Released) { //need to check for: drop on map (drop action) // drop on button junk/drop // drop on grid (inventory move action) // drop on [x] dialog ([x] add action) m_alpha = 255; SetParent(m_preDragParent); if (((EOInventory) parent).IsOverDrop() || (World.Instance.ActiveMapRenderer.MouseOver && EOChestDialog.Instance == null && EOPaperdollDialog.Instance == null && EOLockerDialog.Instance == null && EOBankAccountDialog.Instance == null && EOTradeDialog.Instance == null)) { Microsoft.Xna.Framework.Point loc = World.Instance.ActiveMapRenderer.MouseOver ? World.Instance.ActiveMapRenderer.GridCoords: new Microsoft.Xna.Framework.Point(World.Instance.MainPlayer.ActiveCharacter.X, World.Instance.MainPlayer.ActiveCharacter.Y); //in range if maximum coordinate difference is <= 2 away bool inRange = Math.Abs(Math.Max(World.Instance.MainPlayer.ActiveCharacter.X - loc.X, World.Instance.MainPlayer.ActiveCharacter.Y - loc.Y)) <= 2; if (m_itemData.Special == ItemSpecial.Lore) { EODialog.Show(DATCONST1.ITEM_IS_LORE_ITEM, XNADialogButtons.Ok, EODialogStyle.SmallDialogSmallHeader); } else if (World.Instance.JailMap == World.Instance.MainPlayer.ActiveCharacter.CurrentMap) { EODialog.Show(World.GetString(DATCONST2.JAIL_WARNING_CANNOT_DROP_ITEMS), World.GetString(DATCONST2.STATUS_LABEL_TYPE_WARNING), XNADialogButtons.Ok, EODialogStyle.SmallDialogSmallHeader); } else if (m_inventory.amount > 1 && inRange) { EOItemTransferDialog dlg = new EOItemTransferDialog(m_itemData.Name, EOItemTransferDialog.TransferType.DropItems, m_inventory.amount); dlg.DialogClosing += (sender, args) => { if (args.Result == XNADialogResult.OK) { //note: not sure of the actual limit. 10000 is arbitrary here if (dlg.SelectedAmount > 10000 && m_inventory.id == 1 && !safetyCommentHasBeenShown) EODialog.Show(DATCONST1.DROP_MANY_GOLD_ON_GROUND, XNADialogButtons.Ok, EODialogStyle.SmallDialogSmallHeader, (o, e) => { safetyCommentHasBeenShown = true; }); else if (!m_api.DropItem(m_inventory.id, dlg.SelectedAmount, (byte) loc.X, (byte) loc.Y)) ((EOGame) Game).LostConnectionDialog(); } }; } else if (inRange) { if (!m_api.DropItem(m_inventory.id, 1, (byte)loc.X, (byte)loc.Y)) ((EOGame)Game).LostConnectionDialog(); } else /*if (!inRange)*/ { EOGame.Instance.Hud.SetStatusLabel(DATCONST2.STATUS_LABEL_TYPE_WARNING, DATCONST2.STATUS_LABEL_ITEM_DROP_OUT_OF_RANGE); } } else if (((EOInventory) parent).IsOverJunk()) { if (m_inventory.amount > 1) { EOItemTransferDialog dlg = new EOItemTransferDialog(m_itemData.Name, EOItemTransferDialog.TransferType.JunkItems, m_inventory.amount, DATCONST2.DIALOG_TRANSFER_JUNK); dlg.DialogClosing += (sender, args) => { if (args.Result == XNADialogResult.OK && !m_api.JunkItem(m_inventory.id, dlg.SelectedAmount)) ((EOGame)Game).LostConnectionDialog(); }; } else if (!m_api.JunkItem(m_inventory.id, 1)) ((EOGame) Game).LostConnectionDialog(); } else if (EOChestDialog.Instance != null && EOChestDialog.Instance.MouseOver && EOChestDialog.Instance.MouseOverPreviously) { if (m_itemData.Special == ItemSpecial.Lore) { EODialog.Show(DATCONST1.ITEM_IS_LORE_ITEM, XNADialogButtons.Ok, EODialogStyle.SmallDialogSmallHeader); } else if (m_inventory.amount > 1) { EOItemTransferDialog dlg = new EOItemTransferDialog(m_itemData.Name, EOItemTransferDialog.TransferType.DropItems, m_inventory.amount); dlg.DialogClosing += (sender, args) => { if (args.Result == XNADialogResult.OK && !m_api.ChestAddItem(EOChestDialog.Instance.CurrentChestX, EOChestDialog.Instance.CurrentChestY, m_inventory.id, dlg.SelectedAmount)) EOGame.Instance.LostConnectionDialog(); }; } else { if (!m_api.ChestAddItem(EOChestDialog.Instance.CurrentChestX, EOChestDialog.Instance.CurrentChestY, m_inventory.id, 1)) EOGame.Instance.LostConnectionDialog(); } } else if (EOPaperdollDialog.Instance != null && EOPaperdollDialog.Instance.MouseOver && EOPaperdollDialog.Instance.MouseOverPreviously) { //equipable items should be equipped //other item types should do nothing switch (m_itemData.Type) { case ItemType.Accessory: case ItemType.Armlet: case ItemType.Armor: case ItemType.Belt: case ItemType.Boots: case ItemType.Bracer: case ItemType.Gloves: case ItemType.Hat: case ItemType.Necklace: case ItemType.Ring: case ItemType.Shield: case ItemType.Weapon: _handleDoubleClick(); break; } } else if (EOLockerDialog.Instance != null && EOLockerDialog.Instance.MouseOver && EOLockerDialog.Instance.MouseOverPreviously) { byte x = EOLockerDialog.Instance.X; byte y = EOLockerDialog.Instance.Y; if (m_inventory.id == 1) { EODialog.Show(DATCONST1.LOCKER_DEPOSIT_GOLD_ERROR, XNADialogButtons.Ok, EODialogStyle.SmallDialogSmallHeader); } else if (m_inventory.amount > 1) { EOItemTransferDialog dlg = new EOItemTransferDialog(m_itemData.Name, EOItemTransferDialog.TransferType.ShopTransfer, m_inventory.amount, DATCONST2.DIALOG_TRANSFER_TRANSFER); dlg.DialogClosing += (sender, args) => { if (args.Result == XNADialogResult.OK) { if (EOLockerDialog.Instance.GetNewItemAmount(m_inventory.id, dlg.SelectedAmount) > Constants.LockerMaxSingleItemAmount) EODialog.Show(DATCONST1.LOCKER_FULL_SINGLE_ITEM_MAX, XNADialogButtons.Ok, EODialogStyle.SmallDialogSmallHeader); else if (!m_api.LockerAddItem(x, y, m_inventory.id, dlg.SelectedAmount)) EOGame.Instance.LostConnectionDialog(); } }; } else { if (EOLockerDialog.Instance.GetNewItemAmount(m_inventory.id, 1) > Constants.LockerMaxSingleItemAmount) EODialog.Show(DATCONST1.LOCKER_FULL_SINGLE_ITEM_MAX, XNADialogButtons.Ok, EODialogStyle.SmallDialogSmallHeader); else if (!m_api.LockerAddItem(x, y, m_inventory.id, 1)) EOGame.Instance.LostConnectionDialog(); } } else if (EOBankAccountDialog.Instance != null && EOBankAccountDialog.Instance.MouseOver && EOBankAccountDialog.Instance.MouseOverPreviously && m_inventory.id == 1) { if (m_inventory.amount == 0) { EODialog.Show(DATCONST1.BANK_ACCOUNT_UNABLE_TO_DEPOSIT, XNADialogButtons.Ok, EODialogStyle.SmallDialogSmallHeader); } else if (m_inventory.amount > 1) { EOItemTransferDialog dlg = new EOItemTransferDialog(m_itemData.Name, EOItemTransferDialog.TransferType.BankTransfer, m_inventory.amount, DATCONST2.DIALOG_TRANSFER_DEPOSIT); dlg.DialogClosing += (o, e) => { if (e.Result == XNADialogResult.Cancel) return; if (!m_api.BankDeposit(dlg.SelectedAmount)) EOGame.Instance.LostConnectionDialog(); }; } else { if (!m_api.BankDeposit(1)) EOGame.Instance.LostConnectionDialog(); } } else if (EOTradeDialog.Instance != null && EOTradeDialog.Instance.MouseOver && EOTradeDialog.Instance.MouseOverPreviously && !EOTradeDialog.Instance.MainPlayerAgrees) { if (m_itemData.Special == ItemSpecial.Lore) { EODialog.Show(DATCONST1.ITEM_IS_LORE_ITEM); } else if (m_inventory.amount > 1) { EOItemTransferDialog dlg = new EOItemTransferDialog(m_itemData.Name, EOItemTransferDialog.TransferType.TradeItems, m_inventory.amount, DATCONST2.DIALOG_TRANSFER_OFFER); dlg.DialogClosing += (o, e) => { if (e.Result != XNADialogResult.OK) return; if (!m_api.TradeAddItem(m_inventory.id, dlg.SelectedAmount)) { EOTradeDialog.Instance.Close(XNADialogResult.NO_BUTTON_PRESSED); ((EOGame)Game).LostConnectionDialog(); } }; } else if(!m_api.TradeAddItem(m_inventory.id, 1)) { EOTradeDialog.Instance.Close(XNADialogResult.NO_BUTTON_PRESSED); ((EOGame)Game).LostConnectionDialog(); } } //update the location - if it isn't on the grid, the bounds check will set it back to where it used to be originally //Item amount will be updated or item will be removed in packet response to the drop operation UpdateItemLocation(ItemCurrentSlot()); //mouse has been released. finish dragging. m_beingDragged = false; m_nameLabel.Visible = true; DrawOrder = m_preDragDrawOrder; } if (!m_beingDragged && PreviousMouseState.LeftButton == ButtonState.Pressed && currentState.LeftButton == ButtonState.Released && MouseOver && MouseOverPreviously) { Interlocked.Increment(ref m_recentClickCount); if (m_recentClickCount == 2) { _handleDoubleClick(); } } if (!MouseOverPreviously && MouseOver && !m_beingDragged) { m_nameLabel.Visible = true; EOGame.Instance.Hud.SetStatusLabel(DATCONST2.STATUS_LABEL_TYPE_ITEM, m_nameLabel.Text); } else if (!MouseOver && !m_beingDragged && m_nameLabel != null && m_nameLabel.Visible) { m_nameLabel.Visible = false; } base.Update(gameTime); //sets mouseoverpreviously = mouseover, among other things }