forked from teamnwah/openmw-tes3coop
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 endcoverity_scan^2
parent
107dacac6d
commit
adb49b7c7d
@ -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)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
@ -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
|
@ -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 New Issue