mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-03-30 07:06:43 +00:00
[Client] Handle input from server-sent custom messageboxes less hackily
This commit is contained in:
parent
eb1641dd86
commit
58d8367cb0
7 changed files with 109 additions and 58 deletions
|
@ -295,22 +295,21 @@ namespace MWBase
|
||||||
virtual void messageBox (const std::string& message, enum MWGui::ShowInDialogueMode showInDialogueMode = MWGui::ShowInDialogueMode_IfPossible) = 0;
|
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 staticMessageBox(const std::string& message) = 0;
|
||||||
virtual void removeStaticMessageBox() = 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,
|
virtual void interactiveMessageBox (const std::string& message,
|
||||||
const std::vector<std::string>& buttons = std::vector<std::string>(), bool block=false) = 0;
|
const std::vector<std::string>& buttons = std::vector<std::string>(), 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)
|
/// returns the index of the pressed button or -1 if no button was pressed (->MessageBoxmanager->InteractiveMessageBox)
|
||||||
virtual int readPressedButton() = 0;
|
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;
|
virtual void update (float duration) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -8,6 +8,18 @@
|
||||||
#include <components/debug/debuglog.hpp>
|
#include <components/debug/debuglog.hpp>
|
||||||
#include <components/misc/stringops.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/environment.hpp"
|
||||||
#include "../mwbase/soundmanager.hpp"
|
#include "../mwbase/soundmanager.hpp"
|
||||||
#include "../mwbase/inputmanager.hpp"
|
#include "../mwbase/inputmanager.hpp"
|
||||||
|
@ -86,6 +98,18 @@ namespace MWGui
|
||||||
|
|
||||||
if(mInterMessageBoxe != nullptr && mInterMessageBoxe->mMarkedToDelete) {
|
if(mInterMessageBoxe != nullptr && mInterMessageBoxe->mMarkedToDelete) {
|
||||||
mLastButtonPressed = mInterMessageBoxe->readPressedButton();
|
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);
|
mInterMessageBoxe->setVisible(false);
|
||||||
delete mInterMessageBoxe;
|
delete mInterMessageBoxe;
|
||||||
mInterMessageBoxe = nullptr;
|
mInterMessageBoxe = nullptr;
|
||||||
|
@ -125,7 +149,16 @@ namespace MWGui
|
||||||
mStaticMessageBox = nullptr;
|
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)
|
if (mInterMessageBoxe != nullptr)
|
||||||
{
|
{
|
||||||
|
@ -136,6 +169,15 @@ namespace MWGui
|
||||||
}
|
}
|
||||||
|
|
||||||
mInterMessageBoxe = new InteractiveMessageBox(*this, message, buttons);
|
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;
|
mLastButtonPressed = -1;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -25,7 +25,16 @@ namespace MWGui
|
||||||
void onFrame (float frameDuration);
|
void onFrame (float frameDuration);
|
||||||
void createMessageBox (const std::string& message, bool stat = false);
|
void createMessageBox (const std::string& message, bool stat = false);
|
||||||
void removeStaticMessageBox ();
|
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 ();
|
bool isInteractiveMessageBox ();
|
||||||
|
|
||||||
int getMessagesCount();
|
int getMessagesCount();
|
||||||
|
@ -87,6 +96,16 @@ namespace MWGui
|
||||||
|
|
||||||
bool mMarkedToDelete;
|
bool mMarkedToDelete;
|
||||||
|
|
||||||
|
/*
|
||||||
|
Start of tes3mp addition
|
||||||
|
|
||||||
|
Track whether the message box has a server origin
|
||||||
|
*/
|
||||||
|
bool mHasServerOrigin = false;
|
||||||
|
/*
|
||||||
|
End of tes3mp addition
|
||||||
|
*/
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void buttonActivated (MyGUI::Widget* _widget);
|
void buttonActivated (MyGUI::Widget* _widget);
|
||||||
|
|
||||||
|
|
|
@ -728,9 +728,20 @@ namespace MWGui
|
||||||
popGuiMode();
|
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();
|
updateVisible();
|
||||||
|
|
||||||
if (block)
|
if (block)
|
||||||
|
@ -788,19 +799,6 @@ namespace MWGui
|
||||||
return mMessageBoxManager->readPressedButton();
|
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_)
|
std::string WindowManager::getGameSettingString(const std::string &id, const std::string &default_)
|
||||||
{
|
{
|
||||||
const ESM::GameSetting *setting = mStore->get<ESM::GameSetting>().search(id);
|
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 messageBox (const std::string& message, enum MWGui::ShowInDialogueMode showInDialogueMode = MWGui::ShowInDialogueMode_IfPossible);
|
||||||
virtual void staticMessageBox(const std::string& message);
|
virtual void staticMessageBox(const std::string& message);
|
||||||
virtual void removeStaticMessageBox();
|
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,
|
virtual void interactiveMessageBox (const std::string& message,
|
||||||
const std::vector<std::string>& buttons = std::vector<std::string>(), bool block=false);
|
const std::vector<std::string>& buttons = std::vector<std::string>(), 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)
|
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);
|
virtual void update (float duration);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -41,7 +41,6 @@ mwmp::GUIController::GUIController(): mInputBox(0), mListBox(0)
|
||||||
mChat = nullptr;
|
mChat = nullptr;
|
||||||
keySay = SDL_SCANCODE_Y;
|
keySay = SDL_SCANCODE_Y;
|
||||||
keyChatMode = SDL_SCANCODE_F2;
|
keyChatMode = SDL_SCANCODE_F2;
|
||||||
calledInteractiveMessage = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mwmp::GUIController::~GUIController()
|
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)
|
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);
|
std::vector<std::string> buttons = splitString(guiMessageBox.buttons);
|
||||||
windowManager->interactiveMessageBox(guiMessageBox.label, buttons);
|
windowManager->interactiveMessageBox(guiMessageBox.label, buttons, false, true);
|
||||||
calledInteractiveMessage = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void mwmp::GUIController::showInputBox(const BasePlayer::GUIMessageBox &guiMessageBox)
|
void mwmp::GUIController::showInputBox(const BasePlayer::GUIMessageBox &guiMessageBox)
|
||||||
|
@ -222,23 +220,18 @@ void mwmp::GUIController::update(float dt)
|
||||||
{
|
{
|
||||||
if (mChat != nullptr)
|
if (mChat != nullptr)
|
||||||
mChat->update(dt);
|
mChat->update(dt);
|
||||||
|
}
|
||||||
|
|
||||||
// Make sure we read the pressed button without resetting it, because it may also get
|
void mwmp::GUIController::processCustomMessageBoxInput(int pressedButton)
|
||||||
// checked somewhere else
|
{
|
||||||
int pressedButton = MWBase::Environment::get().getWindowManager()->readPressedButton(false);
|
LOG_MESSAGE_SIMPLE(TimedLog::LOG_VERBOSE, "Pressed: %d", pressedButton);
|
||||||
|
|
||||||
if (pressedButton != -1 && calledInteractiveMessage)
|
LocalPlayer* localPlayer = Main::get().getLocalPlayer();
|
||||||
{
|
localPlayer->guiMessageBox.data = MyGUI::utility::toString(pressedButton);
|
||||||
LOG_MESSAGE_SIMPLE(TimedLog::LOG_VERBOSE, "Pressed: %d", pressedButton);
|
|
||||||
calledInteractiveMessage = false;
|
|
||||||
|
|
||||||
LocalPlayer *localPlayer = Main::get().getLocalPlayer();
|
PlayerPacket* playerPacket = Main::get().getNetworking()->getPlayerPacket(ID_GUI_MESSAGEBOX);
|
||||||
localPlayer->guiMessageBox.data = MyGUI::utility::toString(pressedButton);
|
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)
|
void mwmp::GUIController::WM_UpdateVisible(MWGui::GuiMode mode)
|
||||||
|
|
|
@ -52,6 +52,8 @@ namespace mwmp
|
||||||
|
|
||||||
void update(float dt);
|
void update(float dt);
|
||||||
|
|
||||||
|
void processCustomMessageBoxInput(int pressedButton);
|
||||||
|
|
||||||
void WM_UpdateVisible(MWGui::GuiMode mode);
|
void WM_UpdateVisible(MWGui::GuiMode mode);
|
||||||
|
|
||||||
void updatePlayersMarkers(MWGui::LocalMapBase *localMapBase);
|
void updatePlayersMarkers(MWGui::LocalMapBase *localMapBase);
|
||||||
|
@ -68,7 +70,6 @@ namespace mwmp
|
||||||
int keyChatMode;
|
int keyChatMode;
|
||||||
|
|
||||||
long id;
|
long id;
|
||||||
bool calledInteractiveMessage;
|
|
||||||
TextInputDialog *mInputBox;
|
TextInputDialog *mInputBox;
|
||||||
GUIDialogList *mListBox;
|
GUIDialogList *mListBox;
|
||||||
void onInputBoxDone(MWGui::WindowBase* parWindow);
|
void onInputBoxDone(MWGui::WindowBase* parWindow);
|
||||||
|
|
Loading…
Reference in a new issue