From 58d8367cb06eeb5c7c29fa8ac765792115ed5dac Mon Sep 17 00:00:00 2001 From: David Cernat Date: Sat, 18 Jul 2020 01:36:13 +0200 Subject: [PATCH] [Client] Handle input from server-sent custom messageboxes less hackily --- apps/openmw/mwbase/windowmanager.hpp | 21 ++++++------ apps/openmw/mwgui/messagebox.cpp | 44 +++++++++++++++++++++++++- apps/openmw/mwgui/messagebox.hpp | 21 +++++++++++- apps/openmw/mwgui/windowmanagerimp.cpp | 28 ++++++++-------- apps/openmw/mwgui/windowmanagerimp.hpp | 21 ++++++------ apps/openmw/mwmp/GUIController.cpp | 29 +++++++---------- apps/openmw/mwmp/GUIController.hpp | 3 +- 7 files changed, 109 insertions(+), 58 deletions(-) diff --git a/apps/openmw/mwbase/windowmanager.hpp b/apps/openmw/mwbase/windowmanager.hpp index 76de088a6..19d3b9328 100644 --- a/apps/openmw/mwbase/windowmanager.hpp +++ b/apps/openmw/mwbase/windowmanager.hpp @@ -295,22 +295,21 @@ namespace MWBase virtual void messageBox (const std::string& message, enum MWGui::ShowInDialogueMode showInDialogueMode = MWGui::ShowInDialogueMode_IfPossible) = 0; virtual void staticMessageBox(const std::string& message) = 0; virtual void removeStaticMessageBox() = 0; + /* + Start of tes3mp change (major) + + Add a hasServerOrigin boolean to the list of arguments so those messageboxes + can be differentiated from client-only ones + */ virtual void interactiveMessageBox (const std::string& message, - const std::vector& buttons = std::vector(), bool block=false) = 0; + const std::vector& buttons = std::vector(), bool block=false, bool hasServerOrigin=false) = 0; + /* + End of tes3mp change (major) + */ /// returns the index of the pressed button or -1 if no button was pressed (->MessageBoxmanager->InteractiveMessageBox) virtual int readPressedButton() = 0; - /* - Start of tes3mp addition - - Allow the reading of a pressed button without resetting it - */ - virtual int readPressedButton(bool reset) = 0; - /* - End of tes3mp addition - */ - virtual void update (float duration) = 0; /** diff --git a/apps/openmw/mwgui/messagebox.cpp b/apps/openmw/mwgui/messagebox.cpp index d64ec9c37..6198ecff5 100644 --- a/apps/openmw/mwgui/messagebox.cpp +++ b/apps/openmw/mwgui/messagebox.cpp @@ -8,6 +8,18 @@ #include #include +/* + Start of tes3mp addition + + Include additional headers for multiplayer purposes +*/ +#include +#include "../mwmp/Main.hpp" +#include "../mwmp/GUIController.hpp" +/* + End of tes3mp addition +*/ + #include "../mwbase/environment.hpp" #include "../mwbase/soundmanager.hpp" #include "../mwbase/inputmanager.hpp" @@ -86,6 +98,18 @@ namespace MWGui if(mInterMessageBoxe != nullptr && mInterMessageBoxe->mMarkedToDelete) { mLastButtonPressed = mInterMessageBoxe->readPressedButton(); + + /* + Start of tes3mp addition + + If this message box was created by the server, send the input back to it + */ + if (mInterMessageBoxe->mHasServerOrigin) + mwmp::Main::get().getGUIController()->processCustomMessageBoxInput(mLastButtonPressed); + /* + End of tes3mp addition + */ + mInterMessageBoxe->setVisible(false); delete mInterMessageBoxe; mInterMessageBoxe = nullptr; @@ -125,7 +149,16 @@ namespace MWGui mStaticMessageBox = nullptr; } - bool MessageBoxManager::createInteractiveMessageBox (const std::string& message, const std::vector& buttons) + /* + Start of tes3mp change (major) + + Add a hasServerOrigin boolean to the list of arguments so those messageboxes + can be differentiated from client-only ones + */ + bool MessageBoxManager::createInteractiveMessageBox (const std::string& message, const std::vector& buttons, bool hasServerOrigin) + /* + End of tes3mp change (major) + */ { if (mInterMessageBoxe != nullptr) { @@ -136,6 +169,15 @@ namespace MWGui } mInterMessageBoxe = new InteractiveMessageBox(*this, message, buttons); + /* + Start of tes3mp addition + + Track whether the message box has a server origin + */ + mInterMessageBoxe->mHasServerOrigin = hasServerOrigin; + /* + End of tes3mp addition + */ mLastButtonPressed = -1; return true; diff --git a/apps/openmw/mwgui/messagebox.hpp b/apps/openmw/mwgui/messagebox.hpp index e4e4b743c..f6f14e55d 100644 --- a/apps/openmw/mwgui/messagebox.hpp +++ b/apps/openmw/mwgui/messagebox.hpp @@ -25,7 +25,16 @@ namespace MWGui void onFrame (float frameDuration); void createMessageBox (const std::string& message, bool stat = false); void removeStaticMessageBox (); - bool createInteractiveMessageBox (const std::string& message, const std::vector& buttons); + /* + Start of tes3mp change (major) + + Add a hasServerOrigin boolean to the list of arguments so those messageboxes + can be differentiated from client-only ones + */ + bool createInteractiveMessageBox (const std::string& message, const std::vector& buttons, bool hasServerOrigin = false); + /* + End of tes3mp change (major) + */ bool isInteractiveMessageBox (); int getMessagesCount(); @@ -87,6 +96,16 @@ namespace MWGui bool mMarkedToDelete; + /* + Start of tes3mp addition + + Track whether the message box has a server origin + */ + bool mHasServerOrigin = false; + /* + End of tes3mp addition + */ + private: void buttonActivated (MyGUI::Widget* _widget); diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp index 926376e10..307ec6b08 100644 --- a/apps/openmw/mwgui/windowmanagerimp.cpp +++ b/apps/openmw/mwgui/windowmanagerimp.cpp @@ -728,9 +728,20 @@ namespace MWGui popGuiMode(); } - void WindowManager::interactiveMessageBox(const std::string &message, const std::vector &buttons, bool block) + /* + Start of tes3mp change (major) + + Add a hasServerOrigin boolean to the list of arguments so those messageboxes + can be differentiated from client-only ones + + Use the hasServerOrigin argument when creating an interactive message box + */ + void WindowManager::interactiveMessageBox(const std::string &message, const std::vector &buttons, bool block, bool hasServerOrigin) { - mMessageBoxManager->createInteractiveMessageBox(message, buttons); + mMessageBoxManager->createInteractiveMessageBox(message, buttons, hasServerOrigin); + /* + End of tes3mp change (major) + */ updateVisible(); if (block) @@ -788,19 +799,6 @@ namespace MWGui return mMessageBoxManager->readPressedButton(); } - /* - Start of tes3mp addition - - Allow the reading of a pressed button without resetting it - */ - int WindowManager::readPressedButton(bool reset) - { - return mMessageBoxManager->readPressedButton(reset); - } - /* - End of tes3mp addition - */ - std::string WindowManager::getGameSettingString(const std::string &id, const std::string &default_) { const ESM::GameSetting *setting = mStore->get().search(id); diff --git a/apps/openmw/mwgui/windowmanagerimp.hpp b/apps/openmw/mwgui/windowmanagerimp.hpp index ebb55187e..7787078db 100644 --- a/apps/openmw/mwgui/windowmanagerimp.hpp +++ b/apps/openmw/mwgui/windowmanagerimp.hpp @@ -329,21 +329,20 @@ namespace MWGui virtual void messageBox (const std::string& message, enum MWGui::ShowInDialogueMode showInDialogueMode = MWGui::ShowInDialogueMode_IfPossible); virtual void staticMessageBox(const std::string& message); virtual void removeStaticMessageBox(); + /* + Start of tes3mp change (major) + + Add a hasServerOrigin boolean to the list of arguments so those messageboxes + can be differentiated from client-only ones + */ virtual void interactiveMessageBox (const std::string& message, - const std::vector& buttons = std::vector(), bool block=false); + const std::vector& buttons = std::vector(), bool block=false, bool hasServerOrigin=false); + /* + End of tes3mp change (major) + */ virtual int readPressedButton (); ///< returns the index of the pressed button or -1 if no button was pressed (->MessageBoxmanager->InteractiveMessageBox) - /* - Start of tes3mp addition - - Allow the reading of a pressed button without resetting it - */ - virtual int readPressedButton(bool reset); - /* - End of tes3mp addition - */ - virtual void update (float duration); /** diff --git a/apps/openmw/mwmp/GUIController.cpp b/apps/openmw/mwmp/GUIController.cpp index 341487f36..80123b513 100644 --- a/apps/openmw/mwmp/GUIController.cpp +++ b/apps/openmw/mwmp/GUIController.cpp @@ -41,7 +41,6 @@ mwmp::GUIController::GUIController(): mInputBox(0), mListBox(0) mChat = nullptr; keySay = SDL_SCANCODE_Y; keyChatMode = SDL_SCANCODE_F2; - calledInteractiveMessage = false; } mwmp::GUIController::~GUIController() @@ -145,10 +144,9 @@ std::vector splitString(const std::string &str, char delim = ';') void mwmp::GUIController::showCustomMessageBox(const BasePlayer::GUIMessageBox &guiMessageBox) { - MWBase::WindowManager *windowManager = MWBase::Environment::get().getWindowManager(); + MWBase::WindowManager* windowManager = MWBase::Environment::get().getWindowManager(); std::vector buttons = splitString(guiMessageBox.buttons); - windowManager->interactiveMessageBox(guiMessageBox.label, buttons); - calledInteractiveMessage = true; + windowManager->interactiveMessageBox(guiMessageBox.label, buttons, false, true); } void mwmp::GUIController::showInputBox(const BasePlayer::GUIMessageBox &guiMessageBox) @@ -222,23 +220,18 @@ void mwmp::GUIController::update(float dt) { if (mChat != nullptr) mChat->update(dt); +} - // Make sure we read the pressed button without resetting it, because it may also get - // checked somewhere else - int pressedButton = MWBase::Environment::get().getWindowManager()->readPressedButton(false); +void mwmp::GUIController::processCustomMessageBoxInput(int pressedButton) +{ + LOG_MESSAGE_SIMPLE(TimedLog::LOG_VERBOSE, "Pressed: %d", pressedButton); - if (pressedButton != -1 && calledInteractiveMessage) - { - LOG_MESSAGE_SIMPLE(TimedLog::LOG_VERBOSE, "Pressed: %d", pressedButton); - calledInteractiveMessage = false; + LocalPlayer* localPlayer = Main::get().getLocalPlayer(); + localPlayer->guiMessageBox.data = MyGUI::utility::toString(pressedButton); - LocalPlayer *localPlayer = Main::get().getLocalPlayer(); - localPlayer->guiMessageBox.data = MyGUI::utility::toString(pressedButton); - - PlayerPacket *playerPacket = Main::get().getNetworking()->getPlayerPacket(ID_GUI_MESSAGEBOX); - playerPacket->setPlayer(Main::get().getLocalPlayer()); - playerPacket->Send(); - } + PlayerPacket* playerPacket = Main::get().getNetworking()->getPlayerPacket(ID_GUI_MESSAGEBOX); + playerPacket->setPlayer(Main::get().getLocalPlayer()); + playerPacket->Send(); } void mwmp::GUIController::WM_UpdateVisible(MWGui::GuiMode mode) diff --git a/apps/openmw/mwmp/GUIController.hpp b/apps/openmw/mwmp/GUIController.hpp index 27fdf519e..ccd55bb1e 100644 --- a/apps/openmw/mwmp/GUIController.hpp +++ b/apps/openmw/mwmp/GUIController.hpp @@ -52,6 +52,8 @@ namespace mwmp void update(float dt); + void processCustomMessageBoxInput(int pressedButton); + void WM_UpdateVisible(MWGui::GuiMode mode); void updatePlayersMarkers(MWGui::LocalMapBase *localMapBase); @@ -68,7 +70,6 @@ namespace mwmp int keyChatMode; long id; - bool calledInteractiveMessage; TextInputDialog *mInputBox; GUIDialogList *mListBox; void onInputBoxDone(MWGui::WindowBase* parWindow);