mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-03-03 17:19:39 +00:00
Add New GUI dialog: ListBox
Example: local GUI_LISTBOX = 42 function OnPlayerSendMessage(pid, message) if message == "/lb" then local items = "consectetur adipiscing elit\nsed do eiusmod tempor incididunt ut labore\net dolore magna aliqua." -- items can be separated through newline local label = "Lorem ipsum dolor sit amet" tes3mp.ListBox(pid, GUI_LISTBOX, label, items) end end function OnGUIAction(pid, idGui, data) if idGui == GUI_LISTBOX then print("ID: " .. idGui .. " data: " .. tostring(data)) -- if value higher than last item id end end
This commit is contained in:
parent
107dacac6d
commit
adb49b7c7d
13 changed files with 190 additions and 12 deletions
|
@ -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);
|
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
|
void GUIFunctions::SetMapVisibility(unsigned short targetPID, unsigned short affectedPID, unsigned short state) noexcept
|
||||||
{
|
{
|
||||||
LOG_MESSAGE(Log::LOG_WARN, "%s", "stub");
|
LOG_MESSAGE(Log::LOG_WARN, "%s", "stub");
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
{"MessageBox", GUIFunctions::_MessageBox},\
|
{"MessageBox", GUIFunctions::_MessageBox},\
|
||||||
{"CustomMessageBox", GUIFunctions::CustomMessageBox},\
|
{"CustomMessageBox", GUIFunctions::CustomMessageBox},\
|
||||||
{"InputDialog", GUIFunctions::InputDialog},\
|
{"InputDialog", GUIFunctions::InputDialog},\
|
||||||
|
{"ListBox", GUIFunctions::ListBox},\
|
||||||
{"SetMapVisibility", GUIFunctions::SetMapVisibility},\
|
{"SetMapVisibility", GUIFunctions::SetMapVisibility},\
|
||||||
{"SetMapVisibilityAll", GUIFunctions::SetMapVisibilityAll}\
|
{"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 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 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
|
//state 0 - disallow, 1 - allow
|
||||||
static void SetMapVisibility(unsigned short targetPID, unsigned short affectedPID, unsigned short state) noexcept;
|
static void SetMapVisibility(unsigned short targetPID, unsigned short affectedPID, unsigned short state) noexcept;
|
||||||
static void SetMapVisibilityAll(unsigned short targetPID, unsigned short state) noexcept;
|
static void SetMapVisibilityAll(unsigned short targetPID, unsigned short state) noexcept;
|
||||||
|
|
|
@ -96,7 +96,7 @@ add_openmw_dir (mwbase
|
||||||
inputmanager windowmanager statemanager
|
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
|
# Main executable
|
||||||
|
|
||||||
|
|
|
@ -48,8 +48,7 @@ namespace MWGui
|
||||||
GM_LoadingWallpaper,
|
GM_LoadingWallpaper,
|
||||||
GM_Jail,
|
GM_Jail,
|
||||||
|
|
||||||
GM_QuickKeysMenu,
|
GM_QuickKeysMenu
|
||||||
GM_TES3MPPipe
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Windows shown in inventory mode
|
// Windows shown in inventory mode
|
||||||
|
|
|
@ -677,10 +677,8 @@ namespace MWGui
|
||||||
mToolTips->setVisible(false);
|
mToolTips->setVisible(false);
|
||||||
setCursorVisible(mMessageBoxManager && mMessageBoxManager->isInteractiveMessageBox());
|
setCursorVisible(mMessageBoxManager && mMessageBoxManager->isInteractiveMessageBox());
|
||||||
break;
|
break;
|
||||||
case GM_TES3MPPipe:
|
|
||||||
mwmp::Main::get().getGUIController()->WM_UpdateVisible(mode);
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
|
mwmp::Main::get().getGUIController()->WM_UpdateVisible(mode);
|
||||||
// Unsupported mode, switch back to game
|
// Unsupported mode, switch back to game
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,9 +28,11 @@
|
||||||
#include "Main.hpp"
|
#include "Main.hpp"
|
||||||
#include "PlayerMarkerCollection.hpp"
|
#include "PlayerMarkerCollection.hpp"
|
||||||
#include "DedicatedPlayer.hpp"
|
#include "DedicatedPlayer.hpp"
|
||||||
|
#include "GUIDialogList.hpp"
|
||||||
|
#include "GUIChat.hpp"
|
||||||
|
|
||||||
|
|
||||||
mwmp::GUIController::GUIController(): mInputBox(0)
|
mwmp::GUIController::GUIController(): mInputBox(0), mListBox(0)
|
||||||
{
|
{
|
||||||
mChat = nullptr;
|
mChat = nullptr;
|
||||||
keySay = SDLK_y;
|
keySay = SDLK_y;
|
||||||
|
@ -80,6 +82,37 @@ void mwmp::GUIController::setChatVisible(bool chatVisible)
|
||||||
mChat->setVisible(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<std::string> 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)
|
void mwmp::GUIController::ShowMessageBox(const BasePlayer::GUIMessageBox &guiMessageBox)
|
||||||
{
|
{
|
||||||
MWBase::WindowManager *windowManager = MWBase::Environment::get().getWindowManager();
|
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();
|
MWBase::WindowManager *windowManager = MWBase::Environment::get().getWindowManager();
|
||||||
|
|
||||||
windowManager->removeDialog(mInputBox);
|
windowManager->removeDialog(mInputBox);
|
||||||
windowManager->pushGuiMode(MWGui::GM_TES3MPPipe);
|
windowManager->pushGuiMode((MWGui::GuiMode)GM_TES3MP_InputBox);
|
||||||
mInputBox = 0;
|
mInputBox = 0;
|
||||||
mInputBox = new MWGui::TextInputDialog();
|
mInputBox = new MWGui::TextInputDialog();
|
||||||
mInputBox->setTextLabel(guiMessageBox.label);
|
mInputBox->setTextLabel(guiMessageBox.label);
|
||||||
|
@ -175,14 +208,20 @@ void mwmp::GUIController::update(float dt)
|
||||||
|
|
||||||
void mwmp::GUIController::WM_UpdateVisible(MWGui::GuiMode mode)
|
void mwmp::GUIController::WM_UpdateVisible(MWGui::GuiMode mode)
|
||||||
{
|
{
|
||||||
switch(mode)
|
switch((int)mode)
|
||||||
{
|
{
|
||||||
case MWGui::GM_TES3MPPipe:
|
case GM_TES3MP_InputBox:
|
||||||
{
|
{
|
||||||
if (mInputBox != 0)
|
if (mInputBox != 0)
|
||||||
mInputBox->setVisible(true);
|
mInputBox->setVisible(true);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case GM_TES3MP_ListBox:
|
||||||
|
{
|
||||||
|
if(mListBox != 0)
|
||||||
|
mListBox->setVisible(true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
#include <apps/openmw/mwgui/textinput.hpp>
|
#include <apps/openmw/mwgui/textinput.hpp>
|
||||||
#include <apps/openmw/mwgui/mode.hpp>
|
#include <apps/openmw/mwgui/mode.hpp>
|
||||||
#include <components/openmw-mp/Base/BasePlayer.hpp>
|
#include <components/openmw-mp/Base/BasePlayer.hpp>
|
||||||
#include "GUIChat.hpp"
|
|
||||||
#include "PlayerMarkerCollection.hpp"
|
#include "PlayerMarkerCollection.hpp"
|
||||||
|
|
||||||
namespace MWGui
|
namespace MWGui
|
||||||
|
@ -20,9 +19,17 @@ namespace MWGui
|
||||||
|
|
||||||
namespace mwmp
|
namespace mwmp
|
||||||
{
|
{
|
||||||
|
class GUIDialogList;
|
||||||
|
class GUIChat;
|
||||||
class GUIController
|
class GUIController
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
enum GM
|
||||||
|
{
|
||||||
|
GM_TES3MP_InputBox = MWGui::GM_QuickKeysMenu + 1,
|
||||||
|
GM_TES3MP_ListBox
|
||||||
|
|
||||||
|
};
|
||||||
GUIController();
|
GUIController();
|
||||||
~GUIController();
|
~GUIController();
|
||||||
void cleanup();
|
void cleanup();
|
||||||
|
@ -35,6 +42,8 @@ namespace mwmp
|
||||||
void ShowCustomMessageBox(const BasePlayer::GUIMessageBox &guiMessageBox);
|
void ShowCustomMessageBox(const BasePlayer::GUIMessageBox &guiMessageBox);
|
||||||
void ShowInputBox(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
|
/// Return true if any tes3mp gui element in active state
|
||||||
bool HaveFocusedElement();
|
bool HaveFocusedElement();
|
||||||
/// Returns 0 if there was no events
|
/// Returns 0 if there was no events
|
||||||
|
@ -60,6 +69,7 @@ namespace mwmp
|
||||||
long id;
|
long id;
|
||||||
bool calledMessageBox;
|
bool calledMessageBox;
|
||||||
MWGui::TextInputDialog *mInputBox;
|
MWGui::TextInputDialog *mInputBox;
|
||||||
|
GUIDialogList *mListBox;
|
||||||
void OnInputBoxDone(MWGui::WindowBase* parWindow);
|
void OnInputBoxDone(MWGui::WindowBase* parWindow);
|
||||||
//MyGUI::Widget *oldFocusWidget, *currentFocusWidget;
|
//MyGUI::Widget *oldFocusWidget, *currentFocusWidget;
|
||||||
};
|
};
|
||||||
|
|
53
apps/openmw/mwmp/GUIDialogList.cpp
Normal file
53
apps/openmw/mwmp/GUIDialogList.cpp
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
//
|
||||||
|
// Created by koncord on 03.11.16.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "GUIDialogList.hpp"
|
||||||
|
#include "Main.hpp"
|
||||||
|
#include <MyGUI_EditBox.h>
|
||||||
|
#include <MyGUI_Button.h>
|
||||||
|
#include <MyGUI_ListBox.h>
|
||||||
|
#include <apps/openmw/mwgui/windowmanagerimp.hpp>
|
||||||
|
#include <apps/openmw/mwbase/environment.hpp>
|
||||||
|
#include <components/openmw-mp/Log.hpp>
|
||||||
|
|
||||||
|
using namespace mwmp;
|
||||||
|
|
||||||
|
GUIDialogList::GUIDialogList(const std::string &message, const std::vector<std::string> &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)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
27
apps/openmw/mwmp/GUIDialogList.hpp
Normal file
27
apps/openmw/mwmp/GUIDialogList.hpp
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
//
|
||||||
|
// Created by koncord on 03.11.16.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef OPENMW_GUIDIALOGLIST_HPP
|
||||||
|
#define OPENMW_GUIDIALOGLIST_HPP
|
||||||
|
|
||||||
|
|
||||||
|
#include <apps/openmw/mwgui/windowbase.hpp>
|
||||||
|
|
||||||
|
namespace mwmp
|
||||||
|
{
|
||||||
|
class GUIDialogList : public MWGui::WindowModal
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
GUIDialogList(const std::string &message, const std::vector<std::string> &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
|
|
@ -641,6 +641,8 @@ void Networking::ProcessPlayerPacket(RakNet::Packet *packet)
|
||||||
Main::get().getGUIController()->ShowCustomMessageBox(getLocalPlayer()->guiMessageBox);
|
Main::get().getGUIController()->ShowCustomMessageBox(getLocalPlayer()->guiMessageBox);
|
||||||
else if (getLocalPlayer()->guiMessageBox.type == BasePlayer::GUIMessageBox::InputDialog)
|
else if (getLocalPlayer()->guiMessageBox.type == BasePlayer::GUIMessageBox::InputDialog)
|
||||||
Main::get().getGUIController()->ShowInputBox(getLocalPlayer()->guiMessageBox);
|
Main::get().getGUIController()->ShowInputBox(getLocalPlayer()->guiMessageBox);
|
||||||
|
else if (getLocalPlayer()->guiMessageBox.type == BasePlayer::GUIMessageBox::ListBox)
|
||||||
|
Main::get().getGUIController()->ShowDialogList(getLocalPlayer()->guiMessageBox);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,7 +70,8 @@ namespace mwmp
|
||||||
MessageBox = 0,
|
MessageBox = 0,
|
||||||
CustomMessageBox,
|
CustomMessageBox,
|
||||||
InputDialog,
|
InputDialog,
|
||||||
PasswordDialog
|
PasswordDialog,
|
||||||
|
ListBox
|
||||||
};
|
};
|
||||||
std::string label;
|
std::string label;
|
||||||
std::string buttons;
|
std::string buttons;
|
||||||
|
|
|
@ -92,6 +92,7 @@ set(MYGUI_FILES
|
||||||
|
|
||||||
tes3mp_login.layout
|
tes3mp_login.layout
|
||||||
tes3mp_login.skin.xml
|
tes3mp_login.skin.xml
|
||||||
|
tes3mp_dialog_list.layout
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
32
files/mygui/tes3mp_dialog_list.layout
Normal file
32
files/mygui/tes3mp_dialog_list.layout
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<MyGUI type="Layout">
|
||||||
|
<Widget type="Window" skin="MW_Dialog" layer="Windows" position="0 0 300 300" name="_Main">
|
||||||
|
<Property key="Visible" value="false"/>
|
||||||
|
|
||||||
|
<Widget type="EditBox" skin="MW_TextEditClient" position="16 8 268 48" name="Message" align="Center Top">
|
||||||
|
<Property key="FontName" value="Default"/>
|
||||||
|
<Property key="TextAlign" value="Top HCenter"/>
|
||||||
|
<Property key="Static" value="true"/>
|
||||||
|
<Property key="WordWrap" value="true"/>
|
||||||
|
<Property key="MultiLine" value="true"/>
|
||||||
|
</Widget>
|
||||||
|
|
||||||
|
<Widget type="ListBox" skin="MW_List" position="16 56 268 170" align="Left Top" name="ListBox"/>
|
||||||
|
|
||||||
|
<Widget type="VBox" position="0 262 292 24" align="Right Bottom">
|
||||||
|
<Widget type="HBox">
|
||||||
|
<Property key="Spacing" value="8"/>
|
||||||
|
|
||||||
|
<Widget type="AutoSizedButton" skin="MW_Button" name="OkButton" align="Right Bottom">
|
||||||
|
<Property key="Caption" value="#{sYes}"/>
|
||||||
|
</Widget>
|
||||||
|
<!--<Widget type="AutoSizedButton" skin="MW_Button" name="CancelButton" align="Right Bottom">
|
||||||
|
<Property key="Caption" value="#{sNo}"/>
|
||||||
|
</Widget>-->
|
||||||
|
</Widget>
|
||||||
|
|
||||||
|
<Widget type="Widget"/>
|
||||||
|
</Widget>
|
||||||
|
</Widget>
|
||||||
|
</MyGUI>
|
Loading…
Reference in a new issue