-
-
Notifications
You must be signed in to change notification settings - Fork 474
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
Conversation
cockatrice/src/deckview.cpp
Outdated
@@ -1,5 +1,6 @@ | |||
#include <QApplication> | |||
#include <QGraphicsSceneMouseEvent> | |||
#include <QDebug> |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
cockatrice/src/deckview.cpp
Outdated
m.set_card_name(c->getName().toStdString()); | ||
m.set_start_zone(c->getOriginZone().toStdString()); | ||
|
||
if (c->getOriginZone() == "main") |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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()
cockatrice/src/deckview.cpp
Outdated
if (event->button() == Qt::LeftButton) | ||
{ | ||
qDebug() << "LEFT"; | ||
QList<MoveCard_ToZone> *result = new QList<MoveCard_ToZone>(); |
There was a problem hiding this comment.
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
cockatrice/src/deckview.cpp
Outdated
@@ -1,5 +1,6 @@ | |||
#include <QApplication> | |||
#include <QGraphicsSceneMouseEvent> | |||
#include <QDebug> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add an #include <QMouseEvent>
, should fix compilation:
https://travis-ci.org/Cockatrice/Cockatrice/jobs/223830200#L1507
https://ci.appveyor.com/project/Daenyth/cockatrice-8k7y5/build/0.0.1-branch-master-build-809/job/2p5nwyxxn0l0jq7l#L3374
cockatrice/src/tab_game.cpp
Outdated
@@ -274,13 +275,26 @@ void DeckViewContainer::sideboardLockButtonClicked() | |||
|
|||
void DeckViewContainer::sideboardPlanChanged() |
There was a problem hiding this comment.
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.
cockatrice/src/tab_game.cpp
Outdated
cmd.add_move_list()->CopyFrom(newPlan->at(i)); | ||
parentGame->sendGameCommand(cmd, playerId); | ||
|
||
// TODO: Need to figure out how to re-paint the deck view |
There was a problem hiding this comment.
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
So the current WIP has some issues still, but it's a step in the right direction.
|
Oh wow, codacy even does reviews of open pr's with comments and info!? sweeet |
Any further help @ctrlaltca @Daenyth ? |
cockatrice/src/tab_game.cpp
Outdated
{ | ||
QList<MoveCard_ToZone> newPlan = *input; |
There was a problem hiding this comment.
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
cockatrice/src/deckview.h
Outdated
@@ -95,6 +94,9 @@ class DeckViewScene : public QGraphicsScene { | |||
void updateContents(); | |||
QList<MoveCard_ToZone> getSideboardPlan() const; | |||
void resetSideboardPlan(); | |||
QMap<QString, DeckViewCardContainer *> getCardContainers() { return cardContainers; }; | 8000
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused, remove?
cockatrice/src/deckview.h
Outdated
public: | ||
DeckViewCardDragItem(DeckViewCard *_item, const QPointF &_hotSpot, AbstractCardDragItem *parentDrag = 0); | ||
void updatePosition(const QPointF &cursorScenePos); | ||
void handleDrop(DeckViewCardContainer *target); |
There was a problem hiding this comment.
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?
cockatrice/src/deckview.cpp
Outdated
@@ -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 *))); |
There was a problem hiding this comment.
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 *)
cockatrice/src/deckview.cpp
Outdated
m.set_card_name(c->getName().toStdString()); | ||
m.set_start_zone(c->getOriginZone().toStdString()); | ||
|
||
if (c->getOriginZone() == "main") |
There was a problem hiding this comment.
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()
This PR is ready to be reviewed. |
There was a problem hiding this 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...
@tooomm I fixed it to work server-side too |
There was a problem hiding this 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 👍
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.