From 2cedcbb93b857a7372f436d3985ae517554e3f19 Mon Sep 17 00:00:00 2001 From: Mercury233 Date: Sun, 2 May 2021 18:00:08 +0800 Subject: [PATCH] fix card showing popup menu may be inaccurate (#2342) --- gframe/client_field.cpp | 2 ++ gframe/client_field.h | 1 + gframe/event_handler.cpp | 33 ++++++++++++++++++--------------- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/gframe/client_field.cpp b/gframe/client_field.cpp index 647abc5dd..3ecb2bcfc 100644 --- a/gframe/client_field.cpp +++ b/gframe/client_field.cpp @@ -15,6 +15,7 @@ ClientField::ClientField() { hovered_card = 0; clicked_card = 0; highlighting_card = 0; + menu_card = 0; hovered_controler = 0; hovered_location = 0; hovered_sequence = 0; @@ -83,6 +84,7 @@ void ClientField::Clear() { hovered_card = 0; clicked_card = 0; highlighting_card = 0; + menu_card = 0; hovered_controler = 0; hovered_location = 0; hovered_sequence = 0; diff --git a/gframe/client_field.h b/gframe/client_field.h index 49f01fdb0..350c898c7 100644 --- a/gframe/client_field.h +++ b/gframe/client_field.h @@ -132,6 +132,7 @@ class ClientField: public irr::IEventReceiver { ClientCard* clicked_card; ClientCard* command_card; ClientCard* highlighting_card; + ClientCard* menu_card; int list_command; virtual bool OnEvent(const irr::SEvent& event); diff --git a/gframe/event_handler.cpp b/gframe/event_handler.cpp index c3b5f5fa5..45b558ed1 100644 --- a/gframe/event_handler.cpp +++ b/gframe/event_handler.cpp @@ -366,10 +366,12 @@ bool ClientField::OnEvent(const irr::SEvent& event) { mainGame->wCmdMenu->setVisible(false); ShowCancelOrFinishButton(0); if(!list_command) { + if(!menu_card) + break; select_options.clear(); select_options_index.clear(); for (size_t i = 0; i < activatable_cards.size(); ++i) { - if (activatable_cards[i] == clicked_card) { + if (activatable_cards[i] == menu_card) { if(activatable_descs[i].second == EDESC_OPERATION) continue; else if(activatable_descs[i].second == EDESC_RESET) { @@ -392,7 +394,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) { } DuelClient::SendResponse(); } else { - command_card = clicked_card; + command_card = menu_card; ShowSelectOption(); select_ready = false; ShowCancelOrFinishButton(1); @@ -448,10 +450,10 @@ bool ClientField::OnEvent(const irr::SEvent& event) { } case BUTTON_CMD_SUMMON: { mainGame->wCmdMenu->setVisible(false); - if(!clicked_card) + if(!menu_card) break; for(size_t i = 0; i < summonable_cards.size(); ++i) { - if(summonable_cards[i] == clicked_card) { + if(summonable_cards[i] == menu_card) { ClearCommandFlag(); DuelClient::SetResponseI(i << 16); DuelClient::SendResponse(); @@ -463,10 +465,10 @@ bool ClientField::OnEvent(const irr::SEvent& event) { case BUTTON_CMD_SPSUMMON: { mainGame->wCmdMenu->setVisible(false); if(!list_command) { - if(!clicked_card) + if(!menu_card) break; for(size_t i = 0; i < spsummonable_cards.size(); ++i) { - if(spsummonable_cards[i] == clicked_card) { + if(spsummonable_cards[i] == menu_card) { ClearCommandFlag(); DuelClient::SetResponseI((i << 16) + 1); DuelClient::SendResponse(); @@ -505,10 +507,10 @@ bool ClientField::OnEvent(const irr::SEvent& event) { } case BUTTON_CMD_MSET: { mainGame->wCmdMenu->setVisible(false); - if(!clicked_card) + if(!menu_card) break; for(size_t i = 0; i < msetable_cards.size(); ++i) { - if(msetable_cards[i] == clicked_card) { + if(msetable_cards[i] == menu_card) { DuelClient::SetResponseI((i << 16) + 3); DuelClient::SendResponse(); break; @@ -518,10 +520,10 @@ bool ClientField::OnEvent(const irr::SEvent& event) { } case BUTTON_CMD_SSET: { mainGame->wCmdMenu->setVisible(false); - if(!clicked_card) + if(!menu_card) break; for(size_t i = 0; i < ssetable_cards.size(); ++i) { - if(ssetable_cards[i] == clicked_card) { + if(ssetable_cards[i] == menu_card) { DuelClient::SetResponseI((i << 16) + 4); DuelClient::SendResponse(); break; @@ -531,10 +533,10 @@ bool ClientField::OnEvent(const irr::SEvent& event) { } case BUTTON_CMD_REPOS: { mainGame->wCmdMenu->setVisible(false); - if(!clicked_card) + if(!menu_card) break; for(size_t i = 0; i < reposable_cards.size(); ++i) { - if(reposable_cards[i] == clicked_card) { + if(reposable_cards[i] == menu_card) { DuelClient::SetResponseI((i << 16) + 2); DuelClient::SendResponse(); break; @@ -544,10 +546,10 @@ bool ClientField::OnEvent(const irr::SEvent& event) { } case BUTTON_CMD_ATTACK: { mainGame->wCmdMenu->setVisible(false); - if(!clicked_card) + if(!menu_card) break; for(size_t i = 0; i < attackable_cards.size(); ++i) { - if(attackable_cards[i] == clicked_card) { + if(attackable_cards[i] == menu_card) { DuelClient::SetResponseI((i << 16) + 1); DuelClient::SendResponse(); break; @@ -1560,7 +1562,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) { SetShowMark(hovered_card, false); } if(mcard) { - if(mcard != clicked_card) + if(mcard != menu_card) mainGame->wCmdMenu->setVisible(false); if(hovered_location == LOCATION_HAND) { mcard->is_hovered = true; @@ -2249,6 +2251,7 @@ void ClientField::ShowMenu(int flag, int x, int y) { mainGame->wCmdMenu->setVisible(false); return; } + menu_card = clicked_card; int height = 1; int offset = mainGame->gameConf.resize_popup_menu ? ((mainGame->yScale >= 0.666) ? 21 * mainGame->yScale : 14) : 21; if(flag & COMMAND_ACTIVATE) {