1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-16 04:49:54 +00:00
openmw-tes3mp/apps/openmw/mwmp/GUIDialogList.cpp
Koncord adb49b7c7d 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
2016-11-04 00:24:16 +08:00

53 lines
1.5 KiB
C++

//
// 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)
{
}