[Client] Handle input from server-sent custom messageboxes less hackily

pull/593/head
David Cernat 5 years ago
parent eb1641dd86
commit 58d8367cb0

@ -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;
virtual void interactiveMessageBox (const std::string& message,
const std::vector<std::string>& buttons = std::vector<std::string>(), bool block=false) = 0;
/// returns the index of the pressed button or -1 if no button was pressed (->MessageBoxmanager->InteractiveMessageBox)
virtual int readPressedButton() = 0;
/*
Start of tes3mp addition
Start of tes3mp change (major)
Allow the reading of a pressed button without resetting it
Add a hasServerOrigin boolean to the list of arguments so those messageboxes
can be differentiated from client-only ones
*/
virtual int readPressedButton(bool reset) = 0;
virtual void interactiveMessageBox (const std::string& message,
const std::vector<std::string>& buttons = std::vector<std::string>(), bool block=false, bool hasServerOrigin=false) = 0;
/*
End of tes3mp addition
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;
virtual void update (float duration) = 0;
/**

@ -8,6 +8,18 @@
#include <components/debug/debuglog.hpp>
#include <components/misc/stringops.hpp>
/*
Start of tes3mp addition
Include additional headers for multiplayer purposes
*/
#include <components/openmw-mp/TimedLog.hpp>
#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<std::string>& 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<std::string>& 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;

@ -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<std::string>& 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<std::string>& 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);

@ -728,9 +728,20 @@ namespace MWGui
popGuiMode();
}
void WindowManager::interactiveMessageBox(const std::string &message, const std::vector<std::string> &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<std::string> &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<ESM::GameSetting>().search(id);

@ -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();
virtual void interactiveMessageBox (const std::string& message,
const std::vector<std::string>& buttons = std::vector<std::string>(), bool block=false);
virtual int readPressedButton (); ///< returns the index of the pressed button or -1 if no button was pressed (->MessageBoxmanager->InteractiveMessageBox)
/*
Start of tes3mp addition
Start of tes3mp change (major)
Allow the reading of a pressed button without resetting it
Add a hasServerOrigin boolean to the list of arguments so those messageboxes
can be differentiated from client-only ones
*/
virtual int readPressedButton(bool reset);
virtual void interactiveMessageBox (const std::string& message,
const std::vector<std::string>& buttons = std::vector<std::string>(), bool block=false, bool hasServerOrigin=false);
/*
End of tes3mp addition
End of tes3mp change (major)
*/
virtual int readPressedButton (); ///< returns the index of the pressed button or -1 if no button was pressed (->MessageBoxmanager->InteractiveMessageBox)
virtual void update (float duration);
/**

@ -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<std::string> 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<std::string> 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);
if (pressedButton != -1 && calledInteractiveMessage)
{
LOG_MESSAGE_SIMPLE(TimedLog::LOG_VERBOSE, "Pressed: %d", pressedButton);
calledInteractiveMessage = false;
void mwmp::GUIController::processCustomMessageBoxInput(int pressedButton)
{
LOG_MESSAGE_SIMPLE(TimedLog::LOG_VERBOSE, "Pressed: %d", pressedButton);
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)

@ -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);

Loading…
Cancel
Save