Allow to disable a keyboard configuration without deleting it

This commit is contained in:
Alayan-stk-2 2018-09-15 18:28:31 +02:00 committed by GitHub
parent 78e592bfbf
commit 19ba899afd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -82,44 +82,78 @@ void OptionsScreenDevice::init()
tabBar->select( "tab_controls", PLAYER_ID_GAME_MASTER ); tabBar->select( "tab_controls", PLAYER_ID_GAME_MASTER );
ButtonWidget* delete_button = getWidget<ButtonWidget>("delete"); ButtonWidget* delete_button = getWidget<ButtonWidget>("delete");
ButtonWidget* disable_toggle = getWidget<ButtonWidget>("disable_toggle");
if (m_config->isGamePadAndroid())
{
delete_button->setActive(false);
disable_toggle->setActive(false);
}
else
{
core::stringw label;
if (!m_config->isKeyboard()) if (!m_config->isKeyboard())
{ {
core::stringw label = (m_config->isEnabled() // Only allow to enable or disable a gamepad,
// as it is only in the list when connected
delete_button->setActive(false);
label = (m_config->isEnabled()
? //I18N: button to disable a gamepad configuration ? //I18N: button to disable a gamepad configuration
_("Disable Device") _("Disable Device")
: //I18N: button to enable a gamepad configuration : //I18N: button to enable a gamepad configuration
_("Enable Device")); _("Enable Device"));
}
else
{
// Don't allow deleting the last config
delete_button->setActive(
input_manager->getDeviceManager()->getKeyboardAmount() > 1);
label = (m_config->isEnabled()
? //I18N: button to disable a gamepad configuration
_("Disable Configuration")
: //I18N: button to enable a gamepad configuration
_("Enable Configuration"));
}
// Make sure button is wide enough as the text is being changed away // Make sure button is wide enough as the text is being changed away
// from the original value // from the original value
core::dimension2d<u32> size = core::dimension2d<u32> size =
GUIEngine::getFont()->getDimension(label.c_str()); GUIEngine::getFont()->getDimension(label.c_str());
const int needed = size.Width + delete_button->getWidthNeededAroundLabel(); const int needed = size.Width + disable_toggle->getWidthNeededAroundLabel();
if (delete_button->m_w < needed) delete_button->m_w = needed; if (disable_toggle->m_w < needed) disable_toggle->m_w = needed;
delete_button->setLabel(label); disable_toggle->setLabel(label);
} }
else if (m_config->isGamePadAndroid())
// Make the three buttons the same length, not strictly needed but will
// look nicer...
ButtonWidget* backBtn = getWidget<ButtonWidget>("back_to_device_list");
if (disable_toggle->m_w < delete_button->m_w)
{ {
delete_button->setLabel(_("Delete Configuration")); disable_toggle->m_w = delete_button->m_w;
delete_button->setActive(false);
} }
else else
{ {
delete_button->setLabel(_("Delete Configuration")); delete_button->m_w = disable_toggle->m_w;
// Don't allow deleting the last config }
delete_button->setActive( // At this point, the delete button has the same width as the disable button.
input_manager->getDeviceManager()->getKeyboardAmount() > 1); // One comparison is enough.
if (backBtn->m_w < delete_button->m_w)
{
backBtn->m_w = delete_button->m_w;
}
else
{
disable_toggle->m_w = backBtn->m_w;
delete_button->m_w = backBtn->m_w;
} }
// Make the two buttons the same length, not strictly needed but will
// look nicer...
ButtonWidget* backBtn = getWidget<ButtonWidget>("back_to_device_list");
if (backBtn->m_w < delete_button->m_w) backBtn->m_w = delete_button->m_w;
else delete_button->m_w = backBtn->m_w;
backBtn->moveIrrlichtElement(); backBtn->moveIrrlichtElement();
delete_button->moveIrrlichtElement(); delete_button->moveIrrlichtElement();
disable_toggle->moveIrrlichtElement();
LabelWidget* label = getWidget<LabelWidget>("title"); LabelWidget* label = getWidget<LabelWidget>("title");
label->setText( m_config->getName().c_str(), false ); label->setText( m_config->getName().c_str(), false );
@ -159,12 +193,13 @@ void OptionsScreenDevice::init()
actions->setFocusForPlayer(PLAYER_ID_GAME_MASTER); actions->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
actions->setSelectionID(0); actions->setSelectionID(0);
// Disable deletion keyboard configurations // Disable deleting or disabling configuration mid-race
bool in_game = StateManager::get()->getGameState() == GUIEngine::INGAME_MENU; bool in_game = StateManager::get()->getGameState() == GUIEngine::INGAME_MENU;
if (in_game) if (in_game)
{ {
getWidget<ButtonWidget>("delete")->setActive(false); delete_button->setActive(false);
disable_toggle->setActive(false);
} }
} // init } // init
@ -566,29 +601,35 @@ void OptionsScreenDevice::eventCallback(Widget* widget,
} }
} }
else if (name == "delete") else if (name == "delete")
{
if (m_config->isKeyboard())
{ {
// keyboard configs may be deleted // keyboard configs may be deleted
// They should be the only one to have the button enabled
//I18N: shown before deleting an input configuration //I18N: shown before deleting an input configuration
new MessageDialog( _("Are you sure you want to permanently delete " new MessageDialog( _("Are you sure you want to permanently delete "
"this configuration?"), "this configuration?"),
MessageDialog::MESSAGE_DIALOG_CONFIRM, this, false ); MessageDialog::MESSAGE_DIALOG_CONFIRM, this, false );
} }
else else if (name == "disable_toggle")
{ {
// gamepad configs may be disabled // gamepad and keyboard configs may be disabled
if (m_config->isEnabled()) m_config->setEnabled(false); if (m_config->isEnabled()) m_config->setEnabled(false);
else m_config->setEnabled(true); else m_config->setEnabled(true);
// update widget label // update widget label
ButtonWidget* delete_button = getWidget<ButtonWidget>("delete"); ButtonWidget* disable_toggle = getWidget<ButtonWidget>("disable_toggle");
delete_button->setLabel(m_config->isEnabled() ? _("Disable Device") if (!m_config->isKeyboard())
{
disable_toggle->setLabel(m_config->isEnabled() ? _("Disable Device")
: _("Enable Device") ); : _("Enable Device") );
}
else
{
disable_toggle->setLabel(m_config->isEnabled() ? _("Disable Configuration")
: _("Enable Configuration") );
}
input_manager->getDeviceManager()->save(); input_manager->getDeviceManager()->save();
} }
}
} // eventCallback } // eventCallback