mirror of
https://github.com/OpenMW/openmw.git
synced 2025-12-01 21:34:31 +00:00
Add controller support to the companion window; also fix giving stacks
This commit is contained in:
parent
4e2e8d1a81
commit
57ae097257
4 changed files with 100 additions and 3 deletions
|
|
@ -6,6 +6,8 @@
|
||||||
#include <MyGUI_EditBox.h>
|
#include <MyGUI_EditBox.h>
|
||||||
#include <MyGUI_InputManager.h>
|
#include <MyGUI_InputManager.h>
|
||||||
|
|
||||||
|
#include <components/settings/values.hpp>
|
||||||
|
|
||||||
#include "../mwbase/environment.hpp"
|
#include "../mwbase/environment.hpp"
|
||||||
#include "../mwbase/windowmanager.hpp"
|
#include "../mwbase/windowmanager.hpp"
|
||||||
|
|
||||||
|
|
@ -14,6 +16,7 @@
|
||||||
#include "companionitemmodel.hpp"
|
#include "companionitemmodel.hpp"
|
||||||
#include "countdialog.hpp"
|
#include "countdialog.hpp"
|
||||||
#include "draganddrop.hpp"
|
#include "draganddrop.hpp"
|
||||||
|
#include "inventorywindow.hpp"
|
||||||
#include "itemview.hpp"
|
#include "itemview.hpp"
|
||||||
#include "messagebox.hpp"
|
#include "messagebox.hpp"
|
||||||
#include "sortfilteritemmodel.hpp"
|
#include "sortfilteritemmodel.hpp"
|
||||||
|
|
@ -58,6 +61,11 @@ namespace MWGui
|
||||||
mCloseButton->eventMouseButtonClick += MyGUI::newDelegate(this, &CompanionWindow::onCloseButtonClicked);
|
mCloseButton->eventMouseButtonClick += MyGUI::newDelegate(this, &CompanionWindow::onCloseButtonClicked);
|
||||||
|
|
||||||
setCoord(200, 0, 600, 300);
|
setCoord(200, 0, 600, 300);
|
||||||
|
|
||||||
|
mControllerButtons.a = "#{sTake}";
|
||||||
|
mControllerButtons.b = "#{sClose}";
|
||||||
|
mControllerButtons.r3 = "#{sInfo}";
|
||||||
|
mControllerButtons.l2 = "#{sInventory}";
|
||||||
}
|
}
|
||||||
|
|
||||||
void CompanionWindow::onItemSelected(int index)
|
void CompanionWindow::onItemSelected(int index)
|
||||||
|
|
@ -93,8 +101,13 @@ namespace MWGui
|
||||||
name += MWGui::ToolTips::getSoulString(object.getCellRef());
|
name += MWGui::ToolTips::getSoulString(object.getCellRef());
|
||||||
dialog->openCountDialog(name, "#{sTake}", count);
|
dialog->openCountDialog(name, "#{sTake}", count);
|
||||||
dialog->eventOkClicked.clear();
|
dialog->eventOkClicked.clear();
|
||||||
|
if (Settings::gui().mControllerMenus)
|
||||||
|
dialog->eventOkClicked += MyGUI::newDelegate(this, &CompanionWindow::takeItem);
|
||||||
|
else
|
||||||
dialog->eventOkClicked += MyGUI::newDelegate(this, &CompanionWindow::dragItem);
|
dialog->eventOkClicked += MyGUI::newDelegate(this, &CompanionWindow::dragItem);
|
||||||
}
|
}
|
||||||
|
else if (Settings::gui().mControllerMenus)
|
||||||
|
takeItem(nullptr, count);
|
||||||
else
|
else
|
||||||
dragItem(nullptr, count);
|
dragItem(nullptr, count);
|
||||||
}
|
}
|
||||||
|
|
@ -110,6 +123,29 @@ namespace MWGui
|
||||||
mDragAndDrop->startDrag(mSelectedItem, mSortModel, mModel, mItemView, count);
|
mDragAndDrop->startDrag(mSelectedItem, mSortModel, mModel, mItemView, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CompanionWindow::takeItem(MyGUI::Widget* sender, int count)
|
||||||
|
{
|
||||||
|
if (!mModel)
|
||||||
|
return;
|
||||||
|
|
||||||
|
const ItemStack& item = mModel->getItem(mSelectedItem);
|
||||||
|
if (!mModel->onTakeItem(item.mBase, count))
|
||||||
|
return;
|
||||||
|
|
||||||
|
MWGui::InventoryWindow* inventoryWindow = MWBase::Environment::get().getWindowManager()->getInventoryWindow();
|
||||||
|
ItemModel* playerModel = inventoryWindow->getModel();
|
||||||
|
|
||||||
|
mModel->moveItem(item, count, playerModel);
|
||||||
|
|
||||||
|
inventoryWindow->updateItemView();
|
||||||
|
mItemView->update();
|
||||||
|
|
||||||
|
// play the item's sound
|
||||||
|
MWWorld::Ptr itemBase = item.mBase;
|
||||||
|
const ESM::RefId& sound = itemBase.getClass().getUpSoundId(itemBase);
|
||||||
|
MWBase::Environment::get().getWindowManager()->playSound(sound);
|
||||||
|
}
|
||||||
|
|
||||||
void CompanionWindow::onBackgroundSelected()
|
void CompanionWindow::onBackgroundSelected()
|
||||||
{
|
{
|
||||||
if (mDragAndDrop->mIsOnDragAndDrop)
|
if (mDragAndDrop->mIsOnDragAndDrop)
|
||||||
|
|
@ -202,4 +238,31 @@ namespace MWGui
|
||||||
mSortModel = nullptr;
|
mSortModel = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CompanionWindow::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg)
|
||||||
|
{
|
||||||
|
if (arg.button == SDL_CONTROLLER_BUTTON_A)
|
||||||
|
{
|
||||||
|
int index = mItemView->getControllerFocus();
|
||||||
|
if (index >= 0 && index < mItemView->getItemCount())
|
||||||
|
onItemSelected(index);
|
||||||
|
}
|
||||||
|
else if (arg.button == SDL_CONTROLLER_BUTTON_B)
|
||||||
|
{
|
||||||
|
onCloseButtonClicked(mCloseButton);
|
||||||
|
}
|
||||||
|
else if (arg.button == SDL_CONTROLLER_BUTTON_RIGHTSTICK || arg.button == SDL_CONTROLLER_BUTTON_DPAD_UP
|
||||||
|
|| arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN || arg.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT
|
||||||
|
|| arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT)
|
||||||
|
{
|
||||||
|
mItemView->onControllerButton(arg.button);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CompanionWindow::setActiveControllerWindow(bool active)
|
||||||
|
{
|
||||||
|
mItemView->setActiveControllerWindow(active);
|
||||||
|
WindowBase::setActiveControllerWindow(active);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,9 @@ namespace MWGui
|
||||||
|
|
||||||
std::string_view getWindowIdForLua() const override { return "Companion"; }
|
std::string_view getWindowIdForLua() const override { return "Companion"; }
|
||||||
|
|
||||||
|
bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
|
||||||
|
void setActiveControllerWindow(bool active) override;
|
||||||
|
|
||||||
MWGui::ItemView* getItemView() { return mItemView; }
|
MWGui::ItemView* getItemView() { return mItemView; }
|
||||||
ItemModel* getModel() { return mModel; }
|
ItemModel* getModel() { return mModel; }
|
||||||
|
|
||||||
|
|
@ -55,6 +58,7 @@ namespace MWGui
|
||||||
void onNameFilterChanged(MyGUI::EditBox* _sender);
|
void onNameFilterChanged(MyGUI::EditBox* _sender);
|
||||||
void onBackgroundSelected();
|
void onBackgroundSelected();
|
||||||
void dragItem(MyGUI::Widget* sender, int count);
|
void dragItem(MyGUI::Widget* sender, int count);
|
||||||
|
void takeItem(MyGUI::Widget* sender, int count);
|
||||||
|
|
||||||
void onMessageBoxButtonClicked(int button);
|
void onMessageBoxButtonClicked(int button);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -331,7 +331,10 @@ namespace MWGui
|
||||||
name += MWGui::ToolTips::getSoulString(object.getCellRef());
|
name += MWGui::ToolTips::getSoulString(object.getCellRef());
|
||||||
dialog->openCountDialog(name, message, count);
|
dialog->openCountDialog(name, message, count);
|
||||||
dialog->eventOkClicked.clear();
|
dialog->eventOkClicked.clear();
|
||||||
if (mTrading)
|
if (Settings::gui().mControllerMenus
|
||||||
|
&& (mGuiMode == MWGui::GM_Companion || mGuiMode == MWGui::GM_Container))
|
||||||
|
dialog->eventOkClicked += MyGUI::newDelegate(this, &InventoryWindow::giveItem);
|
||||||
|
else if (mTrading)
|
||||||
dialog->eventOkClicked += MyGUI::newDelegate(this, &InventoryWindow::sellItem);
|
dialog->eventOkClicked += MyGUI::newDelegate(this, &InventoryWindow::sellItem);
|
||||||
else
|
else
|
||||||
dialog->eventOkClicked += MyGUI::newDelegate(this, &InventoryWindow::dragItem);
|
dialog->eventOkClicked += MyGUI::newDelegate(this, &InventoryWindow::dragItem);
|
||||||
|
|
@ -411,6 +414,32 @@ namespace MWGui
|
||||||
notifyContentChanged();
|
notifyContentChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void InventoryWindow::giveItem(MyGUI::Widget* sender, int count)
|
||||||
|
{
|
||||||
|
ensureSelectedItemUnequipped(count);
|
||||||
|
mDragAndDrop->startDrag(mSelectedItem, mSortModel, mTradeModel, mItemView, count);
|
||||||
|
notifyContentChanged();
|
||||||
|
|
||||||
|
if (mGuiMode == MWGui::GM_Companion && mDragAndDrop->mIsOnDragAndDrop)
|
||||||
|
{
|
||||||
|
// Drag and drop the item on the companion's window.
|
||||||
|
MWGui::CompanionWindow* companionWindow = (MWGui::CompanionWindow*)MWBase::Environment::get()
|
||||||
|
.getWindowManager()
|
||||||
|
->getGuiModeWindows(mGuiMode)
|
||||||
|
.at(1);
|
||||||
|
mDragAndDrop->drop(companionWindow->getModel(), companionWindow->getItemView());
|
||||||
|
}
|
||||||
|
else if (mGuiMode == MWGui::GM_Container && mDragAndDrop->mIsOnDragAndDrop)
|
||||||
|
{
|
||||||
|
// Drag and drop the item on the container window.
|
||||||
|
MWGui::ContainerWindow* containerWindow = (MWGui::ContainerWindow*)MWBase::Environment::get()
|
||||||
|
.getWindowManager()
|
||||||
|
->getGuiModeWindows(mGuiMode)
|
||||||
|
.at(0);
|
||||||
|
mDragAndDrop->drop(containerWindow->getModel(), containerWindow->getItemView());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void InventoryWindow::updateItemView()
|
void InventoryWindow::updateItemView()
|
||||||
{
|
{
|
||||||
MWBase::Environment::get().getWindowManager()->updateSpellWindow();
|
MWBase::Environment::get().getWindowManager()->updateSpellWindow();
|
||||||
|
|
@ -944,7 +973,7 @@ namespace MWGui
|
||||||
MWGui::CompanionWindow* companionWindow = (MWGui::CompanionWindow*)MWBase::Environment::get()
|
MWGui::CompanionWindow* companionWindow = (MWGui::CompanionWindow*)MWBase::Environment::get()
|
||||||
.getWindowManager()
|
.getWindowManager()
|
||||||
->getGuiModeWindows(mGuiMode)
|
->getGuiModeWindows(mGuiMode)
|
||||||
.at(0);
|
.at(1);
|
||||||
mDragAndDrop->drop(companionWindow->getModel(), companionWindow->getItemView());
|
mDragAndDrop->drop(companionWindow->getModel(), companionWindow->getItemView());
|
||||||
}
|
}
|
||||||
else if (mGuiMode == MWGui::GM_Container && mDragAndDrop->mIsOnDragAndDrop)
|
else if (mGuiMode == MWGui::GM_Container && mDragAndDrop->mIsOnDragAndDrop)
|
||||||
|
|
|
||||||
|
|
@ -122,6 +122,7 @@ namespace MWGui
|
||||||
|
|
||||||
void sellItem(MyGUI::Widget* sender, int count);
|
void sellItem(MyGUI::Widget* sender, int count);
|
||||||
void dragItem(MyGUI::Widget* sender, int count);
|
void dragItem(MyGUI::Widget* sender, int count);
|
||||||
|
void giveItem(MyGUI::Widget* sender, int count);
|
||||||
|
|
||||||
void onWindowResize(MyGUI::Window* _sender);
|
void onWindowResize(MyGUI::Window* _sender);
|
||||||
void onFilterChanged(MyGUI::Widget* _sender);
|
void onFilterChanged(MyGUI::Widget* _sender);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue