Skip to content

Commit

Permalink
Merge pull request #15763 from garbear/controller-fixes
Browse files Browse the repository at this point in the history
Controller dialog: Update controllers after controller addon installation
  • Loading branch information
garbear committed Apr 15, 2019
2 parents 73b6095 + f32acfa commit c67eb3a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
29 changes: 26 additions & 3 deletions xbmc/games/controllers/windows/GUIControllerList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ bool CGUIControllerList::Initialize(void)
m_controllerButton->SetVisible(false);

CServiceBroker::GetAddonMgr().Events().Subscribe(this, &CGUIControllerList::OnEvent);
Refresh();
Refresh("");

return m_controllerList != nullptr &&
m_controllerButton != nullptr;
Expand All @@ -75,8 +75,17 @@ void CGUIControllerList::Deinitialize(void)
m_controllerButton = nullptr;
}

bool CGUIControllerList::Refresh(void)
bool CGUIControllerList::Refresh(const std::string& controllerId)
{
// Focus specified controller after refresh
std::string focusController = controllerId;

if (focusController.empty() && m_focusedController >= 0)
{
// If controller ID wasn't provided, focus current controller
focusController = m_controllers[m_focusedController]->ID();
}

if (!RefreshControllers())
return false;

Expand All @@ -92,6 +101,12 @@ bool CGUIControllerList::Refresh(void)
CGUIButtonControl* pButton = new CGUIControllerButton(*m_controllerButton, controller->Layout().Label(), buttonId++);
m_controllerList->AddControl(pButton);

if (!focusController.empty() && controller->ID() == focusController)
{
CGUIMessage msg(GUI_MSG_SETFOCUS, m_guiWindow->GetID(), pButton->GetID());
m_guiWindow->OnMessage(msg);
}

// Just in case
if (buttonId >= MAX_CONTROLLER_COUNT)
break;
Expand Down Expand Up @@ -146,11 +161,19 @@ void CGUIControllerList::ResetController(void)

void CGUIControllerList::OnEvent(const ADDON::AddonEvent& event)
{
if (typeid(event) == typeid(ADDON::AddonEvents::ReInstalled) ||
if (typeid(event) == typeid(ADDON::AddonEvents::Enabled) || // also called on install,
typeid(event) == typeid(ADDON::AddonEvents::Disabled) || // not called on uninstall
typeid(event) == typeid(ADDON::AddonEvents::ReInstalled) ||
typeid(event) == typeid(ADDON::AddonEvents::UnInstalled))
{
using namespace MESSAGING;
CGUIMessage msg(GUI_MSG_REFRESH_LIST, m_guiWindow->GetID(), CONTROL_CONTROLLER_LIST);

// Focus installed add-on
if (typeid(event) == typeid(ADDON::AddonEvents::Enabled) ||
typeid(event) == typeid(ADDON::AddonEvents::ReInstalled))
msg.SetStringParam(event.id);

CApplicationMessenger::GetInstance().SendGUIMessage(msg, m_guiWindow->GetID());
}
}
Expand Down
2 changes: 1 addition & 1 deletion xbmc/games/controllers/windows/GUIControllerList.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace GAME
// implementation of IControllerList
virtual bool Initialize(void) override;
virtual void Deinitialize(void) override;
virtual bool Refresh(void) override;
virtual bool Refresh(const std::string& controllerId) override;
virtual void OnFocus(unsigned int controllerIndex) override;
virtual void OnSelect(unsigned int controllerIndex) override;
virtual int GetFocusedController() const override { return m_focusedController; }
Expand Down
3 changes: 2 additions & 1 deletion xbmc/games/controllers/windows/GUIControllerWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ bool CGUIControllerWindow::OnMessage(CGUIMessage& message)

if (controlId == CONTROL_CONTROLLER_LIST)
{
if (m_controllerList && m_controllerList->Refresh())
const std::string controllerId = message.GetStringParam();
if (m_controllerList && m_controllerList->Refresh(controllerId))
{
CGUIDialog::OnMessage(message);
bHandled = true;
Expand Down
3 changes: 2 additions & 1 deletion xbmc/games/controllers/windows/IConfigurationWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ namespace GAME

/*!
* \brief Refresh the contents of the list
* \param controllerId The controller to focus, or empty to leave focus unchanged
* \return True if the list was changed
*/
virtual bool Refresh(void) = 0;
virtual bool Refresh(const std::string& controllerId) = 0;

/*
* \brief The specified controller has been focused
Expand Down

0 comments on commit c67eb3a

Please sign in to comment.