mirror of
https://github.com/OpenMW/openmw.git
synced 2025-12-15 22:13:15 +00:00
Add controller support to the level up dialog
This commit is contained in:
parent
e3a9b71bb9
commit
63a533cd51
2 changed files with 63 additions and 0 deletions
|
|
@ -8,6 +8,7 @@
|
|||
#include <MyGUI_UString.h>
|
||||
|
||||
#include <components/fallback/fallback.hpp>
|
||||
#include <components/settings/values.hpp>
|
||||
#include <components/widgets/box.hpp>
|
||||
|
||||
#include "../mwbase/environment.hpp"
|
||||
|
|
@ -72,6 +73,7 @@ namespace MWGui
|
|||
widgets.mButton->setCaption(attribute.mName);
|
||||
widgets.mValue = hbox->createWidget<Gui::AutoSizedTextBox>("SandText", {}, MyGUI::Align::Default);
|
||||
mAttributeWidgets.emplace(attribute.mId, widgets);
|
||||
mAttributeButtons.emplace_back(widgets.mButton);
|
||||
++i;
|
||||
}
|
||||
|
||||
|
|
@ -90,6 +92,13 @@ namespace MWGui
|
|||
mCoins.push_back(image);
|
||||
}
|
||||
|
||||
if (Settings::gui().mControllerMenus)
|
||||
{
|
||||
mDisableGamepadCursor = true;
|
||||
mControllerButtons.a = "#{sSelect}";
|
||||
mControllerButtons.x = "#{sDone}";
|
||||
}
|
||||
|
||||
center();
|
||||
}
|
||||
|
||||
|
|
@ -217,6 +226,13 @@ namespace MWGui
|
|||
|
||||
center();
|
||||
|
||||
if (Settings::gui().mControllerMenus)
|
||||
{
|
||||
mControllerFocus = 0;
|
||||
for (int i = 0; i < mAttributeButtons.size(); i++)
|
||||
setControllerFocus(mAttributeButtons, i, i == 0);
|
||||
}
|
||||
|
||||
// Play LevelUp Music
|
||||
MWBase::Environment::get().getSoundManager()->streamMusic(MWSound::triumphMusic, MWSound::MusicType::Normal);
|
||||
}
|
||||
|
|
@ -363,4 +379,47 @@ namespace MWGui
|
|||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool LevelupDialog::onControllerButtonEvent(const SDL_ControllerButtonEvent& arg)
|
||||
{
|
||||
if (arg.button == SDL_CONTROLLER_BUTTON_A)
|
||||
{
|
||||
if (mControllerFocus >= 0 && mControllerFocus < mAttributeButtons.size())
|
||||
onAttributeClicked(mAttributeButtons[mControllerFocus]);
|
||||
}
|
||||
else if (arg.button == SDL_CONTROLLER_BUTTON_X)
|
||||
{
|
||||
onOkButtonClicked(mOkButton);
|
||||
}
|
||||
else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_UP)
|
||||
{
|
||||
setControllerFocus(mAttributeButtons, mControllerFocus, false);
|
||||
if (mControllerFocus == 0)
|
||||
mControllerFocus = 3;
|
||||
else if (mControllerFocus == 4)
|
||||
mControllerFocus = 7;
|
||||
else
|
||||
mControllerFocus--;
|
||||
setControllerFocus(mAttributeButtons, mControllerFocus, true);
|
||||
}
|
||||
else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN)
|
||||
{
|
||||
setControllerFocus(mAttributeButtons, mControllerFocus, false);
|
||||
if (mControllerFocus == 3)
|
||||
mControllerFocus = 0;
|
||||
else if (mControllerFocus == 7)
|
||||
mControllerFocus = 4;
|
||||
else
|
||||
mControllerFocus++;
|
||||
setControllerFocus(mAttributeButtons, mControllerFocus, true);
|
||||
}
|
||||
else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT || arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT)
|
||||
{
|
||||
setControllerFocus(mAttributeButtons, mControllerFocus, false);
|
||||
mControllerFocus = (mControllerFocus + 4) % mAttributeButtons.size();
|
||||
setControllerFocus(mAttributeButtons, mControllerFocus, true);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,6 +49,10 @@ namespace MWGui
|
|||
|
||||
std::string_view getLevelupClassImage(
|
||||
const int combatIncreases, const int magicIncreases, const int stealthIncreases);
|
||||
|
||||
bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
|
||||
std::vector<MyGUI::Button*> mAttributeButtons;
|
||||
int mControllerFocus;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue