Replaced combo boxes with list box dialogues to help navigate certain elements better in VR.
parent
00d6dc3a86
commit
a0a7e6b5aa
@ -0,0 +1,89 @@
|
||||
#include "vrlistbox.hpp"
|
||||
|
||||
#include <MyGUI_InputManager.h>
|
||||
#include <MyGUI_LayerManager.h>
|
||||
#include <MyGUI_ComboBox.h>
|
||||
|
||||
#include "../mwbase/environment.hpp"
|
||||
#include "../mwbase/windowmanager.hpp"
|
||||
#include "../mwbase/world.hpp"
|
||||
#include "../mwbase/statemanager.hpp"
|
||||
|
||||
namespace MWVR
|
||||
{
|
||||
VrListBox::VrListBox()
|
||||
: WindowModal("openmw_vr_listbox.layout")
|
||||
, mOK(nullptr)
|
||||
, mCancel(nullptr)
|
||||
, mListBox(nullptr)
|
||||
, mIndex(MyGUI::ITEM_NONE)
|
||||
, mCallback()
|
||||
{
|
||||
getWidget(mOK, "OkButton");
|
||||
getWidget(mCancel, "CancelButton");
|
||||
getWidget(mListBox, "ListBox");
|
||||
|
||||
mOK->eventMouseButtonClick += MyGUI::newDelegate(this, &VrListBox::onOKButtonClicked);
|
||||
mCancel->eventMouseButtonClick += MyGUI::newDelegate(this, &VrListBox::onCancelButtonClicked);
|
||||
mListBox->eventListChangePosition += MyGUI::newDelegate(this, &VrListBox::onItemChanged);
|
||||
mListBox->eventListSelectAccept += MyGUI::newDelegate(this, &VrListBox::onListAccept);
|
||||
}
|
||||
|
||||
VrListBox::~VrListBox()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void VrListBox::open(MyGUI::ComboBox* comboBox, Callback callback)
|
||||
{
|
||||
mCallback = callback;
|
||||
mIndex = MyGUI::ITEM_NONE;
|
||||
mListBox->removeAllItems();
|
||||
mListBox->setIndexSelected(MyGUI::ITEM_NONE);
|
||||
|
||||
for (unsigned i = 0; i < comboBox->getItemCount(); i++)
|
||||
mListBox->addItem(comboBox->getItemNameAt(i));
|
||||
|
||||
mListBox->setItemSelect(comboBox->getIndexSelected());
|
||||
|
||||
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mListBox);
|
||||
|
||||
center();
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
void VrListBox::close()
|
||||
{
|
||||
setVisible(false);
|
||||
}
|
||||
|
||||
void VrListBox::onItemChanged(MyGUI::ListBox* _sender, size_t _index)
|
||||
{
|
||||
mIndex = _index;
|
||||
}
|
||||
|
||||
void VrListBox::onCancelButtonClicked(MyGUI::Widget* sender)
|
||||
{
|
||||
close();
|
||||
|
||||
if (mCallback)
|
||||
mCallback(MyGUI::ITEM_NONE);
|
||||
}
|
||||
|
||||
void VrListBox::onOKButtonClicked(MyGUI::Widget* sender)
|
||||
{
|
||||
accept(mIndex);
|
||||
}
|
||||
|
||||
void VrListBox::onListAccept(MyGUI::ListBox* sender, size_t pos)
|
||||
{
|
||||
accept(pos);
|
||||
}
|
||||
void VrListBox::accept(size_t index)
|
||||
{
|
||||
close();
|
||||
|
||||
if (mCallback)
|
||||
mCallback(index);
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
#ifndef OPENMW_GAME_MWVR_LISTBOX_H
|
||||
#define OPENMW_GAME_MWVR_LISTBOX_H
|
||||
|
||||
#include "../mwgui/windowbase.hpp"
|
||||
|
||||
#include <MyGUI_Button.h>
|
||||
#include <MyGUI_ListBox.h>
|
||||
#include "components/widgets/virtualkeyboardmanager.hpp"
|
||||
|
||||
#include <set>
|
||||
#include <memory>
|
||||
|
||||
namespace Gui
|
||||
{
|
||||
class VirtualKeyboardManager;
|
||||
}
|
||||
|
||||
namespace MWVR
|
||||
{
|
||||
//! A simple dialogue that presents a list of choices. Used as an alternative to combo boxes in VR.
|
||||
class VrListBox : public MWGui::WindowModal
|
||||
{
|
||||
public:
|
||||
using Callback = std::function<void(std::size_t)>;
|
||||
|
||||
VrListBox();
|
||||
~VrListBox();
|
||||
|
||||
void open(MyGUI::ComboBox* comboBox, Callback callback);
|
||||
void close();
|
||||
|
||||
private:
|
||||
void onItemChanged(MyGUI::ListBox* _sender, size_t _index);
|
||||
void onCancelButtonClicked(MyGUI::Widget* sender);
|
||||
void onOKButtonClicked(MyGUI::Widget* sender);
|
||||
void onListAccept(MyGUI::ListBox* sender, size_t pos);
|
||||
void accept(size_t index);
|
||||
|
||||
MyGUI::Widget* mCancel;
|
||||
MyGUI::Widget* mOK;
|
||||
MyGUI::ListBox* mListBox;
|
||||
std::size_t mIndex;
|
||||
Callback mCallback;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<MyGUI type="Layout">
|
||||
<Widget type="VBox" skin="MW_DialogNoTransp" layer="ListBox" position="0 0 500 300" name="_Main" align="Center">
|
||||
<Property key="Spacing" value="8"/>
|
||||
<Property key="Padding" value="8"/>
|
||||
|
||||
<Widget type="ListBox" skin="MW_List" position="0 0 200 400" name="ListBox">
|
||||
<UserString key="HStretch" value="true"/>
|
||||
<UserString key="VStretch" value="true"/>
|
||||
</Widget>
|
||||
<Widget type="HBox" skin="">
|
||||
<Property key="Padding" value="8"/>
|
||||
<UserString key="HStretch" value="true"/>
|
||||
<UserString key="VStretch" value="true"/>
|
||||
<Widget type="AutoSizedButton" skin="MW_Button" name="OkButton">
|
||||
<Property key="Caption" value="#{sOk}"/>
|
||||
</Widget>
|
||||
|
||||
<Widget type="AutoSizedButton" skin="MW_Button" name="CancelButton">
|
||||
<Property key="Caption" value="#{sCancel}"/>
|
||||
</Widget>
|
||||
</Widget>
|
||||
</Widget>
|
||||
</MyGUI>
|
Loading…
Reference in New Issue