diff --git a/apps/openmw-mp/Script/Functions/GUI.cpp b/apps/openmw-mp/Script/Functions/GUI.cpp index 3e7146ede..c1c3bc903 100644 --- a/apps/openmw-mp/Script/Functions/GUI.cpp +++ b/apps/openmw-mp/Script/Functions/GUI.cpp @@ -46,6 +46,19 @@ void GUIFunctions::InputDialog(unsigned short pid, int id, const char *label) no mwmp::Networking::Get().GetPlayerController()->GetPacket(ID_GUI_MESSAGEBOX)->Send(player, false); } +void GUIFunctions::ListBox(unsigned short pid, int id, const char *label, const char *items) +{ + Player *player; + GET_PLAYER(pid, player,); + + player->guiMessageBox.id = id; + player->guiMessageBox.label = label; + player->guiMessageBox.data = items; + player->guiMessageBox.type = Player::GUIMessageBox::ListBox; + + mwmp::Networking::Get().GetPlayerController()->GetPacket(ID_GUI_MESSAGEBOX)->Send(player, false); +} + void GUIFunctions::SetMapVisibility(unsigned short targetPID, unsigned short affectedPID, unsigned short state) noexcept { LOG_MESSAGE(Log::LOG_WARN, "%s", "stub"); diff --git a/apps/openmw-mp/Script/Functions/GUI.hpp b/apps/openmw-mp/Script/Functions/GUI.hpp index e5caba1ca..845623cba 100644 --- a/apps/openmw-mp/Script/Functions/GUI.hpp +++ b/apps/openmw-mp/Script/Functions/GUI.hpp @@ -9,6 +9,7 @@ {"MessageBox", GUIFunctions::_MessageBox},\ {"CustomMessageBox", GUIFunctions::CustomMessageBox},\ {"InputDialog", GUIFunctions::InputDialog},\ + {"ListBox", GUIFunctions::ListBox},\ {"SetMapVisibility", GUIFunctions::SetMapVisibility},\ {"SetMapVisibilityAll", GUIFunctions::SetMapVisibilityAll}\ @@ -21,6 +22,8 @@ public: static void CustomMessageBox(unsigned short pid, int id, const char *label, const char *buttons) noexcept; static void InputDialog(unsigned short pid, int id, const char *label) noexcept; + static void ListBox(unsigned short pid, int id, const char *label, const char *items); + //state 0 - disallow, 1 - allow static void SetMapVisibility(unsigned short targetPID, unsigned short affectedPID, unsigned short state) noexcept; static void SetMapVisibilityAll(unsigned short targetPID, unsigned short state) noexcept; diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index a65cf0996..5f1095f01 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -96,7 +96,7 @@ add_openmw_dir (mwbase inputmanager windowmanager statemanager ) -add_openmw_dir (mwmp DedicatedPlayer LocalPlayer Networking Main GUIChat GUILogin GUIController PlayerMarkerCollection) +add_openmw_dir (mwmp DedicatedPlayer LocalPlayer Networking Main GUIChat GUILogin GUIController PlayerMarkerCollection GUIDialogList) # Main executable diff --git a/apps/openmw/mwgui/mode.hpp b/apps/openmw/mwgui/mode.hpp index 19be8157e..db851e067 100644 --- a/apps/openmw/mwgui/mode.hpp +++ b/apps/openmw/mwgui/mode.hpp @@ -48,8 +48,7 @@ namespace MWGui GM_LoadingWallpaper, GM_Jail, - GM_QuickKeysMenu, - GM_TES3MPPipe + GM_QuickKeysMenu }; // Windows shown in inventory mode diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp index 1742c9d1e..a8c822121 100644 --- a/apps/openmw/mwgui/windowmanagerimp.cpp +++ b/apps/openmw/mwgui/windowmanagerimp.cpp @@ -677,10 +677,8 @@ namespace MWGui mToolTips->setVisible(false); setCursorVisible(mMessageBoxManager && mMessageBoxManager->isInteractiveMessageBox()); break; - case GM_TES3MPPipe: - mwmp::Main::get().getGUIController()->WM_UpdateVisible(mode); - break; default: + mwmp::Main::get().getGUIController()->WM_UpdateVisible(mode); // Unsupported mode, switch back to game break; } diff --git a/apps/openmw/mwmp/GUIController.cpp b/apps/openmw/mwmp/GUIController.cpp index 4d3e6cf96..8d34d0bf5 100644 --- a/apps/openmw/mwmp/GUIController.cpp +++ b/apps/openmw/mwmp/GUIController.cpp @@ -28,9 +28,11 @@ #include "Main.hpp" #include "PlayerMarkerCollection.hpp" #include "DedicatedPlayer.hpp" +#include "GUIDialogList.hpp" +#include "GUIChat.hpp" -mwmp::GUIController::GUIController(): mInputBox(0) +mwmp::GUIController::GUIController(): mInputBox(0), mListBox(0) { mChat = nullptr; keySay = SDLK_y; @@ -80,6 +82,37 @@ void mwmp::GUIController::setChatVisible(bool chatVisible) mChat->setVisible(chatVisible); } +void mwmp::GUIController::ShowDialogList(const mwmp::BasePlayer::GUIMessageBox &guiMessageBox) +{ + MWBase::WindowManager *windowManager = MWBase::Environment::get().getWindowManager(); + windowManager->removeDialog(mInputBox); + if(mListBox) + { + delete mListBox; + mListBox = NULL; + } + + std::vector list; + + std::string buf; + + for(size_t i = 0; i < guiMessageBox.data.size(); i++) + { + if(guiMessageBox.data[i] == '\n') + { + list.push_back(buf); + buf.erase(); + continue; + } + buf += guiMessageBox.data[i]; + } + + list.push_back(buf); + + mListBox = new GUIDialogList(guiMessageBox.label, list); + windowManager->pushGuiMode((MWGui::GuiMode)GM_TES3MP_ListBox); +} + void mwmp::GUIController::ShowMessageBox(const BasePlayer::GUIMessageBox &guiMessageBox) { MWBase::WindowManager *windowManager = MWBase::Environment::get().getWindowManager(); @@ -112,7 +145,7 @@ void mwmp::GUIController::ShowInputBox(const BasePlayer::GUIMessageBox &guiMessa MWBase::WindowManager *windowManager = MWBase::Environment::get().getWindowManager(); windowManager->removeDialog(mInputBox); - windowManager->pushGuiMode(MWGui::GM_TES3MPPipe); + windowManager->pushGuiMode((MWGui::GuiMode)GM_TES3MP_InputBox); mInputBox = 0; mInputBox = new MWGui::TextInputDialog(); mInputBox->setTextLabel(guiMessageBox.label); @@ -175,14 +208,20 @@ void mwmp::GUIController::update(float dt) void mwmp::GUIController::WM_UpdateVisible(MWGui::GuiMode mode) { - switch(mode) + switch((int)mode) { - case MWGui::GM_TES3MPPipe: + case GM_TES3MP_InputBox: { if (mInputBox != 0) mInputBox->setVisible(true); break; } + case GM_TES3MP_ListBox: + { + if(mListBox != 0) + mListBox->setVisible(true); + break; + } default: break; } diff --git a/apps/openmw/mwmp/GUIController.hpp b/apps/openmw/mwmp/GUIController.hpp index c09a918f9..a0e59f857 100644 --- a/apps/openmw/mwmp/GUIController.hpp +++ b/apps/openmw/mwmp/GUIController.hpp @@ -9,7 +9,6 @@ #include #include #include -#include "GUIChat.hpp" #include "PlayerMarkerCollection.hpp" namespace MWGui @@ -20,9 +19,17 @@ namespace MWGui namespace mwmp { + class GUIDialogList; + class GUIChat; class GUIController { public: + enum GM + { + GM_TES3MP_InputBox = MWGui::GM_QuickKeysMenu + 1, + GM_TES3MP_ListBox + + }; GUIController(); ~GUIController(); void cleanup(); @@ -35,6 +42,8 @@ namespace mwmp void ShowCustomMessageBox(const BasePlayer::GUIMessageBox &guiMessageBox); void ShowInputBox(const BasePlayer::GUIMessageBox &guiMessageBox); + void ShowDialogList(const BasePlayer::GUIMessageBox &guiMessageBox); + /// Return true if any tes3mp gui element in active state bool HaveFocusedElement(); /// Returns 0 if there was no events @@ -60,6 +69,7 @@ namespace mwmp long id; bool calledMessageBox; MWGui::TextInputDialog *mInputBox; + GUIDialogList *mListBox; void OnInputBoxDone(MWGui::WindowBase* parWindow); //MyGUI::Widget *oldFocusWidget, *currentFocusWidget; }; diff --git a/apps/openmw/mwmp/GUIDialogList.cpp b/apps/openmw/mwmp/GUIDialogList.cpp new file mode 100644 index 000000000..143bdcdac --- /dev/null +++ b/apps/openmw/mwmp/GUIDialogList.cpp @@ -0,0 +1,53 @@ +// +// Created by koncord on 03.11.16. +// + +#include "GUIDialogList.hpp" +#include "Main.hpp" +#include +#include +#include +#include +#include +#include + +using namespace mwmp; + +GUIDialogList::GUIDialogList(const std::string &message, const std::vector &list) : WindowModal("tes3mp_dialog_list.layout") +{ + center(); // center window + + getWidget(mListBox, "ListBox"); + getWidget(mMessage, "Message"); + getWidget(mButton, "OkButton"); + + mButton->eventMouseButtonClick += MyGUI::newDelegate(this, &GUIDialogList::mousePressed); + + mMessage->setCaptionWithReplacing(message); + for(int i = 0; i < list.size(); i++) + mListBox->addItem(list[i]); + +} + +void GUIDialogList::mousePressed(MyGUI::Widget * /*widget*/) +{ + setVisible(false); + MWBase::Environment::get().getWindowManager()->popGuiMode(); + + size_t id = mListBox->getIndexSelected(); + + Main::get().getLocalPlayer()->guiMessageBox.data = MyGUI::utility::toString(id); + Main::get().getNetworking()->GetPlayerPacket(ID_GUI_MESSAGEBOX)->Send(Main::get().getLocalPlayer()); + + LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Selected id: %d", id); + if(id == MyGUI::ITEM_NONE) + return; + + std::string itemName = mListBox->getItemNameAt(mListBox->getIndexSelected()).asUTF8(); + LOG_APPEND(Log::LOG_VERBOSE, "name of item: '%s'", itemName.c_str()); +} + +void GUIDialogList::onFrame(float frameDuration) +{ + +} diff --git a/apps/openmw/mwmp/GUIDialogList.hpp b/apps/openmw/mwmp/GUIDialogList.hpp new file mode 100644 index 000000000..304cf3236 --- /dev/null +++ b/apps/openmw/mwmp/GUIDialogList.hpp @@ -0,0 +1,27 @@ +// +// Created by koncord on 03.11.16. +// + +#ifndef OPENMW_GUIDIALOGLIST_HPP +#define OPENMW_GUIDIALOGLIST_HPP + + +#include + +namespace mwmp +{ + class GUIDialogList : public MWGui::WindowModal + { + public: + GUIDialogList(const std::string &message, const std::vector &list); + void mousePressed(MyGUI::Widget *_widget); + void onFrame(float frameDuration); + private: + bool mMarkedToDelete; + MyGUI::EditBox *mMessage; + MyGUI::ListBox *mListBox; + MyGUI::Button *mButton; + }; +} + +#endif //OPENMW_GUIDIALOGLIST_HPP diff --git a/apps/openmw/mwmp/Networking.cpp b/apps/openmw/mwmp/Networking.cpp index e0820eb87..e94f25c96 100644 --- a/apps/openmw/mwmp/Networking.cpp +++ b/apps/openmw/mwmp/Networking.cpp @@ -641,6 +641,8 @@ void Networking::ProcessPlayerPacket(RakNet::Packet *packet) Main::get().getGUIController()->ShowCustomMessageBox(getLocalPlayer()->guiMessageBox); else if (getLocalPlayer()->guiMessageBox.type == BasePlayer::GUIMessageBox::InputDialog) Main::get().getGUIController()->ShowInputBox(getLocalPlayer()->guiMessageBox); + else if (getLocalPlayer()->guiMessageBox.type == BasePlayer::GUIMessageBox::ListBox) + Main::get().getGUIController()->ShowDialogList(getLocalPlayer()->guiMessageBox); } break; } diff --git a/components/openmw-mp/Base/BasePlayer.hpp b/components/openmw-mp/Base/BasePlayer.hpp index 19044efb9..894195efe 100644 --- a/components/openmw-mp/Base/BasePlayer.hpp +++ b/components/openmw-mp/Base/BasePlayer.hpp @@ -70,7 +70,8 @@ namespace mwmp MessageBox = 0, CustomMessageBox, InputDialog, - PasswordDialog + PasswordDialog, + ListBox }; std::string label; std::string buttons; diff --git a/files/mygui/CMakeLists.txt b/files/mygui/CMakeLists.txt index 8515ef063..dd7ffee55 100644 --- a/files/mygui/CMakeLists.txt +++ b/files/mygui/CMakeLists.txt @@ -92,6 +92,7 @@ set(MYGUI_FILES tes3mp_login.layout tes3mp_login.skin.xml + tes3mp_dialog_list.layout ) diff --git a/files/mygui/tes3mp_dialog_list.layout b/files/mygui/tes3mp_dialog_list.layout new file mode 100644 index 000000000..d7ccb5e1e --- /dev/null +++ b/files/mygui/tes3mp_dialog_list.layout @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +