8000 Change cards from sb<->mb with double-click by ZeldaZach · Pull Request #2606 · Cockatrice/Cockatrice · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Change cards from sb<->mb with double-click #2606

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 25, 2017
Merged

Change cards from sb<->mb with double-click #2606

merged 1 commit into from
Apr 25, 2017

Conversation

ZeldaZach
Copy link
Member
@ZeldaZach ZeldaZach commented Apr 20, 2017

Related Ticket(s)

Fix #2594

This PR allows a person to double click on a card to change it from sideboard to mainboard and vice versa. This will not impact tokens (if you imported them to the deck) and will work in the exact same context as the drag/drop method.

@ZeldaZach ZeldaZach requested review from ctrlaltca and Daenyth April 20, 2017 05:34
@@ -1,5 +1,6 @@
#include <QApplication>
#include <QGraphicsSceneMouseEvent>
#include <QDebug>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is QDebug needed in the PR?
I see that it outputs "LEFT", though I assume this was for your own testing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a WIP, so I have debugging information in here for my purposes. Will all be removed at the end.

8000
m.set_card_name(c->getName().toStdString());
m.set_start_zone(c->getOriginZone().toStdString());

if (c->getOriginZone() == "main")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't there some public const variables for these named zones?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch.

Can you add some constants for the special zones?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah i'll add that to the PR

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main problem now is that you are using getOriginZone() to determine where a card actually is and where it should move to, but the "original zone" is never updated, so if you move a card from "main" to "side" its original zone will still be "main"; double clicking it again will try to move it again from the main to the side.
You don't want to che the card "original zone", but its "current zone" instead; you should be able to get this information from the card's parentItem()

if (event->button() == Qt::LeftButton)
{
qDebug() << "LEFT";
QList<MoveCard_ToZone> *result = new QList<MoveCard_ToZone>();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left it allocated on purpose until I could get it to work, then would find a safe place to de-allocate

@@ -1,5 +1,6 @@
#include <QApplication>
#include <QGraphicsSceneMouseEvent>
#include <QDebug>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -274,13 +275,26 @@ void DeckViewContainer::sideboardLockButtonClicked()

void DeckViewContainer::sideboardPlanChanged()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please refactor this method in order to make use of your new method, to avoid code duplication.
Alternatively, just drop it and make the old code call directly your method.

cmd.add_move_list()->CopyFrom(newPlan->at(i));
parentGame->sendGameCommand(cmd, playerId);

// TODO: Need to figure out how to re-paint the deck view
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DeckViewScene::applySideboardPlan() is probably a good starting point.
You probably want to handle this inside DeckView::mouseDoubleClickEvent, get the old and new DeckViewCardContainer zones from the scene()->cardContainers list, and then move the card from one zone to another the same way it's implemented in DeckViewCardDragItem::handleDrop

@ZeldaZach
Copy link
Member Author

So the current WIP has some issues still, but it's a step in the right direction.

  • Cards move on double click now to an opposite zone. Issue with this is if I move a card from main to side, then if I click on any copy of that card in either it will force it to the side and cannot be returned to main.
  • When this move happens, the server isn't updated with the settings and the deck, when you start the game, still shows you as the 60 card main deck (even if you made changes)

@ZeldaZach ZeldaZach requested a review from ctrlaltca April 20, 2017 19:55
@tooomm
Copy link
Contributor
tooomm commented Apr 20, 2017

Oh wow, codacy even does reviews of open pr's with comments and info!? sweeet

@ZeldaZach
Copy link
Member Author

Any further help @ctrlaltca @Daenyth ?

{
QList<MoveCard_ToZone> newPlan = *input;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should check if input is null before dereferencing the pointer

8000
@@ -95,6 +94,9 @@ class DeckViewScene : public QGraphicsScene {
void updateContents();
QList<MoveCard_ToZone> getSideboardPlan() const;
void resetSideboardPlan();
QMap<QString, DeckViewCardContainer *> getCardContainers() { return cardContainers; };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused, remove?

public:
DeckViewCardDragItem(DeckViewCard *_item, const QPointF &_hotSpot, AbstractCardDragItem *parentDrag = 0);
void updatePosition(const QPointF &cursorScenePos);
void handleDrop(DeckViewCardContainer *target);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is making this method public this really needed?

@@ -462,7 +494,8 @@ DeckView::DeckView(QWidget *parent)

connect(deckViewScene, SIGNAL(sceneRectChanged(const QRectF &)), this, SLOT(updateSceneRect(const QRectF &)));
connect(deckViewScene, SIGNAL(newCardAdded(AbstractCardItem *)), this, SIGNAL(newCardAdded(AbstractCardItem *)));
connect(deckViewScene, SIGNAL(sideboardPlanChanged()), this, SIGNAL(sideboardPlanChanged()));
connect(deckViewScene, SIGNAL(sideboardPlanChanged(QList<MoveCard_ToZone>*)), this, SIGNAL(sideboardPlanChanged(QList<MoveCard_ToZone>*)));
connect(this, SIGNAL(sideboardPlanChanged(QList<MoveCard_ToZone>*)), this, SIGNAL(sideboardPlanChanged(QObject *)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method signature seems incorrect:
QObject::connect: No such signal DeckView::sideboardPlanChanged(QObject *)

m.set_card_name(c->getName().toStdString());
m.set_start_zone(c->getOriginZone().toStdString());

if (c->getOriginZone() == "main")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main problem now is that you are using getOriginZone() to determine where a card actually is and where it should move to, but the "original zone" is never updated, so if you move a card from "main" to "side" its original zone will still be "main"; double clicking it again will try to move it again from the main to the side.
You don't want to che the card "original zone", but its "current zone" instead; you should be able to get this information from the card's parentItem()

@ZeldaZach ZeldaZach changed the title [WIP] change cards from sb<->mb with double-click Change cards from sb<->mb with double-click Apr 25, 2017
@ZeldaZach
Copy link
Member Author

This PR is ready to be reviewed.

@ZeldaZach ZeldaZach requested review from ctrlaltca and tooomm April 25, 2017 05:53
Copy link
Contributor
@tooomm tooomm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can switch cards around with double click with no issues in a local game.

No idea of the underlying things and the changes to the deck on the server...

@ZeldaZach
Copy link
Member Author

@tooomm I fixed it to work server-side too

Copy link
Contributor
@ctrlaltca ctrlaltca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks fine and works nicely 👍

@ZeldaZach ZeldaZach merged commit 62d8f5a into Cockatrice:master Apr 25, 2017
@ZeldaZach ZeldaZach deleted the click_to_move branch April 25, 2017 18:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0